1、relocation truncated to fit: R_ARM_THM_CALL against symbol 'xxx'
可能的原因有几种:
1、第一种就是如下文所说,超出b/bl 跳转范围,这个可以看编译出来的code 地址来确认。
2、第二种可能是code 所在的section 属性有问题
例如下面这段汇编:
test 在 .startup section中,Test2 在 .text section中
test 会调用Test2, 编译过程中会报错: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:
....
....
这实际上是由于你没有对startup section 指定它的属性。
通过调用如下指令可以看到各个section 的属性
readelf xxx.elf
如何给section 添加属性呢?可以使用如下命令来添加:
.section name [, flag]
用上面例子为例:
可以将startup section 定义为可分配并且可执行, 就编译就没问题了。
.thumb
.section .startup , “ax”
.align 2
.thumb_func
.type test, %function
.globl test
.fnstart