From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CQWiN2UAkGnpNToAWB0awg (envelope-from ) for ; Fri, 13 Feb 2026 23:56:05 -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=OdegbCAy; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DBB6C1E0BA; Fri, 13 Feb 2026 23:56:05 -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 A38751E089 for ; Fri, 13 Feb 2026 23:56:04 -0500 (EST) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 377054BAD148 for ; Sat, 14 Feb 2026 04:56:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 377054BAD148 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=OdegbCAy Received: from mail-dl1-x1233.google.com (mail-dl1-x1233.google.com [IPv6:2607:f8b0:4864:20::1233]) by sourceware.org (Postfix) with ESMTPS id CB5D14B9DB49 for ; Sat, 14 Feb 2026 04:55:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB5D14B9DB49 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 CB5D14B9DB49 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1233 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771044912; cv=none; b=a2OTu2XB8TUg3jxAC+zt1ywfilap+U8MrZvEGrc6yeCiRPQg2Qv7P8kgs01Rt5TzyaQQjj+2j/kVgxx7s+hbLWPsiaO2bgTBdFEJE048XHRarueEfp7P1g3n8XZSZgrWGNdgXK9sEX9V6w4jSE+RdgH1id/DB5g/lQR5r33VDOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1771044912; c=relaxed/simple; bh=HEze1T+DlSneoVAIlyiugWB8288gXu4L4gQAyF3vCSM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Smnthay3fdTXGtYH1aUx8uu04XBbc+o47e1ZgcgLKZqPdzeBmNgqDe5LbVryC/6B/VpQPrF4Y6FCjRgba4Sz1iV9NaVefgObSHz78lQxSA+vbJp/hB8blaNjeiCBbs0ZPp2kAyqdPAV+MEKvE/JUGgB+olxx4L/XGH6RkCVcXKk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CB5D14B9DB49 Received: by mail-dl1-x1233.google.com with SMTP id a92af1059eb24-1271195d2a7so1972388c88.0 for ; Fri, 13 Feb 2026 20:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1771044911; x=1771649711; 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=R4862yxQK/Qur4B46CqfLVvcHGzMqnObLBiXIMRLC84=; b=OdegbCAye2PH54TTNehx0Aruzz42MafYE59O16XaaMmkvXPAPpw0141N5CG7cRqgJ0 wniEzuQ/iSYQ38itvm2bxOt8Xcg5FYXshhclvNDRNSacqvDgzxIhxPbQ5fXWL9yy3G+4 oJAHjQ1u210aVY+faYPVbihzDTH9Yj0NuxM4tW8p/6WxezlhTH5P5iAqdQKaFqtQL6e7 XNHOQHH7NFMcGcLfTo2tttoJnidqsMQ4Y+1M/RjrNyHASuaMyX7c9Xv+dTiKSblpAMPH fRv2nH4IpWIaMqJAI+Tv9dmeginIJ/Zy5pK7EyMiATfiazv4yxdteVQHKA/mQR9zUDQ0 2Ohg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771044911; x=1771649711; 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=R4862yxQK/Qur4B46CqfLVvcHGzMqnObLBiXIMRLC84=; b=lGndd8MZn+tg77/1S4jY1tpwOOhdYZOXC1yxfX5Y4FiNv1UvTeZIXG7cfbXPIlWQDn o6Wns7Hkk/cWfnXs4LXt5oCdRIIfD5exCedffKBbVeTm2NNS0ZXN0l6rd8bMTojYoWGQ 0QyvlTKxZSdP74RstUsn64qpNiURYnuTbBsdfZy1j2KMTaPJiESaK755oX4gqSXWAELt aZlY1cTvlMasuoWUr63bb8a40F1RJFcmlQi0EP6TJuzmqVR/zo6ox9mCxqTzdAsSJ1ag 7h9UM4qsW49M4GO6dkTRRCCKCMtqomaF9PZgkOcrX8BNIKN97jsL+ZFwV6W1y439r/FN xs9A== X-Gm-Message-State: AOJu0Yxzl61/8qDYLc6Y5jndl/imHeTcGKWborQdn8cdszNk/hGGY/x1 tS9REy7gxII3hcxvA7ZKNu+4XYie3KXgJHSVDSpdhZzfaBXmG38E2QBEIzhjr/QxiK8tZn/Q2nm QJynh X-Gm-Gg: AZuq6aK8lhj+TwP9zJDmlHB0YjKY6/0+p8m8dL8qpMeGksTqCN0owOyz74NwLePB4pl Gwo33+PpqhDtlB7Sl8qeWQyp/ZF+1msNhYe7K/p9o53cL232ufT5+WbLLvvS/WtT72BnjrwDOYv 1UPUG8oADAzv+GDxxxn4L5mTZVLGQNvfuLLVOJiUaEBrzKZD7MWliaz1bzzHslzWEvLLN3hPUg4 h9iidudP79wTWxl1SWWQieAfr6Uiq79569Ouinx8DJD3EOfPTwG4PoVpy61cS7nosGJJ2KHhgUY gf7QwngjbRkvmaU+mnY3ujIbwGBTONeZLzYZUiap3x3bWQR1AGQV4iEL4OOAotMDEIuXLcRfOr6 7AcW2x6a81V+Kjij9w1M3EylmJrAogw3hBD8+gz0eqnhCyTy4t5vX4+aOd1gfnBYFUK69uB3OXP +Z1EgsfgRFYbBXmp+RyppCJVLwyfZIkXdQU130HR+xELlV X-Received: by 2002:a05:7022:45a8:b0:119:e569:f277 with SMTP id a92af1059eb24-12741bc94bemr926407c88.32.1771044910653; Fri, 13 Feb 2026 20:55:10 -0800 (PST) Received: from localhost ([2804:14d:7e39:8083:f04c:42e3:5943:38f6]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-12742b62455sm1183074c88.1.2026.02.13.20.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Feb 2026 20:55:10 -0800 (PST) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Chris Packham , Luis , Tom Tromey , Simon Marchi Subject: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Date: Sat, 14 Feb 2026 01:54:48 -0300 Message-ID: <20260214045504.361392-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260214045504.361392-1-thiago.bauermann@linaro.org> References: <20260214045504.361392-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 This file implicitly depends on aarch64-linux's for the definition of GCS_MAGIC and on its for the definition of HWCAP_GCS, but files on gdb/arch/ shouldn't depend on include files specific to the architecture. Regarding GCS_MAGIC and struct user_gcs, move that code section to gdb/nat/aarch64-linux.h which can rely on and . 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 aarch64-linux-tdep.h and use it in aarch64-linux-tdep.c, as is done for other regsets and following a suggestion from Simon Marchi. Regarding HWCAP_GCS, rename it to AARCH64_HWCAP_GCS to ensure that it won't conflict with any system header definition and define it unconditionally, following the example of AARCH64_HWCAP_PACA. Renaming HWCAP_GCS also avoids a potential (and I would say unlikely) problem on non-AArch64 systems: naming conflict if by coincidence they have an unrelated hardware capability bit also named HWCAP_GCS. Finally, I noticed that AARCH64_HWCAP_PACA is duplicated in GDB and gdbserver files, so consolidate them in the same header and rename it to gdb/arch/aarch64-linux.h since it isn't just about GCS anymore. --- As I mentioned on v1's email thread, this patch opens a small can of worms, since other gdb/arch/aarch64*.h do the same kind of thing (mostly with HWCAP macros but also a few others). Perhaps I'm going too far with the HWCAP_GCS renaming and the current handling of it is fine? gdb/Makefile.in | 2 +- gdb/aarch64-linux-nat.c | 4 +-- gdb/aarch64-linux-tdep.c | 9 +++--- gdb/aarch64-linux-tdep.h | 6 ++-- .../{aarch64-gcs-linux.h => aarch64-linux.h} | 30 +++++-------------- gdb/nat/aarch64-linux.h | 16 ++++++++++ gdbserver/linux-aarch64-low.cc | 7 ++--- 7 files changed, 36 insertions(+), 38 deletions(-) rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%) diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 2aa95be968ac..fd47c613966a 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1301,7 +1301,7 @@ HFILES_NO_SRCDIR = \ amdgpu-tdep.h \ annotate.h \ arch/aarch32.h \ - arch/aarch64-gcs-linux.h \ + arch/aarch64-linux.h \ arch/aarch64.h \ arch/aarch64-insn.h \ arch/aarch64-mte.h \ diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c index 028de981588b..b2dd192a7b56 100644 --- a/gdb/aarch64-linux-nat.c +++ b/gdb/aarch64-linux-nat.c @@ -51,7 +51,7 @@ #include "gdb_proc_service.h" #include "arch-utils.h" -#include "arch/aarch64-gcs-linux.h" +#include "arch/aarch64-linux.h" #include "arch/aarch64-mte-linux.h" #include "nat/aarch64-mte-linux-ptrace.h" @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description () active or not. */ features.vq = aarch64_sve_get_vq (tid); 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 & HWCAP2_MTE; features.tls = aarch64_tls_register_count (tid); /* SME feature check. */ diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c index b85c25ecae1d..33e1b411ff1d 100644 --- a/gdb/aarch64-linux-tdep.c +++ b/gdb/aarch64-linux-tdep.c @@ -51,7 +51,7 @@ #include "record-full.h" #include "linux-record.h" -#include "arch/aarch64-gcs-linux.h" +#include "arch/aarch64-linux.h" #include "arch/aarch64-mte.h" #include "arch/aarch64-mte-linux.h" #include "arch/aarch64-scalable-linux.h" @@ -1734,8 +1734,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); } } @@ -1761,7 +1762,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 & HWCAP2_MTE; features.fpmr = hwcap2 & HWCAP2_FPMR; diff --git a/gdb/aarch64-linux-tdep.h b/gdb/aarch64-linux-tdep.h index e926687ff6eb..f247d6aa72cd 100644 --- a/gdb/aarch64-linux-tdep.h +++ b/gdb/aarch64-linux-tdep.h @@ -39,10 +39,10 @@ /* The MTE regset consists of a 64-bit register. */ #define AARCH64_LINUX_SIZEOF_MTE_REGSET (8) +/* The GCS regset consists of 3 64-bit registers. */ +#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8) + extern const struct regset aarch64_linux_gregset; extern const struct regset aarch64_linux_fpregset; -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h. */ -#define AARCH64_HWCAP_PACA (1 << 30) - #endif /* GDB_AARCH64_LINUX_TDEP_H */ diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-linux.h similarity index 61% rename from gdb/arch/aarch64-gcs-linux.h rename to gdb/arch/aarch64-linux.h index b31fc32daa03..a33c082a0318 100644 --- a/gdb/arch/aarch64-gcs-linux.h +++ b/gdb/arch/aarch64-linux.h @@ -1,4 +1,4 @@ -/* Common Linux target-dependent definitions for AArch64 GCS +/* Common Linux target-dependent definitions for AArch64 running Linux. Copyright (C) 2025-2026 Free Software Foundation, Inc. @@ -17,28 +17,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#ifndef GDB_ARCH_AARCH64_GCS_LINUX_H -#define GDB_ARCH_AARCH64_GCS_LINUX_H - -#include +#ifndef GDB_ARCH_AARCH64_LINUX_H +#define GDB_ARCH_AARCH64_LINUX_H +/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h. */ +#define AARCH64_HWCAP_PACA (1 << 30) /* 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 */ +#define AARCH64_HWCAP_GCS (1ULL << 32) -#endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */ +#endif /* GDB_ARCH_AARCH64_LINUX_H */ diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h index bb5381eba3ef..f7c09aa112bf 100644 --- a/gdb/nat/aarch64-linux.h +++ b/gdb/nat/aarch64-linux.h @@ -19,7 +19,9 @@ #ifndef GDB_NAT_AARCH64_LINUX_H #define GDB_NAT_AARCH64_LINUX_H +#include #include +#include /* Defines ps_err_e, struct ps_prochandle. */ #include "gdb_proc_service.h" @@ -113,6 +115,20 @@ typedef struct compat_siginfo #define cpt_si_band _sifields._sigpoll._band #define cpt_si_fd _sifields._sigpoll._fd +/* 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 */ + void aarch64_siginfo_from_compat_siginfo (siginfo_t *to, compat_siginfo_t *from); void aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to, diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc index b19e605f55d6..60ea50f609cc 100644 --- a/gdbserver/linux-aarch64-low.cc +++ b/gdbserver/linux-aarch64-low.cc @@ -39,7 +39,7 @@ #include "gdb_proc_service.h" #include "arch/aarch64.h" -#include "arch/aarch64-gcs-linux.h" +#include "arch/aarch64-linux.h" #include "arch/aarch64-mte-linux.h" #include "arch/aarch64-scalable-linux.h" #include "linux-aarch32-tdesc.h" @@ -984,9 +984,6 @@ aarch64_adjust_register_sets (const struct aarch64_features &features) } } -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h. */ -#define AARCH64_HWCAP_PACA (1 << 30) - /* Implementation of linux target ops method "low_arch_setup". */ void @@ -1009,7 +1006,7 @@ aarch64_target::low_arch_setup () /* A-profile MTE is 64-bit only. */ features.mte = linux_get_hwcap2 (pid, 8) & HWCAP2_MTE; features.tls = aarch64_tls_register_count (tid); - features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & HWCAP_GCS; + features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & AARCH64_HWCAP_GCS; features.fpmr = linux_get_hwcap2 (pid, 8) & HWCAP2_FPMR; /* Scalable Matrix Extension feature and size check. */