← board

C: granular --system-libs opt-out for the magic-link model

Context — the agreed model

The C frontend has no link step. Default is the "magic link": a crtl #include <header> auto-pulls its sibling impl lib/crtl/src/<name>.c (e.g. <math.h>math.c → fabs/sqrt/… bind case-insensitively to the Pascal RTL), so a program links libc-free, zero DT_NEEDED. This is what lets sqlite (whose own Makefile would normally link libc/libm after the compile) just build and run with nothing external.

We decided: magic link stays the default. The programmer opts out only when they explicitly want the real system library. Today that opt-out exists but is all-or-nothing: --system-libs (compiler.pas:134) flips the whole crtl namespace to real external .so resolution (DT_NEEDED libc, libm, …).

The gap

All-or-nothing is too coarse for the realistic case "I want the magic crtl for everything except libm (give me the real libm.so)", or vice-versa. A programmer stating "use external libm" should not lose the libc-free magic for string/stdio/etc.

Proposed

Per-library opt-out, e.g. --system-libs=m,pthread (comma list of soname stems) → only those headers resolve to a real .so (emit DT_NEEDED), the rest stay magic-linked. Bare --system-libs keeps current meaning (everything external) for back-compat. Likely also a source-level form (pragma / directive) so the choice travels with the code, mirroring {$MIMIC FPC} etc.

Policy:

Notes / open questions

Resolution

Implemented 2026-06-28.

Tests: