diff mbox series

-fdump-tree, -save-temps=obj & subdirs

Message ID 5390131e-c9ed-15f4-7faa-1a0e3a2f15ff@acm.org
State New
Headers show
Series -fdump-tree, -save-temps=obj & subdirs | expand

Commit Message

Nathan Sidwell Dec. 7, 2017, 12:10 p.m. UTC
There's an unfortunate interaction between -save-temps=obj and 
-fdump-tree-<whatever> when subdirectories are in play.

Consider:
   g++ -fdump-tree-all -save-temps=obj -c -o tgt/x.o sub/x.cc
we end up with a bunch of errors of the form:
  sub/x.cc:1:0: error: could not open dump file 
‘tgt/tgt/x.046t.profile_estimate’: No such file or directory

you'll see it's added the 'tgt' sub directory twice.  The reason is that 
cc1plus is invoked as:

  /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v 
-D_GNU_SOURCE sub/x.cc -mtune=generic -march=x86-64 -ansi 
-Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings 
-felide-constructors -fdump-tree-all -fpch-preprocess -o tgt/x.ii

to generate the preprocessed output, and then as:

  /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -fpreprocessed tgt/x.ii 
-quiet -dumpbase tgt/x -mtune=generic -march=x86-64 -auxbase-strip 
tgt/x.o -Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings -ansi 
-version -felide-constructors -fdump-tree-all -o tgt/x.s

for the compilation itself.  That has '-dumpbase tgt/x' and 
'-auxbase-strip tgt/x.o' passed in.

The options processing checks if dump-base is absolute, and if not 
prefixes dump_dir_name or aux_base_name's directory components.

It seems to me that the absolute path check is incomplete.  We should 
check if dump-base has /any/ directory components.  If it does, we 
shouldn't touch it.  That's what this patch does:

1) remove the absolute dir check.  That's subsumed into ...
2) look for any DIR_SEPARATOR in the dump-base.  If so, no prefixing
3 & 4) existing prefix code
5) always set dump_base_name_prefixed, so we don't repeat #2 on a 
subsequent invocation.

With this patch we now get a successful compilation:

nathans@lyta:7>egcs/trunk/obj/x86_64/gcc/xg++ -B 
egcs/trunk/obj/x86_64/gcc/ -fdump-tree-all -save-temps=obj -c -o tgt/x.o 
sub/x.cc
nathans@lyta:8>ls tgt
total 100
4 x.003t.original  4 x.010t.eh			  4 x.020t.ssa		     4 
x.049t.release_ssa	4 x.220t.switchlower  4 x.o
4 x.004t.gimple    4 x.011t.cfg			  4 x.027t.fixup_cfg3	     4 
x.050t.local-fnsummary2	4 x.226t.resx	      4 x.s
4 x.006t.omplower  4 x.012t.ompexp		  4 x.028t.local-fnsummary1  4 
x.087t.fixup_cfg4	4 x.228t.optimized
4 x.007t.lower	   4 x.013t.printf-return-value1  4 x.029t.einline	     4 
x.218t.veclower		0 x.313t.statistics
4 x.009t.ehopt	   4 x.019t.fixup_cfg1		  0 x.046t.profile_estimate  4 
x.219t.cplxlower0	4 x.ii

ok?

nathan

Comments

