Skip to content

runtime: support Go 1.26 stdlib calls from C libraries - #2098

Merged
xushiwei merged 2 commits into
xgo-dev:mainfrom
cpunion:codex/go126-c-library-runtime-hooks
Jul 26, 2026
Merged

runtime: support Go 1.26 stdlib calls from C libraries#2098
xushiwei merged 2 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

With Go 1.26, c-shared and c-archive exports that retain standard-library code need runtime hooks LLGo did not provide: Darwin CPU initialization needs the new sysctlbyname bridges, while Linux syscall needs gettimeofday, all-thread syscall, and cgo-caller symbols.

Linux c-shared also registered its constructor through llvm.global_ctors. The raw LLVM target machine lowers that to legacy .ctors, so LLD may not run the runtime and reflection-ABI initialization before C first calls an exported Go function.

Fix

  • add the Darwin internal/cpu sysctl bridges through LLGo's dynamic-import trampoline;
  • add the Linux/amd64 gettimeofday bridge and return ENOTSUP for thread-wide operations LLGo cannot safely implement;
  • register only the Linux c-shared constructor in .init_array, retaining the existing platform lowering for c-archive and Darwin;
  • call fmt.Sprintf, syscall.Gettimeofday, and syscall.AllThreadsSyscall from real static and dynamic C consumers.

The independent diff against current main is +151/-7 across 11 files.

Validation

  • macOS arm64 / Go 1.26.5: c-shared and c-archive build, link, execute, and resolve Go DWARF source locations.
  • Linux amd64 / Go 1.26.5 / LLVM 19.1.7: the same static and dynamic C consumers build, link, execute, and resolve DWARF; the Linux syscall checks run successfully.
  • internal/build coverage is 73.6%; defineLibraryRuntimeInit is 100% covered on both platforms.
  • No existing test is skipped or ignored.

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
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
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch 3 times, most recently from b91e889 to eed7973 Compare July 24, 2026 03:29
@cpunion cpunion changed the title [Based on #2090] runtime: support Go 1.26 in C libraries runtime: support Go 1.26 in C libraries Jul 26, 2026
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from eed7973 to 68ce035 Compare July 26, 2026 01:17
cpunion added 2 commits July 26, 2026 09:59
Provide the Darwin CPU, Linux gettimeofday, and all-thread syscall hooks required by Go 1.26 standard-library code in c-shared and c-archive builds. Exercise them from actual C consumers through fmt.Sprintf, syscall.Gettimeofday, and syscall.AllThreadsSyscall.
@cpunion
cpunion force-pushed the codex/go126-c-library-runtime-hooks branch from 68ce035 to 6ffdfff Compare July 26, 2026 02:20
@cpunion cpunion changed the title runtime: support Go 1.26 in C libraries runtime: support Go 1.26 stdlib calls from C libraries Jul 26, 2026
@xushiwei
xushiwei merged commit 824bc87 into xgo-dev:main Jul 26, 2026
42 checks passed
xushiwei added a commit that referenced this pull request Jul 26, 2026
[Based on #2098] runtime,test: complete Go 1.26 standard-library coverage
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

2 participants