Skip to content

rt: define Darwin stdio globals (__std{in,out,err}p) on non-Darwin backends - #1016

Closed
ropoctl wants to merge 1 commit into
fix-migrate-paste-suffix-glibcfrom
fix-darwin-stdio-globals-glibc
Closed

ropoctl wants to merge 1 commit into
fix-migrate-paste-suffix-glibcfrom
fix-darwin-stdio-globals-glibc

Conversation

@ropoctl

@ropoctl ropoctl commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes the pcre2-wo-drift lane failing to link the corpus harness on every
glibc Linux lane (linux-x86_64, linux-aarch64), while it passed on darwin.

Stacked on #997.

Root cause

A .wo corpus harness is migrated once from the host's preprocessed C and
checked in for all platforms. lib/std/re/pcre2test.w was migrated on darwin,
whose <stdio.h> does #define stderr __stderrp (also __stdoutp /
__stdinp), so the checked-in harness references the bare symbols __stdinp /
__stdoutp / __stderrp (91 sites). glibc exports the streams as
stdin / stdout / stderr instead, so on Linux those three symbols had no
producer
— the harness link (against both the stored embedded bundle and the
freshly-rebuilt one) failed with undefined reference to '__stderrp' etc.

Fix

Mirrors the existing __error / __open darwin-compat precedent already in the
tree:

  • rt/linux_x86_64.w, rt/linux_aarch64.w: define pub var __stdinp / __stdoutp / __stderrp and bind them to the glibc streams
    stdin / stdout / stderr in rt_store_args, the guaranteed pre-main
    entry hook. Darwin's libSystem provides these directly, so the darwin backend
    does not define them and is unaffected.
  • src/FnAbi.w: add the three names to codegen_is_runtime_abi_symbol's
    whitelist so a runtime-source pub var definition keeps its bare link
    name in module-object mode (it otherwise mangles to __with_mod_<hash>__<base>
    and never satisfies the harness's bare reference) — exactly as __error /
    __open already do.
  • docs/with-abi.sha256: FnAbi.w is an ABI-defining source, so its hash
    is re-recorded. The pcre2 bundle re-keys and rebuilds once into its new slot;
    the object is byte-identical (the symbol-naming change does not touch pcre2
    codegen). The naming convention is unchanged — a whitelist extension, like the
    prior __error / __open entries — so WITH_ABI_VERSION stays 1.

No platform gate, no skip: the Darwin-spelled globals now resolve on every
target.

Verification

On linux-x86_64 (glibc):

  • with build + with build :fixpoint green (stage2 == stage3).
  • with build :pcre2-wo-drift green: survey: all targets green;
    harness-build-stored.stderr clean of undefined-symbol errors (was
    undefined reference to '__stderrp'/'__stdoutp'/'__stdinp').
  • nm out/lib/rt_linux_x86_64.o shows __stdinp / __stdoutp / __stderrp
    as bare BSS symbols.

…ckends

A .wo corpus harness is migrated once from the host's preprocessed C and
checked in for every platform. pcre2test.w was migrated on darwin, whose
<stdio.h> does `#define stderr __stderrp` (also __stdoutp / __stdinp), so the
checked-in harness references the bare symbols __stdinp / __stdoutp / __stderrp
(91 sites). glibc exports the streams as stdin / stdout / stderr instead, so on
Linux those three symbols were undefined and the pcre2-wo-drift lane failed to
link the harness (against both the stored and the freshly-rebuilt bundle) --
red on every glibc lane, green on darwin only.

Root cause: the Darwin-spelled stdio globals have no producer on a glibc host.

Fix, mirroring the existing __error / __open darwin-compat precedent:

  - rt/linux_x86_64.w and rt/linux_aarch64.w define `pub var __stdinp /
    __stdoutp / __stderrp` and bind them to the glibc streams stdin / stdout /
    stderr in rt_store_args, the guaranteed pre-main entry hook. Darwin's
    libSystem provides these directly, so the darwin backend does not define
    them and is unaffected.

  - src/FnAbi.w adds the three names to codegen_is_runtime_abi_symbol's
    whitelist so a runtime-source `pub var` definition keeps its bare link
    name in module-object mode (otherwise it mangles to
    __with_mod_<hash>__<base> and never satisfies the harness's bare
    reference) -- exactly as __error / __open already do.

FnAbi.w is an ABI-defining source, so docs/with-abi.sha256 is re-recorded; the
pcre2 bundle re-keys and rebuilds once into its new slot (byte-identical
object -- the symbol-naming change does not touch pcre2 codegen). The naming
convention is unchanged (a whitelist extension, like the prior __error / __open
entries), so WITH_ABI_VERSION stays 1.

Verified on linux-x86_64: with build + :fixpoint green; pcre2-wo-drift green
with harness-build-stored.stderr clean of undefined-symbol errors; the rt
platform object exports __std{in,out,err}p as bare BSS symbols.
@ehartford

Copy link
Copy Markdown
Contributor

Landed on main via cherry-pick under a new hash: b0d06da (rt: define Darwin stdio globals __std{in,out,err}p on non-Darwin backends). Closing as merged-by-content; the original SHA differs because it was cherry-picked into the batch, not merged.

@ehartford ehartford closed this Sep 6, 2026
@ehartford
ehartford deleted the fix-darwin-stdio-globals-glibc branch September 24, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants