From 7afec9cc0ff1654619d30b6f30e2a4d13369c8bf Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 27 Apr 2011 23:08:15 +0000 Subject: [PATCH] Rename getPersonalityPICSymbol to getCFIPersonalitySymbol, document it, and give it a bit more responsibility. Also implement it for MachO. If hacked to use cfi, 32 bit MachO will produce .cfi_personality 155, L___gxx_personality_v0$non_lazy_ptr and 64 bit will produce .cfi_presonality ___gxx_personality_v0 The general idea is that .cfi_personality gets passed the final symbol. It is up to codegen to produce it if using indirect representation (like 32 bit MachO), but it is up to MC to decide which relocations to create. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130341 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../CodeGen/TargetLoweringObjectFileImpl.h | 11 ++++- .../llvm/Target/TargetLoweringObjectFile.h | 6 ++- lib/CodeGen/AsmPrinter/DwarfCFIException.cpp | 13 +---- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 47 +++++++++++++++++-- lib/Target/TargetLoweringObjectFile.cpp | 9 ++-- lib/Target/X86/X86TargetObjectFile.cpp | 6 +++ lib/Target/X86/X86TargetObjectFile.h | 6 +++ 7 files changed, 75 insertions(+), 23 deletions(-) diff --git a/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index 8aa34f0174b..411e4ccd081 100644 --- a/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -58,7 +58,6 @@ public: virtual void Initialize(MCContext &Ctx, const TargetMachine &TM); virtual const MCSection *getEHFrameSection() const; - virtual MCSymbol *getPersonalityPICSymbol(StringRef Name) const; virtual void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, @@ -86,6 +85,11 @@ public: getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const; + + // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality. + virtual MCSymbol * + getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, + Mangler *Mang, MachineModuleInfo *MMI) const; }; @@ -177,6 +181,11 @@ public: MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const; + // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality. + virtual MCSymbol * + getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, + Mangler *Mang, MachineModuleInfo *MMI) const; + virtual unsigned getPersonalityEncoding() const; virtual unsigned getLSDAEncoding() const; virtual unsigned getFDEEncoding() const; diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index c787dfb6304..e4bbd018d76 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -140,7 +140,6 @@ public: const MCSection *getStaticDtorSection() const { return StaticDtorSection; } const MCSection *getLSDASection() const { return LSDASection; } virtual const MCSection *getEHFrameSection() const = 0; - virtual MCSymbol *getPersonalityPICSymbol(StringRef Name) const; virtual void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const; @@ -222,6 +221,11 @@ public: MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const; + // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality. + virtual MCSymbol * + getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, + Mangler *Mang, MachineModuleInfo *MMI) const; + /// const MCExpr * getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding, diff --git a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp index 70c0c8a82eb..5b92edeb29b 100644 --- a/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp +++ b/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp @@ -109,17 +109,8 @@ void DwarfCFIException::BeginFunction(const MachineFunction *MF) { if (PerEncoding == dwarf::DW_EH_PE_omit || !Per) return; - const MCSymbol *Sym; - switch (PerEncoding & 0x70) { - default: - report_fatal_error("We do not support this DWARF encoding yet!"); - case dwarf::DW_EH_PE_absptr: - Sym = Asm->Mang->getSymbol(Per); - break; - case dwarf::DW_EH_PE_pcrel: - Sym = TLOF.getPersonalityPICSymbol(Per->getName()); - break; - } + const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(Per, PerEncoding, + Asm->Mang, MMI); Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding); } diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index 7888a838ad9..1a4da73ffa5 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -178,15 +178,29 @@ const MCSection *TargetLoweringObjectFileELF::getEHFrameSection() const { } MCSymbol * -TargetLoweringObjectFileELF::getPersonalityPICSymbol(StringRef Name) const { - Twine FullName = StringRef("DW.ref.") + Name; - return getContext().GetOrCreateSymbol(FullName); +TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV, + unsigned Encoding, + Mangler *Mang, + MachineModuleInfo *MMI) const { + switch (Encoding & 0x70) { + default: + report_fatal_error("We do not support this DWARF encoding yet!"); + case dwarf::DW_EH_PE_absptr: + return Mang->getSymbol(GV); + break; + case dwarf::DW_EH_PE_pcrel: { + Twine FullName = StringRef("DW.ref.") + Mang->getSymbol(GV)->getName(); + return getContext().GetOrCreateSymbol(FullName); + break; + } + } } void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, - const MCSymbol *Sym) const { - MCSymbol *Label = getPersonalityPICSymbol(Sym->getName()); + const MCSymbol *Sym) const { + Twine FullName = StringRef("DW.ref.") + Sym->getName(); + MCSymbol *Label = getContext().GetOrCreateSymbol(FullName); Streamer.EmitSymbolAttribute(Label, MCSA_Hidden); Streamer.EmitSymbolAttribute(Label, MCSA_Weak); Twine SectionName = StringRef(".data.") + Label->getName(); @@ -834,6 +848,29 @@ getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); } +MCSymbol *TargetLoweringObjectFileMachO:: +getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang, + MachineModuleInfo *MMI) const { + // The mach-o version of this method defaults to returning a stub reference. + MachineModuleInfoMachO &MachOMMI = + MMI->getObjFileInfo(); + + SmallString<128> Name; + Mang->getNameWithPrefix(Name, GV, true); + Name += "$non_lazy_ptr"; + + // Add information about the stub reference to MachOMMI so that the stub + // gets emitted by the asmprinter. + MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str()); + MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym); + if (StubSym.getPointer() == 0) { + MCSymbol *Sym = Mang->getSymbol(GV); + StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage()); + } + + return SSym; +} + unsigned TargetLoweringObjectFileMachO::getPersonalityEncoding() const { return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; } diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index 040e0f920b0..07f9773eb2e 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -120,16 +120,15 @@ static bool IsNullTerminatedString(const Constant *C) { return false; } -MCSymbol * -TargetLoweringObjectFile::getPersonalityPICSymbol(StringRef Name) const { - assert(0 && "Not Available in this format."); - return 0; +MCSymbol *TargetLoweringObjectFile:: +getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang, + MachineModuleInfo *MMI) const { + return Mang->getSymbol(GV); } void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM, const MCSymbol *Sym) const { - assert(0 && "Not Available in this format."); } diff --git a/lib/Target/X86/X86TargetObjectFile.cpp b/lib/Target/X86/X86TargetObjectFile.cpp index 3b1e33d0022..68c5aadcfcf 100644 --- a/lib/Target/X86/X86TargetObjectFile.cpp +++ b/lib/Target/X86/X86TargetObjectFile.cpp @@ -38,6 +38,12 @@ getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer); } +MCSymbol *X8664_MachoTargetObjectFile:: +getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang, + MachineModuleInfo *MMI) const { + return Mang->getSymbol(GV); +} + unsigned X8632_ELFTargetObjectFile::getPersonalityEncoding() const { if (TM.getRelocationModel() == Reloc::PIC_) return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4; diff --git a/lib/Target/X86/X86TargetObjectFile.h b/lib/Target/X86/X86TargetObjectFile.h index f2fd49caca3..7d14175271f 100644 --- a/lib/Target/X86/X86TargetObjectFile.h +++ b/lib/Target/X86/X86TargetObjectFile.h @@ -25,6 +25,12 @@ namespace llvm { getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang, MachineModuleInfo *MMI, unsigned Encoding, MCStreamer &Streamer) const; + + // getCFIPersonalitySymbol - The symbol that gets passed to + // .cfi_personality. + virtual MCSymbol * + getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, + Mangler *Mang, MachineModuleInfo *MMI) const; }; class X8632_ELFTargetObjectFile : public TargetLoweringObjectFileELF { -- 2.34.1