From patchwork Tue Sep 22 14:15:24 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 144409 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 9E0554BA23DB for ; Tue, 22 Sep 2026 14:16:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E0554BA23DB Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=QHSvlJkj X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-vs2-x1f.google.com (mail-vs2-x1f.google.com [IPv6:2a00:1450:4864:3a::1f]) by sourceware.org (Postfix) with ESMTPS id E967A4BA2E11 for ; Tue, 22 Sep 2026 14:15:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E967A4BA2E11 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E967A4BA2E11 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:3a::1f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790086539; cv=none; b=MOBp+6gRRDQLllCMLKOis1ZGa6ELZ/bjbW31TbIPlVJhQj6NuSyKVUudEuRP/5epBKAFGKCdbHneoe7/p0ZUJfNAcAjEJUY8ZSbV+PP/MS6c4ByXk7B1pDsPFzvbqLbNvGqJIuA6ZYGLnU4S7aumSc4P4uJdv5/LUo9VGl5FGD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790086539; c=relaxed/simple; bh=JcfjCiGUsr4XHR229f8rP/pWfAqhiDWxytDwpjoLXDM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=wkAMCjU6zTvakALcswxzCgLG4zWcTZ+ETJaknILlohXTgePSkMi3OPkWFIBcYh/OOIJ3LO0VHa1mRASca33QUsMT3ItTOhy8Eu++L9avvCIrUAwvfJrqKe8nTcPM+5rgwlrLLySLY1I06MqkPbXLDEKdvt5pvuP0MgCHkDwIvDE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=QHSvlJkj DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E967A4BA2E11 Received: by mail-vs2-x1f.google.com with SMTP id 71dfb90a1353d-5c963d7503fso1396255e0c.0 for ; Tue, 22 Sep 2026 07:15:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1790086538; x=1790691338; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=QtBAviZJyM6VKxafOg3ujGM81EmyPJPrQNlTQX0lnNI=; b=QHSvlJkjTQeGkpJI00jhISY7OXzgXxhYN6PQYYV31ZPKIhsBy98cAUEuCbvZw1DkB9 4IUmc2Wf8xTet5hbr4whA2f0mpve8knzb3vhPO2fBoRg7D+mhjbhFVItSGtw0sWto/qr Z2SssRp6h/pc84UJtF5WpxwEe6oM5eGwvVPseU1KbtgK1lo/th7bRVjUBCENXFR+eqKI AlSIV3WQLnNnN2vpGdpMu52D3L07RJ1AgKfb07dSN60FrNG7M2+U4P4gMJY+2Kiq7FrG ocNEQsTrp0+yjZyEbzAzQ2SU3HwVQwDOTDew7wnDZnr4i9rbmLGnnAUhxy6ewvp5e6OO ypNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1790086538; x=1790691338; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QtBAviZJyM6VKxafOg3ujGM81EmyPJPrQNlTQX0lnNI=; b=LfFGGTg2UzTkkIfWd38KSYXq+Ibg3F+iIsStOjFDGYjzaY5oCDgPOI2KOcqUqaXf9R aNzm98feMMU/ZmcUBSMO1xgcJ9pnkVdW6SHaZdHf03NjzvxQFM9nbOv7m1oJ2B58FzIp WbHLhR0SSdgJmrF4ugOGgp4djLYhMjeMi7hhIiJQsff72fcX+Tf5W/SUhMd8X711pYTd 2Fvrz4vCKkaXQd4FD3vmm1QFArBMNO3ex/BgHCe4sm3TLLDmjVXsMsHBGzeXlkA5mAk1 mMglm+muNjqHERpS4kQthxdIbNEjcxbHeXLQhiotNsaMUjwW6aJVlqMRDbcdvTHrtVQF MpaA== X-Gm-Message-State: AFuF++kULBPkelfpQzUDOFtwhHMtbnotTUL3wbThKQrKhpzcDRBar1IA EDRUY1LRiHK/9dIjS6DfDgdPmwe0FMB/AQbFAU/PQhP5YiL1D0Iy5esEXIqdDoDvA08QWKYZy9S nr5JW X-Gm-Gg: AYBFou1Wn0fgvbvRF/gqzUMM+qsjLPStCQVlPQ60Xu8lByp1kqKZxqHobiLtPwEKys9 ZCnPlvbK7ZqOGLi69FCRixxh8RHJpYQGZ6/pMcP/4iHabHI42NoAbt60NtyE0oea8OJugsLU0Qm wOMtTlaoraI8Vbi/J6T3lzg8DwgRy1kURx5zvFBztA0q7afMeKKXAaeGXvbcsYF0Z67KzbZ4dRJ 9M3OC0lrWEyGyYmB4qhcZMojc+as10FnBbolGmrg3iQBAy+foR2dqDWm9vRDT0K3kUXDhdLE4Xu WlBfZwa9GBwJFEa+MCjSqXow0bb6iuwBthrmZPwcsg1Dj9e14FdZwmKh98/iL6nBnW709nQyH6D 5oy7+3iVhIeaXsYItt/i3nIxpWplmO2CrOUiYRnGaXS8jWiZN7D+esCX/J1F+0+pTdFGCdLUtzh 9/9fmVWJOSshjewDgQkkMra+QMUAMK6+IQex2XSsTDmwaXI9gELOAj/dHprCPc8p6gXBrE4/l55 qIpSCZ383QH6kjWpF5EuTDKHRZphmD6CUGHYOQ= X-Received: by 2002:a05:6122:46a2:b0:5c9:a60b:e5d5 with SMTP id 71dfb90a1353d-5c9b5a024ecmr8164065e0c.15.1790086538193; Tue, 22 Sep 2026 07:15:38 -0700 (PDT) Received: from mandiga ([2804:1b3:a7c0:321:19b5:1ce7:ad44:9587]) by smtp.gmail.com with ESMTPSA id 71dfb90a1353d-5c9e7d81054sm1648651e0c.17.2026.09.22.07.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2026 07:15:37 -0700 (PDT) From: Adhemerval Zanella To: binutils@sourceware.org Cc: Thiago Jung Bauermann Subject: [PATCH] gdb: Skip useless minsym scan in variable-only symbol searches Date: Tue, 22 Sep 2026 11:15:24 -0300 Message-ID: <20260922141533.3468100-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, 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: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org The symbol-listing command -symbol-info-* family goes through global_symbol_searcher::search, which has 3 steps: 1. expand_symtabs (objfile, preg): make sure every compunit that could contain a match is expanded. Returns found_msymbol = true if it saw a matching msymbol that has no debug info. 2. add_matching_symbols (...): walk the compunits and collect the real matches. 3. After the loop, a minsym fallback: if found_msymbol was set, or unconditionally for any variable search with no file filter, re-scan msymbols and append the ones without debug info (unless the searcher set exclude_minsyms). Step 1 had two phases, first objfile::search, which uses the quick-symbol index to expand candidate compunits; then the pre-pass for every msymbol in the objfile whose name matches the regexp: 1.1. function search: call find_compunit_symtab_for_pc (address). This consults the quick functions and can expand the compunit containing that address. 1.2. variable search: call lookup_symbol_in_objfile_from_linkage_name, which does a linear scan of objfile->compunits () per lookup. It can not expand anything; its only output is setting found_msymbol when the lookup fails. So for variables the pre-pass costs 'msymbols * expanded-compunits' block lookups and produces exactly one bit of information (found_msymbol) and this dominates the command execution time. And in step 3. these MI3 commands (search_module_symbols) calls spec2.set_exclude_minsyms (true), which sets !m_exclude_minsyms to false. The fallback never runs (found_msymbol is ignored), making the pre-pass calculation not required. The fix is make SEARCH_VAR_DOMAIN skip the pre-pass. For variable searches with no filenames the fallback condition already contains '(m_kind & SEARCH_VAR_DOMAIN) != 0' as an unconditional alternative. Since the pre-pass now only runs for searches that include SEARCH_FUNCTION_DOMAIN, the lookup_symbol_in_objfile_from_linkage_name branch of the conditional inside the loop is unreachable. Also update the comments, which still described the variable lookup and claimed it forces symtabs to be read. That was true when lookup_symbol_in_objfile_from_linkage_name was added in commit 422d65e705c7, but it no longer expands any symtab. -symbol-info-module-variables --module on the 2000-module benchmark drops from 90 s to 0.56 s cold. Change-Id: I6019bcf80629f21cf6dee74d0e96fa788a70e220 --- gdb/symtab.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 93684c14777..13824587e75 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4750,22 +4750,20 @@ global_symbol_searcher::expand_symtabs SEARCH_GLOBAL_BLOCK | SEARCH_STATIC_BLOCK, kind); - /* Here, we search through the minimal symbol tables for functions and - variables that match, and force their symbols to be read. This is in - particular necessary for demangled variable names, which are no longer - put into the partial symbol tables. The symbol will then be found + /* Here, we search through the minimal symbol tables for functions that + match, and force their symbols to be read. The symbol will then be found during the scan of symtabs later. - For functions, find_pc_symtab should succeed if we have debug info for - the function, for variables we have to call - lookup_symbol_in_objfile_from_linkage_name to determine if the - variable has debug info. If the lookup fails, set found_msymbol so - that we will rescan to print any matching symbols without debug info. - We only search the objfile the msymbol came from, we no longer search - all objfiles. In large programs (1000s of shared libs) searching all - objfiles is not worth the pain. */ + The find_compunit_symtab_for_pc should succeed if we have debug info for + the function. If it fails, set found_msymbol so that we will rescan to + print any matching symbols without debug info. We only search the + objfile the msymbol came from, we no longer search all objfiles. + + Variables are not handled here, and looking them up does not expand any + symtab. When no file names were given the caller unconditionally rescans + the minimal symbols for SEARCH_VAR_DOMAIN. */ if (m_filenames.empty () - && (kind & (SEARCH_VAR_DOMAIN | SEARCH_FUNCTION_DOMAIN)) != 0) + && (kind & SEARCH_FUNCTION_DOMAIN) != 0) { for (minimal_symbol *msymbol : objfile->msymbols ()) { @@ -4780,18 +4778,13 @@ global_symbol_searcher::expand_symtabs || preg->exec (msymbol->natural_name (), 0, NULL, 0) == 0) { - /* An important side-effect of these lookup functions is + /* An important side-effect of this lookup function is to expand the symbol table if msymbol is found, later in the process we will add matching symbols or msymbols to the results list, and that requires that the symbols tables are expanded. */ - if ((kind & SEARCH_FUNCTION_DOMAIN) != 0 - ? (find_compunit_symtab_for_pc - (msymbol->value_address (objfile)) == NULL) - : (lookup_symbol_in_objfile_from_linkage_name - (objfile, msymbol->linkage_name (), - SEARCH_VFT) - .symbol == NULL)) + if (find_compunit_symtab_for_pc + (msymbol->value_address (objfile)) == nullptr) found_msymbol = true; } }