ARM 程序集中的函数地址有一个字节偏移? [英] Function address in ARM assembly have one byte offset?

查看:10
本文介绍了ARM 程序集中的函数地址有一个字节偏移?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,我有以下由 objdump 得到的汇编代码.f()的地址是080001d4.但是 printf("%x", f) 输出 080001d5.而 f() 可以通过 (*((int (*)())080001d5))()(*((int (*)())080001d4))().

For example, I have the following assembly code got by objdump. The address of f() is 080001d4. But printf("%x", f) outputs 080001d5. And f() can be done by (*((int (*)())080001d5))() but (*((int (*)())080001d4))().

为什么函数地址有一个字节偏移?

Why there is one byte offset in function address?

080001d4 <f>:
 80001d4:   2000        movs    r0, #0
 80001d6:   4770        bx  lr

推荐答案

ARM 有两种指令模式,地址的最低有效位用于指示给定函数使用哪种模式.Thumb 模式的奇数地址,ARM 模式的偶数地址.

ARM has two instruction modes, and the least-significant bit of the address is used to indicate which mode a given function uses. Odd addresses for Thumb mode, and even addresses for ARM mode.

即使您使用 -marm 开关重新编译该地址也是如此.

The address will be even if you recompile it using the -marm switch.

[1] 中的第 A4.1.1 节在 Thumb 状态和 ARM 状态之间切换"陈述如下:

Section A4.1.1 "Changing between Thumb state and ARM state" in [1] states the following:

处于 Thumb 状态的处理器可以通过执行任何以下指令: BX 、 BLX 或 LDR或加载 PC 的 LDM.

A processor in Thumb state can enter ARM state by executing any of the following instructions: BX , BLX , or an LDR or LDM that loads the PC.

....

目标指令集要么直接编码在指令中(对于 BLX 的直接偏移版本),或者是保存为互通地址的位[0].

The target instruction set is either encoded directly in the instruction (for the immediate offset version of BLX ), or is held as bit[0] of an interworking address.

<小时>

[1] ARM® 架构参考手册:ARMv7-A 和 ARMv7-R 版.ARM,2014 年.DDI 0406C.c.[在线的].可用:http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html.[2019 年 8 月 26 日访问].


[1] ARM® Architecture Reference Manual: ARMv7-A and ARMv7-R edition. ARM, 2014. DDI 0406C.c. [Online]. Available: http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0406c/index.html. [Accessed 26 Aug. 2019].

这篇关于ARM 程序集中的函数地址有一个字节偏移?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