path: root/lto-plugin
diff options
authorAlexandre Oliva <>2020-05-26 04:30:15 -0300
committerAlexandre Oliva <>2020-05-26 04:30:15 -0300
commit1dedc12d186a110854537e1279b4e6c29f2df35a (patch)
treeb7d3f5e261169b8780d70b5a4c606258a81868f2 /lto-plugin
parentAllow ChangeLog entries for ignored location. (diff)
revamp dump and aux output names
This patch simplifies (!!!) the logic governing the naming of dump files and auxiliary output files in the driver, in the compiler, and in the LTO wrapper. No changes are made to the naming of primary outputs, there are often ways to restore past behavior, and a number of inconsistencies are fixed. Some internal options are removed (-auxbase and -auxbase-strip), sensible existing uses of -dumpdir and -dumpbase options remain unchanged, additional useful cases are added, making for what is still admittedly quite complex. Extensive documentation and testcases provide numerous examples, from normal to corner cases. The most visible changes are: - aux and dump files now always go in the same directory, that defaults to the directory of the primary output, but that can be overridden with -dumpdir, -save-temps=*, or, preserving past behavior, with a -dumpbase with a directory component. - driver and compiler now have the same notion of naming of auxiliary outputs, e.g. .dwo files will no longer be in one location while the debug info suggests they are elsewhere, and -save-temps and .dwo auxiliary outputs now go in the same location as .su, .ci and coverage data, with consistent naming. - explicitly-specified primary output names guide not only the location of aux and dump outputs: the output base name is also used in their base name, as a prefix when also linking (e.g. foo.c bar.c -o foobar creates foobar-foo.dwo and foobar-bar.dwo with -gsplit-dwarf), or as the base name instead of the input name (foo.c -c -o whatever.o creates rather than with -fstack-usage). The preference for the input file base name, quite useful for our testsuite, can be restored with -dumpbase "". When compiling and linking tests in the testsuite with additional inputs, we now use this flag. Files named in dejagnu board ldflags, libs, and ldscripts are now quoted in the gcc testsuite with -Wl, so that they are not counted as additional inputs by the compiler driver. - naming a -dumpbase when compiling multiple sources used to cause dumps from later compiles to overwrite those of earlier ones; it is now used as a prefix when compiling multiple sources, like an executable name above. - the dumpbase, explicitly specified or computed from output or input names, now also governs the naming of aux outputs; since aux outputs usually replaced the suffix from the input name, while dump outputs append their own additional suffixes, a -dumpbase-ext option is introduced to enable a chosen suffix to be dropped from dumpbase to form aux output names. - LTO dump and aux outputs were quite a mess, sometimes leaking temporary output names into -save-temps output names, sometimes conversely generating desirable aux outputs in temporary locations. They now obey the same logic of compiler aux and dump outputs, landing in the expected location and taking the linker output name or an explicit dumpbase overrider into account. - Naming of -fdump-final-insns outputs now follows the dump file naming logic for the .gkd files, and the .gk dump files generated in the second -fcompare-debug compilation get the .gk inserted before the suffix that -dumpbase-ext drops in aux outputs. gcc/ChangeLog: * common.opt (aux_base_name): Define. (dumpbase, dumpdir): Mark as Driver options. (-dumpbase, -dumpdir): Likewise. (dumpbase-ext, -dumpbase-ext): New. (auxbase, auxbase-strip): Drop. * doc/invoke.texi (-dumpbase, -dumpbase-ext, -dumpdir): Document. (-o): Introduce the notion of primary output, mention it influences auxiliary and dump output names as well, add examples. (-save-temps): Adjust, move examples into -dump*. (-save-temps=cwd, -save-temps=obj): Likewise. (-fdump-final-insns): Adjust. * dwarf2out.c (gen_producer_string): Drop auxbase and auxbase_strip; add dumpbase_ext. * gcc.c (enum save_temps): Add SAVE_TEMPS_DUMP. (save_temps_prefix, save_temps_length): Drop. (save_temps_overrides_dumpdir): New. (dumpdir, dumpbase, dumpbase_ext): New. (dumpdir_length, dumpdir_trailing_dash_added): New. (outbase, outbase_length): New. (The Specs Language): Introduce %". Adjust %b and %B. (ASM_FINAL_SPEC): Use %b.dwo for an aux output name always. Precede object file with %w when it's the primary output. (cpp_debug_options): Do not pass on incoming -dumpdir, -dumpbase and -dumpbase-ext options; recompute them with %:dumps. (cc1_options): Drop auxbase with and without compare-debug; use cpp_debug_options instead of dumpbase. Mark asm output with %w when it's the primary output. (static_spec_functions): Drop %:compare-debug-auxbase-opt and %:replace-exception. Add %:dumps. (driver_handle_option): Implement -save-temps=*/-dumpdir mutual overriding logic. Save dumpdir, dumpbase and dumpbase-ext options. Do not save output_file in save_temps_prefix. (adds_single_suffix_p): New. (single_input_file_index): New. (process_command): Combine output dir, output base name, and dumpbase into dumpdir and outbase. (set_collect_gcc_options): Pass a possibly-adjusted -dumpdir. (do_spec_1): Optionally dumpdir instead of save_temps_prefix, and outbase instead of input_basename in %b, %B and in -save-temps aux files. Handle empty argument %". (driver::maybe_run_linker): Adjust dumpdir and auxbase. (compare_debug_dump_opt_spec_function): Adjust gkd dump file naming. Spec-quote the computed -fdump-final-insns file name. (debug_auxbase_opt): Drop. (compare_debug_self_opt_spec_function): Drop auxbase-strip computation. (compare_debug_auxbase_opt_spec_function): Drop. (not_actual_file_p): New. (replace_extension_spec_func): Drop. (dumps_spec_func): New. (convert_white_space): Split-out parts into... (quote_string, whitespace_to_convert_p): ... these. New. (quote_spec_char_p, quote_spec, quote_spec_arg): New. (driver::finalize): Release and reset new variables; drop removed ones. * lto-wrapper.c (HAVE_TARGET_EXECUTABLE_SUFFIX): Define if... (TARGET_EXECUTABLE_SUFFIX): ... is defined; define this to the empty string otherwise. (DUMPBASE_SUFFIX): Drop leading period. (debug_objcopy): Use concat. (run_gcc): Recognize -save-temps=* as -save-temps too. Obey -dumpdir. Pass on empty dumpdir and dumpbase with a directory component. Simplify temp file names. * opts.c (finish_options): Drop aux base name handling. (common_handle_option): Drop auxbase-strip handling. * toplev.c (print_switch_values): Drop auxbase, add dumpbase-ext. (process_options): Derive aux_base_name from dump_base_name and dump_base_ext. (lang_dependent_init): Compute dump_base_ext along with dump_base_name. Disable stack usage and callgraph-info during lto generation and compare-debug recompilation. gcc/fortran/ChangeLog: * options.c (gfc_get_option_string): Drop auxbase, add dumpbase_ext. gcc/ada/ChangeLog: * gcc-interface/lang-specs.h: Drop auxbase and auxbase-strip. Use %:dumps instead of -dumpbase. Add %w for implicit .s primary output. * switch.adb (Is_Internal_GCC_Switch): Recognize dumpdir and dumpbase-ext. Drop auxbase and auxbase-strip. lto-plugin/ChangeLog: * lto-plugin.c (skip_in_suffix): New. (exec_lto_wrapper): Use skip_in_suffix and concat to build non-temporary output names. (onload): Look for -dumpdir in COLLECT_GCC_OPTIONS, and override link_output_name with it. contrib/ChangeLog: * compare-debug: Adjust for .gkd files named as dump files, with the source suffix rather than the object suffix. gcc/testsuite/ChangeLog: * gcc.misc-tests/outputs.exp: New. * gcc.misc-tests/outputs-0.c: New. * gcc.misc-tests/outputs-1.c: New. * gcc.misc-tests/outputs-2.c: New. * lib/gcc-defs.exp (gcc_adjusted_linker_flags): New. (gcc_adjust_linker_flags): New. (dg-additional-files-options): Call it. Pass -dumpbase "" when there are additional sources. * lib/profopt.exp (profopt-execute): Pass the executable suffix with -dumpbase-ext. * lib/scandump.exp (dump-base): Mention -dumpbase "" use. * lib/scanltranstree.exp: Adjust dump suffix expectation. * lib/scanwpaipa.exp: Likewise.
Diffstat (limited to 'lto-plugin')
1 files changed, 79 insertions, 8 deletions
diff --git a/lto-plugin/lto-plugin.c b/lto-plugin/lto-plugin.c
index 37f4bda742a..a65c2801b9b 100644
--- a/lto-plugin/lto-plugin.c
+++ b/lto-plugin/lto-plugin.c
@@ -203,6 +203,10 @@ static bool linker_output_known;
203static bool linker_output_auto_nolto_rel; 203static bool linker_output_auto_nolto_rel;
204static const char *link_output_name = NULL; 204static const char *link_output_name = NULL;
205 205
206/* This indicates link_output_name already contains the dot of the
207 suffix, so we can skip it in extensions. */
208static int skip_in_suffix = 0;
206/* The version of gold being used, or -1 if not gold. The number is 210/* The version of gold being used, or -1 if not gold. The number is
207 MAJOR * 100 + MINOR. */ 211 MAJOR * 100 + MINOR. */
208static int gold_version = -1; 212static int gold_version = -1;
@@ -621,14 +625,11 @@ exec_lto_wrapper (char *argv[])
621 /* Write argv to a file to avoid a command line that is too long 625 /* Write argv to a file to avoid a command line that is too long
622 Save the file locally on save-temps. */ 626 Save the file locally on save-temps. */
623 if (save_temps && link_output_name) 627 if (save_temps && link_output_name)
624 { 628 arguments_file_name = concat (link_output_name,
625 arguments_file_name = (char *) xmalloc (strlen (link_output_name) 629 ".lto_wrapper_args"
626 + sizeof (".lto_wrapper_args") + 1); 630 + skip_in_suffix, NULL);
627 strcpy (arguments_file_name, link_output_name);
628 strcat (arguments_file_name, ".lto_wrapper_args");
629 }
630 else 631 else
631 arguments_file_name = make_temp_file (".lto_wrapper_args"); 632 arguments_file_name = make_temp_file (".lto_wrapper_args");
632 check (arguments_file_name, LDPL_FATAL, 633 check (arguments_file_name, LDPL_FATAL,
633 "Failed to generate a temorary file name"); 634 "Failed to generate a temorary file name");
634 635
@@ -1439,12 +1440,82 @@ onload (struct ld_plugin_tv *tv)
1439 if (strstr (collect_gcc_options, "'-fno-use-linker-plugin'")) 1440 if (strstr (collect_gcc_options, "'-fno-use-linker-plugin'"))
1440 return LDPS_ERR; 1441 return LDPS_ERR;
1441 1442
1442 if ( strstr (collect_gcc_options, "'-save-temps'")) 1443 if (strstr (collect_gcc_options, "'-save-temps'"))
1443 save_temps = true; 1444 save_temps = true;
1444 1445
1445 if (strstr (collect_gcc_options, "'-v'") 1446 if (strstr (collect_gcc_options, "'-v'")
1446 || strstr (collect_gcc_options, "'--verbose'")) 1447 || strstr (collect_gcc_options, "'--verbose'"))
1447 verbose = true; 1448 verbose = true;
1450 const char *p;
1451 if ((p = strstr (collect_gcc_options, "'-dumpdir'")))
1452 {
1453 p += sizeof ("'-dumpdir'");
1454 while (*p == ' ')
1455 p++;
1456 const char *start = p;
1457 int ticks = 0, escapes = 0;
1458 /* Count ticks (') and escaped (\.) characters. Stop at the
1459 end of the options or at a blank after an even number of
1460 ticks (not counting escaped ones. */
1461 for (p = start; *p; p++)
1462 {
1463 if (*p == '\'')
1464 {
1465 ticks++;
1466 continue;
1467 }
1468 else if ((ticks % 2) != 0)
1469 {
1470 if (*p == ' ')
1471 break;
1472 if (*p == '\\')
1473 {
1474 if (*++p)
1475 escapes++;
1476 else
1477 p--;
1478 }
1479 }
1480 }
1482 /* Now allocate a new link_output_name and decode dumpdir
1483 into it. The loop uses the same logic, except it counts
1484 ticks and escapes backwards (so ticks is adjusted if we
1485 find an odd number of them), and it copies characters
1486 that are escaped or not otherwise skipped. */
1487 int len = p - start - ticks - escapes + 1;
1488 char *q = xmalloc (len);
1489 link_output_name = q;
1490 int oddticks = (ticks % 2);
1491 ticks += oddticks;
1492 for (p = start; *p; p++)
1493 {
1494 if (*p == '\'')
1495 {
1496 ticks--;
1497 continue;
1498 }
1499 else if ((ticks % 2) != 0)
1500 {
1501 if (*p == ' ')
1502 break;
1503 if (*p == '\\')
1504 {
1505 if (*++p)
1506 escapes--;
1507 else
1508 p--;
1509 }
1510 }
1511 *q++ = *p;
1512 }
1513 *q = '\0';
1514 assert (escapes == 0);
1515 assert (ticks == oddticks);
1516 assert (q - link_output_name == len - 1);
1517 skip_in_suffix = 1;
1518 }
1448 } 1519 }
1449 1520
1450 return LDPS_OK; 1521 return LDPS_OK;