Skip to content
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

[NativeAOT] Fix ILC warning for NSObject.RegisterToggleRef #18889

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tools/dotnet-linker/AppBundleRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,12 @@ public MethodReference Foundation_NSObject_FlagsSetterMethod {
return GetMethodReference (PlatformAssembly, Foundation_NSObject, "set_flags", "Foundation.NSObject::set_flags", predicate: null, out var _);
}
}

public MethodReference Foundation_NSObject_RegisterToggleRef {
get {
return GetMethodReference (PlatformAssembly, Foundation_NSObject, "RegisterToggleRef", "Foundation.NSObject::RegisterToggleRef", predicate: null, out var _);
}
}
#else
public FieldReference Foundation_NSObject_FlagsField {
get {
Expand Down
18 changes: 18 additions & 0 deletions tools/dotnet-linker/Steps/ManagedRegistrarStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ protected override void TryProcessAssembly (AssemblyDefinition assembly)
var md = abr.RegistrarHelper_RuntimeTypeHandleEquals.Resolve ();
md.IsPublic = true;
Annotations.Mark (md);
} else if (App.XamarinRuntime == XamarinRuntime.NativeAOT && Configuration.Profile.IsProductAssembly (assembly)) {
ImplementNSObjectRegisterToggleRefMethodStub ();
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't really fit with the managed static registrar, but I think it's good for now.

At some point we might want to move random stuff out of the managed static registrar and into a "MakeEverythingWorkWithNativeAOTStep"...

}

abr.ClearCurrentAssembly ();
Expand Down Expand Up @@ -1376,5 +1378,21 @@ MethodDefinition CloneConstructorWithNativeHandle (MethodDefinition ctor)

return clonedCtor;
}

void ImplementNSObjectRegisterToggleRefMethodStub ()
{
// The NSObject.RegisterToggleRef method is a Mono icall that is unused in NativeAOT
// and we need to modify it so that ILC doesn't report the following warning:
//
// ILC: Method '[Microsoft.iOS]Foundation.NSObject.RegisterToggleRef(NSObject,native int,bool)' will always throw because:
// Invalid IL or CLR metadata in 'Void Foundation.NSObject.RegisterToggleRef(Foundation.NSObject, IntPtr, Boolean)'
//
var registerToggleRef = abr.Foundation_NSObject_RegisterToggleRef.Resolve ();
registerToggleRef.IsPublic = false;
registerToggleRef.IsInternalCall = false;

registerToggleRef.CreateBody (out var il);
il.Emit (OpCodes.Ret);
}
}
}
Loading