Skip to content

[Based on #2090] runtime: support Go 1.26 in C libraries#2098

Open
cpunion wants to merge 17 commits into
xgo-dev:mainfrom
cpunion:codex/go126-c-library-runtime-hooks
Open

[Based on #2090] runtime: support Go 1.26 in C libraries#2098
cpunion wants to merge 17 commits into
xgo-dev:mainfrom
cpunion:codex/go126-c-library-runtime-hooks

Conversation

@cpunion

@cpunion cpunion commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Problem

Go 1.26 standard-library code retained by c-shared and c-archive needs runtime hooks LLGo did not provide. This caused unresolved symbols on Darwin. On Linux, the generated shared-library constructor was lowered to legacy .ctors, so it did not initialize the runtime or reflection ABI tables before C first called an exported Go function; the export demo then crashed in fmt.Sprintf.

Fix

  • add the missing Go 1.26 synctest, Darwin sysctl, and Linux syscall/time runtime hooks
  • initialize the GLS context, runtime, and reflection ABI tables before C calls Go
  • emit a Linux c-shared constructor in .init_array; keep platform constructor lowering for c-archive and Darwin
  • exercise fmt.Sprintf, goroutines, funcinfo, platform syscall paths, and explicit DWARF lookup from real C consumers

This PR is based on #2090 (and transitively #2079). The broader 176-package standard-library coverage remains in a separate follow-up.

Validation

  • macOS arm64 / Go 1.26.5: c-shared and c-archive build, C link, execution, funcinfo, and DWARF checks pass
  • Linux amd64 / Go 1.26.5: the same shared/static checks pass
  • internal/build: 73.7% statement coverage
  • cmd/internal/test: 72.8% statement coverage

Closes #2096

@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cpunion cpunion added go1.26 Go 1.26 compatibility and support bugfix Fixes an existing bug or regression labels Jul 16, 2026
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch 2 times, most recently from 75c7b56 to 4b2d5d1 Compare July 19, 2026 13:38
@cpunion cpunion changed the title runtime: add Go 1.26 C library hooks runtime: add missing C-library runtime hooks Jul 19, 2026
@cpunion
cpunion marked this pull request as draft July 19, 2026 15:23
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from bab45a2 to dc28e83 Compare July 19, 2026 17:04
@cpunion cpunion changed the title runtime: add missing C-library runtime hooks runtime: complete stdlib functional coverage across build modes Jul 19, 2026
@cpunion cpunion changed the title runtime: complete stdlib functional coverage across build modes runtime: complete stdlib support and functional coverage across build modes Jul 19, 2026
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from 037745f to de1b304 Compare July 20, 2026 01:05
@cpunion cpunion changed the title runtime: complete stdlib support and functional coverage across build modes runtime: complete stdlib package coverage across build modes Jul 20, 2026
@cpunion
cpunion marked this pull request as ready for review July 20, 2026 01:46
@cpunion
cpunion marked this pull request as draft July 20, 2026 01:49
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from de1b304 to 048bea5 Compare July 20, 2026 03:03
@cpunion cpunion changed the title runtime: complete stdlib package coverage across build modes runtime: add Go 1.26 C library hooks Jul 20, 2026
@cpunion
cpunion marked this pull request as ready for review July 20, 2026 03:25
cpunion added 9 commits July 20, 2026 12:09
Store each immutable Func as one atomic pointer and validate the queried PC from the Func itself. This prevents concurrent cache replacement from combining a PC and function from different writers. Apply the same publication rule to the prebuilt function cache and stress multiple PCs during concurrent first use.
Give each package-backed locality block an owner-local TLS cache so hot accesses are O(1) regardless of the number of touched packages. Keep the block list only for GC reachability and teardown.

Require locality variables to be unexported and reject go:linkname aliases. Add codegen, lifecycle, and 2/4/8-package performance coverage.
Provide the synctest, Darwin CPU, Linux gettimeofday, and all-thread syscall hooks required by Go 1.26 standard-library code in c-shared and c-archive builds. Extend the export demo so C consumers link and execute fmt, goroutine, syscall, funcinfo, and explicit DWARF paths in both library modes.
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from 048bea5 to e4cc229 Compare July 20, 2026 06:00
@cpunion cpunion changed the title runtime: add Go 1.26 C library hooks [Based on #2090] runtime: add Go 1.26 C library hooks Jul 20, 2026
@cpunion cpunion changed the title [Based on #2090] runtime: add Go 1.26 C library hooks [Based on #2090] runtime: support Go 1.26 in C libraries Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes an existing bug or regression go1.26 Go 1.26 compatibility and support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: Go 1.26 C libraries miss runtime hooks on Darwin and Linux

1 participant