Skip to content

Cast IMPs to the correct signature before calling - #418

Merged
davidchisnall merged 1 commit into
gnustep:masterfrom
HendrikHuebner:wasm-imp-signatures
Oct 18, 2026
Merged

davidchisnall merged 1 commit into
gnustep:masterfrom
HendrikHuebner:wasm-imp-signatures

Conversation

@HendrikHuebner

Copy link
Copy Markdown
Contributor

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.

Comment thread arc.mm Outdated
Comment thread arc.mm Outdated
Comment on lines +572 to +574
NewAutoreleasePool = reinterpret_cast<NewAutoreleasePoolIMP>(
class_getMethodImplementation(object_getClass(AutoreleasePool),
SELECTOR(new)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we consolidate the casts with something like:

auto storeSelector = [](auto &target, IMP imp)
    {
         target = reinterpret_cast<std::remove_reference_t<decltype(target)>>(imp);
    };

Comment thread runtime.c
// `.cxx_destruct` method may deallocate the class.
Class currentClass = cls;
cls = cls->super_class;
if (currentClass->cxx_destruct)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should probably change the type of these from IMP and do the cast when we set them.

@HendrikHuebner

Copy link
Copy Markdown
Contributor Author

updated

@davidchisnall

Copy link
Copy Markdown
Member

Please can you squash for merging?

@HendrikHuebner

Copy link
Copy Markdown
Contributor Author

Done. I don't think I have permissions to merge PRs myself.

@HendrikHuebner

Copy link
Copy Markdown
Contributor Author

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. @finally is gonna land on the LLVM side once their CI stops failing spuriously.

@HendrikHuebner

Copy link
Copy Markdown
Contributor Author

@hmelder You asked me for progress on the @finally handling a few weeks ago - are you taking over some of the WASM work?

@hmelder

hmelder commented Oct 17, 2026

Copy link
Copy Markdown
Member

are you taking over some of the WASM work?

Yeah, what is the current state?

@davidchisnall
davidchisnall merged commit 0faf694 into gnustep:master Oct 18, 2026
91 checks passed
@HendrikHuebner

Copy link
Copy Markdown
Contributor Author

@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.

@hmelder

hmelder commented Oct 18, 2026

Copy link
Copy Markdown
Member

Thanks for the update. I'll try to look into this in the last week of October.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants