Skip to content

stdlib-opt: trim runtime/internal/lib patches#1621

Merged
xushiwei merged 71 commits intogoplus:mainfrom
cpunion:stdlib-opt-trim-internal-lib
Feb 10, 2026
Merged

stdlib-opt: trim runtime/internal/lib patches#1621
xushiwei merged 71 commits intogoplus:mainfrom
cpunion:stdlib-opt-trim-internal-lib

Conversation

@cpunion
Copy link
Collaborator

@cpunion cpunion commented Feb 7, 2026

Links

Summary

  • Trim runtime/internal/lib down to a small, explicit set of alt packages needed by llgo ABI/runtime and syscall path.
  • Wire syscall intrinsics + runtime hooks so stdlib syscall wrappers can be reused (Darwin + Linux focus).
  • Keep overlays (notably runtime/_overlay/math) so stdlib can build without relying on upstream asm.

Key changes

  • Runtime hooks/syscall path shims to match stdlib expectations.
  • Darwin: link syscall.syscall* to llgo intrinsics and normalize errno handling.
  • Linux: provide internal/runtime/syscall alt with Syscall6 backed by libc syscall.
  • Math overlay: overlay archExp/archExp2 via libc and disable asm-only paths where needed.

Alt packages (source of truth: runtime/build.go hasAltPkg)

  • crypto/internal/boring/sig
  • hash/crc32
  • internal/abi
  • internal/bytealg
  • internal/cpu
  • internal/reflectlite
  • internal/runtime/atomic
  • internal/runtime/maps
  • internal/runtime/syscall
  • internal/weak
  • reflect
  • runtime
  • runtime/internal/syscall
  • sync
  • sync/atomic
  • syscall/js
  • unique
  • weak

