forked from OSchip/llvm-project
[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
This commit is contained in:
parent
fa784f6382
commit
f004ecf6ec
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue