Skip to content

[wasm] Port BlocksRuntime for no dlfcn.h platforms #4869

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

Conversation

kateinoigakukun
Copy link
Member

BlocksRuntime uses dlsym to find objc_destructInstance, which is not available on all platforms. This change adds a check for dlfcn.h and only uses dlsym if it is available and otherwise crashes the program.

The crash will not usually happen, as _Block_use_RR is only called from objc-auto, which is not available for such platforms.

@kateinoigakukun kateinoigakukun added the WASI WebAssembly System Interface-related changes label Feb 7, 2024
@MaxDesiatov
Copy link
Contributor

@swift-ci test

_Block_destructInstance = dlsym(RTLD_DEFAULT, "objc_destructInstance");
# else
assert(0 && "No way to find objc_destructInstance on this platform");
Copy link
Member

Choose a reason for hiding this comment

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

Can we just set _Block_destructInstance to NULL? IIRC, _Block_destructInstance(...) should do nothing if the pointer is NULL (this is how weak pointers work).

Copy link
Member Author

Choose a reason for hiding this comment

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

_Block_destructInstance can be called without null guard https://github.com/apple/swift-corelibs-foundation/blob/dbca8c7ddcfd19f7f6f6e1b60fd3ee3f748e263c/Sources/BlocksRuntime/runtime.c#L530, so _Block_destructInstance_default might be safer here

BlocksRuntime uses dlsym to find objc_destructInstance, which is not
available on all platforms. This change adds a check for dlfcn.h and
only uses dlsym if it is available and otherwise crashes the program.

The crash will not usually happen, as `_Block_use_RR` is only called
from objc-auto, which is not available for such platforms.
@kateinoigakukun kateinoigakukun force-pushed the pr-c22e31c72f24e4dfb622a01da59752a0bf3f863a branch from ad1dfe8 to 18d6a75 Compare February 7, 2024 18:43
Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me. Does this actually get used? We have too many copies of blocks runtime (compiler-rt, libdispatch, and Foundation). I believe on Windows at least, we use the libdispatch copy universally.

@kateinoigakukun
Copy link
Member Author

Thanks @compnerd! Right, this change needs to be also applied to those copies eventually.

@compnerd
Copy link
Member

compnerd commented Feb 7, 2024

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Feb 8, 2024

/Users/ec2-user/jenkins/workspace/swift-corelibs-foundation-PR-macOS/branch-main/swift-corelibs-foundation/CoreFoundation/PlugIn.subproj/CFBundle_Locale.c:151:70: error: initializer element is not a compile-time constant

This seems to suggest the CF code is not being compiled with the correct flags on Darwin.

@kateinoigakukun
Copy link
Member Author

kateinoigakukun commented Feb 8, 2024

@parkera Yes, would you mind checking if the upstream has already fixed it or not? #4866 (comment)

@compnerd
Copy link
Member

compnerd commented Feb 9, 2024

@kateinoigakukun I don't think that gas is being used (and it is unlikely to be cctools as as well). This is most likely using the LLVM IAS.

@kateinoigakukun
Copy link
Member Author

@compnerd Sorry, I don't understand why you mentioned assemblers here. Would you mind elaborating a little bit more?

@compnerd
Copy link
Member

compnerd commented Feb 9, 2024

Oh, I saw the old version of the comment where has was typoed as gas. Whoops, never mind me.

@kateinoigakukun
Copy link
Member Author

Ah, that's my bad, sorry for confusion 😓

@kateinoigakukun
Copy link
Member Author

@swift-ci test Windows platform

@kateinoigakukun kateinoigakukun merged commit 40496bb into swiftlang:main Feb 22, 2024
@kateinoigakukun kateinoigakukun deleted the pr-c22e31c72f24e4dfb622a01da59752a0bf3f863a branch February 22, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WASI WebAssembly System Interface-related changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants