Merged
Conversation
yuri91
requested changes
Jun 23, 2025
| if (DtorFunc->isNullValue()) | ||
| break; // Found a null terminator, skip the rest. | ||
|
|
||
| // We do not add global destructors that are genericjs. |
Member
There was a problem hiding this comment.
Investigate if it is possible to inherit from the pass, or use it from another pass, instead of editing its source directly.
Don't spend too much time on it though, if it seems difficult
This is no longer necessary, as placing these in the start function during CallConstructors ensures they are reachable, and thus GDA will not remove them.
3a1caa1 to
ef5ed32
Compare
This caused a crash in asan with the current state of constructors and destructors. Originally, it's meant to be a thread_local with a constructor that runs lazily on first use. Currently in cheerp, thread_local constructors are not supported. Removing the initializer is safe because the struct is only ever used as a global, and it's initialized to zero by default. This was not a problem before, because the constructor was never run. Since it initialized to zero it had no effect. With the work on global destructors however, there is now a reason to run this constructor.
Previously this was unused, but now with global destructors this can be called.
This commit enables global destructors to run after main. Destructors that are in genericjs are not run. The new wrapper pass is run to lower functions with the destructor attribute into calls to __cxa_atexit. If the libc exit function is not reachable from the code, the destructors are removed. Finally, exit is now called automatically after the main function has finished running in WASI mode, or when -pthread is passed.
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.
Run global destructors when exit is called. Exit is now automatically called after main in WASI mode, and when -pthread is passed.