我正在尝试使用符号文件链接CortexM 3上的程序。“程序”在RAM中运行,并使用来自ROM的静态绑定函数。所以我使用一个符号文件来标识所有ROM函数的地址。
问题是gcc似乎认为符号文件中的所有函数都是ARM 32而不是Thumb,所以我最终使用了thumb-> arm 32转换(当然,由于M3不支持ARM 32指令,这会崩溃)
试验c:
extern void tfunc();
int main()
{
tfunc();
return 0;
}
字符串
符号文件:
tfunc = 0x08011029;
型
编译:
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -c test.c
arm-none-eabi-ld test.o --just-symbols=symbolfile
型
生成如下代码:
arm-none-eabi-objdump -d a.out
a.out: file format elf32-littlearm
Disassembly of section .text:
00008000 <main>:
8000: b580 push {r7, lr}
8002: af00 add r7, sp, #0
8004: f000 e804 blx 8010 <__tfunc_from_thumb>
8008: 2300 movs r3, #0
800a: 4618 mov r0, r3
800c: bd80 pop {r7, pc}
800e: bf00 nop
00008010 <__tfunc_from_thumb>:
8010: e51ff004 ldr pc, [pc, #-4] ; 8014 <__tfunc_from_thumb+0x4>
8014: 08011029 .word 0x08011029
型
请注意,“blx”调用是到偶数地址,而M3规范要求所有跳转都是到奇数(拇指)地址
我在网上找到了一个解决方案,使用汇编器而不是符号文件:符号:
.global tfunc
.type tfunc %function
.equ tfunc, 0x08011029
型
和建设:
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -c test.c
arm-none-eabi-as -o sym.o sym.s
arm-none-eabi-ld test.o sym.o
型
这会生成一个(相当冗长,但至少功能上是正确的):
00008000 <main>:
8000: b580 push {r7, lr}
8002: af00 add r7, sp, #0
8004: f000 f804 bl 8010 <__tfunc_veneer>
8008: 2300 movs r3, #0
800a: 4618 mov r0, r3
800c: bd80 pop {r7, pc}
800e: bf00 nop
00008010 <__tfunc_veneer>:
8010: b401 push {r0}
8012: 4802 ldr r0, [pc, #8] ; (801c <__tfunc_veneer+0xc>)
8014: 4684 mov ip, r0
8016: bc01 pop {r0}
8018: 4760 bx ip
801a: bf00 nop
801c: 08011029 .word 0x08011029
型
我发现我可以通过在我的c代码顶部添加'#pragma long_calls'来解决这个问题。
然而,我的问题不是如何让我的代码正确地构建,而是如何在CortexM中使用符号文件,因为有些情况下#pragma不起作用,虽然汇编选项是可行的,但它使构建系统变得更加复杂
1条答案
按热度按时间k0pti3hp1#
注意,“blx”调用是到偶数地址
这些函数由链接器
ld
生成。arm-none-eabi-ld test.o --just-symbols=symbolfile
个您必须告诉
arm-none-eabi-ld
您想要生成thumb代码。使用arm-none-eabi-gcc
作为链接的前端通常更简单。