@@ -84,6 +84,7 @@ extern cl::opt<bool> KeepNops;
8484extern cl::opt<bool > Lite;
8585extern cl::list<std::string> ReorderData;
8686extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
87+ extern cl::opt<bool > TerminalHLT;
8788extern cl::opt<bool > TerminalTrap;
8889extern cl::opt<bool > TimeBuild;
8990extern cl::opt<bool > TimeRewrite;
@@ -880,14 +881,9 @@ void RewriteInstance::discoverFileObjects() {
880881 // code section (see IHI0056B). $d identifies data contents.
881882 // Compilers usually merge multiple data objects in a single $d-$x interval,
882883 // but we need every data object to be marked with $d. Because of that we
883- // create a vector of MarkerSyms with all locations of data objects.
884+ // keep track of marker symbols with all locations of data objects.
884885
885- struct MarkerSym {
886- uint64_t Address;
887- MarkerSymType Type;
888- };
889-
890- std::vector<MarkerSym> SortedMarkerSymbols;
886+ DenseMap<uint64_t , MarkerSymType> MarkerSymbols;
891887 auto addExtraDataMarkerPerSymbol = [&]() {
892888 bool IsData = false ;
893889 uint64_t LastAddr = 0 ;
@@ -911,14 +907,14 @@ void RewriteInstance::discoverFileObjects() {
911907 }
912908
913909 if (MarkerType != MarkerSymType::NONE) {
914- SortedMarkerSymbols. push_back (MarkerSym{ SymInfo.Address , MarkerType}) ;
910+ MarkerSymbols[ SymInfo.Address ] = MarkerType;
915911 LastAddr = SymInfo.Address ;
916912 IsData = MarkerType == MarkerSymType::DATA;
917913 continue ;
918914 }
919915
920916 if (IsData) {
921- SortedMarkerSymbols. push_back ({ SymInfo.Address , MarkerSymType::DATA}) ;
917+ MarkerSymbols[ SymInfo.Address ] = MarkerSymType::DATA;
922918 LastAddr = SymInfo.Address ;
923919 }
924920 }
@@ -1283,27 +1279,24 @@ void RewriteInstance::discoverFileObjects() {
12831279 BC->setHasSymbolsWithFileName (FileSymbols.size ());
12841280
12851281 // Now that all the functions were created - adjust their boundaries.
1286- adjustFunctionBoundaries ();
1282+ adjustFunctionBoundaries (MarkerSymbols );
12871283
12881284 // Annotate functions with code/data markers in AArch64
1289- for (auto ISym = SortedMarkerSymbols.begin ();
1290- ISym != SortedMarkerSymbols.end (); ++ISym) {
1291-
1292- auto *BF =
1293- BC->getBinaryFunctionContainingAddress (ISym->Address , true , true );
1285+ for (auto &[Address, Type] : MarkerSymbols) {
1286+ auto *BF = BC->getBinaryFunctionContainingAddress (Address, true , true );
12941287
12951288 if (!BF) {
12961289 // Stray marker
12971290 continue ;
12981291 }
1299- const auto EntryOffset = ISym-> Address - BF->getAddress ();
1300- if (ISym-> Type == MarkerSymType::CODE) {
1292+ const auto EntryOffset = Address - BF->getAddress ();
1293+ if (Type == MarkerSymType::CODE) {
13011294 BF->markCodeAtOffset (EntryOffset);
13021295 continue ;
13031296 }
1304- if (ISym-> Type == MarkerSymType::DATA) {
1297+ if (Type == MarkerSymType::DATA) {
13051298 BF->markDataAtOffset (EntryOffset);
1306- BC->AddressToConstantIslandMap [ISym-> Address ] = BF;
1299+ BC->AddressToConstantIslandMap [Address] = BF;
13071300 continue ;
13081301 }
13091302 llvm_unreachable (" Unknown marker" );
@@ -1832,7 +1825,8 @@ void RewriteInstance::disassemblePLT() {
18321825 }
18331826}
18341827
1835- void RewriteInstance::adjustFunctionBoundaries () {
1828+ void RewriteInstance::adjustFunctionBoundaries (
1829+ DenseMap<uint64_t , MarkerSymType> &MarkerSyms) {
18361830 for (auto BFI = BC->getBinaryFunctions ().begin (),
18371831 BFE = BC->getBinaryFunctions ().end ();
18381832 BFI != BFE; ++BFI) {
@@ -1870,12 +1864,15 @@ void RewriteInstance::adjustFunctionBoundaries() {
18701864 continue ;
18711865 }
18721866
1873- // This is potentially another entry point into the function.
1874- uint64_t EntryOffset = NextSymRefI->first - Function.getAddress ();
1875- LLVM_DEBUG (dbgs () << " BOLT-DEBUG: adding entry point to function "
1876- << Function << " at offset 0x"
1877- << Twine::utohexstr (EntryOffset) << ' \n ' );
1878- 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+ }
18791876
18801877 ++NextSymRefI;
18811878 }
@@ -2177,7 +2174,9 @@ void RewriteInstance::adjustCommandLineOptions() {
21772174 if (!opts::KeepNops.getNumOccurrences ())
21782175 opts::KeepNops = true ;
21792176
2180- // Linux kernel may resume execution after a trap instruction in some cases.
2177+ // Linux kernel may resume execution after a trap or x86 HLT instruction.
2178+ if (!opts::TerminalHLT.getNumOccurrences ())
2179+ opts::TerminalHLT = false ;
21812180 if (!opts::TerminalTrap.getNumOccurrences ())
21822181 opts::TerminalTrap = false ;
21832182 }
0 commit comments