@@ -881,14 +881,9 @@ void RewriteInstance::discoverFileObjects() {
881881 // code section (see IHI0056B). $d identifies data contents.
882882 // Compilers usually merge multiple data objects in a single $d-$x interval,
883883 // but we need every data object to be marked with $d. Because of that we
884- // create a vector of MarkerSyms with all locations of data objects.
884+ // keep track of marker symbols with all locations of data objects.
885885
886- struct MarkerSym {
887- uint64_t Address;
888- MarkerSymType Type;
889- };
890-
891- std::vector<MarkerSym> SortedMarkerSymbols;
886+ DenseMap<uint64_t , MarkerSymType> MarkerSymbols;
892887 auto addExtraDataMarkerPerSymbol = [&]() {
893888 bool IsData = false ;
894889 uint64_t LastAddr = 0 ;
@@ -912,14 +907,14 @@ void RewriteInstance::discoverFileObjects() {
912907 }
913908
914909 if (MarkerType != MarkerSymType::NONE) {
915- SortedMarkerSymbols. push_back (MarkerSym{ SymInfo.Address , MarkerType}) ;
910+ MarkerSymbols[ SymInfo.Address ] = MarkerType;
916911 LastAddr = SymInfo.Address ;
917912 IsData = MarkerType == MarkerSymType::DATA;
918913 continue ;
919914 }
920915
921916 if (IsData) {
922- SortedMarkerSymbols. push_back ({ SymInfo.Address , MarkerSymType::DATA}) ;
917+ MarkerSymbols[ SymInfo.Address ] = MarkerSymType::DATA;
923918 LastAddr = SymInfo.Address ;
924919 }
925920 }
@@ -1284,27 +1279,24 @@ void RewriteInstance::discoverFileObjects() {
12841279 BC->setHasSymbolsWithFileName (FileSymbols.size ());
12851280
12861281 // Now that all the functions were created - adjust their boundaries.
1287- adjustFunctionBoundaries ();
1282+ adjustFunctionBoundaries (MarkerSymbols );
12881283
12891284 // Annotate functions with code/data markers in AArch64
1290- for (auto ISym = SortedMarkerSymbols.begin ();
1291- ISym != SortedMarkerSymbols.end (); ++ISym) {
1292-
1293- auto *BF =
1294- BC->getBinaryFunctionContainingAddress (ISym->Address , true , true );
1285+ for (auto &[Address, Type] : MarkerSymbols) {
1286+ auto *BF = BC->getBinaryFunctionContainingAddress (Address, true , true );
12951287
12961288 if (!BF) {
12971289 // Stray marker
12981290 continue ;
12991291 }
1300- const auto EntryOffset = ISym-> Address - BF->getAddress ();
1301- if (ISym-> Type == MarkerSymType::CODE) {
1292+ const auto EntryOffset = Address - BF->getAddress ();
1293+ if (Type == MarkerSymType::CODE) {
13021294 BF->markCodeAtOffset (EntryOffset);
13031295 continue ;
13041296 }
1305- if (ISym-> Type == MarkerSymType::DATA) {
1297+ if (Type == MarkerSymType::DATA) {
13061298 BF->markDataAtOffset (EntryOffset);
1307- BC->AddressToConstantIslandMap [ISym-> Address ] = BF;
1299+ BC->AddressToConstantIslandMap [Address] = BF;
13081300 continue ;
13091301 }
13101302 llvm_unreachable (" Unknown marker" );
@@ -1833,7 +1825,8 @@ void RewriteInstance::disassemblePLT() {
18331825 }
18341826}
18351827
1836- void RewriteInstance::adjustFunctionBoundaries () {
1828+ void RewriteInstance::adjustFunctionBoundaries (
1829+ DenseMap<uint64_t , MarkerSymType> &MarkerSyms) {
18371830 for (auto BFI = BC->getBinaryFunctions ().begin (),
18381831 BFE = BC->getBinaryFunctions ().end ();
18391832 BFI != BFE; ++BFI) {
@@ -1871,12 +1864,15 @@ void RewriteInstance::adjustFunctionBoundaries() {
18711864 continue ;
18721865 }
18731866
1874- // This is potentially another entry point into the function.
1875- uint64_t EntryOffset = NextSymRefI->first - Function.getAddress ();
1876- LLVM_DEBUG (dbgs () << " BOLT-DEBUG: adding entry point to function "
1877- << Function << " at offset 0x"
1878- << Twine::utohexstr (EntryOffset) << ' \n ' );
1879- Function.addEntryPointAtOffset (EntryOffset);
1867+ auto It = MarkerSyms.find (NextSymRefI->first );
1868+ if (It == MarkerSyms.end () || It->second != MarkerSymType::DATA) {
1869+ // This is potentially another entry point into the function.
1870+ uint64_t EntryOffset = NextSymRefI->first - Function.getAddress ();
1871+ LLVM_DEBUG (dbgs () << " BOLT-DEBUG: adding entry point to function "
1872+ << Function << " at offset 0x"
1873+ << Twine::utohexstr (EntryOffset) << ' \n ' );
1874+ Function.addEntryPointAtOffset (EntryOffset);
1875+ }
18801876
18811877 ++NextSymRefI;
18821878 }
0 commit comments