llvm.org GIT mirror llvm / 7afec9c
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 Rafael Espindola 9 years ago
7 changed file(s) with 75 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
5757 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
5858
5959 virtual const MCSection *getEHFrameSection() const;
60 virtual MCSymbol *getPersonalityPICSymbol(StringRef Name) const;
6160
6261 virtual void emitPersonalityValue(MCStreamer &Streamer,
6362 const TargetMachine &TM,
8584 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
8685 MachineModuleInfo *MMI, unsigned Encoding,
8786 MCStreamer &Streamer) const;
87
88 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
89 virtual MCSymbol *
90 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
91 Mangler *Mang, MachineModuleInfo *MMI) const;
8892 };
8993
9094
176180 MachineModuleInfo *MMI, unsigned Encoding,
177181 MCStreamer &Streamer) const;
178182
183 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
184 virtual MCSymbol *
185 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
186 Mangler *Mang, MachineModuleInfo *MMI) const;
187
179188 virtual unsigned getPersonalityEncoding() const;
180189 virtual unsigned getLSDAEncoding() const;
181190 virtual unsigned getFDEEncoding() const;
139139 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
140140 const MCSection *getLSDASection() const { return LSDASection; }
141141 virtual const MCSection *getEHFrameSection() const = 0;
142 virtual MCSymbol *getPersonalityPICSymbol(StringRef Name) const;
143142 virtual void emitPersonalityValue(MCStreamer &Streamer,
144143 const TargetMachine &TM,
145144 const MCSymbol *Sym) const;
221220 MachineModuleInfo *MMI, unsigned Encoding,
222221 MCStreamer &Streamer) const;
223222
223 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
224 virtual MCSymbol *
225 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
226 Mangler *Mang, MachineModuleInfo *MMI) const;
227
224228 ///
225229 const MCExpr *
226230 getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding,
108108 if (PerEncoding == dwarf::DW_EH_PE_omit || !Per)
109109 return;
110110
111 const MCSymbol *Sym;
112 switch (PerEncoding & 0x70) {
113 default:
114 report_fatal_error("We do not support this DWARF encoding yet!");
115 case dwarf::DW_EH_PE_absptr:
116 Sym = Asm->Mang->getSymbol(Per);
117 break;
118 case dwarf::DW_EH_PE_pcrel:
119 Sym = TLOF.getPersonalityPICSymbol(Per->getName());
120 break;
121 }
111 const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(Per, PerEncoding,
112 Asm->Mang, MMI);
122113 Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding);
123114 }
124115
177177 }
178178
179179 MCSymbol *
180 TargetLoweringObjectFileELF::getPersonalityPICSymbol(StringRef Name) const {
181 Twine FullName = StringRef("DW.ref.") + Name;
182 return getContext().GetOrCreateSymbol(FullName);
180 TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV,
181 unsigned Encoding,
182 Mangler *Mang,
183 MachineModuleInfo *MMI) const {
184 switch (Encoding & 0x70) {
185 default:
186 report_fatal_error("We do not support this DWARF encoding yet!");
187 case dwarf::DW_EH_PE_absptr:
188 return Mang->getSymbol(GV);
189 break;
190 case dwarf::DW_EH_PE_pcrel: {
191 Twine FullName = StringRef("DW.ref.") + Mang->getSymbol(GV)->getName();
192 return getContext().GetOrCreateSymbol(FullName);
193 break;
194 }
195 }
183196 }
184197
185198 void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer,
186199 const TargetMachine &TM,
187 const MCSymbol *Sym) const {
188 MCSymbol *Label = getPersonalityPICSymbol(Sym->getName());
200 const MCSymbol *Sym) const {
201 Twine FullName = StringRef("DW.ref.") + Sym->getName();
202 MCSymbol *Label = getContext().GetOrCreateSymbol(FullName);
189203 Streamer.EmitSymbolAttribute(Label, MCSA_Hidden);
190204 Streamer.EmitSymbolAttribute(Label, MCSA_Weak);
191205 Twine SectionName = StringRef(".data.") + Label->getName();
833847 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
834848 }
835849
850 MCSymbol *TargetLoweringObjectFileMachO::
851 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang,
852 MachineModuleInfo *MMI) const {
853 // The mach-o version of this method defaults to returning a stub reference.
854 MachineModuleInfoMachO &MachOMMI =
855 MMI->getObjFileInfo();
856
857 SmallString<128> Name;
858 Mang->getNameWithPrefix(Name, GV, true);
859 Name += "$non_lazy_ptr";
860
861 // Add information about the stub reference to MachOMMI so that the stub
862 // gets emitted by the asmprinter.
863 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
864 MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
865 if (StubSym.getPointer() == 0) {
866 MCSymbol *Sym = Mang->getSymbol(GV);
867 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
868 }
869
870 return SSym;
871 }
872
836873 unsigned TargetLoweringObjectFileMachO::getPersonalityEncoding() const {
837874 return DW_EH_PE_indirect | DW_EH_PE_pcrel | DW_EH_PE_sdata4;
838875 }
119119 return false;
120120 }
121121
122 MCSymbol *
123 TargetLoweringObjectFile::getPersonalityPICSymbol(StringRef Name) const {
124 assert(0 && "Not Available in this format.");
125 return 0;
122 MCSymbol *TargetLoweringObjectFile::
123 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang,
124 MachineModuleInfo *MMI) const {
125 return Mang->getSymbol(GV);
126126 }
127127
128128 void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
129129 const TargetMachine &TM,
130130 const MCSymbol *Sym) const {
131 assert(0 && "Not Available in this format.");
132131 }
133132
134133
3535
3636 return TargetLoweringObjectFileMachO::
3737 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
38 }
39
40 MCSymbol *X8664_MachoTargetObjectFile::
41 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding, Mangler *Mang,
42 MachineModuleInfo *MMI) const {
43 return Mang->getSymbol(GV);
3844 }
3945
4046 unsigned X8632_ELFTargetObjectFile::getPersonalityEncoding() const {
2424 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
2525 MachineModuleInfo *MMI, unsigned Encoding,
2626 MCStreamer &Streamer) const;
27
28 // getCFIPersonalitySymbol - The symbol that gets passed to
29 // .cfi_personality.
30 virtual MCSymbol *
31 getCFIPersonalitySymbol(const GlobalValue *GV, unsigned Encoding,
32 Mangler *Mang, MachineModuleInfo *MMI) const;
2733 };
2834
2935 class X8632_ELFTargetObjectFile : public TargetLoweringObjectFileELF {