No description
Find a file
Simon Marchi 230952d4dc gdb: multiple solib_ops per program space
This patch adds the possibility for a program space to have multiple
solib_ops.  The motivation for this is to support ROCm (GPU) debugging
more cleanly.

Currently, when debugging a ROCm program, in order to be able to list
device code objects (the equivalent of shared libraries but for the
GPU), we install an instance of rocm_solib_ops as the program space's
sole solib_ops.  But in order to still be able to list host shared
libraries, the rocm_solib_ops wraps the previously installed solib_ops
(currently always an svr4_solib_ops instance) and forwards method calls
to it.

By allowing program spaces to use multiple solib_ops, each solib_ops can
work side by side and rocm_solib_ops won't need to care about the host
solib_ops.

This change starts by making program_space::m_solib_ops a vector of
solib_ops_up instead of a single solib_ops_up, and it propagates from
there.

program_space::set_solib_ops becomes program_space::add_solib_ops.  I
put in the restriction that there can be only one instance of a given
kind of solib_ops in the vector (it wouldn't make sense to have two
svr4_solib_ops instances in there, it would likely be a bug).

Remove program_space::unset_solib_ops, but add
program_space::remove_solib_ops (to remove a single solib_ops) and
program_space::clear_solib_ops (to remove all solib_ops).  Removing an
solib_ops now automatically removes all the solibs produced by that
solib_ops, to avoid having solibs with stale solib_ops backlinks.

Add program_space::find_solib_ops, which can be used to find the
instance of a given kind of solib_ops.

Then, the code in solib.c gets adapted to deal with the fact that there
might be multiple solib_ops.  The logic is done on a case by case basis:

 - update_solib_list: where we call open_symbol_file_object, iterate
   over all solib_ops until we find one that knows how to find and open
   the main executable

 - also update_solib_list: where we fetch the list of current SOs from
   the inferior and compare it against the list of SOs know to GDB,
   iterate over all solib_ops and fetch current SOs from all of them.
   When comparing the SOs fetched from the solib_ops with the SOs
   known to GDB, also compare the solib_ops before considering it a
   match.

 - print_solib_list_table: to determine whether to print the namespace
   column, iterate over all solib_ops until we find one for which
   supports_namespaces returns true and num_active_namespaces returns
   greater than 0.  If the namespace column is printed and some solibs
   are from an solib_ops that doesn't support namespaces, skip the
   column.

 - info_linker_namespace_command: iterate over all solib_ops.  For each
   solib_ops, print all namespaces.

 - solib_keep_data_in_core: iterate over all solib_ops until one says
   that the given memory range should be kept.

 - clear_solib: call clear_solib on all solib_ops

 - solib_create_inferior_hook: call create_inferior_hook on all
   solib_ops

 - in_solib_dynsym_resolve_code: iterate over all solib_ops until one
   says that the given PC falls into dynsym resolve code

 - update_solib_breakpoints: call update_breakpoints on all solib_ops

 - handle_solib_event: call handle_event on all solib_ops.  The event
   normally concern only one of those solib_ops, but at the moment we
   have no way to tell which solib_ops that is.  Perhaps, in the future,
   we can link bp_shlib_event breakpoints to which solib_ops the event
   is for, and call handle_event just for that solib_ops.  In the mean
   time, it is expected that for solib_ops not concerned by the event,
   calling handle_event will have no effect.

 - reload_shared_libraries: call clear_solib on all solib_ops

 - solib_linker_namespace_count: sum the number of active linker
   namespace over all solib_ops.  I don't know if this makes sense, but
   there is no known case today of two solib_ops supporting namespaces
   working side-by-side, so it's a theoretical problem for now.

With multiple solib_ops, the concept of
iterate_over_objfiles_in_search_order becomes a bit more complex.  The
implementation is mostly based on suppositions on my part.  The idea
implemented in this patch is to give priority to the solib_ops
responsible for an objfile when searching for a symbol.  If you're
stopped debugging some GPU code and look up a variable, and there is a
variable by that name both on the host and GPU side, I believe it is
more likely that you are interested in the GPU one.

Since we're going to ask multiple solib_ops to search successively,
change solib_ops::iterate_over_objfiles_in_search_order to return a
bool, to indicate if the search was successful or if we should continue.

Then, change solib_ops::iterate_over_objfiles_in_search_order (the
implementation used by all except svr4_solib_ops) to only search the
objfiles from that solib_ops as well as (optionally) the main objfile
(program_space::symfile_object_file).  The idea regarding the main
objfile is that it falls under the "linking domain" of the host-side
solib_ops, even though it wasn't produced by that solib_ops.
svr4_solib_ops has its own implementation of
iterate_over_objfiles_in_search_order, which does check the main
objfile.

Checking the main objfile is predicated by the HANDE_MAIN_OBJFILE
solib_ops constructor parameter, for which rocm_solib_ops passes false.

Then in program_space::iterate_over_objfiles_in_search_order, the search
strategy becomes:

  - if there is a current objfile:
    - if that objfile was contributed by an solib_ops:
      - call that solib_ops' iterate_over_objfiles_in_search_order
    - else:
      - search the current objfile by itself

