#Android Arm Backtrace

1 messages · Page 1 of 1 (latest)

drifting mortar
#

I figure out a way to create Android aab using zig and debug them using Android Studio, while debugging I can have a perfectly fine stacktrace.

But when the program panics zigs (from popular zig-android repos) panichandler stack trace crashes even unwind.h crashes with SIGILL!

Native crash report prints a backtrace that just doesn’t make any cense printing a stack different from the one I have when debugging on Android Studio, addr2line also doesn’t work to resolve the backtrace.

What could be possibly the issue, for can’t printing a stacktrace at runtime and having a bad native crash backtrace?

Plus triggering a SIGSEV doesn’t go through the zig panic handle instead it goes to a function called art_sigsegv_fault

Edit: I captured the signal using sigaction but callstack in debug is lost

drifting mortar
#

I did manage to get the stack trace using libunwind! (unwind.h is deprecated I think) but itcan't resolve the symbol name at runtime, despite having the info somewhere in the so

What I can do is use dladdr to resolve the module relative address by subtracting info.dli_fbase from the ip reg with this result I can then plug into addr2line and find my stack trace

Android native crash still wrong and that is the portion that will get uploaded though the Play Store as an ARN

drifting mortar
#

from libunwid + dladdr

panic: !
  0 pc 0x0014d67c /data/app/com.zig.android/lib/arm/libgame.so!<unknown>
  1 pc 0x001434c0 /data/app/com.zig.android/lib/arm/libgame.so!<unknown>
  2 pc 0x00140694 /data/app/com.zig.android/lib/arm/libgame.so!<unknown>
  3 pc 0x000a60b5 /apex/com.android.runtime/lib/bionic/libc.so!<unknown>
  4 pc 0x00060785 /apex/com.android.runtime/lib/bionic/libc.so!<unknown>
#

android crash

Fatal signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0x8b3dad4c in tid 30692 (com.zig.android), pid 30647 (com.zig.android)
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'motorola/malta_l/malta:10/QOLS30.288-52-23/2c2b6:user/release-keys'
Revision: '0'
ABI: 'arm'
Timestamp: 2023-03-11 21:50:17-0300
pid: 30647, tid: 30692, name: com.zig.android  >>> com.zig.android <<<
uid: 10195
signal 4 (SIGILL), code 1 (ILL_ILLOPC), fault addr 0x8b3dad4c (*pc=0xe7ffdefe)
Abort message: 'panic: !'
    r0  00000000  r1  ffffffff  r2  00000054  r3  8b4d6cf0
    r4  8b151408  r5  8b152230  r6  8b152230  r7  00000078
    r8  000077b7  r9  000077b7  r10 b6307020  r11 8b152040
    ip  00000011  sp  8b14f388  lr  8b4d7240  pc  8b3dad4c

backtrace:
      #00 pc 000fbd4c  /data/app/com.zig.android/lib/arm/libgame.so!libgame.so (offset 0xf5000)
      #01 pc 001f823c  /data/app/com.zig.android/lib/arm/libgame.so!libgame.so (offset 0xf5000) (array_hash_map.ArrayHashMapUnmanaged(u64,debug.Dwarf.CompileUnit.SrcLocCache.LineEntry,array_hash_map.AutoContext(u64),false).getOrPutInternal__anon_61580+256)
      #02 pc 0013d678  /data/app/com.zig.android/lib/arm/libgame.so!libgame.so (offset 0xf5000) (android.App.immersiveMode+8912)
      #03 pc 001334bc  /data/app/com.zig.android/lib/arm/libgame.so!libgame.so (offset 0xf5000) (fmt.format_float.pow5Factor__anon_8708+244)
      #04 pc 00130690  /data/app/com.zig.android/lib/arm/libgame.so!libgame.so (offset 0xf5000) (fmt.format_float.writeDecimal__anon_8155+4220)
      #05 pc 000a60b3  /apex/com.android.runtime/lib/bionic/libc.so (__pthread_start(void*)+20) (BuildId: 4431b35d55c1d9b5f8568451110b8281)
      #06 pc 00060783  /apex/com.android.runtime/lib/bionic/libc.so (__start_thread+30) (BuildId: 4431b35d55c1d9b5f8568451110b8281)
glue: no `onPause`
#

I found that using @trap() instead of abort in the custom panicHanlder does a better job

drifting mortar
#

Ok, android unwind has a lot of bugs, this doc tells more about them and how to fix each one https://android.googlesource.com/platform/system/unwinding/+/master/libunwindstack/AndroidVersions.md

For my particular case adding --no-rosegment to ld did the trick, but acording with the docs there's way more cases that need to be managed

The real throuble is how I did that, and let me tell you it's so messy...

  • Zig just doesn't allow you to just pass linker args, to the linker
  • I can't build an object and link it because zig doesn't allowme to disable PIE when building object files (this is a bug)
  • The solution is to manyally re-link after zig links the final .so, I can do this but the cmd line needs arguments that I had to hard code for now 🙁