fix: guard native code on portable builds#14
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes cross-architecture build selection for the project’s native (SSE/AVX2) implementation by adding explicit amd64 build constraints and introducing a standard-library fallback for non-amd64, noasm, and appengine builds.
Changes:
- Added
//go:build amd64 && !noasm && !appengineconstraints across native dispatch/export/generated code so non-amd64builds can’t select the x86 loader path. - Introduced split implementations in
base64x: a native-backed version foramd64and a stdlib-based fallback for other build contexts. - Updated CI workflows and typo configuration; ran gofmt-style formatting updates across multiple files.
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/rt/fastmem.go | gofmt/comment formatting adjustments in low-level runtime helpers. |
| internal/rt/asm_arm64.s | Added license header above existing build constraints for ARM64 asm. |
| internal/rt/asm_amd64.s | Added license header above existing build constraints for AMD64 asm. |
| internal/native/sse/native_export.go | Added amd64 && !noasm && !appengine build constraints; gofmt import/indent cleanup. |
| internal/native/sse/b64encode_text_amd64.go | Tightened build constraints and gofmt formatting of generated text blob. |
| internal/native/sse/b64encode_subr.go | Tightened build constraints and gofmt formatting. |
| internal/native/sse/b64encode.go | Tightened build constraints and gofmt formatting. |
| internal/native/sse/b64decode_text_amd64.go | Tightened build constraints and gofmt formatting of generated text blob. |
| internal/native/sse/b64decode_subr.go | Tightened build constraints and gofmt formatting. |
| internal/native/sse/b64decode.go | Tightened build constraints and gofmt formatting. |
| internal/native/avx2/native_export.go | Added amd64 && !noasm && !appengine build constraints; gofmt import/indent cleanup. |
| internal/native/avx2/b64encode_text_amd64.go | Tightened build constraints and gofmt formatting of generated text blob. |
| internal/native/avx2/b64encode_subr.go | Tightened build constraints and gofmt formatting. |
| internal/native/avx2/b64encode.go | Tightened build constraints and gofmt formatting. |
| internal/native/avx2/b64decode_text_amd64.go | Tightened build constraints and gofmt formatting of generated text blob. |
| internal/native/avx2/b64decode_subr.go | Tightened build constraints and gofmt formatting. |
| internal/native/avx2/b64decode.go | Tightened build constraints and gofmt formatting. |
| internal/native/native_test.go | Restricted native tests to amd64 && !noasm && !appengine; gofmt formatting. |
| internal/native/native_export.tmpl | Added amd64 && !noasm && !appengine build constraints to template output. |
| internal/native/dispatch.go | Added license header + amd64 && !noasm && !appengine build constraints; import order/gofmt cleanup. |
| internal/native/b64encode.tmpl | Added amd64 && !noasm && !appengine build constraints to template output. |
| internal/native/b64decode.tmpl | Added amd64 && !noasm && !appengine build constraints to template output. |
| fuzz_test.go | Added //go:build go1.18; gofmt import/loop formatting. |
| faststr.go | gofmt formatting and comment spacing. |
| bench/bench_test.go | Added license header; gofmt formatting and import ordering. |
| base64x_test.go | gofmt formatting across tests. |
| base64x_subr_amd64.go | Added license header + tighter build constraints for native subr symbols. |
| base64x_native.go | New file: native-backed encode/decode helpers under amd64 && !noasm && !appengine. |
| base64x_fallback.go | New file: stdlib-based fallback encode/decode under `!amd64 |
| base64x.go | Removed direct native import; routed through build-tagged encode/decode helpers; gofmt cleanup. |
| _typos.toml | Excluded base64x_test.go from typos; added shll extended word. |
| .github/workflows/tests.yml | Updated actions versions; added fallback build/compile matrix job. |
| .github/workflows/pr-check.yml | Moved to hosted runner; updated action versions; minor YAML cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de877db460
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
2cddb16 to
a3259a4
Compare
Split native amd64 code from the stdlib fallback path, preserve amd64 linkname compatibility symbols for noasm/appengine builds, and cover fallback targets in CI.
Summary
amd64 && !noasm && !appenginebuilds.noasm, andappenginebuilds._subr__b64decode/_subr__b64encodecompatibility symbols while avoiding native imports in fallback builds.github.com/bytedance/sonic/loadertov0.5.1for Go 1.26 native runtime compatibility.Motivation
The native SSE/AVX2 implementation imports the loader/native path and is only valid for x86 native builds. Without explicit architecture constraints, portable builds such as darwin/arm64 with Go 1.20 can select the native path and fail before package-level fallback behavior is available.
Go 1.26 also changes the native loader runtime/moduledata behavior. With
sonic/loader v0.3.0, darwin/amd64 native tests fail at init time withfatal error: invalid function symbol tablefromruntime.moduledataverify1.sonic/loader v0.5.1includes the upstream Go 1.26 loader support.Implementation Notes
encode/decodeare compiled only foramd64 && !noasm && !appengine.encode/decodeuseencoding/base64for portable builds.encoding/jsonfor simpler, standard behavior.encoding/base64errors directly instead of rewriting missing-padding error positions.Validation
GOTOOLCHAIN=go1.26.0 GOOS=darwin GOARCH=amd64 CGO_ENABLED=0 go test -run 'TestEncoder|TestDecoder|TestSubrCompatibilitySymbols' -count=1 -v .GOTOOLCHAIN=go1.26.0 GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .GOTOOLCHAIN=go1.26.0 CGO_ENABLED=0 go test -tags noasm -run '^$' .GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test .GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test -tags noasm .GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test -tags appengine .GOTOOLCHAIN=go1.20.14 CGO_ENABLED=0 go test ./...GOTOOLCHAIN=go1.20.14 GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go test -run '^$' .GOTOOLCHAIN=go1.20.14 GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .GOTOOLCHAIN=go1.20.14 GOOS=linux GOARCH=riscv64 CGO_ENABLED=0 go test -run '^$' -exec=/usr/bin/true .GOTOOLCHAIN=go1.17.13 CGO_ENABLED=0 go test .