Working with 64-bit ARM Binaries on x86-64 Ubuntu


$ sudo apt install qemu-user
$ sudo apt-get install gcc-10-aarch64-linux-gnu
$ sudo apt install gcc-arm-none-eabi
$ sudo apt install gdb-multiarch

Compiling C to 64-bit ARM

Compile with the -static flag to avoid dynamic linking errors. (e.g. /lib/ No such file or director)

$ aarch64-linux-gnu-gcc-10 -static hello.c -o hello

Running ARM Binaries with QEMU

$ qemu-aarch64 ./hello

Assembling and Linking

.section .data

    .asciz "Hello\n"

.section .text
.global _start

    # write(stdout, "Hello\n")
    mov x0, #1
    ldr x1, =message
    mov x2, #6
    mov x8, #64
    svc #0

    # exit(123)
    mov x0, #123
    mov x8, #93
    svc #0
$ aarch64-linux-gnu-as hello.s -o hello.o
$ aarch64-linux-gnu-ld hello.o -o hello

Disassembling ARM Binaries

$ aarch64-linux-gnu-objdump -D hello

Debugging ARM Binaries in QEMU

$ qemu-aarch64 -g 9999 ./hello
$ gdb-multiarch -q ./hello
Reading symbols from ./hello...
(No debugging symbols found in ./hello)
(gdb) target remote :9999
Remote debugging using :9999
0x00000000004000b0 in _start ()
(gdb) set disassemble-next-line on