ARM FAQ Summary

1. relocation truncated to fit: R_ARM_THM_CALL against symbol 'xxx'
There are several possible reasons:
1. The first one is that, as mentioned below, it exceeds the jump range of b/bl. This can be confirmed by looking at the compiled code address.
insert image description here
2. The second possibility is that there is a problem with the section attribute where the code is located.
For example, the following compilation:
test is in the .startup section, and Test2 is in the .text section.
Test will call Test2, and an error will be reported during compilation:relocation truncated to fit: R_ARM_THM_CALL against symbol 'xxx'

            .thumb
            .section .startup 
            .align   2

            .thumb_func
            .type    test, %function
            .globl   test
            .fnstart
test:
                ldr      r0, =__stack
                msr      msp, r0
                ldr      r0, =__StackLimit
                msr      msplim, r0
                bl     Test2

....
                .thumb
                .section .text
                .align   2
 				.thumb_func
                .type    Test2, %function
                .globl   Test2
                .fnstart
Test2:     
....
....         

This is actually because you did not specify its attributes for the startup section.

You can see the properties of each section by calling the following command

readelf xxx.elf

insert image description here
How to add attributes to section? You can use the following command to add:

.section name [, flag]

Take the above example as an example:
you can define the startup section as distributable and executable, and there will be no problem with compiling.

            .thumb
            .section .startup , “ax”
            .align   2

            .thumb_func
            .type    test, %function
            .globl   test
            .fnstart

Guess you like

Origin blog.csdn.net/shenjin_s/article/details/111942659