Commit 1132b82
fix(server): make the glibc single-threaded shim writable (#15)
codegraph-server segfaulted at startup on Linux/aarch64 - every
invocation, including --version and --help, before main() ever ran.
The shim defined __libc_single_threaded as an immutable static, which
lands in .rodata, and its comment claimed "on newer glibc the real symbol
shadows this at runtime". That is the opposite of how ELF resolves it: a
definition in the executable takes precedence over the one in libc. On
aarch64 the symbol is also emitted into .dynsym, so glibc bound its own
startup write of the flag to our read-only byte and took SIGSEGV. x86_64
escaped it only because the symbol is not dynamically exported there, so
glibc kept using its own copy - which is why this looked environment-
specific and why the shipped x86_64 binaries were fine.
glibc owns the value: it sets the flag at startup and clears it on thread
creation. We only supply storage, wrapped in an UnsafeCell so it lands in
writable memory, and never read it. On a glibc too old to maintain it the
byte stays 0, the conservative "not single threaded" answer, so the
SLES 15 SP4 / glibc 2.31 case the shim exists for still links and runs.
Verified on aarch64 Ubuntu 24.04 (glibc 2.39), built from these sources:
before, --version and --help both exited 139 and the symbol was `R`;
after, the symbol is `B` and --version, --help and --info all exit 0.
codegraph-pro-server carries the same shim and needs the same change.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rVbt7rENTwXkdHt3Bpgb51 parent 77edac8 commit 1132b82
1 file changed
Lines changed: 31 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
19 | 34 | | |
20 | | - | |
21 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
22 | 49 | | |
23 | 50 | | |
24 | 51 | | |
| |||
0 commit comments