Implement debuginfo path remapping by michaelwoerister · Pull Request #41419 · rust-lang/rust (original) (raw)
(continuing on the main part of the PR):
I think this problem could be solved by adapting the rules slightly. We could say that [..]
Hm, I think that is not ideal... I'm trying to find ways to avoid forcing people to make "tradeoffs" when deciding whether they want reproducible builds.
How about, instead of storing the unmapped work_dir
and src
plus the mapping, you store the mapped work_dir
and src
plus the to
value that was actually used (or empty if no mapping was applied)? Then you can still calculate relative paths from other crates when inlining.
It relies on the inlined crate having a good mapping applied when it was compiled, but distributions/people that want reproducible builds, would want to do this anyways.
Concretely:
CRATE A
working dir = /P/build
src = ../src/lib.rs
compiled with a map /P => AA
gives A.rlib containing:
working_dir = AA/build
src = ../src/lib.rs
virtual_base = AA
Later, perhaps on a different machine:
CRATE B
working dir = /Q/build
src = /Q/src/lib.rs
with A.rlib located in /irrelevant/A.rlib
, compiled with a map /Q => BB
gives B.rlib containing:
working_dir = BB/build
src = BB/src/lib.rs
virtual_base = BB
virtual_base[A] = AA # read from A.rlib, could maybe omit this I think
Function B_func1, imported from A: AA/src/lib.rs (resolved from AA/build + ../src/lib.rs [*])
Later, perhaps on a different machine:
CRATE C
working_dir = /R/build
src = ../src/lib.rs
with A.rlib, B.rlib located wherever, compiled with a map /R => CC
gives C.rlib containing:
working_dir = CC/build
src = ../src/lib.rs
virtual_base = CC
virtual_base[A] = AA # could maybe omit
virtual_base[B] = BB # could maybe omit
# not sure re-exports are possible in rust, but anyway for demonstration:
Function C_func1 = B_func1, imported from B (originally imported from A): AA/src/lib.rs
A debugger reading C.rlib later could map virtual_base[A]
, ..[B]
and ..[C]
to whatever directories it wants.
I appreciate this is a bit more complex, but I don't think it's too much more complex - instead of storing debug_prefix_map
we store a (or several) virtual_base
s.
[*] A minor addition for usability would be, when compiling A.rlib, check if /P/build + ../src/lib.rs
is still affected by the same mapping that affects /P/build
, and issue a warning if not. Either way, rustc can proceed based on "the user knows what's best".