Fix SafeHeap crash when start function calls an imported function#8306
Open
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Open
Fix SafeHeap crash when start function calls an imported function#8306sumleo wants to merge 1 commit intoWebAssembly:mainfrom
sumleo wants to merge 1 commit intoWebAssembly:mainfrom
Conversation
findCalledFunctions transitively walks all functions called from the start function to determine which functions should not be instrumented. When the start function calls an imported function, the import was added to the worklist and then FindAll<Call> was called on its null body, causing an assertion failure in the walker (assert(*currp) in wasm-traversal.h). Skip imported functions in the traversal since they have no body to walk.
kripken
reviewed
Feb 12, 2026
Member
kripken
left a comment
There was a problem hiding this comment.
Thanks, looks good aside from some test comments.
| @@ -0,0 +1,28 @@ | |||
| ;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited. | |||
| ;; RUN: wasm-opt %s --safe-heap --enable-threads --enable-simd -S -o - | filecheck %s | |||
Member
There was a problem hiding this comment.
Suggested change
| ;; RUN: wasm-opt %s --safe-heap --enable-threads --enable-simd -S -o - | filecheck %s | |
| ;; RUN: wasm-opt %s --safe-heap -S -o - | filecheck %s |
These features are not used in the testcase.
| (import "env" "some_import" (func $import)) | ||
| ;; CHECK: (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32))) | ||
| (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32))) | ||
| (memory 1 1 shared) |
Member
There was a problem hiding this comment.
Suggested change
| (memory 1 1 shared) | |
| (memory 1 1) |
No need for this to be shared.
| ;; CHECK: (import "env" "some_import" (func $import)) | ||
| (import "env" "some_import" (func $import)) | ||
| ;; CHECK: (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32))) | ||
| (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32))) |
Member
There was a problem hiding this comment.
Suggested change
| (import "env" "emscripten_get_sbrk_ptr" (func $emscripten_get_sbrk_ptr (result i32))) |
No need for this import.
| (call $import) | ||
| ) | ||
|
|
||
| (start $start) |
Member
There was a problem hiding this comment.
By convention we put this before the first function (around line 16, here)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
findCalledFunctionsin SafeHeap transitively walks all functions called from the start function to determine which functions should not be instrumented. When the start function calls an imported function, the import was added to the worklist and thenFindAll<Call>was called on its null body, causing an assertion failure in the walker:Reproducer:
Fix
Skip imported functions in the traversal since they have no body to walk.
Test plan
test/lit/passes/safe-heap-start-import.wastwith a start function that calls an import