ARM Undefine Instruction


I am compiling in IDE DS-5 an embedded C software for a NXP IMX6UL bare metal product that is an ARM cortex A7 . I'm not using any operating system.

The issue is that I am using the compiler of AMR GCC 7.2.1 [arm-none-eabi] with the following flags:


C Flags: -march = armv7-a -mfpu = vfpv4 -mfloat-abi = hard -mthumb -o -g   -Wall -mno-unaligned-access -MMD -MP -fno-common -ffunction-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std = gnu99


ASM Flags: -march = armv7-a -mfpu = vfpv4 -mfloat-abi = hard -mthumb -g   -Wall -fno-common -function-sections -fdata-sections -ffreestanding -fno-builtin -mapcs -std = gnu99


Linker Flags: -march = armv7-a -mfpu = vfpv4 -mfloat-abi = hard -mthumb -g   -fno-common -function-sections -fdata-sections -ffreestanding -fno-builtin -mapcs --spec = nosys.specs --specs = nano.specs -Xlinker --gc-sections -Xlinker -statics -Xlinker -z - Xlinker muldefs

The program compiles well, 0 errors 0 warnings, but when using any function of libgcc or lib , functiones as fopen or printf , this day:


undefined instructions error

Some functions, such as malloc do not present the previous error, they simply return null .

My guess is that somehow the gcc libraries that are used are not compiled for this type of chipset so the obj Contain instructions that the processor does not understand. Although these libraries were downloaded from the same page of NXP .

Any ideas on how to solve this?

Here is the simplified code

    #include <stdio.h>

    int main(int argc, char *argv[])
        FILE * file = NULL;

        file = fopen("D:\Test.txt", "rb");
            printf("File opened");
            printf("Fail to open file");

        return 0;
asked by Thomas Jaquez 05.07.2018 в 22:12

1 answer


I can not prove the error first hand for lack of materials, but I can tell you that it is very likely that many of libc utilities depend on the existence of an operating system.

The gcc documentation warns you that the -ffreestanding flag (to compile without an operating system) implies that the standard library may not exist:




Assert that compilation targets to freestanding environment.   This implies -fno-builtin. A freestanding environment is one in which the   standard library may not exist, and program startup may not   necessarily be at main. The most obvious example is an OS kernel. Este   is equivalent to -fno-hosted.

Given my lack of experience in these cases, I can only guide you to continue searching for documentation on your specific programming platform. Maybe a place to start could be the page suggested by the GCC documentation itself that talks about the standards supported in the different implementations:

Language Standards supported by GCC

answered by 06.07.2018 в 23:28