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>


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@180737 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2013-04-29 22:25:40 +00:00
parent 59a0e79631
commit fa2eac54e6
2 changed files with 16 additions and 0 deletions

View File

@ -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);
};
}

View File

@ -1254,6 +1254,11 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
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(const Constant *List, bool isCtor) {
}
}
/// 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
//