summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/tools/llvm-readobj/ELF/versym-invalid.test')
-rw-r--r--llvm/test/tools/llvm-readobj/ELF/versym-invalid.test220
1 files changed, 220 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test b/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
new file mode 100644
index 00000000000..a88318e5f49
--- /dev/null
+++ b/llvm/test/tools/llvm-readobj/ELF/versym-invalid.test
@@ -0,0 +1,220 @@
+## Test how llvm-readobj/llvm-readelf tools handle invalid SHT_GNU_versym sections.
+
+## Check that we report a warning when sh_link references a non-existent section.
+
+# RUN: yaml2obj --docnum=1 %s -o %t1
+# RUN: llvm-readelf -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=GNU-INVALID-LINK
+# RUN: llvm-readobj -V %t1 2>&1 | FileCheck -DFILE=%t1 %s --check-prefix=LLVM-INVALID-LINK
+
+# GNU-INVALID-LINK: Version symbols section '.gnu.version' contains 0 entries:
+# GNU-INVALID-LINK-EMPTY:
+# GNU-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
+# GNU-INVALID-LINK-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 255 (<corrupt>)
+
+# LLVM-INVALID-LINK: VersionSymbols [
+# LLVM-INVALID-LINK-EMPTY:
+# LLVM-INVALID-LINK-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: invalid section index: 255
+# LLVM-INVALID-LINK-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Link: 0xFF
+ Entries: [ ]
+
+## Check that we report a warning when the sh_link field of a SHT_GNU_versym section does not reference
+## a dynamic symbol table section.
+
+# RUN: yaml2obj --docnum=2 %s -o %t2
+# RUN: llvm-readelf -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-GNU
+# RUN: llvm-readobj -V %t2 2>&1 | FileCheck -DFILE=%t2 %s --check-prefix=INVALID-SYMBOL-TABLE-LLVM
+
+# INVALID-SYMBOL-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries:
+# INVALID-SYMBOL-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 0 ()
+# INVALID-SYMBOL-TABLE-GNU-EMPTY:
+# INVALID-SYMBOL-TABLE-GNU-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL
+# INVALID-SYMBOL-TABLE-GNU-NEXT: 000: 0 (*local*)
+
+# INVALID-SYMBOL-TABLE-LLVM: VersionSymbols [
+# INVALID-SYMBOL-TABLE-LLVM-EMPTY:
+# INVALID-SYMBOL-TABLE-LLVM-NEXT: warning: '[[FILE]]': invalid section linked to SHT_GNU_versym section with index 1: expected SHT_DYNSYM, but got SHT_NULL
+# INVALID-SYMBOL-TABLE-LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Link: 0x0
+ Entries: [ 0 ]
+
+## Check we report a warning when something is wrong with a string table linked to a symbol table that
+## is linked with SHT_GNU_versym. In this case we are unable to produce LLVM style output,
+## but GNU style is fine because it does not need that string table.
+
+# RUN: yaml2obj --docnum=3 %s -o %t3
+# RUN: llvm-readelf -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-GNU
+# RUN: llvm-readobj -V %t3 2>&1 | FileCheck -DFILE=%t3 %s --check-prefix=INVALID-STRING-TABLE-LLVM
+
+# INVALID-STRING-TABLE-GNU: Version symbols section '.gnu.version' contains 1 entries:
+# INVALID-STRING-TABLE-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 5 (.dynsym)
+# INVALID-STRING-TABLE-GNU-EMPTY:
+# INVALID-STRING-TABLE-GNU-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
+# INVALID-STRING-TABLE-GNU-NEXT: 000: 0 (*local*)
+
+# INVALID-STRING-TABLE-LLVM: VersionSymbols [
+# INVALID-STRING-TABLE-LLVM-EMPTY:
+# INVALID-STRING-TABLE-LLVM-NEXT: warning: '[[FILE]]': can't get a string table for the symbol table linked to SHT_GNU_versym section with index 1: invalid string table linked to SHT_DYNSYM section with index 5: invalid sh_type for string table section [index 2]: expected SHT_STRTAB, but got SHT_NULL
+# INVALID-STRING-TABLE-LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Link: .dynsym
+ Entries: [ 0 ]
+ - Name: .dynstr
+ Type: SHT_NULL
+DynamicSymbols: []
+
+## Check we report a warning when a SHT_GNU_versym section is not correctly aligned in memory.
+
+# RUN: yaml2obj --docnum=4 %s -o %t4
+# RUN: llvm-readelf -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-GNU
+# RUN: llvm-readobj -V %t4 2>&1 | FileCheck -DFILE=%t4 %s --check-prefix=MISALIGNED-LLVM
+
+# MISALIGNED-GNU: Version symbols section '.gnu.version' contains 0 entries:
+# MISALIGNED-GNU-NEXT: Addr: 0000000000000000 Offset: 0x00ffff Link: 0 ()
+# MISALIGNED-GNU-EMPTY:
+# MISALIGNED-GNU-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned
+
+# MISALIGNED-LLVM: VersionSymbols [
+# MISALIGNED-LLVM-EMPTY:
+# MISALIGNED-LLVM-NEXT: warning: '[[FILE]]': the SHT_GNU_versym section with index 1 is misaligned
+# MISALIGNED-LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Entries: [ ]
+ ShOffset: 0xffff
+
+## 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
+
+# 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-EMPTY:
+# 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: VersionSymbols [
+# INVALID-ENT-SIZE-LLVM-EMPTY:
+# 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: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Entries: [ 0 ]
+ EntSize: 3
+
+## Check we report a warning when the number of version entries does not match the number of symbols in the associated symbol table.
+
+# RUN: yaml2obj --docnum=6 %s -o %t6
+# RUN: llvm-readelf -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-GNU
+# RUN: llvm-readobj -V %t6 2>&1 | FileCheck -DFILE=%t6 %s --check-prefix=SYMBOLS-NUM-MISMATCH-LLVM
+
+# SYMBOLS-NUM-MISMATCH-GNU: Version symbols section '.gnu.version' contains 2 entries:
+# SYMBOLS-NUM-MISMATCH-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 4 (.dynsym)
+# SYMBOLS-NUM-MISMATCH-GNU-EMPTY:
+# SYMBOLS-NUM-MISMATCH-GNU-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4
+# SYMBOLS-NUM-MISMATCH-GNU-NEXT: 000: 0 (*local*) 1 (*global*)
+
+# SYMBOLS-NUM-MISMATCH-LLVM: VersionSymbols [
+# SYMBOLS-NUM-MISMATCH-LLVM-EMPTY:
+# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: warning: '[[FILE]]': SHT_GNU_versym section with index 1: the number of entries (2) does not match the number of symbols (3) in the symbol table with index 4
+# SYMBOLS-NUM-MISMATCH-LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Entries: [ 0, 1 ]
+ Link: .dynsym
+DynamicSymbols:
+ - Name: foo
+ - Name: bar
+
+## Check we can dump a SHT_GNU_versym section when it is linked to a custom dynamic symbol
+## table that is not called ".dynsym".
+
+# RUN: yaml2obj --docnum=7 %s -o %t7
+# RUN: llvm-readelf -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-GNU
+# RUN: llvm-readobj -V %t7 2>&1 | FileCheck -DFILE=%t7 %s --check-prefix=CUSTOM-SYMTAB-LLVM
+
+# CUSTOM-SYMTAB-GNU: Version symbols section '.gnu.version' contains 1 entries:
+# CUSTOM-SYMTAB-GNU-NEXT: Addr: 0000000000000000 Offset: 0x000040 Link: 2 (.foo.dynsym)
+# CUSTOM-SYMTAB-GNU-NEXT: 000: 0 (*local*)
+
+# CUSTOM-SYMTAB-LLVM: VersionSymbols [
+# CUSTOM-SYMTAB-LLVM-NEXT: Symbol {
+# CUSTOM-SYMTAB-LLVM-NEXT: Version: 0
+# CUSTOM-SYMTAB-LLVM-NEXT: Name:
+# CUSTOM-SYMTAB-LLVM-NEXT: }
+# CUSTOM-SYMTAB-LLVM-NEXT: ]
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .gnu.version
+ Type: SHT_GNU_versym
+ Link: .foo.dynsym
+ Entries: [ 0 ]
+## A custom empty dynamic symbol table with a null entry.
+ - Name: .foo.dynsym
+ Type: SHT_DYNSYM
+ Link: .dynstr
+ EntSize: 24
+ Size: 24
+DynamicSymbols:
+ - Name: foo
+ - Name: bar
OpenPOWER on IntegriCloud