pacak / cargo-show-asm

cargo subcommand showing the assembly, LLVM-IR and MIR generated for Rust code
Apache License 2.0
714 stars 35 forks source link

panic with message "DWARF file refers to an undefined location" #289

Closed betelgeuse closed 5 months ago

betelgeuse commented 5 months ago

Output

:/app# RUST_BACKTRACE=full cargo asm --bin mmap --rust --everything

    Finished `release` profile [optimized] target(s) in 0.07s
    .text
    .file   "mmap.d5c79bd6df815694-cgu.0"
.section .text.std::io::Write::write_fmt,"ax",@progbits
    .p2align    2
    .type   std::io::Write::write_fmt,@function
std::io::Write::write_fmt:
thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-show-asm-0.2.36/src/asm.rs:285:21:
DWARF file refers to an undefined location Loc { file: 1, line: 1814, column: 0, extra: None }
stack backtrace:
   0:     0xaaaac0cf1428 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdbd0154edd27beae
   1:     0xaaaac0d11bd0 - core::fmt::write::hd00e4dd0f79a6962
   2:     0xaaaac0cee3a0 - std::io::Write::write_fmt::hfe9cba738b97abe4
   3:     0xaaaac0cf1270 - std::sys::backtrace::print::h98cdc673933b7a70
   4:     0xaaaac0cf2780 - std::panicking::default_hook::{{closure}}::h2fd387741efa82f6
   5:     0xaaaac0cf23e8 - std::panicking::default_hook::hae15ef2aca4ca978
   6:     0xaaaac0cf2cb4 - std::panicking::rust_panic_with_hook::h0fab909538e02d6f
   7:     0xaaaac0cf2abc - std::panicking::begin_panic_handler::{{closure}}::hce66eb404d13d1f8
   8:     0xaaaac0cf1910 - std::sys::backtrace::__rust_end_short_backtrace::ha5ea7c255d0d41a0
   9:     0xaaaac0cf27d0 - rust_begin_unwind
  10:     0xaaaac0b6722c - core::panicking::panic_fmt::h79524b56a5fcb226
  11:     0xaaaac0b98fd4 - <cargo_show_asm::asm::Asm as cargo_show_asm::Dumpable>::dump_range::h31821f4de5e275a3
  12:     0xaaaac0b8286c - cargo_show_asm::dump_function::h4ff065852407b087
  13:     0xaaaac0b7cf7c - cargo_asm::main::hbec0d681464995a0
  14:     0xaaaac0b94c20 - std::sys::backtrace::__rust_begin_short_backtrace::h7ea072e629dbbbdc
  15:     0xaaaac0b8f3b8 - std::rt::lang_start::{{closure}}::he9b4f38ea1b05712
  16:     0xaaaac0ce86ec - std::rt::lang_start_internal::h457550829114b953
  17:     0xaaaac0b7e9e8 - main
  18:     0xffff97c47780 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  19:     0xffff97c47858 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  20:     0xaaaac0b67870 - _start
  21:                0x0 - <unknown>

Presumably at least the situation could be handled more gracefully.

pacak commented 5 months ago

Do you have a reproduction public? Also - what platform/version do you use?

On Wed, Jun 26, 2024, 11:28 Petteri Räty @.***> wrote:

Output

:/app# RUST_BACKTRACE=full cargo asm --bin mmap --rust --everything

Finished `release` profile [optimized] target(s) in 0.07s

