[lld] ea72c08 - [ELF] Change getSymbolIndex to use const reference. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 18 13:59:01 PDT 2024
Author: Fangrui Song
Date: 2024-03-18T13:58:55-07:00
New Revision: ea72c082bc29fdceca33f37477b7588f31630a5f
URL: https://github.com/llvm/llvm-project/commit/ea72c082bc29fdceca33f37477b7588f31630a5f
DIFF: https://github.com/llvm/llvm-project/commit/ea72c082bc29fdceca33f37477b7588f31630a5f.diff
LOG: [ELF] Change getSymbolIndex to use const reference. NFC
Added:
Modified:
lld/ELF/InputSection.cpp
lld/ELF/OutputSections.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/SyntheticSections.h
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 7508a1336c91a4..19a6595d10ce7b 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -408,7 +408,7 @@ void InputSection::copyRelocations(uint8_t *buf,
// Output section VA is zero for -r, so r_offset is an offset within the
// section, but for --emit-relocs it is a virtual address.
p->r_offset = sec->getVA(rel.offset);
- p->setSymbolAndType(in.symTab->getSymbolIndex(&sym), type,
+ p->setSymbolAndType(in.symTab->getSymbolIndex(sym), type,
config->isMips64EL);
if (sym.type == STT_SECTION) {
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 55e6a14f103e02..f986aa5f675707 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -583,7 +583,7 @@ static void finalizeShtGroup(OutputSection *os, InputSection *section) {
// sh_info then contain index of an entry in symbol table section which
// provides signature of the section group.
ArrayRef<Symbol *> symbols = section->file->getSymbols();
- os->info = in.symTab->getSymbolIndex(symbols[section->info]);
+ os->info = in.symTab->getSymbolIndex(*symbols[section->info]);
// Some group members may be combined or discarded, so we need to compute the
// new size. The content will be rewritten in InputSection::copyShtGroup.
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 206fb0f5376664..248ff6b4a865a3 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1600,7 +1600,7 @@ uint32_t DynamicReloc::getSymIndex(SymbolTableBaseSection *symTab) const {
if (!needsDynSymIndex())
return 0;
- size_t index = symTab->getSymbolIndex(sym);
+ size_t index = symTab->getSymbolIndex(*sym);
assert((index != 0 || (type != target->gotRel && type != target->pltRel) ||
!mainPart->dynSymTab->getParent()) &&
"GOT or PLT relocation must refer to symbol in dynamic symbol table");
@@ -2172,9 +2172,9 @@ void SymbolTableBaseSection::addSymbol(Symbol *b) {
symbols.push_back({b, strTabSec.addString(b->getName(), false)});
}
-size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
+size_t SymbolTableBaseSection::getSymbolIndex(const Symbol &sym) {
if (this == mainPart->dynSymTab.get())
- return sym->dynsymIndex;
+ return sym.dynsymIndex;
// Initializes symbol lookup tables lazily. This is used only for -r,
// --emit-relocs and dynsyms in partitions other than the main one.
@@ -2191,9 +2191,9 @@ size_t SymbolTableBaseSection::getSymbolIndex(Symbol *sym) {
// Section symbols are mapped based on their output sections
// to maintain their semantics.
- if (sym->type == STT_SECTION)
- return sectionIndexMap.lookup(sym->getOutputSection());
- return symbolIndexMap.lookup(sym);
+ if (sym.type == STT_SECTION)
+ return sectionIndexMap.lookup(sym.getOutputSection());
+ return symbolIndexMap.lookup(&sym);
}
template <class ELFT>
@@ -2427,7 +2427,7 @@ void GnuHashTableSection::writeTo(uint8_t *buf) {
// Write a hash bucket. Hash buckets contain indices in the following hash
// value table.
write32(buckets + i->bucketIdx,
- getPartition().dynSymTab->getSymbolIndex(i->sym));
+ getPartition().dynSymTab->getSymbolIndex(*i->sym));
oldBucket = i->bucketIdx;
}
}
diff --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 7882ad87c241d7..b41e6941005412 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -641,7 +641,7 @@ class SymbolTableBaseSection : public SyntheticSection {
size_t getSize() const override { return getNumSymbols() * entsize; }
void addSymbol(Symbol *sym);
unsigned getNumSymbols() const { return symbols.size() + 1; }
- size_t getSymbolIndex(Symbol *sym);
+ size_t getSymbolIndex(const Symbol &sym);
ArrayRef<SymbolTableEntry> getSymbols() const { return symbols; }
protected:
More information about the llvm-commits
mailing list