PIC is wasteful

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


Interestingly, it all works in 32 bit mode. I can compile without -fpic 
and make an absolute reference to a global variable with no GOT entry 
and no PLT in a shared object and I get no warnings or errors. It just 
works. Also, there is no exception handler section even though I did not 
turn off exceptions.

Why is 64 bit mode so different?


On 24-06-2011 10:23, Andrew Haley wrote:
>
>> Why does it make 32 bit absolute addresses when I specify
>> -mcmodel=medium?
> Small symbols are placed in the lower 2G.
So I would have to replace all variables with very big arrays in order 
to prevent 32 bit addresses in 64 bit mode :-(

Is there no way to avoid 32 bit absolute addresses in 64 bit mode other 
than -fpic which has the undesired effect of using GOT and PLT entries?

This is weird:
-fpic doesn't make position-independent code as the name implies - it 
makes code that fits into a shared object. My test code compiled with 
-fpic or -fPIC still has absolute references in virtual tables and in 
the exception handler section in both 32 and 64 bit mode.

-Bsymbolic doesn't seem to do anything. At least it doesn't prevent GOT 
entries



More information about the Gcc-help mailing list