[lld] 1c0234d - [lld-macho][nfc] Have findContainingSubsection take a Section

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 21 04:23:17 PDT 2022


Author: Jez Ng
Date: 2022-03-21T07:23:09-04:00
New Revision: 1c0234dfccc9f68637a4d0fa8a1493552616b412

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

LOG: [lld-macho][nfc] Have findContainingSubsection take a Section

... instead of an instance of `Subsections`.

This simplifies the code slightly since all its callsites have a Section
instance anyway.

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp
    lld/MachO/InputFiles.h

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index e4508b22a6eba..41fb45ccdfc3d 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -373,13 +373,13 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
 // same location as an offset relative to the start of the containing
 // subsection.
 template <class T>
-static InputSection *findContainingSubsection(const Subsections &subsections,
+static InputSection *findContainingSubsection(const Section &section,
                                               T *offset) {
   static_assert(std::is_same<uint64_t, T>::value ||
                     std::is_same<uint32_t, T>::value,
                 "unexpected type for offset");
   auto it = std::prev(llvm::upper_bound(
-      subsections, *offset,
+      section.subsections, *offset,
       [](uint64_t value, Subsection subsec) { return value < subsec.offset; }));
   *offset -= it->offset;
   return it->isec;
@@ -420,11 +420,12 @@ static bool validateRelocationInfo(InputFile *file, const SectionHeader &sec,
 template <class SectionHeader>
 void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
                                const SectionHeader &sec,
-                               Subsections &subsections) {
+                               Section &section) {
   auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
   ArrayRef<relocation_info> relInfos(
       reinterpret_cast<const relocation_info *>(buf + sec.reloff), sec.nreloc);
 
+  Subsections &subsections = section.subsections;
   auto subsecIt = subsections.rbegin();
   for (size_t i = 0; i < relInfos.size(); i++) {
     // Paired relocations serve as Mach-O's method for attaching a
@@ -503,10 +504,8 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
         // The addend for a non-pcrel relocation is its absolute address.
         referentOffset = totalAddend - referentSecHead.addr;
       }
-      Subsections &referentSubsections =
-          sections[relInfo.r_symbolnum - 1]->subsections;
-      r.referent =
-          findContainingSubsection(referentSubsections, &referentOffset);
+      r.referent = findContainingSubsection(*sections[relInfo.r_symbolnum - 1],
+                                            &referentOffset);
       r.addend = referentOffset;
     }
 
@@ -520,7 +519,7 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
       ++subsecIt;
     if (subsecIt == subsections.rend() ||
         subsecIt->offset + subsecIt->isec->getSize() <= r.offset) {
-      subsec = findContainingSubsection(subsections, &r.offset);
+      subsec = findContainingSubsection(section, &r.offset);
       // Now that we know the relocs are unsorted, avoid trying the 'fast path'
       // for the other relocations.
       subsecIt = subsections.rend();
@@ -544,10 +543,8 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
       } else {
         uint64_t referentOffset =
             totalAddend - sectionHeaders[minuendInfo.r_symbolnum - 1].addr;
-        Subsections &referentSubsectVec =
-            sections[minuendInfo.r_symbolnum - 1]->subsections;
-        p.referent =
-            findContainingSubsection(referentSubsectVec, &referentOffset);
+        p.referent = findContainingSubsection(
+            *sections[minuendInfo.r_symbolnum - 1], &referentOffset);
         p.addend = referentOffset;
       }
       subsec->relocs.push_back(p);
@@ -734,7 +731,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
         StringRef name = strtab + sym.n_strx;
         uint64_t symbolOffset = sym.n_value - sectionAddr;
         InputSection *isec =
-            findContainingSubsection(subsections, &symbolOffset);
+            findContainingSubsection(*sections[i], &symbolOffset);
         if (symbolOffset != 0) {
           error(toString(lastIsec) + ":  symbol " + name +
                 " at misaligned offset");
@@ -898,8 +895,7 @@ template <class LP> void ObjFile::parse() {
   // parsed all the symbols.
   for (size_t i = 0, n = sections.size(); i < n; ++i)
     if (!sections[i]->subsections.empty())
-      parseRelocations(sectionHeaders, sectionHeaders[i],
-                       sections[i]->subsections);
+      parseRelocations(sectionHeaders, sectionHeaders[i], *sections[i]);
 
   parseDebugInfo();
   if (compactUnwindSection)

diff  --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 66e4e086db47a..7dda230b3e1da 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -163,7 +163,7 @@ class ObjFile final : public InputFile {
   Symbol *parseNonSectionSymbol(const NList &sym, StringRef name);
   template <class SectionHeader>
   void parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
-                        const SectionHeader &, Subsections &);
+                        const SectionHeader &, Section &);
   void parseDebugInfo();
   void registerCompactUnwind();
 };


        


More information about the llvm-commits mailing list