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

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 30 21:48:12 PDT 2016

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.



More information about the llvm-commits mailing list