RazrFalcon / cargo-bloat

Find out what takes most of the space in your executable.
MIT License
2.37k stars 50 forks source link

Crash when trying to check repository #63

Closed qarmin closed 3 years ago

qarmin commented 4 years ago
git clone https://github.com/qarmin/czkawka
cd czkawka
cargo bloat --release

will print this panic

rafal@rafalDesktop:~/Projekty/Rust/czkawka$ cargo bloat --release
    Finished release [optimized] target(s) in 0.08s
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: MalformedInput', /home/rafal/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-bloat-0.10.0/src/main.rs:806:59
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
qarmin commented 4 years ago

Ubuntu 20.04

Shnatsel commented 4 years ago

The error does look like it originated in binfarce. I'll take a look.

Shnatsel commented 4 years ago

I've run cargo install cargo-bloat and ran it on czkawka repository on commit 1829d19b2878420dd4c852be1459cf0bfd95aee8 - both cargo bloat and cargo bloat --release work for me on Ubuntu 18.04. Interesting.

Shnatsel commented 4 years ago

The error in the backtrace you've provided points to the last unwrap() in this line:

https://github.com/RazrFalcon/cargo-bloat/blob/ea34f9835fc67a0e383ebdc19b9176a3cc44464c/src/main.rs#L806

So ELF parsing has succeeded, but symbol extraction has failed. Interesting. Could you attach the contents of your target/ directory after running both cargo bloat and cargo bloat --release?

qarmin commented 4 years ago

target folder which caused crash have 7,7 GB of data.

I moved it to trash, then created new target directory(by compiling program), next I renamed it and at the end I restored from trash original target directory.

But now I can't reproduce issue. I tried compile it, create doc etc. but nothing cause crash

qarmin commented 4 years ago

The strangest is that when I run cargo bloat --release, then almost everytime shows different results e.g.

rafal@rafalDesktop:~/Projekty/Rust/czkawka$ cargo bloat --release
    Finished release [optimized] target(s) in 0.08s
    Analyzing target/release/czkawka_gui

 File  .text     Size        Crate Name
 0.9%   6.4%  36.5KiB  czkawka_gui czkawka_gui::main::{{closure}}
 0.6%   4.0%  22.6KiB  czkawka_gui czkawka_gui::main
 0.4%   3.0%  16.9KiB czkawka_core czkawka_core::duplicate::DuplicateFinder::find_duplicates
 0.4%   2.9%  16.4KiB  czkawka_gui czkawka_gui::main::{{closure}}
 0.3%   1.9%  10.7KiB    [Unknown] add_ranges
 0.3%   1.8%  10.3KiB    [Unknown] read_line_info
 0.2%   1.7%   9.4KiB czkawka_core czkawka_core::big_file::BigFile::find_big_files
 0.2%   1.6%   9.3KiB    [Unknown] elf_add
 0.2%   1.5%   8.4KiB czkawka_core czkawka_core::empty_folder::EmptyFolder::find_empty_folders
 0.2%   1.4%   8.2KiB czkawka_core czkawka_core::temporary::Temporary::find_temporary_files
 0.2%   1.4%   8.0KiB czkawka_core czkawka_core::empty_files::EmptyFiles::find_empty_files
 0.2%   1.4%   7.7KiB          std __rdos_backtrace_dwarf_add
 0.2%   1.2%   7.0KiB    [Unknown] read_attribute
 0.1%   1.0%   5.4KiB czkawka_core <czkawka_core::duplicate::DuplicateFinder as czkawka_core::common_traits::SaveResults>::save_results_to_file
 0.1%   0.9%   5.0KiB          std core::num::flt2dec::strategy::dragon::format_shortest
 0.1%   0.7%   4.0KiB          std core::num::flt2dec::strategy::dragon::format_exact
 0.1%   0.7%   3.8KiB czkawka_core <czkawka_core::empty_folder::EmptyFolder as czkawka_core::common_traits::SaveResults>::save_results_to_file
 0.1%   0.7%   3.8KiB    [Unknown] elf_zlib_inflate_and_verify
 0.1%   0.6%   3.7KiB czkawka_core czkawka_core::common_extensions::Extensions::set_allowed_extensions
 0.1%   0.6%   3.6KiB czkawka_core czkawka_core::common_directory::Directories::set_included_directory
 8.0%  54.9% 312.7KiB              And 1216 smaller methods. Use -n N to show more.
