From patchwork Fri Jul 22 13:48:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 106294 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 23196B6F70 for ; Fri, 22 Jul 2011 23:49:18 +1000 (EST) Received: (qmail 25046 invoked by alias); 22 Jul 2011 13:49:15 -0000 Received: (qmail 25027 invoked by uid 22791); 22 Jul 2011 13:49:13 -0000 X-SWARE-Spam-Status: No, hits=-7.0 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CP, TW_GD, TW_GV, TW_GX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 22 Jul 2011 13:48:57 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6MDmo1c019606 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 22 Jul 2011 09:48:50 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6MDmnIN029691 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 22 Jul 2011 09:48:50 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id p6MDmm2R027903; Fri, 22 Jul 2011 15:48:48 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id p6MDmmFm027901; Fri, 22 Jul 2011 15:48:48 +0200 Date: Fri, 22 Jul 2011 15:48:48 +0200 From: Jakub Jelinek To: "Joseph S. Myers" , Jason Merrill Cc: Richard Henderson , Tom Tromey , Jan Kratochvil , gcc-patches@gcc.gnu.org, Roland McGrath Subject: [PATCH] -grecord-gcc-switches (PR other/32998, take 3) Message-ID: <20110722134847.GE2687@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek References: <20110712234608.GR2687@tyan-ft48-01.lab.bos.redhat.com> <20110721201944.GW2687@tyan-ft48-01.lab.bos.redhat.com> <20110722130058.GC2687@tyan-ft48-01.lab.bos.redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 On Fri, Jul 22, 2011 at 01:31:20PM +0000, Joseph S. Myers wrote: > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > I don't see a change to invoke.texi to document the new options, but Oops, fixed below, tested with make doc. > otherwise it looks OK in option handling terms. Thanks. Jason, is this ok for you too? 2011-07-22 Jakub Jelinek PR other/32998 * common.opt (grecord-gcc-switches, gno-record-gcc-switches): New options. * dwarf2out.c: Include opts.h. (dchar_p): New typedef. Define heap VEC for it. (producer_string): New variable. (gen_producer_string): New function. (gen_compile_unit_die): Use it. (dwarf2out_finish): Fix up comp_unit_die () DW_AT_producer if needed. * Makefile.in (dwarf2out.o): Depend on $(OPTS_H). * doc/invoke.texi: Document -grecord-gcc-switches and -gno-record-gcc-switches, add a -grecord-gcc-switches reference to -frecord-gcc-switches description. Jakub --- gcc/common.opt.jj 2011-07-13 17:31:09.000000000 +0200 +++ gcc/common.opt 2011-07-14 10:36:40.000000000 +0200 @@ -2184,6 +2184,14 @@ ggdb Common JoinedOrMissing Generate debug information in default extended format +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. + +grecord-gcc-switches +Common RejectNegative Var(dwarf_record_gcc_switches,1) +Record gcc command line switches in DWARF DW_AT_producer. + gstabs Common JoinedOrMissing Negative(gstabs+) Generate debug information in STABS format --- gcc/dwarf2out.c.jj 2011-07-22 09:18:49.000000000 +0200 +++ gcc/dwarf2out.c 2011-07-22 09:30:40.000000000 +0200 @@ -94,6 +94,7 @@ along with GCC; see the file COPYING3. #include "tree-pass.h" #include "tree-flow.h" #include "cfglayout.h" +#include "opts.h" static void dwarf2out_source_line (unsigned int, const char *, int, bool); static rtx last_var_location_insn; @@ -18116,13 +18117,123 @@ gen_ptr_to_mbr_type_die (tree type, dw_d add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); } +typedef const char *dchar_p; /* For DEF_VEC_P. */ +DEF_VEC_P(dchar_p); +DEF_VEC_ALLOC_P(dchar_p,heap); + +static char *producer_string; + +/* Return a heap allocated producer string including command line options + if -grecord-gcc-switches. */ + +static char * +gen_producer_string (void) +{ + size_t j; + VEC(dchar_p, heap) *switches = NULL; + const char *language_string = lang_hooks.name; + char *producer, *tail; + const char *p; + size_t len = dwarf_record_gcc_switches ? 0 : 3; + size_t plen = strlen (language_string) + 1 + strlen (version_string); + + for (j = 1; dwarf_record_gcc_switches && j < save_decoded_options_count; j++) + switch (save_decoded_options[j].opt_index) + { + case OPT_o: + case OPT_d: + case OPT_dumpbase: + case OPT_dumpdir: + case OPT_auxbase: + case OPT_auxbase_strip: + case OPT_quiet: + case OPT_version: + case OPT_v: + case OPT_w: + case OPT_L: + case OPT_D: + case OPT_I: + case OPT_U: + case OPT_SPECIAL_unknown: + case OPT_SPECIAL_ignore: + case OPT_SPECIAL_program_name: + case OPT_SPECIAL_input_file: + case OPT_grecord_gcc_switches: + case OPT_gno_record_gcc_switches: + case OPT__output_pch_: + case OPT_fdiagnostics_show_location_: + case OPT_fdiagnostics_show_option: + case OPT____: + case OPT__sysroot_: + case OPT_nostdinc: + case OPT_nostdinc__: + /* Ignore these. */ + continue; + default: + gcc_checking_assert (save_decoded_options[j].canonical_option[0][0] + == '-'); + switch (save_decoded_options[j].canonical_option[0][1]) + { + case 'M': + case 'i': + case 'W': + continue; + case 'f': + if (strncmp (save_decoded_options[j].canonical_option[0] + 2, + "dump", 4) == 0) + continue; + break; + default: + break; + } + VEC_safe_push (dchar_p, heap, switches, + save_decoded_options[j].orig_option_with_args_text); + len += strlen (save_decoded_options[j].orig_option_with_args_text) + 1; + break; + } + + producer = XNEWVEC (char, plen + 1 + len + 1); + tail = producer; + sprintf (tail, "%s %s", language_string, version_string); + tail += plen; + + if (!dwarf_record_gcc_switches) + { +#ifdef MIPS_DEBUGGING_INFO + /* The MIPS/SGI compilers place the 'cc' command line options in the + producer string. The SGI debugger looks for -g, -g1, -g2, or -g3; + if they do not appear in the producer string, the debugger reaches + the conclusion that the object file is stripped and has no debugging + information. To get the MIPS/SGI debugger to believe that there is + debugging information in the object file, we add a -g to the producer + string. */ + if (debug_info_level > DINFO_LEVEL_TERSE) + { + memcpy (tail, " -g", 3); + tail += 3; + } +#endif + } + + FOR_EACH_VEC_ELT (dchar_p, switches, j, p) + { + len = strlen (p); + *tail = ' '; + memcpy (tail + 1, p, len); + tail += len + 1; + } + + *tail = '\0'; + VEC_free (dchar_p, heap, switches); + return producer; +} + /* Generate the DIE for the compilation unit. */ static dw_die_ref gen_compile_unit_die (const char *filename) { dw_die_ref die; - char producer[250]; const char *language_string = lang_hooks.name; int language; @@ -18136,20 +18247,9 @@ gen_compile_unit_die (const char *filena add_comp_dir_attribute (die); } - sprintf (producer, "%s %s", language_string, version_string); - -#ifdef MIPS_DEBUGGING_INFO - /* The MIPS/SGI compilers place the 'cc' command line options in the producer - string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do - not appear in the producer string, the debugger reaches the conclusion - that the object file is stripped and has no debugging information. - To get the MIPS/SGI debugger to believe that there is debugging - information in the object file, we add a -g to the producer string. */ - if (debug_info_level > DINFO_LEVEL_TERSE) - strcat (producer, " -g"); -#endif - - add_AT_string (die, DW_AT_producer, producer); + if (producer_string == NULL) + producer_string = gen_producer_string (); + add_AT_string (die, DW_AT_producer, producer_string); /* If our producer is LTO try to figure out a common language to use from the global list of translation units. */ @@ -22123,6 +22223,15 @@ dwarf2out_finish (const char *filename) htab_t comdat_type_table; unsigned int i; + /* PCH might result in DW_AT_producer string being restored from the + header compilation, fix it up if needed. */ + dw_attr_ref producer = get_AT (comp_unit_die (), DW_AT_producer); + if (strcmp (AT_string (producer), producer_string) != 0) + { + struct indirect_string_node *node = find_AT_string (producer_string); + producer->dw_attr_val.v.val_str = node; + } + gen_scheduled_generic_parms_dies (); gen_remaining_tmpl_value_param_die_attribute (); --- gcc/Makefile.in.jj 2011-07-13 17:31:18.000000000 +0200 +++ gcc/Makefile.in 2011-07-14 10:36:40.000000000 +0200 @@ -2953,7 +2953,7 @@ dwarf2out.o : dwarf2out.c $(CONFIG_H) $( $(GGC_H) $(EXCEPT_H) dwarf2asm.h $(TM_P_H) langhooks.h $(HASHTAB_H) \ gt-dwarf2out.h $(TARGET_H) $(CGRAPH_H) $(MD5_H) $(INPUT_H) $(FUNCTION_H) \ $(GIMPLE_H) $(TREE_PASS_H) $(TREE_FLOW_H) $(CFGLAYOUT_H) \ - tree-pretty-print.h $(COMMON_TARGET_H) + tree-pretty-print.h $(COMMON_TARGET_H) $(OPTS_H) dwarf2cfi.o : dwarf2cfi.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) \ version.h $(RTL_H) $(FUNCTION_H) $(DWARF2_H) dwarf2asm.h dwarf2out.h \ $(GGC_H) $(TM_P_H) $(TARGET_H) $(TREE_PASS_H) --- gcc/doc/invoke.texi.jj 2011-07-19 11:20:34.000000000 +0200 +++ gcc/doc/invoke.texi 2011-07-22 15:42:31.573545950 +0200 @@ -11,7 +11,7 @@ @c man begin COPYRIGHT Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, -1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 +1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document @@ -328,7 +328,8 @@ Objective-C and Objective-C++ Dialects}. -fstack-usage -ftest-coverage -ftime-report -fvar-tracking @gol -fvar-tracking-assignments -fvar-tracking-assignments-toggle @gol -g -g@var{level} -gtoggle -gcoff -gdwarf-@var{version} @gol --ggdb -gstabs -gstabs+ -gstrict-dwarf -gno-strict-dwarf @gol +-ggdb -grecord-gcc-switches -gno-record-gcc-switches @gol +-gstabs -gstabs+ -gstrict-dwarf -gno-strict-dwarf @gol -gvms -gxcoff -gxcoff+ @gol -fno-merge-debug-strings -fno-dwarf2-cfi-asm @gol -fdebug-prefix-map=@var{old}=@var{new} @gol @@ -4687,6 +4688,20 @@ use, some non-conflicting DWARF 3 extens Version 4 may require GDB 7.0 and @option{-fvar-tracking-assignments} for maximum benefit. +@item -grecord-gcc-switches +@opindex grecord-gcc-switches +This switch causes the command line options, that were used to invoke the +compiler and may affect code generation, to be appended to the +DW_AT_producer attribute in DWARF debugging information. The options +are concatenated with spaces separating them from each other and from +the compiler version. See also @option{-frecord-gcc-switches} for another +way of storing compiler options into the object file. + +@item -gno-record-gcc-switches +@opindex gno-record-gcc-switches +Disallow appending command line options to the DW_AT_producer attribute +in DWARF debugging information. This is the default. + @item -gstrict-dwarf @opindex gstrict-dwarf Disallow using extensions of later DWARF standard version than selected @@ -18029,6 +18044,8 @@ usually takes the form of a section cont switch is related to the @option{-fverbose-asm} switch, but that switch only records information in the assembler output file as comments, so it never reaches the object file. +See also @option{-grecord-gcc-switches} for another +way of storing compiler options into the object file. @item -fpic @opindex fpic