This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: RFC: PR lto/41564: -fdump-tree-all for lto does not work as expected
On Sat, Jan 2, 2010 at 12:03 PM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Sat, Jan 2, 2010 at 8:06 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>> On Sat, Jan 2, 2010 at 10:47 AM, Richard Guenther
>> <richard.guenther@gmail.com> wrote:
>>> On Sat, Jan 2, 2010 at 7:17 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> On Sat, Jan 2, 2010 at 10:05 AM, H.J. Lu <hjl.tools@gmail.com> wrote:
>>>>> On Sat, Jan 2, 2010 at 9:18 AM, Richard Guenther
>>>>> <richard.guenther@gmail.com> wrote:
>>>>>> On Sat, Jan 2, 2010 at 6:05 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> When -fdump-tree-all is used with lto, the dump files are generated in
>>>>>>> /tmp instead of the directory containing the output. The problem is
>>>>>>> lto-wrapper translates
>>>>>>>
>>>>>>> /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 -o gcc-dg-lto-20081222-31 -fdump-tree-all -v -mtune=generic c_lto_20081222_0.o c_lto_20081222_1.o
>>>>>>>
>>>>>>> to
>>>>>>>
>>>>>>> /export/build/gnu/gcc/build-x86_64-linux/gcc/xgcc -combine -x lto -c -o /tmp/cclzoEg3.lto.o -B/export/build/gnu/gcc/build-x86_64-linux/gcc/ -O2 --fdump-tree-all -mtune=generic c_lto_20081222_0.o c_lto_20081222_1.o
>>>>>>>
>>>>>>> There is no good way to tell which directory should be used for dump.
>>>>>>> This patch adds -dumpdir. lto-wrapper uses it to tell lto1 to dump
>>>>>>> files in the output directory.
>>>>>>>
>>>>>>> Any comments?
>>>>>>
>>>>>> What -dumpbase will lto1 use if compile and link step are combined?
>>>>>> Otherwise I think it's the right thing to do to dump where regular dump
>>>>>> files would be.
>>>>>
>>>>> The gcc driver uses the first input .o file for -dumpbase, which is
>>>>> some random generated out file. Maybe we should use the LTO
>>>>> output name for -dumpbase.
>>>>
>>>>
>>>> This patch on top of my previous patch does it. It will make
>>>> dumpbase consistent no matter how lto1 is used. Should I
>>>> incorporate it into my patch for PR 41564?
>>>
>>> I get
>>>
>>> $ ./xgcc -B. -c t1.c t2.c -flto -O -fdump-tree-optimized
>>> $ ./xgcc -B. -o t t1.o t2.o -flto -O -fdump-tree-optimized
>>> collect2: lto-wrapper terminated with signal 11 [Segmentation fault]
>>>
>>> same with
>>>
>>> $ ./xgcc -B. -o t t1.o t2.o -flto -O -fdump-tree-optimized
>>> collect2: lto-wrapper terminated with signal 11 [Segmentation fault]
>>>
>>> but yes, I think it should be combined into the fix for PR41564.
>>> I wanted to test what happens with -fwhopr as well (well, it segfaults
>>> like above).
>>>
>>
>> This patch should fix it.
>
> Thanks. ?And indeed with -fwhopr we now get
>
> $ ./xgcc -B. -o t t1.c t2.c -fwhopr -O -fdump-tree-optimized -v
> ...
> ?./lto1 -quiet -dumpbase ccNyDgHp.wpa.o -dumpbase t -dumpdir ./
> -mtune=generic -auxbase-strip /tmp/ccNyDgHp.wpa.ltrans.o -O -version
> -fdump-tree-optimized -fltrans /tmp/ccNyDgHp.wpa.o -o /tmp/ccIN6FT8.s
> ...
> ./lto1 -quiet -dumpbase ccif3J9z.wpa.o -dumpbase t -dumpdir ./
> -mtune=generic -auxbase-strip /tmp/ccif3J9z.wpa.ltrans.o -O -version
> -fdump-tree-optimized -fltrans /tmp/ccif3J9z.wpa.o -o /tmp/ccS2qVN9.s
>
> thus the dump-file of the first ltrans file gets overwritten by the second one.
> For ltrans we should append a sequence number to the -dumpbase, like
> t.ltrans0, t.ltrans1, etc. - also drop the redundant -dumpbase (that is also
> present in the -flto case).
Here is the updated patch to remove the redundant -dumpbase. However,
I didn't try to handle dumpbase for WHOPR mode. I only pass -dumpbase
to gcc in LTO mode.. I would prefer to address LTO mode first and open
a new bug for dumpbase in WHOPR mode.
Thanks.
--
H.J.
2010-01-02 H.J. Lu <hongjiu.lu@intel.com>
PR lto/41564
* common.opt: Add dumpdir.
* gcc.c (cc1_options): Add "-dumpbase %B" only if -dumpbase
isn't specified.
(option_map): Add --dumpdir.
* gcc.h (DEFAULT_WORD_SWITCH_TAKES_ARG): Add dumpdir.
* lto-wrapper.c (run_gcc): Add -dumpbase and -dumpdir for -o.
* opts.c (decode_options): Try dump_dir_name first if
dump_base_name isn't an absolute path.
(common_handle_option): Handle OPT_dumpdir.
* toplev.c (dump_dir_name): New.
(print_switch_values): Also ignore -dumpdir.
* toplev.h (dump_dir_name): New.
diff --git a/gcc/common.opt b/gcc/common.opt
index 77967f8..e5a2823 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -253,6 +253,10 @@ dumpbase
Common Separate
-dumpbase <file> Set the file basename to be used for dumps
+dumpdir
+Common Separate
+-dumpdir <dir> Set the directory name to be used for dumps
+
; The version of the C++ ABI in use. The following values are allowed:
;
; 0: The version of the ABI believed most conformant with the C++ ABI
diff --git a/gcc/gcc.c b/gcc/gcc.c
index ad69de7..d76e63a 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -891,7 +891,7 @@ static const char *cpp_debug_options = "%{d*}";
/* NB: This is shared amongst all front-ends, except for Ada. */
static const char *cc1_options =
"%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
- %1 %{!Q:-quiet} -dumpbase %B %{d*} %{m*} %{a*}\
+ %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{a*}\
%{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} \
%{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} \
%{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\
@@ -1188,6 +1188,7 @@ static const struct option_map option_map[] =
{"--dependencies", "-M", 0},
{"--dump", "-d", "a"},
{"--dumpbase", "-dumpbase", "a"},
+ {"--dumpdir", "-dumpdir", "a"},
{"--encoding", "-fencoding=", "aj"},
{"--entry", "-e", 0},
{"--extra-warnings", "-W", 0},
diff --git a/gcc/gcc.h b/gcc/gcc.h
index 560c7f9..5bbf583 100644
--- a/gcc/gcc.h
+++ b/gcc/gcc.h
@@ -52,7 +52,8 @@ struct spec_function
|| !strcmp (STR, "isysroot") \
|| !strcmp (STR, "-param") || !strcmp (STR, "specs") \
|| !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ") \
- || !strcmp (STR, "fintrinsic-modules-path") || !strcmp (STR, "dumpbase"))
+ || !strcmp (STR, "fintrinsic-modules-path") \
+ || !strcmp (STR, "dumpbase") || !strcmp (STR, "dumpdir"))
/* These are exported by gcc.c. */
diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
index 5f24f59..7736fbe 100644
--- a/gcc/lto-wrapper.c
+++ b/gcc/lto-wrapper.c
@@ -258,7 +258,7 @@ run_gcc (unsigned argc, char *argv[])
const char **argv_ptr;
char *list_option_full = NULL;
- new_argc += 8;
+ new_argc += 12;
new_argv = (const char **) xcalloc (sizeof (char *), new_argc);
argv_ptr = new_argv;
@@ -316,7 +316,36 @@ run_gcc (unsigned argc, char *argv[])
temporary file for the LTO output. The `-o' option
will be interpreted by the linker. */
if (s[2] == '\0')
- i++;
+ {
+ char *output_dir, *base, *name;
+
+ i++;
+ output_dir = xstrdup (argv[i]);
+ base = output_dir;
+ for (name = base; *name; name++)
+ if (IS_DIR_SEPARATOR (*name))
+ base = name + 1;
+ *base = '\0';
+
+ if (*output_dir == '\0')
+ {
+ static char current_dir[] =
+ { '.', DIR_SEPARATOR, '\0' };
+ output_dir = current_dir;
+ base = argv[i];
+ }
+ else
+ base = &argv[i][base - output_dir];
+
+ if (lto_mode == LTO_MODE_LTO)
+ {
+ *argv_ptr++ = "-dumpbase";
+ *argv_ptr++ = base;
+ }
+
+ *argv_ptr++ = "-dumpdir";
+ *argv_ptr++ = output_dir;
+ }
}
else
/* Pass the option or argument to LTO. */
diff --git a/gcc/opts.c b/gcc/opts.c
index 5407527..fc997a0 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -971,24 +971,31 @@ decode_options (unsigned int argc, const char **argv)
handle_options (argc, argv, lang_mask);
- /* Make DUMP_BASE_NAME relative to the AUX_BASE_NAME directory,
- typically the directory to contain the object file. */
- if (aux_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
+ if (dump_base_name && ! IS_ABSOLUTE_PATH (dump_base_name))
{
- const char *aux_base;
-
- base_of_path (aux_base_name, &aux_base);
- if (aux_base_name != aux_base)
+ /* First try to make DUMP_BASE_NAME relative to the DUMP_DIR_NAME
+ directory. Then try to make DUMP_BASE_NAME relative to the
+ AUX_BASE_NAME directory, typically the directory to contain
+ the object file. */
+ if (dump_dir_name)
+ dump_base_name = concat (dump_dir_name, dump_base_name, NULL);
+ else if (aux_base_name)
{
- int dir_len = aux_base - aux_base_name;
- char *new_dump_base_name =
- XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
-
- /* Copy directory component from AUX_BASE_NAME. */
- memcpy (new_dump_base_name, aux_base_name, dir_len);
- /* Append existing DUMP_BASE_NAME. */
- strcpy (new_dump_base_name + dir_len, dump_base_name);
- dump_base_name = new_dump_base_name;
+ const char *aux_base;
+
+ base_of_path (aux_base_name, &aux_base);
+ if (aux_base_name != aux_base)
+ {
+ int dir_len = aux_base - aux_base_name;
+ char *new_dump_base_name =
+ XNEWVEC (char, strlen(dump_base_name) + dir_len + 1);
+
+ /* Copy directory component from AUX_BASE_NAME. */
+ memcpy (new_dump_base_name, aux_base_name, dir_len);
+ /* Append existing DUMP_BASE_NAME. */
+ strcpy (new_dump_base_name + dir_len, dump_base_name);
+ dump_base_name = new_dump_base_name;
+ }
}
}
@@ -1701,6 +1708,10 @@ common_handle_option (size_t scode, const char *arg, int value,
dump_base_name = arg;
break;
+ case OPT_dumpdir:
+ dump_dir_name = arg;
+ break;
+
case OPT_falign_functions_:
align_functions = value;
break;
diff --git a/gcc/toplev.c b/gcc/toplev.c
index e916c8d..224b288 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -152,6 +152,10 @@ struct line_maps *line_table;
const char *dump_base_name;
+/* Directory used for dump output files. */
+
+const char *dump_dir_name;
+
/* Name to use as a base for auxiliary output files. */
const char *aux_base_name;
@@ -1388,6 +1392,7 @@ print_switch_values (print_switch_fn_type print_fn)
/* Ignore these. */
if (strcmp (*p, "-o") == 0
|| strcmp (*p, "-dumpbase") == 0
+ || strcmp (*p, "-dumpdir") == 0
|| strcmp (*p, "-auxbase") == 0)
{
if (p[1] != NULL)
diff --git a/gcc/toplev.h b/gcc/toplev.h
index 53f981c..2c7b036 100644
--- a/gcc/toplev.h
+++ b/gcc/toplev.h
@@ -116,6 +116,7 @@ extern unsigned local_tick;
extern const char *progname;
extern const char *dump_base_name;
+extern const char *dump_dir_name;
extern const char *aux_base_name;
extern const char *aux_info_file_name;
extern const char *profile_data_prefix;