aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2005-12-09 18:24:29 +0000
committerChris Lattner <sabre@nondot.org>2005-12-09 18:24:29 +0000
commit646f7afb797630020f02c6f552c6c5c8d7e73ad6 (patch)
treef19b63d893f5e9826f122840a60bd6dd5b9915f5
parent5e3c5b4e13d45d631cddf42176b380f64fde918f (diff)
Teach the PPC backend about the ctor and dtor list when not using __main and
linking the entire program into one bc file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24645 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/PowerPC/PPCAsmPrinter.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp
index e8613f1867..66f72a77f7 100644
--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp
+++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp
@@ -202,6 +202,8 @@ public:
virtual const char *getPassName() const {
return "Darwin PPC Assembly Printer";
}
+
+ void EmitXXStructorList(Constant *List);
bool runOnMachineFunction(MachineFunction &F);
bool doInitialization(Module &M);
@@ -412,6 +414,21 @@ bool DarwinAsmPrinter::doInitialization(Module &M) {
return false;
}
+/// EmitXXStructorList - Emit the ctor or dtor list. On darwin, this just
+/// prints out the function pointers.
+void DarwinAsmPrinter::EmitXXStructorList(Constant *List) {
+ // Should be an array of '{ int, void ()* }' structs. The first value is the
+ // init priority, which we ignore.
+ if (!isa<ConstantArray>(List)) return;
+ ConstantArray *InitList = cast<ConstantArray>(List);
+ for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
+ if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
+ if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
+ // Emit the function pointer.
+ EmitGlobalConstant(CS->getOperand(1));
+ }
+}
+
bool DarwinAsmPrinter::doFinalization(Module &M) {
const TargetData &TD = TM.getTargetData();
@@ -419,6 +436,23 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I)
if (I->hasInitializer()) { // External global require no code
+ // Check to see if this is a special global used by LLVM.
+ if (I->hasAppendingLinkage()) {
+ if (I->getName() == "llvm.used")
+ continue; // No need to emit this at all.
+ if (I->getName() == "llvm.global_ctors") {
+ SwitchSection(".mod_init_func", 0);
+ EmitAlignment(2, 0);
+ EmitXXStructorList(I->getInitializer());
+ continue;
+ } else if (I->getName() == "llvm.global_dtors") {
+ SwitchSection(".mod_term_func", 0);
+ EmitAlignment(2, 0);
+ EmitXXStructorList(I->getInitializer());
+ continue;
+ }
+ }
+
O << '\n';
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();