[PATCH] D91993: [ELF] Don't relax R_X86_64_GOTPCRELX if addend != -4

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 26 09:28:56 PST 2020

MaskRay added a comment.

In D91993#2417791 <https://reviews.llvm.org/D91993#2417791>, @grimar wrote:

> In D91993#2416496 <https://reviews.llvm.org/D91993#2416496>, @MaskRay wrote:
>> Note, R_X86_64_GOTPCRELX already does not guarantee ensured relaxation, e.g. when the symbol is preemptible the linker cannot relax the instruction, when the instruction is not one of call,jmp,adc,add,and,cmp,or,sbb,sub,test,xor, etc.
> Seems that, e.g., `R_X86_64_GOTPCREL` should give a guarantee that relaxation will not be performed though. As far I understand GNU linkers can relax `R_X86_64_GOTPCREL` too? It looks like a violation of ABI?
> The suggested change (for ABI) about addend then seems only needed to support this behavior of GNU linkers. In LLVM we probably should just not emit a potentially relaxable relocation from the begining.

GNU ld and gold can relax `R_X86_64_GOTPCREL` if the instruction is a movq. This behavior is not documented in the x86-64 psABI. I think LLD's choice is more sensible: no relaxation for `R_X86_64_GOTPCREL`.

(GNU ld's behavior is actually very complex (https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=56ceb5b5405af23eddd12e12d8ba849010120324 not changed a lot since it was committed))

  rG LLVM Github Monorepo



More information about the llvm-commits mailing list