[llvm] 7749e2d - [llvm-readobj] - Don`t crash when --section-symbols is requested for an object w/o .symtab.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 26 04:13:46 PDT 2020
Author: Georgii Rymar
Date: 2020-08-26T14:13:05+03:00
New Revision: 7749e2de20d82a6bb8b8beaa74b2a8dbd8232067
URL: https://github.com/llvm/llvm-project/commit/7749e2de20d82a6bb8b8beaa74b2a8dbd8232067
DIFF: https://github.com/llvm/llvm-project/commit/7749e2de20d82a6bb8b8beaa74b2a8dbd8232067.diff
LOG: [llvm-readobj] - Don`t crash when --section-symbols is requested for an object w/o .symtab.
llvm-readobj crashes when `-S --section-symbols` is used
on an object that has no symbol table.
The patch fixes it.
Differential revision: https://reviews.llvm.org/D86520
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/sections-ext.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/sections-ext.test b/llvm/test/tools/llvm-readobj/ELF/sections-ext.test
index cc58f6da4534..f061e4eabb15 100644
--- a/llvm/test/tools/llvm-readobj/ELF/sections-ext.test
+++ b/llvm/test/tools/llvm-readobj/ELF/sections-ext.test
@@ -217,3 +217,28 @@ Sections:
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
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index 7b6781e70dc1..644489fb3b06 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -6297,20 +6297,21 @@ void LLVMStyle<ELFT>::printSectionHeaders(const ELFO *Obj) {
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);
+ }
}
}
More information about the llvm-commits
mailing list