move production of .reference directives for static ctor/dtor list on

darwin into common code.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93849 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2010-01-19 04:34:02 +00:00
parent a756b1d914
commit 71eae71315
7 changed files with 23 additions and 29 deletions

View File

@ -36,7 +36,13 @@ namespace llvm {
/// HasMachoZeroFillDirective - True if this is a MachO target that supports /// HasMachoZeroFillDirective - True if this is a MachO target that supports
/// the macho-specific .zerofill directive for emitting BSS Symbols. /// the macho-specific .zerofill directive for emitting BSS Symbols.
bool HasMachoZeroFillDirective; // Default is false. bool HasMachoZeroFillDirective; // Default is false.
/// HasStaticCtorDtorReferenceInStaticMode - True if the compiler should
/// emit a ".reference .constructors_used" or ".reference .destructors_used"
/// directive after the a static ctor/dtor list. This directive is only
/// emitted in Static relocation model.
bool HasStaticCtorDtorReferenceInStaticMode; // Default is false.
/// NeedsSet - True if target asm treats expressions in data directives /// NeedsSet - True if target asm treats expressions in data directives
/// as linktime-relocatable. For assembly-time computation, we need to /// as linktime-relocatable. For assembly-time computation, we need to
@ -314,7 +320,9 @@ namespace llvm {
// Accessors. // Accessors.
// //
bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; } bool hasMachoZeroFillDirective() const { return HasMachoZeroFillDirective; }
bool hasStaticCtorDtorReferenceInStaticMode() const {
return HasStaticCtorDtorReferenceInStaticMode;
}
const char *getNonexecutableStackDirective() const { const char *getNonexecutableStackDirective() const {
return NonexecutableStackDirective; return NonexecutableStackDirective;
} }

View File

@ -449,6 +449,10 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection()); OutStreamer.SwitchSection(getObjFileLowering().getStaticCtorSection());
EmitAlignment(Align, 0); EmitAlignment(Align, 0);
EmitXXStructorList(GV->getInitializer()); EmitXXStructorList(GV->getInitializer());
if (TM.getRelocationModel() == Reloc::Static &&
MAI->hasStaticCtorDtorReferenceInStaticMode())
O << ".reference .constructors_used\n";
return true; return true;
} }
@ -456,6 +460,10 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection()); OutStreamer.SwitchSection(getObjFileLowering().getStaticDtorSection());
EmitAlignment(Align, 0); EmitAlignment(Align, 0);
EmitXXStructorList(GV->getInitializer()); EmitXXStructorList(GV->getInitializer());
if (TM.getRelocationModel() == Reloc::Static &&
MAI->hasStaticCtorDtorReferenceInStaticMode())
O << ".reference .destructors_used\n";
return true; return true;
} }

View File

@ -20,6 +20,7 @@ using namespace llvm;
MCAsmInfo::MCAsmInfo() { MCAsmInfo::MCAsmInfo() {
HasMachoZeroFillDirective = false; HasMachoZeroFillDirective = false;
HasStaticCtorDtorReferenceInStaticMode = false;
NonexecutableStackDirective = 0; NonexecutableStackDirective = 0;
NeedsSet = false; NeedsSet = false;
MaxInstLength = 4; MaxInstLength = 4;

View File

@ -36,6 +36,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
LCOMMDirective = "\t.lcomm\t"; LCOMMDirective = "\t.lcomm\t";
ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
HasMachoZeroFillDirective = true; // Uses .zerofill HasMachoZeroFillDirective = true; // Uses .zerofill
HasStaticCtorDtorReferenceInStaticMode = true;
SetDirective = "\t.set"; SetDirective = "\t.set";
ProtectedDirective = "\t.globl\t"; ProtectedDirective = "\t.globl\t";
HasDotTypeDotSizeDirective = false; HasDotTypeDotSizeDirective = false;

View File

@ -1171,17 +1171,8 @@ void ARMAsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
return; return;
// Check to see if this is a special global used by LLVM, if so, emit it. // Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar))
if (EmitSpecialLLVMGlobal(GVar)) {
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::Static) {
if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return; return;
}
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar); MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);

View File

@ -933,15 +933,8 @@ void PPCDarwinAsmPrinter::PrintGlobalVariable(const GlobalVariable *GVar) {
return; // External global require no code return; // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it. // Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar)) { if (EmitSpecialLLVMGlobal(GVar))
if (TM.getRelocationModel() == Reloc::Static) {
if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return; return;
}
MCSymbol *GVarSym = GetGlobalValueSymbol(GVar); MCSymbol *GVarSym = GetGlobalValueSymbol(GVar);
printVisibility(GVarSym, GVar->getVisibility()); printVisibility(GVarSym, GVar->getVisibility());

View File

@ -651,16 +651,8 @@ void X86AsmPrinter::PrintGlobalVariable(const GlobalVariable* GVar) {
return; // External global require no code return; // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it. // Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar)) { if (EmitSpecialLLVMGlobal(GVar))
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::Static) {
if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return; return;
}
const TargetData *TD = TM.getTargetData(); const TargetData *TD = TM.getTargetData();