[PATCH] compiler-rt: build embedded Darwin variants

Tim Northover t.p.northover at gmail.com
Mon Nov 11 12:16:11 PST 2013


Hi all,

The two patches attached here are intended to produce versions of
libclang_rt suitable for use in various embedded situations in a
vaguely Darwin-like environment (i.e. still not __aeabi_*)

1. Architecture: armv6m, armv7m armv7em, armv7, i386, x86_64
2. PICness: we may want to load the resulting program anywhere, or may not care.
3. Floatiness: we may want to disallow all FP operations (to save
context-switching), or it may not matter.

Within these axes, I'm producing basically anything that makes sense
from a hardware point of view:

libclang_rt.soft_static.a: armv6m, armv7m, armv7em, armv7
libclang_rt.soft_pic.a: armv6m, armv7m, armv7em, armv7
libclang_rt.hard_static.a: armv7em, armv7, i386, x86_64
libclang_rt.hard_pic.a: armv7em, armv7, i386, x86_64

(longer term, it would be good to have soft-float x86 builds but Clang
currently doesn't honour -msoft-float, so that's not supportable now).

The patches create another make target, "clang_darwin_embedded", to
deal with these combinations. There's a lot of overlap between this
and the cc_kext versions in clang_darwin, but they're not quite the
same thing and trying to solve different problems so I think a
separate file is justified.

These runtime libraries aren't used automatically yet, but we're
planning to make driver changes in the near future to make them far
simpler for programmers.

This is my first foray into compiler-rt and other areas that affect
install layout, so lots of scrutiny would be welcome.

Should I commit, or change things?

Cheers.

Tim.
-------------- next part --------------
commit 31afdc7aa5106a72954af2f49fba836661f038c5
Author: Tim Northover <tnorthover at apple.com>
Date:   Mon Nov 11 12:14:18 2013 -0800

    Darwin(ish): enable compiler-rt darwin_embedded builds

diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile
index 930a8c2..ab35a4f 100644
--- a/runtime/compiler-rt/Makefile
+++ b/runtime/compiler-rt/Makefile
@@ -78,10 +78,12 @@ ifeq ($(shell test -d $(COMPILERRT_SRC_ROOT) && echo OK),OK)
 # support.
 RuntimeDirs :=
 ifeq ($(OS),Darwin)
-RuntimeDirs += darwin
+RuntimeDirs += darwin darwin_embedded
 RuntimeLibrary.darwin.Configs := \
 	eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \
 	profile_osx.a profile_ios.a
+RuntimeLibrary.darwin_embedded.Configs := \
+	soft_static.a hard_static.a soft_pic.a hard_pic.a
 #	Apple Internal: Disable building asan libraries. <rdar://12423266>
 #	asan_osx_dynamic.dylib ubsan_osx.a
 
-------------- next part --------------
commit b5f55de70e07f6985d2d076cefa4baffaed0445f
Author: Tim Northover <tnorthover at apple.com>
Date:   Tue Oct 29 11:19:45 2013 +0000

    Add clang_darwin_embedded platform for OS-level stuff.

diff --git a/lib/arm/Makefile.mk b/lib/arm/Makefile.mk
index 04dec88..a2df115 100644
--- a/lib/arm/Makefile.mk
+++ b/lib/arm/Makefile.mk
@@ -9,7 +9,7 @@
 
 ModuleName := builtins
 SubDirs := 
