Search code examples
linuxgccmakefilearmcross-compiling

How can I fix this cross-compilation linking error


I am trying to cross-compile a project on a linux x86_64 machine for an arm target, I am using gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf.

The error I am getting during compilation is:

/home/zoist/workspace/gcc-linaro-7.4.1-2019.02-x86_64_arm-linux-gnueabihf/bin/../lib/gcc/arm-linux-gnueabihf/7.4.1/libgcc.a(_dvmd_lnx.o): In function `__aeabi_idiv0':
/home/tcwg-buildslave/workspace/tcwg-make-release_0/snapshots/gcc.git~linaro-7.4-2019.02/libgcc/config/arm/lib1funcs.S:1545: undefined reference to `raise'
collect2: error: ld returned 1 exit status

My compilation flags are:

CFLAGS  = -mtune=cortex-a9 -march=armv7-a -Wall -Werror  \
          -nostdlib -marm -mfloat-abi=hard -mfpu=neon-vfpv4 -mcpu=cortex-a9
ASFLAGS = -D__ASSEMBLY__ $(CFLAGS)
LDFLAGS = -Wl,-L$(CROSS_COMPILE_DIR)/lib/gcc/arm-linux-gnueabihf/7.4.1/ -lgcc -Wl,-T$(LINK_SCRIPT_GEN) -nostdlib -Wl,--build-id=none
LDLIBS  = -Wl,-T$(LINK_SCRIPT_GEN) -lgcc

I have spent time reading similar topics online but cannot resolve my problem. Are there suggestions on how I can fix this issue?

Please let me know if you would require more information.

Edit:

The full command causing the error is

arm-linux-gnueabihf-gcc -Wl,-L/lib/gcc/arm-linux-gnueabihf/7.4.1/ -lgcc -Wl,-T../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/firmware.lnk -nostdlib -Wl,--build-id=none -o ../../../../build/tests/arm32/vexpress-a9/freertos/freertos.elf ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/basic_irq.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/basic_stdio.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/basic_string.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_ro.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_rw.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_strerror.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_support.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_sw.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/libfdt/fdt_wip.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/pic/gic.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/serial/pl01x.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/sys/vminfo.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../../common/basic/timer/sp804.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/arch_cache_v7.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/arch_irq.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/arch_math.o ../../../../build/tests/arm32/vexpress-a9/freertos/../basic/arch_board.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/croutine.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/event_groups.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/list.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/portable/MemMang/heap_4.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/queue.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/stream_buffer.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/tasks.o ../../../../build/tests/arm32/vexpress-a9/freertos/FreeRTOS/Source/timers.o ../../../../build/tests/arm32/vexpress-a9/freertos/arm_entry_v7.o ../../../../build/tests/arm32/vexpress-a9/freertos/glue.o ../../../../build/tests/arm32/vexpress-a9/freertos/main.o ../../../../build/tests/arm32/vexpress-a9/freertos/port/port.o ../../../../build/tests/arm32/vexpress-a9/freertos/port/portASM.o ../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/firmware.lnk -Wl,-T../../../../build/tests/arm32/vexpress-a9/freertos/../../common/basic/firmware.lnk -lgcc

Solution

  • The arm-linux-gnueabihf cross compiler is the variant for Linux targets which requires some (Linux) OS support as the undefined reference of the raise Linux system call indicates.
    When building a bare metal/FreeRTOS application an appropriate cross compiler has to be used. For instance the bare metal (non OS) GCC variant for 32 bit ARM CPUs is arm-none-eabi.
    Using a bare metal cross compiler should solve the issue you’ve encountered.