From: Luis Machado Date: Tue, 22 Jun 2021 18:25:32 +0000 (-0300) Subject: Fix ABI check X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=21ff4803088f753e40ccb352570740beadf5d845;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/aarch64-tdep.c b/gdb/aarch64-tdep.c index f8609bfe8d6..4f65b2b6b05 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -60,6 +60,7 @@ #include "inferior.h" #include "elf-bfd.h" +#include "elf/aarch64.h" /* for ELF flags. */ /* A Homogeneous Floating-Point or Short-Vector Aggregate may have at most four members. */ @@ -5055,16 +5056,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; } @@ -5261,6 +5274,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 c46dea99b16..a57184db967 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-03-17 Luis Machado * opcode/aarch64.h (enum map_type): Moved from opcodes/aarch64-dis.c. diff --git a/include/elf/aarch64.h b/include/elf/aarch64.h index 4eb4691ed10..8ebb4584837 100644 --- a/include/elf/aarch64.h +++ b/include/elf/aarch64.h @@ -43,6 +43,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. */