Bad MIPS address arithmetic

Paul Koning Paul_Koning@Dell.com
Mon May 10 21:17:00 GMT 2010


I spotted this in binutils 2.18.

Given the source file:

foo:	ld	$v0,40000($sp)
	jr	$ra

The resulting code is:

	lui	v0, 1
	addu	v0, v0, sp
	jr	ra
	ld	v0, -25536(sp) 

The problem is that this produces wrong addresses in machines with 64
bit registers, if the current sp is 0x7fff0000 or higher.  If so, the
addu produces 0xffffffff8000nnnn in v0, and the ld then references
0xffffffff7fffnnnn which is not likely to be a valid address.

It seems that daddu rather than addu should be used here, for O64 (and
probably N32) ABIs.

	paul



More information about the Binutils mailing list