[llvm] 0a0f691 - [Hexagon] Move STT_TLS setting from fixELFSymbolsInTLSFixups to getRelocType

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 22 20:00:58 PDT 2025


Author: Fangrui Song
Date: 2025-03-22T20:00:52-07:00
New Revision: 0a0f691af6468372d2f5d31b83317fcc263e89d4

URL: https://github.com/llvm/llvm-project/commit/0a0f691af6468372d2f5d31b83317fcc263e89d4
DIFF: https://github.com/llvm/llvm-project/commit/0a0f691af6468372d2f5d31b83317fcc263e89d4.diff

LOG: [Hexagon] Move STT_TLS setting from fixELFSymbolsInTLSFixups to getRelocType

The legacy generic code uses `ELFObjectWriter::fixSymbolsInTLSFixups` to
set `STT_TLS` (and use an unnecessary expression walk). The better way
is to do this in `getRelocType`, which I have done for AArch64, PowerPC,
RISC-V, and X86.

Added: 
    

Modified: 
    llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
    llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp
    llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
index 84fb0b8db5101..b9e0ea5960f31 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonELFObjectWriter.cpp
@@ -43,6 +43,20 @@ unsigned HexagonELFObjectWriter::getRelocType(MCContext &Ctx,
                                               MCFixup const &Fixup,
                                               bool IsPCRel) const {
   auto Variant = HexagonMCExpr::VariantKind(Target.getAccessVariant());
+  switch (Variant) {
+  case HexagonMCExpr::VK_GD_GOT:
+  case HexagonMCExpr::VK_LD_GOT:
+  case HexagonMCExpr::VK_GD_PLT:
+  case HexagonMCExpr::VK_LD_PLT:
+  case HexagonMCExpr::VK_IE:
+  case HexagonMCExpr::VK_IE_GOT:
+  case HexagonMCExpr::VK_TPREL:
+    if (auto *S = Target.getSymA())
+      cast<MCSymbolELF>(S->getSymbol()).setType(ELF::STT_TLS);
+    break;
+  default:
+    break;
+  }
   switch (Fixup.getTargetKind()) {
   default:
     report_fatal_error("Unrecognized relocation type");

diff  --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp
index f02aece2c585e..e764e53e0c9e4 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.cpp
@@ -37,48 +37,6 @@ MCFragment *llvm::HexagonMCExpr::findAssociatedFragment() const {
   return Expr->findAssociatedFragment();
 }
 
-static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
-  switch (Expr->getKind()) {
-  case MCExpr::Target:
-    llvm_unreachable("Cannot handle nested target MCExpr");
-    break;
-  case MCExpr::Constant:
-    break;
-
-  case MCExpr::Binary: {
-    const MCBinaryExpr *be = cast<MCBinaryExpr>(Expr);
-    fixELFSymbolsInTLSFixupsImpl(be->getLHS(), Asm);
-    fixELFSymbolsInTLSFixupsImpl(be->getRHS(), Asm);
-    break;
-  }
-  case MCExpr::SymbolRef: {
-    const MCSymbolRefExpr &symRef = *cast<MCSymbolRefExpr>(Expr);
-    switch (getVariantKind(&symRef)) {
-    default:
-      return;
-    case HexagonMCExpr::VK_GD_GOT:
-    case HexagonMCExpr::VK_LD_GOT:
-    case HexagonMCExpr::VK_GD_PLT:
-    case HexagonMCExpr::VK_LD_PLT:
-    case HexagonMCExpr::VK_IE:
-    case HexagonMCExpr::VK_IE_GOT:
-    case HexagonMCExpr::VK_TPREL:
-      break;
-    }
-    cast<MCSymbolELF>(symRef.getSymbol()).setType(ELF::STT_TLS);
-    break;
-  }
-  case MCExpr::Unary:
-    fixELFSymbolsInTLSFixupsImpl(cast<MCUnaryExpr>(Expr)->getSubExpr(), Asm);
-    break;
-  }
-}
-
-void HexagonMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
-  auto expr = getExpr();
-  fixELFSymbolsInTLSFixupsImpl(expr, Asm);
-}
-
 MCExpr const *HexagonMCExpr::getExpr() const { return Expr; }
 
 void HexagonMCExpr::setMustExtend(bool Val) {

diff  --git a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h
index 07404859f36f4..b22960efc372b 100644
--- a/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h
+++ b/llvm/lib/Target/Hexagon/MCTargetDesc/HexagonMCExpr.h
@@ -41,7 +41,6 @@ class HexagonMCExpr : public MCTargetExpr {
                                  const MCAssembler *Asm) const override;
   void visitUsedExpr(MCStreamer &Streamer) const override;
   MCFragment *findAssociatedFragment() const override;
-  void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
   MCExpr const *getExpr() const;
   void setMustExtend(bool Val = true);
   bool mustExtend() const;


        


More information about the llvm-commits mailing list