Skip to content

IRGen: setup foreign calls properly#42157

Open
compnerd wants to merge 1 commit intoswiftlang:mainfrom
compnerd:foreign-affairs
Open

IRGen: setup foreign calls properly#42157
compnerd wants to merge 1 commit intoswiftlang:mainfrom
compnerd:foreign-affairs

Conversation

@compnerd
Copy link
Copy Markdown
Member

@compnerd compnerd commented Apr 3, 2022

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.

Replace this paragraph with a description of your changes and rationale. Provide links to external references/discussions if appropriate.

Resolves SR-NNNN.

@compnerd
Copy link
Copy Markdown
Member Author

compnerd commented Apr 3, 2022

CC: @aschwaighofer @rjmccall

@compnerd
Copy link
Copy Markdown
Member Author

compnerd commented Apr 3, 2022

@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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant