]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
[Morello] Add static ABI detection based on the __cap_relocs section
authorLuis Machado <luis.machado@arm.com>
Thu, 1 Oct 2020 15:15:39 +0000 (12:15 -0300)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 1 Sep 2022 22:53:22 +0000 (15:53 -0700)
This patch attempts to detect if we are loading a capability-enabled symbol
file or not, so we can set the proper hooks.

FIXME-Morello: This still needs formalization in the ABI document.

gdb/ChangeLog:

2020-10-20  Luis Machado  <luis.machado@arm.com>

* aarch64-tdep.c (aarch64_bfd_has_capabilities): New function.
(aarch64_gdbarch_init): Do static ABI check.

gdb/aarch64-tdep.c

index 29c71f02600a19af775027221c25a7f0a9ba1574..9ad02205e594b4e689550df09de3665fe370f8cc 100644 (file)
@@ -3667,6 +3667,32 @@ aarch64_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR val)
   return (val & ~1);
 }
 
+/* Given ABFD, try to determine if we are dealing with a symbol file
+   that uses capabilities.
+
+   Return true if the symbol file uses capabilities and false otherwise.  */
+
+static bool
+aarch64_bfd_has_capabilities (bfd *abfd)
+{
+  if (aarch64_debug)
+    debug_printf ("%s: Entering\n", __func__);
+
+  gdb_assert (abfd != nullptr);
+
+  asection *cap_relocs = bfd_get_section_by_name (abfd, "__cap_relocs");
+
+  if (aarch64_debug)
+    debug_printf ("%s: cap_relocs = %s\n", __func__,
+                 cap_relocs == nullptr? "not found" : "found");
+
+  if (cap_relocs != nullptr)
+    return true;
+
+  /* Assume regular non-capability symbol file.  */
+  return false;
+}
+
 /* Initialize the current architecture based on INFO.  If possible,
    re-use an architecture from ARCHES, which is a list of
    architectures already created during this debugging session.
@@ -3701,6 +3727,18 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     internal_error (__FILE__, __LINE__, _("VQ out of bounds: %s (max %d)"),
                    pulongest (vq), AARCH64_MAX_SVE_VQ);
 
+  /* If we have a symbol file, try to determine if it uses capabilities or if
+     it is just regular AArch64.  */
+  bool have_capability = false;
+  if (aarch64_current_abi_global == AARCH64_ABI_AUTO && info.abfd != NULL)
+    {
+      if (aarch64_bfd_has_capabilities (info.abfd))
+       {
+         abi = 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);
        best_arch != nullptr;
@@ -3708,14 +3746,11 @@ aarch64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
     {
       aarch64_gdbarch_tdep *tdep
        = (aarch64_gdbarch_tdep *) gdbarch_tdep (best_arch->gdbarch);
-      if (tdep && tdep->vq == vq)
+      if (tdep && tdep->vq == vq
+         && tdep->abi == abi)
        return best_arch->gdbarch;
     }
 
-  /* FIXME-Morello: Put a check in place so we can determine, from ELF, if
-     we are dealing with a capability-enabled binary or not.  */
-  bool have_capability = false;
-
   /* Ensure we always have a target descriptor, and that it is for the given VQ
      value.  */
   const struct target_desc *tdesc = info.target_desc;