diff --git a/lld/MachO/Arch/ARM64.cpp b/lld/MachO/Arch/ARM64.cpp index 882873ae5de0..bf458e392be8 100644 --- a/lld/MachO/Arch/ARM64.cpp +++ b/lld/MachO/Arch/ARM64.cpp @@ -202,7 +202,7 @@ InputSection *ARM64::getThunkBranchTarget(InputSection *thunk) const { assert(thunk->relocs.size() == 1 && "expected a single reloc on ARM64 ICF thunk"); auto &reloc = thunk->relocs[0]; - assert(reloc.referent.is() && + assert(isa(reloc.referent) && "ARM64 thunk reloc is expected to point to an InputSection"); return reloc.referent.dyn_cast(); diff --git a/lld/MachO/ConcatOutputSection.cpp b/lld/MachO/ConcatOutputSection.cpp index e89cafe0d1e6..6a9301f84a03 100644 --- a/lld/MachO/ConcatOutputSection.cpp +++ b/lld/MachO/ConcatOutputSection.cpp @@ -145,7 +145,7 @@ bool TextOutputSection::needsThunks() const { for (Reloc &r : isec->relocs) { if (!target->hasAttr(r.type, RelocAttrBits::BRANCH)) continue; - auto *sym = r.referent.get(); + auto *sym = cast(r.referent); // Pre-populate the thunkMap and memoize call site counts for every // InputSection and ThunkInfo. We do this for the benefit of // estimateStubsInRangeVA(). @@ -297,7 +297,7 @@ void TextOutputSection::finalize() { backwardBranchRange < callVA ? callVA - backwardBranchRange : 0; uint64_t highVA = callVA + forwardBranchRange; // Calculate our call referent address - auto *funcSym = r.referent.get(); + auto *funcSym = cast(r.referent); ThunkInfo &thunkInfo = thunkMap[funcSym]; // The referent is not reachable, so we need to use a thunk ... if (funcSym->isInStubs() && callVA >= stubsInRangeVA) { diff --git a/lld/MachO/EhFrame.cpp b/lld/MachO/EhFrame.cpp index 55a85f316cdd..2446b49b5098 100644 --- a/lld/MachO/EhFrame.cpp +++ b/lld/MachO/EhFrame.cpp @@ -114,7 +114,7 @@ static void createSubtraction(PointerUnion a, auto minuend = b; if (Invert) std::swap(subtrahend, minuend); - assert(subtrahend.is()); + assert(isa(subtrahend)); Reloc subtrahendReloc(target->subtractorRelocType, /*pcrel=*/false, length, off, /*addend=*/0, subtrahend); Reloc minuendReloc(target->unsignedRelocType, /*pcrel=*/false, length, off, diff --git a/lld/MachO/ICF.cpp b/lld/MachO/ICF.cpp index 32dd44ab729e..75702b9c15e7 100644 --- a/lld/MachO/ICF.cpp +++ b/lld/MachO/ICF.cpp @@ -115,16 +115,16 @@ bool ICF::equalsConstant(const ConcatInputSection *ia, return false; if (ra.offset != rb.offset) return false; - if (ra.referent.is() != rb.referent.is()) + if (isa(ra.referent) != isa(rb.referent)) return false; InputSection *isecA, *isecB; uint64_t valueA = 0; uint64_t valueB = 0; - if (ra.referent.is()) { - const auto *sa = ra.referent.get(); - const auto *sb = rb.referent.get(); + if (isa(ra.referent)) { + const auto *sa = cast(ra.referent); + const auto *sb = cast(rb.referent); if (sa->kind() != sb->kind()) return false; // ICF runs before Undefineds are treated (and potentially converted into @@ -143,8 +143,8 @@ bool ICF::equalsConstant(const ConcatInputSection *ia, isecB = db->isec(); valueB = db->value; } else { - isecA = ra.referent.get(); - isecB = rb.referent.get(); + isecA = cast(ra.referent); + isecB = cast(rb.referent); } // Typically, we should not encounter sections marked with `keepUnique` at @@ -167,7 +167,7 @@ bool ICF::equalsConstant(const ConcatInputSection *ia, return ra.addend == rb.addend; // Else we have two literal sections. References to them are equal iff their // offsets in the output section are equal. - if (ra.referent.is()) + if (isa(ra.referent)) // For symbol relocs, we compare the contents at the symbol address. We // don't do `getOffset(value + addend)` because value + addend may not be // a valid offset in the literal section. @@ -195,12 +195,12 @@ bool ICF::equalsVariable(const ConcatInputSection *ia, if (ra.referent == rb.referent) return true; const ConcatInputSection *isecA, *isecB; - if (ra.referent.is()) { + if (isa(ra.referent)) { // Matching DylibSymbols are already filtered out by the // identical-referent check above. Non-matching DylibSymbols were filtered // out in equalsConstant(). So we can safely cast to Defined here. - const auto *da = cast(ra.referent.get()); - const auto *db = cast(rb.referent.get()); + const auto *da = cast(cast(ra.referent)); + const auto *db = cast(cast(rb.referent)); if (da->isAbsolute()) return true; isecA = dyn_cast(da->isec()); @@ -208,8 +208,8 @@ bool ICF::equalsVariable(const ConcatInputSection *ia, return true; // literal sections were checked in equalsConstant. isecB = cast(db->isec()); } else { - const auto *sa = ra.referent.get(); - const auto *sb = rb.referent.get(); + const auto *sa = cast(ra.referent); + const auto *sb = cast(rb.referent); isecA = dyn_cast(sa); if (!isecA) return true; diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index c3f7c434ffca..9adfbc9d3f6f 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -1291,7 +1291,7 @@ static CIE parseCIE(const InputSection *isec, const EhReader &reader, const auto *personalityReloc = isec->getRelocAt(personalityAddrOff); if (!personalityReloc) reader.failOn(off, "Failed to locate relocation for personality symbol"); - cie.personalitySymbol = personalityReloc->referent.get(); + cie.personalitySymbol = cast(personalityReloc->referent); } return cie; } @@ -1338,12 +1338,12 @@ targetSymFromCanonicalSubtractor(const InputSection *isec, assert(target->hasAttr(minuend.type, RelocAttrBits::UNSIGNED)); // Note: pcSym may *not* be exactly at the PC; there's usually a non-zero // addend. - auto *pcSym = cast(subtrahend.referent.get()); + auto *pcSym = cast(cast(subtrahend.referent)); Defined *target = cast_or_null(minuend.referent.dyn_cast()); if (!pcSym) { auto *targetIsec = - cast(minuend.referent.get()); + cast(cast(minuend.referent)); target = findSymbolAtOffset(targetIsec, minuend.addend); } if (Invert) diff --git a/lld/MachO/InputSection.cpp b/lld/MachO/InputSection.cpp index c1b3297f321f..07e39b04cba4 100644 --- a/lld/MachO/InputSection.cpp +++ b/lld/MachO/InputSection.cpp @@ -226,13 +226,13 @@ void ConcatInputSection::writeTo(uint8_t *buf) { const bool needsFixup = config->emitChainedFixups && target->hasAttr(r.type, RelocAttrBits::UNSIGNED); if (target->hasAttr(r.type, RelocAttrBits::SUBTRAHEND)) { - const Symbol *fromSym = r.referent.get(); + const Symbol *fromSym = cast(r.referent); const Reloc &minuend = relocs[++i]; uint64_t minuendVA; if (const Symbol *toSym = minuend.referent.dyn_cast()) minuendVA = toSym->getVA() + minuend.addend; else { - auto *referentIsec = minuend.referent.get(); + auto *referentIsec = cast(minuend.referent); assert(!::shouldOmitFromOutput(referentIsec)); minuendVA = referentIsec->getVA(minuend.addend); } diff --git a/lld/MachO/MarkLive.cpp b/lld/MachO/MarkLive.cpp index c26c3aa32119..4f67f3a2d802 100644 --- a/lld/MachO/MarkLive.cpp +++ b/lld/MachO/MarkLive.cpp @@ -160,7 +160,7 @@ void MarkLiveImpl::markTransitively() { if (auto *s = r.referent.dyn_cast()) addSym(s, entry); else - enqueue(r.referent.get(), r.addend, entry); + enqueue(cast(r.referent), r.addend, entry); } for (Defined *d : getInputSection(entry)->symbols) addSym(d, entry); @@ -183,7 +183,7 @@ void MarkLiveImpl::markTransitively() { enqueue(isec, 0, makeEntry(referentIsec, nullptr)); } } else { - auto *referentIsec = r.referent.get(); + auto *referentIsec = cast(r.referent); if (referentIsec->isLive(r.addend)) enqueue(isec, 0, makeEntry(referentIsec, nullptr)); } diff --git a/lld/MachO/ObjC.cpp b/lld/MachO/ObjC.cpp index ff13e8eb4b5c..272197b34e11 100644 --- a/lld/MachO/ObjC.cpp +++ b/lld/MachO/ObjC.cpp @@ -263,7 +263,7 @@ void ObjcCategoryChecker::parseCategory(const ConcatInputSection *catIsec) { if (!classReloc) return; - auto *classSym = classReloc->referent.get(); + auto *classSym = cast(classReloc->referent); if (auto *d = dyn_cast(classSym)) if (!classMap.count(d)) parseClass(d); @@ -603,7 +603,7 @@ void ObjcCategoryMerger::tryEraseDefinedAtIsecOffset( if (!reloc) return; - Defined *sym = dyn_cast_or_null(reloc->referent.get()); + Defined *sym = dyn_cast_or_null(cast(reloc->referent)); if (!sym) return; @@ -675,7 +675,7 @@ void ObjcCategoryMerger::parseProtocolListInfo( if (!reloc) return; - auto *ptrListSym = dyn_cast_or_null(reloc->referent.get()); + auto *ptrListSym = dyn_cast_or_null(cast(reloc->referent)); assert(ptrListSym && "Protocol list reloc does not have a valid Defined"); // Theoretically protocol count can be either 32b or 64b, depending on @@ -707,7 +707,7 @@ void ObjcCategoryMerger::parseProtocolListInfo( const Reloc *reloc = ptrListSym->isec()->getRelocAt(off); assert(reloc && "No reloc found at protocol list offset"); - auto *listSym = dyn_cast_or_null(reloc->referent.get()); + auto *listSym = dyn_cast_or_null(cast(reloc->referent)); assert(listSym && "Protocol list reloc does not have a valid Defined"); ptrList.allPtrs.push_back(listSym); @@ -745,7 +745,7 @@ bool ObjcCategoryMerger::parsePointerListInfo(const ConcatInputSection *isec, if (!reloc) return true; - auto *ptrListSym = dyn_cast_or_null(reloc->referent.get()); + auto *ptrListSym = dyn_cast_or_null(cast(reloc->referent)); assert(ptrListSym && "Reloc does not have a valid Defined"); uint32_t thisStructSize = *reinterpret_cast( diff --git a/lld/MachO/Relocations.cpp b/lld/MachO/Relocations.cpp index e8ede19d1fda..aac0e1bd3c9e 100644 --- a/lld/MachO/Relocations.cpp +++ b/lld/MachO/Relocations.cpp @@ -27,7 +27,7 @@ InputSection *Reloc::getReferentInputSection() const { return d->isec(); return nullptr; } else { - return referent.get(); + return cast(referent); } } @@ -38,7 +38,7 @@ StringRef Reloc::getReferentString() const { return cisec->getStringRefAtOffset(addend); } - auto *sym = dyn_cast(referent.get()); + auto *sym = dyn_cast(cast(referent)); assert(sym && "referent must be a Defined symbol"); auto *symIsec = sym->isec(); diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 24844c2f3a1e..28fb8047cacd 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -1990,7 +1990,7 @@ void InitOffsetsSection::setUp() { if (rel.addend != 0) error(isec->getLocation(rel.offset) + ": relocation addend is not representable in __init_offsets"); - if (rel.referent.is()) + if (isa(rel.referent)) error(isec->getLocation(rel.offset) + ": unexpected section relocation"); @@ -2136,12 +2136,12 @@ void ObjCMethListSection::writeRelativeOffsetForIsec( symVA = selRef->getVA(); assert(selRef->data.size() == target->wordSize && "Expected one selref per ConcatInputSection"); - } else if (reloc->referent.is()) { - auto *def = dyn_cast_or_null(reloc->referent.get()); + } else if (auto *sym = dyn_cast(reloc->referent)) { + auto *def = dyn_cast_or_null(sym); assert(def && "Expected all syms in __objc_methlist to be defined"); symVA = def->getVA(); } else { - auto *isec = reloc->referent.get(); + auto *isec = cast(reloc->referent); symVA = isec->getVA(reloc->addend); } diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index 7033481d6014..624464e41d77 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -390,7 +390,7 @@ void UnwindInfoSectionImpl::relocateCompactUnwind( cu.encoding = support::endian::read32le(buf + cuLayout.encodingOffset); for (const Reloc &r : d->unwindEntry()->relocs) { if (r.offset == cuLayout.personalityOffset) - cu.personality = r.referent.get(); + cu.personality = cast(r.referent); else if (r.offset == cuLayout.lsdaOffset) cu.lsda = r.getReferentInputSection(); }