[llvm] bb7d75e - [llvm-readelf][llvm-readobj][test] - Cleanup test cases for versioning sections.
Georgii Rymar via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 27 23:56:08 PST 2019
Author: Georgii Rymar
Date: 2019-11-28T10:18:51+03:00
New Revision: bb7d75ef1df350948a95d875c9746115f6481a2d
URL: https://github.com/llvm/llvm-project/commit/bb7d75ef1df350948a95d875c9746115f6481a2d
DIFF: https://github.com/llvm/llvm-project/commit/bb7d75ef1df350948a95d875c9746115f6481a2d.diff
LOG: [llvm-readelf][llvm-readobj][test] - Cleanup test cases for versioning sections.
Currently we have 2 tests for testing versioning sections:
1) elf-versioninfo.test
2) elf-invalid-versioning.test
The first one currently checks how versioning sections are dumped +
how tools dump invalid SHT_GNU_verdef section.
The second despite of its name contains only tests for invalid SHT_GNU_verneed section.
In this patch I`ve renamed elf-invalid-versioning.test->elf-verneed-invalid.test,
and moved a few tests from elf-versioninfo.test to a new elf-verdef-invalid.test.
It will help to maintain these and a new tests for broken versioning sections.
Differential revision:
Added:
llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
llvm/test/tools/llvm-readobj/elf-verneed-invalid.test
Modified:
llvm/test/tools/llvm-readobj/elf-versioninfo.test
Removed:
llvm/test/tools/llvm-readobj/elf-invalid-versioning.test
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test b/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
new file mode 100644
index 000000000000..493537464a00
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/elf-verdef-invalid.test
@@ -0,0 +1,236 @@
+## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_verdef sections.
+
+## Check that we report a warning when sh_link references a non-existent section.
+
+# RUN: yaml2obj %s --docnum=1 -o %t1
+# RUN: llvm-readobj -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-LLVM -DFILE=%t1
+# RUN: not llvm-readelf -V %t1 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-GNU -DFILE=%t1
+
+# INVALID-LINK-LLVM: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255
+
+## TODO: llvm-readelf should also report a meaningful warning instead of an error.
+# INVALID-LINK-GNU: Version definition
+# INVALID-LINK-GNU: error: '[[FILE]]': invalid section index: 255
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: 0xFF
+ Info: 0x0
+ Entries: []
+
+## Check that we report a warning when the sh_link field of a SHT_GNU_verdef section references a non-string table section.
+
+# RUN: yaml2obj %s --docnum=2 -o %t2
+# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2
+# RUN: llvm-readelf -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t2
+
+# INVALID-STRING-TABLE: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verdef section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: 0x0
+ Info: 0x0
+ Entries: []
+
+## Check that we report a warning when we can't read the content of the SHT_GNU_verdef section.
+
+# RUN: yaml2obj %s --docnum=3 -o %t3
+# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3
+# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t3
+
+# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that cannot be represented
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .dynstr
+ Info: 0x0
+ Entries: []
+ ShOffset: 0xFFFFFFFF
+DynamicSymbols:
+ - Name: foo
+
+## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
+## that goes past the end of the section.
+
+# RUN: yaml2obj %s --docnum=4 -o %t4
+# RUN: llvm-readobj -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4
+# RUN: llvm-readelf -V %t4 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t4
+
+# DEF-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 goes past the end of the section
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .dynstr
+ Info: 0x1
+ Entries:
+ - Version: 0
+ Flags: 0
+ VersionNdx: 0
+ Hash: 0
+ Names:
+ - FOO
+ ShSize: 1
+DynamicSymbols:
+ - Name: foo
+
+## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
+## that refers to an auxiliary entry that goes past the end of the section.
+
+# RUN: yaml2obj %s --docnum=5 -o %t5
+# RUN: llvm-readobj -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5
+# RUN: llvm-readelf -V %t5 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t5
+
+# AUX-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 refers to an auxiliary entry that goes past the end of the section
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .dynstr
+ Info: 0x1
+ Entries:
+ - Version: 0
+ Flags: 0
+ VersionNdx: 0
+ Hash: 0
+ Names:
+ - FOO
+ ShSize: 21
+DynamicSymbols:
+ - Name: foo
+
+## Check that we can dump a SHT_GNU_verdef section properly even if it contains version names strings
+## that overrun the linked string table.
+
+# RUN: yaml2obj %s --docnum=6 -o %t6
+# RUN: llvm-readobj -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-LLVM --implicit-check-not="warning:" -DFILE=%t6
+# RUN: llvm-readelf -V %t6 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-GNU --implicit-check-not="warning:" -DFILE=%t6
+
+# PAST-STRTAB-END-LLVM: VersionDefinitions [
+# PAST-STRTAB-END-LLVM-NEXT: Definition {
+# PAST-STRTAB-END-LLVM-NEXT: Version: 0
+# PAST-STRTAB-END-LLVM-NEXT: Flags [ (0x0)
+# PAST-STRTAB-END-LLVM-NEXT: ]
+# PAST-STRTAB-END-LLVM-NEXT: Index: 0
+# PAST-STRTAB-END-LLVM-NEXT: Hash: 0
+# PAST-STRTAB-END-LLVM-NEXT: Name: <invalid vda_name: 5>
+# PAST-STRTAB-END-LLVM-NEXT: Predecessors: []
+# PAST-STRTAB-END-LLVM-NEXT: }
+# PAST-STRTAB-END-LLVM-NEXT: ]
+
+# PAST-STRTAB-END-GNU: Version definition section '.gnu.version_d' contains 1 entries:
+# PAST-STRTAB-END-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.strtab)
+# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 0 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5>
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .strtab
+ Info: 0x1
+ Entries:
+ - Version: 0
+ Flags: 0
+ VersionNdx: 0
+ Hash: 0
+ Names:
+ - FOO
+ - Name: .strtab
+ Type: SHT_STRTAB
+DynamicSymbols:
+ - Name: BAR
+
+## Check we report a warning when a version definition is not correctly aligned in memory.
+
+# RUN: yaml2obj %s --docnum=7 -o %t7
+# RUN: llvm-readobj -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7
+# RUN: llvm-readelf -V %t7 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t7
+
+# MISALIGNED-DEF: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned version definition entry at offset 0x0
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Type: Fill
+ Size: 0x1
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Link: .dynstr
+ Info: 0x1
+ Entries:
+ - Version: 0
+ Flags: 0
+ VersionNdx: 0
+ Hash: 0
+ Names:
+ - FOO
+DynamicSymbols:
+ - Name: foo
+
+## Check we report a warning when an auxiliary entry is not correctly aligned in memory.
+
+# RUN: yaml2obj %s --docnum=8 -o %t8
+# RUN: llvm-readobj -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8
+# RUN: llvm-readelf -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t8
+
+# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned auxiliary entry at offset 0x13
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_DYN
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version_d
+ Type: SHT_GNU_verdef
+ Flags: [ SHF_ALLOC ]
+ Link: .dynstr
+ Info: 0x1
+## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.
+ Content: "0000000000000100000000001300000000000000"
+DynamicSymbols:
+ - Name: foo
+ Binding: STB_GLOBAL
diff --git a/llvm/test/tools/llvm-readobj/elf-invalid-versioning.test b/llvm/test/tools/llvm-readobj/elf-verneed-invalid.test
similarity index 98%
rename from llvm/test/tools/llvm-readobj/elf-invalid-versioning.test
rename to llvm/test/tools/llvm-readobj/elf-verneed-invalid.test
index d7a5198df100..971cada0195a 100644
--- a/llvm/test/tools/llvm-readobj/elf-invalid-versioning.test
+++ b/llvm/test/tools/llvm-readobj/elf-verneed-invalid.test
@@ -1,5 +1,4 @@
-## Here we test how llvm-readelf/llvm-readobj behave when inputs have
-## invalid versioning sections.
+## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_verneed sections.
## In the first case we have a SHT_GNU_versym section that refers to
## a version listed in a SHT_GNU_verneed section. That version has an
diff --git a/llvm/test/tools/llvm-readobj/elf-versioninfo.test b/llvm/test/tools/llvm-readobj/elf-versioninfo.test
index 591dfe27a1a8..a7eaa80bb5df 100644
--- a/llvm/test/tools/llvm-readobj/elf-versioninfo.test
+++ b/llvm/test/tools/llvm-readobj/elf-versioninfo.test
@@ -1,4 +1,6 @@
## Test how llvm-readobj/llvm-readelf tools dump versioning sections.
+## Check that SHT_GNU_versym dumper can see versions described in
+## SHT_GNU_verdef and SHT_GNU_verneed sections.
# RUN: yaml2obj %s --docnum=1 -o %t1
# RUN: llvm-readobj -V %t1 | FileCheck %s --check-prefix=LLVM
@@ -293,238 +295,3 @@ DynamicSymbols:
# GNU-NEXT: 0x0050: Name: v2 Flags: <unknown> Version: 5
# GNU-NEXT: 0x0060: Version: 1 File: verneed2.so.0 Cnt: 1
# GNU-NEXT: 0x0070: Name: v3 Flags: none Version: 6
-
-## Check that we report a warning when sh_link references a non-existent section.
-
-# RUN: yaml2obj %s --docnum=2 -o %t2
-# RUN: llvm-readobj -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-LLVM -DFILE=%t2
-# RUN: not llvm-readelf -V %t2 2>&1 | FileCheck %s --check-prefix=INVALID-LINK-GNU -DFILE=%t2
-
-# INVALID-LINK-LLVM: warning: '[[FILE]]': invalid section linked to SHT_GNU_verdef section with index 1: invalid section index: 255
-
-## TODO: llvm-readelf should also report a meaningful warning instead of an error.
-# INVALID-LINK-GNU: Version definition
-# INVALID-LINK-GNU: error: '[[FILE]]': invalid section index: 255
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: 0xFF
- Info: 0x0
- Entries: []
-
-## Check that we report a warning when the sh_link field of a SHT_GNU_verdef section references a non-string table section.
-
-# RUN: yaml2obj %s --docnum=3 -o %t3
-# RUN: llvm-readobj -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t3
-# RUN: llvm-readelf -V %t3 2>&1 | FileCheck %s --check-prefix=INVALID-STRING-TABLE -DFILE=%t3
-
-# INVALID-STRING-TABLE: warning: '[[FILE]]': invalid string table linked to SHT_GNU_verdef section with index 1: invalid sh_type for string table section [index 0]: expected SHT_STRTAB, but got SHT_NULL
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: 0x0
- Info: 0x0
- Entries: []
-
-## Check that we report a warning when we can't read the content of the SHT_GNU_verdef section.
-
-# RUN: yaml2obj %s --docnum=4 -o %t4
-# RUN: llvm-readobj -V %t4 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t4
-# RUN: llvm-readelf -V %t4 2>&1 | FileCheck %s --check-prefix=INVALID-DATA -DFILE=%t4
-
-# INVALID-DATA: warning: '[[FILE]]': cannot read content of SHT_GNU_verdef section with index 1: section [index 1] has a sh_offset (0xffffffff) + sh_size (0x0) that cannot be represented
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: .dynstr
- Info: 0x0
- Entries: []
- ShOffset: 0xFFFFFFFF
-DynamicSymbols:
- - Name: foo
-
-## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
-## that goes past the end of the section.
-
-# RUN: yaml2obj %s --docnum=5 -o %t5
-# RUN: llvm-readobj -V %t5 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t5
-# RUN: llvm-readelf -V %t5 2>&1 | FileCheck %s --check-prefix=DEF-PAST-END -DFILE=%t5
-
-# DEF-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 goes past the end of the section
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: .dynstr
- Info: 0x1
- Entries:
- - Version: 0
- Flags: 0
- VersionNdx: 0
- Hash: 0
- Names:
- - FOO
- ShSize: 1
-DynamicSymbols:
- - Name: foo
-
-## Check that we report a warning when a SHT_GNU_verdef section contains a version definition
-## that refers to an auxiliary entry that goes past the end of the section.
-
-# RUN: yaml2obj %s --docnum=6 -o %t6
-# RUN: llvm-readobj -V %t6 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t6
-# RUN: llvm-readelf -V %t6 2>&1 | FileCheck %s --check-prefix=AUX-PAST-END -DFILE=%t6
-
-# AUX-PAST-END: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: version definition 1 refers to an auxiliary entry that goes past the end of the section
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: .dynstr
- Info: 0x1
- Entries:
- - Version: 0
- Flags: 0
- VersionNdx: 0
- Hash: 0
- Names:
- - FOO
- ShSize: 21
-DynamicSymbols:
- - Name: foo
-
-## Check that we can dump a SHT_GNU_verdef section properly even if it contains version names strings
-## that overrun the linked string table.
-
-# RUN: yaml2obj %s --docnum=7 -o %t7
-# RUN: llvm-readobj -V %t7 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-LLVM --implicit-check-not="warning:" -DFILE=%t7
-# RUN: llvm-readelf -V %t7 2>&1 | FileCheck %s --check-prefix=PAST-STRTAB-END-GNU --implicit-check-not="warning:" -DFILE=%t7
-
-# PAST-STRTAB-END-LLVM: VersionDefinitions [
-# PAST-STRTAB-END-LLVM-NEXT: Definition {
-# PAST-STRTAB-END-LLVM-NEXT: Version: 0
-# PAST-STRTAB-END-LLVM-NEXT: Flags [ (0x0)
-# PAST-STRTAB-END-LLVM-NEXT: ]
-# PAST-STRTAB-END-LLVM-NEXT: Index: 0
-# PAST-STRTAB-END-LLVM-NEXT: Hash: 0
-# PAST-STRTAB-END-LLVM-NEXT: Name: <invalid vda_name: 5>
-# PAST-STRTAB-END-LLVM-NEXT: Predecessors: []
-# PAST-STRTAB-END-LLVM-NEXT: }
-# PAST-STRTAB-END-LLVM-NEXT: ]
-
-# PAST-STRTAB-END-GNU: Version definition section '.gnu.version_d' contains 1 entries:
-# PAST-STRTAB-END-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.strtab)
-# PAST-STRTAB-END-GNU-NEXT: 0x0000: Rev: 0 Flags: none Index: 0 Cnt: 1 Name: <invalid vda_name: 5>
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: .strtab
- Info: 0x1
- Entries:
- - Version: 0
- Flags: 0
- VersionNdx: 0
- Hash: 0
- Names:
- - FOO
- - Name: .strtab
- Type: SHT_STRTAB
-DynamicSymbols:
- - Name: BAR
-
-## Check we report a warning when a version definition is not correctly aligned in memory.
-
-# RUN: yaml2obj %s --docnum=8 -o %t8
-# RUN: llvm-readobj -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t8
-# RUN: llvm-readelf -V %t8 2>&1 | FileCheck %s --check-prefix=MISALIGNED-DEF -DFILE=%t8
-
-# MISALIGNED-DEF: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned version definition entry at offset 0x0
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Type: Fill
- Size: 0x1
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Link: .dynstr
- Info: 0x1
- Entries:
- - Version: 0
- Flags: 0
- VersionNdx: 0
- Hash: 0
- Names:
- - FOO
-DynamicSymbols:
- - Name: foo
-
-## Check we report a warning when an auxiliary entry is not correctly aligned in memory.
-
-# RUN: yaml2obj %s --docnum=9 -o %t9
-# RUN: llvm-readobj -V %t9 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t9
-# RUN: llvm-readelf -V %t9 2>&1 | FileCheck %s --check-prefix=MISALIGNED-AUX -DFILE=%t9
-
-# MISALIGNED-AUX: warning: '[[FILE]]': invalid SHT_GNU_verdef section with index 1: found a misaligned auxiliary entry at offset 0x13
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_DYN
- Machine: EM_X86_64
-Sections:
- - Name: .gnu.version_d
- Type: SHT_GNU_verdef
- Flags: [ SHF_ALLOC ]
- Link: .dynstr
- Info: 0x1
-## The byte offset to the auxiliary entry is 0x13, i.e. it is not correctly aligned in memory.
- Content: "0000000000000100000000001300000000000000"
-DynamicSymbols:
- - Name: foo
- Binding: STB_GLOBAL
More information about the llvm-commits
mailing list