gpt4 book ai didi

c - ARM 程序集 - bl 分支到错误的地址

转载 作者:太空宇宙 更新时间:2023-11-03 23:38:36 24 4
gpt4 key购买 nike

已解决:电源循环修复了它。一定是上部闪存 block 的电气问题导致硬件执行单元从闪存中读取错误值

我正在 assembly 步进,但发生了一些奇怪的事情。

我有两个独立的闪存 block ,它们都包含代码。因为它们相距甚远,所以从一个 block 到另一个 block 的函数调用需要一个中间跳转,也就是 veneer这是由链接器自动生成的。

到目前为止,这一直有效,我做了一些事情 - 不知道是什么 - 来打破它。

0x1001a9ca: 0x0cf0c5fe bl 0x10027758 <__atiupy_PutOutput2_veneer>

执行完后PC为0x100275ce 哪个是错误的

如果我在反汇编窗口中滚动到 0x10027758 , 我看到标签 __atiupy_PutOutput2_veneer .

为什么会跳错地址?

更新

C 代码跳到 C++ 代码。是的,我有 extern "C".h对于从 C 代码调用的 C++ 代码中的函数。

C 编译选项是:-x c -Wall -Werror -std=c99 -nostdlib -mthumb -mtune=cortex-m4 -mlittle-endian -Wdouble-promotion -DNDEBUG -fdata-sections -ffunction-sections -c -save-temps=obj -g3 -gdwarf-2

C++ 编译选项是:-mthumb -mlittle-endian -x c++ -gdwarf-2 -g3 -fomit-frame-pointer -fnothrow-opt -ffreestanding -fverbose-asm -std=c++11 -c -fno-rtti -ffunction-sections -fdata-sections -fno-exceptions

根据要求,一些反汇编使用 objdump -d .

即将跳转到0x10027758的地方(但从未到达那里)

1001a9bc <mp_hal_stdout_tx_strn_cooked>:
1001a9bc: b580 push {r7, lr}
1001a9be: b082 sub sp, #8
1001a9c0: af00 add r7, sp, #0
1001a9c2: 6078 str r0, [r7, #4]
1001a9c4: 6039 str r1, [r7, #0]
1001a9c6: 6878 ldr r0, [r7, #4]
1001a9c8: 6839 ldr r1, [r7, #0]
1001a9ca: f00c fec5 bl 10027758 <__atiupy_PutOutput2_veneer>
1001a9ce: f107 0708 add.w r7, r7, #8
1001a9d2: 46bd mov sp, r7
1001a9d4: bd80 pop {r7, pc}
1001a9d6: bf00 nop

应该跳转到哪里

10027758 <__atiupy_PutOutput2_veneer>:
10027758: b401 push {r0}
1002775a: 4802 ldr r0, [pc, #8] ; (10027764 <__atiupy_PutOutput2_veneer+0xc>)
1002775c: 4684 mov ip, r0
1002775e: bc01 pop {r0}
10027760: 4760 bx ip
10027762: bf00 nop
10027764: 00035abd .word 0x00035abd

它实际上跳转到0x100275ce但我粘贴了位于此处的整个函数

100275c8 <___ZN21CKinetisI2CController7DisableEv_veneer>:
100275c8: b401 push {r0}
100275ca: 4802 ldr r0, [pc, #8] ; (100275d4 <___ZN21CKinetisI2CController7DisableEv_veneer+0xc>)
100275cc: 4684 mov ip, r0
100275ce: bc01 pop {r0}
100275d0: 4760 bx ip
100275d2: bf00 nop
100275d4: 00029b2d .word 0x00029b2d

我在 mp_hal_stdout_tx_strn_cooked 处设置了一个断点然后使用 stepi 进行组装

p/x $pc
$2 = 0x1001a9c6
disass
Dump of assembler code for function mp_hal_stdout_tx_strn_cooked:
0x1001a9bc <+0>: push {r7, lr}
0x1001a9be <+2>: sub sp, #8
0x1001a9c0 <+4>: add r7, sp, #0
0x1001a9c2 <+6>: str r0, [r7, #4]
0x1001a9c4 <+8>: str r1, [r7, #0]
=> 0x1001a9c6 <+10>: ldr r0, [r7, #4]
0x1001a9c8 <+12>: ldr r1, [r7, #0]
0x1001a9ca <+14>: bl 0x10027758 <__atiupy_PutOutput2_veneer>
0x1001a9ce <+18>: add.w r7, r7, #8
0x1001a9d2 <+22>: mov sp, r7
0x1001a9d4 <+24>: pop {r7, pc}
End of assembler dump.
stepi
stepi
0x1001a9c8 23 atiupy_PutOutput2(str, len);
disass
Dump of assembler code for function mp_hal_stdout_tx_strn_cooked:
0x1001a9bc <+0>: push {r7, lr}
0x1001a9be <+2>: sub sp, #8
0x1001a9c0 <+4>: add r7, sp, #0
0x1001a9c2 <+6>: str r0, [r7, #4]
0x1001a9c4 <+8>: str r1, [r7, #0]
0x1001a9c6 <+10>: ldr r0, [r7, #4]
=> 0x1001a9c8 <+12>: ldr r1, [r7, #0]
0x1001a9ca <+14>: bl 0x10027758 <__atiupy_PutOutput2_veneer>
0x1001a9ce <+18>: add.w r7, r7, #8
0x1001a9d2 <+22>: mov sp, r7
0x1001a9d4 <+24>: pop {r7, pc}
End of assembler dump.
stepi
stepi
0x1001a9ca 23 atiupy_PutOutput2(str, len);
diasass
Undefined command: "diasass". Try "help".
disass
Dump of assembler code for function mp_hal_stdout_tx_strn_cooked:
0x1001a9bc <+0>: push {r7, lr}
0x1001a9be <+2>: sub sp, #8
0x1001a9c0 <+4>: add r7, sp, #0
0x1001a9c2 <+6>: str r0, [r7, #4]
0x1001a9c4 <+8>: str r1, [r7, #0]
0x1001a9c6 <+10>: ldr r0, [r7, #4]
0x1001a9c8 <+12>: ldr r1, [r7, #0]
=> 0x1001a9ca <+14>: bl 0x10027758 <__atiupy_PutOutput2_veneer>
0x1001a9ce <+18>: add.w r7, r7, #8
0x1001a9d2 <+22>: mov sp, r7
0x1001a9d4 <+24>: pop {r7, pc}
End of assembler dump.
stepi
stepi
0x100275ce in ___ZN21CKinetisI2CController7DisableEv_veneer ()
disass
Dump of assembler code for function ___ZN21CKinetisI2CController7DisableEv_veneer:
0x100275c8 <+0>: push {r0}
0x100275ca <+2>: ldr r0, [pc, #8] ; (0x100275d4 <___ZN21CKinetisI2CController7DisableEv_veneer+12>)
0x100275cc <+4>: mov r12, r0
=> 0x100275ce <+6>: pop {r0}
0x100275d0 <+8>: bx r12
0x100275d2 <+10>: nop
0x100275d4 <+12>: ldr r3, [sp, #180] ; 0xb4
0x100275d6 <+14>: movs r2, r0
End of assembler dump.
stepi
stepi
0x100275d0 in ___ZN21CKinetisI2CController7DisableEv_veneer ()
disass
Dump of assembler code for function ___ZN21CKinetisI2CController7DisableEv_veneer:
0x100275c8 <+0>: push {r0}
0x100275ca <+2>: ldr r0, [pc, #8] ; (0x100275d4 <___ZN21CKinetisI2CController7DisableEv_veneer+12>)
0x100275cc <+4>: mov r12, r0
0x100275ce <+6>: pop {r0}
=> 0x100275d0 <+8>: bx r12
0x100275d2 <+10>: nop
0x100275d4 <+12>: ldr r3, [sp, #180] ; 0xb4
0x100275d6 <+14>: movs r2, r0
End of assembler dump.

编译前的汇编文件

有人想要编译器输出的汇编文件,而不是 objdump的解释。此输出是编译选项 -save-temps=obj 的结果

.LFE14:
.size mp_hal_stdout_tx_strn, .-mp_hal_stdout_tx_strn
.section .text.mp_hal_stdout_tx_strn_cooked,"ax",%progbits
.align 2
.global mp_hal_stdout_tx_strn_cooked
.thumb
.thumb_func
.type mp_hal_stdout_tx_strn_cooked, %function
mp_hal_stdout_tx_strn_cooked:
.LFB15:
.loc 1 22 0
.cfi_startproc
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
push {r7, lr}
.LCFI11:
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
.cfi_offset 14, -4
sub sp, sp, #8
.LCFI12:
.cfi_def_cfa_offset 16
add r7, sp, #0
.LCFI13:
.cfi_def_cfa_register 7
str r0, [r7, #4]
str r1, [r7, #0]
.loc 1 23 0
ldr r0, [r7, #4]
ldr r1, [r7, #0]
bl atiupy_PutOutput2
.loc 1 25 0
add r7, r7, #8
mov sp, r7
pop {r7, pc}
.cfi_endproc

(悲伤)更新

我创建了最小示例,但问题没有发生。因此,我认为这与我的环境有关。我将开始恢复本地更改并进行更新。我不会将下面的代码称为完整,因为您需要链接器文件,但由于它不会重现问题,所以我认为提供所有内容没有意义。

main.cpp

#include "common.h"

int main()
{
test1();
}

int main_test()
{
int a = 5;
a = 23424 * a;
return a;
}

测试.c

#include "common.h"

void test1()
{
int a;
a = main_test();
a *= 2;
}

common.h

#ifdef __cplusplus
extern "C" {
#endif //#ifdef __cplusplus


int main_test();
void test1();


#ifdef __cplusplus
}
#endif //#ifdef __cplusplus

ma​​in.obj 位于“下部”闪存 block 中,而 test.obj 位于上部 block 中。从上跳到下时,PC正确跳转到veneer的正确地址.

最佳答案

已解决:电源循环修复了它。一定是上部闪存 block 的电气问题导致硬件执行单元从闪存中读取错误值。

关于c - ARM 程序集 - bl 分支到错误的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52208836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com