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

.NET 8 RC1: NativeAOT fails to build for linux-bionic-arm64 when specifying project as library (Linker error) #92272

Closed
LittleCodingFox opened this issue Sep 19, 2023 · 14 comments · Fixed by #100755
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged os-android
Milestone

Comments

@LittleCodingFox
Copy link

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 of Exe

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:

ld.lld : error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
ld.lld : error : version script assignment of 'V1.0' to symbol '_fini' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
clang : error : linker command failed with exit code 1 (use -v to see invocation) [HelloBionic\HelloBionic.csproj]

...\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.0-rc.1.23419.4\build\Microsoft.NETCore.Native.targets(364
,5): error MSB3073: The command ""clang" "obj\Release\net8.0\linux-bionic-arm64\native\HelloBionic.o" -o "bin\Release\n
et8.0\linux-bionic-arm64\native\HelloBionic.so" -Wl,--version-script=obj\Release\net8.0\linux-bionic-arm64\native\Hello
Bionic.exports -gz=zlib -fuse-ld=lld ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic
-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libbootstrapperdll.o ...\.nuget\packages\micros
oft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libRuntime.
WorkstationGC.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.234
19.4/runtimes/linux-bionic-arm64/\native\libeventpipe-disabled.a ...\.nuget\packages\microsoft.netcore.app.ru
ntime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libstdc++compat.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-
arm64/\native\libSystem.Native.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm
64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libSystem.IO.Compression.Native.a ...\.nuget\packag
es\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\li
bSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-android21 -g -Wl,-rpath,"$ORIGIN" -Wl,--build-id=
sha1 -Wl,--as-needed -Wl,-e0x0 -pthread -ldl -lz -llog -lm -shared -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--dis
card-all -Wl,--gc-sections -Wl,-T,"obj\Release\net8.0\linux-bionic-arm64\native\sections.ld"" exited with code 1. [...\HelloBionic\HelloBionic.csproj]

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

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Sep 19, 2023
@ghost
Copy link

ghost commented Sep 19, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

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 of Exe

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:

ld.lld : error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
ld.lld : error : version script assignment of 'V1.0' to symbol '_fini' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
clang : error : linker command failed with exit code 1 (use -v to see invocation) [HelloBionic\HelloBionic.csproj]

...\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.0-rc.1.23419.4\build\Microsoft.NETCore.Native.targets(364
,5): error MSB3073: The command ""clang" "obj\Release\net8.0\linux-bionic-arm64\native\HelloBionic.o" -o "bin\Release\n
et8.0\linux-bionic-arm64\native\HelloBionic.so" -Wl,--version-script=obj\Release\net8.0\linux-bionic-arm64\native\Hello
Bionic.exports -gz=zlib -fuse-ld=lld ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic
-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libbootstrapperdll.o ...\.nuget\packages\micros
oft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libRuntime.
WorkstationGC.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.234
19.4/runtimes/linux-bionic-arm64/\native\libeventpipe-disabled.a ...\.nuget\packages\microsoft.netcore.app.ru
ntime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libstdc++compat.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-
arm64/\native\libSystem.Native.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm
64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libSystem.IO.Compression.Native.a ...\.nuget\packag
es\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\li
bSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-android21 -g -Wl,-rpath,"$ORIGIN" -Wl,--build-id=
sha1 -Wl,--as-needed -Wl,-e0x0 -pthread -ldl -lz -llog -lm -shared -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--dis
card-all -Wl,--gc-sections -Wl,-T,"obj\Release\net8.0\linux-bionic-arm64\native\sections.ld"" exited with code 1. [...\HelloBionic\HelloBionic.csproj]

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

Author: LittleCodingFox
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@ghost
Copy link

ghost commented Sep 19, 2023

Tagging subscribers to 'arch-android': @steveisok, @akoeplinger
See info in area-owners.md if you want to be subscribed.

Issue Details

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 of Exe

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:

ld.lld : error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
ld.lld : error : version script assignment of 'V1.0' to symbol '_fini' failed: symbol not defined [HelloBionic\HelloBionic.csproj]
clang : error : linker command failed with exit code 1 (use -v to see invocation) [HelloBionic\HelloBionic.csproj]

...\.nuget\packages\microsoft.dotnet.ilcompiler\8.0.0-rc.1.23419.4\build\Microsoft.NETCore.Native.targets(364
,5): error MSB3073: The command ""clang" "obj\Release\net8.0\linux-bionic-arm64\native\HelloBionic.o" -o "bin\Release\n
et8.0\linux-bionic-arm64\native\HelloBionic.so" -Wl,--version-script=obj\Release\net8.0\linux-bionic-arm64\native\Hello
Bionic.exports -gz=zlib -fuse-ld=lld ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic
-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libbootstrapperdll.o ...\.nuget\packages\micros
oft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libRuntime.
WorkstationGC.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.234
19.4/runtimes/linux-bionic-arm64/\native\libeventpipe-disabled.a ...\.nuget\packages\microsoft.netcore.app.ru
ntime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libstdc++compat.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-
arm64/\native\libSystem.Native.a ...\.nuget\packages\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm
64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\libSystem.IO.Compression.Native.a ...\.nuget\packag
es\microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64\8.0.0-rc.1.23419.4/runtimes/linux-bionic-arm64/\native\li
bSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-android21 -g -Wl,-rpath,"$ORIGIN" -Wl,--build-id=
sha1 -Wl,--as-needed -Wl,-e0x0 -pthread -ldl -lz -llog -lm -shared -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--dis
card-all -Wl,--gc-sections -Wl,-T,"obj\Release\net8.0\linux-bionic-arm64\native\sections.ld"" exited with code 1. [...\HelloBionic\HelloBionic.csproj]

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

Author: LittleCodingFox
Assignees: -
Labels:

os-android, untriaged, area-NativeAOT-coreclr

Milestone: -

@MichalStrehovsky
Copy link
Member

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).

@MichalStrehovsky MichalStrehovsky added the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 20, 2023
@ghost
Copy link

ghost commented Sep 20, 2023

This issue has been marked needs-author-action and may be missing some important information.

@LittleCodingFox
Copy link
Author

LittleCodingFox commented Sep 20, 2023

The Android NDK in my PATH is C:/Users/User/AppData/Local/Android/Sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/windows-x86_64/bin, so 26.0.10792818.

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!

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Sep 20, 2023
@MichalStrehovsky
Copy link
Member

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:

streamWriter.WriteLine(" global: _init; _fini;");

We'll need to investigate what changed and what's the new thing.

@MichalStrehovsky MichalStrehovsky added this to the 9.0.0 milestone Sep 20, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Sep 20, 2023
@LittleCodingFox
Copy link
Author

Will do, I'll have a look and let you know the results!

@LittleCodingFox
Copy link
Author

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!

@am11
Copy link
Member

am11 commented Sep 23, 2023

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:

<LinkerArg Include="-Wl,--defsym,__xmknod=mknod" Condition="'$(StaticExecutable)' == 'true'" />

@LittleCodingFox
Copy link
Author

LittleCodingFox commented Sep 23, 2023

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!

@josephmoresena
Copy link
Contributor

Check my NativeAOT-AndroidHelloJniLib repo! Sorry for late.

@CasualPokePlayer
Copy link

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.

ld.lld : error : --defsym:1: symbol not found: __libc_fini
ld.lld : error : --defsym:1: symbol not found: __libc_init

@CasualPokePlayer
Copy link

CasualPokePlayer commented Apr 7, 2024

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 --no-undefined-version, which got switched to being the default in clang 16, indicating it only ever "worked" before due to clang not erroring due to the missing symbols (which even then, at runtime these missing symbols don't seem to cause any issues? at least for my project, could be due to it just being a shared library maybe?).

<ItemGroup Condition="'$(RuntimeIdentifier)' == 'linux-bionic'">
  <LinkerArg Include="-Wl,--undefined-version" />
</ItemGroup

This would be a possible workaround where __libc_init/__libc_fini don't appear to be defined either.

@am11
Copy link
Member

am11 commented Apr 7, 2024

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:
<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))">

@dotnet-policy-service dotnet-policy-service bot added the in-pr There is an active PR which will close this issue when it is merged label Apr 9, 2024
jonpryor added a commit to jonpryor/Android-NativeAOT that referenced this issue May 1, 2024
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
jonathanpeppers pushed a commit to jonathanpeppers/Android-NativeAOT that referenced this issue May 1, 2024
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
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr in-pr There is an active PR which will close this issue when it is merged os-android
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

6 participants