Skip to content

Commit

Permalink
[dotnet] Handle lib prefix for P/Invokes for runtime native librari…
Browse files Browse the repository at this point in the history
…es (#11158)


* Workaround dotnet/runtime#47533 and avoid listing required symbols when native libraries are dynamically linked
* Don't call LibMonoNativeLinkMode on macOS builds
* Apply iOS workarounds also for tvOS and Mac Catalyst
  • Loading branch information
filipnavara authored Apr 10, 2021
1 parent 4e48aa2 commit 605bc43
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 12 deletions.
6 changes: 6 additions & 0 deletions tools/common/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -786,9 +786,15 @@ void GenerateIOSMain (StringWriter sw, Abi abi)
else
mono_native_lib = app.GetLibNativeName () + ".dylib";
sw.WriteLine ();
#if NET
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"libSystem.Native\", NULL, \"{mono_native_lib}\", NULL);");
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"libSystem.Security.Cryptography.Native.Apple\", NULL, \"{mono_native_lib}\", NULL);");
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"libSystem.Net.Security.Native\", NULL, \"{mono_native_lib}\", NULL);");
#else
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"System.Native\", NULL, \"{mono_native_lib}\", NULL);");
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"System.Security.Cryptography.Native.Apple\", NULL, \"{mono_native_lib}\", NULL);");
sw.WriteLine ($"\tmono_dllmap_insert (NULL, \"System.Net.Security.Native\", NULL, \"{mono_native_lib}\", NULL);");
#endif
sw.WriteLine ();
}
}
Expand Down
43 changes: 31 additions & 12 deletions tools/linker/MonoTouch.Tuner/ListExportedSymbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void ProcessMethod (MethodDefinition method)
{
if (method.IsPInvokeImpl && method.HasPInvokeInfo && method.PInvokeInfo != null) {
var pinfo = method.PInvokeInfo;
bool addPInvokeSymbol = false;

if (state != null) {
switch (pinfo.EntryPoint) {
Expand All @@ -125,37 +126,55 @@ void ProcessMethod (MethodDefinition method)
DerivedLinkContext.RequiredSymbols.AddFunction (pinfo.EntryPoint).AddMember (method);
break;

case "libSystem.Net.Security.Native":
case "System.Net.Security.Native":
#if NET
// tvOS does not ship with System.Net.Security.Native due to https://github.com/dotnet/runtime/issues/45535
if (DerivedLinkContext.App.Platform == ApplePlatform.TVOS) {
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // tvOS does not ship with System.Net.Security.Native due to https://github.com/dotnet/runtime/issues/45535
break;
}
#endif
addPInvokeSymbol = true;
break;

if (DerivedLinkContext.App.Platform == ApplePlatform.MacOSX) {
case "libSystem.Security.Cryptography.Native.Apple":
case "System.Security.Cryptography.Native.Apple":
#if NET
// https://github.com/dotnet/runtime/issues/47533
if (DerivedLinkContext.App.Platform != ApplePlatform.MacOSX) {
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // The macOS version of the BCL has several references to native methods supposedly in libSystem.Net.Security.Native that aren't there, so skip it.
break;
}

goto case "System.Native";
#endif
addPInvokeSymbol = true;
break;

case "libSystem.Native":
case "System.Native":
#if NET
if (DerivedLinkContext.App.Platform == ApplePlatform.MacOSX) {
// https://github.com/dotnet/runtime/issues/47533
if (DerivedLinkContext.App.Platform != ApplePlatform.MacOSX && pinfo.EntryPoint == "SystemNative_ConfigureTerminalForChildProcess") {
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break; // The macOS version of the BCL has several references to native methods supposedly in libSystem.Native that aren't there, so skip it.
break;
}
goto case "System.Security.Cryptography.Native.Apple";
#endif
case "System.Security.Cryptography.Native.Apple":
Driver.Log (4, "Adding native reference to {0} in {1} because it's referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
DerivedLinkContext.RequireMonoNative = true;
DerivedLinkContext.RequiredSymbols.AddFunction (pinfo.EntryPoint).AddMember (method);
addPInvokeSymbol = true;
break;

default:
Driver.Log (4, "Did not add native reference to {0} in {1} referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
break;
}

if (addPInvokeSymbol) {
Driver.Log (4, "Adding native reference to {0} in {1} because it's referenced by {2} in {3}.", pinfo.EntryPoint, pinfo.Module.Name, method.FullName, method.Module.Name);
DerivedLinkContext.RequireMonoNative = true;
if (DerivedLinkContext.App.Platform != ApplePlatform.MacOSX &&
DerivedLinkContext.App.LibMonoNativeLinkMode == AssemblyBuildTarget.StaticObject) {
DerivedLinkContext.RequiredSymbols.AddFunction (pinfo.EntryPoint).AddMember (method);
}
}
}

if (method.IsPropertyMethod ()) {
Expand Down

5 comments on commit 605bc43

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

Packages generated

View packages

Test results

1 tests failed, 180 tests passed.

Failed tests

  • introspection/watchOS 32-bits - simulator/Debug (watchOS 5.0): LaunchFailure

Pipeline on Agent XAMBOT-1035

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Tests failed catastrophically on VSTS: device tests iOS (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Tests failed catastrophically on VSTS: device tests tvOS (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

🔥 Tests failed catastrophically on VSTS: device tests iOS32b (no summary found). 🔥

Result file $(TEST_SUMMARY_PATH) not found.

Pipeline on Agent

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

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

❌ Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

Packages generated

View packages

Test results

1 tests failed, 180 tests passed.

Failed tests

  • introspection/watchOS 32-bits - simulator/Debug (watchOS 5.0): LaunchFailure

Pipeline on Agent XAMBOT-1017'

Please sign in to comment.