Repository navigation
--emit=exe and --emit=dll link for Android - #508
Merged
Merged
Conversation
A triple <arch>-linux-android<api> now links through the Android NDK (--android-ndk-path or ANDROID_NDK_HOME): the driver gets the NDK's sysroot and clang resource directory, the host tag and clang version found by listing them, and from those takes Bionic's startup objects and libraries for the API level, compiler-rt's builtins and libunwind. - Objects and links default to PIC for Android (obj.cpp, buildExe): executables must be PIE, and LLVM's default is static. - libc++ and libc++abi are linked statically (-l:libc++.a); no -lpthread, -lrt (part of Bionic's libc) or -lcurl (the Android default library has http_stub.cpp). - --emit=dll links the static default library, so the .so an app loads is self-contained: the shared one leaves GC_* to the process, and an app's process has no collector. It links with --no-undefined, so a symbol Bionic lacks is a link error rather than an UnsatisfiedLinkError in the app. - A triple with no API level, a missing NDK and a directory that is not one are refused with an error that says so. - checkGCLibPath/checkTslangLibPath name the library as the target does (libgc.a) rather than the host (gc.lib). test-compile-android-codegen (no NDK needed) checks Android objects are PIC and the two errors; test-compile-android-link links an exe and a .so for x86_64 Android, and is skipped without the NDK and the Android libraries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A triple
<arch>-linux-android<api>now links with--emit=exeand--emit=dll, through the Android NDK (--android-ndk-path, orANDROID_NDK_HOME).--emit=dllis what an app loads withSystem.loadLibrary;--emit=exeshares the same code and suitsadb shellruns.How
--sysrootand-resource-dirfrom the NDK. The host tag (windows-x86_64,linux-x86_64, …) and the clang version are found by listing directories, not hardcoded. From those, the driver itself picks Bionic's startup objects and libraries for the API level, compiler-rt's builtins andlibunwind.a; tslang's clang 22 driver handles the NDK's clang 21 layout.obj.cppandbuildExe: executables must be PIE, and LLVM's default is static.-relocation-model=picis no longer needed.libc+++libc++abi(-l:libc++.a). No-lpthreador-lrt(part of Bionic's libc) and no-lcurl(the Android default library useshttp_stub.cpp).--emit=dlllinks the static default library: the shared one leavesGC_*to the hosting process, and an app's process (the Java VM) has no collector. The output depends only onlibc.so,libm.soandlibdl.so.--no-undefinedfor an Android.so: a symbol Bionic lacks fails the link, not the app'sSystem.loadLibrary.checkGCLibPath/checkTslangLibPathname the library as the target does (libgc.a), not the host (gc.lib). That's the same bug class as Codegen picks the target's CRT, not the host's (Android cross-compile) #506.Verification
/system/bin/linker64as its interpreter;libc,libmandlibdl;export functionby its plain name and has.init_array(top-level code runs at load).--di) dll links with DWARF.test-compile-android-codegenruns everywhere, with no NDK: it checks Android code is position independent without-relocation-model=pic, and the API-level and missing-NDK errors. The PIC check discriminates: x86_64 Linux code without PIC takes the same constant as an absolute immediate, and the test asserts that too.test-compile-android-linklinks an exe and a.sofor x86_64/gc. It's skipped (not failed) withoutANDROID_NDK_HOMEand the Android builds from Android: build scripts for the collector and the async runtime #507 and DefaultLib Cannot build config tsc debug: MLIR not found #22.-mm=rcthrough tslang wasn't exercised (only through the earlier manual NDK link).Known limitation:
-mm=gcin an app libraryGC_initandGC_enable_threadsare injected into the module's global constructor (ormain), so a gc.sowith top-level code starts its collector at load; without either, Boehm initializes lazily. But Boehm only scans the stacks of threads registered with it. A JVM thread calling into the library (any JNI thread other than the one that loaded it) isn't registered, so under-mm=gcobjects allocated or held there aren't safe yet.-mm=rcand-mm=nonearen't affected. This needs a device or emulator run to confirm and fix.Follow-ups
android-readme-tslang-link), after this merges.🤖 Generated with Claude Code