Skip to content

Commit 3282be1

Browse files
authored
[BOLT] Use ULEB128 encoding for PIE/DSO exception tables (#116911)
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. For testing, we rely on runtime EH tests.
1 parent 86734c8 commit 3282be1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

bolt/lib/Core/BinaryEmitter.cpp

Lines changed: 15 additions & 8 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
}
@@ -976,10 +976,12 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
976976
Streamer.emitLabel(TTBaseRefLabel);
977977
}
978978

979-
// Emit the landing pad call site table. We use signed data4 since we can emit
980-
// a landing pad in a different part of the split function that could appear
981-
// earlier in the address space than LPStart.
982-
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
979+
// Emit encoding of entries in the call site table. The format is used for the
980+
// call site start, length, and corresponding landing pad.
981+
if (BC.HasFixedLoadAddress)
982+
Streamer.emitIntValue(dwarf::DW_EH_PE_sdata4, 1);
983+
else
984+
Streamer.emitIntValue(dwarf::DW_EH_PE_uleb128, 1);
983985

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

997999
// Start of the range is emitted relative to the start of current
9981000
// function split part.
999-
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
1000-
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1001+
if (BC.HasFixedLoadAddress) {
1002+
Streamer.emitAbsoluteSymbolDiff(BeginLabel, StartSymbol, 4);
1003+
Streamer.emitAbsoluteSymbolDiff(EndLabel, BeginLabel, 4);
1004+
} else {
1005+
Streamer.emitAbsoluteSymbolDiffAsULEB128(BeginLabel, StartSymbol);
1006+
Streamer.emitAbsoluteSymbolDiffAsULEB128(EndLabel, BeginLabel);
1007+
}
10011008
emitLandingPad(CallSite.LP);
10021009
Streamer.emitULEB128IntValue(CallSite.Action);
10031010
}

0 commit comments

Comments
 (0)