[llvm] 54bdde1 - [llvm-readelf] - Stop using 'unwrapOrError()' in 'ELFDumper<ELFT>::getSymbolVersion'.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 9 03:45:56 PDT 2020
Author: Georgii Rymar
Date: 2020-07-09T13:43:52+03:00
New Revision: 54bdde1dc0cde8176ef5616c82ee793218173cab
URL: https://github.com/llvm/llvm-project/commit/54bdde1dc0cde8176ef5616c82ee793218173cab
DIFF: https://github.com/llvm/llvm-project/commit/54bdde1dc0cde8176ef5616c82ee793218173cab.diff
LOG: [llvm-readelf] - Stop using 'unwrapOrError()' in 'ELFDumper<ELFT>::getSymbolVersion'.
This allows to propagate an error and report a warning properly.
Differential revision: https://reviews.llvm.org/D83393
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
llvm/tools/llvm-readobj/ELFDumper.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test b/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
index 7151a905b1d1..d495b1cfd063 100644
--- a/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
+++ b/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
@@ -115,13 +115,39 @@ Sections:
## Check we report a warning when a SHT_GNU_versym section has an invalid entry size.
# RUN: yaml2obj --docnum=5 %s -o %t5
-# RUN: llvm-readelf -V %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU
-# RUN: llvm-readobj -V %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM
-
+# RUN: llvm-readelf -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-GNU
+# RUN: llvm-readobj -V --dyn-syms %t5 2>&1 | FileCheck -DFILE=%t5 %s --check-prefix=INVALID-ENT-SIZE-LLVM
+
+# INVALID-ENT-SIZE-GNU: Symbol table '.dynsym' contains 2 entries:
+# INVALID-ENT-SIZE-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
+# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
+# INVALID-ENT-SIZE-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND @<corrupt>
+# INVALID-ENT-SIZE-GNU-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND foo@<corrupt>
# INVALID-ENT-SIZE-GNU: Version symbols section '.gnu.version' contains 1 entries:
# INVALID-ENT-SIZE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 0 ()
# INVALID-ENT-SIZE-GNU-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_entsize: 3
+# INVALID-ENT-SIZE-LLVM: DynamicSymbols [
+# INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': section [index 1] has invalid sh_entsize: expected 2, but got 3
+# INVALID-ENT-SIZE-LLVM-NEXT: Symbol {
+# INVALID-ENT-SIZE-LLVM-NEXT: Name: @<corrupt> (0)
+# INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0
+# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0
+# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0
+# INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: }
+# INVALID-ENT-SIZE-LLVM-NEXT: Symbol {
+# INVALID-ENT-SIZE-LLVM-NEXT: Name: foo@<corrupt> (1)
+# INVALID-ENT-SIZE-LLVM-NEXT: Value: 0x0
+# INVALID-ENT-SIZE-LLVM-NEXT: Size: 0
+# INVALID-ENT-SIZE-LLVM-NEXT: Binding: Local (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: Type: None (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: Other: 0
+# INVALID-ENT-SIZE-LLVM-NEXT: Section: Undefined (0x0)
+# INVALID-ENT-SIZE-LLVM-NEXT: }
+# INVALID-ENT-SIZE-LLVM-NEXT: ]
# INVALID-ENT-SIZE-LLVM: VersionSymbols [
# INVALID-ENT-SIZE-LLVM-NEXT: warning: '[[FILE]]': cannot read content of SHT_GNU_versym section with index 1: section [index 1] has an invalid sh_entsize: 3
# INVALID-ENT-SIZE-LLVM-NEXT: ]
@@ -137,6 +163,8 @@ Sections:
Type: SHT_GNU_versym
Entries: [ 0 ]
EntSize: 3
+DynamicSymbols:
+ - Name: foo
## Check we report a warning when the number of version entries does not match the number of symbols in the associated symbol table.
diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp
index b8a5de27cb67..6a7f37e39a9a 100644
--- a/llvm/tools/llvm-readobj/ELFDumper.cpp
+++ b/llvm/tools/llvm-readobj/ELFDumper.cpp
@@ -1086,10 +1086,12 @@ Expected<StringRef> ELFDumper<ELFT>::getSymbolVersion(const Elf_Sym *Sym,
sizeof(Elf_Sym);
// Get the corresponding version index entry.
- const Elf_Versym *Versym = unwrapOrError(
- ObjF->getFileName(), ObjF->getELFFile()->template getEntry<Elf_Versym>(
- SymbolVersionSection, EntryIndex));
- return this->getSymbolVersionByIndex(Versym->vs_index, IsDefault);
+ if (Expected<const Elf_Versym *> EntryOrErr =
+ ObjF->getELFFile()->template getEntry<Elf_Versym>(
+ SymbolVersionSection, EntryIndex))
+ return this->getSymbolVersionByIndex((*EntryOrErr)->vs_index, IsDefault);
+ else
+ return EntryOrErr.takeError();
}
template <typename ELFT>
More information about the llvm-commits
mailing list