From d88cb738e6a7a7179dfaff8af78d69250c852af1 Mon Sep 17 00:00:00 2001 From: Luis Machado Date: Tue, 24 May 2022 23:31:09 +0100 Subject: [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 --- gdb/utils.c | 22 ---------------------- 1 file changed, 22 deletions(-) (limited to 'gdb/utils.c') diff --git a/gdb/utils.c b/gdb/utils.c index 74917f2..4a715b9 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -3110,28 +3110,6 @@ show_debug_timestamp (struct ui_file *file, int from_tty, } -/* See utils.h. */ - -CORE_ADDR -address_significant (gdbarch *gdbarch, CORE_ADDR addr) -{ - /* Clear insignificant bits of a target address and sign extend resulting - address, avoiding shifts larger or equal than the width of a CORE_ADDR. - The local variable ADDR_BIT stops the compiler reporting a shift overflow - when it won't occur. Skip updating of target address if current target - has not set gdbarch significant_addr_bit. */ - int addr_bit = gdbarch_significant_addr_bit (gdbarch); - - if (addr_bit && (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))) - { - CORE_ADDR sign = (CORE_ADDR) 1 << (addr_bit - 1); - addr &= ((CORE_ADDR) 1 << addr_bit) - 1; - addr = (addr ^ sign) - sign; - } - - return addr; -} - const char * paddress (struct gdbarch *gdbarch, CORE_ADDR addr) { -- cgit v1.1