ARM Cortex-M7 long branch get error "relocation truncated to fit: R_ARM_PREL31" at compiling time

0

I'm developing an embedded system with NXP's I.MXRT Series Cortex-M7 chip. I need relocation some C function in RAM(ITCM) while not in Flash. Address of ITCM begin at 0x00000000, Flash begin at 0x60000000. So a function locating at Flash call a function locating at ITCM will perform a long branch. But It gets a compiling error

(.ARM.exidx.itcm.text+0x0): relocation truncated to fit: R_ARM_PREL31 against `.itcm.text'

Here is my code

__attribute__ ((long_call,section(".itcm.text"),noinline))
int foo(int k)
{
     return k + 1;
}

My linkscript

MEMORY
{
 /*
 *  SPI Flash 
 *  
 *  
 */
ITCM(xrw) : ORIGIN = 0x00000000, LENGTH = 128K
DTCM (xrw) : ORIGIN = 0x20000000, LENGTH = 256K
RAM (xrw) : ORIGIN =   0x20200000, LENGTH = 256K
FLASH (rx) : ORIGIN =  0x60000000, LENGTH = 4096K
}
 /*************omit***************/
_siitcm = LOADADDR(.itcm.text);
.itcm.text : ALIGN(4)
{
    __itcm_start__ = .;
    *(.itcm.text .itcm.text.*)
    . = ALIGN(4);
    __itcm_end__ = .;
} >ITCM AT>FLASH

Compiler flags are

arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb ${FP_FLAGS} -std=c++11 -O3 -munaligned-access -ffunction-sections -fdata-sections -ffreestanding

Linker flags are

"arm-none-eabi-gcc -mcpu=cortex-m7 -mthumb ${FP_FLAGS} -std=c++11 -O3 -munaligned-access -ffunction-sections -fdata-sections -ffreestanding -T ${MEM_LD_FILE} -T ${LIBS_LD_FILE} -T ${SECTIONS_LD_FILE} -nostartfiles -Xlinker -gc-sections -u _printf_float -Wl,-Map=${TARGET_MAP} --specs=nano.specs"

It seems the error occurs when branch address is greater than 0x40000000. So, how to fix this issue?

/* Second Edition */

I have solved the issue by adding a compiler flag -fno-exceptions. But I don't know why?

gcc
arm
cortex-m
asked on Stack Overflow Oct 4, 2018 by Hyz Yuzhou • edited Oct 8, 2018 by Hyz Yuzhou

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0