From 0ca95b269ff90afb706e2cf4c4a59d7c3afe6c65 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 16 Dec 2023 15:43:41 -0800 Subject: [PATCH] [llvm-objdump,test] Improve zero dumping and inline relocs tests --- .../X86/disassemble-zeroes-relocations.test | 121 +++++++----- .../llvm-objdump/X86/elf-disassemble-relocs.test | 218 ++++++++++----------- 2 files changed, 169 insertions(+), 170 deletions(-) rewrite llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test (73%) rewrite llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test (74%) diff --git a/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test b/llvm/test/tools/llvm-objdump/X86/disassemble-zeroes-relocations.test dissimilarity index 73% index c48e2d8c4f61..d61d7455570b 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 - -## Check we do not skip zeroes blocks if have relocations pointed to these places. -# RUN: llvm-objdump -D --reloc %t - -# CHECK: 0000000000000000 .rodata: -# CHECK-NEXT: 0: 00 00 addb %al, (%rax) -# CHECK-NEXT: 0000000000000000: R_X86_64_64 *ABS* -# 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 that without -reloc all zeroes would be omitted. -# RUN: llvm-objdump -D %t | FileCheck %s --check-prefix=SKIP - -# SKIP: 0000000000000000 <.rodata>: -# SKIP-NEXT: ... -# SKIP-EMPTY: -# SKIP-NEXT: Disassembly of section .rela.rodata: - ---- !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 +# 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 -j .rodata %t | FileCheck %s + +# CHECK: 0000000000000000 : +# CHECK-NEXT: 0: 00 00 addb %al, (%rax) +# 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 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 : +# CHECK-NEXT: ... +# CHECK-EMPTY: +# CHECK-NEXT: 0000000000000037 : +# 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: Disassembly of section .rodata: +# SKIP-EMPTY: +# SKIP-NEXT: 0000000000000000 : +# SKIP-NEXT: ... +# SKIP-NEXT: 1c: 00 00 addb %al, (%rax) +# SKIP-NEXT: 1e: 00 00 addb %al, (%rax) +# SKIP-EMPTY: +# SKIP-NEXT: 000000000000001f : +# SKIP-NEXT: ... +# SKIP-EMPTY: +# SKIP-NEXT: 0000000000000037 : +# 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 + +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 dissimilarity index 74% index 593735a6a102..33438cbfa126 100644 --- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test +++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs.test @@ -1,116 +1,102 @@ -## 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" - -# 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 - ---- !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 - -## 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 - -# ERR: error: '[[FILE]]': section (1): failed to get a relocated section: invalid section index: 255 - ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_X86_64 -Sections: -- Name: .rela.debug_info - Type: SHT_RELA - Link: 0 - Info: 0xFF - Relocations: [] - -## 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 - -# ADDENDS: Disassembly of section .text: -# ADDENDS: R_X86_64_64 glob-0x8000000000000000 -# ADDENDS: R_X86_64_64 glob+0x7fffffffffffffff -# ADDENDS: R_X86_64_64 glob-0x1 -# 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 +## Show that --disassemble + --reloc prints relocations inline and does not dump +## the relocation sections. + +# 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 + +#--- 1.s +# CHECK: 0000000000000000 : +# CHECK-NEXT: 0: e8 00 00 00 00 callq 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 +# CHECK-NEXT: 0000000000000006: R_X86_64_PLT32 foo+0x1 +# CHECK-EMPTY: +# CHECK-NEXT: 000000000000000a : +# CHECK-NEXT: a: 90 nop +# CHECK-NEXT: b: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x12 +# CHECK-NEXT: 000000000000000e: R_X86_64_REX_GOTPCRELX var-0x4 +# CHECK-EMPTY: +# CHECK-NEXT: 0000000000000012 : +# CHECK-NEXT: 12: e8 00 00 00 00 callq 0x17 +# CHECK-NEXT: 0000000000000013: R_X86_64_PLT32 foo-0x4 +# CHECK-EMPTY: +# CHECK-NEXT: 0000000000000017 : +# CHECK-NEXT: 17: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x1e +# CHECK-NEXT: 000000000000001a: R_X86_64_REX_GOTPCRELX var-0x4 +# CHECK-NOT: {{.}} + +## FIXME: --disassemble-symbols: remove inline relocs from skipped functions +# CHECK2: 000000000000000a : +# 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 +# CHECK2-NEXT: 000000000000000e: R_X86_64_REX_GOTPCRELX var-0x4 +# CHECK2-EMPTY: +# CHECK2-NEXT: 0000000000000017 : +# CHECK2-NEXT: 17: 48 8b 05 00 00 00 00 movq (%rip), %rax # 0x1e +# 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@GOTPCREL(%rip), %rax + +x3: + call foo + +x4: + movq var@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 2.yaml -o 2.o +# RUN: not llvm-objdump 2.o -d --reloc 2>&1 | FileCheck %s --check-prefix=ERR + +# ERR: error: '2.o': section (1): failed to get a relocated section: invalid section index: 255 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: +- Name: .rela.debug_info + Type: SHT_RELA + Link: 0 + Info: 0xFF + Relocations: [] + +#--- 3.s +## Check ranges of addends being displayed in a dump of relocations mixed with disassembly. +# 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 +# ADDENDS: R_X86_64_64 glob+0x7fffffffffffffff +# ADDENDS: R_X86_64_64 glob-0x1 +# ADDENDS: R_X86_64_64 glob+0x12345678 +# ADDENDS: R_X86_64_64 glob{{$}} + +.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 -- 2.11.4.GIT