aboutsummaryrefslogtreecommitdiff
path: root/gcc/opts.c
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2020-11-23 13:40:04 +0100
committerMartin Liska <mliska@suse.cz>2020-12-04 10:13:51 +0100
commit7caa49706316e650fb67719e1a1bf3a35054b685 (patch)
treebfe3d80eb7261ea7781761b41c645f4951d47e1b /gcc/opts.c
parent241a2c498005207d52a3d64884e41953fc00275c (diff)
downloadgcc-7caa49706316e650fb67719e1a1bf3a35054b685.zip
gcc-7caa49706316e650fb67719e1a1bf3a35054b685.tar.gz
gcc-7caa49706316e650fb67719e1a1bf3a35054b685.tar.bz2
Refactor -frecord-gcc-switches.
gcc/ChangeLog: * doc/tm.texi: Change argument of the record_gcc_switches hook and remove SWITCH_TYPE_* enum values. * dwarf2out.c (gen_producer_string): Move to opts.c and remove handling of the dwarf_record_gcc_switches option. (dwarf2out_early_finish): Use moved gen_producer_string function. * opts.c (gen_producer_string): New. * opts.h (gen_producer_string): New. * target.def: Change type of record_gcc_switches. * target.h (enum print_switch_type): Remove. (elf_record_gcc_switches): Change first argument. * toplev.c (MAX_LINE): Remove. (print_to_asm_out_file): Likewise. (print_to_stderr): Likewise. (print_single_switch): Likewise. (print_switch_values): Likewise. (init_asm_output): Use new gen_producer_string function. (process_options): Likewise. * varasm.c (elf_record_gcc_switches): Just save the string argument to the ELF container.
Diffstat (limited to 'gcc/opts.c')
-rw-r--r--gcc/opts.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/gcc/opts.c b/gcc/opts.c
index cc1d0cc..3db08b3 100644
--- a/gcc/opts.c
+++ b/gcc/opts.c
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3. If not see
#include "spellcheck.h"
#include "opt-suggestions.h"
#include "diagnostic-color.h"
+#include "version.h"
#include "selftest.h"
static void set_Wstrict_aliasing (struct gcc_options *opts, int onoff);
@@ -3266,6 +3267,124 @@ get_option_url (diagnostic_context *, int option_index)
return NULL;
}
+/* Return a heap allocated producer with command line options. */
+
+char *
+gen_command_line_string (cl_decoded_option *options,
+ unsigned int options_count)
+{
+ auto_vec<const char *> switches;
+ char *options_string, *tail;
+ const char *p;
+ size_t len = 0;
+
+ for (unsigned i = 0; i < options_count; i++)
+ switch (options[i].opt_index)
+ {
+ case OPT_o:
+ case OPT_d:
+ case OPT_dumpbase:
+ case OPT_dumpdir:
+ 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_warn_removed:
+ case OPT_SPECIAL_program_name:
+ case OPT_SPECIAL_input_file:
+ case OPT_grecord_gcc_switches:
+ case OPT_frecord_gcc_switches:
+ case OPT__output_pch_:
+ case OPT_fdiagnostics_show_location_:
+ case OPT_fdiagnostics_show_option:
+ case OPT_fdiagnostics_show_caret:
+ case OPT_fdiagnostics_show_labels:
+ case OPT_fdiagnostics_show_line_numbers:
+ case OPT_fdiagnostics_color_:
+ case OPT_fdiagnostics_format_:
+ case OPT_fverbose_asm:
+ case OPT____:
+ case OPT__sysroot_:
+ case OPT_nostdinc:
+ case OPT_nostdinc__:
+ case OPT_fpreprocessed:
+ case OPT_fltrans_output_list_:
+ case OPT_fresolution_:
+ case OPT_fdebug_prefix_map_:
+ case OPT_fmacro_prefix_map_:
+ case OPT_ffile_prefix_map_:
+ case OPT_fcompare_debug:
+ case OPT_fchecking:
+ case OPT_fchecking_:
+ /* Ignore these. */
+ continue;
+ case OPT_flto_:
+ {
+ const char *lto_canonical = "-flto";
+ switches.safe_push (lto_canonical);
+ len += strlen (lto_canonical) + 1;
+ break;
+ }
+ default:
+ if (cl_options[options[i].opt_index].flags
+ & CL_NO_DWARF_RECORD)
+ continue;
+ gcc_checking_assert (options[i].canonical_option[0][0] == '-');
+ switch (options[i].canonical_option[0][1])
+ {
+ case 'M':
+ case 'i':
+ case 'W':
+ continue;
+ case 'f':
+ if (strncmp (options[i].canonical_option[0] + 2,
+ "dump", 4) == 0)
+ continue;
+ break;
+ default:
+ break;
+ }
+ switches.safe_push (options[i].orig_option_with_args_text);
+ len += strlen (options[i].orig_option_with_args_text) + 1;
+ break;
+ }
+
+ options_string = XNEWVEC (char, len + 1);
+ tail = options_string;
+
+ unsigned i;
+ FOR_EACH_VEC_ELT (switches, i, p)
+ {
+ len = strlen (p);
+ memcpy (tail, p, len);
+ tail += len;
+ if (i != switches.length () - 1)
+ {
+ *tail = ' ';
+ ++tail;
+ }
+ }
+
+ *tail = '\0';
+ return options_string;
+}
+
+/* Return a heap allocated producer string including command line options. */
+
+char *
+gen_producer_string (const char *language_string, cl_decoded_option *options,
+ unsigned int options_count)
+{
+ return concat (language_string, " ", version_string, " ",
+ gen_command_line_string (options, options_count), NULL);
+}
+
#if CHECKING_P
namespace selftest {