sparc64-add-missing-tls-get-addr
authorLLVM Packaging Team <pkg-llvm-team@lists.alioth.debian.org>
Wed, 27 Jun 2018 14:24:20 +0000 (15:24 +0100)
committerGianfranco Costamagna <locutusofborg@debian.org>
Wed, 27 Jun 2018 14:24:20 +0000 (15:24 +0100)
Gbp-Pq: Name sparc64-add-missing-tls-get-addr.diff

lib/Target/Sparc/MCTargetDesc/SparcMCExpr.cpp

index a77f760d9eff06a9c0e00016c858b1faaa521a1c..7bc5c8b7b439e0c135d720b2960374b75234cf2c 100644 (file)
@@ -193,14 +193,30 @@ static void fixELFSymbolsInTLSFixupsImpl(const MCExpr *Expr, MCAssembler &Asm) {
 void SparcMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
   switch(getKind()) {
   default: return;
+  case VK_Sparc_TLS_GD_CALL:
+  case VK_Sparc_TLS_LDM_CALL: {
+    // The corresponding relocations reference __tls_get_addr, as they call it,
+    // but this is only implicit; there is no connection in the ELF file
+    // between the relocation and the symbol, other than the specification for
+    // the semantics of the relocations. However, the symbol must be included
+    // in our symbol table despite the lack of references to it, since it needs
+    // to be bound during linking for these relocations. For details see
+    // https://sourceware.org/bugzilla/show_bug.cgi?id=22832.
+    MCSymbol *Symbol = Asm.getContext().getOrCreateSymbol("__tls_get_addr");
+    Asm.registerSymbol(*Symbol);
+    auto ELFSymbol = cast<MCSymbolELF>(Symbol);
+    if (!ELFSymbol->isBindingSet()) {
+      ELFSymbol->setBinding(ELF::STB_GLOBAL);
+      ELFSymbol->setExternal(true);
+    }
+    LLVM_FALLTHROUGH;
+  }
   case VK_Sparc_TLS_GD_HI22:
   case VK_Sparc_TLS_GD_LO10:
   case VK_Sparc_TLS_GD_ADD:
-  case VK_Sparc_TLS_GD_CALL:
   case VK_Sparc_TLS_LDM_HI22:
   case VK_Sparc_TLS_LDM_LO10:
   case VK_Sparc_TLS_LDM_ADD:
-  case VK_Sparc_TLS_LDM_CALL:
   case VK_Sparc_TLS_LDO_HIX22:
   case VK_Sparc_TLS_LDO_LOX10:
   case VK_Sparc_TLS_LDO_ADD: