kubo39's blog

ただの雑記です。

Ubuntu14.04にARM(64bit)環境

さきほどは32bit環境だったので、今度は64bit環境を入れます。ARM64bitはaarch64と呼ばれます。

$ sudo aptitude install gcc-aarch64-linux-gnu -y

さっきの記事と同じですが

$ aarch64-linux-gnu-gcc hello.c
$ qemu-aarch64 -L /usr/aarch64-linux-gnu a.out
Hello.

GDBによるデバッグ方法なんですが、aarch64と名のついたパッケージがなくてどうするのか悩んでたんですが、gdb-multiarch というパッケージを試したらうまくいきました。

 $ gdb-multiarch -q ./a.out 
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) set sysroot /usr/aarch64-linux-gnu/
(gdb) target remote :1234
Remote debugging using :1234
Reading symbols from /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1...(no debugging symbols found)...done.
Loaded symbols for /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1
0x0000004000801f40 in ?? () from /usr/aarch64-linux-gnu/lib/ld-linux-aarch64.so.1
(gdb) b main
Breakpoint 1 at 0x4005e0
(gdb) cont
Continuing.

Breakpoint 1, 0x00000000004005e0 in main ()
(gdb) disas
Dump of assembler code for function main:
   0x00000000004005d0 <+0>:     stp     x29, x30, [sp,#-16]!
   0x00000000004005d4 <+4>:     mov     x29, sp
   0x00000000004005d8 <+8>:     adrp    x0, 0x400000
   0x00000000004005dc <+12>:    add     x0, x0, #0x688
=> 0x00000000004005e0 <+16>:    bl      0x400460 <puts@plt>
   0x00000000004005e4 <+20>:    mov     w0, #0x0                        // #0
   0x00000000004005e8 <+24>:    ldp     x29, x30, [sp],#16
   0x00000000004005ec <+28>:    ret
End of assembler dump.