aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbarch.c
diff options
context:
space:
mode:
authorLuis Machado <luis.machado@arm.com>2022-05-24 23:31:09 +0100
committerLuis Machado <luis.machado@arm.com>2022-12-16 11:18:32 +0000
commitd88cb738e6a7a7179dfaff8af78d69250c852af1 (patch)
treec34f73f06cea5177a4763afb73baf2e8a41c68f6 /gdb/gdbarch.c
parent22a8433e00fd33efcb1fa4961eb826cd97f2cd8b (diff)
downloadgdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.zip
gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.gz
gdb-d88cb738e6a7a7179dfaff8af78d69250c852af1.tar.bz2
[aarch64] Fix removal of non-address bits for PAuth
PR gdb/28947 The address_significant gdbarch setting was introduced as a way to remove non-address bits from pointers, and it is specified by a constant. This constant represents the number of address bits in a pointer. Right now AArch64 is the only architecture that uses it, and 56 was a correct option so far. But if we are using Pointer Authentication (PAuth), we might use up to 2 bytes from the address space to store the required information. We could also have cases where we're using both PAuth and MTE. We could adjust the constant to 48 to cover those cases, but this doesn't cover the case where GDB needs to sign-extend kernel addresses after removal of the non-address bits. This has worked so far because bit 55 is used to select between kernel-space and user-space addresses. But trying to clear a range of bits crossing the bit 55 boundary requires the hook to be smarter. The following patch renames the gdbarch hook from significant_addr_bit to remove_non_address_bits and passes a pointer as opposed to the number of bits. The hook is now responsible for removing the required non-address bits and sign-extending the address if needed. While at it, make GDB and GDBServer share some more code for aarch64 and add a new arch-specific testcase gdb.arch/aarch64-non-address-bits.exp. Bug-url: https://sourceware.org/bugzilla/show_bug.cgi?id=28947 Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diffstat (limited to 'gdb/gdbarch.c')
-rw-r--r--gdb/gdbarch.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 74c12c5..2d4b116 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -143,7 +143,7 @@ struct gdbarch
int frame_red_zone_size = 0;
gdbarch_convert_from_func_ptr_addr_ftype *convert_from_func_ptr_addr = convert_from_func_ptr_addr_identity;
gdbarch_addr_bits_remove_ftype *addr_bits_remove = core_addr_identity;
- int significant_addr_bit = 0;
+ gdbarch_remove_non_address_bits_ftype *remove_non_address_bits = default_remove_non_address_bits;
gdbarch_memtag_to_string_ftype *memtag_to_string = default_memtag_to_string;
gdbarch_tagged_address_p_ftype *tagged_address_p = default_tagged_address_p;
gdbarch_memtag_matches_p_ftype *memtag_matches_p = default_memtag_matches_p;
@@ -400,7 +400,7 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of frame_red_zone_size, invalid_p == 0 */
/* Skip verify of convert_from_func_ptr_addr, invalid_p == 0 */
/* Skip verify of addr_bits_remove, invalid_p == 0 */
- /* Skip verify of significant_addr_bit, invalid_p == 0 */
+ /* Skip verify of remove_non_address_bits, invalid_p == 0 */
/* Skip verify of memtag_to_string, invalid_p == 0 */
/* Skip verify of tagged_address_p, invalid_p == 0 */
/* Skip verify of memtag_matches_p, invalid_p == 0 */
@@ -885,8 +885,8 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
"gdbarch_dump: addr_bits_remove = <%s>\n",
host_address_to_string (gdbarch->addr_bits_remove));
gdb_printf (file,
- "gdbarch_dump: significant_addr_bit = %s\n",
- plongest (gdbarch->significant_addr_bit));
+ "gdbarch_dump: remove_non_address_bits = <%s>\n",
+ host_address_to_string (gdbarch->remove_non_address_bits));
gdb_printf (file,
"gdbarch_dump: memtag_to_string = <%s>\n",
host_address_to_string (gdbarch->memtag_to_string));
@@ -3100,21 +3100,21 @@ set_gdbarch_addr_bits_remove (struct gdbarch *gdbarch,
gdbarch->addr_bits_remove = addr_bits_remove;
}
-int
-gdbarch_significant_addr_bit (struct gdbarch *gdbarch)
+CORE_ADDR
+gdbarch_remove_non_address_bits (struct gdbarch *gdbarch, CORE_ADDR pointer)
{
gdb_assert (gdbarch != NULL);
- /* Skip verify of significant_addr_bit, invalid_p == 0 */
+ gdb_assert (gdbarch->remove_non_address_bits != NULL);
if (gdbarch_debug >= 2)
- gdb_printf (gdb_stdlog, "gdbarch_significant_addr_bit called\n");
- return gdbarch->significant_addr_bit;
+ gdb_printf (gdb_stdlog, "gdbarch_remove_non_address_bits called\n");
+ return gdbarch->remove_non_address_bits (gdbarch, pointer);
}
void
-set_gdbarch_significant_addr_bit (struct gdbarch *gdbarch,
- int significant_addr_bit)
+set_gdbarch_remove_non_address_bits (struct gdbarch *gdbarch,
+ gdbarch_remove_non_address_bits_ftype remove_non_address_bits)
{
- gdbarch->significant_addr_bit = significant_addr_bit;
+ gdbarch->remove_non_address_bits = remove_non_address_bits;
}
std::string