-
Notifications
You must be signed in to change notification settings - Fork 515
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
[dotnet] Prevent linking out code referenced by P/Invoke #10182
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0c18eb
[dotnet] Generate references.mm to prevent linking out code reference…
filipnavara 9f8ccad
Address PR feedback: Namespaces.Foundation -> "Foundation."
filipnavara d9b782b
Address PR feedback: Simplify hasSymbols
filipnavara 76d5c84
Reuse ListExportedSymbols step, respect App.SymbolMode
filipnavara 7f603a4
Address PR feedback
filipnavara 39948aa
Workaround for tvOS
filipnavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
|
||
using Mono.Cecil; | ||
|
||
using Xamarin.Bundler; | ||
using Xamarin.Linker; | ||
|
||
namespace Xamarin { | ||
|
||
public class GenerateReferencesStep : ConfigurationAwareStep { | ||
private Symbols required_symbols = new Symbols (); | ||
|
||
protected override string Name { get; } = "Generate References"; | ||
protected override int ErrorCode { get; } = 2320; | ||
|
||
protected override void TryEndProcess () | ||
{ | ||
base.TryEndProcess (); | ||
|
||
var items = new List<MSBuildItem> (); | ||
var file = Path.Combine (Configuration.CacheDirectory, $"references.mm"); | ||
if (Configuration.Target.GenerateReferencingSource (file, required_symbols) != null) { | ||
filipnavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var item = new MSBuildItem { Include = file }; | ||
items.Add (item); | ||
} | ||
Configuration.WriteOutputForMSBuild ("_ReferencesFile", items); | ||
} | ||
|
||
protected override void TryProcessAssembly (AssemblyDefinition assembly) | ||
filipnavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
base.TryProcessAssembly (assembly); | ||
|
||
if (!assembly.MainModule.HasTypes) | ||
return; | ||
|
||
var hasSymbols = false; | ||
if (assembly.MainModule.HasModuleReferences) { | ||
hasSymbols = true; | ||
} else if (assembly.MainModule.HasTypeReference (Namespaces.Foundation + ".FieldAttribute")) { | ||
filipnavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hasSymbols = true; | ||
} | ||
if (!hasSymbols) | ||
return; | ||
|
||
foreach (var type in assembly.MainModule.Types) | ||
ProcessType (type); | ||
} | ||
|
||
void ProcessType (TypeDefinition type) | ||
{ | ||
if (type.HasNestedTypes) { | ||
foreach (var nested in type.NestedTypes) | ||
ProcessType (nested); | ||
} | ||
|
||
if (type.HasMethods) { | ||
foreach (var method in type.Methods) | ||
ProcessMethod (method); | ||
} | ||
} | ||
|
||
void ProcessMethod (MethodDefinition method) | ||
{ | ||
if (method.IsPInvokeImpl && method.HasPInvokeInfo && method.PInvokeInfo != null) { | ||
var pinfo = method.PInvokeInfo; | ||
if (pinfo.Module.Name == "__Internal") { | ||
required_symbols.AddFunction (pinfo.EntryPoint).AddMember (method); | ||
} | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not clear in PR but it seems to be after sweeping/cleaning.
Do check that enabling the linker result in less generated symbols (to keep around)