-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AOT] provide libc and libm stubs so NDK is not required (#7475)
Context: 346a933 Commit 346a933 made it possible to build and link AOT shared libraries without having to have an Android NDK available. However, it seems that the produced shared libraries do not depend on the `libc.so` and `libm.so ` standard libraries, leading to runtime errors similar to: D monodroid-assembly: monodroid_dlopen: hash match found, DSO name is 'libaot-Mono.Android.dll.so' I monodroid-assembly: Trying to load shared library '/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so' I monodroid-assembly: Failed to load shared library '/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so'. dlopen failed: cannot locate symbol "memset" referenced by "/data/app/~~4kGTzxWG6HKO7nzyg6ryBg==/com.companyname.hellomaui.old-h8Jlutcvf8Dzfpuuq1ouUA==/lib/arm64/libaot-Mono.Android.dll.so"... This is caused by us not passing the `-lc` and `-lm` flags to the linker (or full paths to the `libc.so` and `libm.so` libraries). However, without the NDK available we do not have either of these standard libraries to link against. Fortunately, ELF shared libraries by default will resolve symbols from anywhere in the process address space, so there is no need to provide a `libc.so` which contains *all* public symbols. We can instead build and use a "dummy"/"stub" version of `libc.so` and `libm.so`, existing only so that the linker will add the appropriate `NEEDED` entries and resolve symbols from those libraries. Update `src/monodroid` to also produce "stub" `libc.so` and `libm.so` native libraries, and update the `<Aot/>` task to add the equivalent of `-L path/to/libstubs -lc -lm` to the AOT command-line. This ensures that the resulting `.so` files now require `libc.so`: $ llvm-readelf -a Mono.Android.dll.so | grep NEEDED 0x0000000000000001 (NEEDED) Shared library: [libc.so] 0x0000000000000001 (NEEDED) Shared library: [libm.so]
- Loading branch information
Showing
8 changed files
with
225 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#if !defined (STUB_LIB_NAME) | ||
#error STUB_LIB_NAME must be defined on command line | ||
#endif | ||
|
||
void STUB_LIB_NAME () | ||
{ | ||
// no-op | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters