]> 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)
committerLuis Machado <luis.machado@linaro.org>
Tue, 20 Oct 2020 18:06:22 +0000 (15:06 -0300)
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/ChangeLog
gdb/aarch64-tdep.c

index 301d78fbca350a1b59f4d7f5ed02992c92ed5900..8058c6b4e4410c94c293ad21343bd9c58fb3c276 100644 (file)
@@ -1,3 +1,8 @@
+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.
+
 2020-10-20  Luis Machado  <luis.machado@arm.com>
 
        * aarch64-tdep.c (aarch64_morello_register_aliases): New static global.
index ddab4c722e69d896eee421d504afa00a4d55a7b9..6938acad28aa2d38cc14a3d393562456ca658a6d 100644 (file)
@@ -3597,6 +3597,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.
@@ -3630,20 +3656,29 @@ 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;
        best_arch = gdbarch_list_lookup_by_info (best_arch->next, &info))
     {
       struct gdbarch_tdep *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;