-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Fix stack arguments passing via reflection. #46456
Comments
Does it have impact on GC stack walking ( |
Yes, it goes down to In the prototype, my idea was to return the correct result from |
I would go with the option #2. I would make the signature of StackElemSize the same for all platforms and just ignore the argument for non-osx arm64. |
I will fix the prototype according to @janvorli review and publish a PR after the NY. |
@sandreenko I think this can be closed now, right? |
I think it is still not working for crossgen2, like Line 72 in ec3f9fa
returns 8 when it should be something like
but I am not sure if we ever crossgen2 any reflection code and if we don't we can ignore this issue for 6.0. |
Reflection invocation and the related argument passing is handled purely in the native runtime for both jitted and crossgened code. |
Not really, according to my knowledge the transition block algorithms are only used for generating GC refmap information for method import cells. For @sandreenko's comment, I'm not really sure what "crossgen2[-ing] any reflection code" alludes to, we certainly do Crossgen2-compile reflection-related library code and arbitrary code that may be called via reflection. |
Hmm, so if this code doesn't fully match its native counterpart for the Apple Silicon case, we could possibly generate wrong GC refmap. Maybe that could possibly explain the weird null reference exceptions we are hunting. cc: @mangod9, @davidwrighton |
Do you say that if we have a method like
and we call crossgen2 compiler for it it will compile it into native? |
Both for the jitted and crossgened case, it will call a runtime native helper that performs the invocation. |
See RuntimeMethodHandle::InvokeMethod in src/coreclr/vm/reflectioninvocation.cpp |
For Sergey's comment, the call to |
Of course! |
we should check whether this case is hit within crossgen2 compilation of tests which are intermittently failing. Dont think cg2 itself has any reflection based invocations does it? |
It can affect any code, the impact is not limited to reflection. |
This is an interesting point. On the one hand, I'm not aware of any place in Crossgen2 source code explicitly calling the Invoke method; on the other hand, Crossgen2-compiled Crossgen2 certainly does emit GC refmap info for various callees so a discrepancy between CG2 and runtime would still apply. Having said that, I think that CoreCLR testing doesn't actually use CG2-compiled Crossgen2, that gets only produced by the installer build for the purpose of publishing the Crossgen2 nuget package, it's not used for internal testing within the runtime repo (at least not in the coreclr partition). According to my recollection we shouldn't be running it on top of live-built (and CG2-compiled) framework exactly because that used to transform various CG2 bugs in its compilation into subsequent weird compile-time crashes but I'm not 100% sure whether the OSX arm64 build conforms to the same scheme, it could be special-cased to some extent. |
It uses CG2-compiler CoreLib and the framework, right? The crashes can be triggered by GC tracking problems introduced in the framework. |
It seems that the test failures that I am seeing streaming in regularly are most if not all with running coreclr tests crossgened with crossgen2. |
This change should disable R2R on Linux / OSX, Windows section should be below in the same file. |
yeah only wanted to check whether disabling R2R helps resolve NRE on OSX, doesn't appear to have helped. |
(Which is probably sufficient as you're interested in OSX arm64.) Your findings confirm my suspicion that it's not a R2R bug, it's a runtime bug (somewhere between VM / JIT / GC). |
Aren't the tests in CG2 legs using runtime crossgened by CG2 too? The change @mangod9 made is just for the test binaries. |
I think the point is that we most often see the NRE in the CG2 compilation itself and the CG2 compiler as such is not crossgenned. Having said that, I'm not sure what runtime it runs on - normally it should be run using a LKG version of the dotnet command, not by the "live" one, but I'm not sure if it's not special cased on OSX arm64 as it's a new platform. If it does use the live-built dotnet on OSX arm64, it would be still susceptible to potential CG2 compilation bugs of S.P.C and the framework, disabling those would require patching two more places in the build scripts. |
I think it uses the LKG runtime from the .dotnet folder. But doesn't that have runtime assemblies crossgened by crossgen2? I mean, when the SDK is published? |
That is true (assuming it's a sufficiently new dotnet) but COMPlus_ReadyToRun=0 should block that out too and I believe that's what Manish did in his instrumented PR. |
Closing as this work is done. The only remaining related work is to create matching changes in the managed clone of the ArgIterator and TransitionBlock in CG2. |
This is the last item from #41130. I have extracted it into a separate issue for a cleaner discussion.
Such a method when called via reflection is getting stack arguments with wrong offsets:
public int TestSmallStackArgsMethod(short s1, short s2, short s3, short s4, short s5, short s6, short s7, short s8, short s9, short s10, short s11, short s12)
This minimal test:
sandreenko@678ce4b
because VM logic that moves "Invoke" arguments from the array to the slots does not know about apple specific alignment. Actually, VM operates in "stack slot" terms that do not exist there.
I see two options here:
the first is cheap, the second could still be preferable if any other components depend on them (like if we want varags or debugger needs proper sizes/offsets somehow)
What do you think @sdmaclea , @janvorli , @davidwrighton?
The text was updated successfully, but these errors were encountered: