-
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
Changes from all commits
d0c18eb
9f8ccad
d9b782b
76d5c84
7f603a4
39948aa
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 | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
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 { | ||||||
protected override string Name { get; } = "Generate References"; | ||||||
protected override int ErrorCode { get; } = 2320; | ||||||
|
||||||
protected override void TryEndProcess () | ||||||
{ | ||||||
base.TryEndProcess (); | ||||||
|
||||||
var app = Configuration.Application; | ||||||
var required_symbols = Configuration.DerivedLinkContext.RequiredSymbols; | ||||||
var items = new List<MSBuildItem> (); | ||||||
|
||||||
switch (app.SymbolMode) { | ||||||
case SymbolMode.Ignore: | ||||||
break; | ||||||
case SymbolMode.Code: | ||||||
string reference_m = Path.Combine (Configuration.CacheDirectory, "reference.m"); | ||||||
reference_m = Configuration.Target.GenerateReferencingSource (reference_m, required_symbols); | ||||||
if (!string.IsNullOrEmpty (reference_m)) { | ||||||
var item = new MSBuildItem { Include = reference_m }; | ||||||
items.Add (item); | ||||||
} | ||||||
Configuration.WriteOutputForMSBuild ("_ReferencesFile", items); | ||||||
break; | ||||||
case SymbolMode.Linker: | ||||||
foreach (var symbol in required_symbols) { | ||||||
var item = new MSBuildItem { Include = "-u" + symbol.Prefix + symbol.Name }; | ||||||
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 you need a space here:
Suggested change
although that might have to be treated as two different MSBuildItems. 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 actually checked it and the space is not necessary. In fact the space would create a problem because it would pass the whole thing quoted to the linker and the linker would expect the space to be part of the symbol name. |
||||||
items.Add (item); | ||||||
} | ||||||
Configuration.WriteOutputForMSBuild ("_ReferencesLinkerFlags", items); | ||||||
break; | ||||||
default: | ||||||
throw ErrorHelper.CreateError (99, Errors.MX0099, $"invalid symbol mode: {app.SymbolMode}"); | ||||||
} | ||||||
} | ||||||
} | ||||||
} |
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)