[LEDE-DEV] [PATCH] gcc: 7.2: remove mips patch causing broken code

Hauke Mehrtens hauke at hauke-m.de
Sun Dec 17 13:29:20 PST 2017


On 12/17/2017 10:21 PM, Hauke Mehrtens wrote:
> This patch made GCC produce broken code, remove it.
> In mp_cmp_d() function in th libtommath shipped with dropbear the
> following code was compiled wrong:
> 
> /* compare based on magnitude */
> if (a->used > 1) {
>   return 1;
> }
> 
> In the broken ASM this part returned -1 like the previous return
> statement did instead of 1 like it should.
> 
> This did not happen when the -funroll-loops option was given to GCC.
> 
> Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>

This is the broken code:

0041d978 <mp_cmp_d>:
  41d978:	8c830008 	lw	v1,8(a0)
  41d97c:	24020001 	li	v0,1
  41d980:	1062000c 	beq	v1,v0,41d9b4 <mp_cmp_d+0x3c>
  41d984:	2402ffff 	li	v0,-1
  41d988:	8c830000 	lw	v1,0(a0)
  41d98c:	28630002 	slti	v1,v1,2
  41d990:	10600008 	beqz	v1,41d9b4 <mp_cmp_d+0x3c>
  41d994:	00000000 	nop
  41d998:	8c82000c 	lw	v0,12(a0)
  41d99c:	8c420000 	lw	v0,0(v0)
  41d9a0:	00a2182b 	sltu	v1,a1,v0
  41d9a4:	14600005 	bnez	v1,41d9bc <mp_cmp_d+0x44>
  41d9a8:	00000000 	nop
  41d9ac:	0045102b 	sltu	v0,v0,a1
  41d9b0:	00021023 	negu	v0,v0
  41d9b4:	03e00008 	jr	ra
  41d9b8:	00000000 	nop
  41d9bc:	03e00008 	jr	ra
  41d9c0:	24020001 	li	v0,1


To fix this in line 41d994 "li	v0,1" should be added instated of the nop.

Without this patch I ma getting this code:

0041d864 <mp_cmp_d>:
  41d864:	8c860008 	lw	a2,8(a0)
  41d868:	24030001 	li	v1,1
  41d86c:	10c3000b 	beq	a2,v1,41d89c <mp_cmp_d+0x38>
  41d870:	2402ffff 	li	v0,-1
  41d874:	8c860000 	lw	a2,0(a0)
  41d878:	28c60002 	slti	a2,a2,2
  41d87c:	10c00007 	beqz	a2,41d89c <mp_cmp_d+0x38>
  41d880:	24020001 	li	v0,1
  41d884:	8c83000c 	lw	v1,12(a0)
  41d888:	8c630000 	lw	v1,0(v1)
  41d88c:	00a3202b 	sltu	a0,a1,v1
  41d890:	14800002 	bnez	a0,41d89c <mp_cmp_d+0x38>
  41d894:	0065182b 	sltu	v1,v1,a1
  41d898:	00031023 	negu	v0,v1
  41d89c:	03e00008 	jr	ra
  41d8a0:	00000000 	nop

This looks correct.

Hauke



More information about the Lede-dev mailing list