From: Luis Machado Date: Tue, 22 Jun 2021 18:25:32 +0000 (-0300) Subject: Fix ABI check X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f4db8e29e4099be215dcf82610c2d335e776cc5;p=thirdparty%2Fbinutils-gdb.git Fix ABI check Morello GDB used to rely on the presence of the __cap_relocs section to identify a ELF file that followed the pure-cap ABI. This isn't reliable anymore. Instead, we check two types of information. One of them is the e_flags, which contains a bit identifying the pure-cap ABI. The second one is the LSB of the e_entry, which is set for a pure-cap ABI ELF. gdb/ChangeLog: 2021-06-24 Luis Machado * aarch64-tdep.c: Include elf/aarch64.h. (aarch64_bfd_has_capabilities): Make more robust. (aarch64_gdbarch_init): Set have_capability if we have a pure-cap ABI marker. include/ChangeLog: 2021-06-24 Luis Machado * elf/aarch64.h (EF_AARCH64_CHERI_PURECAP): New constant. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c65189810fa..a4fa095d066 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2021-06-24 Luis Machado + + * aarch64-tdep.c: Include elf/aarch64.h. + (aarch64_bfd_has_capabilities): Make more robust. + (aarch64_gdbarch_init): Set have_capability if we have a pure-cap + ABI marker. + 2021-06-24 Luis Machado * aarch64-linux-nat.c (maint_print_cap_from_addr_cmd) diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index a6d694bb25d..f80f59f4245 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -59,6 +59,7 @@ #include "inferior.h" #include "elf-bfd.h" +#include "elf/aarch64.h" /* for ELF flags. */ #define submask(x) ((1L << ((x) + 1)) - 1) #define bit(obj,st) (((obj) >> (st)) & 1) @@ -4990,16 +4991,28 @@ aarch64_bfd_has_capabilities (bfd *abfd) gdb_assert (abfd != nullptr); - asection *cap_relocs = bfd_get_section_by_name (abfd, "__cap_relocs"); + int e_flags = elf_elfheader (abfd)->e_flags; if (aarch64_debug) - debug_printf ("%s: cap_relocs = %s\n", __func__, - cap_relocs == nullptr? "not found" : "found"); + debug_printf ("%s: e_flags = %x\n", __func__, e_flags); - if (cap_relocs != nullptr) + if (e_flags & EF_AARCH64_CHERI_PURECAP) return true; - /* Assume regular non-capability symbol file. */ + if (aarch64_debug) + debug_printf ("%s: e_flags doesn't contain EF_AARCH64_CHERI_PURECAP.\n", + __func__); + + /* Use the LSB of e_entry for now. If the LSB is set, this means we have a + Morello pure capability binary. */ + if (elf_elfheader (abfd)->e_entry & 1) + return true; + + if (aarch64_debug) + debug_printf ("%s: e_entry's LSB is not set. Assuming AAPCS64 ABI.\n", + __func__); + + /* Assume this is a Hybrid ABI ELF. */ return false; } @@ -5195,6 +5208,8 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches) have_capability = true; } } + else if (aarch64_current_abi_global == AARCH64_ABI_AAPCS64_CAP) + have_capability = true; /* If there is already a candidate, use it. */ for (gdbarch_list *best_arch = gdbarch_list_lookup_by_info (arches, &info); diff --git a/include/ChangeLog b/include/ChangeLog index e94dfdfc6ac..c3d6ee31f03 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2021-06-24 Luis Machado + + * elf/aarch64.h (EF_AARCH64_CHERI_PURECAP): New constant. + 2021-05-24 Luis Machado * elf/common.h (NT_MEMTAG): New constant. diff --git a/include/elf/aarch64.h b/include/elf/aarch64.h index 65af6a7a20f..c8d9094b857 100644 --- a/include/elf/aarch64.h +++ b/include/elf/aarch64.h @@ -40,6 +40,9 @@ #define DT_AARCH64_PAC_PLT (DT_LOPROC + 3) #define DT_AARCH64_VARIANT_PCS (DT_LOPROC + 5) +/* AArch64-specific e_flags entries. */ +#define EF_AARCH64_CHERI_PURECAP 0x00010000 + /* AArch64-specific values for st_other. */ #define STO_AARCH64_VARIANT_PCS 0x80 /* Symbol may follow different call convention from the base PCS. */