-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow DynamicDependencyAttribute on Class and Struct #37352
Comments
I'd proposed this as well here: |
Is there any way we can also allow it on interfaces? That would help for interop scenarios when trying to project COM or WinRT interfaces to generated C#. C#/WinRT for example could use this to create more reliably linkable code even for interop scenarios without necessarily needing a tool to post-process the application to discover and hard-code the supported interop types. |
Would adding support on interfaces help for more scenarios than COM? See #36659 for more plans on how to support or trim COM. |
The COM support I mention would be more for out-of-band COM support. One example would be for an implementation of |
@jkoritzinsky Can you shed more light into the COM/WinRT support you are hoping to enable with this? Replacing
For the |
@MichalStrehovsky I think based on what you've said, the meaning of |
Can we do this by adding a static method which gets called from all of the .ctors (nothing in it, so JIT will effectively remove it) and put the attribute on that one? From linkers point of view it should have the same effect as if it was on all the constructors. |
I'd much rather we didn't. If we have to start playing such tricks to work around deficiencies in tools, we should instead fix the deficiencies in the tools. And these are sensitive code paths; the JIT should remove such a method when optimizations are enabled, but adding such additional code to such paths makes me nervous. |
I didn't list all the places that were needed, but another one is runtime/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml Lines 19 to 23 in 13fbbee
and runtime/src/coreclr/src/System.Private.CoreLib/ILLinkTrim.xml Lines 28 to 40 in 13fbbee
|
The struct case is the strongest motivation for me for this to be added |
For the |
Closing, as we are going to enable this scenario by using an XML descriptor + feature swtich. See dotnet/linker#1268 (comment) for discussion. |
Background and Motivation
There are some "global" dynamic dependencies that can't be identified by managed IL methods, constructors, or fields. For example, some members on core types, like
Task
,ThreadPool
, etc, are only necessary for debuggers to call. They are not called by any code in our libraries nor are they public. In order for the ILLinker to preserve these private members, we need to mark them with a[DynamicDependency]
, but the issue is there isn't a good place to put the attribute, since there are no callsites.So instead, we need to place the
[DynamicDependency]
on the class/struct itself, meaning "if this type is preserved at all, then also preserve this member".See the discussion here: #37288 (comment)
Proposed API
Usage Examples
Alternative Designs
Risks
We initially didn't want to allow
[DynamicDependency]
on a type itself because we were concerned that users could make a mistake, and too many members will be kept unnecessarily.cc @vitek-karas @MichalStrehovsky @marek-safar @joperezr @layomia
The text was updated successfully, but these errors were encountered: