Skip to content

Commit 59abc04

Browse files
cataphractclaude
andcommitted
fix(ExecSolib): compile trampoline as PIE; abort on ET_EXEC
The trampoline binary embedded in ddtrace.so was produced as ET_EXEC (non-PIE) by toolchains that don't default to -fPIE (e.g. devtoolset-7 on CentOS 7). elf_load_trampoline accepted only ET_DYN and used mmap(NULL) to pick a random load base — an ET_EXEC binary loaded that way crashes because its absolute virtual addresses no longer match. Two-pronged fix: 1. libdatadog/spawn_worker/build.rs: add -fPIE/-pie on Linux so the trampoline is always ET_DYN, matching the original design intent. 2. solib_bootstrap.c: add a __builtin_trap() guard after the ET_DYN check so a mis-built ET_EXEC trampoline aborts loudly instead of silently misbehaving. Fixes "failed to map trampoline" (exit 121) on bookworm-slim for PHP 8.3-8.5. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent da0f6aa commit 59abc04

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

ext/solib_bootstrap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,11 @@ static int elf_load_trampoline(const void *src, size_t src_len,
709709
const Elf64_Ehdr *ehdr = (const Elf64_Ehdr *)src;
710710

711711
if (elf_check_header(ehdr, 1u << ET_DYN, 32) < 0) return -1;
712+
// The trampoline must be a PIE (ET_DYN) executable. ET_EXEC cannot be
713+
// loaded at a random base address. build.rs enforces -fPIE/-pie; if
714+
// something goes wrong in the build and ET_EXEC slips through, abort
715+
// loudly rather than silently misbehaving.
716+
if (ehdr->e_type != ET_DYN) __builtin_trap();
712717
if (ehdr->e_phoff + (uint64_t)ehdr->e_phnum * sizeof(Elf64_Phdr) > src_len) return -1;
713718

714719
const Elf64_Phdr *phdrs = (const Elf64_Phdr *)((const char *)src + ehdr->e_phoff);

libdatadog

0 commit comments

Comments
 (0)