[PATCH] D76081: [Object] object::ELFObjectFile::dynamic_symbol_begin(): skip symbol index 0
Xing GUO via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 04:08:44 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG541bead8b424: [Object] object::ELFObjectFile::dynamic_symbol_begin(): skip symbol index 0 (authored by Higuoxing).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76081/new/
https://reviews.llvm.org/D76081
Files:
llvm/include/llvm/Object/ELFObjectFile.h
llvm/test/tools/llvm-nm/dynamic.test
Index: llvm/test/tools/llvm-nm/dynamic.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-nm/dynamic.test
@@ -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
Index: llvm/include/llvm/Object/ELFObjectFile.h
===================================================================
--- llvm/include/llvm/Object/ELFObjectFile.h
+++ llvm/include/llvm/Object/ELFObjectFile.h
@@ -1027,8 +1027,12 @@
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>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76081.255020.patch
Type: text/x-patch
Size: 2734 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200404/d37d9374/attachment.bin>
More information about the llvm-commits
mailing list