From patchwork Thu Aug 16 23:52:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sterling Augustine X-Patchwork-Id: 178130 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id ACC532C0098 for ; Fri, 17 Aug 2012 09:53:14 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1345765995; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:To:Subject:Message-Id:Date: From:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=ZcemoDg jqIQo7fdGxrT/rO9USiQ=; b=uWS3CKINqGb6PZYJeFrmk5E9hKuaBE2qfHhCnIp sR4ZPa3v8u7mkfQsTzJFEOPjvWufPXQJRpbOXw7E641VfPq1wE/aDRU3meyU4lUE zd2amHbAE16VtFyfN1RjNvpxYxLHteIYxip12+yjipZVrwXdrA0ksv5T/Hsqw8vh T4Ys= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:X-Google-DKIM-Signature:Received:Received:Received:Received:Received:To:Subject:Message-Id:Date:From:X-Gm-Message-State:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=ubsAvmyb5ajjNKrzTwoz+GyNlbQcWrusBg+N5YAWM2U2ABwRdrSse3gV0ylqQZ PsJsSJ6owdZ4V4rIWraCkA32hTKhUeVaw23eTP1Q4ng7iFD6BQfsicRR1l+awOGk dosXOOkDXDtk7NsVUuI9MfVKoW4j/1miT5IhMxHnw5v5s=; Received: (qmail 22779 invoked by alias); 16 Aug 2012 23:53:06 -0000 Received: (qmail 22768 invoked by uid 22791); 16 Aug 2012 23:53:04 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, KAM_STOCKGEN, KHOP_RCVD_TRUST, RCVD_IN_DNSWL_LOW, RCVD_IN_HOSTKARMA_YE, RP_MATCHES_RCVD, TW_CX, URIBL_DBL_REDIR X-Spam-Check-By: sourceware.org Received: from mail-fa0-f73.google.com (HELO mail-fa0-f73.google.com) (209.85.161.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 16 Aug 2012 23:52:50 +0000 Received: by fapp1 with SMTP id p1so148955fap.2 for ; Thu, 16 Aug 2012 16:52:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=to:subject:message-id:date:from:x-gm-message-state; bh=2+rdhxepQojM5StUEEpp4kJEisZRLddkD7+RuwEYwJs=; b=ASxygl3XNqyYn7c6SanJYV2AR1beTfL1NsUhivgA8f3NiFaGVFhvIh36qT2cw4/OCR r3UJxfkz1bsqNsyCD3CDeyeCAsCgsUu432LdVXIbSUW9QCid7UI0VewLTEchlOMKBYTZ /uleCowuvguZeGUxq6Awkmxs6DRWN9poXIbQCuMBMOs1dd4Pof83b8TFvaeFzOwB0Ofm bL2LrXHJqht9RNrMIEYudq/n0lUol0yhcHXHNxQ0EJLOrHVxdPOHlZVUi79CErWwu4rv uhoLsOr1zWy99vjPwStW0csGVswlJ0uTWLlfHOOL+GIKNCwDfHLBFrIdTq/o35SGuOmF Xrpg== Received: by 10.14.179.72 with SMTP id g48mr2592270eem.2.1345161169017; Thu, 16 Aug 2012 16:52:49 -0700 (PDT) Received: by 10.14.179.72 with SMTP id g48mr2592264eem.2.1345161168961; Thu, 16 Aug 2012 16:52:48 -0700 (PDT) Received: from hpza10.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id 46si7784494eed.1.2012.08.16.16.52.48 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 16 Aug 2012 16:52:48 -0700 (PDT) Received: from sterling.mtv.corp.google.com (sterling.mtv.corp.google.com [172.18.111.14]) by hpza10.eem.corp.google.com (Postfix) with ESMTP id 9C3B420004E; Thu, 16 Aug 2012 16:52:48 -0700 (PDT) Received: by sterling.mtv.corp.google.com (Postfix, from userid 135279) id DEDE11609D0; Thu, 16 Aug 2012 16:52:47 -0700 (PDT) To: reply@codereview.appspotmail.com,gcc-patches@gcc.gnu.org Subject: [Google 4.7] Generate pubnames compatible with gdb-index version 7. (issue6459099) Message-Id: <20120816235247.DEDE11609D0@sterling.mtv.corp.google.com> Date: Thu, 16 Aug 2012 16:52:47 -0700 (PDT) From: saugustine@google.com (Sterling Augustine) X-Gm-Message-State: ALoCoQm2gV7sNjh39jNyf8NOy/lcvKP6WQCfz9wvH9Bjqn2q6XYqn8tAsq4kreyOvDya3sJjoG2MzzXTHXzpWAEI6iKhutQtiptZGKoHcNiA+MMF/65MCF3TIVtgAZQkk4WkWaD6OeCl9mtwhfwcz1qmApgLxSjDW6ZLvHQtxuDWtNiJcIRpdVzBcn/58ybpMW1+ig29sYs5 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The enclosed patch adds a new option -ggnu-pubnames to solve the problem that current pubnames don't supply enough information for Gold to generate a version 7 gdb index. The patch encodes the flag byte from gdb-index version 7, and saves it between the offset and name in the pubtype. We can't generate the index entry directly because the cu_index is calculated during the link, but we can generate the flag byte. Of particular note is the fact that this patch adds include/gdb/gdb-index.h from the gdb and binutils trees. OK for google 4.7? Sterling 2012-08-16 Sterling Augustine gcc/ChangeLog * dwarf2out.c (DEBUG_PUBNAMES_SECTION, DEBUG_PUBTYPES_SECTION): Adjust macros. (is_java, include_pubname_in_output): New functions. (size_of_pubnames): Call include_pubname_in_output. New variable space_for_flags. (output_pubnames): Refactor, moving most of the logic to... (output_pubname): ... here. New function. (dwarf2out_finish): Move output pubtable logic to... (output_pubtables): ... here. New function. * common.opt (ggnu-pubnames): New option. * doc/invoke.texi: Document it. include/ChangeLog: * gdb/gdb-index.h: Check in from src. --- This patch is available for review at http://codereview.appspot.com/6459099 Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 190448) +++ dwarf2out.c (working copy) @@ -96,6 +96,7 @@ along with GCC; see the file COPYING3. If not see #include "cfglayout.h" #include "opts.h" #include "l-ipo.h" +#include "gdb/gdb-index.h" static void dwarf2out_source_line (unsigned int, const char *, int, bool); static rtx last_var_location_insn; @@ -3634,10 +3635,14 @@ new_addr_loc_descr (rtx addr, int dtprel) #define DEBUG_DWO_LOC_SECTION ".debug_loc.dwo" #endif #ifndef DEBUG_PUBNAMES_SECTION -#define DEBUG_PUBNAMES_SECTION ".debug_pubnames" +#define DEBUG_PUBNAMES_SECTION \ + ((debug_generate_pub_sections == 2) \ + ? ".debug_gnu_pubnames" : ".debug_pubnames") #endif #ifndef DEBUG_PUBTYPES_SECTION -#define DEBUG_PUBTYPES_SECTION ".debug_pubtypes" +#define DEBUG_PUBTYPES_SECTION \ + ((debug_generate_pub_sections == 2) \ + ? ".debug_gnu_pubtypes" : ".debug_pubtypes") #endif #define DEBUG_NORM_STR_OFFSETS_SECTION ".debug_str_offsets" #define DEBUG_DWO_STR_OFFSETS_SECTION ".debug_str_offsets.dwo" @@ -5148,6 +5153,16 @@ is_cxx (void) return lang == DW_LANG_C_plus_plus || lang == DW_LANG_ObjC_plus_plus; } +/* Return TRUE if the language is Java. */ + +static inline bool +is_java (void) +{ + unsigned int lang = get_AT_unsigned (comp_unit_die (), DW_AT_language); + + return lang == DW_LANG_Java; +} + /* Return TRUE if the language is Fortran. */ static inline bool @@ -8257,22 +8272,32 @@ unmark_all_dies (dw_die_ref die) unmark_all_dies (AT_ref (a)); } +/* Calculate if the entry should appear in the final output file. It may be + from a pruned a type. */ + +static bool +include_pubname_in_output (VEC (pubname_entry, gc) *table, pubname_entry *p) +{ + return (table != pubtype_table + || p->die->die_offset != 0 + || !flag_eliminate_unused_debug_types); +} + /* Return the size of the .debug_pubnames or .debug_pubtypes table generated for the compilation unit. */ static unsigned long -size_of_pubnames (VEC (pubname_entry, gc) * names) +size_of_pubnames (VEC (pubname_entry, gc) *names) { unsigned long size; unsigned i; pubname_ref p; + int space_for_flags = (debug_generate_pub_sections == 2) ? 1 : 0; size = DWARF_PUBNAMES_HEADER_SIZE; FOR_EACH_VEC_ELT (pubname_entry, names, i, p) - if (names != pubtype_table - || p->die->die_offset != 0 - || !flag_eliminate_unused_debug_types) - size += strlen (p->name) + DWARF_OFFSET_SIZE + 1; + if (include_pubname_in_output (names, p)) + size += strlen (p->name) + DWARF_OFFSET_SIZE + 1 + space_for_flags; size += DWARF_OFFSET_SIZE; return size; @@ -9395,6 +9420,71 @@ add_pubtype (tree decl, dw_die_ref die) } } +/* Output a single entry in the pubnames table. */ + +static void +output_pubname (dw_offset die_offset, pubname_entry *entry) +{ + dw_die_ref die = entry->die; + int is_static = get_AT_flag (die, DW_AT_external) ? 1 : 0; + + dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset"); + + if (debug_generate_pub_sections == 2) + { + uint32_t flags = GDB_INDEX_SYMBOL_KIND_NONE; + switch (die->die_tag) + { + case DW_TAG_typedef: + case DW_TAG_base_type: + case DW_TAG_subrange_type: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE); + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1); + break; + case DW_TAG_enumerator: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, + GDB_INDEX_SYMBOL_KIND_VARIABLE); + if (!is_cxx () && !is_java ()) + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1); + break; + case DW_TAG_subprogram: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, + GDB_INDEX_SYMBOL_KIND_FUNCTION); + if (!is_ada ()) + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static); + break; + case DW_TAG_constant: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, + GDB_INDEX_SYMBOL_KIND_VARIABLE); + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static); + break; + case DW_TAG_variable: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, + GDB_INDEX_SYMBOL_KIND_VARIABLE); + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, is_static); + break; + case DW_TAG_namespace: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE); + break; + case DW_TAG_class_type: + case DW_TAG_interface_type: + case DW_TAG_structure_type: + case DW_TAG_union_type: + case DW_TAG_enumeration_type: + GDB_INDEX_SYMBOL_KIND_SET_VALUE(flags, GDB_INDEX_SYMBOL_KIND_TYPE); + GDB_INDEX_SYMBOL_STATIC_SET_VALUE(flags, 1); + break; + default: + gcc_unreachable (); + } + dw2_asm_output_data (1, flags >> GDB_INDEX_CU_BITSIZE, + "GDB-index flags"); + } + + dw2_asm_output_nstring (entry->name, -1, "external name"); +} + + /* Output the public names table used to speed up access to externally visible names; or the public types table used to find type definitions. */ @@ -9405,29 +9495,14 @@ output_pubnames (VEC (pubname_entry, gc) * names) unsigned long pubnames_length = size_of_pubnames (names); pubname_ref pub; - if (!want_pubnames () || !info_section_emitted) - return; - if (names == pubname_table) - { - switch_to_section (debug_pubnames_section); - ASM_OUTPUT_LABEL (asm_out_file, debug_pubnames_section_label); - } - else - { - switch_to_section (debug_pubtypes_section); - ASM_OUTPUT_LABEL (asm_out_file, debug_pubtypes_section_label); - } if (DWARF_INITIAL_LENGTH_SIZE - DWARF_OFFSET_SIZE == 4) dw2_asm_output_data (4, 0xffffffff, "Initial length escape value indicating 64-bit DWARF extension"); - if (names == pubname_table) - dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, - "Length of Public Names Info"); - else - dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, - "Length of Public Type Names Info"); - /* Version number for pubnames/pubtypes is still 2, even in DWARF3. */ + dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, "Pub Info Length"); + + /* Version number for pubnames/pubtypes is independent of dwarf version. */ dw2_asm_output_data (2, 2, "DWARF Version"); + if (dwarf_split_debug_info) dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_skeleton_info_section_label, debug_skeleton_info_section, @@ -9445,9 +9520,7 @@ output_pubnames (VEC (pubname_entry, gc) * names) if (names == pubname_table) gcc_assert (pub->die->die_mark); - if (names != pubtype_table - || pub->die->die_offset != 0 - || !flag_eliminate_unused_debug_types) + if (include_pubname_in_output (names, pub)) { dw_offset die_offset = pub->die->die_offset; @@ -9465,15 +9538,33 @@ output_pubnames (VEC (pubname_entry, gc) * names) : 0); } - dw2_asm_output_data (DWARF_OFFSET_SIZE, die_offset, "DIE offset"); - - dw2_asm_output_nstring (pub->name, -1, "external name"); + output_pubname (die_offset, pub); } } dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); } +/* Output public names and types tables if necessary. */ + +static void +output_pubtables (void) +{ + if (!want_pubnames () || !info_section_emitted) + return; + + switch_to_section (debug_pubnames_section); + ASM_OUTPUT_LABEL (asm_out_file, debug_pubnames_section_label); + output_pubnames (pubname_table); + /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2. + It shouldn't hurt to emit it always, since pure DWARF2 consumers + simply won't look for the section. */ + switch_to_section (debug_pubtypes_section); + ASM_OUTPUT_LABEL (asm_out_file, debug_pubtypes_section_label); + output_pubnames (pubtype_table); +} + + /* Output the information that goes into the .debug_aranges table. Namely, define the beginning and ending address range of the text section generated for this compilation unit. */ @@ -23740,12 +23831,7 @@ dwarf2out_finish (const char *filename) output_location_lists (comp_unit_die ()); } - /* Output public names and types tables if necessary. */ - output_pubnames (pubname_table); - /* ??? Only defined by DWARF3, but emitted by Darwin for DWARF2. - It shouldn't hurt to emit it always, since pure DWARF2 consumers - simply won't look for the section. */ - output_pubnames (pubtype_table); + output_pubtables (); /* Output the address range information if a CU (.debug_info section) was emitted. We output an empty table even if we had no functions Index: common.opt =================================================================== --- common.opt (revision 190448) +++ common.opt (working copy) @@ -2424,6 +2424,10 @@ gpubnames Common RejectNegative Var(debug_generate_pub_sections, 1) Generate DWARF pubnames and pubtypes sections. +ggnu-pubnames +Common RejectNegative Var(debug_generate_pub_sections, 2) +Generate DWARF pubnames and pubtypes sections. + gno-record-gcc-switches Common RejectNegative Var(dwarf_record_gcc_switches,0) Init(0) Don't record gcc command line switches in DWARF DW_AT_producer. Index: doc/invoke.texi =================================================================== --- doc/invoke.texi (revision 190448) +++ doc/invoke.texi (working copy) @@ -4973,6 +4973,12 @@ @opindex gpubnames Generate dwarf .debug_pubnames and .debug_pubtypes sections. +@item -ggnu-pubnames +@opindex ggnu-pubnames +Generate .debug_pubnames and .debug_pubtypes sections in a format +suitable for conversion into a GDB@ index. This option is only useful +with a linker that can produce GDB@ index version 7. + @item -gstabs @opindex gstabs Produce debugging information in stabs format (if that is supported),