You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Mono AOT compiler exports the symbols as-is without prefixing it with an _ which is required on iOS platforms.
This results in failures when trying to load the symbol dynamically from the native code via:
diff --git a/src/mono/sample/iOS/Program.cs b/src/mono/sample/iOS/Program.cs
index 603ff2e4ebc..fbdc8032daa 100644
--- a/src/mono/sample/iOS/Program.cs+++ b/src/mono/sample/iOS/Program.cs@@ -24,6 +24,9 @@ private static void OnButtonClick()
ios_set_text("OnButtonClick! #" + counter++);
}
+ [UnmanagedCallersOnly(EntryPoint="exposed_managed_method")]+ public static int ManagedMethod() => 42;+
#if CI_TEST
public static async Task<int> Main(string[] args)
#else
diff --git a/src/mono/sample/iOS/Program.csproj b/src/mono/sample/iOS/Program.csproj
index 0e6aa8777fa..f0187ba8f81 100644
--- a/src/mono/sample/iOS/Program.csproj+++ b/src/mono/sample/iOS/Program.csproj@@ -16,6 +16,10 @@
<TrimMode>Link</TrimMode>
</PropertyGroup>
+ <ItemGroup>+ <TrimmerRootDescriptor Include="$(MSBuildThisFileDirectory)ILLink.Descriptors.xml" />+ </ItemGroup>+
<PropertyGroup Condition="'$(TargetOS)' == 'MacCatalyst'">
<DevTeamProvisioning Condition="'$(TargetOS)' == 'MacCatalyst' and '$(DevTeamProvisioning)' == ''">adhoc</DevTeamProvisioning>
<EnableAppSandbox Condition="'$(EnableAppSandbox)' == ''">false</EnableAppSandbox>
@@ -79,6 +83,7 @@
TargetOS="$(TargetOS)"
Arch="$(TargetArchitecture)"
ProjectName="$(AppName)"
+ NativeMainSource="$(MSBuildThisFileDirectory)/main.m"
MonoRuntimeHeaders="$(MicrosoftNetCoreAppRuntimePackDir)runtimes\$(TargetOS.ToLower())-$(TargetArchitecture)\native\include\mono-2.0"
Assemblies="@(BundleAssemblies)"
MainLibraryFileName="Program.dll"
diff --git a/src/mono/sample/iOS/main.m b/src/mono/sample/iOS/main.m
index 0ab407e8398..e6d8a3f31f4 100644
--- a/src/mono/sample/iOS/main.m+++ b/src/mono/sample/iOS/main.m@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
#import <UIKit/UIKit.h>
+#import <dlfcn.h>
#import "runtime.h"
@interface ViewController : UIViewController
@@ -45,6 +46,8 @@ void (*clickHandlerPtr)(void);
[self.view addSubview:button];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ void *del = dlsym (RTLD_DEFAULT, "exposed_managed_method");+ NSAssert(del != NULL, @"'exposed_managed_method' not found");
mono_ios_runtime_init ();
});
}
And add the ILLink.Descriptors.xml file to the project directory with the following contents:
<linker>
<!-- this is here to show how to configure the trimming -->
<assemblyfullname="Program">
<typefullname="Program">
<methodname="ManagedMethod" />
</type>
</assembly>
</linker>
Finally, build it with:
cd src/mono/sample/iOS
make build-appbundle MONO_ARCH=arm64 AOT=true DEPLOY_AND_RUN=true
Workaround
Possible workaround is to prefix the EntryPoint name with the underscore, but then such code is not platform independent.
Description
If a method is marked with
UnmanagedCallersOnlyAttribute
and a named export is specified viaEntryPoint
e.g.,Mono AOT compiler exports the symbols as-is without prefixing it with an
_
which is required on iOS platforms.This results in failures when trying to load the symbol dynamically from the native code via:
Repro
To reproduce, apply the following patch:
And add the
ILLink.Descriptors.xml
file to the project directory with the following contents:Finally, build it with:
cd src/mono/sample/iOS make build-appbundle MONO_ARCH=arm64 AOT=true DEPLOY_AND_RUN=true
Workaround
Possible workaround is to prefix the EntryPoint name with the underscore, but then such code is not platform independent.
/cc @mdh1418 @steveisok
The text was updated successfully, but these errors were encountered: