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