Skip to content

Commit 2377925

Browse files
committed
Always preload libm.so.6 in sidecar direct spawn
The portable (musl-built, glibc-compat) libdatadog_php.so has its libc DT_NEEDED patched out and relies on the host's libc being in the global scope. When the sidecar is direct-spawned, ld-linux execs the DSO itself, so anything it needs beyond libc.so.6 (which ld-linux always brings in) must be passed with --preload. add_glibc_direct_preloads() only did that on glibc < 2.34, assuming 2.34 had merged all four DSOs into libc. It did not merge libm: exp/log/pow (referenced by libdd-ddsketch, libdd-telemetry and datadog-ipc's shm stats) still live in libm.so.6 on every glibc. On glibc >= 2.34 hosts the spawned sidecar therefore died at load with libdatadog_php.so: symbol lookup error: undefined symbol: exp which made every sidecar connection reset, so AppSec never started ("AppSec sidecar backend is unavailable"). This broke the FrankenPHP SSI tests (dunglas/frankenphp:1.4-php8.4 is Debian 12, glibc 2.36): 27 FrankenphpClassicTests + 10 FrankenphpWorkerTests failures in the "helper-rust integration coverage" job. Preload libm.so.6 whenever the host is glibc, and keep libdl/libpthread/ librt for glibc < 2.34. Verified with test8.4-release-zts-ssi (glibc 2.36, FrankenPHP): 27 failures before, 0 after; test8.3-release-ssi (glibc 2.31, the < 2.34 path) still green.
1 parent 3eef763 commit 2377925

2 files changed

Lines changed: 25 additions & 9 deletions

File tree

loader/dd_library_loader.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ static void *libdatadog_php_handle = NULL;
3939

4040
#if !defined(__MUSL__)
4141
// A portable musl-built libdatadog_php.so has unversioned references to these
42-
// APIs. On glibc before 2.34 their providers are separate DSOs, so make them
43-
// global before loading libdatadog_php.so.
42+
// APIs. libm is always a separate DSO (2.34 merged libdl/libpthread/librt into
43+
// libc, but never libm), and before 2.34 so are the others, so make them global
44+
// before loading libdatadog_php.so.
4445
static const char *const libdatadog_php_glibc_dependencies[] = {
4546
"libdl.so.2",
4647
"libm.so.6",

sidecar/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@ fn add_glibc_direct_preloads(config: &mut Config) {
1919
return;
2020
};
2121

22-
if !glibc_version().is_some_and(|version| version < (2, 34)) {
22+
// On musl hosts the dynamic loader is libc itself (math included), so
23+
// there is nothing to preload — and the glibc DSO names don't exist.
24+
let Some(version) = glibc_version() else {
2325
return;
24-
}
26+
};
2527

2628
// Direct spawn asks ld-linux to load the entrypoint DSO itself, before the
27-
// sidecar can run any initialization code. Before 2.34, glibc provided
28-
// these symbols in separate libraries, so load them explicitly.
29-
direct_spawn
30-
.preloads
31-
.extend(["libdl.so.2", "libm.so.6", "libpthread.so.0", "librt.so.1"].map(String::from));
29+
// sidecar can run any initialization code. The portable DSO has no
30+
// DT_NEEDED entry for libc (it's built against musl and the dependency is
31+
// patched out), so it relies on its undefined symbols being satisfied by
32+
// whatever ld-linux has in the global scope.
33+
//
34+
// ld-linux always brings in libc.so.6, but libm was never merged into it
35+
// (not even in 2.34, which only absorbed libdl/libpthread/librt/libutil/
36+
// libanl). Math symbols — exp/log/pow, referenced by libdd-ddsketch,
37+
// libdd-telemetry and datadog-ipc's shm stats — therefore always need
38+
// libm.so.6 to be loaded explicitly.
39+
direct_spawn.preloads.push("libm.so.6".to_string());
40+
41+
// Before 2.34 these were separate DSOs as well.
42+
if version < (2, 34) {
43+
direct_spawn
44+
.preloads
45+
.extend(["libdl.so.2", "libpthread.so.0", "librt.so.1"].map(String::from));
46+
}
3247
}
3348

3449
#[cfg(all(feature = "glibc-compat", target_os = "linux"))]

0 commit comments

Comments
 (0)