@@ -906,17 +906,6 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
906
906
if (Sites.empty ())
907
907
return ;
908
908
909
- // Calculate callsite table size. Size of each callsite entry is:
910
- //
911
- // sizeof(start) + sizeof(length) + sizeof(LP) + sizeof(uleb128(action))
912
- //
913
- // or
914
- //
915
- // sizeof(dwarf::DW_EH_PE_data4) * 3 + sizeof(uleb128(action))
916
- uint64_t CallSiteTableLength = llvm::size (Sites) * 4 * 3 ;
917
- for (const auto &FragmentCallSite : Sites)
918
- CallSiteTableLength += getULEB128Size (FragmentCallSite.second .Action );
919
-
920
909
Streamer.switchSection (BC.MOFI ->getLSDASection ());
921
910
922
911
const unsigned TTypeEncoding = BF.getLSDATypeEncoding ();
@@ -975,36 +964,24 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
975
964
976
965
Streamer.emitIntValue (TTypeEncoding, 1 ); // TType format
977
966
978
- // See the comment in EHStreamer::emitExceptionTable() on to use
979
- // uleb128 encoding (which can use variable number of bytes to encode the same
980
- // value) to ensure type info table is properly aligned at 4 bytes without
981
- // iteratively fixing sizes of the tables.
982
- unsigned CallSiteTableLengthSize = getULEB128Size (CallSiteTableLength);
983
- unsigned TTypeBaseOffset =
984
- sizeof (int8_t ) + // Call site format
985
- CallSiteTableLengthSize + // Call site table length size
986
- CallSiteTableLength + // Call site table length
987
- BF.getLSDAActionTable ().size () + // Actions table size
988
- BF.getLSDATypeTable ().size () * TTypeEncodingSize; // Types table size
989
- unsigned TTypeBaseOffsetSize = getULEB128Size (TTypeBaseOffset);
990
- unsigned TotalSize = sizeof (int8_t ) + // LPStart format
991
- sizeof (int8_t ) + // TType format
992
- TTypeBaseOffsetSize + // TType base offset size
993
- TTypeBaseOffset; // TType base offset
994
- unsigned SizeAlign = (4 - TotalSize) & 3 ;
995
-
996
- if (TTypeEncoding != dwarf::DW_EH_PE_omit)
997
- // Account for any extra padding that will be added to the call site table
998
- // length.
999
- Streamer.emitULEB128IntValue (TTypeBaseOffset,
1000
- /* PadTo=*/ TTypeBaseOffsetSize + SizeAlign);
967
+ MCSymbol *TTBaseLabel = nullptr ;
968
+ if (TTypeEncoding != dwarf::DW_EH_PE_omit) {
969
+ TTBaseLabel = BC.Ctx ->createTempSymbol (" TTBase" );
970
+ MCSymbol *TTBaseRefLabel = BC.Ctx ->createTempSymbol (" TTBaseRef" );
971
+ Streamer.emitAbsoluteSymbolDiffAsULEB128 (TTBaseLabel, TTBaseRefLabel);
972
+ Streamer.emitLabel (TTBaseRefLabel);
973
+ }
1001
974
1002
975
// Emit the landing pad call site table. We use signed data4 since we can emit
1003
976
// a landing pad in a different part of the split function that could appear
1004
977
// earlier in the address space than LPStart.
1005
978
Streamer.emitIntValue (dwarf::DW_EH_PE_sdata4, 1 );
1006
- Streamer.emitULEB128IntValue (CallSiteTableLength);
1007
979
980
+ MCSymbol *CSTStartLabel = BC.Ctx ->createTempSymbol (" CSTStart" );
981
+ MCSymbol *CSTEndLabel = BC.Ctx ->createTempSymbol (" CSTEnd" );
982
+ Streamer.emitAbsoluteSymbolDiffAsULEB128 (CSTEndLabel, CSTStartLabel);
983
+
984
+ Streamer.emitLabel (CSTStartLabel);
1008
985
for (const auto &FragmentCallSite : Sites) {
1009
986
const BinaryFunction::CallSite &CallSite = FragmentCallSite.second ;
1010
987
const MCSymbol *BeginLabel = CallSite.Start ;
@@ -1020,6 +997,7 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
1020
997
emitLandingPad (CallSite.LP );
1021
998
Streamer.emitULEB128IntValue (CallSite.Action );
1022
999
}
1000
+ Streamer.emitLabel (CSTEndLabel);
1023
1001
1024
1002
// Write out action, type, and type index tables at the end.
1025
1003
//
@@ -1038,6 +1016,8 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
1038
1016
assert (TypeTable.size () == BF.getLSDATypeTable ().size () &&
1039
1017
" indirect type table size mismatch" );
1040
1018
1019
+ Streamer.emitValueToAlignment (Align (TTypeAlignment));
1020
+
1041
1021
for (int Index = TypeTable.size () - 1 ; Index >= 0 ; --Index) {
1042
1022
const uint64_t TypeAddress = TypeTable[Index];
1043
1023
switch (TTypeEncoding & 0x70 ) {
@@ -1063,6 +1043,10 @@ void BinaryEmitter::emitLSDA(BinaryFunction &BF, const FunctionFragment &FF) {
1063
1043
}
1064
1044
}
1065
1045
}
1046
+
1047
+ if (TTypeEncoding != dwarf::DW_EH_PE_omit)
1048
+ Streamer.emitLabel (TTBaseLabel);
1049
+
1066
1050
for (uint8_t const &Byte : BF.getLSDATypeIndexTable ())
1067
1051
Streamer.emitIntValue (Byte, 1 );
1068
1052
}
0 commit comments