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 <luoliwoshang@users.noreply.github.com>
Co-authored-by: xgopilot <noreply@goplus.org>
This commit is contained in:
xgopilot
2025-10-14 07:04:42 +00:00
parent 7e1abf1486
commit cf6cc937ef
2 changed files with 15 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ var hasAltPkg = map[string]none{
"crypto/subtle": {},
"go/parser": {},
"hash/crc32": {},
"hash/maphash": {},
"internal/abi": {},
"internal/bytealg": {},
"internal/chacha8rand": {},

View File

@@ -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