Skip to content
This repository was archived by the owner on Feb 9, 2020. It is now read-only.

Commit 5db68ba

Browse files
committed
Rollup merge of rust-lang#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`.
2 parents e92f1b9 + 5595aeb commit 5db68ba

14 files changed

+71
-15
lines changed

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@
377377
# Whether to verify generated LLVM IR
378378
#verify-llvm-ir = false
379379

380+
# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`,
381+
# generally only set for releases
382+
#remap-debuginfo = false
383+
380384
# =============================================================================
381385
# Options for specific targets
382386
#

src/bootstrap/bin/rustc.rs

+4
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,10 @@ fn main() {
263263
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
264264
cmd.arg("-Z").arg("force-unstable-if-unmarked");
265265
}
266+
267+
if let Ok(map) = env::var("RUSTC_DEBUGINFO_MAP") {
268+
cmd.arg("--remap-path-prefix").arg(&map);
269+
}
266270
} else {
267271
// Override linker if necessary.
268272
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {

src/bootstrap/builder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use native;
3232
use test;
3333
use tool;
3434
use util::{add_lib_path, exe, libdir};
35-
use {Build, DocTests, Mode};
35+
use {Build, DocTests, Mode, GitRepo};
3636

3737
pub use Compiler;
3838

@@ -876,6 +876,10 @@ impl<'a> Builder<'a> {
876876
cargo.env("RUSTC_HOST_CRT_STATIC", x.to_string());
877877
}
878878

879+
if let Some(map) = self.build.debuginfo_map(GitRepo::Rustc) {
880+
cargo.env("RUSTC_DEBUGINFO_MAP", map);
881+
}
882+
879883
// Enable usage of unstable features
880884
cargo.env("RUSTC_BOOTSTRAP", "1");
881885
self.add_rust_test_threads(&mut cargo);
@@ -964,7 +968,7 @@ impl<'a> Builder<'a> {
964968
let cc = ccacheify(&self.cc(target));
965969
cargo.env(format!("CC_{}", target), &cc).env("CC", &cc);
966970

967-
let cflags = self.cflags(target).join(" ");
971+
let cflags = self.cflags(target, GitRepo::Rustc).join(" ");
968972
cargo
969973
.env(format!("CFLAGS_{}", target), cflags.clone())
970974
.env("CFLAGS", cflags.clone());

src/bootstrap/cc_detect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use std::process::Command;
3939
use build_helper::output;
4040
use cc;
4141

42-
use Build;
42+
use {Build, GitRepo};
4343
use config::Target;
4444
use cache::Interned;
4545

@@ -107,7 +107,7 @@ pub fn find(build: &mut Build) {
107107

108108
build.cc.insert(target, compiler);
109109
build.verbose(&format!("CC_{} = {:?}", &target, build.cc(target)));
110-
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target)));
110+
build.verbose(&format!("CFLAGS_{} = {:?}", &target, build.cflags(target, GitRepo::Rustc)));
111111
if let Some(ar) = ar {
112112
build.verbose(&format!("AR_{} = {:?}", &target, ar));
113113
build.ar.insert(target, ar);

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use filetime::FileTime;
3030
use serde_json;
3131

3232
use util::{exe, libdir, is_dylib, CiEnv};
33-
use {Compiler, Mode};
33+
use {Compiler, Mode, GitRepo};
3434
use native;
3535
use tool;
3636

@@ -895,7 +895,7 @@ pub fn compiler_file(builder: &Builder,
895895
target: Interned<String>,
896896
file: &str) -> PathBuf {
897897
let mut cmd = Command::new(compiler);
898-
cmd.args(builder.cflags(target));
898+
cmd.args(builder.cflags(target, GitRepo::Rustc));
899899
cmd.arg(format!("-print-file-name={}", file));
900900
let out = output(&mut cmd);
901901
PathBuf::from(out.trim())

src/bootstrap/config.rs

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub struct Config {
109109
pub rust_codegen_backends: Vec<Interned<String>>,
110110
pub rust_codegen_backends_dir: String,
111111
pub rust_verify_llvm_ir: bool,
112+
pub rust_remap_debuginfo: bool,
112113

113114
pub build: Interned<String>,
114115
pub hosts: Vec<Interned<String>>,
@@ -321,6 +322,7 @@ struct Rust {
321322
deny_warnings: Option<bool>,
322323
backtrace_on_ice: Option<bool>,
323324
verify_llvm_ir: Option<bool>,
325+
remap_debuginfo: Option<bool>,
324326
}
325327

326328
/// TOML representation of how each build target is configured.
@@ -557,6 +559,7 @@ impl Config {
557559
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
558560
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
559561
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
562+
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
560563

561564
if let Some(ref backends) = rust.codegen_backends {
562565
config.rust_codegen_backends = backends.iter()

src/bootstrap/lib.rs

+31-1
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@ pub enum DocTests {
237237
Only,
238238
}
239239

240+
pub enum GitRepo {
241+
Rustc,
242+
Llvm,
243+
}
244+
240245
/// Global configuration for the build system.
241246
///
242247
/// This structure transitively contains all configuration for the build system.
@@ -738,14 +743,29 @@ impl Build {
738743
self.config.jobs.unwrap_or_else(|| num_cpus::get() as u32)
739744
}
740745

746+
fn debuginfo_map(&self, which: GitRepo) -> Option<String> {
747+
if !self.config.rust_remap_debuginfo {
748+
return None
749+
}
750+
751+
let path = match which {
752+
GitRepo::Rustc => {
753+
let sha = self.rust_info.sha().expect("failed to find sha");
754+
format!("/rustc/{}", sha)
755+
}
756+
GitRepo::Llvm => format!("/rustc/llvm"),
757+
};
758+
Some(format!("{}={}", self.src.display(), path))
759+
}
760+
741761
/// Returns the path to the C compiler for the target specified.
742762
fn cc(&self, target: Interned<String>) -> &Path {
743763
self.cc[&target].path()
744764
}
745765

746766
/// Returns a list of flags to pass to the C compiler for the target
747767
/// specified.
748-
fn cflags(&self, target: Interned<String>) -> Vec<String> {
768+
fn cflags(&self, target: Interned<String>, which: GitRepo) -> Vec<String> {
749769
// Filter out -O and /O (the optimization flags) that we picked up from
750770
// cc-rs because the build scripts will determine that for themselves.
751771
let mut base = self.cc[&target].args().iter()
@@ -767,6 +787,16 @@ impl Build {
767787
if &*target == "i686-pc-windows-gnu" {
768788
base.push("-fno-omit-frame-pointer".into());
769789
}
790+
791+
if let Some(map) = self.debuginfo_map(which) {
792+
let cc = self.cc(target);
793+
if cc.ends_with("clang") || cc.ends_with("gcc") {
794+
base.push(format!("-fdebug-prefix-map={}", map).into());
795+
} else if cc.ends_with("clang-cl.exe") {
796+
base.push("-Xclang".into());
797+
base.push(format!("-fdebug-prefix-map={}", map).into());
798+
}
799+
}
770800
base
771801
}
772802

src/bootstrap/native.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use util::{self, exe};
3333
use build_helper::up_to_date;
3434
use builder::{Builder, RunConfig, ShouldRun, Step};
3535
use cache::Interned;
36+
use GitRepo;
3637

3738
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
3839
pub struct Llvm {
@@ -373,8 +374,8 @@ fn configure_cmake(builder: &Builder,
373374
}
374375

375376
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
376-
cfg.define("CMAKE_C_FLAGS", builder.cflags(target).join(" "));
377-
let mut cxxflags = builder.cflags(target).join(" ");
377+
cfg.define("CMAKE_C_FLAGS", builder.cflags(target, GitRepo::Llvm).join(" "));
378+
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
378379
if building_dist_binaries {
379380
if builder.config.llvm_static_stdcpp && !target.contains("windows") {
380381
cxxflags.push_str(" -static-libstdc++");
@@ -680,7 +681,7 @@ impl Step for Openssl {
680681
};
681682
configure.arg(os);
682683
configure.env("CC", builder.cc(target));
683-
for flag in builder.cflags(target) {
684+
for flag in builder.cflags(target, GitRepo::Rustc) {
684685
configure.arg(flag);
685686
}
686687
// There is no specific os target for android aarch64 or x86_64,

src/bootstrap/test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use tool::{self, Tool, SourceType};
3434
use toolstate::ToolState;
3535
use util::{self, dylib_path, dylib_path_var};
3636
use Crate as CargoCrate;
37-
use {DocTests, Mode};
37+
use {DocTests, Mode, GitRepo};
3838

3939
const ADB_TEST_DIR: &str = "/data/tmp/work";
4040

@@ -1142,7 +1142,7 @@ impl Step for Compiletest {
11421142
.arg("--cxx")
11431143
.arg(builder.cxx(target).unwrap())
11441144
.arg("--cflags")
1145-
.arg(builder.cflags(target).join(" "))
1145+
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
11461146
.arg("--llvm-components")
11471147
.arg(llvm_components.trim())
11481148
.arg("--llvm-cxxflags")

src/ci/run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export RUST_RELEASE_CHANNEL=nightly
5555
if [ "$DEPLOY$DEPLOY_ALT" != "" ]; then
5656
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
5757
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
58+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
5859

5960
if [ "$NO_LLVM_ASSERTIONS" = "1" ]; then
6061
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --disable-llvm-assertions"

src/libstd/build.rs

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ fn build_libbacktrace(target: &str) -> Result<(), ()> {
9797
.file("../libbacktrace/sort.c")
9898
.file("../libbacktrace/state.c");
9999

100+
let any_debug = env::var("RUSTC_DEBUGINFO").unwrap_or(String::new()) == "true" ||
101+
env::var("RUSTC_DEBUGINFO_LINES").unwrap_or(String::new()) == "true";
102+
build.debug(any_debug);
103+
100104
if target.contains("darwin") {
101105
build.file("../libbacktrace/macho.c");
102106
} else if target.contains("windows") {

src/test/ui/consts/const-size_of-cycle.rs

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-musl
12+
// ignore-x86
1113
// error-pattern: cycle detected
1214

1315
struct Foo {

src/test/ui/impl-trait/impl-generic-mismatch.rs

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-musl
12+
// ignore-x86
13+
1114
use std::fmt::Debug;
1215

1316
trait Foo {

src/test/ui/impl-trait/impl-generic-mismatch.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0643]: method `foo` has incompatible signature for trait
2-
--> $DIR/impl-generic-mismatch.rs:18:12
2+
--> $DIR/impl-generic-mismatch.rs:21:12
33
|
44
LL | fn foo(&self, _: &impl Debug);
55
| ---------- declaration in trait here
@@ -12,7 +12,7 @@ LL | fn foo(&self, _: &impl Debug) { }
1212
| -- ^^^^^^^^^^
1313

1414
error[E0643]: method `bar` has incompatible signature for trait
15-
--> $DIR/impl-generic-mismatch.rs:27:23
15+
--> $DIR/impl-generic-mismatch.rs:30:23
1616
|
1717
LL | fn bar<U: Debug>(&self, _: &U);
1818
| - declaration in trait here
@@ -25,7 +25,7 @@ LL | fn bar<U: Debug>(&self, _: &U) { }
2525
| ^^^^^^^^^^ ^
2626

2727
error[E0643]: method `hash` has incompatible signature for trait
28-
--> $DIR/impl-generic-mismatch.rs:38:33
28+
--> $DIR/impl-generic-mismatch.rs:41:33
2929
|
3030
LL | fn hash(&self, hasher: &mut impl Hasher) {}
3131
| ^^^^^^^^^^^ expected generic parameter, found `impl Trait`

0 commit comments

Comments
 (0)