From patchwork Mon Nov 20 16:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 167257 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2b07:b0:403:3b70:6f57 with SMTP id io7csp55722vqb; Mon, 20 Nov 2023 08:34:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEGG8yY5w157uBDisnZI80WmK222KHXV0eEv29ZX6LYOE0Gr8/EPXLdLgKbZpIE0yvo8iz X-Received: by 2002:ac8:5d51:0:b0:419:6cde:86e6 with SMTP id g17-20020ac85d51000000b004196cde86e6mr24673786qtx.32.1700498065855; Mon, 20 Nov 2023 08:34:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700498065; cv=pass; d=google.com; s=arc-20160816; b=jatXt+58sfvG4AB/64L4AZx/TnGzo1RM8LF1GCi/aSypxyNOMdB2B1o2wDhs+/ZU1J v00X6CVfm/3K+hqPveb9O0e6U8r9grNPtWJcBrCAKa23hkh0Xb78DtuTxXBcLsvym2fh q98zJv/RN16Xbn0aTkYuK7rOZ7LSyYNqbPwtL8Byky/NqAZqiowHIKL/iLm10VECz/cw ePu3aFKYh+4lxgWZ9GbWLmgKfMoFfyw1kw7LnN6Rhn5PflMQYOPShov4sDDUPumMYTbr hpG79CmiITIR8c6/a2YHSUVaVodebT5i5FlaWYGC3EDVI+mJlsssS1ZCoUlYywS78t8x qLjg== 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=Vw473MzHCdV+UBog2sHVf2Inj0DVx2AQqRi0fDp0W1E=; fh=PTZv/fEnntkVjZjJeDKIkUWVkECXkQyaIllNGCyO/VM=; b=btIESW8wAASHhf8exo5hzEdGvNWpsGVdj4p0SwHXcFTfFHLq44oi3Ke/qtkBQbWmJz SElAsOgZrDWoJDdJohbmRkoKZK1mEI4twno+h1TIA+Y3DRdkHe3MXJUvjSSFdaFDEE3n KyetDcMD7tSX+Y7c1WIF6v8NwcfN+dQZ5ZSGqNFwM228kFAyyg83YnFljpJYmeiD2h1l 9/rqCVV6EfivQbQqmi9INg5O5KupGJzA5ninKaeDTms7zNdMvzaPVscMq5bUmjP/Hn5S GuHTpgnalRNESAKhW+ZMmTxcr2mPEBG7cs0GRILyLxw0h/rLmtAw72TtXg+QcR+dpU+q H5vQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@tromey.com header.s=default header.b=iIanw13o; 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 p7-20020a05622a13c700b00417c0806678si7272260qtk.725.2023.11.20.08.34.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 08:34:25 -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=iIanw13o; 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 59A133870C01 for ; Mon, 20 Nov 2023 16:34:04 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from omta034.useast.a.cloudfilter.net (omta034.useast.a.cloudfilter.net [44.202.169.33]) by sourceware.org (Postfix) with ESMTPS id E1F1F38449E5 for ; Mon, 20 Nov 2023 16:33:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1F1F38449E5 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 E1F1F38449E5 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=44.202.169.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700498035; cv=none; b=QWCVQZXUSyBZbCJKRvl1ObjaCi62dvgyXkOLkZOSBj6Z8E7JuCXAsuuU7NBXEhqEOBWh8fXLuyPdeOBCfEZFJcUfz6eIBhQcxf+H27/Uelo+7pnn7yU9/FUsw2AX/yqg5fD6UUpoVton4dD+awJ66JmmkjzQCZ/tIv5XF6fbu6Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700498035; c=relaxed/simple; bh=4x45ek2dPUVlLPghB6yyeGEfylUApF/p9SQjiU9Gj8w=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=U30eHxoYTilNPBBnhSYat/BQcc/bwrrqJPl0cwfxDt0sZRo1ZskWG9GaCQrF9xVxiMRydXhDS16Tff0X4sYm53rm/7ggOp4lBTPqmWO6tY7mZc9yfecpOtAKkNIy1qnPB1Nk/OHFB6ykz16JFNXYm6X0JdhFt6en/UVq479eQFA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from eig-obgw-5009a.ext.cloudfilter.net ([10.0.29.176]) by cmsmtp with ESMTPS id 555yrMf5yjtZ357DhrSHWK; Mon, 20 Nov 2023 16:33:57 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id 57DbrooW997pz57DbriHTO; Mon, 20 Nov 2023 16:33:51 +0000 X-Authority-Analysis: v=2.4 cv=ULDOoQTy c=1 sm=1 tr=0 ts=655b8a6f a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=BNY50KLci1gA:10 a=Qbun_eYptAEA:10 a=fvL0G6l5JvUnnJqGCwwA:9 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=Vw473MzHCdV+UBog2sHVf2Inj0DVx2AQqRi0fDp0W1E=; b=iIanw13oODcLvgWxMWCm7S94nJ KXZGEGkMpprCAlNRaYMBmVHBiPfYGjlqJ9UGvZP2SBxg0m+E+Vim5MqHVNwvKcWGVDaVZKTthet1N yh0SJ9hav247q334gmIzunVKB; Received: from 97-122-77-73.hlrn.qwest.net ([97.122.77.73]:37692 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 1r57Db-000T8d-0K; Mon, 20 Nov 2023 09:33:51 -0700 From: Tom Tromey To: binutils@sourceware.org Cc: Tom Tromey Subject: [pushed] Restore .gdb_index v9 display in readelf Date: Mon, 20 Nov 2023 09:33:53 -0700 Message-ID: <20231120163353.1488312-1-tom@tromey.com> X-Mailer: git-send-email 2.41.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: 1r57Db-000T8d-0K X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-77-73.hlrn.qwest.net (localhost.localdomain) [97.122.77.73]:37692 X-Source-Auth: tom+tromey.com X-Email-Count: 4 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfI0hFETVp3GZCOTTO5MoH01FT7L9ZXQc/akxX33pgHLBbHcJoSnvNA//0/mMKS/y/MQj3MK/yblIxkorEWniREfFi1+q7lkQ0Pssss86ldeJGbk26mlt ZPeH53yiR3DmyZz1zJNnM3SXkqKrHwsGFNZ4jfEiRl55VYC72etiKON8eJvCHf7cvkpgF3nxxetZU/F+colX/Lh8rHDznmeOw9U= X-Spam-Status: No, score=-3024.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, 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: 1783101459806505352 X-GMAIL-MSGID: 1783101459806505352 An earlier patch (commit b05efa39 "readelf..debug-dump=loc displays bogus base addresses") inadvertently removed support for displaying .gdb_index v9 sections. This patch corrects the oversight. I tested this by using readelf on an appropriate file. * dwarf.c (display_gdb_index): Restore v9 display code. --- binutils/dwarf.c | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 024b322b542..705451db68f 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -10641,29 +10641,31 @@ display_gdb_index (struct dwarf_section *section, unsigned char *start = section->start; uint32_t version; uint32_t cu_list_offset, tu_list_offset; - uint32_t address_table_offset, symbol_table_offset, constant_pool_offset; + uint32_t address_table_offset, symbol_table_offset, constant_pool_offset, + shortcut_table_offset; unsigned int cu_list_elements, tu_list_elements; unsigned int address_table_elements, symbol_table_slots; unsigned char *cu_list, *tu_list; - unsigned char *address_table, *symbol_table, *constant_pool; + unsigned char *address_table, *symbol_table, *shortcut_table, *constant_pool; unsigned int i; /* The documentation for the format of this file is in gdb/dwarf2read.c. */ introduce (section, false); - if (section->size < 6 * sizeof (uint32_t)) + version = section->size < 4 ? 0 : byte_get_little_endian (start, 4); + size_t header_size = (version < 9 ? 6 : 7) * sizeof (uint32_t); + if (section->size < header_size) { warn (_("Truncated header in the %s section.\n"), section->name); return 0; } - version = byte_get_little_endian (start, 4); printf (_("Version %lu\n"), (unsigned long) version); /* Prior versions are obsolete, and future versions may not be backwards compatible. */ - if (version < 3 || version > 8) + if (version < 3 || version > 9) { warn (_("Unsupported version %lu.\n"), (unsigned long) version); return 0; @@ -10685,17 +10687,23 @@ display_gdb_index (struct dwarf_section *section, tu_list_offset = byte_get_little_endian (start + 8, 4); address_table_offset = byte_get_little_endian (start + 12, 4); symbol_table_offset = byte_get_little_endian (start + 16, 4); - constant_pool_offset = byte_get_little_endian (start + 20, 4); + shortcut_table_offset = byte_get_little_endian (start + 20, 4); + if (version < 9) + constant_pool_offset = shortcut_table_offset; + else + constant_pool_offset = byte_get_little_endian (start + 24, 4); if (cu_list_offset > section->size || tu_list_offset > section->size || address_table_offset > section->size || symbol_table_offset > section->size + || shortcut_table_offset > section->size || constant_pool_offset > section->size || tu_list_offset < cu_list_offset || address_table_offset < tu_list_offset || symbol_table_offset < address_table_offset - || constant_pool_offset < symbol_table_offset) + || shortcut_table_offset < symbol_table_offset + || constant_pool_offset < shortcut_table_offset) { warn (_("Corrupt header in the %s section.\n"), section->name); return 0; @@ -10704,12 +10712,13 @@ display_gdb_index (struct dwarf_section *section, cu_list_elements = (tu_list_offset - cu_list_offset) / 16; tu_list_elements = (address_table_offset - tu_list_offset) / 24; address_table_elements = (symbol_table_offset - address_table_offset) / 20; - symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8; + symbol_table_slots = (shortcut_table_offset - symbol_table_offset) / 8; cu_list = start + cu_list_offset; tu_list = start + tu_list_offset; address_table = start + address_table_offset; symbol_table = start + symbol_table_offset; + shortcut_table = start + shortcut_table_offset; constant_pool = start + constant_pool_offset; printf (_("\nCU table:\n")); @@ -10821,6 +10830,38 @@ display_gdb_index (struct dwarf_section *section, } } + if (version >= 9) + { + printf (_("\nShortcut table:\n")); + + if (shortcut_table_offset + 8 > constant_pool_offset) + { + warn (_("Corrupt shortcut table in the %s section.\n"), section->name); + return 0; + } + + uint32_t lang = byte_get_little_endian (shortcut_table, 4); + printf (_("Language of main: ")); + display_lang (lang); + printf ("\n"); + + printf (_("Name of main: ")); + if (lang == 0) + printf (_("\n")); + else + { + uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); + if (name_offset >= section->size - constant_pool_offset) + { + printf (_("\n"), name_offset); + warn (_("Corrupt name offset of 0x%x found for name of main\n"), + name_offset); + } + else + printf ("%s\n", constant_pool + name_offset); + } + } + return 1; }