387 const std::vector<const GlobalValue *> &TypeInfos = MF->
getTypeInfos();
388 const std::vector<unsigned> &FilterIds = MF->
getFilterIds();
389 const std::vector<LandingPadInfo> &PadInfos = MF->
getLandingPads();
394 LandingPads.
reserve(PadInfos.size());
400 if (LPI.LandingPadLabel && !LPI.LandingPadLabel->isDefined())
407 return L->TypeIds < R->TypeIds;
426 bool HasLEB128Directives =
Asm->MAI.hasLEB128Directives();
427 unsigned CallSiteEncoding =
429 Asm->getObjFileLowering().getCallSiteEncoding();
430 bool HaveTTData = !TypeInfos.empty() || !FilterIds.empty();
433 MCSection *LSDASection =
Asm->getObjFileLowering().getSectionForLSDA(
435 unsigned TTypeEncoding;
469 TTypeEncoding =
Asm->getObjFileLowering().getTTypeEncoding();
476 Asm->OutStreamer->switchSection(LSDASection);
481 Asm->OutContext.getOrCreateSymbol(
Twine(
"GCC_except_table")+
483 Asm->OutStreamer->emitLabel(GCCETSym);
485 CallSiteRanges.
size() > 1 ?
"action_table_base" :
"cst_end");
489 TTBaseLabel =
Asm->createTempSymbol(
"ttbase");
491 const bool VerboseAsm =
Asm->OutStreamer->isVerboseAsm();
497 auto EmitTypeTableRefAndCallSiteTableEndRef = [&]() {
498 Asm->emitEncodingByte(TTypeEncoding,
"@TType");
504 MCSymbol *TTBaseRefLabel =
Asm->createTempSymbol(
"ttbaseref");
505 Asm->emitLabelDifferenceAsULEB128(TTBaseLabel, TTBaseRefLabel);
506 Asm->OutStreamer->emitLabel(TTBaseRefLabel);
513 MCSymbol *CstBeginLabel =
Asm->createTempSymbol(
"cst_begin");
514 Asm->emitEncodingByte(CallSiteEncoding,
"Call site");
515 Asm->emitLabelDifferenceAsULEB128(CstEndLabel, CstBeginLabel);
516 Asm->OutStreamer->emitLabel(CstBeginLabel);
525 auto EmitTypeTableOffsetAndCallSiteTableOffset = [&]() {
527 "Targets supporting .uleb128 do not need to take this path.");
528 if (CallSiteRanges.
size() > 1)
530 "-fbasic-block-sections is not yet supported on "
531 "platforms that do not have general LEB128 directive support.");
533 uint64_t CallSiteTableSize = 0;
544 Asm->emitEncodingByte(TTypeEncoding,
"@TType");
546 const unsigned ByteSizeOfCallSiteOffset =
548 uint64_t ActionTableSize = 0;
556 const unsigned TypeInfoSize =
559 const uint64_t LSDASizeBeforeAlign =
561 + ByteSizeOfCallSiteOffset
565 const uint64_t LSDASizeWithoutAlign = LSDASizeBeforeAlign + TypeInfoSize;
566 const unsigned ByteSizeOfLSDAWithoutAlign =
568 const uint64_t DisplacementBeforeAlign =
570 + ByteSizeOfLSDAWithoutAlign + LSDASizeBeforeAlign;
573 const unsigned NeedAlignVal = (4 - DisplacementBeforeAlign % 4) % 4;
574 uint64_t LSDASizeWithAlign = LSDASizeWithoutAlign + NeedAlignVal;
575 const unsigned ByteSizeOfLSDAWithAlign =
581 if (ByteSizeOfLSDAWithAlign > ByteSizeOfLSDAWithoutAlign)
582 LSDASizeWithAlign -= 1;
584 Asm->OutStreamer->emitULEB128IntValue(LSDASizeWithAlign,
585 ByteSizeOfLSDAWithAlign);
588 Asm->emitEncodingByte(CallSiteEncoding,
"Call site");
589 Asm->OutStreamer->emitULEB128IntValue(CallSiteTableSize);
593 if (IsSJLJ || IsWasm) {
594 Asm->OutStreamer->emitLabel(
Asm->getMBBExceptionSym(
Asm->MF->front()));
598 EmitTypeTableRefAndCallSiteTableEndRef();
602 I = CallSites.
begin(), E = CallSites.
end();
I != E; ++
I, ++idx) {
607 Asm->OutStreamer->AddComment(
">> Call Site " +
Twine(idx) +
" <<");
608 Asm->OutStreamer->AddComment(
" On exception at call site "+
Twine(idx));
610 Asm->emitULEB128(idx);
617 Asm->OutStreamer->AddComment(
" Action: cleanup");
619 Asm->OutStreamer->AddComment(
" Action: " +
624 Asm->OutStreamer->emitLabel(CstEndLabel);
646 assert(CallSiteRanges.
size() != 0 &&
"No call-site ranges!");
652 if (CSRange.IsLPRange) {
653 assert(LandingPadRange ==
nullptr &&
654 "All landing pads must be in a single callsite range.");
655 LandingPadRange = &CSRange;
674 if (CSRange.CallSiteBeginIdx != 0) {
679 Asm->OutStreamer->emitLabel(CSRange.ExceptionLabel);
685 if (CallSiteRanges.size() == 1 || LandingPadRange ==
nullptr) {
687 }
else if (!
Asm->isPositionIndependent()) {
693 Asm->MAI.getCodePointerSize());
698 MCSymbol *Dot = Context.createTempSymbol();
699 Asm->OutStreamer->emitLabel(Dot);
700 Asm->OutStreamer->emitValue(
705 Asm->MAI.getCodePointerSize());
708 if (HasLEB128Directives)
709 EmitTypeTableRefAndCallSiteTableEndRef();
711 EmitTypeTableOffsetAndCallSiteTableOffset();
713 for (
size_t CallSiteIdx = CSRange.CallSiteBeginIdx;
714 CallSiteIdx != CSRange.CallSiteEndIdx; ++CallSiteIdx) {
717 MCSymbol *EHFuncBeginSym = CSRange.FragmentBeginLabel;
718 MCSymbol *EHFuncEndSym = CSRange.FragmentEndLabel;
722 BeginLabel = EHFuncBeginSym;
725 EndLabel = EHFuncEndSym;
729 Asm->OutStreamer->AddComment(
">> Call Site " +
Twine(++Entry) +
731 Asm->emitCallSiteOffset(BeginLabel, EHFuncBeginSym, CallSiteEncoding);
733 Asm->OutStreamer->AddComment(
Twine(
" Call between ") +
734 BeginLabel->
getName() +
" and " +
736 Asm->emitCallSiteOffset(EndLabel, BeginLabel, CallSiteEncoding);
742 Asm->OutStreamer->AddComment(
" has no landing pad");
743 Asm->emitCallSiteValue(0, CallSiteEncoding);
746 Asm->OutStreamer->AddComment(
Twine(
" jumps to ") +
758 Asm->OutStreamer->AddComment(
" On action: cleanup");
760 Asm->OutStreamer->AddComment(
" On action: " +
766 Asm->OutStreamer->emitLabel(CstEndLabel);
774 Asm->OutStreamer->AddComment(
">> Action Record " +
Twine(++Entry) +
" <<");
782 if (Action.ValueForTypeID > 0)
783 Asm->OutStreamer->AddComment(
" Catch TypeInfo " +
784 Twine(Action.ValueForTypeID));
785 else if (Action.ValueForTypeID < 0)
786 Asm->OutStreamer->AddComment(
" Filter TypeInfo " +
787 Twine(Action.ValueForTypeID));
789 Asm->OutStreamer->AddComment(
" Cleanup");
791 Asm->emitSLEB128(Action.ValueForTypeID);
795 if (Action.Previous ==
unsigned(-1)) {
796 Asm->OutStreamer->AddComment(
" No further actions");
798 Asm->OutStreamer->AddComment(
" Continue to action " +
799 Twine(Action.Previous + 1));
802 Asm->emitSLEB128(Action.NextAction);