fix(android): use --wrap=pthread_create instead of raw symbol override
Build #10 failed with: ld.lld: error: duplicate symbol: pthread_create >>> defined at pthread_shim.c:30 >>> ... in archive libpthread_shim.a (the other definition coming from libstd's bundled libc.a stub) The raw-symbol-override approach was naive: when two static archives both define the same symbol the linker refuses instead of picking one. Switch to GNU-ld's `--wrap=pthread_create` mechanism: - All `pthread_create` references get rewritten to `__wrap_pthread_create` - Our shim now defines `__wrap_pthread_create` (no symbol clash) - Inside the shim we `dlopen("libc.so")` + `dlsym("pthread_create")` to get the real runtime symbol directly, bypassing BOTH the broken static stub (libstd's libc.a copy) AND libstd's own pthread_create path - `--real_pthread_create` is deliberately NOT used — it would alias the same broken stub the wrap exists to avoid The wrap flag is emitted via `cargo:rustc-link-arg` in build.rs so it only affects the Android target (the Android-branch of build.rs is the only place that emits it). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -112,6 +112,12 @@ 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.
|
||||
|
||||
Reference in New Issue
Block a user