914 Fix stacktrace symbols when dladdr fails#915
Conversation
f504d95 to
bb9d248
Compare
Codecov Report
@@ Coverage Diff @@
## develop #915 +/- ##
========================================
Coverage 82.79% 82.79%
========================================
Files 356 356
Lines 11232 11232
========================================
Hits 9300 9300
Misses 1932 1932 |
|
Before going down this path, why not try out libbacktrace? It's part of gcc, but it's BSD licensed |
I considered that, but it's another dependency (which, by the way, doesn't have cmake). Our current stack traces work correctly except for extracting the symbols for some gcc versions. I remedy that by calling addr2line or atos depending on the platform. I don't see a strong advantage to using an external library compared to the existing simpler solution. |
|
In a process failure setting, especially, calling Given the license, libbacktrace could be vendored into our source tree as a stand-alone piece. There's also boost stacktrace, which again, could be imported into our tree if we didn't want an external dependency. |
Yes, I'm familiar. There's a proposal to put stack traces in the standard that follows the boost implementation: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0881r5.html |
|
Plus, with an external binary, there's no guarantee that its presence in the build environment means it's available in the execution environment. |
Another option would be to put |
|
addr2line is GPL licensed as part of GNU binutils, and depends on libbfd, which is also part of the GPL licensed GNU binutils |
'Everywhere we need it' is relatively modern Linux and macOS? It has ELF and Mach-O support, so we should be good. |
|
For a separate concern with anything using |
|
Here is a project that adds cmake support for libbacktrace with an older version. We should use it's cmake with the latest libbacktrace code: There is also a PR open in the base libbacktrace for adding cmake support, but it is incomplete and it refers to this other fork: ianlancetaylor/libbacktrace#19 edit: actually someone tried to use it with the newer libbacktrace code and was more trouble than it was worth |
|
The boost stacktrace library relies on a lot of boostisms and macros and might be hard to extract. It also doesn't have cmake: |
|
The other thing to note is that most these libraries depend on a low-level system function: |
|
Rust supports backtraces and has recently moved away from libbacktrace due to several portability and maintainability issues outlined here: rust-lang/rust#73441 Their new solution is rolled from the ground up and it written in rust (not super helpful): https://github.com/gimli-rs |
|
@PhilMiller Actually, I might have just found a really good alternative with cmake support: https://github.com/bombela/backward-cpp |
Ian Lance Taylor is the upstream maintainer of libbacktrace. I suspect that if you gave that PR a nudge, possibly with suitable testing report, that it would move ahead. |
I'm now thinking that https://github.com/bombela/backward-cpp might be the best library to embed. It's more modern, handles reading dwarf, has wide support across many platforms, and an MIT license. |
|
Backward depends on either libbfd or libdw from elfutils. The former is GPL, the latter is dual GPL/LGPL. Either way, it's doing the pretty-printing, not the actual DWARF-reading. |
We don't need to include those in the source, right? It makes the call to those libraries to read the symbols (that's what I meant): I'm thinking we embed backward; we will only need those libs for the pretty backtrace.
|
|
Re |
|
How about libunwind: |
Looks like it will similarly be limited in symbol naming by lack of |
b823eac to
675630f
Compare
|
@PhilMiller I have |
675630f to
7b9a0cc
Compare
|
Even with fully static builds? That's great news. |
|
I'm +1 on passing the |
|
@nlslatt Can you look at the cmake here? |
7b9a0cc to
a5f62f3
Compare
a5f62f3 to
957ce09
Compare
PhilMiller
left a comment
There was a problem hiding this comment.
OK, CMake's policy and variable scoping rules are really weird, but they make good sense for the use case.
For anyone else following along:
The include(CheckLinkerFlag) pushes a fresh frame on the 'policy stack', and the end of the file pops that frame. Thus, the cmake_policy command only applies inside that file.
The function command captures the top of the policy stack, and all invocations of the function are evaluated with that policy set in place.
Files input and calls to functions each create their own variable scope. So, the set only applies within the function.
Fixes #914