Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / rename.s
blobe1d3fa04f75f3123f61ef03c1e0cb0d1238524cd
1 # REQUIRES: x86
3 # RUN: rm -rf %t; split-file %s %t
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t.o
6 # RUN: %lld -o %t.out %t.o
8 ## Check option format.
9 # RUN: not %lld \
10 # RUN: -rename_section B@GUS_SEG b@gus_sect S/ASHY_SEG st*rry_sect \
11 # RUN: -rename_section __FROM_SECT __from_sect __TO_SECT \
12 # RUN: -o /dev/null %t.o 2>&1 | FileCheck %s --check-prefix=BAD1
14 # BAD1-DAG: error: invalid name for segment or section: B@GUS_SEG
15 # BAD1-DAG: error: invalid name for segment or section: b@gus_sect
16 # BAD1-DAG: error: invalid name for segment or section: S/ASHY_SEG
17 # BAD1-DAG: error: invalid name for segment or section: st*rry_sect
18 # BAD1-DAG: error: invalid name for segment or section: -o
19 # BAD1-DAG: error: {{.*}}: unhandled file type
21 # RUN: not %lld \
22 # RUN: -rename_segment H#SHY_SEG PL+SSY_SEG \
23 # RUN: -rename_segment __FROM_SEG \
24 # RUN: -o /dev/null %t.o 2>&1 | FileCheck %s --check-prefix=BAD2
26 # BAD2-DAG: error: invalid name for segment or section: H#SHY_SEG
27 # BAD2-DAG: error: invalid name for segment or section: PL+SSY_SEG
28 # BAD2-DAG: error: invalid name for segment or section: -o
29 # BAD2-DAG: error: {{.*}}: unhandled file type
31 ## Check that section and segment renames happen.
32 # RUN: %lld -lSystem \
33 # RUN: -rename_section __FROM_SECT __from_sect __TO_SECT __to_sect \
34 # RUN: -rename_segment __FROM_SEG __TO_SEG \
35 # RUN: -rename_section __TEXT __cstring __RODATA __cstring \
36 # RUN: -o %t.out %t.o
37 # RUN: llvm-otool -l %t.out | FileCheck %s
39 # CHECK: {{^}}Section{{$}}
40 # CHECK-NEXT: sectname __text
41 # CHECK-NEXT: segname __TEXT
42 # CHECK: {{^}}Section{{$}}
43 # CHECK-NEXT: sectname __to_sect
44 # CHECK-NEXT: segname __TO_SECT
45 # CHECK: {{^}}Section{{$}}
46 # CHECK-NEXT: sectname __from_seg
47 # CHECK-NEXT: segname __TO_SEG
48 # CHECK: {{^}}Section{{$}}
49 # CHECK-NEXT: sectname __cstring
50 # CHECK-NEXT: segname __RODATA
52 ## Check interaction between -rename_section and -rename_segment.
53 ## rename_segment should be applied after rename_section, so the output
54 ## name of rename_section is renamed by rename_segment.
55 ## (ld64 leaves an empty __TO_SECT,__to_sect in the output for the intermediate
56 ## name, but it too writes the actual data to __SEG,__to_sect.)
57 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/small.s \
58 # RUN: -o %t/small.o
59 # RUN: %lld -dylib \
60 # RUN: -rename_section __FROM_SECT __from_sect __TO_SECT __to_sect \
61 # RUN: -rename_segment __TO_SECT __SEG \
62 # RUN: -o %t.dylib %t/small.o
63 # RUN: llvm-otool -l %t.dylib | FileCheck --check-prefix=SECTSEGYES %s
64 # RUN: %lld -dylib \
65 # RUN: -rename_segment __TO_SECT __SEG \
66 # RUN: -rename_section __FROM_SECT __from_sect __TO_SECT __to_sect \
67 # RUN: -o %t.dylib %t/small.o
68 # RUN: llvm-otool -l %t.dylib | FileCheck --check-prefix=SECTSEGYES %s
69 # SECTSEGYES: Section
70 # SECTSEGYES-NEXT: sectname __text
71 # SECTSEGYES-NEXT: segname __TEXT
72 # SECTSEGYES: Section
73 # SECTSEGYES-NEXT: sectname __to_sect
74 # SECTSEGYES-NEXT: segname __SEG
75 ## ...but rename_segment has no effect if it doesn't match the name after
76 ## rename_section is applied.
77 # RUN: %lld -dylib \
78 # RUN: -rename_section __FROM_SECT __from_sect __TO_SECT __to_sect \
79 # RUN: -rename_segment __FROM_SECT __SEG \
80 # RUN: -o %t.dylib %t/small.o
81 # RUN: llvm-otool -l %t.dylib | FileCheck --check-prefix=SECTSEGSOME %s
82 # SECTSEGSOME: Section
83 # SECTSEGSOME-NEXT: sectname __text
84 # SECTSEGSOME-NEXT: segname __TEXT
85 # SECTSEGSOME: Section
86 # SECTSEGSOME-NEXT: sectname __to_sect
87 # SECTSEGSOME-NEXT: segname __TO_SECT
88 ## If rename_section would only match after rename_segment, rename_section has
89 ## no effect.
90 # RUN: %lld -dylib \
91 # RUN: -rename_section __SEG __from_sect __TO_SECT __to_sect \
92 # RUN: -rename_segment __FROM_SECT __SEG \
93 # RUN: -o %t.dylib %t/small.o
94 # RUN: llvm-otool -l %t.dylib | FileCheck --check-prefix=SECTSEGNO %s
95 # RUN: %lld -dylib \
96 # RUN: -rename_segment __FROM_SECT __SEG \
97 # RUN: -rename_section __SEG __from_sect __TO_SECT __to_sect \
98 # RUN: -o %t.dylib %t/small.o
99 # RUN: llvm-otool -l %t.dylib | FileCheck --check-prefix=SECTSEGNO %s
100 # SECTSEGNO: Section
101 # SECTSEGNO-NEXT: sectname __text
102 # SECTSEGNO-NEXT: segname __TEXT
103 # SECTSEGNO: Section
104 # SECTSEGNO-NEXT: sectname __from_sect
105 # SECTSEGNO-NEXT: segname __SEG
107 #--- main.s
108 .section __FROM_SECT,__from_sect
109 .global _from_sect
110 _from_sect:
111 .space 8
113 .section __FROM_SEG,__from_seg
114 .global _from_seg
115 _from_seg:
116 .space 8
118 ## This is a synthetic section; make sure it gets renamed too.
119 .cstring
120 .space 8
122 .text
123 .global _main
124 _main:
127 #--- small.s
128 .section __FROM_SECT,__from_sect
129 .global _from_sect
130 _from_sect:
131 .space 8