Mercurial > hg > CbC > CbC_gcc
comparison gcc/gcc.c @ 132:d34655255c78
update gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 10:21:07 +0900 |
parents | ab0bcb71f44d 84e7813d76e9 |
children | 351920fa3827 |
comparison
equal
deleted
inserted
replaced
130:e108057fa461 | 132:d34655255c78 |
---|---|
1 /* Compiler driver program that can handle many languages. | 1 /* Compiler driver program that can handle many languages. |
2 Copyright (C) 1987-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1987-2018 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 |
34 #include "tm.h" | 34 #include "tm.h" |
35 #include "xregex.h" | 35 #include "xregex.h" |
36 #include "obstack.h" | 36 #include "obstack.h" |
37 #include "intl.h" | 37 #include "intl.h" |
38 #include "prefix.h" | 38 #include "prefix.h" |
39 #include "opt-suggestions.h" | |
39 #include "gcc.h" | 40 #include "gcc.h" |
40 #include "diagnostic.h" | 41 #include "diagnostic.h" |
41 #include "flags.h" | 42 #include "flags.h" |
42 #include "opts.h" | 43 #include "opts.h" |
43 #include "params.h" | 44 #include "params.h" |
168 #endif | 169 #endif |
169 | 170 |
170 | 171 |
171 | 172 |
172 /* By default there is no special suffix for target executables. */ | 173 /* By default there is no special suffix for target executables. */ |
173 /* FIXME: when autoconf is fixed, remove the host check - dj */ | 174 #ifdef TARGET_EXECUTABLE_SUFFIX |
174 #if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX) | |
175 #define HAVE_TARGET_EXECUTABLE_SUFFIX | 175 #define HAVE_TARGET_EXECUTABLE_SUFFIX |
176 #else | |
177 #define TARGET_EXECUTABLE_SUFFIX "" | |
176 #endif | 178 #endif |
177 | 179 |
178 /* By default there is no special suffix for host executables. */ | 180 /* By default there is no special suffix for host executables. */ |
179 #ifdef HOST_EXECUTABLE_SUFFIX | 181 #ifdef HOST_EXECUTABLE_SUFFIX |
180 #define HAVE_HOST_EXECUTABLE_SUFFIX | 182 #define HAVE_HOST_EXECUTABLE_SUFFIX |
216 static int print_help_list; | 218 static int print_help_list; |
217 | 219 |
218 /* Flag saying to print the version of gcc and its sub-processes. */ | 220 /* Flag saying to print the version of gcc and its sub-processes. */ |
219 | 221 |
220 static int print_version; | 222 static int print_version; |
223 | |
224 /* Flag that stores string prefix for which we provide bash completion. */ | |
225 | |
226 static const char *completion = NULL; | |
221 | 227 |
222 /* Flag indicating whether we should ONLY print the command and | 228 /* Flag indicating whether we should ONLY print the command and |
223 arguments (like verbose_flag) without executing the command. | 229 arguments (like verbose_flag) without executing the command. |
224 Displayed arguments are quoted so that the generated command | 230 Displayed arguments are quoted so that the generated command |
225 line is suitable for execution. This is intended for use in | 231 line is suitable for execution. This is intended for use in |
347 static inline bool switch_matches (const char *, const char *, int); | 353 static inline bool switch_matches (const char *, const char *, int); |
348 static inline void mark_matching_switches (const char *, const char *, int); | 354 static inline void mark_matching_switches (const char *, const char *, int); |
349 static inline void process_marked_switches (void); | 355 static inline void process_marked_switches (void); |
350 static const char *process_brace_body (const char *, const char *, const char *, int, int); | 356 static const char *process_brace_body (const char *, const char *, const char *, int, int); |
351 static const struct spec_function *lookup_spec_function (const char *); | 357 static const struct spec_function *lookup_spec_function (const char *); |
352 static const char *eval_spec_function (const char *, const char *); | 358 static const char *eval_spec_function (const char *, const char *, const char *); |
353 static const char *handle_spec_function (const char *, bool *); | 359 static const char *handle_spec_function (const char *, bool *, const char *); |
354 static char *save_string (const char *, int); | 360 static char *save_string (const char *, int); |
355 static void set_collect_gcc_options (void); | 361 static void set_collect_gcc_options (void); |
356 static int do_spec_1 (const char *, int, const char *); | 362 static int do_spec_1 (const char *, int, const char *); |
357 static int do_spec_2 (const char *); | 363 static int do_spec_2 (const char *, const char *); |
358 static void do_option_spec (const char *, const char *); | 364 static void do_option_spec (const char *, const char *); |
359 static void do_self_spec (const char *); | 365 static void do_self_spec (const char *); |
360 static const char *find_file (const char *); | 366 static const char *find_file (const char *); |
361 static int is_directory (const char *, bool); | 367 static int is_directory (const char *, bool); |
362 static const char *validate_switches (const char *, bool); | 368 static const char *validate_switches (const char *, bool); |
364 static inline void validate_switches_from_spec (const char *, bool); | 370 static inline void validate_switches_from_spec (const char *, bool); |
365 static void give_switch (int, int); | 371 static void give_switch (int, int); |
366 static int default_arg (const char *, int); | 372 static int default_arg (const char *, int); |
367 static void set_multilib_dir (void); | 373 static void set_multilib_dir (void); |
368 static void print_multilib_info (void); | 374 static void print_multilib_info (void); |
369 static void perror_with_name (const char *); | |
370 static void display_help (void); | 375 static void display_help (void); |
371 static void add_preprocessor_option (const char *, int); | 376 static void add_preprocessor_option (const char *, int); |
372 static void add_assembler_option (const char *, int); | 377 static void add_assembler_option (const char *, int); |
373 static void add_linker_option (const char *, int); | 378 static void add_linker_option (const char *, int); |
374 static void process_command (unsigned int, struct cl_decoded_option *); | 379 static void process_command (unsigned int, struct cl_decoded_option *); |
473 %w marks the argument containing or following the %w as the | 478 %w marks the argument containing or following the %w as the |
474 "output file" of this compilation. This puts the argument | 479 "output file" of this compilation. This puts the argument |
475 into the sequence of arguments that %o will substitute later. | 480 into the sequence of arguments that %o will substitute later. |
476 %V indicates that this compilation produces no "output file". | 481 %V indicates that this compilation produces no "output file". |
477 %W{...} | 482 %W{...} |
478 like %{...} but mark last argument supplied within | 483 like %{...} but marks the last argument supplied within as a file |
479 as a file to be deleted on failure. | 484 to be deleted on failure. |
485 %@{...} | |
486 like %{...} but puts the result into a FILE and substitutes @FILE | |
487 if an @file argument has been supplied. | |
480 %o substitutes the names of all the output files, with spaces | 488 %o substitutes the names of all the output files, with spaces |
481 automatically placed around them. You should write spaces | 489 automatically placed around them. You should write spaces |
482 around the %o as well or the results are undefined. | 490 around the %o as well or the results are undefined. |
483 %o is for use in the specs for running the linker. | 491 %o is for use in the specs for running the linker. |
484 Input files whose names have no recognized suffix are not compiled | 492 Input files whose names have no recognized suffix are not compiled |
681 #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" | 689 #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" |
682 #endif | 690 #endif |
683 | 691 |
684 #ifndef LIBASAN_SPEC | 692 #ifndef LIBASAN_SPEC |
685 #define STATIC_LIBASAN_LIBS \ | 693 #define STATIC_LIBASAN_LIBS \ |
686 " %{static-libasan:%:include(libsanitizer.spec)%(link_libasan)}" | 694 " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}" |
687 #ifdef LIBASAN_EARLY_SPEC | 695 #ifdef LIBASAN_EARLY_SPEC |
688 #define LIBASAN_SPEC STATIC_LIBASAN_LIBS | 696 #define LIBASAN_SPEC STATIC_LIBASAN_LIBS |
689 #elif defined(HAVE_LD_STATIC_DYNAMIC) | 697 #elif defined(HAVE_LD_STATIC_DYNAMIC) |
690 #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ | 698 #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ |
691 "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ | 699 "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ |
699 #define LIBASAN_EARLY_SPEC "" | 707 #define LIBASAN_EARLY_SPEC "" |
700 #endif | 708 #endif |
701 | 709 |
702 #ifndef LIBTSAN_SPEC | 710 #ifndef LIBTSAN_SPEC |
703 #define STATIC_LIBTSAN_LIBS \ | 711 #define STATIC_LIBTSAN_LIBS \ |
704 " %{static-libtsan:%:include(libsanitizer.spec)%(link_libtsan)}" | 712 " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}" |
705 #ifdef LIBTSAN_EARLY_SPEC | 713 #ifdef LIBTSAN_EARLY_SPEC |
706 #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS | 714 #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS |
707 #elif defined(HAVE_LD_STATIC_DYNAMIC) | 715 #elif defined(HAVE_LD_STATIC_DYNAMIC) |
708 #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ | 716 #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ |
709 "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ | 717 "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ |
717 #define LIBTSAN_EARLY_SPEC "" | 725 #define LIBTSAN_EARLY_SPEC "" |
718 #endif | 726 #endif |
719 | 727 |
720 #ifndef LIBLSAN_SPEC | 728 #ifndef LIBLSAN_SPEC |
721 #define STATIC_LIBLSAN_LIBS \ | 729 #define STATIC_LIBLSAN_LIBS \ |
722 " %{static-liblsan:%:include(libsanitizer.spec)%(link_liblsan)}" | 730 " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}" |
723 #ifdef LIBLSAN_EARLY_SPEC | 731 #ifdef LIBLSAN_EARLY_SPEC |
724 #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS | 732 #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS |
725 #elif defined(HAVE_LD_STATIC_DYNAMIC) | 733 #elif defined(HAVE_LD_STATIC_DYNAMIC) |
726 #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \ | 734 #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \ |
727 "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ | 735 "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ |
735 #define LIBLSAN_EARLY_SPEC "" | 743 #define LIBLSAN_EARLY_SPEC "" |
736 #endif | 744 #endif |
737 | 745 |
738 #ifndef LIBUBSAN_SPEC | 746 #ifndef LIBUBSAN_SPEC |
739 #define STATIC_LIBUBSAN_LIBS \ | 747 #define STATIC_LIBUBSAN_LIBS \ |
740 " %{static-libubsan:%:include(libsanitizer.spec)%(link_libubsan)}" | 748 " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}" |
741 #ifdef HAVE_LD_STATIC_DYNAMIC | 749 #ifdef HAVE_LD_STATIC_DYNAMIC |
742 #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ | 750 #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ |
743 "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ | 751 "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ |
744 STATIC_LIBUBSAN_LIBS | 752 STATIC_LIBUBSAN_LIBS |
745 #else | 753 #else |
861 | 869 |
862 /* This is overridable by the target in case they need to specify the | 870 /* This is overridable by the target in case they need to specify the |
863 -lgcc and -lc order specially, yet not require them to override all | 871 -lgcc and -lc order specially, yet not require them to override all |
864 of LINK_COMMAND_SPEC. */ | 872 of LINK_COMMAND_SPEC. */ |
865 #ifndef LINK_GCC_C_SEQUENCE_SPEC | 873 #ifndef LINK_GCC_C_SEQUENCE_SPEC |
866 #define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G" | 874 #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" |
867 #endif | 875 #endif |
868 | 876 |
869 #ifndef LINK_SSP_SPEC | 877 #ifndef LINK_SSP_SPEC |
870 #ifdef TARGET_LIBC_PROVIDES_SSP | 878 #ifdef TARGET_LIBC_PROVIDES_SSP |
871 #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ | 879 #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ |
958 #define LINK_PLUGIN_SPEC \ | 966 #define LINK_PLUGIN_SPEC \ |
959 "%{" PLUGIN_COND": \ | 967 "%{" PLUGIN_COND": \ |
960 -plugin %(linker_plugin_file) \ | 968 -plugin %(linker_plugin_file) \ |
961 -plugin-opt=%(lto_wrapper) \ | 969 -plugin-opt=%(lto_wrapper) \ |
962 -plugin-opt=-fresolution=%u.res \ | 970 -plugin-opt=-fresolution=%u.res \ |
971 %{flinker-output=*:-plugin-opt=-linker-output-known} \ | |
963 %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \ | 972 %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \ |
964 }" PLUGIN_COND_CLOSE | 973 }" PLUGIN_COND_CLOSE |
965 #else | 974 #else |
966 /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */ | 975 /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */ |
967 #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\ | 976 #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\ |
969 #endif | 978 #endif |
970 | 979 |
971 /* Linker command line options for -fsanitize= early on the command line. */ | 980 /* Linker command line options for -fsanitize= early on the command line. */ |
972 #ifndef SANITIZER_EARLY_SPEC | 981 #ifndef SANITIZER_EARLY_SPEC |
973 #define SANITIZER_EARLY_SPEC "\ | 982 #define SANITIZER_EARLY_SPEC "\ |
974 %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \ | 983 %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \ |
975 %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \ | 984 %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \ |
976 %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}" | 985 %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}" |
977 #endif | 986 #endif |
978 | 987 |
979 /* Linker command line options for -fsanitize= late on the command line. */ | 988 /* Linker command line options for -fsanitize= late on the command line. */ |
980 #ifndef SANITIZER_SPEC | 989 #ifndef SANITIZER_SPEC |
981 #define SANITIZER_SPEC "\ | 990 #define SANITIZER_SPEC "\ |
982 %{!nostdlib:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\ | 991 %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\ |
983 %{static:%ecannot specify -static with -fsanitize=address}}\ | 992 %{static:%ecannot specify -static with -fsanitize=address}}\ |
984 %{%:sanitize(thread):" LIBTSAN_SPEC "\ | 993 %{%:sanitize(thread):" LIBTSAN_SPEC "\ |
985 %{static:%ecannot specify -static with -fsanitize=thread}}\ | 994 %{static:%ecannot specify -static with -fsanitize=thread}}\ |
986 %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\ | 995 %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\ |
987 %{%:sanitize(leak):" LIBLSAN_SPEC "}}}" | 996 %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}" |
988 #endif | 997 #endif |
989 | 998 |
990 #ifndef POST_LINK_SPEC | 999 #ifndef POST_LINK_SPEC |
991 #define POST_LINK_SPEC "" | 1000 #define POST_LINK_SPEC "" |
992 #endif | 1001 #endif |
996 the vtable verification runtime functions are in libstdc++, so we use | 1005 the vtable verification runtime functions are in libstdc++, so we use |
997 the spec just below this one. */ | 1006 the spec just below this one. */ |
998 #ifndef VTABLE_VERIFICATION_SPEC | 1007 #ifndef VTABLE_VERIFICATION_SPEC |
999 #if ENABLE_VTABLE_VERIFY | 1008 #if ENABLE_VTABLE_VERIFY |
1000 #define VTABLE_VERIFICATION_SPEC "\ | 1009 #define VTABLE_VERIFICATION_SPEC "\ |
1001 %{!nostdlib:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\ | 1010 %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\ |
1002 %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}" | 1011 %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}" |
1003 #else | 1012 #else |
1004 #define VTABLE_VERIFICATION_SPEC "\ | 1013 #define VTABLE_VERIFICATION_SPEC "\ |
1005 %{fvtable-verify=none:} \ | 1014 %{fvtable-verify=none:} \ |
1006 %{fvtable-verify=std: \ | 1015 %{fvtable-verify=std: \ |
1007 %e-fvtable-verify=std is not supported in this configuration} \ | 1016 %e-fvtable-verify=std is not supported in this configuration} \ |
1008 %{fvtable-verify=preinit: \ | 1017 %{fvtable-verify=preinit: \ |
1009 %e-fvtable-verify=preinit is not supported in this configuration}" | 1018 %e-fvtable-verify=preinit is not supported in this configuration}" |
1010 #endif | 1019 #endif |
1011 #endif | |
1012 | |
1013 #ifndef CHKP_SPEC | |
1014 #define CHKP_SPEC "" | |
1015 #endif | 1020 #endif |
1016 | 1021 |
1017 /* -u* was put back because both BSD and SysV seem to support it. */ | 1022 /* -u* was put back because both BSD and SysV seem to support it. */ |
1018 /* %{static|no-pie|static-pie:} simply prevents an error message: | 1023 /* %{static|no-pie|static-pie:} simply prevents an error message: |
1019 1. If the target machine doesn't handle -static. | 1024 1. If the target machine doesn't handle -static. |
1033 LINK_PLUGIN_SPEC \ | 1038 LINK_PLUGIN_SPEC \ |
1034 "%{flto|flto=*:%<fcompare-debug*} \ | 1039 "%{flto|flto=*:%<fcompare-debug*} \ |
1035 %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \ | 1040 %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \ |
1036 "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ | 1041 "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ |
1037 "%X %{o*} %{e*} %{N} %{n} %{r}\ | 1042 "%X %{o*} %{e*} %{N} %{n} %{r}\ |
1038 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!nostartfiles:%S}} \ | 1043 %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ |
1039 %{static|no-pie|static-pie:} %{L*} %(mfwrap) %(link_libgcc) " \ | 1044 %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) " \ |
1040 VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o " CHKP_SPEC " \ | 1045 VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ |
1041 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ | 1046 %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ |
1042 %:include(libgomp.spec)%(link_gomp)}\ | 1047 %:include(libgomp.spec)%(link_gomp)}\ |
1043 %{fcilkplus:%:include(libcilkrts.spec)%(link_cilkrts)}\ | |
1044 %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ | 1048 %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ |
1045 %(mflib) " STACK_SPLIT_SPEC "\ | 1049 %(mflib) " STACK_SPLIT_SPEC "\ |
1046 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ | 1050 %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ |
1047 %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ | 1051 %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\ |
1048 %{!nostdlib:%{!nostartfiles:%E}} %{T*} \n%(post_link) }}}}}}" | 1052 %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}" |
1049 #endif | 1053 #endif |
1050 | 1054 |
1051 #ifndef LINK_LIBGCC_SPEC | 1055 #ifndef LINK_LIBGCC_SPEC |
1052 /* Generate -L options for startfile prefix list. */ | 1056 /* Generate -L options for startfile prefix list. */ |
1053 # define LINK_LIBGCC_SPEC "%D" | 1057 # define LINK_LIBGCC_SPEC "%D" |
1110 | 1114 |
1111 /* We don't wrap .d files in %W{} since a missing .d file, and | 1115 /* We don't wrap .d files in %W{} since a missing .d file, and |
1112 therefore no dependency entry, confuses make into thinking a .o | 1116 therefore no dependency entry, confuses make into thinking a .o |
1113 file that happens to exist is up-to-date. */ | 1117 file that happens to exist is up-to-date. */ |
1114 static const char *cpp_unique_options = | 1118 static const char *cpp_unique_options = |
1115 "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %{I*&F*} %{P} %I\ | 1119 "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\ |
1116 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ | 1120 %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
1117 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ | 1121 %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ |
1118 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ | 1122 %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ |
1119 %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ | 1123 %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ |
1120 %{remap} %{g3|ggdb3|gstabs3|gcoff3|gxcoff3|gvms3:-dD}\ | 1124 %{remap} %{g3|ggdb3|gstabs3|gxcoff3|gvms3:-dD}\ |
1121 %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ | 1125 %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
1122 %{H} %C %{D*&U*&A*} %{i*} %Z %i\ | 1126 %{H} %C %{D*&U*&A*} %{i*} %Z %i\ |
1123 %{E|M|MM:%W{o*}}"; | 1127 %{E|M|MM:%W{o*}}"; |
1124 | 1128 |
1125 /* This contains cpp options which are common with cc1_options and are passed | 1129 /* This contains cpp options which are common with cc1_options and are passed |
1213 /* Likewise for -fgnu-tm. */ | 1217 /* Likewise for -fgnu-tm. */ |
1214 #ifndef GTM_SELF_SPECS | 1218 #ifndef GTM_SELF_SPECS |
1215 #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}" | 1219 #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}" |
1216 #endif | 1220 #endif |
1217 | 1221 |
1218 /* Likewise for -fcilkplus. */ | |
1219 #ifndef CILK_SELF_SPECS | |
1220 #define CILK_SELF_SPECS "%{fcilkplus: -pthread}" | |
1221 #endif | |
1222 | |
1223 static const char *const driver_self_specs[] = { | 1222 static const char *const driver_self_specs[] = { |
1224 "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns", | 1223 "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns", |
1225 DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS, | 1224 DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS |
1226 CILK_SELF_SPECS | |
1227 }; | 1225 }; |
1228 | 1226 |
1229 #ifndef OPTION_DEFAULT_SPECS | 1227 #ifndef OPTION_DEFAULT_SPECS |
1230 #define OPTION_DEFAULT_SPECS { "", "" } | 1228 #define OPTION_DEFAULT_SPECS { "", "" } |
1231 #endif | 1229 #endif |
1934 /* Accumulate a command (program name and args), and run it. */ | 1932 /* Accumulate a command (program name and args), and run it. */ |
1935 | 1933 |
1936 typedef const char *const_char_p; /* For DEF_VEC_P. */ | 1934 typedef const char *const_char_p; /* For DEF_VEC_P. */ |
1937 | 1935 |
1938 /* Vector of pointers to arguments in the current line of specifications. */ | 1936 /* Vector of pointers to arguments in the current line of specifications. */ |
1939 | |
1940 static vec<const_char_p> argbuf; | 1937 static vec<const_char_p> argbuf; |
1938 | |
1939 /* Likewise, but for the current @file. */ | |
1940 static vec<const_char_p> at_file_argbuf; | |
1941 | |
1942 /* Whether an @file is currently open. */ | |
1943 static bool in_at_file = false; | |
1941 | 1944 |
1942 /* Were the options -c, -S or -E passed. */ | 1945 /* Were the options -c, -S or -E passed. */ |
1943 static int have_c = 0; | 1946 static int have_c = 0; |
1944 | 1947 |
1945 /* Was the option -o passed. */ | 1948 /* Was the option -o passed. */ |
1976 | 1979 |
1977 static void | 1980 static void |
1978 alloc_args (void) | 1981 alloc_args (void) |
1979 { | 1982 { |
1980 argbuf.create (10); | 1983 argbuf.create (10); |
1984 at_file_argbuf.create (10); | |
1981 } | 1985 } |
1982 | 1986 |
1983 /* Clear out the vector of arguments (after a command is executed). */ | 1987 /* Clear out the vector of arguments (after a command is executed). */ |
1984 | 1988 |
1985 static void | 1989 static void |
1986 clear_args (void) | 1990 clear_args (void) |
1987 { | 1991 { |
1988 argbuf.truncate (0); | 1992 argbuf.truncate (0); |
1993 at_file_argbuf.truncate (0); | |
1989 } | 1994 } |
1990 | 1995 |
1991 /* Add one argument to the vector at the end. | 1996 /* Add one argument to the vector at the end. |
1992 This is done when a space is seen or at the end of the line. | 1997 This is done when a space is seen or at the end of the line. |
1993 If DELETE_ALWAYS is nonzero, the arg is a filename | 1998 If DELETE_ALWAYS is nonzero, the arg is a filename |
1996 and the file should be deleted if this compilation fails. */ | 2001 and the file should be deleted if this compilation fails. */ |
1997 | 2002 |
1998 static void | 2003 static void |
1999 store_arg (const char *arg, int delete_always, int delete_failure) | 2004 store_arg (const char *arg, int delete_always, int delete_failure) |
2000 { | 2005 { |
2001 argbuf.safe_push (arg); | 2006 if (in_at_file) |
2007 at_file_argbuf.safe_push (arg); | |
2008 else | |
2009 argbuf.safe_push (arg); | |
2002 | 2010 |
2003 if (delete_always || delete_failure) | 2011 if (delete_always || delete_failure) |
2004 { | 2012 { |
2005 const char *p; | 2013 const char *p; |
2006 /* If the temporary file we should delete is specified as | 2014 /* If the temporary file we should delete is specified as |
2009 && (p = strrchr (arg, '='))) | 2017 && (p = strrchr (arg, '='))) |
2010 arg = p + 1; | 2018 arg = p + 1; |
2011 record_temp_file (arg, delete_always, delete_failure); | 2019 record_temp_file (arg, delete_always, delete_failure); |
2012 } | 2020 } |
2013 } | 2021 } |
2022 | |
2023 /* Open a temporary @file into which subsequent arguments will be stored. */ | |
2024 | |
2025 static void | |
2026 open_at_file (void) | |
2027 { | |
2028 if (in_at_file) | |
2029 fatal_error (input_location, "cannot open nested response file"); | |
2030 else | |
2031 in_at_file = true; | |
2032 } | |
2033 | |
2034 /* Close the temporary @file and add @file to the argument list. */ | |
2035 | |
2036 static void | |
2037 close_at_file (void) | |
2038 { | |
2039 if (!in_at_file) | |
2040 fatal_error (input_location, "cannot close nonexistent response file"); | |
2041 | |
2042 in_at_file = false; | |
2043 | |
2044 const unsigned int n_args = at_file_argbuf.length (); | |
2045 if (n_args == 0) | |
2046 return; | |
2047 | |
2048 char **argv = (char **) alloca (sizeof (char *) * (n_args + 1)); | |
2049 char *temp_file = make_temp_file (""); | |
2050 char *at_argument = concat ("@", temp_file, NULL); | |
2051 FILE *f = fopen (temp_file, "w"); | |
2052 int status; | |
2053 unsigned int i; | |
2054 | |
2055 /* Copy the strings over. */ | |
2056 for (i = 0; i < n_args; i++) | |
2057 argv[i] = CONST_CAST (char *, at_file_argbuf[i]); | |
2058 argv[i] = NULL; | |
2059 | |
2060 at_file_argbuf.truncate (0); | |
2061 | |
2062 if (f == NULL) | |
2063 fatal_error (input_location, "could not open temporary response file %s", | |
2064 temp_file); | |
2065 | |
2066 status = writeargv (argv, f); | |
2067 | |
2068 if (status) | |
2069 fatal_error (input_location, | |
2070 "could not write to temporary response file %s", | |
2071 temp_file); | |
2072 | |
2073 status = fclose (f); | |
2074 | |
2075 if (status == EOF) | |
2076 fatal_error (input_location, "could not close temporary response file %s", | |
2077 temp_file); | |
2078 | |
2079 store_arg (at_argument, 0, 0); | |
2080 | |
2081 record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
2082 } | |
2014 | 2083 |
2015 /* Load specs from a file name named FILENAME, replacing occurrences of | 2084 /* Load specs from a file name named FILENAME, replacing occurrences of |
2016 various different types of line-endings, \r\n, \n\r and just \r, with | 2085 various different types of line-endings, \r\n, \n\r and just \r, with |
2017 a single \n. */ | 2086 a single \n. */ |
2018 | 2087 |
2031 fnotice (stderr, "Reading specs from %s\n", filename); | 2100 fnotice (stderr, "Reading specs from %s\n", filename); |
2032 | 2101 |
2033 /* Open and stat the file. */ | 2102 /* Open and stat the file. */ |
2034 desc = open (filename, O_RDONLY, 0); | 2103 desc = open (filename, O_RDONLY, 0); |
2035 if (desc < 0) | 2104 if (desc < 0) |
2036 pfatal_with_name (filename); | 2105 { |
2106 failed: | |
2107 /* This leaves DESC open, but the OS will save us. */ | |
2108 fatal_error (input_location, "cannot read spec file %qs: %m", filename); | |
2109 } | |
2110 | |
2037 if (stat (filename, &statbuf) < 0) | 2111 if (stat (filename, &statbuf) < 0) |
2038 pfatal_with_name (filename); | 2112 goto failed; |
2039 | 2113 |
2040 /* Read contents of file into BUFFER. */ | 2114 /* Read contents of file into BUFFER. */ |
2041 buffer = XNEWVEC (char, statbuf.st_size + 1); | 2115 buffer = XNEWVEC (char, statbuf.st_size + 1); |
2042 readlen = read (desc, buffer, (unsigned) statbuf.st_size); | 2116 readlen = read (desc, buffer, (unsigned) statbuf.st_size); |
2043 if (readlen < 0) | 2117 if (readlen < 0) |
2044 pfatal_with_name (filename); | 2118 goto failed; |
2045 buffer[readlen] = 0; | 2119 buffer[readlen] = 0; |
2046 close (desc); | 2120 close (desc); |
2047 | 2121 |
2048 specs = XNEWVEC (char, readlen + 1); | 2122 specs = XNEWVEC (char, readlen + 1); |
2049 specs_p = specs; | 2123 specs_p = specs; |
2420 do \ | 2494 do \ |
2421 { \ | 2495 { \ |
2422 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ | 2496 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ |
2423 if (unlink (NAME) < 0) \ | 2497 if (unlink (NAME) < 0) \ |
2424 if (VERBOSE_FLAG) \ | 2498 if (VERBOSE_FLAG) \ |
2425 perror_with_name (NAME); \ | 2499 error ("%s: %m", (NAME)); \ |
2426 } while (0) | 2500 } while (0) |
2427 #endif | 2501 #endif |
2428 | 2502 |
2429 static void | 2503 static void |
2430 delete_if_ordinary (const char *name) | 2504 delete_if_ordinary (const char *name) |
3099 | (string == commands[i].prog ? PEX_SEARCH : 0)), | 3173 | (string == commands[i].prog ? PEX_SEARCH : 0)), |
3100 string, CONST_CAST (char **, commands[i].argv), | 3174 string, CONST_CAST (char **, commands[i].argv), |
3101 NULL, NULL, &err); | 3175 NULL, NULL, &err); |
3102 if (errmsg != NULL) | 3176 if (errmsg != NULL) |
3103 { | 3177 { |
3104 if (err == 0) | 3178 errno = err; |
3105 fatal_error (input_location, errmsg); | 3179 fatal_error (input_location, |
3106 else | 3180 err ? G_("cannot execute %qs: %s: %m") |
3107 { | 3181 : G_("cannot execute %qs: %s"), |
3108 errno = err; | 3182 string, errmsg); |
3109 pfatal_with_name (errmsg); | |
3110 } | |
3111 } | 3183 } |
3112 | 3184 |
3113 if (i && string != commands[i].prog) | 3185 if (i && string != commands[i].prog) |
3114 free (CONST_CAST (char *, string)); | 3186 free (CONST_CAST (char *, string)); |
3115 } | 3187 } |
3825 add_preprocessor_option ("--version", strlen ("--version")); | 3897 add_preprocessor_option ("--version", strlen ("--version")); |
3826 add_assembler_option ("--version", strlen ("--version")); | 3898 add_assembler_option ("--version", strlen ("--version")); |
3827 add_linker_option ("--version", strlen ("--version")); | 3899 add_linker_option ("--version", strlen ("--version")); |
3828 break; | 3900 break; |
3829 | 3901 |
3902 case OPT__completion_: | |
3903 validated = true; | |
3904 completion = decoded->arg; | |
3905 break; | |
3906 | |
3830 case OPT__help: | 3907 case OPT__help: |
3831 print_help_list = 1; | 3908 print_help_list = 1; |
3832 | 3909 |
3833 /* CPP driver cannot obtain switch from cc1_options. */ | 3910 /* CPP driver cannot obtain switch from cc1_options. */ |
3834 if (is_cpp_driver) | 3911 if (is_cpp_driver) |
4470 else | 4547 else |
4471 fname = xstrdup (arg); | 4548 fname = xstrdup (arg); |
4472 | 4549 |
4473 if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) | 4550 if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) |
4474 { | 4551 { |
4475 if (fname[0] == '@' && access (fname + 1, F_OK) < 0) | 4552 bool resp = fname[0] == '@' && access (fname + 1, F_OK) < 0; |
4476 perror_with_name (fname + 1); | 4553 error ("%s: %m", fname + resp); |
4477 else | |
4478 perror_with_name (fname); | |
4479 } | 4554 } |
4480 else | 4555 else |
4481 add_infile (arg, spec_lang); | 4556 add_infile (arg, spec_lang); |
4482 | 4557 |
4483 free (fname); | 4558 free (fname); |
4865 int | 4940 int |
4866 do_spec (const char *spec) | 4941 do_spec (const char *spec) |
4867 { | 4942 { |
4868 int value; | 4943 int value; |
4869 | 4944 |
4870 value = do_spec_2 (spec); | 4945 value = do_spec_2 (spec, NULL); |
4871 | 4946 |
4872 /* Force out any unfinished command. | 4947 /* Force out any unfinished command. |
4873 If -pipe, this forces out the last command if it ended in `|'. */ | 4948 If -pipe, this forces out the last command if it ended in `|'. */ |
4874 if (value == 0) | 4949 if (value == 0) |
4875 { | 4950 { |
4884 } | 4959 } |
4885 | 4960 |
4886 return value; | 4961 return value; |
4887 } | 4962 } |
4888 | 4963 |
4964 /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value | |
4965 of a matched * pattern which may be re-injected by way of %*. */ | |
4966 | |
4889 static int | 4967 static int |
4890 do_spec_2 (const char *spec) | 4968 do_spec_2 (const char *spec, const char *soft_matched_part) |
4891 { | 4969 { |
4892 int result; | 4970 int result; |
4893 | 4971 |
4894 clear_args (); | 4972 clear_args (); |
4895 arg_going = 0; | 4973 arg_going = 0; |
4898 this_is_library_file = 0; | 4976 this_is_library_file = 0; |
4899 this_is_linker_script = 0; | 4977 this_is_linker_script = 0; |
4900 input_from_pipe = 0; | 4978 input_from_pipe = 0; |
4901 suffix_subst = NULL; | 4979 suffix_subst = NULL; |
4902 | 4980 |
4903 result = do_spec_1 (spec, 0, NULL); | 4981 result = do_spec_1 (spec, 0, soft_matched_part); |
4904 | 4982 |
4905 end_going_arg (); | 4983 end_going_arg (); |
4906 | 4984 |
4907 return result; | 4985 return result; |
4908 } | 4986 } |
4909 | |
4910 | 4987 |
4911 /* Process the given spec string and add any new options to the end | 4988 /* Process the given spec string and add any new options to the end |
4912 of the switches/n_switches array. */ | 4989 of the switches/n_switches array. */ |
4913 | 4990 |
4914 static void | 4991 static void |
4963 static void | 5040 static void |
4964 do_self_spec (const char *spec) | 5041 do_self_spec (const char *spec) |
4965 { | 5042 { |
4966 int i; | 5043 int i; |
4967 | 5044 |
4968 do_spec_2 (spec); | 5045 do_spec_2 (spec, NULL); |
4969 do_spec_1 (" ", 0, NULL); | 5046 do_spec_1 (" ", 0, NULL); |
4970 | 5047 |
4971 /* Mark %<S switches processed by do_self_spec to be ignored permanently. | 5048 /* Mark %<S switches processed by do_self_spec to be ignored permanently. |
4972 do_self_specs adds the replacements to switches array, so it shouldn't | 5049 do_self_specs adds the replacements to switches array, so it shouldn't |
4973 be processed afterwards. */ | 5050 be processed afterwards. */ |
5089 /* Must not damage the original path. */ | 5166 /* Must not damage the original path. */ |
5090 if (info->append_len == 0) | 5167 if (info->append_len == 0) |
5091 path[len - 1] = save; | 5168 path[len - 1] = save; |
5092 | 5169 |
5093 return NULL; | 5170 return NULL; |
5094 } | |
5095 | |
5096 /* Create a temporary FILE with the contents of ARGV. Add @FILE to the | |
5097 argument list. */ | |
5098 | |
5099 static void | |
5100 create_at_file (char **argv) | |
5101 { | |
5102 char *temp_file = make_temp_file (""); | |
5103 char *at_argument = concat ("@", temp_file, NULL); | |
5104 FILE *f = fopen (temp_file, "w"); | |
5105 int status; | |
5106 | |
5107 if (f == NULL) | |
5108 fatal_error (input_location, "could not open temporary response file %s", | |
5109 temp_file); | |
5110 | |
5111 status = writeargv (argv, f); | |
5112 | |
5113 if (status) | |
5114 fatal_error (input_location, | |
5115 "could not write to temporary response file %s", | |
5116 temp_file); | |
5117 | |
5118 status = fclose (f); | |
5119 | |
5120 if (EOF == status) | |
5121 fatal_error (input_location, "could not close temporary response file %s", | |
5122 temp_file); | |
5123 | |
5124 store_arg (at_argument, 0, 0); | |
5125 | |
5126 record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
5127 } | 5171 } |
5128 | 5172 |
5129 /* True if we should compile INFILE. */ | 5173 /* True if we should compile INFILE. */ |
5130 | 5174 |
5131 static bool | 5175 static bool |
5315 while (*p != 0 && *p != '\n') | 5359 while (*p != 0 && *p != '\n') |
5316 p++; | 5360 p++; |
5317 buf = (char *) alloca (p - q + 1); | 5361 buf = (char *) alloca (p - q + 1); |
5318 strncpy (buf, q, p - q); | 5362 strncpy (buf, q, p - q); |
5319 buf[p - q] = 0; | 5363 buf[p - q] = 0; |
5320 inform (0, "%s", _(buf)); | 5364 inform (UNKNOWN_LOCATION, "%s", _(buf)); |
5321 if (*p) | 5365 if (*p) |
5322 p++; | 5366 p++; |
5323 } | 5367 } |
5324 break; | 5368 break; |
5325 | 5369 |
5536 break; | 5580 break; |
5537 | 5581 |
5538 case 'i': | 5582 case 'i': |
5539 if (combine_inputs) | 5583 if (combine_inputs) |
5540 { | 5584 { |
5585 /* We are going to expand `%i' into `@FILE', where FILE | |
5586 is a newly-created temporary filename. The filenames | |
5587 that would usually be expanded in place of %o will be | |
5588 written to the temporary file. */ | |
5541 if (at_file_supplied) | 5589 if (at_file_supplied) |
5542 { | 5590 open_at_file (); |
5543 /* We are going to expand `%i' to `@FILE', where FILE | 5591 |
5544 is a newly-created temporary filename. The filenames | 5592 for (i = 0; (int) i < n_infiles; i++) |
5545 that would usually be expanded in place of %o will be | 5593 if (compile_input_file_p (&infiles[i])) |
5546 written to the temporary file. */ | 5594 { |
5547 char **argv; | 5595 store_arg (infiles[i].name, 0, 0); |
5548 int n_files = 0; | 5596 infiles[i].compiled = true; |
5549 int j; | 5597 } |
5550 | 5598 |
5551 for (i = 0; i < n_infiles; i++) | 5599 if (at_file_supplied) |
5552 if (compile_input_file_p (&infiles[i])) | 5600 close_at_file (); |
5553 n_files++; | |
5554 | |
5555 argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
5556 | |
5557 /* Copy the strings over. */ | |
5558 for (i = 0, j = 0; i < n_infiles; i++) | |
5559 if (compile_input_file_p (&infiles[i])) | |
5560 { | |
5561 argv[j] = CONST_CAST (char *, infiles[i].name); | |
5562 infiles[i].compiled = true; | |
5563 j++; | |
5564 } | |
5565 argv[j] = NULL; | |
5566 | |
5567 create_at_file (argv); | |
5568 } | |
5569 else | |
5570 for (i = 0; (int) i < n_infiles; i++) | |
5571 if (compile_input_file_p (&infiles[i])) | |
5572 { | |
5573 store_arg (infiles[i].name, 0, 0); | |
5574 infiles[i].compiled = true; | |
5575 } | |
5576 } | 5601 } |
5577 else | 5602 else |
5578 { | 5603 { |
5579 obstack_grow (&obstack, gcc_input_filename, | 5604 obstack_grow (&obstack, gcc_input_filename, |
5580 input_filename_length); | 5605 input_filename_length); |
5643 spec_path, &info); | 5668 spec_path, &info); |
5644 } | 5669 } |
5645 break; | 5670 break; |
5646 | 5671 |
5647 case 'o': | 5672 case 'o': |
5648 { | 5673 /* We are going to expand `%o' into `@FILE', where FILE |
5649 int max = n_infiles; | 5674 is a newly-created temporary filename. The filenames |
5650 max += lang_specific_extra_outfiles; | 5675 that would usually be expanded in place of %o will be |
5651 | 5676 written to the temporary file. */ |
5652 if (HAVE_GNU_LD && at_file_supplied) | 5677 if (at_file_supplied) |
5653 { | 5678 open_at_file (); |
5654 /* We are going to expand `%o' to `@FILE', where FILE | 5679 |
5655 is a newly-created temporary filename. The filenames | 5680 for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++) |
5656 that would usually be expanded in place of %o will be | 5681 if (outfiles[i]) |
5657 written to the temporary file. */ | 5682 store_arg (outfiles[i], 0, 0); |
5658 | 5683 |
5659 char **argv; | 5684 if (at_file_supplied) |
5660 int n_files, j; | 5685 close_at_file (); |
5661 | 5686 break; |
5662 /* Convert OUTFILES into a form suitable for writeargv. */ | |
5663 | |
5664 /* Determine how many are non-NULL. */ | |
5665 for (n_files = 0, i = 0; i < max; i++) | |
5666 n_files += outfiles[i] != NULL; | |
5667 | |
5668 argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
5669 | |
5670 /* Copy the strings over. */ | |
5671 for (i = 0, j = 0; i < max; i++) | |
5672 if (outfiles[i]) | |
5673 { | |
5674 argv[j] = CONST_CAST (char *, outfiles[i]); | |
5675 j++; | |
5676 } | |
5677 argv[j] = NULL; | |
5678 | |
5679 create_at_file (argv); | |
5680 } | |
5681 else | |
5682 for (i = 0; i < max; i++) | |
5683 if (outfiles[i]) | |
5684 store_arg (outfiles[i], 0, 0); | |
5685 break; | |
5686 } | |
5687 | 5687 |
5688 case 'O': | 5688 case 'O': |
5689 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); | 5689 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
5690 arg_going = 1; | 5690 arg_going = 1; |
5691 break; | 5691 break; |
5722 if (argbuf.length () != cur_index) | 5722 if (argbuf.length () != cur_index) |
5723 record_temp_file (argbuf.last (), 0, 1); | 5723 record_temp_file (argbuf.last (), 0, 1); |
5724 break; | 5724 break; |
5725 } | 5725 } |
5726 | 5726 |
5727 case '@': | |
5728 /* Handle the {...} following the %@. */ | |
5729 if (*p != '{') | |
5730 fatal_error (input_location, | |
5731 "spec %qs has invalid %<%%@%c%>", spec, *p); | |
5732 if (at_file_supplied) | |
5733 open_at_file (); | |
5734 p = handle_braces (p + 1); | |
5735 if (at_file_supplied) | |
5736 close_at_file (); | |
5737 if (p == 0) | |
5738 return -1; | |
5739 break; | |
5740 | |
5727 /* %x{OPTION} records OPTION for %X to output. */ | 5741 /* %x{OPTION} records OPTION for %X to output. */ |
5728 case 'x': | 5742 case 'x': |
5729 { | 5743 { |
5730 const char *p1 = p; | 5744 const char *p1 = p; |
5731 char *string; | 5745 char *string; |
5866 if (p == 0) | 5880 if (p == 0) |
5867 return -1; | 5881 return -1; |
5868 break; | 5882 break; |
5869 | 5883 |
5870 case ':': | 5884 case ':': |
5871 p = handle_spec_function (p, NULL); | 5885 p = handle_spec_function (p, NULL, soft_matched_part); |
5872 if (p == 0) | 5886 if (p == 0) |
5873 return -1; | 5887 return -1; |
5874 break; | 5888 break; |
5875 | 5889 |
5876 case '%': | 5890 case '%': |
6028 } | 6042 } |
6029 | 6043 |
6030 /* Evaluate a spec function. */ | 6044 /* Evaluate a spec function. */ |
6031 | 6045 |
6032 static const char * | 6046 static const char * |
6033 eval_spec_function (const char *func, const char *args) | 6047 eval_spec_function (const char *func, const char *args, |
6048 const char *soft_matched_part) | |
6034 { | 6049 { |
6035 const struct spec_function *sf; | 6050 const struct spec_function *sf; |
6036 const char *funcval; | 6051 const char *funcval; |
6037 | 6052 |
6038 /* Saved spec processing context. */ | 6053 /* Saved spec processing context. */ |
6078 | 6093 |
6079 /* Create a new spec processing context, and build the function | 6094 /* Create a new spec processing context, and build the function |
6080 arguments. */ | 6095 arguments. */ |
6081 | 6096 |
6082 alloc_args (); | 6097 alloc_args (); |
6083 if (do_spec_2 (args) < 0) | 6098 if (do_spec_2 (args, soft_matched_part) < 0) |
6084 fatal_error (input_location, "error in args to spec function %qs", func); | 6099 fatal_error (input_location, "error in args to spec function %qs", func); |
6085 | 6100 |
6086 /* argbuf_index is an index for the next argument to be inserted, and | 6101 /* argbuf_index is an index for the next argument to be inserted, and |
6087 so contains the count of the args already inserted. */ | 6102 so contains the count of the args already inserted. */ |
6088 | 6103 |
6115 argument vector in the normal fashion. The function returns a string | 6130 argument vector in the normal fashion. The function returns a string |
6116 containing a spec which we then process in the caller's context, or | 6131 containing a spec which we then process in the caller's context, or |
6117 NULL if no processing is required. | 6132 NULL if no processing is required. |
6118 | 6133 |
6119 If RETVAL_NONNULL is not NULL, then store a bool whether function | 6134 If RETVAL_NONNULL is not NULL, then store a bool whether function |
6120 returned non-NULL. */ | 6135 returned non-NULL. |
6136 | |
6137 SOFT_MATCHED_PART holds the current value of a matched * pattern, which | |
6138 may be re-expanded with a %* as part of the function arguments. */ | |
6121 | 6139 |
6122 static const char * | 6140 static const char * |
6123 handle_spec_function (const char *p, bool *retval_nonnull) | 6141 handle_spec_function (const char *p, bool *retval_nonnull, |
6142 const char *soft_matched_part) | |
6124 { | 6143 { |
6125 char *func, *args; | 6144 char *func, *args; |
6126 const char *endp, *funcval; | 6145 const char *endp, *funcval; |
6127 int count; | 6146 int count; |
6128 | 6147 |
6161 args = save_string (p, endp - p); | 6180 args = save_string (p, endp - p); |
6162 p = ++endp; | 6181 p = ++endp; |
6163 | 6182 |
6164 /* p now points to just past the end of the spec function expression. */ | 6183 /* p now points to just past the end of the spec function expression. */ |
6165 | 6184 |
6166 funcval = eval_spec_function (func, args); | 6185 funcval = eval_spec_function (func, args, soft_matched_part); |
6167 if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) | 6186 if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) |
6168 p = NULL; | 6187 p = NULL; |
6169 if (retval_nonnull) | 6188 if (retval_nonnull) |
6170 *retval_nonnull = funcval != NULL; | 6189 *retval_nonnull = funcval != NULL; |
6171 | 6190 |
6315 SKIP_WHITE (); | 6334 SKIP_WHITE (); |
6316 if (*p == '%' && p[1] == ':') | 6335 if (*p == '%' && p[1] == ':') |
6317 { | 6336 { |
6318 atom = NULL; | 6337 atom = NULL; |
6319 end_atom = NULL; | 6338 end_atom = NULL; |
6320 p = handle_spec_function (p + 2, &a_matched); | 6339 p = handle_spec_function (p + 2, &a_matched, NULL); |
6321 } | 6340 } |
6322 else | 6341 else |
6323 { | 6342 { |
6324 if (*p == '.') | 6343 if (*p == '.') |
6325 p++, a_is_suffix = true; | 6344 p++, a_is_suffix = true; |
6867 errmsg = pex_run (pex, pex_flags, new_argv[0], | 6886 errmsg = pex_run (pex, pex_flags, new_argv[0], |
6868 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, | 6887 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, |
6869 err_temp, &err); | 6888 err_temp, &err); |
6870 if (errmsg != NULL) | 6889 if (errmsg != NULL) |
6871 { | 6890 { |
6872 if (err == 0) | 6891 errno = err; |
6873 fatal_error (input_location, errmsg); | 6892 fatal_error (input_location, |
6874 else | 6893 err ? G_ ("cannot execute %qs: %s: %m") |
6875 { | 6894 : G_ ("cannot execute %qs: %s"), |
6876 errno = err; | 6895 new_argv[0], errmsg); |
6877 pfatal_with_name (errmsg); | |
6878 } | |
6879 } | 6896 } |
6880 | 6897 |
6881 if (!pex_get_status (pex, 1, &exit_status)) | 6898 if (!pex_get_status (pex, 1, &exit_status)) |
6882 goto out; | 6899 goto out; |
6883 | 6900 |
7042 insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1], | 7059 insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1], |
7043 *stderr_commented); | 7060 *stderr_commented); |
7044 | 7061 |
7045 /* In final attempt we append compiler options and preprocesssed code to last | 7062 /* In final attempt we append compiler options and preprocesssed code to last |
7046 generated .out file with configuration and backtrace. */ | 7063 generated .out file with configuration and backtrace. */ |
7047 char **output = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1]; | 7064 char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1]; |
7048 do_report_bug (new_argv, nargs, stderr_commented, output); | 7065 do_report_bug (new_argv, nargs, stderr_commented, err); |
7049 } | 7066 } |
7050 | 7067 |
7051 out: | 7068 out: |
7052 for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++) | 7069 for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++) |
7053 if (temp_files[i]) | 7070 if (temp_files[i]) |
7269 return ret; | 7286 return ret; |
7270 } | 7287 } |
7271 | 7288 |
7272 driver::driver (bool can_finalize, bool debug) : | 7289 driver::driver (bool can_finalize, bool debug) : |
7273 explicit_link_files (NULL), | 7290 explicit_link_files (NULL), |
7274 decoded_options (NULL), | 7291 decoded_options (NULL) |
7275 m_option_suggestions (NULL) | |
7276 { | 7292 { |
7277 env.init (can_finalize, debug); | 7293 env.init (can_finalize, debug); |
7278 } | 7294 } |
7279 | 7295 |
7280 driver::~driver () | 7296 driver::~driver () |
7281 { | 7297 { |
7282 XDELETEVEC (explicit_link_files); | 7298 XDELETEVEC (explicit_link_files); |
7283 XDELETEVEC (decoded_options); | 7299 XDELETEVEC (decoded_options); |
7284 if (m_option_suggestions) | |
7285 { | |
7286 int i; | |
7287 char *str; | |
7288 FOR_EACH_VEC_ELT (*m_option_suggestions, i, str) | |
7289 free (str); | |
7290 delete m_option_suggestions; | |
7291 } | |
7292 } | 7300 } |
7293 | 7301 |
7294 /* driver::main is implemented as a series of driver:: method calls. */ | 7302 /* driver::main is implemented as a series of driver:: method calls. */ |
7295 | 7303 |
7296 int | 7304 int |
7307 putenv_COLLECT_GCC (argv[0]); | 7315 putenv_COLLECT_GCC (argv[0]); |
7308 maybe_putenv_COLLECT_LTO_WRAPPER (); | 7316 maybe_putenv_COLLECT_LTO_WRAPPER (); |
7309 maybe_putenv_OFFLOAD_TARGETS (); | 7317 maybe_putenv_OFFLOAD_TARGETS (); |
7310 handle_unrecognized_options (); | 7318 handle_unrecognized_options (); |
7311 | 7319 |
7320 if (completion) | |
7321 { | |
7322 m_option_proposer.suggest_completion (completion); | |
7323 return 0; | |
7324 } | |
7325 | |
7312 if (!maybe_print_and_exit ()) | 7326 if (!maybe_print_and_exit ()) |
7313 return 0; | 7327 return 0; |
7314 | 7328 |
7315 early_exit = prepare_infiles (); | 7329 early_exit = prepare_infiles (); |
7316 if (early_exit) | 7330 if (early_exit) |
7553 } | 7567 } |
7554 | 7568 |
7555 /* Process sysroot_suffix_spec. */ | 7569 /* Process sysroot_suffix_spec. */ |
7556 if (*sysroot_suffix_spec != 0 | 7570 if (*sysroot_suffix_spec != 0 |
7557 && !no_sysroot_suffix | 7571 && !no_sysroot_suffix |
7558 && do_spec_2 (sysroot_suffix_spec) == 0) | 7572 && do_spec_2 (sysroot_suffix_spec, NULL) == 0) |
7559 { | 7573 { |
7560 if (argbuf.length () > 1) | 7574 if (argbuf.length () > 1) |
7561 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); | 7575 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); |
7562 else if (argbuf.length () == 1) | 7576 else if (argbuf.length () == 1) |
7563 target_sysroot_suffix = xstrdup (argbuf.last ()); | 7577 target_sysroot_suffix = xstrdup (argbuf.last ()); |
7577 #endif | 7591 #endif |
7578 | 7592 |
7579 /* Process sysroot_hdrs_suffix_spec. */ | 7593 /* Process sysroot_hdrs_suffix_spec. */ |
7580 if (*sysroot_hdrs_suffix_spec != 0 | 7594 if (*sysroot_hdrs_suffix_spec != 0 |
7581 && !no_sysroot_suffix | 7595 && !no_sysroot_suffix |
7582 && do_spec_2 (sysroot_hdrs_suffix_spec) == 0) | 7596 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) |
7583 { | 7597 { |
7584 if (argbuf.length () > 1) | 7598 if (argbuf.length () > 1) |
7585 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); | 7599 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); |
7586 else if (argbuf.length () == 1) | 7600 else if (argbuf.length () == 1) |
7587 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); | 7601 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); |
7588 } | 7602 } |
7589 | 7603 |
7590 /* Look for startfiles in the standard places. */ | 7604 /* Look for startfiles in the standard places. */ |
7591 if (*startfile_prefix_spec != 0 | 7605 if (*startfile_prefix_spec != 0 |
7592 && do_spec_2 (startfile_prefix_spec) == 0 | 7606 && do_spec_2 (startfile_prefix_spec, NULL) == 0 |
7593 && do_spec_1 (" ", 0, NULL) == 0) | 7607 && do_spec_1 (" ", 0, NULL) == 0) |
7594 { | 7608 { |
7595 const char *arg; | 7609 const char *arg; |
7596 int ndx; | 7610 int ndx; |
7597 FOR_EACH_VEC_ELT (argbuf, ndx, arg) | 7611 FOR_EACH_VEC_ELT (argbuf, ndx, arg) |
7775 | 7789 |
7776 free (offload_targets); | 7790 free (offload_targets); |
7777 offload_targets = NULL; | 7791 offload_targets = NULL; |
7778 } | 7792 } |
7779 | 7793 |
7780 /* Helper function for driver::suggest_option. Populate | |
7781 m_option_suggestions with candidate strings for misspelled options. | |
7782 The strings will be freed by the driver's dtor. */ | |
7783 | |
7784 void | |
7785 driver::build_option_suggestions (void) | |
7786 { | |
7787 gcc_assert (m_option_suggestions == NULL); | |
7788 m_option_suggestions = new auto_vec <char *> (); | |
7789 | |
7790 /* We build a vec of m_option_suggestions, using add_misspelling_candidates | |
7791 to add copies of strings, without a leading dash. */ | |
7792 | |
7793 for (unsigned int i = 0; i < cl_options_count; i++) | |
7794 { | |
7795 const struct cl_option *option = &cl_options[i]; | |
7796 const char *opt_text = option->opt_text; | |
7797 switch (i) | |
7798 { | |
7799 default: | |
7800 if (option->var_type == CLVC_ENUM) | |
7801 { | |
7802 const struct cl_enum *e = &cl_enums[option->var_enum]; | |
7803 for (unsigned j = 0; e->values[j].arg != NULL; j++) | |
7804 { | |
7805 char *with_arg = concat (opt_text, e->values[j].arg, NULL); | |
7806 add_misspelling_candidates (m_option_suggestions, option, | |
7807 with_arg); | |
7808 free (with_arg); | |
7809 } | |
7810 } | |
7811 else | |
7812 add_misspelling_candidates (m_option_suggestions, option, | |
7813 opt_text); | |
7814 break; | |
7815 | |
7816 case OPT_fsanitize_: | |
7817 case OPT_fsanitize_recover_: | |
7818 /* -fsanitize= and -fsanitize-recover= can take | |
7819 a comma-separated list of arguments. Given that combinations | |
7820 are supported, we can't add all potential candidates to the | |
7821 vec, but if we at least add them individually without commas, | |
7822 we should do a better job e.g. correcting | |
7823 "-sanitize=address" | |
7824 to | |
7825 "-fsanitize=address" | |
7826 rather than to "-Wframe-address" (PR driver/69265). */ | |
7827 { | |
7828 for (int j = 0; sanitizer_opts[j].name != NULL; ++j) | |
7829 { | |
7830 struct cl_option optb; | |
7831 /* -fsanitize=all is not valid, only -fno-sanitize=all. | |
7832 So don't register the positive misspelling candidates | |
7833 for it. */ | |
7834 if (sanitizer_opts[j].flag == ~0U && i == OPT_fsanitize_) | |
7835 { | |
7836 optb = *option; | |
7837 optb.opt_text = opt_text = "-fno-sanitize="; | |
7838 optb.cl_reject_negative = true; | |
7839 option = &optb; | |
7840 } | |
7841 /* Get one arg at a time e.g. "-fsanitize=address". */ | |
7842 char *with_arg = concat (opt_text, | |
7843 sanitizer_opts[j].name, | |
7844 NULL); | |
7845 /* Add with_arg and all of its variant spellings e.g. | |
7846 "-fno-sanitize=address" to candidates (albeit without | |
7847 leading dashes). */ | |
7848 add_misspelling_candidates (m_option_suggestions, option, | |
7849 with_arg); | |
7850 free (with_arg); | |
7851 } | |
7852 } | |
7853 break; | |
7854 } | |
7855 } | |
7856 } | |
7857 | |
7858 /* Helper function for driver::handle_unrecognized_options. | |
7859 | |
7860 Given an unrecognized option BAD_OPT (without the leading dash), | |
7861 locate the closest reasonable matching option (again, without the | |
7862 leading dash), or NULL. | |
7863 | |
7864 The returned string is owned by the driver instance. */ | |
7865 | |
7866 const char * | |
7867 driver::suggest_option (const char *bad_opt) | |
7868 { | |
7869 /* Lazily populate m_option_suggestions. */ | |
7870 if (!m_option_suggestions) | |
7871 build_option_suggestions (); | |
7872 gcc_assert (m_option_suggestions); | |
7873 | |
7874 /* "m_option_suggestions" is now populated. Use it. */ | |
7875 return find_closest_string | |
7876 (bad_opt, | |
7877 (auto_vec <const char *> *) m_option_suggestions); | |
7878 } | |
7879 | |
7880 /* Reject switches that no pass was interested in. */ | 7794 /* Reject switches that no pass was interested in. */ |
7881 | 7795 |
7882 void | 7796 void |
7883 driver::handle_unrecognized_options () | 7797 driver::handle_unrecognized_options () |
7884 { | 7798 { |
7885 for (size_t i = 0; (int) i < n_switches; i++) | 7799 for (size_t i = 0; (int) i < n_switches; i++) |
7886 if (! switches[i].validated) | 7800 if (! switches[i].validated) |
7887 { | 7801 { |
7888 const char *hint = suggest_option (switches[i].part1); | 7802 const char *hint = m_option_proposer.suggest_option (switches[i].part1); |
7889 if (hint) | 7803 if (hint) |
7890 error ("unrecognized command line option %<-%s%>;" | 7804 error ("unrecognized command line option %<-%s%>;" |
7891 " did you mean %<-%s%>?", | 7805 " did you mean %<-%s%>?", |
7892 switches[i].part1, hint); | 7806 switches[i].part1, hint); |
7893 else | 7807 else |
8042 | 7956 |
8043 if (print_version) | 7957 if (print_version) |
8044 { | 7958 { |
8045 printf (_("%s %s%s\n"), progname, pkgversion_string, | 7959 printf (_("%s %s%s\n"), progname, pkgversion_string, |
8046 version_string); | 7960 version_string); |
8047 printf ("Copyright %s 2017 Free Software Foundation, Inc.\n", | 7961 printf ("Copyright %s 2018 Free Software Foundation, Inc.\n", |
8048 _("(C)")); | 7962 _("(C)")); |
8049 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ | 7963 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ |
8050 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), | 7964 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), |
8051 stdout); | 7965 stdout); |
8052 if (! verbose_flag) | 7966 if (! verbose_flag) |
8192 if (value < 0) | 8106 if (value < 0) |
8193 this_file_error = 1; | 8107 this_file_error = 1; |
8194 else if (compare_debug && debug_check_temp_file[0]) | 8108 else if (compare_debug && debug_check_temp_file[0]) |
8195 { | 8109 { |
8196 if (verbose_flag) | 8110 if (verbose_flag) |
8197 inform (0, "recompiling with -fcompare-debug"); | 8111 inform (UNKNOWN_LOCATION, |
8112 "recompiling with -fcompare-debug"); | |
8198 | 8113 |
8199 compare_debug = -compare_debug; | 8114 compare_debug = -compare_debug; |
8200 n_switches = n_switches_debug_check[1]; | 8115 n_switches = n_switches_debug_check[1]; |
8201 n_switches_alloc = n_switches_alloc_debug_check[1]; | 8116 n_switches_alloc = n_switches_alloc_debug_check[1]; |
8202 switches = switches_debug_check[1]; | 8117 switches = switches_debug_check[1]; |
8217 gcc_assert (debug_check_temp_file[1] | 8132 gcc_assert (debug_check_temp_file[1] |
8218 && filename_cmp (debug_check_temp_file[0], | 8133 && filename_cmp (debug_check_temp_file[0], |
8219 debug_check_temp_file[1])); | 8134 debug_check_temp_file[1])); |
8220 | 8135 |
8221 if (verbose_flag) | 8136 if (verbose_flag) |
8222 inform (0, "comparing final insns dumps"); | 8137 inform (UNKNOWN_LOCATION, "comparing final insns dumps"); |
8223 | 8138 |
8224 if (compare_files (debug_check_temp_file)) | 8139 if (compare_files (debug_check_temp_file)) |
8225 this_file_error = 1; | 8140 this_file_error = 1; |
8226 } | 8141 } |
8227 | 8142 |
8490 memcpy (result, s, len); | 8405 memcpy (result, s, len); |
8491 result[len] = 0; | 8406 result[len] = 0; |
8492 return result; | 8407 return result; |
8493 } | 8408 } |
8494 | 8409 |
8495 void | |
8496 pfatal_with_name (const char *name) | |
8497 { | |
8498 perror_with_name (name); | |
8499 delete_temp_files (); | |
8500 exit (1); | |
8501 } | |
8502 | |
8503 static void | |
8504 perror_with_name (const char *name) | |
8505 { | |
8506 error ("%s: %m", name); | |
8507 } | |
8508 | 8410 |
8509 static inline void | 8411 static inline void |
8510 validate_switches_from_spec (const char *spec, bool user) | 8412 validate_switches_from_spec (const char *spec, bool user) |
8511 { | 8413 { |
8512 const char *p = spec; | 8414 const char *p = spec; |
8513 char c; | 8415 char c; |
8514 while ((c = *p++)) | 8416 while ((c = *p++)) |
8515 if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{'))) | 8417 if (c == '%' |
8418 && (*p == '{' | |
8419 || *p == '<' | |
8420 || (*p == 'W' && *++p == '{') | |
8421 || (*p == '@' && *++p == '{'))) | |
8516 /* We have a switch spec. */ | 8422 /* We have a switch spec. */ |
8517 p = validate_switches (p + 1, user); | 8423 p = validate_switches (p + 1, user); |
8518 } | 8424 } |
8519 | 8425 |
8520 static void | 8426 static void |
8591 { | 8497 { |
8592 p++; | 8498 p++; |
8593 if (*p == '{' || *p == '<') | 8499 if (*p == '{' || *p == '<') |
8594 p = validate_switches (p+1, user_spec); | 8500 p = validate_switches (p+1, user_spec); |
8595 else if (p[0] == 'W' && p[1] == '{') | 8501 else if (p[0] == 'W' && p[1] == '{') |
8502 p = validate_switches (p+2, user_spec); | |
8503 else if (p[0] == '@' && p[1] == '{') | |
8596 p = validate_switches (p+2, user_spec); | 8504 p = validate_switches (p+2, user_spec); |
8597 } | 8505 } |
8598 else | 8506 else |
8599 p++; | 8507 p++; |
8600 } | 8508 } |
9329 /* getenv built-in spec function. | 9237 /* getenv built-in spec function. |
9330 | 9238 |
9331 Returns the value of the environment variable given by its first argument, | 9239 Returns the value of the environment variable given by its first argument, |
9332 concatenated with the second argument. If the variable is not defined, a | 9240 concatenated with the second argument. If the variable is not defined, a |
9333 fatal error is issued unless such undefs are internally allowed, in which | 9241 fatal error is issued unless such undefs are internally allowed, in which |
9334 case the variable name is used as the variable value. */ | 9242 case the variable name prefixed by a '/' is used as the variable value. |
9243 | |
9244 The leading '/' allows using the result at a spot where a full path would | |
9245 normally be expected and when the actual value doesn't really matter since | |
9246 undef vars are allowed. */ | |
9335 | 9247 |
9336 static const char * | 9248 static const char * |
9337 getenv_spec_function (int argc, const char **argv) | 9249 getenv_spec_function (int argc, const char **argv) |
9338 { | 9250 { |
9339 const char *value; | 9251 const char *value; |
9347 return NULL; | 9259 return NULL; |
9348 | 9260 |
9349 varname = argv[0]; | 9261 varname = argv[0]; |
9350 value = env.get (varname); | 9262 value = env.get (varname); |
9351 | 9263 |
9264 /* If the variable isn't defined and this is allowed, craft our expected | |
9265 return value. Assume variable names used in specs strings don't contain | |
9266 any active spec character so don't need escaping. */ | |
9352 if (!value && spec_undefvar_allowed) | 9267 if (!value && spec_undefvar_allowed) |
9353 value = varname; | 9268 { |
9269 result = XNEWVAR (char, strlen(varname) + 2); | |
9270 sprintf (result, "/%s", varname); | |
9271 return result; | |
9272 } | |
9354 | 9273 |
9355 if (!value) | 9274 if (!value) |
9356 fatal_error (input_location, | 9275 fatal_error (input_location, |
9357 "environment variable %qs not defined", varname); | 9276 "environment variable %qs not defined", varname); |
9358 | 9277 |
9714 | 9633 |
9715 if (arg != 0) | 9634 if (arg != 0) |
9716 fatal_error (input_location, | 9635 fatal_error (input_location, |
9717 "too many arguments to %%:compare-debug-dump-opt"); | 9636 "too many arguments to %%:compare-debug-dump-opt"); |
9718 | 9637 |
9719 do_spec_2 ("%{fdump-final-insns=*:%*}"); | 9638 do_spec_2 ("%{fdump-final-insns=*:%*}", NULL); |
9720 do_spec_1 (" ", 0, NULL); | 9639 do_spec_1 (" ", 0, NULL); |
9721 | 9640 |
9722 if (argbuf.length () > 0 | 9641 if (argbuf.length () > 0 |
9723 && strcmp (argv[argbuf.length () - 1], ".")) | 9642 && strcmp (argv[argbuf.length () - 1], ".")) |
9724 { | 9643 { |
9732 { | 9651 { |
9733 const char *ext = NULL; | 9652 const char *ext = NULL; |
9734 | 9653 |
9735 if (argbuf.length () > 0) | 9654 if (argbuf.length () > 0) |
9736 { | 9655 { |
9737 do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}"); | 9656 do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}", NULL); |
9738 ext = ".gkd"; | 9657 ext = ".gkd"; |
9739 } | 9658 } |
9740 else if (!compare_debug) | 9659 else if (!compare_debug) |
9741 return NULL; | 9660 return NULL; |
9742 else | 9661 else |
9743 do_spec_2 ("%g.gkd"); | 9662 do_spec_2 ("%g.gkd", NULL); |
9744 | 9663 |
9745 do_spec_1 (" ", 0, NULL); | 9664 do_spec_1 (" ", 0, NULL); |
9746 | 9665 |
9747 gcc_assert (argbuf.length () > 0); | 9666 gcc_assert (argbuf.length () > 0); |
9748 | 9667 |
9790 "too many arguments to %%:compare-debug-self-opt"); | 9709 "too many arguments to %%:compare-debug-self-opt"); |
9791 | 9710 |
9792 if (compare_debug >= 0) | 9711 if (compare_debug >= 0) |
9793 return NULL; | 9712 return NULL; |
9794 | 9713 |
9795 do_spec_2 ("%{c|S:%{o*:%*}}"); | 9714 do_spec_2 ("%{c|S:%{o*:%*}}", NULL); |
9796 do_spec_1 (" ", 0, NULL); | 9715 do_spec_1 (" ", 0, NULL); |
9797 | 9716 |
9798 if (argbuf.length () > 0) | 9717 if (argbuf.length () > 0) |
9799 debug_auxbase_opt = concat ("-auxbase-strip ", | 9718 debug_auxbase_opt = concat ("-auxbase-strip ", |
9800 argbuf.last (), | 9719 argbuf.last (), |
10150 extra_specs = NULL; | 10069 extra_specs = NULL; |
10151 #endif | 10070 #endif |
10152 | 10071 |
10153 processing_spec_function = 0; | 10072 processing_spec_function = 0; |
10154 | 10073 |
10155 argbuf.truncate (0); | 10074 clear_args (); |
10156 | 10075 |
10157 have_c = 0; | 10076 have_c = 0; |
10158 have_o = 0; | 10077 have_o = 0; |
10159 | 10078 |
10160 temp_names = NULL; | 10079 temp_names = NULL; |