step D(android): compile cpp/getauxval_fix.c alongside hello.c
Fourth incremental variable. Adds the getauxval_fix.c shim from the legacy wzp-android crate (which has been shipping with it for months without issue) to our cc::Build on Android. The file defines a single getauxval() function that delegates to bionic's real runtime implementation via dlsym — this is needed because rustc links compiler-rt's broken static getauxval stub that SIGSEGVs in .so libraries loaded via dlopen (reads __libc_auxv which is NULL). Not imported from Rust. Goal: verify that adding a second C static archive (and especially one that overrides a libc-ish symbol) doesn't regress the working build. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,17 +16,22 @@ fn main() {
|
||||
println!("cargo:rerun-if-changed=../../.git/refs/heads");
|
||||
|
||||
// ─── Step A: single trivial cpp/hello.c compiled via cc::Build ─────────
|
||||
// We deliberately add this on Android only so we can verify that the
|
||||
// cc::Build → static archive → rustc-link pipeline itself does not
|
||||
// regress the working build #17. cpp/hello.c defines `wzp_hello_stub`
|
||||
// which is never called from Rust — if the crash comes back just from
|
||||
// adding a tiny C static lib, we know the build pipeline is the issue.
|
||||
// ─── Step D: also compile getauxval_fix.c (legacy wzp-android shim) ────
|
||||
// getauxval_fix.c overrides the broken static getauxval stub that
|
||||
// compiler-rt pulls in for Android targets. It's been shipping in the
|
||||
// legacy wzp-android .so for months without issue, so including it here
|
||||
// is low-risk — but it's an incremental variable we want to isolate.
|
||||
let target = std::env::var("TARGET").unwrap_or_default();
|
||||
if target.contains("android") {
|
||||
println!("cargo:rerun-if-changed=cpp/hello.c");
|
||||
cc::Build::new()
|
||||
.file("cpp/hello.c")
|
||||
.compile("wzp_hello");
|
||||
|
||||
println!("cargo:rerun-if-changed=cpp/getauxval_fix.c");
|
||||
cc::Build::new()
|
||||
.file("cpp/getauxval_fix.c")
|
||||
.compile("getauxval_fix");
|
||||
}
|
||||
|
||||
tauri_build::build()
|
||||
|
||||
26
desktop/src-tauri/cpp/getauxval_fix.c
Normal file
26
desktop/src-tauri/cpp/getauxval_fix.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* Override the broken static getauxval from compiler-rt/CRT.
|
||||
*
|
||||
* The static version reads from __libc_auxv which is NULL in shared libs
|
||||
* loaded via dlopen, causing SIGSEGV in init_have_lse_atomics at load time.
|
||||
* This version calls the real bionic getauxval via dlsym.
|
||||
*
|
||||
* Copied verbatim from crates/wzp-android/cpp/getauxval_fix.c — the legacy
|
||||
* wzp-android crate has been using this shim successfully for months.
|
||||
*/
|
||||
#ifdef __ANDROID__
|
||||
#include <dlfcn.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef unsigned long (*getauxval_fn)(unsigned long);
|
||||
|
||||
unsigned long getauxval(unsigned long type) {
|
||||
static getauxval_fn real_getauxval = (getauxval_fn)0;
|
||||
if (!real_getauxval) {
|
||||
real_getauxval = (getauxval_fn)dlsym((void*)-1L /* RTLD_DEFAULT */, "getauxval");
|
||||
if (!real_getauxval) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return real_getauxval(type);
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user