-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Attribute to tag methods that implicitly depend on its caller #41690
Comments
DynamicSecurityMethod attribute was used for Code Access Security originally. CoreCLR reused it as an internal implementation detail for a different purpose that has nothing to do with security. If we were to make it a public concept, I think we should give it a new name that captures the intent properly. |
There may be alternative designs possible: Add |
@jkotas, I think you misunderstand my proposal here. This is not about making it available to the general public, nor to change its meaning. It's about an inconsistency in the attribute not being present in the reference assemblies of dotnet, while the implementation assembly does carry it. This pseudocustom attribute is emitted as a reserved method flag. While it was originally used for security, it has also been applied to BCL methods that require an intact stack, and therefore cannot, and should not be cross module optimized. The absence of this flag in the reference assembly, as noted by @dsyme, leads to incorrect compiled IL by compilers that do compile time inlining like F#. In short, I think all method flags in the reference assembly of runtime .NET Core libraries should be equal to the flags in the implementation assembly. |
@jkotas, just to emphasize: this is not an api-suggestion, but a bug, or oversight in the current Base Class Libraries. I can see two ways to fix this:
Example:Take
While the implementation assembly has:
Note the difference in the signature, the first misses the -.method public hidebysig static class System.Reflection.Assembly
+.method public hidebysig reqsecobj static class System.Reflection.Assembly |
We have number of other attributes that are present in the implementation assemblies, but that are not present in reference assemblies.
The |
@abelbraaksma I agree with @jkotas - this is really an internal implementation flag.
This is a good suggestion |
Aha, gotcha. But this one is currently present internally(but compiled as method flag, not attribute), and since this is a reserved method attribute, we don't need to add the attribute itself to a method in the reference assembly, but only the runtime/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/Assembly.CoreCLR.cs Lines 68 to 73 in 6072e4d
I wasn't aware. But now I see that |
@dsyme, I'm not sure I follow, how would that help the current situation? If it does, that would be great, of course. |
It wouldn't, AFAIU it would be a new API in .NET For F# we still need to do something about knowing what methods should not be inlined |
Possibly relevant to this discussion is how CoreCLR currently fixed this for crossgen: dotnet/coreclr#27050. The issue for source-code inlining is similar, except that we don't have the same info as the CLR during compiling (as noted in the discussion above). This is not only about inlining, but also about tail-calling when done during the compile phase (vs the JIT phase). |
I have created formal API proposal https://github.com/dotnet/runtime/issues/56601 |
Description
The reference assemblies typically expose the same meta-info as implementation assemblies, but
DynamicSecurityMethod
, orreqsecobj
is not exposed and only visible in the implementation assembly.As an example, check
GetCallingAssembly
orGetExecutingAssembly
.Is this a deliberate limitation of the reference assemblies? It appears to me that this information should be present and the 70 or so BCL methods (see #11698 (comment), but probably less now after dotnet/coreclr#21825) that have
reqsecobj
should also setDynamicSecurityMethod
in their reference assemblies.If there is no backwards compat issue or other requirement that prevents inclusion of
reqsecobj
in the signatures, I propose we add it, so that compilers can rely on these signatures to be accurate.Other information
This information is relevant for compilers, like here in F# (dotnet/fsharp#9283 (comment)), where we should not inline
GetExecutingAssembly
, but since the compiler uses the reference assemblies as a guide, it cannot properly make that decision.Note that this is an inlining decision at compile time, irrelevant on the inlining decision of the JIT, which doesn't have this problem as it'll see the implementation assembly.
A workaround was proposed by @dsyme (see dotnet/fsharp#9283 (comment)) to hard-code the BCL methods that have
reqsecobj
and/orStackCrawlMark
so thatThe text was updated successfully, but these errors were encountered: