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)
#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. */
};
/* 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);
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;
}
}
- 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;
}