Skip to content

Instantly share code, notes, and snippets.

@ChronoMonochrome
Last active June 8, 2022 14:23
Show Gist options
  • Save ChronoMonochrome/711f5b7a09e97b7fe747c6107dfb4698 to your computer and use it in GitHub Desktop.
Save ChronoMonochrome/711f5b7a09e97b7fe747c6107dfb4698 to your computer and use it in GitHub Desktop.
Cross architecture (arm64) development cheat-sheet

Mount qemu qcow2 image

modprobe nbd max_part=8
qemu-nbd --connect=/dev/nbd0 bionic-server-cloudimg-arm64.img

Copy qemu-aarch64-static to the aarch64 filesystem and chroot

mkdir -p bionic-server-cloudimg-arm64
cd bionic-server-cloudimg-arm64
for f in dev dev/pts sys proc run ; do sudo mount --bind /$f ./$f ; done
cp /usr/bin/qemu-aarch64-static ./usr/bin
chroot .

Install dependencies

apt install binutils libc-dev

Link GAS assembly file to aarch64 libc

as -o chall_1.o chall_1.S
ld -o chall_1 -dynamic-linker /lib/ld-linux-aarch64.so.1 /usr/lib/aarch64-linux-gnu/crt1.o \
   /usr/lib/aarch64-linux-gnu/crti.o -lc chall_1.o /usr/lib/aarch64-linux-gnu/crtn.o

Useful links

How to mount a qcow2 disk image
Build qemu-user-static from source code
QEMU User Emulation
How to link a gas assembly program that uses the C standard library with ld without using gcc?
Ubuntu 18.04 LTS (Bionic Beaver) cloud builds
bionic-server-cloudimg-arm64.img
ld: cannot find crt1.o: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment