mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[Object] object::ELFObjectFile::dynamic_symbol_begin(): skip symbol index 0
Summary: Note: This revision is very similar to D62296. In D75756, we need `getDynamicSymbolIterators()` to skip first NULL symbol in `.dynsym`. And I believe it might be worth pointing this out in a separate patch to gather you experts' opinions. I have checked that current code base will not be affected by this change. ``` dynamic_symbol_begin() |- dynamic_symbol_end(): Ok `- getDynamicSymbolIterators() |- addDynamicElfSymbols(): llvm/tools/llvm-objdump/llvm-objdump.cpp, Line 934 | Ok, NULL symbol will be omitted by Line 945-947 | StringRef Name = unwrapOrError(Symbol.getName(), Obj->getName()); | if (Name.empty()) continue; |- dumpSymbolNameFromObject(): llvm/tools/llvm-nm/llvm-nm.cpp, Line 1192 | There's no test for dumping dynamic debugging symbol. This patch helps improve llvm-nm behavior. (we should add test for this later) `- computeSymbolSizes(): llvm/lib/Object/SymbolSize.cpp, Line 52 |- OProfileJITEventListener::notifyObjectLoaded(): llvm/lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp, Line 92 | Ok, NULL symbol will be omitted by Line 94-95 | if (!Sym.getType() || *Sym.getType() != SF_Function) continue; |- IntelJITEventListener::notifyObjectLoaded(): llvm/lib/ExecutionEngine/IntelJITEvents/IntelJITEventListener.cpp, Line 98 | Ok, NULL symbol will be omitted by Line 124-126 (same as previous one) |- PerfJITEventListener::notifyObjectLoaded(): llvm/lib/ExecutionEngine/PerfJITEvents/PerfJITEventListener.cpp, Line 244 | Ok, NULL symbol will be omitted by Line 254-256, (same as previous one) |- SymbolizableObjectFile::create(): llvm/lib/DebugInfo/Symbolize/SymbolizableObjectFile.cpp, Line 73 | Ok, NULL symbol will be omitted by Line 75 | res->addSymbol() | In addSymbol(), Line 167-168 | if (!Sec || (Obj && Obj->section_end() == *Sec)) return std::error_code(); |- dumpCXXData(): llvm/tools/llvm-cxxdump/llvm-cxxdump.cpp, Line 189 | Ok, NULL symbol will be omitted by Line 199-202 | object::section_iterator SecI = *SecIOrErr; | // Skip external symbols. | if (SecI == Obj->section_end()) | continue; `- printLineInfoForInput(): llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp, Line 418 Ok, NULL symbol will be omitted by Line 430-477 if (Type == object::SymbolRef::ST_Function) { ... } ``` Reviewers: grimar, jhenderson, MaskRay Reviewed By: jhenderson, MaskRay Subscribers: rupprecht, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D76081
This commit is contained in:
parent
ed72276673
commit
0f8b127b0f
@ -1027,8 +1027,12 @@ basic_symbol_iterator ELFObjectFile<ELFT>::symbol_end() const {
|
||||
|
||||
template <class ELFT>
|
||||
elf_symbol_iterator ELFObjectFile<ELFT>::dynamic_symbol_begin() const {
|
||||
DataRefImpl Sym = toDRI(DotDynSymSec, 0);
|
||||
return symbol_iterator(SymbolRef(Sym, this));
|
||||
if (!DotDynSymSec || DotDynSymSec->sh_size < sizeof(Elf_Sym))
|
||||
// Ignore errors here where the dynsym is empty or sh_size less than the
|
||||
// size of one symbol. These should be handled elsewhere.
|
||||
return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 0), this));
|
||||
// Skip 0-index NULL symbol.
|
||||
return symbol_iterator(SymbolRef(toDRI(DotDynSymSec, 1), this));
|
||||
}
|
||||
|
||||
template <class ELFT>
|
||||
|
62
test/tools/llvm-nm/dynamic.test
Normal file
62
test/tools/llvm-nm/dynamic.test
Normal file
@ -0,0 +1,62 @@
|
||||
## This is a test for --dynamic/-D option.
|
||||
|
||||
## Test llvm-nm dumping ELF file with valid .dynsym section.
|
||||
# RUN: yaml2obj --docnum=1 %s -o %t1.o
|
||||
# RUN: llvm-nm --dynamic %t1.o | \
|
||||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM
|
||||
# RUN: llvm-nm -D %t1.o | \
|
||||
# RUN: FileCheck %s --match-full-lines --strict-whitespace --check-prefix DYNSYM
|
||||
|
||||
# DYNSYM: U globalsym
|
||||
# DYNSYM-NEXT: U localsym1
|
||||
# DYNSYM-NEXT:0000000000000000 n localsym2
|
||||
# DYNSYM-EMPTY:
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_DYN
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: section
|
||||
Type: SHT_PROGBITS
|
||||
DynamicSymbols:
|
||||
- Name: localsym1
|
||||
Type: STT_OBJECT
|
||||
- Name: localsym2
|
||||
Section: section
|
||||
- Name: globalsym
|
||||
Type: STT_OBJECT
|
||||
Binding: STB_GLOBAL
|
||||
|
||||
## Test llvm-nm dumping ELF file without a .dynsym section.
|
||||
# RUN: yaml2obj --docnum=2 %s -o %t2.o
|
||||
# RUN: llvm-nm --dynamic %t2.o 2>&1 | \
|
||||
# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t2.o --check-prefix NO-SYMS
|
||||
|
||||
# NO-SYMS:[[FILE]]: no symbols
|
||||
# NO-SYMS-EMPTY:
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_DYN
|
||||
Machine: EM_X86_64
|
||||
|
||||
## Test llvm-nm dumping ELF file with an empty .dynsym section.
|
||||
# RUN: yaml2obj --docnum=3 %s -o %t3.o
|
||||
# RUN: llvm-nm --dynamic %t3.o 2>&1 | \
|
||||
# RUN: FileCheck %s --match-full-lines --strict-whitespace -DFILE=%t3.o --check-prefix NO-SYMS
|
||||
|
||||
--- !ELF
|
||||
FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_DYN
|
||||
Machine: EM_X86_64
|
||||
Sections:
|
||||
- Name: .dynsym
|
||||
Type: SHT_DYNSYM
|
||||
Size: 0
|
Loading…
x
Reference in New Issue
Block a user