Jeff Law Dec. 19, 2017, 4:28 a.m. UTC | #1
On 12/07/2017 05:10 AM, Nathan Sidwell wrote:
> There's an unfortunate interaction between -save-temps=obj and
> -fdump-tree-<whatever> when subdirectories are in play.
> 
> Consider:
>   g++ -fdump-tree-all -save-temps=obj -c -o tgt/x.o sub/x.cc
> we end up with a bunch of errors of the form:
>  sub/x.cc:1:0: error: could not open dump file
> ‘tgt/tgt/x.046t.profile_estimate’: No such file or directory
> 
> you'll see it's added the 'tgt' sub directory twice.  The reason is that
> cc1plus is invoked as:
> 
>  /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v
> -D_GNU_SOURCE sub/x.cc -mtune=generic -march=x86-64 -ansi
> -Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings
> -felide-constructors -fdump-tree-all -fpch-preprocess -o tgt/x.ii
> 
> to generate the preprocessed output, and then as:
> 
>  /usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -fpreprocessed tgt/x.ii
> -quiet -dumpbase tgt/x -mtune=generic -march=x86-64 -auxbase-strip
> tgt/x.o -Woverloaded-virtual -Wall -Wpointer-arith -Wwrite-strings -ansi
> -version -felide-constructors -fdump-tree-all -o tgt/x.s
> 
> for the compilation itself.  That has '-dumpbase tgt/x' and
> '-auxbase-strip tgt/x.o' passed in.
> 
> The options processing checks if dump-base is absolute, and if not
> prefixes dump_dir_name or aux_base_name's directory components.
> 
> It seems to me that the absolute path check is incomplete.  We should
> check if dump-base has /any/ directory components.  If it does, we
> shouldn't touch it.  That's what this patch does:
> 
> 1) remove the absolute dir check.  That's subsumed into ...
> 2) look for any DIR_SEPARATOR in the dump-base.  If so, no prefixing
> 3 & 4) existing prefix code
> 5) always set dump_base_name_prefixed, so we don't repeat #2 on a
> subsequent invocation.
> 
> With this patch we now get a successful compilation:
> 
> nathans@lyta:7>egcs/trunk/obj/x86_64/gcc/xg++ -B
> egcs/trunk/obj/x86_64/gcc/ -fdump-tree-all -save-temps=obj -c -o tgt/x.o
> sub/x.cc
> nathans@lyta:8>ls tgt
> total 100
> 4 x.003t.original  4 x.010t.eh              4 x.020t.ssa             4
> x.049t.release_ssa    4 x.220t.switchlower  4 x.o
> 4 x.004t.gimple    4 x.011t.cfg              4 x.027t.fixup_cfg3        
> 4 x.050t.local-fnsummary2    4 x.226t.resx          4 x.s
> 4 x.006t.omplower  4 x.012t.ompexp          4 x.028t.local-fnsummary1  4
> x.087t.fixup_cfg4    4 x.228t.optimized
> 4 x.007t.lower       4 x.013t.printf-return-value1  4
> x.029t.einline         4 x.218t.veclower        0 x.313t.statistics
> 4 x.009t.ehopt       4 x.019t.fixup_cfg1          0
> x.046t.profile_estimate  4 x.219t.cplxlower0    4 x.ii
> 
> ok?
> 
> nathan
> -- 
> Nathan Sidwell
> 
> pfx.diff
> 
> 
> 2017-12-06  Nathan Sidwell  <nathan@acm.org>
> 
> 	* opts.c (finish_options): Don't prefix dump_base_name if it
> 	already contains directories.
OK.
jeff
diff mbox series

Patch

2017-12-06  Nathan Sidwell  <nathan@acm.org>

	* opts.c (finish_options): Don't prefix dump_base_name if it
	already contains directories.

Index: gcc/opts.c
===================================================================
--- gcc/opts.c	(revision 255442)
+++ gcc/opts.c	(working copy)
@@ -698,19 +698,27 @@  finish_options (struct gcc_options *opts
   enum unwind_info_type ui_except;
 
   if (opts->x_dump_base_name
-      && ! IS_ABSOLUTE_PATH (opts->x_dump_base_name)
       && ! opts->x_dump_base_name_prefixed)
     {
-      /* First try to make OPTS->X_DUMP_BASE_NAME relative to the
-	 OPTS->X_DUMP_DIR_NAME directory.  Then try to make
-	 OPTS->X_DUMP_BASE_NAME relative to the OPTS->X_AUX_BASE_NAME
-	 directory, typically the directory to contain the object
-	 file.  */
-      if (opts->x_dump_dir_name)
+      const char *sep = opts->x_dump_base_name;
+
+      for (; *sep; sep++)
+	if (IS_DIR_SEPARATOR (*sep))
+	  break;
+
+      if (*sep)
+	/* If dump_base_path contains subdirectories, don't prepend
+	   anything.  */;
+      else if (opts->x_dump_dir_name)
+	/* We have a DUMP_DIR_NAME, prepend that.  */
 	opts->x_dump_base_name = opts_concat (opts->x_dump_dir_name,
 					      opts->x_dump_base_name, NULL);
       else if (opts->x_aux_base_name
 	       && strcmp (opts->x_aux_base_name, HOST_BIT_BUCKET) != 0)
+	/* AUX_BASE_NAME is set and is not the bit bucket.  If it
+	   contains a directory component, prepend those directories.
+	   Typically this places things in the same directory as the
+	   object file.  */
 	{
 	  const char *aux_base;
 
@@ -729,7 +737,9 @@  finish_options (struct gcc_options *opts
 	      opts->x_dump_base_name = new_dump_base_name;
 	    }
 	}
-	opts->x_dump_base_name_prefixed = true;
+
+      /* It is definitely prefixed now.  */
+      opts->x_dump_base_name_prefixed = true;
     }
 
   /* Handle related options for unit-at-a-time, toplevel-reorder, and