diff --git a/lld/MachO/Arch/ARM64Common.cpp b/lld/MachO/Arch/ARM64Common.cpp index d90a37fe8c65..599f1e18efda 100644 --- a/lld/MachO/Arch/ARM64Common.cpp +++ b/lld/MachO/Arch/ARM64Common.cpp @@ -38,7 +38,7 @@ int64_t ARM64Common::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset, } } -static void writeValue(uint8_t *loc, const Reloc &r, uint64_t value) { +static void writeValue(uint8_t *loc, const Relocation &r, uint64_t value) { switch (r.length) { case 2: checkInt(loc, r, value, 32); @@ -57,7 +57,7 @@ static void writeValue(uint8_t *loc, const Reloc &r, uint64_t value) { // instruction has opcode & register-operand bits set, with immediate // operands zeroed. We read it from text, OR-in the immediate // operands, then write-back the completed instruction. -void ARM64Common::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value, +void ARM64Common::relocateOne(uint8_t *loc, const Relocation &r, uint64_t value, uint64_t pc) const { auto loc32 = reinterpret_cast(loc); uint32_t base = ((r.length == 2) ? read32le(loc) : 0); @@ -110,7 +110,7 @@ void ARM64Common::relaxGotLoad(uint8_t *loc, uint8_t type) const { write32le(loc, instruction); } -void ARM64Common::handleDtraceReloc(const Symbol *sym, const Reloc &r, +void ARM64Common::handleDtraceReloc(const Symbol *sym, const Relocation &r, uint8_t *loc) const { assert(r.type == ARM64_RELOC_BRANCH26); @@ -138,8 +138,8 @@ static void reportUnalignedLdrStr(Twine loc, uint64_t va, int align, "-byte aligned"); } -void macho::reportUnalignedLdrStr(void *loc, const lld::macho::Reloc &r, - uint64_t va, int align) { +void macho::reportUnalignedLdrStr(void *loc, const Relocation &r, uint64_t va, + int align) { uint64_t off = reinterpret_cast(loc) - in.bufferStart; const InputSection *isec = offsetToInputSection(&off); std::string locStr = isec ? isec->getLocation(off) : "(invalid location)"; diff --git a/lld/MachO/Arch/ARM64Common.h b/lld/MachO/Arch/ARM64Common.h index 70461b4e83d3..f20cd4b17024 100644 --- a/lld/MachO/Arch/ARM64Common.h +++ b/lld/MachO/Arch/ARM64Common.h @@ -23,13 +23,13 @@ struct ARM64Common : TargetInfo { int64_t getEmbeddedAddend(MemoryBufferRef, uint64_t offset, const llvm::MachO::relocation_info) const override; - void relocateOne(uint8_t *loc, const Reloc &, uint64_t va, + void relocateOne(uint8_t *loc, const Relocation &, uint64_t va, uint64_t pc) const override; void relaxGotLoad(uint8_t *loc, uint8_t type) const override; uint64_t getPageSize() const override { return 16 * 1024; } - void handleDtraceReloc(const Symbol *sym, const Reloc &r, + void handleDtraceReloc(const Symbol *sym, const Relocation &r, uint8_t *loc) const override; }; @@ -42,7 +42,7 @@ inline uint64_t bitField(uint64_t value, int right, int width, int left) { // | | imm26 | // +-----------+---------------------------------------------------+ -inline void encodeBranch26(uint32_t *loc, const Reloc &r, uint32_t base, +inline void encodeBranch26(uint32_t *loc, const Relocation &r, uint32_t base, uint64_t va) { checkInt(loc, r, va, 28); // Since branch destinations are 4-byte aligned, the 2 least- @@ -61,7 +61,7 @@ inline void encodeBranch26(uint32_t *loc, SymbolDiagnostic d, uint32_t base, // | |ilo| | immhi | | // +-+---+---------+-------------------------------------+---------+ -inline void encodePage21(uint32_t *loc, const Reloc &r, uint32_t base, +inline void encodePage21(uint32_t *loc, const Relocation &r, uint32_t base, uint64_t va) { checkInt(loc, r, va, 35); llvm::support::endian::write32le(loc, base | bitField(va, 12, 2, 29) | @@ -75,7 +75,8 @@ inline void encodePage21(uint32_t *loc, SymbolDiagnostic d, uint32_t base, bitField(va, 14, 19, 5)); } -void reportUnalignedLdrStr(void *loc, const Reloc &, uint64_t va, int align); +void reportUnalignedLdrStr(void *loc, const Relocation &, uint64_t va, + int align); void reportUnalignedLdrStr(void *loc, SymbolDiagnostic, uint64_t va, int align); // 21 10 diff --git a/lld/MachO/Arch/X86_64.cpp b/lld/MachO/Arch/X86_64.cpp index f35139906554..c0bdffa22f25 100644 --- a/lld/MachO/Arch/X86_64.cpp +++ b/lld/MachO/Arch/X86_64.cpp @@ -28,7 +28,7 @@ struct X86_64 : TargetInfo { int64_t getEmbeddedAddend(MemoryBufferRef, uint64_t offset, const relocation_info) const override; - void relocateOne(uint8_t *loc, const Reloc &, uint64_t va, + void relocateOne(uint8_t *loc, const Relocation &, uint64_t va, uint64_t relocVA) const override; void writeStub(uint8_t *buf, const Symbol &, @@ -44,7 +44,7 @@ struct X86_64 : TargetInfo { void relaxGotLoad(uint8_t *loc, uint8_t type) const override; uint64_t getPageSize() const override { return 4 * 1024; } - void handleDtraceReloc(const Symbol *sym, const Reloc &r, + void handleDtraceReloc(const Symbol *sym, const Relocation &r, uint8_t *loc) const override; }; } // namespace @@ -102,7 +102,7 @@ int64_t X86_64::getEmbeddedAddend(MemoryBufferRef mb, uint64_t offset, return addend + pcrelOffset(rel.r_type); } -void X86_64::relocateOne(uint8_t *loc, const Reloc &r, uint64_t value, +void X86_64::relocateOne(uint8_t *loc, const Relocation &r, uint64_t value, uint64_t relocVA) const { if (r.pcrel) { uint64_t pc = relocVA + (1ull << r.length) + pcrelOffset(r.type); @@ -241,7 +241,7 @@ TargetInfo *macho::createX86_64TargetInfo() { return &t; } -void X86_64::handleDtraceReloc(const Symbol *sym, const Reloc &r, +void X86_64::handleDtraceReloc(const Symbol *sym, const Relocation &r, uint8_t *loc) const { assert(r.type == X86_64_RELOC_BRANCH); diff --git a/lld/MachO/BPSectionOrderer.cpp b/lld/MachO/BPSectionOrderer.cpp index 328c33e6cfb6..c9c6c1c62bdf 100644 --- a/lld/MachO/BPSectionOrderer.cpp +++ b/lld/MachO/BPSectionOrderer.cpp @@ -85,7 +85,7 @@ struct BPOrdererMachO : lld::BPOrderer { private: static uint64_t - getRelocHash(const macho::Reloc &reloc, + getRelocHash(const Relocation &reloc, const llvm::DenseMap §ionToIdx) { auto *isec = reloc.getReferentInputSection(); std::optional sectionIdx; diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp index e559676ef5e9..2612365be2ef 100644 --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -148,7 +148,7 @@ bool TextOutputSection::needsThunks() const { parent->needsThunks = true; } for (ConcatInputSection *isec : inputs) { - for (Reloc &r : isec->relocs) { + for (Relocation &r : isec->relocs) { if (!target->hasAttr(r.type, RelocAttrBits::BRANCH)) continue; auto *sym = cast(r.referent); @@ -333,12 +333,13 @@ void TextOutputSection::finalize() { branchTargetThresholdVA = estimateBranchTargetThresholdVA(callIdx); } // Process relocs by ascending address, i.e., ascending offset within isec - std::vector &relocs = isec->relocs; + std::vector &relocs = isec->relocs; // FIXME: This property does not hold for object files produced by ld64's // `-r` mode. - assert(is_sorted(relocs, - [](Reloc &a, Reloc &b) { return a.offset > b.offset; })); - for (Reloc &r : reverse(relocs)) { + assert(is_sorted(relocs, [](Relocation &a, Relocation &b) { + return a.offset > b.offset; + })); + for (Relocation &r : reverse(relocs)) { ++relocCount; if (!target->hasAttr(r.type, RelocAttrBits::BRANCH)) continue; diff --git a/lld/MachO/EhFrame.cpp b/lld/MachO/EhFrame.cpp index 2446b49b5098..552f4d05f0cf 100644 --- a/lld/MachO/EhFrame.cpp +++ b/lld/MachO/EhFrame.cpp @@ -109,16 +109,16 @@ template static void createSubtraction(PointerUnion a, PointerUnion b, uint64_t off, uint8_t length, - SmallVectorImpl *newRelocs) { + SmallVectorImpl *newRelocs) { auto subtrahend = a; auto minuend = b; if (Invert) std::swap(subtrahend, minuend); assert(isa(subtrahend)); - Reloc subtrahendReloc(target->subtractorRelocType, /*pcrel=*/false, length, - off, /*addend=*/0, subtrahend); - Reloc minuendReloc(target->unsignedRelocType, /*pcrel=*/false, length, off, - (Invert ? 1 : -1) * off, minuend); + Relocation subtrahendReloc(target->subtractorRelocType, /*pcrel=*/false, + length, off, /*addend=*/0, subtrahend); + Relocation minuendReloc(target->unsignedRelocType, /*pcrel=*/false, length, + off, (Invert ? 1 : -1) * off, minuend); newRelocs->push_back(subtrahendReloc); newRelocs->push_back(minuendReloc); } diff --git a/lld/MachO/EhFrame.h b/lld/MachO/EhFrame.h index d5afab3e15ae..a5695abe461e 100644 --- a/lld/MachO/EhFrame.h +++ b/lld/MachO/EhFrame.h @@ -108,7 +108,7 @@ private: InputSection *isec; // Insert new relocs here so that we don't invalidate iterators into the // existing relocs vector. - SmallVector newRelocs; + SmallVector newRelocs; }; } // namespace lld::macho diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp index e0fc89782a41..b03e2c5a42e0 100644 --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -106,7 +106,7 @@ bool ICF::equalsConstant(const ConcatInputSection *ia, return false; if (ia->relocs.size() != ib->relocs.size()) return false; - auto f = [](const Reloc &ra, const Reloc &rb) { + auto f = [](const Relocation &ra, const Relocation &rb) { if (ra.type != rb.type) return false; if (ra.pcrel != rb.pcrel) @@ -213,7 +213,7 @@ bool ICF::equalsVariable(const ConcatInputSection *ia, if (verboseDiagnostics) ++equalsVariableCount; assert(ia->relocs.size() == ib->relocs.size()); - auto f = [this](const Reloc &ra, const Reloc &rb) { + auto f = [this](const Relocation &ra, const Relocation &rb) { // We already filtered out mismatching values/addends in equalsConstant. if (ra.referent == rb.referent) return true; @@ -390,7 +390,7 @@ void ICF::run() { for (icfPass = 0; icfPass < 2; ++icfPass) { parallelForEach(icfInputs, [&](ConcatInputSection *isec) { uint32_t hash = isec->icfEqClass[icfPass % 2]; - for (const Reloc &r : isec->relocs) { + for (const Relocation &r : isec->relocs) { if (auto *sym = r.referent.dyn_cast()) { if (auto *defined = dyn_cast(sym)) { if (defined->isec()) { @@ -520,7 +520,7 @@ void macho::markAddrSigSymbols() { const InputSection *isec = addrSigSection->subsections[0].isec; - for (const Reloc &r : isec->relocs) { + for (const Relocation &r : isec->relocs) { if (auto *sym = r.referent.dyn_cast()) markSymAsAddrSig(sym); else @@ -609,7 +609,7 @@ void macho::foldIdenticalSections(bool onlyCfStrings) { // We have to do this copying serially as the BumpPtrAllocator is not // thread-safe. FIXME: Make a thread-safe allocator. MutableArrayRef copy = isec->data.copy(bAlloc()); - for (const Reloc &r : isec->relocs) + for (const Relocation &r : isec->relocs) target->relocateOne(copy.data() + r.offset, r, /*va=*/0, /*relocVA=*/0); isec->data = copy; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index 81caef5f15ae..681f502ad2cb 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -575,7 +575,7 @@ void ObjFile::parseRelocations(ArrayRef sectionHeaders, int64_t embeddedAddend = target->getEmbeddedAddend(mb, sec.offset, relInfo); assert(!(embeddedAddend && pairedAddend)); int64_t totalAddend = pairedAddend + embeddedAddend; - Reloc r; + Relocation r; r.type = relInfo.r_type; r.pcrel = relInfo.r_pcrel; r.length = relInfo.r_length; @@ -633,7 +633,7 @@ void ObjFile::parseRelocations(ArrayRef sectionHeaders, // attached to the same address. assert(target->hasAttr(minuendInfo.r_type, RelocAttrBits::UNSIGNED) && relInfo.r_address == minuendInfo.r_address); - Reloc p; + Relocation p; p.type = minuendInfo.r_type; if (minuendInfo.r_extern) { p.referent = symbols[minuendInfo.r_symbolnum]; @@ -1161,7 +1161,7 @@ void ObjFile::registerCompactUnwind(Section &compactUnwindSection) { ConcatInputSection *referentIsec; for (auto it = isec->relocs.begin(); it != isec->relocs.end();) { - Reloc &r = *it; + Relocation &r = *it; // CUE::functionAddress is at offset 0. Skip personality & LSDA relocs. if (r.offset != 0) { ++it; @@ -1337,9 +1337,9 @@ static CIE parseCIE(const InputSection *isec, const EhReader &reader, template Defined * targetSymFromCanonicalSubtractor(const InputSection *isec, - std::vector::iterator relocIt) { - macho::Reloc &subtrahend = *relocIt; - macho::Reloc &minuend = *std::next(relocIt); + std::vector::iterator relocIt) { + Relocation &subtrahend = *relocIt; + Relocation &minuend = *std::next(relocIt); assert(target->hasAttr(subtrahend.type, RelocAttrBits::SUBTRAHEND)); assert(target->hasAttr(minuend.type, RelocAttrBits::UNSIGNED)); // Note: pcSym may *not* be exactly at the PC; there's usually a non-zero @@ -1364,7 +1364,7 @@ targetSymFromCanonicalSubtractor(const InputSection *isec, // `oldSym->value + oldOffset == newSym + newOffset`. However, we don't // have an easy way to access the offsets from this point in the code; some // refactoring is needed for that. - macho::Reloc &pcReloc = Invert ? minuend : subtrahend; + Relocation &pcReloc = Invert ? minuend : subtrahend; pcReloc.referent = isec->symbols[0]; assert(isec->symbols[0]->value == 0); minuend.addend = pcReloc.offset * (Invert ? 1LL : -1LL); @@ -1419,8 +1419,9 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) { const size_t cieOffOff = dataOff; EhRelocator ehRelocator(isec); - auto cieOffRelocIt = llvm::find_if( - isec->relocs, [=](const Reloc &r) { return r.offset == cieOffOff; }); + auto cieOffRelocIt = llvm::find_if(isec->relocs, [=](const Relocation &r) { + return r.offset == cieOffOff; + }); InputSection *cieIsec = nullptr; if (cieOffRelocIt != isec->relocs.end()) { // We already have an explicit relocation for the CIE offset. diff --git a/lld/MachO/InputFiles.h b/lld/MachO/InputFiles.h index 2d5bceb16044..8f2cba89abf4 100644 --- a/lld/MachO/InputFiles.h +++ b/lld/MachO/InputFiles.h @@ -45,7 +45,7 @@ class ConcatInputSection; class Symbol; class Defined; class AliasSymbol; -struct Reloc; +struct Relocation; enum class RefState : uint8_t; // If --reproduce option is given, all input files are written diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp index 2b2d28ef63e2..d5499babc326 100644 --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -30,8 +30,8 @@ using namespace lld::macho; // Verify ConcatInputSection's size on 64-bit builds. The size of std::vector // can differ based on STL debug levels (e.g. iterator debugging on MSVC's STL), // so account for that. -static_assert(sizeof(void *) != 8 || - sizeof(ConcatInputSection) == sizeof(std::vector) + 88, +static_assert(sizeof(void *) != 8 || sizeof(ConcatInputSection) == + sizeof(std::vector) + 88, "Try to minimize ConcatInputSection's size, we create many " "instances of it"); @@ -177,9 +177,9 @@ std::string InputSection::getSourceLocation(uint64_t off) const { return {}; } -const Reloc *InputSection::getRelocAt(uint32_t off) const { - auto it = llvm::find_if( - relocs, [=](const macho::Reloc &r) { return r.offset == off; }); +const Relocation *InputSection::getRelocAt(uint32_t off) const { + auto it = llvm::find_if(relocs, + [=](const Relocation &r) { return r.offset == off; }); if (it == relocs.end()) return nullptr; return &*it; @@ -215,7 +215,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) { memcpy(buf, data.data(), data.size()); for (size_t i = 0; i < relocs.size(); i++) { - const Reloc &r = relocs[i]; + const Relocation &r = relocs[i]; uint8_t *loc = buf + r.offset; uint64_t referentVA = 0; @@ -223,7 +223,7 @@ void ConcatInputSection::writeTo(uint8_t *buf) { target->hasAttr(r.type, RelocAttrBits::UNSIGNED); if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) { const Symbol *fromSym = cast(r.referent); - const Reloc &minuend = relocs[++i]; + const Relocation &minuend = relocs[++i]; uint64_t minuendVA; if (const Symbol *toSym = minuend.referent.dyn_cast()) minuendVA = toSym->getVA() + minuend.addend; diff --git a/lld/MachO/InputSection.h b/lld/MachO/InputSection.h index 8e1f7ea0af01..e0a90a2edc0a 100644 --- a/lld/MachO/InputSection.h +++ b/lld/MachO/InputSection.h @@ -56,7 +56,7 @@ public: // Format: Source.cpp:123 (/path/to/Source.cpp:123) std::string getSourceLocation(uint64_t off) const; // Return the relocation at \p off, if it exists. This does a linear search. - const Reloc *getRelocAt(uint32_t off) const; + const Relocation *getRelocAt(uint32_t off) const; // Whether the data at \p off in this InputSection is live. virtual bool isLive(uint64_t off) const = 0; virtual void markLive(uint64_t off) = 0; @@ -88,7 +88,7 @@ public: OutputSection *parent = nullptr; ArrayRef data; - std::vector relocs; + std::vector relocs; // The symbols that belong to this InputSection, sorted by value. With // .subsections_via_symbols, there is typically only one element here. llvm::TinyPtrVector symbols; diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp index d87ccaeee280..a51c800bf4ef 100644 --- a/lld/MachO/MarkLive.cpp +++ b/lld/MachO/MarkLive.cpp @@ -154,7 +154,7 @@ void MarkLiveImpl::markTransitively() { assert(isec->live && "We mark as live when pushing onto the worklist!"); // Mark all symbols listed in the relocation table for this section. - for (const Reloc &r : isec->relocs) { + for (const Relocation &r : isec->relocs) { if (auto *s = r.referent.dyn_cast()) addSym(s, entry); else @@ -172,7 +172,7 @@ void MarkLiveImpl::markTransitively() { if (!(isec->getFlags() & S_ATTR_LIVE_SUPPORT) || isec->live) continue; - for (const Reloc &r : isec->relocs) { + for (const Relocation &r : isec->relocs) { if (auto *s = r.referent.dyn_cast()) { if (s->isLive()) { InputSection *referentIsec = nullptr; diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp index ab7f73c3a1df..2540bffecf2a 100644 --- a/lld/MachO/ObjC.cpp +++ b/lld/MachO/ObjC.cpp @@ -191,7 +191,7 @@ void ObjcCategoryChecker::parseMethods(const ConcatInputSection *methodsIsec, MethodContainerKind mcKind, MethodKind mKind) { ObjcClass &klass = classMap[methodContainerSym]; - for (const Reloc &r : methodsIsec->relocs) { + for (const Relocation &r : methodsIsec->relocs) { if ((r.offset - listHeaderLayout.totalSize) % methodLayout.totalSize != methodLayout.nameOffset) continue; @@ -219,7 +219,7 @@ void ObjcCategoryChecker::parseMethods(const ConcatInputSection *methodsIsec, // We have a duplicate; generate a warning message. const auto &mc = methodMap.lookup(methodName); - const Reloc *nameReloc = nullptr; + const Relocation *nameReloc = nullptr; if (mc.kind == MCK_Category) { nameReloc = mc.isec->getRelocAt(catLayout.nameOffset); } else { @@ -316,7 +316,7 @@ void objc::checkCategories() { ObjcCategoryChecker checker; for (const InputSection *isec : inputSections) { if (isec->getName() == section_names::objcCatList) - for (const Reloc &r : isec->relocs) { + for (const Relocation &r : isec->relocs) { auto *catIsec = cast(r.getReferentInputSection()); checker.parseCategory(catIsec); } @@ -349,7 +349,7 @@ class ObjcCategoryMerger { bool valid = false; // Data has been successfully collected from input uint32_t align = 0; Section *inputSection; - Reloc relocTemplate; + Relocation relocTemplate; OutputSection *outputSection; }; @@ -465,7 +465,7 @@ private: const std::string &baseClassName, ObjFile *objFile); Defined *emitCategoryName(const std::string &name, ObjFile *objFile); void createSymbolReference(Defined *refFrom, const Symbol *refTo, - uint32_t offset, const Reloc &relocTemplate); + uint32_t offset, const Relocation &relocTemplate); Defined *tryFindDefinedOnIsec(const InputSection *isec, uint32_t offset); Symbol *tryGetSymbolAtIsecOffset(const ConcatInputSection *isec, uint32_t offset); @@ -537,7 +537,7 @@ ObjcCategoryMerger::tryGetSymbolAtIsecOffset(const ConcatInputSection *isec, uint32_t offset) { if (!isec) return nullptr; - const Reloc *reloc = isec->getRelocAt(offset); + const Relocation *reloc = isec->getRelocAt(offset); if (!reloc) return nullptr; @@ -597,7 +597,7 @@ Defined *ObjcCategoryMerger::getClassRo(const Defined *classSym, // a symbol(Defined) at that offset, then erase the symbol (mark it not live) void ObjcCategoryMerger::tryEraseDefinedAtIsecOffset( const ConcatInputSection *isec, uint32_t offset) { - const Reloc *reloc = isec->getRelocAt(offset); + const Relocation *reloc = isec->getRelocAt(offset); if (!reloc) return; @@ -670,7 +670,7 @@ void ObjcCategoryMerger::parseProtocolListInfo( assert((isec && (secOffset + target->wordSize <= isec->data.size())) && "Tried to read pointer list beyond protocol section end"); - const Reloc *reloc = isec->getRelocAt(secOffset); + const Relocation *reloc = isec->getRelocAt(secOffset); if (!reloc) return; @@ -703,7 +703,7 @@ void ObjcCategoryMerger::parseProtocolListInfo( uint32_t off = protocolListHeaderLayout.totalSize; for (uint32_t inx = 0; inx < protocolCount; ++inx) { - const Reloc *reloc = ptrListSym->isec()->getRelocAt(off); + const Relocation *reloc = ptrListSym->isec()->getRelocAt(off); assert(reloc && "No reloc found at protocol list offset"); auto *listSym = dyn_cast_or_null(cast(reloc->referent)); @@ -739,7 +739,7 @@ bool ObjcCategoryMerger::parsePointerListInfo(const ConcatInputSection *isec, assert(secOffset + target->wordSize <= isec->data.size() && "Trying to read pointer list beyond section end"); - const Reloc *reloc = isec->getRelocAt(secOffset); + const Relocation *reloc = isec->getRelocAt(secOffset); // Empty list is a valid case, return true. if (!reloc) return true; @@ -765,7 +765,7 @@ bool ObjcCategoryMerger::parsePointerListInfo(const ConcatInputSection *isec, for (uint32_t off = listHeaderLayout.totalSize; off < expectedListSize; off += target->wordSize) { - const Reloc *reloc = ptrListSym->isec()->getRelocAt(off); + const Relocation *reloc = ptrListSym->isec()->getRelocAt(off); assert(reloc && "No reloc found at pointer list offset"); auto *listSym = @@ -787,7 +787,7 @@ bool ObjcCategoryMerger::parsePointerListInfo(const ConcatInputSection *isec, // information about how a class is extended (extInfo) bool ObjcCategoryMerger::parseCatInfoToExtInfo(const InfoInputCategory &catInfo, ClassExtensionInfo &extInfo) { - const Reloc *catNameReloc = + const Relocation *catNameReloc = catInfo.catBodyIsec->getRelocAt(catLayout.nameOffset); // Parse name @@ -1135,11 +1135,10 @@ bool ObjcCategoryMerger::mergeCategoriesIntoSingleCategory( return true; } -void ObjcCategoryMerger::createSymbolReference(Defined *refFrom, - const Symbol *refTo, - uint32_t offset, - const Reloc &relocTemplate) { - Reloc r = relocTemplate; +void ObjcCategoryMerger::createSymbolReference( + Defined *refFrom, const Symbol *refTo, uint32_t offset, + const Relocation &relocTemplate) { + Relocation r = relocTemplate; r.offset = offset; r.addend = 0; r.referent = const_cast(refTo); @@ -1500,7 +1499,9 @@ void ObjcCategoryMerger::eraseSymbolAtIsecOffset(ConcatInputSection *isec, llvm::erase(isec->symbols, sym); // Remove the relocs that refer to this symbol - auto removeAtOff = [offset](Reloc const &r) { return r.offset == offset; }; + auto removeAtOff = [offset](Relocation const &r) { + return r.offset == offset; + }; llvm::erase_if(isec->relocs, removeAtOff); // Now, if the symbol fully occupies a ConcatInputSection, we can also erase diff --git a/lld/MachO/Relocations.cpp b/lld/MachO/Relocations.cpp index 78cc13388d6e..0945e7a96dee 100644 --- a/lld/MachO/Relocations.cpp +++ b/lld/MachO/Relocations.cpp @@ -18,10 +18,10 @@ using namespace llvm; using namespace lld; using namespace lld::macho; -static_assert(sizeof(void *) != 8 || sizeof(Reloc) == 24, +static_assert(sizeof(void *) != 8 || sizeof(Relocation) == 24, "Try to minimize Reloc's size; we create many instances"); -InputSection *Reloc::getReferentInputSection() const { +InputSection *Relocation::getReferentInputSection() const { if (const auto *sym = referent.dyn_cast()) { if (const auto *d = dyn_cast(sym)) return d->isec(); @@ -31,7 +31,7 @@ InputSection *Reloc::getReferentInputSection() const { } } -StringRef Reloc::getReferentString() const { +StringRef Relocation::getReferentString() const { if (auto *isec = dyn_cast(referent)) { const auto *cisec = dyn_cast(isec); assert(cisec && "referent must be a CStringInputSection"); @@ -57,7 +57,8 @@ StringRef Reloc::getReferentString() const { } bool macho::validateSymbolRelocation(const Symbol *sym, - const InputSection *isec, const Reloc &r) { + const InputSection *isec, + const Relocation &r) { const RelocAttrs &relocAttrs = target->getRelocAttrs(r.type); bool valid = true; auto message = [&](const Twine &diagnostic) { @@ -117,7 +118,7 @@ InputSection *macho::offsetToInputSection(uint64_t *off) { return nullptr; } -void macho::reportRangeError(void *loc, const Reloc &r, const Twine &v, +void macho::reportRangeError(void *loc, const Relocation &r, const Twine &v, uint8_t bits, int64_t min, uint64_t max) { std::string hint; uint64_t off = reinterpret_cast(loc) - in.bufferStart; diff --git a/lld/MachO/Relocations.h b/lld/MachO/Relocations.h index d3347de36781..f5d4c3708296 100644 --- a/lld/MachO/Relocations.h +++ b/lld/MachO/Relocations.h @@ -51,7 +51,7 @@ struct RelocAttrs { bool hasAttr(RelocAttrBits b) const { return (bits & b) == b; } }; -struct Reloc { +struct Relocation { uint8_t type = llvm::MachO::GENERIC_RELOC_INVALID; bool pcrel = false; uint8_t length = 0; @@ -63,10 +63,11 @@ struct Reloc { int64_t addend = 0; llvm::PointerUnion referent = nullptr; - Reloc() = default; + Relocation() = default; - Reloc(uint8_t type, bool pcrel, uint8_t length, uint32_t offset, - int64_t addend, llvm::PointerUnion referent) + Relocation(uint8_t type, bool pcrel, uint8_t length, uint32_t offset, + int64_t addend, + llvm::PointerUnion referent) : type(type), pcrel(pcrel), length(length), offset(offset), addend(addend), referent(referent) {} @@ -78,13 +79,13 @@ struct Reloc { }; bool validateSymbolRelocation(const Symbol *, const InputSection *, - const Reloc &); + const Relocation &); /* * v: The value the relocation is attempting to encode * bits: The number of bits actually available to encode this relocation */ -void reportRangeError(void *loc, const Reloc &, const llvm::Twine &v, +void reportRangeError(void *loc, const Relocation &, const llvm::Twine &v, uint8_t bits, int64_t min, uint64_t max); struct SymbolDiagnostic { diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index fecc51f912b0..36d15419a109 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -2010,7 +2010,7 @@ uint64_t InitOffsetsSection::getSize() const { void InitOffsetsSection::writeTo(uint8_t *buf) const { // FIXME: Add function specified by -init when that argument is implemented. for (ConcatInputSection *isec : sections) { - for (const Reloc &rel : isec->relocs) { + for (const Relocation &rel : isec->relocs) { const Symbol *referent = cast(rel.referent); assert(referent && "section relocation should have been rejected"); uint64_t offset = referent->getVA() - in.header->addr; @@ -2035,7 +2035,7 @@ void InitOffsetsSection::writeTo(uint8_t *buf) const { // not known at link time, stub-indirection has to be used. void InitOffsetsSection::setUp() { for (const ConcatInputSection *isec : sections) { - for (const Reloc &rel : isec->relocs) { + for (const Relocation &rel : isec->relocs) { RelocAttrs attrs = target->getRelocAttrs(rel.type); if (!attrs.hasAttr(RelocAttrBits::UNSIGNED)) error(isec->getLocation(rel.offset) + @@ -2076,7 +2076,7 @@ void ObjCMethListSection::setUp() { // Loop through all methods, and ensure a selref for each of them exists. while (methodNameOff < isec->data.size()) { - const Reloc *reloc = isec->getRelocAt(methodNameOff); + const Relocation *reloc = isec->getRelocAt(methodNameOff); assert(reloc && "Relocation expected at method list name slot"); StringRef methname = reloc->getReferentString(); @@ -2177,7 +2177,7 @@ bool ObjCMethListSection::isMethodList(const ConcatInputSection *isec) { void ObjCMethListSection::writeRelativeOffsetForIsec( const ConcatInputSection *isec, uint8_t *buf, uint32_t &inSecOff, uint32_t &outSecOff, bool useSelRef) const { - const Reloc *reloc = isec->getRelocAt(inSecOff); + const Relocation *reloc = isec->getRelocAt(inSecOff); assert(reloc && "Relocation expected at __objc_methlist Offset"); uint32_t symVA = 0; diff --git a/lld/MachO/Target.h b/lld/MachO/Target.h index 20e6af1b2130..145c14037995 100644 --- a/lld/MachO/Target.h +++ b/lld/MachO/Target.h @@ -58,7 +58,7 @@ public: virtual int64_t getEmbeddedAddend(llvm::MemoryBufferRef, uint64_t offset, const llvm::MachO::relocation_info) const = 0; - virtual void relocateOne(uint8_t *loc, const Reloc &, uint64_t va, + virtual void relocateOne(uint8_t *loc, const Relocation &, uint64_t va, uint64_t relocVA) const = 0; // Write code for lazy binding. See the comments on StubsSection for more @@ -119,7 +119,7 @@ public: // For now, handleDtraceReloc only implements -no_dtrace_dof, and ensures // that the linking would not fail even when there are user-provided dtrace // symbols. However, unlike ld64, lld currently does not emit __dof sections. - virtual void handleDtraceReloc(const Symbol *sym, const Reloc &r, + virtual void handleDtraceReloc(const Symbol *sym, const Relocation &r, uint8_t *loc) const { llvm_unreachable("Unsupported architecture for dtrace symbols"); } diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index bf01b12d11df..9775a723a92f 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -232,7 +232,7 @@ void UnwindInfoSectionImpl::prepareRelocations(ConcatInputSection *isec) { // that are referenced from many places, at least some of them likely // live, it wouldn't reduce number of got entries. for (size_t i = 0; i < isec->relocs.size(); ++i) { - Reloc &r = isec->relocs[i]; + Relocation &r = isec->relocs[i]; assert(target->hasAttr(r.type, RelocAttrBits::UNSIGNED)); // Since compact unwind sections aren't part of the inputSections vector, // they don't get canonicalized by scanRelocations(), so we have to do the @@ -386,7 +386,7 @@ void UnwindInfoSectionImpl::relocateCompactUnwind( cu.functionLength = support::endian::read32le(buf + cuLayout.functionLengthOffset); cu.encoding = support::endian::read32le(buf + cuLayout.encodingOffset); - for (const Reloc &r : d->unwindEntry()->relocs) { + for (const Relocation &r : d->unwindEntry()->relocs) { if (r.offset == cuLayout.personalityOffset) cu.personality = cast(r.referent); else if (r.offset == cuLayout.lsdaOffset) diff --git a/lld/MachO/Writer.cpp b/lld/MachO/Writer.cpp index 995792be4174..f9fd12a13dba 100644 --- a/lld/MachO/Writer.cpp +++ b/lld/MachO/Writer.cpp @@ -663,7 +663,7 @@ void Writer::treatSpecialUndefineds() { } static void prepareSymbolRelocation(Symbol *sym, const InputSection *isec, - const lld::macho::Reloc &r) { + const Relocation &r) { if (!sym->isLive()) { if (Defined *defined = dyn_cast(sym)) { if (config->emitInitOffsets && @@ -707,7 +707,7 @@ void Writer::scanRelocations() { continue; for (auto it = isec->relocs.begin(); it != isec->relocs.end(); ++it) { - lld::macho::Reloc &r = *it; + Relocation &r = *it; // Canonicalize the referent so that later accesses in Writer won't // have to worry about it.