[llvm] r361506 - [Object] object::ELFObjectFile::symbol_begin(): skip symbol index 0
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 09:01:59 PDT 2019
Author: maskray
Date: Thu May 23 09:01:59 2019
New Revision: 361506
URL: http://llvm.org/viewvc/llvm-project?rev=361506&view=rev
Log:
[Object] object::ELFObjectFile::symbol_begin(): skip symbol index 0
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
Modified:
llvm/trunk/include/llvm/Object/ELFObjectFile.h
llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
Modified: llvm/trunk/include/llvm/Object/ELFObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/ELFObjectFile.h?rev=361506&r1=361505&r2=361506&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/ELFObjectFile.h (original)
+++ llvm/trunk/include/llvm/Object/ELFObjectFile.h Thu May 23 09:01:59 2019
@@ -982,7 +982,9 @@ ELFObjectFile<ELFT>::ELFObjectFile(ELFOb
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));
}
Modified: llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp?rev=361506&r1=361505&r2=361506&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp (original)
+++ llvm/trunk/tools/llvm-objdump/llvm-objdump.cpp Thu May 23 09:01:59 2019
@@ -1643,11 +1643,6 @@ void printSymbolTable(const ObjectFile *
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);
More information about the llvm-commits
mailing list