Skip to content

Commit

Permalink
[Object] object::ELFObjectFile::symbol_begin(): skip symbol index 0
Browse files Browse the repository at this point in the history
For clients iterating the symbol table, none expects to handle index 0
(STN_UNDEF). Skip it to improve consistency with other binary formats.
Clients that need STN_UNDEF (e.g. lld) can use
getSectionContentsAsArray(). A test will be added in D62148.

Reviewed By: mtrent

Differential Revision: https://reviews.llvm.org/D62296

llvm-svn: 361506
  • Loading branch information
MaskRay committed May 23, 2019
1 parent 8cffa84 commit 6aebd83
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 3 additions & 1 deletion llvm/include/llvm/Object/ELFObjectFile.h
Expand Up @@ -982,7 +982,9 @@ ELFObjectFile<ELFT>::ELFObjectFile(ELFObjectFile<ELFT> &&Other)

template <class ELFT>
basic_symbol_iterator ELFObjectFile<ELFT>::symbol_begin() const {
DataRefImpl Sym = toDRI(DotSymtabSec, 0);
DataRefImpl Sym =
toDRI(DotSymtabSec,
DotSymtabSec && DotSymtabSec->sh_size >= sizeof(Elf_Sym) ? 1 : 0);
return basic_symbol_iterator(SymbolRef(Sym, this));
}

Expand Down
5 changes: 0 additions & 5 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Expand Up @@ -1643,11 +1643,6 @@ void printSymbolTable(const ObjectFile *O, StringRef ArchiveName,

const StringRef FileName = O->getFileName();
for (auto I = O->symbol_begin(), E = O->symbol_end(); I != E; ++I) {
// Skip printing the special zero symbol when dumping an ELF file.
// This makes the output consistent with the GNU objdump.
if (I == O->symbol_begin() && isa<ELFObjectFileBase>(O))
continue;

const SymbolRef &Symbol = *I;
uint64_t Address = unwrapOrError(Symbol.getAddress(), ArchiveName, FileName,
ArchitectureName);
Expand Down

0 comments on commit 6aebd83

Please sign in to comment.