gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32

Message ID CAMe9rOo9zm4h2UVxrOipjo3+55_LU+Lf__bFTHxxKfOKMAHxcA@mail.gmail.com
State New
Headers
Series gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32 |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gdb_build--master-arm fail Patch failed to apply

Commit Message

H.J. Lu March 19, 2024, 6:36 p.m. UTC
  Since MPX isn't available for x32, we should clear X86_XSTATE_MPX bits
on x32.

        PR server/31511
        * linux-x86-low.cc (x86_linux_read_description): Clear
        X86_XSTATE_MPX bits in xcr0 on x32.
---
 gdbserver/linux-x86-low.cc | 4 ++++
 1 file changed, 4 insertions(+)

--
2.44.0
  

Comments

Willgerodt, Felix March 20, 2024, 8:40 a.m. UTC | #1
> -----Original Message-----
> From: H.J. Lu <hjl.tools@gmail.com>
> Sent: Dienstag, 19. März 2024 19:36
> To: GDB <gdb-patches@sourceware.org>; John Baldwin <jhb@freebsd.org>;
> Willgerodt, Felix <felix.willgerodt@intel.com>
> Subject: [PATCH] gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
> 
> Since MPX isn't available for x32, we should clear X86_XSTATE_MPX bits
> on x32.
> 
>         PR server/31511
>         * linux-x86-low.cc (x86_linux_read_description): Clear
>         X86_XSTATE_MPX bits in xcr0 on x32.
> ---
>  gdbserver/linux-x86-low.cc | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
> index 3af0a009052..28b5d523b8e 100644
> --- a/gdbserver/linux-x86-low.cc
> +++ b/gdbserver/linux-x86-low.cc
> @@ -938,6 +938,10 @@ x86_linux_read_description (void)
>           xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
>                              / sizeof (uint64_t))];
> 
> +         /* No MPX on x32.  */
> +         if (!is_elf64)
> +           xcr0 &= ~X86_XSTATE_MPX;
> +

Doesn't that also disable it for 32-bit?

x86_target::low_siginfo_fixup() uses this to check x32:

  /* No fixup for native x32 GDB.  */
  else if (!is_elf64 && sizeof (void *) == 8)


Felix
Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de <http://www.intel.de>
Managing Directors: Christin Eisenschmid, Sharon Heck, Tiffany Doon Silva  
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
H.J. Lu March 20, 2024, 10:48 a.m. UTC | #2
On Wed, Mar 20, 2024 at 1:40 AM Willgerodt, Felix
<felix.willgerodt@intel.com> wrote:
>
> > -----Original Message-----
> > From: H.J. Lu <hjl.tools@gmail.com>
> > Sent: Dienstag, 19. März 2024 19:36
> > To: GDB <gdb-patches@sourceware.org>; John Baldwin <jhb@freebsd.org>;
> > Willgerodt, Felix <felix.willgerodt@intel.com>
> > Subject: [PATCH] gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32
> >
> > Since MPX isn't available for x32, we should clear X86_XSTATE_MPX bits
> > on x32.
> >
> >         PR server/31511
> >         * linux-x86-low.cc (x86_linux_read_description): Clear
> >         X86_XSTATE_MPX bits in xcr0 on x32.
> > ---
> >  gdbserver/linux-x86-low.cc | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
> > index 3af0a009052..28b5d523b8e 100644
> > --- a/gdbserver/linux-x86-low.cc
> > +++ b/gdbserver/linux-x86-low.cc
> > @@ -938,6 +938,10 @@ x86_linux_read_description (void)
> >           xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
> >                              / sizeof (uint64_t))];
> >
> > +         /* No MPX on x32.  */
> > +         if (!is_elf64)
> > +           xcr0 &= ~X86_XSTATE_MPX;
> > +
>
> Doesn't that also disable it for 32-bit?

Fixed in the v2 patch with

+    /* No MPX on x32.  */
+    if (machine == EM_X86_64 && !is_elf64)
+      xcr0 &= ~X86_XSTATE_MPX;
+

> x86_target::low_siginfo_fixup() uses this to check x32:
>
>   /* No fixup for native x32 GDB.  */
>   else if (!is_elf64 && sizeof (void *) == 8)
>
>

Thanks.
  

Patch

diff --git a/gdbserver/linux-x86-low.cc b/gdbserver/linux-x86-low.cc
index 3af0a009052..28b5d523b8e 100644
--- a/gdbserver/linux-x86-low.cc
+++ b/gdbserver/linux-x86-low.cc
@@ -938,6 +938,10 @@  x86_linux_read_description (void)
          xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
                             / sizeof (uint64_t))];

+         /* No MPX on x32.  */
+         if (!is_elf64)
+           xcr0 &= ~X86_XSTATE_MPX;
+
          xsave_len = x86_xsave_length ();

          /* Use PTRACE_GETREGSET if it is available.  */