Skip to content

Commit 959c0cd

Browse files
authored
feat(profiling): Wrap libunwind in a crate (#1510)
# What does this PR do? Wrap libunwind in `libdd-libunwind-sys` Rust crate. # Motivation Crashtracker collects callstacks. When it comes to alpine/musl-libc (mainly on x86_64), we fail at retrieving the callstack passed the signal frame. The problem is that the musl-libc binary does not have the CFIs (unwinding information) and the unwinder does not know how to move forward and stop. Libunwind provides a way to unwind starting from the ucontext: context (registers and state) of the crashing thread. Going that way, we can collect the callstack as much as possible (until hitting musl-libc) # Additional Notes Gitlab jobs have been modified in this [PR ](DataDog/libddprof-build#149 it's working https://gitlab.ddbuild.io/DataDog/apm-reliability/libddprof-build/-/pipelines/100326074. Co-authored-by: gregory.leocadie <gregory.leocadie@datadoghq.com>
1 parent eed7965 commit 959c0cd

17 files changed

Lines changed: 505 additions & 9 deletions

.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
.gitlab-ci.yml @DataDog/apm-common-components-core
1515
.gitlab/benchmarks.yml @DataDog/apm-common-components-core
1616
.gitlab/fuzz.yml @DataDog/chaos-platform
17+
.gitmodules @DataDog/libdatadog
1718
benchmark/ @DataDog/apm-common-components-core
1819
bin_tests/ @DataDog/libdatadog-profiling
1920
build-common/ @DataDog/apm-common-components-core
@@ -44,6 +45,7 @@ libdd-data-pipeline*/ @DataDog/libdatadog-apm
4445
libdd-ddsketch*/ @DataDog/libdatadog-apm @DataDog/apm-common-components-core
4546
libdd-dogstatsd-client @DataDog/apm-common-components-core
4647
libdd-library-config*/ @DataDog/apm-sdk-capabilities
48+
libdd-libunwind*/ @DataDog/libdatadog-profiling
4749
libdd-log*/ @DataDog/apm-common-components-core
4850
libdd-profiling*/ @DataDog/libdatadog-profiling
4951
libdd-telemetry*/ @DataDog/apm-common-components-core

.github/workflows/coverage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ jobs:
2626
docker-images: true
2727
swap-storage: true
2828
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
29+
with:
30+
submodules: recursive
2931
- name: Install Rust
3032
run: rustup install nightly-2026-02-08 && rustup default nightly-2026-02-08
3133
- name: Install cargo-llvm-cov

.github/workflows/lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
steps:
1111
- name: Checkout sources
1212
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
13+
with:
14+
submodules: recursive
1315
- name: Run actionlint
1416
uses: devops-actions/actionlint@c6744a34774e4e1c1df0ff66bdb07ec7ee480ca0 # 0.1.9
1517
with:
@@ -22,6 +24,8 @@ jobs:
2224
steps:
2325
- name: Checkout sources
2426
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
27+
with:
28+
submodules: recursive
2529
- name: Install nightly-2026-02-08 toolchain and rustfmt
2630
run: rustup install nightly-2026-02-08 && rustup default nightly-2026-02-08 && rustup component add rustfmt
2731
- name: Cache [rust]
@@ -41,6 +45,8 @@ jobs:
4145
steps:
4246
- name: Checkout sources
4347
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
48+
with:
49+
submodules: recursive
4450
- name: Install ${{ matrix.rust_version }} toolchain and clippy
4551
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }} && rustup component add clippy
4652
- name: Cache [rust]

