From patchwork Wed Jun 3 19:16:49 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guinevere Larsen X-Patchwork-Id: 136418 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F0944BA2E15 for ; Wed, 3 Jun 2026 19:22:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F0944BA2E15 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VUjV7FWS X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 4EB594BA2E08 for ; Wed, 3 Jun 2026 19:21:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4EB594BA2E08 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4EB594BA2E08 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780514516; cv=none; b=NjZSdUM+W9Yeg+E7rwXx7ljYJ/V+FozLCuRqIEtHwaR8nlRXGjSTJUflR66Gq6pbcB4Cn1X8njcOQJGYPy8MU141W70CryJ4wNTXJt5CYr7xT5MbFPRBmQGbOqcdctTzrE2zXRN0YSHU2PsJbLvCXLLjp6zvjpTm+fH3b+pVbCY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780514516; c=relaxed/simple; bh=vYixLGQQqMczzcCmurdPPhWItYr0V7JDCngSqIFCf9c=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Ivr19UUHWEXncKbCWstehN4ACCWNOLcednClE2orl9EObGE/ZZX2+D4HqUmsCQYKpJYZNZCjNo6UULpUPlXzLuhuPYDfPJXapxzn4EbBlEj/rK42ZvlFGUltG9kzgTZ72JeNKE2oUQSYSs0QCdnJorsqlUDIvSdlrTuHtbGVhCQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VUjV7FWS DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4EB594BA2E08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780514516; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=abZKGqUMzZMC9Qkbwj3CXGrmM9SIKffTESxUxVLPfGk=; b=VUjV7FWSioJDZlWz5CIroSND9zD7f+kFQWf2mgcvgLmlEOpsUjwLt9rTWApvZOaDqt3xJ/ fabLUMw05m9v820kfyAXO3FzGsOKurblHX8TKrV3nejkjl+/YVOmwAh9KiCAzQ7Jz0f0V2 WQ8t7k1PsVnE/JLqaU/6NMFkfCznecg= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-63-FH-6Xd3TOXe4pBUHhAqDww-1; Wed, 03 Jun 2026 15:21:54 -0400 X-MC-Unique: FH-6Xd3TOXe4pBUHhAqDww-1 X-Mimecast-MFC-AGG-ID: FH-6Xd3TOXe4pBUHhAqDww_1780514513 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BC8ED195609D for ; Wed, 3 Jun 2026 19:21:53 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.96.134.41]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DE57F180049F; Wed, 3 Jun 2026 19:21:51 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH v7 5/5] Fixed gdb: prefer symtabs for the current linker namespace Date: Wed, 3 Jun 2026 16:16:49 -0300 Message-ID: <20260603191648.3396195-2-guinevere@redhat.com> In-Reply-To: <20260601192251.60958-1-guinevere@redhat.com> References: <20260601192251.60958-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mrf_C5Hii7eev-WSYheptM4ntHZegZS4JNDXXSxhh0s_1780514513 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org When a user uses the syntax 'filename'::expression, GDB will search symtabs in the order they were loaded by the inferior. This can lead to situations where the following happens: (gdb) p $_linker_namespace $1 = 3 (gdb) p [[1]]::gdb_dlmopen_glob = 1 $2 = 1 (gdb) p [[2]]::gdb_dlmopen_glob = 2 $3 = 2 (gdb) p [[3]]::gdb_dlmopen_glob = 3 $4 = 3 (gdb) p gdb_dlmopen_glob == 'dlmopen-ns-ids-lib.c'::gdb_dlmopen_glob $5 = 0 (gdb) p gdb_dlmopen_glob $6 = 3 (gdb) p 'dlmopen-ns-ids-lib.c'::gdb_dlmopen_glob $7 = 1 As a user, I would expect the expressions with and without the filename returned the exact same variable. As mentioned, because the library was loaded on namespace 1 first, that symtab is loaded first. This commit solves that issue by placing a copy of all symtabs in the current namespace first, and then adding all solibs. This can lead to a performance loss if the user is in namespace N and the symtab they are looking for is after all symtabs in namespace N, because all those symtabs will be searched first. However, I believe this is not a big concern, as I imagine most of the times that this syntax will be used, the user will either search for a symtab in the current namespace or the default one, meaning there is little chance that this will be very noticeable. This could be avoided by creating a set of the symtabs on the current namespace, and then when adding all symtabs, not re-adding ones that were there already, but this seems like too much complexity for an edge case. --- This is a resend of the patch 5/5 sent on monday. That's because the original patch failed to consider the user searching for a symtab before starting the inferior, when solib_ops () is unset, which causes GDB to crash. --- gdb/symtab.c | 6 ++++++ gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c | 3 +++ gdb/testsuite/gdb.base/dlmopen-ns-ids.exp | 9 +++++++++ 3 files changed, 18 insertions(+) base-commit: 6646680f5aa9745b5188afa5b66f6909b0f503d7 diff --git a/gdb/symtab.c b/gdb/symtab.c index d7317a758b1..e5f70f5a699 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -655,6 +655,12 @@ find_symtab (program_space *pspace, const char *name, } else { + if (pspace->solib_ops ()!= nullptr + && pspace->solib_ops ()->supports_namespaces () + && pspace->solib_ops ()->num_active_namespaces () > 1) + objfiles_to_search + = get_objfiles_in_linker_namespace (get_current_linker_namespace (), + pspace); for (objfile &objf : pspace->objfiles ()) objfiles_to_search.push_back (&objf); } diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c index 35c5124a65e..012decc25e5 100644 --- a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c +++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c @@ -52,6 +52,9 @@ main (void) fun = dlsym (handle[0], "func_with_other_call"); fun (0); + fun = dlsym (handle[2], "func_with_other_call"); + fun (0); + dlclose (handle[0]); /* TAG: first dlclose */ dlclose (handle[1]); /* TAG: second dlclose */ dlclose (handle[2]); /* TAG: third dlclose */ diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp index 78daed4518e..9c9f97e6887 100644 --- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp +++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp @@ -370,6 +370,15 @@ proc_with_prefix test_print_namespace_symbol {} { gdb_test "print ${ns2}::'${::srcfile_lib}'::gdb_dlmopen_glob + '${::srcfile}'::global_main_file" \ ".* = 1312" + gdb_continue_to_breakpoint "change_global in namespace 2" + # GDB would find symtabs in load order, ignoring the current linker namespace. + # This test ensures that we prefer the symtabs in the namespace in the current + # point of execution instead. + gdb_test "print gdb_dlmopen_glob == '${::srcfile_lib}'::gdb_dlmopen_glob" \ + ".* = 1" "symtab prioritizes the current namespace" + gdb_test "print &gdb_dlmopen_glob == &'${::srcfile_lib}'::gdb_dlmopen_glob" \ + ".* = 1" "Double checking with addresses" + # Leave to default namespace. gdb_continue_to_breakpoint "TAG: first dlclose" # This global doesn't exist in the default namespace. Rather than