PIC is wasteful

Agner Fog agner@agner.org
Fri Jun 24 10:20:00 GMT 2011



On 23-06-2011 22:02, Marc Glisse wrote:
> On Thu, 23 Jun 2011, Ian Lance Taylor wrote:
>
>> Agner Fog <agner@agner.org> writes:
>>
>>> I wonder why position-independent code (PIC) and global offset tables
>>> (GOT) are used in shared objects (.so) when these features are wasting
>>> resources and apparently unnecessary. The wasteful use of PIC and GOT
>>> in Linux is apparent in the following questions:
>
> Do you mean you would like -Bsymbolic to be the default ? (or maybe 
> Solaris' -Bdirect)

Thanks for the tip about -Bsymbolic, that's what I want, but it doesn't 
seem to do the job.
When I compile with -Bsymbolic -fpic I still get a GOT entry in 64 bit mode.

When I compile with -Bsymbolic and without -fpic I get:

relocation R_X86_64_32 against `__gxx_personality_v0' can not be used 
when making a shared object; recompile with -fPIC

When I compile with -fno-exceptions I don't get this error, but instead 
I get:

relocation R_X86_64_32 against `a local symbol' can not be used when 
making a shared object; recompile with -fPIC

This 'local symbol' is my function in section .eh_frame. Why does it 
make .eh_frame when I turn off exception handling?

A further problem in 64 bit mode is that even though I compile with 
-mcmodel=medium, I get:

relocation R_X86_64_32 against `VariableName' can not be used when 
making a shared object; recompile with -fPIC

Why does it make 32 bit absolute addresses when I specify 
-mcmodel=medium? How can I force it to use full 64 bit addresses or 32 
bit relative addresses without specifying -fpic?



More information about the Gcc-help mailing list