xpack-dev-tools / riscv-none-embed-gcc-xpack

DEPRECATED: Please update to risc-none-elf-gcc-xpack
MIT License
114 stars 30 forks source link

Link error with v8.3.0-2.3 `relocation truncated to fit: R_RISCV_JAL against symbol` #9

Closed bj-wanghz closed 4 years ago

bj-wanghz commented 4 years ago

Description

When building from my code, I got the following linkage errors with -O0 -ggdb options, while the building process would be done using only -Os and no -ggdb option.

build/kernel/libcpu/risc-v/k210/startup_gcc.o: in function `.L0 ':
/home/remember/my_work/k210-openmv_release/src/rt-thread/libcpu/risc-v/k210/startup_gcc.S:125:(.start+0x134): relocation truncated to fit: R_RISCV_JAL against symbol `secondary_cpu_c_start' defined in .text.secondary_cpu_c_start section in build/kernel/libcpu/risc-v/k210/cpuport_smp.o
build/kernel/libcpu/risc-v/common/context_gcc.o: in function `.L0 ':
/home/remember/my_work/k210-openmv_release/src/rt-thread/libcpu/risc-v/common/context_gcc.S:50:(.text+0x12): relocation truncated to fit: R_RISCV_JAL against symbol `rt_cpus_lock_status_restore' defined in .text.rt_cpus_lock_status_restore section in build/kernel/src/cpu.o
build/kernel/libcpu/risc-v/k210/interrupt_gcc.o: in function `.L0 ':
/home/remember/my_work/k210-openmv_release/src/rt-thread/libcpu/risc-v/k210/interrupt_gcc.S:77:(.text.entry+0x7c): relocation truncated to fit: R_RISCV_JAL against symbol `rt_hw_context_switch_exit' defined in .text section in build/kernel/libcpu/risc-v/common/context_gcc.o
collect2: error: ld returned 1 exit status
scons: *** [rtthread.elf] Error 1
scons: building terminated because of errors.

I posted an issue on Sifive Forum. And Jim Wilson guessed that maybe it has been fixed in some commit last year. I'm not sure if the Xpack version has included that.

Steps to Reproduce

Sorry, I cannot provide a testcase for now. As my code reproducing the problem is my whole product project.

Versions

xPack GNU RISC-V Embedded GCC v8.3.0-2.3

ilg-ul commented 4 years ago

This distribution uses the same sources and build options like the SiFive public distribution.

Please check if the issue is also present in the SiFive distribution.

bj-wanghz commented 4 years ago

The problem has been solved. There are jal instruction in these .S files. When the code size becomes large, the targets of jal may be beyond the address range it can access. Then the errors generate. call or tail should be used to invoke an external routine.

TommyMurphyTM1234 commented 4 years ago

I presume that this relates to the same issue?

https://forums.sifive.com/t/link-error-relocation-truncated-to-fit-r-riscv-jal-against-symbol/4163

ilg-ul commented 4 years ago

Thank you for letting us know, your explanation might help other having the same problem.