Skip to content

Commit 6b1e842

Browse files
committed
runtime: source patch crypto internal constanttime
1 parent ac44259 commit 6b1e842

File tree

4 files changed

+57
-51
lines changed

4 files changed

+57
-51
lines changed

internal/build/source_patch_go126_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,36 @@ func TestInternalSyncUsesSourcePatchInsteadOfAltPkg(t *testing.T) {
5858
t.Fatal("internal/sync should not remain an alt package")
5959
}
6060
}
61+
62+
func TestBuildSourcePatchOverlayForCryptoInternalConstanttime(t *testing.T) {
63+
overlay, err := buildSourcePatchOverlayForGOROOT(nil, env.LLGoRuntimeDir(), runtime.GOROOT(), sourcePatchBuildContext{
64+
goos: runtime.GOOS,
65+
goarch: runtime.GOARCH,
66+
goversion: "go1.26.0",
67+
})
68+
if err != nil {
69+
t.Fatal(err)
70+
}
71+
72+
pkgDir := filepath.Join(runtime.GOROOT(), "src", "crypto", "internal", "constanttime")
73+
patchFile := filepath.Join(pkgDir, "z_llgo_patch_constant_time.go")
74+
patchSrc, ok := overlay[patchFile]
75+
if !ok {
76+
t.Fatalf("missing source patch file %s", patchFile)
77+
}
78+
if !strings.Contains(string(patchSrc), "//go:linkname boolToUint8 llgo.boolToUint8") {
79+
t.Fatalf("source patch file %s does not contain boolToUint8 linkname", patchFile)
80+
}
81+
if !strings.HasPrefix(string(patchSrc), sourcePatchLineDirective(filepath.Join(env.LLGoRuntimeDir(), "_patch", "crypto", "internal", "constanttime", "constant_time.go"))) {
82+
t.Fatalf("source patch file %s is missing line directive, got:\n%s", patchFile, patchSrc)
83+
}
84+
}
85+
86+
func TestCryptoInternalConstanttimeUsesSourcePatchInsteadOfAltPkg(t *testing.T) {
87+
if !llruntime.HasSourcePatchPkg("crypto/internal/constanttime") {
88+
t.Fatal("crypto/internal/constanttime should be registered as a source patch package")
89+
}
90+
if llruntime.HasAltPkg("crypto/internal/constanttime") {
91+
t.Fatal("crypto/internal/constanttime should not remain an alt package")
92+
}
93+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2025 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build go1.26
6+
7+
package constanttime
8+
9+
import _ "unsafe"
10+
11+
//go:linkname boolToUint8 llgo.boolToUint8
12+
func boolToUint8(b bool) uint8

runtime/build.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ func SourcePatchPkgPaths() []string {
4040
}
4141

4242
var altPkgs = map[string]altPkgMode{
43-
"crypto/internal/constanttime": altPkgReplace,
44-
"internal/abi": altPkgReplace,
45-
"internal/reflectlite": altPkgReplace,
46-
"internal/runtime/maps": altPkgReplace,
47-
"internal/runtime/sys": altPkgAdditive,
48-
"reflect": altPkgReplace,
49-
"runtime": altPkgReplace,
50-
"sync/atomic": altPkgReplace,
51-
"syscall/js": altPkgReplace,
52-
"unique": altPkgReplace,
43+
"internal/abi": altPkgReplace,
44+
"internal/reflectlite": altPkgReplace,
45+
"internal/runtime/maps": altPkgReplace,
46+
"internal/runtime/sys": altPkgAdditive,
47+
"reflect": altPkgReplace,
48+
"runtime": altPkgReplace,
49+
"sync/atomic": altPkgReplace,
50+
"syscall/js": altPkgReplace,
51+
"unique": altPkgReplace,
5352
}
5453

5554
var sourcePatchPkgs = map[string]struct{}{
56-
"internal/sync": {},
57-
"iter": {},
55+
"crypto/internal/constanttime": {},
56+
"internal/sync": {},
57+
"iter": {},
5858
}

runtime/internal/lib/crypto/internal/constanttime/constant_time.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)