Skip to content

Commit d1e96fd

Browse files
aykevldeadprogram
authored andcommitted
wasm: scan globals conservatively
Make the GC globals scan phase conservative instead of precise on WebAssembly. This reduces code size at the risk of introducing some false positives. This is a stopgap measure to mitigate an issue with the precise scanning of globals that doesn't track all pointers. It works for regular globals but globals created in the interp package don't always have a type and therefore may be missed by the AddGlobalsBitmap pass. The same issue is present on Linux and macOS, but is not as noticeable there.
1 parent ff5d0c9 commit d1e96fd

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

src/runtime/arch_wasm.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ const TargetBits = 32
1414
//go:extern __heap_base
1515
var heapStartSymbol [0]byte
1616

17+
//go:extern __global_base
18+
var globalsStartSymbol [0]byte
19+
1720
//export llvm.wasm.memory.size.i32
1821
func wasm_memory_size(index int32) int32
1922

2023
//export llvm.wasm.memory.grow.i32
2124
func wasm_memory_grow(index int32, delta int32) int32
2225

2326
var (
24-
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
25-
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
27+
heapStart = uintptr(unsafe.Pointer(&heapStartSymbol))
28+
heapEnd = uintptr(wasm_memory_size(0) * wasmPageSize)
29+
globalsStart = uintptr(unsafe.Pointer(&globalsStartSymbol))
30+
globalsEnd = uintptr(unsafe.Pointer(&heapStartSymbol))
2631
)
2732

2833
const wasmPageSize = 64 * 1024

src/runtime/gc_conservative.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func markRoots(start, end uintptr) {
401401
}
402402
}
403403

404-
for addr := start; addr != end; addr += unsafe.Alignof(addr) {
404+
for addr := start; addr < end; addr += unsafe.Alignof(addr) {
405405
root := *(*uintptr)(unsafe.Pointer(addr))
406406
markRoot(addr, root)
407407
}

src/runtime/gc_globals_conservative.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// +build gc.conservative gc.extalloc
2-
// +build baremetal
2+
// +build baremetal wasm
33

44
package runtime
55

src/runtime/gc_globals_precise.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// +build gc.conservative gc.extalloc
2-
// +build !baremetal
2+
// +build !baremetal,!wasm
33

44
package runtime
55

0 commit comments

Comments
 (0)