comparison gcc/gcc.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children 351920fa3827
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 /* Compiler driver program that can handle many languages. 1 /* Compiler driver program that can handle many languages.
2 Copyright (C) 1987-2018 Free Software Foundation, Inc. 2 Copyright (C) 1987-2020 Free Software Foundation, Inc.
3 3
4 This file is part of GCC. 4 This file is part of GCC.
5 5
6 GCC is free software; you can redistribute it and/or modify it under 6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free 7 the terms of the GNU General Public License as published by the Free
39 #include "opt-suggestions.h" 39 #include "opt-suggestions.h"
40 #include "gcc.h" 40 #include "gcc.h"
41 #include "diagnostic.h" 41 #include "diagnostic.h"
42 #include "flags.h" 42 #include "flags.h"
43 #include "opts.h" 43 #include "opts.h"
44 #include "params.h"
45 #include "filenames.h" 44 #include "filenames.h"
46 #include "spellcheck.h" 45 #include "spellcheck.h"
47 46
48 47
49 48
55 env.getenv (); 54 env.getenv ();
56 and 55 and
57 getenv (); 56 getenv ();
58 Hence we need to use "get" for the accessor method, not "getenv". */ 57 Hence we need to use "get" for the accessor method, not "getenv". */
59 58
60 class env_manager 59 struct env_manager
61 { 60 {
62 public: 61 public:
63 void init (bool can_restore, bool debug); 62 void init (bool can_restore, bool debug);
64 const char *get (const char *name); 63 const char *get (const char *name);
65 void xput (const char *string); 64 void xput (const char *string);
406 static const char *compare_debug_auxbase_opt_spec_function (int, const char **); 405 static const char *compare_debug_auxbase_opt_spec_function (int, const char **);
407 static const char *pass_through_libs_spec_func (int, const char **); 406 static const char *pass_through_libs_spec_func (int, const char **);
408 static const char *replace_extension_spec_func (int, const char **); 407 static const char *replace_extension_spec_func (int, const char **);
409 static const char *greater_than_spec_func (int, const char **); 408 static const char *greater_than_spec_func (int, const char **);
410 static const char *debug_level_greater_than_spec_func (int, const char **); 409 static const char *debug_level_greater_than_spec_func (int, const char **);
410 static const char *find_fortran_preinclude_file (int, const char **);
411 static char *convert_white_space (char *); 411 static char *convert_white_space (char *);
412 412
413 /* The Specs Language 413 /* The Specs Language
414 414
415 Specs are strings containing lines, each of which (if not blank) 415 Specs are strings containing lines, each of which (if not blank)
1303 {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0}, 1303 {".f95", "#Fortran", 0, 0, 0}, {".F95", "#Fortran", 0, 0, 0},
1304 {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0}, 1304 {".f03", "#Fortran", 0, 0, 0}, {".F03", "#Fortran", 0, 0, 0},
1305 {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0}, 1305 {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0},
1306 {".r", "#Ratfor", 0, 0, 0}, 1306 {".r", "#Ratfor", 0, 0, 0},
1307 {".go", "#Go", 0, 1, 0}, 1307 {".go", "#Go", 0, 1, 0},
1308 {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0},
1308 /* Next come the entries for C. */ 1309 /* Next come the entries for C. */
1309 {".c", "@c", 0, 0, 1}, 1310 {".c", "@c", 0, 0, 1},
1310 {"@c", 1311 {"@c",
1311 /* cc1 has an integrated ISO C preprocessor. We should invoke the 1312 /* cc1 has an integrated ISO C preprocessor. We should invoke the
1312 external preprocessor if -save-temps is given. */ 1313 external preprocessor if -save-temps is given. */
1644 { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function }, 1645 { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function },
1645 { "pass-through-libs", pass_through_libs_spec_func }, 1646 { "pass-through-libs", pass_through_libs_spec_func },
1646 { "replace-extension", replace_extension_spec_func }, 1647 { "replace-extension", replace_extension_spec_func },
1647 { "gt", greater_than_spec_func }, 1648 { "gt", greater_than_spec_func },
1648 { "debug-level-gt", debug_level_greater_than_spec_func }, 1649 { "debug-level-gt", debug_level_greater_than_spec_func },
1650 { "fortran-preinclude-file", find_fortran_preinclude_file},
1649 #ifdef EXTRA_SPEC_FUNCTIONS 1651 #ifdef EXTRA_SPEC_FUNCTIONS
1650 EXTRA_SPEC_FUNCTIONS 1652 EXTRA_SPEC_FUNCTIONS
1651 #endif 1653 #endif
1652 { 0, 0 } 1654 { 0, 0 }
1653 }; 1655 };
2971 } 2973 }
2972 2974
2973 add_prefix (pprefix, prefix, component, priority, 2975 add_prefix (pprefix, prefix, component, priority,
2974 require_machine_suffix, os_multilib); 2976 require_machine_suffix, os_multilib);
2975 } 2977 }
2978
2979 /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */
2980
2981 static void
2982 add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix,
2983 const char *component,
2984 /* enum prefix_priority */ int priority,
2985 int require_machine_suffix, int os_multilib)
2986 {
2987 if (!IS_ABSOLUTE_PATH (prefix))
2988 fatal_error (input_location, "system path %qs is not absolute", prefix);
2989
2990 if (target_system_root)
2991 {
2992 char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root);
2993 size_t sysroot_len = strlen (target_system_root);
2994
2995 if (sysroot_len > 0
2996 && target_system_root[sysroot_len - 1] == DIR_SEPARATOR)
2997 sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0';
2998
2999 if (target_sysroot_hdrs_suffix)
3000 prefix = concat (sysroot_no_trailing_dir_separator,
3001 target_sysroot_hdrs_suffix, prefix, NULL);
3002 else
3003 prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL);
3004
3005 free (sysroot_no_trailing_dir_separator);
3006
3007 /* We have to override this because GCC's notion of sysroot
3008 moves along with GCC. */
3009 component = "GCC";
3010 }
3011
3012 add_prefix (pprefix, prefix, component, priority,
3013 require_machine_suffix, os_multilib);
3014 }
3015
2976 3016
2977 /* Execute the command specified by the arguments on the current line of spec. 3017 /* Execute the command specified by the arguments on the current line of spec.
2978 When using pipes, this includes several piped-together commands 3018 When using pipes, this includes several piped-together commands
2979 with `|' between them. 3019 with `|' between them.
2980 3020
3025 commands[0].argv = argbuf.address (); 3065 commands[0].argv = argbuf.address ();
3026 3066
3027 if (!wrapper_string) 3067 if (!wrapper_string)
3028 { 3068 {
3029 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); 3069 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false);
3030 commands[0].argv[0] = (string) ? string : commands[0].argv[0]; 3070 if (string)
3071 commands[0].argv[0] = string;
3031 } 3072 }
3032 3073
3033 for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++) 3074 for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)
3034 if (arg && strcmp (arg, "|") == 0) 3075 if (arg && strcmp (arg, "|") == 0)
3035 { /* each command. */ 3076 { /* each command. */
3036 #if defined (__MSDOS__) || defined (OS2) || defined (VMS) 3077 #if defined (__MSDOS__) || defined (OS2) || defined (VMS)
3037 fatal_error (input_location, "-pipe not supported"); 3078 fatal_error (input_location, "%<-pipe%> not supported");
3038 #endif 3079 #endif
3039 argbuf[i] = 0; /* Termination of 3080 argbuf[i] = 0; /* Termination of command args. */
3040 command args. */
3041 commands[n_commands].prog = argbuf[i + 1]; 3081 commands[n_commands].prog = argbuf[i + 1];
3042 commands[n_commands].argv 3082 commands[n_commands].argv
3043 = &(argbuf.address ())[i + 1]; 3083 = &(argbuf.address ())[i + 1];
3044 string = find_a_file (&exec_prefixes, commands[n_commands].prog, 3084 string = find_a_file (&exec_prefixes, commands[n_commands].prog,
3045 X_OK, false); 3085 X_OK, false);
3155 3195
3156 pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) 3196 pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file)
3157 ? PEX_RECORD_TIMES : 0), 3197 ? PEX_RECORD_TIMES : 0),
3158 progname, temp_filename); 3198 progname, temp_filename);
3159 if (pex == NULL) 3199 if (pex == NULL)
3160 fatal_error (input_location, "pex_init failed: %m"); 3200 fatal_error (input_location, "%<pex_init%> failed: %m");
3161 3201
3162 for (i = 0; i < n_commands; i++) 3202 for (i = 0; i < n_commands; i++)
3163 { 3203 {
3164 const char *errmsg; 3204 const char *errmsg;
3165 int err; 3205 int err;
3726 compilers proper are treated just like completely unknown 3766 compilers proper are treated just like completely unknown
3727 options. */ 3767 options. */
3728 const struct cl_option *option = &cl_options[decoded->opt_index]; 3768 const struct cl_option *option = &cl_options[decoded->opt_index];
3729 3769
3730 if (option->cl_reject_driver) 3770 if (option->cl_reject_driver)
3731 error ("unrecognized command line option %qs", 3771 error ("unrecognized command-line option %qs",
3732 decoded->orig_option_with_args_text); 3772 decoded->orig_option_with_args_text);
3733 else 3773 else
3734 save_switch (decoded->canonical_option[0], 3774 save_switch (decoded->canonical_option[0],
3735 decoded->canonical_option_num_elements - 1, 3775 decoded->canonical_option_num_elements - 1,
3736 &decoded->canonical_option[1], false, true); 3776 &decoded->canonical_option[1], false, true);
3998 4038
3999 case OPT_fdiagnostics_color_: 4039 case OPT_fdiagnostics_color_:
4000 diagnostic_color_init (dc, value); 4040 diagnostic_color_init (dc, value);
4001 break; 4041 break;
4002 4042
4043 case OPT_fdiagnostics_urls_:
4044 diagnostic_urls_init (dc, value);
4045 break;
4046
4047 case OPT_fdiagnostics_format_:
4048 diagnostic_output_format_init (dc,
4049 (enum diagnostics_output_format)value);
4050 break;
4051
4003 case OPT_Wa_: 4052 case OPT_Wa_:
4004 { 4053 {
4005 int prev, j; 4054 int prev, j;
4006 /* Pass the rest of this option to the assembler. */ 4055 /* Pass the rest of this option to the assembler. */
4007 4056
4100 save_temps_flag = SAVE_TEMPS_CWD; 4149 save_temps_flag = SAVE_TEMPS_CWD;
4101 else if (strcmp (arg, "obj") == 0 4150 else if (strcmp (arg, "obj") == 0
4102 || strcmp (arg, "object") == 0) 4151 || strcmp (arg, "object") == 0)
4103 save_temps_flag = SAVE_TEMPS_OBJ; 4152 save_temps_flag = SAVE_TEMPS_OBJ;
4104 else 4153 else
4105 fatal_error (input_location, "%qs is an unknown -save-temps option", 4154 fatal_error (input_location, "%qs is an unknown %<-save-temps%> option",
4106 decoded->orig_option_with_args_text); 4155 decoded->orig_option_with_args_text);
4107 break; 4156 break;
4108 4157
4109 case OPT_no_canonical_prefixes: 4158 case OPT_no_canonical_prefixes:
4110 /* Already handled as a special case, so ignored here. */ 4159 /* Already handled as a special case, so ignored here. */
4603 4652
4604 if (save_temps_flag && use_pipes) 4653 if (save_temps_flag && use_pipes)
4605 { 4654 {
4606 /* -save-temps overrides -pipe, so that temp files are produced */ 4655 /* -save-temps overrides -pipe, so that temp files are produced */
4607 if (save_temps_flag) 4656 if (save_temps_flag)
4608 warning (0, "-pipe ignored because -save-temps specified"); 4657 warning (0, "%<-pipe%> ignored because %<-save-temps%> specified");
4609 use_pipes = 0; 4658 use_pipes = 0;
4610 } 4659 }
4611 4660
4612 if (!compare_debug) 4661 if (!compare_debug)
4613 { 4662 {
4690 #endif 4739 #endif
4691 4740
4692 /* More prefixes are enabled in main, after we read the specs file 4741 /* More prefixes are enabled in main, after we read the specs file
4693 and determine whether this is cross-compilation or not. */ 4742 and determine whether this is cross-compilation or not. */
4694 4743
4695 if (n_infiles == last_language_n_infiles && spec_lang != 0) 4744 if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0)
4696 warning (0, "%<-x %s%> after last input file has no effect", spec_lang); 4745 warning (0, "%<-x %s%> after last input file has no effect", spec_lang);
4697 4746
4698 /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG 4747 /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG
4699 environment variable. */ 4748 environment variable. */
4700 if (compare_debug == 2 || compare_debug == 3) 4749 if (compare_debug == 2 || compare_debug == 3)
4703 save_switch (opt, 0, NULL, false, true); 4752 save_switch (opt, 0, NULL, false, true);
4704 compare_debug = 1; 4753 compare_debug = 1;
4705 } 4754 }
4706 4755
4707 /* Ensure we only invoke each subprocess once. */ 4756 /* Ensure we only invoke each subprocess once. */
4708 if (print_subprocess_help || print_help_list || print_version) 4757 if (n_infiles == 0
4709 { 4758 && (print_subprocess_help || print_help_list || print_version))
4710 n_infiles = 0; 4759 {
4711
4712 /* Create a dummy input file, so that we can pass 4760 /* Create a dummy input file, so that we can pass
4713 the help option on to the various sub-processes. */ 4761 the help option on to the various sub-processes. */
4714 add_infile ("help-dummy", "c"); 4762 add_infile ("help-dummy", "c");
4715 } 4763 }
4716 4764
6091 /* Create a new spec processing context, and build the function 6139 /* Create a new spec processing context, and build the function
6092 arguments. */ 6140 arguments. */
6093 6141
6094 alloc_args (); 6142 alloc_args ();
6095 if (do_spec_2 (args, soft_matched_part) < 0) 6143 if (do_spec_2 (args, soft_matched_part) < 0)
6096 fatal_error (input_location, "error in args to spec function %qs", func); 6144 fatal_error (input_location, "error in arguments to spec function %qs",
6145 func);
6097 6146
6098 /* argbuf_index is an index for the next argument to be inserted, and 6147 /* argbuf_index is an index for the next argument to be inserted, and
6099 so contains the count of the args already inserted. */ 6148 so contains the count of the args already inserted. */
6100 6149
6101 funcval = (*sf->func) (argbuf.length (), 6150 funcval = (*sf->func) (argbuf.length (),
6743 #else 6792 #else
6744 thrmod = thread_model; 6793 thrmod = thread_model;
6745 #endif 6794 #endif
6746 6795
6747 fnotice (file, "Thread model: %s\n", thrmod); 6796 fnotice (file, "Thread model: %s\n", thrmod);
6797 fnotice (file, "Supported LTO compression algorithms: zlib");
6798 #ifdef HAVE_ZSTD_H
6799 fnotice (file, " zstd");
6800 #endif
6801 fnotice (file, "\n");
6748 6802
6749 /* compiler_version is truncated at the first space when initialized 6803 /* compiler_version is truncated at the first space when initialized
6750 from version string, so truncate version_string at the first space 6804 from version string, so truncate version_string at the first space
6751 before comparing. */ 6805 before comparing. */
6752 for (n = 0; version_string[n]; n++) 6806 for (n = 0; version_string[n]; n++)
6876 if (append) 6930 if (append)
6877 pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND; 6931 pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND;
6878 6932
6879 pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL); 6933 pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL);
6880 if (!pex) 6934 if (!pex)
6881 fatal_error (input_location, "pex_init failed: %m"); 6935 fatal_error (input_location, "%<pex_init%> failed: %m");
6882 6936
6883 errmsg = pex_run (pex, pex_flags, new_argv[0], 6937 errmsg = pex_run (pex, pex_flags, new_argv[0],
6884 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, 6938 CONST_CAST2 (char *const *, const char **, &new_argv[1]),
6885 err_temp, &err); 6939 out_temp, err_temp, &err);
6886 if (errmsg != NULL) 6940 if (errmsg != NULL)
6887 { 6941 {
6888 errno = err; 6942 errno = err;
6889 fatal_error (input_location, 6943 fatal_error (input_location,
6890 err ? G_ ("cannot execute %qs: %s: %m") 6944 err ? G_ ("cannot execute %qs: %s: %m")
7195 length[i] = st.st_size; 7249 length[i] = st.st_size;
7196 } 7250 }
7197 7251
7198 if (!ret && length[0] != length[1]) 7252 if (!ret && length[0] != length[1])
7199 { 7253 {
7200 error ("%s: -fcompare-debug failure (length)", gcc_input_filename); 7254 error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename);
7201 ret = 1; 7255 ret = 1;
7202 } 7256 }
7203 7257
7204 if (!ret) 7258 if (!ret)
7205 for (i = 0; i < 2; i++) 7259 for (i = 0; i < 2; i++)
7225 7279
7226 if (!ret) 7280 if (!ret)
7227 { 7281 {
7228 if (memcmp (map[0], map[1], length[0]) != 0) 7282 if (memcmp (map[0], map[1], length[0]) != 0)
7229 { 7283 {
7230 error ("%s: -fcompare-debug failure", gcc_input_filename); 7284 error ("%s: %<-fcompare-debug%> failure", gcc_input_filename);
7231 ret = 1; 7285 ret = 1;
7232 } 7286 }
7233 } 7287 }
7234 7288
7235 for (i = 0; i < 2; i++) 7289 for (i = 0; i < 2; i++)
7262 c0 = fgetc (temp[0]); 7316 c0 = fgetc (temp[0]);
7263 c1 = fgetc (temp[1]); 7317 c1 = fgetc (temp[1]);
7264 7318
7265 if (c0 != c1) 7319 if (c0 != c1)
7266 { 7320 {
7267 error ("%s: -fcompare-debug failure", 7321 error ("%s: %<-fcompare-debug%> failure",
7268 gcc_input_filename); 7322 gcc_input_filename);
7269 ret = 1; 7323 ret = 1;
7270 break; 7324 break;
7271 } 7325 }
7272 7326
7366 decoded_options array. */ 7420 decoded_options array. */
7367 7421
7368 void 7422 void
7369 driver::decode_argv (int argc, const char **argv) 7423 driver::decode_argv (int argc, const char **argv)
7370 { 7424 {
7371 /* Register the language-independent parameters. */
7372 global_init_params ();
7373 finish_params ();
7374
7375 init_opts_obstack (); 7425 init_opts_obstack ();
7376 init_options_struct (&global_options, &global_options_set); 7426 init_options_struct (&global_options, &global_options_set);
7377 7427
7378 decode_cmdline_options_to_array (argc, argv, 7428 decode_cmdline_options_to_array (argc, argv,
7379 CL_DRIVER, 7429 CL_DRIVER,
7390 7440
7391 gcc_init_libintl (); 7441 gcc_init_libintl ();
7392 7442
7393 diagnostic_initialize (global_dc, 0); 7443 diagnostic_initialize (global_dc, 0);
7394 diagnostic_color_init (global_dc); 7444 diagnostic_color_init (global_dc);
7445 diagnostic_urls_init (global_dc);
7395 7446
7396 #ifdef GCC_DRIVER_HOST_INITIALIZATION 7447 #ifdef GCC_DRIVER_HOST_INITIALIZATION
7397 /* Perform host dependent initialization when needed. */ 7448 /* Perform host dependent initialization when needed. */
7398 GCC_DRIVER_HOST_INITIALIZATION; 7449 GCC_DRIVER_HOST_INITIALIZATION;
7399 #endif 7450 #endif
7567 if (*sysroot_suffix_spec != 0 7618 if (*sysroot_suffix_spec != 0
7568 && !no_sysroot_suffix 7619 && !no_sysroot_suffix
7569 && do_spec_2 (sysroot_suffix_spec, NULL) == 0) 7620 && do_spec_2 (sysroot_suffix_spec, NULL) == 0)
7570 { 7621 {
7571 if (argbuf.length () > 1) 7622 if (argbuf.length () > 1)
7572 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); 7623 error ("spec failure: more than one argument to "
7624 "%<SYSROOT_SUFFIX_SPEC%>");
7573 else if (argbuf.length () == 1) 7625 else if (argbuf.length () == 1)
7574 target_sysroot_suffix = xstrdup (argbuf.last ()); 7626 target_sysroot_suffix = xstrdup (argbuf.last ());
7575 } 7627 }
7576 7628
7577 #ifdef HAVE_LD_SYSROOT 7629 #ifdef HAVE_LD_SYSROOT
7591 if (*sysroot_hdrs_suffix_spec != 0 7643 if (*sysroot_hdrs_suffix_spec != 0
7592 && !no_sysroot_suffix 7644 && !no_sysroot_suffix
7593 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) 7645 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0)
7594 { 7646 {
7595 if (argbuf.length () > 1) 7647 if (argbuf.length () > 1)
7596 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); 7648 error ("spec failure: more than one argument "
7649 "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>");
7597 else if (argbuf.length () == 1) 7650 else if (argbuf.length () == 1)
7598 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); 7651 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ());
7599 } 7652 }
7600 7653
7601 /* Look for startfiles in the standard places. */ 7654 /* Look for startfiles in the standard places. */
7796 for (size_t i = 0; (int) i < n_switches; i++) 7849 for (size_t i = 0; (int) i < n_switches; i++)
7797 if (! switches[i].validated) 7850 if (! switches[i].validated)
7798 { 7851 {
7799 const char *hint = m_option_proposer.suggest_option (switches[i].part1); 7852 const char *hint = m_option_proposer.suggest_option (switches[i].part1);
7800 if (hint) 7853 if (hint)
7801 error ("unrecognized command line option %<-%s%>;" 7854 error ("unrecognized command-line option %<-%s%>;"
7802 " did you mean %<-%s%>?", 7855 " did you mean %<-%s%>?",
7803 switches[i].part1, hint); 7856 switches[i].part1, hint);
7804 else 7857 else
7805 error ("unrecognized command line option %<-%s%>", 7858 error ("unrecognized command-line option %<-%s%>",
7806 switches[i].part1); 7859 switches[i].part1);
7807 } 7860 }
7808 } 7861 }
7809 7862
7810 /* Handle the various -print-* options, returning 0 if the driver 7863 /* Handle the various -print-* options, returning 0 if the driver
7953 8006
7954 if (print_version) 8007 if (print_version)
7955 { 8008 {
7956 printf (_("%s %s%s\n"), progname, pkgversion_string, 8009 printf (_("%s %s%s\n"), progname, pkgversion_string,
7957 version_string); 8010 version_string);
7958 printf ("Copyright %s 2018 Free Software Foundation, Inc.\n", 8011 printf ("Copyright %s 2020 Free Software Foundation, Inc.\n",
7959 _("(C)")); 8012 _("(C)"));
7960 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ 8013 fputs (_("This is free software; see the source for copying conditions. There is NO\n\
7961 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), 8014 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"),
7962 stdout); 8015 stdout);
7963 if (! verbose_flag) 8016 if (! verbose_flag)
8038 infiles[i].preprocessed = false; 8091 infiles[i].preprocessed = false;
8039 } 8092 }
8040 8093
8041 if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) 8094 if (!combine_inputs && have_c && have_o && lang_n_infiles > 1)
8042 fatal_error (input_location, 8095 fatal_error (input_location,
8043 "cannot specify -o with -c, -S or -E with multiple files"); 8096 "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> "
8097 "with multiple files");
8044 8098
8045 /* No early exit needed from main; we can continue. */ 8099 /* No early exit needed from main; we can continue. */
8046 return false; 8100 return false;
8047 } 8101 }
8048 8102
8104 this_file_error = 1; 8158 this_file_error = 1;
8105 else if (compare_debug && debug_check_temp_file[0]) 8159 else if (compare_debug && debug_check_temp_file[0])
8106 { 8160 {
8107 if (verbose_flag) 8161 if (verbose_flag)
8108 inform (UNKNOWN_LOCATION, 8162 inform (UNKNOWN_LOCATION,
8109 "recompiling with -fcompare-debug"); 8163 "recompiling with %<-fcompare-debug%>");
8110 8164
8111 compare_debug = -compare_debug; 8165 compare_debug = -compare_debug;
8112 n_switches = n_switches_debug_check[1]; 8166 n_switches = n_switches_debug_check[1];
8113 n_switches_alloc = n_switches_alloc_debug_check[1]; 8167 n_switches_alloc = n_switches_alloc_debug_check[1];
8114 switches = switches_debug_check[1]; 8168 switches = switches_debug_check[1];
8120 n_switches_alloc = n_switches_alloc_debug_check[0]; 8174 n_switches_alloc = n_switches_alloc_debug_check[0];
8121 switches = switches_debug_check[0]; 8175 switches = switches_debug_check[0];
8122 8176
8123 if (value < 0) 8177 if (value < 0)
8124 { 8178 {
8125 error ("during -fcompare-debug recompilation"); 8179 error ("during %<-fcompare-debug%> recompilation");
8126 this_file_error = 1; 8180 this_file_error = 1;
8127 } 8181 }
8128 8182
8129 gcc_assert (debug_check_temp_file[1] 8183 gcc_assert (debug_check_temp_file[1]
8130 && filename_cmp (debug_check_temp_file[0], 8184 && filename_cmp (debug_check_temp_file[0],
8211 /* Run ld to link all the compiler output files. */ 8265 /* Run ld to link all the compiler output files. */
8212 8266
8213 if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2) 8267 if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2)
8214 { 8268 {
8215 int tmp = execution_count; 8269 int tmp = execution_count;
8270
8271 detect_jobserver ();
8216 8272
8217 if (! have_c) 8273 if (! have_c)
8218 { 8274 {
8219 #if HAVE_LTO_PLUGIN > 0 8275 #if HAVE_LTO_PLUGIN > 0
8220 #if HAVE_LTO_PLUGIN == 2 8276 #if HAVE_LTO_PLUGIN == 2
8246 char *temp_spec = find_a_file (&exec_prefixes, 8302 char *temp_spec = find_a_file (&exec_prefixes,
8247 LTOPLUGINSONAME, R_OK, 8303 LTOPLUGINSONAME, R_OK,
8248 false); 8304 false);
8249 if (!temp_spec) 8305 if (!temp_spec)
8250 fatal_error (input_location, 8306 fatal_error (input_location,
8251 "-fuse-linker-plugin, but %s not found", 8307 "%<-fuse-linker-plugin%>, but %s not found",
8252 LTOPLUGINSONAME); 8308 LTOPLUGINSONAME);
8253 linker_plugin_file_spec = convert_white_space (temp_spec); 8309 linker_plugin_file_spec = convert_white_space (temp_spec);
8254 } 8310 }
8255 #endif 8311 #endif
8256 lto_gcc_spec = argv0; 8312 lto_gcc_spec = argv0;
8298 8354
8299 if (print_help_list) 8355 if (print_help_list)
8300 { 8356 {
8301 printf (("\nFor bug reporting instructions, please see:\n")); 8357 printf (("\nFor bug reporting instructions, please see:\n"));
8302 printf ("%s\n", bug_report_url); 8358 printf ("%s\n", bug_report_url);
8359 }
8360 }
8361
8362 /* Detect whether jobserver is active and working. If not drop
8363 --jobserver-auth from MAKEFLAGS. */
8364
8365 void
8366 driver::detect_jobserver () const
8367 {
8368 /* Detect jobserver and drop it if it's not working. */
8369 const char *makeflags = env.get ("MAKEFLAGS");
8370 if (makeflags != NULL)
8371 {
8372 const char *needle = "--jobserver-auth=";
8373 const char *n = strstr (makeflags, needle);
8374 if (n != NULL)
8375 {
8376 int rfd = -1;
8377 int wfd = -1;
8378
8379 bool jobserver
8380 = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2
8381 && rfd > 0
8382 && wfd > 0
8383 && is_valid_fd (rfd)
8384 && is_valid_fd (wfd));
8385
8386 /* Drop the jobserver if it's not working now. */
8387 if (!jobserver)
8388 {
8389 unsigned offset = n - makeflags;
8390 char *dup = xstrdup (makeflags);
8391 dup[offset] = '\0';
8392
8393 const char *space = strchr (makeflags + offset, ' ');
8394 if (space != NULL)
8395 strcpy (dup + offset, space);
8396 xputenv (concat ("MAKEFLAGS=", dup, NULL));
8397 }
8398 }
8303 } 8399 }
8304 } 8400 }
8305 8401
8306 /* Determine what the exit code of the driver should be. */ 8402 /* Determine what the exit code of the driver should be. */
8307 8403
8523 static int n_mdswitches; 8619 static int n_mdswitches;
8524 8620
8525 /* Check whether a particular argument was used. The first time we 8621 /* Check whether a particular argument was used. The first time we
8526 canonicalize the switches to keep only the ones we care about. */ 8622 canonicalize the switches to keep only the ones we care about. */
8527 8623
8528 class used_arg_t 8624 struct used_arg_t
8529 { 8625 {
8530 public: 8626 public:
8531 int operator () (const char *p, int len); 8627 int operator () (const char *p, int len);
8532 void finalize (); 8628 void finalize ();
8533 8629
9749 return NULL; 9845 return NULL;
9750 9846
9751 len = strlen (argv[0]); 9847 len = strlen (argv[0]);
9752 if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) 9848 if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0)
9753 fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt " 9849 fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt "
9754 "does not end in .gk"); 9850 "does not end in %<.gk%>");
9755 9851
9756 if (debug_auxbase_opt) 9852 if (debug_auxbase_opt)
9757 return debug_auxbase_opt; 9853 return debug_auxbase_opt;
9758 9854
9759 #define OPT "-auxbase " 9855 #define OPT "-auxbase "
9886 return ""; 9982 return "";
9887 9983
9888 return NULL; 9984 return NULL;
9889 } 9985 }
9890 9986
9987 static void
9988 path_prefix_reset (path_prefix *prefix)
9989 {
9990 struct prefix_list *iter, *next;
9991 iter = prefix->plist;
9992 while (iter)
9993 {
9994 next = iter->next;
9995 free (const_cast <char *> (iter->prefix));
9996 XDELETE (iter);
9997 iter = next;
9998 }
9999 prefix->plist = 0;
10000 prefix->max_len = 0;
10001 }
10002
10003 /* The function takes 3 arguments: OPTION name, file name and location
10004 where we search for Fortran modules.
10005 When the FILE is found by find_file, return OPTION=path_to_file. */
10006
10007 static const char *
10008 find_fortran_preinclude_file (int argc, const char **argv)
10009 {
10010 char *result = NULL;
10011 if (argc != 3)
10012 return NULL;
10013
10014 struct path_prefix prefixes = { 0, 0, "preinclude" };
10015
10016 /* Search first for 'finclude' folder location for a header file
10017 installed by the compiler (similar to omp_lib.h). */
10018 add_prefix (&prefixes, argv[2], NULL, 0, 0, 0);
10019 #ifdef TOOL_INCLUDE_DIR
10020 /* Then search: <prefix>/<target>/<include>/finclude */
10021 add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/",
10022 NULL, 0, 0, 0);
10023 #endif
10024 #ifdef NATIVE_SYSTEM_HEADER_DIR
10025 /* Then search: <sysroot>/usr/include/finclude/<multilib> */
10026 add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/",
10027 NULL, 0, 0, 0);
10028 #endif
10029
10030 const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false);
10031 if (path != NULL)
10032 result = concat (argv[0], path, NULL);
10033 else
10034 {
10035 path = find_a_file (&prefixes, argv[1], R_OK, false);
10036 if (path != NULL)
10037 result = concat (argv[0], path, NULL);
10038 }
10039
10040 path_prefix_reset (&prefixes);
10041 return result;
10042 }
10043
10044
9891 /* Insert backslash before spaces in ORIG (usually a file path), to 10045 /* Insert backslash before spaces in ORIG (usually a file path), to
9892 avoid being broken by spec parser. 10046 avoid being broken by spec parser.
9893 10047
9894 This function is needed as do_spec_1 treats white space (' ' and '\t') 10048 This function is needed as do_spec_1 treats white space (' ' and '\t')
9895 as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so, 10049 as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so,
9934 } 10088 }
9935 else 10089 else
9936 return orig; 10090 return orig;
9937 } 10091 }
9938 10092
9939 static void
9940 path_prefix_reset (path_prefix *prefix)
9941 {
9942 struct prefix_list *iter, *next;
9943 iter = prefix->plist;
9944 while (iter)
9945 {
9946 next = iter->next;
9947 free (const_cast <char *> (iter->prefix));
9948 XDELETE (iter);
9949 iter = next;
9950 }
9951 prefix->plist = 0;
9952 prefix->max_len = 0;
9953 }
9954
9955 /* Restore all state within gcc.c to the initial state, so that the driver 10093 /* Restore all state within gcc.c to the initial state, so that the driver
9956 code can be safely re-run in-process. 10094 code can be safely re-run in-process.
9957 10095
9958 Many const char * variables are referenced by static specs (see 10096 Many const char * variables are referenced by static specs (see
9959 INIT_STATIC_SPEC above). These variables are restored to their default 10097 INIT_STATIC_SPEC above). These variables are restored to their default
9969 10107
9970 void 10108 void
9971 driver::finalize () 10109 driver::finalize ()
9972 { 10110 {
9973 env.restore (); 10111 env.restore ();
9974 params_c_finalize ();
9975 diagnostic_finish (global_dc); 10112 diagnostic_finish (global_dc);
9976 10113
9977 is_cpp_driver = 0; 10114 is_cpp_driver = 0;
9978 at_file_supplied = 0; 10115 at_file_supplied = 0;
9979 print_help_list = 0; 10116 print_help_list = 0;
9989 save_temps_flag = SAVE_TEMPS_NONE; 10126 save_temps_flag = SAVE_TEMPS_NONE;
9990 save_temps_prefix = 0; 10127 save_temps_prefix = 0;
9991 save_temps_length = 0; 10128 save_temps_length = 0;
9992 spec_machine = DEFAULT_TARGET_MACHINE; 10129 spec_machine = DEFAULT_TARGET_MACHINE;
9993 greatest_status = 1; 10130 greatest_status = 1;
9994
9995 finalize_options_struct (&global_options);
9996 finalize_options_struct (&global_options_set);
9997 10131
9998 obstack_free (&obstack, NULL); 10132 obstack_free (&obstack, NULL);
9999 obstack_free (&opts_obstack, NULL); /* in opts.c */ 10133 obstack_free (&opts_obstack, NULL); /* in opts.c */
10000 obstack_free (&collect_obstack, NULL); 10134 obstack_free (&collect_obstack, NULL);
10001 10135