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

[mono] Enable NativeToManaged wrappers to get compiled with LLVM #96910

Conversation

matouskozak
Copy link
Member

@matouskozak matouskozak commented Jan 12, 2024

Enabling native-to-managed wrappers to get compiled with LLVM.

Confirmed locally that the UnmanagedCallersOnlyBasic tests are passing in fullAOT-llvm mode.

The other tests under UnmanagedCallersOnly directory are marked as NativeAotIncompatible and are crashing before/after this PR with:

Running NegativeTest_ViaDelegate...
Test Failure: Xunit.Sdk.ThrowsException: Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(System.NotSupportedException)
Actual:   typeof(System.ExecutionEngineException)

Note: we don't currently have any CI running the affected tests in fullAOT-llvm mode.

Contributes towards implementing UnmanagedCallersOnly support for Swift Interop with LLVM #94081.

@kotlarmilos
Copy link
Member

Is this blocked by #95791?

@matouskozak matouskozak added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jan 23, 2024
@matouskozak
Copy link
Member Author

Is this blocked by #95791?

I don't think so. The error happens for iOS LibraryMode functional test (reproducible on simulator as well) and the log is

/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018: The "LibraryBuilderTask" task failed unexpectedly. [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018: System.Exception: Error: Process returned non-zero exit code: ld: warning: missing line-end at end of file "/tmp/helix/working/A764091C/w/B09A09D4/e/apple_build/AppBundle/mobile_symbols.txt" [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018: Undefined symbols for architecture arm64: [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:   "_SayHello", referenced from: [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:      -exported_symbol[s_list] command line option [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:      (maybe you meant: _iOS_Device_LibraryMode_Test_ClassLibrary_SayHello, _iOS_Device_LibraryMode_Test_wrapper_native_to_managed_ClassLibrary_SayHello , _p_4_plt_iOS_Device_LibraryMode_Test_ClassLibrary_SayHello_llvm ) [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018: ld: symbol(s) not found for architecture arm64 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018: clang: error: linker command failed with exit code 1 (use -v to see invocation) [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at Utils.RunProcess(TaskLoggingHelper logger, String path, String args, IDictionary`2 envVars, String workingDir, Boolean ignoreErrors, Boolean silent, MessageImportance debugMessageImportance) in /_/src/tasks/Common/Utils.cs:line 123 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at Microsoft.Apple.Build.AppleProject.Build(String workingDir, ClangBuildOptions buildOptions, String minOSVersion, Boolean stripDebugSymbols) in /_/src/tasks/MobileBuildTasks/Apple/AppleProject.cs:line 57 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at Microsoft.Apple.Build.AppleProject.Build(String workingDir, ClangBuildOptions buildOptions, Boolean stripDebugSymbols) in /_/src/tasks/MobileBuildTasks/Apple/AppleProject.cs:line 51 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at LibraryBuilderTask.BuildAppleLibrary(List`1 sources, List`1 libs, List`1 linkerArgs) in /_/src/tasks/LibraryBuilder/LibraryBuilder.cs:line 402 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at LibraryBuilderTask.Execute() in /_/src/tasks/LibraryBuilder/LibraryBuilder.cs:line 156 [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]
/tmp/helix/working/A764091C/p/build/common/LibraryBuilder.targets(28,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/private/tmp/helix/working/A764091C/w/B09A09D4/e/publish/ProxyProjectForAOTOnHelix.proj]

triggered by this command xcrun clang -dynamiclib -o libiOS.Device.LibraryMode.Test.dylib -D HOST_APPLE_MOBILE=1 -D FORCE_AOT=1 -mios-version-min=11.0 -isysroot /Applications/Xcode_14.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS16.4.sdk -arch arm64 -I /tmp/helix/working/A764091C/p/build/microsoft.netcore.app.runtime.ios-arm64/runtimes/ios-arm64/native/include/mono-2.0/ -framewor....

Based on my investigation when the native-to-manage wrapper gets compiled with LLVM, the name is fully specified as _wrapper_native_to_managed_ClassLibrary_SayHello
and when compiled with mini, the name is just _SayHello. I was unable to reproduce the same issue on osx-arm64 desktop, i.e., the program gets build and linked correctly on desktop.


Steps to reproduce locally:

  1. checkout this PR
  2. build runtime: ./build.sh mono+libs -os iossimulator -arch arm64
  3. build functional test: ./dotnet.sh build /t:Test -c Debug /p:TargetOS=iossimulator /p:TargetArchitecture=arm64 src/tests/FunctionalTests/iOS/Simulator/LibraryMode/iOS.Simulator.LibraryMode.Test.csproj /p:RuntimeFlavor=Mono

@vargaz
Copy link
Contributor

vargaz commented Jan 23, 2024

The names like _wrapper_native_to_managed are just generated names meant to help native debugging, there is some functionality in the aot compiler to specify the exact names used for exported symbols.

@matouskozak
Copy link
Member Author

/azp run runtime-extra-platforms

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@matouskozak
Copy link
Member Author

The failures on extra-platform CI might be related to this PR...

@ghost ghost closed this Mar 1, 2024
@ghost
Copy link

ghost commented Mar 1, 2024

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Codegen-LLVM-mono NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants