-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[CodeGen][ObjC] Initial WebAssembly Support for GNUstep #169043
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
Open
hmelder
wants to merge
4
commits into
llvm:main
Choose a base branch
from
hmelder:objc-wasm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+36
−5
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a07542b
[clang] Whitelist wasm when targeting GNUstep 2.x
hmelder 0ee0356
[CodeGen][ObjC] Mangle public symbols for wasm
hmelder 45e7f44
[CodeGen][ObjC] Fix class_registerAlias_np signature
hmelder 8ad5d24
[CodeGen][ObjC] Add WASM symbol mangling test
hmelder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // RUN: %clang_cc1 -triple wasm32-unknown-emscripten -emit-llvm -fobjc-runtime=gnustep-2.2 -o - %s | FileCheck %s | ||
|
|
||
| @class NSString; | ||
|
|
||
| @protocol AProtocol | ||
| - (void) meth; | ||
| @end | ||
|
|
||
| @interface AClass <AProtocol> | ||
| @end | ||
|
|
||
| @implementation AClass | ||
| - (void) meth {} | ||
| @end | ||
|
|
||
| // Make sure that all public symbols are mangled correctly. All exported symbols | ||
| // must be valid Javascript identifiers in Emscripten. | ||
| // CHECK: $"$_OBJC_PROTOCOL_AProtocol" = comdat any | ||
| // CHECK: @"$_OBJC_METACLASS_AClass" | ||
| // CHECK: @"$_OBJC_PROTOCOL_AProtocol" | ||
| // CHECK: @"$_OBJC_CLASS_AClass" | ||
| // CHECK: @"$_OBJC_REF_CLASS_AClass" | ||
| // CHECK: @"$_OBJC_INIT_CLASS_AClass" |
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The restriction on valid JS identifiers is specific to Emscripten rather than wasm as a whole, so you might want to check for
isOSEmscriptenhere rather than the bin format. But if you want to have a common ABI across Emscripten and WASI, then this would be OK with me too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should maybe fix emscripten to deal with these symbols instead of patching here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense. we could just do a similar prefix or substitution as the one here? If the export name is invalid, we could just mangle the symbol on the
Moduleobject? Or have an alias soModule[".realSymbol"]could keep working?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can do that. But remember that symbols are also available directly in the module scope as normal variables.
e.g. One can just write
_mallocfor symbols that are not exported on theModule. For exported symbols one can also writeModule['_malloc']. So this change would just mean that symbol are that not valid JS symbol names would not be accessible via the first method... which is an odd difference but maybe better than "link failure" ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, better than link failure I think. And given that the map style accessors aren't going away, maybe it's sufficient to just leave it at that. where if you have invalid identifiers, you just need to use that method (as opposed to trying to mangle them and change the symbol name altogether?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll look into fixing this now on the emscripten side. We have an open bug there already: emscripten-core/emscripten#24825
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hmelder / @HendrikHuebner Would Sam's Emscripten change be useful for the objc use case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does not really matter whether we use
$or.and I would prefer to not add more complexity into the conditional.We mangle the symbols so that they are not directly usable by the user in a C program, or at least this was the original intend with
.on ELF. AFAIK there is an extension that allows$to be used in a C identifier which is why Emscripten supports it in the first place.You can change this in Emscripten but it does not really matter for our use case.