[lld] [lld][ICF] Prevent merging two sections when they point to non-globals (PR #136641)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 22 06:07:47 PDT 2025


================
@@ -356,6 +357,22 @@ static SmallVector<Symbol *> getRelocTargetSyms(const InputSection *sec) {
   return getReloc(sec, rel.relas);
 }
 
+// Checks if relocation has semantics beyond just the offset. We identify
+// such relocations to prevent ICF to preserve correctness.
+static bool isTrivialRelocationType(uint16_t emachine, RelType type) {
+  if (emachine == EM_AARCH64) {
+    switch (type) {
+    case R_AARCH64_GOT_LD_PREL19:
+    case R_AARCH64_LD64_GOTOFF_LO15:
+    case R_AARCH64_ADR_GOT_PAGE:
+    case R_AARCH64_LD64_GOT_LO12_NC:
+    case R_AARCH64_LD64_GOTPAGE_LO15:
+      return false;
----------------
smithp35 wrote:

I think these are the most likely candidates but there's a few more possibilities. We need to consider all relocations in https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst that had `GDAT`, `GTLSDESC` or `GTPREL` in their operation.

The group relocations 300 - 306 construct a constant from a series of `MOVW` and `MOVK` instructions. To the best of my knowledge no compiler uses these yet. They would be most usefil in a position-independent large code-model (`.got` > 4 GiB from the code), but no-one has yet needed anything that big.

TLS (these all use sequences of instructions and a GOT entry)
539 - 543 For the Initial Exec TLS relocations (GTPREL)
560 - 566 For the TLS Descriptor relocations (GTLSDESC)

The AUTH equivalent "Relocations for PAuth ABI extension" can be generated by clang when generating code for the PAuth ABI. These would be:
581 - 597



https://github.com/llvm/llvm-project/pull/136641


More information about the llvm-commits mailing list