[binutils-gdb/gdb-15-branch] gdb-15-branch: Clear the X86_XSTATE_MPX bit in XCRO for x32

H.J. Lu hjl@sourceware.org
Sun Sep 8 23:11:58 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68163a5c4f96a4c316772cea282e7e7febe5fe68

commit 68163a5c4f96a4c316772cea282e7e7febe5fe68
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Sep 4 16:01:50 2024 -0700

    gdb-15-branch: Clear the X86_XSTATE_MPX bit in XCRO for x32
    
    commit 868883583e7520ff1bd99fcb224d2b33a990edff
    Author: Andrew Burgess <aburgess@redhat.com>
    Date:   Sat Mar 23 16:17:36 2024 +0000
    
        gdb/arch: assert that X86_XSTATE_MPX is not set for x32
    
    added
    
      if (xcr0 & X86_XSTATE_MPX)
        {
          /* MPX is not available on x32.  */
          gdb_assert (!is_x32);
          regnum = create_feature_i386_64bit_mpx (tdesc.get (), regnum);
        }
    
    But x32 is a software convention.  There is no x32 mode in hardware and
    CPU always returns the 64-bit mode XCR0 value for x32 processes.  This
    regression was fixed on master branch by
    
    commit bf616be99153b43c1077be9dbb7b081b4c080031 (HEAD)
    Author: Andrew Burgess <aburgess@redhat.com>
    Date:   Thu Jan 25 14:25:57 2024 +0000
    
        gdb/gdbserver: share some code relating to target description creation
    
    which used the gdbserver code to clear the X86_XSTATE_MPX bit in XCR0 for
    x32.  Fix this regression on gdb-15-branch by clearing the X86_XSTATE_MPX
    bit in XCR0 for x32 in gdb.
    
            PR gdb/32143
            * x86-linux-nat.c (x86_linux_nat_target::read_description): Clear
            the X86_XSTATE_MPX bit in XCR0 for x32.
    
    Signed-off-by: H.J. Lu <hjl.tools@gmail.com>

Diff:
---
 gdb/x86-linux-nat.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index a3d8ffb60f1..1214aa4be96 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -180,6 +180,12 @@ x86_linux_nat_target::read_description ()
 	  xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
 			     / sizeof (uint64_t))];
 
+#ifdef __x86_64__
+	  /* No MPX on x32.  */
+	  if (is_x32)
+	    xcr0 &= ~X86_XSTATE_MPX;
+#endif
+
 	  m_xsave_layout = x86_fetch_xsave_layout (xcr0, x86_xsave_length ());
 	}
     }


More information about the Gdb-cvs mailing list