Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / icf-literals.s
blob815ca472a7e3f094df535d31a7c46024fd60cf05
1 # REQUIRES: x86
2 # RUN: rm -rf %t; mkdir %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
4 # RUN: %lld -lSystem --icf=all -o %t/test %t/test.o
5 # RUN: llvm-objdump --macho --syms -d %t/test | FileCheck %s
7 # CHECK: _main:
8 # CHECK-NEXT: callq _foo2_ref
9 # CHECK-NEXT: callq _foo2_ref
10 # CHECK-NEXT: callq _foo2_neg_offset_ref
11 # CHECK-NEXT: callq _foo2_neg_offset_ref
12 # CHECK-NEXT: callq _foo2_pos_offset_ref
13 # CHECK-NEXT: callq _foo2_pos_offset_ref
14 # CHECK-NEXT: callq _bar2_ref
15 # CHECK-NEXT: callq _bar2_ref
16 # CHECK-NEXT: callq _baz2_ref
17 # CHECK-NEXT: callq _baz2_ref
18 # CHECK-NEXT: callq _qux2_ref
19 # CHECK-NEXT: callq _qux2_ref
20 # CHECK-NEXT: callq _sub_str_a_b
21 # CHECK-NEXT: callq _sub_str_b_a
22 # CHECK-NEXT: callq _sub_lit_a_b
23 # CHECK-NEXT: callq _sub_lit_b_a
25 # CHECK: [[#%.16x,FOO:]] l O __TEXT,__cstring _foo1
26 # CHECK-NEXT: [[#%.16x,FOO:]] l O __TEXT,__cstring _foo2
27 # CHECK-NEXT: [[#%.16x,BAR:]] l O __TEXT,__cstring _bar1
28 # CHECK-NEXT: [[#%.16x,BAR:]] l O __TEXT,__cstring _bar2
29 # CHECK-NEXT: [[#%.16x,BAZ:]] l O __TEXT,__literals _baz1
30 # CHECK-NEXT: [[#%.16x,BAZ:]] l O __TEXT,__literals _baz2
31 # CHECK-NEXT: [[#%.16x,QUX:]] l O __TEXT,__literals _qux1
32 # CHECK-NEXT: [[#%.16x,QUX:]] l O __TEXT,__literals _qux2
33 # CHECK-NEXT: [[#%.16x,FOO_REF:]] l F __TEXT,__text _foo1_ref
34 # CHECK-NEXT: [[#%.16x,FOO_REF:]] l F __TEXT,__text _foo2_ref
35 # CHECK-NEXT: [[#%.16x,FOO_NEG:]] l F __TEXT,__text _foo1_neg_offset_ref
36 # CHECK-NEXT: [[#%.16x,FOO_NEG]] l F __TEXT,__text _foo2_neg_offset_ref
37 # CHECK-NEXT: [[#%.16x,FOO_POS:]] l F __TEXT,__text _foo1_pos_offset_ref
38 # CHECK-NEXT: [[#%.16x,FOO_POS]] l F __TEXT,__text _foo2_pos_offset_ref
39 # CHECK-NEXT: [[#%.16x,BAR_REF:]] l F __TEXT,__text _bar1_ref
40 # CHECK-NEXT: [[#%.16x,BAR_REF:]] l F __TEXT,__text _bar2_ref
41 # CHECK-NEXT: [[#%.16x,BAZ_REF:]] l F __TEXT,__text _baz1_ref
42 # CHECK-NEXT: [[#%.16x,BAZ_REF:]] l F __TEXT,__text _baz2_ref
43 # CHECK-NEXT: [[#%.16x,QUX_REF:]] l F __TEXT,__text _qux1_ref
44 # CHECK-NEXT: [[#%.16x,QUX_REF:]] l F __TEXT,__text _qux2_ref
46 ## _foo1 vs _bar1: same section, different offsets
47 ## _foo1 vs _baz1: same offset, different sections
49 .cstring
50 _foo1:
51 .asciz "foo"
52 _foo2:
53 .asciz "foo"
54 _bar1:
55 .asciz "bar"
56 _bar2:
57 .asciz "bar"
59 .literal8
60 _baz1:
61 .quad 0xdead
62 _baz2:
63 .quad 0xdead
64 _qux1:
65 .quad 0xbeef
66 _qux2:
67 .quad 0xbeef
69 .text
70 _foo1_ref:
71 leaq _foo1(%rip), %rax
72 _foo2_ref:
73 leaq _foo2(%rip), %rax
74 _foo1_neg_offset_ref:
75 ## Check that we can correctly handle `_foo1-32` even though it points outside
76 ## the __cstring section.
77 leaq _foo1-32(%rip), %rax
78 _foo2_neg_offset_ref:
79 leaq _foo2-32(%rip), %rax
80 _foo1_pos_offset_ref:
81 leaq _foo1+4(%rip), %rax
82 _foo2_pos_offset_ref:
83 ## Although `_foo2+4` points at _bar1 in the input object file, we shouldn't
84 ## dedup references to _foo2+4 with references to _bar1.
85 leaq _foo2+4(%rip), %rax
86 _bar1_ref:
87 leaq _bar1(%rip), %rax
88 _bar2_ref:
89 leaq _bar2(%rip), %rax
90 _baz1_ref:
91 movq _baz1(%rip), %rax
92 _baz2_ref:
93 movq _baz2(%rip), %rax
94 _qux1_ref:
95 movq _qux1(%rip), %rax
96 _qux2_ref:
97 movq _qux2(%rip), %rax
99 ## _sub_str_a_b and _sub_str_b_a should not be folded: They contain relocations
100 ## against the same string symbols, but in a different order and hence
101 ## return different numbers.
102 _sub_str_a_b:
103 leaq _foo2(%rip), %rdx
104 leaq _bar2(%rip), %rax
105 subq %rdx, %rax
106 _sub_str_b_a:
107 leaq _bar2(%rip), %rdx
108 leaq _foo2(%rip), %rax
109 subq %rdx, %rax
111 ## Same with literals instead of strings.
112 _sub_lit_a_b:
113 movq _baz2(%rip), %rax
114 subq _qux2(%rip), %rax
115 _sub_lit_b_a:
116 movq _qux2(%rip), %rax
117 subq _baz2(%rip), %rax
120 .globl _main
121 _main:
122 callq _foo1_ref
123 callq _foo2_ref
124 callq _foo1_neg_offset_ref
125 callq _foo2_neg_offset_ref
126 callq _foo1_pos_offset_ref
127 callq _foo2_pos_offset_ref
128 callq _bar1_ref
129 callq _bar2_ref
130 callq _baz1_ref
131 callq _baz2_ref
132 callq _qux1_ref
133 callq _qux2_ref
134 callq _sub_str_a_b
135 callq _sub_str_b_a
136 callq _sub_lit_a_b
137 callq _sub_lit_b_a
139 .subsections_via_symbols