llvm.org GIT mirror llvm / 25efd6d
Use TARGET2 relocation for TType references on ARM. Do some cleanup of the code while here. Inspired by patch by Logan Chien! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167904 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 7 years ago
12 changed file(s) with 140 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
384384 /// GetSizeOfEncodedValue - Return the size of the encoding in bytes.
385385 unsigned GetSizeOfEncodedValue(unsigned Encoding) const;
386386
387 /// EmitReference - Emit a reference to a label with a specified encoding.
388 ///
389 void EmitReference(const MCSymbol *Sym, unsigned Encoding) const;
390 void EmitReference(const GlobalValue *GV, unsigned Encoding) const;
387 /// EmitReference - Emit reference to a ttype global with a specified encoding.
388 void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const;
391389
392390 /// EmitSectionOffset - Emit the 4-byte offset of Label from the start of
393391 /// its section. This can be done with a special directive if the target
5656
5757 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
5858 /// to the specified global variable from exception handling information.
59 ///
6059 virtual const MCExpr *
61 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
62 MachineModuleInfo *MMI, unsigned Encoding,
63 MCStreamer &Streamer) const;
60 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
61 MachineModuleInfo *MMI, unsigned Encoding,
62 MCStreamer &Streamer) const;
6463
6564 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
6665 virtual MCSymbol *
102101 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
103102 Mangler *) const;
104103
105 /// getExprForDwarfGlobalReference - The mach-o version of this method
104 /// getTTypeGlobalReference - The mach-o version of this method
106105 /// defaults to returning a stub reference.
107106 virtual const MCExpr *
108 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
109 MachineModuleInfo *MMI, unsigned Encoding,
110 MCStreamer &Streamer) const;
107 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
108 MachineModuleInfo *MMI, unsigned Encoding,
109 MCStreamer &Streamer) const;
111110
112111 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
113112 virtual MCSymbol *
2626 class MCExpr;
2727 class MCSection;
2828 class MCSymbol;
29 class MCSymbolRefExpr;
2930 class MCStreamer;
3031 class GlobalValue;
3132 class TargetMachine;
107108 return 0;
108109 }
109110
110 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
111 /// getTTypeGlobalReference - Return an MCExpr to use for a reference
111112 /// to the specified global variable from exception handling information.
112113 ///
113114 virtual const MCExpr *
114 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
115 MachineModuleInfo *MMI, unsigned Encoding,
116 MCStreamer &Streamer) const;
115 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
116 MachineModuleInfo *MMI, unsigned Encoding,
117 MCStreamer &Streamer) const;
117118
118119 // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
119120 virtual MCSymbol *
122123
123124 ///
124125 const MCExpr *
125 getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding,
126 MCStreamer &Streamer) const;
126 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
127 MCStreamer &Streamer) const;
127128
128129 virtual const MCSection *
129130 getStaticCtorSection(unsigned Priority = 65535) const {
118118 }
119119 }
120120
121 void AsmPrinter::EmitReference(const MCSymbol *Sym, unsigned Encoding) const {
121 void AsmPrinter::EmitTTypeReference(const GlobalValue *GV, unsigned Encoding)const{
122122 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
123123
124124 const MCExpr *Exp =
125 TLOF.getExprForDwarfReference(Sym, Encoding, OutStreamer);
126 OutStreamer.EmitAbsValue(Exp, GetSizeOfEncodedValue(Encoding));
127 }
128
129 void AsmPrinter::EmitReference(const GlobalValue *GV, unsigned Encoding)const{
130 const TargetLoweringObjectFile &TLOF = getObjFileLowering();
131
132 const MCExpr *Exp =
133 TLOF.getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, OutStreamer);
125 TLOF.getTTypeGlobalReference(GV, Mang, MMI, Encoding, OutStreamer);
134126 OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding), /*addrspace*/0);
135127 }
136128
684684 if (VerboseAsm)
685685 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
686686 if (GV)
687 Asm->EmitReference(GV, TTypeEncoding);
687 Asm->EmitTTypeReference(GV, TTypeEncoding);
688688 else
689689 Asm->OutStreamer.EmitIntValue(0,Asm->GetSizeOfEncodedValue(TTypeEncoding),
690690 0);
8787 Streamer.EmitSymbolValue(Sym, Size);
8888 }
8989
90 const MCExpr *TargetLoweringObjectFileELF::
91 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
92 MachineModuleInfo *MMI, unsigned Encoding,
93 MCStreamer &Streamer) const {
94
95 if (Encoding & dwarf::DW_EH_PE_indirect) {
96 MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo();
97
98 SmallString<128> Name;
99 Mang->getNameWithPrefix(Name, GV, true);
100 Name += ".DW.stub";
101
102 // Add information about the stub reference to ELFMMI so that the stub
103 // gets emitted by the asmprinter.
104 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
105 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
106 if (StubSym.getPointer() == 0) {
107 MCSymbol *Sym = Mang->getSymbol(GV);
108 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
109 }
110
111 return TargetLoweringObjectFile::
112 getTTypeReference(MCSymbolRefExpr::Create(SSym, getContext()),
113 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
114 }
115
116 return TargetLoweringObjectFile::
117 getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer);
118 }
119
90120 static SectionKind
91121 getELFKindForNamedSection(StringRef Name, SectionKind K) {
92122 // N.B.: The defaults used in here are no the same ones used in MC.
311341 if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
312342 assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
313343 return DataRelROSection;
314 }
315
316 const MCExpr *TargetLoweringObjectFileELF::
317 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
318 MachineModuleInfo *MMI,
319 unsigned Encoding, MCStreamer &Streamer) const {
320
321 if (Encoding & dwarf::DW_EH_PE_indirect) {
322 MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo();
323
324 SmallString<128> Name;
325 Mang->getNameWithPrefix(Name, GV, true);
326 Name += ".DW.stub";
327
328 // Add information about the stub reference to ELFMMI so that the stub
329 // gets emitted by the asmprinter.
330 MCSymbol *SSym = getContext().GetOrCreateSymbol(Name.str());
331 MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
332 if (StubSym.getPointer() == 0) {
333 MCSymbol *Sym = Mang->getSymbol(GV);
334 StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
335 }
336
337 return TargetLoweringObjectFile::
338 getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
339 }
340
341 return TargetLoweringObjectFile::
342 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
343344 }
344345
345346 const MCSection *
603604 }
604605
605606 const MCExpr *TargetLoweringObjectFileMachO::
606 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
607 MachineModuleInfo *MMI, unsigned Encoding,
608 MCStreamer &Streamer) const {
607 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
608 MachineModuleInfo *MMI, unsigned Encoding,
609 MCStreamer &Streamer) const {
609610 // The mach-o version of this method defaults to returning a stub reference.
610611
611612 if (Encoding & DW_EH_PE_indirect) {
628629 }
629630
630631 return TargetLoweringObjectFile::
631 getExprForDwarfReference(SSym, Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
632 getTTypeReference(MCSymbolRefExpr::Create(SSym, getContext()),
633 Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
632634 }
633635
634636 return TargetLoweringObjectFile::
635 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
637 getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer);
636638 }
637639
638640 MCSymbol *TargetLoweringObjectFileMachO::
99 #include "ARMTargetObjectFile.h"
1010 #include "ARMSubtarget.h"
1111 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCExpr.h"
1213 #include "llvm/MC/MCSectionELF.h"
14 #include "llvm/Target/Mangler.h"
15 #include "llvm/Target/TargetMachine.h"
1316 #include "llvm/Support/Dwarf.h"
1417 #include "llvm/Support/ELF.h"
15 #include "llvm/Target/TargetMachine.h"
1618 #include "llvm/ADT/StringExtras.h"
1719 using namespace llvm;
1820 using namespace dwarf;
3739 0,
3840 SectionKind::getMetadata());
3941 }
42
43 const MCExpr *ARMElfTargetObjectFile::
44 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
45 MachineModuleInfo *MMI, unsigned Encoding,
46 MCStreamer &Streamer) const {
47 assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
48
49 return MCSymbolRefExpr::Create(Mang->getSymbol(GV),
50 MCSymbolRefExpr::VK_ARM_TARGET2,
51 getContext());
52 }
2727
2828 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
2929
30 const MCExpr *
31 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
32 MachineModuleInfo *MMI, unsigned Encoding,
33 MCStreamer &Streamer) const;
34
3035 virtual const MCSection *getAttributesSection() const {
3136 return AttributesSection;
3237 }
284284 return DataSection;
285285 }
286286
287 /// getExprForDwarfGlobalReference - Return an MCExpr to use for a
287 /// getTTypeGlobalReference - Return an MCExpr to use for a
288288 /// reference to the specified global variable from exception
289289 /// handling information.
290290 const MCExpr *TargetLoweringObjectFile::
291 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
292 MachineModuleInfo *MMI, unsigned Encoding,
293 MCStreamer &Streamer) const {
294 const MCSymbol *Sym = Mang->getSymbol(GV);
295 return getExprForDwarfReference(Sym, Encoding, Streamer);
291 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
292 MachineModuleInfo *MMI, unsigned Encoding,
293 MCStreamer &Streamer) const {
294 const MCSymbolRefExpr *Ref =
295 MCSymbolRefExpr::Create(Mang->getSymbol(GV), getContext());
296
297 return getTTypeReference(Ref, Encoding, Streamer);
296298 }
297299
298300 const MCExpr *TargetLoweringObjectFile::
299 getExprForDwarfReference(const MCSymbol *Sym, unsigned Encoding,
300 MCStreamer &Streamer) const {
301 const MCExpr *Res = MCSymbolRefExpr::Create(Sym, getContext());
302
301 getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
302 MCStreamer &Streamer) const {
303303 switch (Encoding & 0x70) {
304304 default:
305305 report_fatal_error("We do not support this DWARF encoding yet!");
306306 case dwarf::DW_EH_PE_absptr:
307307 // Do nothing special
308 return Res;
308 return Sym;
309309 case dwarf::DW_EH_PE_pcrel: {
310310 // Emit a label to the streamer for the current position. This gives us
311311 // .-foo addressing.
312312 MCSymbol *PCSym = getContext().CreateTempSymbol();
313313 Streamer.EmitLabel(PCSym);
314314 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext());
315 return MCBinaryExpr::CreateSub(Res, PC, getContext());
316 }
317 }
318 }
315 return MCBinaryExpr::CreateSub(Sym, PC, getContext());
316 }
317 }
318 }
2121 using namespace dwarf;
2222
2323 const MCExpr *X86_64MachoTargetObjectFile::
24 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
25 MachineModuleInfo *MMI, unsigned Encoding,
26 MCStreamer &Streamer) const {
24 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
25 MachineModuleInfo *MMI, unsigned Encoding,
26 MCStreamer &Streamer) const {
2727
2828 // On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
2929 // is an indirect pc-relative reference.
3636 }
3737
3838 return TargetLoweringObjectFileMachO::
39 getExprForDwarfGlobalReference(GV, Mang, MMI, Encoding, Streamer);
39 getTTypeGlobalReference(GV, Mang, MMI, Encoding, Streamer);
4040 }
4141
4242 MCSymbol *X86_64MachoTargetObjectFile::
2020 class X86_64MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
2121 public:
2222 virtual const MCExpr *
23 getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
24 MachineModuleInfo *MMI, unsigned Encoding,
25 MCStreamer &Streamer) const;
23 getTTypeGlobalReference(const GlobalValue *GV, Mangler *Mang,
24 MachineModuleInfo *MMI, unsigned Encoding,
25 MCStreamer &Streamer) const;
2626
2727 // getCFIPersonalitySymbol - The symbol that gets passed to
2828 // .cfi_personality.
0 ; RUN: llc -mtriple=armv7-none-linux-gnueabi -arm-enable-ehabi -arm-enable-ehabi-descriptors < %s | FileCheck %s
1
2 @_ZTVN10__cxxabiv117__class_type_infoE = external global i8*
3 @_ZTS3Foo = linkonce_odr constant [5 x i8] c"3Foo\00"
4 @_ZTI3Foo = linkonce_odr unnamed_addr constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8** @_ZTVN10__cxxabiv117__class_type_infoE, i32 2) to i8*), i8* getelementptr inbounds ([5 x i8]* @_ZTS3Foo, i32 0, i32 0) }
5
6 define i32 @main() {
7 entry:
8 invoke void @_Z3foov()
9 to label %return unwind label %lpad
10
11 lpad: ; preds = %entry
12 %0 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*)
13 catch i8* bitcast ({ i8*, i8* }* @_ZTI3Foo to i8*)
14 %1 = extractvalue { i8*, i32 } %0, 1
15 %2 = tail call i32 @llvm.eh.typeid.for(i8* bitcast ({ i8*, i8* }* @_ZTI3Foo to i8*)) nounwind
16 ; CHECK: _ZTI3Foo(target2)
17
18 %matches = icmp eq i32 %1, %2
19 br i1 %matches, label %catch, label %eh.resume
20
21 catch: ; preds = %lpad
22 %3 = extractvalue { i8*, i32 } %0, 0
23 %4 = tail call i8* @__cxa_begin_catch(i8* %3) nounwind
24 tail call void @__cxa_end_catch()
25 br label %return
26
27 return: ; preds = %entry, %catch
28 %retval.0 = phi i32 [ 1, %catch ], [ 0, %entry ]
29 ret i32 %retval.0
30
31 eh.resume: ; preds = %lpad
32 resume { i8*, i32 } %0
33 }
34
35 declare void @_Z3foov()
36
37 declare i32 @__gxx_personality_v0(...)
38
39 declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone
40
41 declare i8* @__cxa_begin_catch(i8*)
42
43 declare void @__cxa_end_catch()