]> 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)
committerLuis Machado <luis.machado@linaro.org>
Thu, 24 Jun 2021 13:42:04 +0000 (10:42 -0300)
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/ChangeLog
gdb/aarch64-tdep.c
include/ChangeLog
include/elf/aarch64.h

index c65189810fa04a9cc6c09017df9a4b290d6d9c70..a4fa095d066eb03a94c760417c7a1a92a62bce48 100644 (file)
@@ -1,3 +1,10 @@
+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.
+
 2021-06-24  Luis Machado  <luis.machado@arm.com>
 
        * aarch64-linux-nat.c (maint_print_cap_from_addr_cmd)
index a6d694bb25d8bc4e0c4b6880824545eedd2681b7..f80f59f42455aa463aae2fa189c89b262d12e5ab 100644 (file)
@@ -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);
index e94dfdfc6aca2f64dd2477dfc109d9528d93671b..c3d6ee31f03926301d7bec9df0bb4216e054a88f 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-05-24  Luis Machado  <luis.machado@linaro.org>
 
        * elf/common.h (NT_MEMTAG): New constant.
index 65af6a7a20f1c3b80cb48401b68264472de9335c..c8d9094b857d792be08529ef70d88b1a7cbdce6a 100644 (file)
@@ -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.  */