@@ -733,121 +733,5 @@ Error MachOLinkGraphBuilder::graphifyCStringSection(
733733 return Error::success ();
734734}
735735
736- Error CompactUnwindSplitter::operator ()(LinkGraph &G) {
737- auto *CUSec = G.findSectionByName (CompactUnwindSectionName);
738- if (!CUSec)
739- return Error::success ();
740-
741- if (!G.getTargetTriple ().isOSBinFormatMachO ())
742- return make_error<JITLinkError>(
743- " Error linking " + G.getName () +
744- " : compact unwind splitting not supported on non-macho target " +
745- G.getTargetTriple ().str ());
746-
747- unsigned CURecordSize = 0 ;
748- unsigned PersonalityEdgeOffset = 0 ;
749- unsigned LSDAEdgeOffset = 0 ;
750- switch (G.getTargetTriple ().getArch ()) {
751- case Triple::aarch64:
752- case Triple::x86_64:
753- // 64-bit compact-unwind record format:
754- // Range start: 8 bytes.
755- // Range size: 4 bytes.
756- // CU encoding: 4 bytes.
757- // Personality: 8 bytes.
758- // LSDA: 8 bytes.
759- CURecordSize = 32 ;
760- PersonalityEdgeOffset = 16 ;
761- LSDAEdgeOffset = 24 ;
762- break ;
763- default :
764- return make_error<JITLinkError>(
765- " Error linking " + G.getName () +
766- " : compact unwind splitting not supported on " +
767- G.getTargetTriple ().getArchName ());
768- }
769-
770- std::vector<Block *> OriginalBlocks (CUSec->blocks ().begin (),
771- CUSec->blocks ().end ());
772- LLVM_DEBUG ({
773- dbgs () << " In " << G.getName () << " splitting compact unwind section "
774- << CompactUnwindSectionName << " containing "
775- << OriginalBlocks.size () << " initial blocks...\n " ;
776- });
777-
778- while (!OriginalBlocks.empty ()) {
779- auto *B = OriginalBlocks.back ();
780- OriginalBlocks.pop_back ();
781-
782- if (B->getSize () == 0 ) {
783- LLVM_DEBUG ({
784- dbgs () << " Skipping empty block at "
785- << formatv (" {0:x16}" , B->getAddress ()) << " \n " ;
786- });
787- continue ;
788- }
789-
790- unsigned NumBlocks = B->getSize () / CURecordSize;
791-
792- LLVM_DEBUG ({
793- dbgs () << " Splitting block at " << formatv (" {0:x16}" , B->getAddress ())
794- << " into " << NumBlocks << " compact unwind record(s)\n " ;
795- });
796-
797- if (B->getSize () % CURecordSize)
798- return make_error<JITLinkError>(
799- " Error splitting compact unwind record in " + G.getName () +
800- " : block at " + formatv (" {0:x}" , B->getAddress ()) + " has size " +
801- formatv (" {0:x}" , B->getSize ()) +
802- " (not a multiple of CU record size of " +
803- formatv (" {0:x}" , CURecordSize) + " )" );
804-
805- auto Blocks =
806- G.splitBlock (*B, map_range (seq (1U , NumBlocks), [=](Edge::OffsetT Idx) {
807- return Idx * CURecordSize;
808- }));
809-
810- for (auto *CURec : Blocks) {
811- bool AddedKeepAlive = false ;
812-
813- for (auto &E : CURec->edges ()) {
814- if (E.getOffset () == 0 ) {
815- LLVM_DEBUG ({
816- dbgs () << " Updating compact unwind record at "
817- << CURec->getAddress () << " to point to "
818- << (E.getTarget ().hasName () ? *E.getTarget ().getName ()
819- : StringRef ())
820- << " (at " << E.getTarget ().getAddress () << " )\n " ;
821- });
822-
823- if (E.getTarget ().isExternal ())
824- return make_error<JITLinkError>(
825- " Error adding keep-alive edge for compact unwind record at " +
826- formatv (" {0:x}" , CURec->getAddress ()) + " : target " +
827- *E.getTarget ().getName () + " is an external symbol" );
828- auto &TgtBlock = E.getTarget ().getBlock ();
829- auto &CURecSym =
830- G.addAnonymousSymbol (*CURec, 0 , CURecordSize, false , false );
831- TgtBlock.addEdge (Edge::KeepAlive, 0 , CURecSym, 0 );
832- AddedKeepAlive = true ;
833- } else if (E.getOffset () != PersonalityEdgeOffset &&
834- E.getOffset () != LSDAEdgeOffset)
835- return make_error<JITLinkError>(
836- " Unexpected edge at offset " + formatv (" {0:x}" , E.getOffset ()) +
837- " in compact unwind record at " +
838- formatv (" {0:x}" , CURec->getAddress ()));
839- }
840-
841- if (!AddedKeepAlive)
842- return make_error<JITLinkError>(
843- " Error adding keep-alive edge for compact unwind record at " +
844- formatv (" {0:x}" , CURec->getAddress ()) +
845- " : no outgoing target edge at offset 0" );
846- }
847- }
848-
849- return Error::success ();
850- }
851-
852736} // end namespace jitlink
853737} // end namespace llvm
0 commit comments