-OnlyArchs := armv5 armv6 armv7 armv7f armv7k armv7s
+OnlyArchs := armv5 armv6 armv7 armv7f armv7k armv7m armv7em armv7s
 
 AsmSources := $(foreach file,$(wildcard $(Dir)/*.S),$(notdir $(file)))
 Sources := $(foreach file,$(wildcard $(Dir)/*.c),$(notdir $(file)))
diff --git a/lib/int_util.c b/lib/int_util.c
index 6d8922a..323e461 100644
--- a/lib/int_util.c
+++ b/lib/int_util.c
@@ -31,7 +31,7 @@ void compilerrt_abort_impl(const char *file, int line, const char *function) {
   panic("%s:%d: abort in %s", file, line, function);
 }
 
-#elif __APPLE__ && !__STATIC__
+#elif __APPLE__
 
 /* from libSystem.dylib */
 extern void __assert_rtn(const char *func, const char *file, 
@@ -45,7 +45,6 @@ void compilerrt_abort_impl(const char *file, int line, const char *function) {
   __assert_rtn(function, file, line, "libcompiler_rt abort");
 }
 
-
 #else
 
 /* Get the system definition of abort() */
diff --git a/make/platform/clang_darwin_embedded.mk b/make/platform/clang_darwin_embedded.mk
new file mode 100644
index 0000000..edf8198
--- /dev/null
+++ b/make/platform/clang_darwin_embedded.mk
@@ -0,0 +1,270 @@
+# These are the functions which clang needs when it is targetting a previous
+# version of the OS. The issue is that the backend may use functions which were
+# not present in the libgcc that shipped on the platform. In such cases, we link
+# with a version of the library which contains private_extern definitions of all
+# the extra functions which might be referenced.
+
+Description := Static runtime libraries for embedded clang/Darwin
+
+XCRun = \
+  $(shell \
+    result=`xcrun -find $(1) 2> /dev/null`; \
+    if [ "$$?" != "0" ]; then result=$(1); fi; \
+    echo $$result)
+
+###
+
+CC       := $(call XCRun,clang)
+AR       := $(call XCRun,ar)
+RANLIB   := $(call XCRun,ranlib)
+STRIP    := $(call XCRun,strip)
+LIPO     := $(call XCRun,lipo)
+DSYMUTIL := $(call XCRun,dsymutil)
+
+Configs :=
+UniversalArchs :=
+
+# Soft-float version of the runtime. No floating-point instructions will be used
+# and the ABI (out of necessity) passes floating values in normal registers:
+# non-VFP variant of the AAPCS.
+Configs += soft_static
+UniversalArchs.soft_static := armv6m armv7m armv7em armv7
+
+# Hard-float version of the runtime. On ARM VFP instructions and registers are
+# allowed, and floating point values get passed in them. VFP variant of the
+# AAPCS.
+Configs += hard_static
+UniversalArchs.hard_static := armv7em armv7 i386 x86_64
+
+Configs += soft_pic
+UniversalArchs.soft_pic := armv6m armv7m armv7em armv7
+
+Configs += hard_pic
+UniversalArchs.hard_pic := armv7em armv7 i386 x86_64
+
+CFLAGS := -Wall -Werror -Oz -fomit-frame-pointer -ffreestanding
+
+PIC_CFLAGS := -fPIC
+STATIC_CFLAGS := -static
+
+CFLAGS_SOFT := -mfloat-abi=soft
+CFLAGS_HARD := -mfloat-abi=hard
+
+CFLAGS_ARMV7 := -target thumbv7-apple-darwin-eabi
+CFLAGS_I386  := -march=pentium
+
+CFLAGS.soft_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_SOFT)
+CFLAGS.hard_static := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_HARD)
+CFLAGS.soft_pic    := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_SOFT)
+CFLAGS.hard_pic    := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_HARD)
+
+CFLAGS.soft_static.armv7 := $(CFLAGS.soft_static) $(CFLAGS_ARMV7)
+CFLAGS.hard_static.armv7 := $(CFLAGS.hard_static) $(CFLAGS_ARMV7)
+CFLAGS.soft_pic.armv7    := $(CFLAGS.soft_pic) $(CFLAGS_ARMV7)
+CFLAGS.hard_pic.armv7    := $(CFLAGS.hard_pic) $(CFLAGS_ARMV7)
+
+# x86 platforms ignore -mfloat-abi options and complain about doing so. Despite
+# this they're hard-float.
+CFLAGS.hard_static.i386   := $(CFLAGS) $(STATIC_CFLAGS) $(CFLAGS_I386)
+CFLAGS.hard_pic.i386      := $(CFLAGS) $(PIC_CFLAGS) $(CFLAGS_I386)
+CFLAGS.hard_static.x86_64 := $(CFLAGS) $(STATIC_CFLAGS)
+CFLAGS.hard_pic.x86_64    := $(CFLAGS) $(PIC_CFLAGS)
+
+# Functions not wanted:
+#   + eprintf is obsolete anyway
+#   + *vfp: designed for Thumb1 CPUs with VFPv2
+
+COMMON_FUNCTIONS := \
+	absvdi2 \
+	absvsi2 \
+	addvdi3 \
+	addvsi3 \
+	ashldi3 \
+	ashrdi3 \
+	bswapdi2 \
+	bswapsi2 \
+	clzdi2 \
+	clzsi2 \
+	cmpdi2 \
+	ctzdi2 \
+	ctzsi2 \
+	divdc3 \
+	divdi3 \
+	divsc3 \
+	divmodsi4 \
+	udivmodsi4 \
+	do_global_dtors \
+	ffsdi2 \
+	fixdfdi \
+	fixsfdi \
+	fixunsdfdi \
+	fixunsdfsi \
+	fixunssfdi \
+	fixunssfsi \
+	floatdidf \
+	floatdisf \
+	floatundidf \
+	floatundisf \
+	gcc_bcmp \
+	lshrdi3 \
+	moddi3 \
+	muldc3 \
+	muldi3 \
+	mulsc3 \
+	mulvdi3 \
+	mulvsi3 \
+	negdi2 \
+	negvdi2 \
+	negvsi2 \
+	paritydi2 \
+	paritysi2 \
+	popcountdi2 \
+	popcountsi2 \
+	powidf2 \
+	powisf2 \
+	subvdi3 \
+	subvsi3 \
+	ucmpdi2 \
+	udiv_w_sdiv \
+	udivdi3 \
+	udivmoddi4 \
+	umoddi3 \
+	adddf3 \
+	addsf3 \
+	cmpdf2 \
+	cmpsf2 \
+	div0 \
+	divdf3 \
+	divsf3 \
+	divsi3 \
+	extendsfdf2 \
+	ffssi2 \
+	fixdfsi \
+	fixsfsi \
+	floatsidf \
+	floatsisf \
+	floatunsidf \
+	floatunsisf \
+	comparedf2 \
+	comparesf2 \
+	modsi3 \
+	muldf3 \
+	mulsf3 \
+	negdf2 \
+	negsf2 \
+	subdf3 \
+	subsf3 \
+	truncdfsf2 \
+	udivsi3 \
+	umodsi3 \
+	unorddf2 \
+	unordsf2
+
+ARM_FUNCTIONS := \
+	aeabi_cdcmpeq \
+	aeabi_cdrcmple \
+	aeabi_cfcmpeq \
+	aeabi_cfrcmple \
+	aeabi_dcmpeq \
+	aeabi_dcmpge \
+	aeabi_dcmpgt \
+	aeabi_dcmple \
+	aeabi_dcmplt \
+	aeabi_drsub \
+	aeabi_fcmpeq \
+	aeabi_fcmpge \
+	aeabi_fcmpgt \
+	aeabi_fcmple \
+	aeabi_fcmplt \
+	aeabi_frsub \
+	aeabi_idivmod \
+	aeabi_uidivmod \
+
+# ARM Assembly implementation which requires Thumb2 (i.e. won't work on v6M).
+THUMB2_FUNCTIONS := \
+	switch16 \
+	switch32 \
+	switch8 \
+	switchu8 \
+	sync_fetch_and_add_4 \
+	sync_fetch_and_sub_4 \
+	sync_fetch_and_and_4 \
+	sync_fetch_and_or_4 \
+	sync_fetch_and_xor_4 \
+	sync_fetch_and_nand_4 \
+	sync_fetch_and_max_4 \
+	sync_fetch_and_umax_4 \
+	sync_fetch_and_min_4 \
+	sync_fetch_and_umin_4 \
+	sync_fetch_and_add_8 \
+	sync_fetch_and_sub_8 \
+	sync_fetch_and_and_8 \
+	sync_fetch_and_or_8 \
+	sync_fetch_and_xor_8 \
+	sync_fetch_and_nand_8 \
+	sync_fetch_and_max_8 \
+	sync_fetch_and_umax_8 \
+	sync_fetch_and_min_8 \
+	sync_fetch_and_umin_8
+
+I386_FUNCTIONS :=  \
+	i686.get_pc_thunk.eax \
+	i686.get_pc_thunk.ebp \
+	i686.get_pc_thunk.ebx \
+	i686.get_pc_thunk.ecx \
+	i686.get_pc_thunk.edi \
+	i686.get_pc_thunk.edx \
+	i686.get_pc_thunk.esi
+
+# FIXME: Currently, compiler-rt is missing implementations for a number of the
+# functions. Filter them out for now.
+MISSING_FUNCTIONS := \
+	cmpdf2 cmpsf2 div0 \
+	ffssi2 \
+	udiv_w_sdiv unorddf2 unordsf2 bswapdi2 \
+	bswapsi2 \
+	gcc_bcmp \
+	do_global_dtors \
+	i686.get_pc_thunk.eax i686.get_pc_thunk.ebp i686.get_pc_thunk.ebx \
+	i686.get_pc_thunk.ecx i686.get_pc_thunk.edi i686.get_pc_thunk.edx \
+	i686.get_pc_thunk.esi \
+	aeabi_cdcmpeq aeabi_cdrcmple aeabi_cfcmpeq aeabi_cfrcmple aeabi_dcmpeq \
+	aeabi_dcmpge aeabi_dcmpgt aeabi_dcmple aeabi_dcmplt aeabi_drsub \
+	aeabi_fcmpeq \ aeabi_fcmpge aeabi_fcmpgt aeabi_fcmple aeabi_fcmplt \
+	aeabi_frsub aeabi_idivmod aeabi_uidivmod
+
+FUNCTIONS_ARMV6M  := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS)
+FUNCTIONS_ARM_ALL := $(COMMON_FUNCTIONS) $(ARM_FUNCTIONS) $(THUMB2_FUNCTIONS)
+FUNCTIONS_I386    := $(COMMON_FUNCTIONS) $(I386_FUNCTIONS)
+FUNCTIONS_X86_64  := $(COMMON_FUNCTIONS)
+
+FUNCTIONS_ARMV6M := \
+	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARMV6M))
+FUNCTIONS_ARM_ALL := \
+	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_ARM_ALL))
+FUNCTIONS_I386 := \
+	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_I386))
+FUNCTIONS_X86_64 := \
+	$(filter-out $(MISSING_FUNCTIONS),$(FUNCTIONS_X86_64))
+
+FUNCTIONS.soft_static.armv6m := $(FUNCTIONS_ARMV6M)
+FUNCTIONS.soft_pic.armv6m    := $(FUNCTIONS_ARMV6M)
+
+FUNCTIONS.soft_static.armv7m := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.soft_pic.armv7m    := $(FUNCTIONS_ARM_ALL)
+
+FUNCTIONS.soft_static.armv7em := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.hard_static.armv7em := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.soft_pic.armv7em    := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.hard_pic.armv7em    := $(FUNCTIONS_ARM_ALL)
+
+FUNCTIONS.soft_static.armv7 := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.hard_static.armv7 := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.soft_pic.armv7    := $(FUNCTIONS_ARM_ALL)
+FUNCTIONS.hard_pic.armv7    := $(FUNCTIONS_ARM_ALL)
+
+FUNCTIONS.hard_static.i386 := $(FUNCTIONS_I386)
+FUNCTIONS.hard_pic.i386    := $(FUNCTIONS_I386)
+
+FUNCTIONS.hard_static.x86_64 := $(FUNCTIONS_X86_64)
+FUNCTIONS.hard_pic.x86_64    := $(FUNCTIONS_X86_64)


More information about the llvm-commits mailing list