[lld] r261065 - Use an accurate type instead of unsigned.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 16 21:06:40 PST 2016
Author: ruiu
Date: Tue Feb 16 23:06:40 2016
New Revision: 261065
URL: http://llvm.org/viewvc/llvm-project?rev=261065&view=rev
Log:
Use an accurate type instead of unsigned.
These values are offsets in the string table (which must fit in
host computer's memory space), so size_t is better than unsigned.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/ELF/OutputSections.h
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=261065&r1=261064&r2=261065&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Feb 16 23:06:40 2016
@@ -473,11 +473,11 @@ static bool includeInGnuHashTable(Symbol
template <class ELFT>
void GnuHashTableSection<ELFT>::addSymbols(
- std::vector<std::pair<SymbolBody *, unsigned>> &Symbols) {
- std::vector<std::pair<SymbolBody *, unsigned>> NotHashed;
+ std::vector<std::pair<SymbolBody *, size_t>> &Symbols) {
+ std::vector<std::pair<SymbolBody *, size_t>> NotHashed;
NotHashed.reserve(Symbols.size());
HashedSymbols.reserve(Symbols.size());
- for (const std::pair<SymbolBody *, unsigned> &P : Symbols) {
+ for (const std::pair<SymbolBody *, size_t> &P : Symbols) {
SymbolBody *B = P.first;
if (includeInGnuHashTable(B))
HashedSymbols.push_back(
@@ -1386,14 +1386,13 @@ template <class ELFT> void SymbolTableSe
else if (Config->EMachine == EM_MIPS)
std::stable_sort(Symbols.begin(), Symbols.end(), sortMipsSymbols);
size_t I = 0;
- for (const std::pair<SymbolBody *, unsigned> &P : Symbols)
+ for (const std::pair<SymbolBody *, size_t> &P : Symbols)
P.first->DynsymIndex = ++I;
}
template <class ELFT>
-void SymbolTableSection<ELFT>::addSymbol(SymbolBody *Body) {
- Symbols.push_back(
- std::make_pair(Body, StrTabSec.addString(Body->getName(), false)));
+void SymbolTableSection<ELFT>::addSymbol(SymbolBody *B) {
+ Symbols.push_back({B, StrTabSec.addString(B->getName(), false)});
}
template <class ELFT> void SymbolTableSection<ELFT>::writeTo(uint8_t *Buf) {
@@ -1412,7 +1411,7 @@ void SymbolTableSection<ELFT>::writeLoca
// Iterate over all input object files to copy their local symbols
// to the output symbol table pointed by Buf.
for (const std::unique_ptr<ObjectFile<ELFT>> &File : Table.getObjectFiles()) {
- for (const std::pair<const Elf_Sym *, unsigned> &P : File->KeptLocalSyms) {
+ for (const std::pair<const Elf_Sym *, size_t> &P : File->KeptLocalSyms) {
const Elf_Sym *Sym = P.first;
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
@@ -1454,9 +1453,9 @@ void SymbolTableSection<ELFT>::writeGlob
// Write the internal symbol table contents to the output symbol table
// pointed by Buf.
auto *ESym = reinterpret_cast<Elf_Sym *>(Buf);
- for (const std::pair<SymbolBody *, unsigned> &P : Symbols) {
+ for (const std::pair<SymbolBody *, size_t> &P : Symbols) {
SymbolBody *Body = P.first;
- unsigned SymIdx = P.second;
+ size_t StrOff = P.second;
unsigned char Type = STT_NOTYPE;
uintX_t Size = 0;
@@ -1470,7 +1469,7 @@ void SymbolTableSection<ELFT>::writeGlob
ESym->setBindingAndType(getSymbolBinding(Body), Type);
ESym->st_size = Size;
- ESym->st_name = SymIdx;
+ ESym->st_name = StrOff;
ESym->setVisibility(Body->getVisibility());
ESym->st_value = Body->getVA<ELFT>();
Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=261065&r1=261064&r2=261065&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Feb 16 23:06:40 2016
@@ -230,7 +230,7 @@ public:
StringTableSection<ELFT> &getStrTabSec() const { return StrTabSec; }
unsigned getNumSymbols() const { return NumLocals + Symbols.size() + 1; }
- ArrayRef<std::pair<SymbolBody *, unsigned>> getSymbols() const {
+ ArrayRef<std::pair<SymbolBody *, size_t>> getSymbols() const {
return Symbols;
}
@@ -245,7 +245,9 @@ private:
static uint8_t getSymbolBinding(SymbolBody *Body);
SymbolTable<ELFT> &Table;
- std::vector<std::pair<SymbolBody *, unsigned>> Symbols;
+
+ // A vector of symbols and their string table offsets.
+ std::vector<std::pair<SymbolBody *, size_t>> Symbols;
};
template <class ELFT>
@@ -399,7 +401,7 @@ public:
// Adds symbols to the hash table.
// Sorts the input to satisfy GNU hash section requirements.
- void addSymbols(std::vector<std::pair<SymbolBody *, unsigned>> &Symbols);
+ void addSymbols(std::vector<std::pair<SymbolBody *, size_t>> &Symbols);
private:
static unsigned calcNBuckets(unsigned NumHashed);
@@ -411,7 +413,7 @@ private:
struct HashedSymbolData {
SymbolBody *Body;
- unsigned STName;
+ size_t STName;
uint32_t Hash;
};
More information about the llvm-commits
mailing list