简体   繁体   中英

ra ($31) register contain unaligned return address (MIPS)

I am trying to reproduce call stack on MIPS, for more details check my previous question: How to get a call stack backtrace?(GCC,MIPS,no frame pointer) Since MIPS has no frame pointers, to do so I have to find the return addresses on the stack. I have checked the ra register at the beginning of one of the functions(before it has been pushed to stack) and found out that it contains unaligned return address.

   ra = 0x*******5

Why could that happen?

I suspect you're linking for a microMIPS target (16-bit instructions, GCC option -mmicromips ), perhaps?

Assuming this is correct, from the microMIPS GCC Toolchain Usage document:

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.

In this manner, functions compiled for microMIPS can call functions compiled for MIPS32, and vice-versa, by setting the low-order address of a function (or return address, jump target, etc.) to 0 for MIPS32 or 1 for microMIPS. Since all instructions are either 16-bit or 32-bit and must be aligned accordingly, to find the real return address, simply mask off the low bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM