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

DWARF information does not contain absolute file locations for generics #54408

Closed
yurydelendik opened this issue Sep 20, 2018 · 8 comments · Fixed by #54626
Closed

DWARF information does not contain absolute file locations for generics #54408

yurydelendik opened this issue Sep 20, 2018 · 8 comments · Fixed by #54626
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.)

Comments

@yurydelendik
Copy link
Contributor

STR (on Linux):

  1. Create hey.rs file that has generics usage (wget https://raw.githubusercontent.com/yurydelendik/old-man-sandbox/master/rust-wasm-hey/hey.rs)
  2. Compile code rustc +nightly hey.rs --crate-type=cdylib -g -o hey
  3. Dump DWARF info llvm-dwarfdump hey -debug-info -debug-line > hey.txt

Notice that hey.txt contains such entries as DW_AT_decl_file ("/home/yury/liballoc/vec.rs"), possibly produced by the fact that "liballoc/vec.rs" is a relative path and DW_AT_comp_dir is set to "/home/yury".

It is expected for core files to have absolute path e.g. "/rustc/20dc0c50704ba1fc8c56a88ae2bf05ddb3e419bc/src/liballoc/raw_vec.rs"

@alexcrichton alexcrichton added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Sep 20, 2018
@eddyb
Copy link
Member

eddyb commented Sep 25, 2018

cc @michaelwoerister @tromey I wonder what interaction (path rewriting?) causes this result.

@yurydelendik
Copy link
Contributor Author

FWIW, rustc +nightly hey.rs --crate-type=cdylib -g --emit=llvm-ir -o hey.ll produces hey.ll that shows that !DIFile entries has the directory field empty (and the filename is relative)

@yurydelendik
Copy link
Contributor Author

It is a regression, since +stable has absolute locations, e.g. !47 = !DIFile(filename: "/Users/travis/build/rust-lang/rust/src/libcore/ptr.rs", directory: "")

@michaelwoerister
Copy link
Member

@alexcrichton, could this have to do with #53829?

@alexcrichton
Copy link
Member

Likely so! I'll try to look into this in the near future

@alexcrichton
Copy link
Member

Ok so the change here can be exhibited with this script:

set -e

cat > foo.rs <<-EOF
#![crate_type = "lib"]
#[inline]
pub fn foo() {}
EOF

cat > bar.rs <<-EOF
#![crate_type = "cdylib"]
extern crate foo;
#[no_mangle]
pub extern fn bar() { foo::foo() }
EOF

rm -rf tmp
mkdir tmp
rustc -g foo.rs --out-dir tmp --remap-path-prefix=`pwd`=/another
rustc -g bar.rs --out-dir tmp -L tmp --emit llvm-ir

rg DIFile tmp/bar.ll

If you execute that script you see:

33:!1 = !DIFile(filename: "bar.rs", directory: "/home/alex/code/rust3")
37:!5 = !DIFile(filename: "foo.rs", directory: "")

but if you remove --remap-path-prefix you see:

33:!1 = !DIFile(filename: "bar.rs", directory: "/home/alex/code/rust3")
37:!5 = !DIFile(filename: "/home/alex/code/rust3/foo.rs", directory: "")

It appears that if upstream crates (like libstd) use --remap-path-prefix then their filename is listed as the original relative source file instead of the absolute path name that it had previous to #53829 when it wasn't compiled with --remap-path-prefix.

So somehow using --remap-path-prefix to compile libstd is affecting downstream crates to have relative path names instead of old absolute path names. It makes sense to me that the absolute path name goes away with --remap-path-prefix (that is the whole point after all) but ideally it'd still be an absolute path, just applying the mapping.

@michaelwoerister would you be able to help point me in the direction of where this change in logic might happen? If so I can test out a patch!

@michaelwoerister
Copy link
Member

@alexcrichton This should be what you're looking for:

// When exporting SourceFiles, we expand all paths to absolute
// paths because any relative paths are potentially relative to
// a wrong directory.
// However, if a path has been modified via
// `--remap-path-prefix` we assume the user has already set
// things up the way they want and don't touch the path values
// anymore.

One solution would be to compile libstd with absolute paths and apply proper remapping to those.

@alexcrichton
Copy link
Member

Ah that's perfect! I'll see if I can work up a solution to that soon

alexcrichton added a commit to alexcrichton/rust that referenced this issue Sep 27, 2018
This commit is a fix for rust-lang#54408 where on nightly right now whenever
generics are inlined the path name listed for the inlined function's
debuginfo is a relative path to the cwd, which surely doesn't exist!
Previously on beta/stable the debuginfo mentioned an absolute path which
still didn't exist, but more predictably didn't exist.

The change between stable/nightly is that nightly is now compiled with
`--remap-path-prefix` to give a deterministic prefix to all
rustc-generated paths in debuginfo. By using `--remap-path-prefix` the
previous logic would recognize that the cwd was remapped, causing the
original relative path name of the standard library to get emitted. If
`--remap-path-prefix` *wasn't* passed in then the logic would create an
absolute path name and then create a new source file entry.

The fix in this commit is to apply the "recreate the source file entry
with an absolute path" logic a bit more aggresively. If the source
file's name was remapped then we don't touch it, but otherwise we always
take the working dir (which may have been remapped) and then join it to
the file to ensure that we process all relative file names as well.

The end result is that the standard library should have an absolute path
for all file names in debuginfo (using our `--remap-path-prefix`
argument) as it does on stable after this patch.

Closes rust-lang#54408
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 23, 2018
…aelwoerister

rustc: Tweak filenames encoded into metadata

This commit is a fix for rust-lang#54408 where on nightly right now whenever
generics are inlined the path name listed for the inlined function's
debuginfo is a relative path to the cwd, which surely doesn't exist!
Previously on beta/stable the debuginfo mentioned an absolute path which
still didn't exist, but more predictably didn't exist.

The change between stable/nightly is that nightly is now compiled with
`--remap-path-prefix` to give a deterministic prefix to all
rustc-generated paths in debuginfo. By using `--remap-path-prefix` the
previous logic would recognize that the cwd was remapped, causing the
original relative path name of the standard library to get emitted. If
`--remap-path-prefix` *wasn't* passed in then the logic would create an
absolute path name and then create a new source file entry.

The fix in this commit is to apply the "recreate the source file entry
with an absolute path" logic a bit more aggresively. If the source
file's name was remapped then we don't touch it, but otherwise we always
take the working dir (which may have been remapped) and then join it to
the file to ensure that we process all relative file names as well.

The end result is that the standard library should have an absolute path
for all file names in debuginfo (using our `--remap-path-prefix`
argument) as it does on stable after this patch.

Closes rust-lang#54408
kennytm added a commit to kennytm/rust that referenced this issue Oct 24, 2018
…aelwoerister

rustc: Tweak filenames encoded into metadata

This commit is a fix for rust-lang#54408 where on nightly right now whenever
generics are inlined the path name listed for the inlined function's
debuginfo is a relative path to the cwd, which surely doesn't exist!
Previously on beta/stable the debuginfo mentioned an absolute path which
still didn't exist, but more predictably didn't exist.

The change between stable/nightly is that nightly is now compiled with
`--remap-path-prefix` to give a deterministic prefix to all
rustc-generated paths in debuginfo. By using `--remap-path-prefix` the
previous logic would recognize that the cwd was remapped, causing the
original relative path name of the standard library to get emitted. If
`--remap-path-prefix` *wasn't* passed in then the logic would create an
absolute path name and then create a new source file entry.

The fix in this commit is to apply the "recreate the source file entry
with an absolute path" logic a bit more aggresively. If the source
file's name was remapped then we don't touch it, but otherwise we always
take the working dir (which may have been remapped) and then join it to
the file to ensure that we process all relative file names as well.

The end result is that the standard library should have an absolute path
for all file names in debuginfo (using our `--remap-path-prefix`
argument) as it does on stable after this patch.

Closes rust-lang#54408
pietroalbini added a commit to pietroalbini/rust that referenced this issue Oct 25, 2018
…aelwoerister

rustc: Tweak filenames encoded into metadata

This commit is a fix for rust-lang#54408 where on nightly right now whenever
generics are inlined the path name listed for the inlined function's
debuginfo is a relative path to the cwd, which surely doesn't exist!
Previously on beta/stable the debuginfo mentioned an absolute path which
still didn't exist, but more predictably didn't exist.

The change between stable/nightly is that nightly is now compiled with
`--remap-path-prefix` to give a deterministic prefix to all
rustc-generated paths in debuginfo. By using `--remap-path-prefix` the
previous logic would recognize that the cwd was remapped, causing the
original relative path name of the standard library to get emitted. If
`--remap-path-prefix` *wasn't* passed in then the logic would create an
absolute path name and then create a new source file entry.

The fix in this commit is to apply the "recreate the source file entry
with an absolute path" logic a bit more aggresively. If the source
file's name was remapped then we don't touch it, but otherwise we always
take the working dir (which may have been remapped) and then join it to
the file to ensure that we process all relative file names as well.

The end result is that the standard library should have an absolute path
for all file names in debuginfo (using our `--remap-path-prefix`
argument) as it does on stable after this patch.

Closes rust-lang#54408
bors added a commit that referenced this issue Oct 26, 2018
rustc: Tweak filenames encoded into metadata

This commit is a fix for #54408 where on nightly right now whenever
generics are inlined the path name listed for the inlined function's
debuginfo is a relative path to the cwd, which surely doesn't exist!
Previously on beta/stable the debuginfo mentioned an absolute path which
still didn't exist, but more predictably didn't exist.

The change between stable/nightly is that nightly is now compiled with
`--remap-path-prefix` to give a deterministic prefix to all
rustc-generated paths in debuginfo. By using `--remap-path-prefix` the
previous logic would recognize that the cwd was remapped, causing the
original relative path name of the standard library to get emitted. If
`--remap-path-prefix` *wasn't* passed in then the logic would create an
absolute path name and then create a new source file entry.

The fix in this commit is to apply the "recreate the source file entry
with an absolute path" logic a bit more aggresively. If the source
file's name was remapped then we don't touch it, but otherwise we always
take the working dir (which may have been remapped) and then join it to
the file to ensure that we process all relative file names as well.

The end result is that the standard library should have an absolute path
for all file names in debuginfo (using our `--remap-path-prefix`
argument) as it does on stable after this patch.

Closes #54408
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants