keystone icon indicating copy to clipboard operation
keystone copied to clipboard

MIPS: Dummy nop after a jump instruction

Open david942j opened this issue 6 years ago • 3 comments

I know MIPS's branch instructions need another instruction follows (a.k.a. branch delay slot), but keystone (or, llvm) always adds a dummy nop after branch instructions even there's one.

If no instruction follows, this output is ok:

$ kstool mipsbe 'jal 0x40025c'
# jal 0x40025c = [ 0c 10 00 97 00 00 00 00 ]

But with an instruction follows, a dummy nop is still inserted:

$ kstool mipsbe 'jal 0x40025c ; add $at, $at, $zero'
# jal 0x40025c ; add $at, $at, $zero = [ 0c 10 00 97 00 00 00 00 00 20 08 20 ]

expected:

$ kstool mipsbe 'jal 0x40025c ; add $at, $at, $zero'
# jal 0x40025c ; add $at, $at, $zero = [ 0c 10 00 97 00 20 08 20 ]

No NOP needed to be inserted if an instruction already follows.

david942j avatar Feb 20 '19 05:02 david942j

I guess the same issue appears in Sparc as well.

david942j avatar Feb 20 '19 05:02 david942j

imo keystone should never insert dummy instructions in such cases. It is the programmer's job to understand that a delay slot is used, not keystone's job to read the programmer's mind

cseagle avatar Jul 06 '19 20:07 cseagle