• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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	  -integrated-as \
17	  $(ProjSrcRoot)/make/platform/clang_darwin_test_input.c \
18	  -isysroot $(ProjSrcRoot)/SDKs/darwin \
19	  -o /dev/null > /dev/null 2> /dev/null; then \
20        result="$$result$$arch "; \
21      else \
22	printf 1>&2 \
23	  "warning: clang_darwin.mk: dropping arch '$$arch' from lib '$(2)'\n"; \
24      fi; \
25    done; \
26    echo $$result)
27
28###
29
30CC := clang
31
32Configs :=
33UniversalArchs :=
34
35# Configuration solely for providing access to an eprintf symbol, which may
36# still be referenced from Darwin system headers. This symbol is only ever
37# needed on i386.
38Configs += eprintf
39UniversalArchs.eprintf := $(call CheckArches,i386,eprintf)
40
41# Configuration for targetting 10.4. We need a few functions missing from
42# libgcc_s.10.4.dylib. We only build x86 slices since clang doesn't really
43# support targetting PowerPC.
44Configs += 10.4
45UniversalArchs.10.4 := $(call CheckArches,i386 x86_64,10.4)
46
47# Configuration for targetting iOS for a couple of functions that didn't
48# make it into libSystem.
49Configs += ios
50UniversalArchs.ios := $(call CheckArches,i386 x86_64 armv7,ios)
51
52# Configuration for targetting OSX. These functions may not be in libSystem
53# so we should provide our own.
54Configs += osx
55UniversalArchs.osx := $(call CheckArches,i386 x86_64,osx)
56
57# Configuration for use with kernel/kexts.
58Configs += cc_kext
59UniversalArchs.cc_kext := $(call CheckArches,armv7 i386 x86_64,cc_kext)
60
61# Configuration for use with kernel/kexts for iOS 5.0 and earlier (which used
62# a different code generation strategy).
63Configs += cc_kext_ios5
64UniversalArchs.cc_kext_ios5 := $(call CheckArches,x86_64 armv7,cc_kext_ios5)
65
66# Configurations which define the profiling support functions.
67Configs += profile_osx
68UniversalArchs.profile_osx := $(call CheckArches,i386 x86_64,profile_osx)
69Configs += profile_ios
70UniversalArchs.profile_ios := $(call CheckArches,i386 x86_64 armv7,profile_ios)
71
72# Configurations which define the ASAN support functions.
73Configs += asan_osx_dynamic
74UniversalArchs.asan_osx_dynamic := $(call CheckArches,i386 x86_64,asan_osx_dynamic)
75
76Configs += ubsan_osx
77UniversalArchs.ubsan_osx := $(call CheckArches,i386 x86_64,ubsan_osx)
78
79# Darwin 10.6 has a bug in cctools that makes it unable to use ranlib on our ARM
80# object files. If we are on that platform, strip out all ARM archs. We still
81# build the libraries themselves so that Clang can find them where it expects
82# them, even though they might not have an expected slice.
83ifneq ($(shell test -x /usr/bin/sw_vers && sw_vers -productVersion | grep 10.6),)
84UniversalArchs.ios := $(filter-out armv7, $(UniversalArchs.ios))
85UniversalArchs.cc_kext := $(filter-out armv7, $(UniversalArchs.cc_kext))
86UniversalArchs.cc_kext_ios5 := $(filter-out armv7, $(UniversalArchs.cc_kext_ios5))
87UniversalArchs.profile_ios := $(filter-out armv7, $(UniversalArchs.profile_ios))
88endif
89
90# If RC_SUPPORTED_ARCHS is defined, treat it as a list of the architectures we
91# are intended to support and limit what we try to build to that.
92#
93# We make sure to remove empty configs if we end up dropping all the requested
94# archs for a particular config.
95ifneq ($(RC_SUPPORTED_ARCHS),)
96$(foreach config,$(Configs),\
97  $(call Set,UniversalArchs.$(config),\
98	$(filter $(RC_SUPPORTED_ARCHS),$(UniversalArchs.$(config))))\
99  $(if $(UniversalArchs.$(config)),,\
100	$(call Set,Configs,$(filter-out $(config),$(Configs)))))
101endif
102
103###
104
105# Forcibly strip off any -arch, as that totally breaks our universal support.
106override CC := $(subst -arch ,-arch_,$(CC))
107override CC := $(patsubst -arch_%,,$(CC))
108
109CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
110
111# Always set deployment target arguments for every build, these libraries should
112# never depend on the environmental overrides. We simply set them to minimum
113# supported deployment target -- nothing in the compiler-rt libraries should
114# actually depend on the deployment target.
115OSX_DEPLOYMENT_ARGS := -mmacosx-version-min=10.4
116IOS_DEPLOYMENT_ARGS := -mios-version-min=1.0
117IOS6_DEPLOYMENT_ARGS := -mios-version-min=6.0
118IOSSIM_DEPLOYMENT_ARGS := -mios-simulator-version-min=1.0
119
120# Use our stub SDK as the sysroot to support more portable building.
121OSX_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
122IOS_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
123IOS6_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
124IOSSIM_DEPLOYMENT_ARGS += -isysroot $(ProjSrcRoot)/SDKs/darwin
125
126CFLAGS.eprintf		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
127CFLAGS.10.4		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
128# FIXME: We can't build ASAN with our stub SDK yet.
129CFLAGS.asan_osx_dynamic := \
130	$(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin \
131	-gline-tables-only \
132	-DMAC_INTERPOSE_FUNCTIONS=1 \
133  -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
134
135CFLAGS.ubsan_osx	:= $(CFLAGS) -mmacosx-version-min=10.6 -fno-builtin
136
137CFLAGS.ios.i386		:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
138CFLAGS.ios.x86_64	:= $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
139CFLAGS.ios.armv7	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
140CFLAGS.ios.armv7f	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
141CFLAGS.ios.armv7k	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
142CFLAGS.ios.armv7s	:= $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
143CFLAGS.osx.i386		:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
144CFLAGS.osx.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
145CFLAGS.cc_kext.i386	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
146CFLAGS.cc_kext.x86_64	:= $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
147CFLAGS.cc_kext.armv7	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
148CFLAGS.cc_kext.armv7f	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
149CFLAGS.cc_kext.armv7k	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
150CFLAGS.cc_kext.armv7s	:= $(CFLAGS) $(IOS6_DEPLOYMENT_ARGS)
151CFLAGS.cc_kext_ios5.armv7  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
152CFLAGS.cc_kext_ios5.armv7f := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
153CFLAGS.cc_kext_ios5.armv7k := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
154CFLAGS.cc_kext_ios5.armv7s := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
155CFLAGS.profile_osx.i386   := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
156CFLAGS.profile_osx.x86_64 := $(CFLAGS) $(OSX_DEPLOYMENT_ARGS)
157CFLAGS.profile_ios.i386   := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
158CFLAGS.profile_ios.x86_64 := $(CFLAGS) $(IOSSIM_DEPLOYMENT_ARGS)
159CFLAGS.profile_ios.armv7  := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
160CFLAGS.profile_ios.armv7f := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
161CFLAGS.profile_ios.armv7k := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
162CFLAGS.profile_ios.armv7s := $(CFLAGS) $(IOS_DEPLOYMENT_ARGS)
163
164# Configure the asan_osx_dynamic library to be built shared.
165SHARED_LIBRARY.asan_osx_dynamic := 1
166LDFLAGS.asan_osx_dynamic := -framework Foundation -lstdc++ -undefined dynamic_lookup
167
168FUNCTIONS.eprintf := eprintf
169FUNCTIONS.10.4 := eprintf floatundidf floatundisf floatundixf
170
171FUNCTIONS.ios	    := divmodsi4 udivmodsi4 mulosi4 mulodi4 muloti4
172# On x86, the divmod functions reference divsi.
173FUNCTIONS.ios.i386   := $(FUNCTIONS.ios) \
174                        divsi3 udivsi3
175FUNCTIONS.ios.x86_64 := $(FUNCTIONS.ios) \
176                        divsi3 udivsi3
177
178FUNCTIONS.osx	:= mulosi4 mulodi4 muloti4
179
180FUNCTIONS.profile_osx := GCDAProfiling
181FUNCTIONS.profile_ios := GCDAProfiling
182
183FUNCTIONS.asan_osx_dynamic := $(AsanFunctions) $(InterceptionFunctions) \
184                              $(SanitizerCommonFunctions) \
185	                      $(AsanDynamicFunctions)
186
187FUNCTIONS.ubsan_osx := $(UbsanFunctions) $(UbsanCXXFunctions) \
188                       $(SanitizerCommonFunctions)
189
190CCKEXT_COMMON_FUNCTIONS := \
191	absvdi2 \
192	absvsi2 \
193	addvdi3 \
194	addvsi3 \
195	ashldi3 \
196	ashrdi3 \
197	bswapdi2 \
198	bswapsi2 \
199	clzdi2 \
200	clzsi2 \
201	cmpdi2 \
202	ctzdi2 \
203	ctzsi2 \
204	divdc3 \
205	divdi3 \
206	divsc3 \
207	divmodsi4 \
208	udivmodsi4 \
209	do_global_dtors \
210	eprintf \
211	ffsdi2 \
212	fixdfdi \
213	fixsfdi \
214	fixunsdfdi \
215	fixunsdfsi \
216	fixunssfdi \
217	fixunssfsi \
218	floatdidf \
219	floatdisf \
220	floatundidf \
221	floatundisf \
222	gcc_bcmp \
223	lshrdi3 \
224	moddi3 \
225	muldc3 \
226	muldi3 \
227	mulsc3 \
228	mulvdi3 \
229	mulvsi3 \
230	negdi2 \
231	negvdi2 \
232	negvsi2 \
233	paritydi2 \
234	paritysi2 \
235	popcountdi2 \
236	popcountsi2 \
237	powidf2 \
238	powisf2 \
239	subvdi3 \
240	subvsi3 \
241	ucmpdi2 \
242	udiv_w_sdiv \
243	udivdi3 \
244	udivmoddi4 \
245	umoddi3
246
247CCKEXT_ARM_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
248	adddf3 \
249	addsf3 \
250	aeabi_cdcmpeq \
251	aeabi_cdrcmple \
252	aeabi_cfcmpeq \
253	aeabi_cfrcmple \
254	aeabi_dcmpeq \
255	aeabi_dcmpge \
256	aeabi_dcmpgt \
257	aeabi_dcmple \
258	aeabi_dcmplt \
259	aeabi_drsub \
260	aeabi_fcmpeq \
261	aeabi_fcmpge \
262	aeabi_fcmpgt \
263	aeabi_fcmple \
264	aeabi_fcmplt \
265	aeabi_frsub \
266	aeabi_idivmod \
267	aeabi_uidivmod \
268	cmpdf2 \
269	cmpsf2 \
270	div0 \
271	divdf3 \
272	divsf3 \
273	divsi3 \
274	extendsfdf2 \
275	ffssi2 \
276	fixdfsi \
277	fixsfsi \
278	floatsidf \
279	floatsisf \
280	floatunsidf \
281	floatunsisf \
282	comparedf2 \
283	comparesf2 \
284	modsi3 \
285	muldf3 \
286	mulsf3 \
287	negdf2 \
288	negsf2 \
289	subdf3 \
290	subsf3 \
291	switch16 \
292	switch32 \
293	switch8 \
294	switchu8 \
295	truncdfsf2 \
296	udivsi3 \
297	umodsi3 \
298	unorddf2 \
299	unordsf2
300
301CCKEXT_ARMVFP_FUNCTIONS := $(CCKEXT_ARM_FUNCTIONS) \
302	adddf3vfp \
303	addsf3vfp \
304	divdf3vfp \
305	divsf3vfp \
306	eqdf2vfp \
307	eqsf2vfp \
308	extendsfdf2vfp \
309	fixdfsivfp \
310	fixsfsivfp \
311	fixunsdfsivfp \
312	fixunssfsivfp \
313	floatsidfvfp \
314	floatsisfvfp \
315	floatunssidfvfp \
316	floatunssisfvfp \
317	gedf2vfp \
318	gesf2vfp \
319	gtdf2vfp \
320	gtsf2vfp \
321	ledf2vfp \
322	lesf2vfp \
323	ltdf2vfp \
324	ltsf2vfp \
325	muldf3vfp \
326	mulsf3vfp \
327	nedf2vfp \
328	nesf2vfp \
329	subdf3vfp \
330	subsf3vfp \
331	truncdfsf2vfp \
332	unorddf2vfp \
333	unordsf2vfp
334
335FUNCTIONS.cc_kext.armv7 := $(CCKEXT_ARMVFP_FUNCTIONS)
336FUNCTIONS.cc_kext.armv7f := $(CCKEXT_ARMVFP_FUNCTIONS)
337FUNCTIONS.cc_kext.armv7k := $(CCKEXT_ARMVFP_FUNCTIONS)
338FUNCTIONS.cc_kext.armv7s := $(CCKEXT_ARMVFP_FUNCTIONS)
339FUNCTIONS.cc_kext_ios5.armv7 := $(CCKEXT_ARMVFP_FUNCTIONS)
340FUNCTIONS.cc_kext_ios5.armv7f := $(CCKEXT_ARMVFP_FUNCTIONS)
341FUNCTIONS.cc_kext_ios5.armv7k := $(CCKEXT_ARMVFP_FUNCTIONS)
342FUNCTIONS.cc_kext_ios5.armv7s := $(CCKEXT_ARMVFP_FUNCTIONS)
343
344CCKEXT_X86_FUNCTIONS := $(CCKEXT_COMMON_FUNCTIONS) \
345	divxc3 \
346	fixunsxfdi \
347	fixunsxfsi \
348	fixxfdi \
349	floatdixf \
350	floatundixf \
351	mulxc3 \
352	powixf2
353
354FUNCTIONS.cc_kext.i386 := $(CCKEXT_X86_FUNCTIONS) \
355	ffssi2 \
356	i686.get_pc_thunk.eax \
357	i686.get_pc_thunk.ebp \
358	i686.get_pc_thunk.ebx \
359	i686.get_pc_thunk.ecx \
360	i686.get_pc_thunk.edi \
361	i686.get_pc_thunk.edx \
362	i686.get_pc_thunk.esi
363
364FUNCTIONS.cc_kext.x86_64 := $(CCKEXT_X86_FUNCTIONS) \
365	absvti2 \
366	addvti3 \
367	ashlti3 \
368	ashrti3 \
369	clzti2 \
370	cmpti2 \
371	ctzti2 \
372	divti3 \
373	ffsti2 \
374	fixdfti \
375	fixsfti \
376	fixunsdfti \
377	fixunssfti \
378	fixunsxfti \
379	fixxfti \
380	floattidf \
381	floattisf \
382	floattixf \
383	floatuntidf \
384	floatuntisf \
385	floatuntixf \
386	lshrti3 \
387	modti3 \
388	multi3 \
389	mulvti3 \
390	negti2 \
391	negvti2 \
392	parityti2 \
393	popcountti2 \
394	subvti3 \
395	ucmpti2 \
396	udivmodti4 \
397	udivti3 \
398	umodti3
399
400# FIXME: Currently, compiler-rt is missing implementations for a number of the
401# functions that need to go into libcc_kext.a. Filter them out for now.
402CCKEXT_MISSING_FUNCTIONS := \
403	cmpdf2 cmpsf2 div0 \
404	ffssi2 \
405	udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
406	bswapsi2 \
407	gcc_bcmp \
408	do_global_dtors \
409	i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
410	i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
411	i686.get_pc_thunk.esi \
412	aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
413	aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub aeabi_fcmpeq \
414	aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt aeabi_frsub aeabi_idivmod \
415	aeabi_uidivmod
416
417FUNCTIONS.cc_kext.armv7 := \
418	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7))
419FUNCTIONS.cc_kext.armv7f := \
420	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7f))
421FUNCTIONS.cc_kext.armv7k := \
422	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7k))
423FUNCTIONS.cc_kext.armv7s := \
424	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.armv7s))
425FUNCTIONS.cc_kext_ios5.armv7 := \
426	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7))
427FUNCTIONS.cc_kext_ios5.armv7f := \
428	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7f))
429FUNCTIONS.cc_kext_ios5.armv7k := \
430	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7k))
431FUNCTIONS.cc_kext_ios5.armv7s := \
432	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext_ios5.armv7s))
433FUNCTIONS.cc_kext.i386 := \
434	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.i386))
435FUNCTIONS.cc_kext.x86_64 := \
436	$(filter-out $(CCKEXT_MISSING_FUNCTIONS),$(FUNCTIONS.cc_kext.x86_64))
437
438KERNEL_USE.cc_kext := 1
439KERNEL_USE.cc_kext_ios5 := 1
440
441VISIBILITY_HIDDEN := 1
442
443SHARED_LIBRARY_SUFFIX := dylib
444