Mercurial > hg > CbC > CbC_gcc
comparison gcc/gcc.c @ 146:351920fa3827
merge
author | anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 01 Mar 2020 16:13:28 +0900 |
parents | d34655255c78 1830386684a0 |
children |
comparison
equal
deleted
inserted
replaced
144:8f4e72ab4e11 | 146:351920fa3827 |
---|---|
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 #ifndef noCbC | 1311 #ifndef noCbC |
1311 {".cbc", "@c", 0, 1, 1}, | 1312 {".cbc", "@c", 0, 1, 1}, |
1312 #endif | 1313 #endif |
1647 { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function }, | 1648 { "compare-debug-auxbase-opt", compare_debug_auxbase_opt_spec_function }, |
1648 { "pass-through-libs", pass_through_libs_spec_func }, | 1649 { "pass-through-libs", pass_through_libs_spec_func }, |
1649 { "replace-extension", replace_extension_spec_func }, | 1650 { "replace-extension", replace_extension_spec_func }, |
1650 { "gt", greater_than_spec_func }, | 1651 { "gt", greater_than_spec_func }, |
1651 { "debug-level-gt", debug_level_greater_than_spec_func }, | 1652 { "debug-level-gt", debug_level_greater_than_spec_func }, |
1653 { "fortran-preinclude-file", find_fortran_preinclude_file}, | |
1652 #ifdef EXTRA_SPEC_FUNCTIONS | 1654 #ifdef EXTRA_SPEC_FUNCTIONS |
1653 EXTRA_SPEC_FUNCTIONS | 1655 EXTRA_SPEC_FUNCTIONS |
1654 #endif | 1656 #endif |
1655 { 0, 0 } | 1657 { 0, 0 } |
1656 }; | 1658 }; |
2974 } | 2976 } |
2975 | 2977 |
2976 add_prefix (pprefix, prefix, component, priority, | 2978 add_prefix (pprefix, prefix, component, priority, |
2977 require_machine_suffix, os_multilib); | 2979 require_machine_suffix, os_multilib); |
2978 } | 2980 } |
2981 | |
2982 /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */ | |
2983 | |
2984 static void | |
2985 add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, | |
2986 const char *component, | |
2987 /* enum prefix_priority */ int priority, | |
2988 int require_machine_suffix, int os_multilib) | |
2989 { | |
2990 if (!IS_ABSOLUTE_PATH (prefix)) | |
2991 fatal_error (input_location, "system path %qs is not absolute", prefix); | |
2992 | |
2993 if (target_system_root) | |
2994 { | |
2995 char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); | |
2996 size_t sysroot_len = strlen (target_system_root); | |
2997 | |
2998 if (sysroot_len > 0 | |
2999 && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) | |
3000 sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; | |
3001 | |
3002 if (target_sysroot_hdrs_suffix) | |
3003 prefix = concat (sysroot_no_trailing_dir_separator, | |
3004 target_sysroot_hdrs_suffix, prefix, NULL); | |
3005 else | |
3006 prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); | |
3007 | |
3008 free (sysroot_no_trailing_dir_separator); | |
3009 | |
3010 /* We have to override this because GCC's notion of sysroot | |
3011 moves along with GCC. */ | |
3012 component = "GCC"; | |
3013 } | |
3014 | |
3015 add_prefix (pprefix, prefix, component, priority, | |
3016 require_machine_suffix, os_multilib); | |
3017 } | |
3018 | |
2979 | 3019 |
2980 /* Execute the command specified by the arguments on the current line of spec. | 3020 /* Execute the command specified by the arguments on the current line of spec. |
2981 When using pipes, this includes several piped-together commands | 3021 When using pipes, this includes several piped-together commands |
2982 with `|' between them. | 3022 with `|' between them. |
2983 | 3023 |
3028 commands[0].argv = argbuf.address (); | 3068 commands[0].argv = argbuf.address (); |
3029 | 3069 |
3030 if (!wrapper_string) | 3070 if (!wrapper_string) |
3031 { | 3071 { |
3032 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); | 3072 string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); |
3033 commands[0].argv[0] = (string) ? string : commands[0].argv[0]; | 3073 if (string) |
3074 commands[0].argv[0] = string; | |
3034 } | 3075 } |
3035 | 3076 |
3036 for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++) | 3077 for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++) |
3037 if (arg && strcmp (arg, "|") == 0) | 3078 if (arg && strcmp (arg, "|") == 0) |
3038 { /* each command. */ | 3079 { /* each command. */ |
3039 #if defined (__MSDOS__) || defined (OS2) || defined (VMS) | 3080 #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
3040 fatal_error (input_location, "-pipe not supported"); | 3081 fatal_error (input_location, "%<-pipe%> not supported"); |
3041 #endif | 3082 #endif |
3042 argbuf[i] = 0; /* Termination of | 3083 argbuf[i] = 0; /* Termination of command args. */ |
3043 command args. */ | |
3044 commands[n_commands].prog = argbuf[i + 1]; | 3084 commands[n_commands].prog = argbuf[i + 1]; |
3045 commands[n_commands].argv | 3085 commands[n_commands].argv |
3046 = &(argbuf.address ())[i + 1]; | 3086 = &(argbuf.address ())[i + 1]; |
3047 string = find_a_file (&exec_prefixes, commands[n_commands].prog, | 3087 string = find_a_file (&exec_prefixes, commands[n_commands].prog, |
3048 X_OK, false); | 3088 X_OK, false); |
3158 | 3198 |
3159 pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) | 3199 pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
3160 ? PEX_RECORD_TIMES : 0), | 3200 ? PEX_RECORD_TIMES : 0), |
3161 progname, temp_filename); | 3201 progname, temp_filename); |
3162 if (pex == NULL) | 3202 if (pex == NULL) |
3163 fatal_error (input_location, "pex_init failed: %m"); | 3203 fatal_error (input_location, "%<pex_init%> failed: %m"); |
3164 | 3204 |
3165 for (i = 0; i < n_commands; i++) | 3205 for (i = 0; i < n_commands; i++) |
3166 { | 3206 { |
3167 const char *errmsg; | 3207 const char *errmsg; |
3168 int err; | 3208 int err; |
3729 compilers proper are treated just like completely unknown | 3769 compilers proper are treated just like completely unknown |
3730 options. */ | 3770 options. */ |
3731 const struct cl_option *option = &cl_options[decoded->opt_index]; | 3771 const struct cl_option *option = &cl_options[decoded->opt_index]; |
3732 | 3772 |
3733 if (option->cl_reject_driver) | 3773 if (option->cl_reject_driver) |
3734 error ("unrecognized command line option %qs", | 3774 error ("unrecognized command-line option %qs", |
3735 decoded->orig_option_with_args_text); | 3775 decoded->orig_option_with_args_text); |
3736 else | 3776 else |
3737 save_switch (decoded->canonical_option[0], | 3777 save_switch (decoded->canonical_option[0], |
3738 decoded->canonical_option_num_elements - 1, | 3778 decoded->canonical_option_num_elements - 1, |
3739 &decoded->canonical_option[1], false, true); | 3779 &decoded->canonical_option[1], false, true); |
4001 | 4041 |
4002 case OPT_fdiagnostics_color_: | 4042 case OPT_fdiagnostics_color_: |
4003 diagnostic_color_init (dc, value); | 4043 diagnostic_color_init (dc, value); |
4004 break; | 4044 break; |
4005 | 4045 |
4046 case OPT_fdiagnostics_urls_: | |
4047 diagnostic_urls_init (dc, value); | |
4048 break; | |
4049 | |
4050 case OPT_fdiagnostics_format_: | |
4051 diagnostic_output_format_init (dc, | |
4052 (enum diagnostics_output_format)value); | |
4053 break; | |
4054 | |
4006 case OPT_Wa_: | 4055 case OPT_Wa_: |
4007 { | 4056 { |
4008 int prev, j; | 4057 int prev, j; |
4009 /* Pass the rest of this option to the assembler. */ | 4058 /* Pass the rest of this option to the assembler. */ |
4010 | 4059 |
4103 save_temps_flag = SAVE_TEMPS_CWD; | 4152 save_temps_flag = SAVE_TEMPS_CWD; |
4104 else if (strcmp (arg, "obj") == 0 | 4153 else if (strcmp (arg, "obj") == 0 |
4105 || strcmp (arg, "object") == 0) | 4154 || strcmp (arg, "object") == 0) |
4106 save_temps_flag = SAVE_TEMPS_OBJ; | 4155 save_temps_flag = SAVE_TEMPS_OBJ; |
4107 else | 4156 else |
4108 fatal_error (input_location, "%qs is an unknown -save-temps option", | 4157 fatal_error (input_location, "%qs is an unknown %<-save-temps%> option", |
4109 decoded->orig_option_with_args_text); | 4158 decoded->orig_option_with_args_text); |
4110 break; | 4159 break; |
4111 | 4160 |
4112 case OPT_no_canonical_prefixes: | 4161 case OPT_no_canonical_prefixes: |
4113 /* Already handled as a special case, so ignored here. */ | 4162 /* Already handled as a special case, so ignored here. */ |
4606 | 4655 |
4607 if (save_temps_flag && use_pipes) | 4656 if (save_temps_flag && use_pipes) |
4608 { | 4657 { |
4609 /* -save-temps overrides -pipe, so that temp files are produced */ | 4658 /* -save-temps overrides -pipe, so that temp files are produced */ |
4610 if (save_temps_flag) | 4659 if (save_temps_flag) |
4611 warning (0, "-pipe ignored because -save-temps specified"); | 4660 warning (0, "%<-pipe%> ignored because %<-save-temps%> specified"); |
4612 use_pipes = 0; | 4661 use_pipes = 0; |
4613 } | 4662 } |
4614 | 4663 |
4615 if (!compare_debug) | 4664 if (!compare_debug) |
4616 { | 4665 { |
4693 #endif | 4742 #endif |
4694 | 4743 |
4695 /* More prefixes are enabled in main, after we read the specs file | 4744 /* More prefixes are enabled in main, after we read the specs file |
4696 and determine whether this is cross-compilation or not. */ | 4745 and determine whether this is cross-compilation or not. */ |
4697 | 4746 |
4698 if (n_infiles == last_language_n_infiles && spec_lang != 0) | 4747 if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0) |
4699 warning (0, "%<-x %s%> after last input file has no effect", spec_lang); | 4748 warning (0, "%<-x %s%> after last input file has no effect", spec_lang); |
4700 | 4749 |
4701 /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG | 4750 /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG |
4702 environment variable. */ | 4751 environment variable. */ |
4703 if (compare_debug == 2 || compare_debug == 3) | 4752 if (compare_debug == 2 || compare_debug == 3) |
4706 save_switch (opt, 0, NULL, false, true); | 4755 save_switch (opt, 0, NULL, false, true); |
4707 compare_debug = 1; | 4756 compare_debug = 1; |
4708 } | 4757 } |
4709 | 4758 |
4710 /* Ensure we only invoke each subprocess once. */ | 4759 /* Ensure we only invoke each subprocess once. */ |
4711 if (print_subprocess_help || print_help_list || print_version) | 4760 if (n_infiles == 0 |
4712 { | 4761 && (print_subprocess_help || print_help_list || print_version)) |
4713 n_infiles = 0; | 4762 { |
4714 | |
4715 /* Create a dummy input file, so that we can pass | 4763 /* Create a dummy input file, so that we can pass |
4716 the help option on to the various sub-processes. */ | 4764 the help option on to the various sub-processes. */ |
4717 add_infile ("help-dummy", "c"); | 4765 add_infile ("help-dummy", "c"); |
4718 } | 4766 } |
4719 | 4767 |
6094 /* Create a new spec processing context, and build the function | 6142 /* Create a new spec processing context, and build the function |
6095 arguments. */ | 6143 arguments. */ |
6096 | 6144 |
6097 alloc_args (); | 6145 alloc_args (); |
6098 if (do_spec_2 (args, soft_matched_part) < 0) | 6146 if (do_spec_2 (args, soft_matched_part) < 0) |
6099 fatal_error (input_location, "error in args to spec function %qs", func); | 6147 fatal_error (input_location, "error in arguments to spec function %qs", |
6148 func); | |
6100 | 6149 |
6101 /* argbuf_index is an index for the next argument to be inserted, and | 6150 /* argbuf_index is an index for the next argument to be inserted, and |
6102 so contains the count of the args already inserted. */ | 6151 so contains the count of the args already inserted. */ |
6103 | 6152 |
6104 funcval = (*sf->func) (argbuf.length (), | 6153 funcval = (*sf->func) (argbuf.length (), |
6746 #else | 6795 #else |
6747 thrmod = thread_model; | 6796 thrmod = thread_model; |
6748 #endif | 6797 #endif |
6749 | 6798 |
6750 fnotice (file, "Thread model: %s\n", thrmod); | 6799 fnotice (file, "Thread model: %s\n", thrmod); |
6800 fnotice (file, "Supported LTO compression algorithms: zlib"); | |
6801 #ifdef HAVE_ZSTD_H | |
6802 fnotice (file, " zstd"); | |
6803 #endif | |
6804 fnotice (file, "\n"); | |
6751 | 6805 |
6752 /* compiler_version is truncated at the first space when initialized | 6806 /* compiler_version is truncated at the first space when initialized |
6753 from version string, so truncate version_string at the first space | 6807 from version string, so truncate version_string at the first space |
6754 before comparing. */ | 6808 before comparing. */ |
6755 for (n = 0; version_string[n]; n++) | 6809 for (n = 0; version_string[n]; n++) |
6879 if (append) | 6933 if (append) |
6880 pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND; | 6934 pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND; |
6881 | 6935 |
6882 pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL); | 6936 pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL); |
6883 if (!pex) | 6937 if (!pex) |
6884 fatal_error (input_location, "pex_init failed: %m"); | 6938 fatal_error (input_location, "%<pex_init%> failed: %m"); |
6885 | 6939 |
6886 errmsg = pex_run (pex, pex_flags, new_argv[0], | 6940 errmsg = pex_run (pex, pex_flags, new_argv[0], |
6887 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, | 6941 CONST_CAST2 (char *const *, const char **, &new_argv[1]), |
6888 err_temp, &err); | 6942 out_temp, err_temp, &err); |
6889 if (errmsg != NULL) | 6943 if (errmsg != NULL) |
6890 { | 6944 { |
6891 errno = err; | 6945 errno = err; |
6892 fatal_error (input_location, | 6946 fatal_error (input_location, |
6893 err ? G_ ("cannot execute %qs: %s: %m") | 6947 err ? G_ ("cannot execute %qs: %s: %m") |
7198 length[i] = st.st_size; | 7252 length[i] = st.st_size; |
7199 } | 7253 } |
7200 | 7254 |
7201 if (!ret && length[0] != length[1]) | 7255 if (!ret && length[0] != length[1]) |
7202 { | 7256 { |
7203 error ("%s: -fcompare-debug failure (length)", gcc_input_filename); | 7257 error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename); |
7204 ret = 1; | 7258 ret = 1; |
7205 } | 7259 } |
7206 | 7260 |
7207 if (!ret) | 7261 if (!ret) |
7208 for (i = 0; i < 2; i++) | 7262 for (i = 0; i < 2; i++) |
7228 | 7282 |
7229 if (!ret) | 7283 if (!ret) |
7230 { | 7284 { |
7231 if (memcmp (map[0], map[1], length[0]) != 0) | 7285 if (memcmp (map[0], map[1], length[0]) != 0) |
7232 { | 7286 { |
7233 error ("%s: -fcompare-debug failure", gcc_input_filename); | 7287 error ("%s: %<-fcompare-debug%> failure", gcc_input_filename); |
7234 ret = 1; | 7288 ret = 1; |
7235 } | 7289 } |
7236 } | 7290 } |
7237 | 7291 |
7238 for (i = 0; i < 2; i++) | 7292 for (i = 0; i < 2; i++) |
7265 c0 = fgetc (temp[0]); | 7319 c0 = fgetc (temp[0]); |
7266 c1 = fgetc (temp[1]); | 7320 c1 = fgetc (temp[1]); |
7267 | 7321 |
7268 if (c0 != c1) | 7322 if (c0 != c1) |
7269 { | 7323 { |
7270 error ("%s: -fcompare-debug failure", | 7324 error ("%s: %<-fcompare-debug%> failure", |
7271 gcc_input_filename); | 7325 gcc_input_filename); |
7272 ret = 1; | 7326 ret = 1; |
7273 break; | 7327 break; |
7274 } | 7328 } |
7275 | 7329 |
7369 decoded_options array. */ | 7423 decoded_options array. */ |
7370 | 7424 |
7371 void | 7425 void |
7372 driver::decode_argv (int argc, const char **argv) | 7426 driver::decode_argv (int argc, const char **argv) |
7373 { | 7427 { |
7374 /* Register the language-independent parameters. */ | |
7375 global_init_params (); | |
7376 finish_params (); | |
7377 | |
7378 init_opts_obstack (); | 7428 init_opts_obstack (); |
7379 init_options_struct (&global_options, &global_options_set); | 7429 init_options_struct (&global_options, &global_options_set); |
7380 | 7430 |
7381 decode_cmdline_options_to_array (argc, argv, | 7431 decode_cmdline_options_to_array (argc, argv, |
7382 CL_DRIVER, | 7432 CL_DRIVER, |
7393 | 7443 |
7394 gcc_init_libintl (); | 7444 gcc_init_libintl (); |
7395 | 7445 |
7396 diagnostic_initialize (global_dc, 0); | 7446 diagnostic_initialize (global_dc, 0); |
7397 diagnostic_color_init (global_dc); | 7447 diagnostic_color_init (global_dc); |
7448 diagnostic_urls_init (global_dc); | |
7398 | 7449 |
7399 #ifdef GCC_DRIVER_HOST_INITIALIZATION | 7450 #ifdef GCC_DRIVER_HOST_INITIALIZATION |
7400 /* Perform host dependent initialization when needed. */ | 7451 /* Perform host dependent initialization when needed. */ |
7401 GCC_DRIVER_HOST_INITIALIZATION; | 7452 GCC_DRIVER_HOST_INITIALIZATION; |
7402 #endif | 7453 #endif |
7570 if (*sysroot_suffix_spec != 0 | 7621 if (*sysroot_suffix_spec != 0 |
7571 && !no_sysroot_suffix | 7622 && !no_sysroot_suffix |
7572 && do_spec_2 (sysroot_suffix_spec, NULL) == 0) | 7623 && do_spec_2 (sysroot_suffix_spec, NULL) == 0) |
7573 { | 7624 { |
7574 if (argbuf.length () > 1) | 7625 if (argbuf.length () > 1) |
7575 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); | 7626 error ("spec failure: more than one argument to " |
7627 "%<SYSROOT_SUFFIX_SPEC%>"); | |
7576 else if (argbuf.length () == 1) | 7628 else if (argbuf.length () == 1) |
7577 target_sysroot_suffix = xstrdup (argbuf.last ()); | 7629 target_sysroot_suffix = xstrdup (argbuf.last ()); |
7578 } | 7630 } |
7579 | 7631 |
7580 #ifdef HAVE_LD_SYSROOT | 7632 #ifdef HAVE_LD_SYSROOT |
7594 if (*sysroot_hdrs_suffix_spec != 0 | 7646 if (*sysroot_hdrs_suffix_spec != 0 |
7595 && !no_sysroot_suffix | 7647 && !no_sysroot_suffix |
7596 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) | 7648 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) |
7597 { | 7649 { |
7598 if (argbuf.length () > 1) | 7650 if (argbuf.length () > 1) |
7599 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); | 7651 error ("spec failure: more than one argument " |
7652 "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>"); | |
7600 else if (argbuf.length () == 1) | 7653 else if (argbuf.length () == 1) |
7601 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); | 7654 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); |
7602 } | 7655 } |
7603 | 7656 |
7604 /* Look for startfiles in the standard places. */ | 7657 /* Look for startfiles in the standard places. */ |
7799 for (size_t i = 0; (int) i < n_switches; i++) | 7852 for (size_t i = 0; (int) i < n_switches; i++) |
7800 if (! switches[i].validated) | 7853 if (! switches[i].validated) |
7801 { | 7854 { |
7802 const char *hint = m_option_proposer.suggest_option (switches[i].part1); | 7855 const char *hint = m_option_proposer.suggest_option (switches[i].part1); |
7803 if (hint) | 7856 if (hint) |
7804 error ("unrecognized command line option %<-%s%>;" | 7857 error ("unrecognized command-line option %<-%s%>;" |
7805 " did you mean %<-%s%>?", | 7858 " did you mean %<-%s%>?", |
7806 switches[i].part1, hint); | 7859 switches[i].part1, hint); |
7807 else | 7860 else |
7808 error ("unrecognized command line option %<-%s%>", | 7861 error ("unrecognized command-line option %<-%s%>", |
7809 switches[i].part1); | 7862 switches[i].part1); |
7810 } | 7863 } |
7811 } | 7864 } |
7812 | 7865 |
7813 /* Handle the various -print-* options, returning 0 if the driver | 7866 /* Handle the various -print-* options, returning 0 if the driver |
7956 | 8009 |
7957 if (print_version) | 8010 if (print_version) |
7958 { | 8011 { |
7959 printf (_("%s %s%s\n"), progname, pkgversion_string, | 8012 printf (_("%s %s%s\n"), progname, pkgversion_string, |
7960 version_string); | 8013 version_string); |
7961 printf ("Copyright %s 2018 Free Software Foundation, Inc.\n", | 8014 printf ("Copyright %s 2020 Free Software Foundation, Inc.\n", |
7962 _("(C)")); | 8015 _("(C)")); |
7963 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ | 8016 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ |
7964 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), | 8017 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), |
7965 stdout); | 8018 stdout); |
7966 if (! verbose_flag) | 8019 if (! verbose_flag) |
8041 infiles[i].preprocessed = false; | 8094 infiles[i].preprocessed = false; |
8042 } | 8095 } |
8043 | 8096 |
8044 if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) | 8097 if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) |
8045 fatal_error (input_location, | 8098 fatal_error (input_location, |
8046 "cannot specify -o with -c, -S or -E with multiple files"); | 8099 "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> " |
8100 "with multiple files"); | |
8047 | 8101 |
8048 /* No early exit needed from main; we can continue. */ | 8102 /* No early exit needed from main; we can continue. */ |
8049 return false; | 8103 return false; |
8050 } | 8104 } |
8051 | 8105 |
8107 this_file_error = 1; | 8161 this_file_error = 1; |
8108 else if (compare_debug && debug_check_temp_file[0]) | 8162 else if (compare_debug && debug_check_temp_file[0]) |
8109 { | 8163 { |
8110 if (verbose_flag) | 8164 if (verbose_flag) |
8111 inform (UNKNOWN_LOCATION, | 8165 inform (UNKNOWN_LOCATION, |
8112 "recompiling with -fcompare-debug"); | 8166 "recompiling with %<-fcompare-debug%>"); |
8113 | 8167 |
8114 compare_debug = -compare_debug; | 8168 compare_debug = -compare_debug; |
8115 n_switches = n_switches_debug_check[1]; | 8169 n_switches = n_switches_debug_check[1]; |
8116 n_switches_alloc = n_switches_alloc_debug_check[1]; | 8170 n_switches_alloc = n_switches_alloc_debug_check[1]; |
8117 switches = switches_debug_check[1]; | 8171 switches = switches_debug_check[1]; |
8123 n_switches_alloc = n_switches_alloc_debug_check[0]; | 8177 n_switches_alloc = n_switches_alloc_debug_check[0]; |
8124 switches = switches_debug_check[0]; | 8178 switches = switches_debug_check[0]; |
8125 | 8179 |
8126 if (value < 0) | 8180 if (value < 0) |
8127 { | 8181 { |
8128 error ("during -fcompare-debug recompilation"); | 8182 error ("during %<-fcompare-debug%> recompilation"); |
8129 this_file_error = 1; | 8183 this_file_error = 1; |
8130 } | 8184 } |
8131 | 8185 |
8132 gcc_assert (debug_check_temp_file[1] | 8186 gcc_assert (debug_check_temp_file[1] |
8133 && filename_cmp (debug_check_temp_file[0], | 8187 && filename_cmp (debug_check_temp_file[0], |
8214 /* Run ld to link all the compiler output files. */ | 8268 /* Run ld to link all the compiler output files. */ |
8215 | 8269 |
8216 if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2) | 8270 if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2) |
8217 { | 8271 { |
8218 int tmp = execution_count; | 8272 int tmp = execution_count; |
8273 | |
8274 detect_jobserver (); | |
8219 | 8275 |
8220 if (! have_c) | 8276 if (! have_c) |
8221 { | 8277 { |
8222 #if HAVE_LTO_PLUGIN > 0 | 8278 #if HAVE_LTO_PLUGIN > 0 |
8223 #if HAVE_LTO_PLUGIN == 2 | 8279 #if HAVE_LTO_PLUGIN == 2 |
8249 char *temp_spec = find_a_file (&exec_prefixes, | 8305 char *temp_spec = find_a_file (&exec_prefixes, |
8250 LTOPLUGINSONAME, R_OK, | 8306 LTOPLUGINSONAME, R_OK, |
8251 false); | 8307 false); |
8252 if (!temp_spec) | 8308 if (!temp_spec) |
8253 fatal_error (input_location, | 8309 fatal_error (input_location, |
8254 "-fuse-linker-plugin, but %s not found", | 8310 "%<-fuse-linker-plugin%>, but %s not found", |
8255 LTOPLUGINSONAME); | 8311 LTOPLUGINSONAME); |
8256 linker_plugin_file_spec = convert_white_space (temp_spec); | 8312 linker_plugin_file_spec = convert_white_space (temp_spec); |
8257 } | 8313 } |
8258 #endif | 8314 #endif |
8259 lto_gcc_spec = argv0; | 8315 lto_gcc_spec = argv0; |
8301 | 8357 |
8302 if (print_help_list) | 8358 if (print_help_list) |
8303 { | 8359 { |
8304 printf (("\nFor bug reporting instructions, please see:\n")); | 8360 printf (("\nFor bug reporting instructions, please see:\n")); |
8305 printf ("%s\n", bug_report_url); | 8361 printf ("%s\n", bug_report_url); |
8362 } | |
8363 } | |
8364 | |
8365 /* Detect whether jobserver is active and working. If not drop | |
8366 --jobserver-auth from MAKEFLAGS. */ | |
8367 | |
8368 void | |
8369 driver::detect_jobserver () const | |
8370 { | |
8371 /* Detect jobserver and drop it if it's not working. */ | |
8372 const char *makeflags = env.get ("MAKEFLAGS"); | |
8373 if (makeflags != NULL) | |
8374 { | |
8375 const char *needle = "--jobserver-auth="; | |
8376 const char *n = strstr (makeflags, needle); | |
8377 if (n != NULL) | |
8378 { | |
8379 int rfd = -1; | |
8380 int wfd = -1; | |
8381 | |
8382 bool jobserver | |
8383 = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 | |
8384 && rfd > 0 | |
8385 && wfd > 0 | |
8386 && is_valid_fd (rfd) | |
8387 && is_valid_fd (wfd)); | |
8388 | |
8389 /* Drop the jobserver if it's not working now. */ | |
8390 if (!jobserver) | |
8391 { | |
8392 unsigned offset = n - makeflags; | |
8393 char *dup = xstrdup (makeflags); | |
8394 dup[offset] = '\0'; | |
8395 | |
8396 const char *space = strchr (makeflags + offset, ' '); | |
8397 if (space != NULL) | |
8398 strcpy (dup + offset, space); | |
8399 xputenv (concat ("MAKEFLAGS=", dup, NULL)); | |
8400 } | |
8401 } | |
8306 } | 8402 } |
8307 } | 8403 } |
8308 | 8404 |
8309 /* Determine what the exit code of the driver should be. */ | 8405 /* Determine what the exit code of the driver should be. */ |
8310 | 8406 |
8526 static int n_mdswitches; | 8622 static int n_mdswitches; |
8527 | 8623 |
8528 /* Check whether a particular argument was used. The first time we | 8624 /* Check whether a particular argument was used. The first time we |
8529 canonicalize the switches to keep only the ones we care about. */ | 8625 canonicalize the switches to keep only the ones we care about. */ |
8530 | 8626 |
8531 class used_arg_t | 8627 struct used_arg_t |
8532 { | 8628 { |
8533 public: | 8629 public: |
8534 int operator () (const char *p, int len); | 8630 int operator () (const char *p, int len); |
8535 void finalize (); | 8631 void finalize (); |
8536 | 8632 |
9752 return NULL; | 9848 return NULL; |
9753 | 9849 |
9754 len = strlen (argv[0]); | 9850 len = strlen (argv[0]); |
9755 if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) | 9851 if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) |
9756 fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt " | 9852 fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt " |
9757 "does not end in .gk"); | 9853 "does not end in %<.gk%>"); |
9758 | 9854 |
9759 if (debug_auxbase_opt) | 9855 if (debug_auxbase_opt) |
9760 return debug_auxbase_opt; | 9856 return debug_auxbase_opt; |
9761 | 9857 |
9762 #define OPT "-auxbase " | 9858 #define OPT "-auxbase " |
9889 return ""; | 9985 return ""; |
9890 | 9986 |
9891 return NULL; | 9987 return NULL; |
9892 } | 9988 } |
9893 | 9989 |
9990 static void | |
9991 path_prefix_reset (path_prefix *prefix) | |
9992 { | |
9993 struct prefix_list *iter, *next; | |
9994 iter = prefix->plist; | |
9995 while (iter) | |
9996 { | |
9997 next = iter->next; | |
9998 free (const_cast <char *> (iter->prefix)); | |
9999 XDELETE (iter); | |
10000 iter = next; | |
10001 } | |
10002 prefix->plist = 0; | |
10003 prefix->max_len = 0; | |
10004 } | |
10005 | |
10006 /* The function takes 3 arguments: OPTION name, file name and location | |
10007 where we search for Fortran modules. | |
10008 When the FILE is found by find_file, return OPTION=path_to_file. */ | |
10009 | |
10010 static const char * | |
10011 find_fortran_preinclude_file (int argc, const char **argv) | |
10012 { | |
10013 char *result = NULL; | |
10014 if (argc != 3) | |
10015 return NULL; | |
10016 | |
10017 struct path_prefix prefixes = { 0, 0, "preinclude" }; | |
10018 | |
10019 /* Search first for 'finclude' folder location for a header file | |
10020 installed by the compiler (similar to omp_lib.h). */ | |
10021 add_prefix (&prefixes, argv[2], NULL, 0, 0, 0); | |
10022 #ifdef TOOL_INCLUDE_DIR | |
10023 /* Then search: <prefix>/<target>/<include>/finclude */ | |
10024 add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/", | |
10025 NULL, 0, 0, 0); | |
10026 #endif | |
10027 #ifdef NATIVE_SYSTEM_HEADER_DIR | |
10028 /* Then search: <sysroot>/usr/include/finclude/<multilib> */ | |
10029 add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/", | |
10030 NULL, 0, 0, 0); | |
10031 #endif | |
10032 | |
10033 const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false); | |
10034 if (path != NULL) | |
10035 result = concat (argv[0], path, NULL); | |
10036 else | |
10037 { | |
10038 path = find_a_file (&prefixes, argv[1], R_OK, false); | |
10039 if (path != NULL) | |
10040 result = concat (argv[0], path, NULL); | |
10041 } | |
10042 | |
10043 path_prefix_reset (&prefixes); | |
10044 return result; | |
10045 } | |
10046 | |
10047 | |
9894 /* Insert backslash before spaces in ORIG (usually a file path), to | 10048 /* Insert backslash before spaces in ORIG (usually a file path), to |
9895 avoid being broken by spec parser. | 10049 avoid being broken by spec parser. |
9896 | 10050 |
9897 This function is needed as do_spec_1 treats white space (' ' and '\t') | 10051 This function is needed as do_spec_1 treats white space (' ' and '\t') |
9898 as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so, | 10052 as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so, |
9937 } | 10091 } |
9938 else | 10092 else |
9939 return orig; | 10093 return orig; |
9940 } | 10094 } |
9941 | 10095 |
9942 static void | |
9943 path_prefix_reset (path_prefix *prefix) | |
9944 { | |
9945 struct prefix_list *iter, *next; | |
9946 iter = prefix->plist; | |
9947 while (iter) | |
9948 { | |
9949 next = iter->next; | |
9950 free (const_cast <char *> (iter->prefix)); | |
9951 XDELETE (iter); | |
9952 iter = next; | |
9953 } | |
9954 prefix->plist = 0; | |
9955 prefix->max_len = 0; | |
9956 } | |
9957 | |
9958 /* Restore all state within gcc.c to the initial state, so that the driver | 10096 /* Restore all state within gcc.c to the initial state, so that the driver |
9959 code can be safely re-run in-process. | 10097 code can be safely re-run in-process. |
9960 | 10098 |
9961 Many const char * variables are referenced by static specs (see | 10099 Many const char * variables are referenced by static specs (see |
9962 INIT_STATIC_SPEC above). These variables are restored to their default | 10100 INIT_STATIC_SPEC above). These variables are restored to their default |
9972 | 10110 |
9973 void | 10111 void |
9974 driver::finalize () | 10112 driver::finalize () |
9975 { | 10113 { |
9976 env.restore (); | 10114 env.restore (); |
9977 params_c_finalize (); | |
9978 diagnostic_finish (global_dc); | 10115 diagnostic_finish (global_dc); |
9979 | 10116 |
9980 is_cpp_driver = 0; | 10117 is_cpp_driver = 0; |
9981 at_file_supplied = 0; | 10118 at_file_supplied = 0; |
9982 print_help_list = 0; | 10119 print_help_list = 0; |
9992 save_temps_flag = SAVE_TEMPS_NONE; | 10129 save_temps_flag = SAVE_TEMPS_NONE; |
9993 save_temps_prefix = 0; | 10130 save_temps_prefix = 0; |
9994 save_temps_length = 0; | 10131 save_temps_length = 0; |
9995 spec_machine = DEFAULT_TARGET_MACHINE; | 10132 spec_machine = DEFAULT_TARGET_MACHINE; |
9996 greatest_status = 1; | 10133 greatest_status = 1; |
9997 | |
9998 finalize_options_struct (&global_options); | |
9999 finalize_options_struct (&global_options_set); | |
10000 | 10134 |
10001 obstack_free (&obstack, NULL); | 10135 obstack_free (&obstack, NULL); |
10002 obstack_free (&opts_obstack, NULL); /* in opts.c */ | 10136 obstack_free (&opts_obstack, NULL); /* in opts.c */ |
10003 obstack_free (&collect_obstack, NULL); | 10137 obstack_free (&collect_obstack, NULL); |
10004 | 10138 |