Skip to content

Commit

Permalink
Strip the ILLinkTrim.xml file from System.Private.Xml (#35547)
Browse files Browse the repository at this point in the history
* Strip the ILLinkTrim.xml file from System.Private.Xml

The two methods being preserved in System.Private.Xml (CreateSqlReader and GenerateSerializer) are large, and are not necessary when linking a mobile app. These methods only need to be preserved when linking the shared framework. When a normal app is linked, the linker is able to figure out if the two methods are necessary.

Contributes to #35199

Fix #30912

* Respond to PR feedback

- Add PreserveDependencyAttribute to SqlXml to be explicit.
- Rename ILLinkTrim.xml to ILLinkTrim_LibraryBuild.xml when it shouldn't be embedded in the resulting assembly.
  • Loading branch information
eerhardt authored May 1, 2020
1 parent 6b2f3b5 commit c614097
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion eng/illink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<ILLinkTrimOutputPath>$(IntermediateOutputPath)</ILLinkTrimOutputPath>

<ILLinkTrimXml Condition="'$(ILLinkTrimXml)' == '' and Exists('$(MSBuildProjectDirectory)/ILLinkTrim.xml')">$(MSBuildProjectDirectory)/ILLinkTrim.xml</ILLinkTrimXml>
<!-- ILLinkTrim_LibraryBuild.xml files are only used during building the library, not an app. They shouldn't be embedded into the assembly. -->
<ILLinkTrimXmlLibraryBuild Condition="'$(ILLinkTrimXmlLibraryBuild)' == '' and Exists('$(MSBuildProjectDirectory)/ILLinkTrim_LibraryBuild.xml')">$(MSBuildProjectDirectory)/ILLinkTrim_LibraryBuild.xml</ILLinkTrimXmlLibraryBuild>

<!-- if building a PDB, tell illink to rewrite the symbols file -->
<ILLinkRewritePDBs Condition="'$(ILLinkRewritePDBs)' == '' and '$(DebugSymbols)' != 'false'">true</ILLinkRewritePDBs>
Expand All @@ -40,6 +42,10 @@
</EmbeddedResource>
</ItemGroup>

<ItemGroup Condition="'$(ILLinkTrimXmlLibraryBuild)' != ''">
<None Include="$(ILLinkTrimXmlLibraryBuild)" />
</ItemGroup>

<!-- Custom binplacing for pre/post-trimming and reports that is useful for analysis
Must be enabled by setting BinPlaceILLinkTrimAssembly=true
-->
Expand Down Expand Up @@ -87,7 +93,9 @@
<!-- keep types and members required by Debugger-related attributes -->
<ILLinkArgs>$(ILLinkArgs) -v true</ILLinkArgs>
<!-- don't remove the embedded root xml resource since ILLink may run again on the assembly -->
<ILLinkArgs>$(ILLinkArgs) --strip-descriptors false</ILLinkArgs>
<ILLinkArgs Condition="'$(ILLinkTrimXml)' != ''">$(ILLinkArgs) --strip-descriptors false</ILLinkArgs>
<!-- pass the non-embedded root xml file on the command line -->
<ILLinkArgs Condition="'$(ILLinkTrimXmlLibraryBuild)' != ''">$(ILLinkArgs) -x "$(ILLinkTrimXmlLibraryBuild)"</ILLinkArgs>
<!-- ignore unresolved references -->
<ILLinkArgs>$(ILLinkArgs) --skip-unresolved true</ILLinkArgs>
<!-- keep interface implementations -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@
<Compile Include="System\Data\SQLTypes\SQLBytes.cs" />
<Compile Include="System\Data\ProviderBase\DataReaderContainer.cs" />
<Compile Include="System\Data\ProviderBase\SchemaMapping.cs" />
<Compile Include="$(CommonPath)System\Runtime\CompilerServices\PreserveDependencyAttribute.cs"
Link="Common\System\Runtime\CompilerServices\PreserveDependencyAttribute.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Collections" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Text;
using System.Reflection;
using System.Runtime.CompilerServices;

namespace System.Data.SqlTypes
{
Expand Down Expand Up @@ -127,6 +128,7 @@ private static Func<Stream, XmlReaderSettings, XmlParserContext, XmlReader> Crea

private static MethodInfo CreateSqlReaderMethodInfo
{
[PreserveDependency("CreateSqlReader", "System.Xml.XmlReader", "System.Private.Xml")]
get
{
if (s_createSqlReaderMethodInfo == null)
Expand Down

0 comments on commit c614097

Please sign in to comment.