When building a GeMRTOS project with the Nios II toolchain, the linker may fail if functions are located in memory addresses more than 256MB apart. This occurs because the Nios II compiler uses the call instruction, which has a 256MB address boundary limitation. The fix is to use the -relax-all option, which switches to the callr instruction that has no such boundary constraint.
Issue Description #
This error occurs when functions are located in a memory region more than 256MB apart from the main memory. The Nios II compiler’s call instruction cannot reach across this boundary, causing a link failure. Note that using callr instead may slightly impact software performance, as it requires more assembly instructions than call.
How to Fix It #
In ACDS version 13.1 and later, the -relax-all option is available to force the use of the callr instruction. In Software Build Tools for Eclipse, add the -Wa,-relax-all option in the Application and/or BSP properties as user flags.
For GeMRTOS, the BSP is configured with -Wa,-relax-all as follows:
nios2-bsp hal $1 qsysgrtos.sopcinfo --cpu-name GeMRTOS_Multiprocessor_0_gemrtos_proc_1 --cmd "set_setting hal.enable_reduced_device_drivers true" --cmd "set_setting hal.stderr GeMRTOS_Multiprocessor_0_jtag_uart_1" --cmd "set_setting hal.stdin GeMRTOS_Multiprocessor_0_jtag_uart_0" --cmd "set_setting hal.stdout GeMRTOS_Multiprocessor_0_jtag_uart_0" --cmd "add_section_mapping rstaux GeMRTOS_Multiprocessor_0_rstaux_memory" --cmd "delete_memory_region GeMRTOS_Multiprocessor_0_onchip_memory2_2" --cmd "add_memory_region onchipdata GeMRTOS_Multiprocessor_0_onchip_memory2_2 0 512" --cmd "add_memory_region onchipcode GeMRTOS_Multiprocessor_0_onchip_memory2_2 512 15872" --cmd "add_section_mapping onchipdata onchipdata" --cmd "add_section_mapping onchipmem onchipcode" --cmd "set_setting hal.make.bsp_cflags_user_flags -Wa,-relax-all"And for the application:
nios2-app-generate-makefile.exe --bsp-dir ./${SOFTWARE_DIR_NAME}/${BSP_NAME} --app-dir ./${SOFTWARE_DIR_NAME}/${APP_NAME} --elf-name ${APP_NAME}.elf --set APP_CFLAGS_USER_FLAGS "-Wa,-relax-all" --inc-rdir ./${SOFTWARE_DIR_NAME}/${APP_NAME} --src-rdir ./${SOFTWARE_DIR_NAME}/${APP_NAME}Key Takeaways #
- The 256MB compile boundary is a Nios II
callinstruction hardware limitation — it is not a software or toolchain bug. - The fix is adding
-Wa,-relax-allto BSP and application user flags, which switches the compiler to thecallrinstruction with no address boundary limit. - GeMRTOS’s
gemrtos_build.shscript already includes-Wa,-relax-allin both the BSP and application build commands shown above. - There is a minor performance trade-off:
callruses more assembly instructions thancall, which may slightly increase code size and execution time.
Reference: Intel Support, Article 000079417.