-
Notifications
You must be signed in to change notification settings - Fork 851
Implement --check-stack-overflow flag for wasm-emscripten-finalize #2278
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
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9324f58
Implement --check-stack-overflow
quantum5 ae72862
Only check stack pointer subtractions
quantum5 beb4a80
Add tests
quantum5 c0606fd
Support dynamic linking
quantum5 35e97d7
Make the code easier to understand
quantum5 2dbc634
Avoid NameType
quantum5 21d3863
Parallel processing and modify even epilogue
quantum5 151b585
Deal with GCC's intolerance
quantum5 5c9f6d9
Use passes properly
quantum5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| (module | ||
| (type $0 (func (param i32 i32) (result i32))) | ||
| (type $1 (func)) | ||
| (type $2 (func (result i32))) | ||
| (import "env" "printf" (func $printf (param i32 i32) (result i32))) | ||
| (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 $global$1 i32 (i32.const 66128)) | ||
| (global $global$2 i32 (i32.const 587)) | ||
| (export "memory" (memory $0)) | ||
| (export "__wasm_call_ctors" (func $__wasm_call_ctors)) | ||
| (export "__heap_base" (global $global$1)) | ||
| (export "__data_end" (global $global$2)) | ||
| (export "main" (func $main)) | ||
| (func $__wasm_call_ctors (; 1 ;) (type $1) | ||
| ) | ||
| (func $foo (; 2 ;) (type $0) (param $0 i32) (param $1 i32) (result i32) | ||
| (local $2 i32) | ||
| (global.set $global$0 | ||
| (local.tee $2 | ||
| (i32.sub | ||
| (global.get $global$0) | ||
| (i32.const 16) | ||
| ) | ||
| ) | ||
| ) | ||
| (i32.store offset=4 | ||
| (local.get $2) | ||
| (local.get $1) | ||
| ) | ||
| (i32.store | ||
| (local.get $2) | ||
| (local.get $0) | ||
| ) | ||
| (drop | ||
| (call $printf | ||
| (i32.const 568) | ||
| (local.get $2) | ||
| ) | ||
| ) | ||
| (global.set $global$0 | ||
| (i32.add | ||
| (local.get $2) | ||
| (i32.const 16) | ||
| ) | ||
| ) | ||
| (i32.add | ||
| (local.get $1) | ||
| (local.get $0) | ||
| ) | ||
| ) | ||
| (func $__original_main (; 3 ;) (type $2) (result i32) | ||
| (local $0 i32) | ||
| (global.set $global$0 | ||
| (local.tee $0 | ||
| (i32.sub | ||
| (global.get $global$0) | ||
| (i32.const 16) | ||
| ) | ||
| ) | ||
| ) | ||
| (i32.store | ||
| (local.get $0) | ||
| (call $foo | ||
| (i32.const 1) | ||
| (i32.const 2) | ||
| ) | ||
| ) | ||
| (drop | ||
| (call $printf | ||
| (i32.const 575) | ||
| (local.get $0) | ||
| ) | ||
| ) | ||
| (global.set $global$0 | ||
| (i32.add | ||
| (local.get $0) | ||
| (i32.const 16) | ||
| ) | ||
| ) | ||
| (i32.const 0) | ||
| ) | ||
| (func $main (; 4 ;) (type $0) (param $0 i32) (param $1 i32) (result i32) | ||
| (call $__original_main) | ||
| ) | ||
| ;; custom section "producers", size 111 | ||
| ) | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of silently doing nothing for side modules, how about
Fatal() << "stack overflow checks are not supported with side modules";?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, we actually need to do nothing for side modules because all stack operations gets turned into
stackSaveandstackRestore, which are exported from the main module. In the main module,stackRestoreperforms the overflow check.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that right? I thought side modules manage their own stack in their own memory. At least that's how fastcomp does it - is it completely different in the wasm backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it. This is the prologue of a function in the side module:
and this is the epilogue:
stackSaveandstackRestoreare imported:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's very surprising. Let's see what @sbc100 says. But that doesn't need to block this PR landing (we may need a followup though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this surprising? The sp with the wasm backend is mutable global but we don't have any way to import or export mutable globals (yet), so the side module has to manipulate the global via these helper functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks @sbc100
I guess I'm used to the fastcomp model where not just threads but shared modules also got their own stack.