AArch64: Add pointer authentication feature
authorAlan Hayward <alan.hayward@arm.com>
Fri, 22 Mar 2019 09:58:42 +0000 (09:58 +0000)
committerAlan Hayward <alan.hayward@arm.com>
Fri, 22 Mar 2019 09:58:42 +0000 (09:58 +0000)
Pointer Authentication is a new feature in AArch64 v8.3-a. When enabled in
the compiler, function return addresses will be mangled by the kernel.

Add register description xml and wire up to aarch64_linux_read_description.
This description includes the two pauth user registers.

Nothing yet uses the feature - that is added in later patches.

gdb/ChangeLog:

* aarch64-linux-nat.c
(aarch64_linux_nat_target::read_description): Add pauth param.
* aarch64-linux-tdep.c
(aarch64_linux_core_read_description): Likewise.
* aarch64-tdep.c (struct target_desc): Add in pauth.
(aarch64_read_description): Add pauth param.
(aarch64_gdbarch_init): Likewise.
* aarch64-tdep.h (aarch64_read_description): Likewise.
* arch/aarch64.c (aarch64_create_target_description): Likewise.
* arch/aarch64.h (aarch64_create_target_description): Likewise.
* features/Makefile: Add new files.
* features/aarch64-pauth.c: New file.
* features/aarch64-pauth.xml: New file.

gdb/doc/ChangeLog:

* gdb.texinfo: Describe pauth feature.

gdb/gdbserver/ChangeLog:

* linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
(initialize_low_tracepoint): Likewise.
* linux-aarch64-low.c (aarch64_arch_setup): Likewise.
* linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
* linux-aarch64-tdesc.c (struct target_desc): Likewise.
(aarch64_linux_read_description): Likewise.
* linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.

18 files changed:
gdb/ChangeLog
gdb/aarch64-linux-nat.c
gdb/aarch64-linux-tdep.c
gdb/aarch64-tdep.c
gdb/aarch64-tdep.h
gdb/arch/aarch64.c
gdb/arch/aarch64.h
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/features/Makefile
gdb/features/aarch64-pauth.c [new file with mode: 0644]
gdb/features/aarch64-pauth.xml [new file with mode: 0644]
gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-aarch64-ipa.c
gdb/gdbserver/linux-aarch64-low.c
gdb/gdbserver/linux-aarch64-tdesc-selftest.c
gdb/gdbserver/linux-aarch64-tdesc.c
gdb/gdbserver/linux-aarch64-tdesc.h

index 4345e014695f79e329951e65ac5b71a2fb21f263..743f510b29523f34a40a5960df806a63caeaf96c 100644 (file)
@@ -1,3 +1,20 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+           Jiong Wang  <jiong.wang@arm.com>
+
+       * aarch64-linux-nat.c
+       (aarch64_linux_nat_target::read_description): Add pauth param.
+       * aarch64-linux-tdep.c
+       (aarch64_linux_core_read_description): Likewise.
+       * aarch64-tdep.c (struct target_desc): Add in pauth.
+       (aarch64_read_description): Add pauth param.
+       (aarch64_gdbarch_init): Likewise.
+       * aarch64-tdep.h (aarch64_read_description): Likewise.
+       * arch/aarch64.c (aarch64_create_target_description): Likewise.
+       * arch/aarch64.h (aarch64_create_target_description): Likewise.
+       * features/Makefile: Add new files.
+       * features/aarch64-pauth.c: New file.
+       * features/aarch64-pauth.xml: New file.
+
 2019-03-20  Tom Tromey  <tromey@adacore.com>
 
        * infrun.c (handle_inferior_event): Rename from
index 6f91e9568e57e43bfb31a6d3ab77d403487c6ccf..f58a41e19555b87b07d037ce87b6379d0c3fb1e7 100644 (file)
@@ -605,8 +605,9 @@ aarch64_linux_nat_target::read_description ()
   ret = ptrace (PTRACE_GETREGSET, tid, NT_ARM_VFP, &iovec);
   if (ret == 0)
     return tdesc_arm_with_neon;
