Fix .eh table linkage issues on Darwin. Some EH support

for Darwin PPC, but it's not fully working yet.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44258 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen
2007-11-20 23:24:42 +00:00
parent 99ba1f7b8d
commit 1d4ce2ab96
7 changed files with 44 additions and 13 deletions

View File

@@ -2764,12 +2764,15 @@ private:
bool hasCalls; bool hasCalls;
bool hasLandingPads; bool hasLandingPads;
std::vector<MachineMove> Moves; std::vector<MachineMove> Moves;
Function::LinkageTypes linkage;
FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P, FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P,
bool hC, bool hL, bool hC, bool hL,
const std::vector<MachineMove> &M): const std::vector<MachineMove> &M,
Function::LinkageTypes l):
FnName(FN), Number(Num), PersonalityIndex(P), FnName(FN), Number(Num), PersonalityIndex(P),
hasCalls(hC), hasLandingPads(hL), Moves(M) { } hasCalls(hC), hasLandingPads(hL), Moves(M),
linkage(l) { }
}; };
std::vector<FunctionEHFrameInfo> EHFrames; std::vector<FunctionEHFrameInfo> EHFrames;
@@ -2867,15 +2870,25 @@ private:
Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection()); Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
// Externally visible entry into the functions eh frame info. // Externally visible entry into the functions eh frame info.
if (const char *GlobalDirective = TAI->getGlobalDirective()) // If the corresponding function is static, this should not be
O << GlobalDirective << EHFrameInfo.FnName << "\n"; // externally visible.
if (EHFrameInfo.linkage != Function::InternalLinkage) {
if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
}
// If there are no calls then you can't unwind. // If there are no calls then you can't unwind.
if (!EHFrameInfo.hasCalls) { if (!EHFrameInfo.hasCalls) {
O << EHFrameInfo.FnName << " = 0\n"; O << EHFrameInfo.FnName << " = 0\n";
} else { } else {
O << EHFrameInfo.FnName << ":\n"; O << EHFrameInfo.FnName << ":\n";
// If corresponding function is weak definition, this should be too.
if ((EHFrameInfo.linkage == Function::WeakLinkage ||
EHFrameInfo.linkage == Function::LinkOnceLinkage) &&
TAI->getWeakDefDirective())
O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
// EH frame header. // EH frame header.
EmitDifference("eh_frame_end", EHFrameInfo.Number, EmitDifference("eh_frame_end", EHFrameInfo.Number,
"eh_frame_begin", EHFrameInfo.Number, true); "eh_frame_begin", EHFrameInfo.Number, true);
@@ -3362,7 +3375,8 @@ public:
MMI->getPersonalityIndex(), MMI->getPersonalityIndex(),
MF->getFrameInfo()->hasCalls(), MF->getFrameInfo()->hasCalls(),
!MMI->getLandingPads().empty(), !MMI->getLandingPads().empty(),
MMI->getFrameMoves())); MMI->getFrameMoves(),
MF->getFunction()->getLinkage()));
} }
}; };

View File

