From patchwork Tue May 21 15:44:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 90613 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 1CF54385840B for ; Tue, 21 May 2024 15:44:26 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 66964385840B for ; Tue, 21 May 2024 15:43:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 66964385840B 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 66964385840B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716306187; cv=none; b=bhL7v6uhFgOyQ3S2T3V0qUful9VAXSEuBnaa2hcdSgYN0G3ya1KRa4g6i4/ZUqTvPLgka/weyXoaAdT4sonUg7tWiWc9wLBhbu1sU107IrQ3tcmn5xnnZqngfeGcuWinLpyXS5IFOLShKTgSbgABmbSJnVyFds37ieeLM6zs1hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716306187; c=relaxed/simple; bh=Fm+KeEILMP3fRVhbYwCiz/RjMo0FF6xrjpede+MdgI4=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:From: To:Subject:Date:Message-Id:MIME-Version; b=FCDagUKvH91cb5G7G6Ak33mtoQDNJyZAuS4qWTAj/t9c+a3c+rO9UcyJxP7wN2dorOc35afjCQ3cOGBgxD0z2tpwRuJVWTpjzJlUQtrE7IzyCiEpHyy+S1RZj8A+tyohgGjNnTeVUKubkhw69WIexy3pCQmLkPSoQyHwQriEi3M= ARC-Authentication-Results: i=1; server2.sourceware.org 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 7B0205C293 for ; Tue, 21 May 2024 15:43:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716306183; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvI1dXfOGRpRjtxa2rX5OMDTfQGryhx7F0y68Db5FG0=; b=Q/9yvLgSPgMI2EvNlxezemWHZDLW08CrJ4LjuJwtxZg8WdzWtxDuhdeKijxZHh6/oUrAZs S35r9E4RUOlGhCITSv4hHwenLVgnEZ7x/SdK2RXt9v2G6L2SoBVaMF6mnJSPnhzfzTLynT 9KmU46kxgJ5oS1Af8Smr9pQ8CBjwOGc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716306183; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvI1dXfOGRpRjtxa2rX5OMDTfQGryhx7F0y68Db5FG0=; b=dl/J/B9YloFUqVPVWSbDDjWJV6egknKz2HWgup8CpBVl3FV3qH6Z7njMvWvDk00Qqs+r2W hLHmFj3a+2oNi7AA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="Q/9yvLgS"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="dl/J/B9Y" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1716306183; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvI1dXfOGRpRjtxa2rX5OMDTfQGryhx7F0y68Db5FG0=; b=Q/9yvLgSPgMI2EvNlxezemWHZDLW08CrJ4LjuJwtxZg8WdzWtxDuhdeKijxZHh6/oUrAZs S35r9E4RUOlGhCITSv4hHwenLVgnEZ7x/SdK2RXt9v2G6L2SoBVaMF6mnJSPnhzfzTLynT 9KmU46kxgJ5oS1Af8Smr9pQ8CBjwOGc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1716306183; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qvI1dXfOGRpRjtxa2rX5OMDTfQGryhx7F0y68Db5FG0=; b=dl/J/B9YloFUqVPVWSbDDjWJV6egknKz2HWgup8CpBVl3FV3qH6Z7njMvWvDk00Qqs+r2W hLHmFj3a+2oNi7AA== 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 657B113A21 for ; Tue, 21 May 2024 15:43:03 +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 IOGWFwfBTGbJGwAAD6G6ig (envelope-from ) for ; Tue, 21 May 2024 15:43:03 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH 05/11] [gdb/macros] Work around a gcc PR fixed in gcc 9 Date: Tue, 21 May 2024 17:44:09 +0200 Message-Id: <20240521154415.9543-5-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240521154415.9543-1-tdevries@suse.de> References: <20240521154415.9543-1-tdevries@suse.de> MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; RCVD_TLS_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Action: no action X-Rspamd-Queue-Id: 7B0205C293 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Spam-Score: -3.01 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, 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 When running test-case gdb.base/fission-macro-i.exp with gcc 8, we run into: ... (gdb) set complaints 0^M Offset from DW_FORM_GNU_str_index or DW_FORM_strx pointing outside of \ .debug_str.dwo section in CU at offset 0x0 \ [in module fission-macro-i-v5-b32-s0]^M (gdb) FAIL: gdb.base/fission-macro-i.exp: dwarf_version=5: dwarf_bits=32: \ strict_dwarf=0: set complaints 0 ... We're using dwarf5, so the .debug_str_offsets section is supposed to have a header, but there's none: ... .section .debug_str_offsets.dwo,"e",@progbits .long 0 # indexed string 0x0: GNU C17 8.2.1 20180831 ... .long 0x87 # indexed string 0x1: FIRST 1 .long 0x8f # indexed string 0x2: /home/vries/gdb .long 0x9f # indexed string 0x3: main .long 0xa4 # indexed string 0x4: fission-macro-i.i .long 0xe1 # indexed string 0x5: SECOND 2 ... In other words, we have a v4-style .debug_str_offsets section. Workaround this by detecting that it's not a valid v5 header by comparing the initial length to the the section size, and handling it as a v4 section. IWBN to enable this workaround only for gcc version < 9, but unfortunately the workaround is required to correctly read the producer string, so that's not possible. Tested on x86_64-linux. Tested test-case (and gdb.base/fission-macro.exp) using a current gcc trunk build and gcc 7-14. --- gdb/dwarf2/read.c | 77 +++++++++++++++------- gdb/testsuite/gdb.base/fission-macro-i.exp | 2 - 2 files changed, 53 insertions(+), 26 deletions(-) diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c index 3c2698d6832..abe128f35df 100644 --- a/gdb/dwarf2/read.c +++ b/gdb/dwarf2/read.c @@ -17514,32 +17514,47 @@ read_dwo_str_index (const struct die_reader_specs *reader, ULONGEST str_index) const gdb_byte *p = reader->dwo_file->sections.str_offsets.buffer; /* Header: Initial length. */ - read_initial_length (abfd, p + bytes_read, &bytes_read); + LONGEST initial_length + = read_initial_length (abfd, p + bytes_read, &bytes_read); - /* Determine offset_size based on the .debug_str_offsets header. */ - const bool dwarf5_is_dwarf64 = bytes_read != 4; - offset_size = dwarf5_is_dwarf64 ? 8 : 4; + if (initial_length + bytes_read + == reader->dwo_file->sections.str_offsets.size) + { + /* Determine offset_size based on the .debug_str_offsets header. */ + const bool dwarf5_is_dwarf64 = bytes_read != 4; + offset_size = dwarf5_is_dwarf64 ? 8 : 4; - /* Header: Version. */ - unsigned version = read_2_bytes (abfd, p + bytes_read); - bytes_read += 2; + /* Header: Version. */ + unsigned version = read_2_bytes (abfd, p + bytes_read); + bytes_read += 2; - if (version <= 4) - { - /* We'd like one warning here about ignoring the section, but - because we parse the header more than once (see FIXME above) - we'd have many warnings, so use a complaint instead, which at - least has a limit. */ - complaint (_("Section .debug_str_offsets in %s has unsupported" - " version %d, use empty string."), - reader->dwo_file->dwo_name.c_str (), version); - return ""; - } + if (version <= 4) + { + /* We'd like one warning here about ignoring the section, but + because we parse the header more than once (see FIXME above) + we'd have many warnings, so use a complaint instead, which at + least has a limit. */ + complaint (_("Section .debug_str_offsets in %s has unsupported" + " version %d, use empty string."), + reader->dwo_file->dwo_name.c_str (), version); + return ""; + } - /* Header: Padding. */ - bytes_read += 2; + /* Header: Padding. */ + bytes_read += 2; - str_offsets_base = bytes_read; + str_offsets_base = bytes_read; + } + else + { + /* GCC 8 and earlier has a bug that for dwarf5 it produces a + pre-dwarf5 .debug_str_offsets section. We'd wish we could make + this work-around more precise by checking that producer is gcc and + gcc version <= 8, but that doesn't work if we need this workaround + to read the producer string. */ + offset_size = 4; + str_offsets_base = 0; + } } else { @@ -21249,9 +21264,23 @@ dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, { bfd *abfd = str_offsets_section->get_bfd_owner (); unsigned int bytes_read = 0; - read_initial_length (abfd, str_offsets_section->buffer, &bytes_read, false); - const bool is_dwarf64 = bytes_read != 4; - str_offsets_base = is_dwarf64 ? 16 : 8; + LONGEST initial_length + = read_initial_length (abfd, str_offsets_section->buffer, + &bytes_read, false); + if ((bytes_read == 4 || bytes_read == 12) + && initial_length + bytes_read == str_offsets_section->size) + { + const bool is_dwarf64 = bytes_read != 4; + str_offsets_base = is_dwarf64 ? 16 : 8; + } + else + { + /* GCC 8 and earlier has a bug that for dwarf5 it produces a + pre-dwarf5 .debug_str_offsets section. We use the same test + as in read_dwo_str_index. */ + str_offsets_base = 0; + offset_size = 4; + } } } else diff --git a/gdb/testsuite/gdb.base/fission-macro-i.exp b/gdb/testsuite/gdb.base/fission-macro-i.exp index 3121e1d289b..ae211d0e09b 100644 --- a/gdb/testsuite/gdb.base/fission-macro-i.exp +++ b/gdb/testsuite/gdb.base/fission-macro-i.exp @@ -13,8 +13,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . */ -require {expr [gcc_major_version] >= 9} - # Use a .i file instead of a .c file, to make sure that we only generate one # .debug_macros section, working around gcc PR debug/111409. standard_testfile .i -2.i