-  else
-    return aarch64_read_description (aarch64_sve_get_vq (tid));
+
+  /* pauth not yet supported.  */
+  return aarch64_read_description (aarch64_sve_get_vq (tid), false);
 }
 
 /* Convert a native/host siginfo object, into/from the siginfo in the
index 39e607658f45494382598d220ab315b8b74c191e..445019accc74ead28e3da30416adc856d847aebb 100644 (file)
@@ -640,7 +640,9 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
   if (target_auxv_search (target, AT_HWCAP, &aarch64_hwcap) != 1)
     return NULL;
 
-  return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd));
+  /* pauth not yet supported.  */
+  return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
+                                  false);
 }
 
 /* Implementation of `gdbarch_stap_is_single_operand', as defined in
index dd57ef987396f784a26dffc96cd87a46f16771ab..0518837a1f992fd1a901d3d3c73e45faf5913f68 100644 (file)
@@ -69,7 +69,7 @@
 #define HA_MAX_NUM_FLDS                4
 
 /* All possible aarch64 target descriptors.  */
-struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1];
+struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/];
 
 /* The standard register names, and all the valid aliases for them.  */
 static const struct
@@ -2885,18 +2885,18 @@ aarch64_displaced_step_hw_singlestep (struct gdbarch *gdbarch,
    (It is not possible to set VQ to zero on an SVE system).  */
 
 const target_desc *
-aarch64_read_description (uint64_t vq)
+aarch64_read_description (uint64_t vq, bool pauth_p)
 {
   if (vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq,
           AARCH64_MAX_SVE_VQ);
 
-  struct target_desc *tdesc = tdesc_aarch64_list[vq];
+  struct target_desc *tdesc = tdesc_aarch64_list[vq][pauth_p];
 
   if (tdesc == NULL)
     {
-      tdesc = aarch64_create_target_description (vq);
-      tdesc_aarch64_list[vq] = tdesc;
+      tdesc = aarch64_create_target_description (vq, pauth_p);
+      tdesc_aarch64_list[vq][pauth_p] = tdesc;
     }
 
   return tdesc;
@@ -2961,7 +2961,7 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
 
   /* Ensure we always have a target description.  */
   if (!tdesc_has_registers (tdesc))
-    tdesc = aarch64_read_description (0);
+    tdesc = aarch64_read_description (0, false);
   gdb_assert (tdesc);
 
   feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.aarch64.core");
@@ -3190,7 +3190,7 @@ When on, AArch64 specific debugging is enabled."),
   selftests::register_test ("aarch64-process-record",
                            selftests::aarch64_process_record_test);
   selftests::record_xml_tdesc ("aarch64.xml",
-                              aarch64_create_target_description (0));
+                              aarch64_create_target_description (0, false));
 #endif
 }
 
index 704eacb50c8a13ddaa9ada43f42ac44b6b84a43a..3db6bee9f3fed032f9c2ca6234a44599416fb0df 100644 (file)
@@ -89,7 +89,7 @@ struct gdbarch_tdep
   }
 };
 
-const target_desc *aarch64_read_description (uint64_t vq);
+const target_desc *aarch64_read_description (uint64_t vq, bool pauth_p);
 
 extern int aarch64_process_record (struct gdbarch *gdbarch,
                                struct regcache *regcache, CORE_ADDR addr);
index d36ed9d19e80aba49cf777e2b8c325f92afa5dde..11a15dd94cb145a5d0d67fbce6e8809891fabec6 100644 (file)
 #include "../features/aarch64-core.c"
 #include "../features/aarch64-fpu.c"
 #include "../features/aarch64-sve.c"
+#include "../features/aarch64-pauth.c"
 
 /* See arch/aarch64.h.  */
 
 target_desc *
-aarch64_create_target_description (uint64_t vq)
+aarch64_create_target_description (uint64_t vq, bool pauth_p)
 {
   target_desc *tdesc = allocate_target_description ();
 
@@ -43,5 +44,8 @@ aarch64_create_target_description (uint64_t vq)
   else
     regnum = create_feature_aarch64_sve (tdesc, regnum, vq);
 
+  if (pauth_p)
+    regnum = create_feature_aarch64_pauth (tdesc, regnum);
+
   return tdesc;
 }
index 807a4a6558bb93b02dd2f28f3f415435d123e996..4fe6d02f6e23d47ec9595c170c6fe3450352051b 100644 (file)
 
 /* Create the aarch64 target description.  A non zero VQ value indicates both
    the presence of SVE and the Vector Quotient - the number of 128bit chunks in
-   an SVE Z register.  */
+   an SVE Z register.  HAS_PAUTH_P indicates the presence of the PAUTH
+   feature.  */
 
