Search code examples
gccarmcross-compilingarm64bare-metal

can a bare metal targeted binary be executed on a musllibc linux


my binary file compiled use toolchain from https://developer.arm.com/-/media/Files/downloads/gnu-a/10.3-2021.07/binrel/gcc-arm-10.3-2021.07-x86_64-arm-none-eabi.tar.xz,

with link flag:

-lstdc++ -Wl,-z,relro,-z,now -pass-exit-codes -lm -Wall '--specs=rdimon.specs' -lrdimon '-mcpu=cortex-a72.cortex-a53' -mthumb -static

compiled successfully, but when I execute this file on my openwrt router, it said:

Segmentation fault.

I think a bare-metal binary can also be executed on a linux system, it doesn't have any relationships with any os, only with a cpu model. Am I right?

FYI:

my chip model was rockchip 3389, armv8, 4 cortex-a72 core and 2 cortex-a53 core, run under aarch64 mode


Solution

    1. I think a bare-metal binary can also be executed on a linux system, it doesn't have any relationships with any os, only with a cpu model. Am I right? No, you are not.

    2. If your SoC has A72 and A53 cores, you are not using the right compiler: if you were writing bare-metal programs for it, you would have to use the aarch64-none-elf toolchain, and not the arm-none-eabi one,

    3. OpenWRT is a Linux operating system: on a glibc-based Linux system, you would use the aarch64-none-linux-gnu toolchain, but when targeting a musl-libc-based system, you should for example use a aarch64-linux-musl toolchain.