[llvm] 0ca95b2 - [llvm-objdump, test] Improve zero dumping and inline relocs tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 16 15:43:46 PST 2023


Author: Fangrui Song
Date: 2023-12-16T15:43:41-08:00
New Revision: 0ca95b269ff90afb706e2cf4c4a59d7c3afe6c65

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

LOG: [llvm-objdump,test] Improve zero dumping and inline relocs tests

Added: 
    

Modified: 
    llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
    llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test b/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
index c48e2d8c4f613f..d61d7455570b19 100644
--- a/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
+++ b/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test
@@ -1,54 +1,67 @@
-# RUN: yaml2obj %s -o %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t
 
 ## Check we do not skip zeroes blocks if have relocations pointed to these places.
-# RUN: llvm-objdump -D --reloc %t
+# RUN: llvm-objdump -D --reloc -j .rodata %t | FileCheck %s
 
-# CHECK:      0000000000000000 .rodata:
+# CHECK:      0000000000000000 <rodata1>:
 # CHECK-NEXT:        0:       00 00   addb    %al, (%rax)
-# CHECK-NEXT:                 0000000000000000:  R_X86_64_64  *ABS*
+# CHECK-NEXT:                 0000000000000000:  R_X86_64_64  x0
 # CHECK-NEXT:        2:       00 00   addb    %al, (%rax)
 # CHECK-NEXT:        4:       00 00   addb    %al, (%rax)
 # CHECK-NEXT:        6:       00 00   addb    %al, (%rax)
 # CHECK-NEXT:        8:       00 00   addb    %al, (%rax)
-# CHECK-NEXT:                 0000000000000008:  R_X86_64_64  *ABS*
-# CHECK-NEXT:        a:       00 00   addb    %al, (%rax)
-# CHECK-NEXT:        c:       00 00   addb    %al, (%rax)
-# CHECK-NEXT:        e:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:                 0000000000000008:  R_X86_64_64  x1
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:       16:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:       18:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:                 0000000000000018:  R_X86_64_64  x2
+# CHECK-NEXT:       1a:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:       1c:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:       1e:       00 00   addb    %al, (%rax)
+# CHECK-EMPTY:
+# CHECK-NEXT: 000000000000001f <rodata2>:
+# CHECK-NEXT:                 ...
+# CHECK-EMPTY:
+# CHECK-NEXT: 0000000000000037 <rodata3>:
+# CHECK-NEXT:                 ...
+# CHECK-NEXT:       3f:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:                 000000000000003f:  R_X86_64_64  x3
+# CHECK-NEXT:       41:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:       43:       00 00   addb    %al, (%rax)
+# CHECK-NEXT:       45:       00 00   addb    %al, (%rax)
 
 ## Check that without -reloc all zeroes would be omitted.
 # RUN: llvm-objdump -D %t | FileCheck %s --check-prefix=SKIP
 
-# SKIP:      0000000000000000 <.rodata>:
-# SKIP-NEXT:   ...
+# SKIP:       Disassembly of section .rodata:
 # SKIP-EMPTY:
-# SKIP-NEXT: Disassembly of section .rela.rodata:
+# SKIP-NEXT:  0000000000000000 <rodata1>:
+# SKIP-NEXT:                  ...
+# SKIP-NEXT:        1c:       00 00   addb    %al, (%rax)
+# SKIP-NEXT:        1e:       00 00   addb    %al, (%rax)
+# SKIP-EMPTY:
+# SKIP-NEXT:  000000000000001f <rodata2>:
+# SKIP-NEXT:                  ...
+# SKIP-EMPTY:
+# SKIP-NEXT:  0000000000000037 <rodata3>:
+# SKIP-NEXT:                  ...
+# SKIP-EMPTY:
+# SKIP-NEXT:  Disassembly of section .rela.rodata:
+
+.rodata
+.globl rodata1, rodata2
+rodata1:
+  .reloc ., BFD_RELOC_64, x0
+  .space 8
+  .reloc ., BFD_RELOC_64, x1
+  .space 16
+  .reloc ., BFD_RELOC_64, x2
+  .space 7
+
+rodata2:
+  .space 24
 
---- !ELF
-FileHeader:
-  Class:           ELFCLASS64
-  Data:            ELFDATA2LSB
-  Type:            ET_REL
-  Machine:         EM_X86_64
-Sections:
-  - Name:            .rodata
-    Type:            SHT_PROGBITS
-    Flags:           [ SHF_ALLOC ]
-    AddressAlign:    0x0000000000000001
-    Content:         '00000000000000000000000000000000'
-  - Name:            .rela.rodata
-    Type:            SHT_RELA
-    Flags:           [ SHF_INFO_LINK ]
-    Link:            .symtab
-    AddressAlign:    0x0000000000000008
-    EntSize:         0x0000000000000018
-    Info:            .rodata
-    Relocations:
-      - Offset:          0x0000000000000000
-        Symbol:          x
-        Type:            R_X86_64_64
-      - Offset:          0x0000000000000008
-        Symbol:          x
-        Type:            R_X86_64_64
-Symbols:
-  - Name: x
-    Binding:         STB_GLOBAL
+rodata3:
+  .space 8
+  .reloc ., BFD_RELOC_64, x3
+  .space 8

