[llvm] a8d0201 - [llvm-readobj][test] - Improve section-symbols.test

Georgii Rymar via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 16 02:36:33 PDT 2020


Author: Georgii Rymar
Date: 2020-09-16T12:36:09+03:00
New Revision: a8d02015fcb783d5fdf1e09edd1b9e152c5d19b7

URL: https://github.com/llvm/llvm-project/commit/a8d02015fcb783d5fdf1e09edd1b9e152c5d19b7
DIFF: https://github.com/llvm/llvm-project/commit/a8d02015fcb783d5fdf1e09edd1b9e152c5d19b7.diff

LOG: [llvm-readobj][test] - Improve section-symbols.test

`section-symbols.test` tests how we print section symbols in
different situations.

We might have 2 different cases:
1) A named STT_SECTION symbol.
2) An unnamed STT_SECTION symbol.

Usually section symbols have no name and then `--symbols` uses their
section names when prints them. If symbol has a name, then it is used.

For `--relocations` we also want to have this logic probably,
but currently we always ignore symbol names and always use section names.
It is not consistent with GNU readelf and with our logic for `--symbols`.

This patch refines testing to document the existent behavior and improve
coverage.

Differential revision: https://reviews.llvm.org/D87612

Added: 
    

Modified: 
    llvm/test/tools/llvm-readobj/ELF/section-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 3b6a2eca4fc4e..1aac1e6f06e8f 100644
--- a/llvm/test/tools/llvm-readobj/ELF/section-symbols.test
+++ b/llvm/test/tools/llvm-readobj/ELF/section-symbols.test
@@ -1,35 +1,71 @@
-## ELF section symbols use the section names when printing. This test verifies
-## this and also that appropriate things are printed if the section is somehow
-## invalid.
+## ELF section symbols use the corresponding section names when printing
+## unnamed symbols. This test verifies this and also that appropriate things
+## are printed if the section is somehow invalid.
 
 # RUN: yaml2obj %s -o %t1
-# RUN: llvm-readobj %t1 --symbols 2> %t.llvm.err1 | FileCheck %s --check-prefix=LLVM1
-# RUN: FileCheck %s --input-file %t.llvm.err1 --check-prefix=WARN1 --implicit-check-not=warning
-# RUN: llvm-readelf %t1 --symbols 2> %t.gnu.err1 | FileCheck %s --check-prefix=GNU1
-# RUN: FileCheck %s --input-file %t.gnu.err1 --check-prefix=WARN1 --implicit-check-not=warning
+## FIXME: 1) Relocations should print section symbol names when they are not empty.
+##        2) We should still print a relocation even when we are unable to lookup a symbol name.
+# RUN: llvm-readobj %t1 --symbols --relocations 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t1 --check-prefix=LLVM1 --implicit-check-not="warning:"
+# RUN: llvm-readelf %t1 --symbols --relocations 2>&1 | \
+# RUN:   FileCheck %s -DFILE=%t1 --check-prefix=GNU1 --implicit-check-not="warning:"
+
+# LLVM1:      Relocations [
+# LLVM1-NEXT:   Section (4) .rela.foo {
+# LLVM1-NEXT:     0x1 R_X86_64_NONE .foo 0x0
+# LLVM1-NEXT:     0x2 R_X86_64_NONE .foo 0x0
+# LLVM1-NEXT: warning: '[[FILE]]': unable to print relocation 3 in SHT_RELA section with index 4: invalid section index: 67
+# LLVM1-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_RELA section with index 4: invalid section index: 67
+# LLVM1-NEXT:     0x5 R_X86_64_NONE .bar 0x0
+# LLVM1-NEXT:     0x6 R_X86_64_NONE .bar 0x0
+# LLVM1-NEXT: warning: '[[FILE]]': unable to print relocation 7 in SHT_RELA section with index 4: invalid section index: 66
+# LLVM1-NEXT: warning: '[[FILE]]': unable to print relocation 8 in SHT_RELA section with index 4: invalid section index: 66
+# LLVM1-NEXT:   }
+# LLVM1-NEXT: ]
 
 # LLVM1: Name: (0)
 # LLVM1: Name: .foo (0)
+# LLVM1: Name: symbol1 (25)
+# LLVM1: warning: '[[FILE]]': invalid section index: 67
 # LLVM1: Name: <section 67> (0)
+# LLVM1: Name: symbol2 (17)
 # LLVM1: Name: .bar (0)
+# LLVM1: Name: symbol3 (9)
+# LLVM1: warning: '[[FILE]]': invalid section index: 66
 # LLVM1: Name: <section 66> (0)
+# LLVM1: Name: symbol4 (1)
+
+# GNU1:      Relocation section '.rela.foo' at offset 0x58 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   .foo + 0
+# GNU1-NEXT: warning: '[[FILE]]': unable to print relocation 3 in SHT_RELA section with index 4: invalid section index: 67
+# GNU1-NEXT: warning: '[[FILE]]': unable to print relocation 4 in SHT_RELA section with index 4: invalid section index: 67
+# GNU1-NEXT: 00000005  00000500 R_X86_64_NONE   00000000   .bar + 0
+# GNU1-NEXT: 00000006  00000600 R_X86_64_NONE   00000000   .bar + 0
+# GNU1-NEXT: warning: '[[FILE]]': unable to print relocation 7 in SHT_RELA section with index 4: invalid section index: 66
+# GNU1-NEXT: warning: '[[FILE]]': unable to print relocation 8 in SHT_RELA section with index 4: invalid section index: 66
 
