-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
.NET 8 RC1: NativeAOT fails to build for linux-bionic-arm64 when specifying project as library (Linker error) #92272
Comments
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas Issue DetailsDescriptionI was trying out .NET 8 RC1 for NativeAOT for android bionic, and I get an error regarding ld.lld with a missing symbol for Reproduction StepsUsing the default steps to make a NativeAOT project for android:
open the csproj and edit the type to Finally, change the
Expected behaviorIt should create the library rather than error. It creates the executable properly when it's set as Actual behaviorGet error:
Regression?No response Known WorkaroundsNo response Configuration.NET version: 8.0.100-rc.1.23455.8 Other informationNo response
|
Tagging subscribers to 'arch-android': @steveisok, @akoeplinger Issue DetailsDescriptionI was trying out .NET 8 RC1 for NativeAOT for android bionic, and I get an error regarding ld.lld with a missing symbol for Reproduction StepsUsing the default steps to make a NativeAOT project for android:
open the csproj and edit the type to Finally, change the
Expected behaviorIt should create the library rather than error. It creates the executable properly when it's set as Actual behaviorGet error:
Regression?No response Known WorkaroundsNo response Configuration.NET version: 8.0.100-rc.1.23455.8 Other informationNo response
|
What's the Android NDK that is on your PATH? This doesn't repro for me - it generates an .so file fine (even though there were no UnmanagedCallersOnly methods so it's a bit of a nonsensical library). |
This issue has been marked |
The Android NDK in my PATH is Unless there's something I'm missing, I just set this one in my PATH, I don't think there's anything else missing in the PATH? Thank you! |
Use an older version of the NDK. I tried with r21b because I had that on this machine. r23c should also work. We generate this reference here:
We'll need to investigate what changed and what's the new thing. |
Will do, I'll have a look and let you know the results! |
I just tried r23c and it did build the .so properly! So this seems an issue with r26. Would be good to see if it's possible to make this work with r26 too, since r23 is considered an unsupported version now (it showed in the "Unsupported Downloads" page for NDK). Thank you for your time! |
A workaround could be something like: (untested) <!-- your .csproj -->
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-bionic'">
<LinkerArg Include="-Wl,--defsym,_init=__libc_init" />
<LinkerArg Include="-Wl,--defsym,_fini=__libc_fini" />
</ItemGroup If it works, we can add it next to: runtime/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets Line 162 in 5883b72
|
Hello @am11, it seems to have worked! At least, it doesn't complain anymore. Not sure if the binary actually works but I'd have to give this more time to investigate. But it's a good start! |
Check my NativeAOT-AndroidHelloJniLib repo! Sorry for late. |
I ran into this issue on my own project trying to go to the latest NDK LTS (which is currently 26.2.11394342), and it seems the workaround no longer works for that version.
|
Looking at the .so produced by older NDK, it actually looks like there's no _init or _fini defined in the first place. Looking at the error, it seems to be triggered for
This would be a possible workaround where |
Thanks for the investigation @CasualPokePlayer. I was able to repro it with LTS and your workaround fixed it. Would you like to send a PR updating https://github.com/dotnet/runtime/blob/9b57a265c7efd3732b035bade005561a04767128/src/coreclr/nativeaot/docs/android-bionic.md#known-issues? An additional correction was required in the condition: |
Context: a2fd74c Context: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md#known-issues Commit a2fd74c had a fatal flaw: it would immediately crash on launch: F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** F DEBUG : Build fingerprint: 'google/raven/raven:14/AP1A.240305.019.A1/11445699:user/release-keys' F DEBUG : Revision: 'MP1.0' F DEBUG : ABI: 'arm64' F DEBUG : Timestamp: 2024-05-01 11:01:48.710687354-0400 F DEBUG : Process uptime: 1s F DEBUG : Cmdline: com.jonathanpeppers.nativeaot F DEBUG : pid: 10516, tid: 10516, name: ppers.nativeaot >>> com.jonathanpeppers.nativeaot <<< F DEBUG : uid: 10371 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000006 F DEBUG : Cause: null pointer dereference F DEBUG : x0 0000000000000006 x1 0000007fda6f3340 x2 0000007eb6852980 x3 0000007fda6ef330 F DEBUG : x4 0000007eb6852a00 x5 0000000000000004 x6 0000000001414d4c x7 0000007eb6852004 F DEBUG : x8 0000007eb6852980 x9 0000000000000006 x10 000000000000000f x11 757274736e6f6320 F DEBUG : x12 676e696c6c61632c x13 000180000045dfd0 x14 0000000000018510 x15 0000000000000000 F DEBUG : x16 0000007eb7b3d680 x17 0000007eb7a5fb00 x18 0000007eb6d90000 x19 0000007fda6f3340 F DEBUG : x20 0000007eb6852980 x21 0000000000000006 x22 0000007eb7b4b000 x23 0000007eb67c9e70 F DEBUG : x24 0000007fda6f0518 x25 0000000000000022 x26 0000007eb6843c00 x27 0000007fda6f0500 F DEBUG : x28 0000007eb7b49000 x29 0000007fda6ef2e0 F DEBUG : lr 0000007b57aebc80 sp 0000007fda6ef2c0 pc 0000007b57aebcb0 pst 0000000080001000 F DEBUG : 1 total frames F DEBUG : backtrace: F DEBUG : #00 pc 00000000000c1cb0 /data/app/~~y5LQdnO4d1iwNk2Z6I4Jpg==/com.jonathanpeppers.nativeaot-HJbM4Jw2CNRiWe4-Rn2IxA==/lib/arm64/libdotnet.so (BuildId: 21c56035e6fc411dab6ab373715ba35e82c0fb5f) Turns out™ that the [android-bionic.md][0] documentation has a [Known issues][1] section, which has a *better* workaround: > If you hit > `error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined` - > this is a known issue with .NET 8 release dotnet/runtime#92272, you > can add following lines to your csproj to work around: > > ```xml > <ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"> > <LinkerArg Include="-Wl,--undefined-version" /> > </ItemGroup> > ``` That workaround *does* work, better than the attempted workaround in a2fd74c. Update `libdotnet.targets` to use the documented workaround. Additionally, `libdotnet.so` depends on `libc++_shared.so`: % $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-readelf -a DotNet/bin/Release/net8.0/linux-bionic-arm64/publish/libdotnet.so 0x0000000000000001 (NEEDED) Shared library: [libdl.so] 0x0000000000000001 (NEEDED) Shared library: [libc++_shared.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so] and `libc++_shared.so` needs to be included in the `.apk`. Add a new `_CopyLibcppShared` target which copies `libc++_shared.so` from the NDK into `Native/app/src/main/jniLibs/arm64-v8a`. Failure to do so results in an error at startup: E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~p6cCHwNVFV8uzhECCUKmCg==/com.jonathanpeppers.nativeaot-wVDfzgY8K6AbDgBPnccb_w==/lib/arm64/libnativeaot.so": dlopen failed: library "libc++_shared.so" not found: needed by /data/app/~~p6cCHwNVFV8uzhECCUKmCg==/com.jonathanpeppers.nativeaot-wVDfzgY8K6AbDgBPnccb_w==/lib/arm64/libdotnet.so in namespace clns-4 Update `README.md` to contain clear(er) instruction on how to build and run this sample. [0]: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md [1]: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md#known-issues
Context: a2fd74c Context: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md#known-issues Commit a2fd74c had a fatal flaw: it would immediately crash on launch: F DEBUG : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** F DEBUG : Build fingerprint: 'google/raven/raven:14/AP1A.240305.019.A1/11445699:user/release-keys' F DEBUG : Revision: 'MP1.0' F DEBUG : ABI: 'arm64' F DEBUG : Timestamp: 2024-05-01 11:01:48.710687354-0400 F DEBUG : Process uptime: 1s F DEBUG : Cmdline: com.jonathanpeppers.nativeaot F DEBUG : pid: 10516, tid: 10516, name: ppers.nativeaot >>> com.jonathanpeppers.nativeaot <<< F DEBUG : uid: 10371 F DEBUG : tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) F DEBUG : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000006 F DEBUG : Cause: null pointer dereference F DEBUG : x0 0000000000000006 x1 0000007fda6f3340 x2 0000007eb6852980 x3 0000007fda6ef330 F DEBUG : x4 0000007eb6852a00 x5 0000000000000004 x6 0000000001414d4c x7 0000007eb6852004 F DEBUG : x8 0000007eb6852980 x9 0000000000000006 x10 000000000000000f x11 757274736e6f6320 F DEBUG : x12 676e696c6c61632c x13 000180000045dfd0 x14 0000000000018510 x15 0000000000000000 F DEBUG : x16 0000007eb7b3d680 x17 0000007eb7a5fb00 x18 0000007eb6d90000 x19 0000007fda6f3340 F DEBUG : x20 0000007eb6852980 x21 0000000000000006 x22 0000007eb7b4b000 x23 0000007eb67c9e70 F DEBUG : x24 0000007fda6f0518 x25 0000000000000022 x26 0000007eb6843c00 x27 0000007fda6f0500 F DEBUG : x28 0000007eb7b49000 x29 0000007fda6ef2e0 F DEBUG : lr 0000007b57aebc80 sp 0000007fda6ef2c0 pc 0000007b57aebcb0 pst 0000000080001000 F DEBUG : 1 total frames F DEBUG : backtrace: F DEBUG : #00 pc 00000000000c1cb0 /data/app/~~y5LQdnO4d1iwNk2Z6I4Jpg==/com.jonathanpeppers.nativeaot-HJbM4Jw2CNRiWe4-Rn2IxA==/lib/arm64/libdotnet.so (BuildId: 21c56035e6fc411dab6ab373715ba35e82c0fb5f) Turns out™ that the [android-bionic.md][0] documentation has a [Known issues][1] section, which has a *better* workaround: > If you hit > `error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined` - > this is a known issue with .NET 8 release dotnet/runtime#92272, you > can add following lines to your csproj to work around: > > ```xml > <ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))"> > <LinkerArg Include="-Wl,--undefined-version" /> > </ItemGroup> > ``` That workaround *does* work, better than the attempted workaround in a2fd74c. Update `libdotnet.targets` to use the documented workaround. Additionally, `libdotnet.so` depends on `libc++_shared.so`: % $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-readelf -a DotNet/bin/Release/net8.0/linux-bionic-arm64/publish/libdotnet.so 0x0000000000000001 (NEEDED) Shared library: [libdl.so] 0x0000000000000001 (NEEDED) Shared library: [libc++_shared.so] 0x0000000000000001 (NEEDED) Shared library: [libc.so] and `libc++_shared.so` needs to be included in the `.apk`. Add a new `_CopyLibcppShared` target which copies `libc++_shared.so` from the NDK into `Native/app/src/main/jniLibs/arm64-v8a`. Failure to do so results in an error at startup: E AndroidRuntime: java.lang.UnsatisfiedLinkError: Unable to load native library "/data/app/~~p6cCHwNVFV8uzhECCUKmCg==/com.jonathanpeppers.nativeaot-wVDfzgY8K6AbDgBPnccb_w==/lib/arm64/libnativeaot.so": dlopen failed: library "libc++_shared.so" not found: needed by /data/app/~~p6cCHwNVFV8uzhECCUKmCg==/com.jonathanpeppers.nativeaot-wVDfzgY8K6AbDgBPnccb_w==/lib/arm64/libdotnet.so in namespace clns-4 Update `README.md` to contain clear(er) instruction on how to build and run this sample. [0]: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md [1]: https://github.com/dotnet/runtime/blob/132725d3702d51d78b5f68b0501c5e5845921d04/src/coreclr/nativeaot/docs/android-bionic.md#known-issues
Description
I was trying out .NET 8 RC1 for NativeAOT for android bionic, and I get an error regarding ld.lld with a missing symbol for
_init
and_fini
.Reproduction Steps
Using the default steps to make a NativeAOT project for android:
dotnet new console -o HelloBionic --aot
open the csproj and edit the type to
Library
instead ofExe
Finally, change the
Program.cs
file to not use top-level statements. Something empty such as an empty namespace and/or class should suffice.dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true
Expected behavior
It should create the library rather than error. It creates the executable properly when it's set as
Exe
.Actual behavior
Get error:
Regression?
No response
Known Workarounds
No response
Configuration
.NET version: 8.0.100-rc.1.23455.8
OS: Windows 10 (constantly updated so I assume latest version)
Architecture: x64
I'm not sure if it's specific to this configuration
Other information
No response
The text was updated successfully, but these errors were encountered: