Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

RyuJit doesn't support inlining P/Invokes whose return type is a struct #2144

Closed
nattress opened this issue Nov 5, 2016 · 5 comments
Closed
Labels
Milestone

Comments

@nattress
Copy link
Contributor

nattress commented Nov 5, 2016

In importer.cpp, Compiler::impCanPInvokeInlineCallSite excludes P/Invokes from being emitted inline if they return a struct. This prevents CoreRT from compiling invoke stubs. The actual external method call ends up as a managed direct call instead.

See, ie: System.Console!mincore.GetLargestConsoleWindowSize

@nattress nattress added this to the March 2017 milestone Nov 5, 2016
@jkotas
Copy link
Member

jkotas commented Nov 5, 2016

We need to get onto the compMustInlinePInvokeCalli path for CoreRT.

@nattress
Copy link
Contributor Author

nattress commented Nov 5, 2016

We can force that in JIT startup by setting CorJitFlag.CORJIT_FLG_IL_STUB for p/invokes. That only works for Calli though. We maybe need something CoreRT-specific in that area of the importer to allow it for direct calls.

@jkotas
Copy link
Member

jkotas commented Nov 5, 2016

We maybe need something CoreRT-specific

Agree. CorJitFlag.CORJIT_FLG_IL_STUB flag flips number of different things ... not sure whether we want all of them ... .

@christianscheuer
Copy link
Contributor

Is there a workaround for this, to prevent the inlining from taking place? [MethodImpl(MethodImplOptions.NoInlining)] doesn't help unfortunately.

@jkotas
Copy link
Member

jkotas commented Dec 2, 2016

The proper fix should be like a five line change in RyuJIT. I will try to do it in a next several days.

There is a related problem (#158) that causes structs on Unix to not be always passed in registers according to the platform calling convention. If you have PInvokes that return structs, you are likely to hit that one too.

jkotas added a commit that referenced this issue Dec 7, 2016
The most recent RyuJIT has this issue fixed.
@jkotas jkotas closed this as completed Dec 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants