]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix ABI check
authorLuis Machado <luis.machado@linaro.org>
Tue, 22 Jun 2021 18:25:32 +0000 (15:25 -0300)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:57:21 +0000 (15:57 -0700)
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  <luis.machado@arm.com>

* 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  <luis.machado@arm.com>

* elf/aarch64.h (EF_AARCH64_CHERI_PURECAP): New constant.

gdb/aarch64-tdep.c
include/ChangeLog
include/elf/aarch64.h

index f8609bfe8d610da25e51710c74d9e8c57ee06462..4f65b2b6b05dbbb51a798b27711166f8978aaab9 100644 (file)
@@ -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);
index c46dea99b1625b5561d3f6945d2d13bff47dff07..a57184db967e717da4b66d0d075ca16eea8517c8 100644 (file)
@@ -1,3 +1,7 @@
+2021-06-24  Luis Machado  <luis.machado@arm.com>
+
+       * elf/aarch64.h (EF_AARCH64_CHERI_PURECAP): New constant.
+
 2021-03-17  Luis Machado  <luis.machado@arm.com>
 
        * opcode/aarch64.h (enum map_type): Moved from opcodes/aarch64-dis.c.
index 4eb4691ed104b89b1154404f5866be37e7589afa..8ebb4584837111ed69f56f5736222679a4d3ea62 100644 (file)
@@ -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.  */