Wesley Dahar
Member
Hello all,
I've occasionally run into issues with the linker while building for the SparkFun MicroMod Teensy which, I believe, is analogous to the Teensy 4.0 for the purpose of discussion here (i.e. no difference in the linker script or MCU). I'm using PlatformIO to pull in the Teensyduino framework and facilitate compilation and program loading, but I have rewritten nearly all peripheral drivers, written several additional libraries, and heavily modified a multi-threading library, so little remains of the "Arduino" framework. I'm hoping this won't be a deal breaker for those who would like to provide assistance, and I understand it is rather difficult to help when there are so many unknowns in my case, but I am hoping to move the problem space away from my program in the concrete sense and into the more (or less) familiar area of linkers and the linking process.
And so, with that lengthy introduction to my first post anywhere on the internet, I'll hit you with a wall of linker errors with the details below.
(Note: I'm not sure what writer.c is, but I didn't write it.)
This is the second instance of this specific (and nearly identical) set of linker errors I have encountered with my code base. The first was earlier in my multi-threading library development which occurred only when I started a fresh project (with very few libraries pulled in) to run some tests. After some unsuccessful research and debugging, I abandoned the small project and returned to development on a project with more libraries.
I am familiar with ARM THUMB assembly, the finer aspects of C, and low level computer architectures in general, but there are many things I don't know. As far as I understand the error messages, the issue pertains to the limit of ARM branch instructions which requires relative branch targets to be within [-231, 231 - 1] bytes (+/-1GiB, signed 31 bit (2's compliment)). The symbols which are out of range (either the destination or the branch instruction, I'm not sure which) are related to C++ exception handling. However I have not had any success by compiling with the flag -fno-exceptions. As a sanity check, I have also tried replacing all instances of inline ASM instructions of relative branches to C functions with an equivalent LDR r0,=func and BX r0 to no effect as expected.
For reference:
https://developer.arm.com/documenta...ntrol-instructions/B--BL--BX--and-BLX?lang=en
https://stackoverflow.com/questions...rror-relocation-truncated-to-fit-r-arm-prel31 (Similar issue)
The crux of the issue is my confusion as to why this error would occur at all. This may be a result of the FLASHMEM code being located at 0x60000000. Looking at the i.MX RT1060 TRM and the Teensy 4.0 memory map graphic on the product page, has not really given me any further insight.
Here is the output of a similar build before my foray into the Serial drivers which seemed to be the trigger this time.
Details:
Source code: No source code. (I don't believe this is relevant to the issue)
Error messages: See above. No other warnings from the compiler.
Hardware: SparkFun MicroMod Teensy on a MicroMod ATP carrier board (no other hardware)
Wiring: N/A
Software: Teensyduino, PlatformIO, Windows, Only custom libraries
Thanks,
Wesley Dahar
I've occasionally run into issues with the linker while building for the SparkFun MicroMod Teensy which, I believe, is analogous to the Teensy 4.0 for the purpose of discussion here (i.e. no difference in the linker script or MCU). I'm using PlatformIO to pull in the Teensyduino framework and facilitate compilation and program loading, but I have rewritten nearly all peripheral drivers, written several additional libraries, and heavily modified a multi-threading library, so little remains of the "Arduino" framework. I'm hoping this won't be a deal breaker for those who would like to provide assistance, and I understand it is rather difficult to help when there are so many unknowns in my case, but I am hoping to move the problem space away from my program in the concrete sense and into the more (or less) familiar area of linkers and the linking process.
And so, with that lengthy introduction to my first post anywhere on the internet, I'll hit you with a wall of linker errors with the details below.
Code:
# For convenience
toolchain_path=c:/users/wdahar/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/lib/armv7e-m/fpu/fpv5-d16
${toolchain_path}\libstdc++.a(system_error.o):(.ARM.extab.text._ZNKSt3_V214error_category10_M_messageB5cxx11Ei+0x0): relocation truncated to fit: R_ARM_PREL31 against symbol `__gxx_personality_v0' defined in .text.__gxx_personality_v0 section in ${toolchain_path}\libstdc++.a(eh_personality.o)
${toolchain_path}\libstdc++.a(system_error.o):(.ARM.exidx.text._ZNKSt3_V214error_category10_M_messageB5cxx11Ei+0x4): relocation truncated to fit: R_ARM_PREL31 against `.ARM.extab.text._ZNKSt3_V214error_category10_M_messageB5cxx11Ei'
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.exidx.text._ZSt17__throw_bad_allocv+0x4): relocation truncated to fit: R_ARM_PREL31 against `.ARM.extab.text._ZSt17__throw_bad_allocv'
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.extab.text._ZSt19__throw_logic_errorPKc+0x0): relocation truncated to fit: R_ARM_PREL31 against symbol `__gxx_personality_v0' defined in .text.__gxx_personality_v0 section in ${toolchain_path}\libstdc++.a(eh_personality.o)
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.exidx.text._ZSt19__throw_logic_errorPKc+0x4): relocation truncated to fit: R_ARM_PREL31 against `.ARM.extab.text._ZSt19__throw_logic_errorPKc'
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.extab.text._ZSt20__throw_length_errorPKc+0x0): relocation truncated to fit: R_ARM_PREL31 against
symbol `__gxx_personality_v0' defined in .text.__gxx_personality_v0 section in ${toolchain_path}\libstdc++.a(eh_personality.o)
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.exidx.text._ZSt20__throw_length_errorPKc+0x4): relocation truncated to fit: R_ARM_PREL31 against
`.ARM.extab.text._ZSt20__throw_length_errorPKc'
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.extab.text._ZSt24__throw_out_of_range_fmtPKcz+0x0): relocation truncated to fit: R_ARM_PREL31 against symbol `__gxx_personality_v0' defined in .text.__gxx_personality_v0 section in ${toolchain_path}\libstdc++.a(eh_personality.o)
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.exidx.text._ZSt24__throw_out_of_range_fmtPKcz+0x4): relocation truncated to fit: R_ARM_PREL31 against `.ARM.extab.text._ZSt24__throw_out_of_range_fmtPKcz'
${toolchain_path}\libstdc++.a(functexcept.o):(.ARM.exidx.text._ZSt25__throw_bad_function_callv+0x4): relocation truncated to fit: R_ARM_PREL31 against `.ARM.extab.text._ZSt25__throw_bad_function_callv'
${toolchain_path}\libstdc++.a(cow-stdexcept.o):(.ARM.extab.text._ZNSt11logic_errorC2EPKc+0x0): additional relocation overflows omitted from the output
${toolchain_path}\libg.a(lib_a-writer.o): In function `_write_r':
writer.c:(.text._write_r+0x12): undefined reference to `_write'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\debug\firmware.elf] Error 1
(Note: I'm not sure what writer.c is, but I didn't write it.)
This is the second instance of this specific (and nearly identical) set of linker errors I have encountered with my code base. The first was earlier in my multi-threading library development which occurred only when I started a fresh project (with very few libraries pulled in) to run some tests. After some unsuccessful research and debugging, I abandoned the small project and returned to development on a project with more libraries.
I am familiar with ARM THUMB assembly, the finer aspects of C, and low level computer architectures in general, but there are many things I don't know. As far as I understand the error messages, the issue pertains to the limit of ARM branch instructions which requires relative branch targets to be within [-231, 231 - 1] bytes (+/-1GiB, signed 31 bit (2's compliment)). The symbols which are out of range (either the destination or the branch instruction, I'm not sure which) are related to C++ exception handling. However I have not had any success by compiling with the flag -fno-exceptions. As a sanity check, I have also tried replacing all instances of inline ASM instructions of relative branches to C functions with an equivalent LDR r0,=func and BX r0 to no effect as expected.
For reference:
https://developer.arm.com/documenta...ntrol-instructions/B--BL--BX--and-BLX?lang=en
https://stackoverflow.com/questions...rror-relocation-truncated-to-fit-r-arm-prel31 (Similar issue)
The crux of the issue is my confusion as to why this error would occur at all. This may be a result of the FLASHMEM code being located at 0x60000000. Looking at the i.MX RT1060 TRM and the Teensy 4.0 memory map graphic on the product page, has not really given me any further insight.
Here is the output of a similar build before my foray into the Serial drivers which seemed to be the trigger this time.
Code:
teensy_size: Memory Usage on Teensy MicroMod:
teensy_size: FLASH: code:127508, data:44956, headers:8356 free for files:16334252
teensy_size: RAM1: variables:53600, code:125784, padding:5288 free for local variables:339616
teensy_size: RAM2: variables:12384 free for malloc/new:511904
Details:
Source code: No source code. (I don't believe this is relevant to the issue)
Error messages: See above. No other warnings from the compiler.
Hardware: SparkFun MicroMod Teensy on a MicroMod ATP carrier board (no other hardware)
Wiring: N/A
Software: Teensyduino, PlatformIO, Windows, Only custom libraries
Thanks,
Wesley Dahar