.text .file "mmap.d5c79bd6df815694-cgu.0" .section .@. .p2align 2 .type @. std::io::Write::write_fmt: thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-show-asm-0.2.36/src/asm.rs:285:21: DWARF file refers to an undefined location Loc { file: 1, line: 1814, column: 0, extra: None } stack backtrace: 0: 0xaaaac0cf1428 - ::fmt::hdbd0154edd27beae 1: 0xaaaac0d11bd0 - core::fmt::write::hd00e4dd0f79a6962 2: 0xaaaac0cee3a0 - std::io::Write::write_fmt::hfe9cba738b97abe4 3: 0xaaaac0cf1270 - std::sys::backtrace::print::h98cdc673933b7a70 4: 0xaaaac0cf2780 - std::panicking::default_hook::{{closure}}::h2fd387741efa82f6 5: 0xaaaac0cf23e8 - std::panicking::default_hook::hae15ef2aca4ca978 6: 0xaaaac0cf2cb4 - std::panicking::rust_panic_with_hook::h0fab909538e02d6f 7: 0xaaaac0cf2abc - std::panicking::begin_panic_handler::{{closure}}::hce66eb404d13d1f8 8: 0xaaaac0cf1910 - std::sys::backtrace::__rust_end_short_backtrace::ha5ea7c255d0d41a0 9: 0xaaaac0cf27d0 - rust_begin_unwind 10: 0xaaaac0b6722c - core::panicking::panic_fmt::h79524b56a5fcb226 11: 0xaaaac0b98fd4 - ::dump_range::h31821f4de5e275a3 12: 0xaaaac0b8286c - cargo_show_asm::dump_function::h4ff065852407b087 13: 0xaaaac0b7cf7c - cargo_asm::main::hbec0d681464995a0 14: 0xaaaac0b94c20 - std::sys::backtrace::rust_begin_short_backtrace::h7ea072e629dbbbdc 15: 0xaaaac0b8f3b8 - std::rt::lang_start::{{closure}}::he9b4f38ea1b05712 16: 0xaaaac0ce86ec - std::rt::lang_start_internal::h457550829114b953 17: 0xaaaac0b7e9e8 - main 18: 0xffff97c47780 - libc_start_call_main at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 19: 0xffff97c47858 - __libc_start_main_impl at ./csu/../csu/libc-start.c:360:3 20: 0xaaaac0b67870 - _start 21: 0x0 -

Presumably at least the situation could be handled more gracefully.

— Reply to this email directly, view it on GitHub https://github.com/pacak/cargo-show-asm/issues/289, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAQFI4W6PD3PHMWZBOMVPLZJLMZHAVCNFSM6AAAAABJ6EPVKWVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3TKNRVHEZDGNQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

betelgeuse commented 5 months ago

Do you have a reproduction public? Also - what platform/version do you use?

I don't and Linux f1782c895047 6.6.26-linuxkit #1 SMP Sat Apr 27 04:13:19 UTC 2024 aarch64 GNU/Linux

This is from a container from the image 4da2332e8c88 (rustlang/rust:nightly from some time ago)

pacak commented 5 months ago

So the fix should be as simple as removing panic, but I would like to understand the problem.

Can you attach the .s file it tries to process and output of cargo asm -vv - mostly parts about what it detects? They shouldn't contain anything sensitive, you can use manpacket at gmail if you prefer.

betelgeuse commented 5 months ago

So the fix should be as simple as removing panic, but I would like to understand the problem.

Can you attach the .s file it tries to process and output of cargo asm -vv - mostly parts about what it detects? They shouldn't contain anything sensitive, you can use manpacket at gmail if you prefer.

The .s file is basically all logic inlined. But here's the current output and the start of the .s file.

    Finished `release` profile [optimized] target(s) in 0.08s

Artifact files: ["/app/target/release/mmap"]
Working with file: /app/target/release/deps/mmap-80e1dd19c4c62c11.s
    .text
    .file   "mmap.d5c79bd6df815694-cgu.0"
.section .text.std::sys::backtrace::__rust_begin_short_backtrace,"ax",@progbits
    .p2align    2
    .type   std::sys::backtrace::__rust_begin_short_backtrace,@function
