clang_darwin.mk revision c6f2223a8772262e5e682403f2d57f0b465a98fc
1# These are the functions which clang needs when it is targetting a previous
2# version of the OS. The issue is that the backend may use functions which were
3# not present in the libgcc that shipped on the platform. In such cases, we link
4# with a version of the library which contains private_extern definitions of all
5# the extra functions which might be referenced.
6
7Description := Static runtime libraries for clang/Darwin.
8
9# A function that ensures we don't try to build for architectures that we
10# don't have working toolchains for.
11CheckArches = \
12  $(shell \
13    result=""; \
14    for arch in $(1); do \
15      if $(CC) -arch $$arch -c \
16	  $(ProjSrcRoot)/make/platform/clang_darwin_test_input.c \
17	  -o /dev/null > /dev/null 2> /dev/null; then \
18        result="$$result$$arch "; \
19      fi; \
20    done; \
21    echo $$result)
22
23###
24
25CC := clang
26
27Configs :=
28UniversalArchs :=
29
30# Configuration solely for providing access to an eprintf symbol, which may
31# still be referenced from Darwin system headers. This symbol is only ever
32# needed on i386.
33Configs += eprintf
34UniversalArchs.eprintf := $(call CheckArches,i386)
35
36# Configuration for targetting 10.4. We need a few functions missing from
37# libgcc_s.10.4.dylib. We only build x86 slices since clang doesn't really
38# support targetting PowerPC.
39Configs += 10.4
40UniversalArchs.10.4 := $(call CheckArches,i386 x86_64)
41
42# Configuration for targetting iOS, for some ARMv6 functions, which must be
43# in the same linkage unit, and for a couple of other functions that didn't
44# make it into libSystem.
45Configs += ios
46UniversalArchs.ios := $(call CheckArches,i386 x86_64 armv6 armv7)
47
48# Configuration for targetting OSX. These functions may not be in libSystem
49# so we should provide our own.
50Configs += osx
51UniversalArchs.osx := $(call CheckArches,i386 x86_64)
52
53# Configuration for use with kernel/kexts.
54Configs += cc_kext
55UniversalArchs.cc_kext := $(call CheckArches,armv6 armv7 i386 x86_64)
56
57# Configurations which define the profiling support functions.
58Configs += profile_osx
59UniversalArchs.profile_osx := $(call CheckArches,i386 x86_64)
60Configs += profile_ios
61UniversalArchs.profile_ios := $(call CheckArches,i386 x86_64 armv6 armv7)
62
63# Configurations which define the ASAN support functions.
64#
65# Note that ASAN doesn't appear to currently support i386.
66Configs += asan_osx
67UniversalArchs.asan_osx := $(call CheckArches,i386 x86_64)
68
69# If RC_SUPPORTED_ARCHS is defined, treat it as a list of the architectures we
70# are intended to support and limit what we try to build to that.
71#
72# We make sure to remove empty configs if we end up dropping all the requested
73# archs for a particular config.
74ifneq ($(RC_SUPPORTED_ARCHS),)
75$(foreach config,$(Configs),\
76  $(call Set,UniversalArchs.$(config),\
77	$(filter $(RC_SUPPORTED_ARCHS),$(UniversalArchs.$(config))))\
78  $(if $(UniversalArchs.$(config)),,\
79	$(call Set,Configs,$(filter-out $(config),$(Configs)))))
80endif
81
82###
83
84# Forcibly strip off any -arch, as that totally breaks our universal support.
85override CC := $(subst -arch ,-arch_,$(CC))
86override CC := $(patsubst -arch_%,,$(CC))
87
88CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
89
90# Always set deployment target arguments for every build, these libraries should
91# never depend on the environmental overrides. We simply set them to minimum
92# supported deployment target -- nothing in the compiler-rt libraries should
93# actually depend on the deployment target.
94OSX_DEPLOYMENT_ARGS := -mmacosx-version-min=10.4
95IOS_DEPLOYMENT_ARGS := -miphoneos-version-min=1.0
96IOSSIM_DEPLOYMENT_ARGS := -miphoneos-version-min=1.0
97
98# Use our stub SDK as the sysroot to support more portable building.
99OSX_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
100IOS_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
101IOSSIM_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
102
103CFLAGS.eprintf		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
104CFLAGS.10.4		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
105# FIXME: We can't build ASAN with our stub SDK yet.
106CFLAGS.asan_osx         := $(CFLAGS) -mmacosx-version-min=10.5
107
108CFLAGS.ios.i386		:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
109CFLAGS.ios.x86_64	:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
110CFLAGS.ios.armv6	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
111CFLAGS.ios.armv7	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
112CFLAGS.osx.i386		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
113CFLAGS.osx.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
114CFLAGS.cc_kext.i386	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
115CFLAGS.cc_kext.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
116CFLAGS.cc_kext.armv6	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS) -mthumb
117CFLAGS.cc_kext.armv7	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
118CFLAGS.profile_osx.i386   := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
119CFLAGS.profile_osx.x86_64 := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
120CFLAGS.profile_ios.i386   := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
121CFLAGS.profile_ios.x86_64 := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
122CFLAGS.profile_ios.armv6  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
123CFLAGS.profile_ios.armv7  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
124
125FUNCTIONS.eprintf := eprintf
126FUNCTIONS.10.4 := eprintf floatundidf floatundisf floatundixf
127
128FUNCTIONS.ios	    := divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4
129# On x86, the divmod functions reference divsi.
130FUNCTIONS.ios.i386   := $(FUNCTIONS.ios) \
131                        divsi3 udivsi3
132FUNCTIONS.ios.x86_64 := $(FUNCTIONS.ios) \
133                        divsi3 udivsi3
134FUNCTIONS.ios.armv6 := $(FUNCTIONS.ios) \
135                       sync_synchronize \
136                       switch16 switch32 switch8 switchu8 \
137                       save_vfp_d8_d15_regs restore_vfp_d8_d15_regs
138
139FUNCTIONS.osx	:= mulosi4 mulodi4 muloti4
140
141FUNCTIONS.profile_osx := GCDAProfiling
142FUNCTIONS.profile_ios := GCDAProfiling
143
144FUNCTIONS.asan_osx := $(AsanFunctions)
145
146CCKEXT_COMMON_FUNCTIONS := \
147	absvdi2 \
148	absvsi2 \
149	addvdi3 \
150	addvsi3 \
151	ashldi3 \
152	ashrdi3 \
153	bswapdi2 \
154	bswapsi2 \
155	clzdi2 \
156	clzsi2 \
157	cmpdi2 \
158	ctzdi2 \
159	ctzsi2 \
160	divdc3 \
161	divdi3 \
162	divsc3 \
163	divmodsi4 \
164	udivmodsi4 \
165	do_global_dtors \
166	eprintf \
167	ffsdi2 \
168	fixdfdi \
169	fixsfdi \
170	fixunsdfdi \
171	fixunsdfsi \
172	fixunssfdi \
173	fixunssfsi \
174	floatdidf \
175	floatdisf \
176	floatundidf \
177	floatundisf \
178	gcc_bcmp \
179	lshrdi3 \
180	moddi3 \
181	muldc3 \
182	muldi3 \
183	mulsc3 \
184	mulvdi3 \
185	mulvsi3 \
186	negdi2 \
187	negvdi2 \
188	negvsi2 \
189	paritydi2 \
190	paritysi2 \
191	popcountdi2 \
192	popcountsi2 \
193	powidf2 \
194	powisf2 \
195	subvdi3 \
196	subvsi3 \
197	ucmpdi2 \
198	udiv_w_sdiv \
199	udivdi3 \
200	udivmoddi4 \
201	umoddi3
202
203CCKEXT_ARM_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
204	adddf3 \
205	addsf3 \
206	aeabi_cdcmpeq \
207	aeabi_cdrcmple \
208	aeabi_cfcmpeq \
209	aeabi_cfrcmple \
210	aeabi_dcmpeq \
211	aeabi_dcmpge \
212	aeabi_dcmpgt \
213	aeabi_dcmple \
214	aeabi_dcmplt \
215	aeabi_drsub \
216	aeabi_fcmpeq \
217	aeabi_fcmpge \
218	aeabi_fcmpgt \
219	aeabi_fcmple \
220	aeabi_fcmplt \
221	aeabi_frsub \
222	aeabi_idivmod \
223	aeabi_uidivmod \
224	cmpdf2 \
225	cmpsf2 \
226	div0 \
227	divdf3 \
228	divsf3 \
229	divsi3 \
230	extendsfdf2 \
231	ffssi2 \
232	fixdfsi \
233	fixsfsi \
234	floatsidf \
235	floatsisf \
236	floatunsidf \
237	floatunsisf \
238	comparedf2 \
239	comparesf2 \
240	modsi3 \
241	muldf3 \
242	mulsf3 \
243	negdf2 \
244	negsf2 \
245	subdf3 \
246	subsf3 \
247	switch16 \
248	switch32 \
249	switch8 \
250	switchu8 \
251	truncdfsf2 \
252	udivsi3 \
253	umodsi3 \
254	unorddf2 \
255	unordsf2
256
257CCKEXT_ARMVFP_FUNCTIONS := $(CCKEXT_ARM_FUNCTIONS) \
258	adddf3vfp \
259	addsf3vfp \
260	divdf3vfp \
261	divsf3vfp \
262	eqdf2vfp \
263	eqsf2vfp \
264	extendsfdf2vfp \
265	fixdfsivfp \
266	fixsfsivfp \
267	fixunsdfsivfp \
268	fixunssfsivfp \
269	floatsidfvfp \
270	floatsisfvfp \
271	floatunssidfvfp \
272	floatunssisfvfp \
273	gedf2vfp \
274	gesf2vfp \
275	gtdf2vfp \
276	gtsf2vfp \
277	ledf2vfp \
278	lesf2vfp \
279	ltdf2vfp \
280	ltsf2vfp \
281	muldf3vfp \
282	mulsf3vfp \
283	nedf2vfp \
284	nesf2vfp \
285	subdf3vfp \
286	subsf3vfp \
287	truncdfsf2vfp \
288	unorddf2vfp \
289	unordsf2vfp
290
291FUNCTIONS.cc_kext.armv6 := $(CCKEXT_ARMVFP_FUNCTIONS)
292FUNCTIONS.cc_kext.armv7 := $(CCKEXT_ARMVFP_FUNCTIONS)
293
294CCKEXT_X86_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
295	divxc3 \
296	fixunsxfdi \
297	fixunsxfsi \
298	fixxfdi \
299	floatdixf \
300	floatundixf \
301	mulxc3 \
302	powixf2
303
304FUNCTIONS.cc_kext.i386 := $(CCKEXT_X86_FUNCTIONS) \
305	ffssi2 \
306	i686.get_pc_thunk.eax \
307	i686.get_pc_thunk.ebp \
308	i686.get_pc_thunk.ebx \
309	i686.get_pc_thunk.ecx \
310	i686.get_pc_thunk.edi \
311	i686.get_pc_thunk.edx \
312	i686.get_pc_thunk.esi
313
314FUNCTIONS.cc_kext.x86_64 := $(CCKEXT_X86_FUNCTIONS) \
315	absvti2 \
316	addvti3 \
317	ashlti3 \
318	ashrti3 \
319	clzti2 \
320	cmpti2 \
321	ctzti2 \
322	divti3 \
323	ffsti2 \
324	fixdfti \
325	fixsfti \
326	fixunsdfti \
327	fixunssfti \
328	fixunsxfti \
329	fixxfti \
330	floattidf \
331	floattisf \
332	floattixf \
333	floatuntidf \
334	floatuntisf \
335	floatuntixf \
336	lshrti3 \
337	modti3 \
338	multi3 \
339	mulvti3 \
340	negti2 \
341	negvti2 \
342	parityti2 \
343	popcountti2 \
344	subvti3 \
345	ucmpti2 \
346	udivmodti4 \
347	udivti3 \
348	umodti3
349
350# FIXME: Currently, compiler-rt is missing implementations for a number of the
351# functions that need to go into libcc_kext.a. Filter them out for now.
352CCKEXT_MISSING_FUNCTIONS := \
353	cmpdf2 cmpsf2 div0 \
354	ffssi2 \
355	udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
356	bswapsi2 \
357	gcc_bcmp \
358	do_global_dtors \
359	i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
360	i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
361	i686.get_pc_thunk.esi \
362	aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
363	aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub aeabi_fcmpeq \
364	aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt aeabi_frsub aeabi_idivmod \
365	aeabi_uidivmod
366
367FUNCTIONS.cc_kext.armv6 := \
368	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv6))
369FUNCTIONS.cc_kext.armv7 := \
370	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7))
371FUNCTIONS.cc_kext.i386 := \
372	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.i386))
373FUNCTIONS.cc_kext.x86_64 := \
374	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.x86_64))
375
376KERNEL_USE.cc_kext := 1
377
378VISIBILITY_HIDDEN := 1
379