Skip to content

interp: correctly mark functions as modifying memory #4742

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builder/sizes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func TestBinarySize(t *testing.T) {
tests := []sizeTest{
// microcontrollers
{"hifive1b", "examples/echo", 4560, 280, 0, 2268},
{"microbit", "examples/serial", 2908, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7293, 1487, 116, 6912},
{"microbit", "examples/serial", 2916, 388, 8, 2272},
{"wioterminal", "examples/pininterrupt", 7315, 1489, 116, 6912},

// TODO: also check wasm. Right now this is difficult, because
// wasm binaries are run through wasm-opt and therefore the
Expand Down
6 changes: 3 additions & 3 deletions interp/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,9 @@ func (r *runner) runAtRuntime(fn *function, inst instruction, locals []value, me
case llvm.Call:
llvmFn := operands[len(operands)-1]
args := operands[:len(operands)-1]
for _, arg := range args {
if arg.Type().TypeKind() == llvm.PointerTypeKind {
err := mem.markExternalStore(arg)
for _, op := range operands {
if op.Type().TypeKind() == llvm.PointerTypeKind {
err := mem.markExternalStore(op)
if err != nil {
return r.errorAt(inst, err)
}
Expand Down
6 changes: 3 additions & 3 deletions src/runtime/algorithm.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ func fastrand() uint32 {
return xorshift32State
}

func init() {
func initRand() {
r, _ := hardwareRand()
xorshift64State = uint64(r | 1) // protect against 0
xorshift32State = uint32(xorshift64State)
}

var xorshift32State uint32
var xorshift32State uint32 = 1

func xorshift32(x uint32) uint32 {
// Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs".
Expand All @@ -49,7 +49,7 @@ func fastrand64() uint64 {
return xorshift64State
}

var xorshift64State uint64
var xorshift64State uint64 = 1

// 64-bit xorshift multiply rng from http://vigna.di.unimi.it/ftp/papers/xorshift.pdf
func xorshiftMult64(x uint64) uint64 {
Expand Down
1 change: 1 addition & 0 deletions src/runtime/runtime_wasmentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func wasmEntryReactor() {
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
initHeap()
initRand()

if hasScheduler {
// A package initializer might do funky stuff like start a goroutine and
Expand Down
1 change: 1 addition & 0 deletions src/runtime/scheduler_cooperative.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func sleep(duration int64) {
// With a scheduler, init and the main function are invoked in a goroutine before starting the scheduler.
func run() {
initHeap()
initRand()
go func() {
initAll()
callMain()
Expand Down
1 change: 1 addition & 0 deletions src/runtime/scheduler_none.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const hasParallelism = false
// With the "none" scheduler, init and the main function are invoked directly.
func run() {
initHeap()
initRand()
initAll()
callMain()
mainExited = true
Expand Down