ra ($31) 寄存器包含未对齐的 return 地址 (MIPS)
ra ($31) register contain unaligned return address (MIPS)
我正在尝试在 MIPS 上重现调用堆栈,有关详细信息,请查看我之前的问题:
由于 MIPS 没有帧指针,为此我必须在堆栈上找到 return 地址。
我检查了其中一个函数开头的 ra 寄存器(在它被压入堆栈之前),发现它包含未对齐的 return 地址。
ra = 0x*******5
为什么会这样?
我怀疑您正在链接一个 microMIPS 目标(16 位指令,GCC 选项 -mmicromips
),也许?
假设这是正确的,来自 microMIPS GCC Toolchain Usage 文档:
To enable processors to determine the current ISA (MIPS32 ISA or
microMIPS ISA), the least-significant bit of an address (bit 0) is
utilized as the ISA mode bit (0 = MIPS32 ISA, 1 = microMIPS ISA). This
mechanism enables calls to microMIPS or MIPS32 functions via the JALR
instruction by setting a register value odd (for microMIPS) or even
(for MIPS32) from the address.
这样,为microMIPS编译的函数可以调用为MIPS32编译的函数,反之亦然,通过设置函数的低位地址(或return地址,跳转目标等)对于 MIPS32 为 0,对于 microMIPS 为 1。由于所有指令都是 16 位或 32 位的并且必须相应地对齐,要找到真正的 return 地址,只需屏蔽掉低位即可。
我正在尝试在 MIPS 上重现调用堆栈,有关详细信息,请查看我之前的问题:
ra = 0x*******5
为什么会这样?
我怀疑您正在链接一个 microMIPS 目标(16 位指令,GCC 选项 -mmicromips
),也许?
假设这是正确的,来自 microMIPS GCC Toolchain Usage 文档:
To enable processors to determine the current ISA (MIPS32 ISA or microMIPS ISA), the least-significant bit of an address (bit 0) is utilized as the ISA mode bit (0 = MIPS32 ISA, 1 = microMIPS ISA). This mechanism enables calls to microMIPS or MIPS32 functions via the JALR instruction by setting a register value odd (for microMIPS) or even (for MIPS32) from the address.
这样,为microMIPS编译的函数可以调用为MIPS32编译的函数,反之亦然,通过设置函数的低位地址(或return地址,跳转目标等)对于 MIPS32 为 0,对于 microMIPS 为 1。由于所有指令都是 16 位或 32 位的并且必须相应地对齐,要找到真正的 return 地址,只需屏蔽掉低位即可。