public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [RFC PATCH] -grecord-gcc-switches (PR other/32998)
@ 2011-07-13  0:17 Jakub Jelinek
  2011-07-13 14:04 ` Jason Merrill
  2011-07-21 20:22 ` Joseph S. Myers
  0 siblings, 2 replies; 15+ messages in thread
From: Jakub Jelinek @ 2011-07-13  0:17 UTC (permalink / raw)
  To: Joseph S. Myers, Richard Henderson, Jason Merrill
  Cc: Tom Tromey, Jan Kratochvil, gcc-patches, Roland McGrath

Hi!

As discussed in the PR, this patch implements IMHO a better alternative
to the current -frecord-gcc-switches option which isn't very usable unless
inspected on relocatable files only.  As each switch is zero terminated and
the section is mergeable, for whole binary or shared library we end up with
a set of all options which ever showed up on the command line when compiling
some of the CUs, but it is impossible to narrow it down back to which CU has
been compiled with what options.

This patch insteads appends the options as one long string separated by
spaces to DW_AT_producer attribute (which is normally just a reference
to a string in .debug_str).  Thus, ideally if all or most of the CUs
are compiled with the same options there is just one or just small number of
different DW_AT_producer strings, but it is still possible to find out
what has been compiled with what options.

The aim is to include just (or primarily) code generation affecting options
explicitly passed on the command line.  So that the merging actually works,
options or arguments which include filenames or paths shouldn't be added,
on Roland's request -D*/-U* options aren't added either (that should be
covered by .debug_macinfo), similarly -I/-i* options (the interesting
stuff what headers have been actually used is recorded in .debug_line)
and warning options shouldn't affect code generation either.

Ideally we'd just include explicitly passed options from command line that
haven't been overridden by other command line options, and would sort them,
so that there are higher chances of DW_AT_producer strings being merged
(e.g. -O2 -ffast-math vs. -ffast-math -O2 are now different strings, and
similarly -O2 vs. -O3 -O2 vs. -O0 -O1 -Ofast -O2), but I'm not sure if it is
easily possible using current option handling framework.

Bootstrapped/regtested on x86_64-linux, e.g. cc1plus has just a few
different DW_AT_producers (sort|uniq -c|sort -n -r output):
    322  (indirect string, offset: 0x4fb3): GNU C 4.7.0 20110712 (experimental) -mtune=generic -march=x86-64 -g -O2 -pedantic -fno-common	
     48  (indirect string, offset: 0xf41f1): GNU C 4.7.0 20110712 (experimental) -mtune=generic -march=x86-64 -g -O2 -pedantic	
     16  (indirect string, offset: 0xebf8): GNU C 4.7.0 20110712 (experimental) -mtune=generic -march=x86-64 -g -O2 -fno-common	
      9  (indirect string, offset: 0xfa115): GNU C 4.7.0 20110712 (experimental) -mtune=generic -march=x86-64 -g -O2	
      2  (indirect string, offset: 0xfa974): GNU C 4.7.0 20110712 (experimental) -mtune=generic -march=x86-64 -g -g -g -O2 -O2 -O2 -fPIC -fbuilding-libgcc -fno-stack-protector -fvisibility=hidden	

2011-07-13  Jakub Jelinek  <jakub@redhat.com>

	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.
	(gen_compile_unit_die): Handle dwarf_record_gcc_switches.
	* Makefile.in (dwarf2out.o): Depend on $(OPTS_H).

	* lib/dg-pch.exp (dg-flags-pch): Compile tests for assembly comparison
	with -gno-record-gcc-switches.

