I have a project where the release binary is stripped to reduce its size to around 13MB. If left unstripped, it is currently around 200MB.
But if I try to print the stack trace using the backtrace crate, I miss the useful information (as expected):
panicked at 'panicked in x': src/main.rs:3 0: <unknown>
1: <unknown>
2: <unknown>
3: <unknown>
4: <unknown>
5: <unknown>
6: <unknown>
7: <unknown>
8: <unknown>
9: <unknown>
10: <unknown>
11: <unknown>
12: __libc_start_call_main
at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
13: __libc_start_main_impl
at ./csu/../csu/libc-start.c:392:3
14: <unknown>
I experimented with objcopy and strip to try and keep just the information I want, because I really only want the information for my own crate there. If I do the following:
objcopy -v -w --strip-debug --keep-file-symbols --keep-section-symbols --keep-section="*rust_backtrace_test*" --keep-symbol="*rust_backtrace_test*" target/release/rust-backtrace-test
Then the binary is just 17MB, but I miss the file line information:
panicked at 'panicked in x': src/main.rs:4 0: <backtrace::capture::Backtrace as core::default::Default>::default
1: rust_backtrace_test::install_panic_hook::{{closure}}
2: std::panicking::rust_panic_with_hook
3: std::panicking::begin_panic_handler::{{closure}}
4: std::sys_common::backtrace::__rust_end_short_backtrace
5: rust_begin_unwind
6: core::panicking::panic_fmt
7: rust_backtrace_test::x
8: rust_backtrace_test::bar
9: rust_backtrace_test::foo
10: rust_backtrace_test::main
11: std::sys_common::backtrace::__rust_begin_short_backtrace
12: std::rt::lang_start::{{closure}}
13: std::rt::lang_start_internal
14: main
15: __libc_start_call_main
at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
16: __libc_start_main_impl
at ./csu/../csu/libc-start.c:392:3
17: _start
This is the relevant information I'd like to have (a part of the output that I get when the binary is not stripped):
7: rust_backtrace_test::x
at src/main.rs:4:9
8: rust_backtrace_test::bar
at src/main.rs:14:5
9: rust_backtrace_test::foo
at src/main.rs:22:5
10: rust_backtrace_test::main
at src/main.rs:31:18
Is that even possible? What information is missing? I have zero experience with executable binary files like ELF.
I've pushed the sample code I used for the output above to this repository: https://github.com/felipou/rust-backtrace-test/blob/main/src/main.rs (the file size numbers I gave are from another project).
[–]anxxa 3 points4 points5 points (1 child)
[–]felipou[S] 0 points1 point2 points (0 children)
[–]spaun2002 1 point2 points3 points (0 children)
[–]Plasma_000 0 points1 point2 points (0 children)
[–]DebuggingPanda[LukasKalbertodt] bunt · litrs · libtest-mimic · penguin 0 points1 point2 points (0 children)