-target_desc *aarch64_create_target_description (uint64_t vq);
+target_desc *aarch64_create_target_description (uint64_t vq, bool has_pauth_p);
 
 /* Register numbers of various important registers.
    Note that on SVE, the Z registers reuse the V register numbers and the V
index 447d74e2fa417dfcadb0154bd2f7abf00e9f7718..1f41498dc834baf28104cd63cbd67026fa76c532 100644 (file)
@@ -1,3 +1,8 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+           Jiong Wang  <jiong.wang@arm.com>
+
+       * gdb.texinfo (AArch64 Features): Describe pauth feature.
+
 2019-03-20  Tom Tromey  <tromey@adacore.com>
 
        * python.texi (Selecting Pretty-Printers): Use @defvar for
index 271739b6cdc942e5415e9675f1188fc67c78d7fc..4c1d5e8294fe200c36ac19e7f07e9964296c385b 100644 (file)
@@ -43162,6 +43162,9 @@ The @samp{org.gnu.gdb.aarch64.sve} feature is optional.  If present,
 it should contain registers @samp{z0} through @samp{z31}, @samp{p0}
 through @samp{p15}, @samp{ffr} and @samp{vg}.
 
+The @samp{org.gnu.gdb.aarch64.pauth} feature is optional.  If present,
+it should contain registers @samp{pauth_dmask} and @samp{pauth_cmask}.
+
 @node ARC Features
 @subsection ARC Features
 @cindex target descriptions, ARC Features
index 3d84ca09a15bc969570468acaa8b662c8f7c892a..d0cd4f851fc60aa3f4b2a00352086ea6c3c30e24 100644 (file)
@@ -227,6 +227,7 @@ $(outdir)/%.dat: %.xml number-regs.xsl sort-regs.xsl gdbserver-regs.xsl
 
 FEATURE_XMLFILES = aarch64-core.xml \
        aarch64-fpu.xml \
+       aarch64-pauth.xml \
        i386/32bit-core.xml \
        i386/32bit-sse.xml \
        i386/32bit-linux.xml \
diff --git a/gdb/features/aarch64-pauth.c b/gdb/features/aarch64-pauth.c
new file mode 100644 (file)
index 0000000..e4b84ff
--- /dev/null
@@ -0,0 +1,16 @@
+/* THIS FILE IS GENERATED.  -*- buffer-read-only: t -*- vi:set ro:
+  Original: aarch64-pauth.xml */
+
+#include "common/tdesc.h"
+
+static int
+create_feature_aarch64_pauth (struct target_desc *result, long regnum)
+{
+  struct tdesc_feature *feature;
+
+  feature = tdesc_create_feature (result, "org.gnu.gdb.aarch64.pauth");
+  tdesc_create_reg (feature, "pauth_dmask", regnum++, 1, NULL, 64, "int");
+  tdesc_create_reg (feature, "pauth_cmask", regnum++, 1, NULL, 64, "int");
+
+  return regnum;
+}
diff --git a/gdb/features/aarch64-pauth.xml b/gdb/features/aarch64-pauth.xml
new file mode 100644 (file)
index 0000000..9c8987f
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!-- Copyright (C) 2018 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.pauth">
+  <reg name="pauth_dmask" bitsize="64"/>
+  <reg name="pauth_cmask" bitsize="64"/>
+</feature>
+
index 9879481b17ef01671e2d1e96c39535fbbbce3def..9fdbe1d866ee9ce9a4ecfb79ea5f99f6b3ac8c25 100644 (file)
@@ -1,3 +1,14 @@
+2019-03-22  Alan Hayward  <alan.hayward@arm.com>
+           Jiong Wang  <jiong.wang@arm.com>
+
+       * linux-aarch64-ipa.c (get_ipa_tdesc): Add pauth param.
+       (initialize_low_tracepoint): Likewise.
+       * linux-aarch64-low.c (aarch64_arch_setup): Likewise.
+       * linux-aarch64-tdesc-selftest.c (aarch64_tdesc_test): Likewise.
+       * linux-aarch64-tdesc.c (struct target_desc): Likewise.
+       (aarch64_linux_read_description): Likewise.
+       * linux-aarch64-tdesc.h (aarch64_linux_read_description): Likewise.
+
 2019-03-12  John Baldwin  <jhb@FreeBSD.org>
 
        * linux-x86-tdesc.c (i386_linux_read_description): Update call to
