Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / x86-64-reloc-signed.s
blob00643c838cde5f189d4c2d140f88f13af61a42a5
1 # REQUIRES: x86
2 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
3 # RUN: echo _t > %t.order
4 # RUN: %lld -o %t -order_file %t.order %t.o
5 # RUN: llvm-objdump --section-headers --syms -D %t | FileCheck %s
7 # CHECK-LABEL: Sections:
8 # CHECK: __foo {{[0-9a-f]+}} [[#%x,FOO:]] DATA
10 # CHECK-LABEL: SYMBOL TABLE:
11 # CHECK: [[#%x,S:]] g O __DATA,__data _s
13 # CHECK-LABEL: Disassembly of section
14 # CHECK: <_main>:
15 # CHECK-NEXT: movl {{.*}} ## imm =
16 # CHECK-NEXT: ## 0x[[#S]]
17 # CHECK-NEXT: callq {{.*}}
18 # CHECK-NEXT: movl {{.*}} ## 0x[[#S + 2]]
19 # CHECK-NEXT: callq {{.*}}
20 # CHECK-NEXT: movb {{.*}} ## 0x[[#S]]
21 # CHECK-NEXT: callq {{.*}}
22 # CHECK: <__not_text>:
23 # CHECK-NEXT: movl {{.*}} ## imm =
24 # CHECK-NEXT: ## 0x[[#FOO + 8]]
25 # CHECK-NEXT: callq {{.*}}
26 # CHECK-NEXT: movl {{.*}} ## 0x[[#FOO + 8 + 2]]
27 # CHECK-NEXT: callq {{.*}}
28 # CHECK-NEXT: movb {{.*}} ## 0x[[#FOO + 8]]
29 # CHECK-NEXT: callq {{.*}}
31 .section __TEXT,__text
32 .globl _main
33 _main:
34 ## Symbol relocations
35 movl $0x434241, _s(%rip) # X86_64_RELOC_SIGNED_4
36 callq _f
37 movl $0x44, _s+2(%rip) # X86_64_RELOC_SIGNED_2
38 callq _f
39 movb $0x45, _s(%rip) # X86_64_RELOC_SIGNED_1
40 callq _f
41 xorq %rax, %rax
42 ret
44 _f:
45 movl $0x2000004, %eax # write() syscall
46 mov $1, %rdi # stdout
47 leaq _s(%rip), %rsi
48 mov $3, %rdx # length
49 syscall
50 ret
52 .section __TEXT,__not_text
53 ## Section relocations. We intentionally put them in a separate section since
54 ## the __text section typically starts at an address of zero in object files,
55 ## and so does not fully exercise the relocation logic.
56 movl $0x434241, L._s(%rip) # X86_64_RELOC_SIGNED_4
57 callq _f
58 movl $0x44, L._s+2(%rip) # X86_64_RELOC_SIGNED_2
59 callq _f
60 movb $0x45, L._s(%rip) # X86_64_RELOC_SIGNED_1
61 callq _f
62 ret
64 .section __DATA,__data
65 .globl _s
66 _s:
67 .space 5
69 ## Create a new section to force the assembler to use a section relocation for
70 ## the private symbol L._s. Otherwise, it will instead use a nearby non-private
71 ## symbol to create a symbol relocation plus an addend.
72 .section __DATA,__foo
73 L._s:
74 .space 1
76 ## This symbol exists in order to split __foo into two subsections, thereby
77 ## testing that our code matches the relocations with the right target
78 ## subsection. In particular, although L._s+2 points to an address within _t's
79 ## subsection, it's defined relative to L._s, and should therefore be associated
80 ## with L._s' subsection.
82 ## We furthermore use an order file to rearrange these subsections so that a
83 ## mistake here will be obvious.
84 .globl _t
85 _t:
86 .quad 123
88 .subsections_via_symbols