Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(cymbal): cover android ndk shared objects in the native path (#74430)

Catalin92d264464c5a
diff --git a/cli/tests/debug_symbols.rs b/cli/tests/debug_symbols.rs
index 5e83ee7fd3ed..d0d9729efe0d 100644
--- a/cli/tests/debug_symbols.rs
+++ b/cli/tests/debug_symbols.rs
@@ -76,7 +76,9 @@ fn extracts_debug_ids_matching_cymbal_fixtures() {
fn discovers_and_packages_elf_files() {
let report = discover(&fixtures_dir()).unwrap();
- // The three uncompressed ELF fixtures are found and valid
+ // The four uncompressed ELF fixtures are found and valid, including the
+ // aarch64-linux-android shared object, whose chunk id must match what an
+ // Android SDK derives from a tombstone's per-frame GNU build id
let mut debug_ids: Vec<&str> = report.files.iter().map(|f| f.debug_id.as_str()).collect();
debug_ids.sort();
assert_eq!(
@@ -85,6 +87,7 @@ fn discovers_and_packages_elf_files() {
"140ab543-c098-09dc-22b6-11f72e46d6fe",
"7561847b-1054-7eb3-7763-4415adfaa134",
"850c70a2-6592-a70c-3e49-c0e443794d23",
+ "c393685c-6edc-d276-cbd6-37e4c8b4e2aa",
]
);
// The classification fixtures in the same directory triage instead
diff --git a/rust/cymbal/src/core/types/langs/native.rs b/rust/cymbal/src/core/types/langs/native.rs
index c690569d8669..7b060082a0f5 100644
--- a/rust/cymbal/src/core/types/langs/native.rs
+++ b/rust/cymbal/src/core/types/langs/native.rs
@@ -1105,6 +1105,11 @@ mod test {
// test_rust_binary: debug_id d1dea836-4ad3-daad-dd96-0e8626f766e1,
// charge at 0x10640, lookup(0x10644) ->
// core::hint::black_box inlined into charge
+ // libtest_android.so: debug_id c393685c-6edc-d276-cbd6-37e4c8b4e2aa,
+ // preferred base 0, JNI entry at 0x4448,
+ // lookup(0x43d8) -> engine::inlined_leaf (line 12)
+ // inlined into engine::process_frame (entry 0x43cc),
+ // lookup(0x4454) -> the JNI entry's call site (line 27)
/// Non-PIE ELF: the binary links at a fixed base (0x1000000) and loads
/// there unchanged, so image_addr equals the link-time base.
@@ -1389,6 +1394,89 @@ mod test {
assert_eq!(frames[1].lang, "go");
}
+ /// Android NDK-shaped fixture: an aarch64-linux-android shared object
+ /// (JNI entry, Itanium-mangled C++, inlined leaf). Addresses are
+ /// synthesized the way an SDK would from a tombstone: the tombstone's
+ /// per-frame `rel_pc` is an ELF-relative address, so `image_addr` is
+ /// recovered as `pc - rel_pc` without knowing the real mapping layout.
+ #[sqlx::test(migrations = "./tests/test_migrations")]
+ async fn test_native_symbolication_android_ndk_shared_object(db: sqlx::PgPool) {
+ use crate::frames::RawFrame;
+
+ const ELF: &[u8] = include_bytes!("../../../../tests/static/native/libtest_android.so");
+
+ // Pin the debug id vocabulary: the CLI derives the chunk id from the
+ // ELF at upload, while an Android SDK would derive it from the
+ // tombstone's per-frame GNU build id (first 16 bytes, first three
+ // fields byte-swapped). Both must land on symbolic's derivation.
+ let object = symbolic::debuginfo::Object::parse(ELF).unwrap();
+ let chunk_id = object.debug_id().to_string();
+ assert_eq!(chunk_id, "c393685c-6edc-d276-cbd6-37e4c8b4e2aa");
+
+ let catalog = catalog_for_chunk(&db, &chunk_id, zip_fixture(ELF, None)).await;
+
+ // Android-typical load base. The fixture's rel_pc values are ELF
+ // vaddrs (preferred base 0), including the exec segment's nonzero
+ // load bias (p_vaddr 0x43cc vs p_offset 0x3cc from the NDK's 16 KiB
+ // max-page-size, the APK-embedded mapping shape).
+ let base = 0x7a12_3450_0000u64;
+ let debug_images = vec![debug_image_at(&chunk_id, base)];
+
+ // Tombstone pcs are already the right lookup address (the leaf is
+ // the faulting instruction and libunwindstack rewinds caller pcs to
+ // the call instruction), so the SDK biases instruction_addr by +1 to
+ // cancel the uniform -1 return-address adjustment applied here. The
+ // addresses below model that wire value.
+ //
+ // Crash leaf: faulting instruction 0x43d8, inside inlined_leaf as
+ // inlined into engine::process_frame; sent as 0x43d9, resolved at
+ // 0x43d8.
+ let frame = RawFrame::Native(native_frame_at(base + 0x43d9, base));
+ let frames = frame.resolve(1, &catalog, &debug_images, 15).await.unwrap();
+
+ assert_eq!(
+ frames.len(),
+ 2,
+ "expected inline expansion, got: {frames:#?}"
+ );
+ assert!(frames.iter().all(|f| f.resolved));
+ assert_eq!(
+ frames[0].resolved_name.as_deref(),
+ Some("engine::process_frame")
+ );
+ assert_eq!(
+ frames[1].resolved_name.as_deref(),
+ Some("engine::inlined_leaf")
+ );
+ assert_eq!(frames[1].source.as_deref(), Some("test_android.cpp"));
+ assert_eq!(frames[1].lang, "cpp");
+ // The exact crash line: the +1 bias keeps the lookup on the
+ // faulting instruction instead of shifting one line-table row up.
+ assert_eq!(frames[1].line, Some(12));
+
+ // Caller: the JNI entry point (extern "C", so the name survives
+ // undecorated). The unwinder already rewound the arm64 return
+ // address 0x4458 to the call instruction 0x4454; sent as 0x4455,
+ // resolved at 0x4454. Without the bias the -1 here would adjust it
+ // a second time, off the call's source line.
+ let frame = RawFrame::Native(native_frame_at(base + 0x4455, base));
+ let resolved = frame
+ .resolve(1, &catalog, &debug_images, 15)
+ .await
+ .unwrap()
+ .pop()
+ .unwrap();
+
+ assert!(resolved.resolved, "{:?}", resolved.resolve_failure);
+ assert_eq!(
+ resolved.resolved_name.as_deref(),
+ Some("Java_com_example_app_MainActivity_nativeRender")
+ );
+ assert_eq!(resolved.lang, "cpp");
+ // The call's own line, not the row before it.
+ assert_eq!(resolved.line, Some(27));
+ }
+
/// Missing symbol set: the frame falls back to client-side enrichment and
/// records the failure reason instead of erroring the event.
#[sqlx::test(migrations = "./tests/test_migrations")]
diff --git a/rust/cymbal/tests/static/native/build.sh b/rust/cymbal/tests/static/native/build.sh
index 1df5d852460b..412be58e8f2b 100755
--- a/rust/cymbal/tests/static/native/build.sh
+++ b/rust/cymbal/tests/static/native/build.sh
@@ -40,6 +40,15 @@ zig cc -target x86_64-linux-gnu -O1 -Wl,--build-id=sha1 -o test_binary_nodebug t
llvm-objcopy --strip-debug test_binary_nodebug test_binary_nodebug
zig cc -target x86_64-linux-gnu -g -O1 "-fdebug-prefix-map=$PWD=/cymbal_tests/native" -Wl,--build-id=none -o test_binary_nobuildid test_binary.c
+# Android NDK-shaped fixture: an aarch64-linux-android shared object with a
+# JNI entry, Itanium-mangled C++, and an inlined leaf. Freestanding because
+# zig ships no bionic libc; the tests only need DWARF + build id + symbols.
+# max-page-size matches the NDK's 16 KiB default, giving the executable
+# segment the nonzero load bias real Android .so mappings have.
+zig c++ -target aarch64-linux-android -shared -fPIC -g -O1 -nostdlib \
+ -fno-exceptions -fno-rtti "-fdebug-prefix-map=$PWD=/cymbal_tests/native" \
+ -Wl,--build-id=sha1 -Wl,-z,max-page-size=16384 -o libtest_android.so test_android.cpp
+
# Rust fixture: real rustc-mangled symbols for the demangling assertions.
# zig is used as the cross linker via the zigcc-x86_64-linux wrapper.
cat > .zigcc-x86_64-linux <<'WRAP'
diff --git a/rust/cymbal/tests/static/native/libtest_android.so b/rust/cymbal/tests/static/native/libtest_android.so
new file mode 100755
index 000000000000..f50f32a1613b
Binary files /dev/null and b/rust/cymbal/tests/static/native/libtest_android.so differ
diff --git a/rust/cymbal/tests/static/native/test_android.cpp b/rust/cymbal/tests/static/native/test_android.cpp
new file mode 100644
index 000000000000..741db1a7b0e6
--- /dev/null
+++ b/rust/cymbal/tests/static/native/test_android.cpp
@@ -0,0 +1,28 @@
+// Android NDK-shaped fixture: a JNI entry point calling into mangled C++
+// with an inlined leaf, compiled as an aarch64-linux-android shared object.
+// Mirrors what an NDK crash reports: frames inside an APK-packaged .so.
+// Freestanding (no bionic): the binary is never executed by tests; it only
+// needs valid DWARF, Itanium-mangled symbols, and a GNU build id.
+using i64 = long long;
+
+namespace engine {
+
+__attribute__((always_inline)) inline i64 inlined_leaf(i64 v) {
+ volatile i64 x = v * 3;
+ return x + 1;
+}
+
+__attribute__((noinline)) i64 process_frame(i64 v) {
+ volatile i64 acc = 0;
+ for (int i = 0; i < 4; i++) {
+ acc += inlined_leaf(v + i);
+ }
+ return acc;
+}
+
+} // namespace engine
+
+extern "C" __attribute__((noinline)) i64
+Java_com_example_app_MainActivity_nativeRender(void*, void*, i64 v) {
+ return engine::process_frame(v) + 7;
+}