summaryrefslogtreecommitdiffstats
path: root/docs/adr/0001-dynamic-glibc-i686.md
blob: df791e0d4a38f122f68fd604b0c370fee363afe7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 0001 — Ship a dynamically linked glibc i686 binary, not a static one

**Status:** accepted

## Context

The target is a Debian 12 i386 machine: glibc 2.36, 2 cores, 4 GB RAM. The
development machine is x86-64 with `gcc-multilib` and the `i686-unknown-linux-gnu`
Rust target installed.

"Single static binary" was the original plan, on the assumption that it removes
all runtime dependencies. Two measurements on the development machine contradict
that:

1. **Static glibc cannot use NSS modules, and crashes trying.** An i686 binary
   built with `+crt-static` segfaults inside `libnss_resolve.so.2` at
   `getaddrinfo()`, because the host's `nsswitch.conf` lists `resolve` before
   `files`. Static glibc is documented as unable to load NSS modules; on any
   systemd-resolved machine, DNS from a static glibc binary is a SIGSEGV. The
   failure mode is invisible at build time and appears on the first network call.
2. **Static musl requires a C-free dependency tree, which we do not have.**
   `ring` (pulled in by `rustls`/`ureq`) compiles C and assembly; cc-rs invokes
   `musl-gcc -m32` and fails because no 32-bit musl sysroot exists here. Making
   musl work means adding an `i686-linux-musl` cross toolchain, or swapping the
   TLS stack for a pre-1.0 pure-Rust provider.

The dynamic i686 build works unchanged: TLS handshake, DNS, JSON parse, exit 0.
Its highest required symbol version is `GLIBC_2.34`, and it runs correctly inside
`docker run --platform linux/386 debian:12` (glibc 2.36).

## Decision

Build `i686-unknown-linux-gnu` **dynamically linked against glibc**, using the
host's 32-bit toolchain. Do not use `+crt-static`. Gate every release on a check
that the maximum required symbol version is `<= GLIBC_2.36`, and verify releases
by running them inside the `linux/386 debian:12` container before copying to the
target machine.

## Consequences

- The binary is ~3 MB stripped and needs the target's glibc to be at least 2.34.
  Debian 12 provides 2.36, so there is headroom, but a future dependency can pull
  in newer symbol versions. The `readelf` ceiling check is mandatory, not
  advisory — without it the failure appears only on the i686 machine.
- Distribution is a binary plus its glibc, not a single file to `scp` anywhere.
  Accepted: the target is a known Debian 12 box, not an unknown fleet.
- `ring`/`rustls` stay available, so the dependency tree is unconstrained.
- If the target later turns out to be older than glibc 2.34, or a second target
  appears with an older libc, this decision reopens and musl becomes the path.