File: elf-disassemble-relocs.test

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (102 lines) | stat: -rw-r--r-- 3,804 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
## 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

# RUN: llvm-mc -filetype=obj -triple=x86_64 -crel 1.s -o 1leb.o
# RUN: llvm-objdump 1leb.o -d -r | FileCheck %s --implicit-check-not="RELOCATION RECORDS"
# RUN: llvm-objdump 1leb.o -r --disassemble-symbols=x2,x4 | FileCheck %s --check-prefix=CHECK2

#--- 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:   {{.}}

# CHECK2:      000000000000000a <x2>:
# CHECK2-NEXT:   a: 90                            nop
# 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:            000000000000001a:  R_X86_64_REX_GOTPCRELX       var-0x4
# CHECK2-NOT:  {{.}}

.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