Mercurial > hg > CbC > CbC_gcc
comparison gcc/gcc.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | d34655255c78 1830386684a0 |
comparison
equal
deleted
inserted
replaced
111:04ced10e8804 | 131:84e7813d76e9 |
---|---|
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 |
1931 /* Accumulate a command (program name and args), and run it. */ | 1929 /* Accumulate a command (program name and args), and run it. */ |
1932 | 1930 |
1933 typedef const char *const_char_p; /* For DEF_VEC_P. */ | 1931 typedef const char *const_char_p; /* For DEF_VEC_P. */ |
1934 | 1932 |
1935 /* Vector of pointers to arguments in the current line of specifications. */ | 1933 /* Vector of pointers to arguments in the current line of specifications. */ |
1936 | |
1937 static vec<const_char_p> argbuf; | 1934 static vec<const_char_p> argbuf; |
1935 | |
1936 /* Likewise, but for the current @file. */ | |
1937 static vec<const_char_p> at_file_argbuf; | |
1938 | |
1939 /* Whether an @file is currently open. */ | |
1940 static bool in_at_file = false; | |
1938 | 1941 |
1939 /* Were the options -c, -S or -E passed. */ | 1942 /* Were the options -c, -S or -E passed. */ |
1940 static int have_c = 0; | 1943 static int have_c = 0; |
1941 | 1944 |
1942 /* Was the option -o passed. */ | 1945 /* Was the option -o passed. */ |
1973 | 1976 |
1974 static void | 1977 static void |
1975 alloc_args (void) | 1978 alloc_args (void) |
1976 { | 1979 { |
1977 argbuf.create (10); | 1980 argbuf.create (10); |
1981 at_file_argbuf.create (10); | |
1978 } | 1982 } |
1979 | 1983 |
1980 /* Clear out the vector of arguments (after a command is executed). */ | 1984 /* Clear out the vector of arguments (after a command is executed). */ |
1981 | 1985 |
1982 static void | 1986 static void |
1983 clear_args (void) | 1987 clear_args (void) |
1984 { | 1988 { |
1985 argbuf.truncate (0); | 1989 argbuf.truncate (0); |
1990 at_file_argbuf.truncate (0); | |
1986 } | 1991 } |
1987 | 1992 |
1988 /* Add one argument to the vector at the end. | 1993 /* Add one argument to the vector at the end. |
1989 This is done when a space is seen or at the end of the line. | 1994 This is done when a space is seen or at the end of the line. |
1990 If DELETE_ALWAYS is nonzero, the arg is a filename | 1995 If DELETE_ALWAYS is nonzero, the arg is a filename |
1993 and the file should be deleted if this compilation fails. */ | 1998 and the file should be deleted if this compilation fails. */ |
1994 | 1999 |
1995 static void | 2000 static void |
1996 store_arg (const char *arg, int delete_always, int delete_failure) | 2001 store_arg (const char *arg, int delete_always, int delete_failure) |
1997 { | 2002 { |
1998 argbuf.safe_push (arg); | 2003 if (in_at_file) |
2004 at_file_argbuf.safe_push (arg); | |
2005 else | |
2006 argbuf.safe_push (arg); | |
1999 | 2007 |
2000 if (delete_always || delete_failure) | 2008 if (delete_always || delete_failure) |
2001 { | 2009 { |
2002 const char *p; | 2010 const char *p; |
2003 /* If the temporary file we should delete is specified as | 2011 /* If the temporary file we should delete is specified as |
2006 && (p = strrchr (arg, '='))) | 2014 && (p = strrchr (arg, '='))) |
2007 arg = p + 1; | 2015 arg = p + 1; |
2008 record_temp_file (arg, delete_always, delete_failure); | 2016 record_temp_file (arg, delete_always, delete_failure); |
2009 } | 2017 } |
2010 } | 2018 } |
2019 | |
2020 /* Open a temporary @file into which subsequent arguments will be stored. */ | |
2021 | |
2022 static void | |
2023 open_at_file (void) | |
2024 { | |
2025 if (in_at_file) | |
2026 fatal_error (input_location, "cannot open nested response file"); | |
2027 else | |
2028 in_at_file = true; | |
2029 } | |
2030 | |
2031 /* Close the temporary @file and add @file to the argument list. */ | |
2032 | |
2033 static void | |
2034 close_at_file (void) | |
2035 { | |
2036 if (!in_at_file) | |
2037 fatal_error (input_location, "cannot close nonexistent response file"); | |
2038 | |
2039 in_at_file = false; | |
2040 | |
2041 const unsigned int n_args = at_file_argbuf.length (); | |
2042 if (n_args == 0) | |
2043 return; | |
2044 | |
2045 char **argv = (char **) alloca (sizeof (char *) * (n_args + 1)); | |
2046 char *temp_file = make_temp_file (""); | |
2047 char *at_argument = concat ("@", temp_file, NULL); | |
2048 FILE *f = fopen (temp_file, "w"); | |
2049 int status; | |
2050 unsigned int i; | |
2051 | |
2052 /* Copy the strings over. */ | |
2053 for (i = 0; i < n_args; i++) | |
2054 argv[i] = CONST_CAST (char *, at_file_argbuf[i]); | |
2055 argv[i] = NULL; | |
2056 | |
2057 at_file_argbuf.truncate (0); | |
2058 | |
2059 if (f == NULL) | |
2060 fatal_error (input_location, "could not open temporary response file %s", | |
2061 temp_file); | |
2062 | |
2063 status = writeargv (argv, f); | |
2064 | |
2065 if (status) | |
2066 fatal_error (input_location, | |
2067 "could not write to temporary response file %s", | |
2068 temp_file); | |
2069 | |
2070 status = fclose (f); | |
2071 | |
2072 if (status == EOF) | |
2073 fatal_error (input_location, "could not close temporary response file %s", | |
2074 temp_file); | |
2075 | |
2076 store_arg (at_argument, 0, 0); | |
2077 | |
2078 record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
2079 } | |
2011 | 2080 |
2012 /* Load specs from a file name named FILENAME, replacing occurrences of | 2081 /* Load specs from a file name named FILENAME, replacing occurrences of |
2013 various different types of line-endings, \r\n, \n\r and just \r, with | 2082 various different types of line-endings, \r\n, \n\r and just \r, with |
2014 a single \n. */ | 2083 a single \n. */ |
2015 | 2084 |
2028 fnotice (stderr, "Reading specs from %s\n", filename); | 2097 fnotice (stderr, "Reading specs from %s\n", filename); |
2029 | 2098 |
2030 /* Open and stat the file. */ | 2099 /* Open and stat the file. */ |
2031 desc = open (filename, O_RDONLY, 0); | 2100 desc = open (filename, O_RDONLY, 0); |
2032 if (desc < 0) | 2101 if (desc < 0) |
2033 pfatal_with_name (filename); | 2102 { |
2103 failed: | |
2104 /* This leaves DESC open, but the OS will save us. */ | |
2105 fatal_error (input_location, "cannot read spec file %qs: %m", filename); | |
2106 } | |
2107 | |
2034 if (stat (filename, &statbuf) < 0) | 2108 if (stat (filename, &statbuf) < 0) |
2035 pfatal_with_name (filename); | 2109 goto failed; |
2036 | 2110 |
2037 /* Read contents of file into BUFFER. */ | 2111 /* Read contents of file into BUFFER. */ |
2038 buffer = XNEWVEC (char, statbuf.st_size + 1); | 2112 buffer = XNEWVEC (char, statbuf.st_size + 1); |
2039 readlen = read (desc, buffer, (unsigned) statbuf.st_size); | 2113 readlen = read (desc, buffer, (unsigned) statbuf.st_size); |
2040 if (readlen < 0) | 2114 if (readlen < 0) |
2041 pfatal_with_name (filename); | 2115 goto failed; |
2042 buffer[readlen] = 0; | 2116 buffer[readlen] = 0; |
2043 close (desc); | 2117 close (desc); |
2044 | 2118 |
2045 specs = XNEWVEC (char, readlen + 1); | 2119 specs = XNEWVEC (char, readlen + 1); |
2046 specs_p = specs; | 2120 specs_p = specs; |
2417 do \ | 2491 do \ |
2418 { \ | 2492 { \ |
2419 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ | 2493 if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ |
2420 if (unlink (NAME) < 0) \ | 2494 if (unlink (NAME) < 0) \ |
2421 if (VERBOSE_FLAG) \ | 2495 if (VERBOSE_FLAG) \ |
2422 perror_with_name (NAME); \ | 2496 error ("%s: %m", (NAME)); \ |
2423 } while (0) | 2497 } while (0) |
2424 #endif | 2498 #endif |
2425 | 2499 |
2426 static void | 2500 static void |
2427 delete_if_ordinary (const char *name) | 2501 delete_if_ordinary (const char *name) |
3096 | (string == commands[i].prog ? PEX_SEARCH : 0)), | 3170 | (string == commands[i].prog ? PEX_SEARCH : 0)), |
3097 string, CONST_CAST (char **, commands[i].argv), | 3171 string, CONST_CAST (char **, commands[i].argv), |
3098 NULL, NULL, &err); | 3172 NULL, NULL, &err); |
3099 if (errmsg != NULL) | 3173 if (errmsg != NULL) |
3100 { | 3174 { |
3101 if (err == 0) | 3175 errno = err; |
3102 fatal_error (input_location, errmsg); | 3176 fatal_error (input_location, |
3103 else | 3177 err ? G_("cannot execute %qs: %s: %m") |
3104 { | 3178 : G_("cannot execute %qs: %s"), |
3105 errno = err; | 3179 string, errmsg); |
3106 pfatal_with_name (errmsg); | |
3107 } | |
3108 } | 3180 } |
3109 | 3181 |
3110 if (i && string != commands[i].prog) | 3182 if (i && string != commands[i].prog) |
3111 free (CONST_CAST (char *, string)); | 3183 free (CONST_CAST (char *, string)); |
3112 } | 3184 } |
3822 add_preprocessor_option ("--version", strlen ("--version")); | 3894 add_preprocessor_option ("--version", strlen ("--version")); |
3823 add_assembler_option ("--version", strlen ("--version")); | 3895 add_assembler_option ("--version", strlen ("--version")); |
3824 add_linker_option ("--version", strlen ("--version")); | 3896 add_linker_option ("--version", strlen ("--version")); |
3825 break; | 3897 break; |
3826 | 3898 |
3899 case OPT__completion_: | |
3900 validated = true; | |
3901 completion = decoded->arg; | |
3902 break; | |
3903 | |
3827 case OPT__help: | 3904 case OPT__help: |
3828 print_help_list = 1; | 3905 print_help_list = 1; |
3829 | 3906 |
3830 /* CPP driver cannot obtain switch from cc1_options. */ | 3907 /* CPP driver cannot obtain switch from cc1_options. */ |
3831 if (is_cpp_driver) | 3908 if (is_cpp_driver) |
4467 else | 4544 else |
4468 fname = xstrdup (arg); | 4545 fname = xstrdup (arg); |
4469 | 4546 |
4470 if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) | 4547 if (strcmp (fname, "-") != 0 && access (fname, F_OK) < 0) |
4471 { | 4548 { |
4472 if (fname[0] == '@' && access (fname + 1, F_OK) < 0) | 4549 bool resp = fname[0] == '@' && access (fname + 1, F_OK) < 0; |
4473 perror_with_name (fname + 1); | 4550 error ("%s: %m", fname + resp); |
4474 else | |
4475 perror_with_name (fname); | |
4476 } | 4551 } |
4477 else | 4552 else |
4478 add_infile (arg, spec_lang); | 4553 add_infile (arg, spec_lang); |
4479 | 4554 |
4480 free (fname); | 4555 free (fname); |
4862 int | 4937 int |
4863 do_spec (const char *spec) | 4938 do_spec (const char *spec) |
4864 { | 4939 { |
4865 int value; | 4940 int value; |
4866 | 4941 |
4867 value = do_spec_2 (spec); | 4942 value = do_spec_2 (spec, NULL); |
4868 | 4943 |
4869 /* Force out any unfinished command. | 4944 /* Force out any unfinished command. |
4870 If -pipe, this forces out the last command if it ended in `|'. */ | 4945 If -pipe, this forces out the last command if it ended in `|'. */ |
4871 if (value == 0) | 4946 if (value == 0) |
4872 { | 4947 { |
4881 } | 4956 } |
4882 | 4957 |
4883 return value; | 4958 return value; |
4884 } | 4959 } |
4885 | 4960 |
4961 /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value | |
4962 of a matched * pattern which may be re-injected by way of %*. */ | |
4963 | |
4886 static int | 4964 static int |
4887 do_spec_2 (const char *spec) | 4965 do_spec_2 (const char *spec, const char *soft_matched_part) |
4888 { | 4966 { |
4889 int result; | 4967 int result; |
4890 | 4968 |
4891 clear_args (); | 4969 clear_args (); |
4892 arg_going = 0; | 4970 arg_going = 0; |
4895 this_is_library_file = 0; | 4973 this_is_library_file = 0; |
4896 this_is_linker_script = 0; | 4974 this_is_linker_script = 0; |
4897 input_from_pipe = 0; | 4975 input_from_pipe = 0; |
4898 suffix_subst = NULL; | 4976 suffix_subst = NULL; |
4899 | 4977 |
4900 result = do_spec_1 (spec, 0, NULL); | 4978 result = do_spec_1 (spec, 0, soft_matched_part); |
4901 | 4979 |
4902 end_going_arg (); | 4980 end_going_arg (); |
4903 | 4981 |
4904 return result; | 4982 return result; |
4905 } | 4983 } |
4906 | |
4907 | 4984 |
4908 /* Process the given spec string and add any new options to the end | 4985 /* Process the given spec string and add any new options to the end |
4909 of the switches/n_switches array. */ | 4986 of the switches/n_switches array. */ |
4910 | 4987 |
4911 static void | 4988 static void |
4960 static void | 5037 static void |
4961 do_self_spec (const char *spec) | 5038 do_self_spec (const char *spec) |
4962 { | 5039 { |
4963 int i; | 5040 int i; |
4964 | 5041 |
4965 do_spec_2 (spec); | 5042 do_spec_2 (spec, NULL); |
4966 do_spec_1 (" ", 0, NULL); | 5043 do_spec_1 (" ", 0, NULL); |
4967 | 5044 |
4968 /* Mark %<S switches processed by do_self_spec to be ignored permanently. | 5045 /* Mark %<S switches processed by do_self_spec to be ignored permanently. |
4969 do_self_specs adds the replacements to switches array, so it shouldn't | 5046 do_self_specs adds the replacements to switches array, so it shouldn't |
4970 be processed afterwards. */ | 5047 be processed afterwards. */ |
5086 /* Must not damage the original path. */ | 5163 /* Must not damage the original path. */ |
5087 if (info->append_len == 0) | 5164 if (info->append_len == 0) |
5088 path[len - 1] = save; | 5165 path[len - 1] = save; |
5089 | 5166 |
5090 return NULL; | 5167 return NULL; |
5091 } | |
5092 | |
5093 /* Create a temporary FILE with the contents of ARGV. Add @FILE to the | |
5094 argument list. */ | |
5095 | |
5096 static void | |
5097 create_at_file (char **argv) | |
5098 { | |
5099 char *temp_file = make_temp_file (""); | |
5100 char *at_argument = concat ("@", temp_file, NULL); | |
5101 FILE *f = fopen (temp_file, "w"); | |
5102 int status; | |
5103 | |
5104 if (f == NULL) | |
5105 fatal_error (input_location, "could not open temporary response file %s", | |
5106 temp_file); | |
5107 | |
5108 status = writeargv (argv, f); | |
5109 | |
5110 if (status) | |
5111 fatal_error (input_location, | |
5112 "could not write to temporary response file %s", | |
5113 temp_file); | |
5114 | |
5115 status = fclose (f); | |
5116 | |
5117 if (EOF == status) | |
5118 fatal_error (input_location, "could not close temporary response file %s", | |
5119 temp_file); | |
5120 | |
5121 store_arg (at_argument, 0, 0); | |
5122 | |
5123 record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); | |
5124 } | 5168 } |
5125 | 5169 |
5126 /* True if we should compile INFILE. */ | 5170 /* True if we should compile INFILE. */ |
5127 | 5171 |
5128 static bool | 5172 static bool |
5312 while (*p != 0 && *p != '\n') | 5356 while (*p != 0 && *p != '\n') |
5313 p++; | 5357 p++; |
5314 buf = (char *) alloca (p - q + 1); | 5358 buf = (char *) alloca (p - q + 1); |
5315 strncpy (buf, q, p - q); | 5359 strncpy (buf, q, p - q); |
5316 buf[p - q] = 0; | 5360 buf[p - q] = 0; |
5317 inform (0, "%s", _(buf)); | 5361 inform (UNKNOWN_LOCATION, "%s", _(buf)); |
5318 if (*p) | 5362 if (*p) |
5319 p++; | 5363 p++; |
5320 } | 5364 } |
5321 break; | 5365 break; |
5322 | 5366 |
5533 break; | 5577 break; |
5534 | 5578 |
5535 case 'i': | 5579 case 'i': |
5536 if (combine_inputs) | 5580 if (combine_inputs) |
5537 { | 5581 { |
5582 /* We are going to expand `%i' into `@FILE', where FILE | |
5583 is a newly-created temporary filename. The filenames | |
5584 that would usually be expanded in place of %o will be | |
5585 written to the temporary file. */ | |
5538 if (at_file_supplied) | 5586 if (at_file_supplied) |
5539 { | 5587 open_at_file (); |
5540 /* We are going to expand `%i' to `@FILE', where FILE | 5588 |
5541 is a newly-created temporary filename. The filenames | 5589 for (i = 0; (int) i < n_infiles; i++) |
5542 that would usually be expanded in place of %o will be | 5590 if (compile_input_file_p (&infiles[i])) |
5543 written to the temporary file. */ | 5591 { |
5544 char **argv; | 5592 store_arg (infiles[i].name, 0, 0); |
5545 int n_files = 0; | 5593 infiles[i].compiled = true; |
5546 int j; | 5594 } |
5547 | 5595 |
5548 for (i = 0; i < n_infiles; i++) | 5596 if (at_file_supplied) |
5549 if (compile_input_file_p (&infiles[i])) | 5597 close_at_file (); |
5550 n_files++; | |
5551 | |
5552 argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
5553 | |
5554 /* Copy the strings over. */ | |
5555 for (i = 0, j = 0; i < n_infiles; i++) | |
5556 if (compile_input_file_p (&infiles[i])) | |
5557 { | |
5558 argv[j] = CONST_CAST (char *, infiles[i].name); | |
5559 infiles[i].compiled = true; | |
5560 j++; | |
5561 } | |
5562 argv[j] = NULL; | |
5563 | |
5564 create_at_file (argv); | |
5565 } | |
5566 else | |
5567 for (i = 0; (int) i < n_infiles; i++) | |
5568 if (compile_input_file_p (&infiles[i])) | |
5569 { | |
5570 store_arg (infiles[i].name, 0, 0); | |
5571 infiles[i].compiled = true; | |
5572 } | |
5573 } | 5598 } |
5574 else | 5599 else |
5575 { | 5600 { |
5576 obstack_grow (&obstack, gcc_input_filename, | 5601 obstack_grow (&obstack, gcc_input_filename, |
5577 input_filename_length); | 5602 input_filename_length); |
5640 spec_path, &info); | 5665 spec_path, &info); |
5641 } | 5666 } |
5642 break; | 5667 break; |
5643 | 5668 |
5644 case 'o': | 5669 case 'o': |
5645 { | 5670 /* We are going to expand `%o' into `@FILE', where FILE |
5646 int max = n_infiles; | 5671 is a newly-created temporary filename. The filenames |
5647 max += lang_specific_extra_outfiles; | 5672 that would usually be expanded in place of %o will be |
5648 | 5673 written to the temporary file. */ |
5649 if (HAVE_GNU_LD && at_file_supplied) | 5674 if (at_file_supplied) |
5650 { | 5675 open_at_file (); |
5651 /* We are going to expand `%o' to `@FILE', where FILE | 5676 |
5652 is a newly-created temporary filename. The filenames | 5677 for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++) |
5653 that would usually be expanded in place of %o will be | 5678 if (outfiles[i]) |
5654 written to the temporary file. */ | 5679 store_arg (outfiles[i], 0, 0); |
5655 | 5680 |
5656 char **argv; | 5681 if (at_file_supplied) |
5657 int n_files, j; | 5682 close_at_file (); |
5658 | 5683 break; |
5659 /* Convert OUTFILES into a form suitable for writeargv. */ | |
5660 | |
5661 /* Determine how many are non-NULL. */ | |
5662 for (n_files = 0, i = 0; i < max; i++) | |
5663 n_files += outfiles[i] != NULL; | |
5664 | |
5665 argv = (char **) alloca (sizeof (char *) * (n_files + 1)); | |
5666 | |
5667 /* Copy the strings over. */ | |
5668 for (i = 0, j = 0; i < max; i++) | |
5669 if (outfiles[i]) | |
5670 { | |
5671 argv[j] = CONST_CAST (char *, outfiles[i]); | |
5672 j++; | |
5673 } | |
5674 argv[j] = NULL; | |
5675 | |
5676 create_at_file (argv); | |
5677 } | |
5678 else | |
5679 for (i = 0; i < max; i++) | |
5680 if (outfiles[i]) | |
5681 store_arg (outfiles[i], 0, 0); | |
5682 break; | |
5683 } | |
5684 | 5684 |
5685 case 'O': | 5685 case 'O': |
5686 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); | 5686 obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
5687 arg_going = 1; | 5687 arg_going = 1; |
5688 break; | 5688 break; |
5719 if (argbuf.length () != cur_index) | 5719 if (argbuf.length () != cur_index) |
5720 record_temp_file (argbuf.last (), 0, 1); | 5720 record_temp_file (argbuf.last (), 0, 1); |
5721 break; | 5721 break; |
5722 } | 5722 } |
5723 | 5723 |
5724 case '@': | |
5725 /* Handle the {...} following the %@. */ | |
5726 if (*p != '{') | |
5727 fatal_error (input_location, | |
5728 "spec %qs has invalid %<%%@%c%>", spec, *p); | |
5729 if (at_file_supplied) | |
5730 open_at_file (); | |
5731 p = handle_braces (p + 1); | |
5732 if (at_file_supplied) | |
5733 close_at_file (); | |
5734 if (p == 0) | |
5735 return -1; | |
5736 break; | |
5737 | |
5724 /* %x{OPTION} records OPTION for %X to output. */ | 5738 /* %x{OPTION} records OPTION for %X to output. */ |
5725 case 'x': | 5739 case 'x': |
5726 { | 5740 { |
5727 const char *p1 = p; | 5741 const char *p1 = p; |
5728 char *string; | 5742 char *string; |
5863 if (p == 0) | 5877 if (p == 0) |
5864 return -1; | 5878 return -1; |
5865 break; | 5879 break; |
5866 | 5880 |
5867 case ':': | 5881 case ':': |
5868 p = handle_spec_function (p, NULL); | 5882 p = handle_spec_function (p, NULL, soft_matched_part); |
5869 if (p == 0) | 5883 if (p == 0) |
5870 return -1; | 5884 return -1; |
5871 break; | 5885 break; |
5872 | 5886 |
5873 case '%': | 5887 case '%': |
6025 } | 6039 } |
6026 | 6040 |
6027 /* Evaluate a spec function. */ | 6041 /* Evaluate a spec function. */ |
6028 | 6042 |
6029 static const char * | 6043 static const char * |
6030 eval_spec_function (const char *func, const char *args) | 6044 eval_spec_function (const char *func, const char *args, |
6045 const char *soft_matched_part) | |
6031 { | 6046 { |
6032 const struct spec_function *sf; | 6047 const struct spec_function *sf; |
6033 const char *funcval; | 6048 const char *funcval; |
6034 | 6049 |
6035 /* Saved spec processing context. */ | 6050 /* Saved spec processing context. */ |
6075 | 6090 |
6076 /* Create a new spec processing context, and build the function | 6091 /* Create a new spec processing context, and build the function |
6077 arguments. */ | 6092 arguments. */ |
6078 | 6093 |
6079 alloc_args (); | 6094 alloc_args (); |
6080 if (do_spec_2 (args) < 0) | 6095 if (do_spec_2 (args, soft_matched_part) < 0) |
6081 fatal_error (input_location, "error in args to spec function %qs", func); | 6096 fatal_error (input_location, "error in args to spec function %qs", func); |
6082 | 6097 |
6083 /* argbuf_index is an index for the next argument to be inserted, and | 6098 /* argbuf_index is an index for the next argument to be inserted, and |
6084 so contains the count of the args already inserted. */ | 6099 so contains the count of the args already inserted. */ |
6085 | 6100 |
6112 argument vector in the normal fashion. The function returns a string | 6127 argument vector in the normal fashion. The function returns a string |
6113 containing a spec which we then process in the caller's context, or | 6128 containing a spec which we then process in the caller's context, or |
6114 NULL if no processing is required. | 6129 NULL if no processing is required. |
6115 | 6130 |
6116 If RETVAL_NONNULL is not NULL, then store a bool whether function | 6131 If RETVAL_NONNULL is not NULL, then store a bool whether function |
6117 returned non-NULL. */ | 6132 returned non-NULL. |
6133 | |
6134 SOFT_MATCHED_PART holds the current value of a matched * pattern, which | |
6135 may be re-expanded with a %* as part of the function arguments. */ | |
6118 | 6136 |
6119 static const char * | 6137 static const char * |
6120 handle_spec_function (const char *p, bool *retval_nonnull) | 6138 handle_spec_function (const char *p, bool *retval_nonnull, |
6139 const char *soft_matched_part) | |
6121 { | 6140 { |
6122 char *func, *args; | 6141 char *func, *args; |
6123 const char *endp, *funcval; | 6142 const char *endp, *funcval; |
6124 int count; | 6143 int count; |
6125 | 6144 |
6158 args = save_string (p, endp - p); | 6177 args = save_string (p, endp - p); |
6159 p = ++endp; | 6178 p = ++endp; |
6160 | 6179 |
6161 /* p now points to just past the end of the spec function expression. */ | 6180 /* p now points to just past the end of the spec function expression. */ |
6162 | 6181 |
6163 funcval = eval_spec_function (func, args); | 6182 funcval = eval_spec_function (func, args, soft_matched_part); |
6164 if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) | 6183 if (funcval != NULL && do_spec_1 (funcval, 0, NULL) < 0) |
6165 p = NULL; | 6184 p = NULL; |
6166 if (retval_nonnull) | 6185 if (retval_nonnull) |
6167 *retval_nonnull = funcval != NULL; | 6186 *retval_nonnull = funcval != NULL; |
6168 | 6187 |
6312 SKIP_WHITE (); | 6331 SKIP_WHITE (); |
6313 if (*p == '%' && p[1] == ':') | 6332 if (*p == '%' && p[1] == ':') |
6314 { | 6333 { |
6315 atom = NULL; | 6334 atom = NULL; |
6316 end_atom = NULL; | 6335 end_atom = NULL; |
6317 p = handle_spec_function (p + 2, &a_matched); | 6336 p = handle_spec_function (p + 2, &a_matched, NULL); |
6318 } | 6337 } |
6319 else | 6338 else |
6320 { | 6339 { |
6321 if (*p == '.') | 6340 if (*p == '.') |
6322 p++, a_is_suffix = true; | 6341 p++, a_is_suffix = true; |
6864 errmsg = pex_run (pex, pex_flags, new_argv[0], | 6883 errmsg = pex_run (pex, pex_flags, new_argv[0], |
6865 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, | 6884 CONST_CAST2 (char *const *, const char **, &new_argv[1]), out_temp, |
6866 err_temp, &err); | 6885 err_temp, &err); |
6867 if (errmsg != NULL) | 6886 if (errmsg != NULL) |
6868 { | 6887 { |
6869 if (err == 0) | 6888 errno = err; |
6870 fatal_error (input_location, errmsg); | 6889 fatal_error (input_location, |
6871 else | 6890 err ? G_ ("cannot execute %qs: %s: %m") |
6872 { | 6891 : G_ ("cannot execute %qs: %s"), |
6873 errno = err; | 6892 new_argv[0], errmsg); |
6874 pfatal_with_name (errmsg); | |
6875 } | |
6876 } | 6893 } |
6877 | 6894 |
6878 if (!pex_get_status (pex, 1, &exit_status)) | 6895 if (!pex_get_status (pex, 1, &exit_status)) |
6879 goto out; | 6896 goto out; |
6880 | 6897 |
7039 insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1], | 7056 insert_comments (temp_stderr_files[RETRY_ICE_ATTEMPTS - 1], |
7040 *stderr_commented); | 7057 *stderr_commented); |
7041 | 7058 |
7042 /* In final attempt we append compiler options and preprocesssed code to last | 7059 /* In final attempt we append compiler options and preprocesssed code to last |
7043 generated .out file with configuration and backtrace. */ | 7060 generated .out file with configuration and backtrace. */ |
7044 char **output = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1]; | 7061 char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1]; |
7045 do_report_bug (new_argv, nargs, stderr_commented, output); | 7062 do_report_bug (new_argv, nargs, stderr_commented, err); |
7046 } | 7063 } |
7047 | 7064 |
7048 out: | 7065 out: |
7049 for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++) | 7066 for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++) |
7050 if (temp_files[i]) | 7067 if (temp_files[i]) |
7266 return ret; | 7283 return ret; |
7267 } | 7284 } |
7268 | 7285 |
7269 driver::driver (bool can_finalize, bool debug) : | 7286 driver::driver (bool can_finalize, bool debug) : |
7270 explicit_link_files (NULL), | 7287 explicit_link_files (NULL), |
7271 decoded_options (NULL), | 7288 decoded_options (NULL) |
7272 m_option_suggestions (NULL) | |
7273 { | 7289 { |
7274 env.init (can_finalize, debug); | 7290 env.init (can_finalize, debug); |
7275 } | 7291 } |
7276 | 7292 |
7277 driver::~driver () | 7293 driver::~driver () |
7278 { | 7294 { |
7279 XDELETEVEC (explicit_link_files); | 7295 XDELETEVEC (explicit_link_files); |
7280 XDELETEVEC (decoded_options); | 7296 XDELETEVEC (decoded_options); |
7281 if (m_option_suggestions) | |
7282 { | |
7283 int i; | |
7284 char *str; | |
7285 FOR_EACH_VEC_ELT (*m_option_suggestions, i, str) | |
7286 free (str); | |
7287 delete m_option_suggestions; | |
7288 } | |
7289 } | 7297 } |
7290 | 7298 |
7291 /* driver::main is implemented as a series of driver:: method calls. */ | 7299 /* driver::main is implemented as a series of driver:: method calls. */ |
7292 | 7300 |
7293 int | 7301 int |
7304 putenv_COLLECT_GCC (argv[0]); | 7312 putenv_COLLECT_GCC (argv[0]); |
7305 maybe_putenv_COLLECT_LTO_WRAPPER (); | 7313 maybe_putenv_COLLECT_LTO_WRAPPER (); |
7306 maybe_putenv_OFFLOAD_TARGETS (); | 7314 maybe_putenv_OFFLOAD_TARGETS (); |
7307 handle_unrecognized_options (); | 7315 handle_unrecognized_options (); |
7308 | 7316 |
7317 if (completion) | |
7318 { | |
7319 m_option_proposer.suggest_completion (completion); | |
7320 return 0; | |
7321 } | |
7322 | |
7309 if (!maybe_print_and_exit ()) | 7323 if (!maybe_print_and_exit ()) |
7310 return 0; | 7324 return 0; |
7311 | 7325 |
7312 early_exit = prepare_infiles (); | 7326 early_exit = prepare_infiles (); |
7313 if (early_exit) | 7327 if (early_exit) |
7550 } | 7564 } |
7551 | 7565 |
7552 /* Process sysroot_suffix_spec. */ | 7566 /* Process sysroot_suffix_spec. */ |
7553 if (*sysroot_suffix_spec != 0 | 7567 if (*sysroot_suffix_spec != 0 |
7554 && !no_sysroot_suffix | 7568 && !no_sysroot_suffix |
7555 && do_spec_2 (sysroot_suffix_spec) == 0) | 7569 && do_spec_2 (sysroot_suffix_spec, NULL) == 0) |
7556 { | 7570 { |
7557 if (argbuf.length () > 1) | 7571 if (argbuf.length () > 1) |
7558 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); | 7572 error ("spec failure: more than one arg to SYSROOT_SUFFIX_SPEC"); |
7559 else if (argbuf.length () == 1) | 7573 else if (argbuf.length () == 1) |
7560 target_sysroot_suffix = xstrdup (argbuf.last ()); | 7574 target_sysroot_suffix = xstrdup (argbuf.last ()); |
7574 #endif | 7588 #endif |
7575 | 7589 |
7576 /* Process sysroot_hdrs_suffix_spec. */ | 7590 /* Process sysroot_hdrs_suffix_spec. */ |
7577 if (*sysroot_hdrs_suffix_spec != 0 | 7591 if (*sysroot_hdrs_suffix_spec != 0 |
7578 && !no_sysroot_suffix | 7592 && !no_sysroot_suffix |
7579 && do_spec_2 (sysroot_hdrs_suffix_spec) == 0) | 7593 && do_spec_2 (sysroot_hdrs_suffix_spec, NULL) == 0) |
7580 { | 7594 { |
7581 if (argbuf.length () > 1) | 7595 if (argbuf.length () > 1) |
7582 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); | 7596 error ("spec failure: more than one arg to SYSROOT_HEADERS_SUFFIX_SPEC"); |
7583 else if (argbuf.length () == 1) | 7597 else if (argbuf.length () == 1) |
7584 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); | 7598 target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); |
7585 } | 7599 } |
7586 | 7600 |
7587 /* Look for startfiles in the standard places. */ | 7601 /* Look for startfiles in the standard places. */ |
7588 if (*startfile_prefix_spec != 0 | 7602 if (*startfile_prefix_spec != 0 |
7589 && do_spec_2 (startfile_prefix_spec) == 0 | 7603 && do_spec_2 (startfile_prefix_spec, NULL) == 0 |
7590 && do_spec_1 (" ", 0, NULL) == 0) | 7604 && do_spec_1 (" ", 0, NULL) == 0) |
7591 { | 7605 { |
7592 const char *arg; | 7606 const char *arg; |
7593 int ndx; | 7607 int ndx; |
7594 FOR_EACH_VEC_ELT (argbuf, ndx, arg) | 7608 FOR_EACH_VEC_ELT (argbuf, ndx, arg) |
7772 | 7786 |
7773 free (offload_targets); | 7787 free (offload_targets); |
7774 offload_targets = NULL; | 7788 offload_targets = NULL; |
7775 } | 7789 } |
7776 | 7790 |
7777 /* Helper function for driver::suggest_option. Populate | |
7778 m_option_suggestions with candidate strings for misspelled options. | |
7779 The strings will be freed by the driver's dtor. */ | |
7780 | |
7781 void | |
7782 driver::build_option_suggestions (void) | |
7783 { | |
7784 gcc_assert (m_option_suggestions == NULL); | |
7785 m_option_suggestions = new auto_vec <char *> (); | |
7786 | |
7787 /* We build a vec of m_option_suggestions, using add_misspelling_candidates | |
7788 to add copies of strings, without a leading dash. */ | |
7789 | |
7790 for (unsigned int i = 0; i < cl_options_count; i++) | |
7791 { | |
7792 const struct cl_option *option = &cl_options[i]; | |
7793 const char *opt_text = option->opt_text; | |
7794 switch (i) | |
7795 { | |
7796 default: | |
7797 if (option->var_type == CLVC_ENUM) | |
7798 { | |
7799 const struct cl_enum *e = &cl_enums[option->var_enum]; | |
7800 for (unsigned j = 0; e->values[j].arg != NULL; j++) | |
7801 { | |
7802 char *with_arg = concat (opt_text, e->values[j].arg, NULL); | |
7803 add_misspelling_candidates (m_option_suggestions, option, | |
7804 with_arg); | |
7805 free (with_arg); | |
7806 } | |
7807 } | |
7808 else | |
7809 add_misspelling_candidates (m_option_suggestions, option, | |
7810 opt_text); | |
7811 break; | |
7812 | |
7813 case OPT_fsanitize_: | |
7814 case OPT_fsanitize_recover_: | |
7815 /* -fsanitize= and -fsanitize-recover= can take | |
7816 a comma-separated list of arguments. Given that combinations | |
7817 are supported, we can't add all potential candidates to the | |
7818 vec, but if we at least add them individually without commas, | |
7819 we should do a better job e.g. correcting | |
7820 "-sanitize=address" | |
7821 to | |
7822 "-fsanitize=address" | |
7823 rather than to "-Wframe-address" (PR driver/69265). */ | |
7824 { | |
7825 for (int j = 0; sanitizer_opts[j].name != NULL; ++j) | |
7826 { | |
7827 struct cl_option optb; | |
7828 /* -fsanitize=all is not valid, only -fno-sanitize=all. | |
7829 So don't register the positive misspelling candidates | |
7830 for it. */ | |
7831 if (sanitizer_opts[j].flag == ~0U && i == OPT_fsanitize_) | |
7832 { | |
7833 optb = *option; | |
7834 optb.opt_text = opt_text = "-fno-sanitize="; | |
7835 optb.cl_reject_negative = true; | |
7836 option = &optb; | |
7837 } | |
7838 /* Get one arg at a time e.g. "-fsanitize=address". */ | |
7839 char *with_arg = concat (opt_text, | |
7840 sanitizer_opts[j].name, | |
7841 NULL); | |
7842 /* Add with_arg and all of its variant spellings e.g. | |
7843 "-fno-sanitize=address" to candidates (albeit without | |
7844 leading dashes). */ | |
7845 add_misspelling_candidates (m_option_suggestions, option, | |
7846 with_arg); | |
7847 free (with_arg); | |
7848 } | |
7849 } | |
7850 break; | |
7851 } | |
7852 } | |
7853 } | |
7854 | |
7855 /* Helper function for driver::handle_unrecognized_options. | |
7856 | |
7857 Given an unrecognized option BAD_OPT (without the leading dash), | |
7858 locate the closest reasonable matching option (again, without the | |
7859 leading dash), or NULL. | |
7860 | |
7861 The returned string is owned by the driver instance. */ | |
7862 | |
7863 const char * | |
7864 driver::suggest_option (const char *bad_opt) | |
7865 { | |
7866 /* Lazily populate m_option_suggestions. */ | |
7867 if (!m_option_suggestions) | |
7868 build_option_suggestions (); | |
7869 gcc_assert (m_option_suggestions); | |
7870 | |
7871 /* "m_option_suggestions" is now populated. Use it. */ | |
7872 return find_closest_string | |
7873 (bad_opt, | |
7874 (auto_vec <const char *> *) m_option_suggestions); | |
7875 } | |
7876 | |
7877 /* Reject switches that no pass was interested in. */ | 7791 /* Reject switches that no pass was interested in. */ |
7878 | 7792 |
7879 void | 7793 void |
7880 driver::handle_unrecognized_options () | 7794 driver::handle_unrecognized_options () |
7881 { | 7795 { |
7882 for (size_t i = 0; (int) i < n_switches; i++) | 7796 for (size_t i = 0; (int) i < n_switches; i++) |
7883 if (! switches[i].validated) | 7797 if (! switches[i].validated) |
7884 { | 7798 { |
7885 const char *hint = suggest_option (switches[i].part1); | 7799 const char *hint = m_option_proposer.suggest_option (switches[i].part1); |
7886 if (hint) | 7800 if (hint) |
7887 error ("unrecognized command line option %<-%s%>;" | 7801 error ("unrecognized command line option %<-%s%>;" |
7888 " did you mean %<-%s%>?", | 7802 " did you mean %<-%s%>?", |
7889 switches[i].part1, hint); | 7803 switches[i].part1, hint); |
7890 else | 7804 else |
8039 | 7953 |
8040 if (print_version) | 7954 if (print_version) |
8041 { | 7955 { |
8042 printf (_("%s %s%s\n"), progname, pkgversion_string, | 7956 printf (_("%s %s%s\n"), progname, pkgversion_string, |
8043 version_string); | 7957 version_string); |
8044 printf ("Copyright %s 2017 Free Software Foundation, Inc.\n", | 7958 printf ("Copyright %s 2018 Free Software Foundation, Inc.\n", |
8045 _("(C)")); | 7959 _("(C)")); |
8046 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ | 7960 fputs (_("This is free software; see the source for copying conditions. There is NO\n\ |
8047 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), | 7961 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"), |
8048 stdout); | 7962 stdout); |
8049 if (! verbose_flag) | 7963 if (! verbose_flag) |
8189 if (value < 0) | 8103 if (value < 0) |
8190 this_file_error = 1; | 8104 this_file_error = 1; |
8191 else if (compare_debug && debug_check_temp_file[0]) | 8105 else if (compare_debug && debug_check_temp_file[0]) |
8192 { | 8106 { |
8193 if (verbose_flag) | 8107 if (verbose_flag) |
8194 inform (0, "recompiling with -fcompare-debug"); | 8108 inform (UNKNOWN_LOCATION, |
8109 "recompiling with -fcompare-debug"); | |
8195 | 8110 |
8196 compare_debug = -compare_debug; | 8111 compare_debug = -compare_debug; |
8197 n_switches = n_switches_debug_check[1]; | 8112 n_switches = n_switches_debug_check[1]; |
8198 n_switches_alloc = n_switches_alloc_debug_check[1]; | 8113 n_switches_alloc = n_switches_alloc_debug_check[1]; |
8199 switches = switches_debug_check[1]; | 8114 switches = switches_debug_check[1]; |
8214 gcc_assert (debug_check_temp_file[1] | 8129 gcc_assert (debug_check_temp_file[1] |
8215 && filename_cmp (debug_check_temp_file[0], | 8130 && filename_cmp (debug_check_temp_file[0], |
8216 debug_check_temp_file[1])); | 8131 debug_check_temp_file[1])); |
8217 | 8132 |
8218 if (verbose_flag) | 8133 if (verbose_flag) |
8219 inform (0, "comparing final insns dumps"); | 8134 inform (UNKNOWN_LOCATION, "comparing final insns dumps"); |
8220 | 8135 |
8221 if (compare_files (debug_check_temp_file)) | 8136 if (compare_files (debug_check_temp_file)) |
8222 this_file_error = 1; | 8137 this_file_error = 1; |
8223 } | 8138 } |
8224 | 8139 |
8487 memcpy (result, s, len); | 8402 memcpy (result, s, len); |
8488 result[len] = 0; | 8403 result[len] = 0; |
8489 return result; | 8404 return result; |
8490 } | 8405 } |
8491 | 8406 |
8492 void | |
8493 pfatal_with_name (const char *name) | |
8494 { | |
8495 perror_with_name (name); | |
8496 delete_temp_files (); | |
8497 exit (1); | |
8498 } | |
8499 | |
8500 static void | |
8501 perror_with_name (const char *name) | |
8502 { | |
8503 error ("%s: %m", name); | |
8504 } | |
8505 | 8407 |
8506 static inline void | 8408 static inline void |
8507 validate_switches_from_spec (const char *spec, bool user) | 8409 validate_switches_from_spec (const char *spec, bool user) |
8508 { | 8410 { |
8509 const char *p = spec; | 8411 const char *p = spec; |
8510 char c; | 8412 char c; |
8511 while ((c = *p++)) | 8413 while ((c = *p++)) |
8512 if (c == '%' && (*p == '{' || *p == '<' || (*p == 'W' && *++p == '{'))) | 8414 if (c == '%' |
8415 && (*p == '{' | |
8416 || *p == '<' | |
8417 || (*p == 'W' && *++p == '{') | |
8418 || (*p == '@' && *++p == '{'))) | |
8513 /* We have a switch spec. */ | 8419 /* We have a switch spec. */ |
8514 p = validate_switches (p + 1, user); | 8420 p = validate_switches (p + 1, user); |
8515 } | 8421 } |
8516 | 8422 |
8517 static void | 8423 static void |
8588 { | 8494 { |
8589 p++; | 8495 p++; |
8590 if (*p == '{' || *p == '<') | 8496 if (*p == '{' || *p == '<') |
8591 p = validate_switches (p+1, user_spec); | 8497 p = validate_switches (p+1, user_spec); |
8592 else if (p[0] == 'W' && p[1] == '{') | 8498 else if (p[0] == 'W' && p[1] == '{') |
8499 p = validate_switches (p+2, user_spec); | |
8500 else if (p[0] == '@' && p[1] == '{') | |
8593 p = validate_switches (p+2, user_spec); | 8501 p = validate_switches (p+2, user_spec); |
8594 } | 8502 } |
8595 else | 8503 else |
8596 p++; | 8504 p++; |
8597 } | 8505 } |
9326 /* getenv built-in spec function. | 9234 /* getenv built-in spec function. |
9327 | 9235 |
9328 Returns the value of the environment variable given by its first argument, | 9236 Returns the value of the environment variable given by its first argument, |
9329 concatenated with the second argument. If the variable is not defined, a | 9237 concatenated with the second argument. If the variable is not defined, a |
9330 fatal error is issued unless such undefs are internally allowed, in which | 9238 fatal error is issued unless such undefs are internally allowed, in which |
9331 case the variable name is used as the variable value. */ | 9239 case the variable name prefixed by a '/' is used as the variable value. |
9240 | |
9241 The leading '/' allows using the result at a spot where a full path would | |
9242 normally be expected and when the actual value doesn't really matter since | |
9243 undef vars are allowed. */ | |
9332 | 9244 |
9333 static const char * | 9245 static const char * |
9334 getenv_spec_function (int argc, const char **argv) | 9246 getenv_spec_function (int argc, const char **argv) |
9335 { | 9247 { |
9336 const char *value; | 9248 const char *value; |
9344 return NULL; | 9256 return NULL; |
9345 | 9257 |
9346 varname = argv[0]; | 9258 varname = argv[0]; |
9347 value = env.get (varname); | 9259 value = env.get (varname); |
9348 | 9260 |
9261 /* If the variable isn't defined and this is allowed, craft our expected | |
9262 return value. Assume variable names used in specs strings don't contain | |
9263 any active spec character so don't need escaping. */ | |
9349 if (!value && spec_undefvar_allowed) | 9264 if (!value && spec_undefvar_allowed) |
9350 value = varname; | 9265 { |
9266 result = XNEWVAR (char, strlen(varname) + 2); | |
9267 sprintf (result, "/%s", varname); | |
9268 return result; | |
9269 } | |
9351 | 9270 |
9352 if (!value) | 9271 if (!value) |
9353 fatal_error (input_location, | 9272 fatal_error (input_location, |
9354 "environment variable %qs not defined", varname); | 9273 "environment variable %qs not defined", varname); |
9355 | 9274 |
9711 | 9630 |
9712 if (arg != 0) | 9631 if (arg != 0) |
9713 fatal_error (input_location, | 9632 fatal_error (input_location, |
9714 "too many arguments to %%:compare-debug-dump-opt"); | 9633 "too many arguments to %%:compare-debug-dump-opt"); |
9715 | 9634 |
9716 do_spec_2 ("%{fdump-final-insns=*:%*}"); | 9635 do_spec_2 ("%{fdump-final-insns=*:%*}", NULL); |
9717 do_spec_1 (" ", 0, NULL); | 9636 do_spec_1 (" ", 0, NULL); |
9718 | 9637 |
9719 if (argbuf.length () > 0 | 9638 if (argbuf.length () > 0 |
9720 && strcmp (argv[argbuf.length () - 1], ".")) | 9639 && strcmp (argv[argbuf.length () - 1], ".")) |
9721 { | 9640 { |
9729 { | 9648 { |
9730 const char *ext = NULL; | 9649 const char *ext = NULL; |
9731 | 9650 |
9732 if (argbuf.length () > 0) | 9651 if (argbuf.length () > 0) |
9733 { | 9652 { |
9734 do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}"); | 9653 do_spec_2 ("%{o*:%*}%{!o:%{!S:%b%O}%{S:%b.s}}", NULL); |
9735 ext = ".gkd"; | 9654 ext = ".gkd"; |
9736 } | 9655 } |
9737 else if (!compare_debug) | 9656 else if (!compare_debug) |
9738 return NULL; | 9657 return NULL; |
9739 else | 9658 else |
9740 do_spec_2 ("%g.gkd"); | 9659 do_spec_2 ("%g.gkd", NULL); |
9741 | 9660 |
9742 do_spec_1 (" ", 0, NULL); | 9661 do_spec_1 (" ", 0, NULL); |
9743 | 9662 |
9744 gcc_assert (argbuf.length () > 0); | 9663 gcc_assert (argbuf.length () > 0); |
9745 | 9664 |
9787 "too many arguments to %%:compare-debug-self-opt"); | 9706 "too many arguments to %%:compare-debug-self-opt"); |
9788 | 9707 |
9789 if (compare_debug >= 0) | 9708 if (compare_debug >= 0) |
9790 return NULL; | 9709 return NULL; |
9791 | 9710 |
9792 do_spec_2 ("%{c|S:%{o*:%*}}"); | 9711 do_spec_2 ("%{c|S:%{o*:%*}}", NULL); |
9793 do_spec_1 (" ", 0, NULL); | 9712 do_spec_1 (" ", 0, NULL); |
9794 | 9713 |
9795 if (argbuf.length () > 0) | 9714 if (argbuf.length () > 0) |
9796 debug_auxbase_opt = concat ("-auxbase-strip ", | 9715 debug_auxbase_opt = concat ("-auxbase-strip ", |
9797 argbuf.last (), | 9716 argbuf.last (), |
10147 extra_specs = NULL; | 10066 extra_specs = NULL; |
10148 #endif | 10067 #endif |
10149 | 10068 |
10150 processing_spec_function = 0; | 10069 processing_spec_function = 0; |
10151 | 10070 |
10152 argbuf.truncate (0); | 10071 clear_args (); |
10153 | 10072 |
10154 have_c = 0; | 10073 have_c = 0; |
10155 have_o = 0; | 10074 have_o = 0; |
10156 | 10075 |
10157 temp_names = NULL; | 10076 temp_names = NULL; |