[lld] [ELF] Add target-specific relocation scanning for x86 (PR #178846)

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 6 04:16:24 PST 2026


================
@@ -66,8 +66,106 @@ class RelocScan {
                                 uint64_t relOff) const;
   void process(RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
                int64_t addend) const;
+  // Process relocation after needsGot/needsPlt flags are already handled.
+  void processAux(RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
+                  int64_t addend) const;
   unsigned handleTlsRelocation(RelExpr expr, RelType type, uint64_t offset,
                                Symbol &sym, int64_t addend);
+
+  // Process R_PC relocations. These are the most common relocation type, so we
+  // inline the isStaticLinkTimeConstant check.
+  void processR_PC(RelType type, uint64_t offset, int64_t addend, Symbol &sym) {
+    if (LLVM_UNLIKELY(sym.isGnuIFunc()))
+      sym.setFlags(HAS_DIRECT_RELOC);
+    if (sym.isPreemptible || (isAbsolute(sym) && ctx.arg.isPic))
+      processAux(R_PC, type, offset, sym, addend);
+    else
+      sec->addReloc({R_PC, type, offset, addend, &sym});
+  }
+
+  // Process R_PLT_PC relocations. These are very common (calls), so we inline
+  // the isStaticLinkTimeConstant check. Non-preemptible symbols are optimized
+  // to R_PC (direct call).
+  void processR_PLT_PC(RelType type, uint64_t offset, int64_t addend,
+                       Symbol &sym) {
+    if (LLVM_UNLIKELY(sym.isGnuIFunc())) {
+      process(R_PLT_PC, type, offset, sym, addend);
+      return;
+    }
+    if (sym.isPreemptible) {
+      sym.setFlags(NEEDS_PLT);
+      sec->addReloc({R_PLT_PC, type, offset, addend, &sym});
+    } else if (!(isAbsolute(sym) && ctx.arg.isPic)) {
+      sec->addReloc({R_PC, type, offset, addend, &sym});
+    } else {
+      processAux(R_PC, type, offset, sym, addend);
+    }
+  }
+
+  // Handle TLS Initial-Exec relocation.
+  void handleTlsIe(RelExpr ieExpr, RelType type, uint64_t offset,
+                   int64_t addend, Symbol &sym) {
+    ctx.hasTlsIe.store(true, std::memory_order_relaxed);
----------------
smithp35 wrote:

I don't think this is needed if we relax to Local Exec. Looking at what it is used for, I don't think it will make any difference in the output, but could be worth putting in the code-path for Initial Exec only.

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


More information about the llvm-commits mailing list