Re: Don't know if my previous message got through....

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

 



Ian Lance Taylor wrote:
Asfand Yar Qazi <email@xxxxxxxxxxxxxxxxx> writes:


On several occasions I've used the '-whole-archive' flag of ld via -Wl
on gcc to convert .a files to .so files.  I can't understand why
libtool has to compile things twice, once using -fPIC and once not
using it - I checked the resulting object  files and the -fPIC files
are bigger, and yet I've never needed to use that flag when doing my
.a to .so conversions.

Could someone explain this to me?  Isn't compiling twice with libtool
redundant and a waste of time?


Code compiled without -fPIC is more efficient in an ordinary
executable, because it does not require using the Global Offset Table
to access variables.  You can put code compiled without -fPIC in a
shared library.  However, when you do this, the linker is forced to
create dynamic relocations for the .text section.  When the dynamic
linker sees them, it is forced to make a copy of the shared library,
and apply the dynamic relocations based on the specific address where
the shared library was mapped.  That means that the shared library is
specific to a process, and is, in fact, no longer shared.  That
doesn't matter much for the process (except for startup time) but it
does decrease overall system performance.

So the summary is that code compiled without -fPIC is more efficient
in an ordinary executable, but less efficient in a shared library, so
it is reasonable for libtool to compile both ways.

Ian



Ah, thanks. I was going to create a library that make a '.a' file and converts it to a '.so' file using the --whole-archive trick, but now I realise I must compile everything twice - yuk.

Still, I think I'll create some way of preprocessing the file first into a '.i' file or a '.ii' file, then compiling the preprocessed '.i' or '.ii' file twice, once with -fPIC and again without - should speed up compilation slightly.

Again, thanks
          Asfand Yar

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux