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
This commit is contained in:
Chris Lattner 2005-12-09 18:24:29 +00:00
parent 5e3c5b4e13
commit 646f7afb79

View File

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