Skip to content
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
13 changes: 3 additions & 10 deletions src/wasm/wasm-emscripten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,10 @@ void addExportedFunction(Module& wasm, Function* function) {
}

Global* getStackPointerGlobal(Module& wasm) {
// Assumption: The stack pointer is either imported as __stack_pointer or
// we just assume it's the first non-imported global.
// TODO(sbc): Find a better way to discover the stack pointer. Perhaps the
// linker could export it by name?
// Assumption: The stack pointer is either be an imported global called
// __stack_pointer or a defined global with that name.
for (auto& g : wasm.globals) {
if (g->imported() && g->base == STACK_POINTER) {
return g.get();
}
}
for (auto& g : wasm.globals) {
if (!g->imported()) {
if (g->base == STACK_POINTER || g->name == STACK_POINTER) {
return g.get();
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/finalize/recursive_safe_stack.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(memory $0 2)
(data (i32.const 568) "%d:%d\n\00Result: %d\n\00")
(table $0 1 1 funcref)
(global $global$0 (mut i32) (i32.const 66128))
(global $__stack_pointer (mut i32) (i32.const 66128))
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 587))
(export "memory" (memory $0))
Expand All @@ -18,10 +18,10 @@
)
(func $foo (; 2 ;) (type $0) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(global.set $global$0
(global.set $__stack_pointer
(local.tee $2
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -40,7 +40,7 @@
(local.get $2)
)
)
(global.set $global$0
(global.set $__stack_pointer
(i32.add
(local.get $2)
(i32.const 16)
Expand All @@ -53,10 +53,10 @@
)
(func $__original_main (; 3 ;) (type $2) (result i32)
(local $0 i32)
(global.set $global$0
(global.set $__stack_pointer
(local.tee $0
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -74,7 +74,7 @@
(local.get $0)
)
)
(global.set $global$0
(global.set $__stack_pointer
(i32.add
(local.get $0)
(i32.const 16)
Expand Down
14 changes: 7 additions & 7 deletions test/finalize/recursive_safe_stack.wat.out
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(type $4 (func (param i32 i32)))
(import "env" "printf" (func $printf (param i32 i32) (result i32)))
(import "env" "__handle_stack_overflow" (func $__handle_stack_overflow (param i32)))
(global $global$0 (mut i32) (i32.const 66128))
(global $__stack_pointer (mut i32) (i32.const 66128))
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 587))
(global $__stack_base (mut i32) (i32.const 0))
Expand All @@ -33,7 +33,7 @@
(local.tee $3
(local.tee $2
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -51,7 +51,7 @@
)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $3)
)
)
Expand Down Expand Up @@ -92,7 +92,7 @@
)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $4)
)
)
Expand All @@ -112,7 +112,7 @@
(local.tee $1
(local.tee $0
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -130,7 +130,7 @@
)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $1)
)
)
Expand Down Expand Up @@ -170,7 +170,7 @@
)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $2)
)
)
Expand Down
14 changes: 7 additions & 7 deletions test/finalize/safe_stack_standalone-wasm.wat
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
(memory $0 2)
(data (i32.const 568) "%d:%d\n\00Result: %d\n\00")
(table $0 1 1 funcref)
(global $global$0 (mut i32) (i32.const 66128))
(global $__stack_pointer (mut i32) (i32.const 66128))
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 587))
(export "memory" (memory $0))
Expand All @@ -18,10 +18,10 @@
)
(func $foo (; 2 ;) (type $0) (param $0 i32) (param $1 i32) (result i32)
(local $2 i32)
(global.set $global$0
(global.set $__stack_pointer
(local.tee $2
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -40,7 +40,7 @@
(local.get $2)
)
)
(global.set $global$0
(global.set $__stack_pointer
(i32.add
(local.get $2)
(i32.const 16)
Expand All @@ -53,10 +53,10 @@
)
(func $__original_main (; 3 ;) (type $2) (result i32)
(local $0 i32)
(global.set $global$0
(global.set $__stack_pointer
(local.tee $0
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -74,7 +74,7 @@
(local.get $0)
)
)
(global.set $global$0
(global.set $__stack_pointer
(i32.add
(local.get $0)
(i32.const 16)
Expand Down
14 changes: 7 additions & 7 deletions test/finalize/safe_stack_standalone-wasm.wat.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(type $2 (func (result i32)))
(type $3 (func (param i32 i32)))
(import "env" "printf" (func $printf (param i32 i32) (result i32)))
(global $global$0 (mut i32) (i32.const 66128))
(global $__stack_pointer (mut i32) (i32.const 66128))
(global $global$1 i32 (i32.const 66128))
(global $global$2 i32 (i32.const 587))
(global $__stack_base (mut i32) (i32.const 0))
Expand All @@ -31,7 +31,7 @@
(local.tee $3
(local.tee $2
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -47,7 +47,7 @@
(unreachable)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $3)
)
)
Expand Down Expand Up @@ -86,7 +86,7 @@
(unreachable)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $4)
)
)
Expand All @@ -106,7 +106,7 @@
(local.tee $1
(local.tee $0
(i32.sub
(global.get $global$0)
(global.get $__stack_pointer)
(i32.const 16)
)
)
Expand All @@ -122,7 +122,7 @@
(unreachable)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $1)
)
)
Expand Down Expand Up @@ -160,7 +160,7 @@
(unreachable)
)
)
(global.set $global$0
(global.set $__stack_pointer
(local.get $2)
)
)
Expand Down
16 changes: 8 additions & 8 deletions test/lit/passes/stack-check-memory64.wast
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

;; CHECK: (type $1 (func (param i64 i64)))

;; CHECK: (global $sp (mut i64) (i64.const 0))
(global $sp (mut i64) (i64.const 0))
;; CHECK: (global $__stack_pointer (mut i64) (i64.const 0))
(global $__stack_pointer (mut i64) (i64.const 0))
;; CHECK: (global $__stack_base (mut i64) (i64.const 0))

;; CHECK: (global $__stack_limit (mut i64) (i64.const 0))
Expand Down Expand Up @@ -41,15 +41,15 @@
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.set $sp
;; CHECK-NEXT: (global.set $__stack_pointer
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (global.get $sp)
;; CHECK-NEXT: (global.get $__stack_pointer)
;; CHECK-NEXT: )
(func $use_stack (export "use_stack") (result i64)
(global.set $sp (i64.const 42))
(global.get $sp)
(global.set $__stack_pointer (i64.const 42))
(global.get $__stack_pointer)
)
)
;; CHECK: (func $__set_stack_limits (param $0 i64) (param $1 i64)
Expand All @@ -67,8 +67,8 @@

;; CHECK: (type $1 (func (param i64 i64)))

;; CHECK: (global $sp (mut i64) (i64.const 0))
(global $sp (mut i64) (i64.const 0))
;; CHECK: (global $__stack_pointer (mut i64) (i64.const 0))
(global $__stack_pointer (mut i64) (i64.const 0))
;; CHECK: (global $__stack_base (mut i64) (i64.const 0))
(global $__stack_base (mut i64) (i64.const 0))
;; CHECK: (global $__stack_limit (mut i64) (i64.const 0))
Expand Down
Loading
Loading