[lld] da6b6b3 - [lld-macho][nfc] Factor out findSymbolAtOffset

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 7 06:13:48 PDT 2022


Author: Jez Ng
Date: 2022-04-07T09:13:39-04:00
New Revision: da6b6b3c8201473a37499baab6594ef5b087f8dc

URL: https://github.com/llvm/llvm-project/commit/da6b6b3c8201473a37499baab6594ef5b087f8dc
DIFF: https://github.com/llvm/llvm-project/commit/da6b6b3c8201473a37499baab6594ef5b087f8dc.diff

LOG: [lld-macho][nfc] Factor out findSymbolAtOffset

Our compact unwind handling code currently has some logic to locate a
symbol at a given offset in an InputSection. The EH frame code will need
to do something similar, so let's factor out the code.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D123301

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 42bea7c8d6246..6d7769878cece 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -385,6 +385,20 @@ static InputSection *findContainingSubsection(const Section &section,
   return it->isec;
 }
 
+// Find a symbol at offset `off` within `isec`.
+static Defined *findSymbolAtOffset(const ConcatInputSection *isec,
+                                   uint64_t off) {
+  auto it = llvm::lower_bound(isec->symbols, off, [](Defined *d, uint64_t off) {
+    return d->value < off;
+  });
+  // The offset should point at the exact address of a symbol (with no addend.)
+  if (it == isec->symbols.end() || (*it)->value != off) {
+    assert(isec->wasCoalesced);
+    return nullptr;
+  }
+  return *it;
+}
+
 template <class SectionHeader>
 static bool validateRelocationInfo(InputFile *file, const SectionHeader &sec,
                                    relocation_info rel) {
@@ -1002,17 +1016,12 @@ void ObjFile::registerCompactUnwind() {
       // The functionAddress relocations are typically section relocations.
       // However, unwind info operates on a per-symbol basis, so we search for
       // the function symbol here.
-      auto symIt = llvm::lower_bound(
-          referentIsec->symbols, add,
-          [](Defined *d, uint64_t add) { return d->value < add; });
-      // The relocation should point at the exact address of a symbol (with no
-      // addend).
-      if (symIt == referentIsec->symbols.end() || (*symIt)->value != add) {
-        assert(referentIsec->wasCoalesced);
+      Defined *d = findSymbolAtOffset(referentIsec, add);
+      if (!d) {
         ++it;
         continue;
       }
-      (*symIt)->unwindEntry = isec;
+      d->unwindEntry = isec;
       // Since we've sliced away the functionAddress, we should remove the
       // corresponding relocation too. Given that clang emits relocations in
       // reverse order of address, this relocation should be at the end of the


        


More information about the llvm-commits mailing list