Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / rebase-opcodes.s
blob073c39a613acd70afaf2abc9f1bbf913c7e6844a
1 # REQUIRES: x86
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
4 # RUN: %lld -dylib %t.o -o %t.dylib
5 # RUN: obj2yaml %t.dylib | FileCheck %s
7 .text
8 .globl _foo
9 _foo:
11 .data
12 # CHECK: RebaseOpcodes:
13 # CHECK-NEXT: Opcode: REBASE_OPCODE_SET_TYPE_IMM
14 # CHECK-NEXT: Imm: 1
15 # CHECK-NEXT: Opcode: REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB
16 # CHECK-NEXT: Imm: 1
17 # CHECK-NEXT: ExtraData: [ 0x0 ]
19 ## 1/ Single rebases with a gap after them are encoded as REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB.
20 .quad _foo
21 .space 16
22 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
23 # CHECK-NEXT: Imm: 0
24 # CHECK-NEXT: ExtraData: [ 0x10 ]
26 ## 2/ Consecutive rebases are encoded as REBASE_OPCODE_DO_REBASE_IMM_TIMES.
27 .quad _foo
28 .quad _foo
29 .quad _foo
30 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
31 # CHECK-NEXT: Imm: 3
33 ## 3/ Gaps smaller than 16 words are encoded as REBASE_OPCODE_ADD_ADDR_IMM_SCALED.
34 .space 120
35 # CHECK-NEXT: Opcode: REBASE_OPCODE_ADD_ADDR_IMM_SCALED
36 # CHECK-NEXT: Imm: 15
38 ## 4/ Rebases with equal gaps betwen them are encoded as REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB.
39 .quad _foo
40 .space 16
41 .quad _foo
42 .space 16
43 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
44 # CHECK-NEXT: Imm: 0
45 # CHECK-NEXT: ExtraData: [ 0x2, 0x10 ]
47 ## 5/ Rebase does not become a part of DO_REBASE_ULEB_TIMES_SKIPPING_ULEB if the next rebase is closer than the gap.
48 .quad _foo
49 .space 8
50 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB
51 # CHECK-NEXT: Imm: 0
52 # CHECK-NEXT: ExtraData: [ 0x8 ]
54 .quad _foo
55 .quad _foo
56 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
57 # CHECK-NEXT: Imm: 2
59 ## 6/ Large gaps are encoded as REBASE_OPCODE_ADD_ADDR_ULEB.
60 .space 128
61 # CHECK-NEXT: Opcode: REBASE_OPCODE_ADD_ADDR_ULEB
62 # CHECK-NEXT: Imm: 0
63 # CHECK-NEXT: ExtraData: [ 0x80 ]
65 .quad _foo
66 .space 8
67 .quad _foo
68 .space 8
69 .quad _foo
70 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB
71 # CHECK-NEXT: Imm: 0
72 # CHECK-NEXT: ExtraData: [ 0x3, 0x8 ]
75 ## 7/ An add opcode is emitted if the next relocation is farther away than the DO_REBASE_ULEB_TIMES_SKIPPING_ULEB gap.
76 .space 16
77 .quad _foo
78 # CHECK-NEXT: Opcode: REBASE_OPCODE_ADD_ADDR_IMM_SCALED
79 # CHECK-NEXT: Imm: 1
80 # CHECK-NEXT: Opcode: REBASE_OPCODE_DO_REBASE_IMM_TIMES
81 # CHECK-NEXT: Imm: 1
83 ## 8/ The rebase section is terminated by REBASE_OPCODE_DONE.
84 # CHECK-NEXT: Opcode: REBASE_OPCODE_DONE
85 # CHECK-NEXT: Imm: 0