diff --git a/configure b/configure index 1d95965150cae..e3b6bf794c0eb 100755 --- a/configure +++ b/configure @@ -945,162 +945,6 @@ then fi fi -# If the clang isn't already enabled, check for GCC, and if it is missing, turn -# on clang as a backup. -if [ -z "$CFG_ENABLE_CLANG" ] -then - CFG_GCC_VERSION=$("$CFG_GCC" --version 2>&1) - if [ $? -ne 0 ] - then - step_msg "GCC not installed, will try using Clang" - CFG_ENABLE_CLANG=1 - fi -fi - -# Okay, at this point, we have made up our minds about whether we are -# going to force CFG_ENABLE_CLANG or not; save the setting if so. -if [ -n "$CFG_ENABLE_CLANG" ] -then - putvar CFG_ENABLE_CLANG -fi - -# Same with jemalloc. save the setting here. -if [ -n "$CFG_DISABLE_JEMALLOC" ] -then - putvar CFG_DISABLE_JEMALLOC -fi - -if [ -n "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ] -then - step_msg "using custom LLVM at $CFG_LLVM_ROOT" - - LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config" - LLVM_VERSION=$($LLVM_CONFIG --version) - - case $LLVM_VERSION in - (3.[5-8]*) - msg "found ok version of LLVM: $LLVM_VERSION" - ;; - (*) - err "bad LLVM version: $LLVM_VERSION, need >=3.5" - ;; - esac -fi - -# Even when the user overrides the choice of CC, still try to detect -# clang to disable some clang-specific warnings. We here draw a -# distinction between: -# -# CFG_ENABLE_CLANG : passed --enable-clang, or host "requires" clang, -# CFG_USING_CLANG : compiler (clang / gcc / $CC) looks like clang. -# -# This distinction is important because there are some safeguards we -# would prefer to skip when merely CFG_USING_CLANG is set; but when -# CFG_ENABLE_CLANG is set, that indicates that we are opting into -# running such safeguards. - -if [ -n "$CC" ] -then - msg "skipping compiler inference steps; using provided CC=$CC" - CFG_CC="$CC" - - CFG_OSX_CC_VERSION=$("$CFG_CC" --version 2>&1 | grep "clang") - if [ $? -eq 0 ] - then - step_msg "note, user-provided CC looks like clang; CC=$CC." - CFG_USING_CLANG=1 - putvar CFG_USING_CLANG - fi -else - if [ -n "$CFG_ENABLE_CLANG" ] - then - if [ -z "$CFG_CLANG" ] - then - err "clang requested but not found" - fi - CFG_CC="$CFG_CLANG" - CFG_USING_CLANG=1 - putvar CFG_USING_CLANG - else - CFG_CC="gcc" - fi -fi - -if [ -n "$CFG_ENABLE_CLANG" ] -then - case "$CC" in - (''|*clang) - CFG_CLANG_REPORTED_VERSION=$($CFG_CC --version | grep version) - - if echo $CFG_CLANG_REPORTED_VERSION | grep -q "(based on LLVM "; then - CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*(based on LLVM \(.*\))/\1/') - elif echo $CFG_CLANG_REPORTED_VERSION | grep -q "Apple LLVM"; then - CFG_OSX_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/') - else - CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/') - fi - - if [ -n "$CFG_OSX_CLANG_VERSION" ] - then - case $CFG_OSX_CLANG_VERSION in - (7.0*) - step_msg "found ok version of APPLE CLANG: $CFG_OSX_CLANG_VERSION" - ;; - (*) - err "bad APPLE CLANG version: $CFG_OSX_CLANG_VERSION, need >=7.0" - ;; - esac - else - case $CFG_CLANG_VERSION in - (3.2* | 3.3* | 3.4* | 3.5* | 3.6* | 3.7* | 3.8*) - step_msg "found ok version of CLANG: $CFG_CLANG_VERSION" - ;; - (*) - err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn" - ;; - esac - fi - - if [ -z "$CC" ] - then - CFG_CC="clang" - CFG_CXX="clang++" - fi - esac -fi - -if [ -n "$CFG_ENABLE_CCACHE" ] -then - if [ -z "$CFG_CCACHE" ] - then - err "ccache requested but not found" - fi - - CFG_CC="ccache $CFG_CC" -fi - -if [ -z "$CC" -a -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ] -then - err "either clang or gcc is required" -fi - -# All safeguards based on $CFG_ENABLE_CLANG should occur before this -# point in the script; after this point, script logic should inspect -# $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG. - -# Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS} -envopt CC -envopt CXX -envopt CPP -envopt CFLAGS -envopt CXXFLAGS - -# stdc++ name in use -# used to manage non-standard name (on OpenBSD for example) -program_transform_name=$($CFG_CC -v 2>&1 | sed -n "s/.*--program-transform-name='\([^']*\)'.*/\1/p") -CFG_STDCPP_NAME=$(echo "stdc++" | sed "${program_transform_name}") -putvar CFG_STDCPP_NAME - # a little post-processing of various config values CFG_PREFIX=${CFG_PREFIX%/} CFG_MANDIR=${CFG_MANDIR%/} @@ -1214,15 +1058,18 @@ $ pacman -R python2 && pacman -S mingw-w64-x86_64-python2 " fi - # MSVC requires cmake because that's how we're going to build LLVM - probe_need CFG_CMAKE cmake - - # There are three builds of cmake on windows: MSVC, MinGW and Cygwin - # The Cygwin build does not have generators for Visual Studio, so - # detect that here and error. - if ! "$CFG_CMAKE" --help | sed -n '/^Generators/,$p' | grep 'Visual Studio' > /dev/null + # Only probe for cmake if we actually need to build LLVM + if [ -z $CFG_LLVM_ROOT ] then - err " + # MSVC requires cmake because that's how we're going to build LLVM + probe_need CFG_CMAKE cmake + + # There are three builds of cmake on windows: MSVC, MinGW and Cygwin + # The Cygwin build does not have generators for Visual Studio, so + # detect that here and error. + if ! "$CFG_CMAKE" --help | sed -n '/^Generators/,$p' | grep 'Visual Studio' > /dev/null + then + err " cmake does not support Visual Studio generators. @@ -1235,6 +1082,7 @@ package instead of cmake: $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake " + fi fi # Use the REG program to figure out where VS is installed @@ -1300,6 +1148,162 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake esac done +# If we're not targetting MSVC, and clang isn't already enabled, check for GCC, +# and if it is missing, turn on clang as a backup. +if [ -z "$CFG_MSVC_ROOT" -a -z "$CFG_ENABLE_CLANG" ] +then + CFG_GCC_VERSION=$("$CFG_GCC" --version 2>&1) + if [ $? -ne 0 ] + then + step_msg "GCC not installed, will try using Clang" + CFG_ENABLE_CLANG=1 + fi +fi + +# Okay, at this point, we have made up our minds about whether we are +# going to force CFG_ENABLE_CLANG or not; save the setting if so. +if [ -n "$CFG_ENABLE_CLANG" ] +then + putvar CFG_ENABLE_CLANG +fi + +# Same with jemalloc. save the setting here. +if [ -n "$CFG_DISABLE_JEMALLOC" ] +then + putvar CFG_DISABLE_JEMALLOC +fi + +if [ -n "$CFG_LLVM_ROOT" -a -z "$CFG_DISABLE_LLVM_VERSION_CHECK" -a -e "$CFG_LLVM_ROOT/bin/llvm-config" ] +then + step_msg "using custom LLVM at $CFG_LLVM_ROOT" + + LLVM_CONFIG="$CFG_LLVM_ROOT/bin/llvm-config" + LLVM_VERSION=$($LLVM_CONFIG --version) + + case $LLVM_VERSION in + (3.[5-8]*) + msg "found ok version of LLVM: $LLVM_VERSION" + ;; + (*) + err "bad LLVM version: $LLVM_VERSION, need >=3.5" + ;; + esac +fi + +# Even when the user overrides the choice of CC, still try to detect +# clang to disable some clang-specific warnings. We here draw a +# distinction between: +# +# CFG_ENABLE_CLANG : passed --enable-clang, or host "requires" clang, +# CFG_USING_CLANG : compiler (clang / gcc / $CC) looks like clang. +# +# This distinction is important because there are some safeguards we +# would prefer to skip when merely CFG_USING_CLANG is set; but when +# CFG_ENABLE_CLANG is set, that indicates that we are opting into +# running such safeguards. + +if [ -n "$CC" ] +then + msg "skipping compiler inference steps; using provided CC=$CC" + CFG_CC="$CC" + + CFG_OSX_CC_VERSION=$("$CFG_CC" --version 2>&1 | grep "clang") + if [ $? -eq 0 ] + then + step_msg "note, user-provided CC looks like clang; CC=$CC." + CFG_USING_CLANG=1 + putvar CFG_USING_CLANG + fi +else + if [ -n "$CFG_ENABLE_CLANG" ] + then + if [ -z "$CFG_CLANG" ] + then + err "clang requested but not found" + fi + CFG_CC="$CFG_CLANG" + CFG_USING_CLANG=1 + putvar CFG_USING_CLANG + else + CFG_CC="gcc" + fi +fi + +if [ -n "$CFG_ENABLE_CLANG" ] +then + case "$CC" in + (''|*clang) + CFG_CLANG_REPORTED_VERSION=$($CFG_CC --version | grep version) + + if echo $CFG_CLANG_REPORTED_VERSION | grep -q "(based on LLVM "; then + CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*(based on LLVM \(.*\))/\1/') + elif echo $CFG_CLANG_REPORTED_VERSION | grep -q "Apple LLVM"; then + CFG_OSX_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/') + else + CFG_CLANG_VERSION=$(echo $CFG_CLANG_REPORTED_VERSION | sed 's/.*version \(.*\) .*/\1/') + fi + + if [ -n "$CFG_OSX_CLANG_VERSION" ] + then + case $CFG_OSX_CLANG_VERSION in + (7.0*) + step_msg "found ok version of APPLE CLANG: $CFG_OSX_CLANG_VERSION" + ;; + (*) + err "bad APPLE CLANG version: $CFG_OSX_CLANG_VERSION, need >=7.0" + ;; + esac + else + case $CFG_CLANG_VERSION in + (3.2* | 3.3* | 3.4* | 3.5* | 3.6* | 3.7* | 3.8*) + step_msg "found ok version of CLANG: $CFG_CLANG_VERSION" + ;; + (*) + err "bad CLANG version: $CFG_CLANG_VERSION, need >=3.0svn" + ;; + esac + fi + + if [ -z "$CC" ] + then + CFG_CC="clang" + CFG_CXX="clang++" + fi + esac +fi + +if [ -n "$CFG_ENABLE_CCACHE" ] +then + if [ -z "$CFG_CCACHE" ] + then + err "ccache requested but not found" + fi + + CFG_CC="ccache $CFG_CC" +fi + +if [ -z "$CFG_MSVC_ROOT" -a -z "$CC" -a -z "$CFG_ENABLE_CLANG" -a -z "$CFG_GCC" ] +then + err "either clang or gcc is required" +fi + +# All safeguards based on $CFG_ENABLE_CLANG should occur before this +# point in the script; after this point, script logic should inspect +# $CFG_USING_CLANG rather than $CFG_ENABLE_CLANG. + +# Set CFG_{CC,CXX,CPP,CFLAGS,CXXFLAGS} +envopt CC +envopt CXX +envopt CPP +envopt CFLAGS +envopt CXXFLAGS + +# stdc++ name in use +# used to manage non-standard name (on OpenBSD for example) +program_transform_name=$($CFG_CC -v 2>&1 | sed -n "s/.*--program-transform-name='\([^']*\)'.*/\1/p") +CFG_STDCPP_NAME=$(echo "stdc++" | sed "${program_transform_name}") +putvar CFG_STDCPP_NAME + if [ -n "$CFG_PERF" ] then HAVE_PERF_LOGFD=`$CFG_PERF stat --log-fd 2>&1 | grep 'unknown option'` @@ -1418,6 +1422,10 @@ then msg "git: submodule deinit src/jemalloc" "${CFG_GIT}" submodule deinit src/jemalloc fi + if [ -n "${CFG_MSVC_ROOT}" ]; then + msg "git: submodule deinit src/compiler-rt" + "${CFG_GIT}" submodule deinit src/compiler-rt + fi msg "git: submodule update" "${CFG_GIT}" submodule update diff --git a/mk/rt.mk b/mk/rt.mk index 1f60aaed4730b..1f51aabaf2095 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -202,6 +202,27 @@ endif # compiler-rt ################################################################################ +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 + +ifeq ($$(findstring msvc,$(1)),msvc) +$$(COMPRT_BUILD_DIR_$(1))/compiler-rt.c: + @$$(call E, make: fake compiler-rt) + @mkdir -p $$(@D) + touch $$(COMPRT_BUILD_DIR_$(1))/compiler-rt.c + +OBJS_compiler-rt_$(1) := $$(RT_OUTPUT_DIR_$(1))/compiler-rt.o + +$$(RT_OUTPUT_DIR_$(1))/compiler-rt.o: $$(COMPRT_BUILD_DIR_$(1))/compiler-rt.c + @mkdir -p $$(@D) + $$(Q)$$(call CFG_COMPILE_C_$(1), $$@, \ + $$(RUNTIME_CFLAGS_$(1))) $$< + +$$(COMPRT_LIB_$(1)): $$(OBJS_compiler-rt_$(1)) + @$$(call E, link: $$@) + $$(Q)$$(call CFG_CREATE_ARCHIVE_$(1),$$@) $$^ +else # if not msvc ifdef CFG_ENABLE_FAST_MAKE COMPRT_DEPS := $(S)/.gitmodules else @@ -212,27 +233,9 @@ COMPRT_DEPS := $(wildcard \ $(S)src/compiler-rt/*/*/*/*) endif -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 - -# Note that on MSVC-targeting builds we hardwire CC/AR to gcc/ar even though -# we're targeting MSVC. This is because although compiler-rt has a CMake build -# config I can't actually figure out how to use it, so I'm not sure how to use -# cl.exe to build the objects. Additionally, the compiler-rt library when built -# with gcc has the same ABI as cl.exe, so they're largely compatible COMPRT_CC_$(1) := $$(CC_$(1)) COMPRT_AR_$(1) := $$(AR_$(1)) COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -ifeq ($$(findstring msvc,$(1)),msvc) -COMPRT_CC_$(1) := gcc -COMPRT_AR_$(1) := ar -ifeq ($$(findstring i686,$(1)),i686) -COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m32 -else -COMPRT_CFLAGS_$(1) := $$(CFG_GCCISH_CFLAGS_$(1)) -m64 -endif -endif $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) @$$(call E, make: compiler-rt) @@ -246,7 +249,7 @@ $$(COMPRT_LIB_$(1)): $$(COMPRT_DEPS) $$(MKFILE_DEPS) TargetTriple=$(1) \ triple-builtins $$(Q)cp $$(COMPRT_BUILD_DIR_$(1))/triple/builtins/libcompiler_rt.a $$@ - +endif # msvc ################################################################################ # libbacktrace # diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index 1b7cbb050d1d9..652ade2cd6241 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -255,10 +255,22 @@ impl Float for f32 { #[inline] fn recip(self) -> f32 { 1.0 / self } - #[inline] + #[inline] #[cfg(not(target_env = "msvc"))] fn powi(self, n: i32) -> f32 { unsafe { intrinsics::powif32(self, n) } } + #[inline] #[cfg(target_env = "msvc")] + fn powi(self, n: i32) -> f32 { + let (mut r, mut a) = (1., self); + let mut b = if n < 0 { n.wrapping_neg() as u32 } else { n as u32 }; + loop { + if b & 1 != 0 { r *= a } + b >>= 1; + if b == 0 { break } + a *= a; + } + if n < 0 { r.recip() } else { r } + } /// Converts to degrees, assuming the number is in radians. #[inline] diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index a057e5fe51a7d..e1b07a7edbf76 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -255,10 +255,22 @@ impl Float for f64 { #[inline] fn recip(self) -> f64 { 1.0 / self } - #[inline] + #[inline] #[cfg(not(target_env = "msvc"))] fn powi(self, n: i32) -> f64 { unsafe { intrinsics::powif64(self, n) } } + #[inline] #[cfg(target_env = "msvc")] + fn powi(self, n: i32) -> f64 { + let (mut r, mut a) = (1., self); + let mut b = if n < 0 { n.wrapping_neg() as u32 } else { n as u32 }; + loop { + if b & 1 != 0 { r *= a } + b >>= 1; + if b == 0 { break } + a *= a; + } + if n < 0 { r.recip() } else { r } + } /// Converts to degrees, assuming the number is in radians. #[inline] diff --git a/src/librustc_back/target/windows_msvc_base.rs b/src/librustc_back/target/windows_msvc_base.rs index fe9ac32ee8fb5..191d95bf37e48 100644 --- a/src/librustc_back/target/windows_msvc_base.rs +++ b/src/librustc_back/target/windows_msvc_base.rs @@ -61,6 +61,7 @@ pub fn opts() -> TargetOptions { ], archive_format: "gnu".to_string(), exe_allocation_crate: super::best_allocator(), + no_compiler_rt: true, .. Default::default() }