Cannot execute binary file: Exec format error

Hello,
I tried to run a hello world application on the target but i got the following “cannot execute binary file: Exec format error”.

Commands on the host:

user@pc:~/yocto/workspace/tdx-dunfell/sdk$ uname -a
Linux PC 5.4.0-147-generic #164~18.04.1-Ubuntu SMP Tue Apr 4 00:20:20 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
user@pc:~/yocto/workspace/tdx-dunfell/sdk$ source environment-setup-armv7at2hf-neon-tdx-linux-gnueabi
user@pc:~/yocto/workspace/tdx-dunfell/sdk$ echo ${CC}
arm-tdx-linux-gnueabi-gcc -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard -fstack-protector-strong -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security --sysroot=/home/pc/yocto/workspace/tdx-dunfell/sdk/sysroots/armv7at2hf-neon-tdx-linux-gnueabi
user@pc:~/yocto/workspace/tdx-dunfell/sdk$ echo ${CFLAGS}
-O2 -pipe -g -feliminate-unused-debug-types
user@pc:~/yocto/workspace/tdx-dunfell/sdk$ cd /home/pc/vsc-workspace/c/hello
user@pc:~/vsc-workspace/c/hello$ ${CC} ${CFLAGS} -c hello.c -o hello
user@pc:~/vsc-workspace/c/hello$ file hello
hello: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
user@pc:~/vsc-workspace/c/hello$ scp hello root@192.168.1.21:
hello                                               100% 5424   924.6KB/s   00:00

Commands on the target:

root@apalis-tk1-03129001:~# uname -a
Linux apalis-tk1-03129001 5.4.193-rt74-5.7.1-devel+git.f5d73fd6e9f8 #1 SMP PREEx
root@apalis-tk1-03129001:~# ls -lh
-rw-r--r--    1 root     root        5.3K Sep 20 10:57 hello
root@apalis-tk1-03129001:~# chmod +x hello 
root@apalis-tk1-03129001:~# ./hello 
-sh: ./hello: cannot execute binary file: Exec format error
root@apalis-tk1-03129001:~# strace ./hello 
execve("./hello", ["./hello"], 0xbedc0d30 /* 21 vars */) = -1 ENOEXEC (Exec for)
strace: exec: Exec format error
+++ exited with 1 +++

Host: Linux MYPC 5.4.0-146-generic #163~18.04.1-Ubuntu SMP Mon Mar 20 15:02:59 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Target Som: Apalis TK1
Target Carrier: Ixora Carrier Board V1.1
Target Kernel: 5.4.193-rt74-5.7.1-devel+git.f5d73fd6e9f8

Hey @back4u,

The process you have shown does look like it should work. So initially I don’t see exactly why its having an an exec error, which is common with platform mismatch.

Our suggested method of a hello world can be found here: Custom Meta layers, recipes, and images. We would recommend making a custom layer and adding the hello world recipe. Would this method work for you?

I also see you are using the -rt- real time version for the kernel, is this intentional?

-Eric

You created an object file here and not an executable. That might be the issue.
Try to compile without “-c”

${CC} ${CFLAGS} hello.c -o hello

2 Likes

Hey @eric.tx,

I tried the a sample recipe and it worked. I used the rt version intentionally.

Thank you.

Hey @pajo,

You are definitely right. It fixed the problem.

Thank you.