[lld] 46d29d4 - [ELF] Remove unused handleTlsRelocation (#184951)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 5 21:53:33 PST 2026


Author: Fangrui Song
Date: 2026-03-06T05:53:28Z
New Revision: 46d29d43ba8ee99c34a3afdc0f4e4b5a9c8b6218

URL: https://github.com/llvm/llvm-project/commit/46d29d43ba8ee99c34a3afdc0f4e4b5a9c8b6218
DIFF: https://github.com/llvm/llvm-project/commit/46d29d43ba8ee99c34a3afdc0f4e4b5a9c8b6218.diff

LOG: [ELF] Remove unused handleTlsRelocation (#184951)

Now that all targets use target-specific relocation scanning for TLS
(#181332 RISC-V being the last), handleTlsRelocation is unused.

Added: 
    

Modified: 
    lld/ELF/InputSection.cpp
    lld/ELF/RelocScan.h
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 4396871f1d3f2..c8c0a7cdbf109 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -780,9 +780,8 @@ static int64_t getTlsTpOffset(Ctx &ctx, const Symbol &s) {
     return s.getVA(ctx, 0) + (tls->p_vaddr & (tls->p_align - 1)) - 0x7000;
   case EM_LOONGARCH:
   case EM_RISCV:
-    // See the comment in handleTlsRelocation. For TLSDESC=>IE,
-    // R_RISCV_TLSDESC_{LOAD_LO12,ADD_LO12_I,CALL} also reach here. While
-    // `tls` may be null, the return value is ignored.
+    // For TLSDESC=>IE, R_RISCV_TLSDESC_{LOAD_LO12,ADD_LO12_I,CALL} reference
+    // a non-TLS label and reach here.
     if (s.type != STT_TLS)
       return 0;
     return s.getVA(ctx, 0) + (tls->p_vaddr & (tls->p_align - 1));

diff  --git a/lld/ELF/RelocScan.h b/lld/ELF/RelocScan.h
index 561c70430e7b1..4135c15963b95 100644
--- a/lld/ELF/RelocScan.h
+++ b/lld/ELF/RelocScan.h
@@ -69,8 +69,6 @@ class RelocScan {
   // 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.
@@ -211,19 +209,6 @@ void RelocScan::scan(typename Relocs<RelTy>::const_iterator &it, RelType type,
     ctx.in.got->hasGotOffRel.store(true, std::memory_order_relaxed);
   }
 
-  // Process TLS relocations, including TLS optimizations. Note that
-  // R_TPREL and R_TPREL_NEG relocations are resolved in processAux.
-  //
-  // Some RISCV TLSDESC relocations reference a local NOTYPE symbol,
-  // but we need to process them in handleTlsRelocation.
-  if (sym.isTls() || oneof<R_TLSDESC_PC, R_TLSDESC_CALL>(expr)) {
-    if (unsigned processed =
-            handleTlsRelocation(expr, type, offset, sym, addend)) {
-      it += processed - 1;
-      return;
-    }
-  }
-
   process(expr, type, offset, sym, addend);
 }
 

diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index b71f20921e1e7..ee6b14f2798ed 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1123,106 +1123,6 @@ void RelocScan::processAux(RelExpr expr, RelType type, uint64_t offset,
   printLocation(diag, *sec, sym, offset);
 }
 
-// Notes about General Dynamic and Local Dynamic TLS models below. They may
-// require the generation of a pair of GOT entries that have associated dynamic
-// relocations. The pair of GOT entries created are of the form GOT[e0] Module
-// Index (Used to find pointer to TLS block at run-time) GOT[e1] Offset of
-// symbol in TLS block.
-//
-// Returns the number of relocations processed.
-unsigned RelocScan::handleTlsRelocation(RelExpr expr, RelType type,
-                                        uint64_t offset, Symbol &sym,
-                                        int64_t addend) {
-  if (expr == R_TPREL || expr == R_TPREL_NEG)
-    return checkTlsLe(offset, sym, type) ? 1 : 0;
-
-  if (oneof<R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC, R_TLSDESC_GOTPLT>(expr) &&
-      ctx.arg.shared) {
-    if (expr != R_TLSDESC_CALL) {
-      sym.setFlags(NEEDS_TLSDESC);
-      sec->addReloc({expr, type, offset, addend, &sym});
-    }
-    return 1;
-  }
-
-  bool execOptimize = !ctx.arg.shared;
-
-  // If we are producing an executable and the symbol is non-preemptable, it
-  // must be defined and the code sequence can be optimized to use Local-Exec.
-  //
-  // While some targets do not have TLS optimizations, we can omit the
-  // DTPMOD dynamic relocations and resolve them at link time because them
-  // are always 1. This may be necessary for static linking as DTPMOD may
-  // not be expected at load time.
-  bool isLocalInExecutable = !sym.isPreemptible && !ctx.arg.shared;
-
-  // Local Dynamic is for access to module local TLS variables, while still
-  // being suitable for being dynamically loaded via dlopen. GOT[e0] is the
-  // module index, with a special value of 0 for the current module. GOT[e1] is
-  // unused. There only needs to be one module index entry.
-  if (oneof<R_TLSLD_GOT, R_TLSLD_GOTPLT, R_TLSLD_PC, R_TLSLD_HINT>(expr)) {
-    // Local-Dynamic relocs can be optimized to Local-Exec.
-    if (execOptimize) {
-      sec->addReloc({ctx.target->adjustTlsExpr(type, R_RELAX_TLS_LD_TO_LE),
-                     type, offset, addend, &sym});
-      return ctx.target->getTlsGdRelaxSkip(type);
-    }
-    if (expr == R_TLSLD_HINT)
-      return 1;
-    ctx.needsTlsLd.store(true, std::memory_order_relaxed);
-    sec->addReloc({expr, type, offset, addend, &sym});
-    return 1;
-  }
-
-  // Local-Dynamic relocs can be optimized to Local-Exec.
-  if (expr == R_DTPREL) {
-    if (execOptimize)
-      expr = ctx.target->adjustTlsExpr(type, R_RELAX_TLS_LD_TO_LE);
-    sec->addReloc({expr, type, offset, addend, &sym});
-    return 1;
-  }
-
-  if (oneof<R_TLSDESC, R_TLSDESC_CALL, R_TLSDESC_PC, R_TLSDESC_GOTPLT,
-            R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC>(expr)) {
-    if (!execOptimize) {
-      sym.setFlags(NEEDS_TLSGD);
-      sec->addReloc({expr, type, offset, addend, &sym});
-      return 1;
-    }
-
-    // Global-Dynamic/TLSDESC can be optimized to Initial-Exec or Local-Exec
-    // depending on the symbol being locally defined or not.
-    if (sym.isPreemptible) {
-      sym.setFlags(NEEDS_TLSIE);
-      sec->addReloc({ctx.target->adjustTlsExpr(type, R_RELAX_TLS_GD_TO_IE),
-                     type, offset, addend, &sym});
-    } else {
-      sec->addReloc({ctx.target->adjustTlsExpr(type, R_RELAX_TLS_GD_TO_LE),
-                     type, offset, addend, &sym});
-    }
-    return ctx.target->getTlsGdRelaxSkip(type);
-  }
-
-  if (oneof<R_GOT, R_GOTPLT, R_GOT_PC, R_GOT_OFF, R_TLSIE_HINT>(expr)) {
-    // Initial-Exec relocs can be optimized to Local-Exec if the symbol is
-    // locally defined.
-    if (execOptimize && isLocalInExecutable) {
-      sec->addReloc({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym});
-    } else if (expr != R_TLSIE_HINT) {
-      sym.setFlags(NEEDS_TLSIE);
-      // R_GOT needs a relative relocation for PIC on Hexagon.
-      if (expr == R_GOT && ctx.arg.isPic &&
-          !ctx.target->usesOnlyLowPageBits(type))
-        addRelativeReloc<true>(ctx, *sec, offset, sym, addend, expr, type);
-      else
-        sec->addReloc({expr, type, offset, addend, &sym});
-    }
-    return 1;
-  }
-
-  return 0;
-}
-
 template <class ELFT, class RelTy>
 void TargetInfo::scanSectionImpl(InputSectionBase &sec, Relocs<RelTy> rels) {
   RelocScan rs(ctx, &sec);


        


More information about the llvm-commits mailing list