@@ -84,6 +84,7 @@ extern cl::opt<bool> KeepNops;
84
84
extern cl::opt<bool > Lite;
85
85
extern cl::list<std::string> ReorderData;
86
86
extern cl::opt<bolt::ReorderFunctions::ReorderType> ReorderFunctions;
87
+ extern cl::opt<bool > TerminalHLT;
87
88
extern cl::opt<bool > TerminalTrap;
88
89
extern cl::opt<bool > TimeBuild;
89
90
extern cl::opt<bool > TimeRewrite;
@@ -880,14 +881,9 @@ void RewriteInstance::discoverFileObjects() {
880
881
// code section (see IHI0056B). $d identifies data contents.
881
882
// Compilers usually merge multiple data objects in a single $d-$x interval,
882
883
// 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.
884
885
885
- struct MarkerSym {
886
- uint64_t Address;
887
- MarkerSymType Type;
888
- };
889
-
890
- std::vector<MarkerSym> SortedMarkerSymbols;
886
+ DenseMap<uint64_t , MarkerSymType> MarkerSymbols;
891
887
auto addExtraDataMarkerPerSymbol = [&]() {
892
888
bool IsData = false ;
893
889
uint64_t LastAddr = 0 ;
@@ -911,14 +907,14 @@ void RewriteInstance::discoverFileObjects() {
911
907
}
912
908
913
909
if (MarkerType != MarkerSymType::NONE) {
914
- SortedMarkerSymbols. push_back (MarkerSym{ SymInfo.Address , MarkerType}) ;
910
+ MarkerSymbols[ SymInfo.Address ] = MarkerType;
915
911
LastAddr = SymInfo.Address ;
916
912
IsData = MarkerType == MarkerSymType::DATA;
917
913
continue ;
918
914
}
919
915
920
916
if (IsData) {
921
- SortedMarkerSymbols. push_back ({ SymInfo.Address , MarkerSymType::DATA}) ;
917
+ MarkerSymbols[ SymInfo.Address ] = MarkerSymType::DATA;
922
918
LastAddr = SymInfo.Address ;
923
919
}
924
920
}
@@ -1283,27 +1279,24 @@ void RewriteInstance::discoverFileObjects() {
1283
1279
BC->setHasSymbolsWithFileName (FileSymbols.size ());
1284
1280
1285
1281
// Now that all the functions were created - adjust their boundaries.
1286
- adjustFunctionBoundaries ();
1282
+ adjustFunctionBoundaries (MarkerSymbols );
1287
1283
1288
1284
// 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 );
1294
1287
1295
1288
if (!BF) {
1296
1289
// Stray marker
1297
1290
continue ;
1298
1291
}
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) {
1301
1294
BF->markCodeAtOffset (EntryOffset);
1302
1295
continue ;
1303
1296
}
1304
- if (ISym-> Type == MarkerSymType::DATA) {
1297
+ if (Type == MarkerSymType::DATA) {
1305
1298
BF->markDataAtOffset (EntryOffset);
1306
- BC->AddressToConstantIslandMap [ISym-> Address ] = BF;
1299
+ BC->AddressToConstantIslandMap [Address] = BF;
1307
1300
continue ;
1308
1301
}
1309
1302
llvm_unreachable (" Unknown marker" );
@@ -1832,7 +1825,8 @@ void RewriteInstance::disassemblePLT() {
1832
1825
}
1833
1826
}
1834
1827
1835
- void RewriteInstance::adjustFunctionBoundaries () {
1828
+ void RewriteInstance::adjustFunctionBoundaries (
1829
+ DenseMap<uint64_t , MarkerSymType> &MarkerSyms) {
1836
1830
for (auto BFI = BC->getBinaryFunctions ().begin (),
1837
1831
BFE = BC->getBinaryFunctions ().end ();
1838
1832
BFI != BFE; ++BFI) {
@@ -1870,12 +1864,15 @@ void RewriteInstance::adjustFunctionBoundaries() {
1870
1864
continue ;
1871
1865
}
1872
1866
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
+ }
1879
1876
1880
1877
++NextSymRefI;
1881
1878
}
@@ -2177,7 +2174,9 @@ void RewriteInstance::adjustCommandLineOptions() {
2177
2174
if (!opts::KeepNops.getNumOccurrences ())
2178
2175
opts::KeepNops = true ;
2179
2176
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 ;
2181
2180
if (!opts::TerminalTrap.getNumOccurrences ())
2182
2181
opts::TerminalTrap = false ;
2183
2182
}
0 commit comments