From patchwork Fri Oct 6 17:49:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 149367 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp498096vqo; Fri, 6 Oct 2023 10:49:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGdoMdEXlwP6cGj5nZqC7d6391QXn2xAqqT8P229Dh35eorwhMMjGa6+6J/sFLSF4CdztTq X-Received: by 2002:a05:6402:35ca:b0:52e:3ce8:e333 with SMTP id z10-20020a05640235ca00b0052e3ce8e333mr4391263edc.18.1696614596424; Fri, 06 Oct 2023 10:49:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696614596; cv=none; d=google.com; s=arc-20160816; b=XyYDUt5rp7vSLGMXcky/gDNijz6aRrW9CTHTsCyhL4dQkN5osnDfC33pEPGxvn+XaX KCrX04mHATfS1C19oBcoksJdhyblWyxEqkejPXakrsd0kXdME97clOtFH3Sptdvay0Hb 9Hki3DuL92pCze9FO0uAqfZGhTQAU7uOajVCNARwqwMGiuKRYqmTOJy2g+Oesgy6P0Rm DYJhsqCUmQb0hWDpmmiUfeoZ5KUgw2QIx2yH+//+Yd1YobBcYuQMeV060eHtsJpuyPV5 0zkadoSreRvCSraFOovH4Zx2BrhIiipmFcdeP4TnOhtfOv5IVL6NGcgtdtZhJVsliz18 57gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=6GsDfSO6PVBr9oDPqntTZ2QLpuztqfELgGZf2E9iZso=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=Qx+uKLCmw2pDc9mzYxPNRmUIqLV/vZ79+3Zb9mokyFWQcSmEGSir9leu1UQ23ogn21 wdYDo/BSeXtJLB5hDSmNQxyzzW1V9HxiUTx/7KFicQO8hfMaNbhiSdjx1xdg6AdnLPha ZUmTjYDPmnt4VfNdLJYir3prg04cEbobLnlZ4agEeJCLN6VB7Qd7PqJUxGpw8PazD40m Y8wJQojstGh8l8sLv6s2VugKwmr8jUFtN6eR2dAe7jIo/9pj7+xtaLQiqvbFQrU8HJv+ L7kKk9L/v0L9IYduj6FJ67TwNHgIUmffIi/9fsa6fUkBD3fe6nn+jBOd+7Vbyzdk4Rdk VMCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=e3nYGQ5v; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id l14-20020a056402028e00b0053317c1d986si1747547edv.222.2023.10.06.10.49.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 10:49:56 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=e3nYGQ5v; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B7AFA3856DC2 for ; Fri, 6 Oct 2023 17:49:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B7AFA3856DC2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1696614591; bh=6GsDfSO6PVBr9oDPqntTZ2QLpuztqfELgGZf2E9iZso=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=e3nYGQ5vmQw4avhXyWvsibep1Jz9oaZRyL3yo4ANsic9m17oazukSfCz88ZN2tFyC M0cBa/t0T2ex936/7TXXQGaw85SYcNzamewEly+LyUuHZtV3LEZL6mvyswtlSLaGq0 yOfML+V8lRKxvD8TItLyFKV58Cpk//V46K8fsHS0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id C9EB3385828E for ; Fri, 6 Oct 2023 17:49:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C9EB3385828E Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id F2A8F21880 for ; Fri, 6 Oct 2023 17:49:40 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id DEA3213A7A for ; Fri, 6 Oct 2023 17:49:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6FEsNbRIIGXwQAAAMHmgww (envelope-from ) for ; Fri, 06 Oct 2023 17:49:40 +0000 To: binutils@sourceware.org Subject: [PATCH 2/2] [readelf] Handle .gdb_index section version 9 Date: Fri, 6 Oct 2023 19:49:42 +0200 Message-Id: <20231006174942.27361-3-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231006174942.27361-1-tdevries@suse.de> References: <20231006174942.27361-1-tdevries@suse.de> MIME-Version: 1.0 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, 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: 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: , X-Patchwork-Original-From: Tom de Vries via Binutils From: Tom de Vries Reply-To: Tom de Vries Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779029347221487600 X-GMAIL-MSGID: 1779029347221487600 Add the abilitity to print a v9 .gdb_index section. The v9 section contains an extra table, which is printed as follows: ... Shortcut table: Language of main: Fortran 95 Name of main: contains_keyword ... [ For the example, I used the exec of gdb test-case gdb.fortran/nested-funcs-2-exp when running the test-case with target board cc-with-gdb-index. ] Tested on x86_64-linux. --- binutils/dwarf.c | 176 ++++++++++++++++++++++++++++++----------------- 1 file changed, 113 insertions(+), 63 deletions(-) diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 7a350cae50b..6adc37c9169 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -2342,6 +2342,72 @@ display_discr_list (unsigned long form, printf (")(unsigned)"); } +static void +display_lang (uint64_t uvalue) +{ + switch (uvalue) + { + /* Ordered by the numeric value of these constants. */ + case DW_LANG_C89: printf ("ANSI C"); break; + case DW_LANG_C: printf ("non-ANSI C"); break; + case DW_LANG_Ada83: printf ("Ada"); break; + case DW_LANG_C_plus_plus: printf ("C++"); break; + case DW_LANG_Cobol74: printf ("Cobol 74"); break; + case DW_LANG_Cobol85: printf ("Cobol 85"); break; + case DW_LANG_Fortran77: printf ("FORTRAN 77"); break; + case DW_LANG_Fortran90: printf ("Fortran 90"); break; + case DW_LANG_Pascal83: printf ("ANSI Pascal"); break; + case DW_LANG_Modula2: printf ("Modula 2"); break; + + /* DWARF 2.1 values. */ + case DW_LANG_Java: printf ("Java"); break; + case DW_LANG_C99: printf ("ANSI C99"); break; + case DW_LANG_Ada95: printf ("ADA 95"); break; + case DW_LANG_Fortran95: printf ("Fortran 95"); break; + + /* DWARF 3 values. */ + case DW_LANG_PLI: printf ("PLI"); break; + case DW_LANG_ObjC: printf ("Objective C"); break; + case DW_LANG_ObjC_plus_plus: printf ("Objective C++"); break; + case DW_LANG_UPC: printf ("Unified Parallel C"); break; + case DW_LANG_D: printf ("D"); break; + + /* DWARF 4 values. */ + case DW_LANG_Python: printf ("Python"); break; + + /* DWARF 5 values. */ + case DW_LANG_OpenCL: printf ("OpenCL"); break; + case DW_LANG_Go: printf ("Go"); break; + case DW_LANG_Modula3: printf ("Modula 3"); break; + case DW_LANG_Haskell: printf ("Haskell"); break; + case DW_LANG_C_plus_plus_03: printf ("C++03"); break; + case DW_LANG_C_plus_plus_11: printf ("C++11"); break; + case DW_LANG_OCaml: printf ("OCaml"); break; + case DW_LANG_Rust: printf ("Rust"); break; + case DW_LANG_C11: printf ("C11"); break; + case DW_LANG_Swift: printf ("Swift"); break; + case DW_LANG_Julia: printf ("Julia"); break; + case DW_LANG_Dylan: printf ("Dylan"); break; + case DW_LANG_C_plus_plus_14: printf ("C++14"); break; + case DW_LANG_Fortran03: printf ("Fortran 03"); break; + case DW_LANG_Fortran08: printf ("Fortran 08"); break; + case DW_LANG_RenderScript: printf ("RenderScript"); break; + + /* MIPS extension. */ + case DW_LANG_Mips_Assembler: printf ("MIPS assembler"); break; + + /* UPC extension. */ + case DW_LANG_Upc: printf ("Unified Parallel C"); break; + + default: + if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) + printf (_("implementation defined: %#" PRIx64 ""), uvalue); + else + printf (_("unknown: %#" PRIx64 ""), uvalue); + break; + } +} + static unsigned char * read_and_display_attr_value (unsigned long attribute, unsigned long form, @@ -3110,61 +3176,9 @@ read_and_display_attr_value (unsigned long attribute, break; case DW_AT_language: - printf ("\t"); - switch (uvalue) - { - /* Ordered by the numeric value of these constants. */ - case DW_LANG_C89: printf ("(ANSI C)"); break; - case DW_LANG_C: printf ("(non-ANSI C)"); break; - case DW_LANG_Ada83: printf ("(Ada)"); break; - case DW_LANG_C_plus_plus: printf ("(C++)"); break; - case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; - case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; - case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; - case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; - case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; - case DW_LANG_Modula2: printf ("(Modula 2)"); break; - /* DWARF 2.1 values. */ - case DW_LANG_Java: printf ("(Java)"); break; - case DW_LANG_C99: printf ("(ANSI C99)"); break; - case DW_LANG_Ada95: printf ("(ADA 95)"); break; - case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; - /* DWARF 3 values. */ - case DW_LANG_PLI: printf ("(PLI)"); break; - case DW_LANG_ObjC: printf ("(Objective C)"); break; - case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; - case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; - case DW_LANG_D: printf ("(D)"); break; - /* DWARF 4 values. */ - case DW_LANG_Python: printf ("(Python)"); break; - /* DWARF 5 values. */ - case DW_LANG_OpenCL: printf ("(OpenCL)"); break; - case DW_LANG_Go: printf ("(Go)"); break; - case DW_LANG_Modula3: printf ("(Modula 3)"); break; - case DW_LANG_Haskell: printf ("(Haskell)"); break; - case DW_LANG_C_plus_plus_03: printf ("(C++03)"); break; - case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; - case DW_LANG_OCaml: printf ("(OCaml)"); break; - case DW_LANG_Rust: printf ("(Rust)"); break; - case DW_LANG_C11: printf ("(C11)"); break; - case DW_LANG_Swift: printf ("(Swift)"); break; - case DW_LANG_Julia: printf ("(Julia)"); break; - case DW_LANG_Dylan: printf ("(Dylan)"); break; - case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; - case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; - case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; - case DW_LANG_RenderScript: printf ("(RenderScript)"); break; - /* MIPS extension. */ - case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; - /* UPC extension. */ - case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; - default: - if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) - printf (_("(implementation defined: %#" PRIx64 ")"), uvalue); - else - printf (_("(unknown: %#" PRIx64 ")"), uvalue); - break; - } + printf ("\t("); + display_lang (uvalue); + printf (")"); break; case DW_AT_encoding: @@ -10738,29 +10752,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; @@ -10782,17 +10798,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; @@ -10801,12 +10823,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")); @@ -10918,6 +10941,33 @@ 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"); + + uint32_t name_offset = byte_get_little_endian (shortcut_table + 4, 4); + printf (_("Name of main: ")); + 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; }