xref: /aosp_15_r20/system/unwinding/libunwindstack/AndroidVersions.md (revision eb293b8f56ee8303637c5595cfcdeef8039e85c6)
1*eb293b8fSAndroid Build Coastguard Worker# Unwinder Support Per Android Release
2*eb293b8fSAndroid Build Coastguard WorkerThis document describes the changes in the way the libunwindstack
3*eb293b8fSAndroid Build Coastguard Workerunwinder works on different Android versions. It does not describe
4*eb293b8fSAndroid Build Coastguard Workerevery change in the code made between different versions, but is
5*eb293b8fSAndroid Build Coastguard Workermeant to allow an app developer to know what might be supported
6*eb293b8fSAndroid Build Coastguard Workeron different versions. It also describes the different way an unwind
7*eb293b8fSAndroid Build Coastguard Workerwill display on different versions of Android.
8*eb293b8fSAndroid Build Coastguard Worker
9*eb293b8fSAndroid Build Coastguard Worker## Android 9 ("Pie", API level 28)
10*eb293b8fSAndroid Build Coastguard Workerlibunwindstack was first introduced in API level 28.
11*eb293b8fSAndroid Build Coastguard Worker
12*eb293b8fSAndroid Build Coastguard Worker* Supports up to and including Dwarf 4 unwinding information.
13*eb293b8fSAndroid Build Coastguard Worker  See http://dwarfstd.org/ for Dwarf standards.
14*eb293b8fSAndroid Build Coastguard Worker* Supports Arm exidx unwinding.
15*eb293b8fSAndroid Build Coastguard Worker* Supports the gdb JIT unwinding interface, which is how ART creates unwinding
16*eb293b8fSAndroid Build Coastguard Worker  information for the JIT'd Java frames.
17*eb293b8fSAndroid Build Coastguard Worker* Supports special frames added to represent an ART Java interpreter frame.
18*eb293b8fSAndroid Build Coastguard Worker  ART has marked the dex pc using cfi information that the unwinder
19*eb293b8fSAndroid Build Coastguard Worker  understands and handles by adding a new frame in the stacktrace.
20*eb293b8fSAndroid Build Coastguard Worker
21*eb293b8fSAndroid Build Coastguard Worker## Note
22*eb293b8fSAndroid Build Coastguard WorkerBy default, lld creates two separate maps of the elf in memory, one read-only
23*eb293b8fSAndroid Build Coastguard Workerand one read/executable. The libunwindstack on P and the unwinder on older
24*eb293b8fSAndroid Build Coastguard Workerversions of Android will not unwind properly in this case. For apps that
25*eb293b8fSAndroid Build Coastguard Workertarget API level 28 or older, make sure that `-Wl,--no-rosegment` is
26*eb293b8fSAndroid Build Coastguard Workerincluded in linker arguments when using lld.
27*eb293b8fSAndroid Build Coastguard Worker
28*eb293b8fSAndroid Build Coastguard Worker## Android 10 ("Q", API level 29)
29*eb293b8fSAndroid Build Coastguard Worker* Fix bug (b/109824792) that handled load bias data incorrectly when
30*eb293b8fSAndroid Build Coastguard Worker  FDEs use pc relative addressing in the eh\_frame\_hdr.
31*eb293b8fSAndroid Build Coastguard Worker  Unfortunately, this wasn't fixed correctly in Q since it assumes
32*eb293b8fSAndroid Build Coastguard Worker  that the bias is coming from the program header for the executable
33*eb293b8fSAndroid Build Coastguard Worker  load. The real fix was to use the bias from the actual section data and
34*eb293b8fSAndroid Build Coastguard Worker  is not completely fixed until API level 30. For apps targeting API level 29,
35*eb293b8fSAndroid Build Coastguard Worker  if it is being compiled with the llvm linker lld, it might be necessary
36*eb293b8fSAndroid Build Coastguard Worker  to add the linker option `-Wl,-zseparate-code` to avoid creating an elf
37*eb293b8fSAndroid Build Coastguard Worker  created this way.
38*eb293b8fSAndroid Build Coastguard Worker* Change the way the exidx section offset is found (b/110704153). Before
39*eb293b8fSAndroid Build Coastguard Worker  the p\_vaddr value from the program header minus the load bias was used
40*eb293b8fSAndroid Build Coastguard Worker  to find the start of the exidx data. Changed to use the p\_offset since
41*eb293b8fSAndroid Build Coastguard Worker  it doesn't require any load bias manipulations.
42*eb293b8fSAndroid Build Coastguard Worker* Fix bug handling of dwarf sections without any header (b/110235461).
43*eb293b8fSAndroid Build Coastguard Worker  Previously, the code assumed that FDEs are non-overlapping, and the FDEs
44*eb293b8fSAndroid Build Coastguard Worker  are always in sorted order from low pc to high pc. Thus the code would
45*eb293b8fSAndroid Build Coastguard Worker  read the entire set of CIEs/FDEs and then do a binary search to find
46*eb293b8fSAndroid Build Coastguard Worker  the appropriate FDE for a given pc. Now the code does a sequential read
47*eb293b8fSAndroid Build Coastguard Worker  and stops when it finds the FDE for a pc. It also understands the
48*eb293b8fSAndroid Build Coastguard Worker  overlapping FDEs, so find the first FDE that matches a pc. In practice,
49*eb293b8fSAndroid Build Coastguard Worker  elf files with this format only ever occurs if the file was generated
50*eb293b8fSAndroid Build Coastguard Worker  without an eh\_frame/eh\_frame\_hdr section and only a debug\_frame. The
51*eb293b8fSAndroid Build Coastguard Worker  other way this has been observed is when running simpleperf to unwind since
52*eb293b8fSAndroid Build Coastguard Worker  sometimes there is not enough information in the eh\_frame for all points
53*eb293b8fSAndroid Build Coastguard Worker  in the executable. On API level 28, this would result in some incorrect
54*eb293b8fSAndroid Build Coastguard Worker  unwinds coming from simpleperf. Nearly all crashes from API level 28 should
55*eb293b8fSAndroid Build Coastguard Worker  be correct since the eh\_frame information was enough to do the unwind
56*eb293b8fSAndroid Build Coastguard Worker  properly.
57*eb293b8fSAndroid Build Coastguard Worker* Be permissive of badly formed elf files. Previously, any detected error
58*eb293b8fSAndroid Build Coastguard Worker  would result in unwinds stopping even if there is enough valid information
59*eb293b8fSAndroid Build Coastguard Worker  to do an unwind.
60*eb293b8fSAndroid Build Coastguard Worker  * The code now allows program header/section header offsets to point
61*eb293b8fSAndroid Build Coastguard Worker    to unreadable memory. As long as the code can find the unwind tables,
62*eb293b8fSAndroid Build Coastguard Worker    that is good enough.
63*eb293b8fSAndroid Build Coastguard Worker  * The code allows program headers/section headers to be missing.
64*eb293b8fSAndroid Build Coastguard Worker  * Allow a symbol table section header to point to invalid symbol table
65*eb293b8fSAndroid Build Coastguard Worker    values.
66*eb293b8fSAndroid Build Coastguard Worker* Support for the linker read-only segment option (b/109657296).
67*eb293b8fSAndroid Build Coastguard Worker  This is a feature of lld whereby there are two sections that
68*eb293b8fSAndroid Build Coastguard Worker  contain elf data. The first is read-only and contains the elf header data,
69*eb293b8fSAndroid Build Coastguard Worker  and the second is read-execute or execute only that
70*eb293b8fSAndroid Build Coastguard Worker  contains the executable code from the elf. Before this, the unwinder
71*eb293b8fSAndroid Build Coastguard Worker  always assumed that there was only a single read-execute section that
72*eb293b8fSAndroid Build Coastguard Worker  contained the elf header data and the executable code.
73*eb293b8fSAndroid Build Coastguard Worker* Build ID information for elf objects added. This will display the
74*eb293b8fSAndroid Build Coastguard Worker  NT\_GNU\_BUILD\_ID note found in elf files. This information can be used
75*eb293b8fSAndroid Build Coastguard Worker  to identify the exact version of a shared library to help get symbol
76*eb293b8fSAndroid Build Coastguard Worker  information when looking at a crash.
77*eb293b8fSAndroid Build Coastguard Worker* Add support for displaying the soname from an apk frame. Previously,
78*eb293b8fSAndroid Build Coastguard Worker  a frame map name would be only the apk, but now if the shared library
79*eb293b8fSAndroid Build Coastguard Worker  in the apk has set a soname, the map name will be `app.apk!libexample.so`
80*eb293b8fSAndroid Build Coastguard Worker  instead of only `app.apk`.
81*eb293b8fSAndroid Build Coastguard Worker* Minimal support for Dwarf 5. This merely treats a Dwarf 5 version
82*eb293b8fSAndroid Build Coastguard Worker  elf file as Dwarf 4. It does not support the new dwarf ops in Dwarf 5.
83*eb293b8fSAndroid Build Coastguard Worker  Since the new ops are not likely to be used very often, this allows
84*eb293b8fSAndroid Build Coastguard Worker  continuing to unwind even when encountering Dwarf 5 elf files.
85*eb293b8fSAndroid Build Coastguard Worker* Fix bug in pc handling of signal frames (b/130302288). In the previous
86*eb293b8fSAndroid Build Coastguard Worker  version, the pc would be wrong in the signal frame. The rest of the
87*eb293b8fSAndroid Build Coastguard Worker  unwind was correct, only the frame in the signal handler was incorrect
88*eb293b8fSAndroid Build Coastguard Worker  in API level 28.
89*eb293b8fSAndroid Build Coastguard Worker* Detect when an elf file is not readable so that a message can be
90*eb293b8fSAndroid Build Coastguard Worker  displayed indicating that. This can happen when an app puts the shared
91*eb293b8fSAndroid Build Coastguard Worker  libraries in non-standard locations that are not readable due to
92*eb293b8fSAndroid Build Coastguard Worker  security restrictions (selinux rules).
93*eb293b8fSAndroid Build Coastguard Worker
94*eb293b8fSAndroid Build Coastguard Worker## Android 11 ("R", API level 30)
95*eb293b8fSAndroid Build Coastguard Worker* Display the offsets for Java interpreter frames. If this frame came
96*eb293b8fSAndroid Build Coastguard Worker  from a non-zero offset map, no offset is printed. Previously, the
97*eb293b8fSAndroid Build Coastguard Worker  line would look like:
98*eb293b8fSAndroid Build Coastguard Worker
99*eb293b8fSAndroid Build Coastguard Worker    #17 pc 00500d7a  GoogleCamera.apk (com.google.camera.AndroidPriorityThread.run+10)
100*eb293b8fSAndroid Build Coastguard Worker
101*eb293b8fSAndroid Build Coastguard Worker  to:
102*eb293b8fSAndroid Build Coastguard Worker
103*eb293b8fSAndroid Build Coastguard Worker    #17 pc 00500d7a  GoogleCamera.apk (offset 0x11d0000) (com.google.camera.AndroidPriorityThread.run+10)
104*eb293b8fSAndroid Build Coastguard Worker* Fix bug where the load bias was set from the first PT\_LOAD program
105*eb293b8fSAndroid Build Coastguard Worker  header that has a zero p\_offset value. Now it is set from the first
106*eb293b8fSAndroid Build Coastguard Worker  executable PT\_LOAD program header. This has only ever been a problem
107*eb293b8fSAndroid Build Coastguard Worker  for host executables compiled for the x86\_64 architecture.
108*eb293b8fSAndroid Build Coastguard Worker* Switched to the libc++ demangler for function names. Previously, the
109*eb293b8fSAndroid Build Coastguard Worker  demangler used was not complete, so some less common demangled function
110*eb293b8fSAndroid Build Coastguard Worker  names would not be properly demangled or the function name would not be
111*eb293b8fSAndroid Build Coastguard Worker  demangled at all.
112*eb293b8fSAndroid Build Coastguard Worker* Fix bug in load bias handling. If the unwind information in the eh\_frame
113*eb293b8fSAndroid Build Coastguard Worker  or eh\_frame\_hdr does not have the same bias as the executable section,
114*eb293b8fSAndroid Build Coastguard Worker  and uses pc relative FDEs, the unwind will be incorrect. This tends
115*eb293b8fSAndroid Build Coastguard Worker  to truncate unwinds since the unwinder could not find the correct unwind
116*eb293b8fSAndroid Build Coastguard Worker  information for a given pc.
117*eb293b8fSAndroid Build Coastguard Worker
118*eb293b8fSAndroid Build Coastguard Worker## Android 12 ("S", API level 31)
119*eb293b8fSAndroid Build Coastguard Worker* Fix bug where, if a shared library is dlopen'ed from within an apk file,
120*eb293b8fSAndroid Build Coastguard Worker  is not readable, and the shared library only produces a single read-
121*eb293b8fSAndroid Build Coastguard Worker  executable map for the elf data and executable data, the offset into the
122*eb293b8fSAndroid Build Coastguard Worker  apk will not be displayed. Previously the line would look like:
123*eb293b8fSAndroid Build Coastguard Worker
124*eb293b8fSAndroid Build Coastguard Worker    #01 pc 000000000222675c  GoogleCamera.apk
125*eb293b8fSAndroid Build Coastguard Worker
126*eb293b8fSAndroid Build Coastguard Worker  to:
127*eb293b8fSAndroid Build Coastguard Worker
128*eb293b8fSAndroid Build Coastguard Worker    #01 pc 000000000222675c  GoogleCamera.apk (offset 0x269f000)
129*eb293b8fSAndroid Build Coastguard Worker
130*eb293b8fSAndroid Build Coastguard Worker  If the apk file is readable, or dlopen'ing the shared library creates
131*eb293b8fSAndroid Build Coastguard Worker  a read-only map of the elf data, and a read-executable map of the
132*eb293b8fSAndroid Build Coastguard Worker  code, the offset will be displayed properly without this fix.
133*eb293b8fSAndroid Build Coastguard Worker
134*eb293b8fSAndroid Build Coastguard Worker## Android 15 ("V", API level 35)
135*eb293b8fSAndroid Build Coastguard Worker* Added support for a compressed .debug\_frame, compressed with either zlib or
136*eb293b8fSAndroid Build Coastguard Worker  zstd.
137