Skip to content

Commit 77c1977

Browse files
committed
[BOLT] Support files with no symbols
`LastSymbol` handling in `discoverFileObjects` assumes a non-zero number of symbols in an object file. It's not the case for broken_dynsym.test added in D130073, and potentially other stripped binaries. Reviewed By: maksfb Differential Revision: https://reviews.llvm.org/D130544
1 parent 8a13326 commit 77c1977

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,9 @@ void RewriteInstance::discoverFileObjects() {
866866

867867
llvm::stable_sort(SortedFileSymbols, CompareSymbols);
868868

869-
auto LastSymbol = SortedFileSymbols.end() - 1;
869+
auto LastSymbol = SortedFileSymbols.end();
870+
if (!SortedFileSymbols.empty())
871+
--LastSymbol;
870872

871873
// For aarch64, the ABI defines mapping symbols so we identify data in the
872874
// code section (see IHI0056B). $d identifies data contents.
@@ -912,13 +914,16 @@ void RewriteInstance::discoverFileObjects() {
912914
LastSymbol = std::stable_partition(
913915
SortedFileSymbols.begin(), SortedFileSymbols.end(),
914916
[this](const SymbolRef &Symbol) { return !BC->isMarker(Symbol); });
915-
--LastSymbol;
917+
if (!SortedFileSymbols.empty())
918+
--LastSymbol;
916919
}
917920

918921
BinaryFunction *PreviousFunction = nullptr;
919922
unsigned AnonymousId = 0;
920923

921-
const auto SortedSymbolsEnd = std::next(LastSymbol);
924+
const auto SortedSymbolsEnd = LastSymbol == SortedFileSymbols.end()
925+
? LastSymbol
926+
: std::next(LastSymbol);
922927
for (auto ISym = SortedFileSymbols.begin(); ISym != SortedSymbolsEnd;
923928
++ISym) {
924929
const SymbolRef &Symbol = *ISym;

0 commit comments

Comments
 (0)