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