From cf6cc937efdd3a18884c54bf185882d6eb826ac6 Mon Sep 17 00:00:00 2001 From: xgopilot Date: Tue, 14 Oct 2025 07:04:42 +0000 Subject: [PATCH] fix: add runtime.rand and runtime.memhash for hash/maphash support - Register hash/maphash in hasAltPkg map in runtime/build.go - Add rand() function that bridges to fastrand64() in runtime overlay - Add memhash() function that bridges to internal memhash() in runtime overlay - Fixes issue where hash/maphash package failed with undefined symbols Fixes #1338 Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang Co-authored-by: xgopilot --- runtime/build.go | 1 + runtime/internal/lib/runtime/runtime.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/runtime/build.go b/runtime/build.go index a4ac3753..32bee643 100644 --- a/runtime/build.go +++ b/runtime/build.go @@ -24,6 +24,7 @@ var hasAltPkg = map[string]none{ "crypto/subtle": {}, "go/parser": {}, "hash/crc32": {}, + "hash/maphash": {}, "internal/abi": {}, "internal/bytealg": {}, "internal/chacha8rand": {}, diff --git a/runtime/internal/lib/runtime/runtime.go b/runtime/internal/lib/runtime/runtime.go index 0defce9e..b107c605 100644 --- a/runtime/internal/lib/runtime/runtime.go +++ b/runtime/internal/lib/runtime/runtime.go @@ -56,4 +56,18 @@ func write(fd uintptr, p unsafe.Pointer, n int32) int32 { return int32(c_write(c.Int(fd), p, c.SizeT(n))) } +//go:linkname llgo_fastrand64 github.com/goplus/llgo/runtime/internal/runtime.fastrand64 +func llgo_fastrand64() uint64 + +//go:linkname llgo_memhash github.com/goplus/llgo/runtime/internal/runtime.memhash +func llgo_memhash(p unsafe.Pointer, seed, s uintptr) uintptr + +func rand() uint64 { + return llgo_fastrand64() +} + +func memhash(p unsafe.Pointer, seed, s uintptr) uintptr { + return llgo_memhash(p, seed, s) +} + const heapArenaBytes = 1024 * 1024