Emit smaller exception tables for non-SJLJ mode.

* Use uleb128 for code offsets in the LSDA call site table.
* Omit the TTBase offset if the type table is empty.

This change can reduce the size of the DWARF/Itanium LSDA by about half.

Patch by Ryan Prichard!

llvm-svn: 324750
This commit is contained in:
Rafael Espindola 2018-02-09 17:13:37 +00:00
parent d09b416943
commit c052fa0bd3
10 changed files with 39 additions and 38 deletions

View File

@ -374,15 +374,17 @@ void EHStreamer::emitExceptionTable() {
computeCallSiteTable(CallSites, LandingPads, FirstActions);
bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true;
unsigned CallSiteEncoding =
IsSJLJ ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_uleb128;
bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
// Type infos.
MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
unsigned TTypeEncoding;
if (!HaveTTData) {
// For SjLj exceptions, if there is no TypeInfo, then we just explicitly say
// that we're omitting that bit.
// If there is no TypeInfo, then we just explicitly say that we're omitting
// that bit.
TTypeEncoding = dwarf::DW_EH_PE_omit;
} else {
// Okay, we have actual filters or typeinfos to emit. As such, we need to
@ -450,7 +452,7 @@ void EHStreamer::emitExceptionTable() {
// Emit the landing pad call site table.
MCSymbol *CstBeginLabel = Asm->createTempSymbol("cst_begin");
MCSymbol *CstEndLabel = Asm->createTempSymbol("cst_end");
Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site");
Asm->EmitEncodingByte(CallSiteEncoding, "Call site");
Asm->EmitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel);
Asm->OutStreamer->EmitLabel(CstBeginLabel);
@ -518,23 +520,24 @@ void EHStreamer::emitExceptionTable() {
// Offset of the call site relative to the start of the procedure.
if (VerboseAsm)
Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) + " <<");
Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4);
Asm->EmitLabelDifferenceAsULEB128(BeginLabel, EHFuncBeginSym);
if (VerboseAsm)
Asm->OutStreamer->AddComment(Twine(" Call between ") +
BeginLabel->getName() + " and " +
EndLabel->getName());
Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
Asm->EmitLabelDifferenceAsULEB128(EndLabel, BeginLabel);
// Offset of the landing pad relative to the start of the procedure.
if (!S.LPad) {
if (VerboseAsm)
Asm->OutStreamer->AddComment(" has no landing pad");
Asm->OutStreamer->EmitIntValue(0, 4/*size*/);
Asm->EmitULEB128(0);
} else {
if (VerboseAsm)
Asm->OutStreamer->AddComment(Twine(" jumps to ") +
S.LPad->LandingPadLabel->getName());
Asm->EmitLabelDifference(S.LPad->LandingPadLabel, EHFuncBeginSym, 4);
Asm->EmitLabelDifferenceAsULEB128(S.LPad->LandingPadLabel,
EHFuncBeginSym);
}
// Offset of the first associated action record, relative to the start of

View File

@ -64,8 +64,8 @@ declare void @__cxa_end_catch()
; CHECK: .cfi_personality 0,
; CHECK: .cfi_lsda 0,
; CHECK: @TType Encoding = absptr
; CHECK: @ Call site Encoding = udata4
; CHECK: @ Call site Encoding = uleb128
; CHECK-PIC: .cfi_personality 155,
; CHECK-PIC: .cfi_lsda 27,
; CHECK-PIC: @TType Encoding = indirect pcrel sdata4
; CHECK-PIC: @ Call site Encoding = udata4
; CHECK-PIC: @ Call site Encoding = uleb128

View File

@ -57,5 +57,5 @@ try.cont:
; CHECK: .byte 255 @ @LPStart Encoding = omit
; CHECK: .byte 0 @ @TType Encoding = absptr
; CHECK: .uleb128 .Lttbase
; CHECK: .byte 3 @ Call site Encoding = udata4
; CHECK: .byte 1 @ Call site Encoding = uleb128
; CHECK: .fnend

View File

@ -52,9 +52,9 @@ try.cont:
; CHECK: .byte 255 @ @LPStart Encoding = omit
; CHECK: .byte 0 @ @TType Encoding = absptr
; CHECK: .uleb128 .Lttbase
; CHECK: .byte 3 @ Call site Encoding = udata4
; CHECK: .byte 1 @ Call site Encoding = uleb128
; CHECK: .uleb128 .Lcst_end
; CHECK: .long
; CHECK: .long
; CHECK: .long
; CHECK: .uleb128
; CHECK: .uleb128
; CHECK: .uleb128
; CHECK: .fnend

View File

@ -20,5 +20,5 @@ bb2:
ret void
; CHECK: [[END:.Lfunc_end.*]]:
; CHECK: .long [[END]]-
; CHECK: .uleb128 [[END]]-
}

View File

