[PATCH] D83393: [llvm-readelf] - Stop using 'unwrapOrError()' in 'ELFDumper<ELFT>::getSymbolVersion'.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 06:40:19 PDT 2020
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
This allows to propagate an error and report a warning properly.
https://reviews.llvm.org/D83393
Files:
llvm/test/tools/llvm-readobj/ELF/versym-invalid.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
@@ -1086,10 +1086,12 @@
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>
Index: llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
===================================================================
--- llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
+++ llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
@@ -115,13 +115,39 @@
## 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 @@
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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83393.276409.patch
Type: text/x-patch
Size: 4072 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200708/f362b41c/attachment.bin>
More information about the llvm-commits
mailing list