this is my code and I want to run it on a cortex-m4 linux based board (stm32f429) but before that I want to test my program on my pc using qemu.
#include <iostream>
int main()
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
I have compiled it with this command : arm-linux-gnueabi-g++ -static -mcpu=cortex-m4 hello.cpp -o hello
and I checked the generated elf file with readelf
and this is the output:
$ readelf -A hello
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "7E-M"
Tag_CPU_arch: v7E-M
Tag_CPU_arch_profile: Microcontroller
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_rounding: Needed
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_CPU_unaligned_access: v6
this is how I'm trying to emulate it: qemu-arm -cpu cortex-m4 hello
but it throws this error:
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction
even when I tryied to run it on my physical board, my kernel throwed error -8
which is a ENOEXEC
error or basicaly: Exec format error
I tryed it with all cortex-m CPUs but none of them worked (cortex m0, m3, m4, m7)
what is wrong with my elf file? why qemu and my physical board throws this error?