Skip to content

Commit c37a824

Browse files
link.exe: don't embed full path to PDB file in binary.
1 parent 972452c commit c37a824

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

compiler/rustc_codegen_ssa/src/back/linker.rs

+9
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,15 @@ impl<'a> Linker for MsvcLinker<'a> {
928928
// from the CodeView line tables in the object files.
929929
self.cmd.arg("/DEBUG");
930930

931+
// Default to emitting only the file name of the PDB file into
932+
// the binary instead of the full path. Emitting the full path
933+
// may leak private information (such as user names).
934+
// See https://github.com/rust-lang/rust/issues/87825.
935+
//
936+
// This default behavior can be overridden by explicitly passing
937+
// `-Clink-arg=/PDBALTPATH:...` to rustc.
938+
self.cmd.arg("/PDBALTPATH:%_PDB%");
939+
931940
// This will cause the Microsoft linker to embed .natvis info into the PDB file
932941
let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
933942
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {

tests/run-make/pdb-alt-path/Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
include ../tools.mk
2+
3+
# only-windows-msvc
4+
5+
all:
6+
# Test that we don't have the full path to the PDB file in the binary
7+
$(RUSTC) main.rs -g --crate-name my_crate_name --crate-type bin
8+
$(CGREP) "my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe
9+
$(CGREP) -v "\\my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe
10+
11+
# Test that backtraces still can find debuginfo by checking that they contain symbol names and
12+
# source locations.
13+
RUST_BACKTRACE="full" $(TMPDIR)/my_crate_name.exe &> $(TMPDIR)/backtrace.txt || exit 0
14+
$(CGREP) "my_crate_name::main" < $(TMPDIR)/backtrace.txt
15+
$(CGREP) "pdb-alt-path\\main.rs:2" < $(TMPDIR)/backtrace.txt
16+
17+
# Test that explicitly passed `-Clink-arg=/PDBALTPATH:...` is respected
18+
$(RUSTC) main.rs -g --crate-name my_crate_name --crate-type bin -Clink-arg=/PDBALTPATH:abcdefg.pdb
19+
$(CGREP) "abcdefg.pdb" < $(TMPDIR)/my_crate_name.exe
20+
$(CGREP) -v "my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe

tests/run-make/pdb-alt-path/main.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
panic!("backtrace please");
3+
}

0 commit comments

Comments
 (0)