------- Comment #5 from brian at dessent dot net 2008-03-07 23:48 ------- Subject: Re: Documentation for -fPIC/-fpic/-fpie is not clear
> I am still learning about linking and loading and I can't guess why non-PIC > DSOs would work on x86 but not on x86_64. Could you please explain briefly. > > This is all very useful information that I couldn't find anywhere else (I > guess > I could always look at gcc code :) ). Can the following be added to > documentation? PIC is always required for DSOs, at least on unix/ELF-like targets. It's just that one platform in particular lets you get away with linking non-PIC code into a .so, namely x86. All (?) other architectures will give a link time error if you try to do this. So it's horribly non-portable and it really just works by accident. And it loses most of the advantages of shared libraries to put non-PIC code in a .so: text relocs. This prevents sharing of code pages between processes, so really the .so is no longer shared from a memory footprint standpoint since each process will have its own dedicated copy as the .text section needs to be modified (relocated). This also has a startup cost. This kind of thing can't really be easily documented in the gcc manual because it's platform specific. gcc is not just a compiler for x86 or Linux, it supports dozens and dozens of platforms/targets and they each have different semantics of how shared libraries work -- if they even have shared libraries. For example there might be x86 platforms that don't even have shared libraries, like bare metal or a.out targets, so you can't even make any definitive statements about x86. So while "x86 linux" may be common it is most certainly not the only thing gcc is used with. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35500