File: bind-opcodes.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 (186 lines) | stat: -rw-r--r-- 7,861 bytes parent folder | download | duplicates (14)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# REQUIRES: x86, aarch64
# RUN: rm -rf %t; split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin --defsym PTR64=0 %t/test.s -o %t/test.o
# RUN: %lld -O2 -dylib %t/foo.o -o %t/libfoo.dylib
# RUN: %lld -O2 -lSystem %t/test.o %t/libfoo.dylib -o %t/test-x86_64

## Test (64-bit):
## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
# RUN: obj2yaml %t/test-x86_64 | FileCheck %s

# CHECK:      BindOpcodes:
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   Symbol:          _foo
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_TYPE_IMM
# CHECK-NEXT:   Imm:             1
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
# CHECK-NEXT:   Imm:             2
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
# CHECK-NEXT:   Imm:             2
# CHECK-NEXT:   ULEBExtraData:   [ 0x0 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   ULEBExtraData:   [ 0x2, 0x8 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_ADDEND_SLEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   SLEBExtraData:   [ 1 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   ULEBExtraData:   [ 0x1008 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_ADDEND_SLEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   SLEBExtraData:   [ 0 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   Symbol:          _bar
# CHECK-NEXT:   Opcode:          BIND_OPCODE_SET_TYPE_IMM
# CHECK-NEXT:   Imm:             1
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_ADD_ADDR_ULEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   ULEBExtraData:   [ 0xFFFFFFFFFFFFEFD0 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
# CHECK-NEXT:   Imm:             1
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   ULEBExtraData:   [ 0x1008 ]
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DO_BIND
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   Symbol:          ''
# CHECK-NEXT:   Opcode:          BIND_OPCODE_DONE
# CHECK-NEXT:   Imm:             0
# CHECK-NEXT:   Symbol:          ''

# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %t/foo.s -o %t/foo.o
# RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin --defsym PTR32=0 %t/test.s -o %t/test.o
# RUN: %lld-watchos -O2 -dylib %t/foo.o -o %t/libfoo.dylib
# RUN: %lld-watchos -O2 -dylib %t/test.o %t/libfoo.dylib -o %t/libtest-arm64_32.dylib

## Test (32-bit):
## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
# RUN: obj2yaml %t/libtest-arm64_32.dylib | FileCheck %s --check-prefix=CHECK32

# CHECK32:      BindOpcodes:
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   Symbol:          _foo
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_TYPE_IMM
# CHECK32-NEXT:   Imm:             1
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
# CHECK32-NEXT:   Imm:             2
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
# CHECK32-NEXT:   Imm:             1
# CHECK32-NEXT:   ULEBExtraData:   [ 0x0 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   ULEBExtraData:   [ 0x2, 0x4 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_ADDEND_SLEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   SLEBExtraData:   [ 1 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   ULEBExtraData:   [ 0x1004 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_ADDEND_SLEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   SLEBExtraData:   [ 0 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   Symbol:          _bar
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_SET_TYPE_IMM
# CHECK32-NEXT:   Imm:             1
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_ADD_ADDR_ULEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   ULEBExtraData:   [ 0xFFFFFFFFFFFFEFE8 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
# CHECK32-NEXT:   Imm:             1
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   ULEBExtraData:   [ 0x1004 ]
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DO_BIND
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   Symbol:          ''
# CHECK32-NEXT:   Opcode:          BIND_OPCODE_DONE
# CHECK32-NEXT:   Imm:             0
# CHECK32-NEXT:   Symbol:          ''

# RUN: llvm-objdump --macho --bind %t/test-x86_64 | FileCheck %s -D#PTR=8 --check-prefix=BIND
# RUN: llvm-objdump --macho --bind %t/libtest-arm64_32.dylib | FileCheck %s -D#PTR=4 --check-prefix=BIND
# BIND:       Bind table:
# BIND-NEXT:  segment  section   address                               type       addend dylib     symbol
# BIND-NEXT:  __DATA   __data    0x[[#%X,DATA:]]                       pointer         0 libfoo    _foo
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + mul(PTR, 2)]]        pointer         0 libfoo    _foo
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + mul(PTR, 4)]]        pointer         1 libfoo    _foo
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + 4096 + mul(PTR, 6)]] pointer         0 libfoo    _foo
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + PTR]]                pointer         0 libfoo    _bar
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + mul(PTR, 3)]]        pointer         0 libfoo    _bar
# BIND-NEXT:  __DATA   __data    0x[[#%.8X,DATA + 4096 + mul(PTR, 5)]] pointer         0 libfoo    _bar
# BIND-EMPTY:

#--- foo.s
.globl _foo, _bar
_foo:
  .space 4
_bar:
  .space 4

#--- test.s
.ifdef PTR64
.macro ptr val
  .quad \val
.endm
.endif

.ifdef PTR32
.macro ptr val
  .int \val
.endm
.endif

.data
ptr _foo
ptr _bar
ptr _foo
ptr _bar
ptr _foo+1
.zero 0x1000
ptr _bar
ptr _foo

.globl _main
.text
_main: