[lld] f004ecf - [lld-macho][nfc] Remove indirection when looking up common section members
Jez Ng via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 11:31:06 PDT 2022
Author: Jez Ng
Date: 2022-04-07T14:28:52-04:00
New Revision: f004ecf6ec1d12fb6b57fc9033eeec7e892c9151
URL: https://github.com/llvm/llvm-project/commit/f004ecf6ec1d12fb6b57fc9033eeec7e892c9151
DIFF: https://github.com/llvm/llvm-project/commit/f004ecf6ec1d12fb6b57fc9033eeec7e892c9151.diff
LOG: [lld-macho][nfc] Remove indirection when looking up common section members
{D118797} means that we can now check the name/segname of a given
section directly, instead of having to look those properties up on one
of its subsections. This allows us to simplify our code.
Reviewed By: #lld-macho, oontvoo
Differential Revision: https://reviews.llvm.org/D123275
Added:
Modified:
lld/MachO/Driver.cpp
lld/MachO/InputFiles.cpp
lld/MachO/InputFiles.h
Removed:
################################################################################
diff --git a/lld/MachO/Driver.cpp b/lld/MachO/Driver.cpp
index 7d2a76ce9f4d3..2661c70712124 100644
--- a/lld/MachO/Driver.cpp
+++ b/lld/MachO/Driver.cpp
@@ -986,14 +986,11 @@ static void gatherInputSections() {
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<ConcatInputSection>(subsection.isec)) {
if (isec->isCoalescedWeak())
continue;
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
index 6d7769878cece..26fa566b63c37 100644
--- a/lld/MachO/InputFiles.cpp
+++ b/lld/MachO/InputFiles.cpp
@@ -95,6 +95,10 @@ std::string lld::toString(const InputFile *f) {
return (f->archiveName + "(" + path::filename(f->getName()) + ")").str();
}
+std::string lld::toString(const Section &sec) {
+ return (toString(sec.file) + ":(" + sec.name + ")").str();
+}
+
SetVector<InputFile *> macho::inputFiles;
std::unique_ptr<TarWriter> macho::tar;
int InputFile::idCount = 0;
@@ -302,7 +306,7 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
" is too large");
continue;
}
- const Section §ion = *sections.back();
+ Section §ion = *sections.back();
uint32_t align = 1 << sec.align;
ArrayRef<uint8_t> data = {isZeroFill(sec.flags) ? nullptr
: buf + sec.offset,
@@ -311,7 +315,7 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
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<ConcatInputSection>(
@@ -336,11 +340,11 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
} else {
isec = make<WordLiteralInputSection>(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 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
// 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 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
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 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
// 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 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
InputSection *isec =
findContainingSubsection(*sections[i], &symbolOffset);
if (symbolOffset != 0) {
- error(toString(lastIsec) + ": symbol " + name +
+ error(toString(*sections[i]) + ": symbol " + name +
" at misaligned offset");
continue;
}
diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h
index 7dda230b3e1da..5d455d277b6f2 100644
--- a/lld/MachO/InputFiles.h
+++ b/lld/MachO/InputFiles.h
@@ -307,6 +307,7 @@ std::vector<const CommandType *> findCommands(const void *anyHdr,
} // namespace macho
std::string toString(const macho::InputFile *file);
+std::string toString(const macho::Section &);
} // namespace lld
#endif
More information about the llvm-commits
mailing list