[PATCH] D65388: [llvm-readelf/llvm-readobj] - Test the case when e_shstrndx==SHN_XINDEX, but sec[0].sh_link is broken.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 29 07:37:03 PDT 2019
grimar created this revision.
grimar added reviewers: jhenderson, MaskRay.
Herald added subscribers: rupprecht, arphaman.
When `e_shstrndx` is equal to `SHN_XINDEX`,
the index of the section string table section should
be taken from zero section `sh_link` field.
If `sh_link` is broken, e.g. contains an index that is
larger than number of sections, then error is reported.
This error message was untested before.
https://reviews.llvm.org/D65388
Files:
test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test
test/tools/llvm-readobj/elf-invalid-shstrndx.test
tools/llvm-readobj/ELFDumper.cpp
Index: tools/llvm-readobj/ELFDumper.cpp
===================================================================
--- tools/llvm-readobj/ELFDumper.cpp
+++ tools/llvm-readobj/ELFDumper.cpp
@@ -3015,7 +3015,6 @@
Index = Sections[0].sh_link;
if (!Index) // no section string table.
return "";
- // TODO: Test a case when the sh_link of the section with index 0 is broken.
if (Index >= Sections.size())
reportError(ElfObj.getFileName(),
createError("section header string table index " +
Index: test/tools/llvm-readobj/elf-invalid-shstrndx.test
===================================================================
--- test/tools/llvm-readobj/elf-invalid-shstrndx.test
+++ /dev/null
@@ -1,26 +0,0 @@
-# RUN: yaml2obj %s -o %t
-# RUN: not llvm-readelf --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=GNU
-# RUN: not llvm-readobj --headers -S 2>&1 %t | FileCheck %s -DFILE=%t --check-prefix=LLVM
-
-# GNU: ELF Header:
-# GNU: Section header string table index: 255
-# GNU-NEXT: There are 4 section headers, starting at offset 0x40:
-# GNU: Section Headers:
-# GNU-NEXT: [Nr] Name
-# GNU-EMPTY:
-# GNU-NEXT: error: '[[FILE]]': section header string table index 255 does not exist
-
-# LLVM: ElfHeader {
-# LLVM: StringTableSectionIndex: 255
-# LLVM-NEXT: }
-# LLVM-NEXT: Sections [
-# LLVM-EMPTY:
-# LLVM-NEXT: error: '[[FILE]]': section header string table index 255 does not exist
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
- SHStrNdx: 0xFF
Index: test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test
===================================================================
--- /dev/null
+++ test/tools/llvm-readobj/elf-invalid-sechdr-strtab-index.test
@@ -0,0 +1,46 @@
+## Check the case when e_shstrndx contains an invalid section header table index.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: not llvm-readelf --headers -S 2>&1 %t1 | FileCheck %s -DFILE=%t1 --check-prefixes=GNU,GNU-SHSTRNDX
+# RUN: not llvm-readobj --headers -S 2>&1 %t1 | FileCheck %s -DFILE=%t1 --check-prefixes=LLVM,LLVM-SHSTRNDX
+
+# GNU: ELF Header:
+# GNU-SHSTRNDX: Section header string table index: 255
+# GNU-LINK: Section header string table index: 65535 (255)
+# GNU-NEXT: There are 4 section headers, starting at offset 0x40:
+# GNU: Section Headers:
+# GNU-NEXT: [Nr] Name
+# GNU-EMPTY:
+# GNU-NEXT: error: '[[FILE]]': section header string table index 255 does not exist
+
+# LLVM: ElfHeader {
+# LLVM-SHSTRNDX: StringTableSectionIndex: 255
+# LLVM-LINK: StringTableSectionIndex: 65535 (255)
+# LLVM-NEXT: }
+# LLVM-NEXT: Sections [
+# LLVM-EMPTY:
+# LLVM-NEXT: error: '[[FILE]]': section header string table index 255 does not exist
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+ SHStrNdx: 0xFF
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: not llvm-readelf --headers -S 2>&1 %t2 | FileCheck %s -DFILE=%t2 --check-prefixes=GNU,GNU-LINK
+# RUN: not llvm-readobj --headers -S 2>&1 %t2 | FileCheck %s -DFILE=%t2 --check-prefixes=LLVM,LLVM-LINK
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+## SHN_XINDEX == 0xffff.
+ SHStrNdx: 0xffff
+Sections:
+ - Type: SHT_NULL
+ Link: 0xff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65388.212141.patch
Type: text/x-patch
Size: 3443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190729/00fd05f6/attachment.bin>
More information about the llvm-commits
mailing list