From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id KT3oJRLHTmpG0iwAWB0awg (envelope-from ) for ; Wed, 08 Jul 2026 17:54:26 -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=aOMSQ83w; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 9742E1E098; Wed, 08 Jul 2026 17:54:26 -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=unavailable autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 021D31E04F for ; Wed, 08 Jul 2026 17:54:26 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2B354BA23C7 for ; Wed, 8 Jul 2026 21:54:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2B354BA23C7 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=aOMSQ83w Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id E89184BA2E10 for ; Wed, 8 Jul 2026 21:54:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E89184BA2E10 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 E89184BA2E10 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=1783547642; cv=none; b=txBVhWw3ZdAvzIy5OJ9EvSayTNaSpNqADIfDyGw+Wo9beGdKpmwViS8lndWvrzauaRhwWBeg6HxLZp0ravrYFYew9i/eyqZPZcfs2ZrBwOiyIy5k/orXlYpfDggoFuaVKAASeJd5jpXUFgnc7/v+Ywm3UjXb5rnuKt2CSdEJ4E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1783547642; c=relaxed/simple; bh=yIizaosyM4kJSpXbU0eIQdVLA2zdcphg3pycWwTPWeo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=E+Q/D9zeuWZOmiXjph+ovKLXPzERN5GEUqY4IYNuYccW8QuoeJsUaRxE7kI7d7uSR7Maagxxg92Vo8YeYaDYDLMhZzg25mwZRXM6k+OHebUqaIrudnpPsFqxcGPGMP5mCsQhW5D1HcQtA12/wCCu7PBy2LvUeWo0Q+WD9lZqzuE= 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=aOMSQ83w DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E89184BA2E10 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 668LrrmY118047 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 8 Jul 2026 17:53:58 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 668LrrmY118047 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1783547638; bh=HQGzSkMNJqx4tljCNC/zv0MzgECzFvtqEQBWqEJvATE=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=aOMSQ83wHM5Fy5ZQhtj1tP+tSbtSu0yeK45aNzGVKLJPERUGCoHtpo06YqLJQqDrX fgZKA3Epyt6PA/HBgoJKVW96KKO1SM5gH2whnjWKIo0atqXCBPNQgUfUanaD53C8xx 09mrD5c6we3LivaYUXcWC9mSA9e+5MpXPvb+Wb+9VlSD5eRpMlD1BjB9esRtJS+RFh f0zUohkgRu+p4fzhGYWpe2nQbNYJTGj/QtfwQBOgZ4EFve4Sns8yOINRwkxZnPGXDc wGi+ptlhLtFoqXsOMBlDxD6tlLEimqpwWCZlj53k55UInBouR/7GvtuEn7mgnVysh2 6JSNLjkKrgeug== Received: by simark.ca (Postfix) id 37F8C1E04F; Wed, 08 Jul 2026 17:53:53 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Tom Tromey , Lancelot SIX , Simon Marchi Subject: [PATCH v3 08/10] gdb: add objfile -> solib backlink Date: Wed, 8 Jul 2026 17:51:40 -0400 Message-ID: <20260708215145.93134-9-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 21:53:53 +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 The following "multiple solib_ops" patch will require accessing the solib(s) related to an objfile fairly often. To make that easier, add an objfile to solib backlink. However, I learned that there may be more than one solib linked to one objfile. The only case I am aware of is the dynamic linker itself (ld-linux.so), where the same instance (same load address) appears in all namespaces. We get one solib per "view" of that library, but they all point to the same objfile. So this backlink is actually a vector. Rename find_solib_for_objfile to find_one_solib_for_objfile to reflect that this function returns just one of possible multiple solibs for the given objfile (if that ever matters). To be clear, this doesn't change its behavior, this is what it was doing before this patch. Change-Id: I427d19407fdbc274b1790e0cae3004ee5fdbea72 --- gdb/objfiles.h | 23 +++++++++++++++++++++++ gdb/solib-svr4.c | 16 ++++++++-------- gdb/solib.c | 13 +++++++++---- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/gdb/objfiles.h b/gdb/objfiles.h index 406ab36b39d6..4c963cb375c3 100644 --- a/gdb/objfiles.h +++ b/gdb/objfiles.h @@ -450,6 +450,25 @@ struct objfile : intrusive_list_node /* Return the program space associated with this objfile. */ program_space *pspace () { return m_pspace; } + /* Return the list of struct solib associated to this objfile. */ + std::vector &solibs () { return m_solibs; } + + /* Add SOLIB to the list of solibs associated to this objfile. */ + void add_solib (solib &solib) + { + gdb_assert (std::find (m_solibs.begin (), m_solibs.end (), &solib) + == m_solibs.end ()); + m_solibs.emplace_back (&solib); + } + + /* Remove SOLIB from the list of solibs associated to this objfile. */ + void remove_solib (solib &solib) + { + auto it = std::find (m_solibs.begin (), m_solibs.end (), &solib); + gdb_assert (it != m_solibs.end ()); + m_solibs.erase (it); + } + using compunit_symtab_iterator = owning_intrusive_list::iterator; using compunit_symtab_range = iterator_range; @@ -702,6 +721,10 @@ struct objfile : intrusive_list_node program_space *m_pspace; + /* The solibs associated to this objfile. This is a 1 objfile to N solibs + relationship (see solib.c for details). */ + std::vector m_solibs; + public: /* The object file's BFD. Can be null if the objfile contains only minimal symbols (e.g. the run time common symbols for SunOS4) or diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c index 35c81000b10a..33fb6e3cd970 100644 --- a/gdb/solib-svr4.c +++ b/gdb/solib-svr4.c @@ -3592,10 +3592,10 @@ lp64_svr4_solib_ops::fetch_link_map_offsets () const } -/* Return the DSO matching OBJFILE or nullptr if none can be found. */ +/* Return one solib matching OBJFILE or nullptr if none can be found. */ -static const solib * -find_solib_for_objfile (struct objfile *objfile) +static solib * +find_one_solib_for_objfile (struct objfile *objfile) { if (objfile == nullptr) return nullptr; @@ -3605,9 +3605,9 @@ find_solib_for_objfile (struct objfile *objfile) if (objfile->separate_debug_objfile_backlink != nullptr) objfile = objfile->separate_debug_objfile_backlink; - for (const solib &so : current_program_space->solibs ()) - if (so.objfile == objfile) - return &so; + if (const auto &solibs = objfile->solibs (); + !solibs.empty ()) + return solibs.front (); return nullptr; } @@ -3676,7 +3676,7 @@ svr4_solib_ops::iterate_over_objfiles_in_search_order r_debug object, defaulting to the initial namespace. */ svr4_info *info = get_svr4_info (current_program_space); CORE_ADDR default_debug_base = this->default_debug_base (info); - const solib *curr_solib = find_solib_for_objfile (current_objfile); + const solib *curr_solib = find_one_solib_for_objfile (current_objfile); CORE_ADDR debug_base = find_debug_base_for_solib (curr_solib); if (debug_base == 0) debug_base = default_debug_base; @@ -3691,7 +3691,7 @@ svr4_solib_ops::iterate_over_objfiles_in_search_order If we fail, e.g. for manually added symbol files or for the main executable, we assume that they were added to the initial namespace. */ - const solib *solib = find_solib_for_objfile (&objfile); + const solib *solib = find_one_solib_for_objfile (&objfile); CORE_ADDR solib_base = find_debug_base_for_solib (solib); if (solib_base == 0) solib_base = default_debug_base; diff --git a/gdb/solib.c b/gdb/solib.c index 6afa97e1aed5..b9b0f11cb477 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -650,6 +650,7 @@ solib_read_symbols (solib &so, symfile_add_flags flags) so.objfile->addr_low = so.addr_low; } + so.objfile->add_solib (so); so.symbols_loaded = true; } catch (const gdb_exception_error &e) @@ -715,10 +716,14 @@ remove_solib (program_space *pspace, notify_solib_unloaded (pspace, *solib_it, still_in_use, false); /* Unless the user loaded it explicitly, free SO's objfile. */ - if (solib_it->objfile != nullptr - && !(solib_it->objfile->flags & OBJF_USERLOADED) - && !still_in_use) - solib_it->objfile->unlink (); + if (solib_it->objfile != nullptr) + { + /* Remove the objfile -> solib backlink. */ + solib_it->objfile->remove_solib (*solib_it); + + if (!(solib_it->objfile->flags & OBJF_USERLOADED) && !still_in_use) + solib_it->objfile->unlink (); + } pspace->deleted_solibs.push_back (solib_it->name); -- 2.55.0