fix: Android SIGSEGV caused by weak sdallocx symbol in aws-lc-sys#2
fix: Android SIGSEGV caused by weak sdallocx symbol in aws-lc-sys#2MrImmortal09 merged 1 commit intomainfrom
Conversation
|
Ref: 1. BoringSSL (and forks like AWS-LC)The root cause of this hack originates directly in BoringSSL (Google's OpenSSL fork, which // BoringSSL's crypto/mem.c
void sdallocx(void *ptr, size_t size, int flags);
__attribute((weak, noinline))
void sdallocx(void *ptr, size_t size, int flags) {
free(ptr);
}Projects that consume BoringSSL/AWS-LC on Android often run into the aforementioned linker bug and have to override it with a strong symbol in their own codebase, exactly as Fedimint did. 2. React Native (via Meta's
|
Problem
On Android, the app crashes with
SIGSEGV(signal 11, "trying to execute non-executable memory") during federation join. The crash occurs insideaws_lc_sysduring jitter entropy initialization:Root cause:
aws-lc-sysdeclaressdallocx(a jemalloc deallocator) as a weak symbol and guards calls withif (sdallocx). On Android's Bionic linker, weak undefined symbols have a split resolution:ifcheck) → resolves to the PLT stub address (non-NULL)So the null check passes, but the call jumps to address 0 in
.bss— crash.Fix
sdallocx_stub.c— Provides strong definitions ofsdallocx,sallocx, andnallocxthat delegate to standardfree()/malloc(), ensuring both GOT entries resolve to valid function addresses.build.rs— Conditionally compiles the stub via thecccrate whentarget_os == "android".lib.rs— Referencessdallocxviaextern "C"+#[used] staticto force the linker to include the strong symbol.Cargo.toml— Pinsaws-lc-rsto=1.15.1(aws-lc-sys v0.34.0) to avoid a separate cmake bug in v0.35.0 that adds-DCMAKE_OSX_ARCHITECTURESfor Android targets on macOS hosts.Also switched the database path constant from
fedimint.redbtofedimint_dbto match the RocksDB directory-based storage.Verified