aboutsummaryrefslogtreecommitdiff
path: root/gdb/features
diff options
context:
space:
mode:
authorThiago Jung Bauermann <thiago.bauermann@linaro.org>2025-05-01 18:12:19 -0300
committerThiago Jung Bauermann <thiago.bauermann@linaro.org>2025-08-29 18:35:58 -0300
commitff62d39aa4999f44ac79360dee6357fc69d4e322 (patch)
tree70213c3c357a5e93fa6ce54837100045306aa70e /gdb/features
parent02ecff0c714254cd5a67b55a6d11d62cfd904dbc (diff)
downloadbinutils-ff62d39aa4999f44ac79360dee6357fc69d4e322.zip
binutils-ff62d39aa4999f44ac79360dee6357fc69d4e322.tar.gz
binutils-ff62d39aa4999f44ac79360dee6357fc69d4e322.tar.bz2
GDB, gdbserver: aarch64-linux: Initial Guarded Control Stack support
Add the org.gnu.gdb.aarch64.gcs feature with the GCSPR register, and the org.gnu.gdb.aarch64.gcs.linux feature with "registers" to represent the Linux kernel ptrace and prctl knobs that enable and lock specific GCS functionality. This code supports GCS only in Linux userspace applications, so the GCSPR that is exposed is the one at EL0. Also, support for calling inferior functions is enabled by adding an implementation for the shadow_stack_push gdbarch method. If for some reason a target description contains the org.gnu.gdb.aarch64.gcs feature but not the org.gnu.gdb.aarch64.gcs.linux feature then GCS support is disabled and GDB continues the debugging session. Features that need GCS support (for example, calling inferior functions) will not work and the inferior will get a segmentation fault signal instead. There's a testcase for this scenario but it only checks the native debugging case, even though in practice this problem would only occur in remote debugging with a broken stub or gdbserver. I tested manually with a gdbserver hacked to send a broken target description and it worked as described. Testcases gdb.arch/aarch64-gcs.exp, gdb.arch/aarch64-gcs-core.exp and gdb.arch/aarch64-gcs-wrong-tdesc.exp are included to cover the added functionality. Reviewed-By: Christina Schimpe <christina.schimpe@intel.com> Approved-By: Luis Machado <luis.machado@arm.com>
Diffstat (limited to 'gdb/features')
-rw-r--r--gdb/features/Makefile2
-rw-r--r--gdb/features/aarch64-gcs-linux.c21
-rw-r--r--gdb/features/aarch64-gcs-linux.xml18
-rw-r--r--gdb/features/aarch64-gcs.c14
-rw-r--r--gdb/features/aarch64-gcs.xml11
5 files changed, 66 insertions, 0 deletions
diff --git a/gdb/features/Makefile b/gdb/features/Makefile
index b206ddd..d17c349 100644
--- a/gdb/features/Makefile
+++ b/gdb/features/Makefile
@@ -204,6 +204,8 @@ FEATURE_XMLFILES = aarch64-core.xml \
aarch64-fpu.xml \
aarch64-pauth.xml \
aarch64-mte.xml \
+ aarch64-gcs.xml \
+ aarch64-gcs-linux.xml \
arc/v1-core.xml \
arc/v1-aux.xml \
arc/v2-core.xml \
diff --git a/gdb/features/aarch64-gcs-linux.c b/gdb/features/aarch64-gcs-linux.c
new file mode 100644
index 0000000..6b0d25b
--- /dev/null
+++ b/gdb/features/aarch64-gcs-linux.c
@@ -0,0 +1,21 @@
+/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro:
+ Original: aarch64-gcs-linux.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_aarch64_gcs_linux (struct target_desc *result, long regnum)
+{
+ struct tdesc_feature *feature;
+
+ feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.gcs.linux");
+ tdesc_type_with_fields *type_with_fields;
+ type_with_fields = tdesc_create_flags (feature, "features_flags", 8);
+ tdesc_add_flag (type_with_fields, 0, "PR_SHADOW_STACK_ENABLE");
+ tdesc_add_flag (type_with_fields, 1, "PR_SHADOW_STACK_WRITE");
+ tdesc_add_flag (type_with_fields, 2, "PR_SHADOW_STACK_PUSH");
+
+ tdesc_create_reg (feature, "gcs_features_enabled", regnum++, 1, "system", 64, "features_flags");
+ tdesc_create_reg (feature, "gcs_features_locked", regnum++, 1, "system", 64, "features_flags");
+ return regnum;
+}
diff --git a/gdb/features/aarch64-gcs-linux.xml b/gdb/features/aarch64-gcs-linux.xml
new file mode 100644
index 0000000..8d9d2ce
--- /dev/null
+++ b/gdb/features/aarch64-gcs-linux.xml
@@ -0,0 +1,18 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2025 Free Software Foundation, Inc.
+
+ Copying and distribution of this file, with or without modification,
+ are permitted in any medium without royalty provided the copyright
+ notice and this notice are preserved. -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.aarch64.gcs.linux">
+ <flags id="features_flags" size="8">
+ <field name="PR_SHADOW_STACK_ENABLE" start="0" end="0"/>
+ <field name="PR_SHADOW_STACK_WRITE" start="1" end="1"/>
+ <field name="PR_SHADOW_STACK_PUSH" start="2" end="2"/>
+ </flags>
+
+ <reg name="gcs_features_enabled" bitsize="64" type="features_flags" group="system"/>
+ <reg name="gcs_features_locked" bitsize="64" type="features_flags" group="system"/>
+</feature>
diff --git a/gdb/features/aarch64-gcs.c b/gdb/features/aarch64-gcs.c
new file mode 100644
index 0000000..2b2caf2
--- /dev/null
+++ b/gdb/features/aarch64-gcs.c
@@ -0,0 +1,14 @@
+/* THIS FILE IS GENERATED. -*- buffer-read-only: t -*- vi:set ro:
+ Original: aarch64-gcs.xml */
+
+#include "gdbsupport/tdesc.h"
+
+static int
+create_feature_aarch64_gcs (struct target_desc *result, long regnum)
+{
+ struct tdesc_feature *feature;
+
+ feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.gcs");
+ tdesc_create_reg (feature, "gcspr", regnum++, 1, "system", 64, "data_ptr");
+ return regnum;
+}
diff --git a/gdb/features/aarch64-gcs.xml b/gdb/features/aarch64-gcs.xml
new file mode 100644
index 0000000..bbee5e0
--- /dev/null
+++ b/gdb/features/aarch64-gcs.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2025 Free Software Foundation, Inc.
+
+ Copying and distribution of this file, with or without modification,
+ are permitted in any medium without royalty provided the copyright
+ notice and this notice are preserved. -->
+
+<!DOCTYPE feature SYSTEM "gdb-target.dtd">
+<feature name="org.gnu.gdb.aarch64.gcs">
+ <reg name="gcspr" bitsize="64" type="data_ptr" group="system"/>
+</feature>