Skip to content

Commit 0c3cda3

Browse files
committed
[BOLT] Use ULEB128 encoding for PIE/DSO exception tables
Use ULEB128 encoding for call sites in PIE/DSO binaries. The encoding reduces the size of the tables compared to sdata4 and is the default format used by Clang. Note that for fixed-address executables we still use absolute addressing to cover cases where landing pads can reside in different function fragments.
1 parent 314e9b1 commit 0c3cda3

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -959,9 +959,9 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
959959
if (NeedsLPAdjustment)
960960
LPOffsetExpr = MCBinaryExpr::createAdd(
961961
LPOffsetExpr, MCConstantExpr::create(1, *BC.Ctx), *BC.Ctx);
962-
Streamer.emitValue(LPOffsetExpr, 4);
962+
Streamer.emitULEB128Value(LPOffsetExpr);
963963
} else {
964-
Streamer.emitIntValue(0, 4);
964+
Streamer.emitULEB128IntValue(0);
965965
}
966966
};
967967
}
@@ -979,7 +979,10 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
979979
// Emit the landing pad call site table. We use signed data4 since we can emit
980980
// a landing pad in a different part of the split function that could appear
981981
// earlier in the address space than LPStart.
982-
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
982+
if (BC.HasFixedLoadAddress)
983+
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
984+
else
985+
Streamer.emitIntValue(dwarf::DW_EH_PE_uleb128, 1);
983986

984987
MCSymbol *CSTStartLabel = BC.Ctx->createTempSymbol("CSTStart");
985988
MCSymbol *CSTEndLabel = BC.Ctx->createTempSymbol("CSTEnd");
@@ -996,8 +999,13 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
996999

9971000
// Start of the range is emitted relative to the start of current
9981001
// function split part.
999-
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
1000-
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1002+
if (BC.HasFixedLoadAddress) {
1003+
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
1004+
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1005+
} else {
1006+
Streamer.emitAbsoluteSymbolDiffAsULEB128(BeginLabel, StartSymbol);
1007+
Streamer.emitAbsoluteSymbolDiffAsULEB128(EndLabel, BeginLabel);
1008+
}
10011009
emitLandingPad(CallSite.LP);
10021010
Streamer.emitULEB128IntValue(CallSite.Action);
10031011
}

0 commit comments

Comments
 (0)