[PATCH] D26133: [ELF] Relative relocations to absolute symbols in PIC

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 31 10:01:52 PDT 2016


> generate a dynamic relocation when the expression is relative relocation to an absolute symbol

Looks like that's what I was trying to fix in https://reviews.llvm.org/D25560

> "foo = ." is not actually absolute

It's not the only problem. For instance `foo = variable` is also
absolute as well as `foo = ADDR(.section)`.
Also when I define `foo = 0` in script and use ld/gold, foo is a load
address of an image. When I use lld it's just zero.

2016-10-31 15:25 GMT+03:00 Rafael EspĂ­ndola via llvm-commits
<llvm-commits at lists.llvm.org>:
> I don't think this is correct.
>
> The underlying problem is that a symbol created with "foo = ." is not
> actually absolute, it is a position in the file.
>
> This has showed in two bugs so far, so I will give it a try at making
> "foo = ." non absolute and see if it fixes the issue.
>
> Cheers,
> Rafael
>
>
> On 31 October 2016 at 00:48, Petr Hosek via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> phosek added a comment.
>>
>> I ran into this issue while looking a linker script failure described in bug 30406 <https://llvm.org/bugs/show_bug.cgi?id=30406>. The failure was caused by the check in `ELF/Relocation.cpp`. While debugging the issue, I noticed that both BFD ld and gold handle this case and don't throw an error for the `relocation-relative-absolute.s` test case.
>>
>> This is really a corner case behavior that's not document very well by the ELF specification, so I got in touch with Ian Lance Taylor and his opinion on this is:
>>
>>> It's an unusual case, but the only possible meaning of this is a call to the absolute address.  The linker needs to either generate a dynamic PC-relative relocation to an SHN_ABS symbol (which could of course overflow at runtime on x86_64) or generate a PLT with a JMP_SLOT reference to an SHN_ABS symbol.  I don't see how anything else is correct.  In particular I don't see how it is correct to reject such a case, it's clearly meaningful and the technique is used on, at least, pre-VDSO GNU/Linux and AIX.
>>
>> The problem is that neither BFD ld nor gold do this, instead they both generate an absolute jump. This change changes the lld behavior to match the current behavior of ld and gold. If were to implement the behavior Ian suggested, we'd have to also modify the `scanRelocs` function, in particular the part which handles the constant case and generate a dynamic relocation when the expression is relative relocation to an absolute symbol.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> https://reviews.llvm.org/D26133
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list