std::sys::backtrace::__rust_begin_short_backtrace:
thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/cargo-show-asm-0.2.36/src/asm.rs:285:21:
DWARF file refers to an undefined location Loc { file: 1, line: 151, column: 0, extra: None }
stack backtrace:
   0:     0xaaaacf2e1428 - <std::sys::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hdbd0154edd27beae
   1:     0xaaaacf301bd0 - core::fmt::write::hd00e4dd0f79a6962
   2:     0xaaaacf2de3a0 - std::io::Write::write_fmt::hfe9cba738b97abe4
   3:     0xaaaacf2e1270 - std::sys::backtrace::print::h98cdc673933b7a70
   4:     0xaaaacf2e2780 - std::panicking::default_hook::{{closure}}::h2fd387741efa82f6
   5:     0xaaaacf2e23e8 - std::panicking::default_hook::hae15ef2aca4ca978
   6:     0xaaaacf2e2cb4 - std::panicking::rust_panic_with_hook::h0fab909538e02d6f
   7:     0xaaaacf2e2abc - std::panicking::begin_panic_handler::{{closure}}::hce66eb404d13d1f8
   8:     0xaaaacf2e1910 - std::sys::backtrace::__rust_end_short_backtrace::ha5ea7c255d0d41a0
   9:     0xaaaacf2e27d0 - rust_begin_unwind
  10:     0xaaaacf15722c - core::panicking::panic_fmt::h79524b56a5fcb226
  11:     0xaaaacf188fd4 - <cargo_show_asm::asm::Asm as cargo_show_asm::Dumpable>::dump_range::h31821f4de5e275a3
  12:     0xaaaacf17286c - cargo_show_asm::dump_function::h4ff065852407b087
  13:     0xaaaacf16cf7c - cargo_asm::main::hbec0d681464995a0
  14:     0xaaaacf184c20 - std::sys::backtrace::__rust_begin_short_backtrace::h7ea072e629dbbbdc
  15:     0xaaaacf17f3b8 - std::rt::lang_start::{{closure}}::he9b4f38ea1b05712
  16:     0xaaaacf2d86ec - std::rt::lang_start_internal::h457550829114b953
  17:     0xaaaacf16e9e8 - main
  18:     0xffff8fc97780 - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  19:     0xffff8fc97858 - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  20:     0xaaaacf157870 - _start
  21:                0x0 - <unknown>

head -n 20 target/release/deps/mmap-80e1dd19c4c62c11.s

    .text
    .file   "mmap.d5c79bd6df815694-cgu.0"
    .section    .text._ZN3std3sys9backtrace28__rust_begin_short_backtrace17h065b82dfadfc7072E,"ax",@progbits
    .p2align    2
    .type   _ZN3std3sys9backtrace28__rust_begin_short_backtrace17h065b82dfadfc7072E,@function
_ZN3std3sys9backtrace28__rust_begin_short_backtrace17h065b82dfadfc7072E:
.Lfunc_begin0:
    .file   1 "/rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys" "backtrace.rs"
    .loc    1 151 0
    .cfi_startproc
    str x30, [sp, #-16]!
    .cfi_def_cfa_offset 16
    .cfi_offset w30, -16
.Ltmp1358:
    .file   2 "/rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src/ops" "function.rs"
    .loc    2 250 5 prologue_end
    blr x0
.Ltmp1359:
    .file   3 "/rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/core/src" "hint.rs"
    .loc    3 338 5

The line does seem to be present in backtrace.rs

# tail -n+150 /rustc/6b0f4b5ec3aa707ecaa78230722117324a4ce23c/library/std/src/sys/backtrace.rs | head -n 10
#[cfg_attr(feature = "backtrace", inline(never))]
pub fn __rust_begin_short_backtrace<F, T>(f: F) -> T
where
    F: FnOnce() -> T,
{
    let result = f();

    // prevent this frame from being tail-call optimised away
    crate::hint::black_box(());
pacak commented 5 months ago

Thank you for the bug report, I was able to reproduce and the fix was trivial after that. 0.2.37 is out.