1 # REQUIRES: x86, aarch64
2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/foo.s -o %t/foo.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin --defsym PTR64=0 %t/test.s -o %t/test.o
5 # RUN: %lld -O2 -dylib %t/foo.o -o %t/libfoo.dylib
6 # RUN: %lld -O2 -lSystem %t/test.o %t/libfoo.dylib -o %t/test-x86_64
9 ## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
10 ## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
11 ## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
12 ## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
13 # RUN: obj2yaml %t/test-x86_64 | FileCheck %s
16 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
18 # CHECK-NEXT: Symbol: _foo
19 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
21 # CHECK-NEXT: Symbol: ''
22 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
24 # CHECK-NEXT: Symbol: ''
25 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
27 # CHECK-NEXT: ULEBExtraData: [ 0x0 ]
28 # CHECK-NEXT: Symbol: ''
29 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
31 # CHECK-NEXT: ULEBExtraData: [ 0x2, 0x8 ]
32 # CHECK-NEXT: Symbol: ''
33 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
35 # CHECK-NEXT: SLEBExtraData: [ 1 ]
36 # CHECK-NEXT: Symbol: ''
37 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
39 # CHECK-NEXT: ULEBExtraData: [ 0x1008 ]
40 # CHECK-NEXT: Symbol: ''
41 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
43 # CHECK-NEXT: SLEBExtraData: [ 0 ]
44 # CHECK-NEXT: Symbol: ''
45 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND
47 # CHECK-NEXT: Symbol: ''
48 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
50 # CHECK-NEXT: Symbol: _bar
51 # CHECK-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
53 # CHECK-NEXT: Symbol: ''
54 # CHECK-NEXT: Opcode: BIND_OPCODE_ADD_ADDR_ULEB
56 # CHECK-NEXT: ULEBExtraData: [ 0xFFFFFFFFFFFFEFD0 ]
57 # CHECK-NEXT: Symbol: ''
58 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
60 # CHECK-NEXT: Symbol: ''
61 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
63 # CHECK-NEXT: ULEBExtraData: [ 0x1008 ]
64 # CHECK-NEXT: Symbol: ''
65 # CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND
67 # CHECK-NEXT: Symbol: ''
68 # CHECK-NEXT: Opcode: BIND_OPCODE_DONE
70 # CHECK-NEXT: Symbol: ''
72 # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin %t/foo.s -o %t/foo.o
73 # RUN: llvm-mc -filetype=obj -triple=arm64_32-apple-darwin --defsym PTR32=0 %t/test.s -o %t/test.o
74 # RUN: %lld-watchos -O2 -dylib %t/foo.o -o %t/libfoo.dylib
75 # RUN: %lld-watchos -O2 -dylib %t/test.o %t/libfoo.dylib -o %t/libtest-arm64_32.dylib
78 ## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
79 ## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
80 ## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
81 ## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
82 # RUN: obj2yaml %t/libtest-arm64_32.dylib | FileCheck %s --check-prefix=CHECK32
84 # CHECK32: BindOpcodes:
85 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
86 # CHECK32-NEXT: Imm: 0
87 # CHECK32-NEXT: Symbol: _foo
88 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
89 # CHECK32-NEXT: Imm: 1
90 # CHECK32-NEXT: Symbol: ''
91 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_DYLIB_ORDINAL_IMM
92 # CHECK32-NEXT: Imm: 2
93 # CHECK32-NEXT: Symbol: ''
94 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
95 # CHECK32-NEXT: Imm: 1
96 # CHECK32-NEXT: ULEBExtraData: [ 0x0 ]
97 # CHECK32-NEXT: Symbol: ''
98 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB
99 # CHECK32-NEXT: Imm: 0
100 # CHECK32-NEXT: ULEBExtraData: [ 0x2, 0x4 ]
101 # CHECK32-NEXT: Symbol: ''
102 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
103 # CHECK32-NEXT: Imm: 0
104 # CHECK32-NEXT: SLEBExtraData: [ 1 ]
105 # CHECK32-NEXT: Symbol: ''
106 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
107 # CHECK32-NEXT: Imm: 0
108 # CHECK32-NEXT: ULEBExtraData: [ 0x1004 ]
109 # CHECK32-NEXT: Symbol: ''
110 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_ADDEND_SLEB
111 # CHECK32-NEXT: Imm: 0
112 # CHECK32-NEXT: SLEBExtraData: [ 0 ]
113 # CHECK32-NEXT: Symbol: ''
114 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND
115 # CHECK32-NEXT: Imm: 0
116 # CHECK32-NEXT: Symbol: ''
117 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM
118 # CHECK32-NEXT: Imm: 0
119 # CHECK32-NEXT: Symbol: _bar
120 # CHECK32-NEXT: Opcode: BIND_OPCODE_SET_TYPE_IMM
121 # CHECK32-NEXT: Imm: 1
122 # CHECK32-NEXT: Symbol: ''
123 # CHECK32-NEXT: Opcode: BIND_OPCODE_ADD_ADDR_ULEB
124 # CHECK32-NEXT: Imm: 0
125 # CHECK32-NEXT: ULEBExtraData: [ 0xFFFFFFFFFFFFEFE8 ]
126 # CHECK32-NEXT: Symbol: ''
127 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
128 # CHECK32-NEXT: Imm: 1
129 # CHECK32-NEXT: Symbol: ''
130 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
131 # CHECK32-NEXT: Imm: 0
132 # CHECK32-NEXT: ULEBExtraData: [ 0x1004 ]
133 # CHECK32-NEXT: Symbol: ''
134 # CHECK32-NEXT: Opcode: BIND_OPCODE_DO_BIND
135 # CHECK32-NEXT: Imm: 0
136 # CHECK32-NEXT: Symbol: ''
137 # CHECK32-NEXT: Opcode: BIND_OPCODE_DONE
138 # CHECK32-NEXT: Imm: 0
139 # CHECK32-NEXT: Symbol: ''
141 # RUN: llvm-objdump --macho --bind %t/test-x86_64 | FileCheck %s -D#PTR=8 --check-prefix=BIND
142 # RUN: llvm-objdump --macho --bind %t/libtest-arm64_32.dylib | FileCheck %s -D#PTR=4 --check-prefix=BIND
144 # BIND-NEXT: segment section address type addend dylib symbol
145 # BIND-NEXT: __DATA __data 0x[[#%X,DATA:]] pointer 0 libfoo _foo
146 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 2)]] pointer 0 libfoo _foo
147 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 4)]] pointer 1 libfoo _foo
148 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + 4096 + mul(PTR, 6)]] pointer 0 libfoo _foo
149 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + PTR]] pointer 0 libfoo _bar
150 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + mul(PTR, 3)]] pointer 0 libfoo _bar
151 # BIND-NEXT: __DATA __data 0x[[#%.8X,DATA + 4096 + mul(PTR, 5)]] pointer 0 libfoo _bar