[PATCH] D130544: [BOLT] Support files with no symbols

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 25 21:26:02 PDT 2022


Amir created this revision.
Herald added a reviewer: rafauler.
Herald added a subscriber: ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

`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 <https://reviews.llvm.org/D130073>, and potentially other stripped binaries.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130544

Files:
  bolt/lib/Rewrite/RewriteInstance.cpp


Index: bolt/lib/Rewrite/RewriteInstance.cpp
===================================================================
--- bolt/lib/Rewrite/RewriteInstance.cpp
+++ bolt/lib/Rewrite/RewriteInstance.cpp
@@ -866,7 +866,9 @@
 
   llvm::stable_sort(SortedFileSymbols, CompareSymbols);
 
-  auto LastSymbol = SortedFileSymbols.end() - 1;
+  auto LastSymbol = SortedFileSymbols.end();
+  if (!SortedFileSymbols.empty())
+    --LastSymbol;
 
   // For aarch64, the ABI defines mapping symbols so we identify data in the
   // code section (see IHI0056B). $d identifies data contents.
@@ -912,13 +914,16 @@
     LastSymbol = std::stable_partition(
         SortedFileSymbols.begin(), SortedFileSymbols.end(),
         [this](const SymbolRef &Symbol) { return !BC->isMarker(Symbol); });
-    --LastSymbol;
+    if (!SortedFileSymbols.empty())
+      --LastSymbol;
   }
 
   BinaryFunction *PreviousFunction = nullptr;
   unsigned AnonymousId = 0;
 
-  const auto SortedSymbolsEnd = std::next(LastSymbol);
+  const auto SortedSymbolsEnd = LastSymbol == SortedFileSymbols.end()
+                                    ? LastSymbol
+                                    : std::next(LastSymbol);
   for (auto ISym = SortedFileSymbols.begin(); ISym != SortedSymbolsEnd;
        ++ISym) {
     const SymbolRef &Symbol = *ISym;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130544.447555.patch
Type: text/x-patch
Size: 1300 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220726/a2758d84/attachment.bin>


More information about the llvm-commits mailing list