aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:30 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:30 +0300
commit2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch)
tree012bb94d777798f1f56ac1cec429509766d05181 /contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp
parent6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff)
downloadydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp')
-rw-r--r--contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp598
1 files changed, 299 insertions, 299 deletions
diff --git a/contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index 2ffe8a7b04..76b737c3d4 100644
--- a/contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/contrib/libs/llvm12/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -44,9 +44,9 @@ EHStreamer::~EHStreamer() = default;
unsigned EHStreamer::sharedTypeIDs(const LandingPadInfo *L,
const LandingPadInfo *R) {
const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
- return std::mismatch(LIds.begin(), LIds.end(), RIds.begin(), RIds.end())
- .first -
- LIds.begin();
+ return std::mismatch(LIds.begin(), LIds.end(), RIds.begin(), RIds.end())
+ .first -
+ LIds.begin();
}
/// Compute the actions table and gather the first action index for each landing
@@ -214,30 +214,30 @@ void EHStreamer::computePadMap(
/// the landing pad and the action. Calls marked 'nounwind' have no entry and
/// must not be contained in the try-range of any entry - they form gaps in the
/// table. Entries must be ordered by try-range address.
-///
-/// Call-sites are split into one or more call-site ranges associated with
-/// different sections of the function.
-///
-/// - Without -basic-block-sections, all call-sites are grouped into one
-/// call-site-range corresponding to the function section.
-///
-/// - With -basic-block-sections, one call-site range is created for each
-/// section, with its FragmentBeginLabel and FragmentEndLabel respectively
-// set to the beginning and ending of the corresponding section and its
-// ExceptionLabel set to the exception symbol dedicated for this section.
-// Later, one LSDA header will be emitted for each call-site range with its
-// call-sites following. The action table and type info table will be
-// shared across all ranges.
-void EHStreamer::computeCallSiteTable(
- SmallVectorImpl<CallSiteEntry> &CallSites,
- SmallVectorImpl<CallSiteRange> &CallSiteRanges,
- const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
- const SmallVectorImpl<unsigned> &FirstActions) {
+///
+/// Call-sites are split into one or more call-site ranges associated with
+/// different sections of the function.
+///
+/// - Without -basic-block-sections, all call-sites are grouped into one
+/// call-site-range corresponding to the function section.
+///
+/// - With -basic-block-sections, one call-site range is created for each
+/// section, with its FragmentBeginLabel and FragmentEndLabel respectively
+// set to the beginning and ending of the corresponding section and its
+// ExceptionLabel set to the exception symbol dedicated for this section.
+// Later, one LSDA header will be emitted for each call-site range with its
+// call-sites following. The action table and type info table will be
+// shared across all ranges.
+void EHStreamer::computeCallSiteTable(
+ SmallVectorImpl<CallSiteEntry> &CallSites,
+ SmallVectorImpl<CallSiteRange> &CallSiteRanges,
+ const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
+ const SmallVectorImpl<unsigned> &FirstActions) {
RangeMapType PadMap;
computePadMap(LandingPads, PadMap);
// The end label of the previous invoke or nounwind try-range.
- MCSymbol *LastLabel = Asm->getFunctionBegin();
+ MCSymbol *LastLabel = Asm->getFunctionBegin();
// Whether there is a potentially throwing instruction (currently this means
// an ordinary call) between the end of the previous try-range and now.
@@ -250,21 +250,21 @@ void EHStreamer::computeCallSiteTable(
// Visit all instructions in order of address.
for (const auto &MBB : *Asm->MF) {
- if (&MBB == &Asm->MF->front() || MBB.isBeginSection()) {
- // We start a call-site range upon function entry and at the beginning of
- // every basic block section.
- CallSiteRanges.push_back(
- {Asm->MBBSectionRanges[MBB.getSectionIDNum()].BeginLabel,
- Asm->MBBSectionRanges[MBB.getSectionIDNum()].EndLabel,
- Asm->getMBBExceptionSym(MBB), CallSites.size()});
- PreviousIsInvoke = false;
- SawPotentiallyThrowing = false;
- LastLabel = nullptr;
- }
-
- if (MBB.isEHPad())
- CallSiteRanges.back().IsLPRange = true;
-
+ if (&MBB == &Asm->MF->front() || MBB.isBeginSection()) {
+ // We start a call-site range upon function entry and at the beginning of
+ // every basic block section.
+ CallSiteRanges.push_back(
+ {Asm->MBBSectionRanges[MBB.getSectionIDNum()].BeginLabel,
+ Asm->MBBSectionRanges[MBB.getSectionIDNum()].EndLabel,
+ Asm->getMBBExceptionSym(MBB), CallSites.size()});
+ PreviousIsInvoke = false;
+ SawPotentiallyThrowing = false;
+ LastLabel = nullptr;
+ }
+
+ if (MBB.isEHPad())
+ CallSiteRanges.back().IsLPRange = true;
+
for (const auto &MI : MBB) {
if (!MI.isEHLabel()) {
if (MI.isCall())
@@ -288,14 +288,14 @@ void EHStreamer::computeCallSiteTable(
assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
"Inconsistent landing pad map!");
- // For Dwarf and AIX exception handling (SjLj handling doesn't use this).
- // If some instruction between the previous try-range and this one may
- // throw, create a call-site entry with no landing pad for the region
- // between the try-ranges.
- if (SawPotentiallyThrowing &&
- (Asm->MAI->usesCFIForEH() ||
- Asm->MAI->getExceptionHandlingType() == ExceptionHandling::AIX)) {
- CallSites.push_back({LastLabel, BeginLabel, nullptr, 0});
+ // For Dwarf and AIX exception handling (SjLj handling doesn't use this).
+ // If some instruction between the previous try-range and this one may
+ // throw, create a call-site entry with no landing pad for the region
+ // between the try-ranges.
+ if (SawPotentiallyThrowing &&
+ (Asm->MAI->usesCFIForEH() ||
+ Asm->MAI->getExceptionHandlingType() == ExceptionHandling::AIX)) {
+ CallSites.push_back({LastLabel, BeginLabel, nullptr, 0});
PreviousIsInvoke = false;
}
@@ -339,20 +339,20 @@ void EHStreamer::computeCallSiteTable(
}
}
- // We end the call-site range upon function exit and at the end of every
- // basic block section.
- if (&MBB == &Asm->MF->back() || MBB.isEndSection()) {
- // If some instruction between the previous try-range and the end of the
- // function may throw, create a call-site entry with no landing pad for
- // the region following the try-range.
- if (SawPotentiallyThrowing && !IsSJLJ) {
- CallSiteEntry Site = {LastLabel, CallSiteRanges.back().FragmentEndLabel,
- nullptr, 0};
- CallSites.push_back(Site);
- SawPotentiallyThrowing = false;
- }
- CallSiteRanges.back().CallSiteEndIdx = CallSites.size();
- }
+ // We end the call-site range upon function exit and at the end of every
+ // basic block section.
+ if (&MBB == &Asm->MF->back() || MBB.isEndSection()) {
+ // If some instruction between the previous try-range and the end of the
+ // function may throw, create a call-site entry with no landing pad for
+ // the region following the try-range.
+ if (SawPotentiallyThrowing && !IsSJLJ) {
+ CallSiteEntry Site = {LastLabel, CallSiteRanges.back().FragmentEndLabel,
+ nullptr, 0};
+ CallSites.push_back(Site);
+ SawPotentiallyThrowing = false;
+ }
+ CallSiteRanges.back().CallSiteEndIdx = CallSites.size();
+ }
}
}
@@ -403,25 +403,25 @@ MCSymbol *EHStreamer::emitExceptionTable() {
SmallVector<unsigned, 64> FirstActions;
computeActionsTable(LandingPads, Actions, FirstActions);
- // Compute the call-site table and call-site ranges. Normally, there is only
- // one call-site-range which covers the whole funciton. With
- // -basic-block-sections, there is one call-site-range per basic block
- // section.
+ // Compute the call-site table and call-site ranges. Normally, there is only
+ // one call-site-range which covers the whole funciton. With
+ // -basic-block-sections, there is one call-site-range per basic block
+ // section.
SmallVector<CallSiteEntry, 64> CallSites;
- SmallVector<CallSiteRange, 4> CallSiteRanges;
- computeCallSiteTable(CallSites, CallSiteRanges, LandingPads, FirstActions);
+ SmallVector<CallSiteRange, 4> CallSiteRanges;
+ computeCallSiteTable(CallSites, CallSiteRanges, LandingPads, FirstActions);
bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
bool IsWasm = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::Wasm;
- bool HasLEB128Directives = Asm->MAI->hasLEB128Directives();
+ bool HasLEB128Directives = Asm->MAI->hasLEB128Directives();
unsigned CallSiteEncoding =
IsSJLJ ? static_cast<unsigned>(dwarf::DW_EH_PE_udata4) :
Asm->getObjFileLowering().getCallSiteEncoding();
bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
// Type infos.
- MCSection *LSDASection =
- Asm->getObjFileLowering().getSectionForLSDA(MF->getFunction(), Asm->TM);
+ MCSection *LSDASection =
+ Asm->getObjFileLowering().getSectionForLSDA(MF->getFunction(), Asm->TM);
unsigned TTypeEncoding;
if (!HaveTTData) {
@@ -471,122 +471,122 @@ MCSymbol *EHStreamer::emitExceptionTable() {
Asm->OutContext.getOrCreateSymbol(Twine("GCC_except_table")+
Twine(Asm->getFunctionNumber()));
Asm->OutStreamer->emitLabel(GCCETSym);
- MCSymbol *CstEndLabel = Asm->createTempSymbol(
- CallSiteRanges.size() > 1 ? "action_table_base" : "cst_end");
+ MCSymbol *CstEndLabel = Asm->createTempSymbol(
+ CallSiteRanges.size() > 1 ? "action_table_base" : "cst_end");
MCSymbol *TTBaseLabel = nullptr;
- if (HaveTTData)
+ if (HaveTTData)
TTBaseLabel = Asm->createTempSymbol("ttbase");
- const bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
-
- // Helper for emitting references (offsets) for type table and the end of the
- // call-site table (which marks the beginning of the action table).
- // * For Itanium, these references will be emitted for every callsite range.
- // * For SJLJ and Wasm, they will be emitted only once in the LSDA header.
- auto EmitTypeTableRefAndCallSiteTableEndRef = [&]() {
- Asm->emitEncodingByte(TTypeEncoding, "@TType");
- if (HaveTTData) {
- // N.B.: There is a dependency loop between the size of the TTBase uleb128
- // here and the amount of padding before the aligned type table. The
- // assembler must sometimes pad this uleb128 or insert extra padding
- // before the type table. See PR35809 or GNU as bug 4029.
- MCSymbol *TTBaseRefLabel = Asm->createTempSymbol("ttbaseref");
- Asm->emitLabelDifferenceAsULEB128(TTBaseLabel, TTBaseRefLabel);
- Asm->OutStreamer->emitLabel(TTBaseRefLabel);
- }
-
- // The Action table follows the call-site table. So we emit the
- // label difference from here (start of the call-site table for SJLJ and
- // Wasm, and start of a call-site range for Itanium) to the end of the
- // whole call-site table (end of the last call-site range for Itanium).
- MCSymbol *CstBeginLabel = Asm->createTempSymbol("cst_begin");
- Asm->emitEncodingByte(CallSiteEncoding, "Call site");
- Asm->emitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel);
- Asm->OutStreamer->emitLabel(CstBeginLabel);
- };
-
- // An alternative path to EmitTypeTableRefAndCallSiteTableEndRef.
- // For some platforms, the system assembler does not accept the form of
- // `.uleb128 label2 - label1`. In those situations, we would need to calculate
- // the size between label1 and label2 manually.
- // In this case, we would need to calculate the LSDA size and the call
- // site table size.
- auto EmitTypeTableOffsetAndCallSiteTableOffset = [&]() {
- assert(CallSiteEncoding == dwarf::DW_EH_PE_udata4 && !HasLEB128Directives &&
- "Targets supporting .uleb128 do not need to take this path.");
- if (CallSiteRanges.size() > 1)
- report_fatal_error(
- "-fbasic-block-sections is not yet supported on "
- "platforms that do not have general LEB128 directive support.");
-
- uint64_t CallSiteTableSize = 0;
- const CallSiteRange &CSRange = CallSiteRanges.back();
- for (size_t CallSiteIdx = CSRange.CallSiteBeginIdx;
- CallSiteIdx < CSRange.CallSiteEndIdx; ++CallSiteIdx) {
- const CallSiteEntry &S = CallSites[CallSiteIdx];
- // Each call site entry consists of 3 udata4 fields (12 bytes) and
- // 1 ULEB128 field.
- CallSiteTableSize += 12 + getULEB128Size(S.Action);
- assert(isUInt<32>(CallSiteTableSize) && "CallSiteTableSize overflows.");
- }
-
- Asm->emitEncodingByte(TTypeEncoding, "@TType");
- if (HaveTTData) {
- const unsigned ByteSizeOfCallSiteOffset =
- getULEB128Size(CallSiteTableSize);
- uint64_t ActionTableSize = 0;
- for (const ActionEntry &Action : Actions) {
- // Each action entry consists of two SLEB128 fields.
- ActionTableSize += getSLEB128Size(Action.ValueForTypeID) +
- getSLEB128Size(Action.NextAction);
- assert(isUInt<32>(ActionTableSize) && "ActionTableSize overflows.");
- }
-
- const unsigned TypeInfoSize =
- Asm->GetSizeOfEncodedValue(TTypeEncoding) * MF->getTypeInfos().size();
-
- const uint64_t LSDASizeBeforeAlign =
- 1 // Call site encoding byte.
- + ByteSizeOfCallSiteOffset // ULEB128 encoding of CallSiteTableSize.
- + CallSiteTableSize // Call site table content.
- + ActionTableSize; // Action table content.
-
- const uint64_t LSDASizeWithoutAlign = LSDASizeBeforeAlign + TypeInfoSize;
- const unsigned ByteSizeOfLSDAWithoutAlign =
- getULEB128Size(LSDASizeWithoutAlign);
- const uint64_t DisplacementBeforeAlign =
- 2 // LPStartEncoding and TypeTableEncoding.
- + ByteSizeOfLSDAWithoutAlign + LSDASizeBeforeAlign;
-
- // The type info area starts with 4 byte alignment.
- const unsigned NeedAlignVal = (4 - DisplacementBeforeAlign % 4) % 4;
- uint64_t LSDASizeWithAlign = LSDASizeWithoutAlign + NeedAlignVal;
- const unsigned ByteSizeOfLSDAWithAlign =
- getULEB128Size(LSDASizeWithAlign);
-
- // The LSDASizeWithAlign could use 1 byte less padding for alignment
- // when the data we use to represent the LSDA Size "needs" to be 1 byte
- // larger than the one previously calculated without alignment.
- if (ByteSizeOfLSDAWithAlign > ByteSizeOfLSDAWithoutAlign)
- LSDASizeWithAlign -= 1;
-
- Asm->OutStreamer->emitULEB128IntValue(LSDASizeWithAlign,
- ByteSizeOfLSDAWithAlign);
- }
-
- Asm->emitEncodingByte(CallSiteEncoding, "Call site");
- Asm->OutStreamer->emitULEB128IntValue(CallSiteTableSize);
- };
-
+ const bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
+
+ // Helper for emitting references (offsets) for type table and the end of the
+ // call-site table (which marks the beginning of the action table).
+ // * For Itanium, these references will be emitted for every callsite range.
+ // * For SJLJ and Wasm, they will be emitted only once in the LSDA header.
+ auto EmitTypeTableRefAndCallSiteTableEndRef = [&]() {
+ Asm->emitEncodingByte(TTypeEncoding, "@TType");
+ if (HaveTTData) {
+ // N.B.: There is a dependency loop between the size of the TTBase uleb128
+ // here and the amount of padding before the aligned type table. The
+ // assembler must sometimes pad this uleb128 or insert extra padding
+ // before the type table. See PR35809 or GNU as bug 4029.
+ MCSymbol *TTBaseRefLabel = Asm->createTempSymbol("ttbaseref");
+ Asm->emitLabelDifferenceAsULEB128(TTBaseLabel, TTBaseRefLabel);
+ Asm->OutStreamer->emitLabel(TTBaseRefLabel);
+ }
+
+ // The Action table follows the call-site table. So we emit the
+ // label difference from here (start of the call-site table for SJLJ and
+ // Wasm, and start of a call-site range for Itanium) to the end of the
+ // whole call-site table (end of the last call-site range for Itanium).
+ MCSymbol *CstBeginLabel = Asm->createTempSymbol("cst_begin");
+ Asm->emitEncodingByte(CallSiteEncoding, "Call site");
+ Asm->emitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel);
+ Asm->OutStreamer->emitLabel(CstBeginLabel);
+ };
+
+ // An alternative path to EmitTypeTableRefAndCallSiteTableEndRef.
+ // For some platforms, the system assembler does not accept the form of
+ // `.uleb128 label2 - label1`. In those situations, we would need to calculate
+ // the size between label1 and label2 manually.
+ // In this case, we would need to calculate the LSDA size and the call
+ // site table size.
+ auto EmitTypeTableOffsetAndCallSiteTableOffset = [&]() {
+ assert(CallSiteEncoding == dwarf::DW_EH_PE_udata4 && !HasLEB128Directives &&
+ "Targets supporting .uleb128 do not need to take this path.");
+ if (CallSiteRanges.size() > 1)
+ report_fatal_error(
+ "-fbasic-block-sections is not yet supported on "
+ "platforms that do not have general LEB128 directive support.");
+
+ uint64_t CallSiteTableSize = 0;
+ const CallSiteRange &CSRange = CallSiteRanges.back();
+ for (size_t CallSiteIdx = CSRange.CallSiteBeginIdx;
+ CallSiteIdx < CSRange.CallSiteEndIdx; ++CallSiteIdx) {
+ const CallSiteEntry &S = CallSites[CallSiteIdx];
+ // Each call site entry consists of 3 udata4 fields (12 bytes) and
+ // 1 ULEB128 field.
+ CallSiteTableSize += 12 + getULEB128Size(S.Action);
+ assert(isUInt<32>(CallSiteTableSize) && "CallSiteTableSize overflows.");
+ }
+
+ Asm->emitEncodingByte(TTypeEncoding, "@TType");
+ if (HaveTTData) {
+ const unsigned ByteSizeOfCallSiteOffset =
+ getULEB128Size(CallSiteTableSize);
+ uint64_t ActionTableSize = 0;
+ for (const ActionEntry &Action : Actions) {
+ // Each action entry consists of two SLEB128 fields.
+ ActionTableSize += getSLEB128Size(Action.ValueForTypeID) +
+ getSLEB128Size(Action.NextAction);
+ assert(isUInt<32>(ActionTableSize) && "ActionTableSize overflows.");
+ }
+
+ const unsigned TypeInfoSize =
+ Asm->GetSizeOfEncodedValue(TTypeEncoding) * MF->getTypeInfos().size();
+
+ const uint64_t LSDASizeBeforeAlign =
+ 1 // Call site encoding byte.
+ + ByteSizeOfCallSiteOffset // ULEB128 encoding of CallSiteTableSize.
+ + CallSiteTableSize // Call site table content.
+ + ActionTableSize; // Action table content.
+
+ const uint64_t LSDASizeWithoutAlign = LSDASizeBeforeAlign + TypeInfoSize;
+ const unsigned ByteSizeOfLSDAWithoutAlign =
+ getULEB128Size(LSDASizeWithoutAlign);
+ const uint64_t DisplacementBeforeAlign =
+ 2 // LPStartEncoding and TypeTableEncoding.
+ + ByteSizeOfLSDAWithoutAlign + LSDASizeBeforeAlign;
+
+ // The type info area starts with 4 byte alignment.
+ const unsigned NeedAlignVal = (4 - DisplacementBeforeAlign % 4) % 4;
+ uint64_t LSDASizeWithAlign = LSDASizeWithoutAlign + NeedAlignVal;
+ const unsigned ByteSizeOfLSDAWithAlign =
+ getULEB128Size(LSDASizeWithAlign);
+
+ // The LSDASizeWithAlign could use 1 byte less padding for alignment
+ // when the data we use to represent the LSDA Size "needs" to be 1 byte
+ // larger than the one previously calculated without alignment.
+ if (ByteSizeOfLSDAWithAlign > ByteSizeOfLSDAWithoutAlign)
+ LSDASizeWithAlign -= 1;
+
+ Asm->OutStreamer->emitULEB128IntValue(LSDASizeWithAlign,
+ ByteSizeOfLSDAWithAlign);
+ }
+
+ Asm->emitEncodingByte(CallSiteEncoding, "Call site");
+ Asm->OutStreamer->emitULEB128IntValue(CallSiteTableSize);
+ };
+
// SjLj / Wasm Exception handling
if (IsSJLJ || IsWasm) {
- Asm->OutStreamer->emitLabel(Asm->getMBBExceptionSym(Asm->MF->front()));
-
- // emit the LSDA header.
- Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
- EmitTypeTableRefAndCallSiteTableEndRef();
-
+ Asm->OutStreamer->emitLabel(Asm->getMBBExceptionSym(Asm->MF->front()));
+
+ // emit the LSDA header.
+ Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
+ EmitTypeTableRefAndCallSiteTableEndRef();
+
unsigned idx = 0;
for (SmallVectorImpl<CallSiteEntry>::const_iterator
I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) {
@@ -611,7 +611,7 @@ MCSymbol *EHStreamer::emitExceptionTable() {
}
Asm->emitULEB128(S.Action);
}
- Asm->OutStreamer->emitLabel(CstEndLabel);
+ Asm->OutStreamer->emitLabel(CstEndLabel);
} else {
// Itanium LSDA exception handling
@@ -633,126 +633,126 @@ MCSymbol *EHStreamer::emitExceptionTable() {
// A missing entry in the call-site table indicates that a call is not
// supposed to throw.
- assert(CallSiteRanges.size() != 0 && "No call-site ranges!");
-
- // There should be only one call-site range which includes all the landing
- // pads. Find that call-site range here.
- const CallSiteRange *LandingPadRange = nullptr;
- for (const CallSiteRange &CSRange : CallSiteRanges) {
- if (CSRange.IsLPRange) {
- assert(LandingPadRange == nullptr &&
- "All landing pads must be in a single callsite range.");
- LandingPadRange = &CSRange;
- }
- }
-
- // The call-site table is split into its call-site ranges, each being
- // emitted as:
- // [ LPStartEncoding | LPStart ]
- // [ TypeTableEncoding | TypeTableOffset ]
- // [ CallSiteEncoding | CallSiteTableEndOffset ]
- // cst_begin -> { call-site entries contained in this range }
- //
- // and is followed by the next call-site range.
- //
- // For each call-site range, CallSiteTableEndOffset is computed as the
- // difference between cst_begin of that range and the last call-site-table's
- // end label. This offset is used to find the action table.
-
+ assert(CallSiteRanges.size() != 0 && "No call-site ranges!");
+
+ // There should be only one call-site range which includes all the landing
+ // pads. Find that call-site range here.
+ const CallSiteRange *LandingPadRange = nullptr;
+ for (const CallSiteRange &CSRange : CallSiteRanges) {
+ if (CSRange.IsLPRange) {
+ assert(LandingPadRange == nullptr &&
+ "All landing pads must be in a single callsite range.");
+ LandingPadRange = &CSRange;
+ }
+ }
+
+ // The call-site table is split into its call-site ranges, each being
+ // emitted as:
+ // [ LPStartEncoding | LPStart ]
+ // [ TypeTableEncoding | TypeTableOffset ]
+ // [ CallSiteEncoding | CallSiteTableEndOffset ]
+ // cst_begin -> { call-site entries contained in this range }
+ //
+ // and is followed by the next call-site range.
+ //
+ // For each call-site range, CallSiteTableEndOffset is computed as the
+ // difference between cst_begin of that range and the last call-site-table's
+ // end label. This offset is used to find the action table.
+
unsigned Entry = 0;
- for (const CallSiteRange &CSRange : CallSiteRanges) {
- if (CSRange.CallSiteBeginIdx != 0) {
- // Align the call-site range for all ranges except the first. The
- // first range is already aligned due to the exception table alignment.
- Asm->emitAlignment(Align(4));
- }
- Asm->OutStreamer->emitLabel(CSRange.ExceptionLabel);
-
- // Emit the LSDA header.
- // If only one call-site range exists, LPStart is omitted as it is the
- // same as the function entry.
- if (CallSiteRanges.size() == 1) {
- Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
- } else if (!Asm->isPositionIndependent()) {
- // For more than one call-site ranges, LPStart must be explicitly
- // specified.
- // For non-PIC we can simply use the absolute value.
- Asm->emitEncodingByte(dwarf::DW_EH_PE_absptr, "@LPStart");
- Asm->OutStreamer->emitSymbolValue(LandingPadRange->FragmentBeginLabel,
- Asm->MAI->getCodePointerSize());
- } else {
- // For PIC mode, we Emit a PC-relative address for LPStart.
- Asm->emitEncodingByte(dwarf::DW_EH_PE_pcrel, "@LPStart");
- MCContext &Context = Asm->OutStreamer->getContext();
- MCSymbol *Dot = Context.createTempSymbol();
- Asm->OutStreamer->emitLabel(Dot);
- Asm->OutStreamer->emitValue(
- MCBinaryExpr::createSub(
- MCSymbolRefExpr::create(LandingPadRange->FragmentBeginLabel,
- Context),
- MCSymbolRefExpr::create(Dot, Context), Context),
- Asm->MAI->getCodePointerSize());
- }
-
- if (HasLEB128Directives)
- EmitTypeTableRefAndCallSiteTableEndRef();
- else
- EmitTypeTableOffsetAndCallSiteTableOffset();
-
- for (size_t CallSiteIdx = CSRange.CallSiteBeginIdx;
- CallSiteIdx != CSRange.CallSiteEndIdx; ++CallSiteIdx) {
- const CallSiteEntry &S = CallSites[CallSiteIdx];
-
- MCSymbol *EHFuncBeginSym = CSRange.FragmentBeginLabel;
- MCSymbol *EHFuncEndSym = CSRange.FragmentEndLabel;
-
- MCSymbol *BeginLabel = S.BeginLabel;
- if (!BeginLabel)
- BeginLabel = EHFuncBeginSym;
- MCSymbol *EndLabel = S.EndLabel;
- if (!EndLabel)
- EndLabel = EHFuncEndSym;
-
- // Offset of the call site relative to the start of the procedure.
+ for (const CallSiteRange &CSRange : CallSiteRanges) {
+ if (CSRange.CallSiteBeginIdx != 0) {
+ // Align the call-site range for all ranges except the first. The
+ // first range is already aligned due to the exception table alignment.
+ Asm->emitAlignment(Align(4));
+ }
+ Asm->OutStreamer->emitLabel(CSRange.ExceptionLabel);
+
+ // Emit the LSDA header.
+ // If only one call-site range exists, LPStart is omitted as it is the
+ // same as the function entry.
+ if (CallSiteRanges.size() == 1) {
+ Asm->emitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
+ } else if (!Asm->isPositionIndependent()) {
+ // For more than one call-site ranges, LPStart must be explicitly
+ // specified.
+ // For non-PIC we can simply use the absolute value.
+ Asm->emitEncodingByte(dwarf::DW_EH_PE_absptr, "@LPStart");
+ Asm->OutStreamer->emitSymbolValue(LandingPadRange->FragmentBeginLabel,
+ Asm->MAI->getCodePointerSize());
+ } else {
+ // For PIC mode, we Emit a PC-relative address for LPStart.
+ Asm->emitEncodingByte(dwarf::DW_EH_PE_pcrel, "@LPStart");
+ MCContext &Context = Asm->OutStreamer->getContext();
+ MCSymbol *Dot = Context.createTempSymbol();
+ Asm->OutStreamer->emitLabel(Dot);
+ Asm->OutStreamer->emitValue(
+ MCBinaryExpr::createSub(
+ MCSymbolRefExpr::create(LandingPadRange->FragmentBeginLabel,
+ Context),
+ MCSymbolRefExpr::create(Dot, Context), Context),
+ Asm->MAI->getCodePointerSize());
+ }
+
+ if (HasLEB128Directives)
+ EmitTypeTableRefAndCallSiteTableEndRef();
+ else
+ EmitTypeTableOffsetAndCallSiteTableOffset();
+
+ for (size_t CallSiteIdx = CSRange.CallSiteBeginIdx;
+ CallSiteIdx != CSRange.CallSiteEndIdx; ++CallSiteIdx) {
+ const CallSiteEntry &S = CallSites[CallSiteIdx];
+
+ MCSymbol *EHFuncBeginSym = CSRange.FragmentBeginLabel;
+ MCSymbol *EHFuncEndSym = CSRange.FragmentEndLabel;
+
+ MCSymbol *BeginLabel = S.BeginLabel;
+ if (!BeginLabel)
+ BeginLabel = EHFuncBeginSym;
+ MCSymbol *EndLabel = S.EndLabel;
+ if (!EndLabel)
+ EndLabel = EHFuncEndSym;
+
+ // Offset of the call site relative to the start of the procedure.
if (VerboseAsm)
- Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) +
- " <<");
- Asm->emitCallSiteOffset(BeginLabel, EHFuncBeginSym, CallSiteEncoding);
+ Asm->OutStreamer->AddComment(">> Call Site " + Twine(++Entry) +
+ " <<");
+ Asm->emitCallSiteOffset(BeginLabel, EHFuncBeginSym, CallSiteEncoding);
if (VerboseAsm)
- Asm->OutStreamer->AddComment(Twine(" Call between ") +
- BeginLabel->getName() + " and " +
- EndLabel->getName());
- Asm->emitCallSiteOffset(EndLabel, BeginLabel, CallSiteEncoding);
-
- // Offset of the landing pad relative to the start of the landing pad
- // fragment.
- if (!S.LPad) {
- if (VerboseAsm)
- Asm->OutStreamer->AddComment(" has no landing pad");
- Asm->emitCallSiteValue(0, CallSiteEncoding);
- } else {
- if (VerboseAsm)
- Asm->OutStreamer->AddComment(Twine(" jumps to ") +
- S.LPad->LandingPadLabel->getName());
- Asm->emitCallSiteOffset(S.LPad->LandingPadLabel,
- LandingPadRange->FragmentBeginLabel,
- CallSiteEncoding);
- }
-
- // Offset of the first associated action record, relative to the start
- // of the action table. This value is biased by 1 (1 indicates the start
- // of the action table), and 0 indicates that there are no actions.
- if (VerboseAsm) {
- if (S.Action == 0)
- Asm->OutStreamer->AddComment(" On action: cleanup");
- else
- Asm->OutStreamer->AddComment(" On action: " +
- Twine((S.Action - 1) / 2 + 1));
- }
- Asm->emitULEB128(S.Action);
+ Asm->OutStreamer->AddComment(Twine(" Call between ") +
+ BeginLabel->getName() + " and " +
+ EndLabel->getName());
+ Asm->emitCallSiteOffset(EndLabel, BeginLabel, CallSiteEncoding);
+
+ // Offset of the landing pad relative to the start of the landing pad
+ // fragment.
+ if (!S.LPad) {
+ if (VerboseAsm)
+ Asm->OutStreamer->AddComment(" has no landing pad");
+ Asm->emitCallSiteValue(0, CallSiteEncoding);
+ } else {
+ if (VerboseAsm)
+ Asm->OutStreamer->AddComment(Twine(" jumps to ") +
+ S.LPad->LandingPadLabel->getName());
+ Asm->emitCallSiteOffset(S.LPad->LandingPadLabel,
+ LandingPadRange->FragmentBeginLabel,
+ CallSiteEncoding);
+ }
+
+ // Offset of the first associated action record, relative to the start
+ // of the action table. This value is biased by 1 (1 indicates the start
+ // of the action table), and 0 indicates that there are no actions.
+ if (VerboseAsm) {
+ if (S.Action == 0)
+ Asm->OutStreamer->AddComment(" On action: cleanup");
+ else
+ Asm->OutStreamer->AddComment(" On action: " +
+ Twine((S.Action - 1) / 2 + 1));
+ }
+ Asm->emitULEB128(S.Action);
}
}
- Asm->OutStreamer->emitLabel(CstEndLabel);
+ Asm->OutStreamer->emitLabel(CstEndLabel);
}
// Emit the Action Table.
@@ -784,11 +784,11 @@ MCSymbol *EHStreamer::emitExceptionTable() {
// Action Record
if (VerboseAsm) {
- if (Action.Previous == unsigned(-1)) {
+ if (Action.Previous == unsigned(-1)) {
Asm->OutStreamer->AddComment(" No further actions");
} else {
- Asm->OutStreamer->AddComment(" Continue to action " +
- Twine(Action.Previous + 1));
+ Asm->OutStreamer->AddComment(" Continue to action " +
+ Twine(Action.Previous + 1));
}
}
Asm->emitSLEB128(Action.NextAction);
@@ -808,7 +808,7 @@ void EHStreamer::emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) {
const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
const std::vector<unsigned> &FilterIds = MF->getFilterIds();
- const bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
+ const bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
int Entry = 0;
// Emit the Catch TypeInfos.