[lld] 9408b75 - [lld-macho][nfc] Hoist out creation of Section in parseSections()

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 14:09:22 PST 2022


Author: Jez Ng
Date: 2022-02-02T17:09:14-05:00
New Revision: 9408b75ec386095b0a057eaef5854e514c68f528

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

LOG: [lld-macho][nfc] Hoist out creation of Section in parseSections()

Simplifies the code slightly.

Reviewed By: #lld-macho, thakis

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

Added: 
    

Modified: 
    lld/MachO/InputFiles.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index bbeb2dc09bf0..74cccffc2889 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -277,17 +277,16 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
     ArrayRef<uint8_t> data = {isZeroFill(sec.flags) ? nullptr
                                                     : buf + sec.offset,
                               static_cast<size_t>(sec.size)};
+    sections.push_back(sec.addr);
     if (sec.align >= 32) {
       error("alignment " + std::to_string(sec.align) + " of section " + name +
             " is too large");
-      sections.push_back(sec.addr);
       continue;
     }
     uint32_t align = 1 << sec.align;
     uint32_t flags = sec.flags;
 
     auto splitRecords = [&](int recordSize) -> void {
-      sections.push_back(sec.addr);
       if (data.empty())
         return;
       Subsections &subsections = sections.back().subsections;
@@ -321,7 +320,6 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
         isec = make<WordLiteralInputSection>(segname, name, this, data, align,
                                              flags);
       }
-      sections.push_back(sec.addr);
       sections.back().subsections.push_back({0, isec});
     } else if (auto recordSize = getRecordSize(segname, name)) {
       splitRecords(*recordSize);
@@ -350,10 +348,9 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
       // ld64 does not appear to emit contents from sections within the __LLVM
       // segment. Symbols within those sections point to bitcode metadata
       // instead of actual symbols. Global symbols within those sections could
-      // have the same name without causing duplicate symbol errors. Push an
-      // empty entry to ensure indices line up for the remaining sections.
+      // have the same name without causing duplicate symbol errors. To avoid
+      // spurious duplicate symbol errors, we do not parse these sections.
       // TODO: Evaluate whether the bitcode metadata is needed.
-      sections.push_back(sec.addr);
     } else {
       auto *isec =
           make<ConcatInputSection>(segname, name, this, data, align, flags);
@@ -361,12 +358,9 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
           isec->getSegName() == segment_names::dwarf) {
         // Instead of emitting DWARF sections, we emit STABS symbols to the
         // object files that contain them. We filter them out early to avoid
-        // parsing their relocations unnecessarily. But we must still push an
-        // empty entry to ensure the indices line up for the remaining sections.
-        sections.push_back(sec.addr);
+        // parsing their relocations unnecessarily.
         debugSections.push_back(isec);
       } else {
-        sections.push_back(sec.addr);
         sections.back().subsections.push_back({0, isec});
       }
     }


        


More information about the llvm-commits mailing list