Skip to content
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

fix dynamic linking int64 exceptions #21759

Merged
merged 12 commits into from Apr 20, 2024
Merged

Conversation

joemarshall
Copy link
Contributor

Currently if you dynamic link to something, and throw an exception in a function which returns int64, a javascript exception is thrown.

This is the same bug that was fixed in #15974 but in this case the dynamic linker is creating the invoke functions in javascript, rather than it being created in advance.

Fixes #21758

@joemarshall
Copy link
Contributor Author

@sbc100 If you look at the code for this, I added a one line check on exceptions thrown, as opposed to adding two function generators, one for bigint return and one for normal, as I think code size is a priority here right? I don't think there's a massive overhead given it is only in the exception thrown case anyway.

Other than that, I think this is pretty uncontroversial; it would be good to get it in soon if possible; I'll submit a patch to it in pyodide until it's in.

src/library_dylink.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be great to add a test for this. Ideally we would figure out which test already covers this case and extend it.

@joemarshall
Copy link
Contributor Author

@sbc100 I added a test for this - it was quite fiddly to force the invoke call to happen, but the test fails before the fix and works after now..

Copy link
Collaborator

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting in the effort to make that test case. It looks like it it is indeed quite hard to reproduce!

I was wondering if there are any existing test that test this feature explictly.. I'll see if I can find one.

test/test_core.py Outdated Show resolved Hide resolved
test/test_core.py Outdated Show resolved Hide resolved
test/test_core.py Outdated Show resolved Hide resolved
test/test_core.py Outdated Show resolved Hide resolved
hoodmane pushed a commit to pyodide/pyodide that referenced this pull request Apr 17, 2024
This is a backport of emscripten-core/emscripten#21759 

It fixes a crash which happens when 
1) An exception is thrown inside a function returning int64
2) The function is in a dynamic library and has been called through dynamic invocation.
@sbc100
Copy link
Collaborator

sbc100 commented Apr 17, 2024

It looks like we do have some existing tests for this part of the code:

coer0.test_dylink_i64_invoke
coer0.test_dylink_i64_invoke_bigint
coer0.test_dylink_raii_exceptions
coer0.test_pthread_dylink_exceptions

other.test_main_module_without_exceptions_message
other.test_metadce_hello_dylink

At least these are the tests that fail when I disable the createInvokeFunction stuff.

I wonder if we can extend/update these tests to cover this corner case? (I think test_dylink_i64_invoke looks like the one)

@joemarshall
Copy link
Contributor Author

Ha ha, you were right. Now I know how to trigger it, it took 3 line changes to that existing test.

@joemarshall
Copy link
Contributor Author

Incidentally, it appears empty throw statements don't always work in emscripten. I don't think that is necessarily a bad thing, as who does that... but it may be an inconsistency from standard C++ behaviour and thus another bug?

@joemarshall
Copy link
Contributor Author

@sbc100 I updated this to main again, can we merge it now?

@sbc100 sbc100 enabled auto-merge (squash) April 20, 2024 21:52
@sbc100 sbc100 merged commit 7d95a47 into emscripten-core:main Apr 20, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Int64 return functions with dynamic linking crashes on exception
2 participants