Skip to content

Commit f98be2c

Browse files
jrtc27krishna2803
authored andcommitted
[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: llvm#150813
1 parent 32a5f9b commit f98be2c

File tree

4 files changed

+31
-47
lines changed

4 files changed

+31
-47
lines changed

lld/ELF/Relocations.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -886,11 +886,11 @@ static void addPltEntry(Ctx &ctx, PltSection &plt, GotPltSection &gotPlt,
886886
plt.addEntry(sym);
887887
gotPlt.addEntry(sym);
888888
if (sym.isPreemptible)
889-
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
890-
DynamicReloc::AgainstSymbol, sym, 0, R_ADDEND});
889+
rel.addReloc(
890+
{type, &gotPlt, sym.getGotPltOffset(ctx), true, sym, 0, R_ADDEND});
891891
else
892-
rel.addReloc({type, &gotPlt, sym.getGotPltOffset(ctx),
893-
DynamicReloc::AddendOnly, sym, 0, R_ABS});
892+
rel.addReloc(
893+
{type, &gotPlt, sym.getGotPltOffset(ctx), false, sym, 0, R_ABS});
894894
}
895895

896896
void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
@@ -899,9 +899,8 @@ void elf::addGotEntry(Ctx &ctx, Symbol &sym) {
899899

900900
// If preemptible, emit a GLOB_DAT relocation.
901901
if (sym.isPreemptible) {
902-
ctx.mainPart->relaDyn->addReloc({ctx.target->gotRel, ctx.in.got.get(), off,
903-
DynamicReloc::AgainstSymbol, sym, 0,
904-
R_ADDEND});
902+
ctx.mainPart->relaDyn->addReloc(
903+
{ctx.target->gotRel, ctx.in.got.get(), off, true, sym, 0, R_ADDEND});
905904
return;
906905
}
907906

@@ -922,15 +921,13 @@ static void addGotAuthEntry(Ctx &ctx, Symbol &sym) {
922921
// If preemptible, emit a GLOB_DAT relocation.
923922
if (sym.isPreemptible) {
924923
ctx.mainPart->relaDyn->addReloc({R_AARCH64_AUTH_GLOB_DAT, ctx.in.got.get(),
925-
off, DynamicReloc::AgainstSymbol, sym, 0,
926-
R_ADDEND});
924+
off, true, sym, 0, R_ADDEND});
927925
return;
928926
}
929927

930928
// Signed GOT requires dynamic relocation.
931929
ctx.in.got->getPartition(ctx).relaDyn->addReloc(
932-
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, DynamicReloc::AddendOnly,
933-
sym, 0, R_ABS});
930+
{R_AARCH64_AUTH_RELATIVE, ctx.in.got.get(), off, false, sym, 0, R_ABS});
934931
}
935932

936933
static void addTpOffsetGotEntry(Ctx &ctx, Symbol &sym) {
@@ -1161,9 +1158,8 @@ void RelocationScanner::processAux(RelExpr expr, RelType type, uint64_t offset,
11611158
sec->addReloc({expr, type, offset, addend, &sym});
11621159
part.relrAuthDyn->relocs.push_back({sec, sec->relocs().size() - 1});
11631160
} else {
1164-
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset,
1165-
DynamicReloc::AddendOnly, sym, addend,
1166-
R_ABS});
1161+
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, sec, offset, false,
1162+
sym, addend, R_ABS});
11671163
}
11681164
return;
11691165
}