14.5% 100.0% 569.3KiB              .text section size, the file size is 3.8MiB
rafal@rafalDesktop:~/Projekty/Rust/czkawka$ cargo bloat --release
    Finished release [optimized] target(s) in 0.08s
    Analyzing target/release/czkawka_gui_orbtk

 File  .text    Size             Crate Name
 0.4%   1.4% 26.2KiB     orbtk_widgets <orbtk_widgets::text_box::TextBox as orbtk_api::widget_base::template::Template>::template
 0.4%   1.2% 22.7KiB     orbtk_widgets <orbtk_widgets::button::Button as orbtk_api::widget_base::template::Template>::template
 0.4%   1.2% 22.6KiB               std std::sync::once::Once::call_once::{{closure}}
 0.3%   1.2% 22.0KiB     orbtk_widgets <orbtk_widgets::tab_widget::TabHeader as orbtk_api::widget_base::template::Template>::template
 0.2%   0.8% 14.2KiB     orbtk_widgets <orbtk_widgets::tab_widget::TabHeader as orbtk_api::widget_base::Widget>::build
 0.2%   0.7% 13.7KiB czkawka_gui_orbtk czkawka_gui_orbtk::main::{{closure}}
 0.2%   0.7% 12.8KiB     orbtk_widgets <orbtk_widgets::button::Button as orbtk_api::widget_base::Widget>::build
 0.2%   0.7% 12.2KiB            minifb minifb::os::posix::wayland::Window::new
 0.2%   0.6% 12.0KiB     orbtk_widgets <orbtk_widgets::text_box::TextBox as orbtk_api::widget_base::Widget>::build
 0.2%   0.6% 11.4KiB         orbtk_api <orbtk_api::layout::grid::GridLayout as orbtk_api::layout::Layout>::arrange
 0.2%   0.6% 10.7KiB         [Unknown] add_ranges
 0.2%   0.6% 10.3KiB         [Unknown] read_line_info
 0.2%   0.5%  9.8KiB            minifb minifb::os::posix::x11::Window::new
 0.2%   0.5%  9.6KiB         orbtk_api orbtk_api::application::window_adapter::create_window
 0.1%   0.5%  9.3KiB         [Unknown] elf_add
 0.1%   0.5%  8.8KiB     orbtk_widgets <orbtk_widgets::behaviors::text_behavior::TextBehavior as orbtk_api::widget_base::Widget>::build
 0.1%   0.5%  8.6KiB         orbtk_api <orbtk_api::systems::event_state_system::EventStateSystem as dces::system::System<orbtk_tree::Tree,dces::component::string_component_store::StringComponentStore,orbtk_re...
 0.1%   0.4%  8.3KiB     orbtk_widgets <orbtk_widgets::window::Window as orbtk_api::widget_base::Widget>::build
 0.1%   0.4%  7.7KiB               std __rdos_backtrace_dwarf_add
 0.1%   0.4%  7.7KiB     orbtk_widgets <orbtk_widgets::tab_widget::TabWidget as orbtk_api::widget_base::Widget>::build
24.4%  83.6%  1.5MiB                   And 5343 smaller methods. Use -n N to show more.
29.1% 100.0%  1.8MiB                   .text section size, the file size is 6.2MiB
RazrFalcon commented 4 years ago

Looks like a binary selection bug. First time you got czkawka_gui, next time czkawka_gui_orbtk.

https://github.com/RazrFalcon/cargo-bloat/blob/ea34f9835fc67a0e383ebdc19b9176a3cc44464c/src/main.rs#L638

Looks like cargo can return artifacts in a random order.

lexxvir commented 3 years ago

Hi there,

I encountered into the same crash when I ran cargo bloat on Xtensa target (it's not in upstream, so I use custom Rust toolchain). Same crate works OK when using thumbv (ARMv7) target.

RazrFalcon commented 3 years ago

Can you sent a produced binary?

lexxvir commented 3 years ago

Hi @RazrFalcon,

Attached minimal binary that reproduced the issue: dummy.zip

RazrFalcon commented 3 years ago

Hm... looks like this file doesn't have the .text section. Only .rtc.text. I'm not familiar with your target and I'm not sure how it should be handled.

And we definitely have to improve binfarce's error reporting.

lexxvir commented 3 years ago

I believe .flash.text section contains a code. It is a target for embedded devices used ESP32 CPU.

RazrFalcon commented 3 years ago

I've created #64 for your issue.

fosskers commented 3 years ago

I had this issue still, but after deleting my target/ and letting cargo bloat --release build the release binary, it worked.

RazrFalcon commented 3 years ago

@lexxvir I've finally added --symbols-section. Please test if it actually works as expected.

lexxvir commented 3 years ago

Hi @RazrFalcon !

Thanks a lot. I've just tested --symbols-section and it works for me.

RazrFalcon commented 3 years ago

Glad to hear!

felipelalli commented 1 year ago

I had this issue still, but after deleting my target/ and letting cargo bloat --release build the release binary, it worked.

Unfortunately it didn't work for me:

    Finished release [optimized] target(s) in 0.15s
Error: parsing failed cause 'section .symtab is missing'.
RazrFalcon commented 1 year ago

@felipelalli Do you have strip = true?

felipelalli commented 1 year ago

@felipelalli Do you have strip = true?

yes, just for release:

[profile.release]
opt-level = 'z'     # Optimize for size
lto = true          # Enable link-time optimization
codegen-units = 1   # Reduce number of codegen units to increase optimizations
panic = 'abort'     # Abort on panic
strip = true        # Strip symbols from binary*
RazrFalcon commented 1 year ago

87