@@ -322,10 +322,11 @@ namespace {
struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter { struct VISIBILITY_HIDDEN DarwinAsmPrinter : public PPCAsmPrinter {
DwarfWriter DW; DwarfWriter DW;
MachineModuleInfo *MMI;
DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM, DarwinAsmPrinter(std::ostream &O, PPCTargetMachine &TM,
const TargetAsmInfo *T) const TargetAsmInfo *T)
: PPCAsmPrinter(O, TM, T), DW(O, this, T) { : PPCAsmPrinter(O, TM, T), DW(O, this, T), MMI(0) {
} }
virtual const char *getPassName() const { virtual const char *getPassName() const {
@@ -774,11 +775,13 @@ std::string DarwinAsmPrinter::getSectionForFunction(const Function &F) const {
/// method to print assembly for each instruction. /// method to print assembly for each instruction.
/// ///
bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) { bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
DW.SetModuleInfo(&getAnalysis<MachineModuleInfo>()); // We need this for Personality functions.
MMI = &getAnalysis<MachineModuleInfo>();
DW.SetModuleInfo(MMI);
SetupMachineFunction(MF); SetupMachineFunction(MF);
O << "\n\n"; O << "\n\n";
// Print out constants referenced by the function // Print out constants referenced by the function
EmitConstantPool(MF.getConstantPool()); EmitConstantPool(MF.getConstantPool());
@@ -1054,6 +1057,15 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
O << "\n"; O << "\n";
if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) {
// Add the (possibly multiple) personalities to the set of global values.
const std::vector<Function *>& Personalities = MMI->getPersonalities();
for (std::vector<Function *>::const_iterator I = Personalities.begin(),
E = Personalities.end(); I != E; ++I)
if (*I) GVStubs.insert("_" + (*I)->getName());
}
// Output stubs for external and common global variables. // Output stubs for external and common global variables.
if (!GVStubs.empty()) { if (!GVStubs.empty()) {
SwitchToDataSection(".non_lazy_symbol_pointer"); SwitchToDataSection(".non_lazy_symbol_pointer");

View File

@@ -43,7 +43,6 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM)
PrivateGlobalPrefix = "L"; PrivateGlobalPrefix = "L";
ConstantPoolSection = "\t.const\t"; ConstantPoolSection = "\t.const\t";
JumpTableDataSection = ".const"; JumpTableDataSection = ".const";
GlobalDirective = "\t.globl\t";
CStringSection = "\t.cstring"; CStringSection = "\t.cstring";
FourByteConstantSection = "\t.literal4\n"; FourByteConstantSection = "\t.literal4\n";
EightByteConstantSection = "\t.literal8\n"; EightByteConstantSection = "\t.literal8\n";
@@ -56,6 +55,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM)
StaticDtorsSection = ".mod_term_func"; StaticDtorsSection = ".mod_term_func";
} }
UsedDirective = "\t.no_dead_strip\t"; UsedDirective = "\t.no_dead_strip\t";
WeakDefDirective = "\t.weak_definition\t";
WeakRefDirective = "\t.weak_reference\t"; WeakRefDirective = "\t.weak_reference\t";
HiddenDirective = "\t.private_extern\t"; HiddenDirective = "\t.private_extern\t";
SupportsExceptionHandling = false; SupportsExceptionHandling = false;
@@ -66,6 +66,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM)
DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
GlobalEHDirective = "\t.globl\t";
DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";

View File

@@ -75,6 +75,7 @@ TargetAsmInfo::TargetAsmInfo() :
HasDotTypeDotSizeDirective(true), HasDotTypeDotSizeDirective(true),
UsedDirective(0), UsedDirective(0),
WeakRefDirective(0), WeakRefDirective(0),
WeakDefDirective(0),
HiddenDirective("\t.hidden\t"), HiddenDirective("\t.hidden\t"),
ProtectedDirective("\t.protected\t"), ProtectedDirective("\t.protected\t"),
AbsoluteDebugSectionOffsets(false), AbsoluteDebugSectionOffsets(false),
@@ -89,6 +90,7 @@ TargetAsmInfo::TargetAsmInfo() :
DwarfInfoSection(".debug_info"), DwarfInfoSection(".debug_info"),
DwarfLineSection(".debug_line"), DwarfLineSection(".debug_line"),
DwarfFrameSection(".debug_frame"), DwarfFrameSection(".debug_frame"),
GlobalEHDirective(0),
DwarfPubNamesSection(".debug_pubnames"), DwarfPubNamesSection(".debug_pubnames"),
DwarfPubTypesSection(".debug_pubtypes"), DwarfPubTypesSection(".debug_pubtypes"),
DwarfStrSection(".debug_str"), DwarfStrSection(".debug_str"),

View File

@@ -124,7 +124,7 @@ bool X86ATTAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// FIXME: This should be parameterized somewhere. // FIXME: This should be parameterized somewhere.
EmitAlignment(4, F, 0, true, 0x90); EmitAlignment(4, F, 0, true, 0x90);
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n";
O << "\t.weak_definition\t" << CurrentFnName << "\n"; O << TAI->getWeakDefDirective() << CurrentFnName << "\n";
} else if (Subtarget->isTargetCygMing()) { } else if (Subtarget->isTargetCygMing()) {
EmitAlignment(4, F); // FIXME: This should be parameterized somewhere. EmitAlignment(4, F); // FIXME: This should be parameterized somewhere.
O << "\t.globl\t" << CurrentFnName << "\n"; O << "\t.globl\t" << CurrentFnName << "\n";

View File

@@ -214,7 +214,7 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
case GlobalValue::WeakLinkage: case GlobalValue::WeakLinkage:
if (Subtarget->isTargetDarwin()) { if (Subtarget->isTargetDarwin()) {
O << "\t.globl\t" << name << "\n" O << "\t.globl\t" << name << "\n"
<< "\t.weak_definition " << name << "\n"; << TAI->getWeakDefDirective() << name << "\n";
SwitchToDataSection(".section __DATA,__const_coal,coalesced", I); SwitchToDataSection(".section __DATA,__const_coal,coalesced", I);
} else if (Subtarget->isTargetCygMing()) { } else if (Subtarget->isTargetCygMing()) {
std::string SectionName(".section\t.data$linkonce." + std::string SectionName(".section\t.data$linkonce." +

View File

@@ -76,6 +76,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
SetDirective = "\t.set"; SetDirective = "\t.set";
PCSymbol = "."; PCSymbol = ".";
UsedDirective = "\t.no_dead_strip\t"; UsedDirective = "\t.no_dead_strip\t";
WeakDefDirective = "\t.weak_definition\t";
WeakRefDirective = "\t.weak_reference\t"; WeakRefDirective = "\t.weak_reference\t";
HiddenDirective = "\t.private_extern\t"; HiddenDirective = "\t.private_extern\t";
@@ -92,6 +93,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
GlobalEHDirective = "\t.globl\t";
DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";