Mercurial > hg > CbC > CbC_gcc
diff 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 |
line wrap: on
line diff
--- a/gcc/gcc.c Sun Dec 23 21:23:56 2018 +0900 +++ b/gcc/gcc.c Sun Mar 01 16:13:28 2020 +0900 @@ -1,5 +1,5 @@ /* Compiler driver program that can handle many languages. - Copyright (C) 1987-2018 Free Software Foundation, Inc. + Copyright (C) 1987-2020 Free Software Foundation, Inc. This file is part of GCC. @@ -41,7 +41,6 @@ #include "diagnostic.h" #include "flags.h" #include "opts.h" -#include "params.h" #include "filenames.h" #include "spellcheck.h" @@ -57,7 +56,7 @@ getenv (); Hence we need to use "get" for the accessor method, not "getenv". */ -class env_manager +struct env_manager { public: void init (bool can_restore, bool debug); @@ -408,6 +407,7 @@ static const char *replace_extension_spec_func (int, const char **); static const char *greater_than_spec_func (int, const char **); static const char *debug_level_greater_than_spec_func (int, const char **); +static const char *find_fortran_preinclude_file (int, const char **); static char *convert_white_space (char *); /* The Specs Language @@ -1305,6 +1305,7 @@ {".f08", "#Fortran", 0, 0, 0}, {".F08", "#Fortran", 0, 0, 0}, {".r", "#Ratfor", 0, 0, 0}, {".go", "#Go", 0, 1, 0}, + {".d", "#D", 0, 1, 0}, {".dd", "#D", 0, 1, 0}, {".di", "#D", 0, 1, 0}, /* Next come the entries for C. */ {".c", "@c", 0, 0, 1}, #ifndef noCbC @@ -1649,6 +1650,7 @@ { "replace-extension", replace_extension_spec_func }, { "gt", greater_than_spec_func }, { "debug-level-gt", debug_level_greater_than_spec_func }, + { "fortran-preinclude-file", find_fortran_preinclude_file}, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -2976,6 +2978,44 @@ add_prefix (pprefix, prefix, component, priority, require_machine_suffix, os_multilib); } + +/* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */ + +static void +add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, + const char *component, + /* enum prefix_priority */ int priority, + int require_machine_suffix, int os_multilib) +{ + if (!IS_ABSOLUTE_PATH (prefix)) + fatal_error (input_location, "system path %qs is not absolute", prefix); + + if (target_system_root) + { + char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); + size_t sysroot_len = strlen (target_system_root); + + if (sysroot_len > 0 + && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) + sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; + + if (target_sysroot_hdrs_suffix) + prefix = concat (sysroot_no_trailing_dir_separator, + target_sysroot_hdrs_suffix, prefix, NULL); + else + prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); + + free (sysroot_no_trailing_dir_separator); + + /* We have to override this because GCC's notion of sysroot + moves along with GCC. */ + component = "GCC"; + } + + add_prefix (pprefix, prefix, component, priority, + require_machine_suffix, os_multilib); +} + /* Execute the command specified by the arguments on the current line of spec. When using pipes, this includes several piped-together commands @@ -3030,17 +3070,17 @@ if (!wrapper_string) { string = find_a_file (&exec_prefixes, commands[0].prog, X_OK, false); - commands[0].argv[0] = (string) ? string : commands[0].argv[0]; + if (string) + commands[0].argv[0] = string; } for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++) if (arg && strcmp (arg, "|") == 0) { /* each command. */ #if defined (__MSDOS__) || defined (OS2) || defined (VMS) - fatal_error (input_location, "-pipe not supported"); -#endif - argbuf[i] = 0; /* Termination of - command args. */ + fatal_error (input_location, "%<-pipe%> not supported"); +#endif + argbuf[i] = 0; /* Termination of command args. */ commands[n_commands].prog = argbuf[i + 1]; commands[n_commands].argv = &(argbuf.address ())[i + 1]; @@ -3160,7 +3200,7 @@ ? PEX_RECORD_TIMES : 0), progname, temp_filename); if (pex == NULL) - fatal_error (input_location, "pex_init failed: %m"); + fatal_error (input_location, "%<pex_init%> failed: %m"); for (i = 0; i < n_commands; i++) { @@ -3731,7 +3771,7 @@ const struct cl_option *option = &cl_options[decoded->opt_index]; if (option->cl_reject_driver) - error ("unrecognized command line option %qs", + error ("unrecognized command-line option %qs", decoded->orig_option_with_args_text); else save_switch (decoded->canonical_option[0], @@ -4003,6 +4043,15 @@ diagnostic_color_init (dc, value); break; + case OPT_fdiagnostics_urls_: + diagnostic_urls_init (dc, value); + break; + + case OPT_fdiagnostics_format_: + diagnostic_output_format_init (dc, + (enum diagnostics_output_format)value); + break; + case OPT_Wa_: { int prev, j; @@ -4105,7 +4154,7 @@ || strcmp (arg, "object") == 0) save_temps_flag = SAVE_TEMPS_OBJ; else - fatal_error (input_location, "%qs is an unknown -save-temps option", + fatal_error (input_location, "%qs is an unknown %<-save-temps%> option", decoded->orig_option_with_args_text); break; @@ -4608,7 +4657,7 @@ { /* -save-temps overrides -pipe, so that temp files are produced */ if (save_temps_flag) - warning (0, "-pipe ignored because -save-temps specified"); + warning (0, "%<-pipe%> ignored because %<-save-temps%> specified"); use_pipes = 0; } @@ -4695,7 +4744,7 @@ /* More prefixes are enabled in main, after we read the specs file and determine whether this is cross-compilation or not. */ - if (n_infiles == last_language_n_infiles && spec_lang != 0) + if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0) warning (0, "%<-x %s%> after last input file has no effect", spec_lang); /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG @@ -4708,10 +4757,9 @@ } /* Ensure we only invoke each subprocess once. */ - if (print_subprocess_help || print_help_list || print_version) - { - n_infiles = 0; - + if (n_infiles == 0 + && (print_subprocess_help || print_help_list || print_version)) + { /* Create a dummy input file, so that we can pass the help option on to the various sub-processes. */ add_infile ("help-dummy", "c"); @@ -6096,7 +6144,8 @@ alloc_args (); if (do_spec_2 (args, soft_matched_part) < 0) - fatal_error (input_location, "error in args to spec function %qs", func); + fatal_error (input_location, "error in arguments to spec function %qs", + func); /* argbuf_index is an index for the next argument to be inserted, and so contains the count of the args already inserted. */ @@ -6748,6 +6797,11 @@ #endif fnotice (file, "Thread model: %s\n", thrmod); + fnotice (file, "Supported LTO compression algorithms: zlib"); +#ifdef HAVE_ZSTD_H + fnotice (file, " zstd"); +#endif + fnotice (file, "\n"); /* compiler_version is truncated at the first space when initialized from version string, so truncate version_string at the first space @@ -6881,11 +6935,11 @@ pex = pex_init (PEX_USE_PIPES, new_argv[0], NULL); if (!pex) - fatal_error (input_location, "pex_init failed: %m"); + fatal_error (input_location, "%<pex_init%> failed: %m"); errmsg = pex_run (pex, pex_flags, new_argv[0], - CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, - err_temp, &err); + CONST_CAST2 (char *const *, const char **, &new_argv[1]), + out_temp, err_temp, &err); if (errmsg != NULL) { errno = err; @@ -7200,7 +7254,7 @@ if (!ret && length[0] != length[1]) { - error ("%s: -fcompare-debug failure (length)", gcc_input_filename); + error ("%s: %<-fcompare-debug%> failure (length)", gcc_input_filename); ret = 1; } @@ -7230,7 +7284,7 @@ { if (memcmp (map[0], map[1], length[0]) != 0) { - error ("%s: -fcompare-debug failure", gcc_input_filename); + error ("%s: %<-fcompare-debug%> failure", gcc_input_filename); ret = 1; } } @@ -7267,7 +7321,7 @@ if (c0 != c1) { - error ("%s: -fcompare-debug failure", + error ("%s: %<-fcompare-debug%> failure", gcc_input_filename); ret = 1; break; @@ -7371,10 +7425,6 @@ void driver::decode_argv (int argc, const char **argv) { - /* Register the language-independent parameters. */ - global_init_params (); - finish_params (); - init_opts_obstack (); init_options_struct (&global_options, &global_options_set); @@ -7395,6 +7445,7 @@ diagnostic_initialize (global_dc, 0); diagnostic_color_init (global_dc); + diagnostic_urls_init (global_dc); #ifdef GCC_DRIVER_HOST_INITIALIZATION /* Perform host dependent initialization when needed. */ @@ -7572,7 +7623,8 @@ && do_spec_2 (sysroot_suffix_spec, NULL) == 0) { if (argbuf.length () > 1) - error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); + error ("spec failure: more than one argument to " + "%<SYSROOT_SUFFIX_SPEC%>"); else if (argbuf.length () == 1) target_sysroot_suffix = xstrdup (argbuf.last ()); } @@ -7596,7 +7648,8 @@ && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) { if (argbuf.length () > 1) - error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); + error ("spec failure: more than one argument " + "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>"); else if (argbuf.length () == 1) target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); } @@ -7801,11 +7854,11 @@ { const char *hint = m_option_proposer.suggest_option (switches[i].part1); if (hint) - error ("unrecognized command line option %<-%s%>;" + error ("unrecognized command-line option %<-%s%>;" " did you mean %<-%s%>?", switches[i].part1, hint); else - error ("unrecognized command line option %<-%s%>", + error ("unrecognized command-line option %<-%s%>", switches[i].part1); } } @@ -7958,7 +8011,7 @@ { printf (_("%s %s%s\n"), progname, pkgversion_string, version_string); - printf ("Copyright %s 2018 Free Software Foundation, Inc.\n", + printf ("Copyright %s 2020 Free Software Foundation, Inc.\n", _("(C)")); fputs (_("This is free software; see the source for copying conditions. There is NO\n\ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), @@ -8043,7 +8096,8 @@ if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) fatal_error (input_location, - "cannot specify -o with -c, -S or -E with multiple files"); + "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> " + "with multiple files"); /* No early exit needed from main; we can continue. */ return false; @@ -8109,7 +8163,7 @@ { if (verbose_flag) inform (UNKNOWN_LOCATION, - "recompiling with -fcompare-debug"); + "recompiling with %<-fcompare-debug%>"); compare_debug = -compare_debug; n_switches = n_switches_debug_check[1]; @@ -8125,7 +8179,7 @@ if (value < 0) { - error ("during -fcompare-debug recompilation"); + error ("during %<-fcompare-debug%> recompilation"); this_file_error = 1; } @@ -8217,6 +8271,8 @@ { int tmp = execution_count; + detect_jobserver (); + if (! have_c) { #if HAVE_LTO_PLUGIN > 0 @@ -8251,7 +8307,7 @@ false); if (!temp_spec) fatal_error (input_location, - "-fuse-linker-plugin, but %s not found", + "%<-fuse-linker-plugin%>, but %s not found", LTOPLUGINSONAME); linker_plugin_file_spec = convert_white_space (temp_spec); } @@ -8306,6 +8362,46 @@ } } +/* Detect whether jobserver is active and working. If not drop + --jobserver-auth from MAKEFLAGS. */ + +void +driver::detect_jobserver () const +{ + /* Detect jobserver and drop it if it's not working. */ + const char *makeflags = env.get ("MAKEFLAGS"); + if (makeflags != NULL) + { + const char *needle = "--jobserver-auth="; + const char *n = strstr (makeflags, needle); + if (n != NULL) + { + int rfd = -1; + int wfd = -1; + + bool jobserver + = (sscanf (n + strlen (needle), "%d,%d", &rfd, &wfd) == 2 + && rfd > 0 + && wfd > 0 + && is_valid_fd (rfd) + && is_valid_fd (wfd)); + + /* Drop the jobserver if it's not working now. */ + if (!jobserver) + { + unsigned offset = n - makeflags; + char *dup = xstrdup (makeflags); + dup[offset] = '\0'; + + const char *space = strchr (makeflags + offset, ' '); + if (space != NULL) + strcpy (dup + offset, space); + xputenv (concat ("MAKEFLAGS=", dup, NULL)); + } + } + } +} + /* Determine what the exit code of the driver should be. */ int @@ -8528,7 +8624,7 @@ /* Check whether a particular argument was used. The first time we canonicalize the switches to keep only the ones we care about. */ -class used_arg_t +struct used_arg_t { public: int operator () (const char *p, int len); @@ -9754,7 +9850,7 @@ len = strlen (argv[0]); if (len < 3 || strcmp (argv[0] + len - 3, ".gk") != 0) fatal_error (input_location, "argument to %%:compare-debug-auxbase-opt " - "does not end in .gk"); + "does not end in %<.gk%>"); if (debug_auxbase_opt) return debug_auxbase_opt; @@ -9891,6 +9987,64 @@ return NULL; } +static void +path_prefix_reset (path_prefix *prefix) +{ + struct prefix_list *iter, *next; + iter = prefix->plist; + while (iter) + { + next = iter->next; + free (const_cast <char *> (iter->prefix)); + XDELETE (iter); + iter = next; + } + prefix->plist = 0; + prefix->max_len = 0; +} + +/* The function takes 3 arguments: OPTION name, file name and location + where we search for Fortran modules. + When the FILE is found by find_file, return OPTION=path_to_file. */ + +static const char * +find_fortran_preinclude_file (int argc, const char **argv) +{ + char *result = NULL; + if (argc != 3) + return NULL; + + struct path_prefix prefixes = { 0, 0, "preinclude" }; + + /* Search first for 'finclude' folder location for a header file + installed by the compiler (similar to omp_lib.h). */ + add_prefix (&prefixes, argv[2], NULL, 0, 0, 0); +#ifdef TOOL_INCLUDE_DIR + /* Then search: <prefix>/<target>/<include>/finclude */ + add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/", + NULL, 0, 0, 0); +#endif +#ifdef NATIVE_SYSTEM_HEADER_DIR + /* Then search: <sysroot>/usr/include/finclude/<multilib> */ + add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/", + NULL, 0, 0, 0); +#endif + + const char *path = find_a_file (&include_prefixes, argv[1], R_OK, false); + if (path != NULL) + result = concat (argv[0], path, NULL); + else + { + path = find_a_file (&prefixes, argv[1], R_OK, false); + if (path != NULL) + result = concat (argv[0], path, NULL); + } + + path_prefix_reset (&prefixes); + return result; +} + + /* Insert backslash before spaces in ORIG (usually a file path), to avoid being broken by spec parser. @@ -9939,22 +10093,6 @@ return orig; } -static void -path_prefix_reset (path_prefix *prefix) -{ - struct prefix_list *iter, *next; - iter = prefix->plist; - while (iter) - { - next = iter->next; - free (const_cast <char *> (iter->prefix)); - XDELETE (iter); - iter = next; - } - prefix->plist = 0; - prefix->max_len = 0; -} - /* Restore all state within gcc.c to the initial state, so that the driver code can be safely re-run in-process. @@ -9974,7 +10112,6 @@ driver::finalize () { env.restore (); - params_c_finalize (); diagnostic_finish (global_dc); is_cpp_driver = 0; @@ -9995,9 +10132,6 @@ spec_machine = DEFAULT_TARGET_MACHINE; greatest_status = 1; - finalize_options_struct (&global_options); - finalize_options_struct (&global_options_set); - obstack_free (&obstack, NULL); obstack_free (&opts_obstack, NULL); /* in opts.c */ obstack_free (&collect_obstack, NULL);