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

Deterministic package files break lldb #9512

Closed
ehuss opened this issue May 26, 2021 · 2 comments · Fixed by #9517
Closed

Deterministic package files break lldb #9512

ehuss opened this issue May 26, 2021 · 2 comments · Fixed by #9517
Labels
C-bug Category: bug

Comments

@ehuss
Copy link
Contributor

ehuss commented May 26, 2021

Problem
#8864 introduced deterministic packaging. One of the key aspects is that the mtime of every file is set to 0. Unfortunately, this seems to prevent lldb from reading the file. This means that stepping into dependencies from crates.io won't show any source information.

Arguably this is a bug in lldb. This does not seem to affect gdb. Unfortunately I feel like the likelyhood of fixing this in lldb is low (and even if it does get fixed, I imagine it would take years to trickle into Apple's release).

Steps

cargo new foo
cd foo
cargo package --allow-dirty
tar -xzvf target/package/foo-0.1.0.crate
cd foo-0.1.0
ls -al src   # verify that timestamp is Dec 31  1969 main.rs
cargo build
lldb target/debug/foo
b main.rs:2
run
######
# You should see output like this, notice there is no source information.
# Process 176294 launched: '/home/eric/Temp/foo/foo-0.1.0/target/debug/foo' (x86_64)
# Process 176294 stopped
# * thread #1, name = 'foo', stop reason = breakpoint 1.1
#     frame #0: 0x000055555555b9d4 foo`foo::main::h2ffdc3ce2a8b2165 at main.rs:2:5
quit

touch src/main.rs
cargo build
lldb target/debug/foo
b main.rs:2
run
######
# You should see output like this, notice we now have source!
# Process 176406 launched: '/home/eric/Temp/foo/foo-0.1.0/target/debug/foo' (x86_64)
# Process 176406 stopped
# * thread #1, name = 'foo', stop reason = breakpoint 1.1
#     frame #0: 0x000055555555b9d4 foo`foo::main::h2ffdc3ce2a8b2165 at main.rs:2:5
#    1    fn main() {
# -> 2        println!("Hello, world!");
#    3    }

Possible Solution(s)
I'm not sure. Cargo could set the timestamp of files when they are extracted. Would just need to be careful with #7590. I think setting all files to the same timestamp should be sufficient?

Notes

Output of cargo version: cargo 1.54.0-nightly (070e459 2021-05-11)

Seems to affect lldb on both macOS and Linux.
Linux: lldb version 10.0.0 and lldb version 11.0.0 and lldb version 12.0.1
macOS: lldb-1200.0.44.2 (Xcode 12.4 (12D4e))

@ehuss ehuss added the C-bug Category: bug label May 26, 2021
@alexcrichton
Copy link
Member

Wow nice find! This comparison in particular looks pretty suspcious.

I forgot that we preserved mtimes... In any case I think we should do two things to fix this:

  • For all tarballs going foward, let's set the mtime to like Jan 1, 2000. Just something that's nonzero (even 1 would probably be fine)
  • I'll update the tar crate to skip setting the mtime if the mtime is zero.

alexcrichton added a commit to alexcrichton/tar-rs that referenced this issue May 26, 2021
With rust-lang/cargo#9512 discovered this is, uh, odd fallout of the
"deterministic" header mode in this crate. This is an unintended
consequence of the deterministic header mode which should ideally be
fixable. This commit changes the `tar` crate to use a different constant
than 0 when creating archives with the deterministic header mode
(specifically 123456789: Nov 29, 1973). It also will now refuse to
create files with a 0 mtime, instead resetting the mtime to 1 which
should help the mtime be nonzero so tools like lldb don't accidentally
think it's zero.
@alexcrichton
Copy link
Member

Thinking more about this, I don't think that we can skip the zero mtime case. If we skip the zero mtime case then we run afoul of #7590 where we'd basically just ignore mtimes altogether. I've opened alexcrichton/tar-rs#250 to handle both points above which I think should fix this issue. New archives created by Cargo will have nonzero mtimes and older archives will start being extracted with an mtime of 1 instead of 0.

@ehuss mind reviewing that PR and the strategy here?

alexcrichton added a commit to alexcrichton/tar-rs that referenced this issue May 27, 2021
With rust-lang/cargo#9512 discovered this is, uh, odd fallout of the
"deterministic" header mode in this crate. This is an unintended
consequence of the deterministic header mode which should ideally be
fixable. This commit changes the `tar` crate to use a different constant
than 0 when creating archives with the deterministic header mode
(specifically 123456789: Nov 29, 1973). It also will now refuse to
create files with a 0 mtime, instead resetting the mtime to 1 which
should help the mtime be nonzero so tools like lldb don't accidentally
think it's zero.
bors added a commit that referenced this issue May 27, 2021
Update tar dependency to 0.4.35

Pulls in a fix which should avoid 0 mtime files from showing up.

Closes #9512
@bors bors closed this as completed in a02b6e5 May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants