File: x86-64-reloc-signed.s

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (88 lines) | stat: -rw-r--r-- 2,667 bytes parent folder | download | duplicates (21)
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
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: echo _t > %t.order
# RUN: %lld -o %t -order_file %t.order %t.o
# RUN: llvm-objdump --section-headers --syms -D %t | FileCheck %s

# CHECK-LABEL: Sections:
# CHECK:       __foo         {{[0-9a-f]+}}  [[#%x,FOO:]]  DATA

# CHECK-LABEL: SYMBOL TABLE:
# CHECK:       [[#%x,S:]]  g     O __DATA,__data _s

# CHECK-LABEL: Disassembly of section
# CHECK:      <_main>:
# CHECK-NEXT:   movl {{.*}}  ## imm =
# CHECK-NEXT:                ## 0x[[#S]]
# CHECK-NEXT:   callq {{.*}}
# CHECK-NEXT:   movl {{.*}}  ## 0x[[#S + 2]]
# CHECK-NEXT:   callq {{.*}}
# CHECK-NEXT:   movb {{.*}}  ## 0x[[#S]]
# CHECK-NEXT:   callq {{.*}}
# CHECK:      <__not_text>:
# CHECK-NEXT:   movl {{.*}}  ## imm =
# CHECK-NEXT:                ## 0x[[#FOO + 8]]
# CHECK-NEXT:   callq {{.*}}
# CHECK-NEXT:   movl {{.*}}  ## 0x[[#FOO + 8 + 2]]
# CHECK-NEXT:   callq {{.*}}
# CHECK-NEXT:   movb {{.*}}  ## 0x[[#FOO + 8]]
# CHECK-NEXT:   callq {{.*}}

.section __TEXT,__text
.globl _main
_main:
  ## Symbol relocations
  movl $0x434241, _s(%rip)  # X86_64_RELOC_SIGNED_4
  callq _f
  movl $0x44, _s+2(%rip)    # X86_64_RELOC_SIGNED_2
  callq _f
  movb $0x45, _s(%rip)      # X86_64_RELOC_SIGNED_1
  callq _f
  xorq %rax, %rax
  ret

_f:
  movl $0x2000004, %eax # write() syscall
  mov $1, %rdi # stdout
  leaq _s(%rip), %rsi
  mov $3, %rdx # length
  syscall
  ret

.section __TEXT,__not_text
  ## Section relocations. We intentionally put them in a separate section since
  ## the __text section typically starts at an address of zero in object files,
  ## and so does not fully exercise the relocation logic.
  movl $0x434241, L._s(%rip)  # X86_64_RELOC_SIGNED_4
  callq _f
  movl $0x44, L._s+2(%rip)    # X86_64_RELOC_SIGNED_2
  callq _f
  movb $0x45, L._s(%rip)      # X86_64_RELOC_SIGNED_1
  callq _f
  ret

.section __DATA,__data
.globl _s
_s:
  .space 5

## Create a new section to force the assembler to use a section relocation for
## the private symbol L._s. Otherwise, it will instead use a nearby non-private
## symbol to create a symbol relocation plus an addend.
.section __DATA,__foo
L._s:
  .space 1

## This symbol exists in order to split __foo into two subsections, thereby
## testing that our code matches the relocations with the right target
## subsection. In particular, although L._s+2 points to an address within _t's
## subsection, it's defined relative to L._s, and should therefore be associated
## with L._s' subsection.
##
## We furthermore use an order file to rearrange these subsections so that a
## mistake here will be obvious.
.globl _t
_t:
  .quad 123

.subsections_via_symbols