From patchwork Wed Jan 8 11:38:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 104340 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B7653858C51 for ; Wed, 8 Jan 2025 11:39:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B7653858C51 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=felsk6sw; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=dROlgiIP; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=WfCYRhxB; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=94S4XXsb X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id B1AF23858C41 for ; Wed, 8 Jan 2025 11:38:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1AF23858C41 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B1AF23858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736336315; cv=none; b=tHyC0fVYUpB2HPxWyt9+HhUHt3NXQWJDabBH7eeigNjorK3Hd8psijIirMX2jjz12tE6TFWHoELtdwoKUYbfIKbqS1Uh7Uani/XEMlLdiJ+u9pXAKVM4OkatpOxsh+rCvq32aTwaVhboTak8eBQa/c8UHEiCGfRVz5mPU0eI6fM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736336315; c=relaxed/simple; bh=7KZvNPCVnNJMlTSG4C9o+a+BV6O5JW9SDiGAMMXKH3Y=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-ID:MIME-Version; b=g6xkWAe3BGTtILwh5yQ2oIoqoogWr6hFm6fkx6MX/y8b6g1eHTVIPPjCdb2cuabhT3pZf9KNktE2u1aNZJH3x7iyclNkHsNaRhR4IQYUxvBrlEQIZR+0lPZEl60oQm+orS4R6VuUEbJJP+jj5enG7U284dRCP8IT0z8QhGLIXds= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1AF23858C41 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A39301F385 for ; Wed, 8 Jan 2025 11:38:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736336314; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YECHAW/3+cq6WGO3Rm/FGVkLG/NHNbwr0Gq3AEW112Q=; b=felsk6swEGKrWSqoRNcIkoP6JNebyD4dhE7ZAJY/wEF6Y4sNiy9W3hvZihtQzv76HV6QVz jYWsFEMnSoqdTzDjHCB3mNcZk5MFIyT9KE79vMT8rTQOSNGeDKHZr+4tKN8e3EwuLE2Hci ZxJtRBGtcnGuRWyYSCCSx1omgjJ4VGw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736336314; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YECHAW/3+cq6WGO3Rm/FGVkLG/NHNbwr0Gq3AEW112Q=; b=dROlgiIPdmN/1ESITf7dthNjbGrttQQDX9EBb+fzwBDa8bqUJTG7HNgMowImqhBjCnMSln jPDWwnA1yScyeICA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=WfCYRhxB; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=94S4XXsb DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1736336313; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YECHAW/3+cq6WGO3Rm/FGVkLG/NHNbwr0Gq3AEW112Q=; b=WfCYRhxBuf0uctv7ixulDIEE67Sxm4dY/ewQW4a3sWOT4virMl9qrXAQNpGQjYi2jKyP9T ohQHiqRt7Wh699fILDlYuGZLJQAXvdJ2opP8Dm41BfyAvx1jn/5yagRkK0FzZoOf9CqhKQ ZehXHGB14vvMLDrvpzAZTwRjVfaxyoA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1736336313; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=YECHAW/3+cq6WGO3Rm/FGVkLG/NHNbwr0Gq3AEW112Q=; b=94S4XXsbLRkldDYZ556rThfipMs1VuAAZJylNXriui7SDeIJUVeMDaufUBCMFguP2ePDBd ps/u08PB01TPMkDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 8CEA7137DA for ; Wed, 8 Jan 2025 11:38:33 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GcMIIbljfmfHEAAAD6G6ig (envelope-from ) for ; Wed, 08 Jan 2025 11:38:33 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH v2] [gdb/symtab] Require current language before symbol lookups Date: Wed, 8 Jan 2025 12:38:16 +0100 Message-ID: <20250108113816.27724-1-tdevries@suse.de> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: A39301F385 X-Spam-Score: -3.01 X-Rspamd-Action: no action X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[99.99%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCPT_COUNT_ONE(0.00)[1]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_NONE(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:rdns, imap1.dmz-prg2.suse.org:helo, suse.de:mid, suse.de:dkim] X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Level: X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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 Test-case gdb.python/py-symbol.exp fails with various target boards, including fission and gold-gdb-index. The problem here is that, in this test, the current language is still unset (i.e., lazy) when the symbol lookup is done. It is eventually set deep in the lookup -- but this then requires a reentrant symbol lookup, which fails. (DWARF symbol lookup is not reentrant.) Fix this by: - detecting symbol lookup reentrance using an assert, and - requiring the current language to be set when entering symbol lookup. Tested on x86_64-linux. Co-Authored-By: Tom Tromey PR symtab/32490 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32490 --- gdb/symtab.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) base-commit: 19ca41656eef546957d707aa086ab196f0890c51 diff --git a/gdb/symtab.c b/gdb/symtab.c index ba421267b9a..837c5aef6be 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -124,6 +124,39 @@ struct main_info static const registry::key main_progspace_key; +/* Symbol lookup is not reentrant (though this is not an intrinsic + restriction). Keep track of whether a symbol lookup is active, to be able + to detect reentrancy. */ +static bool in_symbol_lookup; + +/* Struct to mark that a symbol lookup is active for the duration of its + lifetime. */ + +struct enter_symbol_lookup +{ + enter_symbol_lookup () + { + /* Ensure that the current language has been set. Normally the + language is set lazily. However, when performing a symbol lookup, + this could result in a recursive call into the lookup code in some + cases. Set it now to ensure that this does not happen. */ + get_current_language (); + + /* Detect symbol lookup reentrance. */ + gdb_assert (!in_symbol_lookup); + + in_symbol_lookup = true; + } + + ~enter_symbol_lookup () + { + /* Sanity check. */ + gdb_assert (in_symbol_lookup); + + in_symbol_lookup = false; + } +}; + /* The default symbol cache size. There is no extra cpu cost for large N (except when flushing the cache, which is rare). The value here is just a first attempt. A better default @@ -2259,6 +2292,8 @@ lookup_symbol_in_block (const char *name, symbol_name_match_type match_type, const struct block *block, const domain_search_flags domain) { + enter_symbol_lookup tmp; + struct symbol *sym; if (symbol_lookup_debug) @@ -2294,6 +2329,8 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile, const char *name, const domain_search_flags domain) { + enter_symbol_lookup tmp; + gdb_assert (block_index == GLOBAL_BLOCK || block_index == STATIC_BLOCK); for (objfile *objfile : main_objfile->separate_debug_objfiles ()) @@ -2619,6 +2656,8 @@ lookup_global_or_static_symbol (const char *name, return result; } + enter_symbol_lookup tmp; + /* Do a global search (of global blocks, heh). */ if (result.symbol == NULL) gdbarch_iterate_over_objfiles_in_search_order