Rollup merge of #53829 - alexcrichton:release-debuginfo, r=michaelwoerister

Add rustc SHA to released DWARF debuginfo

This commit updates the debuginfo that is encoded in all of our released
artifacts by default. Currently it has paths like `/checkout/src/...` but these
are a little inconsistent and have changed over time. This commit instead
attempts to actually define the file paths in our debuginfo to be consistent
between releases.

All debuginfo paths are now intended to be `/rustc/$sha` where `$sha` is the git
sha of the released compiler. Sub-paths are all paths into the git repo at that
`$sha`.
This commit is contained in:
kennytm 2018-09-14 00:46:22 +08:00
commit 5db68bae9a
No known key found for this signature in database
GPG key ID: FEF6C8051D0E013C
14 changed files with 71 additions and 15 deletions

View file

@ -377,6 +377,10 @@
# Whether to verify generated LLVM IR # Whether to verify generated LLVM IR
#verify-llvm-ir = false #verify-llvm-ir = false
# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`,
# generally only set for releases
#remap-debuginfo = false
# ============================================================================= # =============================================================================
# Options for specific targets # Options for specific targets
# #

View file

@ -263,6 +263,10 @@ fn main() {
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() { if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
cmd.arg("-Z").arg("force-unstable-if-unmarked"); cmd.arg("-Z").arg("force-unstable-if-unmarked");
} }
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
cmd.arg("--remap-path-prefix").arg(&map);
}
} else { } else {
// Override linker if necessary. // Override linker if necessary.
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") { if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {

View file

@ -32,7 +32,7 @@ use native;
use test; use test;
use tool; use tool;
use util::{add_lib_path, exe, libdir}; use util::{add_lib_path, exe, libdir};
use {Build, DocTests, Mode}; use {Build, DocTests, Mode, GitRepo};
pub use Compiler; pub use Compiler;
@ -876,6 +876,10 @@ impl<'a> Builder<'a> {
cargo.env("RUSTC_HOST_CRT_STATIC", x.to_string()); cargo.env("RUSTC_HOST_CRT_STATIC", x.to_string());
} }
if let Some(map) = self.build.debuginfo_map(GitRepo::Rustc) {
cargo.env("RUSTC_DEBUGINFO_MAP", map);
}
// Enable usage of unstable features // Enable usage of unstable features
cargo.env("RUSTC_BOOTSTRAP", "1"); cargo.env("RUSTC_BOOTSTRAP", "1");
self.add_rust_test_threads(&mut cargo); self.add_rust_test_threads(&mut cargo);
@ -964,7 +968,7 @@ impl<'a> Builder<'a> {
let cc = ccacheify(&self.cc(target)); let cc = ccacheify(&self.cc(target));
cargo.env(format!("CC_{}", target), &cc).env("CC", &cc); cargo.env(format!("CC_{}", target), &cc).env("CC", &cc);
let cflags = self.cflags(target).join(" "); let cflags = self.cflags(target, GitRepo::Rustc).join(" ");
cargo cargo
.env(format!("CFLAGS_{}", target), cflags.clone()) .env(format!("CFLAGS_{}", target), cflags.clone())
.env("CFLAGS", cflags.clone()); .env("CFLAGS", cflags.clone());

View file

@ -39,7 +39,7 @@ use std::process::Command;
use build_helper::output; use build_helper::output;
use cc; use cc;
use Build; use {Build, GitRepo};
use config::Target; use config::Target;
use cache::Interned; use cache::Interned;
@ -107,7 +107,7 @@ pub fn find(build: &mut Build) {
build.cc.insert(target, compiler); build.cc.insert(target, compiler);
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target))); build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target))); build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target, GitRepo::Rustc)));
if let Some(ar) = ar { if let Some(ar) = ar {
build.verbose(&format!("AR_{} = {:?}", &target, ar)); build.verbose(&format!("AR_{} = {:?}", &target, ar));
build.ar.insert(target, ar); build.ar.insert(target, ar);

View file

@ -30,7 +30,7 @@ use filetime::FileTime;
use serde_json; use serde_json;
use util::{exe, libdir, is_dylib, CiEnv}; use util::{exe, libdir, is_dylib, CiEnv};
use {Compiler, Mode}; use {Compiler, Mode, GitRepo};
use native; use native;
use tool; use tool;
@ -895,7 +895,7 @@ pub fn compiler_file(builder: &Builder,
target: Interned<String>, target: Interned<String>,
file: &str) -> PathBuf { file: &str) -> PathBuf {
let mut cmd = Command::new(compiler); let mut cmd = Command::new(compiler);
cmd.args(builder.cflags(target)); cmd.args(builder.cflags(target, GitRepo::Rustc));
cmd.arg(format!("-print-file-name={}", file)); cmd.arg(format!("-print-file-name={}", file));
let out = output(&mut cmd); let out = output(&mut cmd);
PathBuf::from(out.trim()) PathBuf::from(out.trim())

View file

@ -109,6 +109,7 @@ pub struct Config {
pub rust_codegen_backends: Vec<Interned<String>>, pub rust_codegen_backends: Vec<Interned<String>>,
pub rust_codegen_backends_dir: String, pub rust_codegen_backends_dir: String,
pub rust_verify_llvm_ir: bool, pub rust_verify_llvm_ir: bool,
pub rust_remap_debuginfo: bool,
pub build: Interned<String>, pub build: Interned<String>,
pub hosts: Vec<Interned<String>>, pub hosts: Vec<Interned<String>>,
@ -321,6 +322,7 @@ struct Rust {
deny_warnings: Option<bool>, deny_warnings: Option<bool>,
backtrace_on_ice: Option<bool>, backtrace_on_ice: Option<bool>,
verify_llvm_ir: Option<bool>, verify_llvm_ir: Option<bool>,
remap_debuginfo: Option<bool>,
} }
/// TOML representation of how each build target is configured. /// TOML representation of how each build target is configured.
@ -557,6 +559,7 @@ impl Config {
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings)); set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice); set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir); set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
if let Some(ref backends) = rust.codegen_backends { if let Some(ref backends) = rust.codegen_backends {
config.rust_codegen_backends = backends.iter() config.rust_codegen_backends = backends.iter()

View file

@ -237,6 +237,11 @@ pub enum DocTests {
Only, Only,
} }
pub enum GitRepo {
Rustc,
Llvm,
}
/// Global configuration for the build system. /// Global configuration for the build system.
/// ///
/// This structure transitively contains all configuration for the build system. /// This structure transitively contains all configuration for the build system.
@ -738,6 +743,21 @@ impl Build {
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32) self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
} }
fn debuginfo_map(&self, which: GitRepo) -> Option<String> {
if !self.config.rust_remap_debuginfo {
return None
}
let path = match which {
GitRepo::Rustc => {
let sha = self.rust_info.sha().expect("failed to find sha");
format!("/rustc/{}", sha)
}
GitRepo::Llvm => format!("/rustc/llvm"),
};
Some(format!("{}={}", self.src.display(), path))
}
/// Returns the path to the C compiler for the target specified. /// Returns the path to the C compiler for the target specified.
fn cc(&self, target: Interned<String>) -> &Path { fn cc(&self, target: Interned<String>) -> &Path {
self.cc[&target].path() self.cc[&target].path()
@ -745,7 +765,7 @@ impl Build {
/// Returns a list of flags to pass to the C compiler for the target /// Returns a list of flags to pass to the C compiler for the target
/// specified. /// specified.
fn cflags(&self, target: Interned<String>) -> Vec<String> { fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> {
// Filter out -O and /O (the optimization flags) that we picked up from // Filter out -O and /O (the optimization flags) that we picked up from
// cc-rs because the build scripts will determine that for themselves. // cc-rs because the build scripts will determine that for themselves.
let mut base = self.cc[&target].args().iter() let mut base = self.cc[&target].args().iter()
@ -767,6 +787,16 @@ impl Build {
if &*target == "i686-pc-windows-gnu" { if &*target == "i686-pc-windows-gnu" {
base.push("-fno-omit-frame-pointer".into()); base.push("-fno-omit-frame-pointer".into());
} }
if let Some(map) = self.debuginfo_map(which) {
let cc = self.cc(target);
if cc.ends_with("clang") || cc.ends_with("gcc") {
base.push(format!("-fdebug-prefix-map={}", map).into());
} else if cc.ends_with("clang-cl.exe") {
base.push("-Xclang".into());
base.push(format!("-fdebug-prefix-map={}", map).into());
}
}
base base
} }

View file

@ -33,6 +33,7 @@ use util::{self, exe};
use build_helper::up_to_date; use build_helper::up_to_date;
use builder::{Builder, RunConfig, ShouldRun, Step}; use builder::{Builder, RunConfig, ShouldRun, Step};
use cache::Interned; use cache::Interned;
use GitRepo;
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Llvm { pub struct Llvm {
@ -373,8 +374,8 @@ fn configure_cmake(builder: &Builder,
} }
cfg.build_arg("-j").build_arg(builder.jobs().to_string()); cfg.build_arg("-j").build_arg(builder.jobs().to_string());
cfg.define("CMAKE_C_FLAGS", builder.cflags(target).join(" ")); cfg.define("CMAKE_C_FLAGS", builder.cflags(target, GitRepo::Llvm).join(" "));
let mut cxxflags = builder.cflags(target).join(" "); let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
if building_dist_binaries { if building_dist_binaries {
if builder.config.llvm_static_stdcpp && !target.contains("windows") { if builder.config.llvm_static_stdcpp && !target.contains("windows") {
cxxflags.push_str(" -static-libstdc++"); cxxflags.push_str(" -static-libstdc++");
@ -680,7 +681,7 @@ impl Step for Openssl {
}; };
configure.arg(os); configure.arg(os);
configure.env("CC", builder.cc(target)); configure.env("CC", builder.cc(target));
for flag in builder.cflags(target) { for flag in builder.cflags(target, GitRepo::Rustc) {
configure.arg(flag); configure.arg(flag);
} }
// There is no specific os target for android aarch64 or x86_64, // There is no specific os target for android aarch64 or x86_64,

View file

@ -34,7 +34,7 @@ use tool::{self, Tool, SourceType};
use toolstate::ToolState; use toolstate::ToolState;
use util::{self, dylib_path, dylib_path_var}; use util::{self, dylib_path, dylib_path_var};
use Crate as CargoCrate; use Crate as CargoCrate;
use {DocTests, Mode}; use {DocTests, Mode, GitRepo};
const ADB_TEST_DIR: &str = "/data/tmp/work"; const ADB_TEST_DIR: &str = "/data/tmp/work";
@ -1142,7 +1142,7 @@ impl Step for Compiletest {
.arg("--cxx") .arg("--cxx")
.arg(builder.cxx(target).unwrap()) .arg(builder.cxx(target).unwrap())
.arg("--cflags") .arg("--cflags")
.arg(builder.cflags(target).join(" ")) .arg(builder.cflags(target, GitRepo::Rustc).join(" "))
.arg("--llvm-components") .arg("--llvm-components")
.arg(llvm_components.trim()) .arg(llvm_components.trim())
.arg("--llvm-cxxflags") .arg("--llvm-cxxflags")

View file

@ -55,6 +55,7 @@ export RUST_RELEASE_CHANNEL=nightly
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"

View file

@ -97,6 +97,10 @@ fn build_libbacktrace(target: &str) -> Result<(), ()> {
.file("../libbacktrace/sort.c") .file("../libbacktrace/sort.c")
.file("../libbacktrace/state.c"); .file("../libbacktrace/state.c");
let any_debug = env::var("RUSTC_DEBUGINFO").unwrap_or(String::new()) == "true" ||
env::var("RUSTC_DEBUGINFO_LINES").unwrap_or(String::new()) == "true";
build.debug(any_debug);
if target.contains("darwin") { if target.contains("darwin") {
build.file("../libbacktrace/macho.c"); build.file("../libbacktrace/macho.c");
} else if target.contains("windows") { } else if target.contains("windows") {

View file

@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// ignore-musl
// ignore-x86
// error-pattern: cycle detected // error-pattern: cycle detected
struct Foo { struct Foo {

View file

@ -8,6 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
// ignore-musl
// ignore-x86
use std::fmt::Debug; use std::fmt::Debug;
trait Foo { trait Foo {

View file

@ -1,5 +1,5 @@
error[E0643]: method `foo` has incompatible signature for trait error[E0643]: method `foo` has incompatible signature for trait
--> $DIR/impl-generic-mismatch.rs:18:12 --> $DIR/impl-generic-mismatch.rs:21:12
| |
LL | fn foo(&self, _: &impl Debug); LL | fn foo(&self, _: &impl Debug);
| ---------- declaration in trait here | ---------- declaration in trait here
@ -12,7 +12,7 @@ LL | fn foo(&self, _: &impl Debug) { }
| -- ^^^^^^^^^^ | -- ^^^^^^^^^^
error[E0643]: method `bar` has incompatible signature for trait error[E0643]: method `bar` has incompatible signature for trait
--> $DIR/impl-generic-mismatch.rs:27:23 --> $DIR/impl-generic-mismatch.rs:30:23
| |
LL | fn bar<U: Debug>(&self, _: &U); LL | fn bar<U: Debug>(&self, _: &U);
| - declaration in trait here | - declaration in trait here
@ -25,7 +25,7 @@ LL | fn bar<U: Debug>(&self, _: &U) { }
| ^^^^^^^^^^ ^ | ^^^^^^^^^^ ^
error[E0643]: method `hash` has incompatible signature for trait error[E0643]: method `hash` has incompatible signature for trait
--> $DIR/impl-generic-mismatch.rs:38:33 --> $DIR/impl-generic-mismatch.rs:41:33
| |
LL | fn hash(&self, hasher: &mut impl Hasher) {} LL | fn hash(&self, hasher: &mut impl Hasher) {}
| ^^^^^^^^^^^ expected generic parameter, found `impl Trait` | ^^^^^^^^^^^ expected generic parameter, found `impl Trait`