diff options
author | Chris Lattner <sabre@nondot.org> | 2005-12-13 04:53:51 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-12-13 04:53:51 +0000 |
commit | a046e0d79f9f4011b6ebcb02e3b038a9601bf7fc (patch) | |
tree | 88fc7ae326b547e383cce2c90f33b9b1f6a61a8c /lib/Target/X86 | |
parent | deea416570f31a82081f1bbbc65f0c06d44462bf (diff) | |
download | external_llvm-a046e0d79f9f4011b6ebcb02e3b038a9601bf7fc.zip external_llvm-a046e0d79f9f4011b6ebcb02e3b038a9601bf7fc.tar.gz external_llvm-a046e0d79f9f4011b6ebcb02e3b038a9601bf7fc.tar.bz2 |
Add ELF and darwin support for static ctors and dtors
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24693 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/X86')
-rw-r--r-- | lib/Target/X86/X86AsmPrinter.cpp | 39 | ||||
-rwxr-xr-x | lib/Target/X86/X86AsmPrinter.h | 1 |
2 files changed, 40 insertions, 0 deletions
diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 85cc3c2..13c136f 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -18,6 +18,7 @@ #include "X86IntelAsmPrinter.h" #include "X86Subtarget.h" #include "X86.h" +#include "llvm/Constants.h" #include "llvm/Module.h" #include "llvm/Type.h" #include "llvm/Assembly/Writer.h" @@ -73,6 +74,21 @@ bool X86SharedAsmPrinter::doInitialization(Module &M) { return AsmPrinter::doInitialization(M); } +/// EmitXXStructorList - Emit the ctor or dtor list. On darwin, this just +/// prints out the function pointers. +void X86SharedAsmPrinter::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 X86SharedAsmPrinter::doFinalization(Module &M) { const TargetData &TD = TM.getTargetData(); @@ -81,6 +97,29 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { E = M.global_end(); I != E; ++I) { if (!I->hasInitializer()) continue; // 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") { + if (forDarwin) + SwitchSection(".mod_init_func", 0); + else + SwitchSection(".ctors,\"aw\",@progbits", 0); + EmitAlignment(2, 0); + EmitXXStructorList(I->getInitializer()); + continue; + } else if (I->getName() == "llvm.global_dtors") { + if (forDarwin) + SwitchSection(".mod_term_func", 0); + else + SwitchSection(".dtors,\"aw\",@progbits", 0); + EmitAlignment(2, 0); + EmitXXStructorList(I->getInitializer()); + continue; + } + } + O << "\n\n"; std::string name = Mang->getValueName(I); Constant *C = I->getInitializer(); diff --git a/lib/Target/X86/X86AsmPrinter.h b/lib/Target/X86/X86AsmPrinter.h index 3267d4e..a2e5f2f 100755 --- a/lib/Target/X86/X86AsmPrinter.h +++ b/lib/Target/X86/X86AsmPrinter.h @@ -33,6 +33,7 @@ struct X86SharedAsmPrinter : public AsmPrinter { bool doInitialization(Module &M); bool doFinalization(Module &M); + void EmitXXStructorList(Constant *List); bool forDarwin; // FIXME: eliminate. |