diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -108,12 +108,13 @@ class ObjFile final : public InputFile { public: ObjFile(MemoryBufferRef mb, uint32_t modTime, StringRef archiveName); + ArrayRef getDataInCode() const; + static bool classof(const InputFile *f) { return f->kind() == ObjKind; } llvm::DWARFUnit *compileUnit = nullptr; const uint32_t modTime; std::vector debugSections; - ArrayRef dataInCodeEntries; private: Section *compactUnwindSection = nullptr; @@ -130,7 +131,6 @@ void parseRelocations(ArrayRef sectionHeaders, const SectionHeader &, Subsections &); void parseDebugInfo(); - void parseDataInCode(); void registerCompactUnwind(); }; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -880,8 +880,6 @@ sections[i].subsections); parseDebugInfo(); - if (config->emitDataInCodeInfo) - parseDataInCode(); if (compactUnwindSection) registerCompactUnwind(); } @@ -909,19 +907,14 @@ compileUnit = it->get(); } -void ObjFile::parseDataInCode() { +ArrayRef ObjFile::getDataInCode() const { const auto *buf = reinterpret_cast(mb.getBufferStart()); const load_command *cmd = findCommand(buf, LC_DATA_IN_CODE); if (!cmd) - return; + return {}; const auto *c = reinterpret_cast(cmd); - dataInCodeEntries = { - reinterpret_cast(buf + c->dataoff), - c->datasize / sizeof(data_in_code_entry)}; - assert(is_sorted(dataInCodeEntries, [](const data_in_code_entry &lhs, - const data_in_code_entry &rhs) { - return lhs.offset < rhs.offset; - })); + return {reinterpret_cast(buf + c->dataoff), + c->datasize / sizeof(data_in_code_entry)}; } // Create pointers from symbols to their associated compact unwind entries. diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -733,35 +733,30 @@ template static std::vector collectDataInCodeEntries() { - using SegmentCommand = typename LP::segment_command; - using SectionHeader = typename LP::section; - std::vector dataInCodeEntries; for (const InputFile *inputFile : inputFiles) { if (!isa(inputFile)) continue; const ObjFile *objFile = cast(inputFile); - const auto *c = reinterpret_cast( - findCommand(objFile->mb.getBufferStart(), LP::segmentLCType)); - if (!c) - continue; - ArrayRef sectionHeaders{ - reinterpret_cast(c + 1), c->nsects}; - - ArrayRef entries = objFile->dataInCodeEntries; + ArrayRef entries = objFile->getDataInCode(); if (entries.empty()) continue; + + assert(is_sorted(dataInCodeEntries, [](const data_in_code_entry &lhs, + const data_in_code_entry &rhs) { + return lhs.offset < rhs.offset; + })); // For each code subsection find 'data in code' entries residing in it. // Compute the new offset values as // + - <__TEXT address>. - for (size_t i = 0, n = sectionHeaders.size(); i < n; ++i) { - for (const Subsection &subsec : objFile->sections[i].subsections) { + for (const Section §ion : objFile->sections) { + for (const Subsection &subsec : section.subsections) { const InputSection *isec = subsec.isec; if (!isCodeSection(isec)) continue; if (cast(isec)->shouldOmitFromOutput()) continue; - const uint64_t beginAddr = sectionHeaders[i].addr + subsec.offset; + const uint64_t beginAddr = section.address + subsec.offset; auto it = llvm::lower_bound( entries, beginAddr, [](const MachO::data_in_code_entry &entry, uint64_t addr) {