diff options
author | Greg McGary <gkm@fb.com> | 2020-09-12 20:45:00 -0700 |
---|---|---|
committer | Greg McGary <gkm@fb.com> | 2020-09-22 20:31:01 -0700 |
commit | 1a3ef0417c7ca9498895186c96da452f6e2f15a0 (patch) | |
tree | 7e717e8f6d0b8b18108775481ae4f862bff1d489 /lld | |
parent | 2d0de5f9a4c58e2fcdd8f00dabca505ba47abbd0 (diff) | |
download | llvm-1a3ef0417c7ca9498895186c96da452f6e2f15a0.zip llvm-1a3ef0417c7ca9498895186c96da452f6e2f15a0.tar.gz llvm-1a3ef0417c7ca9498895186c96da452f6e2f15a0.tar.bz2 |
[lld-macho] In the context of relocs, s/target/referent/ for sections & symbols
The word "target" is overloaded, so lighten its load by using another word to denote the symbol or section to which a reloc points. While more stilted than "target", "referent" is rather less pompous than "designatum" or "denotatum". :P
Along the way, make a few neighboring variable names more descriptive.
Reviewed By: #lld-macho, int3
Differential Revision: https://reviews.llvm.org/D87584
Diffstat (limited to 'lld')
-rw-r--r-- | lld/MachO/InputFiles.cpp | 44 | ||||
-rw-r--r-- | lld/MachO/InputSection.cpp | 27 | ||||
-rw-r--r-- | lld/MachO/InputSection.h | 6 |
3 files changed, 39 insertions, 38 deletions
diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index d196543..670dbf5 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -172,51 +172,51 @@ static InputSection *findContainingSubsection(SubsectionMap &map, void InputFile::parseRelocations(const section_64 &sec, SubsectionMap &subsecMap) { auto *buf = reinterpret_cast<const uint8_t *>(mb.getBufferStart()); - ArrayRef<any_relocation_info> relInfos( + ArrayRef<any_relocation_info> anyRelInfos( reinterpret_cast<const any_relocation_info *>(buf + sec.reloff), sec.nreloc); - for (const any_relocation_info &anyRel : relInfos) { - if (anyRel.r_word0 & R_SCATTERED) + for (const any_relocation_info &anyRelInfo : anyRelInfos) { + if (anyRelInfo.r_word0 & R_SCATTERED) fatal("TODO: Scattered relocations not supported"); - auto rel = reinterpret_cast<const relocation_info &>(anyRel); + auto relInfo = reinterpret_cast<const relocation_info &>(anyRelInfo); Reloc r; - r.type = rel.r_type; - r.pcrel = rel.r_pcrel; - r.length = rel.r_length; - uint64_t rawAddend = target->getImplicitAddend(mb, sec, rel); + r.type = relInfo.r_type; + r.pcrel = relInfo.r_pcrel; + r.length = relInfo.r_length; + uint64_t rawAddend = target->getImplicitAddend(mb, sec, relInfo); - if (rel.r_extern) { - r.target = symbols[rel.r_symbolnum]; + if (relInfo.r_extern) { + r.referent = symbols[relInfo.r_symbolnum]; r.addend = rawAddend; } else { - if (rel.r_symbolnum == 0 || rel.r_symbolnum > subsections.size()) + if (relInfo.r_symbolnum == 0 || relInfo.r_symbolnum > subsections.size()) fatal("invalid section index in relocation for offset " + std::to_string(r.offset) + " in section " + sec.sectname + " of " + getName()); - SubsectionMap &targetSubsecMap = subsections[rel.r_symbolnum - 1]; - const section_64 &targetSec = sectionHeaders[rel.r_symbolnum - 1]; - uint32_t targetOffset; - if (rel.r_pcrel) { + SubsectionMap &referentSubsecMap = subsections[relInfo.r_symbolnum - 1]; + const section_64 &referentSec = sectionHeaders[relInfo.r_symbolnum - 1]; + uint32_t referentOffset; + if (relInfo.r_pcrel) { // The implicit addend for pcrel section relocations is the pcrel offset // in terms of the addresses in the input file. Here we adjust it so - // that it describes the offset from the start of the target section. + // that it describes the offset from the start of the referent section. // TODO: The offset of 4 is probably not right for ARM64, nor for // relocations with r_length != 2. - targetOffset = - sec.addr + rel.r_address + 4 + rawAddend - targetSec.addr; + referentOffset = + sec.addr + relInfo.r_address + 4 + rawAddend - referentSec.addr; } else { // The addend for a non-pcrel relocation is its absolute address. - targetOffset = rawAddend - targetSec.addr; + referentOffset = rawAddend - referentSec.addr; } - r.target = findContainingSubsection(targetSubsecMap, &targetOffset); - r.addend = targetOffset; + r.referent = findContainingSubsection(referentSubsecMap, &referentOffset); + r.addend = referentOffset; } - r.offset = rel.r_address; + r.offset = relInfo.r_address; InputSection *subsec = findContainingSubsection(subsecMap, &r.offset); subsec->relocs.push_back(r); } diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp index 66f30ad..e164630 100644 --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -35,25 +35,26 @@ void InputSection::writeTo(uint8_t *buf) { memcpy(buf, data.data(), data.size()); for (Reloc &r : relocs) { - uint64_t va = 0; - if (auto *s = r.target.dyn_cast<Symbol *>()) { - va = target->resolveSymbolVA(buf + r.offset, *s, r.type); + uint64_t referentVA = 0; + if (auto *referentSym = r.referent.dyn_cast<Symbol *>()) { + referentVA = + target->resolveSymbolVA(buf + r.offset, *referentSym, r.type); if (isThreadLocalVariables(flags)) { - // References from thread-local variable sections are treated as - // offsets relative to the start of the target section, instead of as - // absolute addresses. - if (auto *defined = dyn_cast<Defined>(s)) - va -= defined->isec->parent->addr; + // References from thread-local variable sections are treated + // as offsets relative to the start of the referent section, + // instead of as absolute addresses. + if (auto *defined = dyn_cast<Defined>(referentSym)) + referentVA -= defined->isec->parent->addr; } - } else if (auto *isec = r.target.dyn_cast<InputSection *>()) { - va = isec->getVA(); + } else if (auto *referentIsec = r.referent.dyn_cast<InputSection *>()) { + referentVA = referentIsec->getVA(); } - uint64_t val = va + r.addend; + uint64_t referentVal = referentVA + r.addend; if (r.pcrel) - val -= getVA() + r.offset; - target->relocateOne(buf + r.offset, r, val); + referentVal -= getVA() + r.offset; + target->relocateOne(buf + r.offset, r, referentVal); } } diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 0f96ad3..1449c87 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -29,10 +29,10 @@ struct Reloc { // The offset from the start of the subsection that this relocation belongs // to. uint32_t offset; - // Adding this offset to the address of the target symbol or subsection gives - // the destination that this relocation refers to. + // Adding this offset to the address of the referent symbol or subsection + // gives the destination that this relocation refers to. uint64_t addend; - llvm::PointerUnion<Symbol *, InputSection *> target; + llvm::PointerUnion<Symbol *, InputSection *> referent; }; inline bool isZeroFill(uint8_t flags) { |