Repository navigation
Description
Follow-up to #81450 (see cherrymui's comment: in scope of that project, tracked here). Narrower successor of #38918, which @eliasnaur closed as a subset of #81450.
What did you do
$ GOOS=android GOARCH=arm64 CGO_ENABLED=0 go build -buildmode=c-shared -o libapp.so .
Go version: go1.27.2
What did you see
-buildmode=c-shared requires external (cgo) linking, but cgo is not enabled
What did you expect to see
A loadable ET_DYN .so without a C toolchain, as internal linking already does for -buildmode=pie on android/arm64.
mustLinkExternal returns true, "buildmode=c-shared" for every non-wasm target. With CGO_ENABLED=0 the build is refused; with CGO_ENABLED=1 the build requires CC pointing at the NDK cross-compiler (clang/lld) even though the module has no C source files, so a Go library for Android (System.loadLibrary) always needs NDK. android/arm64 already supports internal PIE linking, so this is the delta on top of that: emit ET_DYN with a dynamic section, .init_array for _rt0_arm64_linux_lib, and dynsym exports. (#38918 shows what happens if only the mustLinkExternal check is removed: bionic rejects the result with unexpected e_type: 2.)
Acceptance criteria
GOOS=android GOARCH=arm64 go build -buildmode=c-sharedwith no C toolchain produces a.sothatSystem.loadLibraryaccepts- entry symbols come from
//exportin binding mode (proposal: cmd/cgo: cgo without a C toolchain #81450, no .c files); whether that mode is reachable with an explicitCGO_ENABLED=0is being decided there - runtime starts from
.init_array, survives Activity recreation and entry from Android-owned threads - LOAD segments 16 KB-aligned (Google Play requirement since Nov 2025)
Evidence
besmpl/go@d31f0b5f + https://github.com/besmpl/go-android-cgo-free-prototype: a CGO_ENABLED=0 .so with one exported JNI symbol loads on API 29/30/36 arm64 emulators, survives Activity recreation and concurrent entry, and renders through a real SurfaceView. The prototype still links with NDK lld, so it covers the compiler/runtime side, not the linker; the APK-level harness is available as a test bed for the internal-linking work.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsTodo
Activity
gabyhelp commentedon Oct 9, 2026
Related Issues
Related Code Changes
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)