-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add the ability to remove COM support using ILLinker #43501
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -51,4 +51,29 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</assembly> | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
<!-- COM specific attributes --> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<assembly fullname="System.Private.CoreLib" feature="System.Runtime.InteropServices.Marshal.IsComSupported" featurevalue="false"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.ClassInterfaceAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.CoClassAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is stripping these attributes buying us anything? If user chooses to turn off COM, but they still have a bunch of COM classes that are kept, wouldn't it be better if they get useful feedback about it? Stripping these attributes results in obnoxious failure modes like "System.Security.SecurityException: 'ECall methods must be packaged into a system module.'". (That's the exception you get if you try to new up a class like this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It saves some size but it also correctness fix for us that we don't have a dependency on these attribute which is not guarded under COM feature.
They have no meaning for example for MonoVM. Can CoreCLR throw a better error when the runtime starts in COM disabled mode? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to keep these so that output can be inspected for these? I assume if we have a class marked with
The runtime doesn't know this was a COM class if linker strips all signs of it. It's just a class with an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't follow. You apply CoClassAttribute to an interface which type argument of the implementation class. By removing the attribute from the interface you remove the class if there are no further references.
It could, this is standard opt-in feature switch so when someone disables it on Windows you will have the information written in *.runtimeconfig.json /cc @vitek-karas There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Okay, let's say I referred to/commented on the ComImportAttribute a couple lines below. I didn't have my second coffee yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we'll have to leave the MTA/STA alone - those have effect outside of COM support - and even if the app itself doesn't use COM, it still may need to set STA for other Windows stuff to work correctly. |
||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.ComDefaultInterfaceAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.ComImportAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.ComVisibleAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.GuidAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to strip this one, we should make sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, that should be doable There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was looking at the implementation and it returns empty GUID in this case. I guess that's better than to throw. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that what Mono returns when there's no GuidAttribute? The runtime is supposed to compute a GUID using some weird algorithm from name, I think (it does so on CoreCLR). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw the docs for Type.GUID don't mention COM anywhere so this might come as a surprise to some users. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, Mono return empty GUID. Checking the CoreCLR implementation runtime/src/coreclr/src/vm/reflectioninvocation.cpp Lines 2148 to 2171 in 0a69f02
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case we need to make it so that the behavior is the same without linker in the picture. So this change would need to incorporate change to CoreCLR which looks at the runtime property and ignores the attribute in that case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would leave the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about this more, I would be fine removing the My reasoning here is that mono is the canonical runtime implementation with no COM support. This means it should be considered the source of truth semantically speaking. Making this change would also help to validate the assumption that the |
||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<type fullname="System.Runtime.InteropServices.ProgIdAttribute"> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<attribute internal="RemoveAttributeInstances" /> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</type> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</assembly> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</linker> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,13 @@ | |
<field name="s_asyncDebuggingEnabled" value="false" initialize="false" /> | ||
</type> | ||
</assembly> | ||
<assembly fullname="System.Private.CoreLib" feature="System.Runtime.InteropServices.Marshal.IsComSupported" featurevalue="false"> | ||
<type fullname="System.Type" > | ||
<method signature="System.Boolean get_IsCOMObject()" body="stub" value="false" /> | ||
</type> | ||
<type fullname="System.Runtime.InteropServices.Marshal"> | ||
<method signature="System.Boolean IsComObject(System.Object)" body="stub" value="false" /> | ||
<method signature="System.Boolean IsTypeVisibleFromCom(System.Type)" body="stub" value="false" /> | ||
</type> | ||
</assembly> | ||
Comment on lines
+22
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The feature switch should only substitute the IsComSupported property. |
||
</linker> |
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.
This needs to read the runtime property to correctly react to the feature switch.