[llvm] r180737 - Emit the TLS initialization function pointers into the correct section.

Bill Wendling isanbard at gmail.com
Mon Apr 29 15:25:40 PDT 2013


Author: void
Date: Mon Apr 29 17:25:40 2013
New Revision: 180737

URL: http://llvm.org/viewvc/llvm-project?rev=180737&view=rev
Log:
Emit the TLS initialization function pointers into the correct section.

The `llvm.tls_init_funcs' (created by the front-end) holds pointers to the TLS
initialization functions. These need to be placed into the correct section so
that they are run before `main()'.

<rdar://problem/13733006>

Modified:
    llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Modified: llvm/trunk/include/llvm/CodeGen/AsmPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/AsmPrinter.h?rev=180737&r1=180736&r2=180737&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/AsmPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/AsmPrinter.h Mon Apr 29 17:25:40 2013
@@ -486,6 +486,7 @@ namespace llvm {
                             unsigned uid) const;
     void EmitLLVMUsedList(const ConstantArray *InitList);
     void EmitXXStructorList(const Constant *List, bool isCtor);
+    void EmitTLSInitFuncs(const ConstantArray *InitList);
     GCMetadataPrinter *GetOrCreateGCPrinter(GCStrategy *C);
   };
 }

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=180737&r1=180736&r2=180737&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Mon Apr 29 17:25:40 2013
@@ -1254,6 +1254,11 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(c
     return true;
   }
 
+  if (GV->getName() == "llvm.tls_init_funcs") {
+    EmitTLSInitFuncs(cast<ConstantArray>(GV->getInitializer()));
+    return true;
+  }
+
   return false;
 }
 
@@ -1320,6 +1325,16 @@ void AsmPrinter::EmitXXStructorList(cons
   }
 }
 
+/// EmitTLSInitFuncs - Emit the TLS initialization functions.
+void AsmPrinter::EmitTLSInitFuncs(const ConstantArray *InitList) {
+  const DataLayout *TD = TM.getDataLayout();
+  OutStreamer.SwitchSection(getObjFileLowering().getTLSThreadInitSection());
+  EmitAlignment(Log2_32(TD->getPointerPrefAlignment()));
+  for (unsigned I = 0, E = InitList->getNumOperands(); I != E; ++I)
+    EmitGlobalConstant(
+      dyn_cast<Constant>(InitList->getOperand(I)->stripPointerCasts()));
+}
+
 //===--------------------------------------------------------------------===//
 // Emission and print routines
 //





More information about the llvm-commits mailing list