index 94db53f59ad38c68b82d625ff6d531ab2bf7582d..3804b1e23941a8050c341c516d44678678b949cc 100644 (file)
@@ -147,12 +147,12 @@ get_raw_reg (const unsigned char *raw_regs, int regnum)
 
 /* Return target_desc to use for IPA, given the tdesc index passed by
    gdbserver.  Index is ignored, since we have only one tdesc
-   at the moment.  SVE not yet supported.  */
+   at the moment.  SVE and pauth not yet supported.  */
 
 const struct target_desc *
 get_ipa_tdesc (int idx)
 {
-  return aarch64_linux_read_description (0);
+  return aarch64_linux_read_description (0, false);
 }
 
 /* Allocate buffer for the jump pads.  The branch instruction has a reach
@@ -204,6 +204,6 @@ alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-  /* SVE not yet supported.  */
-  aarch64_linux_read_description (0);
+  /* SVE and pauth not yet supported.  */
+  aarch64_linux_read_description (0, false);
 }
index 0b2946ea2281353ea5505dbb93ed4eeb68f38339..db329da4dc9555054670ce15f7aff6886f2535bb 100644 (file)
@@ -501,7 +501,8 @@ aarch64_arch_setup (void)
   if (is_elf64)
     {
       uint64_t vq = aarch64_sve_get_vq (tid);
-      current_process ()->tdesc = aarch64_linux_read_description (vq);
+      /* pauth not yet supported.  */
+      current_process ()->tdesc = aarch64_linux_read_description (vq, false);
     }
   else
     current_process ()->tdesc = tdesc_arm_with_neon;
index 1b2453aa30d5233afe06da1bbf520194851b6aa6..bf24a27c598b78d1ed0ede3c6409b52086a291f0 100644 (file)
@@ -29,7 +29,7 @@ namespace tdesc {
 static void
 aarch64_tdesc_test ()
 {
-  const target_desc *tdesc = aarch64_linux_read_description (0);
+  const target_desc *tdesc = aarch64_linux_read_description (0, false);
   SELF_CHECK (*tdesc == *tdesc_aarch64);
 }
 }
index 6ab473ea51ca5f7793395f7a91d704f33635d94f..6f9b4f1efc634271c4fe27e6d3872aa6bf559ddb 100644 (file)
 #include <inttypes.h>
 
 /* All possible aarch64 target descriptors.  */
-struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1];
+struct target_desc *tdesc_aarch64_list[AARCH64_MAX_SVE_VQ + 1][2/*pauth*/];
 
 /* Create the aarch64 target description.  */
 
 const target_desc *
-aarch64_linux_read_description (uint64_t vq)
+aarch64_linux_read_description (uint64_t vq, bool pauth_p)
 {
   if (vq > AARCH64_MAX_SVE_VQ)
     error (_("VQ is %" PRIu64 ", maximum supported value is %d"), vq,
           AARCH64_MAX_SVE_VQ);
 
-  struct target_desc *tdesc = tdesc_aarch64_list[vq];
+  struct target_desc *tdesc = tdesc_aarch64_list[vq][pauth_p];
 
   if (tdesc == NULL)
     {
-      tdesc = aarch64_create_target_description (vq);
+      tdesc = aarch64_create_target_description (vq, pauth_p);
 
       static const char *expedite_regs_aarch64[] = { "x29", "sp", "pc", NULL };
       static const char *expedite_regs_aarch64_sve[] = { "x29", "sp", "pc",
@@ -50,7 +50,7 @@ aarch64_linux_read_description (uint64_t vq)
       else
        init_target_desc (tdesc, expedite_regs_aarch64_sve);
 
-      tdesc_aarch64_list[vq] = tdesc;
+      tdesc_aarch64_list[vq][pauth_p] = tdesc;
     }
 
   return tdesc;
index 7ce81506636e07f3071452417547dd2333680f72..06b3ec9b1e68a9abf0d0114f70c674b6b08e8d35 100644 (file)
@@ -20,7 +20,7 @@
 #ifndef GDBSERVER_LINUX_AARCH64_TDESC_H
 #define GDBSERVER_LINUX_AARCH64_TDESC_H
 
-const target_desc * aarch64_linux_read_description (uint64_t vq);
+const target_desc * aarch64_linux_read_description (uint64_t vq, bool pauth_p);
 
 #if GDB_SELF_TEST
 void initialize_low_tdesc ();