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

remap-path-prefix from 1.47.0 results in weird prefixes in backtraces #78479

Open
Nemo157 opened this issue Oct 28, 2020 · 1 comment
Open

remap-path-prefix from 1.47.0 results in weird prefixes in backtraces #78479

Nemo157 opened this issue Oct 28, 2020 · 1 comment
Labels
A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Oct 28, 2020

I tried this code:

#![feature(backtrace)]

fn main() {
    futures::executor::block_on(async move {
        println!("{}", std::backtrace::Backtrace::capture());
        panic!()
    });
}

with the environment variables:

RUSTFLAGS='--remap-path-prefix=/home/nemo157/.cargo/registry/src/github.com-1ecc6299db9ec823=crates.io'
RUST_BACKTRACE=1
RUSTC_BOOTSTRAP=1

On 1.46 (and earlier) this results in backtraces looking as expected (for both the Backtrace::capture and begin_panic):

   5: std::thread::local::LocalKey<T>::with
             at /rustc/04488afe34512aa4c33566eb16d8c912a3ae04f9/src/libstd/thread/local.rs:239
   6: futures_executor::local_pool::run_executor
             at crates.io/futures-executor-0.3.7/src/local_pool.rs:83
   7: futures_executor::local_pool::block_on
             at crates.io/futures-executor-0.3.7/src/local_pool.rs:317
   8: foo::main
             at src/main.rs:4

but on 1.47 and later there is a spurious ./ prefixed onto the remapped paths:

   6: std::thread::local::LocalKey<T>::with
             at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39/library/std/src/thread/local.rs:241
   7: futures_executor::local_pool::run_executor
             at ./crates.io/futures-executor-0.3.7/src/local_pool.rs:83
   8: futures_executor::local_pool::block_on
             at ./crates.io/futures-executor-0.3.7/src/local_pool.rs:317
   9: foo::main
             at ./src/main.rs:4

If there are remapped frames on top of each other this seems to become even more complex, in another project using this set of flags:

rustflags = [
  "--remap-path-prefix=/home/nemo157=~",
  "--remap-path-prefix=/home/nemo157/.cargo=cargo",
  "--remap-path-prefix=/home/nemo157/.cargo/registry/src/github.com-1ecc6299db9ec823=crates.io",
  "--remap-path-prefix=/home/nemo157/.rustup=rustup",
]

I got a backtrace like this:

   8: clap::app::App::get_matches_from
             at crates.io/clap-2.33.3/crates.io/clap-2.33.3/src/app/mod.rs:1519:9
   9: clap::app::App::get_matches
             at crates.io/clap-2.33.3/crates.io/clap-2.33.3/src/app/mod.rs:1460:9
  10: structopt::StructOpt::from_args
             at ~/sources/bs58-rs/crates.io/structopt-0.3.18/src/lib.rs:1089:26
  11: <bs58::Args as paw_raw::ParseArgs>::parse_args
             at ~/sources/bs58-rs/cli/src/main.rs:69:17
  12: bs58::main
             at ~/sources/bs58-rs/cli/src/main.rs:83:1

Frames 8 and 9 include duplicate crates.io/clap-2.33.3 prefixes, and frame 10 randomly has a ~/sources/bs58-rs prefix

@Nemo157 Nemo157 added the C-bug Category: This is a bug. label Oct 28, 2020
@jonas-schievink jonas-schievink added A-reproducibility Area: Reproducible / deterministic builds regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 28, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Oct 28, 2020
@spastorino
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@spastorino spastorino added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 28, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue May 18, 2022
… r=davidtwco

--remap-path-prefix: Fix duplicated path components in debuginfo

This PR fixes an issue with `--remap-path-prefix` where path components could appear twice in the remapped version of the path (e.g. rust-lang#78479). The underlying problem was that `--remap-path-prefix` is often used to map an absolute path to something that looks like a relative path, e.g.:

```
--remap-path-prefix=/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823=crates.io",
```

and relative paths in debuginfo are interpreted as being relative to the compilation directory. So if Cargo invokes the compiler with `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0/src/lib.rs` as input and `/home/calvin/.cargo/registry/src/github.com-1ecc6299db9ec823/some_crate-0.1.0` as the compiler's working directory, then debuginfo will state that the working directory was `crates.io/some_crate-0.1.0` and the file is question was `crates.io/some_crate-0.1.0/src/lib.rs`, which combined gives the path:

```
crates.io/some_crate-0.1.0/crates.io/some_crate-0.1.0/src/lib.rs
```

With this PR the compiler will detect this situation and set up debuginfo in LLVM in a way that makes it strip the duplicated path components when emitting DWARF.

The PR also extracts the logic for making remapped paths absolute into a common helper function that is now used by debuginfo too (instead of just during crate metadata generation).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reproducibility Area: Reproducible / deterministic builds C-bug Category: This is a bug. P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants