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

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 15:40:54 PDT 2023


MaskRay added inline comments.


================
Comment at: lld/ELF/Arch/X86_64.cpp:316
+  }
+  // If the max VA difference is under 2^31-1, 32 bit signed offsets cannot
+  // overflow.
----------------



================
Comment at: lld/ELF/Arch/X86_64.cpp:318
+  // overflow.
+  if (maxVA - minVA < (uint64_t(1) << 31) - 1)
+    return false;
----------------
aeubanks wrote:
> @MaskRay is this ok performance wise? this should be very quick and we should skip the expensive stuff below for typical binaries
`if (maxVA - minVA < (uint64_t(1) << 31))` or `isUInt<31>(...)`


================
Comment at: lld/test/ELF/x86-64-gotpc-relax-too-far.s:8
+# RUN: ld.lld %t/a.o -o %t/bin2
+# RUN: llvm-readobj --sections %t/bin2 | FileCheck --check-prefixes=SECTIONS,UNNECESSARY-GOT %s
+
----------------
Prefer `llvm-readelf -S` for new tests. The tabular output is easier to read than `llvm-readobj -S`


================
Comment at: lld/test/ELF/x86-64-gotpc-relax.s:8
 # RUN: ld.lld %t.o -o %t1 --apply-dynamic-relocs
 # RUN: llvm-readobj -x .got.plt -r %t1 | FileCheck --check-prefixes=RELOC,APPLY-DYNAMIC-RELOCS %s
 # RUN: ld.lld %t.o -o %t1
----------------
Additionally test `-S` and check that `.got` has a size of 0.

Add a comment:

```
##  In our implementation, .got is retained even if all GOT-generating relocations are optimized.
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157020/new/

https://reviews.llvm.org/D157020



More information about the llvm-commits mailing list