## W/static linking
This is our binary located on our Linux x86_64 machine:
```
#include <stdio.h>
const char msg[] = "Hello, EABI!\n";
void main() {
asm volatile (
"ldr r0, =msg\n"
"mov r1, r0\n"
"mov r0, #1\n"
"mov r2, #14\n"
"mov r7, #4\n"
"svc #0\n"
"mov r7, #1\n"
"mov r0, #0\n"
"svc #0\n"
);
}
```
We compile it, statically:
```
root@ubuntu:/home/ubuntu# arm-linux-gnueabi-gcc test.c -o hello -static
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, BuildID[sha1]=561da8abdb7a9cf6a6383fdda2701d19dbaf9e03, for GNU/Linux 3.2.0, not stripped
```
To run it we can just use:
```
root@ubuntu:/home/ubuntu# qemu-arm hello
Hello, EABI!
```
## W/dynamic linking
We compile the binary without the `-static`flag:
```
root@ubuntu:/home/ubuntu# arm-linux-gnueabi-gcc test.c -o hello
root@ubuntu:/home/ubuntu# file hello
hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, BuildID[sha1]=47a7f4209de48c9f3cb8bc62c40ac7d20e55cb9c, for GNU/Linux 3.2.0, not stripped
```
To run it we need a couple of things, but first let's try it the same way as before:
```
root@ubuntu:/home/ubuntu# qemu-arm hello
qemu-arm: Could not open '/lib/ld-linux.so.3': No such file or directory
```
This happens because `qemu-arm`is expecting the `ld-linux.so.3`interpreter, and the default env variable (the path to find this interpreter) is: `QEMU_LD_PREFIX = /etc/qemu-binfmt/arm` which doesn't have the required file.
For that we need to compile the binary again, but this time, we specify the interpreter located in the `arm-rootfs`. What is `arm-rootfs`?
Since we are running inside a x86_64 linux machine, we only have x86_64 interpreters/files. To solve this, we need to install a specific root filesystem for ARM, that contains all these interpreters:
```
mkdir -p ~/arm-rootfs
sudo debootstrap --arch=armhf --foreign bookworm ~/arm-rootfs http://deb.debian.org/debian # first stage
```
Let's compile the binary again, but this time, specifying the interpreter that's inside the `arm-rootfs`.
```
arm-linux-gnueabi-gcc test.c -o hello -Wl,--dynamic-linker=/root/arm-rootfs/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3
```
And, when running the binary, we can't forget to specify the `arm-rootfs`:
```
root@ubuntu:/home/ubuntu# qemu-arm -L ~/arm-rootfs hello
Hello, EABI!
```