[lld] 54df4b8 - [NFCI][ELF] Merge AgainstSymbol and AgainstSymbolWithTargetVA

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 09:07:02 PDT 2025


Author: Jessica Clarke
Date: 2025-07-30T17:06:59+01:00
New Revision: 54df4b8c35b6f53d3df418c58a0c920c6132e0f7

URL: https://github.com/llvm/llvm-project/commit/54df4b8c35b6f53d3df418c58a0c920c6132e0f7
DIFF: https://github.com/llvm/llvm-project/commit/54df4b8c35b6f53d3df418c58a0c920c6132e0f7.diff

LOG: [NFCI][ELF] Merge AgainstSymbol and AgainstSymbolWithTargetVA

The former is just a special case of the latter, ignoring the expr and
always just using the addend. If we use R_ADDEND as expr (which
previously had no effect, and so was misleadingly R_ABS not R_ADDEND in
all but one use) then we don't need to maintain this as a separate case.

Aside from the internal Computed Kind, this just leaves MipsMultiGotPage
as a special case; the only difference between the other two Kind values
is what needsDynSymIndex returns.

Reviewers: MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/150798

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/ELF/SyntheticSections.cpp
    lld/ELF/SyntheticSections.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index ed53228359f86..7579def5865bb 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -885,10 +885,12 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt,
                         RelocationBaseSection &rel, RelType type, Symbol &sym) {
   plt.addEntry(sym);
   gotPlt.addEntry(sym);
-  rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
-                sym.isPreemptible ? DynamicReloc::AgainstSymbol
-                                  : DynamicReloc::AddendOnly,
-                sym, 0, R_ABS});
+  if (sym.isPreemptible)
+    rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
+                  DynamicReloc::AgainstSymbol, sym, 0, R_ADDEND});
+  else
+    rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
+                  DynamicReloc::AddendOnly, sym, 0, R_ABS});
 }
 
 void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
@@ -899,7 +901,7 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
   if (sym.isPreemptible) {
     ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off,
                                      DynamicReloc::AgainstSymbol, sym, 0,
-                                     R_ABS});
+                                     R_ADDEND});
     return;
   }
 
@@ -921,7 +923,7 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
   if (sym.isPreemptible) {
     ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(),
                                      off, DynamicReloc::AgainstSymbol, sym, 0,
-                                     R_ABS});
+                                     R_ADDEND});
     return;
   }
 

diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index da0cf1298d1ab..90f87ddb79005 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1065,9 +1065,9 @@ void MipsGotSection::build() {
       // for the TP-relative offset as we don't know how much other data will
       // be allocated before us in the static TLS block.
       if (s->isPreemptible || ctx.arg.shared)
-        ctx.mainPart->relaDyn->addReloc(
-            {ctx.target->tlsGotRel, this, offset,
-             DynamicReloc::AgainstSymbolWithTargetVA, *s, 0, R_ABS});
+        ctx.mainPart->relaDyn->addReloc({ctx.target->tlsGotRel, this, offset,
+                                         DynamicReloc::AgainstSymbol, *s, 0,
+                                         R_ABS});
     }
     for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
       Symbol *s = p.first;
@@ -1650,14 +1650,11 @@ int64_t DynamicReloc::computeAddend(Ctx &ctx) const {
   case Computed:
     llvm_unreachable("addend already computed");
   case AddendOnly:
-  case AgainstSymbolWithTargetVA: {
+  case AgainstSymbol: {
     uint64_t ca = inputSec->getRelocTargetVA(
         ctx, Relocation{expr, type, 0, addend, sym}, getOffset());
     return ctx.arg.is64 ? ca : SignExtend64<32>(ca);
   }
-  case AgainstSymbol:
-    assert(sym != nullptr);
-    return addend;
   case MipsMultiGotPage:
     assert(sym == nullptr);
     return getMipsPageAddr(outputSec->addr) + addend;
@@ -1700,7 +1697,7 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
   // No need to write an addend to the section for preemptible symbols.
   if (sym.isPreemptible)
     addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
-              R_ABS});
+              R_ADDEND});
   else
     addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
              R_ABS, addendRelType);

diff  --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 8185417755d25..bd8fdc5f00391 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -427,13 +427,9 @@ class DynamicReloc {
     /// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
     AddendOnly,
     /// The resulting dynamic relocation references symbol #sym from the dynamic
-    /// symbol table and uses #addend as the value of computeAddend(ctx).
+    /// symbol table and uses InputSection::getRelocTargetVA() for the final
+    /// addend.
     AgainstSymbol,
-    /// The resulting dynamic relocation references symbol #sym from the dynamic
-    /// symbol table and uses InputSection::getRelocTargetVA() + #addend for the
-    /// final addend. It can be used for relocations that write the symbol VA as
-    // the addend (e.g. R_MIPS_TLS_TPREL64) but still reference the symbol.
-    AgainstSymbolWithTargetVA,
     /// This is used by the MIPS multi-GOT implementation. It relocates
     /// addresses of 64kb pages that lie inside the output section.
     MipsMultiGotPage,
@@ -463,7 +459,7 @@ class DynamicReloc {
   uint32_t getSymIndex(SymbolTableBaseSection *symTab) const;
   bool needsDynSymIndex() const {
     assert(kind != Computed && "cannot check kind after computeRaw");
-    return kind == AgainstSymbol || kind == AgainstSymbolWithTargetVA;
+    return kind == AgainstSymbol;
   }
 
   /// Computes the addend of the dynamic relocation. Note that this is not the


        


More information about the llvm-commits mailing list