This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH][MIPS] Fix ext, dextm, dextu size checking
- From: Richard Sandiford <rdsandiford at googlemail dot com>
- To: Chao-Ying Fu <Chao-Ying dot Fu at imgtec dot com>
- Cc: "binutils\ at sourceware dot org" <binutils at sourceware dot org>
- Date: Tue, 30 Apr 2013 19:25:31 +0100
- Subject: Re: [PATCH][MIPS] Fix ext, dextm, dextu size checking
- References: <81D57523CB07B24881D63DE650C6ED82ED389E at bamail02 dot ba dot imgtec dot org>
Chao-Ying Fu <Chao-Ying.Fu@imgtec.com> writes:
> We found out that GAS doesn't check "size" operands correctly for ext, dextm, dextu instructions.
> Note that dext is ok, because it is handled by macro expansion at M_DEXT.
> Ex:
> linux:~/dev/test> cat ext.s
> test:
> ext $2,$3,1,0
> dextm $2,$3,31,2
> dextm $2,$3,1,32
> dextu $2,$3,33,0
>
> linux:~/dev/test> ~/dev/build-binutils/gas/as-new ext.s -o ext.o -mips64r2
> linux:~/dev/test> ~/dev/build-binutils/binutils/objdump -d ext.o
>
> ext.o: file format elf32-tradbigmips
>
>
> Disassembly of section .text:
>
> 00000000 <test>:
> 0: 7c62f840 ext v0,v1,0x1,0x20 <-- WRONG
> 4: 7c620fc1 dextm v0,v1,0x1f,0x22 <-- WRONG
> 8: 7c62f841 dextm v0,v1,0x1,0x40 <-- WRONG
> c: 7c62f842 dextu v0,v1,0x21,0x20 <-- WRONG
>
> Case 1: ext
> GAS checks:
> A. 0 <= pos <= 31
> B. size >= 0
> C. 1 <= pos + size <= 32
>
> This allows 0 <= size <= 32. However, 0 should not be allowed.
>
> Case 2: dextm
> GAS checks:
> A. 0 <= pos <= 31
> B. size >= 0
> C. 33 <= pos + size <= 64
>
> This allows 2 <= size <= 64. However, 2 to 32 should not be allowed.
>
> Case 3: dextu
> GAS checks:
> A. 32 <= pos <= 63
> B. size >= 0
> C. 33 <= pos + size <= 64
>
> This allows 0 <= size <= 32. However, 0 should not be allowed.
>
> A possible fix is as follows. We just need to check if the lower bound of "size" is correct, instead of checking it against 0.
> (Note that there is no issue at the upper bound of "size".)
> Ex:
> 2013-04-22 Chao-ying Fu <Chao-ying.Fu@imgtec.com>
>
> * config/tc-mips.c (mips_ip): Add sizelo.
> For "+C", "+G", and "+H", set sizelo and compare against it.
Looks good, but please add a run_list_test_arches to mips.exp
to check for the errors.
Thanks,
Richard