diff  --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
index 593735a6a10267..33438cbfa126e1 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
+++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test
@@ -1,53 +1,73 @@
 ## Show that --disassemble + --reloc prints relocations inline and does not dump
 ## the relocation sections.
 
-# RUN: yaml2obj %s --docnum=1 -o %t1.o
-# RUN: llvm-objdump %t1.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS"
+# RUN: rm -rf %t && split-file %s %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple=x86_64 1.s -o 1.o
+# RUN: llvm-objdump 1.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS"
+# RUN: llvm-objdump 1.o -r --disassemble-symbols=x2,x4 | FileCheck %s --check-prefix=CHECK2
 
-# CHECK:      0: e8 00 00 00 00                callq   0x5 <.text+0x5>
-# CHECK-NEXT:          0000000000000001:  R_X86_64_PC32        foo-0x4
-# CHECK-NEXT:          0000000000000002:  R_X86_64_NONE        bar+0x8
-# CHECK-NEXT: 5: e8 00 00 00 00                callq   0xa <.text+0xa>
-# CHECK-NEXT:          0000000000000006:  R_X86_64_PLT32       foo+0x1
+#--- 1.s
+# CHECK:       0000000000000000 <x1>:
+# CHECK-NEXT:    0: e8 00 00 00 00                callq   0x5 <x1+0x5>
+# CHECK-NEXT:             0000000000000001:  R_X86_64_PC32        foo-0x4
+# CHECK-NEXT:             0000000000000002:  R_X86_64_NONE        bar+0x8
+# CHECK-NEXT:    5: e8 00 00 00 00                callq   0xa <x2>
+# CHECK-NEXT:             0000000000000006:  R_X86_64_PLT32       foo+0x1
+# CHECK-EMPTY:
+# CHECK-NEXT:  000000000000000a <x2>:
+# CHECK-NEXT:    a: 90                            nop
+# CHECK-NEXT:    b: 48 8b 05 00 00 00 00          movq    (%rip), %rax            # 0x12 <x3>
+# CHECK-NEXT:             000000000000000e:  R_X86_64_REX_GOTPCRELX       var-0x4
+# CHECK-EMPTY:
+# CHECK-NEXT:  0000000000000012 <x3>:
+# CHECK-NEXT:   12: e8 00 00 00 00                callq   0x17 <x4>
+# CHECK-NEXT:             0000000000000013:  R_X86_64_PLT32       foo-0x4
+# CHECK-EMPTY:
+# CHECK-NEXT:  0000000000000017 <x4>:
+# CHECK-NEXT:   17: 48 8b 05 00 00 00 00          movq    (%rip), %rax            # 0x1e <x4+0x7>
+# CHECK-NEXT:             000000000000001a:  R_X86_64_REX_GOTPCRELX       var-0x4
+# CHECK-NOT:   {{.}}
 
---- !ELF
-FileHeader:
-  Class:   ELFCLASS64
-  Data:    ELFDATA2LSB
-  Type:    ET_REL
-  Machine: EM_X86_64
-Sections:
-  - Name:    .text
-    Type:    SHT_PROGBITS
-    Flags:   [SHF_ALLOC, SHF_EXECINSTR]
-    Content: 'e800000000e800000000'
-  - Name:    .rela.text
-    Type:    SHT_RELA
-    Info:    .text
-    Relocations:
-      - Offset: 1
-        Symbol: foo
-        Type:   R_X86_64_PC32
-        Addend: -4
-      - Offset: 2
-        Symbol: bar
-        Type:   R_X86_64_NONE
-        Addend: 8
-      - Offset: 6
-        Symbol: foo
-        Type:   R_X86_64_PLT32
-        Addend: 1
-Symbols:
-  - Name: foo
-  - Name: bar
+## FIXME: --disassemble-symbols: remove inline relocs from skipped functions
+# CHECK2:      000000000000000a <x2>:
+# CHECK2-NEXT:   a: 90                            nop
+# CHECK2-NEXT:           0000000000000001:  R_X86_64_PC32        foo-0x4
+# CHECK2-NEXT:           0000000000000002:  R_X86_64_NONE        bar+0x8
+# CHECK2-NEXT:           0000000000000006:  R_X86_64_PLT32       foo+0x1
+# CHECK2-NEXT:   b: 48 8b 05 00 00 00 00          movq    (%rip), %rax            # 0x12 <x3>
+# CHECK2-NEXT:           000000000000000e:  R_X86_64_REX_GOTPCRELX       var-0x4
+# CHECK2-EMPTY:
+# CHECK2-NEXT: 0000000000000017 <x4>:
+# CHECK2-NEXT:  17: 48 8b 05 00 00 00 00          movq    (%rip), %rax            # 0x1e <x4+0x7>
+# CHECK2-NEXT:            0000000000000013:  R_X86_64_PLT32       foo-0x4
+# CHECK2-NEXT:            000000000000001a:  R_X86_64_REX_GOTPCRELX       var-0x4
+
+.globl x1, x2, x3, x4
+x1:
+  .reloc .+1, R_X86_64_PC32, foo-4
+  .reloc .+2, BFD_RELOC_NONE, bar+8
+  .byte 0xe8, 0, 0, 0, 0
+  .reloc .+1, R_X86_64_PLT32, foo+1
+  .byte 0xe8, 0, 0, 0, 0
+
+x2:
+  nop
+  movq var at GOTPCREL(%rip), %rax
+
+x3:
+  call foo
 
