From: Luis Machado Date: Thu, 1 Oct 2020 15:15:39 +0000 (-0300) Subject: [Morello] Add static ABI detection based on the __cap_relocs section X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=69552c4272fcdc140a81aff184aaec791461180e;p=thirdparty%2Fbinutils-gdb.git [Morello] Add static ABI detection based on the __cap_relocs section 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 * aarch64-tdep.c (aarch64_bfd_has_capabilities): New function. (aarch64_gdbarch_init): Do static ABI check. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 301d78fbca3..8058c6b4e44 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2020-10-20 Luis Machado + + * aarch64-tdep.c (aarch64_bfd_has_capabilities): New function. + (aarch64_gdbarch_init): Do static ABI check. + 2020-10-20 Luis Machado * aarch64-tdep.c (aarch64_morello_register_aliases): New static global. diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c index ddab4c722e6..6938acad28a 100644 --- a/gdb/aarch64-tdep.c +++ b/gdb/aarch64-tdep.c @@ -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;