Description
From Rust v1.37.0 onwards on Mac OS 10.14.6, a panic triggered in a dynamically loaded library does not produce a full stacktrace if the library was loaded by passing an absolute path to dlopen
. I haven't been able to test other platforms Windows and Linux do not have the issue, see #67599 (comment) and #67599 (comment).
The project at https://github.com/t-mw/libreloading-test-rs loads a library using its absolute path by default. The loading is done by libloading
which uses dlopen
internally.
With Rust 1.40 and RUST_BACKTRACE=full cargo run
the following output is produced (Rust 1.37 produces similar output):
thread '<unnamed>' panicked at '!!!', src/lib.rs:6:9
stack backtrace:
0: 0x10d4df815 - <unknown>
1: 0x10d4f6a20 - <unknown>
2: 0x10d4de60b - <unknown>
3: 0x10d4e0f73 - <unknown>
4: 0x10d4e0c7a - <unknown>
5: 0x10d4e15cb - <unknown>
6: 0x10d4db94c - <unknown>
7: 0x10d4db5a4 - <unknown>
8: 0x10d4db3b1 - <unknown>
9: 0x10d445269 - libloading_test::main::h9b608f0903e21359
at src/main.rs:13
...
The expected output can be seen by compiling the same code with Rust 1.36. However, this is still missing some details about line numbers, for example for reloadable::RELOAD_API::{{closure}}
:
thread '<unnamed>' panicked at '!!!', src/lib.rs:6:9
stack backtrace:
0: 0x101056663 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::hbc4a87dc97d9c209
1: 0x1010535d2 - std::sys_common::backtrace::_print::h411a08c36ea9f4e9
2: 0x101055ca6 - std::panicking::default_hook::{{closure}}::hc6f50b761777cef2
3: 0x101055a4f - std::panicking::default_hook::h871283332e86768d
4: 0x10105632f - std::panicking::rust_panic_with_hook::hddd286a9c773fc67
5: 0x10104e010 - std::panicking::begin_panic::h6dc165374aa0a9bd
6: 0x10104e923 - reloadable::RELOAD_API::{{closure}}::h42ed074a77f6faff
7: 0x10104e830 - core::ops::function::FnOnce::call_once::h5642339838887a68
8: 0x100fba70d - libloading_test::main::h7208d4e03f17b192
at src/main.rs:13
...
Ideally, the output would be the same as when a relative path name is passed to dlopen
(by uncommenting https://github.com/t-mw/libreloading-test-rs/blob/master/src/main.rs#L11), which produces a complete backtrace in Rust 1.36 to 1.40. Rust 1.40 produces the following output in that case:
thread '<unnamed>' panicked at '!!!', src/lib.rs:6:9
stack backtrace:
0: 0x10fe8c815 - backtrace::backtrace::libunwind::trace::hb16ec6045891ce5a
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: 0x10fe8c815 - backtrace::backtrace::trace_unsynchronized::hcacbd0efdffd74c6
at /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: 0x10fe8c815 - std::sys_common::backtrace::_print_fmt::h39e22de9d6757d12
at src/libstd/sys_common/backtrace.rs:77
3: 0x10fe8c815 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h415ddd0ba88caaaf
at src/libstd/sys_common/backtrace.rs:61
4: 0x10fea3a20 - core::fmt::write::h3335552e2df81c1d
at src/libcore/fmt/mod.rs:1028
5: 0x10fe8b60b - std::io::Write::write_fmt::he6837371b9a45188
at src/libstd/io/mod.rs:1412
6: 0x10fe8df73 - std::sys_common::backtrace::_print::h89459d14ba97f5fa
at src/libstd/sys_common/backtrace.rs:65
7: 0x10fe8df73 - std::sys_common::backtrace::print::ha4c6688e811b8829
at src/libstd/sys_common/backtrace.rs:50
8: 0x10fe8df73 - std::panicking::default_hook::{{closure}}::h708e66cfeb0483ba
at src/libstd/panicking.rs:188
9: 0x10fe8dc7a - std::panicking::default_hook::h39ea8ddf674c04ec
at src/libstd/panicking.rs:205
10: 0x10fe8e5cb - std::panicking::rust_panic_with_hook::h9db77b22c2255a16
at src/libstd/panicking.rs:464
11: 0x10fe8894c - std::panicking::begin_panic::h21574f5509dfe34a
at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libstd/panicking.rs:400
12: 0x10fe885a4 - reloadable::RELOAD_API::{{closure}}::haea0cf290bcd83d5
at src/lib.rs:6
13: 0x10fe883b1 - core::ops::function::FnOnce::call_once::h32c523a7aa5b79f3
at /rustc/73528e339aae0f17a15ffa49a8ac608f50c6cf14/src/libcore/ops/function.rs:227
14: 0x10fdf2279 - libloading_test::main::h9b608f0903e21359
at src/main.rs:13
...