[PATCH] D157020: [WIP][lld/ELF] Don't relax R_X86_64_(REX_)GOTPCRELX when offset is too far

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 3 11:11:11 PDT 2023


aeubanks created this revision.
aeubanks added reviewers: MaskRay, peter.smith.
Herald added subscribers: luismarques, pengfei, s.egerton, PkmX, simoncook, kristof.beyls, arichardson, emaste.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

For each R_X86_64_(REX_)GOTPCRELX relocation, check that the offset to the symbol is representable with 2^32 signed offset. If not, add a GOT entry for it and set its expr to R_GOT_PC so that we emit the GOT load instead of the relaxed lea. Do this in finalizeAddressDependentContent() where we iteratively attempt this (e.g. RISCV uses this for relaxation, ARM uses this to insert thunks).

Decided not to do the opposite of inserting GOT entries initially and removing them when relaxable because removing GOT entries isn't simple.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D157020

Files:
  lld/ELF/Arch/X86_64.cpp
  lld/ELF/Relocations.cpp
  lld/ELF/Relocations.h
  lld/ELF/Writer.cpp
  lld/test/ELF/x86-64-gotpc-err.s
  lld/test/ELF/x86-64-gotpc-relax-too-far.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157020.546949.patch
Type: text/x-patch
Size: 5850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230803/4cafd03c/attachment.bin>


More information about the llvm-commits mailing list