Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link.exe: Don't embed full path to PDB file in binary. #121297

Merged
merged 3 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,15 @@ impl<'a> Linker for MsvcLinker<'a> {
// from the CodeView line tables in the object files.
self.cmd.arg("/DEBUG");

// Default to emitting only the file name of the PDB file into
// the binary instead of the full path. Emitting the full path
// may leak private information (such as user names).
// See https://github.com/rust-lang/rust/issues/87825.
//
// This default behavior can be overridden by explicitly passing
// `-Clink-arg=/PDBALTPATH:...` to rustc.
self.cmd.arg("/PDBALTPATH:%_PDB%");

// This will cause the Microsoft linker to embed .natvis info into the PDB file
let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
Expand Down
20 changes: 20 additions & 0 deletions tests/run-make/pdb-alt-path/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
include ../tools.mk

# only-windows-msvc

all:
# Test that we don't have the full path to the PDB file in the binary
$(RUSTC) main.rs -g --crate-name my_crate_name --crate-type bin -Cforce-frame-pointers
$(CGREP) "my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe
$(CGREP) -v "\\my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe

# Test that backtraces still can find debuginfo by checking that they contain symbol names and
# source locations.
$(TMPDIR)/my_crate_name.exe &> $(TMPDIR)/backtrace.txt
$(CGREP) "my_crate_name::fn_in_backtrace" < $(TMPDIR)/backtrace.txt
$(CGREP) "main.rs:15" < $(TMPDIR)/backtrace.txt

# Test that explicitly passed `-Clink-arg=/PDBALTPATH:...` is respected
$(RUSTC) main.rs -g --crate-name my_crate_name --crate-type bin -Clink-arg=/PDBALTPATH:abcdefg.pdb -Cforce-frame-pointers
$(CGREP) "abcdefg.pdb" < $(TMPDIR)/my_crate_name.exe
$(CGREP) -v "my_crate_name.pdb" < $(TMPDIR)/my_crate_name.exe
24 changes: 24 additions & 0 deletions tests/run-make/pdb-alt-path/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// The various #[inline(never)] annotations and std::hint::black_box calls are
// an attempt to make unwinding as non-flaky as possible on i686-pc-windows-msvc.

#[inline(never)]
fn generate_backtrace(x: &u32) {
std::hint::black_box(x);
let bt = std::backtrace::Backtrace::force_capture();
println!("{}", bt);
std::hint::black_box(x);
}

#[inline(never)]
fn fn_in_backtrace(x: &u32) {
std::hint::black_box(x);
generate_backtrace(x);
std::hint::black_box(x);
}

fn main() {
let x = &41;
std::hint::black_box(x);
fn_in_backtrace(x);
std::hint::black_box(x);
}
Loading