From 9cd0782172a3dea05c6faedb5df5ef1595d16beb Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Sat, 24 Aug 2019 09:39:34 -0700 Subject: [PATCH] Use system compiler-rt --- debian/README.source | 7 - debian/changelog | 1 + debian/control | 2 + debian/copyright | 23 -- debian/patches/d-use-system-compiler-rt.patch | 337 ++++++++++++++++++ debian/patches/gcc-4.8-aarch64-ice.diff | 25 -- debian/patches/series | 4 +- 7 files changed, 341 insertions(+), 58 deletions(-) create mode 100644 debian/patches/d-use-system-compiler-rt.patch delete mode 100644 debian/patches/gcc-4.8-aarch64-ice.diff diff --git a/debian/README.source b/debian/README.source index 7c5df3178d..f34ded1869 100644 --- a/debian/README.source +++ b/debian/README.source @@ -17,13 +17,6 @@ The upstream source package embeds many external libraries. We make a great effort to remove them and use system versions where possible, but there are a few more remaining: - * compiler-rt from https://github.com/rust-lang/compiler-rt - -> system-wide compiler-rt fails during linkage - - Bug reported upstream, still to be fixed, see: - - https://github.com/rust-lang/rust/issues/15054 - - https://github.com/rust-lang/rust/issues/15708 - * vendor/backtrace-sys, vendor/dlmalloc, vendor/walkdir These are small C libraries designed to be statically linked; their upstream diff --git a/debian/changelog b/debian/changelog index 90d008ea7e..9725c0fe19 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ rustc (1.37.0+dfsg1-1~exp1) UNRELEASED; urgency=medium * New upstream release. + * Use system compiler-rt. -- Ximin Luo Fri, 23 Aug 2019 03:57:40 -0700 diff --git a/debian/control b/debian/control index 6fb8ef4086..88f03e7245 100644 --- a/debian/control +++ b/debian/control @@ -14,6 +14,8 @@ Build-Depends: debhelper (>= 9), rustc:native (<= 1.37.0++) , llvm-8-dev:native, llvm-8-tools:native, + libclang-common-8-dev:native, + libclang-common-8-dev, libllvm8, autotools-dev, cmake (>= 3.0) | cmake3, diff --git a/debian/copyright b/debian/copyright index 1b7fc209a7..0891e5cfa8 100644 --- a/debian/copyright +++ b/debian/copyright @@ -24,20 +24,6 @@ Files-Excluded: src/tools/remote-test-server src/tools/rustfmt src/tools/miri -# Extraneous stuff from compiler-rt that's not needed by Rust - vendor/compiler_builtins/compiler-rt/cmake - vendor/compiler_builtins/compiler-rt/docs - vendor/compiler_builtins/compiler-rt/include - vendor/compiler_builtins/compiler-rt/lib/*san - vendor/compiler_builtins/compiler-rt/lib/fuzzer - vendor/compiler_builtins/compiler-rt/lib/interception - vendor/compiler_builtins/compiler-rt/lib/profile - vendor/compiler_builtins/compiler-rt/lib/sanitizer_common - vendor/compiler_builtins/compiler-rt/lib/scudo - vendor/compiler_builtins/compiler-rt/lib/xray - vendor/compiler_builtins/compiler-rt/test - vendor/compiler_builtins/compiler-rt/unittests - vendor/compiler_builtins/compiler-rt/www # Embedded C libraries vendor/libz-sys/src/zlib* vendor/lzma-sys*/xz-* @@ -235,15 +221,6 @@ Copyright: 2016-2019 Jorge Aparicio License: MIT or Apache-2.0 Comment: see https://github.com/rust-lang-nursery/compiler-builtins -Files: vendor/compiler_builtins/compiler-rt/* -Copyright: 2009-2015 Howard Hinnant - 2009-2015 The CompileRT Developers (see src/compiler-rt/CREDITS.TXT) -License: BSD-3-clause or MIT - -Files: vendor/compiler_builtins/compiler-rt/lib/BlocksRuntime/* -Copyright: 2008-2010 Apple, Inc. -License: MIT - Files: src/librustdoc/html/static/FiraSans* Copyright: 2014, Mozilla Foundation, 2014, Telefonica S.A. License: SIL-OPEN-FONT diff --git a/debian/patches/d-use-system-compiler-rt.patch b/debian/patches/d-use-system-compiler-rt.patch new file mode 100644 index 0000000000..f5e725d012 --- /dev/null +++ b/debian/patches/d-use-system-compiler-rt.patch @@ -0,0 +1,337 @@ +commit 484e4a2e83ca6cbfb96957996d57262792da0a30 +Author: Ximin Luo +Date: Sun May 19 19:15:20 2019 -0700 + + Use system compiler-rt from clang + +--- a/vendor/compiler_builtins/Cargo.toml ++++ b/vendor/compiler_builtins/Cargo.toml +@@ -43,7 +43,13 @@ + optional = true + + [features] +-c = ["cc"] ++c-vendor = ["cc"] ++ ++# Link against system clang_rt.* libraries. ++# LLVM_CONFIG or CLANG (more reliable) must be set. ++c-system = [] ++ ++c = ["c-vendor"] + compiler-builtins = [] + default = ["compiler-builtins"] + mangled-names = [] +--- a/vendor/compiler_builtins/build.rs ++++ b/vendor/compiler_builtins/build.rs +@@ -37,7 +37,7 @@ + // mangling names though we assume that we're also in test mode so we don't + // build anything and we rely on the upstream implementation of compiler-rt + // functions +- if !cfg!(feature = "mangled-names") && cfg!(feature = "c") { ++ if !cfg!(feature = "mangled-names") && cfg!(any(feature = "c-vendor", feature = "c-system")) { + // Don't use a C compiler for these targets: + // + // * wasm32 - clang 8 for wasm is somewhat hard to come by and it's +@@ -47,8 +47,10 @@ + // compiler nor is cc-rs ready for compilation to riscv (at this + // time). This can probably be removed in the future + if !target.contains("wasm32") && !target.contains("nvptx") && !target.starts_with("riscv") { +- #[cfg(feature = "c")] +- c::compile(&llvm_target); ++ #[cfg(feature = "c-vendor")] ++ c_vendor::compile(&llvm_target); ++ #[cfg(feature = "c-system")] ++ c_system::compile(&llvm_target); + } + } + +@@ -70,17 +72,14 @@ + } + } + +-#[cfg(feature = "c")] +-mod c { +- extern crate cc; +- ++#[cfg(any(feature = "c-vendor", feature = "c-system"))] ++mod sources { + use std::collections::BTreeMap; + use std::env; +- use std::path::PathBuf; + +- struct Sources { ++ pub struct Sources { + // SYMBOL -> PATH TO SOURCE +- map: BTreeMap<&'static str, &'static str>, ++ pub map: BTreeMap<&'static str, &'static str>, + } + + impl Sources { +@@ -117,39 +116,11 @@ + } + } + +- /// Compile intrinsics from the compiler-rt C source code +- pub fn compile(llvm_target: &[&str]) { ++ pub fn get_sources(llvm_target: &[&str]) -> Sources { + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); + let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap(); +- let cfg = &mut cc::Build::new(); +- +- cfg.warnings(false); +- +- if target_env == "msvc" { +- // Don't pull in extra libraries on MSVC +- cfg.flag("/Zl"); +- +- // Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP +- cfg.define("__func__", Some("__FUNCTION__")); +- } else { +- // Turn off various features of gcc and such, mostly copying +- // compiler-rt's build system already +- cfg.flag("-fno-builtin"); +- cfg.flag("-fvisibility=hidden"); +- cfg.flag("-ffreestanding"); +- // Avoid the following warning appearing once **per file**: +- // clang: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument] +- // +- // Note that compiler-rt's build system also checks +- // +- // `check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)` +- // +- // in https://github.com/rust-lang/compiler-rt/blob/c8fbcb3/cmake/config-ix.cmake#L19. +- cfg.flag_if_supported("-fomit-frame-pointer"); +- cfg.define("VISIBILITY_HIDDEN", None); +- } + + let mut sources = Sources::new(); + sources.extend(&[ +@@ -411,6 +382,48 @@ + sources.remove(&["__aeabi_cdcmp", "__aeabi_cfcmp"]); + } + ++ sources ++ } ++} ++ ++#[cfg(feature = "c-vendor")] ++mod c_vendor { ++ extern crate cc; ++ ++ use std::env; ++ use std::path::PathBuf; ++ use sources; ++ ++ /// Compile intrinsics from the compiler-rt C source code ++ pub fn compile(llvm_target: &[&str]) { ++ let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap(); ++ let cfg = &mut cc::Build::new(); ++ cfg.warnings(false); ++ ++ if target_env == "msvc" { ++ // Don't pull in extra libraries on MSVC ++ cfg.flag("/Zl"); ++ ++ // Emulate C99 and C++11's __func__ for MSVC prior to 2013 CTP ++ cfg.define("__func__", Some("__FUNCTION__")); ++ } else { ++ // Turn off various features of gcc and such, mostly copying ++ // compiler-rt's build system already ++ cfg.flag("-fno-builtin"); ++ cfg.flag("-fvisibility=hidden"); ++ cfg.flag("-ffreestanding"); ++ // Avoid the following warning appearing once **per file**: ++ // clang: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7' [-Wignored-optimization-argument] ++ // ++ // Note that compiler-rt's build system also checks ++ // ++ // `check_cxx_compiler_flag(-fomit-frame-pointer COMPILER_RT_HAS_FOMIT_FRAME_POINTER_FLAG)` ++ // ++ // in https://github.com/rust-lang/compiler-rt/blob/c8fbcb3/cmake/config-ix.cmake#L19. ++ cfg.flag_if_supported("-fomit-frame-pointer"); ++ cfg.define("VISIBILITY_HIDDEN", None); ++ } ++ + // When compiling the C code we require the user to tell us where the + // source code is, and this is largely done so when we're compiling as + // part of rust-lang/rust we can use the same llvm-project repository as +@@ -423,6 +436,7 @@ + panic!("RUST_COMPILER_RT_ROOT={} does not exist", root.display()); + } + ++ let sources = sources::get_sources(llvm_target); + let src_dir = root.join("lib/builtins"); + for (sym, src) in sources.map.iter() { + let src = src_dir.join(src); +@@ -434,3 +448,93 @@ + cfg.compile("libcompiler-rt.a"); + } + } ++ ++#[cfg(feature = "c-system")] ++mod c_system { ++ use std::env; ++ use std::process::{Command, Output}; ++ use std::str; ++ use std::path::Path; ++ use sources; ++ ++ fn success_output(err: &str, cmd: &mut Command) -> Output { ++ let output = cmd.output().expect(err); ++ let status = output.status; ++ if !status.success() { ++ panic!("{}: {:?}", err, status.code()); ++ } ++ output ++ } ++ ++ // This function recreates the logic of getArchNameForCompilerRTLib, ++ // defined in clang/lib/Driver/ToolChain.cpp. ++ fn get_arch_name_for_compiler_rtlib() -> String { ++ let target = env::var("TARGET").unwrap(); ++ let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); ++ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); ++ let r = match target_arch.as_str() { ++ "arm" => if target.ends_with("eabihf") && target_os != "windows" { ++ "armhf" ++ } else { ++ "arm" ++ }, ++ "x86" => if target_os == "android" { ++ "i686" ++ } else { ++ "i386" ++ }, ++ _ => target_arch.as_str(), ++ }; ++ r.to_string() ++ } ++ ++ /// Link against system clang runtime libraries ++ pub fn compile(llvm_target: &[&str]) { ++ let target = env::var("TARGET").unwrap(); ++ let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); ++ let compiler_rt_arch = get_arch_name_for_compiler_rtlib(); ++ ++ if let Ok(clang) = env::var("CLANG") { ++ let output = success_output( ++ "failed to find clang's compiler-rt", ++ Command::new(clang) ++ .arg(format!("--target={}", target)) ++ .arg("--rtlib=compiler-rt") ++ .arg("--print-libgcc-file-name"), ++ ); ++ let fullpath = Path::new(str::from_utf8(&output.stdout).unwrap()); ++ let libpath = fullpath.parent().unwrap().display(); ++ let libname = fullpath ++ .file_stem() ++ .unwrap() ++ .to_str() ++ .unwrap() ++ .trim_start_matches("lib"); ++ println!("cargo:rustc-link-search=native={}", libpath); ++ println!("cargo:rustc-link-lib=static={}", libname); ++ } else if let Ok(llvm_config) = env::var("LLVM_CONFIG") { ++ // fallback if clang is not installed ++ let (subpath, libname) = match target_os.as_str() { ++ "linux" => ("linux", format!("clang_rt.builtins-{}", &compiler_rt_arch)), ++ "macos" => ("darwin", "clang_rt.builtins_osx_dynamic".to_string()), ++ _ => panic!("unsupported target os: {}", target_os), ++ }; ++ let cmd = format!("ls -1d $({} --libdir)/clang/*/lib/{}", llvm_config, subpath); ++ let output = success_output( ++ "failed to find clang's lib dir", ++ Command::new("sh").args(&["-ec", &cmd]), ++ ); ++ for search_dir in str::from_utf8(&output.stdout).unwrap().lines() { ++ println!("cargo:rustc-link-search=native={}", search_dir); ++ } ++ println!("cargo:rustc-link-lib=static={}", libname); ++ } else { ++ panic!("neither CLANG nor LLVM_CONFIG could be read"); ++ } ++ ++ let sources = sources::get_sources(llvm_target); ++ for (sym, _src) in sources.map.iter() { ++ println!("cargo:rustc-cfg={}=\"optimized-c\"", sym); ++ } ++ } ++} +--- a/src/bootstrap/compile.rs ++++ b/src/bootstrap/compile.rs +@@ -200,6 +200,12 @@ + let mut features = builder.std_features(); + features.push_str(&compiler_builtins_c_feature); + ++ // In Debian this is always available ++ let llvm_config = builder.ensure(native::Llvm { ++ target: builder.config.build, ++ emscripten: false, ++ }); ++ cargo.env("LLVM_CONFIG", llvm_config); + if compiler.stage != 0 && builder.config.sanitizers { + // This variable is used by the sanitizer runtime crates, e.g. + // rustc_lsan, to build the sanitizer runtime from C code +@@ -208,11 +214,7 @@ + // missing + // We also only build the runtimes when --enable-sanitizers (or its + // config.toml equivalent) is used +- let llvm_config = builder.ensure(native::Llvm { +- target: builder.config.build, +- emscripten: false, +- }); +- cargo.env("LLVM_CONFIG", llvm_config); ++ cargo.env("RUSTC_BUILD_SANITIZERS", "1"); + } + + cargo.arg("--features").arg(features) +--- a/src/librustc_asan/build.rs ++++ b/src/librustc_asan/build.rs +@@ -4,6 +4,9 @@ + use cmake::Config; + + fn main() { ++ if env::var("RUSTC_BUILD_SANITIZERS") != Ok("1".to_string()) { ++ return; ++ } + if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { + build_helper::restore_library_path(); + +--- a/src/librustc_lsan/build.rs ++++ b/src/librustc_lsan/build.rs +@@ -4,6 +4,9 @@ + use cmake::Config; + + fn main() { ++ if env::var("RUSTC_BUILD_SANITIZERS") != Ok("1".to_string()) { ++ return; ++ } + if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { + build_helper::restore_library_path(); + +--- a/src/librustc_msan/build.rs ++++ b/src/librustc_msan/build.rs +@@ -4,6 +4,9 @@ + use cmake::Config; + + fn main() { ++ if env::var("RUSTC_BUILD_SANITIZERS") != Ok("1".to_string()) { ++ return; ++ } + if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { + build_helper::restore_library_path(); + +--- a/src/librustc_tsan/build.rs ++++ b/src/librustc_tsan/build.rs +@@ -4,6 +4,9 @@ + use cmake::Config; + + fn main() { ++ if env::var("RUSTC_BUILD_SANITIZERS") != Ok("1".to_string()) { ++ return; ++ } + if let Some(llvm_config) = env::var_os("LLVM_CONFIG") { + build_helper::restore_library_path(); + diff --git a/debian/patches/gcc-4.8-aarch64-ice.diff b/debian/patches/gcc-4.8-aarch64-ice.diff deleted file mode 100644 index aaa4d7b11f..0000000000 --- a/debian/patches/gcc-4.8-aarch64-ice.diff +++ /dev/null @@ -1,25 +0,0 @@ -Index: rustc/vendor/compiler_builtins/compiler-rt/lib/builtins/trunctfdf2.c -=================================================================== ---- rustc.orig/vendor/compiler_builtins/compiler-rt/lib/builtins/trunctfdf2.c -+++ rustc/vendor/compiler_builtins/compiler-rt/lib/builtins/trunctfdf2.c -@@ -7,6 +7,12 @@ - // - //===----------------------------------------------------------------------===// - -+#if defined(__aarch64__) && (__GNUC__ <= 4) && (__GNUC_MINOR__ <= 8) -+// work around https://launchpad.net/bugs/1667761 -+#pragma GCC push_options -+#pragma GCC optimize "O1" -+#endif -+ - #define QUAD_PRECISION - #include "fp_lib.h" - -@@ -20,3 +26,7 @@ COMPILER_RT_ABI double __trunctfdf2(long - } - - #endif -+#if defined(__aarch64__) && (__GNUC__ <= 4) && (__GNUC_MINOR__ <= 8) -+#pragma GCC pop_options -+#endif -+ diff --git a/debian/patches/series b/debian/patches/series index f46f4f7779..7e21595938 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -10,8 +10,6 @@ u-mips-fixes.diff # not forwarded, or forwarded but unlikely to be merged u-reproducible-dl-stage0.patch -gcc-4.8-aarch64-ice.diff - # Debian-specific patches, not suitable for upstream # Patches needed by debian/prune-unused-deps d-0000-ignore-removed-submodules.patch @@ -20,7 +18,7 @@ d-0002-pkg-config-no-special-snowflake.patch d-0003-mdbook-strip-embedded-libs.patch d-0004-mdbook-2-1-compat.patch # Other patches needed by the full Debian build -#d-use-system-compiler-rt.patch +d-use-system-compiler-rt.patch d-ignore-error-detail-diff.patch d-disable-cargo-vendor.patch d-rust-gdb-paths