Skip to content

fix(gnu.org/gcc): bottle the libc via --with-sysroot (addresses #8423)#13092

Closed
tannevaled wants to merge 3 commits into
pkgxdev:mainfrom
tannevaled:fix/gcc-sysroot
Closed

fix(gnu.org/gcc): bottle the libc via --with-sysroot (addresses #8423)#13092
tannevaled wants to merge 3 commits into
pkgxdev:mainfrom
tannevaled:fix/gcc-sysroot

Conversation

@tannevaled
Copy link
Copy Markdown
Contributor

Summary

  • Adds gnu.org/glibc + kernel.org/linux-headers as Linux runtime deps
  • Configures gcc with --with-sysroot={{deps.gnu.org/glibc.prefix}}, --with-build-sysroot=..., --with-native-system-header-dir=/include, --with-glibc-version=2.43
  • Result: gcc's spec file embeds the bottled-glibc paths; end-user pkgx gcc test.c finds stdlib.h + crt*.o + libc.so.6 from the pkgx-integrated bottle, no host glibc-devel / libc6-dev needed (Fedora repro in Inconsistencies with dnf/apt install gcc #8423).

Why this approach (vs #13084's first attempt)

  • fix(gnu.org/gcc): wire libc + linux-headers (closes #8423) #13084 added glibc as a dep + a runtime.env exporting CPATH/LIBRARY_PATH. That:
    • clobbered brewkit's composed CPATH during gcc's own build → gmp.h not found at configure
    • and (in a later iteration) caused fixincl.c to link-fail with undefined reference to __isoc23_strtoul (compile saw bottled glibc 2.43 headers, link saw host glibc ~2.35).
  • This PR uses gcc's own --with-sysroot mechanism instead — same libc backs both compile AND link, no env-var override.

Pairs with

Test plan

  • CI builds gcc on linux/x86-64 + linux/aarch64
  • Verify pkgx gcc -print-sysroot returns the bottled glibc path
  • Manual: on a stock Fedora without glibc-devel, pkgx gcc test.c -o test succeeds
  • Darwin builds unchanged (sysroot args are linux-only)

🤖 Generated with Claude Code

tannevaled and others added 3 commits May 29, 2026 18:21
…ev#8423)

Adds gnu.org/glibc + kernel.org/linux-headers as Linux deps and points
gcc's configure at the bottled glibc via:
  --with-sysroot={{deps.gnu.org/glibc.prefix}}
  --with-build-sysroot={{deps.gnu.org/glibc.prefix}}
  --with-native-system-header-dir=/include
  --with-glibc-version=2.43

This embeds the bottled-glibc paths into gcc's spec file at build
time. End-user `pkgx gcc test.c` resolves stdlib.h + crt*.o + libc.so.6
from the pkgx-integrated bottle — no host glibc-devel / libc6-dev
needed (addresses the Fedora repro in pkgxdev#8423).

Avoids the previous attempt's failure mode: when only the headers
were exposed via CPATH but the linker found a different (older) libc,
fixincl.c → libc references became unresolvable (__isoc23_strtoul).
With sysroot the same libc backs both compile and link.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Native gcc fixincl.c was linking transitively against pkgx glibc 2.43,
which exposes C23 symbol redirects (__isoc23_strtoul, …). The CI
runner's underlying libc (Ubuntu 22.04, glibc 2.35) doesn't have them,
hence `undefined reference to __isoc23_strtoul` at link time.

Pinning to <2.38 (the version that first introduced these redirects)
keeps the same sysroot mechanism but matches API surface to what the
runner ships. Cross-builds were already fine because they link
against the sysroot's libc directly.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
With --with-build-sysroot=$pkgx_glibc set, configure-time test
programs were linked against the sysroot's dynamic linker but with
an embedded interp path of `/lib/ld-linux-x86-64.so.2` (sysroot-
stripped) — that path doesn't exist on the build host, so the test
programs couldn't run:

    configure: error: cannot run C++ compiled programs

Drop --with-build-sysroot: the bootstrap compiler now uses the host's
linker (so test programs run cleanly), while the installed gcc still
points at pkgx-glibc via --with-sysroot for end-user invocations.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@tannevaled
Copy link
Copy Markdown
Contributor Author

Closing — both attempts (runtime.env CPATH, sysroot config) fail in distinct ways:

  1. runtime.env CPATH (PR fix(gnu.org/gcc): wire libc + linux-headers (closes #8423) #13084): clobbered brewkit's composed CPATH during gcc's own build → gmp.h not found at configure.
  2. --with-sysroot (this PR): configure-time test programs link against pkgx glibc but the embedded interp/ABI doesn't survive the brewkit-environment runtime, so configure rejects with cannot run C++ compiled programs. --with-build-sysroot made it worse (sysroot-stripped /lib interp path doesn't exist on the host); without it, brewkit's LD_LIBRARY_PATH pulls in pkgx glibc anyway and the libc/crt asymmetry trips configure tests.

The proper fix for #8423 needs a non-build-time mechanism. Two known paths:

  • a thin pkgx gcc wrapper installed alongside the real binary, modeled on the bklibcvenv pattern from brewkit#348, that re-exports CPATH/LIBRARY_PATH for end-user invocations only (no build-time poisoning)
  • a separate bin/sysroot-gcc shim that takes --sysroot={{pkgx.glibc.prefix}} and forwards to gcc, leaving the canonical gcc bottle untouched

Leaving the issue open and revisiting later. The 9 newly-merged green PRs (#13076 #13082 #13083 #13085 #13086 #13087 #13088 #13090 #13091) are independent of this.

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.

Inconsistencies with dnf/apt install gcc

1 participant