-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add a library mode for type hierarchy marking #2114
Conversation
test/Mono.Linker.Tests.Cases/Reflection/ObjectGetTypeLibraryMode.cs
Outdated
Show resolved
Hide resolved
test/Mono.Linker.Tests.Cases/Reflection/ObjectGetTypeLibraryMode.cs
Outdated
Show resolved
Hide resolved
src/linker/Linker.Dataflow/DynamicallyAccessedMembersTypeHierarchy.cs
Outdated
Show resolved
Hide resolved
We can't take this as is based on the discussion in dotnet/runtime#54859. For those we want to take this change. I think we'll have to make a "hack" and intentionally ignore the DAM on |
Unfortunately, internal custom Will move the special casing of |
What about the other use cases for type hierarchy marking - without the proper fix for library mode, it's bound to break (either now, or soon). |
Unfortunately, rebasing caused some changes that are not part of this fix to be displayed |
f9e0765
to
1f500bc
Compare
1f500bc
to
648c3b1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - please validate the impact on runtime repo before merging (running the runtime repo build with the new linker should basically make no difference)
Co-authored-by: Vitek Karas <vitek.karas@microsoft.com>
src/linker/Linker.Dataflow/DynamicallyAccessedMembersTypeHierarchy.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last nit, otherwise LGTM. Thank you!
src/linker/Linker.Dataflow/DynamicallyAccessedMembersTypeHierarchy.cs
Outdated
Show resolved
Hide resolved
* Fix special handling of EventSource FB * special case EventSource handling to library mode * test fixes * Update src/linker/Linker/LinkContext.cs Co-authored-by: Vitek Karas <vitek.karas@microsoft.com> * FB * FB Co-authored-by: Vitek Karas <vitek.karas@microsoft.com> Commit migrated from dotnet/linker@e1c0c83
We added type hierarchy support to the linker via #1929 but the annotations to the derived types were only triggered via
object.GetType()
in code. This causes problems in library mode linking, especially for internal types when the assembly does not have code that triggersobject.GetType()
. Library mode linking can remove members in such cases which might be needed later by application code that invokes the removed internal code via reflection. A specific example is an internal type like NetEventSource inSystem.Net.Mail.dll
library, where the library does not have code that triggersobject.GetType()
. Library mode linking removes nested types in such cases and application code patterns like this will fail in such cases.Unfortunately, we cannot yet remove the special case handling that we currently have for
EventSource
in the trimmer with this change as discussed in #1949. This is because some library code relies in the trimmer to remove unused code in customEventSources
and that goal conflicts with this change since this change will keep all code in customEventSources
. There is a runtime issue 54859 that tracks this. This change moves the EventSource special handling to library modeCodeOptimizations
,OptimizeTypeHierarchyAnnotations
, that will be disabled in library mode linking. Disabling the optimization will cause types to be marked whenobject.GetType()
is not seen and the type is used.-
EventSource
types will not be impacted due to the size concerns expressed aboveDisableEventSourceSpecialHandling
in library mode.- Type hierarchy annotation in
EventSource
types will not be triggered withoutobject.GetType()
- Also removed the special handling of the
EventDataAttribute
atMarkTypeSpecialCustomAttributes
in this mode sinceEventSource
type has annotations to keep all methods.- We are keeping the special handling of EventSource for earlier runtimes than .NET6.
EventSource