Skip to content

Commit ba6b2d8

Browse files
committed
Elaborate on linkers for separate debuginfo
1 parent 998ecf4 commit ba6b2d8

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

text/3127-trim-paths.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ If the user further supplies custom `--remap-path-prefix` arguments via `RUSTFLA
164164
or similar mechanisms, they will take precedence over the one supplied by `trim-paths`. This means that the user-defined remapping arguments must be
165165
supplied *after* Cargo's own remapping.
166166

167-
168-
Additionally, when using MSVC linker, Cargo should emit `/PDBALTPATH:%_PDB%` to the linker via `-C link-arg`. This makes the linker embed
169-
only the file name of the .pdb file without the path to it.
170-
171167
## Changing handling of sysroot path in `rustc`
172168

173169
The virtualisation of sysroot files to `/rustc/[commit hash]/library/...` was done at compiler bootstraping, specifically when
@@ -180,6 +176,20 @@ Only the virtual name is ever emitted for metadata or codegen. We want to change
180176
discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a `--remap-path-prefix` that causes this
181177
local path to be remapped in the usual way.
182178

179+
## Linker arguments
180+
181+
If a separate debuginfo file is to be generated (which can be determined by `split-debuginfo` codegen option), the linker may include an absolute
182+
path to the object into the binary. If the user wants debug information to be remapped, then the inclusion of this absolute path is
183+
undesirable. `rustc` cannot exhaustively control the behaviour of an external program (the linker) specified by the user, but we should
184+
supply appropriate linker options to mitigate this as much as we could.
185+
186+
The linker in use can be determined by the [`linker-flavor`](https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor) flag, itself
187+
generally being inferred by `rustc`. If `debuginfo` is in `--remap-path-scope` and `split-debuginfo` is not `off`, the following linker-specific
188+
options should be emitted:
189+
190+
- When using MSVC linker, `/PDBALTPATH:%_PDB%` should be emitted. This makes the linker embed only the file name of the .pdb file without the path
191+
to it.
192+
183193

184194
# Drawbacks
185195
[drawbacks]: #drawbacks
@@ -221,11 +231,18 @@ the other for only debuginfo: https://reproducible-builds.org/docs/build-path/.
221231
# Unresolved questions
222232
[unresolved-questions]: #unresolved-questions
223233

234+
- Should we use a slightly more complex remapping rule, like distinguishing packages from registry, git and path, as proposed in
235+
[Issue #40552](https://github.com/rust-lang/rust/issues/40552)?
236+
- With debug information in separate files, debuggers and Rust's own backtrace rely on the path embedded in the binary to find these files to display
237+
source code lines, columns and symbols etc. If we sanitise these paths to relative paths, then debuggers and backtrace must be invoked
238+
in specific directories for these paths to work. [For instance](https://github.com/rust-lang/rust/issues/87825#issuecomment-920693005), `cargo run`
239+
invoked under crate root will fail to print meaningful backtrace symbols because the binary and `.pdb` file are under `target/release`, but
240+
the backtrace library will attempt to find the `.pdb` file from the working directory (crate root), where it doesn't exist.
241+
- At the time of writing, `rustc` recognises 10 [`linker-flavor`s](https://doc.rust-lang.org/rustc/codegen-options/index.html#linker-flavor).
242+
We need to find the right option for each to change the embedded path to debug information.
224243
- Should we treat the current working directory the same as other packages? We could have one fewer remapping rule by remapping all
225244
package roots to `[package name]-[version]`. A minor downside to this is not being able to `Ctrl+click` on paths to files the user is working
226245
on from panic messages.
227-
- Should we use a slightly more complex remapping rule, like distinguishing packages from registry, git and path, as mentioned in
228-
https://github.com/rust-lang/rust/issues/40552?
229246
- Will these cover all potentially embedded paths? Have we missed anything?
230247
- Should we make this affect more `CompileMode`s, such as `Check`, where the emitted `rmeta` file will also contain absolute paths?
231248

0 commit comments

Comments
 (0)