I installed FreeBSD 13.0 on a Raspberry Pi 4B, and tried to assemble and link a "Hello World" assembly program on it. Assembler (as) and linker (ld) produced output files without any error messages, but when I tried to run the program, I got the following error message:
ELF binary type "0" not known. Exec format error. Binary file not executable.
I used the following commands to assemble and link,
as hello.asm -o hello.o
ld hello.o -o hello
and here is the source code of my "Hello World" program hello.asm:
.global _start
.align 4
_start:
mov X0, #1
adr X1, helloworld
mov X2, #16
mov X16, #4
svc #0x80
mov X0, #0
mov X16, #1
svc #0x80
helloworld: .ascii "Hello Pi-World!\n"
My assembler and linker versions are:
as -v
GNU assembler version 2.37 (aarch64-portbld-freebsd13.0) using BFD version (GNU Binutils) 2.37
ld -v
LLD 11.0.1 (FreeBSD llvmorg-11.0.1-0-g43ff75f2c3fe-1300007) (compatible with GNU linkers)
and the file command gives
file hello
hello: ELF 64-bit LSB relocatable, ARM aarch64, version 1 (SYSV), not stripped
and my system details are
uname -a
FreeBSD BSD 13.0-RELEASE FreeBSD 13.0-RELEASE #0 releng/13.0-n244733-ea31abc261f: Fri Apr 9 06:06:55 UTC 2021 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/arm64.aarch64/sys/GENERIC arm64
Could anyone explain to me what the problem is, and how to fix it? Thanks.
EDIT: Posted a follow-up question on how to use system calls in FreeBSD on ARM64 architectures, see here.