backtrace-rs
backtrace-rs copied to clipboard
gimli/libbacktrace don't handle dynamically loaded libraries
Currently iteration over all dynamic objects happens once in libbacktrace/gimli (gimli for sure, libbacktrace is a best approximation). This means that if a backtrace is generated and then afterwards a dynamic object is loaded (e.g. via dlopen
) the backtraces through that new dynamic object may be missing symbol information. We'll likely need to add a fallback in gimli where if a symbol doesn't hit the cache of libraries we know about we check again to see if any new libraries have been opened.
Could this explain backtraces in dynamically loaded libraries becoming <unknown>
from Rust 1.37 onwards? I also saw that https://github.com/rust-lang/rust/pull/57967 was causing a similar issue in >= 1.37 (https://github.com/rust-lang/rust/issues/61416), but that appears to have been fixed.
I don't believe this is related to gimli because gimli isn't used in libstd. That being said that still sounds like a regression that's likely related to this crate! (just separate)
Thanks, I've filed a separate issue at https://github.com/rust-lang/rust/issues/67599.
Assuming this is still a problem, would calling backtrace::clear_symbol_cache()
after every dlopen()
be an effective workaround?
At least on 0.36:
- this is still a problem
- calling
clear_symbol_cache()
doesn't clearcache.libraries
, onlycache.mappings
. So if you load a new library, you won't get any new symbols.
I'll put up a PR for adding the ability to reload the library cache shortly.
@alexcrichton do you have a preference for rolling it into the existing clear_symbol_cache
function? or a new function (e.g. reload_native_library_cache
)
Given that cache.mappings
has indexes into cache.libraries
, I think I'll make a new function that clears both cache.libraries
AND cache.mappings
.
We'll likely need to add a fallback in gimli where if a symbol doesn't hit the cache of libraries we know about we check again to see if any new libraries have been opened.
I think this is a better solution that requiring users to call a function to clear the cache.