diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -172,51 +172,51 @@ void InputFile::parseRelocations(const section_64 &sec, SubsectionMap &subsecMap) { auto *buf = reinterpret_cast(mb.getBufferStart()); - ArrayRef relInfos( + ArrayRef anyRelInfos( reinterpret_cast(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(anyRel); + auto relInfo = reinterpret_cast(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.h b/lld/MachO/InputSection.h --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -29,10 +29,10 @@ // 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 target; + llvm::PointerUnion referent; }; inline bool isZeroFill(uint8_t flags) { diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -35,25 +35,26 @@ memcpy(buf, data.data(), data.size()); for (Reloc &r : relocs) { - uint64_t va = 0; - if (auto *s = r.target.dyn_cast()) { - va = target->resolveSymbolVA(buf + r.offset, *s, r.type); + uint64_t referentVA = 0; + if (auto *referentSym = r.referent.dyn_cast()) { + 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(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(referentSym)) + referentVA -= defined->isec->parent->addr; } - } else if (auto *isec = r.target.dyn_cast()) { - va = isec->getVA(); + } else if (auto *referentIsec = r.referent.dyn_cast()) { + 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); } }