fix(android): drop pthread_shim — clang shim makes it unnecessary (and harmful)
Some checks failed
Mirror to GitHub / mirror (push) Failing after 37s
Build Release Binaries / build-amd64 (push) Failing after 3m49s

Once the Dockerfile rewrites every android24-clang to exec android26-clang,
the linker uses the API-26 NDK sysroot and libstd's pthread_create reference
resolves directly against libc.so's real runtime symbol — no interposition
needed.

The pthread_shim.c approach was actually fighting its own solution: our
shim's dlsym() call bound at link time to libdl.a's STUB dlsym (a
five-line function inside libdl_static.o that just returns NULL and sets
dlerror to "libdl.a is a stub --- use libdl.so instead"). NDK r19 and
glibc 2.34 both replaced libdl.a with empty stubs because dynamic loading
is now part of the main libc/bionic — so no amount of link-order
tinkering can make a static libdl.a dlsym actually work.

Remove pthread_shim.c, the cc::Build::new().file("cpp/pthread_shim.c")
step in build.rs, and the -Wl,--wrap=pthread_create rustc-link-arg. Keep
getauxval_fix.c because that one DOES work at link time (the symbol
override is for a function compiler-rt defines statically, not one that
would depend on the stub libdl.a/libc.a).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-09 13:52:53 +04:00
parent 5df9d418c9
commit e2e023d2bc
2 changed files with 0 additions and 94 deletions

View File

@@ -38,14 +38,6 @@ fn build_oboe_android(target: &str) {
.file("cpp/getauxval_fix.c")
.compile("getauxval_fix");
// pthread_shim: interpose pthread_create so Rust libstd can't use the
// broken static pthread_create stub (which calls __init_tcb, crashing
// in a .so). Our shim forwards to libc.so's real one via RTLD_NEXT.
// Compiled as its own static lib so the linker links it ahead of libstd.
cc::Build::new()
.file("cpp/pthread_shim.c")
.compile("pthread_shim");
let oboe_dir = fetch_oboe();
match oboe_dir {
Some(oboe_path) => {
@@ -112,12 +104,6 @@ fn build_oboe_android(target: &str) {
// Oboe requires Android log + OpenSLES backends
println!("cargo:rustc-link-lib=log");
println!("cargo:rustc-link-lib=OpenSLES");
// Wrap pthread_create: redirect every `pthread_create` reference to our
// `__wrap_pthread_create` in pthread_shim.c, which forwards to the real
// libc.so symbol via dlsym. Without this the linker binds to libstd's
// bundled broken static pthread_create stub (see pthread_shim.c).
println!("cargo:rustc-link-arg=-Wl,--wrap=pthread_create");
}
/// Recursively add all .cpp files from a directory to a cc::Build.