Skip to content

Commit f645560

Browse files
committed
[ELF] Move getSymbol/getRelocTargetSym from ObjFile<ELFT> to InputFile. NFC
This removes lots of unneeded `template getFile<ELFT>()`.
1 parent b7f97d3 commit f645560

File tree

8 files changed

+29
-30
lines changed

8 files changed

+29
-30
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@ addTaggedSymbolReferences(InputSectionBase &sec,
994994
error("non-RELA relocations are not allowed with memtag globals");
995995

996996
for (const typename ELFT::Rela &rel : rels.relas) {
997-
Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
997+
Symbol &sym = sec.file->getRelocTargetSym(rel);
998998
// Linker-synthesized symbols such as __executable_start may be referenced
999999
// as tagged in input objfiles, and we don't want them to be tagged. A
10001000
// cheap way to exclude them is the type check, but their type is

lld/ELF/Arch/PPC64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ getRelaTocSymAndAddend(InputSectionBase *tocSec, uint64_t offset) {
347347
uint64_t index = std::min<uint64_t>(offset / 8, relas.size() - 1);
348348
for (;;) {
349349
if (relas[index].r_offset == offset) {
350-
Symbol &sym = tocSec->getFile<ELFT>()->getRelocTargetSym(relas[index]);
350+
Symbol &sym = tocSec->file->getRelocTargetSym(relas[index]);
351351
return {dyn_cast<Defined>(&sym), getAddend<ELFT>(relas[index])};
352352
}
353353
if (relas[index].r_offset < offset || index == 0)

lld/ELF/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,9 +2302,9 @@ static void readSymbolPartitionSection(InputSectionBase *s) {
23022302
Symbol *sym;
23032303
const RelsOrRelas<ELFT> rels = s->template relsOrRelas<ELFT>();
23042304
if (rels.areRelocsRel())
2305-
sym = &s->getFile<ELFT>()->getRelocTargetSym(rels.rels[0]);
2305+
sym = &s->file->getRelocTargetSym(rels.rels[0]);
23062306
else
2307-
sym = &s->getFile<ELFT>()->getRelocTargetSym(rels.relas[0]);
2307+
sym = &s->file->getRelocTargetSym(rels.relas[0]);
23082308
if (!isa<Defined>(sym) || !sym->includeInDynsym())
23092309
return;
23102310

lld/ELF/ICF.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,8 @@ bool ICF<ELFT>::constantEq(const InputSection *secA, ArrayRef<RelTy> ra,
247247
uint64_t addA = getAddend<ELFT>(ra[i]);
248248
uint64_t addB = getAddend<ELFT>(rb[i]);
249249

250-
Symbol &sa = secA->template getFile<ELFT>()->getRelocTargetSym(ra[i]);
251-
Symbol &sb = secB->template getFile<ELFT>()->getRelocTargetSym(rb[i]);
250+
Symbol &sa = secA->file->getRelocTargetSym(ra[i]);
251+
Symbol &sb = secB->file->getRelocTargetSym(rb[i]);
252252
if (&sa == &sb) {
253253
if (addA == addB)
254254
continue;
@@ -338,8 +338,8 @@ bool ICF<ELFT>::variableEq(const InputSection *secA, ArrayRef<RelTy> ra,
338338

339339
for (size_t i = 0; i < ra.size(); ++i) {
340340
// The two sections must be identical.
341-
Symbol &sa = secA->template getFile<ELFT>()->getRelocTargetSym(ra[i]);
342-
Symbol &sb = secB->template getFile<ELFT>()->getRelocTargetSym(rb[i]);
341+
Symbol &sa = secA->file->getRelocTargetSym(ra[i]);
342+
Symbol &sb = secB->file->getRelocTargetSym(rb[i]);
343343
if (&sa == &sb)
344344
continue;
345345

@@ -437,12 +437,12 @@ void ICF<ELFT>::forEachClass(llvm::function_ref<void(size_t, size_t)> fn) {
437437

438438
// Combine the hashes of the sections referenced by the given section into its
439439
// hash.
440-
template <class ELFT, class RelTy>
440+
template <class RelTy>
441441
static void combineRelocHashes(unsigned cnt, InputSection *isec,
442442
ArrayRef<RelTy> rels) {
443443
uint32_t hash = isec->eqClass[cnt % 2];
444444
for (RelTy rel : rels) {
445-
Symbol &s = isec->template getFile<ELFT>()->getRelocTargetSym(rel);
445+
Symbol &s = isec->file->getRelocTargetSym(rel);
446446
if (auto *d = dyn_cast<Defined>(&s))
447447
if (auto *relSec = dyn_cast_or_null<InputSection>(d->section))
448448
hash += relSec->eqClass[cnt % 2];
@@ -504,9 +504,9 @@ template <class ELFT> void ICF<ELFT>::run() {
504504
parallelForEach(sections, [&](InputSection *s) {
505505
const RelsOrRelas<ELFT> rels = s->template relsOrRelas<ELFT>();
506506
if (rels.areRelocsRel())
507-
combineRelocHashes<ELFT>(cnt, s, rels.rels);
507+
combineRelocHashes(cnt, s, rels.rels);
508508
else
509-
combineRelocHashes<ELFT>(cnt, s, rels.relas);
509+
combineRelocHashes(cnt, s, rels.relas);
510510
});
511511
}
512512

lld/ELF/InputFiles.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ class InputFile {
9999
return {symbols.get(), numSymbols};
100100
}
101101

102+
Symbol &getSymbol(uint32_t symbolIndex) const {
103+
assert(fileKind == ObjKind);
104+
if (symbolIndex >= numSymbols)
105+
fatal(toString(this) + ": invalid symbol index");
106+
return *this->symbols[symbolIndex];
107+
}
108+
109+
template <typename RelT> Symbol &getRelocTargetSym(const RelT &rel) const {
110+
uint32_t symIndex = rel.getSymbol(config->isMips64EL);
111+
return getSymbol(symIndex);
112+
}
113+
102114
// Get filename to use for linker script processing.
103115
StringRef getNameForScript() const;
104116

@@ -242,19 +254,8 @@ template <class ELFT> class ObjFile : public ELFFileBase {
242254
StringRef getShtGroupSignature(ArrayRef<Elf_Shdr> sections,
243255
const Elf_Shdr &sec);
244256

245-
Symbol &getSymbol(uint32_t symbolIndex) const {
246-
if (symbolIndex >= numSymbols)
247-
fatal(toString(this) + ": invalid symbol index");
248-
return *this->symbols[symbolIndex];
249-
}
250-
251257
uint32_t getSectionIndex(const Elf_Sym &sym) const;
252258

253-
template <typename RelT> Symbol &getRelocTargetSym(const RelT &rel) const {
254-
uint32_t symIndex = rel.getSymbol(config->isMips64EL);
255-
return getSymbol(symIndex);
256-
}
257-
258259
std::optional<llvm::DILineInfo> getDILineInfo(const InputSectionBase *,
259260
uint64_t);
260261
std::optional<std::pair<std::string, unsigned>>

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
924924
if (!RelTy::IsRela)
925925
addend += target.getImplicitAddend(bufLoc, type);
926926

927-
Symbol &sym = getFile<ELFT>()->getRelocTargetSym(rel);
927+
Symbol &sym = this->file->getRelocTargetSym(rel);
928928
RelExpr expr = target.getRelExpr(type, sym, bufLoc);
929929
if (expr == R_NONE)
930930
continue;
@@ -939,7 +939,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
939939
val = *tombstone;
940940
} else {
941941
val = sym.getVA(addend) -
942-
(getFile<ELFT>()->getRelocTargetSym(rels[i]).getVA(0) +
942+
(this->file->getRelocTargetSym(rels[i]).getVA(0) +
943943
getAddend<ELFT>(rels[i]));
944944
}
945945
if (overwriteULEB128(bufLoc, val) >= 0x80)

lld/ELF/MarkLive.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ template <class ELFT>
8989
template <class RelTy>
9090
void MarkLive<ELFT>::resolveReloc(InputSectionBase &sec, RelTy &rel,
9191
bool fromFDE) {
92-
Symbol &sym = sec.getFile<ELFT>()->getRelocTargetSym(rel);
93-
9492
// If a symbol is referenced in a live section, it is used.
93+
Symbol &sym = sec.file->getRelocTargetSym(rel);
9594
sym.used = true;
9695

9796
if (auto *d = dyn_cast<Defined>(&sym)) {

lld/ELF/SyntheticSections.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ CieRecord *EhFrameSection::addCie(EhSectionPiece &cie, ArrayRef<RelTy> rels) {
365365
Symbol *personality = nullptr;
366366
unsigned firstRelI = cie.firstRelocation;
367367
if (firstRelI != (unsigned)-1)
368-
personality =
369-
&cie.sec->template getFile<ELFT>()->getRelocTargetSym(rels[firstRelI]);
368+
personality = &cie.sec->file->getRelocTargetSym(rels[firstRelI]);
370369

371370
// Search for an existing CIE by CIE contents/relocation target pair.
372371
CieRecord *&rec = cieMap[{cie.data(), personality}];
@@ -396,7 +395,7 @@ Defined *EhFrameSection::isFdeLive(EhSectionPiece &fde, ArrayRef<RelTy> rels) {
396395
return nullptr;
397396

398397
const RelTy &rel = rels[firstRelI];
399-
Symbol &b = sec->template getFile<ELFT>()->getRelocTargetSym(rel);
398+
Symbol &b = sec->file->getRelocTargetSym(rel);
400399

401400
// FDEs for garbage-collected or merged-by-ICF sections, or sections in
402401
// another partition, are dead.

0 commit comments

Comments
 (0)