[BUG] ndk-stack does not accommodate for the difference in relative PC computation between Android versions
- Dominant language
- No language data
- Stars
- 2.3k
- Forks
- 310
- PR merge metrics
- No merged PRs in 30d
Description
#### Description
Different Android versions compute relative PC printed in backtrace in different ways. Here are examples of the very same crash (same APK) running on three different devices with three different Android versions:
Android 8.1 on Pixel 2
```
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/walleye/walleye:8.1.0/OPM2.171026.006.G3/5513837:user/release-keys'
Revision: 'MP1'
ABI: 'arm'
pid: 10616, tid: 10669, name: 1.ui >>> io.flutter.examples.hello_world <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
r0 00000000 r1 000029ad r2 00000006 r3 00000008
r4 00002978 r5 000029ad r6 c89ff08c r7 0000010c
r8 00000000 r9 c9cc0ac1 sl dc026400 fp c8a0011c
ip c8ad651b sp c89ff078 lr e5a33c31 pc e5a2d782 cpsr 200e0030
backtrace:
#00 pc 0001a782 /system/lib/libc.so (abort+63)
#01 pc 002c9b91 /data/app/io.flutter.examples.hello_world-tiqKsqQ08yBXU2hWODwfTA==/lib/arm/libflutter.so (offset 0xff5000)
```
Android 10 on Pixel 4a
```
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/flame/flame:10/QQ3A.200805.001/6578210:user/release-keys'
Revision: 'MP1.0'
ABI: 'arm'
Timestamp: 2020-10-20 13:47:08-0700
pid: 20536, tid: 20586, name: 1.ui >>> io.flutter.examples.hello_world <<<
uid: 10222
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
r0 00000000 r1 0000506a r2 00000006 r3 c2132878
r4 c213288c r5 c2132870 r6 00005038 r7 0000016b
r8 c2132888 r9 c2132878 r10 c21328a8 r11 c2132898
ip 0000506a sp c2132848 lr ebe2c6e3 pc ebe2c6f6
backtrace:
#00 pc 0005f6f6 /apex/com.android.runtime/lib/bionic/libc.so (abort+166) (BuildId: 8c3173001a99af3ab544de85a610e066)
#01 pc 012beb91 /data/app/io.flutter.examples.hello_world-8nGxY8_VmIDo8hf0WEUzUQ==/lib/arm/libflutter.so (BuildId: f3226de58c8d62b2de4d5f7b4066c4a9c0f07b4e)
#02 pc 65000000
```
Android 11 on Pixel 3a
```
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'google/sargo/sargo:11/RP1A.201005.004/6782484:userdebug/dev-keys'
Revision: 'MP1.0'
ABI: 'arm'
Timestamp: 2020-10-22 09:28:26+0200
pid: 13676, tid: 13705, name: 1.ui >>> io.flutter.examples.hello_world <<<
uid: 10274
signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr --------
r0 00000000 r1 00003589 r2 00000006 r3 c7a87808
r4 c7a8781c r5 c7a87800 r6 0000356c r7 0000016b
r8 c7a87808 r9 c7a87818 r10 c7a87838 r11 c7a87828
ip 00003589 sp c7a877d8 lr f30433e1 pc f30433f4
backtrace:
#00 pc 000383f4 /apex/com.android.runtime/lib/bionic/libc.so (abort+172) (BuildId: 09f5dc86ced902a66ebda24ea42c217d)
#01 pc 012bfb91 /data/app/~~sGzta02j0vlFNEgy7PjzQA==/io.flutter.examples.hello_world-HrS9T-azBIoKi_uwl9sUkQ==/lib/arm/libflutter.so (BuildId: f3226de58c8d62b2de4d5f7b4066c4a9c0f07b4e)
#02 pc 66000000
```
Out of all three reports only the last one from Android 11 would symbolise correctly using `ndk-stack`:
```console
$ ~/android-ndk-r21d/ndk-stack -sym . < crashes.txt
********** Crash dump: **********
Build fingerprint: 'google/walleye/walleye:8.1.0/OPM2.171026.006.G3/5513837:user/release-keys'
#00 0x0001a782 /system/lib/libc.so (abort+63)
#01 0x002c9b91 /data/app/io.flutter.examples.hello_world-tiqKsqQ08yBXU2hWODwfTA==/lib/arm/libflutter.so (offset 0xff5000)
??
??:0:0
Crash dump is completed
********** Crash dump: **********
Build fingerprint: 'google/flame/flame:10/QQ3A.200805.001/6578210:user/release-keys'
#00 0x0005f6f6 /apex/com.android.runtime/lib/bionic/libc.so (abort+166) (BuildId: 8c3173001a99af3ab544de85a610e066)
#01 0x012beb91 /data/app/io.flutter.examples.hello_world-8nGxY8_VmIDo8hf0WEUzUQ==/lib/arm/libflutter.so (BuildId: f3226de58c8d62b2de4d5f7b4066c4a9c0f07b4e)
dart::DN_HelperInternal_makeListFixedLength(dart::Isolate*, dart::Thread*, dart::Zone*, dart::NativeArguments*)
/usr/local/google/home/vegorov/src/flutter/engine/src/out/android_debug/../../third_party/dart/runtime/lib/growable_array.cc:84:3
dart::BootstrapNatives::DN_Internal_makeListFixedLength(dart::Thread*, dart::Zone*, dart::NativeArguments*)
/usr/local/google/home/vegorov/src/flutter/engine/src/out/android_debug/../../third_party/dart/runtime/lib/growable_array.cc:83:1
#02 0x65000000
Crash dump is completed
********** Crash dump: **********
Build fingerprint: 'google/sargo/sargo:11/RP1A.201005.004/6782484:userdebug/dev-keys'
#00 0x000383f4 /apex/com.android.runtime/lib/bionic/libc.so (abort+172) (BuildId: 09f5dc86ced902a66ebda24ea42c217d)
#01 0x012bfb91 /data/app/~~sGzta02j0vlFNEgy7PjzQA==/io.flutter.examples.hello_world-HrS9T-azBIoKi_uwl9sUkQ==/lib/arm/libflutter.so (BuildId: f3226de58c8d62b2de4d5f7b4066c4a9c0f07b4e)
dart::DN_HelperObject_dumpStack(dart::Isolate*, dart::Thread*, dart::Zone*, dart::NativeArguments*)
/usr/local/google/home/vegorov/src/flutter/engine/src/out/android_debug/../../third_party/dart/runtime/lib/object.cc:130:5
dart::BootstrapNatives::DN_Object_dumpStack(dart::Thread*, dart::Zone*, dart::NativeArguments*)
/usr/local/google/home/vegorov/src/flutter/engine/src/out/android_debug/../../third_party/dart/runtime/lib/object.cc:100:1
#02 0x66000000
```
This is not surprising: `ndk-stack` simply passes PCs it extracts from crash dumps _as is_ into `llvm-symbolizer` (or `addr2line`). From what I can see this always was the behaviour (even when it was implemented as a C program). Both of these tools expect VMAs - however only Android 11 prints correct VMA.
Android 10 is off by 0x1000 (seems to be load bias - difference between .text section file offset and VMA): `012beb91 - 012bfb91 = 0x1000`.
Android 8.1 seems to print offset into RX section - which is off from PC VMA by .text section VMA aligned down to the page size:
```console
$ ~/android-ndk-r21d/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android-readelf -l libflutter.so | grep 'R E'
LOAD 0xff57c0 0x00ff67c0 0x00ff67c0 0x53f870 0x53f870 R E 0x1000
```
Observe that `0x00ff67c0 & ~0xFFF = 0xff6000` and `0xff6000 + 002c9b91 = 0x12bfb91`.
For your convenience [this archive](https://drive.google.com/file/d/1fSGmQUIWvn2UtA9hvELKt9iZxFzdMCB8/view?usp=sharing) (shared with Google only) contains both crashing APK and a library with debugging information.
I suspect this might have been unnoticed over the years because GCC and LLVM lay out binaries in a slightly different way, so things might have worked okay with GCC and got broken with LLVM binaries.
#### Environment Details
Not all of these will be relevant to every bug, but please provide as much
information as you can.
* NDK Version: 21.3.6528147
* Build system:
* Host OS: Mac
* ABI:
* NDK API level:
* Device API level:
Contributor guide
Assessment
This issue has not been assessed yet.