From patchwork Mon Dec 4 15:12:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 173440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp2828987vqy; Mon, 4 Dec 2023 07:12:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IGkLMhGnduD1EFrmtk1lUGpKfo9tQZMN5PDyQ4YT/6dLFN7BluQrWyernK2fTQUbCmxNDJG X-Received: by 2002:a05:6808:120d:b0:3b8:b063:a1c2 with SMTP id a13-20020a056808120d00b003b8b063a1c2mr5707216oil.76.1701702769594; Mon, 04 Dec 2023 07:12:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701702769; cv=pass; d=google.com; s=arc-20160816; b=V7LlHsEYLM18BDvRyXvdosrK4ec7BCx3wY6BYMUGFQEQRb1F767/Owic0IjER38Ick TXvnhHof0lzAp6xrmYNL1j92lkU8RkOo70EoeR6Uxai45W+OsNTfqzIs39/MKaCi5T9u EKMz3bYZfMXo1liGRRV4a5jYx99Q0wGt0BaFpHZ9NlwdgOAz+OIPMSpA4rfD/PcI46a9 XCvg69t/YN8y6WBj+zliTCkGnNiB1ge7M+x2ADEm3uUrI+Y1exMJZbRc25UkPmIEwGAc 1ZuOrZMR8X17qEsPTlUSUenhFtqtkACneqhNOvCDcvzKFmGgFWT4T0dzUrzzYlGLRRio S+sA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=PRUpAboXixztF1AjgI2By4o6FRwspA6uvKyKZ75/5GA=; fh=PTZv/fEnntkVjZjJeDKIkUWVkECXkQyaIllNGCyO/VM=; b=yeVcv4EXD2AqYsLS5SRQW9EWoS50lJMjg0+ZrFybTtBuinH+bFKGU36SUwICje2fOF i+E4ugPlwnDP18vAtHnC8igrt7iaJOH0ZkISZIbaMZt02gjKaImNrMraLEa2M/tftG/s ZPyzVMfZOq0UARCU4Os1V9SilwEfWUioJPQm6+TuprHn8359zbvWnu4W4E2vv3r4de/D MLrzPulBljsmx0G3qGEdSq2ktuirMUxbLSiRUHZ5y01481FCdPw7HO/rRzZ1SYxgu/hx XT9PntAfqThobjAtrNBV/4IvMP5H2FQ61bKA1w1VOJZjfADcZ40nFYRD8uWvJaGYDwQ1 IzVg== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=bH6szwWK; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id k5-20020a056102116500b004645fce3bfbsi184823vsg.342.2023.12.04.07.12.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 07:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=bH6szwWK; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4F3C0385828E for ; Mon, 4 Dec 2023 15:12:49 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by sourceware.org (Postfix) with ESMTPS id 5BCA03858C98 for ; Mon, 4 Dec 2023 15:12:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5BCA03858C98 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5BCA03858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=35.89.44.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701702764; cv=none; b=QJsu3VpdnsJxMjM+1utqOR620bxHWpclEvOmo8ecG9ib9hm5jG9s4zS18lOaK0Ls9GWbFG4DykRAFehKUGxGIXpW8a96OXpSQS8uuzS8ZOu27xi1DI6e7oKm89xIRXWl5Fv9ZORvzZVTv75YnFJFjEJvrcUN/fjXxoJUhGeRz1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701702764; c=relaxed/simple; bh=V4ii20NTQqp+04XwN+q3Evrx2YdPkrOY6X4Y3XbVJnY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tfsbY0V+8Y7fEYDV77rh4bmNRxIKgyUKN/zHIrf6h/YPPon6i/0uwiSWt8ZaQiYmhPz4kylLKTSKzrSkQ6hfW7UM6UELcdQ1FRxd4ObDFJ1H0M9A0oJMlgvnFw9ybCzkIuc3/XCPrFuzeZaz+SP5a+I87XcQ+Rj65O9EoeeasKI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-6004a.ext.cloudfilter.net ([10.0.30.197]) by cmsmtp with ESMTPS id A9O9ro5ibhqFdAAchrb89o; Mon, 04 Dec 2023 15:12:39 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id AAcgraZNxRGmSAAchrOJAT; Mon, 04 Dec 2023 15:12:39 +0000 X-Authority-Analysis: v=2.4 cv=efcuwpIH c=1 sm=1 tr=0 ts=656dec67 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=e2cXIFwxEfEA:10 a=Qbun_eYptAEA:10 a=zstS-IiYAAAA:8 a=EYb50_e_yDXIDiQrBW8A:9 a=4G6NA9xxw8l3yy4pmD5M:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=PRUpAboXixztF1AjgI2By4o6FRwspA6uvKyKZ75/5GA=; b=bH6szwWKwiH90nC0gwY5ONXAdj quuTySeeebl3fzK1OyjplFDb3hv34tQU2bYiRDjfOnIYCMj8RCZIEEKPAdj2dF6NIsbSPMH8oA2Uz Ljs5vArCMWfR9jUU9mH4d69au; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:55662 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96.2) (envelope-from ) id 1rAAcg-003CEN-1e; Mon, 04 Dec 2023 08:12:38 -0700 From: Tom Tromey To: binutils@sourceware.org Cc: Tom Tromey Subject: [PATCH] Fix two buglets in .debug_names dumping Date: Mon, 4 Dec 2023 08:12:31 -0700 Message-ID: <20231204151231.60788-1-tom@tromey.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.77.73 X-Source-L: No X-Exim-ID: 1rAAcg-003CEN-1e X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:55662 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfBiS2P3bVmqWySHBurw+0o7qAuRIdcAV0jAxKB1QcFFBraStVQ79NXHQz9Nr1O1lkPkAbqz1qsm9S//Kv8jImuY+jARf8jeKPibiZ8ze33Y6ttZROEG2 n7g3WNt3mWzvWo50fvin2vI1W/X5v2ilddUx6O3osmjiHOPEQByzwQSdaxoDGtDS4BGyEs0p/SHfCx8CTrGsvwC92cpeirERH70= X-Spam-Status: No, score=-3023.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: 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+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784364683267099723 X-GMAIL-MSGID: 1784364683267099723 While working on gdb's .debug_names writer, I found a couple of small bugs in binutils .debug_names dumping. First, the DWARF spec (section 6.1.1.4.6 Name Table) says: These two arrays are indexed starting at 1, [...] I think it is clearer for binutils to follow this, particularly because DW_IDX_parent refers to this number. Second, I think the handling of an empty hash table is slightly wrong. Currently the dumping code assumes there is always an array of hashes. However, section 6.1.1.4.5 Hash Lookup Table says: The optional hash lookup table immediately follows the list of type signatures. and then: The hash lookup table is actually two separate arrays: an array of buckets, followed immediately by an array of hashes. My reading of this is that the hash table as a whole is optional, and so the hashes will not exist in this case. (This also makes sense because the hashes are not useful without the buckets anyway.) This patch fixes both of these problems. FWIW I have some gdb patches in progress that change gdb both to omit the hash table and to use DW_IDX_parent. binutils/ChangeLog 2023-12-04 Tom Tromey * dwarf.c (display_debug_names): Handle empty .debug_names hash table. Name entries start at 1. --- binutils/ChangeLog | 5 +++++ binutils/dwarf.c | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 9e7d8753148..47eadfd1c67 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -10353,7 +10353,8 @@ display_debug_names (struct dwarf_section *section, void *file) const uint32_t *const hash_table_buckets = (uint32_t *) hdrptr; hdrptr += bucket_count * sizeof (uint32_t); const uint32_t *const hash_table_hashes = (uint32_t *) hdrptr; - hdrptr += name_count * sizeof (uint32_t); + if (bucket_count != 0) + hdrptr += name_count * sizeof (uint32_t); unsigned char *const name_table_string_offsets = hdrptr; hdrptr += name_count * offset_size; unsigned char *const name_table_entry_offsets = hdrptr; @@ -10478,8 +10479,12 @@ display_debug_names (struct dwarf_section *section, void *file) p = name_table_entry_offsets + namei * offset_size; SAFE_BYTE_GET (entry_offset, p, offset_size, unit_end); - printf ("[%3u] #%08x %s:", namei, hash_table_hashes[namei], - fetch_indirect_string (string_offset)); + /* The name table is indexed starting at 1 according to + DWARF, so be sure to use the DWARF numbering here. */ + printf ("[%3u] ", namei + 1); + if (bucket_count != 0) + printf ("#%08x ", hash_table_hashes[namei]); + printf ("%s:", fetch_indirect_string (string_offset)); unsigned char *entryptr = entry_pool + entry_offset;