[llvm] r362938 - [llvm-readobj/llvm-readelf] - Don't fail to dump the object if .dynsym has broken sh_link field.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 07:23:46 PDT 2019
Author: grimar
Date: Mon Jun 10 07:23:46 2019
New Revision: 362938
URL: http://llvm.org/viewvc/llvm-project?rev=362938&view=rev
Log:
[llvm-readobj/llvm-readelf] - Don't fail to dump the object if .dynsym has broken sh_link field.
This is https://bugs.llvm.org/show_bug.cgi?id=42215.
GNU readelf allows to dump the objects in that case,
but llvm-readobj/llvm-readelf reports an error and stops.
The patch fixes that.
Differential revision: https://reviews.llvm.org/D63074
Added:
llvm/trunk/test/tools/llvm-readobj/Inputs/elf-broken-dynsym-link.elf-x86-64 (with props)
llvm/trunk/test/tools/llvm-readobj/elf-broken-dynsym-link.test
Modified:
llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
llvm/trunk/tools/llvm-readobj/llvm-readobj.h
Added: llvm/trunk/test/tools/llvm-readobj/Inputs/elf-broken-dynsym-link.elf-x86-64
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/Inputs/elf-broken-dynsym-link.elf-x86-64?rev=362938&view=auto
==============================================================================
Binary file - no diff available.
Propchange: llvm/trunk/test/tools/llvm-readobj/Inputs/elf-broken-dynsym-link.elf-x86-64
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
Added: llvm/trunk/test/tools/llvm-readobj/elf-broken-dynsym-link.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-readobj/elf-broken-dynsym-link.test?rev=362938&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-readobj/elf-broken-dynsym-link.test (added)
+++ llvm/trunk/test/tools/llvm-readobj/elf-broken-dynsym-link.test Mon Jun 10 07:23:46 2019
@@ -0,0 +1,60 @@
+## Test that we are able to dump section headers even if the
+## .dynsym section's sh_link field is broken.
+
+## Case 1: sh_link is set to 0.
+# RUN: yaml2obj %s -o %t1
+# RUN: llvm-readobj -S %t1 2>&1 | FileCheck %s --check-prefixes=LLVM,ERR
+# RUN: llvm-readelf -S %t1 2>&1 | FileCheck %s --check-prefixes=GNU,ERR
+
+# ERR: warning: invalid sh_type for string table, expected SHT_STRTAB
+
+# LLVM: Name: .dynsym
+# LLVM-NEXT: Type: SHT_DYNSYM
+# LLVM-NEXT: Flags [
+# LLVM-NEXT: SHF_ALLOC
+# LLVM-NEXT: ]
+# LLVM-NEXT: Address: 0x0
+# LLVM-NEXT: Offset: 0x180
+# LLVM-NEXT: Size: 24
+# LLVM-NEXT: Link: 0
+
+# GNU: Section Headers:
+# GNU-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
+# GNU-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
+# GNU-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000018 18 A 0
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .dynsym
+ Type: SHT_DYNSYM
+
+## TODO: Remove precompiled input object after fixing yaml2obj.
+## See https://bugs.llvm.org/show_bug.cgi?id=42216.
+
+## Case 2: sh_link is set to 255, which is larger than the number of the sections.
+# RUN: llvm-readobj -S %p/Inputs/elf-broken-dynsym-link.elf-x86-64 2>&1 \
+# RUN: | FileCheck %s --check-prefixes=LLVM2,ERR2
+# RUN: llvm-readelf -S %p/Inputs/elf-broken-dynsym-link.elf-x86-64 2>&1 \
+# RUN: | FileCheck %s --check-prefixes=GNU2,ERR2
+
+# ERR2: warning: invalid section index
+
+# LLVM2: Name: .dynsym
+# LLVM2-NEXT: Type: SHT_DYNSYM
+# LLVM2-NEXT: Flags [
+# LLVM2-NEXT: SHF_ALLOC
+# LLVM2-NEXT: ]
+# LLVM2-NEXT: Address: 0x0
+# LLVM2-NEXT: Offset: 0x180
+# LLVM2-NEXT: Size: 2
+# LLVM2-NEXT: Link: 255
+
+# GNU2: Section Headers:
+# GNU2-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
+# GNU2-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
+# GNU2-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000002 18 A 255
Modified: llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml?rev=362938&r1=362937&r2=362938&view=diff
==============================================================================
--- llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml (original)
+++ llvm/trunk/test/tools/yaml2obj/explicit-dynsym-no-dynstr.yaml Mon Jun 10 07:23:46 2019
@@ -2,14 +2,14 @@
## explicitly, but .dynstr is not present.
# RUN: yaml2obj %s -o %t
-# RUN: not llvm-readelf --section-headers %t 2>&1 | FileCheck %s
+# RUN: llvm-readelf --section-headers %t | FileCheck %s
-## TODO: Check that .dynsym has Link field set to 0.
-## GNU readelf is able to dump sections headers,
-## but llvm-readelf reports an error below too early.
-## See https://bugs.llvm.org/show_bug.cgi?id=42215.
+## Check that .dynsym has Link field set to 0.
-# CHECK: error: invalid sh_type for string table, expected SHT_STRTAB
+# CHECK: Section Headers:
+# CHECK-NEXT: [Nr] Name Type Address Off Size ES Flg Lk
+# CHECK-NEXT: [ 0] NULL 0000000000000000 000000 000000 00 0 0
+# CHECK-NEXT: [ 1] .dynsym DYNSYM 0000000000000000 000180 000018 18 A 0
--- !ELF
FileHeader:
Modified: llvm/trunk/tools/llvm-readobj/ELFDumper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/ELFDumper.cpp?rev=362938&r1=362937&r2=362938&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/ELFDumper.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/ELFDumper.cpp Mon Jun 10 07:23:46 2019
@@ -1423,7 +1423,11 @@ ELFDumper<ELFT>::ELFDumper(const object:
// This is only used (if Elf_Shdr present)for naming section in GNU
// style
DynSymtabName = unwrapOrError(Obj->getSectionName(&Sec));
- DynamicStringTable = unwrapOrError(Obj->getStringTableForSymtab(Sec));
+
+ if (Expected<StringRef> E = Obj->getStringTableForSymtab(Sec))
+ DynamicStringTable = *E;
+ else
+ warn(E.takeError());
}
break;
case ELF::SHT_SYMTAB_SHNDX:
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=362938&r1=362937&r2=362938&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Mon Jun 10 07:23:46 2019
@@ -378,6 +378,12 @@ void reportWarning(Twine Msg) {
WithColor::warning(errs()) << Msg << "\n";
}
+void warn(Error Err) {
+ handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) {
+ reportWarning(EI.message());
+ });
+}
+
void error(Error EC) {
if (!EC)
return;
Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.h?rev=362938&r1=362937&r2=362938&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.h (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.h Mon Jun 10 07:23:46 2019
@@ -23,6 +23,7 @@ namespace llvm {
// Various helper functions.
LLVM_ATTRIBUTE_NORETURN void reportError(Twine Msg);
void reportWarning(Twine Msg);
+ void warn(llvm::Error Err);
void error(std::error_code EC);
void error(llvm::Error EC);
template <typename T> T error(llvm::Expected<T> &&E) {
More information about the llvm-commits
mailing list