This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH][MIPS] Fix ext, dextm, dextu size checking


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]