mirror of
https://git.proxmox.com/git/rustc
synced 2026-08-11 11:07:15 +00:00
Use system compiler-rt
This commit is contained in:
parent
c4a98a6852
commit
9cd0782172
7
debian/README.source
vendored
7
debian/README.source
vendored
@ -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
|
||||
|
||||
1
debian/changelog
vendored
1
debian/changelog
vendored
@ -1,6 +1,7 @@
|
||||
rustc (1.37.0+dfsg1-1~exp1) UNRELEASED; urgency=medium
|
||||
|
||||
* New upstream release.
|
||||
* Use system compiler-rt.
|
||||
|
||||
-- Ximin Luo <infinity0@debian.org> Fri, 23 Aug 2019 03:57:40 -0700
|
||||
|
||||
|
||||
2
debian/control
vendored
2
debian/control
vendored
@ -14,6 +14,8 @@ Build-Depends: debhelper (>= 9),
|
||||
rustc:native (<= 1.37.0++) <!pkg.rustc.dlstage0>,
|
||||
llvm-8-dev:native,
|
||||
llvm-8-tools:native,
|
||||
libclang-common-8-dev:native,
|
||||
libclang-common-8-dev,
|
||||
libllvm8,
|
||||
autotools-dev,
|
||||
cmake (>= 3.0) | cmake3,
|
||||
|
||||
23
debian/copyright
vendored
23
debian/copyright
vendored
@ -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 <japaricious@gmail.com>
|
||||
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
|
||||
|
||||
337
debian/patches/d-use-system-compiler-rt.patch
vendored
Normal file
337
debian/patches/d-use-system-compiler-rt.patch
vendored
Normal file
@ -0,0 +1,337 @@
|
||||
commit 484e4a2e83ca6cbfb96957996d57262792da0a30
|
||||
Author: Ximin Luo <infinity0@debian.org>
|
||||
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();
|
||||
|
||||
25
debian/patches/gcc-4.8-aarch64-ice.diff
vendored
25
debian/patches/gcc-4.8-aarch64-ice.diff
vendored
@ -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
|
||||
+
|
||||
4
debian/patches/series
vendored
4
debian/patches/series
vendored
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user