Sanitize the address before working with allocation tags
authorLuis Machado <luis.machado@linaro.org>
Fri, 14 May 2021 14:34:06 +0000 (11:34 -0300)
committerLuis Machado <luis.machado@linaro.org>
Mon, 28 Jun 2021 18:20:55 +0000 (15:20 -0300)
Remove the logical tag/top byte from the address whenever we have to work with
allocation tags.

gdb/ChangeLog:

2021-06-28  Luis Machado  <luis.machado@linaro.org>

* aarch64-linux-tdep.c (aarch64_linux_memtag_matches_p): Remove the top
byte.
(aarch64_linux_set_memtags): Likewise.
(aarch64_linux_get_memtag): Likewise.
(aarch64_linux_report_signal_info): Likewise.

gdb/ChangeLog
gdb/aarch64-linux-tdep.c

index 92a102c9fca5e48e71ada0d9c697c7c006218045..51132e4a44db82a916fbfc80f0c5fff766370032 100644 (file)
@@ -1,3 +1,11 @@
+2021-06-28  Luis Machado  <luis.machado@linaro.org>
+
+       * aarch64-linux-tdep.c (aarch64_linux_memtag_matches_p): Remove the top
+       byte.
+       (aarch64_linux_set_memtags): Likewise.
+       (aarch64_linux_get_memtag): Likewise.
+       (aarch64_linux_report_signal_info): Likewise.
+
 2021-06-28  Luis Machado  <luis.machado@linaro.org>
 
        * aarch64-linux-tdep.c
index 167035275a4662f214cb3a6136d8974bcd3d2bc1..63c200b47f7bb8edf009aa2b71609cff67153bd5 100644 (file)
@@ -1587,7 +1587,8 @@ aarch64_linux_memtag_matches_p (struct gdbarch *gdbarch,
   CORE_ADDR addr = value_as_address (address);
 
   /* Fetch the allocation tag for ADDRESS.  */
-  gdb::optional<CORE_ADDR> atag = aarch64_mte_get_atag (addr);
+  gdb::optional<CORE_ADDR> atag
+    = aarch64_mte_get_atag (address_significant (gdbarch, addr));
 
   if (!atag.has_value ())
     return true;
@@ -1625,6 +1626,9 @@ aarch64_linux_set_memtags (struct gdbarch *gdbarch, struct value *address,
     }
   else
     {
+      /* Remove the top byte.  */
+      addr = address_significant (gdbarch, addr);
+
       /* Make sure we are dealing with a tagged address to begin with.  */
       if (!aarch64_linux_tagged_address_p (gdbarch, address))
        return false;
@@ -1679,6 +1683,8 @@ aarch64_linux_get_memtag (struct gdbarch *gdbarch, struct value *address,
       if (!aarch64_linux_tagged_address_p (gdbarch, address))
        return nullptr;
 
+      /* Remove the top byte.  */
+      addr = address_significant (gdbarch, addr);
       gdb::optional<CORE_ADDR> atag = aarch64_mte_get_atag (addr);
 
       if (!atag.has_value ())
@@ -1751,7 +1757,8 @@ aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
       uiout->field_core_addr ("fault-addr", gdbarch, fault_addr);
       uiout->text ("\n");
 
-      gdb::optional<CORE_ADDR> atag = aarch64_mte_get_atag (fault_addr);
+      gdb::optional<CORE_ADDR> atag
+       = aarch64_mte_get_atag (address_significant (gdbarch, fault_addr));
       gdb_byte ltag = aarch64_mte_get_ltag (fault_addr);
 
       if (!atag.has_value ())