[llvm-commits] CVS: llvm/lib/Target/X86/X86AsmPrinter.cpp X86AsmPrinter.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Dec 12 20:54:03 PST 2005
Changes in directory llvm/lib/Target/X86:
X86AsmPrinter.cpp updated: 1.157 -> 1.158
X86AsmPrinter.h updated: 1.8 -> 1.9
---
Log message:
Add ELF and darwin support for static ctors and dtors
---
Diffs of the changes: (+40 -0)
X86AsmPrinter.cpp | 39 +++++++++++++++++++++++++++++++++++++++
X86AsmPrinter.h | 1 +
2 files changed, 40 insertions(+)
Index: llvm/lib/Target/X86/X86AsmPrinter.cpp
diff -u llvm/lib/Target/X86/X86AsmPrinter.cpp:1.157 llvm/lib/Target/X86/X86AsmPrinter.cpp:1.158
--- llvm/lib/Target/X86/X86AsmPrinter.cpp:1.157 Mon Nov 21 17:06:54 2005
+++ llvm/lib/Target/X86/X86AsmPrinter.cpp Mon Dec 12 22:53:51 2005
@@ -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 @@
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 @@
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\", at 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\", at progbits", 0);
+ EmitAlignment(2, 0);
+ EmitXXStructorList(I->getInitializer());
+ continue;
+ }
+ }
+
O << "\n\n";
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();
Index: llvm/lib/Target/X86/X86AsmPrinter.h
diff -u llvm/lib/Target/X86/X86AsmPrinter.h:1.8 llvm/lib/Target/X86/X86AsmPrinter.h:1.9
--- llvm/lib/Target/X86/X86AsmPrinter.h:1.8 Mon Nov 21 17:06:54 2005
+++ llvm/lib/Target/X86/X86AsmPrinter.h Mon Dec 12 22:53:51 2005
@@ -33,6 +33,7 @@
bool doInitialization(Module &M);
bool doFinalization(Module &M);
+ void EmitXXStructorList(Constant *List);
bool forDarwin; // FIXME: eliminate.
More information about the llvm-commits
mailing list