Skip to content

Commit 4845531

Browse files
author
Georgii Rymar
committed
[lib/Object] - Refine interface of ELFFile<ELFT>. NFCI.
`ELFFile<ELFT>` has many methods that take pointers, though they assume that arguments are never null and hence could take references instead. This patch performs such clean-up. Differential revision: https://reviews.llvm.org/D87385
1 parent 9b4fa85 commit 4845531

File tree

21 files changed

+378
-379
lines changed

21 files changed

+378
-379
lines changed

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ AMDGPU::AMDGPU() {
4141
}
4242

4343
static uint32_t getEFlags(InputFile *file) {
44-
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader()->e_flags;
44+
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader().e_flags;
4545
}
4646

4747
uint32_t AMDGPU::calcEFlags() const {

lld/ELF/Arch/Hexagon.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ uint32_t Hexagon::calcEFlags() const {
6666
// greatest revision in the list of inputs.
6767
uint32_t ret = 0;
6868
for (InputFile *f : objectFiles) {
69-
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader()->e_flags;
69+
uint32_t eflags = cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
7070
if (eflags > ret)
7171
ret = eflags;
7272
}

lld/ELF/Arch/Mips.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ bool MIPS<ELFT>::needsThunk(RelExpr expr, RelType type, const InputFile *file,
372372
if (!f)
373373
return false;
374374
// If current file has PIC code, LA25 stub is not required.
375-
if (f->getObj().getHeader()->e_flags & EF_MIPS_PIC)
375+
if (f->getObj().getHeader().e_flags & EF_MIPS_PIC)
376376
return false;
377377
auto *d = dyn_cast<Defined>(&s);
378378
// LA25 is required if target file has PIC code
@@ -749,7 +749,7 @@ template <class ELFT> bool elf::isMipsPIC(const Defined *sym) {
749749
if (!file)
750750
return false;
751751

752-
return file->getObj().getHeader()->e_flags & EF_MIPS_PIC;
752+
return file->getObj().getHeader().e_flags & EF_MIPS_PIC;
753753
}
754754

755755
template <class ELFT> TargetInfo *elf::getMipsTargetInfo() {

lld/ELF/Arch/MipsArchTree.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ static uint32_t getArchFlags(ArrayRef<FileFlags> files) {
297297
template <class ELFT> uint32_t elf::calcMipsEFlags() {
298298
std::vector<FileFlags> v;
299299
for (InputFile *f : objectFiles)
300-
v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader()->e_flags});
300+
v.push_back({f, cast<ObjFile<ELFT>>(f)->getObj().getHeader().e_flags});
301301
if (v.empty()) {
302302
// If we don't have any input files, we'll have to rely on the information
303303
// we can derive from emulation information, since this at least gets us
@@ -363,7 +363,7 @@ uint8_t elf::getMipsFpAbiFlag(uint8_t oldFlag, uint8_t newFlag,
363363

364364
template <class ELFT> static bool isN32Abi(const InputFile *f) {
365365
if (auto *ef = dyn_cast<ELFFileBase>(f))
366-
return ef->template getObj<ELFT>().getHeader()->e_flags & EF_MIPS_ABI2;
366+
return ef->template getObj<ELFT>().getHeader().e_flags & EF_MIPS_ABI2;
367367
return false;
368368
}
369369

lld/ELF/Arch/PPC64.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ int PPC64::getTlsGdRelaxSkip(RelType type) const {
620620

621621
static uint32_t getEFlags(InputFile *file) {
622622
if (config->ekind == ELF64BEKind)
623-
return cast<ObjFile<ELF64BE>>(file)->getObj().getHeader()->e_flags;
624-
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader()->e_flags;
623+
return cast<ObjFile<ELF64BE>>(file)->getObj().getHeader().e_flags;
624+
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader().e_flags;
625625
}
626626

627627
// This file implements v2 ABI. This function makes sure that all

lld/ELF/Arch/RISCV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ RISCV::RISCV() {
104104

105105
static uint32_t getEFlags(InputFile *f) {
106106
if (config->is64)
107-
return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader()->e_flags;
108-
return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader()->e_flags;
107+
return cast<ObjFile<ELF64LE>>(f)->getObj().getHeader().e_flags;
108+
return cast<ObjFile<ELF32LE>>(f)->getObj().getHeader().e_flags;
109109
}
110110

111111
uint32_t RISCV::calcEFlags() const {

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) {
17191719
ArrayRef<Symbol *> syms = obj->getSymbols();
17201720
if (obj->addrsigSec) {
17211721
ArrayRef<uint8_t> contents =
1722-
check(obj->getObj().getSectionContents(obj->addrsigSec));
1722+
check(obj->getObj().getSectionContents(*obj->addrsigSec));
17231723
const uint8_t *cur = contents.begin();
17241724
while (cur != contents.end()) {
17251725
unsigned size;

lld/ELF/InputFiles.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,9 @@ template <class ELFT> void ELFFileBase::init() {
348348

349349
// Initialize trivial attributes.
350350
const ELFFile<ELFT> &obj = getObj<ELFT>();
351-
emachine = obj.getHeader()->e_machine;
352-
osabi = obj.getHeader()->e_ident[llvm::ELF::EI_OSABI];
353-
abiVersion = obj.getHeader()->e_ident[llvm::ELF::EI_ABIVERSION];
351+
emachine = obj.getHeader().e_machine;
352+
osabi = obj.getHeader().e_ident[llvm::ELF::EI_OSABI];
353+
abiVersion = obj.getHeader().e_ident[llvm::ELF::EI_ABIVERSION];
354354

355355
ArrayRef<Elf_Shdr> sections = CHECK(obj.sections(), this);
356356

@@ -378,7 +378,7 @@ template <class ELFT> void ELFFileBase::init() {
378378
template <class ELFT>
379379
uint32_t ObjFile<ELFT>::getSectionIndex(const Elf_Sym &sym) const {
380380
return CHECK(
381-
this->getObj().getSectionIndex(&sym, getELFSyms<ELFT>(), shndxTable),
381+
this->getObj().getSectionIndex(sym, getELFSyms<ELFT>(), shndxTable),
382382
this);
383383
}
384384

@@ -566,7 +566,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
566566

567567
if (sec.sh_type == ELF::SHT_LLVM_CALL_GRAPH_PROFILE)
568568
cgProfile =
569-
check(obj.template getSectionContentsAsArray<Elf_CGProfile>(&sec));
569+
check(obj.template getSectionContentsAsArray<Elf_CGProfile>(sec));
570570

571571
// SHF_EXCLUDE'ed sections are discarded by the linker. However,
572572
// if -r is given, we'll let the final link discard such sections.
@@ -595,7 +595,7 @@ void ObjFile<ELFT>::initializeSections(bool ignoreComdats) {
595595

596596

597597
ArrayRef<Elf_Word> entries =
598-
CHECK(obj.template getSectionContentsAsArray<Elf_Word>(&sec), this);
598+
CHECK(obj.template getSectionContentsAsArray<Elf_Word>(sec), this);
599599
if (entries.empty())
600600
fatal(toString(this) + ": empty SHT_GROUP");
601601

@@ -870,7 +870,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
870870

871871
if (config->emachine == EM_ARM && sec.sh_type == SHT_ARM_ATTRIBUTES) {
872872
ARMAttributeParser attributes;
873-
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec));
873+
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(sec));
874874
if (Error e = attributes.parse(contents, config->ekind == ELF32LEKind
875875
? support::little
876876
: support::big)) {
@@ -894,7 +894,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
894894

895895
if (config->emachine == EM_RISCV && sec.sh_type == SHT_RISCV_ATTRIBUTES) {
896896
RISCVAttributeParser attributes;
897-
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(&sec));
897+
ArrayRef<uint8_t> contents = check(this->getObj().getSectionContents(sec));
898898
if (Error e = attributes.parse(contents, support::little)) {
899899
auto *isec = make<InputSection>(*this, sec, name);
900900
warn(toString(isec) + ": " + llvm::toString(std::move(e)));
@@ -919,7 +919,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
919919
if (config->relocatable)
920920
break;
921921
ArrayRef<char> data =
922-
CHECK(this->getObj().template getSectionContentsAsArray<char>(&sec), this);
922+
CHECK(this->getObj().template getSectionContentsAsArray<char>(sec), this);
923923
if (!data.empty() && data.back() != '\0') {
924924
error(toString(this) +
925925
": corrupted dependent libraries section (unterminated string): " +
@@ -959,12 +959,12 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
959959
": multiple relocation sections to one section are not supported");
960960

961961
if (sec.sh_type == SHT_RELA) {
962-
ArrayRef<Elf_Rela> rels = CHECK(getObj().relas(&sec), this);
962+
ArrayRef<Elf_Rela> rels = CHECK(getObj().relas(sec), this);
963963
target->firstRelocation = rels.begin();
964964
target->numRelocations = rels.size();
965965
target->areRelocsRela = true;
966966
} else {
967-
ArrayRef<Elf_Rel> rels = CHECK(getObj().rels(&sec), this);
967+
ArrayRef<Elf_Rel> rels = CHECK(getObj().rels(sec), this);
968968
target->firstRelocation = rels.begin();
969969
target->numRelocations = rels.size();
970970
target->areRelocsRela = false;
@@ -1065,7 +1065,7 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(const Elf_Shdr &sec) {
10651065

10661066
template <class ELFT>
10671067
StringRef ObjFile<ELFT>::getSectionName(const Elf_Shdr &sec) {
1068-
return CHECK(getObj().getSectionName(&sec, sectionStringTable), this);
1068+
return CHECK(getObj().getSectionName(sec, sectionStringTable), this);
10691069
}
10701070

10711071
// Initialize this->Symbols. this->Symbols is a parallel array as
@@ -1279,7 +1279,7 @@ std::vector<uint32_t> SharedFile::parseVerneed(const ELFFile<ELFT> &obj,
12791279
if (!sec)
12801280
return {};
12811281
std::vector<uint32_t> verneeds;
1282-
ArrayRef<uint8_t> data = CHECK(obj.getSectionContents(sec), this);
1282+
ArrayRef<uint8_t> data = CHECK(obj.getSectionContents(*sec), this);
12831283
const uint8_t *verneedBuf = data.begin();
12841284
for (unsigned i = 0; i != sec->sh_info; ++i) {
12851285
if (verneedBuf + sizeof(typename ELFT::Verneed) > data.end())
@@ -1355,7 +1355,7 @@ template <class ELFT> void SharedFile::parse() {
13551355
continue;
13561356
case SHT_DYNAMIC:
13571357
dynamicTags =
1358-
CHECK(obj.template getSectionContentsAsArray<Elf_Dyn>(&sec), this);
1358+
CHECK(obj.template getSectionContentsAsArray<Elf_Dyn>(sec), this);
13591359
break;
13601360
case SHT_GNU_versym:
13611361
versymSec = &sec;
@@ -1414,7 +1414,7 @@ template <class ELFT> void SharedFile::parse() {
14141414
std::vector<uint16_t> versyms(size, VER_NDX_GLOBAL);
14151415
if (versymSec) {
14161416
ArrayRef<Elf_Versym> versym =
1417-
CHECK(obj.template getSectionContentsAsArray<Elf_Versym>(versymSec),
1417+
CHECK(obj.template getSectionContentsAsArray<Elf_Versym>(*versymSec),
14181418
this)
14191419
.slice(firstGlobal);
14201420
for (size_t i = 0; i < size; ++i)

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static ArrayRef<uint8_t> getSectionContents(ObjFile<ELFT> &file,
5353
const typename ELFT::Shdr &hdr) {
5454
if (hdr.sh_type == SHT_NOBITS)
5555
return makeArrayRef<uint8_t>(nullptr, hdr.sh_size);
56-
return check(file.getObj().getSectionContents(&hdr));
56+
return check(file.getObj().getSectionContents(hdr));
5757
}
5858

5959
InputSectionBase::InputSectionBase(InputFile *file, uint64_t flags,
@@ -456,7 +456,7 @@ void InputSection::copyRelocations(uint8_t *buf, ArrayRef<RelTy> rels) {
456456
Elf_Shdr_Impl<ELFT> sec =
457457
CHECK(file->getObj().sections(), file)[secIdx];
458458
warn("relocation refers to a discarded section: " +
459-
CHECK(file->getObj().getSectionName(&sec), file) +
459+
CHECK(file->getObj().getSectionName(sec), file) +
460460
"\n>>> referenced by " + getObjMsg(p->r_offset));
461461
}
462462
p->setSymbolAndType(0, 0, false);

lld/ELF/Relocations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ static std::string maybeReportDiscarded(Undefined &sym) {
692692
if (sym.type == ELF::STT_SECTION) {
693693
msg = "relocation refers to a discarded section: ";
694694
msg += CHECK(
695-
file->getObj().getSectionName(&objSections[sym.discardedSecIdx]), file);
695+
file->getObj().getSectionName(objSections[sym.discardedSecIdx]), file);
696696
} else {
697697
msg = "relocation refers to a symbol in a discarded section: " +
698698
toString(sym);

0 commit comments

Comments
 (0)