[NFC][ELF] Replace DynamicReloc::Kind with the equivalent bool in APIs

DynamicReloc::AgainstSymbol is now true and DynamicReloc::AddendOnly is
now false; uses of the constants were replaced mechanically.

Reviewers: rnk, MaskRay

Reviewed By: MaskRay

Pull Request: https://github.com/llvm/llvm-project/pull/150813
This commit is contained in:
Jessica Clarke
2025-07-30 17:08:36 +01:00
committed by GitHub
parent ab12b43047
commit 52ddcfd8d6
4 changed files with 31 additions and 47 deletions

View File

@@ -886,11 +886,11 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt,
plt.addEntry(sym);
gotPlt.addEntry(sym);
if (sym.isPreemptible)
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
DynamicReloc::AgainstSymbol, sym, 0, R_ADDEND});
rel.addReloc(
{type, &gotPlt, sym.getGotPltOffset(ctx), true, sym, 0, R_ADDEND});
else
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
DynamicReloc::AddendOnly, sym, 0, R_ABS});
rel.addReloc(
{type, &gotPlt, sym.getGotPltOffset(ctx), false, sym, 0, R_ABS});
}
void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
@@ -899,9 +899,8 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
// If preemptible, emit a GLOB_DAT relocation.
if (sym.isPreemptible) {
ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off,
DynamicReloc::AgainstSymbol, sym, 0,
R_ADDEND});
ctx.mainPart->relaDyn->addReloc(
{ctx.target->gotRel, ctx.in.got.get(), off, true, sym, 0, R_ADDEND});
return;
}
@@ -922,15 +921,13 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
// If preemptible, emit a GLOB_DAT relocation.
if (sym.isPreemptible) {
ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(),
off, DynamicReloc::AgainstSymbol, sym, 0,
R_ADDEND});
off, true, sym, 0, R_ADDEND});
return;
}
// Signed GOT requires dynamic relocation.
ctx.in.got->getPartition(ctx).relaDyn->addReloc(
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, DynamicReloc::AddendOnly,
sym, 0, R_ABS});
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, false, sym, 0, R_ABS});
}
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
@@ -1161,9 +1158,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
sec->addReloc({expr, type, offset, addend, &sym});
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
} else {
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
DynamicReloc::AddendOnly, sym, addend,
R_ABS});
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset, false,
sym, addend, R_ABS});
}
return;
}

View File

