IRGen: setup foreign calls properly#42157
Open
compnerd wants to merge 1 commit intoswiftlang:mainfrom
Open
Conversation
Member
Author
Member
Author
|
@swift-ci please test |
We would previously drop all calling convention information for foreign calls on the floor when arranging a function call. This could (would in the case of many Windows i686 system calls) construct invalid function calls. We would simply mark everything as being cdecl rather than the effective calling convention of the function call. In the case of windows i686, this is problematic as many functions are callee cleanup with pass by stack, aka, `__stdcall`. We would as a result of the missing information pass arguments incorrectly, or in the worst case (like on Windows i686), corrupt the stack. The heart of this change is that when arranging the function call, if we are calling a foreign function, we should consult clang for the extended information for the call. Given that SIL does not preserve this information, we need to go back to the original foreign function declaration and query the information. This declaration is only available significantly earlier in the call stack. The newly introduced parameters are to help identify potential gaps where we may be leaking a calling convention attribute on the foreign call. However, the current state is sufficient to enable loading Foundation on Windows i686 which uses a number of foreign calls with different conventions.
f723282 to
ddadb47
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We would previously drop all calling convention information for foreign
calls on the floor when arranging a function call. This could (would in
the case of many Windows i686 system calls) construct invalid function
calls. We would simply mark everything as being cdecl rather than the
effective calling convention of the function call. In the case of
windows i686, this is problematic as many functions are callee cleanup
with pass by stack, aka,
__stdcall. We would as a result of themissing information pass arguments incorrectly, or in the worst case
(like on Windows i686), corrupt the stack.
The heart of this change is that when arranging the function call, if we
are calling a foreign function, we should consult clang for the extended
information for the call. Given that SIL does not preserve this
information, we need to go back to the original foreign function
declaration and query the information. This declaration is only
available significantly earlier in the call stack. The newly introduced
parameters are to help identify potential gaps where we may be leaking a
calling convention attribute on the foreign call. However, the current
state is sufficient to enable loading Foundation on Windows i686 which
uses a number of foreign calls with different conventions.
Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.
Resolves SR-NNNN.