# compiler-rt
################################################################################
-ifdef CFG_ENABLE_FAST_MAKE
-COMPRT_DEPS := $(S)/.gitmodules
-else
-COMPRT_DEPS := $(wildcard \
- $(S)src/compiler-rt/* \
- $(S)src/compiler-rt/*/* \
- $(S)src/compiler-rt/*/*/* \
- $(S)src/compiler-rt/*/*/*/*)
-endif
-
-# compiler-rt's build system is a godawful mess. Here we figure out
-# the ridiculous platform-specific values and paths necessary to get
-# useful artifacts out of it.
+# Everything below is a manual compilation of compiler-rt, disregarding its
+# build system. See comments in `src/bootstrap/native.rs` for more information.
COMPRT_NAME_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),compiler-rt)
COMPRT_LIB_$(1) := $$(RT_OUTPUT_DIR_$(1))/$$(COMPRT_NAME_$(1))
COMPRT_BUILD_DIR_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt
-COMPRT_ARCH_$(1) := $$(word 1,$$(subst -, ,$(1)))
+# GENERIC_SOURCES in CMakeLists.txt
+COMPRT_OBJS_$(1) := \
+ absvdi2.o \
+ absvsi2.o \
+ adddf3.o \
+ addsf3.o \
+ addvdi3.o \
+ addvsi3.o \
+ apple_versioning.o \
+ ashldi3.o \
+ ashrdi3.o \
+ clear_cache.o \
+ clzdi2.o \
+ clzsi2.o \
+ cmpdi2.o \
+ comparedf2.o \
+ comparesf2.o \
+ ctzdi2.o \
+ ctzsi2.o \
+ divdc3.o \
+ divdf3.o \
+ divdi3.o \
+ divmoddi4.o \
+ divmodsi4.o \
+ divsc3.o \
+ divsf3.o \
+ divsi3.o \
+ divxc3.o \
+ extendsfdf2.o \
+ extendhfsf2.o \
+ ffsdi2.o \
+ fixdfdi.o \
+ fixdfsi.o \
+ fixsfdi.o \
+ fixsfsi.o \
+ fixunsdfdi.o \
+ fixunsdfsi.o \
+ fixunssfdi.o \
+ fixunssfsi.o \
+ fixunsxfdi.o \
+ fixunsxfsi.o \
+ fixxfdi.o \
+ floatdidf.o \
+ floatdisf.o \
+ floatdixf.o \
+ floatsidf.o \
+ floatsisf.o \
+ floatundidf.o \
+ floatundisf.o \
+ floatundixf.o \
+ floatunsidf.o \
+ floatunsisf.o \
+ int_util.o \
+ lshrdi3.o \
+ moddi3.o \
+ modsi3.o \
+ muldc3.o \
+ muldf3.o \
+ muldi3.o \
+ mulodi4.o \
+ mulosi4.o \
+ muloti4.o \
+ mulsc3.o \
+ mulsf3.o \
+ mulvdi3.o \
+ mulvsi3.o \
+ mulxc3.o \
+ negdf2.o \
+ negdi2.o \
+ negsf2.o \
+ negvdi2.o \
+ negvsi2.o \
+ paritydi2.o \
+ paritysi2.o \
+ popcountdi2.o \
+ popcountsi2.o \
+ powidf2.o \
+ powisf2.o \
+ powixf2.o \
+ subdf3.o \
+ subsf3.o \
+ subvdi3.o \
+ subvsi3.o \
+ truncdfhf2.o \
+ truncdfsf2.o \
+ truncsfhf2.o \
+ ucmpdi2.o \
+ udivdi3.o \
+ udivmoddi4.o \
+ udivmodsi4.o \
+ udivsi3.o \
+ umoddi3.o \
+ umodsi3.o
-# All this is to figure out the path to the compiler-rt bin
-ifeq ($$(findstring windows-msvc,$(1)),windows-msvc)
-COMPRT_DIR_$(1) := windows/Release
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins-$$(patsubst i%86,i386,$$(COMPRT_ARCH_$(1)))
+ifeq ($$(findstring ios,$(1)),)
+COMPRT_OBJS_$(1) += \
+ absvti2.o \
+ addtf3.o \
+ addvti3.o \
+ ashlti3.o \
+ ashrti3.o \
+ clzti2.o \
+ cmpti2.o \
+ ctzti2.o \
+ divtf3.o \
+ divti3.o \
+ ffsti2.o \
+ fixdfti.o \
+ fixsfti.o \
+ fixunsdfti.o \
+ fixunssfti.o \
+ fixunsxfti.o \
+ fixxfti.o \
+ floattidf.o \
+ floattisf.o \
+ floattixf.o \
+ floatuntidf.o \
+ floatuntisf.o \
+ floatuntixf.o \
+ lshrti3.o \
+ modti3.o \
+ multf3.o \
+ multi3.o \
+ mulvti3.o \
+ negti2.o \
+ negvti2.o \
+ parityti2.o \
+ popcountti2.o \
+ powitf2.o \
+ subtf3.o \
+ subvti3.o \
+ trampoline_setup.o \
+ ucmpti2.o \
+ udivmodti4.o \
+ udivti3.o \
+ umodti3.o
endif
-ifeq ($$(findstring windows-gnu,$(1)),windows-gnu)
-COMPRT_DIR_$(1) := windows
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins-$$(COMPRT_ARCH_$(1))
+ifeq ($$(findstring apple,$(1)),apple)
+COMPRT_OBJS_$(1) += \
+ atomic_flag_clear.o \
+ atomic_flag_clear_explicit.o \
+ atomic_flag_test_and_set.o \
+ atomic_flag_test_and_set_explicit.o \
+ atomic_signal_fence.o \
+ atomic_thread_fence.o
endif
-ifeq ($$(findstring darwin,$(1)),darwin)
-COMPRT_DIR_$(1) := builtins
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins_$$(patsubst i686,i386,$$(COMPRT_ARCH_$(1)))_osx
-endif
-ifeq ($$(findstring ios,$(1)),ios)
-COMPRT_DIR_$(1) := builtins
-COMPRT_ARCH_$(1) := $$(patsubst armv7s,armv7em,$$(COMPRT_ARCH_$(1)))
-COMPRT_LIB_NAME_$(1) := clang_rt.hard_pic_$$(COMPRT_ARCH_$(1))_macho_embedded
-ifeq ($$(COMPRT_ARCH_$(1)),aarch64)
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins_arm64_ios
-endif
-COMPRT_DEFINES_$(1) := -DCOMPILER_RT_ENABLE_IOS=ON
+ifeq ($$(findstring windows,$(1)),)
+COMPRT_OBJS_$(1) += emutls.o
endif
-ifndef COMPRT_DIR_$(1)
-# NB: FreeBSD and NetBSD output to "linux"...
-COMPRT_DIR_$(1) := linux
-COMPRT_ARCH_$(1) := $$(patsubst i586,i386,$$(COMPRT_ARCH_$(1)))
+ifeq ($$(findstring msvc,$(1)),)
-ifeq ($$(findstring android,$(1)),android)
-ifeq ($$(findstring arm,$$(COMPRT_ARCH_$(1))),arm)
-COMPRT_ARCH_$(1) := armhf
-endif
+ifeq ($$(findstring freebsd,$(1)),)
+COMPRT_OBJS_$(1) += gcc_personality_v0.o
endif
-ifeq ($$(findstring eabihf,$(1)),eabihf)
-ifeq ($$(findstring armv7,$(1)),)
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins-armhf
-endif
+COMPRT_OBJS_$(1) += emutls.o
+
+ifeq ($$(findstring x86_64,$(1)),x86_64)
+COMPRT_OBJS_$(1) += \
+ x86_64/chkstk.o \
+ x86_64/chkstk2.o \
+ x86_64/floatdidf.o \
+ x86_64/floatdisf.o \
+ x86_64/floatdixf.o \
+ x86_64/floatundidf.o \
+ x86_64/floatundisf.o \
+ x86_64/floatundixf.o
endif
-ifndef COMPRT_LIB_NAME_$(1)
-COMPRT_LIB_NAME_$(1) := clang_rt.builtins-$$(COMPRT_ARCH_$(1))
-endif
+ifeq ($$(findstring i686,$$(patsubts i%86,i686,$(1))),i686)
+COMPRT_OBJS_$(1) += \
+ i386/ashldi3.o \
+ i386/ashrdi3.o \
+ i386/chkstk.o \
+ i386/chkstk2.o \
+ i386/divdi3.o \
+ i386/floatdidf.o \
+ i386/floatdisf.o \
+ i386/floatdixf.o \
+ i386/floatundidf.o \
+ i386/floatundisf.o \
+ i386/floatundixf.o \
+ i386/lshrdi3.o \
+ i386/moddi3.o \
+ i386/muldi3.o \
+ i386/udivdi3.o \
+ i386/umoddi3.o
endif
+else
+
+ifeq ($$(findstring x86_64,$(1)),x86_64)
+COMPRT_OBJS_$(1) += \
+ x86_64/floatdidf.o \
+ x86_64/floatdisf.o \
+ x86_64/floatdixf.o
+endif
-ifeq ($$(findstring windows-gnu,$(1)),windows-gnu)
-COMPRT_LIB_FILE_$(1) := lib$$(COMPRT_LIB_NAME_$(1)).a
endif
-ifeq ($$(findstring android,$(1)),android)
+# Generic ARM sources, nothing compiles on iOS though
ifeq ($$(findstring arm,$(1)),arm)
-COMPRT_LIB_FILE_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$$(COMPRT_LIB_NAME_$(1))-android)
+ifeq ($$(findstring ios,$(1)),)
+COMPRT_OBJS_$(1) += \
+ arm/aeabi_cdcmp.o \
+ arm/aeabi_cdcmpeq_check_nan.o \
+ arm/aeabi_cfcmp.o \
+ arm/aeabi_cfcmpeq_check_nan.o \
+ arm/aeabi_dcmp.o \
+ arm/aeabi_div0.o \
+ arm/aeabi_drsub.o \
+ arm/aeabi_fcmp.o \
+ arm/aeabi_frsub.o \
+ arm/aeabi_idivmod.o \
+ arm/aeabi_ldivmod.o \
+ arm/aeabi_memcmp.o \
+ arm/aeabi_memcpy.o \
+ arm/aeabi_memmove.o \
+ arm/aeabi_memset.o \
+ arm/aeabi_uidivmod.o \
+ arm/aeabi_uldivmod.o \
+ arm/bswapdi2.o \
+ arm/bswapsi2.o \
+ arm/clzdi2.o \
+ arm/clzsi2.o \
+ arm/comparesf2.o \
+ arm/divmodsi4.o \
+ arm/divsi3.o \
+ arm/modsi3.o \
+ arm/switch16.o \
+ arm/switch32.o \
+ arm/switch8.o \
+ arm/switchu8.o \
+ arm/sync_synchronize.o \
+ arm/udivmodsi4.o \
+ arm/udivsi3.o \
+ arm/umodsi3.o
endif
endif
-ifndef COMPRT_LIB_FILE_$(1)
-COMPRT_LIB_FILE_$(1) := $$(call CFG_STATIC_LIB_NAME_$(1),$$(COMPRT_LIB_NAME_$(1)))
+# Thumb sources
+ifeq ($$(findstring armv7,$(1)),armv7)
+COMPRT_OBJS_$(1) += \
+ arm/sync_fetch_and_add_4.o \
+ arm/sync_fetch_and_add_8.o \
+ arm/sync_fetch_and_and_4.o \
+ arm/sync_fetch_and_and_8.o \
+ arm/sync_fetch_and_max_4.o \
+ arm/sync_fetch_and_max_8.o \
+ arm/sync_fetch_and_min_4.o \
+ arm/sync_fetch_and_min_8.o \
+ arm/sync_fetch_and_nand_4.o \
+ arm/sync_fetch_and_nand_8.o \
+ arm/sync_fetch_and_or_4.o \
+ arm/sync_fetch_and_or_8.o \
+ arm/sync_fetch_and_sub_4.o \
+ arm/sync_fetch_and_sub_8.o \
+ arm/sync_fetch_and_umax_4.o \
+ arm/sync_fetch_and_umax_8.o \
+ arm/sync_fetch_and_umin_4.o \
+ arm/sync_fetch_and_umin_8.o \
+ arm/sync_fetch_and_xor_4.o \
+ arm/sync_fetch_and_xor_8.o
endif
-COMPRT_OUTPUT_$(1) := $$(COMPRT_BUILD_DIR_$(1))/lib/$$(COMPRT_DIR_$(1))/$$(COMPRT_LIB_FILE_$(1))
-
-ifeq ($$(findstring windows-msvc,$(1)),windows-msvc)
-COMPRT_BUILD_ARGS_$(1) := //v:m //nologo
-COMPRT_BUILD_TARGET_$(1) := lib/builtins/builtins
-COMPRT_BUILD_CC_$(1) :=
-else
-COMPRT_BUILD_ARGS_$(1) :=
-ifndef COMPRT_BUILD_TARGET_$(1)
-COMPRT_BUILD_TARGET_$(1) := $$(COMPRT_LIB_NAME_$(1))
+# VFP sources
+ifeq ($$(findstring eabihf,$(1)),eabihf)
+COMPRT_OBJS_$(1) += \
+ arm/adddf3vfp.o \
+ arm/addsf3vfp.o \
+ arm/divdf3vfp.o \
+ arm/divsf3vfp.o \
+ arm/eqdf2vfp.o \
+ arm/eqsf2vfp.o \
+ arm/extendsfdf2vfp.o \
+ arm/fixdfsivfp.o \
+ arm/fixsfsivfp.o \
+ arm/fixunsdfsivfp.o \
+ arm/fixunssfsivfp.o \
+ arm/floatsidfvfp.o \
+ arm/floatsisfvfp.o \
+ arm/floatunssidfvfp.o \
+ arm/floatunssisfvfp.o \
+ arm/gedf2vfp.o \
+ arm/gesf2vfp.o \
+ arm/gtdf2vfp.o \
+ arm/gtsf2vfp.o \
+ arm/ledf2vfp.o \
+ arm/lesf2vfp.o \
+ arm/ltdf2vfp.o \
+ arm/ltsf2vfp.o \
+ arm/muldf3vfp.o \
+ arm/mulsf3vfp.o \
+ arm/negdf2vfp.o \
+ arm/negsf2vfp.o \
+ arm/nedf2vfp.o \
+ arm/nesf2vfp.o \
+ arm/restore_vfp_d8_d15_regs.o \
+ arm/save_vfp_d8_d15_regs.o \
+ arm/subdf3vfp.o \
+ arm/subsf3vfp.o \
+ arm/truncdfsf2vfp.o \
+ arm/unorddf2vfp.o \
+ arm/unordsf2vfp.o
endif
-COMPRT_BUILD_CC_$(1) := -DCMAKE_C_COMPILER=$$(call FIND_COMPILER,$$(CC_$(1))) \
- -DCMAKE_CXX_COMPILER=$$(call FIND_COMPILER,$$(CXX_$(1)))
-ifeq ($$(findstring ios,$(1)),)
-COMPRT_BUILD_CC_$(1) := $$(COMPRT_BUILD_CC_$(1)) \
- -DCMAKE_C_FLAGS="$$(CFG_GCCISH_CFLAGS_$(1)) -Wno-error"
+ifeq ($$(findstring aarch64,$(1)),aarch64)
+COMPRT_OBJS_$(1) += \
+ comparetf2.o \
+ extenddftf2.o \
+ extendsftf2.o \
+ fixtfdi.o \
+ fixtfsi.o \
+ fixtfti.o \
+ fixunstfdi.o \
+ fixunstfsi.o \
+ fixunstfti.o \
+ floatditf.o \
+ floatsitf.o \
+ floatunditf.o \
+ floatunsitf.o \
+ multc3.o \
+ trunctfdf2.o \
+ trunctfsf2.o
endif
+ifeq ($$(findstring msvc,$(1)),msvc)
+$$(COMPRT_BUILD_DIR_$(1))/%.o: CFLAGS += -Zl -D__func__=__FUNCTION__
+else
+$$(COMPRT_BUILD_DIR_$(1))/%.o: CFLAGS += -fno-builtin -fvisibility=hidden \
+ -fomit-frame-pointer -ffreestanding
endif
-ifeq ($$(findstring emscripten,$(1)),emscripten)
+COMPRT_OBJS_$(1) := $$(COMPRT_OBJS_$(1):%=$$(COMPRT_BUILD_DIR_$(1))/%)
-# FIXME: emscripten doesn't use compiler-rt and can't build it without
-# further hacks
-$$(COMPRT_LIB_$(1)):
- touch $$@
+$$(COMPRT_BUILD_DIR_$(1))/%.o: $(S)src/compiler-rt/lib/builtins/%.c
+ @mkdir -p $$(@D)
+ @$$(call E, compile: $$@)
+ $$(Q)$$(call CFG_COMPILE_C_$(1),$$@,$$<)
-else
+$$(COMPRT_BUILD_DIR_$(1))/%.o: $(S)src/compiler-rt/lib/builtins/%.S \
+ $$(LLVM_CONFIG_$$(CFG_BUILD))
+ @mkdir -p $$(@D)
+ @$$(call E, compile: $$@)
+ $$(Q)$$(call CFG_ASSEMBLE_$(1),$$@,$$<)
-$$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD))
- @$$(call E, cmake: compiler-rt)
- $$(Q)rm -rf $$(COMPRT_BUILD_DIR_$(1))
- $$(Q)mkdir $$(COMPRT_BUILD_DIR_$(1))
- $$(Q)cd "$$(COMPRT_BUILD_DIR_$(1))"; \
- $$(CFG_CMAKE) "$(S)src/compiler-rt" \
- -DCMAKE_BUILD_TYPE=$$(LLVM_BUILD_CONFIG_MODE) \
- -DLLVM_CONFIG_PATH=$$(LLVM_CONFIG_$$(CFG_BUILD)) \
- -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=$(1) \
- -DCOMPILER_RT_BUILD_SANITIZERS=OFF \
- -DCOMPILER_RT_BUILD_EMUTLS=OFF \
- $$(COMPRT_DEFINES_$(1)) \
- $$(COMPRT_BUILD_CC_$(1)) \
- -G"$$(CFG_CMAKE_GENERATOR)"
- $$(Q)$$(CFG_CMAKE) --build "$$(COMPRT_BUILD_DIR_$(1))" \
- --target $$(COMPRT_BUILD_TARGET_$(1)) \
- --config $$(LLVM_BUILD_CONFIG_MODE) \
- -- $$(COMPRT_BUILD_ARGS_$(1)) $$(MFLAGS)
- $$(Q)cp "$$(COMPRT_OUTPUT_$(1))" $$@
+ifeq ($$(findstring msvc,$(1)),msvc)
+$$(COMPRT_BUILD_DIR_$(1))/%.o: \
+ export INCLUDE := $$(CFG_MSVC_INCLUDE_PATH_$$(HOST_$(1)))
+endif
+ifeq ($$(findstring emscripten,$(1)),emscripten)
+# FIXME: emscripten doesn't use compiler-rt and can't build it without
+# further hacks
+COMPRT_OBJS_$(1) :=
endif
+$$(COMPRT_LIB_$(1)): $$(COMPRT_OBJS_$(1))
+ @$$(call E, link: $$@)
+ $$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^
+
################################################################################
# libbacktrace
#