@@ -496,7 +496,7 @@ BinaryContext::handleAddressRef(uint64_t Address, BinaryFunction &BF,
496496 const MemoryContentsType MemType = analyzeMemoryAt (Address, BF);
497497 if (MemType == MemoryContentsType::POSSIBLE_PIC_JUMP_TABLE && IsPCRel) {
498498 const MCSymbol *Symbol =
499- getOrCreateJumpTable (BF, Address, JumpTable::JTT_PIC );
499+ getOrCreateJumpTable (BF, Address, JumpTable::JTT_X86_64_PIC4 );
500500
501501 return std::make_pair (Symbol, 0 );
502502 }
@@ -540,10 +540,10 @@ MemoryContentsType BinaryContext::analyzeMemoryAt(uint64_t Address,
540540
541541 // Start with checking for PIC jump table. We expect non-PIC jump tables
542542 // to have high 32 bits set to 0.
543- if (analyzeJumpTable (Address, JumpTable::JTT_PIC , BF))
543+ if (analyzeJumpTable (Address, JumpTable::JTT_X86_64_PIC4 , BF))
544544 return MemoryContentsType::POSSIBLE_PIC_JUMP_TABLE;
545545
546- if (analyzeJumpTable (Address, JumpTable::JTT_NORMAL , BF))
546+ if (analyzeJumpTable (Address, JumpTable::JTT_X86_64_ABS , BF))
547547 return MemoryContentsType::POSSIBLE_JUMP_TABLE;
548548
549549 return MemoryContentsType::UNKNOWN;
@@ -607,13 +607,13 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
607607 << " -> " );
608608 // Check if there's a proper relocation against the jump table entry.
609609 if (HasRelocations) {
610- if (Type == JumpTable::JTT_PIC &&
610+ if (Type == JumpTable::JTT_X86_64_PIC4 &&
611611 !DataPCRelocations.count (EntryAddress)) {
612612 LLVM_DEBUG (
613613 dbgs () << " FAIL: JTT_PIC table, no relocation for this address\n " );
614614 break ;
615615 }
616- if (Type == JumpTable::JTT_NORMAL && !getRelocationAt (EntryAddress)) {
616+ if (Type == JumpTable::JTT_X86_64_ABS && !getRelocationAt (EntryAddress)) {
617617 LLVM_DEBUG (
618618 dbgs ()
619619 << " FAIL: JTT_NORMAL table, no relocation for this address\n " );
@@ -645,24 +645,19 @@ bool BinaryContext::analyzeJumpTable(const uint64_t Address,
645645
646646 // Function or one of its fragments.
647647 const BinaryFunction *TargetBF = getBinaryFunctionContainingAddress (Value);
648- const bool DoesBelongToFunction =
649- BF.containsAddress (Value) ||
650- (TargetBF && areRelatedFragments (TargetBF, &BF));
651- if (!DoesBelongToFunction) {
648+ if (!TargetBF || !areRelatedFragments (TargetBF, &BF)) {
652649 LLVM_DEBUG ({
653- if (!BF.containsAddress (Value)) {
654- dbgs () << " FAIL: function doesn't contain this address\n " ;
655- if (TargetBF) {
656- dbgs () << " ! function containing this address: "
657- << TargetBF->getPrintName () << ' \n ' ;
658- if (TargetBF->isFragment ()) {
659- dbgs () << " ! is a fragment" ;
660- for (BinaryFunction *Parent : TargetBF->ParentFragments )
661- dbgs () << " , parent: " << Parent->getPrintName ();
662- dbgs () << ' \n ' ;
663- }
664- }
665- }
650+ dbgs () << " FAIL: function doesn't contain this address\n " ;
651+ if (!TargetBF)
652+ break ;
653+ dbgs () << " ! function containing this address: " << *TargetBF << ' \n ' ;
654+ if (!TargetBF->isFragment ())
655+ break ;
656+ dbgs () << " ! is a fragment with parents: " ;
657+ ListSeparator LS;
658+ for (BinaryFunction *Parent : TargetBF->ParentFragments )
659+ dbgs () << LS << *Parent;
660+ dbgs () << ' \n ' ;
666661 });
667662 break ;
668663 }
@@ -702,10 +697,8 @@ void BinaryContext::populateJumpTables() {
702697 ++JTI) {
703698 JumpTable *JT = JTI->second ;
704699
705- bool NonSimpleParent = false ;
706- for (BinaryFunction *BF : JT->Parents )
707- NonSimpleParent |= !BF->isSimple ();
708- if (NonSimpleParent)
700+ auto isSimple = std::bind (&BinaryFunction::isSimple, std::placeholders::_1);
701+ if (!llvm::all_of (JT->Parents , isSimple))
709702 continue ;
710703
711704 uint64_t NextJTAddress = 0 ;
@@ -743,7 +736,7 @@ void BinaryContext::populateJumpTables() {
743736
744737 // In strict mode, erase PC-relative relocation record. Later we check that
745738 // all such records are erased and thus have been accounted for.
746- if (opts::StrictMode && JT->Type == JumpTable::JTT_PIC ) {
739+ if (opts::StrictMode && JT->Type == JumpTable::JTT_X86_64_PIC4 ) {
747740 for (uint64_t Address = JT->getAddress ();
748741 Address < JT->getAddress () + JT->getSize ();
749742 Address += JT->EntrySize ) {
@@ -839,33 +832,26 @@ BinaryContext::getOrCreateJumpTable(BinaryFunction &Function, uint64_t Address,
839832 assert (JT->Type == Type && " jump table types have to match" );
840833 assert (Address == JT->getAddress () && " unexpected non-empty jump table" );
841834
842- // Prevent associating a jump table to a specific fragment twice.
843- if (!llvm::is_contained (JT->Parents , &Function)) {
844- assert (llvm::all_of (JT->Parents ,
845- [&](const BinaryFunction *BF) {
846- return areRelatedFragments (&Function, BF);
847- }) &&
848- " cannot re-use jump table of a different function" );
849- // Duplicate the entry for the parent function for easy access
850- JT->Parents .push_back (&Function);
851- if (opts::Verbosity > 2 ) {
852- this ->outs () << " BOLT-INFO: Multiple fragments access same jump table: "
853- << JT->Parents [0 ]->getPrintName () << " ; "
854- << Function.getPrintName () << " \n " ;
855- JT->print (this ->outs ());
856- }
857- Function.JumpTables .emplace (Address, JT);
858- for (BinaryFunction *Parent : JT->Parents )
859- Parent->setHasIndirectTargetToSplitFragment (true );
860- }
835+ if (llvm::is_contained (JT->Parents , &Function))
836+ return JT->getFirstLabel ();
861837
862- bool IsJumpTableParent = false ;
863- (void )IsJumpTableParent;
864- for (BinaryFunction *Frag : JT->Parents )
865- if (Frag == &Function)
866- IsJumpTableParent = true ;
867- assert (IsJumpTableParent &&
838+ // Prevent associating a jump table to a specific fragment twice.
839+ auto isSibling = std::bind (&BinaryContext::areRelatedFragments, this ,
840+ &Function, std::placeholders::_1);
841+ assert (llvm::all_of (JT->Parents , isSibling) &&
868842 " cannot re-use jump table of a different function" );
843+ if (opts::Verbosity > 2 ) {
844+ this ->outs () << " BOLT-INFO: Multiple fragments access same jump table: "
845+ << JT->Parents [0 ]->getPrintName () << " ; "
846+ << Function.getPrintName () << " \n " ;
847+ JT->print (this ->outs ());
848+ }
849+ if (JT->Parents .size () == 1 )
850+ JT->Parents .front ()->setHasIndirectTargetToSplitFragment (true );
851+ Function.setHasIndirectTargetToSplitFragment (true );
852+ // Duplicate the entry for the parent function for easy access
853+ JT->Parents .push_back (&Function);
854+ Function.JumpTables .emplace (Address, JT);
869855 return JT->getFirstLabel ();
870856 }
871857
0 commit comments