lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, 2003-12-02 at 18:11, Reuben Thomas wrote:
> Oh great, so unlike the wonderful world of ARM where PIC is the only
> option, on x86 you get the option to shoot yourself all because you might
> otherwise lose a few % performance. Sigh. I wouldn't have any problem
> being able to turn PIC off, but it should at least be the default.

Again, while ARM's code is PIC, the interlinking, preamble, postamble
etc all need to be aware that they're going into shared objects.

> I'm only really worried about x86, as I'm not maintaining my package for
> Fedora Core or anything fancy. Are there architectures on which building
> -fPIC for shared objects is a problem?

Not that I've found, although there are interesting issues with ia64
which I can't remember, but I do remember encountering. Of course those
might have been due to my odd set of -Wl flags I was giving to gcc in
order to get SONAME resources right in the resultant shared objects.

> > So in summary -- when building a shared object *always* compile -fPIC
> > (-fpic) and *always* link -fPIC too. Regardless of the target
> > CPU/code-generator, both the compiler and linker need to know that
> > they're meant to be making code for a shared object.
> Ah, the linking I hadn't cottoned on about. I'll shuffle off and do that
> now; if anyone's reading this who read my earlier announcement of an
> update, then look for the -2 release of the RPM, which will be built with
> -fPIC for linking too. I won't bother to reannounce.

Assuming you're linking using the gcc driver frontend, then it should
pick it up automagically from the objects and the fact that you say
-shared to link the shared object...

My link rules are:

 gcc -o lib/liblua50.so.$V -shared -Wl,-soname,liblua50.so.$V \
               src/*.os -lc
 ln -fs liblua50.so.$V lib/liblua-build50.so
        gcc -o lib/liblualib50.so.$V -shared \
               -Wl,-soname,liblualib50.so.$V \
               src/lib/*.os -Llib -llua-build50 -lm -lc
        cd lib; ln -fs liblua50.so.$V liblua50.so; \
                ln -fs liblualib50.so.$V liblualib50.so

in the so: target of the top level Makefile.

Then to make the blah.os files (object, shared) I had the following
rules:

%.os: %.c
        $(CC) $(CFLAGS) -fPIC -DPIC -o $@ -c $<

in the config file

The -DPIC is mostly superfluous, but I put it in through force of habit
more than anything.

D.

-- 
Daniel Silverstone <dsilvers@digital-scurf.org>
Digital-Scurf