diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -200,7 +200,7 @@ uint32_t DuplicatedJumpTables{0x10000000}; /// Function fragments to skip. - std::vector FragmentsToSkip; + std::unordered_set FragmentsToSkip; /// The runtime library. std::unique_ptr RtLibrary; @@ -236,6 +236,18 @@ MIB = std::move(TargetBuilder); } + /// Return function fragments to skip. + const std::unordered_set &getFragmentsToSkip() { + return FragmentsToSkip; + } + + /// Add function fragment to skip + void addFragmentsToSkip(BinaryFunction *Function) { + FragmentsToSkip.insert(Function); + } + + void clearFragmentsToSkip() { FragmentsToSkip.clear(); } + /// Given DWOId returns CU if it exists in DWOCUs. Optional getDWOCU(uint64_t DWOId); @@ -476,15 +488,15 @@ /// If \p NextJTAddress is different from zero, it is used as an upper /// bound for jump table memory layout. /// - /// Optionally, populate \p Offsets with jump table entries. The entries + /// Optionally, populate \p Address from jump table entries. The entries /// could be partially populated if the jump table detection fails. bool analyzeJumpTable(const uint64_t Address, const JumpTable::JumpTableType Type, BinaryFunction &BF, const uint64_t NextJTAddress = 0, - JumpTable::OffsetsType *Offsets = nullptr); + JumpTable::AddressesType *EntriesAsAddress = nullptr); /// After jump table locations are established, this function will populate - /// their OffsetEntries based on memory contents. + /// their EntriesAsAddress based on memory contents. void populateJumpTables(); /// Returns a jump table ID and label pointing to the duplicated jump table. @@ -499,12 +511,12 @@ /// to function \p BF. std::string generateJumpTableName(const BinaryFunction &BF, uint64_t Address); - /// Free memory used by jump table offsets - void clearJumpTableOffsets() { + /// Free memory used by JumpTable's EntriesAsAddress + void clearJumpTableTempData() { for (auto &JTI : JumpTables) { JumpTable &JT = *JTI.second; - JumpTable::OffsetsType Temp; - Temp.swap(JT.OffsetEntries); + JumpTable::AddressesType Temp; + Temp.swap(JT.EntriesAsAddress); } } /// Return true if the array of bytes represents a valid code padding. diff --git a/bolt/include/bolt/Core/BinaryFunction.h b/bolt/include/bolt/Core/BinaryFunction.h --- a/bolt/include/bolt/Core/BinaryFunction.h +++ b/bolt/include/bolt/Core/BinaryFunction.h @@ -333,9 +333,9 @@ /// True if the original entry point was patched. bool IsPatched{false}; - /// True if the function contains jump table with entries pointing to - /// locations in fragments. - bool HasSplitJumpTable{false}; + /// True if the function contains explicit or implicit indirect branch to its + /// split fragments, e.g., split jump table, landing pad in split fragment + bool HasIndirectTargetToSplitFragment{false}; /// True if there are no control-flow edges with successors in other functions /// (i.e. if tail calls have edges to function-local basic blocks). @@ -1437,9 +1437,12 @@ /// otherwise processed. bool isPseudo() const { return IsPseudo; } - /// Return true if the function contains a jump table with entries pointing - /// to split fragments. - bool hasSplitJumpTable() const { return HasSplitJumpTable; } + /// Return true if the function contains explicit or implicit indirect branch + /// to its split fragments, e.g., split jump table, landing pad in split + /// fragment. + bool hasIndirectTargetToSplitFragment() const { + return HasIndirectTargetToSplitFragment; + } /// Return true if all CFG edges have local successors. bool hasCanonicalCFG() const { return HasCanonicalCFG; } @@ -1834,7 +1837,9 @@ void setIsPatched(bool V) { IsPatched = V; } - void setHasSplitJumpTable(bool V) { HasSplitJumpTable = V; } + void setHasIndirectTargetToSplitFragment(bool V) { + HasIndirectTargetToSplitFragment = V; + } void setHasCanonicalCFG(bool V) { HasCanonicalCFG = V; } diff --git a/bolt/include/bolt/Core/JumpTable.h b/bolt/include/bolt/Core/JumpTable.h --- a/bolt/include/bolt/Core/JumpTable.h +++ b/bolt/include/bolt/Core/JumpTable.h @@ -69,9 +69,9 @@ /// All the entries as labels. std::vector Entries; - /// All the entries as offsets into a function. Invalid after CFG is built. - using OffsetsType = std::vector; - OffsetsType OffsetEntries; + /// All the entries as absolute addresses. Invalid after disassembly is done. + using AddressesType = std::vector; + AddressesType EntriesAsAddress; /// Map ->