@@ -1061,9 +1061,8 @@ void MipsGotSection::build() {
// for the TP-relative offset as we don't know how much other data will
// be allocated before us in the static TLS block.
if (s->isPreemptible || ctx.arg.shared)
ctx.mainPart->relaDyn->addReloc({ctx.target->tlsGotRel, this, offset,
DynamicReloc::AgainstSymbol, *s, 0,
R_ABS});
ctx.mainPart->relaDyn->addReloc(
{ctx.target->tlsGotRel, this, offset, true, *s, 0, R_ABS});
}
for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
Symbol *s = p.first;
@@ -1112,15 +1111,15 @@ void MipsGotSection::build() {
for (size_t pi = 0; pi < pageCount; ++pi) {
uint64_t offset = (l.second.firstIndex + pi) * ctx.arg.wordsize;
ctx.mainPart->relaDyn->addReloc(
{ctx.target->relativeRel, this, offset, DynamicReloc::AddendOnly,
*l.second.repSym, int64_t(pi * 0x10000), RE_MIPS_OSEC_LOCAL_PAGE});
{ctx.target->relativeRel, this, offset, false, *l.second.repSym,
int64_t(pi * 0x10000), RE_MIPS_OSEC_LOCAL_PAGE});
}
}
for (const std::pair<GotEntry, size_t> &p : got.local16) {
uint64_t offset = p.second * ctx.arg.wordsize;
ctx.mainPart->relaDyn->addReloc({ctx.target->relativeRel, this, offset,
DynamicReloc::AddendOnly, *p.first.first,
p.first.second, R_ABS});
false, *p.first.first, p.first.second,
R_ABS});
}
}
}
@@ -1674,8 +1673,8 @@ RelocationBaseSection::RelocationBaseSection(Ctx &ctx, StringRef name,
void RelocationBaseSection::addSymbolReloc(
RelType dynType, InputSectionBase &isec, uint64_t offsetInSec, Symbol &sym,
int64_t addend, std::optional<RelType> addendRelType) {
addReloc(DynamicReloc::AgainstSymbol, dynType, isec, offsetInSec, sym, addend,
R_ADDEND, addendRelType ? *addendRelType : ctx.target->noneRel);
addReloc(true, dynType, isec, offsetInSec, sym, addend, R_ADDEND,
addendRelType ? *addendRelType : ctx.target->noneRel);
}
void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
@@ -1683,11 +1682,9 @@ void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
RelType addendRelType) {
// No need to write an addend to the section for preemptible symbols.
if (sym.isPreemptible)
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
R_ADDEND});
addReloc({dynType, &isec, offsetInSec, true, sym, 0, R_ADDEND});
else
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
R_ABS, addendRelType);
addReloc(false, dynType, isec, offsetInSec, sym, 0, R_ABS, addendRelType);
}
void RelocationBaseSection::mergeRels() {

View File

@@ -420,27 +420,17 @@ private:
class DynamicReloc {
public:
enum Kind {
/// The resulting dynamic relocation will not reference a symbol: #sym is
/// only used to compute the addend with InputSection::getRelocTargetVA().
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
AddendOnly,
/// The resulting dynamic relocation references symbol #sym from the dynamic
/// symbol table and uses InputSection::getRelocTargetVA() for the final
/// addend.
AgainstSymbol,
};
/// This constructor records a normal relocation.
DynamicReloc(RelType type, const InputSectionBase *inputSec,
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
RelExpr expr)
uint64_t offsetInSec, bool isAgainstSymbol, Symbol &sym,
int64_t addend, RelExpr expr)
: sym(&sym), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
addend(addend), isAgainstSymbol(kind == AgainstSymbol), isFinal(false),
addend(addend), isAgainstSymbol(isAgainstSymbol), isFinal(false),
expr(expr) {}
/// This constructor records a relative relocation with no symbol.
DynamicReloc(RelType type, const InputSectionBase *inputSec,
uint64_t offsetInSec, int64_t addend = 0)
: DynamicReloc(type, inputSec, offsetInSec, AddendOnly,
: DynamicReloc(type, inputSec, offsetInSec, false,
*inputSec->getCtx().dummySym, addend, R_ADDEND) {}
uint64_t getOffset() const;
@@ -518,8 +508,8 @@ public:
uint64_t offsetInSec, Symbol &sym, int64_t addend,
RelType addendRelType, RelExpr expr) {
assert(expr != R_ADDEND && "expected non-addend relocation expression");
addReloc<shard>(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym,
addend, expr, addendRelType);
addReloc<shard>(false, dynType, isec, offsetInSec, sym, addend, expr,
addendRelType);
}
/// Add a dynamic relocation using the target address of \p sym as the addend
/// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.
@@ -528,14 +518,15 @@ public:
uint64_t offsetInSec, Symbol &sym,
RelType addendRelType);
template <bool shard = false>
void addReloc(DynamicReloc::Kind kind, RelType dynType, InputSectionBase &sec,
void addReloc(bool isAgainstSymbol, RelType dynType, InputSectionBase &sec,
uint64_t offsetInSec, Symbol &sym, int64_t addend, RelExpr expr,
RelType addendRelType) {
// Write the addends to the relocated address if required. We skip
// it if the written value would be zero.
if (ctx.arg.writeAddends && (expr != R_ADDEND || addend != 0))
sec.addReloc({expr, addendRelType, offsetInSec, addend, &sym});
addReloc<shard>({dynType, &sec, offsetInSec, kind, sym, addend, expr});
addReloc<shard>(
{dynType, &sec, offsetInSec, isAgainstSymbol, sym, addend, expr});
}
bool isNeeded() const override {
return !relocs.empty() ||

View File

@@ -1586,8 +1586,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
if (isInt<32>(reloc.sym->getVA(ctx, reloc.addend)))
return false;
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
reloc.offset, DynamicReloc::AddendOnly,
*reloc.sym, reloc.addend, R_ABS});
reloc.offset, false, *reloc.sym,
reloc.addend, R_ABS});
return true;
});
changed |= (it != part.relrAuthDyn->relocs.end());