diff --git a/Dockerfile b/Dockerfile index c5235cd..ecd59d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -40,8 +40,6 @@ RUN cd llvm/tools/lld && \ #RUN cd llvm/projects/libcxx && \ # git am /build/patches/libcxx-*.patch -RUN git clone -b release_39 --depth=1 https://github.com/llvm-mirror/compiler-rt.git - RUN mkdir /build/prefix # Build LLVM @@ -106,20 +104,26 @@ RUN cd mingw-w64/mingw-w64-crt && \ RUN cp /build/mingw-w64/mingw-w64-libraries/winpthreads/include/* $MINGW_PREFIX/include/ -#Work around upstream issue with capital W windows.h - this is required -#by compiler-rt, see e.g. https://reviews.llvm.org/D23308. -RUN ln -s /build/prefix/armv7-w64-mingw32/include/windows.h /build/prefix/armv7-w64-mingw32/include/Windows.h - COPY patches/compiler-rt-*.patch /build/patches/ +RUN git clone -b master --depth=1 https://github.com/llvm-mirror/compiler-rt.git RUN cd compiler-rt && \ git am /build/patches/compiler-rt-*.patch # Manually build compiler-rt as a standalone project -RUN cd compiler-rt && \ - make clang_mingw-builtins-arm RANLIB=llvm-ranlib AR=llvm-ar - -RUN mkdir -p /build/prefix/lib/clang/3.9.0/lib/windows && \ - cp /build/compiler-rt/clang_mingw/builtins-arm/libcompiler_rt.a /build/prefix/lib/clang/3.9.0/lib/windows/libclang_rt.builtins-arm.a +RUN cd compiler-rt && mkdir build && cd build && cmake \ + -DCMAKE_C_COMPILER=$CC \ + -DCMAKE_CXX_COMPILER=$CXX \ + -DCMAKE_SYSTEM_NAME=Windows \ + -DCMAKE_AR=$TOOLCHAIN_PREFIX/bin/$AR \ + -DCMAKE_RANLIB=$TOOLCHAIN_PREFIX/bin/$RANLIB \ + -DCMAKE_C_COMPILER_WORKS=1 \ + -DLLVM_CONFIG_PATH=$TOOLCHAIN_PREFIX/bin/llvm-config \ + -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE="armv7--windows-gnu" \ + -DCMAKE_SIZEOF_VOID_P=4 \ + ../lib/builtins && \ + make -j4 && \ + mkdir -p /build/prefix/lib/clang/3.9.0/lib/windows && \ + cp lib/windows/libclang_rt.builtins-arm.a /build/prefix/lib/clang/3.9.0/lib/windows RUN cd mingw-w64/mingw-w64-libraries && cd winstorecompat && \ autoreconf -vif && \ diff --git a/patches/compiler-rt-0001.patch b/patches/compiler-rt-0001.patch index 725b786..81a7c8a 100644 --- a/patches/compiler-rt-0001.patch +++ b/patches/compiler-rt-0001.patch @@ -1,55 +1,330 @@ -From 1e1bd1b7ddb2b259a88fcdc3fdeea6fad16d3b11 Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?Martin=20Storsj=C3=B6?= -Date: Tue, 9 Aug 2016 23:50:59 +0300 -Subject: [PATCH] Fix "make clang_mingw-builtins-arm" with latest master +From b362e07e7a8e0d11291d1bc681eebef2cc000b74 Mon Sep 17 00:00:00 2001 +From: Martell Malone +Date: Tue, 16 Aug 2016 15:50:50 -0700 +Subject: [PATCH 1/2] builtins: add support for windows arm divide functions -This does the same to clang_linux.mk as was done in SVN rev -258863, git mirror commit 20da67f8d3f8. +The divmod functions work in the same way as the corresponding +__rt_*div* functions for windows, but their parameters are swapped. --- - make/platform/clang_linux.mk | 14 ++------------ - 1 file changed, 2 insertions(+), 12 deletions(-) + cmake/base-config-ix.cmake | 2 +- + cmake/builtin-config-ix.cmake | 2 +- + lib/builtins/CMakeLists.txt | 25 ++++++++++++++++++++++++- + lib/builtins/arm/aeabi_idivmod.S | 9 +++++++++ + lib/builtins/arm/aeabi_ldivmod.S | 12 ++++++++++++ + lib/builtins/arm/aeabi_uidivmod.S | 9 +++++++++ + lib/builtins/arm/aeabi_uldivmod.S | 12 ++++++++++++ + lib/builtins/fixdfdi.c | 8 ++++++++ + lib/builtins/fixsfdi.c | 8 ++++++++ + lib/builtins/fixunsdfdi.c | 8 ++++++++ + lib/builtins/fixunssfdi.c | 8 ++++++++ + lib/builtins/floatdidf.c | 8 ++++++++ + lib/builtins/floatdisf.c | 8 ++++++++ + lib/builtins/floatundidf.c | 8 ++++++++ + lib/builtins/floatundisf.c | 8 ++++++++ + 15 files changed, 132 insertions(+), 3 deletions(-) -diff --git a/make/platform/clang_linux.mk b/make/platform/clang_linux.mk -index 870209f..6dce2e1 100644 ---- a/make/platform/clang_linux.mk -+++ b/make/platform/clang_linux.mk -@@ -49,16 +49,14 @@ endif +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 830e443..644cea2 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -153,7 +153,7 @@ macro(test_targets) + elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "mips") + test_target_arch(mips "" "-mips32r2" "--target=mips-linux-gnu") + test_target_arch(mips64 "" "-mips64r2" "--target=mips64-linux-gnu" "-mabi=64") +- elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm") ++ elseif("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "arm|armv7") + if(WIN32) + test_target_arch(arm "" "" "") + else() +diff --git a/cmake/builtin-config-ix.cmake b/cmake/builtin-config-ix.cmake +index 9289618..bf15570 100644 +--- a/cmake/builtin-config-ix.cmake ++++ b/cmake/builtin-config-ix.cmake +@@ -2,7 +2,7 @@ include(BuiltinTests) + include(CheckCSourceCompiles) - # Build runtime libraries for i386. - ifeq ($(call contains,$(SupportedArches),i386),true) --Configs += builtins-i386 profile-i386 -+Configs += builtins-i386 - Arch.builtins-i386 := i386 --Arch.profile-i386 := i386 - endif + # Make all the tests only check the compiler +-set(TEST_COMPILE_ONLY On) ++set(TEST_COMPILE_ONLY TRUE) - # Build runtime libraries for x86_64. - ifeq ($(call contains,$(SupportedArches),x86_64),true) --Configs += builtins-x86_64 profile-x86_64 -+Configs += builtins-x86_64 - Arch.builtins-x86_64 := x86_64 --Arch.profile-x86_64 := x86_64 - endif + builtin_check_c_compiler_flag(-fPIC COMPILER_RT_HAS_FPIC_FLAG) + builtin_check_c_compiler_flag(-fPIE COMPILER_RT_HAS_FPIE_FLAG) +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index a7d665e..18bdee9 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -367,7 +367,30 @@ set(arm_Thumb1_SOURCES + ${arm_Thumb1_VFPv2_SOURCES} + ${arm_Thumb1_icache_SOURCES}) - endif -@@ -71,17 +69,9 @@ CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer +-if(NOT WIN32) ++if(WIN32) ++ set(arm_SOURCES ++ fixdfdi.c ++ fixsfdi.c ++ fixunsdfdi.c ++ fixunssfdi.c ++ floatdidf.c ++ floatdisf.c ++ floatundidf.c ++ floatundisf.c ++ arm/aeabi_idivmod.S ++ arm/aeabi_ldivmod.S ++ arm/aeabi_uidivmod.S ++ arm/aeabi_uldivmod.S ++ divmoddi4.c ++ divmodsi4.c ++ divdi3.c ++ divsi3.c ++ moddi3.c ++ udivmoddi4.c ++ udivmodsi4.c ++ udivsi3.c ++ umoddi3.c) ++else(WIN32) + # TODO the EABI sources should only be added to EABI targets + set(arm_SOURCES + ${arm_SOURCES} +diff --git a/lib/builtins/arm/aeabi_idivmod.S b/lib/builtins/arm/aeabi_idivmod.S +index 2fcad86..5dab937 100644 +--- a/lib/builtins/arm/aeabi_idivmod.S ++++ b/lib/builtins/arm/aeabi_idivmod.S +@@ -15,12 +15,21 @@ + // return {quot, rem}; + // } - CFLAGS.builtins-i386 := $(CFLAGS) -m32 - CFLAGS.builtins-x86_64 := $(CFLAGS) -m64 --CFLAGS.profile-i386 := $(CFLAGS) -m32 --CFLAGS.profile-x86_64 := $(CFLAGS) -m64 ++#ifdef __MINGW32__ ++#define __aeabi_idivmod __rt_sdiv ++#endif ++ + .syntax unified + .p2align 2 + DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod) + push { lr } + sub sp, sp, #4 + mov r2, sp ++#ifdef __MINGW32__ ++ mov r3, r0 ++ mov r0, r1 ++ mov r1, r3 ++#endif + bl SYMBOL_NAME(__divmodsi4) + ldr r1, [sp] + add sp, sp, #4 +diff --git a/lib/builtins/arm/aeabi_ldivmod.S b/lib/builtins/arm/aeabi_ldivmod.S +index 9f161f3..4821e82 100644 +--- a/lib/builtins/arm/aeabi_ldivmod.S ++++ b/lib/builtins/arm/aeabi_ldivmod.S +@@ -16,6 +16,10 @@ + // return {quot, rem}; + // } - FUNCTIONS.builtins-i386 := $(CommonFunctions) $(ArchFunctions.i386) - FUNCTIONS.builtins-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64) --FUNCTIONS.profile-i386 := GCDAProfiling InstrProfiling InstrProfilingBuffer \ -- InstrProfilingFile InstrProfilingPlatformOther \ -- InstrProfilingRuntime InstrProfilingUtil \ -- InstrProfilingWriter InstrProfilingValue \ -- InstrProfilingMerge InstrProfilingMergeFile --FUNCTIONS.profile-x86_64 := $(FUNCTIONS.profile-i386) ++#ifdef __MINGW32__ ++#define __aeabi_ldivmod __rt_sdiv64 ++#endif ++ + .syntax unified + .p2align 2 + DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod) +@@ -23,6 +27,14 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_ldivmod) + sub sp, sp, #16 + add r12, sp, #8 + str r12, [sp] ++#ifdef __MINGW32__ ++ mov r12, r0 ++ mov r0, r2 ++ mov r2, r12 ++ mov r12, r1 ++ mov r1, r3 ++ mov r3, r12 ++#endif + bl SYMBOL_NAME(__divmoddi4) + ldr r2, [sp, #8] + ldr r3, [sp, #12] +diff --git a/lib/builtins/arm/aeabi_uidivmod.S b/lib/builtins/arm/aeabi_uidivmod.S +index e1e12d9..6606a50 100644 +--- a/lib/builtins/arm/aeabi_uidivmod.S ++++ b/lib/builtins/arm/aeabi_uidivmod.S +@@ -16,12 +16,21 @@ + // return {quot, rem}; + // } - # Always use optimized variants. - OPTIMIZED := 1 ++#ifdef __MINGW32__ ++#define __aeabi_uidivmod __rt_udiv ++#endif ++ + .syntax unified + .p2align 2 + DEFINE_COMPILERRT_FUNCTION(__aeabi_uidivmod) + push { lr } + sub sp, sp, #4 + mov r2, sp ++#ifdef __MINGW32__ ++ mov r3, r0 ++ mov r0, r1 ++ mov r1, r3 ++#endif + bl SYMBOL_NAME(__udivmodsi4) + ldr r1, [sp] + add sp, sp, #4 +diff --git a/lib/builtins/arm/aeabi_uldivmod.S b/lib/builtins/arm/aeabi_uldivmod.S +index e8aaef2..60fee45 100644 +--- a/lib/builtins/arm/aeabi_uldivmod.S ++++ b/lib/builtins/arm/aeabi_uldivmod.S +@@ -16,6 +16,10 @@ + // return {quot, rem}; + // } + ++#ifdef __MINGW32__ ++#define __aeabi_uldivmod __rt_udiv64 ++#endif ++ + .syntax unified + .p2align 2 + DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod) +@@ -23,6 +27,14 @@ DEFINE_COMPILERRT_FUNCTION(__aeabi_uldivmod) + sub sp, sp, #16 + add r12, sp, #8 + str r12, [sp] ++#ifdef __MINGW32__ ++ mov r12, r0 ++ mov r0, r2 ++ mov r2, r12 ++ mov r12, r1 ++ mov r1, r3 ++ mov r3, r12 ++#endif + bl SYMBOL_NAME(__udivmoddi4) + ldr r2, [sp, #8] + ldr r3, [sp, #12] +diff --git a/lib/builtins/fixdfdi.c b/lib/builtins/fixdfdi.c +index 14283ef..4bcd432 100644 +--- a/lib/builtins/fixdfdi.c ++++ b/lib/builtins/fixdfdi.c +@@ -44,3 +44,11 @@ __fixdfdi(fp_t a) { + } + + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI di_int ++__dtoi64(double a) ++{ ++ return __fixdfdi(a); ++} ++#endif +diff --git a/lib/builtins/fixsfdi.c b/lib/builtins/fixsfdi.c +index fab47e2..24f6e83 100644 +--- a/lib/builtins/fixsfdi.c ++++ b/lib/builtins/fixsfdi.c +@@ -45,3 +45,11 @@ __fixsfdi(fp_t a) { + } + + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI di_int ++__stoi64(float a) ++{ ++ return __fixsfdi(a); ++} ++#endif +diff --git a/lib/builtins/fixunsdfdi.c b/lib/builtins/fixunsdfdi.c +index 4b0bc9e..5a8bb5c 100644 +--- a/lib/builtins/fixunsdfdi.c ++++ b/lib/builtins/fixunsdfdi.c +@@ -42,3 +42,11 @@ __fixunsdfdi(fp_t a) { + } + + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI du_int ++__dtou64(double a) ++{ ++ return __fixunsdfdi(a); ++} ++#endif +diff --git a/lib/builtins/fixunssfdi.c b/lib/builtins/fixunssfdi.c +index f8ebab8..72fdf4d 100644 +--- a/lib/builtins/fixunssfdi.c ++++ b/lib/builtins/fixunssfdi.c +@@ -43,3 +43,11 @@ __fixunssfdi(fp_t a) { + } + + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI du_int ++__stou64(float a) ++{ ++ return __fixunssfdi(a); ++} ++#endif +diff --git a/lib/builtins/floatdidf.c b/lib/builtins/floatdidf.c +index 2b023ad..d13f832 100644 +--- a/lib/builtins/floatdidf.c ++++ b/lib/builtins/floatdidf.c +@@ -105,3 +105,11 @@ __floatdidf(di_int a) + return fb.f; + } + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI double ++__i64tod(di_int a) ++{ ++ return __floatdidf(a); ++} ++#endif +diff --git a/lib/builtins/floatdisf.c b/lib/builtins/floatdisf.c +index 3e47580..8f9bf9d 100644 +--- a/lib/builtins/floatdisf.c ++++ b/lib/builtins/floatdisf.c +@@ -78,3 +78,11 @@ __floatdisf(di_int a) + ((su_int)a & 0x007FFFFF); /* mantissa */ + return fb.f; + } ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI float ++__i64tos(di_int a) ++{ ++ return __floatdisf(a); ++} ++#endif +diff --git a/lib/builtins/floatundidf.c b/lib/builtins/floatundidf.c +index cfd3a7a..e7f63bf 100644 +--- a/lib/builtins/floatundidf.c ++++ b/lib/builtins/floatundidf.c +@@ -104,3 +104,11 @@ __floatundidf(du_int a) + return fb.f; + } + #endif ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI double ++__u64tod(du_int a) ++{ ++ return __floatundidf(a); ++} ++#endif +diff --git a/lib/builtins/floatundisf.c b/lib/builtins/floatundisf.c +index 713a44a..3716ec2 100644 +--- a/lib/builtins/floatundisf.c ++++ b/lib/builtins/floatundisf.c +@@ -75,3 +75,11 @@ __floatundisf(du_int a) + ((su_int)a & 0x007FFFFF); /* mantissa */ + return fb.f; + } ++ ++#ifdef __MINGW32__ ++COMPILER_RT_ABI float ++__u64tos(du_int a) ++{ ++ return __floatundisf(a); ++} ++#endif -- 2.7.4 diff --git a/patches/compiler-rt-0002.patch b/patches/compiler-rt-0002.patch new file mode 100644 index 0000000..00f4fd2 --- /dev/null +++ b/patches/compiler-rt-0002.patch @@ -0,0 +1,44 @@ +From 608efc9306e10f9e9daf0ea981f53deb98851772 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +Date: Thu, 25 Aug 2016 10:02:16 +0300 +Subject: [PATCH 2/2] builtins: Allow building the necessary helper functions + for msvc mode with cmake + +--- + lib/builtins/CMakeLists.txt | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 18bdee9..003d5b8 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -367,7 +367,7 @@ set(arm_Thumb1_SOURCES + ${arm_Thumb1_VFPv2_SOURCES} + ${arm_Thumb1_icache_SOURCES}) + +-if(WIN32) ++if(WIN32 AND MINGW) + set(arm_SOURCES + fixdfdi.c + fixsfdi.c +@@ -390,6 +390,17 @@ if(WIN32) + udivmodsi4.c + udivsi3.c + umoddi3.c) ++elseif(WIN32) ++ set(arm_SOURCES ++ umoddi3.c ++ moddi3.c ++ udivmoddi4.c ++ divsi3.c ++ udivsi3.c ++ umodsi3.c ++ udivdi3.c ++ modsi3.c ++ divdi3.c) + else(WIN32) + # TODO the EABI sources should only be added to EABI targets + set(arm_SOURCES +-- +2.7.4 +