Open vsmenon opened 3 years ago
FYI - @mraleph - @jefflim-google was asking.
Also, is there an easy way to show ARM code from an x86 machine?
cc @alexmarkov
Currently, you can't get disassembly with --disassemble
from dart compile exe
or flutter build apk --release
because they use PRODUCT
build of gen_snapshot
which exclude disassembler. There is actually no good reason for why it excludes it (it historical). I have recently (see d7a57a5df4629045ebf406951eb73679a601c7b8) fixed it to include IL printer into PRODUCT
gen_snapshot
and I think we can similarly include disassembler as well.
That said you can do the following today:
flutter build apk --profile --extra-gen-snapshot-options=--disassemble
would work and dump disassemblyflutter build apk --release --extra-gen-snapshot-options=--print-flow-graph
or dart compile exe --extra-gen-snapshot-options=--print-flow-graph
would work and dump IL graphs (which are much easier to read than assembly anyway). flutter build apk --release --extra-gen-snapshot-options=--no-strip,--code-comments,--write-code-comments-as-synthetic-source-to=/tmp/comments.txt
after which you can use the right objdump
to disassemble ./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so
and see IL instructions along with disassembly, e.g. $ aarch64-linux-gnu-nm ./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so | grep main
0000000000034334 t Precompiled__IntegerImplementation_0150898_remainder_584
00000000000e7204 t Precompiled____main_3795
00000000000e7234 t Precompiled____main_main_3796
0000000000083df0 t Precompiled_ReadBuffer_get_hasRemaining_1949
$ aarch64-linux-gnu-objdump --source --disassemble=Precompiled____main_3795 ./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so
./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so: file format elf64-littleaarch64
Disassembly of section .text:
Disassembly of section .text:
00000000000e7204 <Precompiled____main_3795>:
EnterCallRuntimeFrame
EnterCallRuntimeFrame
EnterCallRuntimeFrame
B0
B1
Enter frame
e7204: a9bf79fd stp x29, x30, [x15, #-16]!
e7208: aa0f03fd mov x29, x15
CheckStackOverflow:8(stack=0, loop=0)
e720c: f9402350 ldr x16, [x26, #64]
e7210: eb1001ff cmp x15, x16
e7214: 540000c9 b.ls e722c <Precompiled____main_3795+0x28> // b.plast
StaticCall:10( runApp<0> , result_type = T{Null?})
e7218: 97fef350 bl a3f58 <Precompiled____runApp_2550>
ParallelMove r0 <- C
e721c: aa1603e0 mov x0, x22
Return:12(v0)
e7220: aa1d03ef mov x15, x29
e7224: a8c179fd ldp x29, x30, [x15], #16
e7228: d65f03c0 ret
CheckStackOverflowSlowPath
e722c: 97fffd11 bl e6670 <Precompiled_Stub__iso_stub_StackOverflowSharedWithoutFPURegsStub>
e7230: 54ffff4e b.al e7218 <Precompiled____main_3795+0x14>
This is on Linux using aarch64
binutils (available via sudo apt-get install binutils-aarch64-linux-gnu
, similarly you can install binutils for ARM).
Alternatively if you have Android NDK installed (which you often do), you can look for llvm-objdump
there. It has slightly different flags and format of the output, but the idea is the same (you can replace linux
below with darwin
on Mac).
$ ${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-objdump --source --disassemble-symbols=Precompiled____main_3795 ./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so
./build/app/intermediates/merged_native_libs/release/out/lib/arm64-v8a/libapp.so: file format elf64-littleaarch64
Disassembly of section .text:
00000000000e7204 <Precompiled____main_3795>:
; Enter frame
e7204: fd 79 bf a9 stp x29, x30, [x15, #-16]!
e7208: fd 03 0f aa mov x29, x15
; CheckStackOverflow:8(stack=0, loop=0)
e720c: 50 23 40 f9 ldr x16, [x26, #64]
e7210: ff 01 10 eb cmp x15, x16
e7214: c9 00 00 54 b.ls 0xe722c <Precompiled____main_3795+0x28>
; StaticCall:10( runApp<0> , result_type = T{Null?})
e7218: 50 f3 fe 97 bl 0xa3f58 <Precompiled____runApp_2550>
; ParallelMove r0 <- C
e721c: e0 03 16 aa mov x0, x22
; Return:12(v0)
e7220: ef 03 1d aa mov x15, x29
e7224: fd 79 c1 a8 ldp x29, x30, [x15], #16
e7228: c0 03 5f d6 ret
; CheckStackOverflowSlowPath
e722c: 11 fd ff 97 bl 0xe6670 <Precompiled_Stub__iso_stub_StackOverflowSharedWithoutFPURegsStub>
e7230: 4e ff ff 54 b.al 0xe7218 <Precompiled____main_3795+0x14>
Today:
provides a convenient way to view disassembled code, but only for JIT mode.
AFAIK, you need a checked SDK to view AOT disassembled code (which is more useful) - e.g.,:
Is there a way to integrate that into the Dart cli?
@jefflim-google