Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Fixes for type forwarders. - #2

Merged
marek-safar merged 1 commit into
dotnet:masterfrom
erozenfeld:TypeForwarderFixes
Nov 10, 2016
Merged

marek-safar merged 1 commit into
dotnet:masterfrom
erozenfeld:TypeForwarderFixes

Conversation

@erozenfeld

Copy link
Copy Markdown
Contributor

The changes in MarkStep.cs and SweepStep.cs are mostly from https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileMarkStep.cs#L33 and https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileSweepStep.cs#L45 . One additional line
Annotations.Mark (assembly.MainModule);
was added to MarkStep.Process().

The changes in ResolveFromXmlStep.cs are new and allow type forwarders to be specified in xml descriptors.

The change in Mono.Linker.csproj allows opt-out from embedding the default xml descriptors.

The changes in MarkStep.cs and SweepStep.cs are mostly from https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileMarkStep.cs#L33 and https://github.com/xamarin/xamarin-macios/blob/master/tools/linker/MobileSweepStep.cs#L45 . One additional line
Annotations.Mark (assembly.MainModule);
was added to MarkStep.Process().

The changes in ResolveFromXmlStep.cs are new and allow type forwarders to be specified in xml descriptors.

The change in Mono.Linker.csproj allows opt-out from embedding the default xml descriptors.
@dnfclas

dnfclas commented Nov 9, 2016

Copy link
Copy Markdown

Hi @erozenfeld, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@erozenfeld

Copy link
Copy Markdown
Contributor Author

@marek-safar PTAL

@marek-safar
marek-safar merged commit d57b8dd into dotnet:master Nov 10, 2016
if (!Annotations.IsMarked (type))
continue;
Annotations.Mark (exported);
Annotations.Mark (assembly.MainModule);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning for adding this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a type forwarder needs to be kept, then the module/assembly containing the type forwarder also needs to be kept. In .NET Core we have some assemblies that only have type forwarders and we ran into a case where the assembly was incorrectly deleted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation. I run into similar issue and wasn't sure about the reasoning/history there.

I noticed it was even there in the original MonoTouchMarkStep.cs (https://github.com/xamarin/monotouch/commit/49fc552e1d43bc1dd39b3e12552d16cb9ac7dc53), but I am not sure why it was removed later (there were many moves of this code so it is not easy to follow)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting 404 error trying to open xamarin/monotouch@7c0e0a1 . Is there an explanation in that commit of why the line was removed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The commit message is: Only mark the destnation (the type being forwarded to) not the origin. Allows competely removing System.Core (if no types are needed from it).

@spouliot do you remember why this change was made?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked some more into code that deals with type forwarders. I believe the intention is that if nothing in an assembly is marked except type forwarders, then all references to the type forwarders in other assemblies should be resolved in SweepStep.SweepReferences and the assembly can be deleted. There is another piece of code in SweepStep.Process that resolves all references in Copy assemblies to make sure they don't have references to type forwarders in deleted assemblies.

I have some scenarios where I don't want this optimization to kick in and need to keep assemblies with type forwarders and not resolve references to them. So, I'll create another pull request where I will add a command line switch to disable this optimization. assembly.MainModule above will only be marked when the switch is passed. Likewise, the code resolving references in SweepStep.Process and SweepStep.SweepReferences will only run if the new switch is not passed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New PR: #12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, things can be a bit easier for XI since we can assume there will be no code generation (or download) so the linker sees everything. That is not a correct assumption outside XI fullAOT compilation. That piece of code might be better left for XI (not mobile) alone - and not used in .net core.

There's also an issue in C9 (Cecil 0.10) where some Scope are not updated (on exported types). That did not happen with C8 (Cecil 0.9) but it might not be related to Cecil (I'm investigating this).

erozenfeld added a commit to erozenfeld/linker that referenced this pull request Feb 2, 2017
The linker had an optimization that removed assemblies that had only type forwarders referenced.
dotnet#2 broke that optimization by adding a line that
marked assembly.MainModule whenever a type forwarder was marked.

This change introduces a new switch -t that controls this optimization. The optimization is on
by default; if -t is specified, the optimization is disabled and assemblies with referenced type
forwarders are kept.

Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
erozenfeld added a commit to erozenfeld/linker that referenced this pull request Feb 8, 2017
The linker had an optimization that removed assemblies that had only type forwarders referenced.
dotnet#2 broke that optimization by adding a line that
marked assembly.MainModule whenever a type forwarder was marked.

This change introduces a new switch -t that controls this optimization. The optimization is on
by default; if -t is specified, the optimization is disabled and assemblies with referenced type
forwarders are kept.

Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
erozenfeld added a commit to erozenfeld/linker that referenced this pull request Feb 9, 2017
The linker had an optimization that removed assemblies that had only type forwarders referenced.
dotnet#2 broke that optimization by adding a line that
marked assembly.MainModule whenever a type forwarder was marked.

This change introduces a new switch -t that controls this optimization. The optimization is on
by default; if -t is specified, the optimization is disabled and assemblies with referenced type
forwarders are kept.

Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
marek-safar pushed a commit that referenced this pull request Feb 13, 2017
The linker had an optimization that removed assemblies that had only type forwarders referenced.
#2 broke that optimization by adding a line that
marked assembly.MainModule whenever a type forwarder was marked.

This change introduces a new switch -t that controls this optimization. The optimization is on
by default; if -t is specified, the optimization is disabled and assemblies with referenced type
forwarders are kept.

Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.
sbomer referenced this pull request in sbomer/linker Dec 13, 2019
Add a sample about solving higher level APIs on the Lazy of T example
tlakollo referenced this pull request in tlakollo/linker Apr 9, 2021
Add more functionality to Value Nodes
jtschuster referenced this pull request in jtschuster/linker Jan 19, 2022
# This is the 1st commit message:

Add Function to parse xml and return a list of injected attributes

# This is the commit message #2:

Finalize schema so all test xml is valid

# This is the commit message dotnet#3:

Add restrictions on some attributes and change uses of "nothing" to
"none"

# This is the commit message dotnet#4:

Remove schema reference in generated file expectation
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
The linker had an optimization that removed assemblies that had only type forwarders referenced.
dotnet/linker#2 broke that optimization by adding a line that
marked assembly.MainModule whenever a type forwarder was marked.

This change introduces a new switch -t that controls this optimization. The optimization is on
by default; if -t is specified, the optimization is disabled and assemblies with referenced type
forwarders are kept.

Additionally, this includes a change that marks all type forwarders in assemblies specified with -a.


Commit migrated from dotnet/linker@b118b30
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants