llvm.org GIT mirror llvm / 4295d62
[AsmPrinter] Make the encoding of call sites in .gcc_except_table configurable and use for RISC-V The original behavior was to always emit the offsets to each call site in the call site table as uleb128 values, however on some architectures (eg RISCV) these uleb128 offsets into the code cannot always be resolved until link time (because relaxation will invalidate any calculated offsets), and there are no appropriate relocations for uleb128 values. As a consequence it needs to be possible to specify an alternative. This also switches RISCV to use DW_EH_PE_udata4 for call side encodings in .gcc_except_table Differential Revision: https://reviews.llvm.org/D63415 Patch by Edward Jones. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366329 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Bradbury 3 months ago
7 changed file(s) with 44 addition(s) and 13 deletion(s). Raw diff Collapse all Expand all
542542 emitDwarfStringOffset(S.getEntry());
543543 }
544544
545 /// Emit reference to a call site with a specified encoding
546 void EmitCallSiteOffset(const MCSymbol *Hi, const MCSymbol *Lo,
547 unsigned Encoding) const;
548 /// Emit an integer value corresponding to the call site encoding
549 void EmitCallSiteValue(uint64_t Value, unsigned Encoding) const;
550
545551 /// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
546552 virtual unsigned getISAEncoding() { return 0; }
547553
5050 unsigned PersonalityEncoding = 0;
5151 unsigned LSDAEncoding = 0;
5252 unsigned TTypeEncoding = 0;
53 unsigned CallSiteEncoding = 0;
5354
5455 /// This section contains the static constructor pointer list.
5556 MCSection *StaticCtorSection = nullptr;
146147 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
147148 unsigned getLSDAEncoding() const { return LSDAEncoding; }
148149 unsigned getTTypeEncoding() const { return TTypeEncoding; }
150 unsigned getCallSiteEncoding() const { return CallSiteEncoding; }
149151
150152 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
151153 MCStreamer &Streamer) const;
182182 EmitLabelPlusOffset(Label, Offset, MAI->getCodePointerSize());
183183 }
184184
185 void AsmPrinter::EmitCallSiteOffset(const MCSymbol *Hi,
186 const MCSymbol *Lo,
187 unsigned Encoding) const {
188 // The least significant 3 bits specify the width of the encoding
189 if ((Encoding & 0x7) == dwarf::DW_EH_PE_uleb128)
190 EmitLabelDifferenceAsULEB128(Hi, Lo);
191 else
192 EmitLabelDifference(Hi, Lo, GetSizeOfEncodedValue(Encoding));
193 }
194
195 void AsmPrinter::EmitCallSiteValue(uint64_t Value,
196 unsigned Encoding) const {
197 // The least significant 3 bits specify the width of the encoding
198 if ((Encoding & 0x7) == dwarf::DW_EH_PE_uleb128)
199 EmitULEB128(Value);
200 else
201 OutStreamer->EmitIntValue(Value, GetSizeOfEncodedValue(Encoding));
202 }
203
185204 //===----------------------------------------------------------------------===//
186205 // Dwarf Lowering Routines
187206 //===----------------------------------------------------------------------===//
377377 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
378378 bool IsWasm = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Wasm;
379379 unsigned CallSiteEncoding =
380 IsSJLJ ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_uleb128;
380 IsSJLJ ? static_cast(dwarf::DW_EH_PE_udata4) :
381 Asm->getObjFileLowering().getCallSiteEncoding();
381382 bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
382383
383384 // Type infos.
522523 // Offset of the call site relative to the start of the procedure.
523524 if (VerboseAsm)
524525 Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) + " <<");
525 Asm->EmitLabelDifferenceAsULEB128(BeginLabel, EHFuncBeginSym);
526 Asm->EmitCallSiteOffset(BeginLabel, EHFuncBeginSym, CallSiteEncoding);
526527 if (VerboseAsm)
527528 Asm->OutStreamer->AddComment(Twine(" Call between ") +
528529 BeginLabel->getName() + " and " +
529530 EndLabel->getName());
530 Asm->EmitLabelDifferenceAsULEB128(EndLabel, BeginLabel);
531 Asm->EmitCallSiteOffset(EndLabel, BeginLabel, CallSiteEncoding);
531532
532533 // Offset of the landing pad relative to the start of the procedure.
533534 if (!S.LPad) {
534535 if (VerboseAsm)
535536 Asm->OutStreamer->AddComment(" has no landing pad");
536 Asm->EmitULEB128(0);
537 Asm->EmitCallSiteValue(0, CallSiteEncoding);
537538 } else {
538539 if (VerboseAsm)
539540 Asm->OutStreamer->AddComment(Twine(" jumps to ") +
540541 S.LPad->LandingPadLabel->getName());
541 Asm->EmitLabelDifferenceAsULEB128(S.LPad->LandingPadLabel,
542 EHFuncBeginSym);
542 Asm->EmitCallSiteOffset(S.LPad->LandingPadLabel, EHFuncBeginSym,
543 CallSiteEncoding);
543544 }
544545
545546 // Offset of the first associated action record, relative to the start of
217217 PersonalityEncoding = dwarf::DW_EH_PE_absptr;
218218 TTypeEncoding = dwarf::DW_EH_PE_absptr;
219219 }
220 CallSiteEncoding = dwarf::DW_EH_PE_udata4;
220221 break;
221222 case Triple::riscv32:
222223 case Triple::riscv64:
225226 dwarf::DW_EH_PE_sdata4;
226227 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
227228 dwarf::DW_EH_PE_sdata4;
229 CallSiteEncoding = dwarf::DW_EH_PE_udata4;
228230 break;
229231 case Triple::sparcv9:
230232 LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
4646
4747 // Reset various EH DWARF encodings.
4848 PersonalityEncoding = LSDAEncoding = TTypeEncoding = dwarf::DW_EH_PE_absptr;
49 CallSiteEncoding = dwarf::DW_EH_PE_uleb128;
4950 }
5051
5152 TargetLoweringObjectFile::~TargetLoweringObjectFile() {
5252 ; CHECK-NEXT: .byte 155 # @TType Encoding = indirect pcrel sdata4
5353 ; TODO: call site encoding should be DW_EH_PE_udata4
5454 ; CHECK: .Lttbaseref0:
55 ; CHECK-NEXT: .byte 1 # Call site Encoding = uleb128
55 ; CHECK-NEXT: .byte 3 # Call site Encoding = udata4
5656 ; CHECK-NEXT: .uleb128 .Lcst_end0-.Lcst_begin0
5757 ; CHECK-NEXT: cst_begin0:
58 ; CHECK-NEXT: .uleb128 .Ltmp0-.Lfunc_begin0 # >> Call Site 1 <<
59 ; CHECK-NEXT: .uleb128 .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
60 ; CHECK-NEXT: .uleb128 .Ltmp2-.Lfunc_begin0 # jumps to .Ltmp2
58 ; CHECK-NEXT: .word .Ltmp0-.Lfunc_begin0 # >> Call Site 1 <<
59 ; CHECK-NEXT: .word .Ltmp1-.Ltmp0 # Call between .Ltmp0 and .Ltmp1
60 ; CHECK-NEXT: .word .Ltmp2-.Lfunc_begin0 # jumps to .Ltmp2
6161 ; CHECK-NEXT: .byte 1 # On action: 1
62 ; CHECK-NEXT: .uleb128 .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
63 ; CHECK-NEXT: .uleb128 .Lfunc_end0-.Ltmp1 # Call between .Ltmp1 and .Lfunc_end0
64 ; CHECK-NEXT: .byte 0 # has no landing pad
62 ; CHECK-NEXT: .word .Ltmp1-.Lfunc_begin0 # >> Call Site 2 <<
63 ; CHECK-NEXT: .word .Lfunc_end0-.Ltmp1 # Call between .Ltmp1 and .Lfunc_end0
64 ; CHECK-NEXT: .word 0 # has no landing pad
6565 ; CHECK-NEXT: .byte 0 # On action: cleanup