[LLD][MachO][NFC] Rename Reloc to Relocation (#175586)
Due to heavy use of using namespace llvm, Reloc is often ambiguous with llvm::Reloc, the relocation model. Previously, this was sometimes disambiguated with macho::Reloc. This ambiguity is even more problematic when using pre-compiled headers, where it's no longer "obvious" whether it should be Reloc or macho::Reloc. Therefore, rename Reloc to Relocation. This is also consistent with lld/ELF, where the type is also named Relocation.
This commit is contained in:
parent
ef2ec1fbac
commit
af98aadc63
@ -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<uint32_t *>(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<const uint8_t *>(loc) - in.bufferStart;
|
||||
const InputSection *isec = offsetToInputSection(&off);
|
||||
std::string locStr = isec ? isec->getLocation(off) : "(invalid location)";
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ struct BPOrdererMachO : lld::BPOrderer<BPOrdererMachO> {
|
||||
|
||||
private:
|
||||
static uint64_t
|
||||
getRelocHash(const macho::Reloc &reloc,
|
||||
getRelocHash(const Relocation &reloc,
|
||||
const llvm::DenseMap<const void *, uint64_t> §ionToIdx) {
|
||||
auto *isec = reloc.getReferentInputSection();
|
||||
std::optional<uint64_t> sectionIdx;
|
||||
|
||||
@ -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<Symbol *>(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<Reloc> &relocs = isec->relocs;
|
||||
std::vector<Relocation> &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;
|
||||
|
||||
@ -109,16 +109,16 @@ template <bool Invert = false>
|
||||
static void createSubtraction(PointerUnion<Symbol *, InputSection *> a,
|
||||
PointerUnion<Symbol *, InputSection *> b,
|
||||
uint64_t off, uint8_t length,
|
||||
SmallVectorImpl<Reloc> *newRelocs) {
|
||||
SmallVectorImpl<Relocation> *newRelocs) {
|
||||
auto subtrahend = a;
|
||||
auto minuend = b;
|
||||
if (Invert)
|
||||
std::swap(subtrahend, minuend);
|
||||
assert(isa<Symbol *>(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);
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ private:
|
||||
InputSection *isec;
|
||||
// Insert new relocs here so that we don't invalidate iterators into the
|
||||
// existing relocs vector.
|
||||
SmallVector<Reloc, 6> newRelocs;
|
||||
SmallVector<Relocation, 6> newRelocs;
|
||||
};
|
||||
|
||||
} // namespace lld::macho
|
||||
|
||||
@ -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<Symbol *>()) {
|
||||
if (auto *defined = dyn_cast<Defined>(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<Symbol *>())
|
||||
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<uint8_t> 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;
|
||||
|
||||
@ -575,7 +575,7 @@ void ObjFile::parseRelocations(ArrayRef<SectionHeader> 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<SectionHeader> 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 <bool Invert = false>
|
||||
Defined *
|
||||
targetSymFromCanonicalSubtractor(const InputSection *isec,
|
||||
std::vector<macho::Reloc>::iterator relocIt) {
|
||||
macho::Reloc &subtrahend = *relocIt;
|
||||
macho::Reloc &minuend = *std::next(relocIt);
|
||||
std::vector<Relocation>::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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<Reloc>) + 88,
|
||||
static_assert(sizeof(void *) != 8 || sizeof(ConcatInputSection) ==
|
||||
sizeof(std::vector<Relocation>) + 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<Symbol *>(r.referent);
|
||||
const Reloc &minuend = relocs[++i];
|
||||
const Relocation &minuend = relocs[++i];
|
||||
uint64_t minuendVA;
|
||||
if (const Symbol *toSym = minuend.referent.dyn_cast<Symbol *>())
|
||||
minuendVA = toSym->getVA() + minuend.addend;
|
||||
|
||||
@ -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<uint8_t> data;
|
||||
std::vector<Reloc> relocs;
|
||||
std::vector<Relocation> relocs;
|
||||
// The symbols that belong to this InputSection, sorted by value. With
|
||||
// .subsections_via_symbols, there is typically only one element here.
|
||||
llvm::TinyPtrVector<Defined *> symbols;
|
||||
|
||||
@ -154,7 +154,7 @@ void MarkLiveImpl<RecordWhyLive>::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<Symbol *>())
|
||||
addSym(s, entry);
|
||||
else
|
||||
@ -172,7 +172,7 @@ void MarkLiveImpl<RecordWhyLive>::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<Symbol *>()) {
|
||||
if (s->isLive()) {
|
||||
InputSection *referentIsec = nullptr;
|
||||
|
||||
@ -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<ConcatInputSection>(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<Defined>(cast<Symbol *>(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<Symbol *>(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
|
||||
|
||||
@ -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<Symbol *>()) {
|
||||
if (const auto *d = dyn_cast<Defined>(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<InputSection *>(referent)) {
|
||||
const auto *cisec = dyn_cast<CStringInputSection>(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<const uint8_t *>(loc) - in.bufferStart;
|
||||
|
||||
@ -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<Symbol *, InputSection *> referent = nullptr;
|
||||
|
||||
Reloc() = default;
|
||||
Relocation() = default;
|
||||
|
||||
Reloc(uint8_t type, bool pcrel, uint8_t length, uint32_t offset,
|
||||
int64_t addend, llvm::PointerUnion<Symbol *, InputSection *> referent)
|
||||
Relocation(uint8_t type, bool pcrel, uint8_t length, uint32_t offset,
|
||||
int64_t addend,
|
||||
llvm::PointerUnion<Symbol *, InputSection *> 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 {
|
||||
|
||||
@ -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<Symbol *>(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;
|
||||
|
||||
@ -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");
|
||||
}
|
||||
|
||||
@ -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<Symbol *>(r.referent);
|
||||
else if (r.offset == cuLayout.lsdaOffset)
|
||||
|
||||
@ -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<Defined>(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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user