-# GNU1:      Symbol table '.symtab' contains 5 entries:
+# GNU1:      Symbol table '.symtab' contains 9 entries:
 # GNU1-NEXT:    Num: {{.*}} Type    {{.*}} Ndx Name
 # GNU1-NEXT:      0: {{.*}} NOTYPE  {{.*}} UND {{$}}
-# GNU1-NEXT:      1: {{.*}} SECTION {{.*}}   1 .foo
-# GNU1-NEXT:      2: {{.*}} SECTION {{.*}}  67 <section 67>
-# GNU1-NEXT:      3: {{.*}} SECTION {{.*}}   2 .bar
-# GNU1-NEXT:      4: {{.*}} SECTION {{.*}}  66 <section 66>
-
-# WARN1: warning: '{{.*}}.tmp1': invalid section index: 67
-# WARN1: warning: '{{.*}}.tmp1': invalid section index: 66
+# GNU1-NEXT:      1: {{.*}} SECTION {{.*}}  1 .foo
+# GNU1-NEXT:      2: {{.*}} SECTION {{.*}}  1 symbol1
+# GNU1-NEXT: warning: '[[FILE]]': invalid section index: 67
+# GNU1-NEXT:      3: {{.*}} SECTION {{.*}} 67 <section 67>
+# GNU1-NEXT:      4: {{.*}} SECTION {{.*}} 67 symbol2
+# GNU1-NEXT:      5: {{.*}} SECTION {{.*}}  2 .bar
+# GNU1-NEXT:      6: {{.*}} SECTION {{.*}}  2 symbol3
+# GNU1-NEXT: warning: '[[FILE]]': invalid section index: 66
+# GNU1-NEXT:      7: {{.*}} SECTION {{.*}} 66 <section 66>
+# GNU1-NEXT:      8: {{.*}} SECTION {{.*}} 66 symbol4
 
 --- !ELF
 FileHeader:
-  Class: ELFCLASS32
-  Data:  ELFDATA2LSB
-  Type:  ET_REL
+  Class:   ELFCLASS32
+  Data:    ELFDATA2LSB
+  Type:    ET_REL
+  Machine: EM_X86_64
 Sections:
   - Name: .foo
     Type: SHT_PROGBITS
@@ -38,22 +74,69 @@ Sections:
   - Name: .symtab_shndx
     Type: SHT_SYMTAB_SHNDX
     Link: .symtab
-    Entries: [ 0, 0, 0, 2, 0x42 ]
+    Entries: [ 0, 0, 0, 0, 0, 2, 2, 0x42, 0x42 ]
+  - Name: .rela.foo
+    Type: SHT_RELA
+    Link: .symtab
+    Info: .foo
+    Relocations:
+      - Offset: 0x1
+        Symbol: 1
+        Type:   R_X86_64_NONE
+      - Offset: 0x2
+        Symbol: 2
+        Type:   R_X86_64_NONE
+      - Offset: 0x3
+        Symbol: 3
+        Type:   R_X86_64_NONE
+      - Offset: 0x4
+        Symbol: 4
+        Type:   R_X86_64_NONE
+      - Offset: 0x5
+        Symbol: 5
+        Type:   R_X86_64_NONE
+      - Offset: 0x6
+        Symbol: 6
+        Type:   R_X86_64_NONE
+      - Offset: 0x7
+        Symbol: 7
+        Type:   R_X86_64_NONE
+      - Offset: 0x8
+        Symbol: 8
+        Type:   R_X86_64_NONE
 Symbols:
+## Case 1: a valid unnamed section symbol.
   - Name: ""
     Section: .foo
     Type: STT_SECTION
+## Case 2: a valid named section symbol.
+  - Name: "symbol1"
+    Section: .foo
+    Type: STT_SECTION
+## Case 3: an unnamed section symbol with invalid index.
   - Name: ""
     Index: 0x43
     Type: STT_SECTION
-  # Section symbol via SHT_SYMTAB_SHNDX.
+## Case 4: a named section symbol with invalid index.
+  - Name: "symbol2"
+    Index: 0x43
+    Type: STT_SECTION
+## Case 5: a valid unnamed section symbol via SHT_SYMTAB_SHNDX.
   - Name: ""
     Index: SHN_XINDEX
     Type: STT_SECTION
-  # Section symbol via SHT_SYMTAB_SHNDX with invalid index.
+## Case 6: a valid named section symbol via SHT_SYMTAB_SHNDX.
+  - Name: "symbol3"
+    Index: SHN_XINDEX
+    Type: STT_SECTION
+## Case 7: a unnamed section symbol via SHT_SYMTAB_SHNDX with invalid index.
   - Name: ""
     Index: SHN_XINDEX
     Type: STT_SECTION
+## Case 8: a named section symbol via SHT_SYMTAB_SHNDX with invalid index.
+  - Name: "symbol4"
+    Index: SHN_XINDEX
+    Type: STT_SECTION
 
 # RUN: yaml2obj %s --docnum=2 -o %t2
 # RUN: llvm-readobj %t2 --symbols 2> %t.llvm.err2 | FileCheck %s --check-prefix=LLVM2


        


More information about the llvm-commits mailing list