Notes

  • Everything else under runtime/internal/lib is not treated as an alt package on this branch (e.g. internal/itoa, internal/syscall, most syscall/*, most crypto/*, etc.).

Testing

  • Demo runs (macOS/arm64):
    • OK: _demo/go/{goimporter-1389,gotypes,maphash,netip,randcrypt,oswritestring,reflectmake,sysexec,texttemplate}
    • Expected external deps: _demo/py/tensor, _demo/c/cargs

@gemini-code-assist
Copy link

Summary of Changes

Hello @cpunion, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request represents a major architectural shift aimed at improving LLGo's compatibility and maintainability by enabling more direct reuse of the upstream Go standard library. By introducing compiler intrinsics and carefully crafted runtime hooks, LLGo can now leverage existing Go standard library code for critical functionalities like syscalls and math operations, significantly reducing the need for custom, LLGo-specific implementations. This change simplifies the codebase, aligns LLGo more closely with upstream Go, and enhances the robustness of its runtime environment.

Highlights

  • Standard Library Reuse: The runtime/internal/lib directory has been significantly trimmed, focusing on a minimal, explicit set of alternative packages required for llgo's ABI, runtime, and syscall path. This reduces the need for custom LLGo implementations of standard library components.
  • Syscall Intrinsics and Runtime Hooks: New llgo intrinsics (llgo.funcPCABI0, llgo.syscall variants, llgo.skip) have been introduced to directly handle platform-specific syscall behaviors and function pointers within the compiler. This allows for direct reuse of Go standard library syscall wrappers without relying on Go assembly.
  • Math Overlays for C Library Integration: Overlays for math functions (e.g., exp, exp2) have been added to link directly to C library equivalents, ensuring standard library builds without dependency on upstream assembly implementations.
  • Enhanced Development and CI Environment: New Dockerfiles and helper scripts (dev/compose.sh, dev/llgo-auto.sh) have been added to support building and testing LLGo across multiple Go versions (1.21.13, 1.22.12, 1.23.6, 1.25.2) and architectures, streamlining the development and continuous integration process.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • _demo/go/syscall/main.go
    • Added a new demo program to test syscall functionality, including Getpid, Getwd, Open, Read, and Close, with error handling for syscall.Errno.
  • cl/_testdata/llgointrinsics/in.go
    • Introduced a new test file defining //go:linkname functions for llgo.funcPCABI0 and llgo.skip to test the new intrinsics with various function types and return behaviors.
  • cl/_testdata/llgointrinsics/out.ll
    • Added LLVM IR output demonstrating how llgo.funcPCABI0 resolves to C function pointers and how llgo.skip calls are optimized away.
  • cl/_testdata/llgosyscall/in.go
    • Added a new test file defining //go:linkname functions for various llgo.syscall variants (syscall, syscall6, syscall6X, syscallPtr, rawSyscall, rawSyscall6) to verify their behavior.
  • cl/_testdata/llgosyscall/out.ll
    • Added LLVM IR output showing how llgo.syscall variants are lowered to direct calls with cliteErrno for error handling.
  • cl/_testgo/embedunexport-1598/expect.txt
    • Added a test expectation file for an embed unexport test case.
  • cl/_testlibgo/complex/out.ll
    • Updated LLVM IR to reflect changes in complex math function linking, specifically changing cabs to math/cmplx.Abs.
  • cl/_testlibgo/math/out.ll
    • Updated LLVM IR to reflect changes in math function linking, specifically changing sqrt to math.Sqrt.
  • cl/compile.go
    • Modified compileInstrOrValue to recognize and handle the new llgoFuncPCABI0 intrinsic.
    • Added logic to processPkg to skip compiling functions ending with _trampoline, preventing generation of Go assembly for these C-linked functions.
  • cl/import.go
    • Added new llgoInstrBase constants for llgoGetClosurePtr, llgoSetClosurePtr, llgoFuncPCABI0, llgoSkip, and llgoSyscall intrinsics.
    • Introduced extractTrampolineCName to parse C function names from _trampoline suffixes, supporting the funcPCABI0 intrinsic.
    • Updated varName to include special handling for go: linknames within the runtime package.
  • cl/instr.go
    • Implemented the funcPCABI0 intrinsic, handling various function types and extracting C function addresses.
    • Added zeroResult helper for llgo.skip return values and syscallFnSig/syscallFnSigFixed for defining syscall function signatures.
    • Implemented syscallErrno for errno retrieval and syscallIntrinsic for handling syscall calls with error normalization.
    • Introduced Darwin-specific trampoline name remapping (darwinTrampolineCNameMap, remapTrampolineCName).
    • Integrated llgoFuncPCABI0, llgoSkip, and llgoSyscall into the compiler's call dispatch mechanism.
  • dev/Dockerfile.go1.21.13
    • Added Dockerfile for Go 1.21.13, including LLVM/Clang toolchain, Go toolchain installation, Python dependencies, and cargs asset download.
  • dev/Dockerfile.go1.22.12
    • Added Dockerfile for Go 1.22.12, similar to 1.21.13 but with specific versioning.
  • dev/Dockerfile.go1.23.6
    • Added Dockerfile for Go 1.23.6, similar to previous versions but with specific versioning.
  • dev/Dockerfile.go1.25.2
    • Added Dockerfile for Go 1.25.2, similar to previous versions but with specific versioning.
  • dev/_llgo_setup.sh
    • Added _llgo_find_go function to reliably locate the go executable.
    • Updated _llgo_compute_bin_path and _llgo_ensure_llgo_cli to use the dynamically found go executable.
  • dev/compose.sh
    • Added a new script to manage Docker Compose services for different architectures and Go versions, simplifying development environment setup.
  • dev/docker-compose.yml
    • Added proxy environment variables to the common environment configuration.
    • Expanded Docker Compose services to include configurations for various Go versions (1.21.13, 1.22.12, 1.23.6, 1.25.2) across different architectures, each with dedicated volumes.
  • dev/docker.sh
    • Modified to support selecting specific Go versions via a --go argument when running Docker commands.
  • dev/llgo-auto.sh
    • Added a new script for automatic selection between local and Docker execution based on target OS/architecture and Go version, streamlining llgo command execution.
  • dev/local_ci.sh
    • Introduced repo_gotoolchain variable to explicitly set the GOTOOLCHAIN environment variable for Go commands during local CI runs.
  • doc/syscall-intrinsics-proposal.md
    • Added a comprehensive proposal document detailing the design and implementation plan for LLGo syscall intrinsics and standard library reuse.
  • runtime/_overlay/crypto/md5/md5block_386.s
    • Added empty stub to disable Go assembly for MD5 on 386 architecture.
  • runtime/_overlay/crypto/md5/md5block_amd64.s
    • Added empty stub to disable Go assembly for MD5 on AMD64 architecture.
  • runtime/_overlay/crypto/md5/md5block_arm.s
    • Added empty stub to disable Go assembly for MD5 on ARM architecture.
  • runtime/_overlay/crypto/md5/md5block_arm64.s
    • Added empty stub to disable Go assembly for MD5 on ARM64 architecture.
  • runtime/_overlay/crypto/md5/md5block_decl.go
    • Added declaration for block function, setting haveAsm to false to force pure Go implementation.
  • runtime/_overlay/crypto/md5/md5block_generic.go
    • Added generic implementation for block function, setting haveAsm to false.
  • runtime/_overlay/crypto/md5/md5block_ppc64x.s
    • Added empty stub to disable Go assembly for MD5 on PPC64x architecture.
  • runtime/_overlay/crypto/md5/md5block_s390x.s
    • Added empty stub to disable Go assembly for MD5 on S390x architecture.
  • runtime/_overlay/internal/sync/runtime.go
    • Converted runtime_canSpin, runtime_doSpin, throw, fatal, runtime_nanotime, runtime_SemacquireMutex, runtime_Semrelease to //go:linkname declarations, linking them to actual runtime implementations.
  • runtime/_overlay/math/exp2_asm.go
    • Added overlay for math.Exp2 on ARM64, linking to C.exp2.
  • runtime/_overlay/math/exp_asm.go
    • Added overlay for math.Exp on AMD64 and ARM64, linking to C.exp.
  • runtime/_overlay/math/hypot_asm.go
    • Added overlay for math.Hypot on AMD64 and 386, marked as 'not implemented'.
  • runtime/_overlay/math/log_asm.go
    • Added overlay for math.Log on AMD64, marked as 'not implemented'.
  • runtime/_overlay/math/modf_asm.go
    • Added overlay for math.Modf on ARM64, PPC64, and PPC64LE, marked as 'not implemented'.
  • runtime/build.go
    • Significantly trimmed the hasAltPkg map, removing many custom LLGo implementations and retaining only a core set of alternative packages.
  • runtime/host_goos_darwin.go
    • Added file to define hostGOOS as 'darwin' for Darwin builds.
  • runtime/host_goos_other.go
    • Added file to define hostGOOS as 'linux' for non-Darwin builds.
  • runtime/internal/clite/libuv/_wrap/libuv.c
    • Added C wrapper functions for libuv async and timer initialization, and signal handling, with specific callbacks for runtime and time events.
  • runtime/internal/clite/libuv/async.go
    • Adjusted Async struct size to uvAsyncSize.
  • runtime/internal/clite/libuv/net.go
    • Adjusted Handle struct size to uvHandleSize.
  • runtime/internal/clite/libuv/signal.go
    • Adjusted Signal struct size to uvSignalSize.
    • Converted (*Signal).Start, (*Signal).StartOneshot, (*Signal).Stop to use //go:linkname to C functions.
  • runtime/internal/clite/libuv/sizes_default.go
    • Added constants defining default sizes for libuv handle types.
  • runtime/internal/clite/libuv/timer.go
    • Adjusted Timer struct size to uvTimerSize.
    • Converted (*Timer).Start, (*Timer).Stop, (*Timer).Again, (*Timer).SetRepeat, (*Timer).GetRepeat, (*Timer).GetDueIn to use //go:linkname to C functions.
  • runtime/internal/clite/libuv/wrap_llgo.go
    • Added //go:linkname declarations for new C wrapper functions for libuv async, timer, and signal operations.
  • runtime/internal/clite/os/_os/os.c
    • Added C wrapper functions (llgo_open, llgo_openat, llgo_fcntl, llgo_ioctl) for standard Unix system calls.
  • runtime/internal/clite/pthread/sync/sync.go
    • Added alignment helper structs (align4, align8, alignPtr) and applied them to pthread synchronization primitives (Once, MutexAttr, Mutex, RWLockAttr, RWLock, CondAttr, Cond) to ensure correct memory alignment.
  • runtime/internal/clite/pthread/sync/sync_align_darwin.go
    • Added Darwin-specific alignment type aliases for pthread synchronization primitives.
  • runtime/internal/clite/pthread/sync/sync_align_linux.go
    • Added Linux-specific alignment type aliases for pthread synchronization primitives.
  • runtime/internal/clite/pthread/sync/sync_align_other.go
    • Added generic alignment type aliases for pthread synchronization primitives for non-Linux/Darwin systems.
  • runtime/internal/lib/crypto/hmac/hmac.go
    • Removed custom HMAC implementation.
  • runtime/internal/lib/crypto/internal/boring/sig/sig.go
    • Renamed from runtime/internal/lib/crypto/subtle/xor.go.
    • Repurposed to define no-op functions (BoringCrypto, FIPSOnly, StandardCrypto) as code signatures for compiler signaling.
  • runtime/internal/lib/crypto/internal/fips140/indicator.go
    • Removed FIPS 140 indicator implementation.
  • runtime/internal/lib/crypto/md5/md5.go
    • Removed custom MD5 implementation.
  • runtime/internal/lib/crypto/rand/rand.go
    • Removed custom crypto/rand implementation.
  • runtime/internal/lib/crypto/rand/util.go
    • Removed crypto/rand utility functions.
  • runtime/internal/lib/crypto/sha1/sha1.go
    • Removed custom SHA1 implementation.
  • runtime/internal/lib/crypto/sha256/sha224.go
    • Removed custom SHA224 implementation.
  • runtime/internal/lib/crypto/sha256/sha256.go
    • Removed custom SHA256 implementation.
  • runtime/internal/lib/crypto/sha512/sha384.go
    • Removed custom SHA384 implementation.
  • runtime/internal/lib/crypto/sha512/sha512.go
    • Removed custom SHA512 implementation.
  • runtime/internal/lib/go/build/build.go
    • Removed go/build overlay.
  • runtime/internal/lib/go/parser/parser.go
    • Removed go/parser overlay.
  • runtime/internal/lib/hash/maphash/maphash.go
    • Removed hash/maphash overlay.
  • runtime/internal/lib/internal/abi/abi.go
    • Changed FuncPCABI0 to be a //go:linkname to the new llgo.funcPCABI0 intrinsic.
    • Updated FuncPCABIInternal to call FuncPCABI0.
  • runtime/internal/lib/internal/chacha8rand/chcha8.go
    • Removed internal/chacha8rand implementation.
  • runtime/internal/lib/internal/goarch/gengoarch.go
    • Removed internal/goarch generation script.
  • runtime/internal/lib/internal/goarch/goarch.go
    • Removed internal/goarch core file.
  • runtime/internal/lib/internal/goarch/goarch_386.go
    • Removed internal/goarch 386-specific file.
  • runtime/internal/lib/internal/goarch/goarch_amd64.go
    • Removed internal/goarch AMD64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_arm.go
    • Removed internal/goarch ARM-specific file.
  • runtime/internal/lib/internal/goarch/goarch_arm64.go
    • Removed internal/goarch ARM64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_arm64be.go
    • Removed internal/goarch ARM64BE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_armbe.go
    • Removed internal/goarch ARMBE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_loong64.go
    • Removed internal/goarch Loong64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mips.go
    • Removed internal/goarch MIPS-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mips64.go
    • Removed internal/goarch MIPS64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mips64le.go
    • Removed internal/goarch MIPS64LE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mips64p32.go
    • Removed internal/goarch MIPS64P32-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mips64p32le.go
    • Removed internal/goarch MIPS64P32LE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_mipsle.go
    • Removed internal/goarch MIPSLE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_ppc.go
    • Removed internal/goarch PPC-specific file.
  • runtime/internal/lib/internal/goarch/goarch_ppc64.go
    • Removed internal/goarch PPC64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_ppc64le.go
    • Removed internal/goarch PPC64LE-specific file.
  • runtime/internal/lib/internal/goarch/goarch_riscv.go
    • Removed internal/goarch RISCV-specific file.
  • runtime/internal/lib/internal/goarch/goarch_riscv64.go
    • Removed internal/goarch RISCV64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_s390.go
    • Removed internal/goarch S390-specific file.
  • runtime/internal/lib/internal/goarch/goarch_s390x.go
    • Removed internal/goarch S390x-specific file.
  • runtime/internal/lib/internal/goarch/goarch_sparc.go
    • Removed internal/goarch SPARC-specific file.
  • runtime/internal/lib/internal/goarch/goarch_sparc64.go
    • Removed internal/goarch SPARC64-specific file.
  • runtime/internal/lib/internal/goarch/goarch_wasm.go
    • Removed internal/goarch WASM-specific file.
  • runtime/internal/lib/internal/goarch/zgoarch_386.go
    • Removed generated internal/goarch 386 file.
  • runtime/internal/lib/internal/goarch/zgoarch_amd64.go
    • Removed generated internal/goarch AMD64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_arm.go
    • Removed generated internal/goarch ARM file.
  • runtime/internal/lib/internal/goarch/zgoarch_arm64.go
    • Removed generated internal/goarch ARM64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_arm64be.go
    • Removed generated internal/goarch ARM64BE file.
  • runtime/internal/lib/internal/goarch/zgoarch_armbe.go
    • Removed generated internal/goarch ARMBE file.
  • runtime/internal/lib/internal/goarch/zgoarch_loong64.go
    • Removed generated internal/goarch Loong64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_mips.go
    • Removed generated internal/goarch MIPS file.
  • runtime/internal/lib/internal/goarch/zgoarch_mips64.go
    • Removed generated internal/goarch MIPS64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_mips64le.go
    • Removed generated internal/goarch MIPS64LE file.
  • runtime/internal/lib/internal/goarch/zgoarch_mips64p32.go
    • Removed generated internal/goarch MIPS64P32 file.
  • runtime/internal/lib/internal/goarch/zgoarch_mips64p32le.go
    • Removed generated internal/goarch MIPS64P32LE file.
  • runtime/internal/lib/internal/goarch/zgoarch_mipsle.go
    • Removed generated internal/goarch MIPSLE file.
  • runtime/internal/lib/internal/goarch/zgoarch_ppc.go
    • Removed generated internal/goarch PPC file.
  • runtime/internal/lib/internal/goarch/zgoarch_ppc64.go
    • Removed generated internal/goarch PPC64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_ppc64le.go
    • Removed generated internal/goarch PPC64LE file.
  • runtime/internal/lib/internal/goarch/zgoarch_riscv.go
    • Removed generated internal/goarch RISCV file.
  • runtime/internal/lib/internal/goarch/zgoarch_riscv64.go
    • Removed generated internal/goarch RISCV64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_s390.go
    • Removed generated internal/goarch S390 file.
  • runtime/internal/lib/internal/goarch/zgoarch_s390x.go
    • Removed generated internal/goarch S390x file.
  • runtime/internal/lib/internal/goarch/zgoarch_sparc.go
    • Removed generated internal/goarch SPARC file.
  • runtime/internal/lib/internal/goarch/zgoarch_sparc64.go
    • Removed generated internal/goarch SPARC64 file.
  • runtime/internal/lib/internal/goarch/zgoarch_wasm.go
    • Removed generated internal/goarch WASM file.
  • runtime/internal/lib/internal/godebug/godebug.go
    • Removed internal/godebug stubs.
  • runtime/internal/lib/internal/itoa/itoa.go
    • Added Uitox function for unsigned integer to hexadecimal string conversion.
  • runtime/internal/lib/internal/oserror/errors.go
    • Removed internal/oserror definitions.
  • runtime/internal/lib/internal/poll/poll.go
    • Removed internal/poll stubs.
  • runtime/internal/lib/internal/runtime/atomic/atomic.go
    • Added LoadAcquintptr and StoreReluintptr functions for atomic operations on uintptr.
  • runtime/internal/lib/internal/runtime/maps/maps.go
    • Converted rand, fatal, typedmemmove, typedmemclr, newobject, newarray to use //go:linkname to runtime functions.
    • Added typeString helper function.
  • runtime/internal/lib/internal/runtime/maps/zllgo_stub_darwin.go
    • Added an empty stub file for Darwin-specific internal/runtime/maps.
  • runtime/internal/lib/internal/runtime/sys/sys.go
    • Removed internal/runtime/sys stubs.
  • runtime/internal/lib/internal/runtime/syscall/syscall_linux_llgo.go
    • Added Linux-specific Syscall6 implementation, linking to C.syscall and handling errno.
  • runtime/internal/lib/internal/syscall/execenv/execenv_default.go
    • Removed internal/syscall/execenv default implementation.
  • runtime/internal/lib/internal/syscall/execenv/execenv_windows.go
    • Removed internal/syscall/execenv Windows implementation.
  • runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c
    • Removed internal/syscall/unix C fcntl wrapper.
  • runtime/internal/lib/internal/syscall/unix/at_sysnum_darwin.go
    • Removed internal/syscall/unix Darwin AT_ constants.
  • runtime/internal/lib/internal/syscall/unix/at_sysnum_linux.go
    • Removed internal/syscall/unix Linux AT_ constants.
  • runtime/internal/lib/internal/syscall/unix/constants.go
    • Removed internal/syscall/unix constants.
  • runtime/internal/lib/internal/syscall/unix/fcntl_baremetal.go
    • Removed internal/syscall/unix baremetal fcntl stub.
  • runtime/internal/lib/internal/syscall/unix/fcntl_unix.go
    • Removed internal/syscall/unix Unix fcntl implementation.
  • runtime/internal/lib/internal/syscall/unix/nofollow_bsd.go
    • Removed internal/syscall/unix BSD nofollow errno.
  • runtime/internal/lib/internal/syscall/unix/nofollow_netbsd.go
    • Removed internal/syscall/unix NetBSD nofollow errno.
  • runtime/internal/lib/internal/syscall/unix/nofollow_posix.go
    • Removed internal/syscall/unix POSIX nofollow errno.
  • runtime/internal/lib/internal/syscall/unix/nonblocking_unix.go
    • Removed internal/syscall/unix Unix nonblocking implementation.
  • runtime/internal/lib/internal/syscall/unix/nonblocking_wasm.go
    • Removed internal/syscall/unix WASM nonblocking stub.
  • runtime/internal/lib/internal/syscall/unix/unix.go
    • Modified _unix struct to remove Readlinkat and Unlinkat from llgo:skip list.
  • runtime/internal/lib/internal/syscall/unix/unix_eaccess_linux.go
    • Removed internal/syscall/unix Linux eaccess implementation.
  • runtime/internal/lib/internal/syscall/unix/unix_eaccess_other.go
    • Removed internal/syscall/unix other eaccess implementation.
  • runtime/internal/lib/io/fs/fs.go
    • Removed io/fs ReadFile implementation.
  • runtime/internal/lib/io/pipe.go
    • Removed io/pipe implementation.
  • runtime/internal/lib/iter/iter.go
    • Removed iter package.
  • runtime/internal/lib/math/cmplx/cmplx.go
    • Removed math/cmplx overlay.
  • runtime/internal/lib/math/math.go
    • Removed math overlay.
  • runtime/internal/lib/math/rand/exp.go
    • Removed math/rand exponential distribution implementation.
  • runtime/internal/lib/math/rand/normal.go
    • Removed math/rand normal distribution implementation.
  • runtime/internal/lib/math/rand/rand.go
    • Removed math/rand core implementation.
  • runtime/internal/lib/math/rand/rng.go
    • Removed math/rand RNG source implementation.
  • runtime/internal/lib/math/rand/zipf.go
    • Removed math/rand Zipf distribution implementation.
  • runtime/internal/lib/os/dir.go
    • Removed os directory reading functions.
  • runtime/internal/lib/os/env.go
    • Removed os environment variable functions.
  • runtime/internal/lib/os/error.go
    • Removed os error types and functions.
  • runtime/internal/lib/os/exec.go
    • Removed os process execution functions.
  • runtime/internal/lib/os/exec/exec.go
    • Removed os/exec command execution implementation.
  • runtime/internal/lib/os/exec/exec_plan9.go
    • Removed os/exec Plan 9 specific functions.
  • runtime/internal/lib/os/exec/exec_unix.go
    • Removed os/exec Unix specific functions.
  • runtime/internal/lib/os/exec/exec_windows.go
    • Removed os/exec Windows specific functions.
  • runtime/internal/lib/os/exec/lp_plan9.go
    • Removed os/exec Plan 9 LookPath implementation.
  • runtime/internal/lib/os/exec/lp_unix.go
    • Removed os/exec Unix LookPath implementation.
  • runtime/internal/lib/os/exec/lp_wasm.go
    • Removed os/exec WASM LookPath implementation.
  • runtime/internal/lib/os/exec/lp_windows.go
    • Removed os/exec Windows LookPath implementation.
  • runtime/internal/lib/os/exec/unix_constants.go
    • Removed os/exec Unix constants.
  • runtime/internal/lib/os/exec/unix_eaccess_linux.go
    • Removed os/exec Linux eaccess implementation.
  • runtime/internal/lib/os/exec/unix_eaccess_other.go
    • Removed os/exec other eaccess implementation.
  • runtime/internal/lib/os/exec_plan9.go
    • Removed os Plan 9 process execution functions.
  • runtime/internal/lib/os/exec_posix.go
    • Removed os POSIX process execution functions.
  • runtime/internal/lib/os/exec_unix.go
    • Removed os Unix process execution functions.
  • runtime/internal/lib/os/exec_windows.go
    • Removed os Windows process execution functions.
  • runtime/internal/lib/os/file.go
    • Removed os file operations implementation.
  • runtime/internal/lib/os/file_posix.go
    • Removed os POSIX file operations implementation.
  • runtime/internal/lib/os/file_unix.go
    • Removed os Unix file operations implementation.
  • runtime/internal/lib/os/os.go
    • Removed os package core functions.
  • runtime/internal/lib/os/os_nonwasm.go
    • Removed os non-WASM specific functions.
  • runtime/internal/lib/os/os_wasm.go
    • Removed os WASM specific functions.
  • runtime/internal/lib/os/path.go
    • Removed os path manipulation functions.
  • runtime/internal/lib/os/path_plan9.go
    • Removed os Plan 9 path functions.
  • runtime/internal/lib/os/path_unix.go
    • Removed os Unix path functions.
  • runtime/internal/lib/os/path_windows.go
    • Removed os Windows path functions.
  • runtime/internal/lib/os/pipe2_unix.go
    • Removed os Unix pipe2 implementation.
  • runtime/internal/lib/os/pipe_unix.go
    • Removed os Unix pipe implementation.
  • runtime/internal/lib/os/pipe_wasm.go
    • Removed os WASM pipe implementation.
  • runtime/internal/lib/os/proc.go
    • Removed os process-related functions.
  • runtime/internal/lib/os/removeall_at.go
    • Removed os removeAll implementation using unlinkat.
  • runtime/internal/lib/os/removeall_noat.go
    • Removed os removeAll implementation without unlinkat.
  • runtime/internal/lib/os/signal/signal.go
    • Removed os/signal stubs.
  • runtime/internal/lib/os/stat.go
    • Removed os stat functions.
  • runtime/internal/lib/os/stat_darwin.go
    • Removed os Darwin stat functions.
  • runtime/internal/lib/os/stat_js.go
    • Removed os JS stat functions.
  • runtime/internal/lib/os/stat_linux.go
    • Removed os Linux stat functions.
  • runtime/internal/lib/os/stat_unix.go
    • Removed os Unix stat functions.
  • runtime/internal/lib/os/stat_wasip1.go
    • Removed os WASIP1 stat functions.
  • runtime/internal/lib/os/sticky_bsd.go
    • Removed os BSD sticky bit support.
  • runtime/internal/lib/os/sticky_nonbsd.go
    • Removed os non-BSD sticky bit support.
  • runtime/internal/lib/os/str.go
    • Removed os string conversion functions.
  • runtime/internal/lib/os/sys_js.go
    • Removed os JS supportsCloseOnExec constant.
  • runtime/internal/lib/os/sys_unix.go
    • Removed os Unix supportsCloseOnExec constant.
  • runtime/internal/lib/os/sys_wasm.go
    • Removed os WASM supportsCloseOnExec constant.
  • runtime/internal/lib/os/tempfile.go
    • Removed os temporary file functions.
  • runtime/internal/lib/os/types.go
    • Removed os type definitions.
  • runtime/internal/lib/os/types_plan9.go
    • Removed os Plan 9 type definitions.
  • runtime/internal/lib/os/types_unix.go
    • Removed os Unix type definitions.
  • runtime/internal/lib/os/types_windows.go
    • Removed os Windows type definitions.
  • runtime/internal/lib/os/wait_unimp.go
    • Removed os unimplemented wait functions.
  • runtime/internal/lib/os/wait_wait6.go
    • Removed os wait6 implementation.
  • runtime/internal/lib/os/wait_waitid.go
    • Removed os waitid implementation.
  • runtime/internal/lib/reflect/type.go
    • Updated import path for sync package from github.com/goplus/llgo/runtime/internal/lib/sync to sync.
  • runtime/internal/lib/runtime/cleanup_stub_llgo.go
    • Added minimal cleanup stubs (funcval, _type, mspan, cleanupQueue, addCleanup, setCleanupContext, inUserArenaChunk, findObject, isGoPointerWithoutSpan, debug) to satisfy os.Process cleanup paths.
  • runtime/internal/lib/runtime/debug/debug.go
    • Removed runtime/debug stubs.
  • runtime/internal/lib/runtime/debug_linkname_llgo.go
    • Added //go:linkname declarations for various runtime/debug functions, linking them to internal runtime implementations or providing stubs.
  • runtime/internal/lib/runtime/extern.go
    • Changed debug.StackTrace to clitedebug.StackTrace.
  • runtime/internal/lib/runtime/fatal_linkname_llgo.go
    • Added //go:linkname declarations for throw and fatal functions used by sync and crypto/rand packages.
  • runtime/internal/lib/runtime/fips_stub_llgo.go
    • Added stubs for FIPS 140 functions (fips_getIndicator, fips_setIndicator, fips_fatal) and fipsinfo struct.
  • runtime/internal/lib/runtime/godebug_linkname_llgo.go
    • Added //go:linkname declarations for internal/godebug functions.
  • runtime/internal/lib/runtime/internal/syscall/syscall.go
    • Renamed from runtime/internal/lib/runtime/internal/syscall/syscall.go.
  • runtime/internal/lib/runtime/internal/syscall/syscall_darwin.go
    • Added an empty stub file for Darwin-specific internal/runtime/syscall.
  • runtime/internal/lib/runtime/internal/syscall/syscall_linux_llgo.go
    • Added Linux-specific Syscall6 implementation, linking to C.syscall and handling errno.
  • runtime/internal/lib/runtime/link_darwin_llgo.go
    • Added //go:linkname implementations for various os and syscall runtime functions specific to Darwin, including environment, process, and fcntl handling.
  • runtime/internal/lib/runtime/link_linux_arm64_go122.go
    • Added Linux ARM64-specific syscall.rawVforkSyscall implementation for Go 1.22 and older, handling CLONE syscalls.
  • runtime/internal/lib/runtime/link_linux_llgo.go
    • Added //go:linkname implementations for various os and syscall runtime functions specific to Linux, including environment, process, fcntl, and C.syscall handling.
  • runtime/internal/lib/runtime/link_linux_rawvfork.go
    • Added Linux-specific syscall.rawVforkSyscall implementation (excluding ARM64 Go 1.22 and older), handling CLONE syscalls.
  • runtime/internal/lib/runtime/mcleanup.go
    • Modified Cleanup struct and Stop method to be no-ops, indicating cleanup cancellation is not supported.
    • Updated AddCleanup to return an empty Cleanup struct.
  • runtime/internal/lib/runtime/poll_linkname_llgo.go
    • Added //go:linkname declarations for internal/poll functions and nanotime stub.
  • runtime/internal/lib/runtime/pprof/pprof.go
    • Removed runtime/pprof stubs.
  • runtime/internal/lib/runtime/pprof_darwin_llgo.go
    • Added stubs for Darwin-specific runtime/pprof functions (mach_vm_region, proc_regionfilename).
  • runtime/internal/lib/runtime/pprof_linkname_llgo.go
    • Added //go:linkname declarations for various runtime/pprof functions, linking them to internal runtime implementations or providing stubs.
  • runtime/internal/lib/runtime/pprof_runtime_stub_llgo.go
    • Added minimal runtime/pprof stubs for StackRecord, MemProfileRecord, BlockProfileRecord, MemProfile, BlockProfile, MutexProfile, ThreadCreateProfile, NumGoroutine, SetCPUProfileRate, FuncForPC.
  • runtime/internal/lib/runtime/rand.go
    • Changed fastrand to link to C.rand.
    • Added randn function for random number reduction.
    • Added //go:linkname for os.fastrand and math/rand.fastrand64.
  • runtime/internal/lib/runtime/runtime2.go
    • Modified Stack to return 0.
    • Modified SetMutexProfileFraction to return 0.
    • Modified SetBlockProfileRate to be a no-op.
  • runtime/internal/lib/runtime/sema_llgo.go
    • Added semaphore and notify list support for sync and internal/poll packages using pthread primitives, including numerous //go:linkname declarations.
  • runtime/internal/lib/runtime/signal_llgo.go
    • Added minimal signal support for os/signal using libuv signals, including signal_enable, signal_disable, signal_ignore, signal_ignored, signal_recv, signalWaitUntilIdle implementations.
  • runtime/internal/lib/runtime/symtab.go
    • Changed debug.Info and debug.Addrinfo to clitedebug.Info and clitedebug.Addrinfo.
  • runtime/internal/lib/runtime/sync_runtime_llgo.go
    • Added //go:linkname declarations for sync.runtime_registerPoolCleanup, sync.runtime_procPin, sync.runtime_procUnpin.
  • runtime/internal/lib/runtime/synctest_llgo.go
    • Added minimal synctest stubs for IsInBubble, associate, disassociate, isAssociated.
  • runtime/internal/lib/runtime/syscall_darwin_llgo.go
    • Added //go:linkname implementations for various syscall functions (syscall.syscall, syscall.syscall6, etc.) by linking them to the new llgo.syscall intrinsics and normalizing errors.
  • runtime/internal/lib/runtime/syscall_enterexit_llgo.go
    • Added entersyscall and exitsyscall stubs.
  • runtime/internal/lib/runtime/time_llgo.go
    • Added minimal time/timer support using libuv timers, including //go:linkname declarations for time.now, time.runtimeNow, time.runtimeNano, time.runtimeIsBubbled, time.Sleep.
  • runtime/internal/lib/runtime/time_llgo_go123.go
    • Added minimal time/timer support for Go 1.23+ using libuv timers, adapted for the Go 1.23+ timer layout.
  • runtime/internal/lib/runtime/trace/trace.go
    • Removed runtime/trace stubs.
  • runtime/internal/lib/runtime/trace_stub_llgo.go
    • Added //go:linkname declarations for runtime.traceAdvance, runtime.traceClockNow, runtime/trace.runtime_readTrace.
  • runtime/internal/lib/runtime/vgetrandom_stub_llgo.go
    • Added vgetrandom stub for Linux.
  • runtime/internal/lib/sync/rwmutex_linkname_llgo.go
    • Added //go:linkname for syscall.hasWaitingReaders.
  • runtime/internal/lib/sync/sync.go
    • Added OnceFunc helper function.
  • runtime/internal/lib/sync/zllgo_stub_darwin.go
    • Added an empty stub file for Darwin-specific sync.
  • runtime/internal/lib/syscall/env_unix.go
    • Removed syscall Unix environment variable functions.
  • runtime/internal/lib/syscall/env_windows.go
    • Removed syscall Windows environment variable functions.
  • runtime/internal/lib/syscall/exec_libc.go
    • Removed syscall libc-based forkAndExecInChild implementation.
  • runtime/internal/lib/syscall/exec_libc2.go
    • Removed syscall libc2-based forkAndExecInChild implementation.
  • runtime/internal/lib/syscall/exec_linux.go
    • Removed syscall Linux forkAndExecInChild implementation.
  • runtime/internal/lib/syscall/exec_unix.go
    • Removed syscall Unix forkExec implementation.
  • runtime/internal/lib/syscall/forkpipe.go
    • Removed syscall fork pipe functions.
  • runtime/internal/lib/syscall/forkpipe2.go
    • Removed syscall fork pipe2 functions.
  • runtime/internal/lib/syscall/fs_wasip1.go
    • Removed syscall WASIP1 filesystem functions.
  • runtime/internal/lib/syscall/net_wasip1.go
    • Removed syscall WASIP1 network functions.
  • runtime/internal/lib/syscall/rlimit.go
    • Removed syscall rlimit functions.
  • runtime/internal/lib/syscall/rlimit_darwin.go
    • Removed syscall Darwin rlimit functions.
  • runtime/internal/lib/syscall/rlimit_stub.go
    • Removed syscall rlimit stub.
  • runtime/internal/lib/syscall/syscall.go
    • Removed syscall core functions.
  • runtime/internal/lib/syscall/syscall_bsd.go
    • Removed syscall BSD specific functions.
  • runtime/internal/lib/syscall/syscall_darwin.go
    • Removed syscall Darwin specific functions.
  • runtime/internal/lib/syscall/syscall_linux.go
    • Removed syscall Linux specific functions.
  • runtime/internal/lib/syscall/syscall_nonwasm.go
    • Removed syscall non-WASM specific functions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a significant and well-executed refactoring that trims down the runtime/internal/lib patches, enabling more of the standard library to be used directly. The introduction of syscall intrinsics and the corresponding compiler support in cl/instr.go is a solid approach to handle platform-specific syscalls. The addition of Dockerfiles for different Go versions and helper scripts will improve the development and testing workflow. I have a few minor suggestions for improvement.

@xgopilot
Copy link
Contributor

xgopilot bot commented Feb 7, 2026

Code Review Summary

This PR introduces valuable syscall intrinsics functionality (llgo.funcPCABI0, llgo.skip, llgo.syscall) and trims the runtime/internal/lib to a focused set of alt packages. The proposal document (doc/syscall-intrinsics-proposal.md) is comprehensive and well-written.

Key Observations

Positives:

  • Clean implementation of syscall intrinsics matching Go's stdlib pattern
  • Shell scripts have proper input validation and error handling
  • Pre-allocated slice capacities in hot paths

Areas for improvement:

  • New syscall-related functions in cl/instr.go lack doc comments
  • Some constants appear unused or lack explanation
  • Minor opportunity for caching type signatures

See inline comments for specific suggestions.

@cpunion cpunion force-pushed the stdlib-opt-trim-internal-lib branch from e6a2517 to 0c38765 Compare February 7, 2026 14:05
@codecov
Copy link

codecov bot commented Feb 7, 2026

Codecov Report

❌ Patch coverage is 93.47826% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.08%. Comparing base (d273162) to head (b3ad65e).
⚠️ Report is 76 commits behind head on main.

Files with missing lines Patch % Lines
cl/instr.go 93.67% 3 Missing and 2 partials ⚠️
cl/import.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1621      +/-   ##
==========================================
- Coverage   91.10%   91.08%   -0.03%     
==========================================
  Files          45       45              
  Lines       11921    12041     +120     
==========================================
+ Hits        10861    10967     +106     
- Misses        886      897      +11     
- Partials      174      177       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add doc comments for zeroResult/syscallFnSig/syscallFnSigFixed/syscallErrno/syscallIntrinsic to make the low-level lowering easier to maintain.
@cpunion cpunion force-pushed the stdlib-opt-trim-internal-lib branch from 73d9fd0 to 8a7412e Compare February 7, 2026 14:34
Move dev/ docker/CI tooling updates to chore/dev-dockerfiles (separate PR).
Document the current runtime/internal/lib alt-package set and removal candidates, with notes on upstream assembly dependency and plan9-asm integration targets.
@cpunion cpunion force-pushed the stdlib-opt-trim-internal-lib branch 5 times, most recently from b664177 to edcb511 Compare February 10, 2026 08:35
…nal-lib

# Conflicts:
#	runtime/build.go
#	runtime/internal/lib/crypto/internal/boring/sig/sig.go
@cpunion cpunion force-pushed the stdlib-opt-trim-internal-lib branch from edcb511 to 12046e4 Compare February 10, 2026 08:52
@xushiwei xushiwei merged commit 9c8b6b3 into goplus:main Feb 10, 2026
36 of 37 checks passed
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.

3 participants