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

'Should parse compilation unit: UnexpectedEof' running dwarfdump on a binary with a SHF_COMPRESSED .debug_info #195

Closed
luser opened this issue May 2, 2017 · 8 comments

Comments

@luser
Copy link
Contributor

luser commented May 2, 2017

I tried running gimli's dwarfdump on a binary from an Ubuntu package that was crashing Breakpad's dump_syms, but dwarfdump panics as well. A copy of the binary in question is here. It's from this deb file.

luser@eye7:/build/gimli$ RUST_BACKTRACE=1 cargo run --example dwarfdump -- /tmp/deb-contents/usr/lib/debug/.build-id/02/163988533d4192aa610a0d6ec03c349a2d10b9.debug
    Finished dev [unoptimized + debuginfo] target(s) in 0.2 secs
     Running `target/debug/examples/dwarfdump /tmp/deb-contents/usr/lib/debug/.build-id/02/163988533d4192aa610a0d6ec03c349a2d10b9.debug`

.debug_info
thread 'main' panicked at 'Should parse compilation unit: UnexpectedEof', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:868
stack backtrace:
   1:     0x55880364e66c - std::sys::imp::backtrace::tracing::imp::write::hf33ae72d0baa11ed
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x558803650b8e - std::panicking::default_hook::{{closure}}::h59672b733cc6a455
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:351
   3:     0x558803650794 - std::panicking::default_hook::h1670459d2f3f8843
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:367
   4:     0x558803650f6b - std::panicking::rust_panic_with_hook::hcf0ddb069e7beee7
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:555
   5:     0x558803650e04 - std::panicking::begin_panic::hd6eb68e27bdf6140
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:517
   6:     0x558803650d29 - std::panicking::begin_panic_fmt::hfea5965948b877f8
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:501
   7:     0x558803650cb7 - rust_begin_unwind
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:477
   8:     0x55880367c5cd - core::panicking::panic_fmt::hc0f6d7b2c300cdd9
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/panicking.rs:69
   9:     0x5588035984b6 - core::result::unwrap_failed::h9c0a209799863b53
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/macros.rs:29
  10:     0x55880358d9a5 - <core::result::Result<T, E>>::expect::h33b0d09147a2e563
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:769
  11:     0x5588035f5f09 - dwarfdump::dump_info::h446d1756de9d6452
                        at /build/gimli/examples/dwarfdump.rs:144
  12:     0x5588035f56d0 - dwarfdump::dump_file::hda1b626be36ebb40
                        at /build/gimli/examples/dwarfdump.rs:105
  13:     0x5588035f51b0 - dwarfdump::main::hde97895e853bae8c
                        at /build/gimli/examples/dwarfdump.rs:83
  14:     0x558803657dfa - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  15:     0x5588036516d6 - std::rt::lang_start::hd7c880a37a646e81
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panicking.rs:436
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/panic.rs:361
                        at /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libstd/rt.rs:57
  16:     0x55880360c912 - main
  17:     0x7fca291523f0 - __libc_start_main
  18:     0x55880356dd29 - _start
  19:                0x0 - <unknown>


I'm using the latest master (d591dc4).

@fitzgen
Copy link
Member

fitzgen commented May 2, 2017

Thanks for the bug report!

@luser
Copy link
Contributor Author

luser commented May 2, 2017

FWIW, dwarfdump on my system (Ubuntu 16.10) reads this file without issue:

.debug_info

COMPILE_UNIT<header overall offset = 0x00000000>:
< 0><0x0000000b>  DW_TAG_compile_unit
                    DW_AT_producer              GNU C11 6.2.0 20160901 -mtune=generic -march=x86-64 -g -O2 -fstack-protector-strong -fno-strict-aliasing -fstack-protector-strong
                    DW_AT_language              DW_LANG_C99
                    DW_AT_name                  dbus-binding-tool-glib.c
                    DW_AT_comp_dir              ./dbus
<...>

@tromey
Copy link
Member

tromey commented May 3, 2017

I think the issue is that the .debug_info section is SHF_COMPRESSED, but neither xmas-elf nor gimli decompresses the contents.

@philipc
Copy link
Collaborator

philipc commented May 3, 2017

Yes, gimli's dwarfdump works after using objcopy --decompress-debug-sections.

This is probably best to fix after implementing #182, assuming we still plan to do that.

@luser luser changed the title 'Should parse compilation unit: UnexpectedEof' running dwarfdump on a binary from an Ubuntu package 'Should parse compilation unit: UnexpectedEof' running dwarfdump on a binary with a SHF_COMPRESSED .debug_info May 3, 2017
@luser
Copy link
Contributor Author

luser commented May 3, 2017

Thanks for the info @tromey! Looking at the readelf output for the binary I now notice that it has a C in the flags column:

  [29] .debug_info       PROGBITS         0000000000000000  00000370
       000000000000e133  0000000000000000   C       0     0     1

With a new-enough binutils it's trivially easy to generate a binary for testing. I'm on Ubuntu 16.10:

luser@eye7:/build$ gcc --version
gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

luser@eye7:/build$ objcopy --version
GNU objcopy (GNU Binutils for Ubuntu) 2.27
Copyright (C) 2016 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
luser@eye7:/build$ cat hello.c
#include <stdio.h>

int main(int argc, char** argv)
{
  int x;
  printf("Hello world\n");
  return 0;
}
luser@eye7:/build$ gcc -o hello hello.c -g
luser@eye7:/build$ objcopy --compress-debug-sections hello hello-compressed
luser@eye7:/build/gimli$ cargo run --example dwarfdump -- /build/hello-compressed
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/examples/dwarfdump /build/hello-compressed`

.debug_info
thread 'main' panicked at 'Should parse compilation unit: UnexpectedEof', /buildslave/rust-buildbot/slave/stable-dist-rustc-linux/build/src/libcore/result.rs:868
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@luser
Copy link
Contributor Author

luser commented May 3, 2017

Oh, also, there's a good blog post describing SHF_COMPRESSED.

@fitzgen
Copy link
Member

fitzgen commented May 3, 2017

Thanks for the info @luser !

@philipc
Copy link
Collaborator

philipc commented Oct 15, 2018

This was fixed with the object update in #301.

@philipc philipc closed this as completed Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants