2 # Copyright (c) 2006-2008 Apple Inc. All rights reserved.
4 # @APPLE_LICENSE_HEADER_START@
6 # This file contains Original Code and/or Modifications of Original Code
7 # as defined in and that are subject to the Apple Public Source License
8 # Version 2.0 (the 'License'). You may not use this file except in
9 # compliance with the License. Please obtain a copy of the License at
10 # http://www.opensource.apple.com/apsl/ and read it before using this
13 # The Original Code and all software distributed under the License are
14 # distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 # EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 # INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 # Please see the License for the specific language governing rights and
19 # limitations under the License.
21 # @APPLE_LICENSE_HEADER_END@
25 include ${TESTROOT}/include/common.makefile
27 SHELL = bash # use bash shell so we can redirect just stderr
30 LLVMAR = /usr/local/bin/llvm-ar
33 # Test the we set the stack execution bit properly.
36 all: zero one two three four five six seven eight nine ten \
37 eleven twelve thirteen fourteen fifteen sixteen seventeen \
44 # MachO : main.c : Ufoo2, Ufoo3
47 ${CC} ${CCFLAGS} -flto a.c -c -o a.o
48 ${CC} ${CCFLAGS} -flto b.c -c -o b.o
49 ${CC} ${CCFLAGS} main.c -c -o main.o
50 ${CC} ${CCFLAGS} a.o b.o main.o -o main.exe
51 ${PASS_IFF_GOOD_MACHO} main.exe
55 # llvm : a1.c : Dfoo3, Ufoo4
56 # llvm : b1.c : Dfoo2, Ufoo4
57 # MachO : main1.c : Dfoo4, Ufoo2, Ufoo3
60 ${CC} ${CCFLAGS} -flto a1.c -c -o a1.o
61 ${CC} ${CCFLAGS} -flto b1.c -c -o b1.o
62 ${CC} ${CCFLAGS} main1.c -c -o main1.o
63 ${CC} ${CCFLAGS} a1.o b1.o main1.o -o main1.exe
64 ${PASS_IFF_GOOD_MACHO} main1.exe
68 # llvm : a2.c : Dfoo3, Ufoo4
69 # llvm : b2.c : Dfoo2, Dfoo4
70 # MachO : main2.c : Ufoo2, Ufoo3
73 ${CC} ${CCFLAGS} -flto a2.c -c -o a2.o
74 ${CC} ${CCFLAGS} -flto b2.c -c -o b2.o
75 ${CC} ${CCFLAGS} main2.c -c -o main2.o
76 ${CC} ${CCFLAGS} a2.o b2.o main2.o -o main2.exe
77 ${PASS_IFF_GOOD_MACHO} main2.exe
81 # llvm : a3.c : Dfoo1, Dbar
82 # llvm : b3.c : Dfoo2, Ubar
83 # MachO : main3.c : Ufoo1, Ufoo2, Ubar
86 ${CC} ${CCFLAGS} -flto a3.c -c -o a3.o
87 ${CC} ${CCFLAGS} -flto b3.c -c -o b3.o
88 ${CC} ${CCFLAGS} main3.c -c -o main3.o
89 ${CC} ${CCFLAGS} a3.o b3.o main3.o -o main3.exe
90 ${PASS_IFF_GOOD_MACHO} main3.exe
94 # llvm : a4.c : Dfoo3, Ufoo4
95 # llvm : b4.c : Dfoo2, DLmyfoo, Ufoo4
96 # MachO : main4.c : Dfoo4, Ufoo2, Ufoo3
99 ${CC} ${CCFLAGS} -flto a4.c -c -o a4.o
100 ${CC} ${CCFLAGS} -flto b4.c -c -o b4.o
101 ${CC} ${CCFLAGS} main4.c -c -o main4.o
102 ${CC} ${CCFLAGS} a4.o b4.o main4.o -o main4.exe
103 ${PASS_IFF_GOOD_MACHO} main4.exe
107 # llvm : a5.c : Dfoo1, Ufoo2, Ufoo3
108 # llvm : b5.c : Dfoo2
109 # MachO : main5.c : Dfoo3, Ufoo1
111 #echo "verify that if call to mach-o is optimized away, mach-o func is dead stripped"
112 ${CC} ${CCFLAGS} -flto a5.c -c -o a5.o
113 ${CC} ${CCFLAGS} -flto b5.c -c -o b5.o
114 ${CC} ${CCFLAGS} main5.c -c -o main5.o
115 ${CC} ${CCFLAGS} a5.o b5.o main5.o -o main5.exe -Wl,-dead_strip
116 ${OTOOL} -tV main5.exe | grep foo3 | ${PASS_IFF_EMPTY}
117 ${PASS_IFF_GOOD_MACHO} main5.exe
121 # llvm : a6.c : Dfoo1, Dfoo2
122 # MachO : main6.c : Ufoo1
124 #echo "verify dead stripping of foo2 in main executable"
125 ${CC} ${CCFLAGS} -flto a6.c -c -o a6.o
126 ${CC} ${CCFLAGS} main6.c -c -o main6.o
127 ${CC} ${CCFLAGS} a6.o main6.o -o main6.exe -Wl,-dead_strip
128 ${PASS_IFF_GOOD_MACHO} main6.exe
129 ${OTOOL} -tV main6.exe | grep foo2 | ${PASS_IFF_EMPTY}
133 # llvm : a7.c : Dfoo1, Dfoo2, Ufoo3
134 # llvm : b7.c : Dfoo3, ufoo2
135 # MachO : main7.c : Ufoo1
138 ${CC} ${CCFLAGS} -flto a7.c -c -o a7.o
139 ${CC} ${CCFLAGS} -flto b7.c -c -o b7.o
140 ${CC} ${CCFLAGS} main7.c -c -o main7.o
141 ${CC} ${CCFLAGS} a7.o b7.o main7.o -o main7.exe
142 ${PASS_IFF_GOOD_MACHO} main7.exe
146 # llvm : a8.c : Dfoo1, Dfoo2
147 # MachO : main8.c : Ufoo1
150 ${CC} ${CCFLAGS} -flto a8.c -c -o a8.o
151 ${CC} ${CCFLAGS} main8.c -c -o main8.o
152 ${CC} ${CCFLAGS} a8.o main8.o -o main8.exe -Wl,-dead_strip
153 ${OTOOL} -tV main8.exe | grep foo2 | ${PASS_IFF_EMPTY}
154 ${OTOOL} -tV main8.exe | grep unnamed_2_1 | ${PASS_IFF_EMPTY}
158 # llvm : a9.c : Dfoo1, Dfoo2, Dfoo3, Ufoo3, Ufoo4
159 # MachO : main9.c : Ufoo1, Dfoo4
162 ${CC} ${CCFLAGS} -flto a9.c -c -o a9.o
163 ${CC} ${CCFLAGS} main9.c -c -o main9.o
164 ${CC} ${CCFLAGS} a9.o main9.o -o main9.exe -Wl,-dead_strip
165 ${OTOOL} -tV main9.exe | grep foo2 | ${PASS_IFF_EMPTY}
166 ${OTOOL} -tV main9.exe | grep foo4 | ${PASS_IFF_EMPTY}
167 ${OTOOL} -tV main9.exe | grep unnamed_2_1 | ${PASS_IFF_EMPTY}
176 ${CC} ${CCFLAGS} -flto a10.c -c -o a10.o
177 ${CC} ${CCFLAGS} -flto b10.c -c -o b10.o
178 ${CC} ${CCFLAGS} main10.c -c -o main10.o
179 ${CC} ${CCFLAGS} a10.o b10.o main10.o -o main10.exe
180 ${PASS_IFF_GOOD_MACHO} main10.exe
188 ${CC} ${CCFLAGS} -flto a11.c -c -o a11.o
189 ${CC} ${CCFLAGS} main11.c -c -o main11.o
190 ${CC} ${CCFLAGS} a11.o main11.o -o main11.exe
191 ${PASS_IFF_GOOD_MACHO} main11.exe
198 #echo "verify tentative def in llvm .o referenced from mach-o"
199 ${CC} ${CCFLAGS} -flto a12.c -c -o a12.o
200 ${CC} ${CCFLAGS} main12.c -c -o main12.o
201 ${CC} ${CCFLAGS} a12.o main12.o -o main12.exe
202 ${PASS_IFF_GOOD_MACHO} main12.exe
210 ${CC} ${CXXFLAGS} -flto a13.cc -c -o a13.o
211 ${CC} ${CXXFLAGS} main13.cc -c -o main13.o
212 ${CXX} a13.o main13.o -o main13.exe
218 # echo "verify an used hidden symbol is removed from a dylib"
219 ${CC} ${CXXFLAGS} -O4 -dynamiclib a14.c b14.c -o ab14.dylib
220 ${FAIL_IF_BAD_MACHO} ab14.dylib
221 nm -m ab14.dylib | grep _X | ${PASS_IFF_EMPTY}
224 # echo "verify -dead_strip works with hidden symbols"
225 ${CC} ${CXXFLAGS} -O4 -Wl,-dead_strip a15.c c15.c -o main15.exe
226 ${CC} ${CXXFLAGS} -O4 a15.c c15.c -o main15.exe
227 ${FAIL_IF_BAD_MACHO} main15.exe
228 ${CC} ${CXXFLAGS} -O4 -Wl,-dead_strip -dynamiclib a15.c b15.c -o a15.dylib
229 ${CC} ${CXXFLAGS} -O4 a15.c b15.c -dynamiclib -o a15.dylib
230 ${FAIL_IF_BAD_MACHO} a15.dylib
233 # echo "verify -save-temps"
234 ${CC} ${CCFLAGS} -flto main16.c -c -o main16.o
235 ${CC} ${CCFLAGS} main16.o -o main16.exe -Wl,-save-temps
236 ${PASS_IFF} test -e main16.exe.lto.bc
237 ${PASS_IFF} test -e main16.exe.lto.o
240 # echo "verify ld -r of all bitcode files produces a bitcode file"
241 ${CC} ${CCFLAGS} -flto a17.c -c -o a17.o
242 ${CC} ${CCFLAGS} -flto b17.c -c -o b17.o
243 ${LD} -arch ${ARCH} -r a17.o b17.o -o ab17.o
244 file ab17.o | grep "Mach-O" | ${PASS_IFF_EMPTY}
245 # echo "verify ld -r of bitcode and mach-o produces mach-o"
246 ${CC} ${CCFLAGS} b17.c -c -o b17m.o
247 ${LD} -arch ${ARCH} -r a17.o b17m.o -o ab17m.o
248 file ab17m.o | grep "Mach-O" | ${PASS_IFF_STDIN}
251 #echo verify ld -r -keep_private_externs works
252 ${CC} ${CCFLAGS} -flto a18.c -c -o a18.o
253 ${LD} -arch ${ARCH} -r -keep_private_externs a18.o -o a18-rkpe.o
254 nm -nm a18-rkpe.o | grep _common_hidden1 | grep "private external" | ${FAIL_IF_EMPTY}
255 nm -nm a18-rkpe.o | grep _func_hidden2 | grep "private external" | ${FAIL_IF_EMPTY}
256 #echo verify ld -r makes hidden symbols internal (except for commons)
257 ${LD} -arch ${ARCH} -r a18.o -o a18-r.o
258 #ObjectDump -nm a18-r.o | grep _common_hidden1 | grep " hidden" | ${FAIL_IF_EMPTY}
259 #ObjectDump -nm a18-r.o | grep _func_hidden2 | grep " internal" | ${FAIL_IF_EMPTY}
262 #echo verify missing symbol error
263 ${CC} ${CCFLAGS} -flto main19.c -c -o main19.o
264 ${FAIL_IF_SUCCESS} ${CC} ${CCFLAGS} main19.o -o main19.exe 2>fail.log
265 grep _foo fail.log | ${PASS_IFF_STDIN}
268 #echo verify bitcode files in archives works
269 #${CC} ${CCFLAGS} -flto a20.c -c -o a20.o
270 #${CC} ${CCFLAGS} -flto b20.c -c -o b20.o
271 #libtool -static a20.o b20.o -o lib20.a
272 #${CC} ${CCFLAGS} main20.c lib20.a -all_load -o main20.exe
273 #nm main20.exe | grep _foo | ${PASS_IFF_STDIN}
280 rm -rf *.o main*.exe big.* *.dylib main16.*.bc fail.log lib20.a main21.preload lib21.a