You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the scope of [incident 34148](https://dd.enterprise.slack.com/archives/C088R4S25M5), we have incomplete unwinding on musl. As a first priority we should be able to build a version for PHP that allows unwinding on musl.
6
+
I recommend [this issue](https://github.com/rust-lang/backtrace-rs/issues/698) for more context on the issue.
7
+
8
+
This is only an issue for the languages that do not have a runtime specific unwinding tool.
9
+
- Ruby
10
+
- .NET
11
+
- Python
12
+
13
+
Other languages have their unwinding mechanisms.
14
+
15
+
## Solution proposed
16
+
17
+
Unwinding from the context of the signal handler allows us to get the stacktrace beyond the signal handler. The issue above details some of the experiments I have performed.
18
+
19
+
### Unwinding libraries
20
+
21
+
Using [libunwind](https://github.com/libunwind/libunwind/) is not mandatory. A full rust solution can be considered using framehop (which is built on top of Gimli). We have experience using libunwind and debugging it. libunwind is the unwinder for the .NET profiler.
22
+
When swapping for a different library we should consider maintenance, internal knowledge and the redundancy of what we are shipping.
23
+
24
+
### Packaging of libunwind
25
+
26
+
As this is a C library, we can not use the C header.
27
+
We need to declare the functions we use in libdatadog for the different architectures. This requires some adjustements as the functions have names are architecture specific.
28
+
29
+
We can rely on bindgen to generate the bindings. However as this adds complexity to the builds I favoured declaring the minimal set of functions.
30
+
The libunwind-sys crate did not work correctly though it would be a great starting point.
31
+
32
+
We should statically link libunwind and make symbols invisible to our users.
33
+
The link of libunwind requires `libgcc_s.so.1`. This does not change anythinng as we already needed this dependency (as we are using backtrace mechanisms).
34
+
35
+
Size impacts looking at libdatadog_profiling.so
36
+
- 9 Megs
37
+
- +1.3 Meg
38
+
TODO: check when compiling with PHP if this is acceptable.
39
+
40
+
### Deployment
41
+
42
+
We propose to deploy the feature OFF by default. We can then check with the customer to enable this and get the musl crash locations.
43
+
If this is a success, we can roll out progressively the change.
44
+
45
+
### Out of scope
46
+
47
+
Signal safety is not discussed.
48
+
The current implementation is not signal safe. We have more work to improve this.
49
+
50
+
Shipping libunwund so that .NET folks can reuse it.
51
+
This should come in a second phase.
52
+
53
+
Fixing backtrace-rs
54
+
The ideal solution would be to solve the upstream issue. Unwinding from signals in musl is crucial.
55
+
I currently do not see an obvious way to do this with the [gcc_s functions](https://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/libgcc-sman.html).
0 commit comments