-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #121297 - michaelwoerister:set-pdb-alt-path, r=wesleywiser
link.exe: Don't embed full path to PDB file in binary. This PR makes `rustc` unconditionally pass `/PDBALTPATH:%_PDB%` to MSVC-style linkers, causing the linker to only embed the filename of the PDB in the binary instead of the full path. This will help implement the [trim-paths RFC](#111540) for `*-msvc` targets. Passing `/PDBALTPATH:%_PDB%` to the linker is already done by many projects that need reproducible builds and [debugger's should still be able to find the PDB](https://learn.microsoft.com/cpp/build/reference/pdbpath) if it is in the same directory as the binary. r? `@ghost` Fixes #87825
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |