[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
Mon Nov 23 13:06:00 PST 2020


MaskRay created this revision.
MaskRay added reviewers: craig.topper, grimar, sberg.
Herald added subscribers: llvm-commits, pengfei, kbarton, arichardson, nemanjai, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

clang may produce `movl x at GOTPCREL+4(%rip), %rax` when loading the high 32 bits
of the address of a global variable in -fpic/-fpie mode.

When assembled by GNU as or newer integrated assembler (after commit
f04d92af94a8d763e91ae38fe35319e426dc466c <https://reviews.llvm.org/rGf04d92af94a8d763e91ae38fe35319e426dc466c>), the assembly emits R_X86_64_GOTPCRELX
with an addend != -4. The instruction loads from the GOT entry with an offset and
thus it is incorrect to relax the instruction.

This patch disables the relaxation, which is compatible with the implementation in GNU ld
("Add R_X86_64_[REX_]GOTPCRELX support to gas and ld").

We add a new `TargetInfo::adjustGotPcExpr` for `R_GOT_PC` relaxations. With this
change, `TargetInfo::adjustRelaxExpr` is only related to TLS relaxations and a
subsequent clean-up can delete the `data` parameter.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91993

Files:
  lld/ELF/Arch/PPC64.cpp
  lld/ELF/Arch/X86_64.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Target.cpp
  lld/ELF/Target.h
  lld/test/ELF/x86-64-gotpc-offset.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91993.307180.patch
Type: text/x-patch
Size: 7155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201123/51c1f3e8/attachment.bin>


More information about the llvm-commits mailing list