1# These are the functions which clang needs when it is targeting 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 embedded 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_macho_embedded_test_input.c \
18	  -o /dev/null > /dev/null 2> /dev/null; then \
19        result="$$result$$arch "; \
20      else \
21	printf 1>&2 \
22	  "warning: clang_macho_embedded.mk: dropping arch '$$arch' from lib '$(2)'\n"; \
23      fi; \
24    done; \
25    echo $$result)
26
27XCRun = \
28  $(shell \
29    result=`xcrun -find $(1) 2> /dev/null`; \
30    if [ "$$?" != "0" ]; then result=$(1); fi; \
31    echo $$result)
32
33###
34
35CC       := $(call XCRun,clang)
36AR       := $(call XCRun,ar)
37RANLIB   := $(call XCRun,ranlib)
38STRIP    := $(call XCRun,strip)
39LIPO     := $(call XCRun,lipo)
40DSYMUTIL := $(call XCRun,dsymutil)
41
42Configs :=
43UniversalArchs :=
44
45# Soft-float version of the runtime. No floating-point instructions will be used
46# and the ABI (out of necessity) passes floating values in normal registers:
47# non-VFP variant of the AAPCS.
48UniversalArchs.soft_static := $(call CheckArches,armv6m armv7m armv7em armv7,soft_static)
49Configs += $(if $(UniversalArchs.soft_static),soft_static)
50
51# Hard-float version of the runtime. On ARM VFP instructions and registers are
52# allowed, and floating point values get passed in them. VFP variant of the
53# AAPCS.
54UniversalArchs.hard_static := $(call CheckArches,armv7em armv7 i386 x86_64,hard_static)
55Configs += $(if $(UniversalArchs.hard_static),hard_static)
56
57UniversalArchs.soft_pic := $(call CheckArches,armv6m armv7m armv7em armv7,soft_pic)
58Configs += $(if $(UniversalArchs.soft_pic),soft_pic)
59
60UniversalArchs.hard_pic := $(call CheckArches,armv7em armv7 i386 x86_64,hard_pic)
61Configs += $(if $(UniversalArchs.hard_pic),hard_pic)
62
63CFLAGS := -Wall -Werror -Oz -fomit-frame-pointer -ffreestanding
64
65PIC_CFLAGS := -fPIC
66STATIC_CFLAGS := -static
67
68CFLAGS_SOFT := -mfloat-abi=soft
69CFLAGS_HARD := -mfloat-abi=hard
70
71CFLAGS_ARMV7 := -target thumbv7-apple-darwin-eabi
72CFLAGS_I386  := -march=pentium
73
74CFLAGS.soft_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_SOFT)
75CFLAGS.hard_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_HARD)
76CFLAGS.soft_pic    := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_SOFT)
77CFLAGS.hard_pic    := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_HARD)
78
79CFLAGS.soft_static.armv7 := $(CFLAGS.soft_static) $(CFLAGS_ARMV7)
80CFLAGS.hard_static.armv7 := $(CFLAGS.hard_static) $(CFLAGS_ARMV7)
81CFLAGS.soft_pic.armv7    := $(CFLAGS.soft_pic) $(CFLAGS_ARMV7)
82CFLAGS.hard_pic.armv7    := $(CFLAGS.hard_pic) $(CFLAGS_ARMV7)
83
84# x86 platforms ignore -mfloat-abi options and complain about doing so. Despite
85# this they're hard-float.
86CFLAGS.hard_static.i386   := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_I386)
87CFLAGS.hard_pic.i386      := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_I386)
88CFLAGS.hard_static.x86_64 := $(CFLAGS) $(STATIC_CFLAGS)
89CFLAGS.hard_pic.x86_64    := $(CFLAGS) $(PIC_CFLAGS)
90
91# Functions not wanted:
92#   + eprintf is obsolete anyway
93#   + *vfp: designed for Thumb1 CPUs with VFPv2
94
95COMMON_FUNCTIONS := \
96	absvdi2 \
97	absvsi2 \
98	addvdi3 \
99	addvsi3 \
100	ashldi3 \
101	ashrdi3 \
102	bswapdi2 \
103	bswapsi2 \
104	clzdi2 \
105	clzsi2 \
106	cmpdi2 \
107	ctzdi2 \
108	ctzsi2 \
109	divdc3 \
110	divdi3 \
111	divsc3 \
112	divmodsi4 \
113	udivmodsi4 \
114	do_global_dtors \
115	ffsdi2 \
116	fixdfdi \
117	fixsfdi \
118	fixunsdfdi \
119	fixunsdfsi \
120	fixunssfdi \
121	fixunssfsi \
122	floatdidf \
123	floatdisf \
124	floatundidf \
125	floatundisf \
126	gcc_bcmp \
127	lshrdi3 \
128	moddi3 \
129	muldc3 \
130	muldi3 \
131	mulsc3 \
132	mulvdi3 \
133	mulvsi3 \
134	negdi2 \
135	negvdi2 \
136	negvsi2 \
137	paritydi2 \
138	paritysi2 \
139	popcountdi2 \
140	popcountsi2 \
141	powidf2 \
142	powisf2 \
143	subvdi3 \
144	subvsi3 \
145	ucmpdi2 \
146	udiv_w_sdiv \
147	udivdi3 \
148	udivmoddi4 \
149	umoddi3 \
150	adddf3 \
151	addsf3 \
152	cmpdf2 \
153	cmpsf2 \
154	div0 \
155	divdf3 \
156	divsf3 \
157	divsi3 \
158	extendsfdf2 \
159	ffssi2 \
160	fixdfsi \
161	fixsfsi \
162	floatsidf \
163	floatsisf \
164	floatunsidf \
165	floatunsisf \
166	comparedf2 \
167	comparesf2 \
168	modsi3 \
169	muldf3 \
170	mulsf3 \
171	negdf2 \
172	negsf2 \
173	subdf3 \
174	subsf3 \
175	truncdfsf2 \
176	udivsi3 \
177	umodsi3 \
178	unorddf2 \
179	unordsf2
180
181ARM_FUNCTIONS := \
182	aeabi_cdcmpeq \
183	aeabi_cdrcmple \
184	aeabi_cfcmpeq \
185	aeabi_cfrcmple \
186	aeabi_dcmpeq \
187	aeabi_dcmpge \
188	aeabi_dcmpgt \
189	aeabi_dcmple \
190	aeabi_dcmplt \
191	aeabi_drsub \
192	aeabi_fcmpeq \
193	aeabi_fcmpge \
194	aeabi_fcmpgt \
195	aeabi_fcmple \
196	aeabi_fcmplt \
197	aeabi_frsub \
198	aeabi_idivmod \
199	aeabi_uidivmod \
200
201# ARM Assembly implementation which requires Thumb2 (i.e. won't work on v6M).
202THUMB2_FUNCTIONS := \
203	switch16 \
204	switch32 \
205	switch8 \
206	switchu8 \
207	sync_fetch_and_add_4 \
208	sync_fetch_and_sub_4 \
209	sync_fetch_and_and_4 \
210	sync_fetch_and_or_4 \
211	sync_fetch_and_xor_4 \
212	sync_fetch_and_nand_4 \
213	sync_fetch_and_max_4 \
214	sync_fetch_and_umax_4 \
215	sync_fetch_and_min_4 \
216	sync_fetch_and_umin_4 \
217	sync_fetch_and_add_8 \
218	sync_fetch_and_sub_8 \
219	sync_fetch_and_and_8 \
220	sync_fetch_and_or_8 \
221	sync_fetch_and_xor_8 \
222	sync_fetch_and_nand_8 \
223	sync_fetch_and_max_8 \
224	sync_fetch_and_umax_8 \
225	sync_fetch_and_min_8 \
226	sync_fetch_and_umin_8
227
228I386_FUNCTIONS :=  \
229	i686.get_pc_thunk.eax \
230	i686.get_pc_thunk.ebp \
231	i686.get_pc_thunk.ebx \
232	i686.get_pc_thunk.ecx \
233	i686.get_pc_thunk.edi \
234	i686.get_pc_thunk.edx \
235	i686.get_pc_thunk.esi
236
237# FIXME: Currently, compiler-rt is missing implementations for a number of the
238# functions. Filter them out for now.
239MISSING_FUNCTIONS := \
240	cmpdf2 cmpsf2 div0 \
241	ffssi2 \
242	udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
243	bswapsi2 \
244	gcc_bcmp \
245	do_global_dtors \
246	i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
247	i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
248	i686.get_pc_thunk.esi \
249	aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
250	aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub \
251	aeabi_fcmpeq \ aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt \
252	aeabi_frsub aeabi_idivmod aeabi_uidivmod
253
254FUNCTIONS_ARMV6M  := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS)
255FUNCTIONS_ARM_ALL := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS) $(THUMB2_FUNCTIONS)
256FUNCTIONS_I386    := $(COMMON_FUNCTIONS) $(I386_FUNCTIONS)
257FUNCTIONS_X86_64  := $(COMMON_FUNCTIONS)
258
259FUNCTIONS_ARMV6M := \
260	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARMV6M))
261FUNCTIONS_ARM_ALL := \
262	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARM_ALL))
263FUNCTIONS_I386 := \
264	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_I386))
265FUNCTIONS_X86_64 := \
266	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_X86_64))
267
268FUNCTIONS.soft_static.armv6m := $(FUNCTIONS_ARMV6M)
269FUNCTIONS.soft_pic.armv6m    := $(FUNCTIONS_ARMV6M)
270
271FUNCTIONS.soft_static.armv7m := $(FUNCTIONS_ARM_ALL)
272FUNCTIONS.soft_pic.armv7m    := $(FUNCTIONS_ARM_ALL)
273
274FUNCTIONS.soft_static.armv7em := $(FUNCTIONS_ARM_ALL)
275FUNCTIONS.hard_static.armv7em := $(FUNCTIONS_ARM_ALL)
276FUNCTIONS.soft_pic.armv7em    := $(FUNCTIONS_ARM_ALL)
277FUNCTIONS.hard_pic.armv7em    := $(FUNCTIONS_ARM_ALL)
278
279FUNCTIONS.soft_static.armv7 := $(FUNCTIONS_ARM_ALL)
280FUNCTIONS.hard_static.armv7 := $(FUNCTIONS_ARM_ALL)
281FUNCTIONS.soft_pic.armv7    := $(FUNCTIONS_ARM_ALL)
282FUNCTIONS.hard_pic.armv7    := $(FUNCTIONS_ARM_ALL)
283
284FUNCTIONS.hard_static.i386 := $(FUNCTIONS_I386)
285FUNCTIONS.hard_pic.i386    := $(FUNCTIONS_I386)
286
287FUNCTIONS.hard_static.x86_64 := $(FUNCTIONS_X86_64)
288FUNCTIONS.hard_pic.x86_64    := $(FUNCTIONS_X86_64)
289