Skip to content

Fix lifetime confusion in shadow stack pass #2596

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
Dec 22, 2022
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
6 changes: 3 additions & 3 deletions src/passes/shadowstack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ function needsSlot(module: Module, value: ExpressionRef): bool {
switch (_BinaryenExpressionGetId(value)) {
// no need to stack null pointers
case ExpressionId.Const: return !isConstZero(value);
// already kept in another slot
case ExpressionId.LocalGet:
case ExpressionId.LocalSet: return false; // tee
// note: can't omit a slot when assigning from another local since the other
// local might have shorter lifetime and become reassigned, say in a loop,
// then no longer holding on to the previous value in its stack slot.
}
return true;
}
Expand Down
149 changes: 134 additions & 15 deletions tests/compiler/NonNullable.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,44 @@
i32.const 0
return
)
(func $~start (type $none_=>_none)
call $start:NonNullable
)
(func $~stack_check (type $none_=>_none)
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__data_end
i32.lt_s
if
i32.const 33152
i32.const 33200
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
end
)
(func $~lib/string/String.__eq (type $i32_i32_=>_i32) (param $left i32) (param $right i32) (result i32)
(local $leftLength i32)
(local $3 i32)
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i64.const 0
i64.store $0
local.get $left
local.get $right
i32.eq
if
i32.const 1
local.set $3
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
local.get $3
return
end
local.get $left
Expand All @@ -163,40 +194,117 @@
end
if
i32.const 0
local.set $3
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
local.get $3
return
end
local.get $left
local.set $3
global.get $~lib/memory/__stack_pointer
local.get $3
i32.store $0
local.get $3
call $~lib/string/String#get:length
local.set $leftLength
local.get $leftLength
local.get $right
local.set $3
global.get $~lib/memory/__stack_pointer
local.get $3
i32.store $0
local.get $3
call $~lib/string/String#get:length
i32.ne
if
i32.const 0
local.set $3
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
local.get $3
return
end
local.get $left
local.set $3
global.get $~lib/memory/__stack_pointer
local.get $3
i32.store $0
local.get $3
i32.const 0
local.get $right
local.set $3
global.get $~lib/memory/__stack_pointer
local.get $3
i32.store $0 offset=4
local.get $3
i32.const 0
local.get $leftLength
call $~lib/util/string/compareImpl
i32.eqz
local.set $3
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
local.get $3
return
)
(func $~lib/string/String.__ne (type $i32_i32_=>_i32) (param $left i32) (param $right i32) (result i32)
(local $2 i32)
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i64.const 0
i64.store $0
local.get $left
local.set $2
global.get $~lib/memory/__stack_pointer
local.get $2
i32.store $0
local.get $2
local.get $right
local.set $2
global.get $~lib/memory/__stack_pointer
local.get $2
i32.store $0 offset=4
local.get $2
call $~lib/string/String.__eq
i32.eqz
local.set $2
global.get $~lib/memory/__stack_pointer
i32.const 8
i32.add
global.set $~lib/memory/__stack_pointer
local.get $2
return
)
(func $NonNullable/assertNonNull<~lib/string/String> (type $i32_=>_none) (param $t i32)
(local $1 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store $0
i32.const 0
i32.eqz
drop
local.get $t
local.set $1
global.get $~lib/memory/__stack_pointer
local.get $1
i32.store $0
local.get $1
i32.const 0
call $~lib/string/String.__ne
i32.eqz
Expand All @@ -208,31 +316,42 @@
call $~lib/builtins/abort
unreachable
end
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
)
(func $NonNullable/safetyCheck<~lib/string/String|null> (type $i32_=>_none) (param $t i32)
(local $1 i32)
global.get $~lib/memory/__stack_pointer
i32.const 4
i32.sub
global.set $~lib/memory/__stack_pointer
call $~stack_check
global.get $~lib/memory/__stack_pointer
i32.const 0
i32.store $0
local.get $t
local.set $1
global.get $~lib/memory/__stack_pointer
local.get $1
i32.store $0
local.get $1
i32.const 0
call $~lib/string/String.__ne
if
local.get $t
local.set $1
global.get $~lib/memory/__stack_pointer
local.get $1
i32.store $0
local.get $1
call $NonNullable/assertNonNull<~lib/string/String>
end
)
(func $~start (type $none_=>_none)
call $start:NonNullable
)
(func $~stack_check (type $none_=>_none)
global.get $~lib/memory/__stack_pointer
global.get $~lib/memory/__data_end
i32.lt_s
if
i32.const 33152
i32.const 33200
i32.const 1
i32.const 1
call $~lib/builtins/abort
unreachable
end
i32.const 4
i32.add
global.set $~lib/memory/__stack_pointer
)
(func $start:NonNullable (type $none_=>_none)
(local $0 i32)
Expand Down
Loading