]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/solib-rocm: avoid expensive gdbarch_from_bfd call in rocm_solib_relocate_section_...
authorSimon Marchi <simon.marchi@efficios.com>
Mon, 27 Oct 2025 19:41:51 +0000 (15:41 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 28 Oct 2025 15:55:23 +0000 (11:55 -0400)
Loading a library containing a lot (> 100k) sections proved very slow
with whenever the support for ROCm was built into gdb.  The culprit is
the gdbarch_from_bfd call in rocm_solib_relocate_section_addresses:

    if (!is_amdgpu_arch (gdbarch_from_bfd (so.abfd.get ())))

This function gets called for every section, and gdbarch_from_bfd is
somewhat slow.  It turns out that we can skip the gdbarch_from_bfd call,
since all is_amdgpu_arch needs is the bfd_architecture value, which we
can directly extract from the `bfd *`, without going through the
gdbarch.

Add an overload of is_amdgpu_arch that takes a `bfd *`, and use it in
rocm_solib_relocate_section_addresses.

Update a call site in rocm_solib_bfd_open to use the new overload as
well.  That call site is not as much in a hot path, but there is no
point in paying the extra cost of looking up the gdbarch there.  I
removed the other assert that checked that gdbarch_from_bfd returned a
non-nullptr value.  If that was the case, something would be very wrong
with ROCgdb, and the problem would manifest very soon after anyway.

Change-Id: I55e9e68af59903b1b9727ff57388f9469d0e0002
Approved-by: Lancelot Six <lancelot.six@amd.com> (AMDGPU)
gdb/amdgpu-tdep.c
gdb/amdgpu-tdep.h
gdb/solib-rocm.c

index 07ad307afc18610bf2bb652a5fbe251b7b8d0399..a2cb7d8984acb3f7704d523a2724e936fe8dab7f 100644 (file)
 #include "producer.h"
 #include "reggroups.h"
 
+/* Return true if INFO is of an AMDGPU architecture.  */
+
+static bool
+is_amdgpu_arch (const bfd_arch_info *info)
+{
+  return info->arch == bfd_arch_amdgcn;
+}
+
 /* See amdgpu-tdep.h.  */
 
 bool
 is_amdgpu_arch (struct gdbarch *arch)
 {
-  gdb_assert (arch != nullptr);
-  return gdbarch_bfd_arch_info (arch)->arch == bfd_arch_amdgcn;
+  return is_amdgpu_arch (gdbarch_bfd_arch_info (arch));
+}
+
+/* See amdgpu-tdep.h.  */
+
+bool
+is_amdgpu_arch (bfd *abfd)
+{
+  return is_amdgpu_arch (abfd->arch_info);
 }
 
 /* See amdgpu-tdep.h.  */
index b468c6c098c5ec45bd3aa231cf2b7cb1c2098aac..67bcaaf243a59c21ccda5b97c44c5bcf77783e16 100644 (file)
@@ -84,8 +84,13 @@ struct amdgpu_gdbarch_tdep : gdbarch_tdep_base
 };
 
 /* Return true if GDBARCH is of an AMDGPU architecture.  */
+
 bool is_amdgpu_arch (struct gdbarch *gdbarch);
 
+/* Return true if ABFD is of an AMDGPU architecture.  */
+
+bool is_amdgpu_arch (bfd *abfd);
+
 /* Return the amdgpu-specific data associated to ARCH.  */
 
 amdgpu_gdbarch_tdep *get_amdgpu_gdbarch_tdep (gdbarch *arch);
index 3b121e67cc2b99d31525c80e0c4906295da87e48..b48e4426fd4100e8f20ad439ed2800748686925b 100644 (file)
@@ -245,7 +245,7 @@ void
 rocm_solib_ops::relocate_section_addresses (solib &so,
                                            struct target_section *sec) const
 {
-  if (!is_amdgpu_arch (gdbarch_from_bfd (so.abfd.get ())))
+  if (!is_amdgpu_arch (so.abfd.get ()))
     {
       m_host_ops->relocate_section_addresses (so, sec);
       return;
@@ -728,8 +728,7 @@ rocm_solib_ops::bfd_open (const char *pathname) const
        }
     }
 
-  gdb_assert (gdbarch_from_bfd (abfd.get ()) != nullptr);
-  gdb_assert (is_amdgpu_arch (gdbarch_from_bfd (abfd.get ())));
+  gdb_assert (is_amdgpu_arch (abfd.get ()));
 
   return abfd;
 }