Skip to content

Commit 5595aeb

Browse files
committed
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`.
1 parent fc81e36 commit 5595aeb

14 files changed

+71
-15
lines changed

config.toml.example

+4
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@
373373
# Whether to verify generated LLVM IR
374374
#verify-llvm-ir = false
375375

376+
# Map all debuginfo paths for libstd and crates to `/rust/$sha/$crate/...`,
377+
# generally only set for releases
378+
#remap-debuginfo = false
379+
376380
# =============================================================================
377381
# Options for specific targets
378382
#

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
@@ -108,6 +108,7 @@ pub struct Config {
108108
pub rust_codegen_backends: Vec<Interned<String>>,
109109
pub rust_codegen_backends_dir: String,
110110
pub rust_verify_llvm_ir: bool,
111+
pub rust_remap_debuginfo: bool,
111112

112113
pub build: Interned<String>,
113114
pub hosts: Vec<Interned<String>>,
@@ -319,6 +320,7 @@ struct Rust {
319320
deny_warnings: Option<bool>,
320321
backtrace_on_ice: Option<bool>,
321322
verify_llvm_ir: Option<bool>,
323+
remap_debuginfo: Option<bool>,
322324
}
323325

324326
/// TOML representation of how each build target is configured.
@@ -554,6 +556,7 @@ impl Config {
554556
set(&mut config.deny_warnings, rust.deny_warnings.or(flags.warnings));
555557
set(&mut config.backtrace_on_ice, rust.backtrace_on_ice);
556558
set(&mut config.rust_verify_llvm_ir, rust.verify_llvm_ir);
559+
set(&mut config.rust_remap_debuginfo, rust.remap_debuginfo);
557560

558561
if let Some(ref backends) = rust.codegen_backends {
559562
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 {
@@ -369,8 +370,8 @@ fn configure_cmake(builder: &Builder,
369370
}
370371

371372
cfg.build_arg("-j").build_arg(builder.jobs().to_string());
372-
cfg.define("CMAKE_C_FLAGS", builder.cflags(target).join(" "));
373-
let mut cxxflags = builder.cflags(target).join(" ");
373+
cfg.define("CMAKE_C_FLAGS", builder.cflags(target, GitRepo::Llvm).join(" "));
374+
let mut cxxflags = builder.cflags(target, GitRepo::Llvm).join(" ");
374375
if building_dist_binaries {
375376
if builder.config.llvm_static_stdcpp && !target.contains("windows") {
376377
cxxflags.push_str(" -static-libstdc++");
@@ -676,7 +677,7 @@ impl Step for Openssl {
676677
};
677678
configure.arg(os);
678679
configure.env("CC", builder.cc(target));
679-
for flag in builder.cflags(target) {
680+
for flag in builder.cflags(target, GitRepo::Rustc) {
680681
configure.arg(flag);
681682
}
682683
// 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

@@ -1140,7 +1140,7 @@ impl Step for Compiletest {
11401140
.arg("--cxx")
11411141
.arg(builder.cxx(target).unwrap())
11421142
.arg("--cflags")
1143-
.arg(builder.cflags(target).join(" "))
1143+
.arg(builder.cflags(target, GitRepo::Rustc).join(" "))
11441144
.arg("--llvm-components")
11451145
.arg(llvm_components.trim())
11461146
.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)