+x4:
+  movq var at GOTPCREL(%rip), %rax
+
+#--- 2.yaml
 ## Check we report an error if the relocated section identified by the
 ## sh_info field of a relocation section is invalid.
 
-# RUN: yaml2obj %s --docnum=2 -o %t2.o
-# RUN: not llvm-objdump %t2.o -d --reloc 2>&1 | FileCheck %s -DFILE=%t2.o --check-prefix=ERR
+# RUN: yaml2obj 2.yaml -o 2.o
+# RUN: not llvm-objdump 2.o -d --reloc 2>&1 | FileCheck %s --check-prefix=ERR
 
-# ERR: error: '[[FILE]]': section (1): failed to get a relocated section: invalid section index: 255
+# ERR: error: '2.o': section (1): failed to get a relocated section: invalid section index: 255
 
 --- !ELF
 FileHeader:
@@ -62,9 +82,10 @@ Sections:
   Info: 0xFF
   Relocations: []
 
+#--- 3.s
 ## Check ranges of addends being displayed in a dump of relocations mixed with disassembly.
-# RUN: yaml2obj --docnum=3 %s -o %t3
-# RUN: llvm-objdump -d -r %t3 | FileCheck %s --check-prefix=ADDENDS
+# RUN: llvm-mc -filetype=obj -triple=x86_64 3.s -o 3.o
+# RUN: llvm-objdump -d -r 3.o | FileCheck %s --check-prefix=ADDENDS
 
 # ADDENDS: Disassembly of section .text:
 # ADDENDS: R_X86_64_64 glob-0x8000000000000000
@@ -73,44 +94,9 @@ Sections:
 # ADDENDS: R_X86_64_64 glob+0x12345678
 # ADDENDS: R_X86_64_64 glob{{$}}
 
---- !ELF
-FileHeader:
-  Class:   ELFCLASS64
-  Data:    ELFDATA2LSB
-  Type:    ET_REL
-  Machine: EM_X86_64
-Sections:
-- Name:  .text
-  Type:  SHT_PROGBITS
-  Size:  8
-  Flags: [SHF_EXECINSTR,SHF_ALLOC]
-- Name: .rela.text
-  Type: SHT_RELA
-  Info: .text
-  Relocations:
-    - Offset: 0x0
-      Addend: -9223372036854775808
-      Symbol: glob
-      Type:   R_X86_64_64
-    - Offset: 0x1
-      Symbol: glob
-      Type:   R_X86_64_64
-      Addend: 9223372036854775807
-    - Offset: 0x2
-      Symbol: glob
-      Type:   R_X86_64_64
-      Addend: -1
-    - Offset: 0x3
-      Symbol: glob
-      Type:   R_X86_64_64
-      Addend: 0x12345678
-    - Offset: 0x4
-      Symbol: glob
-      Type:   R_X86_64_64
-      Addend: 0
-Symbols:
-  - Name:    glob
-    Section: .text
-    Value:   0x0
-    Size:    0
-    Binding: STB_GLOBAL
+.reloc ., BFD_RELOC_64, glob-0x8000000000000000
+.reloc .+1, BFD_RELOC_64, glob+0x7fffffffffffffff
+.reloc .+2, BFD_RELOC_64, glob-1
+.reloc .+3, BFD_RELOC_64, glob+0x12345678
+.reloc .+4, BFD_RELOC_64, glob
+.space 8


        


More information about the llvm-commits mailing list