Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / cstring-align.s
blob235b44c1c2e5f2909f51240bcf77de8f88d2bddc
1 # REQUIRES: x86
2 # RUN: rm -rf %t; split-file %s %t
3 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-empty.s -o %t/align-empty.o
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-4-0.s -o %t/align-4-0.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-4-2.s -o %t/align-4-2.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-16-0.s -o %t/align-16-0.o
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-16-2.s -o %t/align-16-2.o
8 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-16-4.s -o %t/align-16-4.o
9 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/align-16-8.s -o %t/align-16-8.o
11 ## Check that we preserve the alignment of cstrings. Alignment is determined
12 ## not by section alignment but by the number of trailing zeros of the cstring's
13 ## address in the input object file.
15 ## The non-dedup case is not particularly interesting since the null bytes don't
16 ## get dedup'ed, meaning that the output strings get their offsets "naturally"
17 ## preserved.
19 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-4-0.o %t/align-16-0.o -o %t/align-4-0-16-0
20 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-4-0-16-0 | \
21 # RUN: FileCheck %s -D#OFF1=4 -D#OFF2=16
22 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-16-0.o %t/align-4-0.o -o %t/align-16-0-4-0
23 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-16-0-4-0 | \
24 # RUN: FileCheck %s -D#OFF1=16 -D#OFF2=20
26 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-4-2.o %t/align-16-0.o -o %t/align-4-2-16-0
27 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-4-2-16-0 | \
28 # RUN: FileCheck %s -D#OFF1=6 -D#OFF2=16
29 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-16-0.o %t/align-4-2.o -o %t/align-16-0-4-2
30 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-16-0-4-2 | \
31 # RUN: FileCheck %s -D#OFF1=16 -D#OFF2=22
33 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-4-0.o %t/align-16-2.o -o %t/align-4-0-16-2
34 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-4-0-16-2 | \
35 # RUN: FileCheck %s -D#OFF1=4 -D#OFF2=18
36 # RUN: %lld -dylib --no-deduplicate-strings %t/align-empty.o %t/align-16-2.o %t/align-4-0.o -o %t/align-16-2-4-0
37 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/align-16-2-4-0 | \
38 # RUN: FileCheck %s -D#OFF1=18 -D#OFF2=20
40 # CHECK: Contents of (__TEXT,__cstring) section
41 # CHECK-NEXT: [[#%.16x,START:]] {{$}}
42 # CHECK: [[#%.16x,START+OFF1]] a{{$}}
43 # CHECK: [[#%.16x,START+OFF2]] a{{$}}
44 # CHECK-EMPTY:
46 ## The dedup cases are more interesting...
48 ## Same offset, different alignments => pick higher alignment
49 # RUN: %lld -dylib %t/align-empty.o %t/align-4-0.o %t/align-16-0.o -o %t/dedup-4-0-16-0
50 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-4-0-16-0 | \
51 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=16
52 # RUN: %lld -dylib %t/align-empty.o %t/align-16-0.o %t/align-4-0.o -o %t/dedup-16-0-4-0
53 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-16-0-4-0 | \
54 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=16
56 ## 16 byte alignment vs 2 byte offset => align to 16 bytes
57 # RUN: %lld -dylib %t/align-empty.o %t/align-4-2.o %t/align-16-0.o -o %t/dedup-4-2-16-0
58 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-4-2-16-0 | \
59 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=16
60 # RUN: %lld -dylib %t/align-empty.o %t/align-16-0.o %t/align-4-2.o -o %t/dedup-16-0-4-2
61 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-16-0-4-2 | \
62 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=16
64 ## 4 byte alignment vs 2 byte offset => align to 4 bytes
65 # RUN: %lld -dylib %t/align-empty.o %t/align-4-0.o %t/align-16-2.o -o %t/dedup-4-0-16-2
66 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-4-0-16-2 | \
67 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=4
68 # RUN: %lld -dylib %t/align-empty.o %t/align-16-2.o %t/align-4-0.o -o %t/dedup-16-2-4-0
69 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-16-2-4-0 | \
70 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=4
72 ## Both inputs are 4-byte aligned, one via offset and the other via section alignment
73 # RUN: %lld -dylib %t/align-empty.o %t/align-4-0.o %t/align-16-4.o -o %t/dedup-4-0-16-4
74 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-4-0-16-4 | \
75 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=4
76 # RUN: %lld -dylib %t/align-empty.o %t/align-16-4.o %t/align-4-0.o -o %t/dedup-16-4-4-0
77 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-16-4-4-0 | \
78 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=4
80 ## 8-byte offset vs 4-byte section alignment => align to 8 bytes
81 # RUN: %lld -dylib %t/align-empty.o %t/align-4-0.o %t/align-16-8.o -o %t/dedup-4-0-16-8
82 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-4-0-16-8 | \
83 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=8
84 # RUN: %lld -dylib %t/align-empty.o %t/align-16-8.o %t/align-4-0.o -o %t/dedup-16-8-4-0
85 # RUN: llvm-objdump --macho --section="__TEXT,__cstring" %t/dedup-16-8-4-0 | \
86 # RUN: FileCheck %s --check-prefix=DEDUP -D#OFF=8
88 # DEDUP: Contents of (__TEXT,__cstring) section
89 # DEDUP-NEXT: [[#%.16x,START:]] {{$}}
90 # DEDUP: [[#%.16x,START+OFF]] a{{$}}
91 # DEDUP-EMPTY:
93 #--- align-empty.s
94 ## We use this file to create an empty string at the start of every output
95 ## file's .cstring section. This makes the test cases more interesting since LLD
96 ## can't place the string "a" at the trivially-aligned zero offset.
97 .cstring
98 .p2align 2
99 .asciz ""
101 #--- align-4-0.s
102 .cstring
103 .p2align 2
104 .asciz "a"
106 #--- align-4-2.s
107 .cstring
108 .p2align 2
109 .zero 0x2
110 .asciz "a"
112 #--- align-16-0.s
113 .cstring
114 .p2align 4
115 .asciz "a"
117 #--- align-16-2.s
118 .cstring
119 .p2align 4
120 .zero 0x2
121 .asciz "a"
123 #--- align-16-4.s
124 .cstring
125 .p2align 4
126 .zero 0x4
127 .asciz "a"
129 #--- align-16-8.s
130 .cstring
131 .p2align 4
132 .zero 0x8
133 .asciz "a"