From 821f2aeae0592c8b04cf3a58b6556269c2fd4b82 Mon Sep 17 00:00:00 2001 From: Ben Krieger Date: Thu, 18 Sep 2025 23:46:46 -0400 Subject: [PATCH] Fix linker errors for runtime.vgetrandom and crypto/internal/sysrand.fatal --- src/runtime/rand.go | 11 +++++++++++ tests/os/smoke/smoke_test.go | 9 +++++++++ 2 files changed, 20 insertions(+) create mode 100644 src/runtime/rand.go diff --git a/src/runtime/rand.go b/src/runtime/rand.go new file mode 100644 index 000000000..531910ef0 --- /dev/null +++ b/src/runtime/rand.go @@ -0,0 +1,11 @@ +package runtime + +import _ "unsafe" + +// TODO: Use hardware when available +// +//go:linkname vgetrandom +func vgetrandom(p []byte, flags uint32) (ret int, supported bool) { return 0, false } + +//go:linkname fatal crypto/internal/sysrand.fatal +func fatal(msg string) { runtimePanic(msg) } diff --git a/tests/os/smoke/smoke_test.go b/tests/os/smoke/smoke_test.go index 068023d61..f454909a8 100644 --- a/tests/os/smoke/smoke_test.go +++ b/tests/os/smoke/smoke_test.go @@ -4,6 +4,8 @@ package os_smoke_test // Intended to catch build tag mistakes affecting bare metal targets. import ( + "crypto/rand" + "crypto/rsa" "fmt" "path/filepath" "testing" @@ -25,3 +27,10 @@ func TestFmt(t *testing.T) { t.Errorf("printf returned %d, expected 14", n) } } + +// Regression test for https://github.com/tinygo-org/tinygo/issues/4921 +func TestRand(t *testing.T) { + if _, err := rsa.GenerateKey(rand.Reader, 2048); err != nil { + t.Error(err) + } +}