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

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

Setup

$ 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/ld-linux-aarch64.so.1: 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

message:
    .asciz "Hello\n"

.section .text
.global _start

_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) set architecture aarch64
(gdb) target remote :9999
Remote debugging using :9999
0x00000000004000b0 in _start ()
(gdb) set disassemble-next-line on
posted @ 2023-12-15 00:14  摩斯电码  阅读(71)  评论(0编辑  收藏  举报