-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add swiftcc attribute for runtime functions called from Swift #30938
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
Doesn't this break backwards compatibility on macOS? |
@compnerd As far as I know, C calling convention is compatible with swiftcc when not using swiftself or swifterror, so this doesn't break backward compatibility. |
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.
This absolutely breaks ABI compatibility even if you aren't using the special registers. Aside from using the special self and error registers, Swift functions have a higher threshold for number of return registers, and divide aggregates differently from the C calling convention. It is not generally safe to mix the Swift and C calling conventions. Why do you want to make this change?
It's interesting. Some swift code in standard library import runtime function by using In my understanding, all name only declared functions are considered as swiftcc in swift compiler. So, are these implementations generally unsafe currently? Instead of defining runtime function as swiftcc, Example: @_silgen_name("swift_retainCount") @convention(c)
public func _getRetainCount(_ Value: AnyObject) -> UInt |
Yes, it is a bug to use |
cc @dcci who added those For functions like |
3e8f958
to
5d3bbd3
Compare
Per our discussion in https://forums.swift.org/t/calling-convention-mismatch-violations-between-runtime-stdlib-and-emitted-code/51975, it seems that this could still proceed? Or is there anything else that needs to be addressed? |
@swift-ci please smoke test |
Requesting a review from @meg-gupta as an author of recent changes that caused some minor conflicts. |
@swift-ci please smoke test |
@swift-ci please smoke test macOS platform |
@kateinoigakukun could you have a look at the failing macOS test? That seems to persist after re-running CI |
This change marks all functions called using swiftcc as swiftcc attribute.
Resolves SR-15188.
On most of architectures, C calling convention functions can be invoked using swiftcc.
However on WebAssembly, swiftcc invocation strictly requires callee function is swiftcc to match the number of parameters with arguments.
Reference: https://reviews.llvm.org/D76049
cc: @jckarter
EDIT: 2020-04-13 1:37 JST
Sorry for not explaining enough.
I mean that the all functions I changed are called using swiftcc by binaries built with currently shipped compilers.
For example,
the code is represented in that LLVM IR
As well as this example, the caller of functions that are defined with
silgen_name
attribute are called using swiftcc.So I think we should define those functions with swiftcc attribute.
Especially on WebAssembly, these calling convention mismatches causes runtime error, so I want to correct the mismatches.