lld/ELF/SyntheticSections.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,9 +1061,8 @@ void MipsGotSection::build() {
10611061
// for the TP-relative offset as we don't know how much other data will
10621062
// be allocated before us in the static TLS block.
10631063
if (s->isPreemptible || ctx.arg.shared)
1064-
ctx.mainPart->relaDyn->addReloc({ctx.target->tlsGotRel, this, offset,
1065-
DynamicReloc::AgainstSymbol, *s, 0,
1066-
R_ABS});
1064+
ctx.mainPart->relaDyn->addReloc(
1065+
{ctx.target->tlsGotRel, this, offset, true, *s, 0, R_ABS});
10671066
}
10681067
for (std::pair<Symbol *, size_t> &p : got.dynTlsSymbols) {
10691068
Symbol *s = p.first;
@@ -1112,15 +1111,15 @@ void MipsGotSection::build() {
11121111
for (size_t pi = 0; pi < pageCount; ++pi) {
11131112
uint64_t offset = (l.second.firstIndex + pi) * ctx.arg.wordsize;
11141113
ctx.mainPart->relaDyn->addReloc(
1115-
{ctx.target->relativeRel, this, offset, DynamicReloc::AddendOnly,
1116-
*l.second.repSym, int64_t(pi * 0x10000), RE_MIPS_OSEC_LOCAL_PAGE});
1114+
{ctx.target->relativeRel, this, offset, false, *l.second.repSym,
1115+
int64_t(pi * 0x10000), RE_MIPS_OSEC_LOCAL_PAGE});
11171116
}
11181117
}
11191118
for (const std::pair<GotEntry, size_t> &p : got.local16) {
11201119
uint64_t offset = p.second * ctx.arg.wordsize;
11211120
ctx.mainPart->relaDyn->addReloc({ctx.target->relativeRel, this, offset,
1122-
DynamicReloc::AddendOnly, *p.first.first,
1123-
p.first.second, R_ABS});
1121+
false, *p.first.first, p.first.second,
1122+
R_ABS});
11241123
}
11251124
}
11261125
}
@@ -1674,20 +1673,18 @@ RelocationBaseSection::RelocationBaseSection(Ctx &ctx, StringRef name,
16741673
void RelocationBaseSection::addSymbolReloc(
16751674
RelType dynType, InputSectionBase &isec, uint64_t offsetInSec, Symbol &sym,
16761675
int64_t addend, std::optional<RelType> addendRelType) {
1677-
addReloc(DynamicReloc::AgainstSymbol, dynType, isec, offsetInSec, sym, addend,
1678-
R_ADDEND, addendRelType ? *addendRelType : ctx.target->noneRel);
1676+
addReloc(true, dynType, isec, offsetInSec, sym, addend, R_ADDEND,
1677+
addendRelType ? *addendRelType : ctx.target->noneRel);
16791678
}
16801679

16811680
void RelocationBaseSection::addAddendOnlyRelocIfNonPreemptible(
16821681
RelType dynType, InputSectionBase &isec, uint64_t offsetInSec, Symbol &sym,
16831682
RelType addendRelType) {
16841683
// No need to write an addend to the section for preemptible symbols.
16851684
if (sym.isPreemptible)
1686-
addReloc({dynType, &isec, offsetInSec, DynamicReloc::AgainstSymbol, sym, 0,
1687-
R_ADDEND});
1685+
addReloc({dynType, &isec, offsetInSec, true, sym, 0, R_ADDEND});
16881686
else
1689-
addReloc(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym, 0,
1690-
R_ABS, addendRelType);
1687+
addReloc(false, dynType, isec, offsetInSec, sym, 0, R_ABS, addendRelType);
16911688
}
16921689

16931690
void RelocationBaseSection::mergeRels() {

lld/ELF/SyntheticSections.h

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,17 @@ class StringTableSection final : public SyntheticSection {
420420

421421
class DynamicReloc {
422422
public:
423-
enum Kind {
424-
/// The resulting dynamic relocation will not reference a symbol: #sym is
425-
/// only used to compute the addend with InputSection::getRelocTargetVA().
426-
/// Useful for various relative and TLS relocations (e.g. R_X86_64_TPOFF64).
427-
AddendOnly,
428-
/// The resulting dynamic relocation references symbol #sym from the dynamic
429-
/// symbol table and uses InputSection::getRelocTargetVA() for the final
430-
/// addend.
431-
AgainstSymbol,
432-
};
433423
/// This constructor records a normal relocation.
434424
DynamicReloc(RelType type, const InputSectionBase *inputSec,
435-
uint64_t offsetInSec, Kind kind, Symbol &sym, int64_t addend,
436-
RelExpr expr)
425+
uint64_t offsetInSec, bool isAgainstSymbol, Symbol &sym,
426+
int64_t addend, RelExpr expr)
437427
: sym(&sym), inputSec(inputSec), offsetInSec(offsetInSec), type(type),
438-
addend(addend), isAgainstSymbol(kind == AgainstSymbol), isFinal(false),
428+
addend(addend), isAgainstSymbol(isAgainstSymbol), isFinal(false),
439429
expr(expr) {}
440430
/// This constructor records a relative relocation with no symbol.
441431
DynamicReloc(RelType type, const InputSectionBase *inputSec,
442432
uint64_t offsetInSec, int64_t addend = 0)
443-
: DynamicReloc(type, inputSec, offsetInSec, AddendOnly,
433+
: DynamicReloc(type, inputSec, offsetInSec, false,
444434
*inputSec->getCtx().dummySym, addend, R_ADDEND) {}
445435

446436
uint64_t getOffset() const;
@@ -518,8 +508,8 @@ class RelocationBaseSection : public SyntheticSection {
518508
uint64_t offsetInSec, Symbol &sym, int64_t addend,
519509
RelType addendRelType, RelExpr expr) {
520510
assert(expr != R_ADDEND && "expected non-addend relocation expression");
521-
addReloc<shard>(DynamicReloc::AddendOnly, dynType, isec, offsetInSec, sym,
522-
addend, expr, addendRelType);
511+
addReloc<shard>(false, dynType, isec, offsetInSec, sym, addend, expr,
512+
addendRelType);
523513
}
524514
/// Add a dynamic relocation using the target address of \p sym as the addend
525515
/// if \p sym is non-preemptible. Otherwise add a relocation against \p sym.
@@ -528,14 +518,15 @@ class RelocationBaseSection : public SyntheticSection {
528518
uint64_t offsetInSec, Symbol &sym,
529519
RelType addendRelType);
530520
template <bool shard = false>
531-
void addReloc(DynamicReloc::Kind kind, RelType dynType, InputSectionBase &sec,
521+
void addReloc(bool isAgainstSymbol, RelType dynType, InputSectionBase &sec,
532522
uint64_t offsetInSec, Symbol &sym, int64_t addend, RelExpr expr,
533523
RelType addendRelType) {
534524
// Write the addends to the relocated address if required. We skip
535525
// it if the written value would be zero.
536526
if (ctx.arg.writeAddends && (expr != R_ADDEND || addend != 0))
537527
sec.addReloc({expr, addendRelType, offsetInSec, addend, &sym});
538-
addReloc<shard>({dynType, &sec, offsetInSec, kind, sym, addend, expr});
528+
addReloc<shard>(
529+
{dynType, &sec, offsetInSec, isAgainstSymbol, sym, addend, expr});
539530
}
540531
bool isNeeded() const override {
541532
return !relocs.empty() ||

lld/ELF/Writer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,8 @@ template <class ELFT> void Writer<ELFT>::finalizeAddressDependentContent() {
15861586
if (isInt<32>(reloc.sym->getVA(ctx, reloc.addend)))
15871587
return false;
15881588
part.relaDyn->addReloc({R_AARCH64_AUTH_RELATIVE, elem.inputSec,
1589-
reloc.offset, DynamicReloc::AddendOnly,
1590-
*reloc.sym, reloc.addend, R_ABS});
1589+
reloc.offset, false, *reloc.sym,
1590+
reloc.addend, R_ABS});
15911591
return true;
15921592
});
15931593
changed |= (it != part.relrAuthDyn->relocs.end());

0 commit comments

Comments
 (0)