If we didn't find anything interesting, we continue the search by asking
other solib_ops to search:

  - for all solib_ops except the one searched before (if any):
    - call that solib_ops' iterate_over_objfiles_in_search_order

Finally, "orphan" objfiles (not mapped to any solib) haven't been
searched (except possibly the current objfile), so:

  - for all objfile without an solib_ops backlink, except the current one (if any):
    - search that objfile

Note that if the current objfile is the main one
(program_space::symfile_object_file), then we won't enter the host
solib_ops::iterate_over_objfiles_in_search_order in the first part,
because that objfile is not associated to any solib, and therefore to
any solib_ops.  Instead, we will enter it in the first iteration of the
second part.  This relies on the fact that the host solib_ops will
always be first in the solib_ops list, with complementary solib_ops
following.  This is always true today, given the order in which
solib_ops instances are pushed.  Otherwise, we could go look for the
solib_ops for which M_HANDLE_MAIN_OBJFILE is true, but it didn't seem
like it was worth the extra complexity.

I wrote the gdb.rocm/symbol-lookup.exp test to try to exercise this
symbol lookup order thing.  The test program loads some shared libraries
and some ROCm code objects, then does some symbol lookups while stopped
in different places.

Finally, the goal of all this, rocm_solib_ops gets changed to not wrap a
host solib_ops anymore!  rocm_solib_ops previously had to use
lm_info_svr4, to avoid confusing svr4_solib_ops.  It doesn't have to
anymore, so introduce a simpler lm_info_rocm that just holds an address.

rocm_solib_ops no longer needs to implement a bunch of methods just to
forward the call to the host solib_ops, so remove them.  In the methods
that rocm_solib_ops actually needs to implement, it no longer needs to
call the host ops, which simplifies things.

Things also get simpler at the points where we push a new
rocm_solib_ops.

