From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ybpDKD+9/mXtyxIAWB0awg (envelope-from ) for ; Sat, 23 Mar 2024 07:30:07 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VNrQpk+i; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 952A31E0C0; Sat, 23 Mar 2024 07:30:07 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6BFB31E030 for ; Sat, 23 Mar 2024 07:30:05 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7611E3858D38 for ; Sat, 23 Mar 2024 11:30:04 +0000 (GMT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6F6123858D28 for ; Sat, 23 Mar 2024 11:29:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F6123858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 6F6123858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711193382; cv=none; b=PvNsPcbLjZVIUtwMYqeJ3T2OZmn5aJ3Ii29tuALUWUGok1ztRXP2lcLykGEKcIMMyjVc8JZ5HstDcGZjHu/B79SwudRiXtfRqeEQsUD48X8OiRRnmAjL6ul1dklZtVNSj4FXqpC/DkpQ9RHHMquLGXhRkZg+L+NGNZuI2wQVkOI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711193382; c=relaxed/simple; bh=RlWdIU/mqJUCpNbrMbWwdj8mfE20lO0vYu5fDr1btrM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=oQN9cpfmjMku0z2FRe1rLNrW7HIUZd8UmlAsnC1gOG7jmkQbqnGnUAW2Bu1fAAGQBirtlnyLX0D9HyX4kB5D9+jJKwDYwECpamzatRLUU1oqevsivKcmeGbzruMXybD8vrU1oYeWtzLMEPPl6jQkyveo9tKVnRIO1UiAwl8Mx1s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711193380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=7/Mu/akSiMbFf/07XzEn5Rl8W54nzU5u4/NqqO1NjUE=; b=VNrQpk+iwalOKskENuX719jKlgQfuqbIPxrwaxbR7dUPKND0/pdYt6NSTwzxeL+QOsLMEq 2aAuOKlBGcs76S6jihdrTHx2TByInR+ZIGAhvqgpAYngmFuHkBQDmcNZF7mqqrcp0RM0vh GWHm3VzRJrJDcvYq7zgGKYoFaJ/fgBI= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-540-gUJIUaX1PzWI1tq7u0On6A-1; Sat, 23 Mar 2024 07:29:38 -0400 X-MC-Unique: gUJIUaX1PzWI1tq7u0On6A-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a470dfe80c8so153251766b.2 for ; Sat, 23 Mar 2024 04:29:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711193377; x=1711798177; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7/Mu/akSiMbFf/07XzEn5Rl8W54nzU5u4/NqqO1NjUE=; b=Sj5arnNDKQ+uu0QKk0PWnNgTsZLqBi65YpQZ2vfALdi6SlL2RkD104Vh6CIOcARo0l 4HbVS5xtYGf9mKOxw4cKPVGMktUEpx7xS0j5eu+ebZe96mFKzQ34CYIU3+AWUjhxpt78 +z5zz2fgqOW02/jIwp6eumXKN6A4Wf3j0OgaeZiAEgZoVlZ0EQgSpgYr4nmwbyfH4gV1 XJ16Vt6pyxrq94FfnXbTwb4CSm+hn7NI5nll9Ltv4gv/gtnXVtbvvHVvp2nktZbWFXrh Oyk2T3yhjnE8e5RuJZwoZK525UwI6y+94JPa9FfYFHkUrFbTVje8lo876bPAyyf8138o moZQ== X-Forwarded-Encrypted: i=1; AJvYcCXttwt6GVi+v8YJcYudguohww6ZO8S2k0jBOlkGjdqArqFBjGSCU/zo/Wrm97duHWkoVtEmUh0Sj1Cw9Uho3hOpYnnMV2c9wWd9wg== X-Gm-Message-State: AOJu0Yz7k1qxY9JjvckTEDQgMPfYg9gST9ymrQqQAnDdLmWGCDJuqMp9 zHOFILBnLKqt7OYdGMfiZK6rcZt3dVXSSFxcBSNWvKGSkOHn65xYaBoqA0IiIez6bewXyjXWiPx 34HLCB+w6HgoIkpilOfXNA3x2ZGha4iH9OMlhLZYSoXELl3f172rLzTz42wg= X-Received: by 2002:a17:906:1e87:b0:a47:1bab:f1d6 with SMTP id e7-20020a1709061e8700b00a471babf1d6mr1620846ejj.72.1711193377086; Sat, 23 Mar 2024 04:29:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGd3beZUab1pUlcyMKA80VD41j1IZ83bsBT+xioVdP+p4d6Xv7HI1qqjJIszqiQ0afX9blLyg== X-Received: by 2002:a17:906:1e87:b0:a47:1bab:f1d6 with SMTP id e7-20020a1709061e8700b00a471babf1d6mr1620821ejj.72.1711193376417; Sat, 23 Mar 2024 04:29:36 -0700 (PDT) Received: from localhost (92.40.185.105.threembb.co.uk. [92.40.185.105]) by smtp.gmail.com with ESMTPSA id u20-20020a1709067d1400b00a473631e261sm822518ejo.28.2024.03.23.04.29.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 04:29:36 -0700 (PDT) From: Andrew Burgess To: "H.J. Lu" , gdb-patches@sourceware.org Cc: felix.willgerodt@intel.com, jhb@FreeBSD.org Subject: Re: [PATCH v2] gdbserver: Clear X86_XSTATE_MPX bits in xcr0 on x32 In-Reply-To: <20240320111318.117728-1-hjl.tools@gmail.com> References: <20240320111318.117728-1-hjl.tools@gmail.com> Date: Sat, 23 Mar 2024 11:29:34 +0000 Message-ID: <87edc1tcdd.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_ABUSEAT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org "H.J. Lu" writes: > 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..933d1fb012a 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 (machine == EM_X86_64 && !is_elf64) > + xcr0 &= ~X86_XSTATE_MPX; Hi, I have a series in flight that conflicts with this change: https://inbox.sourceware.org/gdb-patches/cover.1706801009.git.aburgess@redhat.com And so I'm trying to resolve the conflicts. Initially I thought I could test this by compiling something with the gcc -m32 option, but I now believe that is wrong, and I'd actually need to compile using -mx32, is this correct? Gcc seems to understand this option, but I appear to be missing the required development libraries, and I'm currently struggling to figure out what I'd need to install. Can you suggest a particular distro/version that should have the required development libraries available? Or maybe I'm just not understanding something here and you can point out what I'd doing wrong. The series of mine above came about for one reason: the `machine` type checks in the gdbserver are not a good idea, they rely on access to an executable, which isn't always available (e.g. if gdbserver attaches to a running process for which the executable is not available). When I started looking at this code I then decided to merge the whole target description logic between GDB and gdbserver for x86/linux. Which leads onto my second question; you changed the gdbserver code, but not the GDB code. Was this just an oversight? Or is there some reason why this fix doesn't need making for GDB too? Now worryingly, on the GDB side, in x86_linux_nat_target::read_description (gdb/x86-linux-nat.c) we do have a variable `is_x32` which I sounds like it should be true when we are debugging an x32 process.... but.... this variable is true for a binary compiled with the -m32 flag, which I don't think is right. If my understanding is correct then a -m32 binary is one compiled on an x86-64 machine, but which is uses 32-bit int/pointer types, and which only uses i386 instructions, and can use MPX, right? To summarise: 1. How might I go about compiling an x32 binary? 2. How can we detect an x32 process without checking the machine type? 3. Should your fix above be applied on the GDB side too? I've included below my initial attempt at a test for this change, currently it compiles with -m32 as (like I said) -mx32 doesn't work on my machine. I've been testing this: make check-gdb TESTS="gdb.arch/amd64-x32-no-mpx-in-tdesc.exp" \ RUNTESTFLAGS="--target_board=unix" make check-gdb TESTS="gdb.arch/amd64-x32-no-mpx-in-tdesc.exp" \ RUNTESTFLAGS="--target_board=native-gdbserver" make check-gdb TESTS="gdb.arch/amd64-x32-no-mpx-in-tdesc.exp" \ RUNTESTFLAGS="--target_board=native-extended-gdbserver" Currently it will fail for all as -m32 != -mx32 and the .mpx feature shows up (as expected). I guess you have a target which supports -mx32, so on that target you should be able to change the '-m32' in the test to '-mx32' and I would expect you to see the test pass for the gdbserver boards, but fail on the unix board. Thanks, Andrew --- commit 22167bc5c2f2770e1b1a3f0eb0569df3140921e8 Author: Andrew Burgess Date: Sat Mar 23 10:45:22 2024 +0000 WIP: New test diff --git a/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.c b/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.c new file mode 100644 index 00000000000..e2119ba7d92 --- /dev/null +++ b/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.c @@ -0,0 +1,22 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.exp b/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.exp new file mode 100644 index 00000000000..78e0d948348 --- /dev/null +++ b/gdb/testsuite/gdb.arch/amd64-x32-no-mpx-in-tdesc.exp @@ -0,0 +1,52 @@ +# Copyright 2024 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# This file is part of the gdb testsuite. + +# Check that the mpx feature is not present in the target description +# when debugging x32 binaries on an x86-64 target. + +require {istarget x86_64-*-*} + +standard_testfile +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + {debug additional_flags=-m32}] } { + return -1 +} + +if ![runto_main] { + return -1 +} + +set found_mpx false +gdb_test_multiple "maint print xml-tdesc" "" { + -re "^maint print xml-tdesc\r\n" { + exp_continue + } + + -re "^\\s+\r\n" { + set found_mpx true + exp_continue + } + + -re "^$gdb_prompt $" { + gdb_assert { !$found_mpx } \ + "mpx feature not in target description" + } + + -re "^\[^\r\n\]+\r\n" { + exp_continue + } +}