Repository navigation
Cast IMPs to the correct signature before calling - #418
Conversation
| NewAutoreleasePool = reinterpret_cast<NewAutoreleasePoolIMP>( | ||
| class_getMethodImplementation(object_getClass(AutoreleasePool), | ||
| SELECTOR(new))); |
There was a problem hiding this comment.
Can we consolidate the casts with something like:
auto storeSelector = [](auto &target, IMP imp)
{
target = reinterpret_cast<std::remove_reference_t<decltype(target)>>(imp);
};| // `.cxx_destruct` method may deallocate the class. | ||
| Class currentClass = cls; | ||
| cls = cls->super_class; | ||
| if (currentClass->cxx_destruct) |
There was a problem hiding this comment.
We should probably change the type of these from IMP and do the cast when we set them.
|
updated |
|
Please can you squash for merging? |
3a1c6c5 to
e5455f2
Compare
|
Done. I don't think I have permissions to merge PRs myself. |
e5455f2 to
90a06b5
Compare
|
Hi @davidchisnall this was squashed btw. I've been inactive for a while because I moved and started a new job but I'd stlll like to make some more progress on the WASM support. |
|
@hmelder You asked me for progress on the |
Yeah, what is the current state? |
90a06b5 to
317d5de
Compare
|
@hmelder For the runtime, I have two more open PRs I'd like to merge (#417, #420). On the Clang side everything has landed. For the runtime we're mainly a WASM tests build target for coverage and a CI job. Some tests need fixing because they relied on the non-portable function pointer calls and I didn't run all the exception handling tests. Block-to-IMP support is also missing ofc. I think I also ended up merging all my libs-base / Emscripten compatibility fixes. For Emscripten's "dynamic linking" of Objective-C binaries there is still a blocker related to non-JS identifier exports. |
|
Thanks for the update. I'll try to look into this in the last week of October. |
This PR ensures we do not call any raw IMP function pointers without casting them to the correct type first.
Calling a funtion pointer with a mismatching signature is technically UB I believe but tends to work just fine on many native platforms.
With WebAssembly, this is a problem however, because WASM indirect calls require an exact signature match. This can cause runtime failures.