@ -22,14 +22,12 @@ entry:
; CHECK: .seh_handlerdata
; CHECK: .Lexception0:
; CHECK: .byte 255 # @LPStart Encoding = omit
; CHECK: .byte 0 # @TType Encoding = absptr
; CHECK: .uleb128 .Lttbase0-.Lttbaseref0
; CHECK: .Lttbaseref0:
; CHECK: .byte 3 # Call site Encoding = udata4
; CHECK: .byte 255 # @TType Encoding = omit
; CHECK: .byte 1 # Call site Encoding = uleb128
; CHECK: .uleb128 .Lcst_end0-.Lcst_begin0
; CHECK: .Lcst_begin0:
; CHECK: .long .Lfunc_begin0-.Lfunc_begin0 # >> Call Site 1 <<
; CHECK: .long .Lfunc_end0-.Lfunc_begin0 # Call between .Lfunc_begin0 and .Lfunc_end0
; CHECK: .long 0 # has no landing pad
; CHECK: .uleb128 .Lfunc_begin0-.Lfunc_begin0 # >> Call Site 1 <<
; CHECK: .uleb128 .Lfunc_end0-.Lfunc_begin0 # Call between .Lfunc_begin0 and .Lfunc_end0
; CHECK: .byte 0 # has no landing pad
; CHECK: .byte 0 # On action: cleanup
; CHECK: .Lcst_end0:

View File

@ -36,12 +36,12 @@ threw:
; CHECK-NEXT: .byte 3
; CHECK-NEXT: .uleb128 .Lttbase{{[0-9]+}}-[[TTBASEREF:.Lttbaseref[0-9]+]]
; CHECK-NEXT: [[TTBASEREF]]:
; CHECK-NEXT: .byte 3
; CHECK-NEXT: .byte 1
; CHECK-NEXT: .uleb128 .Lcst_end{{[0-9]+}}-[[CST_BEGIN:.Lcst_begin[0-9]+]]
; CHECK-NEXT: [[CST_BEGIN]]:
; Verify that the unwind data covers the entire patchpoint region:
; CHECK-NEXT: .long .Ltmp0-[[FUNC_BEGIN]]
; CHECK-NEXT: .long [[PP_END]]-.Ltmp0
; CHECK-NEXT: .uleb128 .Ltmp0-[[FUNC_BEGIN]]
; CHECK-NEXT: .uleb128 [[PP_END]]-.Ltmp0
; Verify that the stackmap section got emitted:

View File

@ -11,7 +11,7 @@
; LINUX-NEXT: SHF_ALLOC (0x2)
; LINUX-NEXT: ]
; LINUX-NEXT: Address: 0x0
; LINUX-NEXT: Offset: 0x68
; LINUX-NEXT: Offset: 0x5C
; LINUX-NEXT: Size: 64
; LINUX-NEXT: Link: 0
; LINUX-NEXT: Info: 0

View File

@ -38,8 +38,8 @@ exceptional_return:
ret i64 addrspace(1)* %obj1.relocated1
}
; CHECK-LABEL: GCC_except_table{{[0-9]+}}:
; CHECK: .long .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}}
; CHECK: .long .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}}
; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}}
; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}}
; CHECK: .byte 0
; CHECK: .p2align 4
@ -68,8 +68,8 @@ exceptional_return:
ret i64 addrspace(1)* %obj.relocated
}
; CHECK-LABEL: GCC_except_table{{[0-9]+}}:
; CHECK: .long .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}}
; CHECK: .long .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}}
; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Ltmp{{[0-9]+}}
; CHECK: .uleb128 .Ltmp{{[0-9]+}}-.Lfunc_begin{{[0-9]+}}
; CHECK: .byte 0
; CHECK: .p2align 4

View File

@ -107,16 +107,16 @@ Exit:
; CHECK: .byte 0
; CHECK: .uleb128 [[TTBASE:.Lttbase[0-9]+]]-[[TTBASEREF:.Lttbaseref[0-9]+]]
; CHECK: [[TTBASEREF]]:
; CHECK: .byte 3
; CHECK: .byte 1
; CHECK: .uleb128 [[CST_END:.Lcst_end[0-9]+]]-[[CST_BEGIN:.Lcst_begin[0-9]+]]
; CHECK: [[CST_BEGIN]]:
; CHECK: .long [[PRE_G]]-[[START]]
; CHECK: .long [[POST_G]]-[[PRE_G]]
; CHECK: .long [[LANDING]]-[[START]]
; CHECK: .uleb128 [[PRE_G]]-[[START]]
; CHECK: .uleb128 [[POST_G]]-[[PRE_G]]
; CHECK: .uleb128 [[LANDING]]-[[START]]
; CHECK: .byte 5
; CHECK: .long [[POST_G]]-[[START]]
; CHECK: .long [[END]]-[[POST_G]]
; CHECK: .long 0
; CHECK: .uleb128 [[POST_G]]-[[START]]
; CHECK: .uleb128 [[END]]-[[POST_G]]
; CHECK: .byte 0
; CHECK: .byte 0
; CHECK: [[CST_END]]:
; CHECK: .byte 0