From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kbdzMPxspmlM0hEAWB0awg (envelope-from ) for ; Tue, 03 Mar 2026 00:09:16 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UKWfGNlN; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id C14721E0DD; Tue, 03 Mar 2026 00:09:16 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 419471E08D for ; Tue, 03 Mar 2026 00:09:15 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id EFC974BA23C9 for ; Tue, 3 Mar 2026 05:09:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFC974BA23C9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UKWfGNlN Received: from mail-dl1-x1235.google.com (mail-dl1-x1235.google.com [IPv6:2607:f8b0:4864:20::1235]) by sourceware.org (Postfix) with ESMTPS id BBCE94BA2E0D for ; Tue, 3 Mar 2026 05:06:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBCE94BA2E0D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BBCE94BA2E0D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1235 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772514417; cv=none; b=VCNxxiUSHJ+TD2rq+FQAePuvHvGrMInbD8fPwTaiWpbnM9Vw3UOlzvbkzsN1f9ig186AmA/Cp3PDQYx616Tp4WpiV955/C+16Ddhj1s55ShS7pZQMBobUOw5R5jgjraI7jkyjg/1mJfiv6cmHGJVlVVby5oramW0WTEOfT1jUdQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1772514417; c=relaxed/simple; bh=6Q1q3jbMFlNnXA4K10ZLTE+h4sHXeWrrC2Rh01fJqd4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=C9CP2yPytZLDl+4G9mpm27QOGxzqnDAScmdHQ0UkHO+dZXp27TmXz9K+LPC1MTk1725lsjP43/bPMBgAyZfjoznjj/rF8DOwTGWpvxqqXlclo17wJ2MdSxcngrAj5wsUu7umSERFQegaXKsWGMsAgzose6NX8JXsKibAAsuAJ+U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBCE94BA2E0D Received: by mail-dl1-x1235.google.com with SMTP id a92af1059eb24-1279eced0b9so2464215c88.0 for ; Mon, 02 Mar 2026 21:06:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1772514417; x=1773119217; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kparqPfFFpf4KPWN4n9IAAlDgpIWddpMjC5MTNg+HTQ=; b=UKWfGNlNhBqggnsHdCIxRjpCJmMoQKFDmubM1PxkNi9JJUHiWr0Yc9kLavJxWmnqf1 dROCNmH7jf6MxaVMBJe9zw+orfH8gYEhKQQ4rLNxb5McsoPZsDFxpwa697rQgVPfVKqP BIP+cY9NfbZOCkUbiSPqj/yDzr7GPc7OIgYSqZWCE22cnkwsnq1Fr99U/UcFsbuTnIWw NUlCtcUPqN3dwmuzkwHlfTKPWnPIeJvsioY6u9J4UIyVVYDVRHalMRLuFH6GfLgosut3 w3I6+X/7AGZ8oeGuXKvDXToGmQY11ZLo9KCk0pcrMrwT0vMtV4Jh382TXy1j9OSSJUgq MvJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772514417; x=1773119217; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=kparqPfFFpf4KPWN4n9IAAlDgpIWddpMjC5MTNg+HTQ=; b=hbMCDdamjZzsPjgtt2Un37QxQKO3iudBso70DsfH/z2vfIkkYMusvgbQu7g6BvDDvr tChj3Ynf1dzqQhzTy/hNGakm9GiatCt5pTO79cR7T7Ri7jhNlvgLVSMYSAeURa3L3LGr OxPB+nYeJg2HhugRkq8aKqu+PEecj2lasNeeUp6p1wXgpiAlw7tfgJUenOcBhF+TwxBu W1Yot27mV8KgHutOiYkjX9FyEfNDmFZQbbtif4S5/WylFXbKyVhptQjtocaYG9OW/Y9T 5L1thAiYi8TNvh2XU9CAwsaEJBgJsFKH3o6dYuRknmpUAKQAIz8T93fLbR0BHlaAP2Y1 6aGg== X-Gm-Message-State: AOJu0Ywiy8duqaIrI6S0BNwmJAarH7Oz1WBkgoCtd1KrXRUWeAQTtvxa 4SgP/Sew2J3rod9kZy0lXHlyvuOQCHG2LKAdoqN6yuzT84rBGzxGiNOd+VsaCVJMhZyXDzLMMv5 J3fvi0N0= X-Gm-Gg: ATEYQzx3PulFBvhyp4pH2M6/4DHsTpnnXQYqlFByvoqh98OJ+XSFTELAj6+uLvDjXlc rQa/mYDKr5UCS1q9OM7dUqwp25CC+g4pTxXlEn1aljuFNPmu5hXHbzbP32sou6wRKkRRqM92PDV 0mqPgCGyDa8ayA9kt2SOEy/nehPa+q6ZoCFIikMu8tP4PXsDZ62+gDE/UAEXnt/LW5oYKjagP9Y WTtVLQRHcfc1TCEjv1o9Q9AxqKsXmgV5PzQbf/a6RZiyX/l4juPKhf300ZaG7o0H3MwcAI17GAn 4OdhLIfKUW0hkWtIGDx4Q/OF8oW624hVySWlapU/JsiOs1GteNESlMQIOoUyY6CLMClagRM8K8U dyNqCaUQnqnW8VQ1GD8WGgB2W3gddFdtdzlKNW+Tlz0t/c/A0OIsPx6VRtYiKw3OlcurFY5KZwt CM7QnkPco2/6FYEpppx75FOotEcV1o+g6GGA== X-Received: by 2002:a05:7022:20d:b0:11a:51a8:eca with SMTP id a92af1059eb24-1278fb8fa29mr6457098c88.18.1772514416447; Mon, 02 Mar 2026 21:06:56 -0800 (PST) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12789a43a18sm19883751c88.13.2026.03.02.21.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 21:06:56 -0800 (PST) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Chris Packham , Luis , Tom Tromey , Simon Marchi , sunilkumar.dora@windriver.com Subject: [PATCH v4 5/6] GDB: aarch64-linux: Reorganize GCS-related definitions Date: Tue, 3 Mar 2026 02:06:40 -0300 Message-ID: <20260303050641.198127-6-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260303050641.198127-1-thiago.bauermann@linaro.org> References: <20260303050641.198127-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Only native code should use struct user_gcs, so its definition should be in a native-specific file and not in a file under gdb/arch/. To fix this problem, create gdb/nat/aarch64-gcs-linux-ptrace.h and move the struct user_gcs definition to it, as suggested by Luis. To fix the use of struct user_gcs in gdb/aarch64-linuxt-dep.c, define a macro with the size of the GCS regset in gdb/arch/aarch64-gcs-linux.h and use it in aarch64-linux-tdep.c, as is done for other regsets and following a suggestion from Simon Marchi. Also, move the HWCAP_GCS definition to gdb/nat/aarch64-gcs-linux-ptrace.h and create an AARCH64_HWCAP_GCS definition in gdb/arch/aarch64-gcs-linux.h for use by target-dependent code. Similarly, move the SEGV_CPERR and PR_SHADOW_STACK_{ENABLE,WRITE,PUSH} definitions, which were added by the GCS patches and are only used by aarch64-linux target-dependent code, to gdb/arch/aarch64-gcs-linux.h with an AARCH64_ prefix and adjust users. Finally, I noticed that gdb/aarch64-linux-nat.c and gdbserver/linux-aarch64-low.cc don't need anything from the arch/aarch64-gcs-linux.h header, so make them not include it. Suggested-by: Luis Suggested-by: Simon Marchi --- Changes since v3: - Move HWCAP_GCS definition to gdb/nat/aarch64-gcs-linux-ptrace.h. - Add AARCH64_HWCAP_GCS and use it in gdb/aarch64-linux-tdep.c. - Move the SEGV_CPERR and PR_SHADOW_STACK_{ENABLE,WRITE,PUSH} definitions to gdb/arch/aarch64-gcs-linux.h with an AARCH64_ prefix. - Remove inclusion of arch/aarch64-gcs-linux.h from gdb/aarch64-linux-nat.c and gdbserver/linux-aarch64-low.cc. Changes since v2: - Don't rename gdb/arch/aarch64-gcs-linux.h to gdb/arch/aarch64-linux.h, as suggested by Luis. - Create gdb/nat/aarch64-gcs-linux-ptrace.h to contain definition of struct user_gcs, as suggested by Luis. - Don't rename HWCAP_GCS to AARCH64_HWCAP_GCS, as suggested by Luis. - Move definition of AARCH64_LINUX_SIZEOF_GCS_REGSET from gdb/aarch64-linux-tdep.h to gdb/arch/aarch64-gcs-linux.h, as suggested by Luis. - Move changes to HWCAP_PACA to separate patch. gdb/Makefile.in | 1 + gdb/aarch64-linux-nat.c | 3 +-- gdb/aarch64-linux-tdep.c | 13 +++++----- gdb/arch/aarch64-gcs-linux.h | 24 ++++++------------ gdb/linux-tdep.h | 11 --------- gdb/nat/aarch64-gcs-linux.h | 45 ++++++++++++++++++++++++++++++++++ gdbserver/linux-aarch64-low.cc | 2 +- 7 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 gdb/nat/aarch64-gcs-linux.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 3d9bc86a97fd..4a68189b4340 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1548,6 +1548,7 @@ HFILES_NO_SRCDIR = \ moxie-tdep.h \ namespace.h \ nat/aarch64-fpmr-linux.h \ + nat/aarch64-gcs-linux.h \ nat/aarch64-hw-point.h \ nat/aarch64-linux.h \ nat/aarch64-linux-hw-point.h \ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 4b86ae9ebe16..52ace4aab411 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -33,6 +33,7 @@ #include "aarch32-tdep.h" #include "arch/arm.h" #include "nat/aarch64-fpmr-linux.h" +#include "nat/aarch64-gcs-linux.h" #include "nat/aarch64-linux.h" #include "nat/aarch64-linux-hw-point.h" #include "nat/aarch64-mte-linux-ptrace.h" @@ -54,8 +55,6 @@ #include "gdb_proc_service.h" #include "arch-utils.h" -#include "arch/aarch64-gcs-linux.h" - #include #ifndef TRAP_HWBKPT diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index 4ca05fba771d..d136b0f2145e 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -1736,8 +1736,9 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch, gcs_regmap, regcache_supply_regset, regcache_collect_regset }; - cb (".reg-aarch-gcs", sizeof (user_gcs), sizeof (user_gcs), - &aarch64_linux_gcs_regset, "GCS registers", cb_data); + cb (".reg-aarch-gcs", AARCH64_LINUX_SIZEOF_GCS_REGSET, + AARCH64_LINUX_SIZEOF_GCS_REGSET, &aarch64_linux_gcs_regset, + "GCS registers", cb_data); } } @@ -1763,7 +1764,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch, length. */ features.vq = aarch64_linux_core_read_vq_from_sections (gdbarch, abfd); features.pauth = hwcap & AARCH64_HWCAP_PACA; - features.gcs = features.gcs_linux = hwcap & HWCAP_GCS; + features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS; features.mte = hwcap2 & AARCH64_HWCAP2_MTE; features.fpmr = hwcap2 & AARCH64_HWCAP2_FPMR; @@ -2612,7 +2613,7 @@ aarch64_linux_get_shadow_stack_pointer (gdbarch *gdbarch, regcache *regcache, if (status != REG_VALID) error (_("Can't read $gcspr.")); - shadow_stack_enabled = features_enabled & PR_SHADOW_STACK_ENABLE; + shadow_stack_enabled = features_enabled & AARCH64_PR_SHADOW_STACK_ENABLE; return gcspr; } @@ -2700,7 +2701,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch, if (si_code == AARCH64_SEGV_MTEAERR || si_code == AARCH64_SEGV_MTESERR) meaning = _("Memory tag violation"); - else if (si_code == SEGV_CPERR && si_errno == 0) + else if (si_code == AARCH64_SEGV_CPERR && si_errno == 0) meaning = _("Guarded Control Stack error"); else return; @@ -2733,7 +2734,7 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch, uiout->field_string ("logical-tag", hex_string (ltag)); } } - else if (si_code != SEGV_CPERR) + else if (si_code != AARCH64_SEGV_CPERR) { uiout->text ("\n"); uiout->text (_("Fault address unavailable")); diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-gcs-linux.h index b31fc32daa03..4aa0cbd4def8 100644 --- a/gdb/arch/aarch64-gcs-linux.h +++ b/gdb/arch/aarch64-gcs-linux.h @@ -20,25 +20,17 @@ #ifndef GDB_ARCH_AARCH64_GCS_LINUX_H #define GDB_ARCH_AARCH64_GCS_LINUX_H -#include - /* Feature check for Guarded Control Stack. */ -#ifndef HWCAP_GCS -#define HWCAP_GCS (1ULL << 32) -#endif - -/* Make sure we only define these if the kernel header doesn't. */ -#ifndef GCS_MAGIC +#define AARCH64_HWCAP_GCS (1ULL << 32) -/* GCS state (NT_ARM_GCS). */ +#define AARCH64_SEGV_CPERR 10 /* Control protection error. */ -struct user_gcs -{ - uint64_t features_enabled; - uint64_t features_locked; - uint64_t gcspr_el0; -}; +/* Flag which enables shadow stack in PR_SET_SHADOW_STACK_STATUS prctl. */ +#define AARCH64_PR_SHADOW_STACK_ENABLE (1UL << 0) +#define AARCH64_PR_SHADOW_STACK_WRITE (1UL << 1) +#define AARCH64_PR_SHADOW_STACK_PUSH (1UL << 2) -#endif /* GCS_MAGIC */ +/* The GCS regset consists of 3 64-bit registers. */ +#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8) #endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */ diff --git a/gdb/linux-tdep.h b/gdb/linux-tdep.h index 73d4832069f4..aee52eae0f4a 100644 --- a/gdb/linux-tdep.h +++ b/gdb/linux-tdep.h @@ -27,17 +27,6 @@ struct inferior; struct regcache; -#ifndef SEGV_CPERR -#define SEGV_CPERR 10 /* Control protection error. */ -#endif - -/* Flag which enables shadow stack in PR_SET_SHADOW_STACK_STATUS prctl. */ -#ifndef PR_SHADOW_STACK_ENABLE -#define PR_SHADOW_STACK_ENABLE (1UL << 0) -#define PR_SHADOW_STACK_WRITE (1UL << 1) -#define PR_SHADOW_STACK_PUSH (1UL << 2) -#endif - /* Enum used to define the extra fields of the siginfo type used by an architecture. */ enum linux_siginfo_extra_field_values diff --git a/gdb/nat/aarch64-gcs-linux.h b/gdb/nat/aarch64-gcs-linux.h new file mode 100644 index 000000000000..ddf8342a4284 --- /dev/null +++ b/gdb/nat/aarch64-gcs-linux.h @@ -0,0 +1,45 @@ +/* Common native Linux definitions for AArch64 Guarded Control Stack. + + Copyright (C) 2025-2026 Free Software Foundation, Inc. + + This file is part of GDB. + + 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 . */ + +#ifndef GDB_NAT_AARCH64_GCS_LINUX_H +#define GDB_NAT_AARCH64_GCS_LINUX_H + +#include +#include + +/* Feature check for Guarded Control Stack. */ +#ifndef HWCAP_GCS +#define HWCAP_GCS (1ULL << 32) +#endif + +/* Make sure we only define these if the kernel header doesn't. */ +#ifndef GCS_MAGIC + +/* GCS state (NT_ARM_GCS). */ + +struct user_gcs +{ + uint64_t features_enabled; + uint64_t features_locked; + uint64_t gcspr_el0; +}; + +#endif /* GCS_MAGIC */ + +#endif /* GDB_NAT_AARCH64_GCS_LINUX_H */ diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index c44f75167141..a2588a6e2a9c 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -40,12 +40,12 @@ #include "gdb_proc_service.h" #include "arch/aarch64.h" -#include "arch/aarch64-gcs-linux.h" #include "arch/aarch64-mte-linux.h" #include "arch/aarch64-pauth-linux.h" #include "linux-aarch32-tdesc.h" #include "linux-aarch64-tdesc.h" #include "nat/aarch64-fpmr-linux.h" +#include "nat/aarch64-gcs-linux.h" #include "nat/aarch64-mte-linux-ptrace.h" #include "nat/aarch64-scalable-linux-ptrace.h" #include "tdesc.h"