-
Notifications
You must be signed in to change notification settings - Fork 520
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
net7/8-ios: EntryPointNotFoundException on remapped DllImports, even when #19624
Comments
I can reproduce. Complete test project: sample-8e39058.zip I've found a couple of workarounds, which may or may not work in a bigger project:
|
Even as of May 10, 2024, with .NET 8.0, we are stuck on this issue. With your sample project zip, it fails as you reported (i.e. "EntryPointNotFoundException") If fails even when MtouchExtraArgs looks like this (with 'dlsym:false'): And it still fails even when adding these 3 lines to the csproj: The 'Internal_SDL_SetHint' fails with DllNotFoundException. The 'Internal_SDL_SetHint' call fails with "EntryPointNotFoundException" for "_SDL_SetHint" We're wondering if the failure might have something to do with "_" underscore prefix. |
There are Windows-style paths in there, so I'm assuming you're building from Windows. Do you see the same behavior if you're building on a Mac? |
Thank you for your response. We are building on Windows now, as seems to be what .NET 8 wants us to do. We resolved this by eliminating our need for the C++ DLL on the Mac, porting that code back to C# (where it runs slower, but still runs fast enough). So for us, this issue was resolved by avoidance (i.e. eliminating usage of our C++ DLL), after spinning our wheels for about 2 days. |
After hours testing, the So, are there any workaround for real iPhone device that don't need change code? |
This patch can be deleted after dotnet/macios#19624 done.
This patch can be deleted after dotnet/macios#19624 done.
This patch can be deleted after dotnet/macios#19624 done.
It should work just as well on device as well, so maybe something else is going on. Can you file a new issue and if possible attach a test project - but at the very least we'll need a build log (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#binary-build-logs) - then we can have a look and try to figure out what's going on. |
Here is the repro project https://github.com/FNA-NET/Samples/tree/dllimport-repro/iOSGame1
And the binary build log: |
I can reproduce the problem, thanks for the test case. The problem is that we pass -dead_strip to the native linker, and that ends up removing the native functions that are required at runtime. As a workaround, you can add this to the csproj: <MtouchExtraArgs>-gcc_flags -v</MtouchExtraArgs> This doesn't do anything (except ask the native compiler to be more verbose when compiling), and it works because we disable dead stripping if any value of -gcc_flags is passed. |
This is a followup to #19599. We've migrated to using NativeLibrary.SetDllImportResolver; however, this results in "EntryPointNotFound" unless the function is statically referenced elsewhere.
In legacy Xamarin, using the "Do not strip native debugging symbols." and -force_load flags would preserve all the entry points but it appears that no longer works as expected.
Steps to Reproduce
Link with a static library in net8.0-ios.
Make sure to check "Do not strip native debugging symbols."
Add force_load to the builder flags, --cxx --gcc_flags "-L$(MSBuildProjectDirectory) -force_load $(MSBuildProjectDirectory)/libSDL2.a"
Create a DllImport which is rewritten, example:
[DllImport("RemapMe", EntryPoint = "SDL_SetHint", CallingConvention = CallingConvention.Cdecl)]
private static extern unsafe SDL_bool Internal_SDL_SetHint(
byte* name,
byte* value
);
NativeLibrary.SetDllImportResolver(assembly, MapAndLoad);
private static IntPtr MapAndLoad(
string libraryName,
Assembly assembly,
DllImportSearchPath? dllImportSearchPath
) {
return NativeLibrary.GetMainProgramHandle();
}
(A sample .cs and library are attached.)
Expected Behavior
Native function can be invoked.
Actual Behavior
Native function fails with "EntryPointNotFound" exception.
In the associated test file, we see:
Hello world!
Assembly is TestProj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Attempting to call SDL_SetHint using DllImportResolver with __Internal...
Received request to map UseInternal TestProj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null AssemblyDirectory...
Rewriting to __Internal
Received request to map UseInternal TestProj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null AssemblyDirectory...
Rewriting to __Internal
System.DllNotFoundException: UseInternal
at Program.Main(String[] args) in /Users/miles/Projects/TestProj/Main.cs:line 40
Attempting to call SDL_SetHint using DllImportResolver with GetProgramHandle...
Received request to map UseProgramHandle TestProj, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null AssemblyDirectory...
Rewriting using MainProgramHandle
System.EntryPointNotFoundException: SDL_SetHint
at Program.Main(String[] args) in /Users/miles/Projects/TestProj/Main.cs:line 52
Test complete.
Workaround
If the entry point is directly referenced elsewhere in the project, i.e.,
then the remapped calls will function correctly, but any remapped calls to other entry points will still fail.
Environment
net8.0-ios. This worked fine with .dll.config files in legacy Xamarin.
sample.zip
The text was updated successfully, but these errors were encountered: