[llvm] c6a101d - [llvm-readobj][test] Test -s with an invalid section name
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 8 21:17:23 PDT 2023
Author: Fangrui Song
Date: 2023-09-08T21:17:19-07:00
New Revision: c6a101d7ede0e2d140f3df8a17797c796f674f23
URL: https://github.com/llvm/llvm-project/commit/c6a101d7ede0e2d140f3df8a17797c796f674f23
DIFF: https://github.com/llvm/llvm-project/commit/c6a101d7ede0e2d140f3df8a17797c796f674f23.diff
LOG: [llvm-readobj][test] Test -s with an invalid section name
Added:
Modified:
llvm/test/tools/llvm-readobj/ELF/section-symbols.test
llvm/test/tools/llvm-readobj/ELF/symbols.test
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readobj/ELF/section-symbols.test b/llvm/test/tools/llvm-readobj/ELF/section-symbols.test
index 1e40746b7303f3e..353c2143de480b4 100644
--- a/llvm/test/tools/llvm-readobj/ELF/section-symbols.test
+++ b/llvm/test/tools/llvm-readobj/ELF/section-symbols.test
@@ -9,7 +9,7 @@
# RUN: FileCheck %s -DFILE=%t1 --check-prefix=GNU1 --implicit-check-not="warning:"
# LLVM1: Relocations [
-# LLVM1-NEXT: Section (4) .rela.foo {
+# LLVM1-NEXT: Section (5) .rela.foo {
# LLVM1-NEXT: 0x1 R_X86_64_NONE .foo 0x0
# LLVM1-NEXT: 0x2 R_X86_64_NONE symbol1 0x0
# LLVM1-NEXT: warning: '[[FILE]]': invalid section index: 67
@@ -32,8 +32,10 @@
# LLVM1: Name: symbol3 (9)
# LLVM1: Name: <section 66> (0)
# LLVM1: Name: symbol4 (1)
+# LLVM1: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
+# LLVM1: Name: <section 3> (0)
-# GNU1: Relocation section '.rela.foo' at offset 0x58 contains 8 entries:
+# GNU1: Relocation section '.rela.foo' at offset {{.*}} contains 8 entries:
# GNU1-NEXT: Offset Info Type Sym. Value Symbol's Name + Addend
# GNU1-NEXT: 00000001 00000100 R_X86_64_NONE 00000000 .foo + 0
# GNU1-NEXT: 00000002 00000200 R_X86_64_NONE 00000000 symbol1 + 0
@@ -46,7 +48,7 @@
# GNU1-NEXT: 00000007 00000700 R_X86_64_NONE 00000000 <section 66> + 0
# GNU1-NEXT: 00000008 00000800 R_X86_64_NONE 00000000 symbol4 + 0
-# GNU1: Symbol table '.symtab' contains 9 entries:
+# GNU1: Symbol table '.symtab' contains 10 entries:
# GNU1-NEXT: Num: {{.*}} Type {{.*}} Ndx Name
# GNU1-NEXT: 0: {{.*}} NOTYPE {{.*}} UND {{$}}
# GNU1-NEXT: 1: {{.*}} SECTION {{.*}} 1 .foo
@@ -57,6 +59,8 @@
# GNU1-NEXT: 6: {{.*}} SECTION {{.*}} 2 symbol3
# GNU1-NEXT: 7: {{.*}} SECTION {{.*}} 66 <section 66>
# GNU1-NEXT: 8: {{.*}} SECTION {{.*}} 66 symbol4
+# GNU1-NEXT: warning: '[[FILE]]': a section [index 3] has an invalid sh_name (0xffff) offset which goes past the end of the section name string table
+# GNU1-NEXT: 9: {{.*}} SECTION {{.*}} 3 <section 3>
--- !ELF
FileHeader:
@@ -69,10 +73,13 @@ Sections:
Type: SHT_PROGBITS
- Name: .bar
Type: SHT_PROGBITS
+ - Name: .invalid
+ Type: SHT_PROGBITS
+ ShName: 0xffff
- Name: .symtab_shndx
Type: SHT_SYMTAB_SHNDX
Link: .symtab
- Entries: [ 0, 0, 0, 0, 0, 2, 2, 0x42, 0x42 ]
+ Entries: [ 0, 0, 0, 0, 0, 2, 2, 0x42, 0x42, 0 ]
- Name: .rela.foo
Type: SHT_RELA
Link: .symtab
@@ -135,6 +142,10 @@ Symbols:
- Name: "symbol4"
Index: SHN_XINDEX
Type: STT_SECTION
+## Case 9: a unnamed section symbol with invalid name.
+ - Name: ""
+ Index: 3
+ Type: STT_SECTION
# RUN: yaml2obj %s --docnum=2 -o %t2
# RUN: llvm-readobj %t2 --symbols 2> %t.llvm.err2 | FileCheck %s --check-prefix=LLVM2
diff --git a/llvm/test/tools/llvm-readobj/ELF/symbols.test b/llvm/test/tools/llvm-readobj/ELF/symbols.test
index fd4c07c5cceb7b0..e924f0b67f4bcc4 100644
--- a/llvm/test/tools/llvm-readobj/ELF/symbols.test
+++ b/llvm/test/tools/llvm-readobj/ELF/symbols.test
@@ -228,3 +228,21 @@ Symbols:
# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: Num: Value Size Type Bind Vis Ndx Name
# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
# SYMTAB-SHSTRTAB-ERR-GNU-NEXT: 1: 0000000000000001 0 NOTYPE GLOBAL DEFAULT 1 foo
+
+## Test a symbol defined relative to a section with an invalid name.
+# RUN: yaml2obj --docnum=3 %s -o %t64.err4
+# RUN: llvm-readelf -s %t64.err4 2>&1 | FileCheck /dev/null --implicit-check-not=warning:
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .invalid
+ Type: SHT_PROGBITS
+ ShName: 0xffff
+Symbols:
+ - Name: foo
+ Section: .invalid
More information about the llvm-commits
mailing list