diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp --- a/lld/MachO/Driver.cpp +++ b/lld/MachO/Driver.cpp @@ -986,14 +986,11 @@ int inputOrder = 0; for (const InputFile *file : inputFiles) { for (const Section *section : file->sections) { - const Subsections &subsections = section->subsections; - if (subsections.empty()) - continue; - if (subsections[0].isec->getName() == section_names::compactUnwind) + if (section->name == section_names::compactUnwind) // Compact unwind entries require special handling elsewhere. continue; ConcatOutputSection *osec = nullptr; - for (const Subsection &subsection : subsections) { + for (const Subsection &subsection : section->subsections) { if (auto *isec = dyn_cast(subsection.isec)) { if (isec->isCoalescedWeak()) continue; diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -307,6 +307,7 @@ } // namespace macho std::string toString(const macho::InputFile *file); +std::string toString(const macho::Section &); } // namespace lld #endif diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -95,6 +95,10 @@ return (f->archiveName + "(" + path::filename(f->getName()) + ")").str(); } +std::string lld::toString(const Section &sec) { + return (toString(sec.file) + ":(" + sec.name + ")").str(); +} + SetVector macho::inputFiles; std::unique_ptr macho::tar; int InputFile::idCount = 0; @@ -302,7 +306,7 @@ " is too large"); continue; } - const Section §ion = *sections.back(); + Section §ion = *sections.back(); uint32_t align = 1 << sec.align; ArrayRef data = {isZeroFill(sec.flags) ? nullptr : buf + sec.offset, @@ -311,7 +315,7 @@ auto splitRecords = [&](int recordSize) -> void { if (data.empty()) return; - Subsections &subsections = sections.back()->subsections; + Subsections &subsections = section.subsections; subsections.reserve(data.size() / recordSize); for (uint64_t off = 0; off < data.size(); off += recordSize) { auto *isec = make( @@ -336,11 +340,11 @@ } else { isec = make(section, data, align); } - sections.back()->subsections.push_back({0, isec}); + section.subsections.push_back({0, isec}); } else if (auto recordSize = getRecordSize(segname, name)) { splitRecords(*recordSize); if (name == section_names::compactUnwind) - compactUnwindSection = sections.back(); + compactUnwindSection = §ion; } else if (segname == segment_names::llvm) { if (config->callGraphProfileSort && name == section_names::cgProfile) checkError(parseCallGraph(data, callGraph)); @@ -359,7 +363,7 @@ // parsing their relocations unnecessarily. debugSections.push_back(isec); } else { - sections.back()->subsections.push_back({0, isec}); + section.subsections.push_back({0, isec}); } } } @@ -724,8 +728,7 @@ Subsections &subsections = sections[i]->subsections; if (subsections.empty()) continue; - InputSection *lastIsec = subsections.back().isec; - if (lastIsec->getName() == section_names::ehFrame) { + if (sections[i]->name == section_names::ehFrame) { // __TEXT,__eh_frame only has symbols and SUBTRACTOR relocs when ld64 -r // adds local "EH_Frame1" and "func.eh". Ignore them because they have // gone unused by Mac OS since Snow Leopard (10.6), vintage 2009. @@ -738,7 +741,7 @@ // Record-based sections have already been split into subsections during // parseSections(), so we simply need to match Symbols to the corresponding // subsection here. - if (getRecordSize(lastIsec->getSegName(), lastIsec->getName())) { + if (getRecordSize(sections[i]->segname, sections[i]->name)) { for (size_t j = 0; j < symbolIndices.size(); ++j) { uint32_t symIndex = symbolIndices[j]; const NList &sym = nList[symIndex]; @@ -747,7 +750,7 @@ InputSection *isec = findContainingSubsection(*sections[i], &symbolOffset); if (symbolOffset != 0) { - error(toString(lastIsec) + ": symbol " + name + + error(toString(*sections[i]) + ": symbol " + name + " at misaligned offset"); continue; }