Skip to content

Commit fe0d0a9

Browse files
committed
[ELF] Merge numSymbols and numELFSyms
1 parent 1dfa34c commit fe0d0a9

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ template <class ELFT> void ELFFileBase::init(InputFile::Kind k) {
528528
Fatal(ctx) << this << ": invalid sh_info in symbol table";
529529

530530
elfSyms = reinterpret_cast<const void *>(eSyms.data());
531-
numELFSyms = uint32_t(eSyms.size());
531+
numSymbols = eSyms.size();
532532
stringTable = CHECK2(obj.getStringTableForSymtab(*symtabSec, sections), this);
533533
}
534534

@@ -1089,10 +1089,8 @@ InputSectionBase *ObjFile<ELFT>::createInputSection(uint32_t idx,
10891089
template <class ELFT>
10901090
void ObjFile<ELFT>::initializeSymbols(const object::ELFFile<ELFT> &obj) {
10911091
ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
1092-
if (numSymbols == 0) {
1093-
numSymbols = eSyms.size();
1092+
if (!symbols)
10941093
symbols = std::make_unique<Symbol *[]>(numSymbols);
1095-
}
10961094

10971095
// Some entries have been filled by LazyObjFile.
10981096
auto *symtab = ctx.symtab.get();
@@ -1432,8 +1430,6 @@ template <class ELFT> void SharedFile::parse() {
14321430
const Elf_Shdr *versymSec = nullptr;
14331431
const Elf_Shdr *verdefSec = nullptr;
14341432
const Elf_Shdr *verneedSec = nullptr;
1435-
1436-
numSymbols = numELFSyms;
14371433
symbols = std::make_unique<Symbol *[]>(numSymbols);
14381434

14391435
// Search for .dynsym, .dynamic, .symtab, .gnu.version and .gnu.version_d.
@@ -1457,7 +1453,7 @@ template <class ELFT> void SharedFile::parse() {
14571453
}
14581454
}
14591455

1460-
if (versymSec && numELFSyms == 0) {
1456+
if (versymSec && numSymbols == 0) {
14611457
ErrAlways(ctx) << "SHT_GNU_versym should be associated with symbol table";
14621458
return;
14631459
}
@@ -1500,7 +1496,7 @@ template <class ELFT> void SharedFile::parse() {
15001496
// Parse ".gnu.version" section which is a parallel array for the symbol
15011497
// table. If a given file doesn't have a ".gnu.version" section, we use
15021498
// VER_NDX_GLOBAL.
1503-
size_t size = numELFSyms - firstGlobal;
1499+
size_t size = numSymbols - firstGlobal;
15041500
std::vector<uint16_t> versyms(size, VER_NDX_GLOBAL);
15051501
if (versymSec) {
15061502
ArrayRef<Elf_Versym> versym =

lld/ELF/InputFiles.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class InputFile {
5353

5454
protected:
5555
std::unique_ptr<Symbol *[]> symbols;
56-
uint32_t numSymbols = 0;
56+
size_t numSymbols = 0;
5757
SmallVector<InputSectionBase *, 0> sections;
5858

5959
public:
@@ -208,7 +208,7 @@ class ELFFileBase : public InputFile {
208208
}
209209
template <typename ELFT> typename ELFT::SymRange getELFSyms() const {
210210
return typename ELFT::SymRange(
211-
reinterpret_cast<const typename ELFT::Sym *>(elfSyms), numELFSyms);
211+
reinterpret_cast<const typename ELFT::Sym *>(elfSyms), numSymbols);
212212
}
213213
template <typename ELFT> typename ELFT::SymRange getGlobalELFSyms() const {
214214
return getELFSyms<ELFT>().slice(firstGlobal);
@@ -225,7 +225,6 @@ class ELFFileBase : public InputFile {
225225
const void *elfShdrs = nullptr;
226226
const void *elfSyms = nullptr;
227227
uint32_t numELFShdrs = 0;
228-
uint32_t numELFSyms = 0;
229228
uint32_t firstGlobal = 0;
230229

231230
// Below are ObjFile specific members.

0 commit comments

Comments
 (0)