Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / MachO / start-lib.s
blob2da940c929490d7c503670f299af9faa6f98c740
1 # REQUIRES: x86
3 # RUN: rm -rf %t; split-file %s %t
4 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/main.s -o %t/main.o
5 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o
6 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/1.s -o %t/1.o
7 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/2.s -o %t/2.o
8 # RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o
10 # RUN: echo "%t/1.o" > %t/filelist
11 # RUN: echo "%t/2.o" >> %t/filelist
13 # RUN: llvm-as %t/1.ll -o %t/1.bc
14 # RUN: llvm-as %t/2.ll -o %t/2.bc
16 ## Neither 1.o nor 2.o is loaded.
17 # RUN: %lld %t/main.o -o %t/out --start-lib %t/1.o %t/2.o --end-lib -why_load | count 0
18 # RUN: %lld %t/main.o -o %t/out --start-lib -filelist %t/filelist --end-lib -why_load | count 0
19 # RUN: llvm-readobj -s %t/out | FileCheck %s
20 # CHECK-NOT: Name: _foo
21 # CHECK-NOT: Name: _bar
23 ## _bar loads 2.o. The last --end-lib can be omitted.
24 # RUN: %lld %t/main.o -o %t/out -u _bar --start-lib %t/1.o %t/2.o -t -why_load | FileCheck %s --check-prefix=CHECK2WHY
25 # RUN: %lld %t/main.o -o %t/out -u _bar --start-lib -filelist %t/filelist -t -why_load | FileCheck %s --check-prefix=CHECK2WHY
26 # RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK2 %s
27 # CHECK2WHY: {{.*}}main.o
28 # CHECK2WHY-NEXT: {{.*}}2.o
29 # CHECK2WHY-NEXT: _bar forced load of {{.*}}2.o
30 # CHECK2WHY-EMPTY:
31 # CHECK2-NOT: Name: _foo
32 # CHECK2: Name: _bar
33 # CHECK2-NOT: Name: _foo
35 ## _foo loads 1.o. 1.o loads 2.o.
36 # RUN: %lld %t/main.o -o %t/out -u _foo --start-lib %t/1.o %t/2.o -why_load | FileCheck %s --check-prefix=CHECK3WHY
37 # RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK3 %s
38 # RUN: %lld %t/main.o -o %t/out -u _foo --start-lib %t/2.o --end-lib --start-lib %t/1.o -why_load | FileCheck %s --check-prefix=CHECK3WHY
39 # RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=CHECK3 %s
40 # CHECK3WHY: _foo forced load of {{.*}}1.o
41 # CHECK3WHY-NEXT: _bar forced load of {{.*}}2.o
42 # CHECK3WHY-EMPTY:
43 # CHECK3-DAG: Name: _foo
44 # CHECK3-DAG: Name: _bar
46 ## Don't treat undefined _bar in 1.o as a lazy definition.
47 # RUN: not %lld %t/main.o -u _bar --start-lib %t/1.o 2>&1 | FileCheck %s --check-prefix=CHECK4
48 # CHECK4: error: undefined symbol: _bar
50 # RUN: %lld %t/main.o -o %t/out -u _common --start-lib %t/common.o
51 # RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=COMMON1
52 # COMMON1: Name: _common
54 # RUN: %lld %t/main.o -o %t/out --start-lib %t/common.o
55 # RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=COMMON2
56 # COMMON2-NOT: Name: _common
58 ## Neither 1.bc nor 2.bc is loaded.
59 # RUN: %lld %t/main.o -o %t/out --start-lib %t/1.bc %t/2.bc -why_load | count 0
60 # RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=BITCODE
61 # BITCODE-NOT: Name: _foo
62 # BITCODE-NOT: Name: _bar
64 ## _bar loads 2.bc.
65 # RUN: %lld %t/main.o -o %t/out -u _bar --start-lib %t/1.bc %t/2.bc -why_load | FileCheck %s --check-prefix=BITCODE2WHY
66 # RUN: llvm-readobj -s %t/out | FileCheck %s --check-prefix=BITCODE2
67 # BITCODE2WHY: _bar forced load of {{.*}}2.bc
68 # BITCODE2WHY-EMPTY:
69 # BITCODE2-NOT: Name: _foo
70 # BITCODE2: Name: _bar
71 # BITCODE2-NOT: Name: _foo
73 ## calls-foo.o loads 1.bc. 1.bc loads 2.bc.
74 # RUN: %lld %t/calls-foo.o -o %t/out --start-lib %t/1.bc %t/2.bc -why_load | FileCheck %s --check-prefix=BITCODE3WHY
75 # RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=BITCODE3 %s
76 # RUN: %lld %t/calls-foo.o -o %t/out --start-lib %t/2.bc --end-lib --start-lib %t/1.bc -why_load | FileCheck %s --check-prefix=BITCODE3WHY
77 # RUN: llvm-readobj -s %t/out | FileCheck --check-prefix=BITCODE3 %s
78 # BITCODE3WHY: _foo forced load of {{.*}}1.bc
79 # BITCODE3WHY-NEXT: _bar forced load of {{.*}}2.bc
80 # BITCODE3WHY-EMPTY:
81 # BITCODE3-DAG: Name: _foo
83 # RUN: not %lld %t/main.o --start-lib --start-lib 2>&1 | FileCheck -check-prefix=NESTED-LIB %s
84 # NESTED-LIB: error: nested --start-lib
86 # RUN: not %lld --end-lib 2>&1 | FileCheck %s --check-prefix=STRAY
87 # STRAY: error: stray --end-lib
89 #--- main.s
90 .globl _main
91 _main:
93 #--- calls-foo.s
94 .globl _main
95 _main:
96 call _foo
98 #--- 1.s
99 .globl _foo
100 _foo:
101 call _bar
103 #--- 2.s
104 .globl _bar
105 _bar:
108 #--- common.s
109 .comm _common, 1
111 #--- 1.ll
112 target triple = "x86_64-apple-macosx10.15.0"
113 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
115 define void @foo() {
116 tail call void () @bar()
117 ret void
120 declare void @bar()
122 #--- 2.ll
123 target triple = "x86_64-apple-macosx10.15.0"
124 target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
126 define void @bar() {
127 ret void