.github/workflows/miri.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
PROPTEST_CASES: 1
1515
steps:
1616
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
17+
with:
18+
submodules: recursive
1719
- name: Set up Rust
1820
run: |
1921
set -e

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ jobs:
3636
swap-storage: true
3737
- name: Checkout sources
3838
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
39+
with:
40+
submodules: recursive
3941
- name: Install Rust ${{ matrix.rust_version }}
4042
if: matrix.rust_version != ''
4143
run: rustup install ${{ matrix.rust_version }} && rustup default ${{ matrix.rust_version }}
@@ -155,6 +157,8 @@ jobs:
155157
steps:
156158
- name: Checkout sources
157159
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
160+
with:
161+
submodules: recursive
158162
- name: Setup output dir
159163
shell: bash
160164
run: |
@@ -297,6 +301,8 @@ jobs:
297301
swap-storage: true
298302
- name: Checkout
299303
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
304+
with:
305+
submodules: recursive
300306
- name: Cache [rust]
301307
uses: Swatinem/rust-cache@f13886b937689c021905a6b90929199931d60db1 # 2.8.1
302308
with:
@@ -321,6 +327,8 @@ jobs:
321327
steps:
322328
- name: Checkout
323329
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
330+
with:
331+
submodules: recursive
324332
- name: Set up Docker Buildx
325333
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # 3.10.0
326334
with:

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "libdd-libunwind-sys/libunwind"]
2+
path = libdd-libunwind-sys/libunwind
3+
url = https://github.com/DataDog/libunwind.git
4+
branch = kevin/v1.8.1-custom-2

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ members = [
4646
"libdd-tinybytes",
4747
"libdd-dogstatsd-client",
4848
"libdd-log",
49-
"libdd-log-ffi",
49+
"libdd-log-ffi", "libdd-libunwind-sys",
5050
]
5151

5252
# https://doc.rust-lang.org/cargo/reference/resolver.html

LICENSE-3rdparty.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
root_name: builder, build_common, tools, libdd-alloc, libdd-crashtracker, libdd-common, libdd-telemetry, libdd-ddsketch, libdd-crashtracker-ffi, libdd-common-ffi, datadog-ffe, datadog-ffe-ffi, datadog-ipc, datadog-ipc-macros, libdd-tinybytes, tarpc, tarpc-plugins, spawn_worker, cc_utils, libdd-library-config, libdd-library-config-ffi, datadog-live-debugger, libdd-data-pipeline, libdd-dogstatsd-client, libdd-trace-protobuf, libdd-trace-stats, libdd-trace-utils, libdd-trace-normalization, libdd-log, datadog-live-debugger-ffi, libdd-profiling, libdd-profiling-protobuf, libdd-profiling-ffi, libdd-data-pipeline-ffi, libdd-ddsketch-ffi, libdd-log-ffi, libdd-telemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, datadog-remote-config, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, libdd-trace-obfuscation, datadog-tracer-flare, sidecar_mockgen, test_spawn_from_lib
1+
root_name: builder, build_common, tools, libdd-alloc, libdd-crashtracker, libdd-common, libdd-telemetry, libdd-ddsketch, libdd-crashtracker-ffi, libdd-common-ffi, datadog-ffe, datadog-ffe-ffi, datadog-ipc, datadog-ipc-macros, libdd-tinybytes, tarpc, tarpc-plugins, spawn_worker, cc_utils, libdd-library-config, libdd-library-config-ffi, datadog-live-debugger, libdd-data-pipeline, libdd-dogstatsd-client, libdd-trace-protobuf, libdd-trace-stats, libdd-trace-utils, libdd-trace-normalization, libdd-log, datadog-live-debugger-ffi, libdd-profiling, libdd-profiling-protobuf, libdd-profiling-ffi, libdd-data-pipeline-ffi, libdd-ddsketch-ffi, libdd-log-ffi, libdd-telemetry-ffi, symbolizer-ffi, datadog-profiling-replayer, datadog-remote-config, datadog-sidecar, datadog-sidecar-macros, datadog-sidecar-ffi, libdd-trace-obfuscation, datadog-tracer-flare, sidecar_mockgen, test_spawn_from_lib, bin_tests
22
third_party_libraries:
33
- package_name: addr2line
44
package_version: 0.24.2

libdd-libunwind-sys/Cargo.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[package]
2+
name = "libdd-libunwind"
3+
edition.workspace = true
4+
version.workspace = true
5+
rust-version.workspace = true
6+
license.workspace = true
7+
publish = false
8+
links = "unwind" # Tells Cargo this crate links to libunwind (prevents multiple builds)
9+
10+
[lib]
11+
crate-type = ["lib"]
12+
bench = false
13+
14+
[dependencies]
15+
paste = "1.0"
16+
libc = "0.2"
17+
18+
[build-dependencies]
19+
cc = "1.0"

0 commit comments

Comments
 (0)