[PATCH] D86520: [llvm-readobj] - Don`t crash when --section-symbols is requested for an object w/o .symtab.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 04:13:56 PDT 2020
This revision was automatically updated to reflect the committed changes.
Closed by commit rG7749e2de20d8: [llvm-readobj] - Don`t crash when --section-symbols is requested for an object… (authored by grimar).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D86520/new/
https://reviews.llvm.org/D86520
Files:
llvm/test/tools/llvm-readobj/ELF/sections-ext.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Index: llvm/tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- llvm/tools/llvm-readobj/ELFDumper.cpp
+++ llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6297,20 +6297,21 @@
if (opts::SectionSymbols) {
ListScope D(W, "Symbols");
- const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec();
- StringRef StrTable =
- unwrapOrError(this->FileName, Obj->getStringTableForSymtab(*Symtab));
-
- for (const Elf_Sym &Sym :
- unwrapOrError(this->FileName, Obj->symbols(Symtab))) {
- const Elf_Shdr *SymSec = unwrapOrError(
- this->FileName,
- Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable()));
- if (SymSec == &Sec)
- printSymbol(
- Obj, &Sym,
- unwrapOrError(this->FileName, Obj->symbols(Symtab)).begin(),
- StrTable, false, false);
+ if (const Elf_Shdr *Symtab = this->dumper()->getDotSymtabSec()) {
+ StringRef StrTable = unwrapOrError(
+ this->FileName, Obj->getStringTableForSymtab(*Symtab));
+
+ for (const Elf_Sym &Sym :
+ unwrapOrError(this->FileName, Obj->symbols(Symtab))) {
+ const Elf_Shdr *SymSec = unwrapOrError(
+ this->FileName,
+ Obj->getSection(&Sym, Symtab, this->dumper()->getShndxTable()));
+ if (SymSec == &Sec)
+ printSymbol(
+ Obj, &Sym,
+ unwrapOrError(this->FileName, Obj->symbols(Symtab)).begin(),
+ StrTable, false, false);
+ }
}
}
Index: llvm/test/tools/llvm-readobj/ELF/sections-ext.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/sections-ext.test
+++ llvm/test/tools/llvm-readobj/ELF/sections-ext.test
@@ -217,3 +217,28 @@
Symbols:
- Name: foo
Section: .text
+
+## Check the output for an arbitrary section when --section-symbols is requested,
+## but there is no symbol table in the object.
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readobj -S --section-symbols %t2 2>&1 | \
+# RUN: FileCheck %s --implicit-check-not=warning: --check-prefix=NOSYMTAB
+
+# NOSYMTAB: Section {
+# NOSYMTAB: Index: 1
+# NOSYMTAB-NEXT: Name: .foo
+# NOSYMTAB: Symbols [
+# NOSYMTAB-NEXT: ]
+# NOSYMTAB-NEXT: }
+# NOSYMTAB-NEXT: Section {
+# NOSYMTAB-NEXT: Index: 2
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86520.287913.patch
Type: text/x-patch
Size: 2599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200826/6264cbd1/attachment.bin>
More information about the llvm-commits
mailing list