Skip to content

Commit 3f3988e

Browse files
committed
compiler-rt: support a new embedded linux target
Upstream-Status: Pending Signed-off-by: Khem Raj <raj.khem@gmail.com>
1 parent cacf04b commit 3f3988e

File tree

2 files changed

+286
-0
lines changed

2 files changed

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

compiler-rt/make/platform/clang_linux_embedded_test_input.c

Whitespace-only changes.

0 commit comments

Comments
 (0)