llvm.org GIT mirror llvm / 5426a9e
GCC uses a different encoding of pointers in the FDE when using -fno-dwarf2-cfi-asm. Implement the same behavior. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130637 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 9 years ago
13 changed file(s) with 76 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
187187
188188 virtual unsigned getPersonalityEncoding() const;
189189 virtual unsigned getLSDAEncoding() const;
190 virtual unsigned getFDEEncoding() const;
190 virtual unsigned getFDEEncoding(bool CFI) const;
191191 virtual unsigned getTTypeEncoding() const;
192192 };
193193
280280 //
281281 // This emits the frame info section.
282282 //
283 static void Emit(MCStreamer &streamer);
284 static void EmitDarwin(MCStreamer &streamer);
283 static void Emit(MCStreamer &streamer, bool usingCFI);
284 static void EmitDarwin(MCStreamer &streamer, bool usingCFI);
285285 static void EmitAdvanceLoc(MCStreamer &Streamer, uint64_t AddrDelta);
286286 static void EncodeAdvanceLoc(uint64_t AddrDelta, raw_ostream &OS,
287287 const TargetAsmInfo &AsmInfo);
5757 return TLOF->getEHFrameSection();
5858 }
5959
60 unsigned getFDEEncoding() const {
61 return TLOF->getFDEEncoding();
60 unsigned getFDEEncoding(bool CFI) const {
61 return TLOF->getFDEEncoding(CFI);
6262 }
6363
6464 bool isFunctionEHFrameSymbolPrivate() const {
232232
233233 virtual unsigned getPersonalityEncoding() const;
234234 virtual unsigned getLSDAEncoding() const;
235 virtual unsigned getFDEEncoding() const;
235 virtual unsigned getFDEEncoding(bool CFI) const;
236236 virtual unsigned getTTypeEncoding() const;
237237
238238 protected:
9191 // personality function reference:
9292
9393 unsigned LSDAEncoding = TLOF.getLSDAEncoding();
94 unsigned FDEEncoding = TLOF.getFDEEncoding();
94 unsigned FDEEncoding = TLOF.getFDEEncoding(false);
9595 unsigned PerEncoding = TLOF.getPersonalityEncoding();
9696
9797 char Augmentation[6] = { 0 };
167167 const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
168168
169169 unsigned LSDAEncoding = TLOF.getLSDAEncoding();
170 unsigned FDEEncoding = TLOF.getFDEEncoding();
170 unsigned FDEEncoding = TLOF.getFDEEncoding(false);
171171
172172 Asm->OutStreamer.SwitchSection(TLOF.getEHFrameSection());
173173
878878 return DW_EH_PE_pcrel;
879879 }
880880
881 unsigned TargetLoweringObjectFileMachO::getFDEEncoding() const {
881 unsigned TargetLoweringObjectFileMachO::getFDEEncoding(bool CFI) const {
882882 return DW_EH_PE_pcrel;
883883 }
884884
10681068 // Dump out the dwarf file & directory tables and line tables.
10691069 if (getContext().hasDwarfFiles() && !UseLoc)
10701070 MCDwarfFileTable::Emit(this);
1071
1072 if (getNumFrameInfos() && !UseCFI)
1073 MCDwarfFrameEmitter::Emit(*this, false);
10711074 }
10721075
10731076 MCStreamer *llvm::createAsmStreamer(MCContext &Context,
499499 class FrameEmitterImpl {
500500 int CFAOffset;
501501 int CIENum;
502 bool UsingCFI;
502503
503504 public:
504 FrameEmitterImpl() : CFAOffset(0), CIENum(0) {
505 FrameEmitterImpl(bool usingCFI) : CFAOffset(0), CIENum(0),
506 UsingCFI(usingCFI) {
505507 }
506508
507509 const MCSymbol &EmitCIE(MCStreamer &streamer,
701703 streamer.EmitIntValue(lsdaEncoding, 1);
702704 }
703705 // Encoding of the FDE pointers
704 streamer.EmitIntValue(asmInfo.getFDEEncoding(), 1);
706 streamer.EmitIntValue(asmInfo.getFDEEncoding(UsingCFI), 1);
705707
706708 // Initial Instructions
707709
752754 const MCExpr *offset = MakeStartMinusEndExpr(streamer, cieStart, *fdeStart,
753755 0);
754756 streamer.EmitAbsValue(offset, 4);
755 unsigned fdeEncoding = asmInfo.getFDEEncoding();
757 unsigned fdeEncoding = asmInfo.getFDEEncoding(UsingCFI);
756758 unsigned size = getSizeForEncoding(streamer, fdeEncoding);
757759
758760 // PC Begin
836838 // compatible with the one in CodeGen. It is useful during the transition
837839 // to make it easy to compare the outputs, but should probably be removed
838840 // afterwards.
839 void MCDwarfFrameEmitter::EmitDarwin(MCStreamer &streamer) {
840 FrameEmitterImpl Emitter;
841 void MCDwarfFrameEmitter::EmitDarwin(MCStreamer &streamer,
842 bool usingCFI) {
843 FrameEmitterImpl Emitter(usingCFI);
841844 DenseMap Personalities;
842845 const MCSymbol *aCIE = NULL;
843846 const MCDwarfFrameInfo *aFrame = NULL;
891894 streamer.EmitLabel(fdeEnd);
892895 }
893896
894 void MCDwarfFrameEmitter::Emit(MCStreamer &streamer) {
897 void MCDwarfFrameEmitter::Emit(MCStreamer &streamer,
898 bool usingCFI) {
895899 const MCContext &context = streamer.getContext();
896900 const TargetAsmInfo &asmInfo = context.getTargetAsmInfo();
897901 if (!asmInfo.isFunctionEHFrameSymbolPrivate()) {
898 EmitDarwin(streamer);
902 EmitDarwin(streamer, usingCFI);
899903 return;
900904 }
901905
902906 MCSymbol *fdeEnd = NULL;
903907 DenseMap CIEStarts;
904 FrameEmitterImpl Emitter;
908 FrameEmitterImpl Emitter(usingCFI);
905909
906910 for (unsigned i = 0, n = streamer.getNumFrameInfos(); i < n; ++i) {
907911 const MCDwarfFrameInfo &frame = streamer.getFrameInfo(i);
345345
346346 void MCELFStreamer::Finish() {
347347 if (getNumFrameInfos())
348 MCDwarfFrameEmitter::Emit(*this);
348 MCDwarfFrameEmitter::Emit(*this, true);
349349
350350 for (std::vector::const_iterator i = LocalCommons.begin(),
351351 e = LocalCommons.end();
349349 return dwarf::DW_EH_PE_absptr;
350350 }
351351
352 unsigned TargetLoweringObjectFile::getFDEEncoding() const {
352 unsigned TargetLoweringObjectFile::getFDEEncoding(bool CFI) const {
353353 return dwarf::DW_EH_PE_absptr;
354354 }
355355
5757 return DW_EH_PE_absptr;
5858 }
5959
60 unsigned X8632_ELFTargetObjectFile::getFDEEncoding() const {
60 unsigned X8632_ELFTargetObjectFile::getFDEEncoding(bool FDE) const {
6161 if (TM.getRelocationModel() == Reloc::PIC_)
6262 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
6363 else
9696 return DW_EH_PE_absptr;
9797 }
9898
99 unsigned X8664_ELFTargetObjectFile::getFDEEncoding() const {
100 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
99 unsigned X8664_ELFTargetObjectFile::getFDEEncoding(bool CFI) const {
100 if (CFI)
101 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
102
103 CodeModel::Model Model = TM.getCodeModel();
104 if (TM.getRelocationModel() == Reloc::PIC_)
105 return DW_EH_PE_pcrel | DW_EH_PE_sdata4;
106
107 return DW_EH_PE_udata4;
101108 }
102109
103110 unsigned X8664_ELFTargetObjectFile::getTTypeEncoding() const {
3939 :TM(tm) { }
4040 virtual unsigned getPersonalityEncoding() const;
4141 virtual unsigned getLSDAEncoding() const;
42 virtual unsigned getFDEEncoding() const;
42 virtual unsigned getFDEEncoding(bool CFI) const;
4343 virtual unsigned getTTypeEncoding() const;
4444 };
4545
5050 :TM(tm) { }
5151 virtual unsigned getPersonalityEncoding() const;
5252 virtual unsigned getLSDAEncoding() const;
53 virtual unsigned getFDEEncoding() const;
53 virtual unsigned getFDEEncoding(bool CFI) const;
5454 virtual unsigned getTTypeEncoding() const;
5555 };
5656
0 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -disable-cfi | FileCheck --check-prefix=STATIC %s
1 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -disable-cfi -relocation-model=pic | FileCheck --check-prefix=PIC %s
2
3 ; STATIC: .ascii "zPLR"
4 ; STATIC: .byte 3
5 ; STATIC-NEXT: .long __gxx_personality_v0
6 ; STATIC-NEXT: .byte 3
7 ; STATIC-NEXT: .byte 3
8
9 ; PIC: .ascii "zPLR"
10 ; PIC: .byte 155
11 ; PIC-NEXT: .L
12 ; PIC-NEXT: .long DW.ref.__gxx_personality_v0-.L
13 ; PIC-NEXT: .byte 27
14 ; PIC-NEXT: .byte 27
15
16
17 define void @bar() {
18 entry:
19 %call = invoke i32 @foo()
20 to label %invoke.cont unwind label %lpad
21
22 invoke.cont:
23 ret void
24
25 lpad:
26 %exn = call i8* @llvm.eh.exception() nounwind
27 %eh.selector = call i32 (i8*, i8*, ...)* @llvm.eh.selector(i8* %exn, i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*), i8* null) nounwind
28 ret void
29 }
30
31 declare i32 @foo()
32
33 declare i8* @llvm.eh.exception() nounwind readonly
34
35 declare i32 @__gxx_personality_v0(...)
36
37 declare i32 @llvm.eh.selector(i8*, i8*, ...) nounwind