[PATCH] D19995: Optimize access to global variable references in PIE mode when linker supports copy relocations for PIE

H.J. Lu via llvm-commits llvm-commits at lists.llvm.org
Mon May 9 07:30:20 PDT 2016


On Mon, May 9, 2016 at 7:01 AM, Joerg Sonnenberger via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> On Mon, May 09, 2016 at 05:13:35AM +0000, John McCall via llvm-commits wrote:
>> rjmccall added a comment.
>>
>> In http://reviews.llvm.org/D19995#424356, @joerg wrote:
>>
>> > In http://reviews.llvm.org/D19995#424345, @rjmccall wrote:
>> >
>> > > It seems reasonable to me to have an option enabling the use of copy relocations for globals,
>> > >  and I agree with David that that option should logically be applicable to PIE.  I would also tend
>> > >  to agree with Joerg that that option should default to off, even in non-PIC modes, but it's not my call.
>> >
>> >
>> > Non-PIC use of copy relocations is practically unavoidable
>>
>>
>> This is not even slightly true.  There is absolutely nothing preventing
>> you from using a GOT-style relocation in non-PIC mode.  Even if you
>> didn't have linker support for a non-relative relocation to a GOT entry
>> (on platforms where it matters), you can easily fake one up with weak symbols.
>
> The original ABI design was static linking and dynamic linking of the
> main program from exactly the same object files. Using GOT-style
> relocations is prohibitive on all platforms without cheap PC-relative
> addressing. This includes for example i386. I don't know why amd64

You can use the new R_386_GOT32X relocation to access the
GOT in executable with the base register, like

movl $foo at GOT, %eax
movl foo at GOT, %eax

But not all linkers can relocate it properly.

-- 
H.J.


More information about the llvm-commits mailing list