PIC is wasteful

Agner Fog agner@agner.org
Fri Jun 24 19:50:00 GMT 2011


On 24-06-2011 17:56, Ian Lance Taylor wrote:
> -mcmodel=large.
>> The large model is not supported. If it was, it would probably be
>> inefficient.
> The large model certainly is supported.
>
> What version of gcc are you using?
You are right. I tried a newer version (gcc 4.5.2, binutils 2.21) and 
the large model works.

Now I can make a 64 bit shared object with -mcmodel=large and without 
-fpic and it works. But as I suspected, it is not optimal. It uses full 
64 bit addresses for almost everything rather than 32 bit relative 
addresses. This is inefficient because it makes the code larger and 
because 64 bit addressing is poorly supported in the x64 instruction 
set. It loads the full absolute address into a 64-bit pointer register 
whenever it is reading or writing any register other than eax and when 
calling an external function.

I need a memory model between medium and large to allow 32-bit relative 
addresses but not 32-bit absolute addresses.



More information about the Gcc-help mailing list