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 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.
> At least this is a prerequesite to add scan-lto-dump and cleanup-lto-dump
> support to lto.exp.
>
I updated the patch to check NULL dump_base_name, which can happen
with "gcc -E" as well as make it C++ compatible.
Thanks.
--
H.J.
2010-01-02 H.J. Lu <hongjiu.lu@intel.com>
PR lto/41564
* common.opt: Add dumpdir.
* gcc.c (option_map): Add --dumpdir.
* gcc.h (DEFAULT_WORD_SWITCH_TAKES_ARG): Add dumpdir.
* lto-wrapper.c (run_gcc): Add -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..1c79a79 100644
--- a/gcc/gcc.c
+++ b/gcc/gcc.c
@@ -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..97cd368 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 += 10;
new_argv = (const char **) xcalloc (sizeof (char *), new_argc);
argv_ptr = new_argv;
@@ -316,7 +316,27 @@ 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;
+ }
+
+ *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;