[PATCH] D127670: [lld-macho] Fix symbol name returned from InputSection::getLocation

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 13 12:52:47 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5f627cc2251c: [lld-macho] Fix symbol name returned from InputSection::getLocation (authored by BertalanD, committed by thakis).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127670/new/

https://reviews.llvm.org/D127670

Files:
  lld/MachO/InputSection.cpp
  lld/test/MachO/invalid/range-check.s


Index: lld/test/MachO/invalid/range-check.s
===================================================================
--- lld/test/MachO/invalid/range-check.s
+++ lld/test/MachO/invalid/range-check.s
@@ -17,6 +17,11 @@
 _bar:
 
 #--- test.s
+
+# Added to ensure that the error mentions the right function.
+_baz:
+  ret
+
 .globl _main, _foo
 
 _main:
Index: lld/MachO/InputSection.cpp
===================================================================
--- lld/MachO/InputSection.cpp
+++ lld/MachO/InputSection.cpp
@@ -58,12 +58,14 @@
 std::string InputSection::getLocation(uint64_t off) const {
   // First, try to find a symbol that's near the offset. Use it as a reference
   // point.
-  for (size_t i = 0; i < symbols.size(); ++i)
-    if (symbols[i]->value <= off &&
-        (i + 1 == symbols.size() || symbols[i + 1]->value > off))
-      return (toString(getFile()) + ":(symbol " + symbols.front()->getName() +
-              "+0x" + Twine::utohexstr(off - symbols[i]->value) + ")")
-          .str();
+  auto *nextSym = llvm::upper_bound(
+      symbols, off, [](uint64_t a, const Defined *b) { return a < b->value; });
+  if (nextSym != symbols.begin()) {
+    auto &sym = *std::prev(nextSym);
+    return (toString(getFile()) + ":(symbol " + sym->getName() + "+0x" +
+            Twine::utohexstr(off - sym->value) + ")")
+        .str();
+  }
 
   // If that fails, use the section itself as a reference point.
   for (const Subsection &subsec : section.subsections) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127670.436529.patch
Type: text/x-patch
Size: 1477 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220613/e9859ba1/attachment.bin>


More information about the llvm-commits mailing list