--- gcc/common.opt.jj	2011-06-28 19:09:09.936421970 +0200
+++ gcc/common.opt	2011-07-12 21:17:13.809402161 +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-12 21:15:46.987389471 +0200
+++ gcc/dwarf2out.c	2011-07-13 01:18:21.864451800 +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;
@@ -18110,6 +18111,10 @@ gen_ptr_to_mbr_type_die (tree type, dw_d
 
 /* Generate the DIE for the compilation unit.  */
 
+typedef const char *dchar_p; /* For DEF_VEC_P.  */
+DEF_VEC_P(dchar_p);
+DEF_VEC_ALLOC_P(dchar_p,heap);
+
 static dw_die_ref
 gen_compile_unit_die (const char *filename)
 {
@@ -18130,18 +18135,104 @@ gen_compile_unit_die (const char *filena
 
   sprintf (producer, "%s %s", language_string, version_string);
 
+  if (dwarf_record_gcc_switches)
+    {
+      size_t j;
+      VEC(dchar_p, heap) *switches = NULL;
+      char *producer_and_switches, *tail;
+      const char *p;
+      size_t len = 0, plen = strlen (producer);
+      for (j = 1; 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_:
+	    /* Ignore these.  */
+	    continue;
+	  default:
+	    if (save_decoded_options[j].orig_option_with_args_text[0] != '-')
+	      continue;
+	    switch (save_decoded_options[j].orig_option_with_args_text[1])
+	      {
+	      case 'M':
+	      case 'i':
+	      case 'W':
+		continue;
+	      case 'n':
+		if (save_decoded_options[j].orig_option_with_args_text[2]
+		    == 'o')
+		  continue;
+		break;
+	      case 'f':
+		if (strncmp (save_decoded_options[j].orig_option_with_args_text
+			     + 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;
+	  }
+
+      len += plen + 1;
+      producer_and_switches = XALLOCAVEC (char, len + 1);
+      tail = producer_and_switches;
+      memcpy (tail, producer, plen);
+      tail += plen;
+      FOR_EACH_VEC_ELT (dchar_p, switches, j, p)
+	{
+	  len = strlen (p);
+	  *tail = ' ';
+	  memcpy (tail + 1, p, len);
+	  tail += len + 1;
+	}
+      *tail = '\0';
+      add_AT_string (die, DW_AT_producer, producer_and_switches);
+      VEC_free (dchar_p, heap, switches);
+    }
+  else
+    {
 #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");
+      /* 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);
+      add_AT_string (die, DW_AT_producer, producer);
+    }
 
   /* If our producer is LTO try to figure out a common language to use
      from the global list of translation units.  */
--- gcc/Makefile.in.jj	2011-07-11 18:34:37.297452455 +0200
+++ gcc/Makefile.in	2011-07-12 21:16:34.594796181 +0200
@@ -2968,7 +2968,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/testsuite/lib/dg-pch.exp.jj	2011-01-03 18:58:03.000000000 +0100
+++ gcc/testsuite/lib/dg-pch.exp	2011-07-12 23:13:50.943670171 +0200
@@ -39,7 +39,7 @@ proc dg-flags-pch { subdir test otherfla
 	set dg-do-what-default precompile
 	catch { file_on_host delete "$bname$suffix" }
 	gcc_copy_files "[file rootname $test]${suffix}s" "$bname$suffix"
-	dg-test -keep-output "./$bname$suffix" "$otherflags $flags" ""
+	dg-test -keep-output "./$bname$suffix" "-gno-record-gcc-switches $otherflags $flags" ""
 
 	# For the rest, the default is to compile to .s.
 	set dg-do-what-default compile
@@ -50,14 +50,14 @@ proc dg-flags-pch { subdir test otherfla
 	    # Ensure that the PCH file is used, not the original header.
 	    file_on_host delete "$bname$suffix"
 
-	    dg-test -keep-output $test "$otherflags $flags -I." ""
+	    dg-test -keep-output $test "-gno-record-gcc-switches $otherflags $flags -I." ""
 	    file_on_host delete "$bname$suffix.gch"
 	    if { !$have_errs } {
 		if { [ file_on_host exists "$bname.s" ] } {
 		    remote_upload host "$bname.s" "$bname.s-gch"
 		    remote_download host "$bname.s-gch"
 		    gcc_copy_files "[file rootname $test]${suffix}s" "$bname$suffix"
-		    dg-test -keep-output $test "$otherflags $flags -I." ""
+		    dg-test -keep-output $test "-gno-record-gcc-switches $otherflags $flags -I." ""
 		    remote_upload host "$bname.s"
 		    set tmp [ diff "$bname.s" "$bname.s-gch" ]
 		    if { $tmp == 0 } {

	Jakub

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-07-22 19:56 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-13  0:17 [RFC PATCH] -grecord-gcc-switches (PR other/32998) Jakub Jelinek
2011-07-13 14:04 ` Jason Merrill
2011-07-13 14:34   ` Jakub Jelinek
2011-07-13 14:35     ` Jason Merrill
2011-07-14  9:48       ` Jakub Jelinek
2011-07-14 16:31         ` Jason Merrill
2011-07-14 16:32           ` Jakub Jelinek
2011-07-14 16:40             ` Jason Merrill
2011-07-21 20:22 ` Joseph S. Myers
2011-07-21 20:50   ` Jakub Jelinek
2011-07-21 21:01     ` Joseph S. Myers
2011-07-22 13:27       ` [PATCH] -grecord-gcc-switches (PR other/32998, take 2) Jakub Jelinek
2011-07-22 14:06         ` Joseph S. Myers
2011-07-22 14:11           ` [PATCH] -grecord-gcc-switches (PR other/32998, take 3) Jakub Jelinek
2011-07-22 20:43             ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).