Change-Id: I260cdc0dcb9b11f33040059f300719dacac63d69
Approved-By: Tom Tromey <tom@tromey.com>
2026-07-08 17:40:41 -04:00
bfd Automatic date update in version.in 2026-07-08 00:00:07 +00:00
binutils PR 34353 objcopy: null-pointer dereference bfd/section.c:1433 2026-07-07 10:19:31 +09:30
config Support MinGW & 64-bit libraries/paths in Tcl autoconf scripts 2026-04-02 17:00:30 +02:00
contrib contrib: Make dg-extract-results.py tolerant of unparseable files 2026-05-29 17:28:56 -07:00
cpu mep disassembler buffer overflow 2026-06-18 09:20:56 +09:30
elfcpp gas, bfd, gold: Rename Arm v8/v9 architecture tags 2026-05-28 11:33:39 +00:00
etc Update year range in copyright notice of binutils files 2026-01-01 23:22:14 +10:30
gas aarch64: Fix %dtprel relocations size. 2026-07-08 21:16:04 +00:00
gdb gdb: multiple solib_ops per program space 2026-07-08 17:40:41 -04:00
gdbserver [gdbserver] Use const_target_desc_up for regformat tdescs 2026-07-07 12:11:09 -07:00
gdbsupport Windows: Normalize backslashes to forward slashes 2026-07-06 22:13:07 +01:00
gnulib gnulib: re-generate Makefile.in 2026-01-06 15:14:50 -05:00
gold gas, bfd, gold: Rename Arm v8/v9 architecture tags 2026-05-28 11:33:39 +00:00
gprof gprof: Fix tests on Solaris [PR34237] 2026-06-11 10:05:03 +02:00
gprofng gprofng format mismatch on 32-bit host 2026-04-06 10:31:29 +09:30
include AVR: Adhere to GNU coding style 2026-07-04 11:36:40 +02:00
ld LoongArch: Fix relaxation alignment with ld -r (PR 33236) 2026-07-06 02:26:54 +08:00
libbacktrace tidy m4 plugin config support 2025-11-03 10:59:50 +10:30
libctf PR 34275 double free in ctf_link_deduplicating_per_cu 2026-07-04 09:23:00 +09:30
libdecnumber regen config 2023-08-12 10:27:57 +09:30
libiberty libiberty d_compact_number signed integer overflow 2026-07-01 10:57:51 +09:30
libsframe libsframe testsuite format mismatches on 32-bit host 2026-04-06 10:46:06 +09:30
opcodes s390: Add store CPU counter multiple instruction 2026-07-06 16:11:50 +02:00
readline readline/tcap.h: Update definitions for C23 2025-05-02 12:00:05 -06:00
sim Fix typo in sim/ppc/std-config.h 2026-04-21 08:47:46 -06:00
texinfo
zlib tidy m4 plugin config support 2025-11-03 10:59:50 +10:30
.clang-format Remove ARI 2026-06-26 09:17:29 -06:00
.cvsignore
.editorconfig toplevel: unify the GCC and GDB/binutils .editorconfig files 2025-10-01 16:20:29 +01:00
.gitattributes binutils-gdb/git: Handle *.ac and *.m4 files in .gitattributes 2025-12-18 10:00:54 +01:00
.gitignore Add .clang-format 2026-02-11 07:53:01 -07:00
.pre-commit-config.yaml [gdb] Increase clean range in check-whitespace-pre-commit.py 2026-06-18 22:06:50 +02:00
ar-lib
ChangeLog Import the following commits from the master config sources: a2287c3041a3f2a204eb942e09c015eab00dc7dd 973e3e6af23b73a4f1b8d95680454cae22593bf8 3a71dc102953608d4592ec401b519837c28a672a f91a544533876c70f43b9fd51064b2bcf3fa7382 484648c73f3843b256dd011bd415e81594300a0a 7f4149527babe92cb5da1032734f5cb90cefdac5 9f6e0fe8ce04628bbd4a455118ff3f8309a1aef9 2026-01-08 11:20:38 +00:00
compile
config-ml.in MSP430: Add -fno-exceptions multilib 2023-08-12 10:24:26 +09:30
config.guess Import the following commits from the master config sources: a2287c3041a3f2a204eb942e09c015eab00dc7dd 973e3e6af23b73a4f1b8d95680454cae22593bf8 3a71dc102953608d4592ec401b519837c28a672a f91a544533876c70f43b9fd51064b2bcf3fa7382 484648c73f3843b256dd011bd415e81594300a0a 7f4149527babe92cb5da1032734f5cb90cefdac5 9f6e0fe8ce04628bbd4a455118ff3f8309a1aef9 2026-01-08 11:20:38 +00:00
config.rpath
config.sub Import the following commits from the master config sources: a2287c3041a3f2a204eb942e09c015eab00dc7dd 973e3e6af23b73a4f1b8d95680454cae22593bf8 3a71dc102953608d4592ec401b519837c28a672a f91a544533876c70f43b9fd51064b2bcf3fa7382 484648c73f3843b256dd011bd415e81594300a0a 7f4149527babe92cb5da1032734f5cb90cefdac5 9f6e0fe8ce04628bbd4a455118ff3f8309a1aef9 2026-01-08 11:20:38 +00:00
configure AMDGCN: Disable subdirectory configuration for unsupported GAS and LD 2026-02-18 17:32:32 +00:00
configure.ac AMDGCN: Disable subdirectory configuration for unsupported GAS and LD 2026-02-18 17:32:32 +00:00
COPYING
COPYING.LIB
COPYING.LIBGLOSS
COPYING.NEWLIB
COPYING3
COPYING3.LIB
depcomp
djunpack.bat
install-sh
libtool.m4 Binutils/GCC: Add clang LTO support to AR, NM and RANLIB 2025-09-25 12:30:13 +08:00
ltgcc.m4
ltmain.sh ltmain.sh: allow more flags at link-time 2024-09-25 19:06:10 +01:00
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
MAINTAINERS Fix compiling bfd/vms-lib.c for a 32-bit host. 2024-03-18 10:26:16 +00:00
Makefile.def Sync top-level with GCC 2025-11-03 09:53:04 +00:00
Makefile.in Sync toplevel files from gcc 2025-10-02 07:42:18 +08:00
Makefile.tpl Sync toplevel files from gcc 2025-10-02 07:42:18 +08:00
makefile.vms
missing
mkdep
mkinstalldirs
move-if-change
multilib.am
README README: don't talk about libg++ 2025-09-07 04:06:01 +01:00
README-maintainer-mode
SECURITY.txt Add a SECURITY.txt file describing the GNU Binutils' project's stance on security related bugs. 2023-04-20 16:52:11 +01:00
setup.com
src-release.sh Rename 'binutils' to 'binutils_with_gold'. Rename 'bin_no_gold' to 'binutils'. Add 'gold' 2025-02-04 11:50:02 +00:00
symlink-tree
test-driver
ylwrap

		   README for GNU development tools

This directory contains various GNU compilers, assemblers, linkers, 
debuggers, etc., plus their support routines, definitions, and documentation.

If you are receiving this as part of a GDB release, see the file gdb/README.
If with a binutils release, see binutils/README, and so on. That'll give you
info about this package -- supported targets, how to use it, how to report
bugs, etc.

It is now possible to automatically configure and build a variety of
tools with one command.  To build all of the tools contained herein,
run the ``configure'' script here, e.g.:

	./configure 
	make

To install them (by default in /usr/local/bin, /usr/local/lib, etc),
then do:
	make install

(If the configure script can't determine your type of computer, give it
the name as an argument, for instance ``./configure sun4''.  You can
use the script ``config.sub'' to test whether a name is recognized; if
it is, config.sub translates it to a triplet specifying CPU, vendor,
and OS.)

If you have more than one compiler on your system, it is often best to
explicitly set CC in the environment before running configure, and to
also set CC when running make.  For example (assuming sh/bash/ksh):

	CC=gcc ./configure
	make

A similar example using csh:

	setenv CC gcc
	./configure
	make

Much of the code and documentation enclosed is copyright by
the Free Software Foundation, Inc.  See the file COPYING or
COPYING.LIB in the various directories, for a description of the
GNU General Public License terms under which you can copy the files.

REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info
on where and how to report problems.