[lld] [ELF] Add target-specific relocation scanning for x86 (PR #178846)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 3 23:59:29 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);
+
+ // Handle R_PC relocations. These are the most common relocation type, so we
+ // inline the isStaticLinkTimeConstant check.
+ void scanPCRel(RelType type, uint64_t offset, int64_t addend, Symbol &sym) {
+ if (LLVM_UNLIKELY(sym.isGnuIFunc()))
+ sym.setFlags(HAS_DIRECT_RELOC);
+ if (!sym.isPreemptible && (!ctx.arg.isPic || !isAbsolute(sym))) {
----------------
MaskRay wrote:
Thanks for the suggestion. Adopted this:
```cpp
if (sym.isPreemptible || (isAbsolute(sym) && ctx.arg.isPic)) // uncommon path
processAux(R_PC, type, offset, sym, addend);
else // common path
sec->addReloc({R_PC, type, offset, addend, &sym});
```
https://github.com/llvm/llvm-project/pull/178846
More information about the llvm-commits
mailing list