RE: [PATCH V5 2/3] Add AVX512 register support to gdbserver.

Sturm, Michael
2015-01-08T10:01:56Z

Hello All,

Happy New Year to everyone!

Sorry for the late reply! Yes, the proposed change is correct. Thanks a lot for catching this bug!

Regards,
Michael

-----Original Message-----
From: Joel Brobecker [mailto:brobecker@adacore.com]
Sent: Saturday, December 13, 2014 2:42 PM
To: Andreas Arnez
Cc: Sturm, Michael; palves@redhat.com; eliz@gnu.org; mark.kettenis@xs4all.nl; Tedeschi, Walfred; gdb-patches@sourceware.org
Subject: Re: [PATCH V5 2/3] Add AVX512 register support to gdbserver.

> While building GDB I encountered a gcc warning (array subscript above
> array bounds) and tracked it down to the patch below.

Thanks!

> On Wed, Apr 23 2014, Michael Sturm wrote:
>
> > # Linux object files. This is so we don't have to repeat diff
> > --git a/gdb/gdbserver/i387-fp.c b/gdb/gdbserver/i387-fp.c index
> > e655f74..c2d0bdf 100644
> > --- a/gdb/gdbserver/i387-fp.c
> > +++ b/gdb/gdbserver/i387-fp.c
> > @@ -22,6 +22,11 @@
> >
> > static const int num_mpx_bnd_registers = 4; static const int
> > num_mpx_cfg_registers = 2;
> > +static const int num_avx512_k_registers = 8; static const int
> > +num_avx512_zmmh_low_registers = 16; static const int
> > +num_avx512_zmmh_high_registers = 16; static const int
> > +num_avx512_ymmh_registers = 16; static const int
> > +num_avx512_xmm_registers = 16;
> >
> > /* Note: These functions preserve the reserved bits in control registers.
> > However, gdbserver promptly throws away that information. */ @@
> > -120,6 +125,17 @@ struct i387_xsave {
> > /* Space for 2 MPX configuration registers of 64 bits
> > plus reserved space. */
> > unsigned char mpx_cfg_space[16];
> > +
> > + unsigned char reserved5[48];
> > +
> > + /* Space for 8 OpMask register values of 64 bits. */ unsigned
> > + char k_space[64];
> > +
> > + /* Space for 16 256-bit zmm0-15. */ unsigned char
> > + zmmh_low_space[512];
> > +
> > + /* Space for 16 512-bit zmm16-31 values. */ unsigned char
> > + zmmh_high_space[1024];
> > };
> >
> > [...]
> > +
> > + /* Check if any of ZMM16H-ZMM31H registers are changed. */ if
> > + ((x86_xcr0 & I386_XSTATE_ZMM))
> > + {
> > + int zmm16h_regnum = find_regno (regcache->tdesc, "zmm16h");
> > +
> > + for (i = 0; i < num_avx512_zmmh_high_registers; i++)
> > + {
> > + collect_register (regcache, i + zmm16h_regnum, raw);
> > + p = ((char *) &fp->zmmh_low_space[0]) + 32 + i * 64;
> ^^^^^^^^^^^^^^ Should this really mean
> 'zmm_high_space'?
>
> > + if (memcmp (raw, p, 32) != 0)
>
> The warning occurs for this memcmp().

Based on the comments in "struct i387_xsave", I think you are right!
Michael and/or Pedro, can anyone confirm, please?

Thank you,
--
Joel
Intel GmbH
Dornacher Strasse 1
85622 Feldkirchen/Muenchen, Deutschland
Sitz der Gesellschaft: Feldkirchen bei Muenchen
Geschaeftsfuehrer: Christian Lamprechter, Hannes Schwaderer, Douglas Lusk
Registergericht: Muenchen HRB 47456
Ust.-IdNr./VAT Registration No.: DE129385895
Citibank Frankfurt a.M. (BLZ 502 109 00) 600119052