Bug 32143 - [15 Regression] arch/amd64.c:71: internal-error: amd64_create_target_description: Assertion `!is_x32' failed.
Summary: [15 Regression] arch/amd64.c:71: internal-error: amd64_create_target_descript...
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: 15.1
: P2 normal
Target Milestone: 15.2
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-09-04 21:27 UTC by H.J. Lu
Modified: 2024-09-08 23:45 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
A static x32 binary (270.42 KB, application/x-xz)
2024-09-04 21:27 UTC, H.J. Lu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2024-09-04 21:27:31 UTC
Created attachment 15693 [details]
A static x32 binary

$./gdb/gdb /tmp/x32 
Exception caught while booting Guile.
Error in function "open-file":
No such file or directory: "/usr/local/share/gdb/guile/gdb/boot.scm"
./gdb/gdb: warning: Could not complete Guile gdb module initialization from:
/usr/local/share/gdb/guile/gdb/boot.scm.
Limited Guile support is available.
Suggest passing --data-directory=/path/to/gdb/data-directory.
GNU gdb (GDB) 15.1.90.20240904-git
Copyright (C) 2024 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /tmp/x32...
(No debugging symbols found in /tmp/x32)
(gdb) r
Starting program: /tmp/x32 
/export/gnu/import/git/sources/gdb-release/gdb/arch/amd64.c:71: internal-error: amd64_create_target_description: Assertion `!is_x32' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
----- Backtrace -----
0x4d7be6 gdb_internal_backtrace_1
	/export/gnu/import/git/sources/gdb-release/gdb/bt-utils.c:121
0x4d7be6 _Z22gdb_internal_backtracev
	/export/gnu/import/git/sources/gdb-release/gdb/bt-utils.c:167
0x853f84 internal_vproblem
	/export/gnu/import/git/sources/gdb-release/gdb/utils.c:420
0x8542fc _Z15internal_verrorPKciS0_P13__va_list_tag
	/export/gnu/import/git/sources/gdb-release/gdb/utils.c:500
0x95eb55 _Z18internal_error_locPKciS0_z
	/export/gnu/import/git/sources/gdb-release/gdbsupport/errors.cc:57
0x497df3 _Z31amd64_create_target_descriptionmbbb
	/export/gnu/import/git/sources/gdb-release/gdb/arch/amd64.c:71
0x47eeb4 _Z28amd64_linux_read_descriptionmb
	/export/gnu/import/git/sources/gdb-release/gdb/amd64-linux-tdep.c:1605
0x7d321d _Z23target_find_descriptionv
	/export/gnu/import/git/sources/gdb-release/gdb/target-descriptions.c:494
0x65ed3f _Z20post_create_inferiori
	/export/gnu/import/git/sources/gdb-release/gdb/infcmd.c:243
0x66004f run_command_1
	/export/gnu/import/git/sources/gdb-release/gdb/infcmd.c:484
0x50cee4 _Z8cmd_funcP16cmd_list_elementPKci
	/export/gnu/import/git/sources/gdb-release/gdb/cli/cli-decode.c:2741
0x80ffe6 _Z15execute_commandPKci
	/export/gnu/import/git/sources/gdb-release/gdb/top.c:569
0x5e17bf _Z15command_handlerPKc
	/export/gnu/import/git/sources/gdb-release/gdb/event-top.c:579
0x5e2f0e _Z20command_line_handlerOSt10unique_ptrIcN3gdb13xfree_deleterIcEEE
	/export/gnu/import/git/sources/gdb-release/gdb/event-top.c:815
0x5e2167 gdb_rl_callback_handler
	/export/gnu/import/git/sources/gdb-release/gdb/event-top.c:271
0x899e44 rl_callback_read_char
	/export/gnu/import/git/sources/gdb-release/readline/readline/callback.c:290
0x5e229d gdb_rl_callback_read_char_wrapper_noexcept
	/export/gnu/import/git/sources/gdb-release/gdb/event-top.c:196
0x5e2420 gdb_rl_callback_read_char_wrapper
	/export/gnu/import/git/sources/gdb-release/gdb/event-top.c:235
0x84e58f stdin_event_handler
	/export/gnu/import/git/sources/gdb-release/gdb/ui.c:154
0x95f4b5 gdb_wait_for_event
	/export/gnu/import/git/sources/gdb-release/gdbsupport/event-loop.cc:694
0x960145 _Z16gdb_do_one_eventi
	/export/gnu/import/git/sources/gdb-release/gdbsupport/event-loop.cc:263
0x6c6809 start_event_loop
	/export/gnu/import/git/sources/gdb-release/gdb/main.c:400
0x6c6809 captured_command_loop
	/export/gnu/import/git/sources/gdb-release/gdb/main.c:464
0x6c9414 captured_main
	/export/gnu/import/git/sources/gdb-release/gdb/main.c:1337
0x6c9414 _Z8gdb_mainP18captured_main_args
	/export/gnu/import/git/sources/gdb-release/gdb/main.c:1356
0x433ab8 main
	/export/gnu/import/git/sources/gdb-release/gdb/gdb.c:38
---------------------
/export/gnu/import/git/sources/gdb-release/gdb/arch/amd64.c:71: internal-error: amd64_create_target_description: Assertion `!is_x32' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.

master branch is OK.
Comment 1 H.J. Lu 2024-09-04 21:54:45 UTC
This is caused by

868883583e7520ff1bd99fcb224d2b33a990edff is the first bad commit
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
Comment 2 H.J. Lu 2024-09-04 22:19:57 UTC
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 in:

          /* Get XCR0 from XSAVE extended state.  */
          xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET
                             / sizeof (uint64_t))];

          m_xsave_layout = x86_fetch_xsave_layout (xcr0, x86_xsave_length ());

It is up to software, including GDB, to ignore the MPX feature bit in XCR0 for x32
processes.
Comment 3 H.J. Lu 2024-09-04 22:43:47 UTC
This is fixed by

commit 1845af06191e7a457010b943d06628af731b4549
Author: Andrew Burgess <aburgess@redhat.com>
Date:   Wed Mar 27 14:30:48 2024 +0000

    gdb: move xcr0 == 0 check into i386_linux_core_read_description

on master branch.
Comment 4 H.J. Lu 2024-09-04 22:45:00 UTC
Opps.  This is fixed by

bf616be99153b43c1077be9dbb7b081b4c080031 is the first bad commit
commit bf616be99153b43c1077be9dbb7b081b4c080031
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
Comment 5 Joel Brobecker 2024-09-08 14:13:44 UTC
Added 15.2 target milestone as we're about to push this one to the gdb-15-branch.
Comment 6 Sourceware Commits 2024-09-08 23:11:59 UTC
The gdb-15-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

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>
Comment 7 H.J. Lu 2024-09-08 23:45:03 UTC
Fixed for 15.2.