From 4af349445222fa2a66b6248217ecd18eb6930646 Mon Sep 17 00:00:00 2001 From: Dale Johannesen Date: Tue, 15 Jan 2008 23:24:56 +0000 Subject: [PATCH] Fix and enable EH for x86-64 Darwin. Adds ShortenEHDataFor64Bits as a not-very-accurate abstraction to cover all the changes in DwarfWriter. Some cosmetic changes to Darwin assembly code for gcc testsuite compatibility. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46029 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Target/TargetAsmInfo.h | 7 +++++++ lib/CodeGen/DwarfWriter.cpp | 20 ++++++++++++-------- lib/Target/PowerPC/PPCTargetAsmInfo.cpp | 1 + lib/Target/X86/X86AsmPrinter.cpp | 3 ++- lib/Target/X86/X86TargetAsmInfo.cpp | 15 +++++++++++---- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/include/llvm/Target/TargetAsmInfo.h b/include/llvm/Target/TargetAsmInfo.h index 8192b46f8df..f40fdb5a414 100644 --- a/include/llvm/Target/TargetAsmInfo.h +++ b/include/llvm/Target/TargetAsmInfo.h @@ -313,6 +313,10 @@ namespace llvm { /// handle a weak_definition of constant 0 for an omitted EH frame. bool SupportsWeakOmittedEHFrame; // Defaults to true. + /// ShortenEHDataON64Bit - True if target exception table format requires + /// 32-bit data in certain places even when targeting 64-bits. + bool ShortenEHDataOn64Bit; // Defaults to false. + /// DwarfSectionOffsetDirective - Special section offset directive. const char* DwarfSectionOffsetDirective; // Defaults to NULL @@ -592,6 +596,9 @@ namespace llvm { bool getSupportsWeakOmittedEHFrame() const { return SupportsWeakOmittedEHFrame; } + bool getShortenEHDataOn64Bit() const { + return ShortenEHDataOn64Bit; + } const char *getDwarfSectionOffsetDirective() const { return DwarfSectionOffsetDirective; } diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp index 1f7618a533a..8b315be7a55 100644 --- a/lib/CodeGen/DwarfWriter.cpp +++ b/lib/CodeGen/DwarfWriter.cpp @@ -2835,11 +2835,13 @@ private: Asm->EOL("Personality (pcrel sdata4 indirect)"); - PrintRelDirective(); + PrintRelDirective(TAI->getShortenEHDataOn64Bit()); O << TAI->getPersonalityPrefix(); Asm->EmitExternalGlobal((const GlobalVariable *)(Personality)); O << TAI->getPersonalitySuffix(); - O << "-" << TAI->getPCSymbol(); + if (!TAI->getShortenEHDataOn64Bit()) { + O << "-" << TAI->getPCSymbol(); + } Asm->EOL("Personality"); Asm->EmitULEB128Bytes(DW_EH_PE_pcrel); @@ -2917,7 +2919,7 @@ private: // If there is a personality and landing pads then point to the language // specific data area in the exception table. if (EHFrameInfo.PersonalityIndex) { - Asm->EmitULEB128Bytes(4); + Asm->EmitULEB128Bytes(TAI->getShortenEHDataOn64Bit() ? 8 : 4); Asm->EOL("Augmentation size"); if (EHFrameInfo.hasLandingPads) { @@ -3284,24 +3286,26 @@ private: } EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount, - false, true); + TAI->getShortenEHDataOn64Bit(), true); Asm->EOL("Region start"); if (!S.EndLabel) { - EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber); + EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber, + TAI->getShortenEHDataOn64Bit()); } else { - EmitDifference("label", S.EndLabel, BeginTag, BeginNumber); + EmitDifference("label", S.EndLabel, BeginTag, BeginNumber, + TAI->getShortenEHDataOn64Bit()); } Asm->EOL("Region length"); if (!S.PadLabel) { - if (TD->getPointerSize() == sizeof(int32_t)) + if (TD->getPointerSize() == sizeof(int32_t) || TAI->getShortenEHDataOn64Bit()) Asm->EmitInt32(0); else Asm->EmitInt64(0); } else { EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount, - false, true); + TAI->getShortenEHDataOn64Bit(), true); } Asm->EOL("Landing pad"); diff --git a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp index e593482c65a..8728def217c 100644 --- a/lib/Target/PowerPC/PPCTargetAsmInfo.cpp +++ b/lib/Target/PowerPC/PPCTargetAsmInfo.cpp @@ -50,6 +50,7 @@ DarwinTargetAsmInfo::DarwinTargetAsmInfo(const PPCTargetMachine &TM) StaticCtorsSection = ".mod_init_func"; StaticDtorsSection = ".mod_term_func"; } + SwitchToSectionDirective = "\t.section "; UsedDirective = "\t.no_dead_strip\t"; WeakDefDirective = "\t.weak_definition "; WeakRefDirective = "\t.weak_reference "; diff --git a/lib/Target/X86/X86AsmPrinter.cpp b/lib/Target/X86/X86AsmPrinter.cpp index 8f481626961..b0e8165ad1c 100644 --- a/lib/Target/X86/X86AsmPrinter.cpp +++ b/lib/Target/X86/X86AsmPrinter.cpp @@ -358,7 +358,8 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) { O << "\n"; - if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI) { + if (ExceptionHandling && TAI->doesSupportExceptionHandling() && MMI && + !Subtarget->is64Bit()) { // Add the (possibly multiple) personalities to the set of global values. const std::vector& Personalities = MMI->getPersonalities(); diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp index bc698ba0969..293836a06e8 100644 --- a/lib/Target/X86/X86TargetAsmInfo.cpp +++ b/lib/Target/X86/X86TargetAsmInfo.cpp @@ -59,6 +59,7 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) { SixteenByteConstantSection = "\t.literal16\n"; ReadOnlySection = "\t.const\n"; LCOMMDirective = "\t.lcomm\t"; + SwitchToSectionDirective = "\t.section "; COMMDirectiveTakesAlignment = false; HasDotTypeDotSizeDirective = false; if (TM.getRelocationModel() == Reloc::Static) { @@ -68,8 +69,13 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) { StaticCtorsSection = ".mod_init_func"; StaticDtorsSection = ".mod_term_func"; } - PersonalityPrefix = "L"; - PersonalitySuffix = "$non_lazy_ptr"; + if (Subtarget->is64Bit()) { + PersonalityPrefix = ""; + PersonalitySuffix = "+4@GOTPCREL"; + } else { + PersonalityPrefix = "L"; + PersonalitySuffix = "$non_lazy_ptr"; + } NeedsIndirectEncoding = true; InlineAsmStart = "# InlineAsm Start"; InlineAsmEnd = "# InlineAsm End"; @@ -102,11 +108,12 @@ X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) { DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; // Exceptions handling - if (!Subtarget->is64Bit()) - SupportsExceptionHandling = true; + SupportsExceptionHandling = true; GlobalEHDirective = "\t.globl\t"; SupportsWeakOmittedEHFrame = false; AbsoluteEHSectionOffsets = false; + if (Subtarget->is64Bit()) + ShortenEHDataOn64Bit = true; DwarfEHFrameSection = ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; DwarfExceptionSection = ".section __DATA,__gcc_except_tab";