From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Xs34BqrITmq11CwAWB0awg (envelope-from ) for ; Wed, 08 Jul 2026 18:01:14 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Anv3rVBF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 14AF51E090; Wed, 08 Jul 2026 18:01:14 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 2E33D1E090 for ; Wed, 08 Jul 2026 18:01:12 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 602314BA23D3 for ; Wed, 8 Jul 2026 22:01:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 602314BA23D3 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Anv3rVBF Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 29CAE4BA2E26 for ; Wed, 8 Jul 2026 22:00:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 29CAE4BA2E26 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 29CAE4BA2E26 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783548042; cv=none; b=E+H3kPhppmHXiFp0Z4T9V5qZ3Mt2zfjlvunhnKgaBrNQ4OyqOqVRW8/6628nwPgFwlr2AzmwG0zQAsUwWlbN3i5GKOkSzDNs1OWIqcOC4YXu4Btm4RJpT8zV6+7YshCd2Y6W5CkTMK7YFpuvDii2Ycjo3SG6kHMdu7t77KQTexk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783548042; c=relaxed/simple; bh=yuOl4e/IOGjuO7M0XSW2jh5Lc8QPd9KJ2JIxZo9tXzE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZXM08x/saaXeiL8t8zA/MzNTapguWgyC5MhhkSJ3v3dFeBwXFj017mZc3vZmqP9de3Ey9sKiZRPpvtLDE5xM5C6Qo9uIJIKFyV9Zz4MppN5MZlyd0HO5urXfylNjiCMKYkf/sn+7UN7PYfi1H51LwW7ltNwsrkU4A01TayxTZmI= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=Anv3rVBF DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 29CAE4BA2E26 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 668M0R8F120691 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 8 Jul 2026 18:00:32 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 668M0R8F120691 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1783548033; bh=U7hxH3M2wcjadR83P8AnGxp0RQ+SDirfzq9RhJ3Mc+c=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=Anv3rVBFJCmUN40ErPaH+wah9F9L9ZlEDbrGMTTxEQxQAXM/+Uqp6EPh9NZ6kbEv1 EUzzp3NkP/zbjFQC0QwCX39PyItCM4JP5vQ4ivhv/jgRWdX7vtTxKMufZo9qV53/jv IwP5bdspZq6+Rr9uKyD20SoxOcP7Vt7/c8J3l2zdpZizS/AU3af03j1lSEg8kIjvfd DLjlfoKwHU1B3LUG1elCI2IY0I7P6UNKaQt1JyqxvSMsJTGIXXWVQ+lvx3Img4Np5r lPaPAnOoM+az3jmmUVGn/hDeiVbeY6yiWhOWtwNdCf+EfHWwaGPh1cFfcB616SzbEt l9kpbpQ7qahaw== Received: by simark.ca (Postfix) id 7D02D1E0AE; Wed, 08 Jul 2026 17:51:52 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Tom Tromey , Lancelot SIX , Simon Marchi Subject: [PATCH v3 06/10] gdb/solib-rocm: move per-inferior data to rocm_solib_ops Date: Wed, 8 Jul 2026 17:51:38 -0400 Message-ID: <20260708215145.93134-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260708215145.93134-1-simon.marchi@polymtl.ca> References: <20260708215145.93134-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 8 Jul 2026 22:00:27 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi Move the data currently stored in an inferior registry directly into rocm_solib_ops. This changes the storage of this data from "per inferior" to "per program-space", but it should be equivalent, since there is usually a 1:1 mapping between those two. The only time there isn't a 1:1 mapping is during a vfork, before the exec/exit, but no ROCm activity happens during that slice of time. Function rocm_update_solib_list becomes rocm_solib_ops::update_solib_list. Function rocm_bfd_iovec_open becomes rocm_solib_ops::bfd_iovec_open. Most of the changes consist of accessing the fields directly, instead of going through the solib_info object. The rocm_solib_ops constructor has to take an inferior as a parameter, rather than a program_space, because of the fd cache. Change-Id: I386139008b6f0eca1d897fc35be18faa9d5a104e --- gdb/solib-rocm.c | 111 ++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 59 deletions(-) diff --git a/gdb/solib-rocm.c b/gdb/solib-rocm.c index 9f2fc915b12b..00b97dbdde22 100644 --- a/gdb/solib-rocm.c +++ b/gdb/solib-rocm.c @@ -181,30 +181,15 @@ struct rocm_so lm_info_svr4_up lm_info; }; -struct solib_info -{ - explicit solib_info (inferior *inf) - : fd_cache (inf) - {}; - - /* List of code objects loaded into the inferior. */ - std::vector solib_list; - - /* Cache of opened FD in the inferior. */ - rocm_solib_fd_cache fd_cache; -}; - -/* Per-inferior data key. */ -static const registry::key rocm_solib_data; - /* solib_ops for ROCm systems. */ struct rocm_solib_ops : public solib_ops { /* HOST_OPS is the host solib_ops that rocm_solib_ops hijacks / wraps, in order to provide support for ROCm code objects. */ - explicit rocm_solib_ops (program_space *pspace, solib_ops_up host_ops) - : solib_ops (pspace), m_host_ops (std::move (host_ops)) + explicit rocm_solib_ops (inferior *inf, solib_ops_up host_ops) + : solib_ops (inf->pspace), m_host_ops (std::move (host_ops)), + m_fd_cache (inf) { gdb_assert (m_host_ops != nullptr); gdb_assert (dynamic_cast (m_host_ops.get ()) == nullptr); @@ -221,6 +206,10 @@ struct rocm_solib_ops : public solib_ops void relocate_section_addresses (solib &so, target_section *) const override; void handle_event () override; + /* This needs to be public because it is called from + rocm_solib_target_inferior_created. */ + void update_solib_list (); + /* Implement the following methods just to forward the calls to the host solib_ops. We currently need to implement all the methods that svr4_solib_ops implements. */ @@ -271,17 +260,16 @@ struct rocm_solib_ops : public solib_ops private: owning_intrusive_list solibs_from_rocm_sos (const std::vector &sos); + gdb_bfd_iovec_base *bfd_iovec_open (bfd *abfd, inferior *inferior); solib_ops_up m_host_ops; -}; -/* Fetch the solib_info data for INF. */ + /* List of code objects loaded into the inferior. */ + std::vector m_solib_list; -static struct solib_info * -get_solib_info (inferior *inf) -{ - return &rocm_solib_data.try_emplace (inf, inf); -} + /* Cache of opened FD in the inferior. */ + rocm_solib_fd_cache m_fd_cache; +}; /* Relocate section addresses. */ @@ -300,8 +288,6 @@ rocm_solib_ops::relocate_section_addresses (solib &so, sec->endaddr = sec->endaddr + li->l_addr; } -static void rocm_update_solib_list (); - void rocm_solib_ops::handle_event () { @@ -313,7 +299,7 @@ rocm_solib_ops::handle_event () previously loaded). */ m_host_ops->handle_event (); - rocm_update_solib_list (); + this->update_solib_list (); } /* Create solib objects from rocm_so objects in SOS. */ @@ -340,12 +326,10 @@ rocm_solib_ops::current_sos () owning_intrusive_list sos = m_host_ops->current_sos (); /* Then, the device-side shared library list. */ - std::vector &dev_sos = get_solib_info (current_inferior ())->solib_list; - - if (dev_sos.empty ()) + if (m_solib_list.empty ()) return sos; - owning_intrusive_list dev_solibs = solibs_from_rocm_sos (dev_sos); + owning_intrusive_list dev_solibs = solibs_from_rocm_sos (m_solib_list); if (sos.empty ()) return dev_solibs; @@ -525,8 +509,8 @@ rocm_code_object_stream_memory::read (bfd *, void *buf, file_ptr size, } /* anonymous namespace */ -static gdb_bfd_iovec_base * -rocm_bfd_iovec_open (bfd *abfd, inferior *inferior) +gdb_bfd_iovec_base * +rocm_solib_ops::bfd_iovec_open (bfd *abfd, inferior *inferior) { std::string_view uri (bfd_get_filename (abfd)); std::string_view protocol_delim = "://"; @@ -635,10 +619,9 @@ rocm_bfd_iovec_open (bfd *abfd, inferior *inferior) && decoded_path[3] == '/') decoded_path.erase (0, 1); - auto info = get_solib_info (inferior); fileio_error target_errno; rocm_solib_fd_cache::cached_target_fd fd - = info->fd_cache.open (decoded_path, &target_errno); + = m_fd_cache.open (decoded_path, &target_errno); if (fd.fd () == target_fd::INVALID) { @@ -698,9 +681,9 @@ rocm_solib_ops::bfd_open (const char *pathname) if (strstr (pathname, "://") == nullptr) return m_host_ops->bfd_open (pathname); - auto open = [] (bfd *nbfd) -> gdb_bfd_iovec_base * + auto open = [this] (bfd *nbfd) { - return rocm_bfd_iovec_open (nbfd, current_inferior ()); + return this->bfd_iovec_open (nbfd, current_inferior ()); }; gdb_bfd_ref_ptr abfd = gdb_bfd_openr_iovec (pathname, "elf64-amdgcn", open); @@ -782,13 +765,12 @@ rocm_solib_ops::bfd_open (const char *pathname) void rocm_solib_ops::create_inferior_hook (int from_tty) { - get_solib_info (current_inferior ())->solib_list.clear (); - + m_solib_list.clear (); m_host_ops->create_inferior_hook (from_tty); } -static void -rocm_update_solib_list () +void +rocm_solib_ops::update_solib_list () { inferior *inf = current_inferior (); @@ -796,10 +778,7 @@ rocm_update_solib_list () if (process_id.handle == AMD_DBGAPI_PROCESS_NONE.handle) return; - solib_info *info = get_solib_info (inf); - - info->solib_list.clear (); - std::vector &sos = info->solib_list; + m_solib_list.clear (); amd_dbgapi_code_object_id_t *code_object_list; size_t count; @@ -846,7 +825,8 @@ rocm_update_solib_list () std::string unique_name = string_printf ("code_object_%ld", code_object_list[i].handle); - sos.emplace_back (uri_bytes, std::move (unique_name), std::move (li)); + m_solib_list.emplace_back (uri_bytes, std::move (unique_name), + std::move (li)); } } @@ -857,17 +837,15 @@ rocm_solib_target_inferior_created (inferior *inf) if (inf->vfork_parent != nullptr) return; - get_solib_info (inf)->solib_list.clear (); - auto prev_ops = inf->pspace->release_solib_ops (); - auto rocm_ops - = std::make_unique (inf->pspace, std::move (prev_ops)); + auto rocm_ops = std::make_unique (inf, std::move (prev_ops)); inf->pspace->set_solib_ops (std::move (rocm_ops)); - rocm_update_solib_list (); + gdb::checked_static_cast + (inf->pspace->solib_ops ())->update_solib_list (); /* Force GDB to reload the solibs. */ - current_inferior ()->pspace->clear_solib_cache (); + inf->pspace->clear_solib_cache (); solib_add (nullptr, 0, auto_solib_add); } @@ -882,10 +860,8 @@ rocm_solib_target_inferior_execd (inferior *exec_inf, inferior *follow_inf) auto pspace = follow_inf->pspace; auto prev_ops = pspace->release_solib_ops (); auto rocm_ops - = std::make_unique (pspace, std::move (prev_ops)); + = std::make_unique (follow_inf, std::move (prev_ops)); pspace->set_solib_ops (std::move (rocm_ops)); - - get_solib_info (exec_inf)->solib_list.clear (); } static void @@ -898,10 +874,27 @@ rocm_solib_target_inferior_forked (inferior *parent_inf, inferior *child_inf, /* In this particular configuration, infrun's follow_fork_inferior function moves the parent pspace to the child directly. Remove the existing rocm_solib_ops from the child and restore the host solib_ops, - to make it look like a brand new pspace. */ - auto rocm_ops_holder = child_inf->pspace->release_solib_ops (); + to make it look like a brand new pspace. + + Remove solibs created by the rocm_solib_ops, since they contain back + references to the rocm_solib_ops (namely, to the fd cache). */ + auto &solibs = child_inf->pspace->solibs (); auto rocm_ops - = gdb::checked_static_cast (rocm_ops_holder.get ()); + = gdb::checked_static_cast + (child_inf->pspace->solib_ops ()); + + for (auto solibs_it = solibs.begin (); solibs_it != solibs.end ();) + { + if (&solibs_it->ops () != rocm_ops) + { + ++solibs_it; + continue; + } + + solibs_it = remove_solib (child_inf->pspace, solibs_it); + } + + auto rocm_ops_holder = child_inf->pspace->release_solib_ops (); child_inf->pspace->set_solib_ops (rocm_ops->release_host_ops ()); } } -- 2.55.0