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

[feat] should document on how to support backtrace when size optimize #675

Open
loynoir opened this issue Sep 29, 2024 · 3 comments
Open

Comments

@loynoir
Copy link

loynoir commented Sep 29, 2024

feat

should document on how to support backtrace when size optimize

reproduce

fn show_backtrace() {
    let backtrace = backtrace::Backtrace::new();
    eprintln!("backtrace::Backtrace {:?}", backtrace);
}

fn f4() {
    show_backtrace()
}

fn f3() {
    f4()
}

fn f2() {
    f3()
}

fn f1() {
    f2()
}

fn main() {
    f1()
}

actual

When use size optimize config, backtrace is not working.

[profile.reproduce]
inherits = "release"

debug = false
strip = true
backtrace::Backtrace    0: <unknown>
   1: <unknown>
   2: <unknown>
   3: <unknown>
   4: __libc_start_main
   5: <unknown>

544K    bt

When use backtrace working config, size is much larger than size optimize config.

[profile.reproduce]
inherits = "release"

debug = true
strip = false
backtrace::Backtrace    0: bt::show_backtrace
             at /path/to/reproduce/src/bin/bt.rs:2:21
      bt::f4
             at /path/to/reproduce/src/bin/bt.rs:7:5
      bt::f3
             at /path/to/reproduce/src/bin/bt.rs:11:5
      bt::f2
             at /path/to/reproduce/src/bin/bt.rs:15:5
      bt::f1
             at /path/to/reproduce/src/bin/bt.rs:19:5
      bt::main
             at /path/to/reproduce/src/bin/bt.rs:23:5
   1: core::ops::function::FnOnce::call_once
             at /rustc/9b72238eb813e9d06e9e9d270168512fbffd7ee7/library/core/src/ops/function.rs:250:5
      std::sys::backtrace::__rust_begin_short_backtrace
             at /rustc/9b72238eb813e9d06e9e9d270168512fbffd7ee7/library/std/src/sys/backtrace.rs:154:18
   2: main
   3: <unknown>
   4: __libc_start_main
   5: _start

5.4M    bt

expected

Should document on how to find a balance like something like below.

[profile.reproduce]
inherits = "release"

debug = false_but_keep_user_backtrace
strip = true_but_not_user_backtrace
backtrace::Backtrace    0: bt::show_backtrace
             at /path/to/reproduce/src/bin/bt.rs:2:21
      bt::f4
             at /path/to/reproduce/src/bin/bt.rs:7:5
      bt::f3
             at /path/to/reproduce/src/bin/bt.rs:11:5
      bt::f2
             at /path/to/reproduce/src/bin/bt.rs:15:5
      bt::f1
             at /path/to/reproduce/src/bin/bt.rs:19:5
      bt::main
             at /path/to/reproduce/src/bin/bt.rs:23:5
   **/rustc/xxx are not kept **
   **main, <unknown>, __libc_start_main, _start are not kept**

544K    bt
@bjorn3
Copy link
Member

bjorn3 commented Sep 29, 2024

You can use strip = "debuginfo" to strip all debuginfo, but keep the symbols used for backtraces. In fact this is the default for release mode nowadays. Symbols are a lot smaller than debuginfo, so unless you really need every last kb of space, you should probably use strip = "debuginfo".

@loynoir
Copy link
Author

loynoir commented Sep 29, 2024

But, f1 f2 f3 f4 are still missing.

[profile.reproduce]
inherits = "release"

debug = true
strip = "debuginfo"
backtrace::Backtrace    0: bt::main
   1: std::sys::backtrace::__rust_begin_short_backtrace
   2: main
   3: <unknown>
   4: __libc_start_main
   5: _start

620K    bt

@bjorn3
Copy link
Member

bjorn3 commented Sep 29, 2024

They probably got inlined. Full debuginfo also keeps information about inlined functions, but most of the time backtraces are legible without this information anyway and even with full debuginfo the compiler may replace tail calls with jumps, which would irrecoverably lose the stack frame for the caller.

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

2 participants