1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

mcstreamerize .no_dead_strip and .reference for static ctors/dtors.

llvm-svn: 94290
This commit is contained in:
Chris Lattner 2010-01-23 05:51:36 +00:00
parent e5e7b41090
commit 62d08f5577
7 changed files with 35 additions and 36 deletions

View File

@ -209,10 +209,9 @@ namespace llvm {
/// .file directive, this is true for ELF targets. /// .file directive, this is true for ELF targets.
bool HasSingleParameterDotFile; // Defaults to true. bool HasSingleParameterDotFile; // Defaults to true.
/// UsedDirective - This directive, if non-null, is used to declare a global /// HasNoDeadStrip - True if this target supports the MachO .no_dead_strip
/// as being used somehow that the assembler can't see. This prevents dead /// directive.
/// code elimination on some targets. bool HasNoDeadStrip; // Defaults to false.
const char *UsedDirective; // Defaults to NULL.
/// WeakRefDirective - This directive, if non-null, is used to declare a /// WeakRefDirective - This directive, if non-null, is used to declare a
/// global as being a weak undefined symbol. /// global as being a weak undefined symbol.
@ -410,15 +409,9 @@ namespace llvm {
bool getCOMMDirectiveTakesAlignment() const { bool getCOMMDirectiveTakesAlignment() const {
return COMMDirectiveTakesAlignment; return COMMDirectiveTakesAlignment;
} }
bool hasDotTypeDotSizeDirective() const { bool hasDotTypeDotSizeDirective() const {return HasDotTypeDotSizeDirective;}
return HasDotTypeDotSizeDirective; bool hasSingleParameterDotFile() const { return HasSingleParameterDotFile; }
} bool hasNoDeadStrip() const { return HasNoDeadStrip; }
bool hasSingleParameterDotFile() const {
return HasSingleParameterDotFile;
}
const char *getUsedDirective() const {
return UsedDirective;
}
const char *getWeakRefDirective() const { return WeakRefDirective; } const char *getWeakRefDirective() const { return WeakRefDirective; }
const char *getWeakDefDirective() const { return WeakDefDirective; } const char *getWeakDefDirective() const { return WeakDefDirective; }
const char *getLinkOnceDirective() const { return LinkOnceDirective; } const char *getLinkOnceDirective() const { return LinkOnceDirective; }

View File

@ -313,7 +313,7 @@ bool AsmPrinter::doFinalization(Module &M) {
} }
if (MAI->getSetDirective()) { if (MAI->getSetDirective()) {
O << '\n'; OutStreamer.AddBlankLine();
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end(); for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
I != E; ++I) { I != E; ++I) {
MCSymbol *Name = GetGlobalValueSymbol(I); MCSymbol *Name = GetGlobalValueSymbol(I);
@ -563,7 +563,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
} else { } else {
O << *GetMBBSymbol(MBB->getNumber()); O << *GetMBBSymbol(MBB->getNumber());
// If the arch uses custom Jump Table directives, don't calc relative to // If the arch uses custom Jump Table directives, don't calc relative to
// JT // JT.
if (!HadJTEntryDirective) if (!HadJTEntryDirective)
O << '-' << *GetJTISymbol(uid); O << '-' << *GetJTISymbol(uid);
} }
@ -575,7 +575,7 @@ void AsmPrinter::printPICJumpTableEntry(const MachineJumpTableInfo *MJTI,
/// do nothing and return false. /// do nothing and return false.
bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) { bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
if (GV->getName() == "llvm.used") { if (GV->getName() == "llvm.used") {
if (MAI->getUsedDirective() != 0) // No need to emit this at all. if (MAI->hasNoDeadStrip()) // No need to emit this at all.
EmitLLVMUsedList(GV->getInitializer()); EmitLLVMUsedList(GV->getInitializer());
return true; return true;
} }
@ -597,8 +597,11 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
EmitXXStructorList(GV->getInitializer()); EmitXXStructorList(GV->getInitializer());
if (TM.getRelocationModel() == Reloc::Static && if (TM.getRelocationModel() == Reloc::Static &&
MAI->hasStaticCtorDtorReferenceInStaticMode()) MAI->hasStaticCtorDtorReferenceInStaticMode()) {
O << ".reference .constructors_used\n"; StringRef Sym(".constructors_used");
OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
MCStreamer::Reference);
}
return true; return true;
} }
@ -608,8 +611,11 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
EmitXXStructorList(GV->getInitializer()); EmitXXStructorList(GV->getInitializer());
if (TM.getRelocationModel() == Reloc::Static && if (TM.getRelocationModel() == Reloc::Static &&
MAI->hasStaticCtorDtorReferenceInStaticMode()) MAI->hasStaticCtorDtorReferenceInStaticMode()) {
O << ".reference .destructors_used\n"; StringRef Sym(".destructors_used");
OutStreamer.EmitSymbolAttribute(OutContext.GetOrCreateSymbol(Sym),
MCStreamer::Reference);
}
return true; return true;
} }
@ -620,8 +626,6 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
/// global in the specified llvm.used list for which emitUsedDirectiveFor /// global in the specified llvm.used list for which emitUsedDirectiveFor
/// is true, as being used with this directive. /// is true, as being used with this directive.
void AsmPrinter::EmitLLVMUsedList(Constant *List) { void AsmPrinter::EmitLLVMUsedList(Constant *List) {
const char *Directive = MAI->getUsedDirective();
// Should be an array of 'i8*'. // Should be an array of 'i8*'.
ConstantArray *InitList = dyn_cast<ConstantArray>(List); ConstantArray *InitList = dyn_cast<ConstantArray>(List);
if (InitList == 0) return; if (InitList == 0) return;
@ -629,11 +633,9 @@ void AsmPrinter::EmitLLVMUsedList(Constant *List) {
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) { for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
const GlobalValue *GV = const GlobalValue *GV =
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts()); dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang)) { if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, Mang))
O << Directive; OutStreamer.EmitSymbolAttribute(GetGlobalValueSymbol(GV),
EmitConstantValueOnly(InitList->getOperand(i)); MCStreamer::NoDeadStrip);
O << '\n';
}
} }
} }
@ -1584,6 +1586,7 @@ void AsmPrinter::EmitBasicBlockStart(const MachineBasicBlock *MBB) const {
// Print the main label for the block. // Print the main label for the block.
if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) { if (MBB->pred_empty() || MBB->isOnlyReachableByFallthrough()) {
if (VerboseAsm) { if (VerboseAsm) {
// NOTE: Want this comment at start of line.
O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':'; O << MAI->getCommentString() << " BB#" << MBB->getNumber() << ':';
if (const BasicBlock *BB = MBB->getBasicBlock()) if (const BasicBlock *BB = MBB->getBasicBlock())
if (BB->hasName()) if (BB->hasName())

View File

@ -245,8 +245,9 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) {
// This name has no connection to the function, so it might get // This name has no connection to the function, so it might get
// dead-stripped when the function is not, erroneously. Prohibit // dead-stripped when the function is not, erroneously. Prohibit
// dead-stripping unconditionally. // dead-stripping unconditionally.
if (const char *UsedDirective = MAI->getUsedDirective()) if (MAI->hasNoDeadStrip())
O << UsedDirective << *EHFrameInfo.FunctionEHSym << "\n\n"; Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym,
MCStreamer::NoDeadStrip);
} else { } else {
O << *EHFrameInfo.FunctionEHSym << ":\n"; O << *EHFrameInfo.FunctionEHSym << ":\n";
@ -313,8 +314,9 @@ void DwarfException::EmitFDE(const FunctionEHFrameInfo &EHFrameInfo) {
// on unused functions (calling undefined externals) being dead-stripped to // on unused functions (calling undefined externals) being dead-stripped to
// link correctly. Yes, there really is. // link correctly. Yes, there really is.
if (MMI->isUsedFunction(EHFrameInfo.function)) if (MMI->isUsedFunction(EHFrameInfo.function))
if (const char *UsedDirective = MAI->getUsedDirective()) if (MAI->hasNoDeadStrip())
O << UsedDirective << *EHFrameInfo.FunctionEHSym << "\n\n"; Asm->OutStreamer.EmitSymbolAttribute(EHFrameInfo.FunctionEHSym,
MCStreamer::NoDeadStrip);
} }
Asm->O << '\n'; Asm->O << '\n';
} }
@ -982,7 +984,7 @@ void DwarfException::EndFunction() {
EmitLabel("eh_func_end", SubprogramCount); EmitLabel("eh_func_end", SubprogramCount);
EmitExceptionTable(); EmitExceptionTable();
const MCSymbol *FunctionEHSym = MCSymbol *FunctionEHSym =
Asm->GetSymbolWithGlobalValueBase(MF->getFunction(), ".eh", Asm->GetSymbolWithGlobalValueBase(MF->getFunction(), ".eh",
Asm->MAI->is_EHSymbolPrivate()); Asm->MAI->is_EHSymbolPrivate());

View File

@ -34,7 +34,7 @@ class raw_ostream;
/// ///
class DwarfException : public DwarfPrinter { class DwarfException : public DwarfPrinter {
struct FunctionEHFrameInfo { struct FunctionEHFrameInfo {
const MCSymbol *FunctionEHSym; // L_foo.eh MCSymbol *FunctionEHSym; // L_foo.eh
unsigned Number; unsigned Number;
unsigned PersonalityIndex; unsigned PersonalityIndex;
bool hasCalls; bool hasCalls;
@ -42,7 +42,7 @@ class DwarfException : public DwarfPrinter {
std::vector<MachineMove> Moves; std::vector<MachineMove> Moves;
const Function *function; const Function *function;
FunctionEHFrameInfo(const MCSymbol *EHSym, unsigned Num, unsigned P, FunctionEHFrameInfo(MCSymbol *EHSym, unsigned Num, unsigned P,
bool hC, bool hL, bool hC, bool hL,
const std::vector<MachineMove> &M, const std::vector<MachineMove> &M,
const Function *f): const Function *f):

View File

@ -57,7 +57,7 @@ MCAsmInfo::MCAsmInfo() {
COMMDirectiveTakesAlignment = true; COMMDirectiveTakesAlignment = true;
HasDotTypeDotSizeDirective = true; HasDotTypeDotSizeDirective = true;
HasSingleParameterDotFile = true; HasSingleParameterDotFile = true;
UsedDirective = 0; HasNoDeadStrip = false;
WeakRefDirective = 0; WeakRefDirective = 0;
WeakDefDirective = 0; WeakDefDirective = 0;
LinkOnceDirective = 0; LinkOnceDirective = 0;

View File

@ -39,7 +39,7 @@ MCAsmInfoDarwin::MCAsmInfoDarwin() {
SetDirective = "\t.set"; SetDirective = "\t.set";
ProtectedDirective = "\t.globl\t"; ProtectedDirective = "\t.globl\t";
HasDotTypeDotSizeDirective = false; HasDotTypeDotSizeDirective = false;
UsedDirective = "\t.no_dead_strip\t"; HasNoDeadStrip = true;
// Note: Even though darwin has the .lcomm directive, it is just a synonym for // Note: Even though darwin has the .lcomm directive, it is just a synonym for
// zerofill, so we prefer to use .zerofill. // zerofill, so we prefer to use .zerofill.

View File

@ -234,6 +234,7 @@ void MCMachOStreamer::EmitSymbolAttribute(MCSymbol *Symbol,
case MCStreamer::Internal: case MCStreamer::Internal:
case MCStreamer::Protected: case MCStreamer::Protected:
case MCStreamer::Weak: case MCStreamer::Weak:
case MCStreamer::Local:
assert(0 && "Invalid symbol attribute for Mach-O!"); assert(0 && "Invalid symbol attribute for Mach-O!");
break; break;