[lld-macho][nfc] Have findContainingSubsection take a Section
... instead of an instance of `Subsections`. This simplifies the code slightly since all its callsites have a Section instance anyway.
This commit is contained in:
parent
afbe54f2fe
commit
1c0234dfcc
|
@ -373,13 +373,13 @@ void ObjFile::parseSections(ArrayRef<SectionHeader> sectionHeaders) {
|
|||
// same location as an offset relative to the start of the containing
|
||||
// subsection.
|
||||
template <class T>
|
||||
static InputSection *findContainingSubsection(const Subsections &subsections,
|
||||
static InputSection *findContainingSubsection(const Section §ion,
|
||||
T *offset) {
|
||||
static_assert(std::is_same<uint64_t, T>::value ||
|
||||
std::is_same<uint32_t, T>::value,
|
||||
"unexpected type for offset");
|
||||
auto it = std::prev(llvm::upper_bound(
|
||||
subsections, *offset,
|
||||
section.subsections, *offset,
|
||||
[](uint64_t value, Subsection subsec) { return value < subsec.offset; }));
|
||||
*offset -= it->offset;
|
||||
return it->isec;
|
||||
|
@ -420,11 +420,12 @@ static bool validateRelocationInfo(InputFile *file, const SectionHeader &sec,
|
|||
template <class SectionHeader>
|
||||
void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
|
||||
const SectionHeader &sec,
|
||||
Subsections &subsections) {
|
||||
Section §ion) {
|
||||
auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart());
|
||||
ArrayRef<relocation_info> relInfos(
|
||||
reinterpret_cast<const relocation_info *>(buf + sec.reloff), sec.nreloc);
|
||||
|
||||
Subsections &subsections = section.subsections;
|
||||
auto subsecIt = subsections.rbegin();
|
||||
for (size_t i = 0; i < relInfos.size(); i++) {
|
||||
// Paired relocations serve as Mach-O's method for attaching a
|
||||
|
@ -503,10 +504,8 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
|
|||
// The addend for a non-pcrel relocation is its absolute address.
|
||||
referentOffset = totalAddend - referentSecHead.addr;
|
||||
}
|
||||
Subsections &referentSubsections =
|
||||
sections[relInfo.r_symbolnum - 1]->subsections;
|
||||
r.referent =
|
||||
findContainingSubsection(referentSubsections, &referentOffset);
|
||||
r.referent = findContainingSubsection(*sections[relInfo.r_symbolnum - 1],
|
||||
&referentOffset);
|
||||
r.addend = referentOffset;
|
||||
}
|
||||
|
||||
|
@ -520,7 +519,7 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
|
|||
++subsecIt;
|
||||
if (subsecIt == subsections.rend() ||
|
||||
subsecIt->offset + subsecIt->isec->getSize() <= r.offset) {
|
||||
subsec = findContainingSubsection(subsections, &r.offset);
|
||||
subsec = findContainingSubsection(section, &r.offset);
|
||||
// Now that we know the relocs are unsorted, avoid trying the 'fast path'
|
||||
// for the other relocations.
|
||||
subsecIt = subsections.rend();
|
||||
|
@ -544,10 +543,8 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
|
|||
} else {
|
||||
uint64_t referentOffset =
|
||||
totalAddend - sectionHeaders[minuendInfo.r_symbolnum - 1].addr;
|
||||
Subsections &referentSubsectVec =
|
||||
sections[minuendInfo.r_symbolnum - 1]->subsections;
|
||||
p.referent =
|
||||
findContainingSubsection(referentSubsectVec, &referentOffset);
|
||||
p.referent = findContainingSubsection(
|
||||
*sections[minuendInfo.r_symbolnum - 1], &referentOffset);
|
||||
p.addend = referentOffset;
|
||||
}
|
||||
subsec->relocs.push_back(p);
|
||||
|
@ -734,7 +731,7 @@ void ObjFile::parseSymbols(ArrayRef<typename LP::section> sectionHeaders,
|
|||
StringRef name = strtab + sym.n_strx;
|
||||
uint64_t symbolOffset = sym.n_value - sectionAddr;
|
||||
InputSection *isec =
|
||||
findContainingSubsection(subsections, &symbolOffset);
|
||||
findContainingSubsection(*sections[i], &symbolOffset);
|
||||
if (symbolOffset != 0) {
|
||||
error(toString(lastIsec) + ": symbol " + name +
|
||||
" at misaligned offset");
|
||||
|
@ -898,8 +895,7 @@ template <class LP> void ObjFile::parse() {
|
|||
// parsed all the symbols.
|
||||
for (size_t i = 0, n = sections.size(); i < n; ++i)
|
||||
if (!sections[i]->subsections.empty())
|
||||
parseRelocations(sectionHeaders, sectionHeaders[i],
|
||||
sections[i]->subsections);
|
||||
parseRelocations(sectionHeaders, sectionHeaders[i], *sections[i]);
|
||||
|
||||
parseDebugInfo();
|
||||
if (compactUnwindSection)
|
||||
|
|
|
@ -163,7 +163,7 @@ private:
|
|||
Symbol *parseNonSectionSymbol(const NList &sym, StringRef name);
|
||||
template <class SectionHeader>
|
||||
void parseRelocations(ArrayRef<SectionHeader> sectionHeaders,
|
||||
const SectionHeader &, Subsections &);
|
||||
const SectionHeader &, Section &);
|
||||
void parseDebugInfo();
|
||||
void registerCompactUnwind();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue