| 1 | /* Compiler driver program that can handle many languages. |
| 2 | Copyright (C) 1987-2025 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GCC. |
| 5 | |
| 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 |
| 8 | Software Foundation; either version 3, or (at your option) any later |
| 9 | version. |
| 10 | |
| 11 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GCC; see the file COPYING3. If not see |
| 18 | <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | /* This program is the user interface to the C compiler and possibly to |
| 21 | other compilers. It is used because compilation is a complicated procedure |
| 22 | which involves running several programs and passing temporary files between |
| 23 | them, forwarding the users switches to those programs selectively, |
| 24 | and deleting the temporary files at the end. |
| 25 | |
| 26 | CC recognizes how to compile each input file by suffixes in the file names. |
| 27 | Once it knows which kind of compilation to perform, the procedure for |
| 28 | compilation is specified by a string called a "spec". */ |
| 29 | |
| 30 | #define INCLUDE_STRING |
| 31 | #include "config.h" |
| 32 | #include "system.h" |
| 33 | #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE |
| 34 | #include <sys/personality.h> |
| 35 | #endif |
| 36 | #include "coretypes.h" |
| 37 | #include "multilib.h" /* before tm.h */ |
| 38 | #include "tm.h" |
| 39 | #include "xregex.h" |
| 40 | #include "obstack.h" |
| 41 | #include "intl.h" |
| 42 | #include "prefix.h" |
| 43 | #include "opt-suggestions.h" |
| 44 | #include "gcc.h" |
| 45 | #include "diagnostic.h" |
| 46 | #include "diagnostic-format.h" |
| 47 | #include "pretty-print-urlifier.h" |
| 48 | #include "flags.h" |
| 49 | #include "opts.h" |
| 50 | #include "filenames.h" |
| 51 | #include "spellcheck.h" |
| 52 | #include "opts-jobserver.h" |
| 53 | #include "common/common-target.h" |
| 54 | #include "gcc-urlifier.h" |
| 55 | #include "opts-diagnostic.h" |
| 56 | |
| 57 | #ifndef MATH_LIBRARY |
| 58 | #define MATH_LIBRARY "m" |
| 59 | #endif |
| 60 | |
| 61 | |
| 62 | /* Manage the manipulation of env vars. |
| 63 | |
| 64 | We poison "getenv" and "putenv", so that all enviroment-handling is |
| 65 | done through this class. Note that poisoning happens in the |
| 66 | preprocessor at the identifier level, and doesn't distinguish between |
| 67 | env.getenv (); |
| 68 | and |
| 69 | getenv (); |
| 70 | Hence we need to use "get" for the accessor method, not "getenv". */ |
| 71 | |
| 72 | struct env_manager |
| 73 | { |
| 74 | public: |
| 75 | void init (bool can_restore, bool debug); |
| 76 | const char *get (const char *name); |
| 77 | void xput (const char *string); |
| 78 | void restore (); |
| 79 | |
| 80 | private: |
| 81 | bool m_can_restore; |
| 82 | bool m_debug; |
| 83 | struct kv |
| 84 | { |
| 85 | char *m_key; |
| 86 | char *m_value; |
| 87 | }; |
| 88 | vec<kv> m_keys; |
| 89 | |
| 90 | }; |
| 91 | |
| 92 | /* The singleton instance of class env_manager. */ |
| 93 | |
| 94 | static env_manager env; |
| 95 | |
| 96 | /* Initializer for class env_manager. |
| 97 | |
| 98 | We can't do this as a constructor since we have a statically |
| 99 | allocated instance ("env" above). */ |
| 100 | |
| 101 | void |
| 102 | env_manager::init (bool can_restore, bool debug) |
| 103 | { |
| 104 | m_can_restore = can_restore; |
| 105 | m_debug = debug; |
| 106 | } |
| 107 | |
| 108 | /* Get the value of NAME within the environment. Essentially |
| 109 | a wrapper for ::getenv, but adding logging, and the possibility |
| 110 | of caching results. */ |
| 111 | |
| 112 | const char * |
| 113 | env_manager::get (const char *name) |
| 114 | { |
| 115 | const char *result = ::getenv (name: name); |
| 116 | if (m_debug) |
| 117 | fprintf (stderr, format: "env_manager::getenv (%s) -> %s\n" , name, result); |
| 118 | return result; |
| 119 | } |
| 120 | |
| 121 | /* Put the given KEY=VALUE entry STRING into the environment. |
| 122 | If the env_manager was initialized with CAN_RESTORE set, then |
| 123 | also record the old value of KEY within the environment, so that it |
| 124 | can be later restored. */ |
| 125 | |
| 126 | void |
| 127 | env_manager::xput (const char *string) |
| 128 | { |
| 129 | if (m_debug) |
| 130 | fprintf (stderr, format: "env_manager::xput (%s)\n" , string); |
| 131 | if (verbose_flag) |
| 132 | fnotice (stderr, "%s\n" , string); |
| 133 | |
| 134 | if (m_can_restore) |
| 135 | { |
| 136 | char *equals = strchr (s: const_cast <char *> (string), c: '='); |
| 137 | gcc_assert (equals); |
| 138 | |
| 139 | struct kv kv; |
| 140 | kv.m_key = xstrndup (string, equals - string); |
| 141 | const char *cur_value = ::getenv (name: kv.m_key); |
| 142 | if (m_debug) |
| 143 | fprintf (stderr, format: "saving old value: %s\n" ,cur_value); |
| 144 | kv.m_value = cur_value ? xstrdup (cur_value) : NULL; |
| 145 | m_keys.safe_push (obj: kv); |
| 146 | } |
| 147 | |
| 148 | ::putenv (CONST_CAST (char *, string)); |
| 149 | } |
| 150 | |
| 151 | /* Undo any xputenv changes made since last restore. |
| 152 | Can only be called if the env_manager was initialized with |
| 153 | CAN_RESTORE enabled. */ |
| 154 | |
| 155 | void |
| 156 | env_manager::restore () |
| 157 | { |
| 158 | unsigned int i; |
| 159 | struct kv *item; |
| 160 | |
| 161 | gcc_assert (m_can_restore); |
| 162 | |
| 163 | FOR_EACH_VEC_ELT_REVERSE (m_keys, i, item) |
| 164 | { |
| 165 | if (m_debug) |
| 166 | printf (format: "restoring saved key: %s value: %s\n" , item->m_key, item->m_value); |
| 167 | if (item->m_value) |
| 168 | ::setenv (name: item->m_key, value: item->m_value, replace: 1); |
| 169 | else |
| 170 | ::unsetenv (name: item->m_key); |
| 171 | free (ptr: item->m_key); |
| 172 | free (ptr: item->m_value); |
| 173 | } |
| 174 | |
| 175 | m_keys.truncate (size: 0); |
| 176 | } |
| 177 | |
| 178 | /* Forbid other uses of getenv and putenv. */ |
| 179 | #if (GCC_VERSION >= 3000) |
| 180 | #pragma GCC poison getenv putenv |
| 181 | #endif |
| 182 | |
| 183 | |
| 184 | |
| 185 | /* By default there is no special suffix for target executables. */ |
| 186 | #ifdef TARGET_EXECUTABLE_SUFFIX |
| 187 | #define HAVE_TARGET_EXECUTABLE_SUFFIX |
| 188 | #else |
| 189 | #define TARGET_EXECUTABLE_SUFFIX "" |
| 190 | #endif |
| 191 | |
| 192 | /* By default there is no special suffix for host executables. */ |
| 193 | #ifdef HOST_EXECUTABLE_SUFFIX |
| 194 | #define HAVE_HOST_EXECUTABLE_SUFFIX |
| 195 | #else |
| 196 | #define HOST_EXECUTABLE_SUFFIX "" |
| 197 | #endif |
| 198 | |
| 199 | /* By default, the suffix for target object files is ".o". */ |
| 200 | #ifdef TARGET_OBJECT_SUFFIX |
| 201 | #define HAVE_TARGET_OBJECT_SUFFIX |
| 202 | #else |
| 203 | #define TARGET_OBJECT_SUFFIX ".o" |
| 204 | #endif |
| 205 | |
| 206 | static const char dir_separator_str[] = { DIR_SEPARATOR, 0 }; |
| 207 | |
| 208 | /* Most every one is fine with LIBRARY_PATH. For some, it conflicts. */ |
| 209 | #ifndef LIBRARY_PATH_ENV |
| 210 | #define LIBRARY_PATH_ENV "LIBRARY_PATH" |
| 211 | #endif |
| 212 | |
| 213 | /* If a stage of compilation returns an exit status >= 1, |
| 214 | compilation of that file ceases. */ |
| 215 | |
| 216 | #define MIN_FATAL_STATUS 1 |
| 217 | |
| 218 | /* Flag set by cppspec.cc to 1. */ |
| 219 | int is_cpp_driver; |
| 220 | |
| 221 | /* Flag set to nonzero if an @file argument has been supplied to gcc. */ |
| 222 | static bool at_file_supplied; |
| 223 | |
| 224 | /* Definition of string containing the arguments given to configure. */ |
| 225 | #include "configargs.h" |
| 226 | |
| 227 | /* Flag saying to print the command line options understood by gcc and its |
| 228 | sub-processes. */ |
| 229 | |
| 230 | static int print_help_list; |
| 231 | |
| 232 | /* Flag saying to print the version of gcc and its sub-processes. */ |
| 233 | |
| 234 | static int print_version; |
| 235 | |
| 236 | /* Flag that stores string prefix for which we provide bash completion. */ |
| 237 | |
| 238 | static const char *completion = NULL; |
| 239 | |
| 240 | /* Flag indicating whether we should ONLY print the command and |
| 241 | arguments (like verbose_flag) without executing the command. |
| 242 | Displayed arguments are quoted so that the generated command |
| 243 | line is suitable for execution. This is intended for use in |
| 244 | shell scripts to capture the driver-generated command line. */ |
| 245 | static int verbose_only_flag; |
| 246 | |
| 247 | /* Flag indicating how to print command line options of sub-processes. */ |
| 248 | |
| 249 | static int print_subprocess_help; |
| 250 | |
| 251 | /* Linker suffix passed to -fuse-ld=... */ |
| 252 | static const char *use_ld; |
| 253 | |
| 254 | /* Whether we should report subprocess execution times to a file. */ |
| 255 | |
| 256 | FILE *report_times_to_file = NULL; |
| 257 | |
| 258 | /* Nonzero means place this string before uses of /, so that include |
| 259 | and library files can be found in an alternate location. */ |
| 260 | |
| 261 | #ifdef TARGET_SYSTEM_ROOT |
| 262 | #define DEFAULT_TARGET_SYSTEM_ROOT (TARGET_SYSTEM_ROOT) |
| 263 | #else |
| 264 | #define DEFAULT_TARGET_SYSTEM_ROOT (0) |
| 265 | #endif |
| 266 | static const char *target_system_root = DEFAULT_TARGET_SYSTEM_ROOT; |
| 267 | |
| 268 | /* Nonzero means pass the updated target_system_root to the compiler. */ |
| 269 | |
| 270 | static int target_system_root_changed; |
| 271 | |
| 272 | /* Nonzero means append this string to target_system_root. */ |
| 273 | |
| 274 | static const char *target_sysroot_suffix = 0; |
| 275 | |
| 276 | /* Nonzero means append this string to target_system_root for headers. */ |
| 277 | |
| 278 | static const char *target_sysroot_hdrs_suffix = 0; |
| 279 | |
| 280 | /* Nonzero means write "temp" files in source directory |
| 281 | and use the source file's name in them, and don't delete them. */ |
| 282 | |
| 283 | static enum save_temps { |
| 284 | SAVE_TEMPS_NONE, /* no -save-temps */ |
| 285 | SAVE_TEMPS_CWD, /* -save-temps in current directory */ |
| 286 | SAVE_TEMPS_DUMP, /* -save-temps in dumpdir */ |
| 287 | SAVE_TEMPS_OBJ /* -save-temps in object directory */ |
| 288 | } save_temps_flag; |
| 289 | |
| 290 | /* Set this iff the dumppfx implied by a -save-temps=* option is to |
| 291 | override a -dumpdir option, if any. */ |
| 292 | static bool save_temps_overrides_dumpdir = false; |
| 293 | |
| 294 | /* -dumpdir, -dumpbase and -dumpbase-ext flags passed in, possibly |
| 295 | rearranged as they are to be passed down, e.g., dumpbase and |
| 296 | dumpbase_ext may be cleared if integrated with dumpdir or |
| 297 | dropped. */ |
| 298 | static char *dumpdir, *dumpbase, *dumpbase_ext; |
| 299 | |
| 300 | /* Usually the length of the string in dumpdir. However, during |
| 301 | linking, it may be shortened to omit a driver-added trailing dash, |
| 302 | by then replaced with a trailing period, that is still to be passed |
| 303 | to sub-processes in -dumpdir, but not to be generally used in spec |
| 304 | filename expansions. See maybe_run_linker. */ |
| 305 | static size_t dumpdir_length = 0; |
| 306 | |
| 307 | /* Set if the last character in dumpdir is (or was) a dash that the |
| 308 | driver added to dumpdir after dumpbase or linker output name. */ |
| 309 | static bool dumpdir_trailing_dash_added = false; |
| 310 | |
| 311 | /* True if -r, -shared, -pie, -no-pie, -z lazy, or -z norelro were |
| 312 | specified on the command line, and therefore -fhardened should not |
| 313 | add -z now/relro. */ |
| 314 | static bool avoid_linker_hardening_p; |
| 315 | |
| 316 | /* True if -static was specified on the command line. */ |
| 317 | static bool static_p; |
| 318 | |
| 319 | /* Basename of dump and aux outputs, computed from dumpbase (given or |
| 320 | derived from output name), to override input_basename in non-%w %b |
| 321 | et al. */ |
| 322 | static char *outbase; |
| 323 | static size_t outbase_length = 0; |
| 324 | |
| 325 | /* The compiler version. */ |
| 326 | |
| 327 | static const char *compiler_version; |
| 328 | |
| 329 | /* The target version. */ |
| 330 | |
| 331 | static const char *const spec_version = DEFAULT_TARGET_VERSION; |
| 332 | |
| 333 | /* The target machine. */ |
| 334 | |
| 335 | static const char *spec_machine = DEFAULT_TARGET_MACHINE; |
| 336 | static const char *spec_host_machine = DEFAULT_REAL_TARGET_MACHINE; |
| 337 | |
| 338 | /* List of offload targets. Separated by colon. Empty string for |
| 339 | -foffload=disable. */ |
| 340 | |
| 341 | static char *offload_targets = NULL; |
| 342 | |
| 343 | #if OFFLOAD_DEFAULTED |
| 344 | /* Set to true if -foffload has not been used and offload_targets |
| 345 | is set to the configured in default. */ |
| 346 | static bool offload_targets_default; |
| 347 | #endif |
| 348 | |
| 349 | /* Nonzero if cross-compiling. |
| 350 | When -b is used, the value comes from the `specs' file. */ |
| 351 | |
| 352 | #ifdef CROSS_DIRECTORY_STRUCTURE |
| 353 | static const char *cross_compile = "1" ; |
| 354 | #else |
| 355 | static const char *cross_compile = "0" ; |
| 356 | #endif |
| 357 | |
| 358 | /* Greatest exit code of sub-processes that has been encountered up to |
| 359 | now. */ |
| 360 | static int greatest_status = 1; |
| 361 | |
| 362 | /* This is the obstack which we use to allocate many strings. */ |
| 363 | |
| 364 | static struct obstack obstack; |
| 365 | |
| 366 | /* This is the obstack to build an environment variable to pass to |
| 367 | collect2 that describes all of the relevant switches of what to |
| 368 | pass the compiler in building the list of pointers to constructors |
| 369 | and destructors. */ |
| 370 | |
| 371 | static struct obstack collect_obstack; |
| 372 | |
| 373 | /* Forward declaration for prototypes. */ |
| 374 | struct path_prefix; |
| 375 | struct prefix_list; |
| 376 | |
| 377 | static void init_spec (void); |
| 378 | static void store_arg (const char *, int, int); |
| 379 | static void insert_wrapper (const char *); |
| 380 | static char *load_specs (const char *); |
| 381 | static void read_specs (const char *, bool, bool); |
| 382 | static void set_spec (const char *, const char *, bool); |
| 383 | static struct compiler *lookup_compiler (const char *, size_t, const char *); |
| 384 | static char *build_search_list (const struct path_prefix *, const char *, |
| 385 | bool, bool); |
| 386 | static void xputenv (const char *); |
| 387 | static void putenv_from_prefixes (const struct path_prefix *, const char *, |
| 388 | bool); |
| 389 | static int access_check (const char *, int); |
| 390 | static char *find_a_file (const struct path_prefix *, const char *, int, bool); |
| 391 | static char *find_a_program (const char *); |
| 392 | static void add_prefix (struct path_prefix *, const char *, const char *, |
| 393 | int, int, int); |
| 394 | static void add_sysrooted_prefix (struct path_prefix *, const char *, |
| 395 | const char *, int, int, int); |
| 396 | static char *skip_whitespace (char *); |
| 397 | static void delete_if_ordinary (const char *); |
| 398 | static void delete_temp_files (void); |
| 399 | static void delete_failure_queue (void); |
| 400 | static void clear_failure_queue (void); |
| 401 | static int check_live_switch (int, int); |
| 402 | static const char *handle_braces (const char *); |
| 403 | static inline bool input_suffix_matches (const char *, const char *); |
| 404 | static inline bool switch_matches (const char *, const char *, int); |
| 405 | static inline void mark_matching_switches (const char *, const char *, int); |
| 406 | static inline void process_marked_switches (void); |
| 407 | static const char *process_brace_body (const char *, const char *, const char *, int, int); |
| 408 | static const struct spec_function *lookup_spec_function (const char *); |
| 409 | static const char *eval_spec_function (const char *, const char *, const char *); |
| 410 | static const char *handle_spec_function (const char *, bool *, const char *); |
| 411 | static char *save_string (const char *, int); |
| 412 | static void set_collect_gcc_options (void); |
| 413 | static int do_spec_1 (const char *, int, const char *); |
| 414 | static int do_spec_2 (const char *, const char *); |
| 415 | static void do_option_spec (const char *, const char *); |
| 416 | static void do_self_spec (const char *); |
| 417 | static const char *find_file (const char *); |
| 418 | static int is_directory (const char *); |
| 419 | static const char *validate_switches (const char *, bool, bool); |
| 420 | static void validate_all_switches (void); |
| 421 | static inline void validate_switches_from_spec (const char *, bool); |
| 422 | static void give_switch (int, int); |
| 423 | static int default_arg (const char *, int); |
| 424 | static void set_multilib_dir (void); |
| 425 | static void print_multilib_info (void); |
| 426 | static void display_help (void); |
| 427 | static void add_preprocessor_option (const char *, int); |
| 428 | static void add_assembler_option (const char *, int); |
| 429 | static void add_linker_option (const char *, int); |
| 430 | static void process_command (unsigned int, struct cl_decoded_option *); |
| 431 | static int execute (void); |
| 432 | static void alloc_args (void); |
| 433 | static void clear_args (void); |
| 434 | static void fatal_signal (int); |
| 435 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
| 436 | static void init_gcc_specs (struct obstack *, const char *, const char *, |
| 437 | const char *); |
| 438 | #endif |
| 439 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
| 440 | static const char *convert_filename (const char *, int, int); |
| 441 | #endif |
| 442 | |
| 443 | static void try_generate_repro (const char **argv); |
| 444 | static const char *getenv_spec_function (int, const char **); |
| 445 | static const char *if_exists_spec_function (int, const char **); |
| 446 | static const char *if_exists_else_spec_function (int, const char **); |
| 447 | static const char *if_exists_then_else_spec_function (int, const char **); |
| 448 | static const char *sanitize_spec_function (int, const char **); |
| 449 | static const char *replace_outfile_spec_function (int, const char **); |
| 450 | static const char *remove_outfile_spec_function (int, const char **); |
| 451 | static const char *version_compare_spec_function (int, const char **); |
| 452 | static const char *include_spec_function (int, const char **); |
| 453 | static const char *find_file_spec_function (int, const char **); |
| 454 | static const char *find_plugindir_spec_function (int, const char **); |
| 455 | static const char *print_asm_header_spec_function (int, const char **); |
| 456 | static const char *compare_debug_dump_opt_spec_function (int, const char **); |
| 457 | static const char *compare_debug_self_opt_spec_function (int, const char **); |
| 458 | static const char *pass_through_libs_spec_func (int, const char **); |
| 459 | static const char *dumps_spec_func (int, const char **); |
| 460 | static const char *greater_than_spec_func (int, const char **); |
| 461 | static const char *debug_level_greater_than_spec_func (int, const char **); |
| 462 | static const char *dwarf_version_greater_than_spec_func (int, const char **); |
| 463 | static const char *find_fortran_preinclude_file (int, const char **); |
| 464 | static const char *join_spec_func (int, const char **); |
| 465 | static char *convert_white_space (char *); |
| 466 | static char *quote_spec (char *); |
| 467 | static char *quote_spec_arg (char *); |
| 468 | static bool not_actual_file_p (const char *); |
| 469 | |
| 470 | |
| 471 | /* The Specs Language |
| 472 | |
| 473 | Specs are strings containing lines, each of which (if not blank) |
| 474 | is made up of a program name, and arguments separated by spaces. |
| 475 | The program name must be exact and start from root, since no path |
| 476 | is searched and it is unreliable to depend on the current working directory. |
| 477 | Redirection of input or output is not supported; the subprograms must |
| 478 | accept filenames saying what files to read and write. |
| 479 | |
| 480 | In addition, the specs can contain %-sequences to substitute variable text |
| 481 | or for conditional text. Here is a table of all defined %-sequences. |
| 482 | Note that spaces are not generated automatically around the results of |
| 483 | expanding these sequences; therefore, you can concatenate them together |
| 484 | or with constant text in a single argument. |
| 485 | |
| 486 | %% substitute one % into the program name or argument. |
| 487 | %" substitute an empty argument. |
| 488 | %i substitute the name of the input file being processed. |
| 489 | %b substitute the basename for outputs related with the input file |
| 490 | being processed. This is often a substring of the input file name, |
| 491 | up to (and not including) the last period but, unless %w is active, |
| 492 | it is affected by the directory selected by -save-temps=*, by |
| 493 | -dumpdir, and, in case of multiple compilations, even by -dumpbase |
| 494 | and -dumpbase-ext and, in case of linking, by the linker output |
| 495 | name. When %w is active, it derives the main output name only from |
| 496 | the input file base name; when it is not, it names aux/dump output |
| 497 | file. |
| 498 | %B same as %b, but include the input file suffix (text after the last |
| 499 | period). |
| 500 | %gSUFFIX |
| 501 | substitute a file name that has suffix SUFFIX and is chosen |
| 502 | once per compilation, and mark the argument a la %d. To reduce |
| 503 | exposure to denial-of-service attacks, the file name is now |
| 504 | chosen in a way that is hard to predict even when previously |
| 505 | chosen file names are known. For example, `%g.s ... %g.o ... %g.s' |
| 506 | might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches |
| 507 | the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it |
| 508 | had been pre-processed. Previously, %g was simply substituted |
| 509 | with a file name chosen once per compilation, without regard |
| 510 | to any appended suffix (which was therefore treated just like |
| 511 | ordinary text), making such attacks more likely to succeed. |
| 512 | %|SUFFIX |
| 513 | like %g, but if -pipe is in effect, expands simply to "-". |
| 514 | %mSUFFIX |
| 515 | like %g, but if -pipe is in effect, expands to nothing. (We have both |
| 516 | %| and %m to accommodate differences between system assemblers; see |
| 517 | the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) |
| 518 | %uSUFFIX |
| 519 | like %g, but generates a new temporary file name even if %uSUFFIX |
| 520 | was already seen. |
| 521 | %USUFFIX |
| 522 | substitutes the last file name generated with %uSUFFIX, generating a |
| 523 | new one if there is no such last file name. In the absence of any |
| 524 | %uSUFFIX, this is just like %gSUFFIX, except they don't share |
| 525 | the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' |
| 526 | would involve the generation of two distinct file names, one |
| 527 | for each `%g.s' and another for each `%U.s'. Previously, %U was |
| 528 | simply substituted with a file name chosen for the previous %u, |
| 529 | without regard to any appended suffix. |
| 530 | %jSUFFIX |
| 531 | substitutes the name of the HOST_BIT_BUCKET, if any, and if it is |
| 532 | writable, and if save-temps is off; otherwise, substitute the name |
| 533 | of a temporary file, just like %u. This temporary file is not |
| 534 | meant for communication between processes, but rather as a junk |
| 535 | disposal mechanism. |
| 536 | %.SUFFIX |
| 537 | substitutes .SUFFIX for the suffixes of a matched switch's args when |
| 538 | it is subsequently output with %*. SUFFIX is terminated by the next |
| 539 | space or %. |
| 540 | %d marks the argument containing or following the %d as a |
| 541 | temporary file name, so that file will be deleted if GCC exits |
| 542 | successfully. Unlike %g, this contributes no text to the argument. |
| 543 | %w marks the argument containing or following the %w as the |
| 544 | "output file" of this compilation. This puts the argument |
| 545 | into the sequence of arguments that %o will substitute later. |
| 546 | %V indicates that this compilation produces no "output file". |
| 547 | %W{...} |
| 548 | like %{...} but marks the last argument supplied within as a file |
| 549 | to be deleted on failure. |
| 550 | %@{...} |
| 551 | like %{...} but puts the result into a FILE and substitutes @FILE |
| 552 | if an @file argument has been supplied. |
| 553 | %o substitutes the names of all the output files, with spaces |
| 554 | automatically placed around them. You should write spaces |
| 555 | around the %o as well or the results are undefined. |
| 556 | %o is for use in the specs for running the linker. |
| 557 | Input files whose names have no recognized suffix are not compiled |
| 558 | at all, but they are included among the output files, so they will |
| 559 | be linked. |
| 560 | %O substitutes the suffix for object files. Note that this is |
| 561 | handled specially when it immediately follows %g, %u, or %U |
| 562 | (with or without a suffix argument) because of the need for |
| 563 | those to form complete file names. The handling is such that |
| 564 | %O is treated exactly as if it had already been substituted, |
| 565 | except that %g, %u, and %U do not currently support additional |
| 566 | SUFFIX characters following %O as they would following, for |
| 567 | example, `.o'. |
| 568 | %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot |
| 569 | (made from TARGET_SYSTEM_ROOT), -isystem (made from COMPILER_PATH |
| 570 | and -B options) and -imultilib as necessary. |
| 571 | %s current argument is the name of a library or startup file of some sort. |
| 572 | Search for that file in a standard list of directories |
| 573 | and substitute the full name found. |
| 574 | %T current argument is the name of a linker script. |
| 575 | Search for that file in the current list of directories to scan for |
| 576 | libraries. If the file is located, insert a --script option into the |
| 577 | command line followed by the full path name found. If the file is |
| 578 | not found then generate an error message. |
| 579 | Note: the current working directory is not searched. |
| 580 | %eSTR Print STR as an error message. STR is terminated by a newline. |
| 581 | Use this when inconsistent options are detected. |
| 582 | %nSTR Print STR as a notice. STR is terminated by a newline. |
| 583 | %x{OPTION} Accumulate an option for %X. |
| 584 | %X Output the accumulated linker options specified by compilations. |
| 585 | %Y Output the accumulated assembler options specified by compilations. |
| 586 | %Z Output the accumulated preprocessor options specified by compilations. |
| 587 | %a process ASM_SPEC as a spec. |
| 588 | This allows config.h to specify part of the spec for running as. |
| 589 | %A process ASM_FINAL_SPEC as a spec. A capital A is actually |
| 590 | used here. This can be used to run a post-processor after the |
| 591 | assembler has done its job. |
| 592 | %D Dump out a -L option for each directory in startfile_prefixes. |
| 593 | If multilib_dir is set, extra entries are generated with it affixed. |
| 594 | %l process LINK_SPEC as a spec. |
| 595 | %L process LIB_SPEC as a spec. |
| 596 | %M Output multilib_os_dir. |
| 597 | %P Output a RUNPATH_OPTION for each directory in startfile_prefixes. |
| 598 | %G process LIBGCC_SPEC as a spec. |
| 599 | %R Output the concatenation of target_system_root and |
| 600 | target_sysroot_suffix. |
| 601 | %S process STARTFILE_SPEC as a spec. A capital S is actually used here. |
| 602 | %E process ENDFILE_SPEC as a spec. A capital E is actually used here. |
| 603 | %C process CPP_SPEC as a spec. |
| 604 | %1 process CC1_SPEC as a spec. |
| 605 | %2 process CC1PLUS_SPEC as a spec. |
| 606 | %* substitute the variable part of a matched option. (See below.) |
| 607 | Note that each comma in the substituted string is replaced by |
| 608 | a single space. A space is appended after the last substition |
| 609 | unless there is more text in current sequence. |
| 610 | %<S remove all occurrences of -S from the command line. |
| 611 | Note - this command is position dependent. % commands in the |
| 612 | spec string before this one will see -S, % commands in the |
| 613 | spec string after this one will not. |
| 614 | %>S Similar to "%<S", but keep it in the GCC command line. |
| 615 | %<S* remove all occurrences of all switches beginning with -S from the |
| 616 | command line. |
| 617 | %:function(args) |
| 618 | Call the named function FUNCTION, passing it ARGS. ARGS is |
| 619 | first processed as a nested spec string, then split into an |
| 620 | argument vector in the usual fashion. The function returns |
| 621 | a string which is processed as if it had appeared literally |
| 622 | as part of the current spec. |
| 623 | %{S} substitutes the -S switch, if that switch was given to GCC. |
| 624 | If that switch was not specified, this substitutes nothing. |
| 625 | Here S is a metasyntactic variable. |
| 626 | %{S*} substitutes all the switches specified to GCC whose names start |
| 627 | with -S. This is used for -o, -I, etc; switches that take |
| 628 | arguments. GCC considers `-o foo' as being one switch whose |
| 629 | name starts with `o'. %{o*} would substitute this text, |
| 630 | including the space; thus, two arguments would be generated. |
| 631 | %{S*&T*} likewise, but preserve order of S and T options (the order |
| 632 | of S and T in the spec is not significant). Can be any number |
| 633 | of ampersand-separated variables; for each the wild card is |
| 634 | optional. Useful for CPP as %{D*&U*&A*}. |
| 635 | |
| 636 | %{S:X} substitutes X, if the -S switch was given to GCC. |
| 637 | %{!S:X} substitutes X, if the -S switch was NOT given to GCC. |
| 638 | %{S*:X} substitutes X if one or more switches whose names start |
| 639 | with -S was given to GCC. Normally X is substituted only |
| 640 | once, no matter how many such switches appeared. However, |
| 641 | if %* appears somewhere in X, then X will be substituted |
| 642 | once for each matching switch, with the %* replaced by the |
| 643 | part of that switch that matched the '*'. A space will be |
| 644 | appended after the last substition unless there is more |
| 645 | text in current sequence. |
| 646 | %{.S:X} substitutes X, if processing a file with suffix S. |
| 647 | %{!.S:X} substitutes X, if NOT processing a file with suffix S. |
| 648 | %{,S:X} substitutes X, if processing a file which will use spec S. |
| 649 | %{!,S:X} substitutes X, if NOT processing a file which will use spec S. |
| 650 | |
| 651 | %{S|T:X} substitutes X if either -S or -T was given to GCC. This may be |
| 652 | combined with '!', '.', ',', and '*' as above binding stronger |
| 653 | than the OR. |
| 654 | If %* appears in X, all of the alternatives must be starred, and |
| 655 | only the first matching alternative is substituted. |
| 656 | %{%:function(args):X} |
| 657 | Call function named FUNCTION with args ARGS. If the function |
| 658 | returns non-NULL, then X is substituted, if it returns |
| 659 | NULL, it isn't substituted. |
| 660 | %{S:X; if S was given to GCC, substitutes X; |
| 661 | T:Y; else if T was given to GCC, substitutes Y; |
| 662 | :D} else substitutes D. There can be as many clauses as you need. |
| 663 | This may be combined with '.', '!', ',', '|', and '*' as above. |
| 664 | |
| 665 | %(Spec) processes a specification defined in a specs file as *Spec: |
| 666 | |
| 667 | The switch matching text S in a %{S}, %{S:X}, or similar construct can use |
| 668 | a backslash to ignore the special meaning of the character following it, |
| 669 | thus allowing literal matching of a character that is otherwise specially |
| 670 | treated. For example, %{std=iso9899\:1999:X} substitutes X if the |
| 671 | -std=iso9899:1999 option is given. |
| 672 | |
| 673 | The conditional text X in a %{S:X} or similar construct may contain |
| 674 | other nested % constructs or spaces, or even newlines. They are |
| 675 | processed as usual, as described above. Trailing white space in X is |
| 676 | ignored. White space may also appear anywhere on the left side of the |
| 677 | colon in these constructs, except between . or * and the corresponding |
| 678 | word. |
| 679 | |
| 680 | The -O, -f, -g, -m, and -W switches are handled specifically in these |
| 681 | constructs. If another value of -O or the negated form of a -f, -m, or |
| 682 | -W switch is found later in the command line, the earlier switch |
| 683 | value is ignored, except with {S*} where S is just one letter; this |
| 684 | passes all matching options. |
| 685 | |
| 686 | The character | at the beginning of the predicate text is used to indicate |
| 687 | that a command should be piped to the following command, but only if -pipe |
| 688 | is specified. |
| 689 | |
| 690 | Note that it is built into GCC which switches take arguments and which |
| 691 | do not. You might think it would be useful to generalize this to |
| 692 | allow each compiler's spec to say which switches take arguments. But |
| 693 | this cannot be done in a consistent fashion. GCC cannot even decide |
| 694 | which input files have been specified without knowing which switches |
| 695 | take arguments, and it must know which input files to compile in order |
| 696 | to tell which compilers to run. |
| 697 | |
| 698 | GCC also knows implicitly that arguments starting in `-l' are to be |
| 699 | treated as compiler output files, and passed to the linker in their |
| 700 | proper position among the other output files. */ |
| 701 | |
| 702 | /* Define the macros used for specs %a, %l, %L, %S, %C, %1. */ |
| 703 | |
| 704 | /* config.h can define ASM_SPEC to provide extra args to the assembler |
| 705 | or extra switch-translations. */ |
| 706 | #ifndef ASM_SPEC |
| 707 | #define ASM_SPEC "" |
| 708 | #endif |
| 709 | |
| 710 | /* config.h can define ASM_FINAL_SPEC to run a post processor after |
| 711 | the assembler has run. */ |
| 712 | #ifndef ASM_FINAL_SPEC |
| 713 | #define ASM_FINAL_SPEC \ |
| 714 | "%{gsplit-dwarf: \n\ |
| 715 | objcopy --extract-dwo \ |
| 716 | %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \ |
| 717 | %b.dwo \n\ |
| 718 | objcopy --strip-dwo \ |
| 719 | %{c:%{o*:%*}%{!o*:%w%b%O}}%{!c:%U%O} \ |
| 720 | }" |
| 721 | #endif |
| 722 | |
| 723 | /* config.h can define CPP_SPEC to provide extra args to the C preprocessor |
| 724 | or extra switch-translations. */ |
| 725 | #ifndef CPP_SPEC |
| 726 | #define CPP_SPEC "" |
| 727 | #endif |
| 728 | |
| 729 | /* Operating systems can define OS_CC1_SPEC to provide extra args to cc1 and |
| 730 | cc1plus or extra switch-translations. The OS_CC1_SPEC is appended |
| 731 | to CC1_SPEC in the initialization of cc1_spec. */ |
| 732 | #ifndef OS_CC1_SPEC |
| 733 | #define OS_CC1_SPEC "" |
| 734 | #endif |
| 735 | |
| 736 | /* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus |
| 737 | or extra switch-translations. */ |
| 738 | #ifndef CC1_SPEC |
| 739 | #define CC1_SPEC "" |
| 740 | #endif |
| 741 | |
| 742 | /* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus |
| 743 | or extra switch-translations. */ |
| 744 | #ifndef CC1PLUS_SPEC |
| 745 | #define CC1PLUS_SPEC "" |
| 746 | #endif |
| 747 | |
| 748 | /* config.h can define LINK_SPEC to provide extra args to the linker |
| 749 | or extra switch-translations. */ |
| 750 | #ifndef LINK_SPEC |
| 751 | #define LINK_SPEC "" |
| 752 | #endif |
| 753 | |
| 754 | /* config.h can define LIB_SPEC to override the default libraries. */ |
| 755 | #ifndef LIB_SPEC |
| 756 | #define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}" |
| 757 | #endif |
| 758 | |
| 759 | /* When using -fsplit-stack we need to wrap pthread_create, in order |
| 760 | to initialize the stack guard. We always use wrapping, rather than |
| 761 | shared library ordering, and we keep the wrapper function in |
| 762 | libgcc. This is not yet a real spec, though it could become one; |
| 763 | it is currently just stuffed into LINK_SPEC. FIXME: This wrapping |
| 764 | only works with GNU ld and gold. */ |
| 765 | #ifdef HAVE_GOLD_NON_DEFAULT_SPLIT_STACK |
| 766 | #define STACK_SPLIT_SPEC " %{fsplit-stack: -fuse-ld=gold --wrap=pthread_create}" |
| 767 | #else |
| 768 | #define STACK_SPLIT_SPEC " %{fsplit-stack: --wrap=pthread_create}" |
| 769 | #endif |
| 770 | |
| 771 | #ifndef LIBASAN_SPEC |
| 772 | #define STATIC_LIBASAN_LIBS \ |
| 773 | " %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)}" |
| 774 | #ifdef LIBASAN_EARLY_SPEC |
| 775 | #define LIBASAN_SPEC STATIC_LIBASAN_LIBS |
| 776 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
| 777 | #define LIBASAN_SPEC "%{static-libasan:" LD_STATIC_OPTION \ |
| 778 | "} -lasan %{static-libasan:" LD_DYNAMIC_OPTION "}" \ |
| 779 | STATIC_LIBASAN_LIBS |
| 780 | #else |
| 781 | #define LIBASAN_SPEC "-lasan" STATIC_LIBASAN_LIBS |
| 782 | #endif |
| 783 | #endif |
| 784 | |
| 785 | #ifndef LIBASAN_EARLY_SPEC |
| 786 | #define LIBASAN_EARLY_SPEC "" |
| 787 | #endif |
| 788 | |
| 789 | #ifndef LIBHWASAN_SPEC |
| 790 | #define STATIC_LIBHWASAN_LIBS \ |
| 791 | " %{static-libhwasan|static:%:include(libsanitizer.spec)%(link_libhwasan)}" |
| 792 | #ifdef LIBHWASAN_EARLY_SPEC |
| 793 | #define LIBHWASAN_SPEC STATIC_LIBHWASAN_LIBS |
| 794 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
| 795 | #define LIBHWASAN_SPEC "%{static-libhwasan:" LD_STATIC_OPTION \ |
| 796 | "} -lhwasan %{static-libhwasan:" LD_DYNAMIC_OPTION "}" \ |
| 797 | STATIC_LIBHWASAN_LIBS |
| 798 | #else |
| 799 | #define LIBHWASAN_SPEC "-lhwasan" STATIC_LIBHWASAN_LIBS |
| 800 | #endif |
| 801 | #endif |
| 802 | |
| 803 | #ifndef LIBHWASAN_EARLY_SPEC |
| 804 | #define LIBHWASAN_EARLY_SPEC "" |
| 805 | #endif |
| 806 | |
| 807 | #ifndef LIBTSAN_SPEC |
| 808 | #define STATIC_LIBTSAN_LIBS \ |
| 809 | " %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)}" |
| 810 | #ifdef LIBTSAN_EARLY_SPEC |
| 811 | #define LIBTSAN_SPEC STATIC_LIBTSAN_LIBS |
| 812 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
| 813 | #define LIBTSAN_SPEC "%{static-libtsan:" LD_STATIC_OPTION \ |
| 814 | "} -ltsan %{static-libtsan:" LD_DYNAMIC_OPTION "}" \ |
| 815 | STATIC_LIBTSAN_LIBS |
| 816 | #else |
| 817 | #define LIBTSAN_SPEC "-ltsan" STATIC_LIBTSAN_LIBS |
| 818 | #endif |
| 819 | #endif |
| 820 | |
| 821 | #ifndef LIBTSAN_EARLY_SPEC |
| 822 | #define LIBTSAN_EARLY_SPEC "" |
| 823 | #endif |
| 824 | |
| 825 | #ifndef LIBLSAN_SPEC |
| 826 | #define STATIC_LIBLSAN_LIBS \ |
| 827 | " %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}" |
| 828 | #ifdef LIBLSAN_EARLY_SPEC |
| 829 | #define LIBLSAN_SPEC STATIC_LIBLSAN_LIBS |
| 830 | #elif defined(HAVE_LD_STATIC_DYNAMIC) |
| 831 | #define LIBLSAN_SPEC "%{static-liblsan:" LD_STATIC_OPTION \ |
| 832 | "} -llsan %{static-liblsan:" LD_DYNAMIC_OPTION "}" \ |
| 833 | STATIC_LIBLSAN_LIBS |
| 834 | #else |
| 835 | #define LIBLSAN_SPEC "-llsan" STATIC_LIBLSAN_LIBS |
| 836 | #endif |
| 837 | #endif |
| 838 | |
| 839 | #ifndef LIBLSAN_EARLY_SPEC |
| 840 | #define LIBLSAN_EARLY_SPEC "" |
| 841 | #endif |
| 842 | |
| 843 | #ifndef LIBUBSAN_SPEC |
| 844 | #define STATIC_LIBUBSAN_LIBS \ |
| 845 | " %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}" |
| 846 | #ifdef HAVE_LD_STATIC_DYNAMIC |
| 847 | #define LIBUBSAN_SPEC "%{static-libubsan:" LD_STATIC_OPTION \ |
| 848 | "} -lubsan %{static-libubsan:" LD_DYNAMIC_OPTION "}" \ |
| 849 | STATIC_LIBUBSAN_LIBS |
| 850 | #else |
| 851 | #define LIBUBSAN_SPEC "-lubsan" STATIC_LIBUBSAN_LIBS |
| 852 | #endif |
| 853 | #endif |
| 854 | |
| 855 | /* Linker options for compressed debug sections. */ |
| 856 | #if HAVE_LD_COMPRESS_DEBUG == 0 |
| 857 | /* No linker support. */ |
| 858 | #define LINK_COMPRESS_DEBUG_SPEC \ |
| 859 | " %{gz*:%e-gz is not supported in this configuration} " |
| 860 | #elif HAVE_LD_COMPRESS_DEBUG == 1 |
| 861 | /* ELF gABI style. */ |
| 862 | #define LINK_COMPRESS_DEBUG_SPEC \ |
| 863 | " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ |
| 864 | " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ |
| 865 | " %{gz=zstd:%e-gz=zstd is not supported in this configuration} " \ |
| 866 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
| 867 | #elif HAVE_LD_COMPRESS_DEBUG == 2 |
| 868 | /* ELF gABI style and ZSTD. */ |
| 869 | #define LINK_COMPRESS_DEBUG_SPEC \ |
| 870 | " %{gz|gz=zlib:" LD_COMPRESS_DEBUG_OPTION "=zlib}" \ |
| 871 | " %{gz=none:" LD_COMPRESS_DEBUG_OPTION "=none}" \ |
| 872 | " %{gz=zstd:" LD_COMPRESS_DEBUG_OPTION "=zstd}" \ |
| 873 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
| 874 | #else |
| 875 | #error Unknown value for HAVE_LD_COMPRESS_DEBUG. |
| 876 | #endif |
| 877 | |
| 878 | /* config.h can define LIBGCC_SPEC to override how and when libgcc.a is |
| 879 | included. */ |
| 880 | #ifndef LIBGCC_SPEC |
| 881 | #if defined(REAL_LIBGCC_SPEC) |
| 882 | #define LIBGCC_SPEC REAL_LIBGCC_SPEC |
| 883 | #elif defined(LINK_LIBGCC_SPECIAL_1) |
| 884 | /* Have gcc do the search for libgcc.a. */ |
| 885 | #define LIBGCC_SPEC "libgcc.a%s" |
| 886 | #else |
| 887 | #define LIBGCC_SPEC "-lgcc" |
| 888 | #endif |
| 889 | #endif |
| 890 | |
| 891 | /* config.h can define STARTFILE_SPEC to override the default crt0 files. */ |
| 892 | #ifndef STARTFILE_SPEC |
| 893 | #define STARTFILE_SPEC \ |
| 894 | "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}" |
| 895 | #endif |
| 896 | |
| 897 | /* config.h can define ENDFILE_SPEC to override the default crtn files. */ |
| 898 | #ifndef ENDFILE_SPEC |
| 899 | #define ENDFILE_SPEC "" |
| 900 | #endif |
| 901 | |
| 902 | #ifndef LINKER_NAME |
| 903 | #define LINKER_NAME "collect2" |
| 904 | #endif |
| 905 | |
| 906 | #ifdef HAVE_AS_DEBUG_PREFIX_MAP |
| 907 | #define ASM_MAP " %{ffile-prefix-map=*:--debug-prefix-map %*} %{fdebug-prefix-map=*:--debug-prefix-map %*}" |
| 908 | #else |
| 909 | #define ASM_MAP "" |
| 910 | #endif |
| 911 | |
| 912 | /* Assembler options for compressed debug sections. */ |
| 913 | #if HAVE_LD_COMPRESS_DEBUG == 0 |
| 914 | /* Reject if the linker cannot write compressed debug sections. */ |
| 915 | #define ASM_COMPRESS_DEBUG_SPEC \ |
| 916 | " %{gz*:%e-gz is not supported in this configuration} " |
| 917 | #else /* HAVE_LD_COMPRESS_DEBUG >= 1 */ |
| 918 | #if HAVE_AS_COMPRESS_DEBUG == 0 |
| 919 | /* No assembler support. Ignore silently. */ |
| 920 | #define ASM_COMPRESS_DEBUG_SPEC \ |
| 921 | " %{gz*:} " |
| 922 | #elif HAVE_AS_COMPRESS_DEBUG == 1 |
| 923 | /* ELF gABI style. */ |
| 924 | #define ASM_COMPRESS_DEBUG_SPEC \ |
| 925 | " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ |
| 926 | " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ |
| 927 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
| 928 | #elif HAVE_AS_COMPRESS_DEBUG == 2 |
| 929 | /* ELF gABI style and ZSTD. */ |
| 930 | #define ASM_COMPRESS_DEBUG_SPEC \ |
| 931 | " %{gz|gz=zlib:" AS_COMPRESS_DEBUG_OPTION "=zlib}" \ |
| 932 | " %{gz=none:" AS_COMPRESS_DEBUG_OPTION "=none}" \ |
| 933 | " %{gz=zstd:" AS_COMPRESS_DEBUG_OPTION "=zstd}" \ |
| 934 | " %{gz=zlib-gnu:}" /* Ignore silently zlib-gnu option value. */ |
| 935 | #else |
| 936 | #error Unknown value for HAVE_AS_COMPRESS_DEBUG. |
| 937 | #endif |
| 938 | #endif /* HAVE_LD_COMPRESS_DEBUG >= 1 */ |
| 939 | |
| 940 | /* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' |
| 941 | to the assembler, when compiling assembly sources only. */ |
| 942 | #ifndef ASM_DEBUG_SPEC |
| 943 | # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) |
| 944 | /* If --gdwarf-N is supported and as can handle even compiler generated |
| 945 | .debug_line with it, supply --gdwarf-N in ASM_DEBUG_OPTION_SPEC rather |
| 946 | than in ASM_DEBUG_SPEC, so that it applies to both .s and .c etc. |
| 947 | compilations. */ |
| 948 | # define ASM_DEBUG_DWARF_OPTION "" |
| 949 | # elif defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && !defined(HAVE_LD_BROKEN_PE_DWARF5) |
| 950 | # define ASM_DEBUG_DWARF_OPTION "%{%:dwarf-version-gt(4):--gdwarf-5;" \ |
| 951 | "%:dwarf-version-gt(3):--gdwarf-4;" \ |
| 952 | "%:dwarf-version-gt(2):--gdwarf-3;" \ |
| 953 | ":--gdwarf2}" |
| 954 | # else |
| 955 | # define ASM_DEBUG_DWARF_OPTION "--gdwarf2" |
| 956 | # endif |
| 957 | # if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) |
| 958 | # define ASM_DEBUG_SPEC "%{g*:%{%:debug-level-gt(0):" \ |
| 959 | ASM_DEBUG_DWARF_OPTION "}}" ASM_MAP |
| 960 | # endif |
| 961 | # endif |
| 962 | #ifndef ASM_DEBUG_SPEC |
| 963 | # define ASM_DEBUG_SPEC "" |
| 964 | #endif |
| 965 | |
| 966 | /* Define ASM_DEBUG_OPTION_SPEC to be a spec suitable for translating '-g' |
| 967 | to the assembler when compiling all sources. */ |
| 968 | #ifndef ASM_DEBUG_OPTION_SPEC |
| 969 | # if defined(HAVE_AS_GDWARF_5_DEBUG_FLAG) && defined(HAVE_AS_WORKING_DWARF_N_FLAG) |
| 970 | # define ASM_DEBUG_OPTION_DWARF_OPT \ |
| 971 | "%{%:dwarf-version-gt(4):--gdwarf-5 ;" \ |
| 972 | "%:dwarf-version-gt(3):--gdwarf-4 ;" \ |
| 973 | "%:dwarf-version-gt(2):--gdwarf-3 ;" \ |
| 974 | ":--gdwarf2 }" |
| 975 | # if defined(DWARF2_DEBUGGING_INFO) |
| 976 | # define ASM_DEBUG_OPTION_SPEC "%{g*:%{%:debug-level-gt(0):" \ |
| 977 | ASM_DEBUG_OPTION_DWARF_OPT "}}" |
| 978 | # endif |
| 979 | # endif |
| 980 | #endif |
| 981 | #ifndef ASM_DEBUG_OPTION_SPEC |
| 982 | # define ASM_DEBUG_OPTION_SPEC "" |
| 983 | #endif |
| 984 | |
| 985 | /* Here is the spec for running the linker, after compiling all files. */ |
| 986 | |
| 987 | /* This is overridable by the target in case they need to specify the |
| 988 | -lgcc and -lc order specially, yet not require them to override all |
| 989 | of LINK_COMMAND_SPEC. */ |
| 990 | #ifndef LINK_GCC_C_SEQUENCE_SPEC |
| 991 | #define LINK_GCC_C_SEQUENCE_SPEC "%G %{!nolibc:%L %G}" |
| 992 | #endif |
| 993 | |
| 994 | #ifndef LINK_SSP_SPEC |
| 995 | #ifdef TARGET_LIBC_PROVIDES_SSP |
| 996 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ |
| 997 | "|fstack-protector-strong|fstack-protector-explicit:}" |
| 998 | #else |
| 999 | #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \ |
| 1000 | "|fstack-protector-strong|fstack-protector-explicit" \ |
| 1001 | ":-lssp_nonshared -lssp}" |
| 1002 | #endif |
| 1003 | #endif |
| 1004 | |
| 1005 | #ifdef ENABLE_DEFAULT_PIE |
| 1006 | #define PIE_SPEC "!no-pie" |
| 1007 | #define NO_FPIE1_SPEC "fno-pie" |
| 1008 | #define FPIE1_SPEC NO_FPIE1_SPEC ":;" |
| 1009 | #define NO_FPIE2_SPEC "fno-PIE" |
| 1010 | #define FPIE2_SPEC NO_FPIE2_SPEC ":;" |
| 1011 | #define NO_FPIE_SPEC NO_FPIE1_SPEC "|" NO_FPIE2_SPEC |
| 1012 | #define FPIE_SPEC NO_FPIE_SPEC ":;" |
| 1013 | #define NO_FPIC1_SPEC "fno-pic" |
| 1014 | #define FPIC1_SPEC NO_FPIC1_SPEC ":;" |
| 1015 | #define NO_FPIC2_SPEC "fno-PIC" |
| 1016 | #define FPIC2_SPEC NO_FPIC2_SPEC ":;" |
| 1017 | #define NO_FPIC_SPEC NO_FPIC1_SPEC "|" NO_FPIC2_SPEC |
| 1018 | #define FPIC_SPEC NO_FPIC_SPEC ":;" |
| 1019 | #define NO_FPIE1_AND_FPIC1_SPEC NO_FPIE1_SPEC "|" NO_FPIC1_SPEC |
| 1020 | #define FPIE1_OR_FPIC1_SPEC NO_FPIE1_AND_FPIC1_SPEC ":;" |
| 1021 | #define NO_FPIE2_AND_FPIC2_SPEC NO_FPIE2_SPEC "|" NO_FPIC2_SPEC |
| 1022 | #define FPIE2_OR_FPIC2_SPEC NO_FPIE2_AND_FPIC2_SPEC ":;" |
| 1023 | #define NO_FPIE_AND_FPIC_SPEC NO_FPIE_SPEC "|" NO_FPIC_SPEC |
| 1024 | #define FPIE_OR_FPIC_SPEC NO_FPIE_AND_FPIC_SPEC ":;" |
| 1025 | #else |
| 1026 | #define PIE_SPEC "pie" |
| 1027 | #define FPIE1_SPEC "fpie" |
| 1028 | #define NO_FPIE1_SPEC FPIE1_SPEC ":;" |
| 1029 | #define FPIE2_SPEC "fPIE" |
| 1030 | #define NO_FPIE2_SPEC FPIE2_SPEC ":;" |
| 1031 | #define FPIE_SPEC FPIE1_SPEC "|" FPIE2_SPEC |
| 1032 | #define NO_FPIE_SPEC FPIE_SPEC ":;" |
| 1033 | #define FPIC1_SPEC "fpic" |
| 1034 | #define NO_FPIC1_SPEC FPIC1_SPEC ":;" |
| 1035 | #define FPIC2_SPEC "fPIC" |
| 1036 | #define NO_FPIC2_SPEC FPIC2_SPEC ":;" |
| 1037 | #define FPIC_SPEC FPIC1_SPEC "|" FPIC2_SPEC |
| 1038 | #define NO_FPIC_SPEC FPIC_SPEC ":;" |
| 1039 | #define FPIE1_OR_FPIC1_SPEC FPIE1_SPEC "|" FPIC1_SPEC |
| 1040 | #define NO_FPIE1_AND_FPIC1_SPEC FPIE1_OR_FPIC1_SPEC ":;" |
| 1041 | #define FPIE2_OR_FPIC2_SPEC FPIE2_SPEC "|" FPIC2_SPEC |
| 1042 | #define NO_FPIE2_AND_FPIC2_SPEC FPIE1_OR_FPIC2_SPEC ":;" |
| 1043 | #define FPIE_OR_FPIC_SPEC FPIE_SPEC "|" FPIC_SPEC |
| 1044 | #define NO_FPIE_AND_FPIC_SPEC FPIE_OR_FPIC_SPEC ":;" |
| 1045 | #endif |
| 1046 | |
| 1047 | #ifndef LINK_PIE_SPEC |
| 1048 | #ifdef HAVE_LD_PIE |
| 1049 | #ifndef LD_PIE_SPEC |
| 1050 | #define LD_PIE_SPEC "-pie" |
| 1051 | #endif |
| 1052 | #else |
| 1053 | #define LD_PIE_SPEC "" |
| 1054 | #endif |
| 1055 | #define LINK_PIE_SPEC "%{static|shared|r:;" PIE_SPEC ":" LD_PIE_SPEC "} " |
| 1056 | #endif |
| 1057 | |
| 1058 | #ifndef LINK_BUILDID_SPEC |
| 1059 | # if defined(HAVE_LD_BUILDID) && defined(ENABLE_LD_BUILDID) |
| 1060 | # define LINK_BUILDID_SPEC "%{!r:--build-id} " |
| 1061 | # endif |
| 1062 | #endif |
| 1063 | |
| 1064 | #ifndef LTO_PLUGIN_SPEC |
| 1065 | #define LTO_PLUGIN_SPEC "" |
| 1066 | #endif |
| 1067 | |
| 1068 | /* Conditional to test whether the LTO plugin is used or not. |
| 1069 | FIXME: For slim LTO we will need to enable plugin unconditionally. This |
| 1070 | still cause problems with PLUGIN_LD != LD and when plugin is built but |
| 1071 | not useable. For GCC 4.6 we don't support slim LTO and thus we can enable |
| 1072 | plugin only when LTO is enabled. We still honor explicit |
| 1073 | -fuse-linker-plugin if the linker used understands -plugin. */ |
| 1074 | |
| 1075 | /* The linker has some plugin support. */ |
| 1076 | #if HAVE_LTO_PLUGIN > 0 |
| 1077 | /* The linker used has full plugin support, use LTO plugin by default. */ |
| 1078 | #if HAVE_LTO_PLUGIN == 2 |
| 1079 | #define PLUGIN_COND "!fno-use-linker-plugin:%{!fno-lto" |
| 1080 | #define PLUGIN_COND_CLOSE "}" |
| 1081 | #else |
| 1082 | /* The linker used has limited plugin support, use LTO plugin with explicit |
| 1083 | -fuse-linker-plugin. */ |
| 1084 | #define PLUGIN_COND "fuse-linker-plugin" |
| 1085 | #define PLUGIN_COND_CLOSE "" |
| 1086 | #endif |
| 1087 | #define LINK_PLUGIN_SPEC \ |
| 1088 | "%{" PLUGIN_COND": \ |
| 1089 | -plugin %(linker_plugin_file) \ |
| 1090 | -plugin-opt=%(lto_wrapper) \ |
| 1091 | -plugin-opt=-fresolution=%u.res \ |
| 1092 | " LTO_PLUGIN_SPEC "\ |
| 1093 | %{flinker-output=*:-plugin-opt=-linker-output-known} \ |
| 1094 | %{!nostdlib:%{!nodefaultlibs:%:pass-through-libs(%(link_gcc_c_sequence))}} \ |
| 1095 | }" PLUGIN_COND_CLOSE |
| 1096 | #else |
| 1097 | /* The linker used doesn't support -plugin, reject -fuse-linker-plugin. */ |
| 1098 | #define LINK_PLUGIN_SPEC "%{fuse-linker-plugin:\ |
| 1099 | %e-fuse-linker-plugin is not supported in this configuration}" |
| 1100 | #endif |
| 1101 | |
| 1102 | /* Linker command line options for -fsanitize= early on the command line. */ |
| 1103 | #ifndef SANITIZER_EARLY_SPEC |
| 1104 | #define SANITIZER_EARLY_SPEC "\ |
| 1105 | %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_EARLY_SPEC "} \ |
| 1106 | %{%:sanitize(hwaddress):" LIBHWASAN_EARLY_SPEC "} \ |
| 1107 | %{%:sanitize(thread):" LIBTSAN_EARLY_SPEC "} \ |
| 1108 | %{%:sanitize(leak):" LIBLSAN_EARLY_SPEC "}}}}" |
| 1109 | #endif |
| 1110 | |
| 1111 | /* Linker command line options for -fsanitize= late on the command line. */ |
| 1112 | #ifndef SANITIZER_SPEC |
| 1113 | #define SANITIZER_SPEC "\ |
| 1114 | %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):" LIBASAN_SPEC "\ |
| 1115 | %{static:%ecannot specify -static with -fsanitize=address}}\ |
| 1116 | %{%:sanitize(hwaddress):" LIBHWASAN_SPEC "\ |
| 1117 | %{static:%ecannot specify -static with -fsanitize=hwaddress}}\ |
| 1118 | %{%:sanitize(thread):" LIBTSAN_SPEC "\ |
| 1119 | %{static:%ecannot specify -static with -fsanitize=thread}}\ |
| 1120 | %{%:sanitize(undefined):" LIBUBSAN_SPEC "}\ |
| 1121 | %{%:sanitize(leak):" LIBLSAN_SPEC "}}}}" |
| 1122 | #endif |
| 1123 | |
| 1124 | #ifndef POST_LINK_SPEC |
| 1125 | #define POST_LINK_SPEC "" |
| 1126 | #endif |
| 1127 | |
| 1128 | /* This is the spec to use, once the code for creating the vtable |
| 1129 | verification runtime library, libvtv.so, has been created. Currently |
| 1130 | the vtable verification runtime functions are in libstdc++, so we use |
| 1131 | the spec just below this one. */ |
| 1132 | #ifndef VTABLE_VERIFICATION_SPEC |
| 1133 | #if ENABLE_VTABLE_VERIFY |
| 1134 | #define VTABLE_VERIFICATION_SPEC "\ |
| 1135 | %{!nostdlib:%{!r:%{fvtable-verify=std: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}\ |
| 1136 | %{fvtable-verify=preinit: -lvtv -u_vtable_map_vars_start -u_vtable_map_vars_end}}}" |
| 1137 | #else |
| 1138 | #define VTABLE_VERIFICATION_SPEC "\ |
| 1139 | %{fvtable-verify=none:} \ |
| 1140 | %{fvtable-verify=std: \ |
| 1141 | %e-fvtable-verify=std is not supported in this configuration} \ |
| 1142 | %{fvtable-verify=preinit: \ |
| 1143 | %e-fvtable-verify=preinit is not supported in this configuration}" |
| 1144 | #endif |
| 1145 | #endif |
| 1146 | |
| 1147 | /* -u* was put back because both BSD and SysV seem to support it. */ |
| 1148 | /* %{static|no-pie|static-pie:} simply prevents an error message: |
| 1149 | 1. If the target machine doesn't handle -static. |
| 1150 | 2. If PIE isn't enabled by default. |
| 1151 | 3. If the target machine doesn't handle -static-pie. |
| 1152 | */ |
| 1153 | /* We want %{T*} after %{L*} and %D so that it can be used to specify linker |
| 1154 | scripts which exist in user specified directories, or in standard |
| 1155 | directories. */ |
| 1156 | /* We pass any -flto flags on to the linker, which is expected |
| 1157 | to understand them. In practice, this means it had better be collect2. */ |
| 1158 | /* %{e*} includes -export-dynamic; see comment in common.opt. */ |
| 1159 | #ifndef LINK_COMMAND_SPEC |
| 1160 | #define LINK_COMMAND_SPEC "\ |
| 1161 | %{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ |
| 1162 | %(linker) " \ |
| 1163 | LINK_PLUGIN_SPEC \ |
| 1164 | "%{flto|flto=*:%<fcompare-debug*} \ |
| 1165 | %{flto} %{fno-lto} %{flto=*} %l " LINK_PIE_SPEC \ |
| 1166 | "%{fuse-ld=*:-fuse-ld=%*} " LINK_COMPRESS_DEBUG_SPEC \ |
| 1167 | "%X %{o*} %{e*} %{N} %{n} %{r}\ |
| 1168 | %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} \ |
| 1169 | %{static|no-pie|static-pie:} %@{L*} %(link_libgcc) " \ |
| 1170 | VTABLE_VERIFICATION_SPEC " " SANITIZER_EARLY_SPEC " %o "" \ |
| 1171 | %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1):\ |
| 1172 | %:include(libgomp.spec)%(link_gomp)}\ |
| 1173 | %{fgnu-tm:%:include(libitm.spec)%(link_itm)}\ |
| 1174 | " STACK_SPLIT_SPEC "\ |
| 1175 | %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:-lgcov} " SANITIZER_SPEC " \ |
| 1176 | %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}}\ |
| 1177 | %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*} \n%(post_link) }}}}}}" |
| 1178 | #endif |
| 1179 | |
| 1180 | #ifndef LINK_LIBGCC_SPEC |
| 1181 | /* Generate -L options for startfile prefix list. */ |
| 1182 | # define LINK_LIBGCC_SPEC "%D" |
| 1183 | #endif |
| 1184 | |
| 1185 | #ifndef STARTFILE_PREFIX_SPEC |
| 1186 | # define STARTFILE_PREFIX_SPEC "" |
| 1187 | #endif |
| 1188 | |
| 1189 | #ifndef SYSROOT_SPEC |
| 1190 | # define SYSROOT_SPEC "--sysroot=%R" |
| 1191 | #endif |
| 1192 | |
| 1193 | #ifndef SYSROOT_SUFFIX_SPEC |
| 1194 | # define SYSROOT_SUFFIX_SPEC "" |
| 1195 | #endif |
| 1196 | |
| 1197 | #ifndef SYSROOT_HEADERS_SUFFIX_SPEC |
| 1198 | # define "" |
| 1199 | #endif |
| 1200 | |
| 1201 | #ifndef RUNPATH_OPTION |
| 1202 | # define RUNPATH_OPTION "-rpath" |
| 1203 | #endif |
| 1204 | |
| 1205 | static const char *asm_debug = ASM_DEBUG_SPEC; |
| 1206 | static const char *asm_debug_option = ASM_DEBUG_OPTION_SPEC; |
| 1207 | static const char *cpp_spec = CPP_SPEC; |
| 1208 | static const char *cc1_spec = CC1_SPEC OS_CC1_SPEC; |
| 1209 | static const char *cc1plus_spec = CC1PLUS_SPEC; |
| 1210 | static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC; |
| 1211 | static const char *link_ssp_spec = LINK_SSP_SPEC; |
| 1212 | static const char *asm_spec = ASM_SPEC; |
| 1213 | static const char *asm_final_spec = ASM_FINAL_SPEC; |
| 1214 | static const char *link_spec = LINK_SPEC; |
| 1215 | static const char *lib_spec = LIB_SPEC; |
| 1216 | static const char *link_gomp_spec = "" ; |
| 1217 | static const char *libgcc_spec = LIBGCC_SPEC; |
| 1218 | static const char *endfile_spec = ENDFILE_SPEC; |
| 1219 | static const char *startfile_spec = STARTFILE_SPEC; |
| 1220 | static const char *linker_name_spec = LINKER_NAME; |
| 1221 | static const char *linker_plugin_file_spec = "" ; |
| 1222 | static const char *lto_wrapper_spec = "" ; |
| 1223 | static const char *lto_gcc_spec = "" ; |
| 1224 | static const char *post_link_spec = POST_LINK_SPEC; |
| 1225 | static const char *link_command_spec = LINK_COMMAND_SPEC; |
| 1226 | static const char *link_libgcc_spec = LINK_LIBGCC_SPEC; |
| 1227 | static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC; |
| 1228 | static const char *sysroot_spec = SYSROOT_SPEC; |
| 1229 | static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC; |
| 1230 | static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC; |
| 1231 | static const char *self_spec = "" ; |
| 1232 | |
| 1233 | /* Standard options to cpp, cc1, and as, to reduce duplication in specs. |
| 1234 | There should be no need to override these in target dependent files, |
| 1235 | but we need to copy them to the specs file so that newer versions |
| 1236 | of the GCC driver can correctly drive older tool chains with the |
| 1237 | appropriate -B options. */ |
| 1238 | |
| 1239 | /* When cpplib handles traditional preprocessing, get rid of this, and |
| 1240 | call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so |
| 1241 | that we default the front end language better. */ |
| 1242 | static const char *trad_capable_cpp = |
| 1243 | "cc1 -E %{traditional|traditional-cpp:-traditional-cpp}" ; |
| 1244 | |
| 1245 | /* We don't wrap .d files in %W{} since a missing .d file, and |
| 1246 | therefore no dependency entry, confuses make into thinking a .o |
| 1247 | file that happens to exist is up-to-date. */ |
| 1248 | static const char *cpp_unique_options = |
| 1249 | "%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I\ |
| 1250 | %{MD:-MD %{!o:%b.d}%{o*:%.d%*}}\ |
| 1251 | %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}}\ |
| 1252 | %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*}\ |
| 1253 | %{Mmodules} %{Mno-modules}\ |
| 1254 | %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}}\ |
| 1255 | %{remap} %{%:debug-level-gt(2):-dD}\ |
| 1256 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
| 1257 | %{H} %C %{D*&U*&A*} %{i*} %Z %i\ |
| 1258 | %{E|M|MM:%W{o*}} %{-embed*}\ |
| 1259 | %{fdeps-format=*:%{!fdeps-file=*:-fdeps-file=%:join(%{!o:%b.ddi}%{o*:%.ddi%*})}}\ |
| 1260 | %{fdeps-format=*:%{!fdeps-target=*:-fdeps-target=%:join(%{!o:%b.o}%{o*:%.o%*})}}" ; |
| 1261 | |
| 1262 | /* This contains cpp options which are common with cc1_options and are passed |
| 1263 | only when preprocessing only to avoid duplication. We pass the cc1 spec |
| 1264 | options to the preprocessor so that it the cc1 spec may manipulate |
| 1265 | options used to set target flags. Those special target flags settings may |
| 1266 | in turn cause preprocessor symbols to be defined specially. */ |
| 1267 | static const char *cpp_options = |
| 1268 | "%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w}\ |
| 1269 | %{f*} %{g*:%{%:debug-level-gt(0):%{g*}\ |
| 1270 | %{!fno-working-directory:-fworking-directory}}} %{O*}\ |
| 1271 | %{undef} %{save-temps*:-fpch-preprocess}" ; |
| 1272 | |
| 1273 | /* Pass -d* flags, possibly modifying -dumpdir, -dumpbase et al. |
| 1274 | |
| 1275 | Make it easy for a language to override the argument for the |
| 1276 | %:dumps specs function call. */ |
| 1277 | #define DUMPS_OPTIONS(EXTS) \ |
| 1278 | "%<dumpdir %<dumpbase %<dumpbase-ext %{d*} %:dumps(" EXTS ")" |
| 1279 | |
| 1280 | /* This contains cpp options which are not passed when the preprocessor |
| 1281 | output will be used by another program. */ |
| 1282 | static const char *cpp_debug_options = DUMPS_OPTIONS ("" ); |
| 1283 | |
| 1284 | /* NB: This is shared amongst all front-ends, except for Ada. */ |
| 1285 | static const char *cc1_options = |
| 1286 | "%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\ |
| 1287 | %{!iplugindir*:%{fplugin*:%:find-plugindir()}}\ |
| 1288 | %1 %{!Q:-quiet} %(cpp_debug_options) %{m*} %{aux-info*}\ |
| 1289 | %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs}\ |
| 1290 | %{v:-version} %{pg:-p} %{p} %{f*} %{undef}\ |
| 1291 | %{Qn:-fno-ident} %{Qy:} %{-help:--help}\ |
| 1292 | %{-target-help:--target-help}\ |
| 1293 | %{-version:--version}\ |
| 1294 | %{-help=*:--help=%*}\ |
| 1295 | %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}}\ |
| 1296 | %{fsyntax-only:-o %j} %{-param*}\ |
| 1297 | %{coverage:-fprofile-arcs -ftest-coverage}\ |
| 1298 | %{fprofile-arcs|fcondition-coverage|fpath-coverage|fprofile-generate*|coverage:\ |
| 1299 | %{!fprofile-update=single:\ |
| 1300 | %{pthread:-fprofile-update=prefer-atomic}}}" ; |
| 1301 | |
| 1302 | static const char *asm_options = |
| 1303 | "%{-target-help:%:print-asm-header()} " |
| 1304 | #if HAVE_GNU_AS |
| 1305 | /* If GNU AS is used, then convert -w (no warnings), -I, and -v |
| 1306 | to the assembler equivalents. */ |
| 1307 | "%{v} %{w:-W} %{I*} " |
| 1308 | #endif |
| 1309 | "%(asm_debug_option)" |
| 1310 | ASM_COMPRESS_DEBUG_SPEC |
| 1311 | "%a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}" ; |
| 1312 | |
| 1313 | static const char *invoke_as = |
| 1314 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
| 1315 | "%{!fwpa*:\ |
| 1316 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ |
| 1317 | %{!S:-o %|.s |\n as %(asm_options) %|.s %A }\ |
| 1318 | }" ; |
| 1319 | #else |
| 1320 | "%{!fwpa*:\ |
| 1321 | %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()}\ |
| 1322 | %{!S:-o %|.s |\n as %(asm_options) %m.s %A }\ |
| 1323 | }" ; |
| 1324 | #endif |
| 1325 | |
| 1326 | /* Some compilers have limits on line lengths, and the multilib_select |
| 1327 | and/or multilib_matches strings can be very long, so we build them at |
| 1328 | run time. */ |
| 1329 | static struct obstack multilib_obstack; |
| 1330 | static const char *multilib_select; |
| 1331 | static const char *multilib_matches; |
| 1332 | static const char *multilib_defaults; |
| 1333 | static const char *multilib_exclusions; |
| 1334 | static const char *multilib_reuse; |
| 1335 | |
| 1336 | /* Check whether a particular argument is a default argument. */ |
| 1337 | |
| 1338 | #ifndef MULTILIB_DEFAULTS |
| 1339 | #define MULTILIB_DEFAULTS { "" } |
| 1340 | #endif |
| 1341 | |
| 1342 | static const char *const multilib_defaults_raw[] = MULTILIB_DEFAULTS; |
| 1343 | |
| 1344 | #ifndef DRIVER_SELF_SPECS |
| 1345 | #define DRIVER_SELF_SPECS "" |
| 1346 | #endif |
| 1347 | |
| 1348 | /* Linking to libgomp implies pthreads. This is particularly important |
| 1349 | for targets that use different start files and suchlike. */ |
| 1350 | #ifndef GOMP_SELF_SPECS |
| 1351 | #define GOMP_SELF_SPECS \ |
| 1352 | "%{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): " \ |
| 1353 | "-pthread}" |
| 1354 | #endif |
| 1355 | |
| 1356 | /* Likewise for -fgnu-tm. */ |
| 1357 | #ifndef GTM_SELF_SPECS |
| 1358 | #define GTM_SELF_SPECS "%{fgnu-tm: -pthread}" |
| 1359 | #endif |
| 1360 | |
| 1361 | static const char *const driver_self_specs[] = { |
| 1362 | "%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns" , |
| 1363 | DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS, |
| 1364 | /* This discards -fmultiflags at the end of self specs processing in the |
| 1365 | driver, so that it is effectively Ignored, without actually marking it as |
| 1366 | Ignored, which would get it discarded before self specs could remap it. */ |
| 1367 | "%<fmultiflags" |
| 1368 | }; |
| 1369 | |
| 1370 | #ifndef OPTION_DEFAULT_SPECS |
| 1371 | #define OPTION_DEFAULT_SPECS { "", "" } |
| 1372 | #endif |
| 1373 | |
| 1374 | struct default_spec |
| 1375 | { |
| 1376 | const char *name; |
| 1377 | const char *spec; |
| 1378 | }; |
| 1379 | |
| 1380 | static const struct default_spec |
| 1381 | option_default_specs[] = { OPTION_DEFAULT_SPECS }; |
| 1382 | |
| 1383 | struct user_specs |
| 1384 | { |
| 1385 | struct user_specs *next; |
| 1386 | const char *filename; |
| 1387 | }; |
| 1388 | |
| 1389 | static struct user_specs *user_specs_head, *user_specs_tail; |
| 1390 | |
| 1391 | |
| 1392 | /* Record the mapping from file suffixes for compilation specs. */ |
| 1393 | |
| 1394 | struct compiler |
| 1395 | { |
| 1396 | const char *suffix; /* Use this compiler for input files |
| 1397 | whose names end in this suffix. */ |
| 1398 | |
| 1399 | const char *spec; /* To use this compiler, run this spec. */ |
| 1400 | |
| 1401 | const char *cpp_spec; /* If non-NULL, substitute this spec |
| 1402 | for `%C', rather than the usual |
| 1403 | cpp_spec. */ |
| 1404 | int combinable; /* If nonzero, compiler can deal with |
| 1405 | multiple source files at once (IMA). */ |
| 1406 | int needs_preprocessing; /* If nonzero, source files need to |
| 1407 | be run through a preprocessor. */ |
| 1408 | }; |
| 1409 | |
| 1410 | /* Pointer to a vector of `struct compiler' that gives the spec for |
| 1411 | compiling a file, based on its suffix. |
| 1412 | A file that does not end in any of these suffixes will be passed |
| 1413 | unchanged to the loader and nothing else will be done to it. |
| 1414 | |
| 1415 | An entry containing two 0s is used to terminate the vector. |
| 1416 | |
| 1417 | If multiple entries match a file, the last matching one is used. */ |
| 1418 | |
| 1419 | static struct compiler *compilers; |
| 1420 | |
| 1421 | /* Number of entries in `compilers', not counting the null terminator. */ |
| 1422 | |
| 1423 | static int n_compilers; |
| 1424 | |
| 1425 | /* The default list of file name suffixes and their compilation specs. */ |
| 1426 | |
| 1427 | static const struct compiler default_compilers[] = |
| 1428 | { |
| 1429 | /* Add lists of suffixes of known languages here. If those languages |
| 1430 | were not present when we built the driver, we will hit these copies |
| 1431 | and be given a more meaningful error than "file not used since |
| 1432 | linking is not done". */ |
| 1433 | {.suffix: ".m" , .spec: "#Objective-C" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".mi" , .spec: "#Objective-C" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1434 | {.suffix: ".mm" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".M" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1435 | {.suffix: ".mii" , .spec: "#Objective-C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1436 | {.suffix: ".cc" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".cxx" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1437 | {.suffix: ".cpp" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".cp" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1438 | {.suffix: ".c++" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".C" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1439 | {.suffix: ".CPP" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".ii" , .spec: "#C++" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1440 | {.suffix: ".ads" , .spec: "#Ada" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".adb" , .spec: "#Ada" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1441 | {.suffix: ".f" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1442 | {.suffix: ".for" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FOR" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1443 | {.suffix: ".ftn" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FTN" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1444 | {.suffix: ".fpp" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".FPP" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1445 | {.suffix: ".f90" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F90" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1446 | {.suffix: ".f95" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F95" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1447 | {.suffix: ".f03" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F03" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1448 | {.suffix: ".f08" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".F08" , .spec: "#Fortran" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1449 | {.suffix: ".r" , .spec: "#Ratfor" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1450 | {.suffix: ".go" , .spec: "#Go" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, |
| 1451 | {.suffix: ".d" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, {.suffix: ".dd" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, {.suffix: ".di" , .spec: "#D" , .cpp_spec: 0, .combinable: 1, .needs_preprocessing: 0}, |
| 1452 | {.suffix: ".mod" , .spec: "#Modula-2" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, {.suffix: ".m2i" , .spec: "#Modula-2" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1453 | /* Next come the entries for C. */ |
| 1454 | {.suffix: ".c" , .spec: "@c" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 1}, |
| 1455 | {.suffix: "@c" , |
| 1456 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
| 1457 | external preprocessor if -save-temps is given. */ |
| 1458 | .spec: "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
| 1459 | %{!E:%{!M:%{!MM:\ |
| 1460 | %{traditional:\ |
| 1461 | %eGNU C no longer supports -traditional without -E}\ |
| 1462 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
| 1463 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ |
| 1464 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ |
| 1465 | %(cc1_options)}\ |
| 1466 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
| 1467 | cc1 %(cpp_unique_options) %(cc1_options)}}}\ |
| 1468 | %{!fsyntax-only:%(invoke_as)}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 1}, |
| 1469 | {.suffix: "-" , |
| 1470 | .spec: "%{!E:%e-E or -x required when input is from standard input}\ |
| 1471 | %(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1472 | {.suffix: ".h" , .spec: "@c-header" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1473 | {.suffix: "@c-header" , |
| 1474 | /* cc1 has an integrated ISO C preprocessor. We should invoke the |
| 1475 | external preprocessor if -save-temps is given. */ |
| 1476 | .spec: "%{E|M|MM:%(trad_capable_cpp) %(cpp_options) %(cpp_debug_options)}\ |
| 1477 | %{!E:%{!M:%{!MM:\ |
| 1478 | %{save-temps*|traditional-cpp|no-integrated-cpp:%(trad_capable_cpp) \ |
| 1479 | %(cpp_options) -o %{save-temps*:%b.i} %{!save-temps*:%g.i} \n\ |
| 1480 | cc1 -fpreprocessed %{save-temps*:%b.i} %{!save-temps*:%g.i} \ |
| 1481 | %(cc1_options)\ |
| 1482 | %{!fsyntax-only:%{!S:-o %g.s} \ |
| 1483 | %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\ |
| 1484 | %W{o*:--output-pch %w%*}}%{!S:%V}}}\ |
| 1485 | %{!save-temps*:%{!traditional-cpp:%{!no-integrated-cpp:\ |
| 1486 | cc1 %(cpp_unique_options) %(cc1_options)\ |
| 1487 | %{!fsyntax-only:%{!S:-o %g.s} \ |
| 1488 | %{!fdump-ada-spec*:%{!o*:--output-pch %w%i.gch}\ |
| 1489 | %W{o*:--output-pch %w%*}}%{!S:%V}}}}}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1490 | {.suffix: ".i" , .spec: "@cpp-output" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1491 | {.suffix: "@cpp-output" , |
| 1492 | .spec: "%{!M:%{!MM:%{!E:cc1 -fpreprocessed %i %(cc1_options) %{!fsyntax-only:%(invoke_as)}}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1493 | {.suffix: ".s" , .spec: "@assembler" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1494 | {.suffix: "@assembler" , |
| 1495 | .spec: "%{!M:%{!MM:%{!E:%{!S:as %(asm_debug) %(asm_options) %i %A }}}}" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1496 | {.suffix: ".sx" , .spec: "@assembler-with-cpp" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1497 | {.suffix: ".S" , .spec: "@assembler-with-cpp" , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1498 | {.suffix: "@assembler-with-cpp" , |
| 1499 | #ifdef AS_NEEDS_DASH_FOR_PIPED_INPUT |
| 1500 | "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
| 1501 | %{E|M|MM:%(cpp_debug_options)}\ |
| 1502 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
| 1503 | as %(asm_debug) %(asm_options) %|.s %A }}}}" |
| 1504 | #else |
| 1505 | .spec: "%(trad_capable_cpp) -lang-asm %(cpp_options) -fno-directives-only\ |
| 1506 | %{E|M|MM:%(cpp_debug_options)}\ |
| 1507 | %{!M:%{!MM:%{!E:%{!S:-o %|.s |\n\ |
| 1508 | as %(asm_debug) %(asm_options) %m.s %A }}}}" |
| 1509 | #endif |
| 1510 | , .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0}, |
| 1511 | |
| 1512 | #include "specs.h" |
| 1513 | /* Mark end of table. */ |
| 1514 | {.suffix: 0, .spec: 0, .cpp_spec: 0, .combinable: 0, .needs_preprocessing: 0} |
| 1515 | }; |
| 1516 | |
| 1517 | /* Number of elements in default_compilers, not counting the terminator. */ |
| 1518 | |
| 1519 | static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1; |
| 1520 | |
| 1521 | typedef char *char_p; /* For DEF_VEC_P. */ |
| 1522 | |
| 1523 | /* A vector of options to give to the linker. |
| 1524 | These options are accumulated by %x, |
| 1525 | and substituted into the linker command with %X. */ |
| 1526 | static vec<char_p> linker_options; |
| 1527 | |
| 1528 | /* A vector of options to give to the assembler. |
| 1529 | These options are accumulated by -Wa, |
| 1530 | and substituted into the assembler command with %Y. */ |
| 1531 | static vec<char_p> assembler_options; |
| 1532 | |
| 1533 | /* A vector of options to give to the preprocessor. |
| 1534 | These options are accumulated by -Wp, |
| 1535 | and substituted into the preprocessor command with %Z. */ |
| 1536 | static vec<char_p> preprocessor_options; |
| 1537 | |
| 1538 | static char * |
| 1539 | skip_whitespace (char *p) |
| 1540 | { |
| 1541 | while (1) |
| 1542 | { |
| 1543 | /* A fully-blank line is a delimiter in the SPEC file and shouldn't |
| 1544 | be considered whitespace. */ |
| 1545 | if (p[0] == '\n' && p[1] == '\n' && p[2] == '\n') |
| 1546 | return p + 1; |
| 1547 | else if (*p == '\n' || *p == ' ' || *p == '\t') |
| 1548 | p++; |
| 1549 | else if (*p == '#') |
| 1550 | { |
| 1551 | while (*p != '\n') |
| 1552 | p++; |
| 1553 | p++; |
| 1554 | } |
| 1555 | else |
| 1556 | break; |
| 1557 | } |
| 1558 | |
| 1559 | return p; |
| 1560 | } |
| 1561 | /* Structures to keep track of prefixes to try when looking for files. */ |
| 1562 | |
| 1563 | struct prefix_list |
| 1564 | { |
| 1565 | const char *prefix; /* String to prepend to the path. */ |
| 1566 | struct prefix_list *next; /* Next in linked list. */ |
| 1567 | int require_machine_suffix; /* Don't use without machine_suffix. */ |
| 1568 | /* 2 means try both machine_suffix and just_machine_suffix. */ |
| 1569 | int priority; /* Sort key - priority within list. */ |
| 1570 | int os_multilib; /* 1 if OS multilib scheme should be used, |
| 1571 | 0 for GCC multilib scheme. */ |
| 1572 | }; |
| 1573 | |
| 1574 | struct path_prefix |
| 1575 | { |
| 1576 | struct prefix_list *plist; /* List of prefixes to try */ |
| 1577 | int max_len; /* Max length of a prefix in PLIST */ |
| 1578 | const char *name; /* Name of this list (used in config stuff) */ |
| 1579 | }; |
| 1580 | |
| 1581 | /* List of prefixes to try when looking for executables. */ |
| 1582 | |
| 1583 | static struct path_prefix exec_prefixes = { .plist: 0, .max_len: 0, .name: "exec" }; |
| 1584 | |
| 1585 | /* List of prefixes to try when looking for startup (crt0) files. */ |
| 1586 | |
| 1587 | static struct path_prefix startfile_prefixes = { .plist: 0, .max_len: 0, .name: "startfile" }; |
| 1588 | |
| 1589 | /* List of prefixes to try when looking for include files. */ |
| 1590 | |
| 1591 | static struct path_prefix include_prefixes = { .plist: 0, .max_len: 0, .name: "include" }; |
| 1592 | |
| 1593 | /* Suffix to attach to directories searched for commands. |
| 1594 | This looks like `MACHINE/VERSION/'. */ |
| 1595 | |
| 1596 | static const char *machine_suffix = 0; |
| 1597 | |
| 1598 | /* Suffix to attach to directories searched for commands. |
| 1599 | This is just `MACHINE/'. */ |
| 1600 | |
| 1601 | static const char *just_machine_suffix = 0; |
| 1602 | |
| 1603 | /* Adjusted value of GCC_EXEC_PREFIX envvar. */ |
| 1604 | |
| 1605 | static const char *gcc_exec_prefix; |
| 1606 | |
| 1607 | /* Adjusted value of standard_libexec_prefix. */ |
| 1608 | |
| 1609 | static const char *gcc_libexec_prefix; |
| 1610 | |
| 1611 | /* Default prefixes to attach to command names. */ |
| 1612 | |
| 1613 | #ifndef STANDARD_STARTFILE_PREFIX_1 |
| 1614 | #define STANDARD_STARTFILE_PREFIX_1 "/lib/" |
| 1615 | #endif |
| 1616 | #ifndef STANDARD_STARTFILE_PREFIX_2 |
| 1617 | #define STANDARD_STARTFILE_PREFIX_2 "/usr/lib/" |
| 1618 | #endif |
| 1619 | |
| 1620 | #ifdef CROSS_DIRECTORY_STRUCTURE /* Don't use these prefixes for a cross compiler. */ |
| 1621 | #undef MD_EXEC_PREFIX |
| 1622 | #undef MD_STARTFILE_PREFIX |
| 1623 | #undef MD_STARTFILE_PREFIX_1 |
| 1624 | #endif |
| 1625 | |
| 1626 | /* If no prefixes defined, use the null string, which will disable them. */ |
| 1627 | #ifndef MD_EXEC_PREFIX |
| 1628 | #define MD_EXEC_PREFIX "" |
| 1629 | #endif |
| 1630 | #ifndef MD_STARTFILE_PREFIX |
| 1631 | #define MD_STARTFILE_PREFIX "" |
| 1632 | #endif |
| 1633 | #ifndef MD_STARTFILE_PREFIX_1 |
| 1634 | #define MD_STARTFILE_PREFIX_1 "" |
| 1635 | #endif |
| 1636 | |
| 1637 | /* These directories are locations set at configure-time based on the |
| 1638 | --prefix option provided to configure. Their initializers are |
| 1639 | defined in Makefile.in. These paths are not *directly* used when |
| 1640 | gcc_exec_prefix is set because, in that case, we know where the |
| 1641 | compiler has been installed, and use paths relative to that |
| 1642 | location instead. */ |
| 1643 | static const char *const standard_exec_prefix = STANDARD_EXEC_PREFIX; |
| 1644 | static const char *const standard_libexec_prefix = STANDARD_LIBEXEC_PREFIX; |
| 1645 | static const char *const standard_bindir_prefix = STANDARD_BINDIR_PREFIX; |
| 1646 | static const char *const standard_startfile_prefix = STANDARD_STARTFILE_PREFIX; |
| 1647 | |
| 1648 | /* For native compilers, these are well-known paths containing |
| 1649 | components that may be provided by the system. For cross |
| 1650 | compilers, these paths are not used. */ |
| 1651 | static const char *md_exec_prefix = MD_EXEC_PREFIX; |
| 1652 | static const char *md_startfile_prefix = MD_STARTFILE_PREFIX; |
| 1653 | static const char *md_startfile_prefix_1 = MD_STARTFILE_PREFIX_1; |
| 1654 | static const char *const standard_startfile_prefix_1 |
| 1655 | = STANDARD_STARTFILE_PREFIX_1; |
| 1656 | static const char *const standard_startfile_prefix_2 |
| 1657 | = STANDARD_STARTFILE_PREFIX_2; |
| 1658 | |
| 1659 | /* A relative path to be used in finding the location of tools |
| 1660 | relative to the driver. */ |
| 1661 | static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX; |
| 1662 | |
| 1663 | /* A prefix to be used when this is an accelerator compiler. */ |
| 1664 | static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX; |
| 1665 | |
| 1666 | /* Subdirectory to use for locating libraries. Set by |
| 1667 | set_multilib_dir based on the compilation options. */ |
| 1668 | |
| 1669 | static const char *multilib_dir; |
| 1670 | |
| 1671 | /* Subdirectory to use for locating libraries in OS conventions. Set by |
| 1672 | set_multilib_dir based on the compilation options. */ |
| 1673 | |
| 1674 | static const char *multilib_os_dir; |
| 1675 | |
| 1676 | /* Subdirectory to use for locating libraries in multiarch conventions. Set by |
| 1677 | set_multilib_dir based on the compilation options. */ |
| 1678 | |
| 1679 | static const char *multiarch_dir; |
| 1680 | |
| 1681 | /* Structure to keep track of the specs that have been defined so far. |
| 1682 | These are accessed using %(specname) in a compiler or link |
| 1683 | spec. */ |
| 1684 | |
| 1685 | struct spec_list |
| 1686 | { |
| 1687 | /* The following 2 fields must be first */ |
| 1688 | /* to allow EXTRA_SPECS to be initialized */ |
| 1689 | const char *name; /* name of the spec. */ |
| 1690 | const char *ptr; /* available ptr if no static pointer */ |
| 1691 | |
| 1692 | /* The following fields are not initialized */ |
| 1693 | /* by EXTRA_SPECS */ |
| 1694 | const char **ptr_spec; /* pointer to the spec itself. */ |
| 1695 | struct spec_list *next; /* Next spec in linked list. */ |
| 1696 | int name_len; /* length of the name */ |
| 1697 | bool user_p; /* whether string come from file spec. */ |
| 1698 | bool alloc_p; /* whether string was allocated */ |
| 1699 | const char *default_ptr; /* The default value of *ptr_spec. */ |
| 1700 | }; |
| 1701 | |
| 1702 | #define INIT_STATIC_SPEC(NAME,PTR) \ |
| 1703 | { NAME, NULL, PTR, (struct spec_list *) 0, sizeof (NAME) - 1, false, false, \ |
| 1704 | *PTR } |
| 1705 | |
| 1706 | /* List of statically defined specs. */ |
| 1707 | static struct spec_list static_specs[] = |
| 1708 | { |
| 1709 | INIT_STATIC_SPEC ("asm" , &asm_spec), |
| 1710 | INIT_STATIC_SPEC ("asm_debug" , &asm_debug), |
| 1711 | INIT_STATIC_SPEC ("asm_debug_option" , &asm_debug_option), |
| 1712 | INIT_STATIC_SPEC ("asm_final" , &asm_final_spec), |
| 1713 | INIT_STATIC_SPEC ("asm_options" , &asm_options), |
| 1714 | INIT_STATIC_SPEC ("invoke_as" , &invoke_as), |
| 1715 | INIT_STATIC_SPEC ("cpp" , &cpp_spec), |
| 1716 | INIT_STATIC_SPEC ("cpp_options" , &cpp_options), |
| 1717 | INIT_STATIC_SPEC ("cpp_debug_options" , &cpp_debug_options), |
| 1718 | INIT_STATIC_SPEC ("cpp_unique_options" , &cpp_unique_options), |
| 1719 | INIT_STATIC_SPEC ("trad_capable_cpp" , &trad_capable_cpp), |
| 1720 | INIT_STATIC_SPEC ("cc1" , &cc1_spec), |
| 1721 | INIT_STATIC_SPEC ("cc1_options" , &cc1_options), |
| 1722 | INIT_STATIC_SPEC ("cc1plus" , &cc1plus_spec), |
| 1723 | INIT_STATIC_SPEC ("link_gcc_c_sequence" , &link_gcc_c_sequence_spec), |
| 1724 | INIT_STATIC_SPEC ("link_ssp" , &link_ssp_spec), |
| 1725 | INIT_STATIC_SPEC ("endfile" , &endfile_spec), |
| 1726 | INIT_STATIC_SPEC ("link" , &link_spec), |
| 1727 | INIT_STATIC_SPEC ("lib" , &lib_spec), |
| 1728 | INIT_STATIC_SPEC ("link_gomp" , &link_gomp_spec), |
| 1729 | INIT_STATIC_SPEC ("libgcc" , &libgcc_spec), |
| 1730 | INIT_STATIC_SPEC ("startfile" , &startfile_spec), |
| 1731 | INIT_STATIC_SPEC ("cross_compile" , &cross_compile), |
| 1732 | INIT_STATIC_SPEC ("version" , &compiler_version), |
| 1733 | INIT_STATIC_SPEC ("multilib" , &multilib_select), |
| 1734 | INIT_STATIC_SPEC ("multilib_defaults" , &multilib_defaults), |
| 1735 | INIT_STATIC_SPEC ("multilib_extra" , &multilib_extra), |
| 1736 | INIT_STATIC_SPEC ("multilib_matches" , &multilib_matches), |
| 1737 | INIT_STATIC_SPEC ("multilib_exclusions" , &multilib_exclusions), |
| 1738 | INIT_STATIC_SPEC ("multilib_options" , &multilib_options), |
| 1739 | INIT_STATIC_SPEC ("multilib_reuse" , &multilib_reuse), |
| 1740 | INIT_STATIC_SPEC ("linker" , &linker_name_spec), |
| 1741 | INIT_STATIC_SPEC ("linker_plugin_file" , &linker_plugin_file_spec), |
| 1742 | INIT_STATIC_SPEC ("lto_wrapper" , <o_wrapper_spec), |
| 1743 | INIT_STATIC_SPEC ("lto_gcc" , <o_gcc_spec), |
| 1744 | INIT_STATIC_SPEC ("post_link" , &post_link_spec), |
| 1745 | INIT_STATIC_SPEC ("link_libgcc" , &link_libgcc_spec), |
| 1746 | INIT_STATIC_SPEC ("md_exec_prefix" , &md_exec_prefix), |
| 1747 | INIT_STATIC_SPEC ("md_startfile_prefix" , &md_startfile_prefix), |
| 1748 | INIT_STATIC_SPEC ("md_startfile_prefix_1" , &md_startfile_prefix_1), |
| 1749 | INIT_STATIC_SPEC ("startfile_prefix_spec" , &startfile_prefix_spec), |
| 1750 | INIT_STATIC_SPEC ("sysroot_spec" , &sysroot_spec), |
| 1751 | INIT_STATIC_SPEC ("sysroot_suffix_spec" , &sysroot_suffix_spec), |
| 1752 | INIT_STATIC_SPEC ("sysroot_hdrs_suffix_spec" , &sysroot_hdrs_suffix_spec), |
| 1753 | INIT_STATIC_SPEC ("self_spec" , &self_spec), |
| 1754 | }; |
| 1755 | |
| 1756 | #ifdef EXTRA_SPECS /* additional specs needed */ |
| 1757 | /* Structure to keep track of just the first two args of a spec_list. |
| 1758 | That is all that the EXTRA_SPECS macro gives us. */ |
| 1759 | struct spec_list_1 |
| 1760 | { |
| 1761 | const char *const name; |
| 1762 | const char *const ptr; |
| 1763 | }; |
| 1764 | |
| 1765 | static const struct spec_list_1 [] = { EXTRA_SPECS }; |
| 1766 | static struct spec_list * = (struct spec_list *) 0; |
| 1767 | #endif |
| 1768 | |
| 1769 | /* List of dynamically allocates specs that have been defined so far. */ |
| 1770 | |
| 1771 | static struct spec_list *specs = (struct spec_list *) 0; |
| 1772 | |
| 1773 | /* List of static spec functions. */ |
| 1774 | |
| 1775 | static const struct spec_function static_spec_functions[] = |
| 1776 | { |
| 1777 | { .name: "getenv" , .func: getenv_spec_function }, |
| 1778 | { .name: "if-exists" , .func: if_exists_spec_function }, |
| 1779 | { .name: "if-exists-else" , .func: if_exists_else_spec_function }, |
| 1780 | { .name: "if-exists-then-else" , .func: if_exists_then_else_spec_function }, |
| 1781 | { .name: "sanitize" , .func: sanitize_spec_function }, |
| 1782 | { .name: "replace-outfile" , .func: replace_outfile_spec_function }, |
| 1783 | { .name: "remove-outfile" , .func: remove_outfile_spec_function }, |
| 1784 | { .name: "version-compare" , .func: version_compare_spec_function }, |
| 1785 | { .name: "include" , .func: include_spec_function }, |
| 1786 | { .name: "find-file" , .func: find_file_spec_function }, |
| 1787 | { .name: "find-plugindir" , .func: find_plugindir_spec_function }, |
| 1788 | { .name: "print-asm-header" , .func: print_asm_header_spec_function }, |
| 1789 | { .name: "compare-debug-dump-opt" , .func: compare_debug_dump_opt_spec_function }, |
| 1790 | { .name: "compare-debug-self-opt" , .func: compare_debug_self_opt_spec_function }, |
| 1791 | { .name: "pass-through-libs" , .func: pass_through_libs_spec_func }, |
| 1792 | { .name: "dumps" , .func: dumps_spec_func }, |
| 1793 | { .name: "gt" , .func: greater_than_spec_func }, |
| 1794 | { .name: "debug-level-gt" , .func: debug_level_greater_than_spec_func }, |
| 1795 | { .name: "dwarf-version-gt" , .func: dwarf_version_greater_than_spec_func }, |
| 1796 | { .name: "fortran-preinclude-file" , .func: find_fortran_preinclude_file}, |
| 1797 | { .name: "join" , .func: join_spec_func}, |
| 1798 | #ifdef EXTRA_SPEC_FUNCTIONS |
| 1799 | EXTRA_SPEC_FUNCTIONS |
| 1800 | #endif |
| 1801 | { .name: 0, .func: 0 } |
| 1802 | }; |
| 1803 | |
| 1804 | static int processing_spec_function; |
| 1805 | |
| 1806 | /* Add appropriate libgcc specs to OBSTACK, taking into account |
| 1807 | various permutations of -shared-libgcc, -shared, and such. */ |
| 1808 | |
| 1809 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
| 1810 | |
| 1811 | #ifndef USE_LD_AS_NEEDED |
| 1812 | #define USE_LD_AS_NEEDED 0 |
| 1813 | #endif |
| 1814 | |
| 1815 | static void |
| 1816 | init_gcc_specs (struct obstack *obstack, const char *shared_name, |
| 1817 | const char *static_name, const char *eh_name) |
| 1818 | { |
| 1819 | char *buf; |
| 1820 | |
| 1821 | #if USE_LD_AS_NEEDED |
| 1822 | buf = concat ("%{static|static-libgcc|static-pie:" , static_name, " " , eh_name, "}" |
| 1823 | "%{!static:%{!static-libgcc:%{!static-pie:" |
| 1824 | "%{!shared-libgcc:" , |
| 1825 | static_name, " " LD_AS_NEEDED_OPTION " " , |
| 1826 | shared_name, " " LD_NO_AS_NEEDED_OPTION |
| 1827 | "}" |
| 1828 | "%{shared-libgcc:" , |
| 1829 | shared_name, "%{!shared: " , static_name, "}" |
| 1830 | "}}" |
| 1831 | #else |
| 1832 | buf = concat ("%{static|static-libgcc:" , static_name, " " , eh_name, "}" |
| 1833 | "%{!static:%{!static-libgcc:" |
| 1834 | "%{!shared:" |
| 1835 | "%{!shared-libgcc:" , static_name, " " , eh_name, "}" |
| 1836 | "%{shared-libgcc:" , shared_name, " " , static_name, "}" |
| 1837 | "}" |
| 1838 | #ifdef LINK_EH_SPEC |
| 1839 | "%{shared:" |
| 1840 | "%{shared-libgcc:" , shared_name, "}" |
| 1841 | "%{!shared-libgcc:" , static_name, "}" |
| 1842 | "}" |
| 1843 | #else |
| 1844 | "%{shared:" , shared_name, "}" |
| 1845 | #endif |
| 1846 | #endif |
| 1847 | "}}" , NULL); |
| 1848 | |
| 1849 | obstack_grow (obstack, buf, strlen (buf)); |
| 1850 | free (ptr: buf); |
| 1851 | } |
| 1852 | #endif /* ENABLE_SHARED_LIBGCC */ |
| 1853 | |
| 1854 | /* Initialize the specs lookup routines. */ |
| 1855 | |
| 1856 | static void |
| 1857 | init_spec (void) |
| 1858 | { |
| 1859 | struct spec_list *next = (struct spec_list *) 0; |
| 1860 | struct spec_list *sl = (struct spec_list *) 0; |
| 1861 | int i; |
| 1862 | |
| 1863 | if (specs) |
| 1864 | return; /* Already initialized. */ |
| 1865 | |
| 1866 | if (verbose_flag) |
| 1867 | fnotice (stderr, "Using built-in specs.\n" ); |
| 1868 | |
| 1869 | #ifdef EXTRA_SPECS |
| 1870 | extra_specs = XCNEWVEC (struct spec_list, ARRAY_SIZE (extra_specs_1)); |
| 1871 | |
| 1872 | for (i = ARRAY_SIZE (extra_specs_1) - 1; i >= 0; i--) |
| 1873 | { |
| 1874 | sl = &extra_specs[i]; |
| 1875 | sl->name = extra_specs_1[i].name; |
| 1876 | sl->ptr = extra_specs_1[i].ptr; |
| 1877 | sl->next = next; |
| 1878 | sl->name_len = strlen (s: sl->name); |
| 1879 | sl->ptr_spec = &sl->ptr; |
| 1880 | gcc_assert (sl->ptr_spec != NULL); |
| 1881 | sl->default_ptr = sl->ptr; |
| 1882 | next = sl; |
| 1883 | } |
| 1884 | #endif |
| 1885 | |
| 1886 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
| 1887 | { |
| 1888 | sl = &static_specs[i]; |
| 1889 | sl->next = next; |
| 1890 | next = sl; |
| 1891 | } |
| 1892 | |
| 1893 | #if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC) |
| 1894 | /* ??? If neither -shared-libgcc nor --static-libgcc was |
| 1895 | seen, then we should be making an educated guess. Some proposed |
| 1896 | heuristics for ELF include: |
| 1897 | |
| 1898 | (1) If "-Wl,--export-dynamic", then it's a fair bet that the |
| 1899 | program will be doing dynamic loading, which will likely |
| 1900 | need the shared libgcc. |
| 1901 | |
| 1902 | (2) If "-ldl", then it's also a fair bet that we're doing |
| 1903 | dynamic loading. |
| 1904 | |
| 1905 | (3) For each ET_DYN we're linking against (either through -lfoo |
| 1906 | or /some/path/foo.so), check to see whether it or one of |
| 1907 | its dependencies depends on a shared libgcc. |
| 1908 | |
| 1909 | (4) If "-shared" |
| 1910 | |
| 1911 | If the runtime is fixed to look for program headers instead |
| 1912 | of calling __register_frame_info at all, for each object, |
| 1913 | use the shared libgcc if any EH symbol referenced. |
| 1914 | |
| 1915 | If crtstuff is fixed to not invoke __register_frame_info |
| 1916 | automatically, for each object, use the shared libgcc if |
| 1917 | any non-empty unwind section found. |
| 1918 | |
| 1919 | Doing any of this probably requires invoking an external program to |
| 1920 | do the actual object file scanning. */ |
| 1921 | { |
| 1922 | const char *p = libgcc_spec; |
| 1923 | int in_sep = 1; |
| 1924 | |
| 1925 | /* Transform the extant libgcc_spec into one that uses the shared libgcc |
| 1926 | when given the proper command line arguments. */ |
| 1927 | while (*p) |
| 1928 | { |
| 1929 | if (in_sep && *p == '-' && startswith (str: p, prefix: "-lgcc" )) |
| 1930 | { |
| 1931 | init_gcc_specs (obstack: &obstack, |
| 1932 | shared_name: "-lgcc_s" |
| 1933 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
| 1934 | " -lunwind" |
| 1935 | #endif |
| 1936 | , |
| 1937 | static_name: "-lgcc" , |
| 1938 | eh_name: "-lgcc_eh" |
| 1939 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
| 1940 | # ifdef HAVE_LD_STATIC_DYNAMIC |
| 1941 | " %{!static:%{!static-pie:" LD_STATIC_OPTION "}} -lunwind" |
| 1942 | " %{!static:%{!static-pie:" LD_DYNAMIC_OPTION "}}" |
| 1943 | # else |
| 1944 | " -lunwind" |
| 1945 | # endif |
| 1946 | #endif |
| 1947 | ); |
| 1948 | |
| 1949 | p += 5; |
| 1950 | in_sep = 0; |
| 1951 | } |
| 1952 | else if (in_sep && *p == 'l' && startswith (str: p, prefix: "libgcc.a%s" )) |
| 1953 | { |
| 1954 | /* Ug. We don't know shared library extensions. Hope that |
| 1955 | systems that use this form don't do shared libraries. */ |
| 1956 | init_gcc_specs (obstack: &obstack, |
| 1957 | shared_name: "-lgcc_s" , |
| 1958 | static_name: "libgcc.a%s" , |
| 1959 | eh_name: "libgcc_eh.a%s" |
| 1960 | #ifdef USE_LIBUNWIND_EXCEPTIONS |
| 1961 | " -lunwind" |
| 1962 | #endif |
| 1963 | ); |
| 1964 | p += 10; |
| 1965 | in_sep = 0; |
| 1966 | } |
| 1967 | else |
| 1968 | { |
| 1969 | obstack_1grow (&obstack, *p); |
| 1970 | in_sep = (*p == ' '); |
| 1971 | p += 1; |
| 1972 | } |
| 1973 | } |
| 1974 | |
| 1975 | obstack_1grow (&obstack, '\0'); |
| 1976 | libgcc_spec = XOBFINISH (&obstack, const char *); |
| 1977 | } |
| 1978 | #endif |
| 1979 | #ifdef USE_AS_TRADITIONAL_FORMAT |
| 1980 | /* Prepend "--traditional-format" to whatever asm_spec we had before. */ |
| 1981 | { |
| 1982 | static const char tf[] = "--traditional-format " ; |
| 1983 | obstack_grow (&obstack, tf, sizeof (tf) - 1); |
| 1984 | obstack_grow0 (&obstack, asm_spec, strlen (asm_spec)); |
| 1985 | asm_spec = XOBFINISH (&obstack, const char *); |
| 1986 | } |
| 1987 | #endif |
| 1988 | |
| 1989 | #if defined LINK_EH_SPEC || defined LINK_BUILDID_SPEC || \ |
| 1990 | defined LINKER_HASH_STYLE |
| 1991 | # ifdef LINK_BUILDID_SPEC |
| 1992 | /* Prepend LINK_BUILDID_SPEC to whatever link_spec we had before. */ |
| 1993 | obstack_grow (&obstack, LINK_BUILDID_SPEC, sizeof (LINK_BUILDID_SPEC) - 1); |
| 1994 | # endif |
| 1995 | # ifdef LINK_EH_SPEC |
| 1996 | /* Prepend LINK_EH_SPEC to whatever link_spec we had before. */ |
| 1997 | obstack_grow (&obstack, LINK_EH_SPEC, sizeof (LINK_EH_SPEC) - 1); |
| 1998 | # endif |
| 1999 | # ifdef LINKER_HASH_STYLE |
| 2000 | /* Prepend --hash-style=LINKER_HASH_STYLE to whatever link_spec we had |
| 2001 | before. */ |
| 2002 | { |
| 2003 | static const char hash_style[] = "--hash-style=" ; |
| 2004 | obstack_grow (&obstack, hash_style, sizeof (hash_style) - 1); |
| 2005 | obstack_grow (&obstack, LINKER_HASH_STYLE, sizeof (LINKER_HASH_STYLE) - 1); |
| 2006 | obstack_1grow (&obstack, ' '); |
| 2007 | } |
| 2008 | # endif |
| 2009 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
| 2010 | link_spec = XOBFINISH (&obstack, const char *); |
| 2011 | #endif |
| 2012 | |
| 2013 | specs = sl; |
| 2014 | } |
| 2015 | |
| 2016 | /* Update the entry for SPEC in the static_specs table to point to VALUE, |
| 2017 | ensuring that we free the previous value if necessary. Set alloc_p for the |
| 2018 | entry to ALLOC_P: this determines whether we take ownership of VALUE (i.e. |
| 2019 | whether we need to free it later on). */ |
| 2020 | static void |
| 2021 | set_static_spec (const char **spec, const char *value, bool alloc_p) |
| 2022 | { |
| 2023 | struct spec_list *sl = NULL; |
| 2024 | |
| 2025 | for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++) |
| 2026 | { |
| 2027 | if (static_specs[i].ptr_spec == spec) |
| 2028 | { |
| 2029 | sl = static_specs + i; |
| 2030 | break; |
| 2031 | } |
| 2032 | } |
| 2033 | |
| 2034 | gcc_assert (sl); |
| 2035 | |
| 2036 | if (sl->alloc_p) |
| 2037 | { |
| 2038 | const char *old = *spec; |
| 2039 | free (ptr: const_cast <char *> (old)); |
| 2040 | } |
| 2041 | |
| 2042 | *spec = value; |
| 2043 | sl->alloc_p = alloc_p; |
| 2044 | } |
| 2045 | |
| 2046 | /* Update a static spec to a new string, taking ownership of that |
| 2047 | string's memory. */ |
| 2048 | static void set_static_spec_owned (const char **spec, const char *val) |
| 2049 | { |
| 2050 | return set_static_spec (spec, value: val, alloc_p: true); |
| 2051 | } |
| 2052 | |
| 2053 | /* Update a static spec to point to a new value, but don't take |
| 2054 | ownership of (i.e. don't free) that string. */ |
| 2055 | static void set_static_spec_shared (const char **spec, const char *val) |
| 2056 | { |
| 2057 | return set_static_spec (spec, value: val, alloc_p: false); |
| 2058 | } |
| 2059 | |
| 2060 | |
| 2061 | /* Change the value of spec NAME to SPEC. If SPEC is empty, then the spec is |
| 2062 | removed; If the spec starts with a + then SPEC is added to the end of the |
| 2063 | current spec. */ |
| 2064 | |
| 2065 | static void |
| 2066 | set_spec (const char *name, const char *spec, bool user_p) |
| 2067 | { |
| 2068 | struct spec_list *sl; |
| 2069 | const char *old_spec; |
| 2070 | int name_len = strlen (s: name); |
| 2071 | int i; |
| 2072 | |
| 2073 | /* If this is the first call, initialize the statically allocated specs. */ |
| 2074 | if (!specs) |
| 2075 | { |
| 2076 | struct spec_list *next = (struct spec_list *) 0; |
| 2077 | for (i = ARRAY_SIZE (static_specs) - 1; i >= 0; i--) |
| 2078 | { |
| 2079 | sl = &static_specs[i]; |
| 2080 | sl->next = next; |
| 2081 | next = sl; |
| 2082 | } |
| 2083 | specs = sl; |
| 2084 | } |
| 2085 | |
| 2086 | /* See if the spec already exists. */ |
| 2087 | for (sl = specs; sl; sl = sl->next) |
| 2088 | if (name_len == sl->name_len && !strcmp (s1: sl->name, s2: name)) |
| 2089 | break; |
| 2090 | |
| 2091 | if (!sl) |
| 2092 | { |
| 2093 | /* Not found - make it. */ |
| 2094 | sl = XNEW (struct spec_list); |
| 2095 | sl->name = xstrdup (name); |
| 2096 | sl->name_len = name_len; |
| 2097 | sl->ptr_spec = &sl->ptr; |
| 2098 | sl->alloc_p = 0; |
| 2099 | *(sl->ptr_spec) = "" ; |
| 2100 | sl->next = specs; |
| 2101 | sl->default_ptr = NULL; |
| 2102 | specs = sl; |
| 2103 | } |
| 2104 | |
| 2105 | old_spec = *(sl->ptr_spec); |
| 2106 | *(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1])) |
| 2107 | ? concat (old_spec, spec + 1, NULL) |
| 2108 | : xstrdup (spec)); |
| 2109 | |
| 2110 | #ifdef DEBUG_SPECS |
| 2111 | if (verbose_flag) |
| 2112 | fnotice (stderr, "Setting spec %s to '%s'\n\n" , name, *(sl->ptr_spec)); |
| 2113 | #endif |
| 2114 | |
| 2115 | /* Free the old spec. */ |
| 2116 | if (old_spec && sl->alloc_p) |
| 2117 | free (CONST_CAST (char *, old_spec)); |
| 2118 | |
| 2119 | sl->user_p = user_p; |
| 2120 | sl->alloc_p = true; |
| 2121 | } |
| 2122 | |
| 2123 | /* Accumulate a command (program name and args), and run it. */ |
| 2124 | |
| 2125 | typedef const char *const_char_p; /* For DEF_VEC_P. */ |
| 2126 | |
| 2127 | /* Vector of pointers to arguments in the current line of specifications. */ |
| 2128 | static vec<const_char_p> argbuf; |
| 2129 | |
| 2130 | /* Likewise, but for the current @file. */ |
| 2131 | static vec<const_char_p> at_file_argbuf; |
| 2132 | |
| 2133 | /* Whether an @file is currently open. */ |
| 2134 | static bool in_at_file = false; |
| 2135 | |
| 2136 | /* Were the options -c, -S or -E passed. */ |
| 2137 | static int have_c = 0; |
| 2138 | |
| 2139 | /* Was the option -o passed. */ |
| 2140 | static int have_o = 0; |
| 2141 | |
| 2142 | /* Was the option -E passed. */ |
| 2143 | static int have_E = 0; |
| 2144 | |
| 2145 | /* Pointer to output file name passed in with -o. */ |
| 2146 | static const char *output_file = 0; |
| 2147 | |
| 2148 | /* Pointer to input file name passed in with -truncate. |
| 2149 | This file should be truncated after linking. */ |
| 2150 | static const char *totruncate_file = 0; |
| 2151 | |
| 2152 | /* This is the list of suffixes and codes (%g/%u/%U/%j) and the associated |
| 2153 | temp file. If the HOST_BIT_BUCKET is used for %j, no entry is made for |
| 2154 | it here. */ |
| 2155 | |
| 2156 | static struct temp_name { |
| 2157 | const char *suffix; /* suffix associated with the code. */ |
| 2158 | int length; /* strlen (suffix). */ |
| 2159 | int unique; /* Indicates whether %g or %u/%U was used. */ |
| 2160 | const char *filename; /* associated filename. */ |
| 2161 | int filename_length; /* strlen (filename). */ |
| 2162 | struct temp_name *next; |
| 2163 | } *temp_names; |
| 2164 | |
| 2165 | /* Number of commands executed so far. */ |
| 2166 | |
| 2167 | static int execution_count; |
| 2168 | |
| 2169 | /* Number of commands that exited with a signal. */ |
| 2170 | |
| 2171 | static int signal_count; |
| 2172 | |
| 2173 | /* Allocate the argument vector. */ |
| 2174 | |
| 2175 | static void |
| 2176 | alloc_args (void) |
| 2177 | { |
| 2178 | argbuf.create (nelems: 10); |
| 2179 | at_file_argbuf.create (nelems: 10); |
| 2180 | } |
| 2181 | |
| 2182 | /* Clear out the vector of arguments (after a command is executed). */ |
| 2183 | |
| 2184 | static void |
| 2185 | clear_args (void) |
| 2186 | { |
| 2187 | argbuf.truncate (size: 0); |
| 2188 | at_file_argbuf.truncate (size: 0); |
| 2189 | } |
| 2190 | |
| 2191 | /* Add one argument to the vector at the end. |
| 2192 | This is done when a space is seen or at the end of the line. |
| 2193 | If DELETE_ALWAYS is nonzero, the arg is a filename |
| 2194 | and the file should be deleted eventually. |
| 2195 | If DELETE_FAILURE is nonzero, the arg is a filename |
| 2196 | and the file should be deleted if this compilation fails. */ |
| 2197 | |
| 2198 | static void |
| 2199 | store_arg (const char *arg, int delete_always, int delete_failure) |
| 2200 | { |
| 2201 | if (in_at_file) |
| 2202 | at_file_argbuf.safe_push (obj: arg); |
| 2203 | else |
| 2204 | argbuf.safe_push (obj: arg); |
| 2205 | |
| 2206 | if (delete_always || delete_failure) |
| 2207 | { |
| 2208 | const char *p; |
| 2209 | /* If the temporary file we should delete is specified as |
| 2210 | part of a joined argument extract the filename. */ |
| 2211 | if (arg[0] == '-' |
| 2212 | && (p = strrchr (s: arg, c: '='))) |
| 2213 | arg = p + 1; |
| 2214 | record_temp_file (arg, delete_always, delete_failure); |
| 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | /* Open a temporary @file into which subsequent arguments will be stored. */ |
| 2219 | |
| 2220 | static void |
| 2221 | open_at_file (void) |
| 2222 | { |
| 2223 | if (in_at_file) |
| 2224 | fatal_error (input_location, "cannot open nested response file" ); |
| 2225 | else |
| 2226 | in_at_file = true; |
| 2227 | } |
| 2228 | |
| 2229 | /* Create a temporary @file name. */ |
| 2230 | |
| 2231 | static char *make_at_file (void) |
| 2232 | { |
| 2233 | static int fileno = 0; |
| 2234 | char filename[20]; |
| 2235 | const char *base, *ext; |
| 2236 | |
| 2237 | if (!save_temps_flag) |
| 2238 | return make_temp_file ("" ); |
| 2239 | |
| 2240 | base = dumpbase; |
| 2241 | if (!(base && *base)) |
| 2242 | base = dumpdir; |
| 2243 | if (!(base && *base)) |
| 2244 | base = "a" ; |
| 2245 | |
| 2246 | sprintf (s: filename, format: ".args.%d" , fileno++); |
| 2247 | ext = filename; |
| 2248 | |
| 2249 | if (base == dumpdir && dumpdir_trailing_dash_added) |
| 2250 | ext++; |
| 2251 | |
| 2252 | return concat (base, ext, NULL); |
| 2253 | } |
| 2254 | |
| 2255 | /* Close the temporary @file and add @file to the argument list. */ |
| 2256 | |
| 2257 | static void |
| 2258 | close_at_file (void) |
| 2259 | { |
| 2260 | if (!in_at_file) |
| 2261 | fatal_error (input_location, "cannot close nonexistent response file" ); |
| 2262 | |
| 2263 | in_at_file = false; |
| 2264 | |
| 2265 | const unsigned int n_args = at_file_argbuf.length (); |
| 2266 | if (n_args == 0) |
| 2267 | return; |
| 2268 | |
| 2269 | char **argv = XALLOCAVEC (char *, n_args + 1); |
| 2270 | char *temp_file = make_at_file (); |
| 2271 | char *at_argument = concat ("@" , temp_file, NULL); |
| 2272 | FILE *f = fopen (filename: temp_file, modes: "w" ); |
| 2273 | int status; |
| 2274 | unsigned int i; |
| 2275 | |
| 2276 | /* Copy the strings over. */ |
| 2277 | for (i = 0; i < n_args; i++) |
| 2278 | argv[i] = CONST_CAST (char *, at_file_argbuf[i]); |
| 2279 | argv[i] = NULL; |
| 2280 | |
| 2281 | at_file_argbuf.truncate (size: 0); |
| 2282 | |
| 2283 | if (f == NULL) |
| 2284 | fatal_error (input_location, "could not open temporary response file %s" , |
| 2285 | temp_file); |
| 2286 | |
| 2287 | status = writeargv (argv, f); |
| 2288 | |
| 2289 | if (status) |
| 2290 | fatal_error (input_location, |
| 2291 | "could not write to temporary response file %s" , |
| 2292 | temp_file); |
| 2293 | |
| 2294 | status = fclose (stream: f); |
| 2295 | |
| 2296 | if (status == EOF) |
| 2297 | fatal_error (input_location, "could not close temporary response file %s" , |
| 2298 | temp_file); |
| 2299 | |
| 2300 | store_arg (arg: at_argument, delete_always: 0, delete_failure: 0); |
| 2301 | |
| 2302 | record_temp_file (temp_file, !save_temps_flag, !save_temps_flag); |
| 2303 | } |
| 2304 | |
| 2305 | /* Load specs from a file name named FILENAME, replacing occurrences of |
| 2306 | various different types of line-endings, \r\n, \n\r and just \r, with |
| 2307 | a single \n. */ |
| 2308 | |
| 2309 | static char * |
| 2310 | load_specs (const char *filename) |
| 2311 | { |
| 2312 | int desc; |
| 2313 | int readlen; |
| 2314 | struct stat statbuf; |
| 2315 | char *buffer; |
| 2316 | char *buffer_p; |
| 2317 | char *specs; |
| 2318 | char *specs_p; |
| 2319 | |
| 2320 | if (verbose_flag) |
| 2321 | fnotice (stderr, "Reading specs from %s\n" , filename); |
| 2322 | |
| 2323 | /* Open and stat the file. */ |
| 2324 | desc = open (file: filename, O_RDONLY, 0); |
| 2325 | if (desc < 0) |
| 2326 | { |
| 2327 | failed: |
| 2328 | /* This leaves DESC open, but the OS will save us. */ |
| 2329 | fatal_error (input_location, "cannot read spec file %qs: %m" , filename); |
| 2330 | } |
| 2331 | |
| 2332 | if (stat (file: filename, buf: &statbuf) < 0) |
| 2333 | goto failed; |
| 2334 | |
| 2335 | /* Read contents of file into BUFFER. */ |
| 2336 | buffer = XNEWVEC (char, statbuf.st_size + 1); |
| 2337 | readlen = read (fd: desc, buf: buffer, nbytes: (unsigned) statbuf.st_size); |
| 2338 | if (readlen < 0) |
| 2339 | goto failed; |
| 2340 | buffer[readlen] = 0; |
| 2341 | close (fd: desc); |
| 2342 | |
| 2343 | specs = XNEWVEC (char, readlen + 1); |
| 2344 | specs_p = specs; |
| 2345 | for (buffer_p = buffer; buffer_p && *buffer_p; buffer_p++) |
| 2346 | { |
| 2347 | int skip = 0; |
| 2348 | char c = *buffer_p; |
| 2349 | if (c == '\r') |
| 2350 | { |
| 2351 | if (buffer_p > buffer && *(buffer_p - 1) == '\n') /* \n\r */ |
| 2352 | skip = 1; |
| 2353 | else if (*(buffer_p + 1) == '\n') /* \r\n */ |
| 2354 | skip = 1; |
| 2355 | else /* \r */ |
| 2356 | c = '\n'; |
| 2357 | } |
| 2358 | if (! skip) |
| 2359 | *specs_p++ = c; |
| 2360 | } |
| 2361 | *specs_p = '\0'; |
| 2362 | |
| 2363 | free (ptr: buffer); |
| 2364 | return (specs); |
| 2365 | } |
| 2366 | |
| 2367 | /* Read compilation specs from a file named FILENAME, |
| 2368 | replacing the default ones. |
| 2369 | |
| 2370 | A suffix which starts with `*' is a definition for |
| 2371 | one of the machine-specific sub-specs. The "suffix" should be |
| 2372 | *asm, *cc1, *cpp, *link, *startfile, etc. |
| 2373 | The corresponding spec is stored in asm_spec, etc., |
| 2374 | rather than in the `compilers' vector. |
| 2375 | |
| 2376 | Anything invalid in the file is a fatal error. */ |
| 2377 | |
| 2378 | static void |
| 2379 | read_specs (const char *filename, bool main_p, bool user_p) |
| 2380 | { |
| 2381 | char *buffer; |
| 2382 | char *p; |
| 2383 | |
| 2384 | buffer = load_specs (filename); |
| 2385 | |
| 2386 | /* Scan BUFFER for specs, putting them in the vector. */ |
| 2387 | p = buffer; |
| 2388 | while (1) |
| 2389 | { |
| 2390 | char *suffix; |
| 2391 | char *spec; |
| 2392 | char *in, *out, *p1, *p2, *p3; |
| 2393 | |
| 2394 | /* Advance P in BUFFER to the next nonblank nocomment line. */ |
| 2395 | p = skip_whitespace (p); |
| 2396 | if (*p == 0) |
| 2397 | break; |
| 2398 | |
| 2399 | /* Is this a special command that starts with '%'? */ |
| 2400 | /* Don't allow this for the main specs file, since it would |
| 2401 | encourage people to overwrite it. */ |
| 2402 | if (*p == '%' && !main_p) |
| 2403 | { |
| 2404 | p1 = p; |
| 2405 | while (*p && *p != '\n') |
| 2406 | p++; |
| 2407 | |
| 2408 | /* Skip '\n'. */ |
| 2409 | p++; |
| 2410 | |
| 2411 | if (startswith (str: p1, prefix: "%include" ) |
| 2412 | && (p1[sizeof "%include" - 1] == ' ' |
| 2413 | || p1[sizeof "%include" - 1] == '\t')) |
| 2414 | { |
| 2415 | char *new_filename; |
| 2416 | |
| 2417 | p1 += sizeof ("%include" ); |
| 2418 | while (*p1 == ' ' || *p1 == '\t') |
| 2419 | p1++; |
| 2420 | |
| 2421 | if (*p1++ != '<' || p[-2] != '>') |
| 2422 | fatal_error (input_location, |
| 2423 | "specs %%include syntax malformed after " |
| 2424 | "%td characters" , p1 - buffer + 1); |
| 2425 | |
| 2426 | p[-2] = '\0'; |
| 2427 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
| 2428 | read_specs (filename: new_filename ? new_filename : p1, main_p: false, user_p); |
| 2429 | continue; |
| 2430 | } |
| 2431 | else if (startswith (str: p1, prefix: "%include_noerr" ) |
| 2432 | && (p1[sizeof "%include_noerr" - 1] == ' ' |
| 2433 | || p1[sizeof "%include_noerr" - 1] == '\t')) |
| 2434 | { |
| 2435 | char *new_filename; |
| 2436 | |
| 2437 | p1 += sizeof "%include_noerr" ; |
| 2438 | while (*p1 == ' ' || *p1 == '\t') |
| 2439 | p1++; |
| 2440 | |
| 2441 | if (*p1++ != '<' || p[-2] != '>') |
| 2442 | fatal_error (input_location, |
| 2443 | "specs %%include syntax malformed after " |
| 2444 | "%td characters" , p1 - buffer + 1); |
| 2445 | |
| 2446 | p[-2] = '\0'; |
| 2447 | new_filename = find_a_file (&startfile_prefixes, p1, R_OK, true); |
| 2448 | if (new_filename) |
| 2449 | read_specs (filename: new_filename, main_p: false, user_p); |
| 2450 | else if (verbose_flag) |
| 2451 | fnotice (stderr, "could not find specs file %s\n" , p1); |
| 2452 | continue; |
| 2453 | } |
| 2454 | else if (startswith (str: p1, prefix: "%rename" ) |
| 2455 | && (p1[sizeof "%rename" - 1] == ' ' |
| 2456 | || p1[sizeof "%rename" - 1] == '\t')) |
| 2457 | { |
| 2458 | int name_len; |
| 2459 | struct spec_list *sl; |
| 2460 | struct spec_list *newsl; |
| 2461 | |
| 2462 | /* Get original name. */ |
| 2463 | p1 += sizeof "%rename" ; |
| 2464 | while (*p1 == ' ' || *p1 == '\t') |
| 2465 | p1++; |
| 2466 | |
| 2467 | if (! ISALPHA ((unsigned char) *p1)) |
| 2468 | fatal_error (input_location, |
| 2469 | "specs %%rename syntax malformed after " |
| 2470 | "%td characters" , p1 - buffer); |
| 2471 | |
| 2472 | p2 = p1; |
| 2473 | while (*p2 && !ISSPACE ((unsigned char) *p2)) |
| 2474 | p2++; |
| 2475 | |
| 2476 | if (*p2 != ' ' && *p2 != '\t') |
| 2477 | fatal_error (input_location, |
| 2478 | "specs %%rename syntax malformed after " |
| 2479 | "%td characters" , p2 - buffer); |
| 2480 | |
| 2481 | name_len = p2 - p1; |
| 2482 | *p2++ = '\0'; |
| 2483 | while (*p2 == ' ' || *p2 == '\t') |
| 2484 | p2++; |
| 2485 | |
| 2486 | if (! ISALPHA ((unsigned char) *p2)) |
| 2487 | fatal_error (input_location, |
| 2488 | "specs %%rename syntax malformed after " |
| 2489 | "%td characters" , p2 - buffer); |
| 2490 | |
| 2491 | /* Get new spec name. */ |
| 2492 | p3 = p2; |
| 2493 | while (*p3 && !ISSPACE ((unsigned char) *p3)) |
| 2494 | p3++; |
| 2495 | |
| 2496 | if (p3 != p - 1) |
| 2497 | fatal_error (input_location, |
| 2498 | "specs %%rename syntax malformed after " |
| 2499 | "%td characters" , p3 - buffer); |
| 2500 | *p3 = '\0'; |
| 2501 | |
| 2502 | for (sl = specs; sl; sl = sl->next) |
| 2503 | if (name_len == sl->name_len && !strcmp (s1: sl->name, s2: p1)) |
| 2504 | break; |
| 2505 | |
| 2506 | if (!sl) |
| 2507 | fatal_error (input_location, |
| 2508 | "specs %s spec was not found to be renamed" , p1); |
| 2509 | |
| 2510 | if (strcmp (s1: p1, s2: p2) == 0) |
| 2511 | continue; |
| 2512 | |
| 2513 | for (newsl = specs; newsl; newsl = newsl->next) |
| 2514 | if (strcmp (s1: newsl->name, s2: p2) == 0) |
| 2515 | fatal_error (input_location, |
| 2516 | "%s: attempt to rename spec %qs to " |
| 2517 | "already defined spec %qs" , |
| 2518 | filename, p1, p2); |
| 2519 | |
| 2520 | if (verbose_flag) |
| 2521 | { |
| 2522 | fnotice (stderr, "rename spec %s to %s\n" , p1, p2); |
| 2523 | #ifdef DEBUG_SPECS |
| 2524 | fnotice (stderr, "spec is '%s'\n\n" , *(sl->ptr_spec)); |
| 2525 | #endif |
| 2526 | } |
| 2527 | |
| 2528 | set_spec (name: p2, spec: *(sl->ptr_spec), user_p); |
| 2529 | if (sl->alloc_p) |
| 2530 | free (CONST_CAST (char *, *(sl->ptr_spec))); |
| 2531 | |
| 2532 | *(sl->ptr_spec) = "" ; |
| 2533 | sl->alloc_p = 0; |
| 2534 | continue; |
| 2535 | } |
| 2536 | else |
| 2537 | fatal_error (input_location, |
| 2538 | "specs unknown %% command after %td characters" , |
| 2539 | p1 - buffer); |
| 2540 | } |
| 2541 | |
| 2542 | /* Find the colon that should end the suffix. */ |
| 2543 | p1 = p; |
| 2544 | while (*p1 && *p1 != ':' && *p1 != '\n') |
| 2545 | p1++; |
| 2546 | |
| 2547 | /* The colon shouldn't be missing. */ |
| 2548 | if (*p1 != ':') |
| 2549 | fatal_error (input_location, |
| 2550 | "specs file malformed after %td characters" , |
| 2551 | p1 - buffer); |
| 2552 | |
| 2553 | /* Skip back over trailing whitespace. */ |
| 2554 | p2 = p1; |
| 2555 | while (p2 > buffer && (p2[-1] == ' ' || p2[-1] == '\t')) |
| 2556 | p2--; |
| 2557 | |
| 2558 | /* Copy the suffix to a string. */ |
| 2559 | suffix = save_string (p, p2 - p); |
| 2560 | /* Find the next line. */ |
| 2561 | p = skip_whitespace (p: p1 + 1); |
| 2562 | if (p[1] == 0) |
| 2563 | fatal_error (input_location, |
| 2564 | "specs file malformed after %td characters" , |
| 2565 | p - buffer); |
| 2566 | |
| 2567 | p1 = p; |
| 2568 | /* Find next blank line or end of string. */ |
| 2569 | while (*p1 && !(*p1 == '\n' && (p1[1] == '\n' || p1[1] == '\0'))) |
| 2570 | p1++; |
| 2571 | |
| 2572 | /* Specs end at the blank line and do not include the newline. */ |
| 2573 | spec = save_string (p, p1 - p); |
| 2574 | p = p1; |
| 2575 | |
| 2576 | /* Delete backslash-newline sequences from the spec. */ |
| 2577 | in = spec; |
| 2578 | out = spec; |
| 2579 | while (*in != 0) |
| 2580 | { |
| 2581 | if (in[0] == '\\' && in[1] == '\n') |
| 2582 | in += 2; |
| 2583 | else if (in[0] == '#') |
| 2584 | while (*in && *in != '\n') |
| 2585 | in++; |
| 2586 | |
| 2587 | else |
| 2588 | *out++ = *in++; |
| 2589 | } |
| 2590 | *out = 0; |
| 2591 | |
| 2592 | if (suffix[0] == '*') |
| 2593 | { |
| 2594 | if (! strcmp (s1: suffix, s2: "*link_command" )) |
| 2595 | link_command_spec = spec; |
| 2596 | else |
| 2597 | { |
| 2598 | set_spec (name: suffix + 1, spec, user_p); |
| 2599 | free (ptr: spec); |
| 2600 | } |
| 2601 | } |
| 2602 | else |
| 2603 | { |
| 2604 | /* Add this pair to the vector. */ |
| 2605 | compilers |
| 2606 | = XRESIZEVEC (struct compiler, compilers, n_compilers + 2); |
| 2607 | |
| 2608 | compilers[n_compilers].suffix = suffix; |
| 2609 | compilers[n_compilers].spec = spec; |
| 2610 | n_compilers++; |
| 2611 | memset (s: &compilers[n_compilers], c: 0, n: sizeof compilers[n_compilers]); |
| 2612 | } |
| 2613 | |
| 2614 | if (*suffix == 0) |
| 2615 | link_command_spec = spec; |
| 2616 | } |
| 2617 | |
| 2618 | if (link_command_spec == 0) |
| 2619 | fatal_error (input_location, "spec file has no spec for linking" ); |
| 2620 | |
| 2621 | XDELETEVEC (buffer); |
| 2622 | } |
| 2623 | |
| 2624 | /* Record the names of temporary files we tell compilers to write, |
| 2625 | and delete them at the end of the run. */ |
| 2626 | |
| 2627 | /* This is the common prefix we use to make temp file names. |
| 2628 | It is chosen once for each run of this program. |
| 2629 | It is substituted into a spec by %g or %j. |
| 2630 | Thus, all temp file names contain this prefix. |
| 2631 | In practice, all temp file names start with this prefix. |
| 2632 | |
| 2633 | This prefix comes from the envvar TMPDIR if it is defined; |
| 2634 | otherwise, from the P_tmpdir macro if that is defined; |
| 2635 | otherwise, in /usr/tmp or /tmp; |
| 2636 | or finally the current directory if all else fails. */ |
| 2637 | |
| 2638 | static const char *temp_filename; |
| 2639 | |
| 2640 | /* Length of the prefix. */ |
| 2641 | |
| 2642 | static int temp_filename_length; |
| 2643 | |
| 2644 | /* Define the list of temporary files to delete. */ |
| 2645 | |
| 2646 | struct temp_file |
| 2647 | { |
| 2648 | const char *name; |
| 2649 | struct temp_file *next; |
| 2650 | }; |
| 2651 | |
| 2652 | /* Queue of files to delete on success or failure of compilation. */ |
| 2653 | static struct temp_file *always_delete_queue; |
| 2654 | /* Queue of files to delete on failure of compilation. */ |
| 2655 | static struct temp_file *failure_delete_queue; |
| 2656 | |
| 2657 | /* Record FILENAME as a file to be deleted automatically. |
| 2658 | ALWAYS_DELETE nonzero means delete it if all compilation succeeds; |
| 2659 | otherwise delete it in any case. |
| 2660 | FAIL_DELETE nonzero means delete it if a compilation step fails; |
| 2661 | otherwise delete it in any case. */ |
| 2662 | |
| 2663 | void |
| 2664 | record_temp_file (const char *filename, int always_delete, int fail_delete) |
| 2665 | { |
| 2666 | char *const name = xstrdup (filename); |
| 2667 | |
| 2668 | if (always_delete) |
| 2669 | { |
| 2670 | struct temp_file *temp; |
| 2671 | for (temp = always_delete_queue; temp; temp = temp->next) |
| 2672 | if (! filename_cmp (s1: name, s2: temp->name)) |
| 2673 | { |
| 2674 | free (ptr: name); |
| 2675 | goto already1; |
| 2676 | } |
| 2677 | |
| 2678 | temp = XNEW (struct temp_file); |
| 2679 | temp->next = always_delete_queue; |
| 2680 | temp->name = name; |
| 2681 | always_delete_queue = temp; |
| 2682 | |
| 2683 | already1:; |
| 2684 | } |
| 2685 | |
| 2686 | if (fail_delete) |
| 2687 | { |
| 2688 | struct temp_file *temp; |
| 2689 | for (temp = failure_delete_queue; temp; temp = temp->next) |
| 2690 | if (! filename_cmp (s1: name, s2: temp->name)) |
| 2691 | { |
| 2692 | free (ptr: name); |
| 2693 | goto already2; |
| 2694 | } |
| 2695 | |
| 2696 | temp = XNEW (struct temp_file); |
| 2697 | temp->next = failure_delete_queue; |
| 2698 | temp->name = name; |
| 2699 | failure_delete_queue = temp; |
| 2700 | |
| 2701 | already2:; |
| 2702 | } |
| 2703 | } |
| 2704 | |
| 2705 | /* Delete all the temporary files whose names we previously recorded. */ |
| 2706 | |
| 2707 | #ifndef DELETE_IF_ORDINARY |
| 2708 | #define DELETE_IF_ORDINARY(NAME,ST,VERBOSE_FLAG) \ |
| 2709 | do \ |
| 2710 | { \ |
| 2711 | if (stat (NAME, &ST) >= 0 && S_ISREG (ST.st_mode)) \ |
| 2712 | if (unlink (NAME) < 0) \ |
| 2713 | if (VERBOSE_FLAG) \ |
| 2714 | error ("%s: %m", (NAME)); \ |
| 2715 | } while (0) |
| 2716 | #endif |
| 2717 | |
| 2718 | static void |
| 2719 | delete_if_ordinary (const char *name) |
| 2720 | { |
| 2721 | struct stat st; |
| 2722 | #ifdef DEBUG |
| 2723 | int i, c; |
| 2724 | |
| 2725 | printf ("Delete %s? (y or n) " , name); |
| 2726 | fflush (stdout); |
| 2727 | i = getchar (); |
| 2728 | if (i != '\n') |
| 2729 | while ((c = getchar ()) != '\n' && c != EOF) |
| 2730 | ; |
| 2731 | |
| 2732 | if (i == 'y' || i == 'Y') |
| 2733 | #endif /* DEBUG */ |
| 2734 | DELETE_IF_ORDINARY (name, st, verbose_flag); |
| 2735 | } |
| 2736 | |
| 2737 | static void |
| 2738 | delete_temp_files (void) |
| 2739 | { |
| 2740 | struct temp_file *temp; |
| 2741 | |
| 2742 | for (temp = always_delete_queue; temp; temp = temp->next) |
| 2743 | delete_if_ordinary (name: temp->name); |
| 2744 | always_delete_queue = 0; |
| 2745 | } |
| 2746 | |
| 2747 | /* Delete all the files to be deleted on error. */ |
| 2748 | |
| 2749 | static void |
| 2750 | delete_failure_queue (void) |
| 2751 | { |
| 2752 | struct temp_file *temp; |
| 2753 | |
| 2754 | for (temp = failure_delete_queue; temp; temp = temp->next) |
| 2755 | delete_if_ordinary (name: temp->name); |
| 2756 | } |
| 2757 | |
| 2758 | static void |
| 2759 | clear_failure_queue (void) |
| 2760 | { |
| 2761 | failure_delete_queue = 0; |
| 2762 | } |
| 2763 | |
| 2764 | /* Call CALLBACK for each path in PATHS, breaking out early if CALLBACK |
| 2765 | returns non-NULL. |
| 2766 | If DO_MULTI is true iterate over the paths twice, first with multilib |
| 2767 | suffix then without, otherwise iterate over the paths once without |
| 2768 | adding a multilib suffix. When DO_MULTI is true, some attempt is made |
| 2769 | to avoid visiting the same path twice, but we could do better. For |
| 2770 | instance, /usr/lib/../lib is considered different from /usr/lib. |
| 2771 | At least EXTRA_SPACE chars past the end of the path passed to |
| 2772 | CALLBACK are available for use by the callback. |
| 2773 | CALLBACK_INFO allows extra parameters to be passed to CALLBACK. |
| 2774 | |
| 2775 | Returns the value returned by CALLBACK. */ |
| 2776 | |
| 2777 | static void * |
| 2778 | for_each_path (const struct path_prefix *paths, |
| 2779 | bool do_multi, |
| 2780 | size_t , |
| 2781 | void *(*callback) (char *, void *), |
| 2782 | void *callback_info) |
| 2783 | { |
| 2784 | struct prefix_list *pl; |
| 2785 | const char *multi_dir = NULL; |
| 2786 | const char *multi_os_dir = NULL; |
| 2787 | const char *multiarch_suffix = NULL; |
| 2788 | const char *multi_suffix; |
| 2789 | const char *just_multi_suffix; |
| 2790 | char *path = NULL; |
| 2791 | void *ret = NULL; |
| 2792 | bool skip_multi_dir = false; |
| 2793 | bool skip_multi_os_dir = false; |
| 2794 | |
| 2795 | multi_suffix = machine_suffix; |
| 2796 | just_multi_suffix = just_machine_suffix; |
| 2797 | if (do_multi && multilib_dir && strcmp (s1: multilib_dir, s2: "." ) != 0) |
| 2798 | { |
| 2799 | multi_dir = concat (multilib_dir, dir_separator_str, NULL); |
| 2800 | multi_suffix = concat (multi_suffix, multi_dir, NULL); |
| 2801 | just_multi_suffix = concat (just_multi_suffix, multi_dir, NULL); |
| 2802 | } |
| 2803 | if (do_multi && multilib_os_dir && strcmp (s1: multilib_os_dir, s2: "." ) != 0) |
| 2804 | multi_os_dir = concat (multilib_os_dir, dir_separator_str, NULL); |
| 2805 | if (multiarch_dir) |
| 2806 | multiarch_suffix = concat (multiarch_dir, dir_separator_str, NULL); |
| 2807 | |
| 2808 | while (1) |
| 2809 | { |
| 2810 | size_t multi_dir_len = 0; |
| 2811 | size_t multi_os_dir_len = 0; |
| 2812 | size_t multiarch_len = 0; |
| 2813 | size_t suffix_len; |
| 2814 | size_t just_suffix_len; |
| 2815 | size_t len; |
| 2816 | |
| 2817 | if (multi_dir) |
| 2818 | multi_dir_len = strlen (s: multi_dir); |
| 2819 | if (multi_os_dir) |
| 2820 | multi_os_dir_len = strlen (s: multi_os_dir); |
| 2821 | if (multiarch_suffix) |
| 2822 | multiarch_len = strlen (s: multiarch_suffix); |
| 2823 | suffix_len = strlen (s: multi_suffix); |
| 2824 | just_suffix_len = strlen (s: just_multi_suffix); |
| 2825 | |
| 2826 | if (path == NULL) |
| 2827 | { |
| 2828 | len = paths->max_len + extra_space + 1; |
| 2829 | len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); |
| 2830 | path = XNEWVEC (char, len); |
| 2831 | } |
| 2832 | |
| 2833 | for (pl = paths->plist; pl != 0; pl = pl->next) |
| 2834 | { |
| 2835 | len = strlen (s: pl->prefix); |
| 2836 | memcpy (dest: path, src: pl->prefix, n: len); |
| 2837 | |
| 2838 | /* Look first in MACHINE/VERSION subdirectory. */ |
| 2839 | if (!skip_multi_dir) |
| 2840 | { |
| 2841 | memcpy (dest: path + len, src: multi_suffix, n: suffix_len + 1); |
| 2842 | ret = callback (path, callback_info); |
| 2843 | if (ret) |
| 2844 | break; |
| 2845 | } |
| 2846 | |
| 2847 | /* Some paths are tried with just the machine (ie. target) |
| 2848 | subdir. This is used for finding as, ld, etc. */ |
| 2849 | if (!skip_multi_dir |
| 2850 | && pl->require_machine_suffix == 2) |
| 2851 | { |
| 2852 | memcpy (dest: path + len, src: just_multi_suffix, n: just_suffix_len + 1); |
| 2853 | ret = callback (path, callback_info); |
| 2854 | if (ret) |
| 2855 | break; |
| 2856 | } |
| 2857 | |
| 2858 | /* Now try the multiarch path. */ |
| 2859 | if (!skip_multi_dir |
| 2860 | && !pl->require_machine_suffix && multiarch_dir) |
| 2861 | { |
| 2862 | memcpy (dest: path + len, src: multiarch_suffix, n: multiarch_len + 1); |
| 2863 | ret = callback (path, callback_info); |
| 2864 | if (ret) |
| 2865 | break; |
| 2866 | } |
| 2867 | |
| 2868 | /* Now try the base path. */ |
| 2869 | if (!pl->require_machine_suffix |
| 2870 | && !(pl->os_multilib ? skip_multi_os_dir : skip_multi_dir)) |
| 2871 | { |
| 2872 | const char *this_multi; |
| 2873 | size_t this_multi_len; |
| 2874 | |
| 2875 | if (pl->os_multilib) |
| 2876 | { |
| 2877 | this_multi = multi_os_dir; |
| 2878 | this_multi_len = multi_os_dir_len; |
| 2879 | } |
| 2880 | else |
| 2881 | { |
| 2882 | this_multi = multi_dir; |
| 2883 | this_multi_len = multi_dir_len; |
| 2884 | } |
| 2885 | |
| 2886 | if (this_multi_len) |
| 2887 | memcpy (dest: path + len, src: this_multi, n: this_multi_len + 1); |
| 2888 | else |
| 2889 | path[len] = '\0'; |
| 2890 | |
| 2891 | ret = callback (path, callback_info); |
| 2892 | if (ret) |
| 2893 | break; |
| 2894 | } |
| 2895 | } |
| 2896 | if (pl) |
| 2897 | break; |
| 2898 | |
| 2899 | if (multi_dir == NULL && multi_os_dir == NULL) |
| 2900 | break; |
| 2901 | |
| 2902 | /* Run through the paths again, this time without multilibs. |
| 2903 | Don't repeat any we have already seen. */ |
| 2904 | if (multi_dir) |
| 2905 | { |
| 2906 | free (CONST_CAST (char *, multi_dir)); |
| 2907 | multi_dir = NULL; |
| 2908 | free (CONST_CAST (char *, multi_suffix)); |
| 2909 | multi_suffix = machine_suffix; |
| 2910 | free (CONST_CAST (char *, just_multi_suffix)); |
| 2911 | just_multi_suffix = just_machine_suffix; |
| 2912 | } |
| 2913 | else |
| 2914 | skip_multi_dir = true; |
| 2915 | if (multi_os_dir) |
| 2916 | { |
| 2917 | free (CONST_CAST (char *, multi_os_dir)); |
| 2918 | multi_os_dir = NULL; |
| 2919 | } |
| 2920 | else |
| 2921 | skip_multi_os_dir = true; |
| 2922 | } |
| 2923 | |
| 2924 | if (multi_dir) |
| 2925 | { |
| 2926 | free (CONST_CAST (char *, multi_dir)); |
| 2927 | free (CONST_CAST (char *, multi_suffix)); |
| 2928 | free (CONST_CAST (char *, just_multi_suffix)); |
| 2929 | } |
| 2930 | if (multi_os_dir) |
| 2931 | free (CONST_CAST (char *, multi_os_dir)); |
| 2932 | if (ret != path) |
| 2933 | free (ptr: path); |
| 2934 | return ret; |
| 2935 | } |
| 2936 | |
| 2937 | /* Callback for build_search_list. Adds path to obstack being built. */ |
| 2938 | |
| 2939 | struct add_to_obstack_info { |
| 2940 | struct obstack *ob; |
| 2941 | bool check_dir; |
| 2942 | bool first_time; |
| 2943 | }; |
| 2944 | |
| 2945 | static void * |
| 2946 | add_to_obstack (char *path, void *data) |
| 2947 | { |
| 2948 | struct add_to_obstack_info *info = (struct add_to_obstack_info *) data; |
| 2949 | |
| 2950 | if (info->check_dir && !is_directory (path)) |
| 2951 | return NULL; |
| 2952 | |
| 2953 | if (!info->first_time) |
| 2954 | obstack_1grow (info->ob, PATH_SEPARATOR); |
| 2955 | |
| 2956 | obstack_grow (info->ob, path, strlen (path)); |
| 2957 | |
| 2958 | info->first_time = false; |
| 2959 | return NULL; |
| 2960 | } |
| 2961 | |
| 2962 | /* Add or change the value of an environment variable, outputting the |
| 2963 | change to standard error if in verbose mode. */ |
| 2964 | static void |
| 2965 | xputenv (const char *string) |
| 2966 | { |
| 2967 | env.xput (string); |
| 2968 | } |
| 2969 | |
| 2970 | /* Build a list of search directories from PATHS. |
| 2971 | PREFIX is a string to prepend to the list. |
| 2972 | If CHECK_DIR_P is true we ensure the directory exists. |
| 2973 | If DO_MULTI is true, multilib paths are output first, then |
| 2974 | non-multilib paths. |
| 2975 | This is used mostly by putenv_from_prefixes so we use `collect_obstack'. |
| 2976 | It is also used by the --print-search-dirs flag. */ |
| 2977 | |
| 2978 | static char * |
| 2979 | build_search_list (const struct path_prefix *paths, const char *prefix, |
| 2980 | bool check_dir, bool do_multi) |
| 2981 | { |
| 2982 | struct add_to_obstack_info info; |
| 2983 | |
| 2984 | info.ob = &collect_obstack; |
| 2985 | info.check_dir = check_dir; |
| 2986 | info.first_time = true; |
| 2987 | |
| 2988 | obstack_grow (&collect_obstack, prefix, strlen (prefix)); |
| 2989 | obstack_1grow (&collect_obstack, '='); |
| 2990 | |
| 2991 | for_each_path (paths, do_multi, extra_space: 0, callback: add_to_obstack, callback_info: &info); |
| 2992 | |
| 2993 | obstack_1grow (&collect_obstack, '\0'); |
| 2994 | return XOBFINISH (&collect_obstack, char *); |
| 2995 | } |
| 2996 | |
| 2997 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
| 2998 | for collect. */ |
| 2999 | |
| 3000 | static void |
| 3001 | putenv_from_prefixes (const struct path_prefix *paths, const char *env_var, |
| 3002 | bool do_multi) |
| 3003 | { |
| 3004 | xputenv (string: build_search_list (paths, prefix: env_var, check_dir: true, do_multi)); |
| 3005 | } |
| 3006 | |
| 3007 | /* Check whether NAME can be accessed in MODE. This is like access, |
| 3008 | except that it never considers directories to be executable. */ |
| 3009 | |
| 3010 | static int |
| 3011 | access_check (const char *name, int mode) |
| 3012 | { |
| 3013 | if (mode == X_OK) |
| 3014 | { |
| 3015 | struct stat st; |
| 3016 | |
| 3017 | if (stat (file: name, buf: &st) < 0 |
| 3018 | || S_ISDIR (st.st_mode)) |
| 3019 | return -1; |
| 3020 | } |
| 3021 | |
| 3022 | return access (name: name, type: mode); |
| 3023 | } |
| 3024 | |
| 3025 | /* Callback for find_a_file. Appends the file name to the directory |
| 3026 | path. If the resulting file exists in the right mode, return the |
| 3027 | full pathname to the file. */ |
| 3028 | |
| 3029 | struct file_at_path_info { |
| 3030 | const char *name; |
| 3031 | const char *suffix; |
| 3032 | int name_len; |
| 3033 | int suffix_len; |
| 3034 | int mode; |
| 3035 | }; |
| 3036 | |
| 3037 | static void * |
| 3038 | file_at_path (char *path, void *data) |
| 3039 | { |
| 3040 | struct file_at_path_info *info = (struct file_at_path_info *) data; |
| 3041 | size_t len = strlen (s: path); |
| 3042 | |
| 3043 | memcpy (dest: path + len, src: info->name, n: info->name_len); |
| 3044 | len += info->name_len; |
| 3045 | |
| 3046 | /* Some systems have a suffix for executable files. |
| 3047 | So try appending that first. */ |
| 3048 | if (info->suffix_len) |
| 3049 | { |
| 3050 | memcpy (dest: path + len, src: info->suffix, n: info->suffix_len + 1); |
| 3051 | if (access_check (name: path, mode: info->mode) == 0) |
| 3052 | return path; |
| 3053 | } |
| 3054 | |
| 3055 | path[len] = '\0'; |
| 3056 | if (access_check (name: path, mode: info->mode) == 0) |
| 3057 | return path; |
| 3058 | |
| 3059 | return NULL; |
| 3060 | } |
| 3061 | |
| 3062 | /* Search for NAME using the prefix list PREFIXES. MODE is passed to |
| 3063 | access to check permissions. If DO_MULTI is true, search multilib |
| 3064 | paths then non-multilib paths, otherwise do not search multilib paths. |
| 3065 | Return 0 if not found, otherwise return its name, allocated with malloc. */ |
| 3066 | |
| 3067 | static char * |
| 3068 | find_a_file (const struct path_prefix *pprefix, const char *name, int mode, |
| 3069 | bool do_multi) |
| 3070 | { |
| 3071 | struct file_at_path_info info; |
| 3072 | |
| 3073 | /* Find the filename in question (special case for absolute paths). */ |
| 3074 | |
| 3075 | if (IS_ABSOLUTE_PATH (name)) |
| 3076 | { |
| 3077 | if (access (name: name, type: mode) == 0) |
| 3078 | return xstrdup (name); |
| 3079 | |
| 3080 | return NULL; |
| 3081 | } |
| 3082 | |
| 3083 | info.name = name; |
| 3084 | info.suffix = (mode & X_OK) != 0 ? HOST_EXECUTABLE_SUFFIX : "" ; |
| 3085 | info.name_len = strlen (s: info.name); |
| 3086 | info.suffix_len = strlen (s: info.suffix); |
| 3087 | info.mode = mode; |
| 3088 | |
| 3089 | return (char*) for_each_path (paths: pprefix, do_multi, |
| 3090 | extra_space: info.name_len + info.suffix_len, |
| 3091 | callback: file_at_path, callback_info: &info); |
| 3092 | } |
| 3093 | |
| 3094 | /* Specialization of find_a_file for programs that also takes into account |
| 3095 | configure-specified default programs. */ |
| 3096 | |
| 3097 | static char* |
| 3098 | find_a_program (const char *name) |
| 3099 | { |
| 3100 | /* Do not search if default matches query. */ |
| 3101 | |
| 3102 | #ifdef DEFAULT_ASSEMBLER |
| 3103 | if (! strcmp (name, "as" ) && access (DEFAULT_ASSEMBLER, X_OK) == 0) |
| 3104 | return xstrdup (DEFAULT_ASSEMBLER); |
| 3105 | #endif |
| 3106 | |
| 3107 | #ifdef DEFAULT_LINKER |
| 3108 | if (! strcmp (name, "ld" ) && access (DEFAULT_LINKER, X_OK) == 0) |
| 3109 | return xstrdup (DEFAULT_LINKER); |
| 3110 | #endif |
| 3111 | |
| 3112 | #ifdef DEFAULT_DSYMUTIL |
| 3113 | if (! strcmp (name, "dsymutil" ) && access (DEFAULT_DSYMUTIL, X_OK) == 0) |
| 3114 | return xstrdup (DEFAULT_DSYMUTIL); |
| 3115 | #endif |
| 3116 | |
| 3117 | return find_a_file (pprefix: &exec_prefixes, name, X_OK, do_multi: false); |
| 3118 | } |
| 3119 | |
| 3120 | /* Ranking of prefixes in the sort list. -B prefixes are put before |
| 3121 | all others. */ |
| 3122 | |
| 3123 | enum path_prefix_priority |
| 3124 | { |
| 3125 | PREFIX_PRIORITY_B_OPT, |
| 3126 | PREFIX_PRIORITY_LAST |
| 3127 | }; |
| 3128 | |
| 3129 | /* Add an entry for PREFIX in PLIST. The PLIST is kept in ascending |
| 3130 | order according to PRIORITY. Within each PRIORITY, new entries are |
| 3131 | appended. |
| 3132 | |
| 3133 | If WARN is nonzero, we will warn if no file is found |
| 3134 | through this prefix. WARN should point to an int |
| 3135 | which will be set to 1 if this entry is used. |
| 3136 | |
| 3137 | COMPONENT is the value to be passed to update_path. |
| 3138 | |
| 3139 | REQUIRE_MACHINE_SUFFIX is 1 if this prefix can't be used without |
| 3140 | the complete value of machine_suffix. |
| 3141 | 2 means try both machine_suffix and just_machine_suffix. */ |
| 3142 | |
| 3143 | static void |
| 3144 | add_prefix (struct path_prefix *pprefix, const char *prefix, |
| 3145 | const char *component, /* enum prefix_priority */ int priority, |
| 3146 | int require_machine_suffix, int os_multilib) |
| 3147 | { |
| 3148 | struct prefix_list *pl, **prev; |
| 3149 | int len; |
| 3150 | |
| 3151 | for (prev = &pprefix->plist; |
| 3152 | (*prev) != NULL && (*prev)->priority <= priority; |
| 3153 | prev = &(*prev)->next) |
| 3154 | ; |
| 3155 | |
| 3156 | /* Keep track of the longest prefix. */ |
| 3157 | |
| 3158 | prefix = update_path (path: prefix, key: component); |
| 3159 | len = strlen (s: prefix); |
| 3160 | if (len > pprefix->max_len) |
| 3161 | pprefix->max_len = len; |
| 3162 | |
| 3163 | pl = XNEW (struct prefix_list); |
| 3164 | pl->prefix = prefix; |
| 3165 | pl->require_machine_suffix = require_machine_suffix; |
| 3166 | pl->priority = priority; |
| 3167 | pl->os_multilib = os_multilib; |
| 3168 | |
| 3169 | /* Insert after PREV. */ |
| 3170 | pl->next = (*prev); |
| 3171 | (*prev) = pl; |
| 3172 | } |
| 3173 | |
| 3174 | /* Same as add_prefix, but prepending target_system_root to prefix. */ |
| 3175 | /* The target_system_root prefix has been relocated by gcc_exec_prefix. */ |
| 3176 | static void |
| 3177 | add_sysrooted_prefix (struct path_prefix *pprefix, const char *prefix, |
| 3178 | const char *component, |
| 3179 | /* enum prefix_priority */ int priority, |
| 3180 | int require_machine_suffix, int os_multilib) |
| 3181 | { |
| 3182 | if (!IS_ABSOLUTE_PATH (prefix)) |
| 3183 | fatal_error (input_location, "system path %qs is not absolute" , prefix); |
| 3184 | |
| 3185 | if (target_system_root) |
| 3186 | { |
| 3187 | char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); |
| 3188 | size_t sysroot_len = strlen (s: target_system_root); |
| 3189 | |
| 3190 | if (sysroot_len > 0 |
| 3191 | && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) |
| 3192 | sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; |
| 3193 | |
| 3194 | if (target_sysroot_suffix) |
| 3195 | prefix = concat (sysroot_no_trailing_dir_separator, |
| 3196 | target_sysroot_suffix, prefix, NULL); |
| 3197 | else |
| 3198 | prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); |
| 3199 | |
| 3200 | free (ptr: sysroot_no_trailing_dir_separator); |
| 3201 | |
| 3202 | /* We have to override this because GCC's notion of sysroot |
| 3203 | moves along with GCC. */ |
| 3204 | component = "GCC" ; |
| 3205 | } |
| 3206 | |
| 3207 | add_prefix (pprefix, prefix, component, priority, |
| 3208 | require_machine_suffix, os_multilib); |
| 3209 | } |
| 3210 | |
| 3211 | /* Same as add_prefix, but prepending target_sysroot_hdrs_suffix to prefix. */ |
| 3212 | |
| 3213 | static void |
| 3214 | add_sysrooted_hdrs_prefix (struct path_prefix *pprefix, const char *prefix, |
| 3215 | const char *component, |
| 3216 | /* enum prefix_priority */ int priority, |
| 3217 | int require_machine_suffix, int os_multilib) |
| 3218 | { |
| 3219 | if (!IS_ABSOLUTE_PATH (prefix)) |
| 3220 | fatal_error (input_location, "system path %qs is not absolute" , prefix); |
| 3221 | |
| 3222 | if (target_system_root) |
| 3223 | { |
| 3224 | char *sysroot_no_trailing_dir_separator = xstrdup (target_system_root); |
| 3225 | size_t sysroot_len = strlen (s: target_system_root); |
| 3226 | |
| 3227 | if (sysroot_len > 0 |
| 3228 | && target_system_root[sysroot_len - 1] == DIR_SEPARATOR) |
| 3229 | sysroot_no_trailing_dir_separator[sysroot_len - 1] = '\0'; |
| 3230 | |
| 3231 | if (target_sysroot_hdrs_suffix) |
| 3232 | prefix = concat (sysroot_no_trailing_dir_separator, |
| 3233 | target_sysroot_hdrs_suffix, prefix, NULL); |
| 3234 | else |
| 3235 | prefix = concat (sysroot_no_trailing_dir_separator, prefix, NULL); |
| 3236 | |
| 3237 | free (ptr: sysroot_no_trailing_dir_separator); |
| 3238 | |
| 3239 | /* We have to override this because GCC's notion of sysroot |
| 3240 | moves along with GCC. */ |
| 3241 | component = "GCC" ; |
| 3242 | } |
| 3243 | |
| 3244 | add_prefix (pprefix, prefix, component, priority, |
| 3245 | require_machine_suffix, os_multilib); |
| 3246 | } |
| 3247 | |
| 3248 | |
| 3249 | /* Execute the command specified by the arguments on the current line of spec. |
| 3250 | When using pipes, this includes several piped-together commands |
| 3251 | with `|' between them. |
| 3252 | |
| 3253 | Return 0 if successful, -1 if failed. */ |
| 3254 | |
| 3255 | static int |
| 3256 | execute (void) |
| 3257 | { |
| 3258 | int i; |
| 3259 | int n_commands; /* # of command. */ |
| 3260 | char *string; |
| 3261 | struct pex_obj *pex; |
| 3262 | struct command |
| 3263 | { |
| 3264 | const char *prog; /* program name. */ |
| 3265 | const char **argv; /* vector of args. */ |
| 3266 | }; |
| 3267 | const char *arg; |
| 3268 | |
| 3269 | struct command *commands; /* each command buffer with above info. */ |
| 3270 | |
| 3271 | gcc_assert (!processing_spec_function); |
| 3272 | |
| 3273 | if (wrapper_string) |
| 3274 | { |
| 3275 | string = find_a_program (name: argbuf[0]); |
| 3276 | if (string) |
| 3277 | argbuf[0] = string; |
| 3278 | insert_wrapper (wrapper_string); |
| 3279 | } |
| 3280 | |
| 3281 | /* Count # of piped commands. */ |
| 3282 | for (n_commands = 1, i = 0; argbuf.iterate (ix: i, ptr: &arg); i++) |
| 3283 | if (strcmp (s1: arg, s2: "|" ) == 0) |
| 3284 | n_commands++; |
| 3285 | |
| 3286 | /* Get storage for each command. */ |
| 3287 | commands = XALLOCAVEC (struct command, n_commands); |
| 3288 | |
| 3289 | /* Split argbuf into its separate piped processes, |
| 3290 | and record info about each one. |
| 3291 | Also search for the programs that are to be run. */ |
| 3292 | |
| 3293 | argbuf.safe_push (obj: 0); |
| 3294 | |
| 3295 | commands[0].prog = argbuf[0]; /* first command. */ |
| 3296 | commands[0].argv = argbuf.address (); |
| 3297 | |
| 3298 | if (!wrapper_string) |
| 3299 | { |
| 3300 | string = find_a_program(name: commands[0].prog); |
| 3301 | if (string) |
| 3302 | commands[0].argv[0] = string; |
| 3303 | } |
| 3304 | |
| 3305 | for (n_commands = 1, i = 0; argbuf.iterate (ix: i, ptr: &arg); i++) |
| 3306 | if (arg && strcmp (s1: arg, s2: "|" ) == 0) |
| 3307 | { /* each command. */ |
| 3308 | #if defined (__MSDOS__) || defined (OS2) || defined (VMS) |
| 3309 | fatal_error (input_location, "%<-pipe%> not supported" ); |
| 3310 | #endif |
| 3311 | argbuf[i] = 0; /* Termination of command args. */ |
| 3312 | commands[n_commands].prog = argbuf[i + 1]; |
| 3313 | commands[n_commands].argv |
| 3314 | = &(argbuf.address ())[i + 1]; |
| 3315 | string = find_a_program(name: commands[n_commands].prog); |
| 3316 | if (string) |
| 3317 | commands[n_commands].argv[0] = string; |
| 3318 | n_commands++; |
| 3319 | } |
| 3320 | |
| 3321 | /* If -v, print what we are about to do, and maybe query. */ |
| 3322 | |
| 3323 | if (verbose_flag) |
| 3324 | { |
| 3325 | /* For help listings, put a blank line between sub-processes. */ |
| 3326 | if (print_help_list) |
| 3327 | fputc (c: '\n', stderr); |
| 3328 | |
| 3329 | /* Print each piped command as a separate line. */ |
| 3330 | for (i = 0; i < n_commands; i++) |
| 3331 | { |
| 3332 | const char *const *j; |
| 3333 | |
| 3334 | if (verbose_only_flag) |
| 3335 | { |
| 3336 | for (j = commands[i].argv; *j; j++) |
| 3337 | { |
| 3338 | const char *p; |
| 3339 | for (p = *j; *p; ++p) |
| 3340 | if (!ISALNUM ((unsigned char) *p) |
| 3341 | && *p != '_' && *p != '/' && *p != '-' && *p != '.') |
| 3342 | break; |
| 3343 | if (*p || !*j) |
| 3344 | { |
| 3345 | fprintf (stderr, format: " \"" ); |
| 3346 | for (p = *j; *p; ++p) |
| 3347 | { |
| 3348 | if (*p == '"' || *p == '\\' || *p == '$') |
| 3349 | fputc (c: '\\', stderr); |
| 3350 | fputc (c: *p, stderr); |
| 3351 | } |
| 3352 | fputc (c: '"', stderr); |
| 3353 | } |
| 3354 | /* If it's empty, print "". */ |
| 3355 | else if (!**j) |
| 3356 | fprintf (stderr, format: " \"\"" ); |
| 3357 | else |
| 3358 | fprintf (stderr, format: " %s" , *j); |
| 3359 | } |
| 3360 | } |
| 3361 | else |
| 3362 | for (j = commands[i].argv; *j; j++) |
| 3363 | /* If it's empty, print "". */ |
| 3364 | if (!**j) |
| 3365 | fprintf (stderr, format: " \"\"" ); |
| 3366 | else |
| 3367 | fprintf (stderr, format: " %s" , *j); |
| 3368 | |
| 3369 | /* Print a pipe symbol after all but the last command. */ |
| 3370 | if (i + 1 != n_commands) |
| 3371 | fprintf (stderr, format: " |" ); |
| 3372 | fprintf (stderr, format: "\n" ); |
| 3373 | } |
| 3374 | fflush (stderr); |
| 3375 | if (verbose_only_flag != 0) |
| 3376 | { |
| 3377 | /* verbose_only_flag should act as if the spec was |
| 3378 | executed, so increment execution_count before |
| 3379 | returning. This prevents spurious warnings about |
| 3380 | unused linker input files, etc. */ |
| 3381 | execution_count++; |
| 3382 | return 0; |
| 3383 | } |
| 3384 | #ifdef DEBUG |
| 3385 | fnotice (stderr, "\nGo ahead? (y or n) " ); |
| 3386 | fflush (stderr); |
| 3387 | i = getchar (); |
| 3388 | if (i != '\n') |
| 3389 | while (getchar () != '\n') |
| 3390 | ; |
| 3391 | |
| 3392 | if (i != 'y' && i != 'Y') |
| 3393 | return 0; |
| 3394 | #endif /* DEBUG */ |
| 3395 | } |
| 3396 | |
| 3397 | #ifdef ENABLE_VALGRIND_CHECKING |
| 3398 | /* Run the each command through valgrind. To simplify prepending the |
| 3399 | path to valgrind and the option "-q" (for quiet operation unless |
| 3400 | something triggers), we allocate a separate argv array. */ |
| 3401 | |
| 3402 | for (i = 0; i < n_commands; i++) |
| 3403 | { |
| 3404 | const char **argv; |
| 3405 | int argc; |
| 3406 | int j; |
| 3407 | |
| 3408 | for (argc = 0; commands[i].argv[argc] != NULL; argc++) |
| 3409 | ; |
| 3410 | |
| 3411 | argv = XALLOCAVEC (const char *, argc + 3); |
| 3412 | |
| 3413 | argv[0] = VALGRIND_PATH; |
| 3414 | argv[1] = "-q" ; |
| 3415 | for (j = 2; j < argc + 2; j++) |
| 3416 | argv[j] = commands[i].argv[j - 2]; |
| 3417 | argv[j] = NULL; |
| 3418 | |
| 3419 | commands[i].argv = argv; |
| 3420 | commands[i].prog = argv[0]; |
| 3421 | } |
| 3422 | #endif |
| 3423 | |
| 3424 | /* Run each piped subprocess. */ |
| 3425 | |
| 3426 | pex = pex_init (PEX_USE_PIPES | ((report_times || report_times_to_file) |
| 3427 | ? PEX_RECORD_TIMES : 0), |
| 3428 | pname: progname, tempbase: temp_filename); |
| 3429 | if (pex == NULL) |
| 3430 | fatal_error (input_location, "%<pex_init%> failed: %m" ); |
| 3431 | |
| 3432 | for (i = 0; i < n_commands; i++) |
| 3433 | { |
| 3434 | const char *errmsg; |
| 3435 | int err; |
| 3436 | const char *string = commands[i].argv[0]; |
| 3437 | |
| 3438 | errmsg = pex_run (obj: pex, |
| 3439 | flags: ((i + 1 == n_commands ? PEX_LAST : 0) |
| 3440 | | (string == commands[i].prog ? PEX_SEARCH : 0)), |
| 3441 | executable: string, CONST_CAST (char **, commands[i].argv), |
| 3442 | NULL, NULL, err: &err); |
| 3443 | if (errmsg != NULL) |
| 3444 | { |
| 3445 | errno = err; |
| 3446 | fatal_error (input_location, |
| 3447 | err ? G_("cannot execute %qs: %s: %m" ) |
| 3448 | : G_("cannot execute %qs: %s" ), |
| 3449 | string, errmsg); |
| 3450 | } |
| 3451 | |
| 3452 | if (i && string != commands[i].prog) |
| 3453 | free (CONST_CAST (char *, string)); |
| 3454 | } |
| 3455 | |
| 3456 | execution_count++; |
| 3457 | |
| 3458 | /* Wait for all the subprocesses to finish. */ |
| 3459 | |
| 3460 | { |
| 3461 | int *statuses; |
| 3462 | struct pex_time *times = NULL; |
| 3463 | int ret_code = 0; |
| 3464 | |
| 3465 | statuses = XALLOCAVEC (int, n_commands); |
| 3466 | if (!pex_get_status (pex, count: n_commands, vector: statuses)) |
| 3467 | fatal_error (input_location, "failed to get exit status: %m" ); |
| 3468 | |
| 3469 | if (report_times || report_times_to_file) |
| 3470 | { |
| 3471 | times = XALLOCAVEC (struct pex_time, n_commands); |
| 3472 | if (!pex_get_times (pex, count: n_commands, vector: times)) |
| 3473 | fatal_error (input_location, "failed to get process times: %m" ); |
| 3474 | } |
| 3475 | |
| 3476 | pex_free (pex); |
| 3477 | |
| 3478 | for (i = 0; i < n_commands; ++i) |
| 3479 | { |
| 3480 | int status = statuses[i]; |
| 3481 | |
| 3482 | if (WIFSIGNALED (status)) |
| 3483 | switch (WTERMSIG (status)) |
| 3484 | { |
| 3485 | case SIGINT: |
| 3486 | case SIGTERM: |
| 3487 | /* SIGQUIT and SIGKILL are not available on MinGW. */ |
| 3488 | #ifdef SIGQUIT |
| 3489 | case SIGQUIT: |
| 3490 | #endif |
| 3491 | #ifdef SIGKILL |
| 3492 | case SIGKILL: |
| 3493 | #endif |
| 3494 | /* The user (or environment) did something to the |
| 3495 | inferior. Making this an ICE confuses the user into |
| 3496 | thinking there's a compiler bug. Much more likely is |
| 3497 | the user or OOM killer nuked it. */ |
| 3498 | fatal_error (input_location, |
| 3499 | "%s signal terminated program %s" , |
| 3500 | strsignal (WTERMSIG (status)), |
| 3501 | commands[i].prog); |
| 3502 | break; |
| 3503 | |
| 3504 | #ifdef SIGPIPE |
| 3505 | case SIGPIPE: |
| 3506 | /* SIGPIPE is a special case. It happens in -pipe mode |
| 3507 | when the compiler dies before the preprocessor is |
| 3508 | done, or the assembler dies before the compiler is |
| 3509 | done. There's generally been an error already, and |
| 3510 | this is just fallout. So don't generate another |
| 3511 | error unless we would otherwise have succeeded. */ |
| 3512 | if (signal_count || greatest_status >= MIN_FATAL_STATUS) |
| 3513 | { |
| 3514 | signal_count++; |
| 3515 | ret_code = -1; |
| 3516 | break; |
| 3517 | } |
| 3518 | #endif |
| 3519 | /* FALLTHROUGH */ |
| 3520 | |
| 3521 | default: |
| 3522 | /* The inferior failed to catch the signal. */ |
| 3523 | internal_error_no_backtrace ("%s signal terminated program %s" , |
| 3524 | strsignal (WTERMSIG (status)), |
| 3525 | commands[i].prog); |
| 3526 | } |
| 3527 | else if (WIFEXITED (status) |
| 3528 | && WEXITSTATUS (status) >= MIN_FATAL_STATUS) |
| 3529 | { |
| 3530 | /* For ICEs in cc1, cc1obj, cc1plus see if it is |
| 3531 | reproducible or not. */ |
| 3532 | const char *p; |
| 3533 | if (flag_report_bug |
| 3534 | && WEXITSTATUS (status) == ICE_EXIT_CODE |
| 3535 | && i == 0 |
| 3536 | && (p = strrchr (s: commands[0].argv[0], DIR_SEPARATOR)) |
| 3537 | && startswith (str: p + 1, prefix: "cc1" )) |
| 3538 | try_generate_repro (argv: commands[0].argv); |
| 3539 | if (WEXITSTATUS (status) > greatest_status) |
| 3540 | greatest_status = WEXITSTATUS (status); |
| 3541 | ret_code = -1; |
| 3542 | } |
| 3543 | |
| 3544 | if (report_times || report_times_to_file) |
| 3545 | { |
| 3546 | struct pex_time *pt = ×[i]; |
| 3547 | double ut, st; |
| 3548 | |
| 3549 | ut = ((double) pt->user_seconds |
| 3550 | + (double) pt->user_microseconds / 1.0e6); |
| 3551 | st = ((double) pt->system_seconds |
| 3552 | + (double) pt->system_microseconds / 1.0e6); |
| 3553 | |
| 3554 | if (ut + st != 0) |
| 3555 | { |
| 3556 | if (report_times) |
| 3557 | fnotice (stderr, "# %s %.2f %.2f\n" , |
| 3558 | commands[i].prog, ut, st); |
| 3559 | |
| 3560 | if (report_times_to_file) |
| 3561 | { |
| 3562 | int c = 0; |
| 3563 | const char *const *j; |
| 3564 | |
| 3565 | fprintf (stream: report_times_to_file, format: "%g %g" , ut, st); |
| 3566 | |
| 3567 | for (j = &commands[i].prog; *j; j = &commands[i].argv[++c]) |
| 3568 | { |
| 3569 | const char *p; |
| 3570 | for (p = *j; *p; ++p) |
| 3571 | if (*p == '"' || *p == '\\' || *p == '$' |
| 3572 | || ISSPACE (*p)) |
| 3573 | break; |
| 3574 | |
| 3575 | if (*p) |
| 3576 | { |
| 3577 | fprintf (stream: report_times_to_file, format: " \"" ); |
| 3578 | for (p = *j; *p; ++p) |
| 3579 | { |
| 3580 | if (*p == '"' || *p == '\\' || *p == '$') |
| 3581 | fputc (c: '\\', stream: report_times_to_file); |
| 3582 | fputc (c: *p, stream: report_times_to_file); |
| 3583 | } |
| 3584 | fputc (c: '"', stream: report_times_to_file); |
| 3585 | } |
| 3586 | else |
| 3587 | fprintf (stream: report_times_to_file, format: " %s" , *j); |
| 3588 | } |
| 3589 | |
| 3590 | fputc (c: '\n', stream: report_times_to_file); |
| 3591 | } |
| 3592 | } |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | if (commands[0].argv[0] != commands[0].prog) |
| 3597 | free (CONST_CAST (char *, commands[0].argv[0])); |
| 3598 | |
| 3599 | return ret_code; |
| 3600 | } |
| 3601 | } |
| 3602 | |
| 3603 | static struct switchstr *switches; |
| 3604 | |
| 3605 | static int n_switches; |
| 3606 | |
| 3607 | static int n_switches_alloc; |
| 3608 | |
| 3609 | /* Set to zero if -fcompare-debug is disabled, positive if it's |
| 3610 | enabled and we're running the first compilation, negative if it's |
| 3611 | enabled and we're running the second compilation. For most of the |
| 3612 | time, it's in the range -1..1, but it can be temporarily set to 2 |
| 3613 | or 3 to indicate that the -fcompare-debug flags didn't come from |
| 3614 | the command-line, but rather from the GCC_COMPARE_DEBUG environment |
| 3615 | variable, until a synthesized -fcompare-debug flag is added to the |
| 3616 | command line. */ |
| 3617 | int compare_debug; |
| 3618 | |
| 3619 | /* Set to nonzero if we've seen the -fcompare-debug-second flag. */ |
| 3620 | int compare_debug_second; |
| 3621 | |
| 3622 | /* Set to the flags that should be passed to the second compilation in |
| 3623 | a -fcompare-debug compilation. */ |
| 3624 | const char *compare_debug_opt; |
| 3625 | |
| 3626 | static struct switchstr *switches_debug_check[2]; |
| 3627 | |
| 3628 | static int n_switches_debug_check[2]; |
| 3629 | |
| 3630 | static int n_switches_alloc_debug_check[2]; |
| 3631 | |
| 3632 | static char *debug_check_temp_file[2]; |
| 3633 | |
| 3634 | /* Language is one of three things: |
| 3635 | |
| 3636 | 1) The name of a real programming language. |
| 3637 | 2) NULL, indicating that no one has figured out |
| 3638 | what it is yet. |
| 3639 | 3) '*', indicating that the file should be passed |
| 3640 | to the linker. */ |
| 3641 | struct infile |
| 3642 | { |
| 3643 | const char *name; |
| 3644 | const char *language; |
| 3645 | struct compiler *incompiler; |
| 3646 | bool compiled; |
| 3647 | bool preprocessed; |
| 3648 | }; |
| 3649 | |
| 3650 | /* Also a vector of input files specified. */ |
| 3651 | |
| 3652 | static struct infile *infiles; |
| 3653 | |
| 3654 | int n_infiles; |
| 3655 | |
| 3656 | static int n_infiles_alloc; |
| 3657 | |
| 3658 | /* True if undefined environment variables encountered during spec processing |
| 3659 | are ok to ignore, typically when we're running for --help or --version. */ |
| 3660 | |
| 3661 | static bool spec_undefvar_allowed; |
| 3662 | |
| 3663 | /* True if multiple input files are being compiled to a single |
| 3664 | assembly file. */ |
| 3665 | |
| 3666 | static bool combine_inputs; |
| 3667 | |
| 3668 | /* This counts the number of libraries added by lang_specific_driver, so that |
| 3669 | we can tell if there were any user supplied any files or libraries. */ |
| 3670 | |
| 3671 | static int added_libraries; |
| 3672 | |
| 3673 | /* And a vector of corresponding output files is made up later. */ |
| 3674 | |
| 3675 | const char **outfiles; |
| 3676 | |
| 3677 | #if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
| 3678 | |
| 3679 | /* Convert NAME to a new name if it is the standard suffix. DO_EXE |
| 3680 | is true if we should look for an executable suffix. DO_OBJ |
| 3681 | is true if we should look for an object suffix. */ |
| 3682 | |
| 3683 | static const char * |
| 3684 | convert_filename (const char *name, int do_exe ATTRIBUTE_UNUSED, |
| 3685 | int do_obj ATTRIBUTE_UNUSED) |
| 3686 | { |
| 3687 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
| 3688 | int i; |
| 3689 | #endif |
| 3690 | int len; |
| 3691 | |
| 3692 | if (name == NULL) |
| 3693 | return NULL; |
| 3694 | |
| 3695 | len = strlen (name); |
| 3696 | |
| 3697 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
| 3698 | /* Convert x.o to x.obj if TARGET_OBJECT_SUFFIX is ".obj". */ |
| 3699 | if (do_obj && len > 2 |
| 3700 | && name[len - 2] == '.' |
| 3701 | && name[len - 1] == 'o') |
| 3702 | { |
| 3703 | obstack_grow (&obstack, name, len - 2); |
| 3704 | obstack_grow0 (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
| 3705 | name = XOBFINISH (&obstack, const char *); |
| 3706 | } |
| 3707 | #endif |
| 3708 | |
| 3709 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
| 3710 | /* If there is no filetype, make it the executable suffix (which includes |
| 3711 | the "."). But don't get confused if we have just "-o". */ |
| 3712 | if (! do_exe || TARGET_EXECUTABLE_SUFFIX[0] == 0 || not_actual_file_p (name)) |
| 3713 | return name; |
| 3714 | |
| 3715 | for (i = len - 1; i >= 0; i--) |
| 3716 | if (IS_DIR_SEPARATOR (name[i])) |
| 3717 | break; |
| 3718 | |
| 3719 | for (i++; i < len; i++) |
| 3720 | if (name[i] == '.') |
| 3721 | return name; |
| 3722 | |
| 3723 | obstack_grow (&obstack, name, len); |
| 3724 | obstack_grow0 (&obstack, TARGET_EXECUTABLE_SUFFIX, |
| 3725 | strlen (TARGET_EXECUTABLE_SUFFIX)); |
| 3726 | name = XOBFINISH (&obstack, const char *); |
| 3727 | #endif |
| 3728 | |
| 3729 | return name; |
| 3730 | } |
| 3731 | #endif |
| 3732 | |
| 3733 | /* Display the command line switches accepted by gcc. */ |
| 3734 | static void |
| 3735 | display_help (void) |
| 3736 | { |
| 3737 | printf (_("Usage: %s [options] file...\n" ), progname); |
| 3738 | fputs (_("Options:\n" ), stdout); |
| 3739 | |
| 3740 | fputs (_(" -pass-exit-codes Exit with highest error code from a phase.\n" ), stdout); |
| 3741 | fputs (_(" --help Display this information.\n" ), stdout); |
| 3742 | fputs (_(" --target-help Display target specific command line options " |
| 3743 | "(including assembler and linker options).\n" ), stdout); |
| 3744 | fputs (_(" --help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,...].\n" ), stdout); |
| 3745 | fputs (_(" Display specific types of command line options.\n" ), stdout); |
| 3746 | if (! verbose_flag) |
| 3747 | fputs (_(" (Use '-v --help' to display command line options of sub-processes).\n" ), stdout); |
| 3748 | fputs (_(" --version Display compiler version information.\n" ), stdout); |
| 3749 | fputs (_(" -dumpspecs Display all of the built in spec strings.\n" ), stdout); |
| 3750 | fputs (_(" -dumpversion Display the version of the compiler.\n" ), stdout); |
| 3751 | fputs (_(" -dumpmachine Display the compiler's target processor.\n" ), stdout); |
| 3752 | fputs (_(" -foffload=<targets> Specify offloading targets.\n" ), stdout); |
| 3753 | fputs (_(" -print-search-dirs Display the directories in the compiler's search path.\n" ), stdout); |
| 3754 | fputs (_(" -print-libgcc-file-name Display the name of the compiler's companion library.\n" ), stdout); |
| 3755 | fputs (_(" -print-file-name=<lib> Display the full path to library <lib>.\n" ), stdout); |
| 3756 | fputs (_(" -print-prog-name=<prog> Display the full path to compiler component <prog>.\n" ), stdout); |
| 3757 | fputs (_("\ |
| 3758 | -print-multiarch Display the target's normalized GNU triplet, used as\n\ |
| 3759 | a component in the library path.\n" ), stdout); |
| 3760 | fputs (_(" -print-multi-directory Display the root directory for versions of libgcc.\n" ), stdout); |
| 3761 | fputs (_("\ |
| 3762 | -print-multi-lib Display the mapping between command line options and\n\ |
| 3763 | multiple library search directories.\n" ), stdout); |
| 3764 | fputs (_(" -print-multi-os-directory Display the relative path to OS libraries.\n" ), stdout); |
| 3765 | fputs (_(" -print-sysroot Display the target libraries directory.\n" ), stdout); |
| 3766 | fputs (_(" -print-sysroot-headers-suffix Display the sysroot suffix used to find headers.\n" ), stdout); |
| 3767 | fputs (_(" -Wa,<options> Pass comma-separated <options> on to the assembler.\n" ), stdout); |
| 3768 | fputs (_(" -Wp,<options> Pass comma-separated <options> on to the preprocessor.\n" ), stdout); |
| 3769 | fputs (_(" -Wl,<options> Pass comma-separated <options> on to the linker.\n" ), stdout); |
| 3770 | fputs (_(" -Xassembler <arg> Pass <arg> on to the assembler.\n" ), stdout); |
| 3771 | fputs (_(" -Xpreprocessor <arg> Pass <arg> on to the preprocessor.\n" ), stdout); |
| 3772 | fputs (_(" -Xlinker <arg> Pass <arg> on to the linker.\n" ), stdout); |
| 3773 | fputs (_(" -save-temps Do not delete intermediate files.\n" ), stdout); |
| 3774 | fputs (_(" -save-temps=<arg> Do not delete intermediate files.\n" ), stdout); |
| 3775 | fputs (_("\ |
| 3776 | -no-canonical-prefixes Do not canonicalize paths when building relative\n\ |
| 3777 | prefixes to other gcc components.\n" ), stdout); |
| 3778 | fputs (_(" -pipe Use pipes rather than intermediate files.\n" ), stdout); |
| 3779 | fputs (_(" -time Time the execution of each subprocess.\n" ), stdout); |
| 3780 | fputs (_(" -specs=<file> Override built-in specs with the contents of <file>.\n" ), stdout); |
| 3781 | fputs (_(" -std=<standard> Assume that the input sources are for <standard>.\n" ), stdout); |
| 3782 | fputs (_("\ |
| 3783 | --sysroot=<directory> Use <directory> as the root directory for headers\n\ |
| 3784 | and libraries.\n" ), stdout); |
| 3785 | fputs (_(" -B <directory> Add <directory> to the compiler's search paths.\n" ), stdout); |
| 3786 | fputs (_(" -v Display the programs invoked by the compiler.\n" ), stdout); |
| 3787 | fputs (_(" -### Like -v but options quoted and commands not executed.\n" ), stdout); |
| 3788 | fputs (_(" -E Preprocess only; do not compile, assemble or link.\n" ), stdout); |
| 3789 | fputs (_(" -S Compile only; do not assemble or link.\n" ), stdout); |
| 3790 | fputs (_(" -c Compile and assemble, but do not link.\n" ), stdout); |
| 3791 | fputs (_(" -o <file> Place the output into <file>.\n" ), stdout); |
| 3792 | fputs (_(" -pie Create a dynamically linked position independent\n\ |
| 3793 | executable.\n" ), stdout); |
| 3794 | fputs (_(" -shared Create a shared library.\n" ), stdout); |
| 3795 | fputs (_("\ |
| 3796 | -x <language> Specify the language of the following input files.\n\ |
| 3797 | Permissible languages include: c c++ assembler none\n\ |
| 3798 | 'none' means revert to the default behavior of\n\ |
| 3799 | guessing the language based on the file's extension.\n\ |
| 3800 | " ), stdout); |
| 3801 | |
| 3802 | printf (_("\ |
| 3803 | \nOptions starting with -g, -f, -m, -O, -W, or --param are automatically\n\ |
| 3804 | passed on to the various sub-processes invoked by %s. In order to pass\n\ |
| 3805 | other options on to these processes the -W<letter> options must be used.\n\ |
| 3806 | " ), progname); |
| 3807 | |
| 3808 | /* The rest of the options are displayed by invocations of the various |
| 3809 | sub-processes. */ |
| 3810 | } |
| 3811 | |
| 3812 | static void |
| 3813 | add_preprocessor_option (const char *option, int len) |
| 3814 | { |
| 3815 | preprocessor_options.safe_push (obj: save_string (option, len)); |
| 3816 | } |
| 3817 | |
| 3818 | static void |
| 3819 | add_assembler_option (const char *option, int len) |
| 3820 | { |
| 3821 | assembler_options.safe_push (obj: save_string (option, len)); |
| 3822 | } |
| 3823 | |
| 3824 | static void |
| 3825 | add_linker_option (const char *option, int len) |
| 3826 | { |
| 3827 | linker_options.safe_push (obj: save_string (option, len)); |
| 3828 | } |
| 3829 | |
| 3830 | /* Allocate space for an input file in infiles. */ |
| 3831 | |
| 3832 | static void |
| 3833 | alloc_infile (void) |
| 3834 | { |
| 3835 | if (n_infiles_alloc == 0) |
| 3836 | { |
| 3837 | n_infiles_alloc = 16; |
| 3838 | infiles = XNEWVEC (struct infile, n_infiles_alloc); |
| 3839 | } |
| 3840 | else if (n_infiles_alloc == n_infiles) |
| 3841 | { |
| 3842 | n_infiles_alloc *= 2; |
| 3843 | infiles = XRESIZEVEC (struct infile, infiles, n_infiles_alloc); |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | /* Store an input file with the given NAME and LANGUAGE in |
| 3848 | infiles. */ |
| 3849 | |
| 3850 | static void |
| 3851 | add_infile (const char *name, const char *language) |
| 3852 | { |
| 3853 | alloc_infile (); |
| 3854 | infiles[n_infiles].name = name; |
| 3855 | infiles[n_infiles++].language = language; |
| 3856 | } |
| 3857 | |
| 3858 | /* Allocate space for a switch in switches. */ |
| 3859 | |
| 3860 | static void |
| 3861 | alloc_switch (void) |
| 3862 | { |
| 3863 | if (n_switches_alloc == 0) |
| 3864 | { |
| 3865 | n_switches_alloc = 16; |
| 3866 | switches = XNEWVEC (struct switchstr, n_switches_alloc); |
| 3867 | } |
| 3868 | else if (n_switches_alloc == n_switches) |
| 3869 | { |
| 3870 | n_switches_alloc *= 2; |
| 3871 | switches = XRESIZEVEC (struct switchstr, switches, n_switches_alloc); |
| 3872 | } |
| 3873 | } |
| 3874 | |
| 3875 | /* Save an option OPT with N_ARGS arguments in array ARGS, marking it |
| 3876 | as validated if VALIDATED and KNOWN if it is an internal switch. */ |
| 3877 | |
| 3878 | static void |
| 3879 | save_switch (const char *opt, size_t n_args, const char *const *args, |
| 3880 | bool validated, bool known) |
| 3881 | { |
| 3882 | alloc_switch (); |
| 3883 | switches[n_switches].part1 = opt + 1; |
| 3884 | if (n_args == 0) |
| 3885 | switches[n_switches].args = 0; |
| 3886 | else |
| 3887 | { |
| 3888 | switches[n_switches].args = XNEWVEC (const char *, n_args + 1); |
| 3889 | memcpy (dest: switches[n_switches].args, src: args, n: n_args * sizeof (const char *)); |
| 3890 | switches[n_switches].args[n_args] = NULL; |
| 3891 | } |
| 3892 | |
| 3893 | switches[n_switches].live_cond = 0; |
| 3894 | switches[n_switches].validated = validated; |
| 3895 | switches[n_switches].known = known; |
| 3896 | switches[n_switches].ordering = 0; |
| 3897 | n_switches++; |
| 3898 | } |
| 3899 | |
| 3900 | /* Set the SOURCE_DATE_EPOCH environment variable to the current time if it is |
| 3901 | not set already. */ |
| 3902 | |
| 3903 | static void |
| 3904 | set_source_date_epoch_envvar () |
| 3905 | { |
| 3906 | /* Array size is 21 = ceil(log_10(2^64)) + 1 to hold string representations |
| 3907 | of 64 bit integers. */ |
| 3908 | char source_date_epoch[21]; |
| 3909 | time_t tt; |
| 3910 | |
| 3911 | errno = 0; |
| 3912 | tt = time (NULL); |
| 3913 | if (tt < (time_t) 0 || errno != 0) |
| 3914 | tt = (time_t) 0; |
| 3915 | |
| 3916 | snprintf (s: source_date_epoch, maxlen: 21, format: "%llu" , (unsigned long long) tt); |
| 3917 | /* Using setenv instead of xputenv because we want the variable to remain |
| 3918 | after finalizing so that it's still set in the second run when using |
| 3919 | -fcompare-debug. */ |
| 3920 | setenv (name: "SOURCE_DATE_EPOCH" , value: source_date_epoch, replace: 0); |
| 3921 | } |
| 3922 | |
| 3923 | /* Handle an option DECODED that is unknown to the option-processing |
| 3924 | machinery. */ |
| 3925 | |
| 3926 | static bool |
| 3927 | driver_unknown_option_callback (const struct cl_decoded_option *decoded) |
| 3928 | { |
| 3929 | const char *opt = decoded->arg; |
| 3930 | if (opt[1] == 'W' && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-' |
| 3931 | && !(decoded->errors & CL_ERR_NEGATIVE)) |
| 3932 | { |
| 3933 | /* Leave unknown -Wno-* options for the compiler proper, to be |
| 3934 | diagnosed only if there are warnings. */ |
| 3935 | save_switch (opt: decoded->canonical_option[0], |
| 3936 | n_args: decoded->canonical_option_num_elements - 1, |
| 3937 | args: &decoded->canonical_option[1], validated: false, known: true); |
| 3938 | return false; |
| 3939 | } |
| 3940 | if (decoded->opt_index == OPT_SPECIAL_unknown) |
| 3941 | { |
| 3942 | /* Give it a chance to define it a spec file. */ |
| 3943 | save_switch (opt: decoded->canonical_option[0], |
| 3944 | n_args: decoded->canonical_option_num_elements - 1, |
| 3945 | args: &decoded->canonical_option[1], validated: false, known: false); |
| 3946 | return false; |
| 3947 | } |
| 3948 | else |
| 3949 | return true; |
| 3950 | } |
| 3951 | |
| 3952 | /* Handle an option DECODED that is not marked as CL_DRIVER. |
| 3953 | LANG_MASK will always be CL_DRIVER. */ |
| 3954 | |
| 3955 | static void |
| 3956 | driver_wrong_lang_callback (const struct cl_decoded_option *decoded, |
| 3957 | unsigned int lang_mask ATTRIBUTE_UNUSED) |
| 3958 | { |
| 3959 | /* At this point, non-driver options are accepted (and expected to |
| 3960 | be passed down by specs) unless marked to be rejected by the |
| 3961 | driver. Options to be rejected by the driver but accepted by the |
| 3962 | compilers proper are treated just like completely unknown |
| 3963 | options. */ |
| 3964 | const struct cl_option *option = &cl_options[decoded->opt_index]; |
| 3965 | |
| 3966 | if (option->cl_reject_driver) |
| 3967 | error ("unrecognized command-line option %qs" , |
| 3968 | decoded->orig_option_with_args_text); |
| 3969 | else |
| 3970 | save_switch (opt: decoded->canonical_option[0], |
| 3971 | n_args: decoded->canonical_option_num_elements - 1, |
| 3972 | args: &decoded->canonical_option[1], validated: false, known: true); |
| 3973 | } |
| 3974 | |
| 3975 | static const char *spec_lang = 0; |
| 3976 | static int last_language_n_infiles; |
| 3977 | |
| 3978 | |
| 3979 | /* Check that GCC is configured to support the offload target. */ |
| 3980 | |
| 3981 | static bool |
| 3982 | check_offload_target_name (const char *target, ptrdiff_t len) |
| 3983 | { |
| 3984 | const char *n, *c = OFFLOAD_TARGETS; |
| 3985 | while (c) |
| 3986 | { |
| 3987 | n = strchr (s: c, c: ','); |
| 3988 | if (n == NULL) |
| 3989 | n = strchr (s: c, c: '\0'); |
| 3990 | if (len == n - c && strncmp (s1: target, s2: c, n: n - c) == 0) |
| 3991 | break; |
| 3992 | c = *n ? n + 1 : NULL; |
| 3993 | } |
| 3994 | if (!c) |
| 3995 | { |
| 3996 | auto_vec<const char*> candidates; |
| 3997 | size_t olen = strlen (OFFLOAD_TARGETS) + 1; |
| 3998 | char *cand = XALLOCAVEC (char, olen); |
| 3999 | memcpy (dest: cand, OFFLOAD_TARGETS, n: olen); |
| 4000 | for (c = strtok (s: cand, delim: "," ); c; c = strtok (NULL, delim: "," )) |
| 4001 | candidates.safe_push (obj: c); |
| 4002 | candidates.safe_push (obj: "default" ); |
| 4003 | candidates.safe_push (obj: "disable" ); |
| 4004 | |
| 4005 | char *target2 = XALLOCAVEC (char, len + 1); |
| 4006 | memcpy (dest: target2, src: target, n: len); |
| 4007 | target2[len] = '\0'; |
| 4008 | |
| 4009 | error ("GCC is not configured to support %qs as %<-foffload=%> argument" , |
| 4010 | target2); |
| 4011 | |
| 4012 | char *s; |
| 4013 | const char *hint = candidates_list_and_hint (arg: target2, str&: s, candidates); |
| 4014 | if (hint) |
| 4015 | inform (UNKNOWN_LOCATION, |
| 4016 | "valid %<-foffload=%> arguments are: %s; " |
| 4017 | "did you mean %qs?" , s, hint); |
| 4018 | else |
| 4019 | inform (UNKNOWN_LOCATION, "valid %<-foffload=%> arguments are: %s" , s); |
| 4020 | XDELETEVEC (s); |
| 4021 | return false; |
| 4022 | } |
| 4023 | return true; |
| 4024 | } |
| 4025 | |
| 4026 | /* Sanity check for -foffload-options. */ |
| 4027 | |
| 4028 | static void |
| 4029 | check_foffload_target_names (const char *arg) |
| 4030 | { |
| 4031 | const char *cur, *next, *end; |
| 4032 | /* If option argument starts with '-' then no target is specified and we |
| 4033 | do not need to parse it. */ |
| 4034 | if (arg[0] == '-') |
| 4035 | return; |
| 4036 | end = strchr (s: arg, c: '='); |
| 4037 | if (end == NULL) |
| 4038 | { |
| 4039 | error ("%<=%>options missing after %<-foffload-options=%>target" ); |
| 4040 | return; |
| 4041 | } |
| 4042 | |
| 4043 | cur = arg; |
| 4044 | while (cur < end) |
| 4045 | { |
| 4046 | next = strchr (s: cur, c: ','); |
| 4047 | if (next == NULL) |
| 4048 | next = end; |
| 4049 | next = (next > end) ? end : next; |
| 4050 | |
| 4051 | /* Retain non-supported targets after printing an error as those will not |
| 4052 | be processed; each enabled target only processes its triplet. */ |
| 4053 | check_offload_target_name (target: cur, len: next - cur); |
| 4054 | cur = next + 1; |
| 4055 | } |
| 4056 | } |
| 4057 | |
| 4058 | /* Parse -foffload option argument. */ |
| 4059 | |
| 4060 | static void |
| 4061 | handle_foffload_option (const char *arg) |
| 4062 | { |
| 4063 | const char *c, *cur, *n, *next, *end; |
| 4064 | char *target; |
| 4065 | |
| 4066 | /* If option argument starts with '-' then no target is specified and we |
| 4067 | do not need to parse it. */ |
| 4068 | if (arg[0] == '-') |
| 4069 | return; |
| 4070 | |
| 4071 | end = strchr (s: arg, c: '='); |
| 4072 | if (end == NULL) |
| 4073 | end = strchr (s: arg, c: '\0'); |
| 4074 | cur = arg; |
| 4075 | |
| 4076 | while (cur < end) |
| 4077 | { |
| 4078 | next = strchr (s: cur, c: ','); |
| 4079 | if (next == NULL) |
| 4080 | next = end; |
| 4081 | next = (next > end) ? end : next; |
| 4082 | |
| 4083 | target = XNEWVEC (char, next - cur + 1); |
| 4084 | memcpy (dest: target, src: cur, n: next - cur); |
| 4085 | target[next - cur] = '\0'; |
| 4086 | |
| 4087 | /* Reset offloading list and continue. */ |
| 4088 | if (strcmp (s1: target, s2: "default" ) == 0) |
| 4089 | { |
| 4090 | free (ptr: offload_targets); |
| 4091 | offload_targets = NULL; |
| 4092 | goto next_item; |
| 4093 | } |
| 4094 | |
| 4095 | /* If 'disable' is passed to the option, clean the list of |
| 4096 | offload targets and return, even if more targets follow. |
| 4097 | Likewise if GCC is not configured to support that offload target. */ |
| 4098 | if (strcmp (s1: target, s2: "disable" ) == 0 |
| 4099 | || !check_offload_target_name (target, len: next - cur)) |
| 4100 | { |
| 4101 | free (ptr: offload_targets); |
| 4102 | offload_targets = xstrdup ("" ); |
| 4103 | return; |
| 4104 | } |
| 4105 | |
| 4106 | if (!offload_targets) |
| 4107 | { |
| 4108 | offload_targets = target; |
| 4109 | target = NULL; |
| 4110 | } |
| 4111 | else |
| 4112 | { |
| 4113 | /* Check that the target hasn't already presented in the list. */ |
| 4114 | c = offload_targets; |
| 4115 | do |
| 4116 | { |
| 4117 | n = strchr (s: c, c: ':'); |
| 4118 | if (n == NULL) |
| 4119 | n = strchr (s: c, c: '\0'); |
| 4120 | |
| 4121 | if (next - cur == n - c && strncmp (s1: c, s2: target, n: n - c) == 0) |
| 4122 | break; |
| 4123 | |
| 4124 | c = n + 1; |
| 4125 | } |
| 4126 | while (*n); |
| 4127 | |
| 4128 | /* If duplicate is not found, append the target to the list. */ |
| 4129 | if (c > n) |
| 4130 | { |
| 4131 | size_t offload_targets_len = strlen (s: offload_targets); |
| 4132 | offload_targets |
| 4133 | = XRESIZEVEC (char, offload_targets, |
| 4134 | offload_targets_len + 1 + next - cur + 1); |
| 4135 | offload_targets[offload_targets_len++] = ':'; |
| 4136 | memcpy (dest: offload_targets + offload_targets_len, src: target, n: next - cur + 1); |
| 4137 | } |
| 4138 | } |
| 4139 | next_item: |
| 4140 | cur = next + 1; |
| 4141 | XDELETEVEC (target); |
| 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | /* Forward certain options to offloading compilation. */ |
| 4146 | |
| 4147 | static void |
| 4148 | forward_offload_option (size_t opt_index, const char *arg, bool validated) |
| 4149 | { |
| 4150 | switch (opt_index) |
| 4151 | { |
| 4152 | case OPT_l: |
| 4153 | /* Use a '_GCC_' prefix and standard name ('-l_GCC_m' irrespective of the |
| 4154 | host's 'MATH_LIBRARY', for example), so that the 'mkoffload's can tell |
| 4155 | this has been synthesized here, and translate/drop as necessary. */ |
| 4156 | /* Note that certain libraries ('-lc', '-lgcc', '-lgomp', for example) |
| 4157 | are injected by default in offloading compilation, and therefore not |
| 4158 | forwarded here. */ |
| 4159 | /* GCC libraries. */ |
| 4160 | if (/* '-lgfortran' */ strcmp (s1: arg, s2: "gfortran" ) == 0 |
| 4161 | || /* '-lstdc++' */ strcmp (s1: arg, s2: "stdc++" ) == 0) |
| 4162 | save_switch (opt: concat ("-foffload-options=-l_GCC_" , arg, NULL), |
| 4163 | n_args: 0, NULL, validated, known: true); |
| 4164 | /* Other libraries. */ |
| 4165 | else |
| 4166 | { |
| 4167 | /* The case will need special consideration where on the host |
| 4168 | '!need_math', but for offloading compilation still need |
| 4169 | '-foffload-options=-l_GCC_m'. The problem is that we don't get |
| 4170 | here anything like '-lm', because it's not synthesized in |
| 4171 | 'gcc/fortran/gfortranspec.cc:lang_specific_driver', for example. |
| 4172 | Generally synthesizing '-foffload-options=-l_GCC_m' etc. in the |
| 4173 | language specific drivers is non-trivial, needs very careful |
| 4174 | review of their options handling. However, this issue is not |
| 4175 | actually relevant for the current set of supported host/offloading |
| 4176 | configurations. */ |
| 4177 | int need_math = (MATH_LIBRARY[0] != '\0'); |
| 4178 | if (/* '-lm' */ (need_math && strcmp (s1: arg, MATH_LIBRARY) == 0)) |
| 4179 | save_switch (opt: "-foffload-options=-l_GCC_m" , |
| 4180 | n_args: 0, NULL, validated, known: true); |
| 4181 | } |
| 4182 | break; |
| 4183 | default: |
| 4184 | gcc_unreachable (); |
| 4185 | } |
| 4186 | } |
| 4187 | |
| 4188 | /* Handle a driver option; arguments and return value as for |
| 4189 | handle_option. */ |
| 4190 | |
| 4191 | static bool |
| 4192 | driver_handle_option (struct gcc_options *opts, |
| 4193 | struct gcc_options *opts_set, |
| 4194 | const struct cl_decoded_option *decoded, |
| 4195 | unsigned int lang_mask ATTRIBUTE_UNUSED, int kind, |
| 4196 | location_t loc, |
| 4197 | const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED, |
| 4198 | diagnostic_context *dc, |
| 4199 | void (*) (void)) |
| 4200 | { |
| 4201 | size_t opt_index = decoded->opt_index; |
| 4202 | const char *arg = decoded->arg; |
| 4203 | const char *compare_debug_replacement_opt; |
| 4204 | int value = decoded->value; |
| 4205 | bool validated = false; |
| 4206 | bool do_save = true; |
| 4207 | |
| 4208 | gcc_assert (opts == &global_options); |
| 4209 | gcc_assert (opts_set == &global_options_set); |
| 4210 | gcc_assert (kind == DK_UNSPECIFIED); |
| 4211 | gcc_assert (loc == UNKNOWN_LOCATION); |
| 4212 | gcc_assert (dc == global_dc); |
| 4213 | |
| 4214 | switch (opt_index) |
| 4215 | { |
| 4216 | case OPT_dumpspecs: |
| 4217 | { |
| 4218 | struct spec_list *sl; |
| 4219 | init_spec (); |
| 4220 | for (sl = specs; sl; sl = sl->next) |
| 4221 | printf (format: "*%s:\n%s\n\n" , sl->name, *(sl->ptr_spec)); |
| 4222 | if (link_command_spec) |
| 4223 | printf (format: "*link_command:\n%s\n\n" , link_command_spec); |
| 4224 | exit (status: 0); |
| 4225 | } |
| 4226 | |
| 4227 | case OPT_dumpversion: |
| 4228 | printf (format: "%s\n" , spec_version); |
| 4229 | exit (status: 0); |
| 4230 | |
| 4231 | case OPT_dumpmachine: |
| 4232 | printf (format: "%s\n" , spec_machine); |
| 4233 | exit (status: 0); |
| 4234 | |
| 4235 | case OPT_dumpfullversion: |
| 4236 | printf ("%s\n" , BASEVER); |
| 4237 | exit (status: 0); |
| 4238 | |
| 4239 | case OPT__version: |
| 4240 | print_version = 1; |
| 4241 | |
| 4242 | /* CPP driver cannot obtain switch from cc1_options. */ |
| 4243 | if (is_cpp_driver) |
| 4244 | add_preprocessor_option (option: "--version" , len: strlen (s: "--version" )); |
| 4245 | add_assembler_option (option: "--version" , len: strlen (s: "--version" )); |
| 4246 | add_linker_option (option: "--version" , len: strlen (s: "--version" )); |
| 4247 | break; |
| 4248 | |
| 4249 | case OPT__completion_: |
| 4250 | validated = true; |
| 4251 | completion = decoded->arg; |
| 4252 | break; |
| 4253 | |
| 4254 | case OPT__help: |
| 4255 | print_help_list = 1; |
| 4256 | |
| 4257 | /* CPP driver cannot obtain switch from cc1_options. */ |
| 4258 | if (is_cpp_driver) |
| 4259 | add_preprocessor_option (option: "--help" , len: 6); |
| 4260 | add_assembler_option (option: "--help" , len: 6); |
| 4261 | add_linker_option (option: "--help" , len: 6); |
| 4262 | break; |
| 4263 | |
| 4264 | case OPT__help_: |
| 4265 | print_subprocess_help = 2; |
| 4266 | break; |
| 4267 | |
| 4268 | case OPT__target_help: |
| 4269 | print_subprocess_help = 1; |
| 4270 | |
| 4271 | /* CPP driver cannot obtain switch from cc1_options. */ |
| 4272 | if (is_cpp_driver) |
| 4273 | add_preprocessor_option (option: "--target-help" , len: 13); |
| 4274 | add_assembler_option (option: "--target-help" , len: 13); |
| 4275 | add_linker_option (option: "--target-help" , len: 13); |
| 4276 | break; |
| 4277 | |
| 4278 | case OPT__no_sysroot_suffix: |
| 4279 | case OPT_pass_exit_codes: |
| 4280 | case OPT_print_search_dirs: |
| 4281 | case OPT_print_file_name_: |
| 4282 | case OPT_print_prog_name_: |
| 4283 | case OPT_print_multi_lib: |
| 4284 | case OPT_print_multi_directory: |
| 4285 | case OPT_print_sysroot: |
| 4286 | case OPT_print_multi_os_directory: |
| 4287 | case OPT_print_multiarch: |
| 4288 | case OPT_print_sysroot_headers_suffix: |
| 4289 | case OPT_time: |
| 4290 | case OPT_wrapper: |
| 4291 | /* These options set the variables specified in common.opt |
| 4292 | automatically, and do not need to be saved for spec |
| 4293 | processing. */ |
| 4294 | do_save = false; |
| 4295 | break; |
| 4296 | |
| 4297 | case OPT_print_libgcc_file_name: |
| 4298 | print_file_name = "libgcc.a" ; |
| 4299 | do_save = false; |
| 4300 | break; |
| 4301 | |
| 4302 | case OPT_fuse_ld_bfd: |
| 4303 | use_ld = ".bfd" ; |
| 4304 | break; |
| 4305 | |
| 4306 | case OPT_fuse_ld_gold: |
| 4307 | use_ld = ".gold" ; |
| 4308 | break; |
| 4309 | |
| 4310 | case OPT_fuse_ld_mold: |
| 4311 | use_ld = ".mold" ; |
| 4312 | break; |
| 4313 | |
| 4314 | case OPT_fcompare_debug_second: |
| 4315 | compare_debug_second = 1; |
| 4316 | break; |
| 4317 | |
| 4318 | case OPT_fcompare_debug: |
| 4319 | switch (value) |
| 4320 | { |
| 4321 | case 0: |
| 4322 | compare_debug_replacement_opt = "-fcompare-debug=" ; |
| 4323 | arg = "" ; |
| 4324 | goto compare_debug_with_arg; |
| 4325 | |
| 4326 | case 1: |
| 4327 | compare_debug_replacement_opt = "-fcompare-debug=-gtoggle" ; |
| 4328 | arg = "-gtoggle" ; |
| 4329 | goto compare_debug_with_arg; |
| 4330 | |
| 4331 | default: |
| 4332 | gcc_unreachable (); |
| 4333 | } |
| 4334 | break; |
| 4335 | |
| 4336 | case OPT_fcompare_debug_: |
| 4337 | compare_debug_replacement_opt = decoded->canonical_option[0]; |
| 4338 | compare_debug_with_arg: |
| 4339 | gcc_assert (decoded->canonical_option_num_elements == 1); |
| 4340 | gcc_assert (arg != NULL); |
| 4341 | if (*arg) |
| 4342 | compare_debug = 1; |
| 4343 | else |
| 4344 | compare_debug = -1; |
| 4345 | if (compare_debug < 0) |
| 4346 | compare_debug_opt = NULL; |
| 4347 | else |
| 4348 | compare_debug_opt = arg; |
| 4349 | save_switch (opt: compare_debug_replacement_opt, n_args: 0, NULL, validated, known: true); |
| 4350 | set_source_date_epoch_envvar (); |
| 4351 | return true; |
| 4352 | |
| 4353 | case OPT_fdiagnostics_color_: |
| 4354 | diagnostic_color_init (context: dc, value); |
| 4355 | break; |
| 4356 | |
| 4357 | case OPT_fdiagnostics_urls_: |
| 4358 | diagnostic_urls_init (context: dc, value); |
| 4359 | break; |
| 4360 | |
| 4361 | case OPT_fdiagnostics_show_highlight_colors: |
| 4362 | dc->set_show_highlight_colors (value); |
| 4363 | break; |
| 4364 | |
| 4365 | case OPT_fdiagnostics_format_: |
| 4366 | { |
| 4367 | const char *basename = (opts->x_dump_base_name ? opts->x_dump_base_name |
| 4368 | : opts->x_main_input_basename); |
| 4369 | gcc_assert (dc); |
| 4370 | diagnostic_output_format_init (*dc, |
| 4371 | main_input_filename_: opts->x_main_input_filename, base_file_name: basename, |
| 4372 | (enum diagnostics_output_format)value, |
| 4373 | json_formatting: opts->x_flag_diagnostics_json_formatting); |
| 4374 | break; |
| 4375 | } |
| 4376 | |
| 4377 | case OPT_fdiagnostics_add_output_: |
| 4378 | handle_OPT_fdiagnostics_add_output_ (opts: *opts, dc&: *dc, arg, loc); |
| 4379 | break; |
| 4380 | |
| 4381 | case OPT_fdiagnostics_set_output_: |
| 4382 | handle_OPT_fdiagnostics_set_output_ (opts: *opts, dc&: *dc, arg, loc); |
| 4383 | break; |
| 4384 | |
| 4385 | case OPT_fdiagnostics_text_art_charset_: |
| 4386 | dc->set_text_art_charset ((enum diagnostic_text_art_charset)value); |
| 4387 | break; |
| 4388 | |
| 4389 | case OPT_Wa_: |
| 4390 | { |
| 4391 | int prev, j; |
| 4392 | /* Pass the rest of this option to the assembler. */ |
| 4393 | |
| 4394 | /* Split the argument at commas. */ |
| 4395 | prev = 0; |
| 4396 | for (j = 0; arg[j]; j++) |
| 4397 | if (arg[j] == ',') |
| 4398 | { |
| 4399 | add_assembler_option (option: arg + prev, len: j - prev); |
| 4400 | prev = j + 1; |
| 4401 | } |
| 4402 | |
| 4403 | /* Record the part after the last comma. */ |
| 4404 | add_assembler_option (option: arg + prev, len: j - prev); |
| 4405 | } |
| 4406 | do_save = false; |
| 4407 | break; |
| 4408 | |
| 4409 | case OPT_Wp_: |
| 4410 | { |
| 4411 | int prev, j; |
| 4412 | /* Pass the rest of this option to the preprocessor. */ |
| 4413 | |
| 4414 | /* Split the argument at commas. */ |
| 4415 | prev = 0; |
| 4416 | for (j = 0; arg[j]; j++) |
| 4417 | if (arg[j] == ',') |
| 4418 | { |
| 4419 | add_preprocessor_option (option: arg + prev, len: j - prev); |
| 4420 | prev = j + 1; |
| 4421 | } |
| 4422 | |
| 4423 | /* Record the part after the last comma. */ |
| 4424 | add_preprocessor_option (option: arg + prev, len: j - prev); |
| 4425 | } |
| 4426 | do_save = false; |
| 4427 | break; |
| 4428 | |
| 4429 | case OPT_Wl_: |
| 4430 | { |
| 4431 | int prev, j; |
| 4432 | /* Split the argument at commas. */ |
| 4433 | prev = 0; |
| 4434 | for (j = 0; arg[j]; j++) |
| 4435 | if (arg[j] == ',') |
| 4436 | { |
| 4437 | add_infile (name: save_string (arg + prev, j - prev), language: "*" ); |
| 4438 | prev = j + 1; |
| 4439 | } |
| 4440 | /* Record the part after the last comma. */ |
| 4441 | add_infile (name: arg + prev, language: "*" ); |
| 4442 | if (strcmp (s1: arg, s2: "-z,lazy" ) == 0 || strcmp (s1: arg, s2: "-z,norelro" ) == 0) |
| 4443 | avoid_linker_hardening_p = true; |
| 4444 | } |
| 4445 | do_save = false; |
| 4446 | break; |
| 4447 | |
| 4448 | case OPT_z: |
| 4449 | if (strcmp (s1: arg, s2: "lazy" ) == 0 || strcmp (s1: arg, s2: "norelro" ) == 0) |
| 4450 | avoid_linker_hardening_p = true; |
| 4451 | break; |
| 4452 | |
| 4453 | case OPT_Xlinker: |
| 4454 | add_infile (name: arg, language: "*" ); |
| 4455 | do_save = false; |
| 4456 | break; |
| 4457 | |
| 4458 | case OPT_Xpreprocessor: |
| 4459 | add_preprocessor_option (option: arg, len: strlen (s: arg)); |
| 4460 | do_save = false; |
| 4461 | break; |
| 4462 | |
| 4463 | case OPT_Xassembler: |
| 4464 | add_assembler_option (option: arg, len: strlen (s: arg)); |
| 4465 | do_save = false; |
| 4466 | break; |
| 4467 | |
| 4468 | case OPT_l: |
| 4469 | /* POSIX allows separation of -l and the lib arg; canonicalize |
| 4470 | by concatenating -l with its arg */ |
| 4471 | add_infile (name: concat ("-l" , arg, NULL), language: "*" ); |
| 4472 | |
| 4473 | /* Forward to offloading compilation '-l[...]' flags for standard, |
| 4474 | well-known libraries. */ |
| 4475 | /* Doing this processing here means that we don't get to see libraries |
| 4476 | injected via specs, such as '-lquadmath' injected via |
| 4477 | '[build]/[target]/libgfortran/libgfortran.spec'. However, this issue |
| 4478 | is not actually relevant for the current set of host/offloading |
| 4479 | configurations. */ |
| 4480 | if (ENABLE_OFFLOADING) |
| 4481 | forward_offload_option (opt_index, arg, validated); |
| 4482 | |
| 4483 | do_save = false; |
| 4484 | break; |
| 4485 | |
| 4486 | case OPT_L: |
| 4487 | /* Similarly, canonicalize -L for linkers that may not accept |
| 4488 | separate arguments. */ |
| 4489 | save_switch (opt: concat ("-L" , arg, NULL), n_args: 0, NULL, validated, known: true); |
| 4490 | return true; |
| 4491 | |
| 4492 | case OPT_F: |
| 4493 | /* Likewise -F. */ |
| 4494 | save_switch (opt: concat ("-F" , arg, NULL), n_args: 0, NULL, validated, known: true); |
| 4495 | return true; |
| 4496 | |
| 4497 | case OPT_save_temps: |
| 4498 | if (!save_temps_flag) |
| 4499 | save_temps_flag = SAVE_TEMPS_DUMP; |
| 4500 | validated = true; |
| 4501 | break; |
| 4502 | |
| 4503 | case OPT_save_temps_: |
| 4504 | if (strcmp (s1: arg, s2: "cwd" ) == 0) |
| 4505 | save_temps_flag = SAVE_TEMPS_CWD; |
| 4506 | else if (strcmp (s1: arg, s2: "obj" ) == 0 |
| 4507 | || strcmp (s1: arg, s2: "object" ) == 0) |
| 4508 | save_temps_flag = SAVE_TEMPS_OBJ; |
| 4509 | else |
| 4510 | fatal_error (input_location, "%qs is an unknown %<-save-temps%> option" , |
| 4511 | decoded->orig_option_with_args_text); |
| 4512 | save_temps_overrides_dumpdir = true; |
| 4513 | break; |
| 4514 | |
| 4515 | case OPT_dumpdir: |
| 4516 | free (ptr: dumpdir); |
| 4517 | dumpdir = xstrdup (arg); |
| 4518 | save_temps_overrides_dumpdir = false; |
| 4519 | break; |
| 4520 | |
| 4521 | case OPT_dumpbase: |
| 4522 | free (ptr: dumpbase); |
| 4523 | dumpbase = xstrdup (arg); |
| 4524 | break; |
| 4525 | |
| 4526 | case OPT_dumpbase_ext: |
| 4527 | free (ptr: dumpbase_ext); |
| 4528 | dumpbase_ext = xstrdup (arg); |
| 4529 | break; |
| 4530 | |
| 4531 | case OPT_no_canonical_prefixes: |
| 4532 | /* Already handled as a special case, so ignored here. */ |
| 4533 | do_save = false; |
| 4534 | break; |
| 4535 | |
| 4536 | case OPT_pipe: |
| 4537 | validated = true; |
| 4538 | /* These options set the variables specified in common.opt |
| 4539 | automatically, but do need to be saved for spec |
| 4540 | processing. */ |
| 4541 | break; |
| 4542 | |
| 4543 | case OPT_specs_: |
| 4544 | { |
| 4545 | struct user_specs *user = XNEW (struct user_specs); |
| 4546 | |
| 4547 | user->next = (struct user_specs *) 0; |
| 4548 | user->filename = arg; |
| 4549 | if (user_specs_tail) |
| 4550 | user_specs_tail->next = user; |
| 4551 | else |
| 4552 | user_specs_head = user; |
| 4553 | user_specs_tail = user; |
| 4554 | } |
| 4555 | validated = true; |
| 4556 | break; |
| 4557 | |
| 4558 | case OPT__sysroot_: |
| 4559 | target_system_root = arg; |
| 4560 | target_system_root_changed = 1; |
| 4561 | /* Saving this option is useful to let self-specs decide to |
| 4562 | provide a default one. */ |
| 4563 | do_save = true; |
| 4564 | validated = true; |
| 4565 | break; |
| 4566 | |
| 4567 | case OPT_time_: |
| 4568 | if (report_times_to_file) |
| 4569 | fclose (stream: report_times_to_file); |
| 4570 | report_times_to_file = fopen (filename: arg, modes: "a" ); |
| 4571 | do_save = false; |
| 4572 | break; |
| 4573 | |
| 4574 | case OPT_truncate: |
| 4575 | totruncate_file = arg; |
| 4576 | do_save = false; |
| 4577 | break; |
| 4578 | |
| 4579 | case OPT____: |
| 4580 | /* "-###" |
| 4581 | This is similar to -v except that there is no execution |
| 4582 | of the commands and the echoed arguments are quoted. It |
| 4583 | is intended for use in shell scripts to capture the |
| 4584 | driver-generated command line. */ |
| 4585 | verbose_only_flag++; |
| 4586 | verbose_flag = 1; |
| 4587 | do_save = false; |
| 4588 | break; |
| 4589 | |
| 4590 | case OPT_B: |
| 4591 | { |
| 4592 | size_t len = strlen (s: arg); |
| 4593 | |
| 4594 | /* Catch the case where the user has forgotten to append a |
| 4595 | directory separator to the path. Note, they may be using |
| 4596 | -B to add an executable name prefix, eg "i386-elf-", in |
| 4597 | order to distinguish between multiple installations of |
| 4598 | GCC in the same directory. Hence we must check to see |
| 4599 | if appending a directory separator actually makes a |
| 4600 | valid directory name. */ |
| 4601 | if (!IS_DIR_SEPARATOR (arg[len - 1]) |
| 4602 | && is_directory (arg)) |
| 4603 | { |
| 4604 | char *tmp = XNEWVEC (char, len + 2); |
| 4605 | strcpy (dest: tmp, src: arg); |
| 4606 | tmp[len] = DIR_SEPARATOR; |
| 4607 | tmp[++len] = 0; |
| 4608 | arg = tmp; |
| 4609 | } |
| 4610 | |
| 4611 | add_prefix (pprefix: &exec_prefixes, prefix: arg, NULL, |
| 4612 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
| 4613 | add_prefix (pprefix: &startfile_prefixes, prefix: arg, NULL, |
| 4614 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
| 4615 | add_prefix (pprefix: &include_prefixes, prefix: arg, NULL, |
| 4616 | priority: PREFIX_PRIORITY_B_OPT, require_machine_suffix: 0, os_multilib: 0); |
| 4617 | } |
| 4618 | validated = true; |
| 4619 | break; |
| 4620 | |
| 4621 | case OPT_E: |
| 4622 | have_E = true; |
| 4623 | break; |
| 4624 | |
| 4625 | case OPT_x: |
| 4626 | spec_lang = arg; |
| 4627 | if (!strcmp (s1: spec_lang, s2: "none" )) |
| 4628 | /* Suppress the warning if -xnone comes after the last input |
| 4629 | file, because alternate command interfaces like g++ might |
| 4630 | find it useful to place -xnone after each input file. */ |
| 4631 | spec_lang = 0; |
| 4632 | else |
| 4633 | last_language_n_infiles = n_infiles; |
| 4634 | do_save = false; |
| 4635 | break; |
| 4636 | |
| 4637 | case OPT_o: |
| 4638 | have_o = 1; |
| 4639 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) || defined(HAVE_TARGET_OBJECT_SUFFIX) |
| 4640 | arg = convert_filename (arg, ! have_c, 0); |
| 4641 | #endif |
| 4642 | output_file = arg; |
| 4643 | /* On some systems, ld cannot handle "-o" without a space. So |
| 4644 | split the option from its argument. */ |
| 4645 | save_switch (opt: "-o" , n_args: 1, args: &arg, validated, known: true); |
| 4646 | return true; |
| 4647 | |
| 4648 | case OPT_pie: |
| 4649 | #ifdef ENABLE_DEFAULT_PIE |
| 4650 | /* -pie is turned on by default. */ |
| 4651 | validated = true; |
| 4652 | #endif |
| 4653 | /* FALLTHROUGH */ |
| 4654 | case OPT_r: |
| 4655 | case OPT_shared: |
| 4656 | case OPT_no_pie: |
| 4657 | avoid_linker_hardening_p = true; |
| 4658 | break; |
| 4659 | |
| 4660 | case OPT_static: |
| 4661 | static_p = true; |
| 4662 | break; |
| 4663 | |
| 4664 | case OPT_static_libgcc: |
| 4665 | case OPT_shared_libgcc: |
| 4666 | case OPT_static_libgfortran: |
| 4667 | case OPT_static_libquadmath: |
| 4668 | case OPT_static_libphobos: |
| 4669 | case OPT_static_libgm2: |
| 4670 | case OPT_static_libstdc__: |
| 4671 | /* These are always valid; gcc.cc itself understands the first two |
| 4672 | gfortranspec.cc understands -static-libgfortran, |
| 4673 | libgfortran.spec handles -static-libquadmath, |
| 4674 | d-spec.cc understands -static-libphobos, |
| 4675 | gm2spec.cc understands -static-libgm2, |
| 4676 | and g++spec.cc understands -static-libstdc++. */ |
| 4677 | validated = true; |
| 4678 | break; |
| 4679 | |
| 4680 | case OPT_fwpa: |
| 4681 | flag_wpa = "" ; |
| 4682 | break; |
| 4683 | |
| 4684 | case OPT_foffload_options_: |
| 4685 | check_foffload_target_names (arg); |
| 4686 | break; |
| 4687 | |
| 4688 | case OPT_foffload_: |
| 4689 | handle_foffload_option (arg); |
| 4690 | if (arg[0] == '-' || NULL != strchr (s: arg, c: '=')) |
| 4691 | save_switch (opt: concat ("-foffload-options=" , arg, NULL), |
| 4692 | n_args: 0, NULL, validated, known: true); |
| 4693 | do_save = false; |
| 4694 | break; |
| 4695 | |
| 4696 | case OPT_gcodeview: |
| 4697 | add_infile (name: "--pdb=" , language: "*" ); |
| 4698 | break; |
| 4699 | |
| 4700 | default: |
| 4701 | /* Various driver options need no special processing at this |
| 4702 | point, having been handled in a prescan above or being |
| 4703 | handled by specs. */ |
| 4704 | break; |
| 4705 | } |
| 4706 | |
| 4707 | if (do_save) |
| 4708 | save_switch (opt: decoded->canonical_option[0], |
| 4709 | n_args: decoded->canonical_option_num_elements - 1, |
| 4710 | args: &decoded->canonical_option[1], validated, known: true); |
| 4711 | return true; |
| 4712 | } |
| 4713 | |
| 4714 | /* Return true if F2 is F1 followed by a single suffix, i.e., by a |
| 4715 | period and additional characters other than a period. */ |
| 4716 | |
| 4717 | static inline bool |
| 4718 | adds_single_suffix_p (const char *f2, const char *f1) |
| 4719 | { |
| 4720 | size_t len = strlen (s: f1); |
| 4721 | |
| 4722 | return (strncmp (s1: f1, s2: f2, n: len) == 0 |
| 4723 | && f2[len] == '.' |
| 4724 | && strchr (s: f2 + len + 1, c: '.') == NULL); |
| 4725 | } |
| 4726 | |
| 4727 | /* Put the driver's standard set of option handlers in *HANDLERS. */ |
| 4728 | |
| 4729 | static void |
| 4730 | set_option_handlers (struct cl_option_handlers *handlers) |
| 4731 | { |
| 4732 | handlers->unknown_option_callback = driver_unknown_option_callback; |
| 4733 | handlers->wrong_lang_callback = driver_wrong_lang_callback; |
| 4734 | handlers->num_handlers = 3; |
| 4735 | handlers->handlers[0].handler = driver_handle_option; |
| 4736 | handlers->handlers[0].mask = CL_DRIVER; |
| 4737 | handlers->handlers[1].handler = common_handle_option; |
| 4738 | handlers->handlers[1].mask = CL_COMMON; |
| 4739 | handlers->handlers[2].handler = target_handle_option; |
| 4740 | handlers->handlers[2].mask = CL_TARGET; |
| 4741 | } |
| 4742 | |
| 4743 | |
| 4744 | /* Return the index into infiles for the single non-library |
| 4745 | non-lto-wpa input file, -1 if there isn't any, or -2 if there is |
| 4746 | more than one. */ |
| 4747 | static inline int |
| 4748 | single_input_file_index () |
| 4749 | { |
| 4750 | int ret = -1; |
| 4751 | |
| 4752 | for (int i = 0; i < n_infiles; i++) |
| 4753 | { |
| 4754 | if (infiles[i].language |
| 4755 | && (infiles[i].language[0] == '*' |
| 4756 | || (flag_wpa |
| 4757 | && strcmp (s1: infiles[i].language, s2: "lto" ) == 0))) |
| 4758 | continue; |
| 4759 | |
| 4760 | if (ret != -1) |
| 4761 | return -2; |
| 4762 | |
| 4763 | ret = i; |
| 4764 | } |
| 4765 | |
| 4766 | return ret; |
| 4767 | } |
| 4768 | |
| 4769 | /* Create the vector `switches' and its contents. |
| 4770 | Store its length in `n_switches'. */ |
| 4771 | |
| 4772 | static void |
| 4773 | process_command (unsigned int decoded_options_count, |
| 4774 | struct cl_decoded_option *decoded_options) |
| 4775 | { |
| 4776 | const char *temp; |
| 4777 | char *temp1; |
| 4778 | char *tooldir_prefix, *tooldir_prefix2; |
| 4779 | char *(*get_relative_prefix) (const char *, const char *, |
| 4780 | const char *) = NULL; |
| 4781 | struct cl_option_handlers handlers; |
| 4782 | unsigned int j; |
| 4783 | |
| 4784 | gcc_exec_prefix = env.get (name: "GCC_EXEC_PREFIX" ); |
| 4785 | |
| 4786 | n_switches = 0; |
| 4787 | n_infiles = 0; |
| 4788 | added_libraries = 0; |
| 4789 | |
| 4790 | /* Figure compiler version from version string. */ |
| 4791 | |
| 4792 | compiler_version = temp1 = xstrdup (version_string); |
| 4793 | |
| 4794 | for (; *temp1; ++temp1) |
| 4795 | { |
| 4796 | if (*temp1 == ' ') |
| 4797 | { |
| 4798 | *temp1 = '\0'; |
| 4799 | break; |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | /* Handle any -no-canonical-prefixes flag early, to assign the function |
| 4804 | that builds relative prefixes. This function creates default search |
| 4805 | paths that are needed later in normal option handling. */ |
| 4806 | |
| 4807 | for (j = 1; j < decoded_options_count; j++) |
| 4808 | { |
| 4809 | if (decoded_options[j].opt_index == OPT_no_canonical_prefixes) |
| 4810 | { |
| 4811 | get_relative_prefix = make_relative_prefix_ignore_links; |
| 4812 | break; |
| 4813 | } |
| 4814 | } |
| 4815 | if (! get_relative_prefix) |
| 4816 | get_relative_prefix = make_relative_prefix; |
| 4817 | |
| 4818 | /* Set up the default search paths. If there is no GCC_EXEC_PREFIX, |
| 4819 | see if we can create it from the pathname specified in |
| 4820 | decoded_options[0].arg. */ |
| 4821 | |
| 4822 | gcc_libexec_prefix = standard_libexec_prefix; |
| 4823 | #ifndef VMS |
| 4824 | /* FIXME: make_relative_prefix doesn't yet work for VMS. */ |
| 4825 | if (!gcc_exec_prefix) |
| 4826 | { |
| 4827 | gcc_exec_prefix = get_relative_prefix (decoded_options[0].arg, |
| 4828 | standard_bindir_prefix, |
| 4829 | standard_exec_prefix); |
| 4830 | gcc_libexec_prefix = get_relative_prefix (decoded_options[0].arg, |
| 4831 | standard_bindir_prefix, |
| 4832 | standard_libexec_prefix); |
| 4833 | if (gcc_exec_prefix) |
| 4834 | xputenv (string: concat ("GCC_EXEC_PREFIX=" , gcc_exec_prefix, NULL)); |
| 4835 | } |
| 4836 | else |
| 4837 | { |
| 4838 | /* make_relative_prefix requires a program name, but |
| 4839 | GCC_EXEC_PREFIX is typically a directory name with a trailing |
| 4840 | / (which is ignored by make_relative_prefix), so append a |
| 4841 | program name. */ |
| 4842 | char *tmp_prefix = concat (gcc_exec_prefix, "gcc" , NULL); |
| 4843 | gcc_libexec_prefix = get_relative_prefix (tmp_prefix, |
| 4844 | standard_exec_prefix, |
| 4845 | standard_libexec_prefix); |
| 4846 | |
| 4847 | /* The path is unrelocated, so fallback to the original setting. */ |
| 4848 | if (!gcc_libexec_prefix) |
| 4849 | gcc_libexec_prefix = standard_libexec_prefix; |
| 4850 | |
| 4851 | free (ptr: tmp_prefix); |
| 4852 | } |
| 4853 | #else |
| 4854 | #endif |
| 4855 | /* From this point onward, gcc_exec_prefix is non-null if the toolchain |
| 4856 | is relocated. The toolchain was either relocated using GCC_EXEC_PREFIX |
| 4857 | or an automatically created GCC_EXEC_PREFIX from |
| 4858 | decoded_options[0].arg. */ |
| 4859 | |
| 4860 | /* Do language-specific adjustment/addition of flags. */ |
| 4861 | lang_specific_driver (&decoded_options, &decoded_options_count, |
| 4862 | &added_libraries); |
| 4863 | |
| 4864 | if (gcc_exec_prefix) |
| 4865 | { |
| 4866 | int len = strlen (s: gcc_exec_prefix); |
| 4867 | |
| 4868 | if (len > (int) sizeof ("/lib/gcc/" ) - 1 |
| 4869 | && (IS_DIR_SEPARATOR (gcc_exec_prefix[len-1]))) |
| 4870 | { |
| 4871 | temp = gcc_exec_prefix + len - sizeof ("/lib/gcc/" ) + 1; |
| 4872 | if (IS_DIR_SEPARATOR (*temp) |
| 4873 | && filename_ncmp (s1: temp + 1, s2: "lib" , n: 3) == 0 |
| 4874 | && IS_DIR_SEPARATOR (temp[4]) |
| 4875 | && filename_ncmp (s1: temp + 5, s2: "gcc" , n: 3) == 0) |
| 4876 | len -= sizeof ("/lib/gcc/" ) - 1; |
| 4877 | } |
| 4878 | |
| 4879 | set_std_prefix (gcc_exec_prefix, len); |
| 4880 | add_prefix (pprefix: &exec_prefixes, prefix: gcc_libexec_prefix, component: "GCC" , |
| 4881 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 4882 | add_prefix (pprefix: &startfile_prefixes, prefix: gcc_exec_prefix, component: "GCC" , |
| 4883 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 4884 | } |
| 4885 | |
| 4886 | /* COMPILER_PATH and LIBRARY_PATH have values |
| 4887 | that are lists of directory names with colons. */ |
| 4888 | |
| 4889 | temp = env.get (name: "COMPILER_PATH" ); |
| 4890 | if (temp) |
| 4891 | { |
| 4892 | const char *startp, *endp; |
| 4893 | char *nstore = (char *) alloca (strlen (temp) + 3); |
| 4894 | |
| 4895 | startp = endp = temp; |
| 4896 | while (1) |
| 4897 | { |
| 4898 | if (*endp == PATH_SEPARATOR || *endp == 0) |
| 4899 | { |
| 4900 | strncpy (dest: nstore, src: startp, n: endp - startp); |
| 4901 | if (endp == startp) |
| 4902 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
| 4903 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
| 4904 | { |
| 4905 | nstore[endp - startp] = DIR_SEPARATOR; |
| 4906 | nstore[endp - startp + 1] = 0; |
| 4907 | } |
| 4908 | else |
| 4909 | nstore[endp - startp] = 0; |
| 4910 | add_prefix (pprefix: &exec_prefixes, prefix: nstore, component: 0, |
| 4911 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 4912 | add_prefix (pprefix: &include_prefixes, prefix: nstore, component: 0, |
| 4913 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 4914 | if (*endp == 0) |
| 4915 | break; |
| 4916 | endp = startp = endp + 1; |
| 4917 | } |
| 4918 | else |
| 4919 | endp++; |
| 4920 | } |
| 4921 | } |
| 4922 | |
| 4923 | temp = env.get (LIBRARY_PATH_ENV); |
| 4924 | if (temp && *cross_compile == '0') |
| 4925 | { |
| 4926 | const char *startp, *endp; |
| 4927 | char *nstore = (char *) alloca (strlen (temp) + 3); |
| 4928 | |
| 4929 | startp = endp = temp; |
| 4930 | while (1) |
| 4931 | { |
| 4932 | if (*endp == PATH_SEPARATOR || *endp == 0) |
| 4933 | { |
| 4934 | strncpy (dest: nstore, src: startp, n: endp - startp); |
| 4935 | if (endp == startp) |
| 4936 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
| 4937 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
| 4938 | { |
| 4939 | nstore[endp - startp] = DIR_SEPARATOR; |
| 4940 | nstore[endp - startp + 1] = 0; |
| 4941 | } |
| 4942 | else |
| 4943 | nstore[endp - startp] = 0; |
| 4944 | add_prefix (pprefix: &startfile_prefixes, prefix: nstore, NULL, |
| 4945 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 4946 | if (*endp == 0) |
| 4947 | break; |
| 4948 | endp = startp = endp + 1; |
| 4949 | } |
| 4950 | else |
| 4951 | endp++; |
| 4952 | } |
| 4953 | } |
| 4954 | |
| 4955 | /* Use LPATH like LIBRARY_PATH (for the CMU build program). */ |
| 4956 | temp = env.get (name: "LPATH" ); |
| 4957 | if (temp && *cross_compile == '0') |
| 4958 | { |
| 4959 | const char *startp, *endp; |
| 4960 | char *nstore = (char *) alloca (strlen (temp) + 3); |
| 4961 | |
| 4962 | startp = endp = temp; |
| 4963 | while (1) |
| 4964 | { |
| 4965 | if (*endp == PATH_SEPARATOR || *endp == 0) |
| 4966 | { |
| 4967 | strncpy (dest: nstore, src: startp, n: endp - startp); |
| 4968 | if (endp == startp) |
| 4969 | strcpy (dest: nstore, src: concat ("." , dir_separator_str, NULL)); |
| 4970 | else if (!IS_DIR_SEPARATOR (endp[-1])) |
| 4971 | { |
| 4972 | nstore[endp - startp] = DIR_SEPARATOR; |
| 4973 | nstore[endp - startp + 1] = 0; |
| 4974 | } |
| 4975 | else |
| 4976 | nstore[endp - startp] = 0; |
| 4977 | add_prefix (pprefix: &startfile_prefixes, prefix: nstore, NULL, |
| 4978 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 4979 | if (*endp == 0) |
| 4980 | break; |
| 4981 | endp = startp = endp + 1; |
| 4982 | } |
| 4983 | else |
| 4984 | endp++; |
| 4985 | } |
| 4986 | } |
| 4987 | |
| 4988 | /* Process the options and store input files and switches in their |
| 4989 | vectors. */ |
| 4990 | |
| 4991 | last_language_n_infiles = -1; |
| 4992 | |
| 4993 | set_option_handlers (&handlers); |
| 4994 | |
| 4995 | for (j = 1; j < decoded_options_count; j++) |
| 4996 | { |
| 4997 | switch (decoded_options[j].opt_index) |
| 4998 | { |
| 4999 | case OPT_S: |
| 5000 | case OPT_c: |
| 5001 | case OPT_E: |
| 5002 | have_c = 1; |
| 5003 | break; |
| 5004 | } |
| 5005 | if (have_c) |
| 5006 | break; |
| 5007 | } |
| 5008 | |
| 5009 | for (j = 1; j < decoded_options_count; j++) |
| 5010 | { |
| 5011 | if (decoded_options[j].opt_index == OPT_SPECIAL_input_file) |
| 5012 | { |
| 5013 | const char *arg = decoded_options[j].arg; |
| 5014 | |
| 5015 | #ifdef HAVE_TARGET_OBJECT_SUFFIX |
| 5016 | arg = convert_filename (arg, 0, access (arg, F_OK)); |
| 5017 | #endif |
| 5018 | add_infile (name: arg, language: spec_lang); |
| 5019 | |
| 5020 | continue; |
| 5021 | } |
| 5022 | |
| 5023 | read_cmdline_option (opts: &global_options, opts_set: &global_options_set, |
| 5024 | decoded: decoded_options + j, UNKNOWN_LOCATION, |
| 5025 | CL_DRIVER, handlers: &handlers, dc: global_dc); |
| 5026 | } |
| 5027 | |
| 5028 | /* If the user didn't specify any, default to all configured offload |
| 5029 | targets. */ |
| 5030 | if (ENABLE_OFFLOADING && offload_targets == NULL) |
| 5031 | { |
| 5032 | handle_foffload_option (OFFLOAD_TARGETS); |
| 5033 | #if OFFLOAD_DEFAULTED |
| 5034 | offload_targets_default = true; |
| 5035 | #endif |
| 5036 | } |
| 5037 | |
| 5038 | /* TODO: check if -static -pie works and maybe use it. */ |
| 5039 | if (flag_hardened) |
| 5040 | { |
| 5041 | if (!avoid_linker_hardening_p && !static_p) |
| 5042 | { |
| 5043 | #if defined HAVE_LD_PIE && defined LD_PIE_SPEC |
| 5044 | save_switch (LD_PIE_SPEC, n_args: 0, NULL, /*validated=*/true, /*known=*/false); |
| 5045 | #endif |
| 5046 | /* These are passed straight down to collect2 so we have to break |
| 5047 | it up like this. */ |
| 5048 | if (HAVE_LD_NOW_SUPPORT) |
| 5049 | { |
| 5050 | add_infile (name: "-z" , language: "*" ); |
| 5051 | add_infile (name: "now" , language: "*" ); |
| 5052 | } |
| 5053 | if (HAVE_LD_RELRO_SUPPORT) |
| 5054 | { |
| 5055 | add_infile (name: "-z" , language: "*" ); |
| 5056 | add_infile (name: "relro" , language: "*" ); |
| 5057 | } |
| 5058 | } |
| 5059 | /* We can't use OPT_Whardened yet. Sigh. */ |
| 5060 | else |
| 5061 | warning_at (UNKNOWN_LOCATION, 0, |
| 5062 | "linker hardening options not enabled by %<-fhardened%> " |
| 5063 | "because other link options were specified on the command " |
| 5064 | "line" ); |
| 5065 | } |
| 5066 | |
| 5067 | /* Handle -gtoggle as it would later in toplev.cc:process_options to |
| 5068 | make the debug-level-gt spec function work as expected. */ |
| 5069 | if (flag_gtoggle) |
| 5070 | { |
| 5071 | if (debug_info_level == DINFO_LEVEL_NONE) |
| 5072 | debug_info_level = DINFO_LEVEL_NORMAL; |
| 5073 | else |
| 5074 | debug_info_level = DINFO_LEVEL_NONE; |
| 5075 | } |
| 5076 | |
| 5077 | if (output_file |
| 5078 | && strcmp (s1: output_file, s2: "-" ) != 0 |
| 5079 | && strcmp (s1: output_file, HOST_BIT_BUCKET) != 0) |
| 5080 | { |
| 5081 | int i; |
| 5082 | for (i = 0; i < n_infiles; i++) |
| 5083 | if ((!infiles[i].language || infiles[i].language[0] != '*') |
| 5084 | && canonical_filename_eq (a: infiles[i].name, b: output_file)) |
| 5085 | fatal_error (input_location, |
| 5086 | "input file %qs is the same as output file" , |
| 5087 | output_file); |
| 5088 | } |
| 5089 | |
| 5090 | if (output_file != NULL && output_file[0] == '\0') |
| 5091 | fatal_error (input_location, "output filename may not be empty" ); |
| 5092 | |
| 5093 | /* -dumpdir and -save-temps=* both specify the location of aux/dump |
| 5094 | outputs; the one that appears last prevails. When compiling |
| 5095 | multiple sources, an explicit dumpbase (minus -ext) may be |
| 5096 | combined with an explicit or implicit dumpdir, whereas when |
| 5097 | linking, a specified or implied link output name (minus |
| 5098 | extension) may be combined with a prevailing -save-temps=* or an |
| 5099 | otherwise implied dumpdir, but not override a prevailing |
| 5100 | -dumpdir. Primary outputs (e.g., linker output when linking |
| 5101 | without -o, or .i, .s or .o outputs when processing multiple |
| 5102 | inputs with -E, -S or -c, respectively) are NOT affected by these |
| 5103 | -save-temps=/-dump* options, always landing in the current |
| 5104 | directory and with the same basename as the input when an output |
| 5105 | name is not given, but when they're intermediate outputs, they |
| 5106 | are named like other aux outputs, so the options affect their |
| 5107 | location and name. |
| 5108 | |
| 5109 | Here are some examples. There are several more in the |
| 5110 | documentation of -o and -dump*, and some quite exhaustive tests |
| 5111 | in gcc.misc-tests/outputs.exp. |
| 5112 | |
| 5113 | When compiling any number of sources, no -dump* nor |
| 5114 | -save-temps=*, all outputs in cwd without prefix: |
| 5115 | |
| 5116 | # gcc -c b.c -gsplit-dwarf |
| 5117 | -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo |
| 5118 | |
| 5119 | # gcc -c b.c d.c -gsplit-dwarf |
| 5120 | -> cc1 [-dumpdir ./] -dumpbase b.c -dumpbase-ext .c # b.o b.dwo |
| 5121 | && cc1 [-dumpdir ./] -dumpbase d.c -dumpbase-ext .c # d.o d.dwo |
| 5122 | |
| 5123 | When compiling and linking, no -dump* nor -save-temps=*, .o |
| 5124 | outputs are temporary, aux outputs land in the dir of the output, |
| 5125 | prefixed with the basename of the linker output: |
| 5126 | |
| 5127 | # gcc b.c d.c -o ab -gsplit-dwarf |
| 5128 | -> cc1 -dumpdir ab- -dumpbase b.c -dumpbase-ext .c # ab-b.dwo |
| 5129 | && cc1 -dumpdir ab- -dumpbase d.c -dumpbase-ext .c # ab-d.dwo |
| 5130 | && link ... -o ab |
| 5131 | |
| 5132 | # gcc b.c d.c [-o a.out] -gsplit-dwarf |
| 5133 | -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.dwo |
| 5134 | && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.dwo |
| 5135 | && link ... [-o a.out] |
| 5136 | |
| 5137 | When compiling and linking, a prevailing -dumpdir fully overrides |
| 5138 | the prefix of aux outputs given by the output name: |
| 5139 | |
| 5140 | # gcc -dumpdir f b.c d.c -gsplit-dwarf [-o [dir/]whatever] |
| 5141 | -> cc1 -dumpdir f -dumpbase b.c -dumpbase-ext .c # fb.dwo |
| 5142 | && cc1 -dumpdir f -dumpbase d.c -dumpbase-ext .c # fd.dwo |
| 5143 | && link ... [-o whatever] |
| 5144 | |
| 5145 | When compiling multiple inputs, an explicit -dumpbase is combined |
| 5146 | with -dumpdir, affecting aux outputs, but not the .o outputs: |
| 5147 | |
| 5148 | # gcc -dumpdir f -dumpbase g- b.c d.c -gsplit-dwarf -c |
| 5149 | -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # b.o fg-b.dwo |
| 5150 | && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # d.o fg-d.dwo |
| 5151 | |
| 5152 | When compiling and linking with -save-temps, the .o outputs that |
| 5153 | would have been temporary become aux outputs, so they get |
| 5154 | affected by -dump* flags: |
| 5155 | |
| 5156 | # gcc -dumpdir f -dumpbase g- -save-temps b.c d.c |
| 5157 | -> cc1 -dumpdir fg- -dumpbase b.c -dumpbase-ext .c # fg-b.o |
| 5158 | && cc1 -dumpdir fg- -dumpbase d.c -dumpbase-ext .c # fg-d.o |
| 5159 | && link |
| 5160 | |
| 5161 | If -save-temps=* prevails over -dumpdir, however, the explicit |
| 5162 | -dumpdir is discarded, as if it wasn't there. The basename of |
| 5163 | the implicit linker output, a.out or a.exe, becomes a- as the aux |
| 5164 | output prefix for all compilations: |
| 5165 | |
| 5166 | # gcc [-dumpdir f] -save-temps=cwd b.c d.c |
| 5167 | -> cc1 -dumpdir a- -dumpbase b.c -dumpbase-ext .c # a-b.o |
| 5168 | && cc1 -dumpdir a- -dumpbase d.c -dumpbase-ext .c # a-d.o |
| 5169 | && link |
| 5170 | |
| 5171 | A single -dumpbase, applying to multiple inputs, overrides the |
| 5172 | linker output name, implied or explicit, as the aux output prefix: |
| 5173 | |
| 5174 | # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c |
| 5175 | -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o |
| 5176 | && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o |
| 5177 | && link |
| 5178 | |
| 5179 | # gcc [-dumpdir f] -dumpbase g- -save-temps=cwd b.c d.c -o dir/h.out |
| 5180 | -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o |
| 5181 | && cc1 -dumpdir g- -dumpbase d.c -dumpbase-ext .c # g-d.o |
| 5182 | && link -o dir/h.out |
| 5183 | |
| 5184 | Now, if the linker output is NOT overridden as a prefix, but |
| 5185 | -save-temps=* overrides implicit or explicit -dumpdir, the |
| 5186 | effective dump dir combines the dir selected by the -save-temps=* |
| 5187 | option with the basename of the specified or implied link output: |
| 5188 | |
| 5189 | # gcc [-dumpdir f] -save-temps=cwd b.c d.c -o dir/h.out |
| 5190 | -> cc1 -dumpdir h- -dumpbase b.c -dumpbase-ext .c # h-b.o |
| 5191 | && cc1 -dumpdir h- -dumpbase d.c -dumpbase-ext .c # h-d.o |
| 5192 | && link -o dir/h.out |
| 5193 | |
| 5194 | # gcc [-dumpdir f] -save-temps=obj b.c d.c -o dir/h.out |
| 5195 | -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o |
| 5196 | && cc1 -dumpdir dir/h- -dumpbase d.c -dumpbase-ext .c # dir/h-d.o |
| 5197 | && link -o dir/h.out |
| 5198 | |
| 5199 | But then again, a single -dumpbase applying to multiple inputs |
| 5200 | gets used instead of the linker output basename in the combined |
| 5201 | dumpdir: |
| 5202 | |
| 5203 | # gcc [-dumpdir f] -dumpbase g- -save-temps=obj b.c d.c -o dir/h.out |
| 5204 | -> cc1 -dumpdir dir/g- -dumpbase b.c -dumpbase-ext .c # dir/g-b.o |
| 5205 | && cc1 -dumpdir dir/g- -dumpbase d.c -dumpbase-ext .c # dir/g-d.o |
| 5206 | && link -o dir/h.out |
| 5207 | |
| 5208 | With a single input being compiled, the output basename does NOT |
| 5209 | affect the dumpdir prefix. |
| 5210 | |
| 5211 | # gcc -save-temps=obj b.c -gsplit-dwarf -c -o dir/b.o |
| 5212 | -> cc1 -dumpdir dir/ -dumpbase b.c -dumpbase-ext .c # dir/b.o dir/b.dwo |
| 5213 | |
| 5214 | but when compiling and linking even a single file, it does: |
| 5215 | |
| 5216 | # gcc -save-temps=obj b.c -o dir/h.out |
| 5217 | -> cc1 -dumpdir dir/h- -dumpbase b.c -dumpbase-ext .c # dir/h-b.o |
| 5218 | |
| 5219 | unless an explicit -dumpdir prevails: |
| 5220 | |
| 5221 | # gcc -save-temps[=obj] -dumpdir g- b.c -o dir/h.out |
| 5222 | -> cc1 -dumpdir g- -dumpbase b.c -dumpbase-ext .c # g-b.o |
| 5223 | |
| 5224 | */ |
| 5225 | |
| 5226 | bool explicit_dumpdir = dumpdir; |
| 5227 | |
| 5228 | if ((!save_temps_overrides_dumpdir && explicit_dumpdir) |
| 5229 | || (output_file && not_actual_file_p (output_file))) |
| 5230 | { |
| 5231 | /* Do nothing. */ |
| 5232 | } |
| 5233 | |
| 5234 | /* If -save-temps=obj and -o name, create the prefix to use for %b. |
| 5235 | Otherwise just make -save-temps=obj the same as -save-temps=cwd. */ |
| 5236 | else if (save_temps_flag != SAVE_TEMPS_CWD && output_file != NULL) |
| 5237 | { |
| 5238 | free (ptr: dumpdir); |
| 5239 | dumpdir = NULL; |
| 5240 | temp = lbasename (output_file); |
| 5241 | if (temp != output_file) |
| 5242 | dumpdir = xstrndup (output_file, |
| 5243 | strlen (s: output_file) - strlen (s: temp)); |
| 5244 | } |
| 5245 | else if (dumpdir) |
| 5246 | { |
| 5247 | free (ptr: dumpdir); |
| 5248 | dumpdir = NULL; |
| 5249 | } |
| 5250 | |
| 5251 | if (save_temps_flag) |
| 5252 | save_temps_flag = SAVE_TEMPS_DUMP; |
| 5253 | |
| 5254 | /* If there is any pathname component in an explicit -dumpbase, it |
| 5255 | overrides dumpdir entirely, so discard it right away. Although |
| 5256 | the presence of an explicit -dumpdir matters for the driver, it |
| 5257 | shouldn't matter for other processes, that get all that's needed |
| 5258 | from the -dumpdir and -dumpbase always passed to them. */ |
| 5259 | if (dumpdir && dumpbase && lbasename (dumpbase) != dumpbase) |
| 5260 | { |
| 5261 | free (ptr: dumpdir); |
| 5262 | dumpdir = NULL; |
| 5263 | } |
| 5264 | |
| 5265 | /* Check that dumpbase_ext matches the end of dumpbase, drop it |
| 5266 | otherwise. */ |
| 5267 | if (dumpbase_ext && dumpbase && *dumpbase) |
| 5268 | { |
| 5269 | int lendb = strlen (s: dumpbase); |
| 5270 | int lendbx = strlen (s: dumpbase_ext); |
| 5271 | |
| 5272 | /* -dumpbase-ext must be a suffix proper; discard it if it |
| 5273 | matches all of -dumpbase, as that would make for an empty |
| 5274 | basename. */ |
| 5275 | if (lendbx >= lendb |
| 5276 | || strcmp (s1: dumpbase + lendb - lendbx, s2: dumpbase_ext) != 0) |
| 5277 | { |
| 5278 | free (ptr: dumpbase_ext); |
| 5279 | dumpbase_ext = NULL; |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | /* -dumpbase with multiple sources goes into dumpdir. With a single |
| 5284 | source, it does only if linking and if dumpdir was not explicitly |
| 5285 | specified. */ |
| 5286 | if (dumpbase && *dumpbase |
| 5287 | && (single_input_file_index () == -2 |
| 5288 | || (!have_c && !explicit_dumpdir))) |
| 5289 | { |
| 5290 | char *prefix; |
| 5291 | |
| 5292 | if (dumpbase_ext) |
| 5293 | /* We checked that they match above. */ |
| 5294 | dumpbase[strlen (s: dumpbase) - strlen (s: dumpbase_ext)] = '\0'; |
| 5295 | |
| 5296 | if (dumpdir) |
| 5297 | prefix = concat (dumpdir, dumpbase, "-" , NULL); |
| 5298 | else |
| 5299 | prefix = concat (dumpbase, "-" , NULL); |
| 5300 | |
| 5301 | free (ptr: dumpdir); |
| 5302 | free (ptr: dumpbase); |
| 5303 | free (ptr: dumpbase_ext); |
| 5304 | dumpbase = dumpbase_ext = NULL; |
| 5305 | dumpdir = prefix; |
| 5306 | dumpdir_trailing_dash_added = true; |
| 5307 | } |
| 5308 | |
| 5309 | /* If dumpbase was not brought into dumpdir but we're linking, bring |
| 5310 | output_file into dumpdir unless dumpdir was explicitly specified. |
| 5311 | The test for !explicit_dumpdir is further below, because we want |
| 5312 | to use the obase computation for a ghost outbase, passed to |
| 5313 | GCC_COLLECT_OPTIONS. */ |
| 5314 | else if (!have_c && (!explicit_dumpdir || (dumpbase && !*dumpbase))) |
| 5315 | { |
| 5316 | /* If we get here, we know dumpbase was not specified, or it was |
| 5317 | specified as an empty string. If it was anything else, it |
| 5318 | would have combined with dumpdir above, because the condition |
| 5319 | for dumpbase to be used when present is broader than the |
| 5320 | condition that gets us here. */ |
| 5321 | gcc_assert (!dumpbase || !*dumpbase); |
| 5322 | |
| 5323 | const char *obase; |
| 5324 | char *tofree = NULL; |
| 5325 | if (!output_file || not_actual_file_p (output_file)) |
| 5326 | obase = "a" ; |
| 5327 | else |
| 5328 | { |
| 5329 | obase = lbasename (output_file); |
| 5330 | size_t blen = strlen (s: obase), xlen; |
| 5331 | /* Drop the suffix if it's dumpbase_ext, if given, |
| 5332 | otherwise .exe or the target executable suffix, or if the |
| 5333 | output was explicitly named a.out, but not otherwise. */ |
| 5334 | if (dumpbase_ext |
| 5335 | ? (blen > (xlen = strlen (s: dumpbase_ext)) |
| 5336 | && strcmp (s1: (temp = (obase + blen - xlen)), |
| 5337 | s2: dumpbase_ext) == 0) |
| 5338 | : ((temp = strrchr (s: obase + 1, c: '.')) |
| 5339 | && (xlen = strlen (s: temp)) |
| 5340 | && (strcmp (s1: temp, s2: ".exe" ) == 0 |
| 5341 | #if defined(HAVE_TARGET_EXECUTABLE_SUFFIX) |
| 5342 | || strcmp (temp, TARGET_EXECUTABLE_SUFFIX) == 0 |
| 5343 | #endif |
| 5344 | || strcmp (s1: obase, s2: "a.out" ) == 0))) |
| 5345 | { |
| 5346 | tofree = xstrndup (obase, blen - xlen); |
| 5347 | obase = tofree; |
| 5348 | } |
| 5349 | } |
| 5350 | |
| 5351 | /* We wish to save this basename to the -dumpdir passed through |
| 5352 | GCC_COLLECT_OPTIONS within maybe_run_linker, for e.g. LTO, |
| 5353 | but we do NOT wish to add it to e.g. %b, so we keep |
| 5354 | outbase_length as zero. */ |
| 5355 | gcc_assert (!outbase); |
| 5356 | outbase_length = 0; |
| 5357 | |
| 5358 | /* If we're building [dir1/]foo[.exe] out of a single input |
| 5359 | [dir2/]foo.c that shares the same basename, dump to |
| 5360 | [dir2/]foo.c.* rather than duplicating the basename into |
| 5361 | [dir2/]foo-foo.c.*. */ |
| 5362 | int idxin; |
| 5363 | if (dumpbase |
| 5364 | || ((idxin = single_input_file_index ()) >= 0 |
| 5365 | && adds_single_suffix_p (f2: lbasename (infiles[idxin].name), |
| 5366 | f1: obase))) |
| 5367 | { |
| 5368 | if (obase == tofree) |
| 5369 | outbase = tofree; |
| 5370 | else |
| 5371 | { |
| 5372 | outbase = xstrdup (obase); |
| 5373 | free (ptr: tofree); |
| 5374 | } |
| 5375 | obase = tofree = NULL; |
| 5376 | } |
| 5377 | else |
| 5378 | { |
| 5379 | if (dumpdir) |
| 5380 | { |
| 5381 | char *p = concat (dumpdir, obase, "-" , NULL); |
| 5382 | free (ptr: dumpdir); |
| 5383 | dumpdir = p; |
| 5384 | } |
| 5385 | else |
| 5386 | dumpdir = concat (obase, "-" , NULL); |
| 5387 | |
| 5388 | dumpdir_trailing_dash_added = true; |
| 5389 | |
| 5390 | free (ptr: tofree); |
| 5391 | obase = tofree = NULL; |
| 5392 | } |
| 5393 | |
| 5394 | if (!explicit_dumpdir || dumpbase) |
| 5395 | { |
| 5396 | /* Absent -dumpbase and present -dumpbase-ext have been applied |
| 5397 | to the linker output name, so compute fresh defaults for each |
| 5398 | compilation. */ |
| 5399 | free (ptr: dumpbase_ext); |
| 5400 | dumpbase_ext = NULL; |
| 5401 | } |
| 5402 | } |
| 5403 | |
| 5404 | /* Now, if we're compiling, or if we haven't used the dumpbase |
| 5405 | above, then outbase (%B) is derived from dumpbase, if given, or |
| 5406 | from the output name, given or implied. We can't precompute |
| 5407 | implied output names, but that's ok, since they're derived from |
| 5408 | input names. Just make sure we skip this if dumpbase is the |
| 5409 | empty string: we want to use input names then, so don't set |
| 5410 | outbase. */ |
| 5411 | if ((dumpbase || have_c) |
| 5412 | && !(dumpbase && !*dumpbase)) |
| 5413 | { |
| 5414 | gcc_assert (!outbase); |
| 5415 | |
| 5416 | if (dumpbase) |
| 5417 | { |
| 5418 | gcc_assert (single_input_file_index () != -2); |
| 5419 | /* We do not want lbasename here; dumpbase with dirnames |
| 5420 | overrides dumpdir entirely, even if dumpdir is |
| 5421 | specified. */ |
| 5422 | if (dumpbase_ext) |
| 5423 | /* We've already checked above that the suffix matches. */ |
| 5424 | outbase = xstrndup (dumpbase, |
| 5425 | strlen (s: dumpbase) - strlen (s: dumpbase_ext)); |
| 5426 | else |
| 5427 | outbase = xstrdup (dumpbase); |
| 5428 | } |
| 5429 | else if (output_file && !not_actual_file_p (output_file)) |
| 5430 | { |
| 5431 | outbase = xstrdup (lbasename (output_file)); |
| 5432 | char *p = strrchr (s: outbase + 1, c: '.'); |
| 5433 | if (p) |
| 5434 | *p = '\0'; |
| 5435 | } |
| 5436 | |
| 5437 | if (outbase) |
| 5438 | outbase_length = strlen (s: outbase); |
| 5439 | } |
| 5440 | |
| 5441 | /* If there is any pathname component in an explicit -dumpbase, do |
| 5442 | not use dumpdir, but retain it to pass it on to the compiler. */ |
| 5443 | if (dumpdir) |
| 5444 | dumpdir_length = strlen (s: dumpdir); |
| 5445 | else |
| 5446 | dumpdir_length = 0; |
| 5447 | |
| 5448 | /* Check that dumpbase_ext, if still present, still matches the end |
| 5449 | of dumpbase, if present, and drop it otherwise. We only retained |
| 5450 | it above when dumpbase was absent to maybe use it to drop the |
| 5451 | extension from output_name before combining it with dumpdir. We |
| 5452 | won't deal with -dumpbase-ext when -dumpbase is not explicitly |
| 5453 | given, even if just to activate backward-compatible dumpbase: |
| 5454 | dropping it on the floor is correct, expected and documented |
| 5455 | behavior. Attempting to deal with a -dumpbase-ext that might |
| 5456 | match the end of some input filename, or of the combination of |
| 5457 | the output basename with the suffix of the input filename, |
| 5458 | possible with an intermediate .gk extension for -fcompare-debug, |
| 5459 | is just calling for trouble. */ |
| 5460 | if (dumpbase_ext) |
| 5461 | { |
| 5462 | if (!dumpbase || !*dumpbase) |
| 5463 | { |
| 5464 | free (ptr: dumpbase_ext); |
| 5465 | dumpbase_ext = NULL; |
| 5466 | } |
| 5467 | else |
| 5468 | gcc_assert (strcmp (dumpbase + strlen (dumpbase) |
| 5469 | - strlen (dumpbase_ext), dumpbase_ext) == 0); |
| 5470 | } |
| 5471 | |
| 5472 | if (save_temps_flag && use_pipes) |
| 5473 | { |
| 5474 | /* -save-temps overrides -pipe, so that temp files are produced */ |
| 5475 | if (save_temps_flag) |
| 5476 | warning (0, "%<-pipe%> ignored because %<-save-temps%> specified" ); |
| 5477 | use_pipes = 0; |
| 5478 | } |
| 5479 | |
| 5480 | if (!compare_debug) |
| 5481 | { |
| 5482 | const char *gcd = env.get (name: "GCC_COMPARE_DEBUG" ); |
| 5483 | |
| 5484 | if (gcd && gcd[0] == '-') |
| 5485 | { |
| 5486 | compare_debug = 2; |
| 5487 | compare_debug_opt = gcd; |
| 5488 | } |
| 5489 | else if (gcd && *gcd && strcmp (s1: gcd, s2: "0" )) |
| 5490 | { |
| 5491 | compare_debug = 3; |
| 5492 | compare_debug_opt = "-gtoggle" ; |
| 5493 | } |
| 5494 | } |
| 5495 | else if (compare_debug < 0) |
| 5496 | { |
| 5497 | compare_debug = 0; |
| 5498 | gcc_assert (!compare_debug_opt); |
| 5499 | } |
| 5500 | |
| 5501 | /* Set up the search paths. We add directories that we expect to |
| 5502 | contain GNU Toolchain components before directories specified by |
| 5503 | the machine description so that we will find GNU components (like |
| 5504 | the GNU assembler) before those of the host system. */ |
| 5505 | |
| 5506 | /* If we don't know where the toolchain has been installed, use the |
| 5507 | configured-in locations. */ |
| 5508 | if (!gcc_exec_prefix) |
| 5509 | { |
| 5510 | #ifndef OS2 |
| 5511 | add_prefix (pprefix: &exec_prefixes, prefix: standard_libexec_prefix, component: "GCC" , |
| 5512 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 1, os_multilib: 0); |
| 5513 | add_prefix (pprefix: &exec_prefixes, prefix: standard_libexec_prefix, component: "BINUTILS" , |
| 5514 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 2, os_multilib: 0); |
| 5515 | add_prefix (pprefix: &exec_prefixes, prefix: standard_exec_prefix, component: "BINUTILS" , |
| 5516 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 2, os_multilib: 0); |
| 5517 | #endif |
| 5518 | add_prefix (pprefix: &startfile_prefixes, prefix: standard_exec_prefix, component: "BINUTILS" , |
| 5519 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 1, os_multilib: 0); |
| 5520 | } |
| 5521 | |
| 5522 | gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix)); |
| 5523 | tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine, |
| 5524 | dir_separator_str, NULL); |
| 5525 | |
| 5526 | /* Look for tools relative to the location from which the driver is |
| 5527 | running, or, if that is not available, the configured prefix. */ |
| 5528 | tooldir_prefix |
| 5529 | = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, |
| 5530 | spec_host_machine, dir_separator_str, spec_version, |
| 5531 | accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL); |
| 5532 | free (ptr: tooldir_prefix2); |
| 5533 | |
| 5534 | add_prefix (pprefix: &exec_prefixes, |
| 5535 | prefix: concat (tooldir_prefix, "bin" , dir_separator_str, NULL), |
| 5536 | component: "BINUTILS" , priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 5537 | add_prefix (pprefix: &startfile_prefixes, |
| 5538 | prefix: concat (tooldir_prefix, "lib" , dir_separator_str, NULL), |
| 5539 | component: "BINUTILS" , priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 5540 | free (ptr: tooldir_prefix); |
| 5541 | |
| 5542 | #if defined(TARGET_SYSTEM_ROOT_RELOCATABLE) && !defined(VMS) |
| 5543 | /* If the normal TARGET_SYSTEM_ROOT is inside of $exec_prefix, |
| 5544 | then consider it to relocate with the rest of the GCC installation |
| 5545 | if GCC_EXEC_PREFIX is set. |
| 5546 | ``make_relative_prefix'' is not compiled for VMS, so don't call it. */ |
| 5547 | if (target_system_root && !target_system_root_changed && gcc_exec_prefix) |
| 5548 | { |
| 5549 | char *tmp_prefix = get_relative_prefix (decoded_options[0].arg, |
| 5550 | standard_bindir_prefix, |
| 5551 | target_system_root); |
| 5552 | if (tmp_prefix && access_check (tmp_prefix, F_OK) == 0) |
| 5553 | { |
| 5554 | target_system_root = tmp_prefix; |
| 5555 | target_system_root_changed = 1; |
| 5556 | } |
| 5557 | } |
| 5558 | #endif |
| 5559 | |
| 5560 | /* More prefixes are enabled in main, after we read the specs file |
| 5561 | and determine whether this is cross-compilation or not. */ |
| 5562 | |
| 5563 | if (n_infiles != 0 && n_infiles == last_language_n_infiles && spec_lang != 0) |
| 5564 | warning (0, "%<-x %s%> after last input file has no effect" , spec_lang); |
| 5565 | |
| 5566 | /* Synthesize -fcompare-debug flag from the GCC_COMPARE_DEBUG |
| 5567 | environment variable. */ |
| 5568 | if (compare_debug == 2 || compare_debug == 3) |
| 5569 | { |
| 5570 | const char *opt = concat ("-fcompare-debug=" , compare_debug_opt, NULL); |
| 5571 | save_switch (opt, n_args: 0, NULL, validated: false, known: true); |
| 5572 | compare_debug = 1; |
| 5573 | } |
| 5574 | |
| 5575 | /* Ensure we only invoke each subprocess once. */ |
| 5576 | if (n_infiles == 0 |
| 5577 | && (print_subprocess_help || print_help_list || print_version)) |
| 5578 | { |
| 5579 | /* Create a dummy input file, so that we can pass |
| 5580 | the help option on to the various sub-processes. */ |
| 5581 | add_infile (name: "help-dummy" , language: "c" ); |
| 5582 | } |
| 5583 | |
| 5584 | /* Decide if undefined variable references are allowed in specs. */ |
| 5585 | |
| 5586 | /* -v alone is safe. --version and --help alone or together are safe. Note |
| 5587 | that -v would make them unsafe, as they'd then be run for subprocesses as |
| 5588 | well, the location of which might depend on variables possibly coming |
| 5589 | from self-specs. Note also that the command name is counted in |
| 5590 | decoded_options_count. */ |
| 5591 | |
| 5592 | unsigned help_version_count = 0; |
| 5593 | |
| 5594 | if (print_version) |
| 5595 | help_version_count++; |
| 5596 | |
| 5597 | if (print_help_list) |
| 5598 | help_version_count++; |
| 5599 | |
| 5600 | spec_undefvar_allowed = |
| 5601 | ((verbose_flag && decoded_options_count == 2) |
| 5602 | || help_version_count == decoded_options_count - 1); |
| 5603 | |
| 5604 | alloc_switch (); |
| 5605 | switches[n_switches].part1 = 0; |
| 5606 | alloc_infile (); |
| 5607 | infiles[n_infiles].name = 0; |
| 5608 | } |
| 5609 | |
| 5610 | /* Store switches not filtered out by %<S in spec in COLLECT_GCC_OPTIONS |
| 5611 | and place that in the environment. */ |
| 5612 | |
| 5613 | static void |
| 5614 | set_collect_gcc_options (void) |
| 5615 | { |
| 5616 | int i; |
| 5617 | int first_time; |
| 5618 | |
| 5619 | /* Build COLLECT_GCC_OPTIONS to have all of the options specified to |
| 5620 | the compiler. */ |
| 5621 | obstack_grow (&collect_obstack, "COLLECT_GCC_OPTIONS=" , |
| 5622 | sizeof ("COLLECT_GCC_OPTIONS=" ) - 1); |
| 5623 | |
| 5624 | first_time = true; |
| 5625 | for (i = 0; (int) i < n_switches; i++) |
| 5626 | { |
| 5627 | const char *const *args; |
| 5628 | const char *p, *q; |
| 5629 | if (!first_time) |
| 5630 | obstack_grow (&collect_obstack, " " , 1); |
| 5631 | |
| 5632 | first_time = false; |
| 5633 | |
| 5634 | /* Ignore elided switches. */ |
| 5635 | if ((switches[i].live_cond |
| 5636 | & (SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC)) |
| 5637 | == SWITCH_IGNORE) |
| 5638 | continue; |
| 5639 | |
| 5640 | obstack_grow (&collect_obstack, "'-" , 2); |
| 5641 | q = switches[i].part1; |
| 5642 | while ((p = strchr (s: q, c: '\''))) |
| 5643 | { |
| 5644 | obstack_grow (&collect_obstack, q, p - q); |
| 5645 | obstack_grow (&collect_obstack, "'\\''" , 4); |
| 5646 | q = ++p; |
| 5647 | } |
| 5648 | obstack_grow (&collect_obstack, q, strlen (q)); |
| 5649 | obstack_grow (&collect_obstack, "'" , 1); |
| 5650 | |
| 5651 | for (args = switches[i].args; args && *args; args++) |
| 5652 | { |
| 5653 | obstack_grow (&collect_obstack, " '" , 2); |
| 5654 | q = *args; |
| 5655 | while ((p = strchr (s: q, c: '\''))) |
| 5656 | { |
| 5657 | obstack_grow (&collect_obstack, q, p - q); |
| 5658 | obstack_grow (&collect_obstack, "'\\''" , 4); |
| 5659 | q = ++p; |
| 5660 | } |
| 5661 | obstack_grow (&collect_obstack, q, strlen (q)); |
| 5662 | obstack_grow (&collect_obstack, "'" , 1); |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | if (dumpdir) |
| 5667 | { |
| 5668 | if (!first_time) |
| 5669 | obstack_grow (&collect_obstack, " " , 1); |
| 5670 | first_time = false; |
| 5671 | |
| 5672 | obstack_grow (&collect_obstack, "'-dumpdir' '" , 12); |
| 5673 | const char *p, *q; |
| 5674 | |
| 5675 | q = dumpdir; |
| 5676 | while ((p = strchr (s: q, c: '\''))) |
| 5677 | { |
| 5678 | obstack_grow (&collect_obstack, q, p - q); |
| 5679 | obstack_grow (&collect_obstack, "'\\''" , 4); |
| 5680 | q = ++p; |
| 5681 | } |
| 5682 | obstack_grow (&collect_obstack, q, strlen (q)); |
| 5683 | |
| 5684 | obstack_grow (&collect_obstack, "'" , 1); |
| 5685 | } |
| 5686 | |
| 5687 | obstack_grow (&collect_obstack, "\0" , 1); |
| 5688 | xputenv (XOBFINISH (&collect_obstack, char *)); |
| 5689 | } |
| 5690 | |
| 5691 | /* Process a spec string, accumulating and running commands. */ |
| 5692 | |
| 5693 | /* These variables describe the input file name. |
| 5694 | input_file_number is the index on outfiles of this file, |
| 5695 | so that the output file name can be stored for later use by %o. |
| 5696 | input_basename is the start of the part of the input file |
| 5697 | sans all directory names, and basename_length is the number |
| 5698 | of characters starting there excluding the suffix .c or whatever. */ |
| 5699 | |
| 5700 | static const char *gcc_input_filename; |
| 5701 | static int input_file_number; |
| 5702 | size_t input_filename_length; |
| 5703 | static int basename_length; |
| 5704 | static int suffixed_basename_length; |
| 5705 | static const char *input_basename; |
| 5706 | static const char *input_suffix; |
| 5707 | #ifndef HOST_LACKS_INODE_NUMBERS |
| 5708 | static struct stat input_stat; |
| 5709 | #endif |
| 5710 | static int input_stat_set; |
| 5711 | |
| 5712 | /* The compiler used to process the current input file. */ |
| 5713 | static struct compiler *input_file_compiler; |
| 5714 | |
| 5715 | /* These are variables used within do_spec and do_spec_1. */ |
| 5716 | |
| 5717 | /* Nonzero if an arg has been started and not yet terminated |
| 5718 | (with space, tab or newline). */ |
| 5719 | static int arg_going; |
| 5720 | |
| 5721 | /* Nonzero means %d or %g has been seen; the next arg to be terminated |
| 5722 | is a temporary file name. */ |
| 5723 | static int delete_this_arg; |
| 5724 | |
| 5725 | /* Nonzero means %w has been seen; the next arg to be terminated |
| 5726 | is the output file name of this compilation. */ |
| 5727 | static int this_is_output_file; |
| 5728 | |
| 5729 | /* Nonzero means %s has been seen; the next arg to be terminated |
| 5730 | is the name of a library file and we should try the standard |
| 5731 | search dirs for it. */ |
| 5732 | static int this_is_library_file; |
| 5733 | |
| 5734 | /* Nonzero means %T has been seen; the next arg to be terminated |
| 5735 | is the name of a linker script and we should try all of the |
| 5736 | standard search dirs for it. If it is found insert a --script |
| 5737 | command line switch and then substitute the full path in place, |
| 5738 | otherwise generate an error message. */ |
| 5739 | static int this_is_linker_script; |
| 5740 | |
| 5741 | /* Nonzero means that the input of this command is coming from a pipe. */ |
| 5742 | static int input_from_pipe; |
| 5743 | |
| 5744 | /* Nonnull means substitute this for any suffix when outputting a switches |
| 5745 | arguments. */ |
| 5746 | static const char *suffix_subst; |
| 5747 | |
| 5748 | /* If there is an argument being accumulated, terminate it and store it. */ |
| 5749 | |
| 5750 | static void |
| 5751 | end_going_arg (void) |
| 5752 | { |
| 5753 | if (arg_going) |
| 5754 | { |
| 5755 | const char *string; |
| 5756 | |
| 5757 | obstack_1grow (&obstack, 0); |
| 5758 | string = XOBFINISH (&obstack, const char *); |
| 5759 | if (this_is_library_file) |
| 5760 | string = find_file (string); |
| 5761 | if (this_is_linker_script) |
| 5762 | { |
| 5763 | char * full_script_path = find_a_file (pprefix: &startfile_prefixes, name: string, R_OK, do_multi: true); |
| 5764 | |
| 5765 | if (full_script_path == NULL) |
| 5766 | { |
| 5767 | error ("unable to locate default linker script %qs in the library search paths" , string); |
| 5768 | /* Script was not found on search path. */ |
| 5769 | return; |
| 5770 | } |
| 5771 | store_arg (arg: "--script" , delete_always: false, delete_failure: false); |
| 5772 | string = full_script_path; |
| 5773 | } |
| 5774 | store_arg (arg: string, delete_always: delete_this_arg, delete_failure: this_is_output_file); |
| 5775 | if (this_is_output_file) |
| 5776 | outfiles[input_file_number] = string; |
| 5777 | arg_going = 0; |
| 5778 | } |
| 5779 | } |
| 5780 | |
| 5781 | |
| 5782 | /* Parse the WRAPPER string which is a comma separated list of the command line |
| 5783 | and insert them into the beginning of argbuf. */ |
| 5784 | |
| 5785 | static void |
| 5786 | insert_wrapper (const char *wrapper) |
| 5787 | { |
| 5788 | int n = 0; |
| 5789 | int i; |
| 5790 | char *buf = xstrdup (wrapper); |
| 5791 | char *p = buf; |
| 5792 | unsigned int old_length = argbuf.length (); |
| 5793 | |
| 5794 | do |
| 5795 | { |
| 5796 | n++; |
| 5797 | while (*p == ',') |
| 5798 | p++; |
| 5799 | } |
| 5800 | while ((p = strchr (s: p, c: ',')) != NULL); |
| 5801 | |
| 5802 | argbuf.safe_grow (len: old_length + n, exact: true); |
| 5803 | memmove (dest: argbuf.address () + n, |
| 5804 | src: argbuf.address (), |
| 5805 | n: old_length * sizeof (const_char_p)); |
| 5806 | |
| 5807 | i = 0; |
| 5808 | p = buf; |
| 5809 | do |
| 5810 | { |
| 5811 | while (*p == ',') |
| 5812 | { |
| 5813 | *p = 0; |
| 5814 | p++; |
| 5815 | } |
| 5816 | argbuf[i] = p; |
| 5817 | i++; |
| 5818 | } |
| 5819 | while ((p = strchr (s: p, c: ',')) != NULL); |
| 5820 | gcc_assert (i == n); |
| 5821 | } |
| 5822 | |
| 5823 | /* Process the spec SPEC and run the commands specified therein. |
| 5824 | Returns 0 if the spec is successfully processed; -1 if failed. */ |
| 5825 | |
| 5826 | int |
| 5827 | do_spec (const char *spec) |
| 5828 | { |
| 5829 | int value; |
| 5830 | |
| 5831 | value = do_spec_2 (spec, NULL); |
| 5832 | |
| 5833 | /* Force out any unfinished command. |
| 5834 | If -pipe, this forces out the last command if it ended in `|'. */ |
| 5835 | if (value == 0) |
| 5836 | { |
| 5837 | if (argbuf.length () > 0 |
| 5838 | && !strcmp (s1: argbuf.last (), s2: "|" )) |
| 5839 | argbuf.pop (); |
| 5840 | |
| 5841 | set_collect_gcc_options (); |
| 5842 | |
| 5843 | if (argbuf.length () > 0) |
| 5844 | value = execute (); |
| 5845 | } |
| 5846 | |
| 5847 | return value; |
| 5848 | } |
| 5849 | |
| 5850 | /* Process the spec SPEC, with SOFT_MATCHED_PART designating the current value |
| 5851 | of a matched * pattern which may be re-injected by way of %*. */ |
| 5852 | |
| 5853 | static int |
| 5854 | do_spec_2 (const char *spec, const char *soft_matched_part) |
| 5855 | { |
| 5856 | int result; |
| 5857 | |
| 5858 | clear_args (); |
| 5859 | arg_going = 0; |
| 5860 | delete_this_arg = 0; |
| 5861 | this_is_output_file = 0; |
| 5862 | this_is_library_file = 0; |
| 5863 | this_is_linker_script = 0; |
| 5864 | input_from_pipe = 0; |
| 5865 | suffix_subst = NULL; |
| 5866 | |
| 5867 | result = do_spec_1 (spec, 0, soft_matched_part); |
| 5868 | |
| 5869 | end_going_arg (); |
| 5870 | |
| 5871 | return result; |
| 5872 | } |
| 5873 | |
| 5874 | /* Process the given spec string and add any new options to the end |
| 5875 | of the switches/n_switches array. */ |
| 5876 | |
| 5877 | static void |
| 5878 | do_option_spec (const char *name, const char *spec) |
| 5879 | { |
| 5880 | unsigned int i, value_count, value_len; |
| 5881 | const char *p, *q, *value; |
| 5882 | char *tmp_spec, *tmp_spec_p; |
| 5883 | |
| 5884 | if (configure_default_options[0].name == NULL) |
| 5885 | return; |
| 5886 | |
| 5887 | for (i = 0; i < ARRAY_SIZE (configure_default_options); i++) |
| 5888 | if (strcmp (s1: configure_default_options[i].name, s2: name) == 0) |
| 5889 | break; |
| 5890 | if (i == ARRAY_SIZE (configure_default_options)) |
| 5891 | return; |
| 5892 | |
| 5893 | value = configure_default_options[i].value; |
| 5894 | value_len = strlen (s: value); |
| 5895 | |
| 5896 | /* Compute the size of the final spec. */ |
| 5897 | value_count = 0; |
| 5898 | p = spec; |
| 5899 | while ((p = strstr (haystack: p, needle: "%(VALUE)" )) != NULL) |
| 5900 | { |
| 5901 | p ++; |
| 5902 | value_count ++; |
| 5903 | } |
| 5904 | |
| 5905 | /* Replace each %(VALUE) by the specified value. */ |
| 5906 | tmp_spec = (char *) alloca (strlen (spec) + 1 |
| 5907 | + value_count * (value_len - strlen ("%(VALUE)" ))); |
| 5908 | tmp_spec_p = tmp_spec; |
| 5909 | q = spec; |
| 5910 | while ((p = strstr (haystack: q, needle: "%(VALUE)" )) != NULL) |
| 5911 | { |
| 5912 | memcpy (dest: tmp_spec_p, src: q, n: p - q); |
| 5913 | tmp_spec_p = tmp_spec_p + (p - q); |
| 5914 | memcpy (dest: tmp_spec_p, src: value, n: value_len); |
| 5915 | tmp_spec_p += value_len; |
| 5916 | q = p + strlen (s: "%(VALUE)" ); |
| 5917 | } |
| 5918 | strcpy (dest: tmp_spec_p, src: q); |
| 5919 | |
| 5920 | do_self_spec (tmp_spec); |
| 5921 | } |
| 5922 | |
| 5923 | /* Process the given spec string and add any new options to the end |
| 5924 | of the switches/n_switches array. */ |
| 5925 | |
| 5926 | static void |
| 5927 | do_self_spec (const char *spec) |
| 5928 | { |
| 5929 | int i; |
| 5930 | |
| 5931 | do_spec_2 (spec, NULL); |
| 5932 | do_spec_1 (" " , 0, NULL); |
| 5933 | |
| 5934 | /* Mark %<S switches processed by do_self_spec to be ignored permanently. |
| 5935 | do_self_specs adds the replacements to switches array, so it shouldn't |
| 5936 | be processed afterwards. */ |
| 5937 | for (i = 0; i < n_switches; i++) |
| 5938 | if ((switches[i].live_cond & SWITCH_IGNORE)) |
| 5939 | switches[i].live_cond |= SWITCH_IGNORE_PERMANENTLY; |
| 5940 | |
| 5941 | if (argbuf.length () > 0) |
| 5942 | { |
| 5943 | const char **argbuf_copy; |
| 5944 | struct cl_decoded_option *decoded_options; |
| 5945 | struct cl_option_handlers handlers; |
| 5946 | unsigned int decoded_options_count; |
| 5947 | unsigned int j; |
| 5948 | |
| 5949 | /* Create a copy of argbuf with a dummy argv[0] entry for |
| 5950 | decode_cmdline_options_to_array. */ |
| 5951 | argbuf_copy = XNEWVEC (const char *, |
| 5952 | argbuf.length () + 1); |
| 5953 | argbuf_copy[0] = "" ; |
| 5954 | memcpy (dest: argbuf_copy + 1, src: argbuf.address (), |
| 5955 | n: argbuf.length () * sizeof (const char *)); |
| 5956 | |
| 5957 | decode_cmdline_options_to_array (argc: argbuf.length () + 1, |
| 5958 | argv: argbuf_copy, |
| 5959 | CL_DRIVER, decoded_options: &decoded_options, |
| 5960 | decoded_options_count: &decoded_options_count); |
| 5961 | free (ptr: argbuf_copy); |
| 5962 | |
| 5963 | set_option_handlers (&handlers); |
| 5964 | |
| 5965 | for (j = 1; j < decoded_options_count; j++) |
| 5966 | { |
| 5967 | switch (decoded_options[j].opt_index) |
| 5968 | { |
| 5969 | case OPT_SPECIAL_input_file: |
| 5970 | /* Specs should only generate options, not input |
| 5971 | files. */ |
| 5972 | if (strcmp (s1: decoded_options[j].arg, s2: "-" ) != 0) |
| 5973 | fatal_error (input_location, |
| 5974 | "switch %qs does not start with %<-%>" , |
| 5975 | decoded_options[j].arg); |
| 5976 | else |
| 5977 | fatal_error (input_location, |
| 5978 | "spec-generated switch is just %<-%>" ); |
| 5979 | break; |
| 5980 | |
| 5981 | case OPT_fcompare_debug_second: |
| 5982 | case OPT_fcompare_debug: |
| 5983 | case OPT_fcompare_debug_: |
| 5984 | case OPT_o: |
| 5985 | /* Avoid duplicate processing of some options from |
| 5986 | compare-debug specs; just save them here. */ |
| 5987 | save_switch (opt: decoded_options[j].canonical_option[0], |
| 5988 | n_args: (decoded_options[j].canonical_option_num_elements |
| 5989 | - 1), |
| 5990 | args: &decoded_options[j].canonical_option[1], validated: false, known: true); |
| 5991 | break; |
| 5992 | |
| 5993 | default: |
| 5994 | read_cmdline_option (opts: &global_options, opts_set: &global_options_set, |
| 5995 | decoded: decoded_options + j, UNKNOWN_LOCATION, |
| 5996 | CL_DRIVER, handlers: &handlers, dc: global_dc); |
| 5997 | break; |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | free (ptr: decoded_options); |
| 6002 | |
| 6003 | alloc_switch (); |
| 6004 | switches[n_switches].part1 = 0; |
| 6005 | } |
| 6006 | } |
| 6007 | |
| 6008 | /* Callback for processing %D and %I specs. */ |
| 6009 | |
| 6010 | struct spec_path_info { |
| 6011 | const char *option; |
| 6012 | const char *append; |
| 6013 | size_t append_len; |
| 6014 | bool omit_relative; |
| 6015 | bool separate_options; |
| 6016 | bool realpaths; |
| 6017 | }; |
| 6018 | |
| 6019 | static void * |
| 6020 | spec_path (char *path, void *data) |
| 6021 | { |
| 6022 | struct spec_path_info *info = (struct spec_path_info *) data; |
| 6023 | size_t len = 0; |
| 6024 | char save = 0; |
| 6025 | |
| 6026 | /* The path must exist; we want to resolve it to the realpath so that this |
| 6027 | can be embedded as a runpath. */ |
| 6028 | if (info->realpaths) |
| 6029 | path = lrealpath (path); |
| 6030 | |
| 6031 | /* However, if we failed to resolve it - perhaps because there was a bogus |
| 6032 | -B option on the command line, then punt on this entry. */ |
| 6033 | if (!path) |
| 6034 | return NULL; |
| 6035 | |
| 6036 | if (info->omit_relative && !IS_ABSOLUTE_PATH (path)) |
| 6037 | return NULL; |
| 6038 | |
| 6039 | if (info->append_len != 0) |
| 6040 | { |
| 6041 | len = strlen (s: path); |
| 6042 | memcpy (dest: path + len, src: info->append, n: info->append_len + 1); |
| 6043 | } |
| 6044 | |
| 6045 | if (!is_directory (path)) |
| 6046 | return NULL; |
| 6047 | |
| 6048 | do_spec_1 (info->option, 1, NULL); |
| 6049 | if (info->separate_options) |
| 6050 | do_spec_1 (" " , 0, NULL); |
| 6051 | |
| 6052 | if (info->append_len == 0) |
| 6053 | { |
| 6054 | len = strlen (s: path); |
| 6055 | save = path[len - 1]; |
| 6056 | if (IS_DIR_SEPARATOR (path[len - 1])) |
| 6057 | path[len - 1] = '\0'; |
| 6058 | } |
| 6059 | |
| 6060 | do_spec_1 (path, 1, NULL); |
| 6061 | do_spec_1 (" " , 0, NULL); |
| 6062 | |
| 6063 | /* Must not damage the original path. */ |
| 6064 | if (info->append_len == 0) |
| 6065 | path[len - 1] = save; |
| 6066 | |
| 6067 | return NULL; |
| 6068 | } |
| 6069 | |
| 6070 | /* True if we should compile INFILE. */ |
| 6071 | |
| 6072 | static bool |
| 6073 | compile_input_file_p (struct infile *infile) |
| 6074 | { |
| 6075 | if ((!infile->language) || (infile->language[0] != '*')) |
| 6076 | if (infile->incompiler == input_file_compiler) |
| 6077 | return true; |
| 6078 | return false; |
| 6079 | } |
| 6080 | |
| 6081 | /* Process each member of VEC as a spec. */ |
| 6082 | |
| 6083 | static void |
| 6084 | do_specs_vec (vec<char_p> vec) |
| 6085 | { |
| 6086 | for (char *opt : vec) |
| 6087 | { |
| 6088 | do_spec_1 (opt, 1, NULL); |
| 6089 | /* Make each accumulated option a separate argument. */ |
| 6090 | do_spec_1 (" " , 0, NULL); |
| 6091 | } |
| 6092 | } |
| 6093 | |
| 6094 | /* Add options passed via -Xassembler or -Wa to COLLECT_AS_OPTIONS. */ |
| 6095 | |
| 6096 | static void |
| 6097 | putenv_COLLECT_AS_OPTIONS (vec<char_p> vec) |
| 6098 | { |
| 6099 | if (vec.is_empty ()) |
| 6100 | return; |
| 6101 | |
| 6102 | obstack_init (&collect_obstack); |
| 6103 | obstack_grow (&collect_obstack, "COLLECT_AS_OPTIONS=" , |
| 6104 | strlen ("COLLECT_AS_OPTIONS=" )); |
| 6105 | |
| 6106 | char *opt; |
| 6107 | unsigned ix; |
| 6108 | |
| 6109 | FOR_EACH_VEC_ELT (vec, ix, opt) |
| 6110 | { |
| 6111 | obstack_1grow (&collect_obstack, '\''); |
| 6112 | obstack_grow (&collect_obstack, opt, strlen (opt)); |
| 6113 | obstack_1grow (&collect_obstack, '\''); |
| 6114 | if (ix < vec.length () - 1) |
| 6115 | obstack_1grow(&collect_obstack, ' '); |
| 6116 | } |
| 6117 | |
| 6118 | obstack_1grow (&collect_obstack, '\0'); |
| 6119 | xputenv (XOBFINISH (&collect_obstack, char *)); |
| 6120 | } |
| 6121 | |
| 6122 | /* Process the sub-spec SPEC as a portion of a larger spec. |
| 6123 | This is like processing a whole spec except that we do |
| 6124 | not initialize at the beginning and we do not supply a |
| 6125 | newline by default at the end. |
| 6126 | INSWITCH nonzero means don't process %-sequences in SPEC; |
| 6127 | in this case, % is treated as an ordinary character. |
| 6128 | This is used while substituting switches. |
| 6129 | INSWITCH nonzero also causes SPC not to terminate an argument. |
| 6130 | |
| 6131 | Value is zero unless a line was finished |
| 6132 | and the command on that line reported an error. */ |
| 6133 | |
| 6134 | static int |
| 6135 | do_spec_1 (const char *spec, int inswitch, const char *soft_matched_part) |
| 6136 | { |
| 6137 | const char *p = spec; |
| 6138 | int c; |
| 6139 | int i; |
| 6140 | int value; |
| 6141 | |
| 6142 | /* If it's an empty string argument to a switch, keep it as is. */ |
| 6143 | if (inswitch && !*p) |
| 6144 | arg_going = 1; |
| 6145 | |
| 6146 | while ((c = *p++)) |
| 6147 | /* If substituting a switch, treat all chars like letters. |
| 6148 | Otherwise, NL, SPC, TAB and % are special. */ |
| 6149 | switch (inswitch ? 'a' : c) |
| 6150 | { |
| 6151 | case '\n': |
| 6152 | end_going_arg (); |
| 6153 | |
| 6154 | if (argbuf.length () > 0 |
| 6155 | && !strcmp (s1: argbuf.last (), s2: "|" )) |
| 6156 | { |
| 6157 | /* A `|' before the newline means use a pipe here, |
| 6158 | but only if -pipe was specified. |
| 6159 | Otherwise, execute now and don't pass the `|' as an arg. */ |
| 6160 | if (use_pipes) |
| 6161 | { |
| 6162 | input_from_pipe = 1; |
| 6163 | break; |
| 6164 | } |
| 6165 | else |
| 6166 | argbuf.pop (); |
| 6167 | } |
| 6168 | |
| 6169 | set_collect_gcc_options (); |
| 6170 | |
| 6171 | if (argbuf.length () > 0) |
| 6172 | { |
| 6173 | value = execute (); |
| 6174 | if (value) |
| 6175 | return value; |
| 6176 | } |
| 6177 | /* Reinitialize for a new command, and for a new argument. */ |
| 6178 | clear_args (); |
| 6179 | arg_going = 0; |
| 6180 | delete_this_arg = 0; |
| 6181 | this_is_output_file = 0; |
| 6182 | this_is_library_file = 0; |
| 6183 | this_is_linker_script = 0; |
| 6184 | input_from_pipe = 0; |
| 6185 | break; |
| 6186 | |
| 6187 | case '|': |
| 6188 | end_going_arg (); |
| 6189 | |
| 6190 | /* Use pipe */ |
| 6191 | obstack_1grow (&obstack, c); |
| 6192 | arg_going = 1; |
| 6193 | break; |
| 6194 | |
| 6195 | case '\t': |
| 6196 | case ' ': |
| 6197 | end_going_arg (); |
| 6198 | |
| 6199 | /* Reinitialize for a new argument. */ |
| 6200 | delete_this_arg = 0; |
| 6201 | this_is_output_file = 0; |
| 6202 | this_is_library_file = 0; |
| 6203 | this_is_linker_script = 0; |
| 6204 | break; |
| 6205 | |
| 6206 | case '%': |
| 6207 | switch (c = *p++) |
| 6208 | { |
| 6209 | case 0: |
| 6210 | fatal_error (input_location, "spec %qs invalid" , spec); |
| 6211 | |
| 6212 | case 'b': |
| 6213 | /* Don't use %b in the linker command. */ |
| 6214 | gcc_assert (suffixed_basename_length); |
| 6215 | if (!this_is_output_file && dumpdir_length) |
| 6216 | obstack_grow (&obstack, dumpdir, dumpdir_length); |
| 6217 | if (this_is_output_file || !outbase_length) |
| 6218 | obstack_grow (&obstack, input_basename, basename_length); |
| 6219 | else |
| 6220 | obstack_grow (&obstack, outbase, outbase_length); |
| 6221 | if (compare_debug < 0) |
| 6222 | obstack_grow (&obstack, ".gk" , 3); |
| 6223 | arg_going = 1; |
| 6224 | break; |
| 6225 | |
| 6226 | case 'B': |
| 6227 | /* Don't use %B in the linker command. */ |
| 6228 | gcc_assert (suffixed_basename_length); |
| 6229 | if (!this_is_output_file && dumpdir_length) |
| 6230 | obstack_grow (&obstack, dumpdir, dumpdir_length); |
| 6231 | if (this_is_output_file || !outbase_length) |
| 6232 | obstack_grow (&obstack, input_basename, basename_length); |
| 6233 | else |
| 6234 | obstack_grow (&obstack, outbase, outbase_length); |
| 6235 | if (compare_debug < 0) |
| 6236 | obstack_grow (&obstack, ".gk" , 3); |
| 6237 | obstack_grow (&obstack, input_basename + basename_length, |
| 6238 | suffixed_basename_length - basename_length); |
| 6239 | |
| 6240 | arg_going = 1; |
| 6241 | break; |
| 6242 | |
| 6243 | case 'd': |
| 6244 | delete_this_arg = 2; |
| 6245 | break; |
| 6246 | |
| 6247 | /* Dump out the directories specified with LIBRARY_PATH, |
| 6248 | followed by the absolute directories |
| 6249 | that we search for startfiles. */ |
| 6250 | case 'D': |
| 6251 | { |
| 6252 | struct spec_path_info info; |
| 6253 | |
| 6254 | info.option = "-L" ; |
| 6255 | info.append_len = 0; |
| 6256 | #ifdef RELATIVE_PREFIX_NOT_LINKDIR |
| 6257 | /* Used on systems which record the specified -L dirs |
| 6258 | and use them to search for dynamic linking. |
| 6259 | Relative directories always come from -B, |
| 6260 | and it is better not to use them for searching |
| 6261 | at run time. In particular, stage1 loses. */ |
| 6262 | info.omit_relative = true; |
| 6263 | #else |
| 6264 | info.omit_relative = false; |
| 6265 | #endif |
| 6266 | info.separate_options = false; |
| 6267 | info.realpaths = false; |
| 6268 | |
| 6269 | for_each_path (paths: &startfile_prefixes, do_multi: true, extra_space: 0, callback: spec_path, callback_info: &info); |
| 6270 | } |
| 6271 | break; |
| 6272 | |
| 6273 | case 'P': |
| 6274 | { |
| 6275 | struct spec_path_info info; |
| 6276 | |
| 6277 | info.option = RUNPATH_OPTION; |
| 6278 | info.append_len = 0; |
| 6279 | info.omit_relative = false; |
| 6280 | info.separate_options = true; |
| 6281 | /* We want to embed the actual paths that have the libraries. */ |
| 6282 | info.realpaths = true; |
| 6283 | |
| 6284 | for_each_path (paths: &startfile_prefixes, do_multi: true, extra_space: 0, callback: spec_path, callback_info: &info); |
| 6285 | } |
| 6286 | break; |
| 6287 | |
| 6288 | case 'e': |
| 6289 | /* %efoo means report an error with `foo' as error message |
| 6290 | and don't execute any more commands for this file. */ |
| 6291 | { |
| 6292 | const char *q = p; |
| 6293 | char *buf; |
| 6294 | while (*p != 0 && *p != '\n') |
| 6295 | p++; |
| 6296 | buf = (char *) alloca (p - q + 1); |
| 6297 | strncpy (dest: buf, src: q, n: p - q); |
| 6298 | buf[p - q] = 0; |
| 6299 | error ("%s" , _(buf)); |
| 6300 | return -1; |
| 6301 | } |
| 6302 | break; |
| 6303 | case 'n': |
| 6304 | /* %nfoo means report a notice with `foo' on stderr. */ |
| 6305 | { |
| 6306 | const char *q = p; |
| 6307 | char *buf; |
| 6308 | while (*p != 0 && *p != '\n') |
| 6309 | p++; |
| 6310 | buf = (char *) alloca (p - q + 1); |
| 6311 | strncpy (dest: buf, src: q, n: p - q); |
| 6312 | buf[p - q] = 0; |
| 6313 | inform (UNKNOWN_LOCATION, "%s" , _(buf)); |
| 6314 | if (*p) |
| 6315 | p++; |
| 6316 | } |
| 6317 | break; |
| 6318 | |
| 6319 | case 'j': |
| 6320 | { |
| 6321 | struct stat st; |
| 6322 | |
| 6323 | /* If save_temps_flag is off, and the HOST_BIT_BUCKET is |
| 6324 | defined, and it is not a directory, and it is |
| 6325 | writable, use it. Otherwise, treat this like any |
| 6326 | other temporary file. */ |
| 6327 | |
| 6328 | if ((!save_temps_flag) |
| 6329 | && (stat (HOST_BIT_BUCKET, buf: &st) == 0) && (!S_ISDIR (st.st_mode)) |
| 6330 | && (access (HOST_BIT_BUCKET, W_OK) == 0)) |
| 6331 | { |
| 6332 | obstack_grow (&obstack, HOST_BIT_BUCKET, |
| 6333 | strlen (HOST_BIT_BUCKET)); |
| 6334 | delete_this_arg = 0; |
| 6335 | arg_going = 1; |
| 6336 | break; |
| 6337 | } |
| 6338 | } |
| 6339 | goto create_temp_file; |
| 6340 | case '|': |
| 6341 | if (use_pipes) |
| 6342 | { |
| 6343 | obstack_1grow (&obstack, '-'); |
| 6344 | delete_this_arg = 0; |
| 6345 | arg_going = 1; |
| 6346 | |
| 6347 | /* consume suffix */ |
| 6348 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
| 6349 | p++; |
| 6350 | if (p[0] == '%' && p[1] == 'O') |
| 6351 | p += 2; |
| 6352 | |
| 6353 | break; |
| 6354 | } |
| 6355 | goto create_temp_file; |
| 6356 | case 'm': |
| 6357 | if (use_pipes) |
| 6358 | { |
| 6359 | /* consume suffix */ |
| 6360 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
| 6361 | p++; |
| 6362 | if (p[0] == '%' && p[1] == 'O') |
| 6363 | p += 2; |
| 6364 | |
| 6365 | break; |
| 6366 | } |
| 6367 | goto create_temp_file; |
| 6368 | case 'g': |
| 6369 | case 'u': |
| 6370 | case 'U': |
| 6371 | create_temp_file: |
| 6372 | { |
| 6373 | struct temp_name *t; |
| 6374 | int suffix_length; |
| 6375 | const char *suffix = p; |
| 6376 | char *saved_suffix = NULL; |
| 6377 | |
| 6378 | while (*p == '.' || ISALNUM ((unsigned char) *p)) |
| 6379 | p++; |
| 6380 | suffix_length = p - suffix; |
| 6381 | if (p[0] == '%' && p[1] == 'O') |
| 6382 | { |
| 6383 | p += 2; |
| 6384 | /* We don't support extra suffix characters after %O. */ |
| 6385 | if (*p == '.' || ISALNUM ((unsigned char) *p)) |
| 6386 | fatal_error (input_location, |
| 6387 | "spec %qs has invalid %<%%0%c%>" , spec, *p); |
| 6388 | if (suffix_length == 0) |
| 6389 | suffix = TARGET_OBJECT_SUFFIX; |
| 6390 | else |
| 6391 | { |
| 6392 | saved_suffix |
| 6393 | = XNEWVEC (char, suffix_length |
| 6394 | + strlen (TARGET_OBJECT_SUFFIX) + 1); |
| 6395 | strncpy (dest: saved_suffix, src: suffix, n: suffix_length); |
| 6396 | strcpy (dest: saved_suffix + suffix_length, |
| 6397 | TARGET_OBJECT_SUFFIX); |
| 6398 | } |
| 6399 | suffix_length += strlen (TARGET_OBJECT_SUFFIX); |
| 6400 | } |
| 6401 | |
| 6402 | if (compare_debug < 0) |
| 6403 | { |
| 6404 | suffix = concat (".gk" , suffix, NULL); |
| 6405 | suffix_length += 3; |
| 6406 | } |
| 6407 | |
| 6408 | /* If -save-temps was specified, use that for the |
| 6409 | temp file. */ |
| 6410 | if (save_temps_flag) |
| 6411 | { |
| 6412 | char *tmp; |
| 6413 | bool adjusted_suffix = false; |
| 6414 | if (suffix_length |
| 6415 | && !outbase_length && !basename_length |
| 6416 | && !dumpdir_trailing_dash_added) |
| 6417 | { |
| 6418 | adjusted_suffix = true; |
| 6419 | suffix++; |
| 6420 | suffix_length--; |
| 6421 | } |
| 6422 | temp_filename_length |
| 6423 | = dumpdir_length + suffix_length + 1; |
| 6424 | if (outbase_length) |
| 6425 | temp_filename_length += outbase_length; |
| 6426 | else |
| 6427 | temp_filename_length += basename_length; |
| 6428 | tmp = (char *) alloca (temp_filename_length); |
| 6429 | if (dumpdir_length) |
| 6430 | memcpy (dest: tmp, src: dumpdir, n: dumpdir_length); |
| 6431 | if (outbase_length) |
| 6432 | memcpy (dest: tmp + dumpdir_length, src: outbase, |
| 6433 | n: outbase_length); |
| 6434 | else if (basename_length) |
| 6435 | memcpy (dest: tmp + dumpdir_length, src: input_basename, |
| 6436 | n: basename_length); |
| 6437 | memcpy (dest: tmp + temp_filename_length - suffix_length - 1, |
| 6438 | src: suffix, n: suffix_length); |
| 6439 | if (adjusted_suffix) |
| 6440 | { |
| 6441 | adjusted_suffix = false; |
| 6442 | suffix--; |
| 6443 | suffix_length++; |
| 6444 | } |
| 6445 | tmp[temp_filename_length - 1] = '\0'; |
| 6446 | temp_filename = tmp; |
| 6447 | |
| 6448 | if (filename_cmp (s1: temp_filename, s2: gcc_input_filename) != 0) |
| 6449 | { |
| 6450 | #ifndef HOST_LACKS_INODE_NUMBERS |
| 6451 | struct stat st_temp; |
| 6452 | |
| 6453 | /* Note, set_input() resets input_stat_set to 0. */ |
| 6454 | if (input_stat_set == 0) |
| 6455 | { |
| 6456 | input_stat_set = stat (file: gcc_input_filename, |
| 6457 | buf: &input_stat); |
| 6458 | if (input_stat_set >= 0) |
| 6459 | input_stat_set = 1; |
| 6460 | } |
| 6461 | |
| 6462 | /* If we have the stat for the gcc_input_filename |
| 6463 | and we can do the stat for the temp_filename |
| 6464 | then the they could still refer to the same |
| 6465 | file if st_dev/st_ino's are the same. */ |
| 6466 | if (input_stat_set != 1 |
| 6467 | || stat (file: temp_filename, buf: &st_temp) < 0 |
| 6468 | || input_stat.st_dev != st_temp.st_dev |
| 6469 | || input_stat.st_ino != st_temp.st_ino) |
| 6470 | #else |
| 6471 | /* Just compare canonical pathnames. */ |
| 6472 | char* input_realname = lrealpath (gcc_input_filename); |
| 6473 | char* temp_realname = lrealpath (temp_filename); |
| 6474 | bool files_differ = filename_cmp (input_realname, temp_realname); |
| 6475 | free (input_realname); |
| 6476 | free (temp_realname); |
| 6477 | if (files_differ) |
| 6478 | #endif |
| 6479 | { |
| 6480 | temp_filename |
| 6481 | = save_string (temp_filename, |
| 6482 | temp_filename_length - 1); |
| 6483 | obstack_grow (&obstack, temp_filename, |
| 6484 | temp_filename_length); |
| 6485 | arg_going = 1; |
| 6486 | delete_this_arg = 0; |
| 6487 | break; |
| 6488 | } |
| 6489 | } |
| 6490 | } |
| 6491 | |
| 6492 | /* See if we already have an association of %g/%u/%U and |
| 6493 | suffix. */ |
| 6494 | for (t = temp_names; t; t = t->next) |
| 6495 | if (t->length == suffix_length |
| 6496 | && strncmp (s1: t->suffix, s2: suffix, n: suffix_length) == 0 |
| 6497 | && t->unique == (c == 'u' || c == 'U' || c == 'j')) |
| 6498 | break; |
| 6499 | |
| 6500 | /* Make a new association if needed. %u and %j |
| 6501 | require one. */ |
| 6502 | if (t == 0 || c == 'u' || c == 'j') |
| 6503 | { |
| 6504 | if (t == 0) |
| 6505 | { |
| 6506 | t = XNEW (struct temp_name); |
| 6507 | t->next = temp_names; |
| 6508 | temp_names = t; |
| 6509 | } |
| 6510 | t->length = suffix_length; |
| 6511 | if (saved_suffix) |
| 6512 | { |
| 6513 | t->suffix = saved_suffix; |
| 6514 | saved_suffix = NULL; |
| 6515 | } |
| 6516 | else |
| 6517 | t->suffix = save_string (suffix, suffix_length); |
| 6518 | t->unique = (c == 'u' || c == 'U' || c == 'j'); |
| 6519 | temp_filename = make_temp_file (t->suffix); |
| 6520 | temp_filename_length = strlen (s: temp_filename); |
| 6521 | t->filename = temp_filename; |
| 6522 | t->filename_length = temp_filename_length; |
| 6523 | } |
| 6524 | |
| 6525 | free (ptr: saved_suffix); |
| 6526 | |
| 6527 | obstack_grow (&obstack, t->filename, t->filename_length); |
| 6528 | delete_this_arg = 1; |
| 6529 | } |
| 6530 | arg_going = 1; |
| 6531 | break; |
| 6532 | |
| 6533 | case 'i': |
| 6534 | if (combine_inputs) |
| 6535 | { |
| 6536 | /* We are going to expand `%i' into `@FILE', where FILE |
| 6537 | is a newly-created temporary filename. The filenames |
| 6538 | that would usually be expanded in place of %o will be |
| 6539 | written to the temporary file. */ |
| 6540 | if (at_file_supplied) |
| 6541 | open_at_file (); |
| 6542 | |
| 6543 | for (i = 0; (int) i < n_infiles; i++) |
| 6544 | if (compile_input_file_p (infile: &infiles[i])) |
| 6545 | { |
| 6546 | store_arg (arg: infiles[i].name, delete_always: 0, delete_failure: 0); |
| 6547 | infiles[i].compiled = true; |
| 6548 | } |
| 6549 | |
| 6550 | if (at_file_supplied) |
| 6551 | close_at_file (); |
| 6552 | } |
| 6553 | else |
| 6554 | { |
| 6555 | obstack_grow (&obstack, gcc_input_filename, |
| 6556 | input_filename_length); |
| 6557 | arg_going = 1; |
| 6558 | } |
| 6559 | break; |
| 6560 | |
| 6561 | case 'I': |
| 6562 | { |
| 6563 | struct spec_path_info info; |
| 6564 | |
| 6565 | if (multilib_dir) |
| 6566 | { |
| 6567 | do_spec_1 (spec: "-imultilib" , inswitch: 1, NULL); |
| 6568 | /* Make this a separate argument. */ |
| 6569 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6570 | do_spec_1 (spec: multilib_dir, inswitch: 1, NULL); |
| 6571 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6572 | } |
| 6573 | |
| 6574 | if (multiarch_dir) |
| 6575 | { |
| 6576 | do_spec_1 (spec: "-imultiarch" , inswitch: 1, NULL); |
| 6577 | /* Make this a separate argument. */ |
| 6578 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6579 | do_spec_1 (spec: multiarch_dir, inswitch: 1, NULL); |
| 6580 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6581 | } |
| 6582 | |
| 6583 | if (gcc_exec_prefix) |
| 6584 | { |
| 6585 | do_spec_1 (spec: "-iprefix" , inswitch: 1, NULL); |
| 6586 | /* Make this a separate argument. */ |
| 6587 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6588 | do_spec_1 (spec: gcc_exec_prefix, inswitch: 1, NULL); |
| 6589 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6590 | } |
| 6591 | |
| 6592 | if (target_system_root_changed || |
| 6593 | (target_system_root && target_sysroot_hdrs_suffix)) |
| 6594 | { |
| 6595 | do_spec_1 (spec: "-isysroot" , inswitch: 1, NULL); |
| 6596 | /* Make this a separate argument. */ |
| 6597 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6598 | do_spec_1 (spec: target_system_root, inswitch: 1, NULL); |
| 6599 | if (target_sysroot_hdrs_suffix) |
| 6600 | do_spec_1 (spec: target_sysroot_hdrs_suffix, inswitch: 1, NULL); |
| 6601 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6602 | } |
| 6603 | |
| 6604 | info.option = "-isystem" ; |
| 6605 | info.append = "include" ; |
| 6606 | info.append_len = strlen (s: info.append); |
| 6607 | info.omit_relative = false; |
| 6608 | info.separate_options = true; |
| 6609 | info.realpaths = false; |
| 6610 | |
| 6611 | for_each_path (paths: &include_prefixes, do_multi: false, extra_space: info.append_len, |
| 6612 | callback: spec_path, callback_info: &info); |
| 6613 | |
| 6614 | info.append = "include-fixed" ; |
| 6615 | if (*sysroot_hdrs_suffix_spec) |
| 6616 | info.append = concat (info.append, dir_separator_str, |
| 6617 | multilib_dir, NULL); |
| 6618 | else if (multiarch_dir) |
| 6619 | { |
| 6620 | /* For multiarch, search include-fixed/<multiarch-dir> |
| 6621 | before include-fixed. */ |
| 6622 | info.append = concat (info.append, dir_separator_str, |
| 6623 | multiarch_dir, NULL); |
| 6624 | info.append_len = strlen (s: info.append); |
| 6625 | for_each_path (paths: &include_prefixes, do_multi: false, extra_space: info.append_len, |
| 6626 | callback: spec_path, callback_info: &info); |
| 6627 | |
| 6628 | info.append = "include-fixed" ; |
| 6629 | } |
| 6630 | info.append_len = strlen (s: info.append); |
| 6631 | for_each_path (paths: &include_prefixes, do_multi: false, extra_space: info.append_len, |
| 6632 | callback: spec_path, callback_info: &info); |
| 6633 | } |
| 6634 | break; |
| 6635 | |
| 6636 | case 'o': |
| 6637 | /* We are going to expand `%o' into `@FILE', where FILE |
| 6638 | is a newly-created temporary filename. The filenames |
| 6639 | that would usually be expanded in place of %o will be |
| 6640 | written to the temporary file. */ |
| 6641 | if (at_file_supplied) |
| 6642 | open_at_file (); |
| 6643 | |
| 6644 | for (i = 0; i < n_infiles + lang_specific_extra_outfiles; i++) |
| 6645 | if (outfiles[i]) |
| 6646 | store_arg (arg: outfiles[i], delete_always: 0, delete_failure: 0); |
| 6647 | |
| 6648 | if (at_file_supplied) |
| 6649 | close_at_file (); |
| 6650 | break; |
| 6651 | |
| 6652 | case 'O': |
| 6653 | obstack_grow (&obstack, TARGET_OBJECT_SUFFIX, strlen (TARGET_OBJECT_SUFFIX)); |
| 6654 | arg_going = 1; |
| 6655 | break; |
| 6656 | |
| 6657 | case 's': |
| 6658 | this_is_library_file = 1; |
| 6659 | break; |
| 6660 | |
| 6661 | case 'T': |
| 6662 | this_is_linker_script = 1; |
| 6663 | break; |
| 6664 | |
| 6665 | case 'V': |
| 6666 | outfiles[input_file_number] = NULL; |
| 6667 | break; |
| 6668 | |
| 6669 | case 'w': |
| 6670 | this_is_output_file = 1; |
| 6671 | break; |
| 6672 | |
| 6673 | case 'W': |
| 6674 | { |
| 6675 | unsigned int cur_index = argbuf.length (); |
| 6676 | /* Handle the {...} following the %W. */ |
| 6677 | if (*p != '{') |
| 6678 | fatal_error (input_location, |
| 6679 | "spec %qs has invalid %<%%W%c%>" , spec, *p); |
| 6680 | p = handle_braces (p + 1); |
| 6681 | if (p == 0) |
| 6682 | return -1; |
| 6683 | end_going_arg (); |
| 6684 | /* If any args were output, mark the last one for deletion |
| 6685 | on failure. */ |
| 6686 | if (argbuf.length () != cur_index) |
| 6687 | record_temp_file (filename: argbuf.last (), always_delete: 0, fail_delete: 1); |
| 6688 | break; |
| 6689 | } |
| 6690 | |
| 6691 | case '@': |
| 6692 | /* Handle the {...} following the %@. */ |
| 6693 | if (*p != '{') |
| 6694 | fatal_error (input_location, |
| 6695 | "spec %qs has invalid %<%%@%c%>" , spec, *p); |
| 6696 | if (at_file_supplied) |
| 6697 | open_at_file (); |
| 6698 | p = handle_braces (p + 1); |
| 6699 | if (at_file_supplied) |
| 6700 | close_at_file (); |
| 6701 | if (p == 0) |
| 6702 | return -1; |
| 6703 | break; |
| 6704 | |
| 6705 | /* %x{OPTION} records OPTION for %X to output. */ |
| 6706 | case 'x': |
| 6707 | { |
| 6708 | const char *p1 = p; |
| 6709 | char *string; |
| 6710 | |
| 6711 | /* Skip past the option value and make a copy. */ |
| 6712 | if (*p != '{') |
| 6713 | fatal_error (input_location, |
| 6714 | "spec %qs has invalid %<%%x%c%>" , spec, *p); |
| 6715 | while (*p++ != '}') |
| 6716 | ; |
| 6717 | string = save_string (p1 + 1, p - p1 - 2); |
| 6718 | |
| 6719 | /* See if we already recorded this option. */ |
| 6720 | for (const char *opt : linker_options) |
| 6721 | if (! strcmp (s1: string, s2: opt)) |
| 6722 | { |
| 6723 | free (ptr: string); |
| 6724 | return 0; |
| 6725 | } |
| 6726 | |
| 6727 | /* This option is new; add it. */ |
| 6728 | add_linker_option (option: string, len: strlen (s: string)); |
| 6729 | free (ptr: string); |
| 6730 | } |
| 6731 | break; |
| 6732 | |
| 6733 | /* Dump out the options accumulated previously using %x. */ |
| 6734 | case 'X': |
| 6735 | do_specs_vec (vec: linker_options); |
| 6736 | break; |
| 6737 | |
| 6738 | /* Dump out the options accumulated previously using -Wa,. */ |
| 6739 | case 'Y': |
| 6740 | do_specs_vec (vec: assembler_options); |
| 6741 | break; |
| 6742 | |
| 6743 | /* Dump out the options accumulated previously using -Wp,. */ |
| 6744 | case 'Z': |
| 6745 | do_specs_vec (vec: preprocessor_options); |
| 6746 | break; |
| 6747 | |
| 6748 | /* Here are digits and numbers that just process |
| 6749 | a certain constant string as a spec. */ |
| 6750 | |
| 6751 | case '1': |
| 6752 | value = do_spec_1 (spec: cc1_spec, inswitch: 0, NULL); |
| 6753 | if (value != 0) |
| 6754 | return value; |
| 6755 | break; |
| 6756 | |
| 6757 | case '2': |
| 6758 | value = do_spec_1 (spec: cc1plus_spec, inswitch: 0, NULL); |
| 6759 | if (value != 0) |
| 6760 | return value; |
| 6761 | break; |
| 6762 | |
| 6763 | case 'a': |
| 6764 | value = do_spec_1 (spec: asm_spec, inswitch: 0, NULL); |
| 6765 | if (value != 0) |
| 6766 | return value; |
| 6767 | break; |
| 6768 | |
| 6769 | case 'A': |
| 6770 | value = do_spec_1 (spec: asm_final_spec, inswitch: 0, NULL); |
| 6771 | if (value != 0) |
| 6772 | return value; |
| 6773 | break; |
| 6774 | |
| 6775 | case 'C': |
| 6776 | { |
| 6777 | const char *const spec |
| 6778 | = (input_file_compiler->cpp_spec |
| 6779 | ? input_file_compiler->cpp_spec |
| 6780 | : cpp_spec); |
| 6781 | value = do_spec_1 (spec, inswitch: 0, NULL); |
| 6782 | if (value != 0) |
| 6783 | return value; |
| 6784 | } |
| 6785 | break; |
| 6786 | |
| 6787 | case 'E': |
| 6788 | value = do_spec_1 (spec: endfile_spec, inswitch: 0, NULL); |
| 6789 | if (value != 0) |
| 6790 | return value; |
| 6791 | break; |
| 6792 | |
| 6793 | case 'l': |
| 6794 | value = do_spec_1 (spec: link_spec, inswitch: 0, NULL); |
| 6795 | if (value != 0) |
| 6796 | return value; |
| 6797 | break; |
| 6798 | |
| 6799 | case 'L': |
| 6800 | value = do_spec_1 (spec: lib_spec, inswitch: 0, NULL); |
| 6801 | if (value != 0) |
| 6802 | return value; |
| 6803 | break; |
| 6804 | |
| 6805 | case 'M': |
| 6806 | if (multilib_os_dir == NULL) |
| 6807 | obstack_1grow (&obstack, '.'); |
| 6808 | else |
| 6809 | obstack_grow (&obstack, multilib_os_dir, |
| 6810 | strlen (multilib_os_dir)); |
| 6811 | break; |
| 6812 | |
| 6813 | case 'G': |
| 6814 | value = do_spec_1 (spec: libgcc_spec, inswitch: 0, NULL); |
| 6815 | if (value != 0) |
| 6816 | return value; |
| 6817 | break; |
| 6818 | |
| 6819 | case 'R': |
| 6820 | /* We assume there is a directory |
| 6821 | separator at the end of this string. */ |
| 6822 | if (target_system_root) |
| 6823 | { |
| 6824 | obstack_grow (&obstack, target_system_root, |
| 6825 | strlen (target_system_root)); |
| 6826 | if (target_sysroot_suffix) |
| 6827 | obstack_grow (&obstack, target_sysroot_suffix, |
| 6828 | strlen (target_sysroot_suffix)); |
| 6829 | } |
| 6830 | break; |
| 6831 | |
| 6832 | case 'S': |
| 6833 | value = do_spec_1 (spec: startfile_spec, inswitch: 0, NULL); |
| 6834 | if (value != 0) |
| 6835 | return value; |
| 6836 | break; |
| 6837 | |
| 6838 | /* Here we define characters other than letters and digits. */ |
| 6839 | |
| 6840 | case '{': |
| 6841 | p = handle_braces (p); |
| 6842 | if (p == 0) |
| 6843 | return -1; |
| 6844 | break; |
| 6845 | |
| 6846 | case ':': |
| 6847 | p = handle_spec_function (p, NULL, soft_matched_part); |
| 6848 | if (p == 0) |
| 6849 | return -1; |
| 6850 | break; |
| 6851 | |
| 6852 | case '%': |
| 6853 | obstack_1grow (&obstack, '%'); |
| 6854 | break; |
| 6855 | |
| 6856 | case '.': |
| 6857 | { |
| 6858 | unsigned len = 0; |
| 6859 | |
| 6860 | while (p[len] && p[len] != ' ' && p[len] != '%') |
| 6861 | len++; |
| 6862 | suffix_subst = save_string (p - 1, len + 1); |
| 6863 | p += len; |
| 6864 | } |
| 6865 | break; |
| 6866 | |
| 6867 | /* Henceforth ignore the option(s) matching the pattern |
| 6868 | after the %<. */ |
| 6869 | case '<': |
| 6870 | case '>': |
| 6871 | { |
| 6872 | unsigned len = 0; |
| 6873 | int have_wildcard = 0; |
| 6874 | int i; |
| 6875 | int switch_option; |
| 6876 | |
| 6877 | if (c == '>') |
| 6878 | switch_option = SWITCH_IGNORE | SWITCH_KEEP_FOR_GCC; |
| 6879 | else |
| 6880 | switch_option = SWITCH_IGNORE; |
| 6881 | |
| 6882 | while (p[len] && p[len] != ' ' && p[len] != '\t') |
| 6883 | len++; |
| 6884 | |
| 6885 | if (p[len-1] == '*') |
| 6886 | have_wildcard = 1; |
| 6887 | |
| 6888 | for (i = 0; i < n_switches; i++) |
| 6889 | if (!strncmp (s1: switches[i].part1, s2: p, n: len - have_wildcard) |
| 6890 | && (have_wildcard || switches[i].part1[len] == '\0')) |
| 6891 | { |
| 6892 | switches[i].live_cond |= switch_option; |
| 6893 | /* User switch be validated from validate_all_switches. |
| 6894 | when the definition is seen from the spec file. |
| 6895 | If not defined anywhere, will be rejected. */ |
| 6896 | if (switches[i].known) |
| 6897 | switches[i].validated = true; |
| 6898 | } |
| 6899 | |
| 6900 | p += len; |
| 6901 | } |
| 6902 | break; |
| 6903 | |
| 6904 | case '*': |
| 6905 | if (soft_matched_part) |
| 6906 | { |
| 6907 | if (soft_matched_part[0]) |
| 6908 | do_spec_1 (spec: soft_matched_part, inswitch: 1, NULL); |
| 6909 | /* Only insert a space after the substitution if it is at the |
| 6910 | end of the current sequence. So if: |
| 6911 | |
| 6912 | "%{foo=*:bar%*}%{foo=*:one%*two}" |
| 6913 | |
| 6914 | matches -foo=hello then it will produce: |
| 6915 | |
| 6916 | barhello onehellotwo |
| 6917 | */ |
| 6918 | if (*p == 0 || *p == '}') |
| 6919 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 6920 | } |
| 6921 | else |
| 6922 | /* Catch the case where a spec string contains something like |
| 6923 | '%{foo:%*}'. i.e. there is no * in the pattern on the left |
| 6924 | hand side of the :. */ |
| 6925 | error ("spec failure: %<%%*%> has not been initialized by pattern match" ); |
| 6926 | break; |
| 6927 | |
| 6928 | /* Process a string found as the value of a spec given by name. |
| 6929 | This feature allows individual machine descriptions |
| 6930 | to add and use their own specs. */ |
| 6931 | case '(': |
| 6932 | { |
| 6933 | const char *name = p; |
| 6934 | struct spec_list *sl; |
| 6935 | int len; |
| 6936 | |
| 6937 | /* The string after the S/P is the name of a spec that is to be |
| 6938 | processed. */ |
| 6939 | while (*p && *p != ')') |
| 6940 | p++; |
| 6941 | |
| 6942 | /* See if it's in the list. */ |
| 6943 | for (len = p - name, sl = specs; sl; sl = sl->next) |
| 6944 | if (sl->name_len == len && !strncmp (s1: sl->name, s2: name, n: len)) |
| 6945 | { |
| 6946 | name = *(sl->ptr_spec); |
| 6947 | #ifdef DEBUG_SPECS |
| 6948 | fnotice (stderr, "Processing spec (%s), which is '%s'\n" , |
| 6949 | sl->name, name); |
| 6950 | #endif |
| 6951 | break; |
| 6952 | } |
| 6953 | |
| 6954 | if (sl) |
| 6955 | { |
| 6956 | value = do_spec_1 (spec: name, inswitch: 0, NULL); |
| 6957 | if (value != 0) |
| 6958 | return value; |
| 6959 | } |
| 6960 | |
| 6961 | /* Discard the closing paren. */ |
| 6962 | if (*p) |
| 6963 | p++; |
| 6964 | } |
| 6965 | break; |
| 6966 | |
| 6967 | case '"': |
| 6968 | /* End a previous argument, if there is one, then issue an |
| 6969 | empty argument. */ |
| 6970 | end_going_arg (); |
| 6971 | arg_going = 1; |
| 6972 | end_going_arg (); |
| 6973 | break; |
| 6974 | |
| 6975 | default: |
| 6976 | error ("spec failure: unrecognized spec option %qc" , c); |
| 6977 | break; |
| 6978 | } |
| 6979 | break; |
| 6980 | |
| 6981 | case '\\': |
| 6982 | /* Backslash: treat next character as ordinary. */ |
| 6983 | c = *p++; |
| 6984 | |
| 6985 | /* When adding more cases that previously matched default, make |
| 6986 | sure to adjust quote_spec_char_p as well. */ |
| 6987 | |
| 6988 | /* Fall through. */ |
| 6989 | default: |
| 6990 | /* Ordinary character: put it into the current argument. */ |
| 6991 | obstack_1grow (&obstack, c); |
| 6992 | arg_going = 1; |
| 6993 | } |
| 6994 | |
| 6995 | /* End of string. If we are processing a spec function, we need to |
| 6996 | end any pending argument. */ |
| 6997 | if (processing_spec_function) |
| 6998 | end_going_arg (); |
| 6999 | |
| 7000 | return 0; |
| 7001 | } |
| 7002 | |
| 7003 | /* Look up a spec function. */ |
| 7004 | |
| 7005 | static const struct spec_function * |
| 7006 | lookup_spec_function (const char *name) |
| 7007 | { |
| 7008 | const struct spec_function *sf; |
| 7009 | |
| 7010 | for (sf = static_spec_functions; sf->name != NULL; sf++) |
| 7011 | if (strcmp (s1: sf->name, s2: name) == 0) |
| 7012 | return sf; |
| 7013 | |
| 7014 | return NULL; |
| 7015 | } |
| 7016 | |
| 7017 | /* Evaluate a spec function. */ |
| 7018 | |
| 7019 | static const char * |
| 7020 | eval_spec_function (const char *func, const char *args, |
| 7021 | const char *soft_matched_part) |
| 7022 | { |
| 7023 | const struct spec_function *sf; |
| 7024 | const char *funcval; |
| 7025 | |
| 7026 | /* Saved spec processing context. */ |
| 7027 | vec<const_char_p> save_argbuf; |
| 7028 | |
| 7029 | int save_arg_going; |
| 7030 | int save_delete_this_arg; |
| 7031 | int save_this_is_output_file; |
| 7032 | int save_this_is_library_file; |
| 7033 | int save_input_from_pipe; |
| 7034 | int save_this_is_linker_script; |
| 7035 | const char *save_suffix_subst; |
| 7036 | |
| 7037 | int save_growing_size; |
| 7038 | void *save_growing_value = NULL; |
| 7039 | |
| 7040 | sf = lookup_spec_function (name: func); |
| 7041 | if (sf == NULL) |
| 7042 | fatal_error (input_location, "unknown spec function %qs" , func); |
| 7043 | |
| 7044 | /* Push the spec processing context. */ |
| 7045 | save_argbuf = argbuf; |
| 7046 | |
| 7047 | save_arg_going = arg_going; |
| 7048 | save_delete_this_arg = delete_this_arg; |
| 7049 | save_this_is_output_file = this_is_output_file; |
| 7050 | save_this_is_library_file = this_is_library_file; |
| 7051 | save_this_is_linker_script = this_is_linker_script; |
| 7052 | save_input_from_pipe = input_from_pipe; |
| 7053 | save_suffix_subst = suffix_subst; |
| 7054 | |
| 7055 | /* If we have some object growing now, finalize it so the args and function |
| 7056 | eval proceed from a cleared context. This is needed to prevent the first |
| 7057 | constructed arg from mistakenly including the growing value. We'll push |
| 7058 | this value back on the obstack once the function evaluation is done, to |
| 7059 | restore a consistent processing context for our caller. This is fine as |
| 7060 | the address of growing objects isn't guaranteed to remain stable until |
| 7061 | they are finalized, and we expect this situation to be rare enough for |
| 7062 | the extra copy not to be an issue. */ |
| 7063 | save_growing_size = obstack_object_size (&obstack); |
| 7064 | if (save_growing_size > 0) |
| 7065 | save_growing_value = obstack_finish (&obstack); |
| 7066 | |
| 7067 | /* Create a new spec processing context, and build the function |
| 7068 | arguments. */ |
| 7069 | |
| 7070 | alloc_args (); |
| 7071 | if (do_spec_2 (spec: args, soft_matched_part) < 0) |
| 7072 | fatal_error (input_location, "error in arguments to spec function %qs" , |
| 7073 | func); |
| 7074 | |
| 7075 | /* argbuf_index is an index for the next argument to be inserted, and |
| 7076 | so contains the count of the args already inserted. */ |
| 7077 | |
| 7078 | funcval = (*sf->func) (argbuf.length (), |
| 7079 | argbuf.address ()); |
| 7080 | |
| 7081 | /* Pop the spec processing context. */ |
| 7082 | argbuf.release (); |
| 7083 | argbuf = save_argbuf; |
| 7084 | |
| 7085 | arg_going = save_arg_going; |
| 7086 | delete_this_arg = save_delete_this_arg; |
| 7087 | this_is_output_file = save_this_is_output_file; |
| 7088 | this_is_library_file = save_this_is_library_file; |
| 7089 | this_is_linker_script = save_this_is_linker_script; |
| 7090 | input_from_pipe = save_input_from_pipe; |
| 7091 | suffix_subst = save_suffix_subst; |
| 7092 | |
| 7093 | if (save_growing_size > 0) |
| 7094 | obstack_grow (&obstack, save_growing_value, save_growing_size); |
| 7095 | |
| 7096 | return funcval; |
| 7097 | } |
| 7098 | |
| 7099 | /* Handle a spec function call of the form: |
| 7100 | |
| 7101 | %:function(args) |
| 7102 | |
| 7103 | ARGS is processed as a spec in a separate context and split into an |
| 7104 | argument vector in the normal fashion. The function returns a string |
| 7105 | containing a spec which we then process in the caller's context, or |
| 7106 | NULL if no processing is required. |
| 7107 | |
| 7108 | If RETVAL_NONNULL is not NULL, then store a bool whether function |
| 7109 | returned non-NULL. |
| 7110 | |
| 7111 | SOFT_MATCHED_PART holds the current value of a matched * pattern, which |
| 7112 | may be re-expanded with a %* as part of the function arguments. */ |
| 7113 | |
| 7114 | static const char * |
| 7115 | handle_spec_function (const char *p, bool *retval_nonnull, |
| 7116 | const char *soft_matched_part) |
| 7117 | { |
| 7118 | char *func, *args; |
| 7119 | const char *endp, *funcval; |
| 7120 | int count; |
| 7121 | |
| 7122 | processing_spec_function++; |
| 7123 | |
| 7124 | /* Get the function name. */ |
| 7125 | for (endp = p; *endp != '\0'; endp++) |
| 7126 | { |
| 7127 | if (*endp == '(') /* ) */ |
| 7128 | break; |
| 7129 | /* Only allow [A-Za-z0-9], -, and _ in function names. */ |
| 7130 | if (!ISALNUM (*endp) && !(*endp == '-' || *endp == '_')) |
| 7131 | fatal_error (input_location, "malformed spec function name" ); |
| 7132 | } |
| 7133 | if (*endp != '(') /* ) */ |
| 7134 | fatal_error (input_location, "no arguments for spec function" ); |
| 7135 | func = save_string (p, endp - p); |
| 7136 | p = ++endp; |
| 7137 | |
| 7138 | /* Get the arguments. */ |
| 7139 | for (count = 0; *endp != '\0'; endp++) |
| 7140 | { |
| 7141 | /* ( */ |
| 7142 | if (*endp == ')') |
| 7143 | { |
| 7144 | if (count == 0) |
| 7145 | break; |
| 7146 | count--; |
| 7147 | } |
| 7148 | else if (*endp == '(') /* ) */ |
| 7149 | count++; |
| 7150 | } |
| 7151 | /* ( */ |
| 7152 | if (*endp != ')') |
| 7153 | fatal_error (input_location, "malformed spec function arguments" ); |
| 7154 | args = save_string (p, endp - p); |
| 7155 | p = ++endp; |
| 7156 | |
| 7157 | /* p now points to just past the end of the spec function expression. */ |
| 7158 | |
| 7159 | funcval = eval_spec_function (func, args, soft_matched_part); |
| 7160 | if (funcval != NULL && do_spec_1 (spec: funcval, inswitch: 0, NULL) < 0) |
| 7161 | p = NULL; |
| 7162 | if (retval_nonnull) |
| 7163 | *retval_nonnull = funcval != NULL; |
| 7164 | |
| 7165 | free (ptr: func); |
| 7166 | free (ptr: args); |
| 7167 | |
| 7168 | processing_spec_function--; |
| 7169 | |
| 7170 | return p; |
| 7171 | } |
| 7172 | |
| 7173 | /* Inline subroutine of handle_braces. Returns true if the current |
| 7174 | input suffix matches the atom bracketed by ATOM and END_ATOM. */ |
| 7175 | static inline bool |
| 7176 | input_suffix_matches (const char *atom, const char *end_atom) |
| 7177 | { |
| 7178 | return (input_suffix |
| 7179 | && !strncmp (s1: input_suffix, s2: atom, n: end_atom - atom) |
| 7180 | && input_suffix[end_atom - atom] == '\0'); |
| 7181 | } |
| 7182 | |
| 7183 | /* Subroutine of handle_braces. Returns true if the current |
| 7184 | input file's spec name matches the atom bracketed by ATOM and END_ATOM. */ |
| 7185 | static bool |
| 7186 | input_spec_matches (const char *atom, const char *end_atom) |
| 7187 | { |
| 7188 | return (input_file_compiler |
| 7189 | && input_file_compiler->suffix |
| 7190 | && input_file_compiler->suffix[0] != '\0' |
| 7191 | && !strncmp (s1: input_file_compiler->suffix + 1, s2: atom, |
| 7192 | n: end_atom - atom) |
| 7193 | && input_file_compiler->suffix[end_atom - atom + 1] == '\0'); |
| 7194 | } |
| 7195 | |
| 7196 | /* Subroutine of handle_braces. Returns true if a switch |
| 7197 | matching the atom bracketed by ATOM and END_ATOM appeared on the |
| 7198 | command line. */ |
| 7199 | static bool |
| 7200 | switch_matches (const char *atom, const char *end_atom, int starred) |
| 7201 | { |
| 7202 | int i; |
| 7203 | int len = end_atom - atom; |
| 7204 | int plen = starred ? len : -1; |
| 7205 | |
| 7206 | for (i = 0; i < n_switches; i++) |
| 7207 | if (!strncmp (s1: switches[i].part1, s2: atom, n: len) |
| 7208 | && (starred || switches[i].part1[len] == '\0') |
| 7209 | && check_live_switch (i, plen)) |
| 7210 | return true; |
| 7211 | |
| 7212 | /* Check if a switch with separated form matching the atom. |
| 7213 | We check -D and -U switches. */ |
| 7214 | else if (switches[i].args != 0) |
| 7215 | { |
| 7216 | if ((*switches[i].part1 == 'D' || *switches[i].part1 == 'U') |
| 7217 | && *switches[i].part1 == atom[0]) |
| 7218 | { |
| 7219 | if (!strncmp (s1: switches[i].args[0], s2: &atom[1], n: len - 1) |
| 7220 | && (starred || (switches[i].part1[1] == '\0' |
| 7221 | && switches[i].args[0][len - 1] == '\0')) |
| 7222 | && check_live_switch (i, (starred ? 1 : -1))) |
| 7223 | return true; |
| 7224 | } |
| 7225 | } |
| 7226 | |
| 7227 | return false; |
| 7228 | } |
| 7229 | |
| 7230 | /* Inline subroutine of handle_braces. Mark all of the switches which |
| 7231 | match ATOM (extends to END_ATOM; STARRED indicates whether there |
| 7232 | was a star after the atom) for later processing. */ |
| 7233 | static inline void |
| 7234 | mark_matching_switches (const char *atom, const char *end_atom, int starred) |
| 7235 | { |
| 7236 | int i; |
| 7237 | int len = end_atom - atom; |
| 7238 | int plen = starred ? len : -1; |
| 7239 | |
| 7240 | for (i = 0; i < n_switches; i++) |
| 7241 | if (!strncmp (s1: switches[i].part1, s2: atom, n: len) |
| 7242 | && (starred || switches[i].part1[len] == '\0') |
| 7243 | && check_live_switch (i, plen)) |
| 7244 | switches[i].ordering = 1; |
| 7245 | } |
| 7246 | |
| 7247 | /* Inline subroutine of handle_braces. Process all the currently |
| 7248 | marked switches through give_switch, and clear the marks. */ |
| 7249 | static inline void |
| 7250 | process_marked_switches (void) |
| 7251 | { |
| 7252 | int i; |
| 7253 | |
| 7254 | for (i = 0; i < n_switches; i++) |
| 7255 | if (switches[i].ordering == 1) |
| 7256 | { |
| 7257 | switches[i].ordering = 0; |
| 7258 | give_switch (i, 0); |
| 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | /* Handle a %{ ... } construct. P points just inside the leading {. |
| 7263 | Returns a pointer one past the end of the brace block, or 0 |
| 7264 | if we call do_spec_1 and that returns -1. */ |
| 7265 | |
| 7266 | static const char * |
| 7267 | handle_braces (const char *p) |
| 7268 | { |
| 7269 | const char *atom, *end_atom; |
| 7270 | const char *d_atom = NULL, *d_end_atom = NULL; |
| 7271 | char *esc_buf = NULL, *d_esc_buf = NULL; |
| 7272 | int esc; |
| 7273 | const char *orig = p; |
| 7274 | |
| 7275 | bool a_is_suffix; |
| 7276 | bool a_is_spectype; |
| 7277 | bool a_is_starred; |
| 7278 | bool a_is_negated; |
| 7279 | bool a_matched; |
| 7280 | |
| 7281 | bool a_must_be_last = false; |
| 7282 | bool ordered_set = false; |
| 7283 | bool disjunct_set = false; |
| 7284 | bool disj_matched = false; |
| 7285 | bool disj_starred = true; |
| 7286 | bool n_way_choice = false; |
| 7287 | bool n_way_matched = false; |
| 7288 | |
| 7289 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
| 7290 | |
| 7291 | do |
| 7292 | { |
| 7293 | if (a_must_be_last) |
| 7294 | goto invalid; |
| 7295 | |
| 7296 | /* Scan one "atom" (S in the description above of %{}, possibly |
| 7297 | with '!', '.', '@', ',', or '*' modifiers). */ |
| 7298 | a_matched = false; |
| 7299 | a_is_suffix = false; |
| 7300 | a_is_starred = false; |
| 7301 | a_is_negated = false; |
| 7302 | a_is_spectype = false; |
| 7303 | |
| 7304 | SKIP_WHITE (); |
| 7305 | if (*p == '!') |
| 7306 | p++, a_is_negated = true; |
| 7307 | |
| 7308 | SKIP_WHITE (); |
| 7309 | if (*p == '%' && p[1] == ':') |
| 7310 | { |
| 7311 | atom = NULL; |
| 7312 | end_atom = NULL; |
| 7313 | p = handle_spec_function (p: p + 2, retval_nonnull: &a_matched, NULL); |
| 7314 | } |
| 7315 | else |
| 7316 | { |
| 7317 | if (*p == '.') |
| 7318 | p++, a_is_suffix = true; |
| 7319 | else if (*p == ',') |
| 7320 | p++, a_is_spectype = true; |
| 7321 | |
| 7322 | atom = p; |
| 7323 | esc = 0; |
| 7324 | while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '=' |
| 7325 | || *p == ',' || *p == '.' || *p == '@' || *p == '\\') |
| 7326 | { |
| 7327 | if (*p == '\\') |
| 7328 | { |
| 7329 | p++; |
| 7330 | if (!*p) |
| 7331 | fatal_error (input_location, |
| 7332 | "braced spec %qs ends in escape" , orig); |
| 7333 | esc++; |
| 7334 | } |
| 7335 | p++; |
| 7336 | } |
| 7337 | end_atom = p; |
| 7338 | |
| 7339 | if (esc) |
| 7340 | { |
| 7341 | const char *ap; |
| 7342 | char *ep; |
| 7343 | |
| 7344 | if (esc_buf && esc_buf != d_esc_buf) |
| 7345 | free (ptr: esc_buf); |
| 7346 | esc_buf = NULL; |
| 7347 | ep = esc_buf = (char *) xmalloc (end_atom - atom - esc + 1); |
| 7348 | for (ap = atom; ap != end_atom; ap++, ep++) |
| 7349 | { |
| 7350 | if (*ap == '\\') |
| 7351 | ap++; |
| 7352 | *ep = *ap; |
| 7353 | } |
| 7354 | *ep = '\0'; |
| 7355 | atom = esc_buf; |
| 7356 | end_atom = ep; |
| 7357 | } |
| 7358 | |
| 7359 | if (*p == '*') |
| 7360 | p++, a_is_starred = 1; |
| 7361 | } |
| 7362 | |
| 7363 | SKIP_WHITE (); |
| 7364 | switch (*p) |
| 7365 | { |
| 7366 | case '&': case '}': |
| 7367 | /* Substitute the switch(es) indicated by the current atom. */ |
| 7368 | ordered_set = true; |
| 7369 | if (disjunct_set || n_way_choice || a_is_negated || a_is_suffix |
| 7370 | || a_is_spectype || atom == end_atom) |
| 7371 | goto invalid; |
| 7372 | |
| 7373 | mark_matching_switches (atom, end_atom, starred: a_is_starred); |
| 7374 | |
| 7375 | if (*p == '}') |
| 7376 | process_marked_switches (); |
| 7377 | break; |
| 7378 | |
| 7379 | case '|': case ':': |
| 7380 | /* Substitute some text if the current atom appears as a switch |
| 7381 | or suffix. */ |
| 7382 | disjunct_set = true; |
| 7383 | if (ordered_set) |
| 7384 | goto invalid; |
| 7385 | |
| 7386 | if (atom && atom == end_atom) |
| 7387 | { |
| 7388 | if (!n_way_choice || disj_matched || *p == '|' |
| 7389 | || a_is_negated || a_is_suffix || a_is_spectype |
| 7390 | || a_is_starred) |
| 7391 | goto invalid; |
| 7392 | |
| 7393 | /* An empty term may appear as the last choice of an |
| 7394 | N-way choice set; it means "otherwise". */ |
| 7395 | a_must_be_last = true; |
| 7396 | disj_matched = !n_way_matched; |
| 7397 | disj_starred = false; |
| 7398 | } |
| 7399 | else |
| 7400 | { |
| 7401 | if ((a_is_suffix || a_is_spectype) && a_is_starred) |
| 7402 | goto invalid; |
| 7403 | |
| 7404 | if (!a_is_starred) |
| 7405 | disj_starred = false; |
| 7406 | |
| 7407 | /* Don't bother testing this atom if we already have a |
| 7408 | match. */ |
| 7409 | if (!disj_matched && !n_way_matched) |
| 7410 | { |
| 7411 | if (atom == NULL) |
| 7412 | /* a_matched is already set by handle_spec_function. */; |
| 7413 | else if (a_is_suffix) |
| 7414 | a_matched = input_suffix_matches (atom, end_atom); |
| 7415 | else if (a_is_spectype) |
| 7416 | a_matched = input_spec_matches (atom, end_atom); |
| 7417 | else |
| 7418 | a_matched = switch_matches (atom, end_atom, starred: a_is_starred); |
| 7419 | |
| 7420 | if (a_matched != a_is_negated) |
| 7421 | { |
| 7422 | disj_matched = true; |
| 7423 | d_atom = atom; |
| 7424 | d_end_atom = end_atom; |
| 7425 | d_esc_buf = esc_buf; |
| 7426 | } |
| 7427 | } |
| 7428 | } |
| 7429 | |
| 7430 | if (*p == ':') |
| 7431 | { |
| 7432 | /* Found the body, that is, the text to substitute if the |
| 7433 | current disjunction matches. */ |
| 7434 | p = process_brace_body (p + 1, d_atom, d_end_atom, disj_starred, |
| 7435 | disj_matched && !n_way_matched); |
| 7436 | if (p == 0) |
| 7437 | goto done; |
| 7438 | |
| 7439 | /* If we have an N-way choice, reset state for the next |
| 7440 | disjunction. */ |
| 7441 | if (*p == ';') |
| 7442 | { |
| 7443 | n_way_choice = true; |
| 7444 | n_way_matched |= disj_matched; |
| 7445 | disj_matched = false; |
| 7446 | disj_starred = true; |
| 7447 | d_atom = d_end_atom = NULL; |
| 7448 | } |
| 7449 | } |
| 7450 | break; |
| 7451 | |
| 7452 | default: |
| 7453 | goto invalid; |
| 7454 | } |
| 7455 | } |
| 7456 | while (*p++ != '}'); |
| 7457 | |
| 7458 | done: |
| 7459 | if (d_esc_buf && d_esc_buf != esc_buf) |
| 7460 | free (ptr: d_esc_buf); |
| 7461 | if (esc_buf) |
| 7462 | free (ptr: esc_buf); |
| 7463 | |
| 7464 | return p; |
| 7465 | |
| 7466 | invalid: |
| 7467 | fatal_error (input_location, "braced spec %qs is invalid at %qc" , orig, *p); |
| 7468 | |
| 7469 | #undef SKIP_WHITE |
| 7470 | } |
| 7471 | |
| 7472 | /* Subroutine of handle_braces. Scan and process a brace substitution body |
| 7473 | (X in the description of %{} syntax). P points one past the colon; |
| 7474 | ATOM and END_ATOM bracket the first atom which was found to be true |
| 7475 | (present) in the current disjunction; STARRED indicates whether all |
| 7476 | the atoms in the current disjunction were starred (for syntax validation); |
| 7477 | MATCHED indicates whether the disjunction matched or not, and therefore |
| 7478 | whether or not the body is to be processed through do_spec_1 or just |
| 7479 | skipped. Returns a pointer to the closing } or ;, or 0 if do_spec_1 |
| 7480 | returns -1. */ |
| 7481 | |
| 7482 | static const char * |
| 7483 | process_brace_body (const char *p, const char *atom, const char *end_atom, |
| 7484 | int starred, int matched) |
| 7485 | { |
| 7486 | const char *body, *end_body; |
| 7487 | unsigned int nesting_level; |
| 7488 | bool have_subst = false; |
| 7489 | |
| 7490 | /* Locate the closing } or ;, honoring nested braces. |
| 7491 | Trim trailing whitespace. */ |
| 7492 | body = p; |
| 7493 | nesting_level = 1; |
| 7494 | for (;;) |
| 7495 | { |
| 7496 | if (*p == '{') |
| 7497 | nesting_level++; |
| 7498 | else if (*p == '}') |
| 7499 | { |
| 7500 | if (!--nesting_level) |
| 7501 | break; |
| 7502 | } |
| 7503 | else if (*p == ';' && nesting_level == 1) |
| 7504 | break; |
| 7505 | else if (*p == '%' && p[1] == '*' && nesting_level == 1) |
| 7506 | have_subst = true; |
| 7507 | else if (*p == '\0') |
| 7508 | goto invalid; |
| 7509 | p++; |
| 7510 | } |
| 7511 | |
| 7512 | end_body = p; |
| 7513 | while (end_body[-1] == ' ' || end_body[-1] == '\t') |
| 7514 | end_body--; |
| 7515 | |
| 7516 | if (have_subst && !starred) |
| 7517 | goto invalid; |
| 7518 | |
| 7519 | if (matched) |
| 7520 | { |
| 7521 | /* Copy the substitution body to permanent storage and execute it. |
| 7522 | If have_subst is false, this is a simple matter of running the |
| 7523 | body through do_spec_1... */ |
| 7524 | char *string = save_string (body, end_body - body); |
| 7525 | if (!have_subst) |
| 7526 | { |
| 7527 | if (do_spec_1 (spec: string, inswitch: 0, NULL) < 0) |
| 7528 | { |
| 7529 | free (ptr: string); |
| 7530 | return 0; |
| 7531 | } |
| 7532 | } |
| 7533 | else |
| 7534 | { |
| 7535 | /* ... but if have_subst is true, we have to process the |
| 7536 | body once for each matching switch, with %* set to the |
| 7537 | variant part of the switch. */ |
| 7538 | unsigned int hard_match_len = end_atom - atom; |
| 7539 | int i; |
| 7540 | |
| 7541 | for (i = 0; i < n_switches; i++) |
| 7542 | if (!strncmp (s1: switches[i].part1, s2: atom, n: hard_match_len) |
| 7543 | && check_live_switch (i, hard_match_len)) |
| 7544 | { |
| 7545 | if (do_spec_1 (spec: string, inswitch: 0, |
| 7546 | soft_matched_part: &switches[i].part1[hard_match_len]) < 0) |
| 7547 | { |
| 7548 | free (ptr: string); |
| 7549 | return 0; |
| 7550 | } |
| 7551 | /* Pass any arguments this switch has. */ |
| 7552 | give_switch (i, 1); |
| 7553 | suffix_subst = NULL; |
| 7554 | } |
| 7555 | } |
| 7556 | free (ptr: string); |
| 7557 | } |
| 7558 | |
| 7559 | return p; |
| 7560 | |
| 7561 | invalid: |
| 7562 | fatal_error (input_location, "braced spec body %qs is invalid" , body); |
| 7563 | } |
| 7564 | |
| 7565 | /* Return 0 iff switch number SWITCHNUM is obsoleted by a later switch |
| 7566 | on the command line. PREFIX_LENGTH is the length of XXX in an {XXX*} |
| 7567 | spec, or -1 if either exact match or %* is used. |
| 7568 | |
| 7569 | A -O switch is obsoleted by a later -O switch. A -f, -g, -m, or -W switch |
| 7570 | whose value does not begin with "no-" is obsoleted by the same value |
| 7571 | with the "no-", similarly for a switch with the "no-" prefix. */ |
| 7572 | |
| 7573 | static int |
| 7574 | check_live_switch (int switchnum, int prefix_length) |
| 7575 | { |
| 7576 | const char *name = switches[switchnum].part1; |
| 7577 | int i; |
| 7578 | |
| 7579 | /* If we already processed this switch and determined if it was |
| 7580 | live or not, return our past determination. */ |
| 7581 | if (switches[switchnum].live_cond != 0) |
| 7582 | return ((switches[switchnum].live_cond & SWITCH_LIVE) != 0 |
| 7583 | && (switches[switchnum].live_cond & SWITCH_FALSE) == 0 |
| 7584 | && (switches[switchnum].live_cond & SWITCH_IGNORE_PERMANENTLY) |
| 7585 | == 0); |
| 7586 | |
| 7587 | /* In the common case of {<at-most-one-letter>*}, a negating |
| 7588 | switch would always match, so ignore that case. We will just |
| 7589 | send the conflicting switches to the compiler phase. */ |
| 7590 | if (prefix_length >= 0 && prefix_length <= 1) |
| 7591 | return 1; |
| 7592 | |
| 7593 | /* Now search for duplicate in a manner that depends on the name. */ |
| 7594 | switch (*name) |
| 7595 | { |
| 7596 | case 'O': |
| 7597 | for (i = switchnum + 1; i < n_switches; i++) |
| 7598 | if (switches[i].part1[0] == 'O') |
| 7599 | { |
| 7600 | switches[switchnum].validated = true; |
| 7601 | switches[switchnum].live_cond = SWITCH_FALSE; |
| 7602 | return 0; |
| 7603 | } |
| 7604 | break; |
| 7605 | |
| 7606 | case 'W': case 'f': case 'm': case 'g': |
| 7607 | if (startswith (str: name + 1, prefix: "no-" )) |
| 7608 | { |
| 7609 | /* We have Xno-YYY, search for XYYY. */ |
| 7610 | for (i = switchnum + 1; i < n_switches; i++) |
| 7611 | if (switches[i].part1[0] == name[0] |
| 7612 | && ! strcmp (s1: &switches[i].part1[1], s2: &name[4])) |
| 7613 | { |
| 7614 | /* --specs are validated with the validate_switches mechanism. */ |
| 7615 | if (switches[switchnum].known) |
| 7616 | switches[switchnum].validated = true; |
| 7617 | switches[switchnum].live_cond = SWITCH_FALSE; |
| 7618 | return 0; |
| 7619 | } |
| 7620 | } |
| 7621 | else |
| 7622 | { |
| 7623 | /* We have XYYY, search for Xno-YYY. */ |
| 7624 | for (i = switchnum + 1; i < n_switches; i++) |
| 7625 | if (switches[i].part1[0] == name[0] |
| 7626 | && switches[i].part1[1] == 'n' |
| 7627 | && switches[i].part1[2] == 'o' |
| 7628 | && switches[i].part1[3] == '-' |
| 7629 | && !strcmp (s1: &switches[i].part1[4], s2: &name[1])) |
| 7630 | { |
| 7631 | /* --specs are validated with the validate_switches mechanism. */ |
| 7632 | if (switches[switchnum].known) |
| 7633 | switches[switchnum].validated = true; |
| 7634 | switches[switchnum].live_cond = SWITCH_FALSE; |
| 7635 | return 0; |
| 7636 | } |
| 7637 | } |
| 7638 | break; |
| 7639 | } |
| 7640 | |
| 7641 | /* Otherwise the switch is live. */ |
| 7642 | switches[switchnum].live_cond |= SWITCH_LIVE; |
| 7643 | return 1; |
| 7644 | } |
| 7645 | |
| 7646 | /* Pass a switch to the current accumulating command |
| 7647 | in the same form that we received it. |
| 7648 | SWITCHNUM identifies the switch; it is an index into |
| 7649 | the vector of switches gcc received, which is `switches'. |
| 7650 | This cannot fail since it never finishes a command line. |
| 7651 | |
| 7652 | If OMIT_FIRST_WORD is nonzero, then we omit .part1 of the argument. */ |
| 7653 | |
| 7654 | static void |
| 7655 | give_switch (int switchnum, int omit_first_word) |
| 7656 | { |
| 7657 | if ((switches[switchnum].live_cond & SWITCH_IGNORE) != 0) |
| 7658 | return; |
| 7659 | |
| 7660 | if (!omit_first_word) |
| 7661 | { |
| 7662 | do_spec_1 (spec: "-" , inswitch: 0, NULL); |
| 7663 | do_spec_1 (spec: switches[switchnum].part1, inswitch: 1, NULL); |
| 7664 | } |
| 7665 | |
| 7666 | if (switches[switchnum].args != 0) |
| 7667 | { |
| 7668 | const char **p; |
| 7669 | for (p = switches[switchnum].args; *p; p++) |
| 7670 | { |
| 7671 | const char *arg = *p; |
| 7672 | |
| 7673 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 7674 | if (suffix_subst) |
| 7675 | { |
| 7676 | unsigned length = strlen (s: arg); |
| 7677 | int dot = 0; |
| 7678 | |
| 7679 | while (length-- && !IS_DIR_SEPARATOR (arg[length])) |
| 7680 | if (arg[length] == '.') |
| 7681 | { |
| 7682 | (CONST_CAST (char *, arg))[length] = 0; |
| 7683 | dot = 1; |
| 7684 | break; |
| 7685 | } |
| 7686 | do_spec_1 (spec: arg, inswitch: 1, NULL); |
| 7687 | if (dot) |
| 7688 | (CONST_CAST (char *, arg))[length] = '.'; |
| 7689 | do_spec_1 (spec: suffix_subst, inswitch: 1, NULL); |
| 7690 | } |
| 7691 | else |
| 7692 | do_spec_1 (spec: arg, inswitch: 1, NULL); |
| 7693 | } |
| 7694 | } |
| 7695 | |
| 7696 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 7697 | switches[switchnum].validated = true; |
| 7698 | } |
| 7699 | |
| 7700 | /* Print GCC configuration (e.g. version, thread model, target, |
| 7701 | configuration_arguments) to a given FILE. */ |
| 7702 | |
| 7703 | static void |
| 7704 | print_configuration (FILE *file) |
| 7705 | { |
| 7706 | int n; |
| 7707 | const char *thrmod; |
| 7708 | |
| 7709 | fnotice (file, "Target: %s\n" , spec_machine); |
| 7710 | fnotice (file, "Configured with: %s\n" , configuration_arguments); |
| 7711 | |
| 7712 | #ifdef THREAD_MODEL_SPEC |
| 7713 | /* We could have defined THREAD_MODEL_SPEC to "%*" by default, |
| 7714 | but there's no point in doing all this processing just to get |
| 7715 | thread_model back. */ |
| 7716 | obstack_init (&obstack); |
| 7717 | do_spec_1 (THREAD_MODEL_SPEC, 0, thread_model); |
| 7718 | obstack_1grow (&obstack, '\0'); |
| 7719 | thrmod = XOBFINISH (&obstack, const char *); |
| 7720 | #else |
| 7721 | thrmod = thread_model; |
| 7722 | #endif |
| 7723 | |
| 7724 | fnotice (file, "Thread model: %s\n" , thrmod); |
| 7725 | fnotice (file, "Supported LTO compression algorithms: zlib" ); |
| 7726 | #ifdef HAVE_ZSTD_H |
| 7727 | fnotice (file, " zstd" ); |
| 7728 | #endif |
| 7729 | fnotice (file, "\n" ); |
| 7730 | |
| 7731 | /* compiler_version is truncated at the first space when initialized |
| 7732 | from version string, so truncate version_string at the first space |
| 7733 | before comparing. */ |
| 7734 | for (n = 0; version_string[n]; n++) |
| 7735 | if (version_string[n] == ' ') |
| 7736 | break; |
| 7737 | |
| 7738 | if (! strncmp (version_string, s2: compiler_version, n: n) |
| 7739 | && compiler_version[n] == 0) |
| 7740 | fnotice (file, "gcc version %s %s\n" , version_string, |
| 7741 | pkgversion_string); |
| 7742 | else |
| 7743 | fnotice (file, "gcc driver version %s %sexecuting gcc version %s\n" , |
| 7744 | version_string, pkgversion_string, compiler_version); |
| 7745 | |
| 7746 | } |
| 7747 | |
| 7748 | #define RETRY_ICE_ATTEMPTS 3 |
| 7749 | |
| 7750 | /* Returns true if FILE1 and FILE2 contain equivalent data, 0 otherwise. |
| 7751 | If lines start with 0x followed by 1-16 lowercase hexadecimal digits |
| 7752 | followed by a space, ignore anything before that space. These are |
| 7753 | typically function addresses from libbacktrace and those can differ |
| 7754 | due to ASLR. */ |
| 7755 | |
| 7756 | static bool |
| 7757 | files_equal_p (char *file1, char *file2) |
| 7758 | { |
| 7759 | FILE *f1 = fopen (filename: file1, modes: "rb" ); |
| 7760 | FILE *f2 = fopen (filename: file2, modes: "rb" ); |
| 7761 | char line1[256], line2[256]; |
| 7762 | |
| 7763 | bool line_start = true; |
| 7764 | while (fgets (s: line1, n: sizeof (line1), stream: f1)) |
| 7765 | { |
| 7766 | if (!fgets (s: line2, n: sizeof (line2), stream: f2)) |
| 7767 | goto error; |
| 7768 | char *p1 = line1, *p2 = line2; |
| 7769 | if (line_start |
| 7770 | && line1[0] == '0' |
| 7771 | && line1[1] == 'x' |
| 7772 | && line2[0] == '0' |
| 7773 | && line2[1] == 'x') |
| 7774 | { |
| 7775 | int i, j; |
| 7776 | for (i = 0; i < 16; ++i) |
| 7777 | if (!ISXDIGIT (line1[2 + i]) || ISUPPER (line1[2 + i])) |
| 7778 | break; |
| 7779 | for (j = 0; j < 16; ++j) |
| 7780 | if (!ISXDIGIT (line2[2 + j]) || ISUPPER (line2[2 + j])) |
| 7781 | break; |
| 7782 | if (i && line1[2 + i] == ' ' && j && line2[2 + j] == ' ') |
| 7783 | { |
| 7784 | p1 = line1 + i + 3; |
| 7785 | p2 = line2 + j + 3; |
| 7786 | } |
| 7787 | } |
| 7788 | if (strcmp (s1: p1, s2: p2) != 0) |
| 7789 | goto error; |
| 7790 | line_start = strchr (s: line1, c: '\n') != NULL; |
| 7791 | } |
| 7792 | if (fgets (s: line2, n: sizeof (line2), stream: f2)) |
| 7793 | goto error; |
| 7794 | |
| 7795 | fclose (stream: f1); |
| 7796 | fclose (stream: f2); |
| 7797 | return 1; |
| 7798 | |
| 7799 | error: |
| 7800 | fclose (stream: f1); |
| 7801 | fclose (stream: f2); |
| 7802 | return 0; |
| 7803 | } |
| 7804 | |
| 7805 | /* Check that compiler's output doesn't differ across runs. |
| 7806 | TEMP_STDOUT_FILES and TEMP_STDERR_FILES are arrays of files, containing |
| 7807 | stdout and stderr for each compiler run. Return true if all of |
| 7808 | TEMP_STDOUT_FILES and TEMP_STDERR_FILES are equivalent. */ |
| 7809 | |
| 7810 | static bool |
| 7811 | check_repro (char **temp_stdout_files, char **temp_stderr_files) |
| 7812 | { |
| 7813 | int i; |
| 7814 | for (i = 0; i < RETRY_ICE_ATTEMPTS - 2; ++i) |
| 7815 | { |
| 7816 | if (!files_equal_p (file1: temp_stdout_files[i], file2: temp_stdout_files[i + 1]) |
| 7817 | || !files_equal_p (file1: temp_stderr_files[i], file2: temp_stderr_files[i + 1])) |
| 7818 | { |
| 7819 | fnotice (stderr, "The bug is not reproducible, so it is" |
| 7820 | " likely a hardware or OS problem.\n" ); |
| 7821 | break; |
| 7822 | } |
| 7823 | } |
| 7824 | return i == RETRY_ICE_ATTEMPTS - 2; |
| 7825 | } |
| 7826 | |
| 7827 | enum attempt_status { |
| 7828 | ATTEMPT_STATUS_FAIL_TO_RUN, |
| 7829 | ATTEMPT_STATUS_SUCCESS, |
| 7830 | ATTEMPT_STATUS_ICE |
| 7831 | }; |
| 7832 | |
| 7833 | |
| 7834 | /* Run compiler with arguments NEW_ARGV to reproduce the ICE, storing stdout |
| 7835 | to OUT_TEMP and stderr to ERR_TEMP. If APPEND is TRUE, append to OUT_TEMP |
| 7836 | and ERR_TEMP instead of truncating. If EMIT_SYSTEM_INFO is TRUE, also write |
| 7837 | GCC configuration into to ERR_TEMP. Return ATTEMPT_STATUS_FAIL_TO_RUN if |
| 7838 | compiler failed to run, ATTEMPT_STATUS_ICE if compiled ICE-ed and |
| 7839 | ATTEMPT_STATUS_SUCCESS otherwise. */ |
| 7840 | |
| 7841 | static enum attempt_status |
| 7842 | run_attempt (const char **new_argv, const char *out_temp, |
| 7843 | const char *err_temp, int emit_system_info, int append) |
| 7844 | { |
| 7845 | |
| 7846 | if (emit_system_info) |
| 7847 | { |
| 7848 | FILE *file_out = fopen (filename: err_temp, modes: "a" ); |
| 7849 | print_configuration (file: file_out); |
| 7850 | fputs (s: "\n" , stream: file_out); |
| 7851 | fclose (stream: file_out); |
| 7852 | } |
| 7853 | |
| 7854 | int exit_status; |
| 7855 | const char *errmsg; |
| 7856 | struct pex_obj *pex; |
| 7857 | int err; |
| 7858 | int pex_flags = PEX_USE_PIPES | PEX_LAST; |
| 7859 | enum attempt_status status = ATTEMPT_STATUS_FAIL_TO_RUN; |
| 7860 | |
| 7861 | if (append) |
| 7862 | pex_flags |= PEX_STDOUT_APPEND | PEX_STDERR_APPEND; |
| 7863 | |
| 7864 | pex = pex_init (PEX_USE_PIPES, pname: new_argv[0], NULL); |
| 7865 | if (!pex) |
| 7866 | fatal_error (input_location, "%<pex_init%> failed: %m" ); |
| 7867 | |
| 7868 | errmsg = pex_run (obj: pex, flags: pex_flags, executable: new_argv[0], |
| 7869 | CONST_CAST2 (char *const *, const char **, &new_argv[1]), |
| 7870 | outname: out_temp, errname: err_temp, err: &err); |
| 7871 | if (errmsg != NULL) |
| 7872 | { |
| 7873 | errno = err; |
| 7874 | fatal_error (input_location, |
| 7875 | err ? G_ ("cannot execute %qs: %s: %m" ) |
| 7876 | : G_ ("cannot execute %qs: %s" ), |
| 7877 | new_argv[0], errmsg); |
| 7878 | } |
| 7879 | |
| 7880 | if (!pex_get_status (pex, count: 1, vector: &exit_status)) |
| 7881 | goto out; |
| 7882 | |
| 7883 | switch (WEXITSTATUS (exit_status)) |
| 7884 | { |
| 7885 | case ICE_EXIT_CODE: |
| 7886 | status = ATTEMPT_STATUS_ICE; |
| 7887 | break; |
| 7888 | |
| 7889 | case SUCCESS_EXIT_CODE: |
| 7890 | status = ATTEMPT_STATUS_SUCCESS; |
| 7891 | break; |
| 7892 | |
| 7893 | default: |
| 7894 | ; |
| 7895 | } |
| 7896 | |
| 7897 | out: |
| 7898 | pex_free (pex); |
| 7899 | return status; |
| 7900 | } |
| 7901 | |
| 7902 | /* This routine reads lines from IN file, adds C++ style comments |
| 7903 | at the begining of each line and writes result into OUT. */ |
| 7904 | |
| 7905 | static void |
| 7906 | (const char *file_in, const char *file_out) |
| 7907 | { |
| 7908 | FILE *in = fopen (filename: file_in, modes: "rb" ); |
| 7909 | FILE *out = fopen (filename: file_out, modes: "wb" ); |
| 7910 | char line[256]; |
| 7911 | |
| 7912 | bool = true; |
| 7913 | while (fgets (s: line, n: sizeof (line), stream: in)) |
| 7914 | { |
| 7915 | if (add_comment) |
| 7916 | fputs (s: "// " , stream: out); |
| 7917 | fputs (s: line, stream: out); |
| 7918 | add_comment = strchr (s: line, c: '\n') != NULL; |
| 7919 | } |
| 7920 | |
| 7921 | fclose (stream: in); |
| 7922 | fclose (stream: out); |
| 7923 | } |
| 7924 | |
| 7925 | /* This routine adds preprocessed source code into the given ERR_FILE. |
| 7926 | To do this, it adds "-E" to NEW_ARGV and execute RUN_ATTEMPT routine to |
| 7927 | add information in report file. RUN_ATTEMPT should return |
| 7928 | ATTEMPT_STATUS_SUCCESS, in other case we cannot generate the report. */ |
| 7929 | |
| 7930 | static void |
| 7931 | do_report_bug (const char **new_argv, const int nargs, |
| 7932 | char **out_file, char **err_file) |
| 7933 | { |
| 7934 | int i, status; |
| 7935 | int fd = open (file: *out_file, O_RDWR | O_APPEND); |
| 7936 | if (fd < 0) |
| 7937 | return; |
| 7938 | write (fd: fd, buf: "\n//" , n: 3); |
| 7939 | for (i = 0; i < nargs; i++) |
| 7940 | { |
| 7941 | write (fd: fd, buf: " " , n: 1); |
| 7942 | write (fd: fd, buf: new_argv[i], n: strlen (s: new_argv[i])); |
| 7943 | } |
| 7944 | write (fd: fd, buf: "\n\n" , n: 2); |
| 7945 | close (fd: fd); |
| 7946 | new_argv[nargs] = "-E" ; |
| 7947 | new_argv[nargs + 1] = NULL; |
| 7948 | |
| 7949 | status = run_attempt (new_argv, out_temp: *out_file, err_temp: *err_file, emit_system_info: 0, append: 1); |
| 7950 | |
| 7951 | if (status == ATTEMPT_STATUS_SUCCESS) |
| 7952 | { |
| 7953 | fnotice (stderr, "Preprocessed source stored into %s file," |
| 7954 | " please attach this to your bugreport.\n" , *out_file); |
| 7955 | /* Make sure it is not deleted. */ |
| 7956 | free (ptr: *out_file); |
| 7957 | *out_file = NULL; |
| 7958 | } |
| 7959 | } |
| 7960 | |
| 7961 | /* Try to reproduce ICE. If bug is reproducible, generate report .err file |
| 7962 | containing GCC configuration, backtrace, compiler's command line options |
| 7963 | and preprocessed source code. */ |
| 7964 | |
| 7965 | static void |
| 7966 | try_generate_repro (const char **argv) |
| 7967 | { |
| 7968 | int i, nargs, out_arg = -1, quiet = 0, attempt; |
| 7969 | const char **new_argv; |
| 7970 | char *temp_files[RETRY_ICE_ATTEMPTS * 2]; |
| 7971 | char **temp_stdout_files = &temp_files[0]; |
| 7972 | char **temp_stderr_files = &temp_files[RETRY_ICE_ATTEMPTS]; |
| 7973 | |
| 7974 | if (gcc_input_filename == NULL || ! strcmp (s1: gcc_input_filename, s2: "-" )) |
| 7975 | return; |
| 7976 | |
| 7977 | for (nargs = 0; argv[nargs] != NULL; ++nargs) |
| 7978 | /* Only retry compiler ICEs, not preprocessor ones. */ |
| 7979 | if (! strcmp (s1: argv[nargs], s2: "-E" )) |
| 7980 | return; |
| 7981 | else if (argv[nargs][0] == '-' && argv[nargs][1] == 'o') |
| 7982 | { |
| 7983 | if (out_arg == -1) |
| 7984 | out_arg = nargs; |
| 7985 | else |
| 7986 | return; |
| 7987 | } |
| 7988 | /* If the compiler is going to output any time information, |
| 7989 | it might varry between invocations. */ |
| 7990 | else if (! strcmp (s1: argv[nargs], s2: "-quiet" )) |
| 7991 | quiet = 1; |
| 7992 | else if (! strcmp (s1: argv[nargs], s2: "-ftime-report" )) |
| 7993 | return; |
| 7994 | |
| 7995 | if (out_arg == -1 || !quiet) |
| 7996 | return; |
| 7997 | |
| 7998 | memset (s: temp_files, c: '\0', n: sizeof (temp_files)); |
| 7999 | new_argv = XALLOCAVEC (const char *, nargs + 4); |
| 8000 | memcpy (dest: new_argv, src: argv, n: (nargs + 1) * sizeof (const char *)); |
| 8001 | new_argv[nargs++] = "-frandom-seed=0" ; |
| 8002 | new_argv[nargs++] = "-fdump-noaddr" ; |
| 8003 | new_argv[nargs] = NULL; |
| 8004 | if (new_argv[out_arg][2] == '\0') |
| 8005 | new_argv[out_arg + 1] = "-" ; |
| 8006 | else |
| 8007 | new_argv[out_arg] = "-o-" ; |
| 8008 | |
| 8009 | #ifdef HOST_HAS_PERSONALITY_ADDR_NO_RANDOMIZE |
| 8010 | personality (persona: personality (persona: 0xffffffffU) | ADDR_NO_RANDOMIZE); |
| 8011 | #endif |
| 8012 | |
| 8013 | int status; |
| 8014 | for (attempt = 0; attempt < RETRY_ICE_ATTEMPTS; ++attempt) |
| 8015 | { |
| 8016 | int emit_system_info = 0; |
| 8017 | int append = 0; |
| 8018 | temp_stdout_files[attempt] = make_temp_file (".out" ); |
| 8019 | temp_stderr_files[attempt] = make_temp_file (".err" ); |
| 8020 | |
| 8021 | if (attempt == RETRY_ICE_ATTEMPTS - 1) |
| 8022 | { |
| 8023 | append = 1; |
| 8024 | emit_system_info = 1; |
| 8025 | } |
| 8026 | |
| 8027 | status = run_attempt (new_argv, out_temp: temp_stdout_files[attempt], |
| 8028 | err_temp: temp_stderr_files[attempt], emit_system_info, |
| 8029 | append); |
| 8030 | |
| 8031 | if (status != ATTEMPT_STATUS_ICE) |
| 8032 | { |
| 8033 | fnotice (stderr, "The bug is not reproducible, so it is" |
| 8034 | " likely a hardware or OS problem.\n" ); |
| 8035 | goto out; |
| 8036 | } |
| 8037 | } |
| 8038 | |
| 8039 | if (!check_repro (temp_stdout_files, temp_stderr_files)) |
| 8040 | goto out; |
| 8041 | |
| 8042 | { |
| 8043 | /* Insert commented out backtrace into report file. */ |
| 8044 | char ** = &temp_stdout_files[RETRY_ICE_ATTEMPTS - 1]; |
| 8045 | insert_comments (file_in: temp_stderr_files[RETRY_ICE_ATTEMPTS - 1], |
| 8046 | file_out: *stderr_commented); |
| 8047 | |
| 8048 | /* In final attempt we append compiler options and preprocesssed code to last |
| 8049 | generated .out file with configuration and backtrace. */ |
| 8050 | char **err = &temp_stderr_files[RETRY_ICE_ATTEMPTS - 1]; |
| 8051 | do_report_bug (new_argv, nargs, out_file: stderr_commented, err_file: err); |
| 8052 | } |
| 8053 | |
| 8054 | out: |
| 8055 | for (i = 0; i < RETRY_ICE_ATTEMPTS * 2; i++) |
| 8056 | if (temp_files[i]) |
| 8057 | { |
| 8058 | unlink (name: temp_stdout_files[i]); |
| 8059 | free (ptr: temp_stdout_files[i]); |
| 8060 | } |
| 8061 | } |
| 8062 | |
| 8063 | /* Search for a file named NAME trying various prefixes including the |
| 8064 | user's -B prefix and some standard ones. |
| 8065 | Return the absolute file name found. If nothing is found, return NAME. */ |
| 8066 | |
| 8067 | static const char * |
| 8068 | find_file (const char *name) |
| 8069 | { |
| 8070 | char *newname = find_a_file (pprefix: &startfile_prefixes, name, R_OK, do_multi: true); |
| 8071 | return newname ? newname : name; |
| 8072 | } |
| 8073 | |
| 8074 | /* Determine whether a directory exists. */ |
| 8075 | |
| 8076 | static int |
| 8077 | is_directory (const char *path1) |
| 8078 | { |
| 8079 | int len1; |
| 8080 | char *path; |
| 8081 | char *cp; |
| 8082 | struct stat st; |
| 8083 | |
| 8084 | /* Ensure the string ends with "/.". The resulting path will be a |
| 8085 | directory even if the given path is a symbolic link. */ |
| 8086 | len1 = strlen (s: path1); |
| 8087 | path = (char *) alloca (3 + len1); |
| 8088 | memcpy (dest: path, src: path1, n: len1); |
| 8089 | cp = path + len1; |
| 8090 | if (!IS_DIR_SEPARATOR (cp[-1])) |
| 8091 | *cp++ = DIR_SEPARATOR; |
| 8092 | *cp++ = '.'; |
| 8093 | *cp = '\0'; |
| 8094 | |
| 8095 | return (stat (file: path, buf: &st) >= 0 && S_ISDIR (st.st_mode)); |
| 8096 | } |
| 8097 | |
| 8098 | /* Set up the various global variables to indicate that we're processing |
| 8099 | the input file named FILENAME. */ |
| 8100 | |
| 8101 | void |
| 8102 | set_input (const char *filename) |
| 8103 | { |
| 8104 | const char *p; |
| 8105 | |
| 8106 | gcc_input_filename = filename; |
| 8107 | input_filename_length = strlen (s: gcc_input_filename); |
| 8108 | input_basename = lbasename (gcc_input_filename); |
| 8109 | |
| 8110 | /* Find a suffix starting with the last period, |
| 8111 | and set basename_length to exclude that suffix. */ |
| 8112 | basename_length = strlen (s: input_basename); |
| 8113 | suffixed_basename_length = basename_length; |
| 8114 | p = input_basename + basename_length; |
| 8115 | while (p != input_basename && *p != '.') |
| 8116 | --p; |
| 8117 | if (*p == '.' && p != input_basename) |
| 8118 | { |
| 8119 | basename_length = p - input_basename; |
| 8120 | input_suffix = p + 1; |
| 8121 | } |
| 8122 | else |
| 8123 | input_suffix = "" ; |
| 8124 | |
| 8125 | /* If a spec for 'g', 'u', or 'U' is seen with -save-temps then |
| 8126 | we will need to do a stat on the gcc_input_filename. The |
| 8127 | INPUT_STAT_SET signals that the stat is needed. */ |
| 8128 | input_stat_set = 0; |
| 8129 | } |
| 8130 | |
| 8131 | /* On fatal signals, delete all the temporary files. */ |
| 8132 | |
| 8133 | static void |
| 8134 | fatal_signal (int signum) |
| 8135 | { |
| 8136 | signal (sig: signum, SIG_DFL); |
| 8137 | delete_failure_queue (); |
| 8138 | delete_temp_files (); |
| 8139 | /* Get the same signal again, this time not handled, |
| 8140 | so its normal effect occurs. */ |
| 8141 | kill (pid: getpid (), sig: signum); |
| 8142 | } |
| 8143 | |
| 8144 | /* Compare the contents of the two files named CMPFILE[0] and |
| 8145 | CMPFILE[1]. Return zero if they're identical, nonzero |
| 8146 | otherwise. */ |
| 8147 | |
| 8148 | static int |
| 8149 | compare_files (char *cmpfile[]) |
| 8150 | { |
| 8151 | int ret = 0; |
| 8152 | FILE *temp[2] = { NULL, NULL }; |
| 8153 | int i; |
| 8154 | |
| 8155 | #if HAVE_MMAP_FILE |
| 8156 | { |
| 8157 | size_t length[2]; |
| 8158 | void *map[2] = { NULL, NULL }; |
| 8159 | |
| 8160 | for (i = 0; i < 2; i++) |
| 8161 | { |
| 8162 | struct stat st; |
| 8163 | |
| 8164 | if (stat (file: cmpfile[i], buf: &st) < 0 || !S_ISREG (st.st_mode)) |
| 8165 | { |
| 8166 | error ("%s: could not determine length of compare-debug file %s" , |
| 8167 | gcc_input_filename, cmpfile[i]); |
| 8168 | ret = 1; |
| 8169 | break; |
| 8170 | } |
| 8171 | |
| 8172 | length[i] = st.st_size; |
| 8173 | } |
| 8174 | |
| 8175 | if (!ret && length[0] != length[1]) |
| 8176 | { |
| 8177 | error ("%s: %<-fcompare-debug%> failure (length)" , gcc_input_filename); |
| 8178 | ret = 1; |
| 8179 | } |
| 8180 | |
| 8181 | if (!ret) |
| 8182 | for (i = 0; i < 2; i++) |
| 8183 | { |
| 8184 | int fd = open (file: cmpfile[i], O_RDONLY); |
| 8185 | if (fd < 0) |
| 8186 | { |
| 8187 | error ("%s: could not open compare-debug file %s" , |
| 8188 | gcc_input_filename, cmpfile[i]); |
| 8189 | ret = 1; |
| 8190 | break; |
| 8191 | } |
| 8192 | |
| 8193 | map[i] = mmap (NULL, len: length[i], PROT_READ, MAP_PRIVATE, fd: fd, offset: 0); |
| 8194 | close (fd: fd); |
| 8195 | |
| 8196 | if (map[i] == (void *) MAP_FAILED) |
| 8197 | { |
| 8198 | ret = -1; |
| 8199 | break; |
| 8200 | } |
| 8201 | } |
| 8202 | |
| 8203 | if (!ret) |
| 8204 | { |
| 8205 | if (memcmp (s1: map[0], s2: map[1], n: length[0]) != 0) |
| 8206 | { |
| 8207 | error ("%s: %<-fcompare-debug%> failure" , gcc_input_filename); |
| 8208 | ret = 1; |
| 8209 | } |
| 8210 | } |
| 8211 | |
| 8212 | for (i = 0; i < 2; i++) |
| 8213 | if (map[i]) |
| 8214 | munmap (addr: (caddr_t) map[i], len: length[i]); |
| 8215 | |
| 8216 | if (ret >= 0) |
| 8217 | return ret; |
| 8218 | |
| 8219 | ret = 0; |
| 8220 | } |
| 8221 | #endif |
| 8222 | |
| 8223 | for (i = 0; i < 2; i++) |
| 8224 | { |
| 8225 | temp[i] = fopen (filename: cmpfile[i], modes: "r" ); |
| 8226 | if (!temp[i]) |
| 8227 | { |
| 8228 | error ("%s: could not open compare-debug file %s" , |
| 8229 | gcc_input_filename, cmpfile[i]); |
| 8230 | ret = 1; |
| 8231 | break; |
| 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | if (!ret && temp[0] && temp[1]) |
| 8236 | for (;;) |
| 8237 | { |
| 8238 | int c0, c1; |
| 8239 | c0 = fgetc (stream: temp[0]); |
| 8240 | c1 = fgetc (stream: temp[1]); |
| 8241 | |
| 8242 | if (c0 != c1) |
| 8243 | { |
| 8244 | error ("%s: %<-fcompare-debug%> failure" , |
| 8245 | gcc_input_filename); |
| 8246 | ret = 1; |
| 8247 | break; |
| 8248 | } |
| 8249 | |
| 8250 | if (c0 == EOF) |
| 8251 | break; |
| 8252 | } |
| 8253 | |
| 8254 | for (i = 1; i >= 0; i--) |
| 8255 | { |
| 8256 | if (temp[i]) |
| 8257 | fclose (stream: temp[i]); |
| 8258 | } |
| 8259 | |
| 8260 | return ret; |
| 8261 | } |
| 8262 | |
| 8263 | driver::driver (bool can_finalize, bool debug) : |
| 8264 | explicit_link_files (NULL), |
| 8265 | decoded_options (NULL) |
| 8266 | { |
| 8267 | env.init (can_restore: can_finalize, debug); |
| 8268 | } |
| 8269 | |
| 8270 | driver::~driver () |
| 8271 | { |
| 8272 | XDELETEVEC (explicit_link_files); |
| 8273 | XDELETEVEC (decoded_options); |
| 8274 | } |
| 8275 | |
| 8276 | /* driver::main is implemented as a series of driver:: method calls. */ |
| 8277 | |
| 8278 | int |
| 8279 | driver::main (int argc, char **argv) |
| 8280 | { |
| 8281 | bool early_exit; |
| 8282 | |
| 8283 | set_progname (argv[0]); |
| 8284 | expand_at_files (argc: &argc, argv: &argv); |
| 8285 | decode_argv (argc, argv: const_cast <const char **> (argv)); |
| 8286 | global_initializations (); |
| 8287 | build_multilib_strings (); |
| 8288 | set_up_specs (); |
| 8289 | putenv_COLLECT_AS_OPTIONS (vec: assembler_options); |
| 8290 | putenv_COLLECT_GCC (argv0: argv[0]); |
| 8291 | maybe_putenv_COLLECT_LTO_WRAPPER (); |
| 8292 | maybe_putenv_OFFLOAD_TARGETS (); |
| 8293 | handle_unrecognized_options (); |
| 8294 | |
| 8295 | if (completion) |
| 8296 | { |
| 8297 | m_option_proposer.suggest_completion (option_prefix: completion); |
| 8298 | return 0; |
| 8299 | } |
| 8300 | |
| 8301 | if (!maybe_print_and_exit ()) |
| 8302 | return 0; |
| 8303 | |
| 8304 | early_exit = prepare_infiles (); |
| 8305 | if (early_exit) |
| 8306 | return get_exit_code (); |
| 8307 | |
| 8308 | do_spec_on_infiles (); |
| 8309 | maybe_run_linker (argv0: argv[0]); |
| 8310 | final_actions (); |
| 8311 | return get_exit_code (); |
| 8312 | } |
| 8313 | |
| 8314 | /* Locate the final component of argv[0] after any leading path, and set |
| 8315 | the program name accordingly. */ |
| 8316 | |
| 8317 | void |
| 8318 | driver::set_progname (const char *argv0) const |
| 8319 | { |
| 8320 | const char *p = argv0 + strlen (s: argv0); |
| 8321 | while (p != argv0 && !IS_DIR_SEPARATOR (p[-1])) |
| 8322 | --p; |
| 8323 | progname = p; |
| 8324 | |
| 8325 | xmalloc_set_program_name (progname); |
| 8326 | } |
| 8327 | |
| 8328 | /* Expand any @ files within the command-line args, |
| 8329 | setting at_file_supplied if any were expanded. */ |
| 8330 | |
| 8331 | void |
| 8332 | driver::expand_at_files (int *argc, char ***argv) const |
| 8333 | { |
| 8334 | char **old_argv = *argv; |
| 8335 | |
| 8336 | expandargv (argc, argv); |
| 8337 | |
| 8338 | /* Determine if any expansions were made. */ |
| 8339 | if (*argv != old_argv) |
| 8340 | at_file_supplied = true; |
| 8341 | } |
| 8342 | |
| 8343 | /* Decode the command-line arguments from argc/argv into the |
| 8344 | decoded_options array. */ |
| 8345 | |
| 8346 | void |
| 8347 | driver::decode_argv (int argc, const char **argv) |
| 8348 | { |
| 8349 | init_opts_obstack (); |
| 8350 | init_options_struct (opts: &global_options, opts_set: &global_options_set); |
| 8351 | |
| 8352 | decode_cmdline_options_to_array (argc, argv, |
| 8353 | CL_DRIVER, |
| 8354 | decoded_options: &decoded_options, decoded_options_count: &decoded_options_count); |
| 8355 | } |
| 8356 | |
| 8357 | /* Perform various initializations and setup. */ |
| 8358 | |
| 8359 | void |
| 8360 | driver::global_initializations () |
| 8361 | { |
| 8362 | /* Unlock the stdio streams. */ |
| 8363 | unlock_std_streams (); |
| 8364 | |
| 8365 | gcc_init_libintl (); |
| 8366 | |
| 8367 | diagnostic_initialize (context: global_dc, n_opts: 0); |
| 8368 | diagnostic_color_init (context: global_dc); |
| 8369 | diagnostic_urls_init (context: global_dc); |
| 8370 | global_dc->push_owned_urlifier (make_gcc_urlifier (lang_mask: 0)); |
| 8371 | |
| 8372 | #ifdef GCC_DRIVER_HOST_INITIALIZATION |
| 8373 | /* Perform host dependent initialization when needed. */ |
| 8374 | GCC_DRIVER_HOST_INITIALIZATION; |
| 8375 | #endif |
| 8376 | |
| 8377 | if (atexit (func: delete_temp_files) != 0) |
| 8378 | fatal_error (input_location, "atexit failed" ); |
| 8379 | |
| 8380 | if (signal (SIGINT, SIG_IGN) != SIG_IGN) |
| 8381 | signal (SIGINT, handler: fatal_signal); |
| 8382 | #ifdef SIGHUP |
| 8383 | if (signal (SIGHUP, SIG_IGN) != SIG_IGN) |
| 8384 | signal (SIGHUP, handler: fatal_signal); |
| 8385 | #endif |
| 8386 | if (signal (SIGTERM, SIG_IGN) != SIG_IGN) |
| 8387 | signal (SIGTERM, handler: fatal_signal); |
| 8388 | #ifdef SIGPIPE |
| 8389 | if (signal (SIGPIPE, SIG_IGN) != SIG_IGN) |
| 8390 | signal (SIGPIPE, handler: fatal_signal); |
| 8391 | #endif |
| 8392 | #ifdef SIGCHLD |
| 8393 | /* We *MUST* set SIGCHLD to SIG_DFL so that the wait4() call will |
| 8394 | receive the signal. A different setting is inheritable */ |
| 8395 | signal (SIGCHLD, SIG_DFL); |
| 8396 | #endif |
| 8397 | |
| 8398 | /* Parsing and gimplification sometimes need quite large stack. |
| 8399 | Increase stack size limits if possible. */ |
| 8400 | stack_limit_increase (64 * 1024 * 1024); |
| 8401 | |
| 8402 | /* Allocate the argument vector. */ |
| 8403 | alloc_args (); |
| 8404 | |
| 8405 | obstack_init (&obstack); |
| 8406 | } |
| 8407 | |
| 8408 | /* Build multilib_select, et. al from the separate lines that make up each |
| 8409 | multilib selection. */ |
| 8410 | |
| 8411 | void |
| 8412 | driver::build_multilib_strings () const |
| 8413 | { |
| 8414 | { |
| 8415 | const char *p; |
| 8416 | const char *const *q = multilib_raw; |
| 8417 | int need_space; |
| 8418 | |
| 8419 | obstack_init (&multilib_obstack); |
| 8420 | while ((p = *q++) != (char *) 0) |
| 8421 | obstack_grow (&multilib_obstack, p, strlen (p)); |
| 8422 | |
| 8423 | obstack_1grow (&multilib_obstack, 0); |
| 8424 | multilib_select = XOBFINISH (&multilib_obstack, const char *); |
| 8425 | |
| 8426 | q = multilib_matches_raw; |
| 8427 | while ((p = *q++) != (char *) 0) |
| 8428 | obstack_grow (&multilib_obstack, p, strlen (p)); |
| 8429 | |
| 8430 | obstack_1grow (&multilib_obstack, 0); |
| 8431 | multilib_matches = XOBFINISH (&multilib_obstack, const char *); |
| 8432 | |
| 8433 | q = multilib_exclusions_raw; |
| 8434 | while ((p = *q++) != (char *) 0) |
| 8435 | obstack_grow (&multilib_obstack, p, strlen (p)); |
| 8436 | |
| 8437 | obstack_1grow (&multilib_obstack, 0); |
| 8438 | multilib_exclusions = XOBFINISH (&multilib_obstack, const char *); |
| 8439 | |
| 8440 | q = multilib_reuse_raw; |
| 8441 | while ((p = *q++) != (char *) 0) |
| 8442 | obstack_grow (&multilib_obstack, p, strlen (p)); |
| 8443 | |
| 8444 | obstack_1grow (&multilib_obstack, 0); |
| 8445 | multilib_reuse = XOBFINISH (&multilib_obstack, const char *); |
| 8446 | |
| 8447 | need_space = false; |
| 8448 | for (size_t i = 0; i < ARRAY_SIZE (multilib_defaults_raw); i++) |
| 8449 | { |
| 8450 | if (need_space) |
| 8451 | obstack_1grow (&multilib_obstack, ' '); |
| 8452 | obstack_grow (&multilib_obstack, |
| 8453 | multilib_defaults_raw[i], |
| 8454 | strlen (multilib_defaults_raw[i])); |
| 8455 | need_space = true; |
| 8456 | } |
| 8457 | |
| 8458 | obstack_1grow (&multilib_obstack, 0); |
| 8459 | multilib_defaults = XOBFINISH (&multilib_obstack, const char *); |
| 8460 | } |
| 8461 | } |
| 8462 | |
| 8463 | /* Set up the spec-handling machinery. */ |
| 8464 | |
| 8465 | void |
| 8466 | driver::set_up_specs () const |
| 8467 | { |
| 8468 | const char *spec_machine_suffix; |
| 8469 | char *specs_file; |
| 8470 | size_t i; |
| 8471 | |
| 8472 | #ifdef INIT_ENVIRONMENT |
| 8473 | /* Set up any other necessary machine specific environment variables. */ |
| 8474 | xputenv (INIT_ENVIRONMENT); |
| 8475 | #endif |
| 8476 | |
| 8477 | /* Make a table of what switches there are (switches, n_switches). |
| 8478 | Make a table of specified input files (infiles, n_infiles). |
| 8479 | Decode switches that are handled locally. */ |
| 8480 | |
| 8481 | process_command (decoded_options_count, decoded_options); |
| 8482 | |
| 8483 | /* Initialize the vector of specs to just the default. |
| 8484 | This means one element containing 0s, as a terminator. */ |
| 8485 | |
| 8486 | compilers = XNEWVAR (struct compiler, sizeof default_compilers); |
| 8487 | memcpy (dest: compilers, src: default_compilers, n: sizeof default_compilers); |
| 8488 | n_compilers = n_default_compilers; |
| 8489 | |
| 8490 | /* Read specs from a file if there is one. */ |
| 8491 | |
| 8492 | machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version, |
| 8493 | accel_dir_suffix, dir_separator_str, NULL); |
| 8494 | just_machine_suffix = concat (spec_machine, dir_separator_str, NULL); |
| 8495 | |
| 8496 | specs_file = find_a_file (pprefix: &startfile_prefixes, name: "specs" , R_OK, do_multi: true); |
| 8497 | /* Read the specs file unless it is a default one. */ |
| 8498 | if (specs_file != 0 && strcmp (s1: specs_file, s2: "specs" )) |
| 8499 | read_specs (filename: specs_file, main_p: true, user_p: false); |
| 8500 | else |
| 8501 | init_spec (); |
| 8502 | |
| 8503 | #ifdef ACCEL_COMPILER |
| 8504 | spec_machine_suffix = machine_suffix; |
| 8505 | #else |
| 8506 | spec_machine_suffix = just_machine_suffix; |
| 8507 | #endif |
| 8508 | |
| 8509 | /* We need to check standard_exec_prefix/spec_machine_suffix/specs |
| 8510 | for any override of as, ld and libraries. */ |
| 8511 | specs_file = (char *) alloca (strlen (standard_exec_prefix) |
| 8512 | + strlen (spec_machine_suffix) + sizeof ("specs" )); |
| 8513 | strcpy (dest: specs_file, src: standard_exec_prefix); |
| 8514 | strcat (dest: specs_file, src: spec_machine_suffix); |
| 8515 | strcat (dest: specs_file, src: "specs" ); |
| 8516 | if (access (name: specs_file, R_OK) == 0) |
| 8517 | read_specs (filename: specs_file, main_p: true, user_p: false); |
| 8518 | |
| 8519 | /* Process any configure-time defaults specified for the command line |
| 8520 | options, via OPTION_DEFAULT_SPECS. */ |
| 8521 | for (i = 0; i < ARRAY_SIZE (option_default_specs); i++) |
| 8522 | do_option_spec (name: option_default_specs[i].name, |
| 8523 | spec: option_default_specs[i].spec); |
| 8524 | |
| 8525 | /* Process DRIVER_SELF_SPECS, adding any new options to the end |
| 8526 | of the command line. */ |
| 8527 | |
| 8528 | for (i = 0; i < ARRAY_SIZE (driver_self_specs); i++) |
| 8529 | do_self_spec (driver_self_specs[i]); |
| 8530 | |
| 8531 | /* If not cross-compiling, look for executables in the standard |
| 8532 | places. */ |
| 8533 | if (*cross_compile == '0') |
| 8534 | { |
| 8535 | if (*md_exec_prefix) |
| 8536 | { |
| 8537 | add_prefix (pprefix: &exec_prefixes, prefix: md_exec_prefix, component: "GCC" , |
| 8538 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 0); |
| 8539 | } |
| 8540 | } |
| 8541 | |
| 8542 | /* Process sysroot_suffix_spec. */ |
| 8543 | if (*sysroot_suffix_spec != 0 |
| 8544 | && !no_sysroot_suffix |
| 8545 | && do_spec_2 (spec: sysroot_suffix_spec, NULL) == 0) |
| 8546 | { |
| 8547 | if (argbuf.length () > 1) |
| 8548 | error ("spec failure: more than one argument to " |
| 8549 | "%<SYSROOT_SUFFIX_SPEC%>" ); |
| 8550 | else if (argbuf.length () == 1) |
| 8551 | target_sysroot_suffix = xstrdup (argbuf.last ()); |
| 8552 | } |
| 8553 | |
| 8554 | #ifdef HAVE_LD_SYSROOT |
| 8555 | /* Pass the --sysroot option to the linker, if it supports that. If |
| 8556 | there is a sysroot_suffix_spec, it has already been processed by |
| 8557 | this point, so target_system_root really is the system root we |
| 8558 | should be using. */ |
| 8559 | if (target_system_root) |
| 8560 | { |
| 8561 | obstack_grow (&obstack, "%(sysroot_spec) " , strlen ("%(sysroot_spec) " )); |
| 8562 | obstack_grow0 (&obstack, link_spec, strlen (link_spec)); |
| 8563 | set_spec (name: "link" , XOBFINISH (&obstack, const char *), user_p: false); |
| 8564 | } |
| 8565 | #endif |
| 8566 | |
| 8567 | /* Process sysroot_hdrs_suffix_spec. */ |
| 8568 | if (*sysroot_hdrs_suffix_spec != 0 |
| 8569 | && !no_sysroot_suffix |
| 8570 | && do_spec_2 (spec: sysroot_hdrs_suffix_spec, NULL) == 0) |
| 8571 | { |
| 8572 | if (argbuf.length () > 1) |
| 8573 | error ("spec failure: more than one argument " |
| 8574 | "to %<SYSROOT_HEADERS_SUFFIX_SPEC%>" ); |
| 8575 | else if (argbuf.length () == 1) |
| 8576 | target_sysroot_hdrs_suffix = xstrdup (argbuf.last ()); |
| 8577 | } |
| 8578 | |
| 8579 | /* Look for startfiles in the standard places. */ |
| 8580 | if (*startfile_prefix_spec != 0 |
| 8581 | && do_spec_2 (spec: startfile_prefix_spec, NULL) == 0 |
| 8582 | && do_spec_1 (spec: " " , inswitch: 0, NULL) == 0) |
| 8583 | { |
| 8584 | for (const char *arg : argbuf) |
| 8585 | add_sysrooted_prefix (pprefix: &startfile_prefixes, prefix: arg, component: "BINUTILS" , |
| 8586 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8587 | } |
| 8588 | /* We should eventually get rid of all these and stick to |
| 8589 | startfile_prefix_spec exclusively. */ |
| 8590 | else if (*cross_compile == '0' || target_system_root) |
| 8591 | { |
| 8592 | if (*md_startfile_prefix) |
| 8593 | add_sysrooted_prefix (pprefix: &startfile_prefixes, prefix: md_startfile_prefix, |
| 8594 | component: "GCC" , priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8595 | |
| 8596 | if (*md_startfile_prefix_1) |
| 8597 | add_sysrooted_prefix (pprefix: &startfile_prefixes, prefix: md_startfile_prefix_1, |
| 8598 | component: "GCC" , priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8599 | |
| 8600 | /* If standard_startfile_prefix is relative, base it on |
| 8601 | standard_exec_prefix. This lets us move the installed tree |
| 8602 | as a unit. If GCC_EXEC_PREFIX is defined, base |
| 8603 | standard_startfile_prefix on that as well. |
| 8604 | |
| 8605 | If the prefix is relative, only search it for native compilers; |
| 8606 | otherwise we will search a directory containing host libraries. */ |
| 8607 | if (IS_ABSOLUTE_PATH (standard_startfile_prefix)) |
| 8608 | add_sysrooted_prefix (pprefix: &startfile_prefixes, |
| 8609 | prefix: standard_startfile_prefix, component: "BINUTILS" , |
| 8610 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8611 | else if (*cross_compile == '0') |
| 8612 | { |
| 8613 | add_prefix (pprefix: &startfile_prefixes, |
| 8614 | prefix: concat (gcc_exec_prefix |
| 8615 | ? gcc_exec_prefix : standard_exec_prefix, |
| 8616 | machine_suffix, |
| 8617 | standard_startfile_prefix, NULL), |
| 8618 | NULL, priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8619 | } |
| 8620 | |
| 8621 | /* Sysrooted prefixes are relocated because target_system_root is |
| 8622 | also relocated by gcc_exec_prefix. */ |
| 8623 | if (*standard_startfile_prefix_1) |
| 8624 | add_sysrooted_prefix (pprefix: &startfile_prefixes, |
| 8625 | prefix: standard_startfile_prefix_1, component: "BINUTILS" , |
| 8626 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8627 | if (*standard_startfile_prefix_2) |
| 8628 | add_sysrooted_prefix (pprefix: &startfile_prefixes, |
| 8629 | prefix: standard_startfile_prefix_2, component: "BINUTILS" , |
| 8630 | priority: PREFIX_PRIORITY_LAST, require_machine_suffix: 0, os_multilib: 1); |
| 8631 | } |
| 8632 | |
| 8633 | /* Process any user specified specs in the order given on the command |
| 8634 | line. */ |
| 8635 | for (struct user_specs *uptr = user_specs_head; uptr; uptr = uptr->next) |
| 8636 | { |
| 8637 | char *filename = find_a_file (pprefix: &startfile_prefixes, name: uptr->filename, |
| 8638 | R_OK, do_multi: true); |
| 8639 | read_specs (filename: filename ? filename : uptr->filename, main_p: false, user_p: true); |
| 8640 | } |
| 8641 | |
| 8642 | /* Process any user self specs. */ |
| 8643 | { |
| 8644 | struct spec_list *sl; |
| 8645 | for (sl = specs; sl; sl = sl->next) |
| 8646 | if (sl->name_len == sizeof "self_spec" - 1 |
| 8647 | && !strcmp (s1: sl->name, s2: "self_spec" )) |
| 8648 | do_self_spec (spec: *sl->ptr_spec); |
| 8649 | } |
| 8650 | |
| 8651 | if (compare_debug) |
| 8652 | { |
| 8653 | enum save_temps save; |
| 8654 | |
| 8655 | if (!compare_debug_second) |
| 8656 | { |
| 8657 | n_switches_debug_check[1] = n_switches; |
| 8658 | n_switches_alloc_debug_check[1] = n_switches_alloc; |
| 8659 | switches_debug_check[1] = XDUPVEC (struct switchstr, switches, |
| 8660 | n_switches_alloc); |
| 8661 | |
| 8662 | do_self_spec (spec: "%:compare-debug-self-opt()" ); |
| 8663 | n_switches_debug_check[0] = n_switches; |
| 8664 | n_switches_alloc_debug_check[0] = n_switches_alloc; |
| 8665 | switches_debug_check[0] = switches; |
| 8666 | |
| 8667 | n_switches = n_switches_debug_check[1]; |
| 8668 | n_switches_alloc = n_switches_alloc_debug_check[1]; |
| 8669 | switches = switches_debug_check[1]; |
| 8670 | } |
| 8671 | |
| 8672 | /* Avoid crash when computing %j in this early. */ |
| 8673 | save = save_temps_flag; |
| 8674 | save_temps_flag = SAVE_TEMPS_NONE; |
| 8675 | |
| 8676 | compare_debug = -compare_debug; |
| 8677 | do_self_spec (spec: "%:compare-debug-self-opt()" ); |
| 8678 | |
| 8679 | save_temps_flag = save; |
| 8680 | |
| 8681 | if (!compare_debug_second) |
| 8682 | { |
| 8683 | n_switches_debug_check[1] = n_switches; |
| 8684 | n_switches_alloc_debug_check[1] = n_switches_alloc; |
| 8685 | switches_debug_check[1] = switches; |
| 8686 | compare_debug = -compare_debug; |
| 8687 | n_switches = n_switches_debug_check[0]; |
| 8688 | n_switches_alloc = n_switches_debug_check[0]; |
| 8689 | switches = switches_debug_check[0]; |
| 8690 | } |
| 8691 | } |
| 8692 | |
| 8693 | |
| 8694 | /* If we have a GCC_EXEC_PREFIX envvar, modify it for cpp's sake. */ |
| 8695 | if (gcc_exec_prefix) |
| 8696 | gcc_exec_prefix = concat (gcc_exec_prefix, spec_host_machine, |
| 8697 | dir_separator_str, spec_version, |
| 8698 | accel_dir_suffix, dir_separator_str, NULL); |
| 8699 | |
| 8700 | /* Now we have the specs. |
| 8701 | Set the `valid' bits for switches that match anything in any spec. */ |
| 8702 | |
| 8703 | validate_all_switches (); |
| 8704 | |
| 8705 | /* Now that we have the switches and the specs, set |
| 8706 | the subdirectory based on the options. */ |
| 8707 | set_multilib_dir (); |
| 8708 | } |
| 8709 | |
| 8710 | /* Set up to remember the pathname of gcc and any options |
| 8711 | needed for collect. We use argv[0] instead of progname because |
| 8712 | we need the complete pathname. */ |
| 8713 | |
| 8714 | void |
| 8715 | driver::putenv_COLLECT_GCC (const char *argv0) const |
| 8716 | { |
| 8717 | obstack_init (&collect_obstack); |
| 8718 | obstack_grow (&collect_obstack, "COLLECT_GCC=" , sizeof ("COLLECT_GCC=" ) - 1); |
| 8719 | obstack_grow (&collect_obstack, argv0, strlen (argv0) + 1); |
| 8720 | xputenv (XOBFINISH (&collect_obstack, char *)); |
| 8721 | } |
| 8722 | |
| 8723 | /* Set up to remember the pathname of the lto wrapper. */ |
| 8724 | |
| 8725 | void |
| 8726 | driver::maybe_putenv_COLLECT_LTO_WRAPPER () const |
| 8727 | { |
| 8728 | char *lto_wrapper_file; |
| 8729 | |
| 8730 | if (have_c) |
| 8731 | lto_wrapper_file = NULL; |
| 8732 | else |
| 8733 | lto_wrapper_file = find_a_program (name: "lto-wrapper" ); |
| 8734 | if (lto_wrapper_file) |
| 8735 | { |
| 8736 | lto_wrapper_file = convert_white_space (lto_wrapper_file); |
| 8737 | set_static_spec_owned (spec: <o_wrapper_spec, val: lto_wrapper_file); |
| 8738 | obstack_init (&collect_obstack); |
| 8739 | obstack_grow (&collect_obstack, "COLLECT_LTO_WRAPPER=" , |
| 8740 | sizeof ("COLLECT_LTO_WRAPPER=" ) - 1); |
| 8741 | obstack_grow (&collect_obstack, lto_wrapper_spec, |
| 8742 | strlen (lto_wrapper_spec) + 1); |
| 8743 | xputenv (XOBFINISH (&collect_obstack, char *)); |
| 8744 | } |
| 8745 | |
| 8746 | } |
| 8747 | |
| 8748 | /* Set up to remember the names of offload targets. */ |
| 8749 | |
| 8750 | void |
| 8751 | driver::maybe_putenv_OFFLOAD_TARGETS () const |
| 8752 | { |
| 8753 | if (offload_targets && offload_targets[0] != '\0') |
| 8754 | { |
| 8755 | obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=" , |
| 8756 | sizeof ("OFFLOAD_TARGET_NAMES=" ) - 1); |
| 8757 | obstack_grow (&collect_obstack, offload_targets, |
| 8758 | strlen (offload_targets) + 1); |
| 8759 | xputenv (XOBFINISH (&collect_obstack, char *)); |
| 8760 | #if OFFLOAD_DEFAULTED |
| 8761 | if (offload_targets_default) |
| 8762 | xputenv ("OFFLOAD_TARGET_DEFAULT=1" ); |
| 8763 | #endif |
| 8764 | } |
| 8765 | |
| 8766 | free (ptr: offload_targets); |
| 8767 | offload_targets = NULL; |
| 8768 | } |
| 8769 | |
| 8770 | /* Reject switches that no pass was interested in. */ |
| 8771 | |
| 8772 | void |
| 8773 | driver::handle_unrecognized_options () |
| 8774 | { |
| 8775 | for (size_t i = 0; (int) i < n_switches; i++) |
| 8776 | if (! switches[i].validated) |
| 8777 | { |
| 8778 | const char *hint = m_option_proposer.suggest_option (bad_opt: switches[i].part1); |
| 8779 | if (hint) |
| 8780 | error ("unrecognized command-line option %<-%s%>;" |
| 8781 | " did you mean %<-%s%>?" , |
| 8782 | switches[i].part1, hint); |
| 8783 | else |
| 8784 | error ("unrecognized command-line option %<-%s%>" , |
| 8785 | switches[i].part1); |
| 8786 | } |
| 8787 | } |
| 8788 | |
| 8789 | /* Handle the various -print-* options, returning 0 if the driver |
| 8790 | should exit, or nonzero if the driver should continue. */ |
| 8791 | |
| 8792 | int |
| 8793 | driver::maybe_print_and_exit () const |
| 8794 | { |
| 8795 | if (print_search_dirs) |
| 8796 | { |
| 8797 | printf (_("install: %s%s\n" ), |
| 8798 | gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix, |
| 8799 | gcc_exec_prefix ? "" : machine_suffix); |
| 8800 | printf (_("programs: %s\n" ), |
| 8801 | build_search_list (paths: &exec_prefixes, prefix: "" , check_dir: false, do_multi: false)); |
| 8802 | printf (_("libraries: %s\n" ), |
| 8803 | build_search_list (paths: &startfile_prefixes, prefix: "" , check_dir: false, do_multi: true)); |
| 8804 | return (0); |
| 8805 | } |
| 8806 | |
| 8807 | if (print_file_name) |
| 8808 | { |
| 8809 | printf (format: "%s\n" , find_file (print_file_name)); |
| 8810 | return (0); |
| 8811 | } |
| 8812 | |
| 8813 | if (print_prog_name) |
| 8814 | { |
| 8815 | if (use_ld != NULL && ! strcmp (print_prog_name, s2: "ld" )) |
| 8816 | { |
| 8817 | /* Append USE_LD to the default linker. */ |
| 8818 | #ifdef DEFAULT_LINKER |
| 8819 | char *ld; |
| 8820 | # ifdef HAVE_HOST_EXECUTABLE_SUFFIX |
| 8821 | int len = (sizeof (DEFAULT_LINKER) |
| 8822 | - sizeof (HOST_EXECUTABLE_SUFFIX)); |
| 8823 | ld = NULL; |
| 8824 | if (len > 0) |
| 8825 | { |
| 8826 | char *default_linker = xstrdup (DEFAULT_LINKER); |
| 8827 | /* Strip HOST_EXECUTABLE_SUFFIX if DEFAULT_LINKER contains |
| 8828 | HOST_EXECUTABLE_SUFFIX. */ |
| 8829 | if (! strcmp (&default_linker[len], HOST_EXECUTABLE_SUFFIX)) |
| 8830 | { |
| 8831 | default_linker[len] = '\0'; |
| 8832 | ld = concat (default_linker, use_ld, |
| 8833 | HOST_EXECUTABLE_SUFFIX, NULL); |
| 8834 | } |
| 8835 | } |
| 8836 | if (ld == NULL) |
| 8837 | # endif |
| 8838 | ld = concat (DEFAULT_LINKER, use_ld, NULL); |
| 8839 | if (access (ld, X_OK) == 0) |
| 8840 | { |
| 8841 | printf ("%s\n" , ld); |
| 8842 | return (0); |
| 8843 | } |
| 8844 | #endif |
| 8845 | print_prog_name = concat (print_prog_name, use_ld, NULL); |
| 8846 | } |
| 8847 | char *newname = find_a_program (print_prog_name); |
| 8848 | printf (format: "%s\n" , (newname ? newname : print_prog_name)); |
| 8849 | return (0); |
| 8850 | } |
| 8851 | |
| 8852 | if (print_multi_lib) |
| 8853 | { |
| 8854 | print_multilib_info (); |
| 8855 | return (0); |
| 8856 | } |
| 8857 | |
| 8858 | if (print_multi_directory) |
| 8859 | { |
| 8860 | if (multilib_dir == NULL) |
| 8861 | printf (format: ".\n" ); |
| 8862 | else |
| 8863 | printf (format: "%s\n" , multilib_dir); |
| 8864 | return (0); |
| 8865 | } |
| 8866 | |
| 8867 | if (print_multiarch) |
| 8868 | { |
| 8869 | if (multiarch_dir == NULL) |
| 8870 | printf (format: "\n" ); |
| 8871 | else |
| 8872 | printf (format: "%s\n" , multiarch_dir); |
| 8873 | return (0); |
| 8874 | } |
| 8875 | |
| 8876 | if (print_sysroot) |
| 8877 | { |
| 8878 | if (target_system_root) |
| 8879 | { |
| 8880 | if (target_sysroot_suffix) |
| 8881 | printf (format: "%s%s\n" , target_system_root, target_sysroot_suffix); |
| 8882 | else |
| 8883 | printf (format: "%s\n" , target_system_root); |
| 8884 | } |
| 8885 | return (0); |
| 8886 | } |
| 8887 | |
| 8888 | if (print_multi_os_directory) |
| 8889 | { |
| 8890 | if (multilib_os_dir == NULL) |
| 8891 | printf (format: ".\n" ); |
| 8892 | else |
| 8893 | printf (format: "%s\n" , multilib_os_dir); |
| 8894 | return (0); |
| 8895 | } |
| 8896 | |
| 8897 | if (print_sysroot_headers_suffix) |
| 8898 | { |
| 8899 | if (*sysroot_hdrs_suffix_spec) |
| 8900 | { |
| 8901 | printf(format: "%s\n" , (target_sysroot_hdrs_suffix |
| 8902 | ? target_sysroot_hdrs_suffix |
| 8903 | : "" )); |
| 8904 | return (0); |
| 8905 | } |
| 8906 | else |
| 8907 | /* The error status indicates that only one set of fixed |
| 8908 | headers should be built. */ |
| 8909 | fatal_error (input_location, |
| 8910 | "not configured with sysroot headers suffix" ); |
| 8911 | } |
| 8912 | |
| 8913 | if (print_help_list) |
| 8914 | { |
| 8915 | display_help (); |
| 8916 | |
| 8917 | if (! verbose_flag) |
| 8918 | { |
| 8919 | printf (_("\nFor bug reporting instructions, please see:\n" )); |
| 8920 | printf (format: "%s.\n" , bug_report_url); |
| 8921 | |
| 8922 | return (0); |
| 8923 | } |
| 8924 | |
| 8925 | /* We do not exit here. Instead we have created a fake input file |
| 8926 | called 'help-dummy' which needs to be compiled, and we pass this |
| 8927 | on the various sub-processes, along with the --help switch. |
| 8928 | Ensure their output appears after ours. */ |
| 8929 | fputc (c: '\n', stdout); |
| 8930 | fflush (stdout); |
| 8931 | } |
| 8932 | |
| 8933 | if (print_version) |
| 8934 | { |
| 8935 | printf (_("%s %s%s\n" ), progname, pkgversion_string, |
| 8936 | version_string); |
| 8937 | printf (format: "Copyright %s 2025 Free Software Foundation, Inc.\n" , |
| 8938 | _("(C)" )); |
| 8939 | fputs (_("This is free software; see the source for copying conditions. There is NO\n\ |
| 8940 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n" ), |
| 8941 | stdout); |
| 8942 | if (! verbose_flag) |
| 8943 | return 0; |
| 8944 | |
| 8945 | /* We do not exit here. We use the same mechanism of --help to print |
| 8946 | the version of the sub-processes. */ |
| 8947 | fputc (c: '\n', stdout); |
| 8948 | fflush (stdout); |
| 8949 | } |
| 8950 | |
| 8951 | if (verbose_flag) |
| 8952 | { |
| 8953 | print_configuration (stderr); |
| 8954 | if (n_infiles == 0) |
| 8955 | return (0); |
| 8956 | } |
| 8957 | |
| 8958 | return 1; |
| 8959 | } |
| 8960 | |
| 8961 | /* Figure out what to do with each input file. |
| 8962 | Return true if we need to exit early from "main", false otherwise. */ |
| 8963 | |
| 8964 | bool |
| 8965 | driver::prepare_infiles () |
| 8966 | { |
| 8967 | size_t i; |
| 8968 | int lang_n_infiles = 0; |
| 8969 | |
| 8970 | if (n_infiles == added_libraries) |
| 8971 | fatal_error (input_location, "no input files" ); |
| 8972 | |
| 8973 | if (seen_error ()) |
| 8974 | /* Early exit needed from main. */ |
| 8975 | return true; |
| 8976 | |
| 8977 | /* Make a place to record the compiler output file names |
| 8978 | that correspond to the input files. */ |
| 8979 | |
| 8980 | i = n_infiles; |
| 8981 | i += lang_specific_extra_outfiles; |
| 8982 | outfiles = XCNEWVEC (const char *, i); |
| 8983 | |
| 8984 | /* Record which files were specified explicitly as link input. */ |
| 8985 | |
| 8986 | explicit_link_files = XCNEWVEC (char, n_infiles); |
| 8987 | |
| 8988 | combine_inputs = have_o || flag_wpa; |
| 8989 | |
| 8990 | for (i = 0; (int) i < n_infiles; i++) |
| 8991 | { |
| 8992 | const char *name = infiles[i].name; |
| 8993 | struct compiler *compiler = lookup_compiler (name, |
| 8994 | strlen (s: name), |
| 8995 | infiles[i].language); |
| 8996 | |
| 8997 | if (compiler && !(compiler->combinable)) |
| 8998 | combine_inputs = false; |
| 8999 | |
| 9000 | if (lang_n_infiles > 0 && compiler != input_file_compiler |
| 9001 | && infiles[i].language && infiles[i].language[0] != '*') |
| 9002 | infiles[i].incompiler = compiler; |
| 9003 | else if (compiler) |
| 9004 | { |
| 9005 | lang_n_infiles++; |
| 9006 | input_file_compiler = compiler; |
| 9007 | infiles[i].incompiler = compiler; |
| 9008 | } |
| 9009 | else |
| 9010 | { |
| 9011 | /* Since there is no compiler for this input file, assume it is a |
| 9012 | linker file. */ |
| 9013 | explicit_link_files[i] = 1; |
| 9014 | infiles[i].incompiler = NULL; |
| 9015 | } |
| 9016 | infiles[i].compiled = false; |
| 9017 | infiles[i].preprocessed = false; |
| 9018 | } |
| 9019 | |
| 9020 | if (!combine_inputs && have_c && have_o && lang_n_infiles > 1) |
| 9021 | fatal_error (input_location, |
| 9022 | "cannot specify %<-o%> with %<-c%>, %<-S%> or %<-E%> " |
| 9023 | "with multiple files" ); |
| 9024 | |
| 9025 | /* No early exit needed from main; we can continue. */ |
| 9026 | return false; |
| 9027 | } |
| 9028 | |
| 9029 | /* Run the spec machinery on each input file. */ |
| 9030 | |
| 9031 | void |
| 9032 | driver::do_spec_on_infiles () const |
| 9033 | { |
| 9034 | size_t i; |
| 9035 | |
| 9036 | for (i = 0; (int) i < n_infiles; i++) |
| 9037 | { |
| 9038 | int this_file_error = 0; |
| 9039 | |
| 9040 | /* Tell do_spec what to substitute for %i. */ |
| 9041 | |
| 9042 | input_file_number = i; |
| 9043 | set_input (infiles[i].name); |
| 9044 | |
| 9045 | if (infiles[i].compiled) |
| 9046 | continue; |
| 9047 | |
| 9048 | /* Use the same thing in %o, unless cp->spec says otherwise. */ |
| 9049 | |
| 9050 | outfiles[i] = gcc_input_filename; |
| 9051 | |
| 9052 | /* Figure out which compiler from the file's suffix. */ |
| 9053 | |
| 9054 | input_file_compiler |
| 9055 | = lookup_compiler (infiles[i].name, input_filename_length, |
| 9056 | infiles[i].language); |
| 9057 | |
| 9058 | if (input_file_compiler) |
| 9059 | { |
| 9060 | /* Ok, we found an applicable compiler. Run its spec. */ |
| 9061 | |
| 9062 | if (input_file_compiler->spec[0] == '#') |
| 9063 | { |
| 9064 | error ("%s: %s compiler not installed on this system" , |
| 9065 | gcc_input_filename, &input_file_compiler->spec[1]); |
| 9066 | this_file_error = 1; |
| 9067 | } |
| 9068 | else |
| 9069 | { |
| 9070 | int value; |
| 9071 | |
| 9072 | if (compare_debug) |
| 9073 | { |
| 9074 | free (ptr: debug_check_temp_file[0]); |
| 9075 | debug_check_temp_file[0] = NULL; |
| 9076 | |
| 9077 | free (ptr: debug_check_temp_file[1]); |
| 9078 | debug_check_temp_file[1] = NULL; |
| 9079 | } |
| 9080 | |
| 9081 | value = do_spec (spec: input_file_compiler->spec); |
| 9082 | infiles[i].compiled = true; |
| 9083 | if (value < 0) |
| 9084 | this_file_error = 1; |
| 9085 | else if (compare_debug && debug_check_temp_file[0]) |
| 9086 | { |
| 9087 | if (verbose_flag) |
| 9088 | inform (UNKNOWN_LOCATION, |
| 9089 | "recompiling with %<-fcompare-debug%>" ); |
| 9090 | |
| 9091 | compare_debug = -compare_debug; |
| 9092 | n_switches = n_switches_debug_check[1]; |
| 9093 | n_switches_alloc = n_switches_alloc_debug_check[1]; |
| 9094 | switches = switches_debug_check[1]; |
| 9095 | |
| 9096 | value = do_spec (spec: input_file_compiler->spec); |
| 9097 | |
| 9098 | compare_debug = -compare_debug; |
| 9099 | n_switches = n_switches_debug_check[0]; |
| 9100 | n_switches_alloc = n_switches_alloc_debug_check[0]; |
| 9101 | switches = switches_debug_check[0]; |
| 9102 | |
| 9103 | if (value < 0) |
| 9104 | { |
| 9105 | error ("during %<-fcompare-debug%> recompilation" ); |
| 9106 | this_file_error = 1; |
| 9107 | } |
| 9108 | |
| 9109 | gcc_assert (debug_check_temp_file[1] |
| 9110 | && filename_cmp (debug_check_temp_file[0], |
| 9111 | debug_check_temp_file[1])); |
| 9112 | |
| 9113 | if (verbose_flag) |
| 9114 | inform (UNKNOWN_LOCATION, "comparing final insns dumps" ); |
| 9115 | |
| 9116 | if (compare_files (cmpfile: debug_check_temp_file)) |
| 9117 | this_file_error = 1; |
| 9118 | } |
| 9119 | |
| 9120 | if (compare_debug) |
| 9121 | { |
| 9122 | free (ptr: debug_check_temp_file[0]); |
| 9123 | debug_check_temp_file[0] = NULL; |
| 9124 | |
| 9125 | free (ptr: debug_check_temp_file[1]); |
| 9126 | debug_check_temp_file[1] = NULL; |
| 9127 | } |
| 9128 | } |
| 9129 | } |
| 9130 | |
| 9131 | /* If this file's name does not contain a recognized suffix, |
| 9132 | record it as explicit linker input. */ |
| 9133 | |
| 9134 | else |
| 9135 | explicit_link_files[i] = 1; |
| 9136 | |
| 9137 | /* Clear the delete-on-failure queue, deleting the files in it |
| 9138 | if this compilation failed. */ |
| 9139 | |
| 9140 | if (this_file_error) |
| 9141 | { |
| 9142 | delete_failure_queue (); |
| 9143 | errorcount++; |
| 9144 | } |
| 9145 | /* If this compilation succeeded, don't delete those files later. */ |
| 9146 | clear_failure_queue (); |
| 9147 | } |
| 9148 | |
| 9149 | /* Reset the input file name to the first compile/object file name, for use |
| 9150 | with %b in LINK_SPEC. We use the first input file that we can find |
| 9151 | a compiler to compile it instead of using infiles.language since for |
| 9152 | languages other than C we use aliases that we then lookup later. */ |
| 9153 | if (n_infiles > 0) |
| 9154 | { |
| 9155 | int i; |
| 9156 | |
| 9157 | for (i = 0; i < n_infiles ; i++) |
| 9158 | if (infiles[i].incompiler |
| 9159 | || (infiles[i].language && infiles[i].language[0] != '*')) |
| 9160 | { |
| 9161 | set_input (infiles[i].name); |
| 9162 | break; |
| 9163 | } |
| 9164 | } |
| 9165 | |
| 9166 | if (!seen_error ()) |
| 9167 | { |
| 9168 | /* Make sure INPUT_FILE_NUMBER points to first available open |
| 9169 | slot. */ |
| 9170 | input_file_number = n_infiles; |
| 9171 | if (lang_specific_pre_link ()) |
| 9172 | errorcount++; |
| 9173 | } |
| 9174 | } |
| 9175 | |
| 9176 | /* If we have to run the linker, do it now. */ |
| 9177 | |
| 9178 | void |
| 9179 | driver::maybe_run_linker (const char *argv0) const |
| 9180 | { |
| 9181 | size_t i; |
| 9182 | int linker_was_run = 0; |
| 9183 | int num_linker_inputs; |
| 9184 | |
| 9185 | /* Determine if there are any linker input files. */ |
| 9186 | num_linker_inputs = 0; |
| 9187 | for (i = 0; (int) i < n_infiles; i++) |
| 9188 | if (explicit_link_files[i] || outfiles[i] != NULL) |
| 9189 | num_linker_inputs++; |
| 9190 | |
| 9191 | /* Arrange for temporary file names created during linking to take |
| 9192 | on names related with the linker output rather than with the |
| 9193 | inputs when appropriate. */ |
| 9194 | if (outbase && *outbase) |
| 9195 | { |
| 9196 | if (dumpdir) |
| 9197 | { |
| 9198 | char *tofree = dumpdir; |
| 9199 | gcc_checking_assert (strlen (dumpdir) == dumpdir_length); |
| 9200 | dumpdir = concat (dumpdir, outbase, "." , NULL); |
| 9201 | free (ptr: tofree); |
| 9202 | } |
| 9203 | else |
| 9204 | dumpdir = concat (outbase, "." , NULL); |
| 9205 | dumpdir_length += strlen (s: outbase) + 1; |
| 9206 | dumpdir_trailing_dash_added = true; |
| 9207 | } |
| 9208 | else if (dumpdir_trailing_dash_added) |
| 9209 | { |
| 9210 | gcc_assert (dumpdir[dumpdir_length - 1] == '-'); |
| 9211 | dumpdir[dumpdir_length - 1] = '.'; |
| 9212 | } |
| 9213 | |
| 9214 | if (dumpdir_trailing_dash_added) |
| 9215 | { |
| 9216 | gcc_assert (dumpdir_length > 0); |
| 9217 | gcc_assert (dumpdir[dumpdir_length - 1] == '.'); |
| 9218 | dumpdir_length--; |
| 9219 | } |
| 9220 | |
| 9221 | free (ptr: outbase); |
| 9222 | input_basename = outbase = NULL; |
| 9223 | outbase_length = suffixed_basename_length = basename_length = 0; |
| 9224 | |
| 9225 | /* Run ld to link all the compiler output files. */ |
| 9226 | |
| 9227 | if (num_linker_inputs > 0 && !seen_error () && print_subprocess_help < 2) |
| 9228 | { |
| 9229 | int tmp = execution_count; |
| 9230 | |
| 9231 | detect_jobserver (); |
| 9232 | |
| 9233 | if (! have_c) |
| 9234 | { |
| 9235 | #if HAVE_LTO_PLUGIN > 0 |
| 9236 | #if HAVE_LTO_PLUGIN == 2 |
| 9237 | const char *fno_use_linker_plugin = "fno-use-linker-plugin" ; |
| 9238 | #else |
| 9239 | const char *fuse_linker_plugin = "fuse-linker-plugin" ; |
| 9240 | #endif |
| 9241 | #endif |
| 9242 | |
| 9243 | /* We'll use ld if we can't find collect2. */ |
| 9244 | if (! strcmp (s1: linker_name_spec, s2: "collect2" )) |
| 9245 | { |
| 9246 | char *s = find_a_program (name: "collect2" ); |
| 9247 | if (s == NULL) |
| 9248 | set_static_spec_shared (spec: &linker_name_spec, val: "ld" ); |
| 9249 | } |
| 9250 | |
| 9251 | #if HAVE_LTO_PLUGIN > 0 |
| 9252 | #if HAVE_LTO_PLUGIN == 2 |
| 9253 | if (!switch_matches (atom: fno_use_linker_plugin, |
| 9254 | end_atom: fno_use_linker_plugin |
| 9255 | + strlen (s: fno_use_linker_plugin), starred: 0)) |
| 9256 | #else |
| 9257 | if (switch_matches (fuse_linker_plugin, |
| 9258 | fuse_linker_plugin |
| 9259 | + strlen (fuse_linker_plugin), 0)) |
| 9260 | #endif |
| 9261 | { |
| 9262 | char *temp_spec = find_a_file (pprefix: &exec_prefixes, |
| 9263 | LTOPLUGINSONAME, R_OK, |
| 9264 | do_multi: false); |
| 9265 | if (!temp_spec) |
| 9266 | fatal_error (input_location, |
| 9267 | "%<-fuse-linker-plugin%>, but %s not found" , |
| 9268 | LTOPLUGINSONAME); |
| 9269 | linker_plugin_file_spec = convert_white_space (temp_spec); |
| 9270 | } |
| 9271 | #endif |
| 9272 | set_static_spec_shared (spec: <o_gcc_spec, val: argv0); |
| 9273 | } |
| 9274 | |
| 9275 | /* Rebuild the COMPILER_PATH and LIBRARY_PATH environment variables |
| 9276 | for collect. */ |
| 9277 | putenv_from_prefixes (paths: &exec_prefixes, env_var: "COMPILER_PATH" , do_multi: false); |
| 9278 | putenv_from_prefixes (paths: &startfile_prefixes, LIBRARY_PATH_ENV, do_multi: true); |
| 9279 | |
| 9280 | if (print_subprocess_help == 1) |
| 9281 | { |
| 9282 | printf (_("\nLinker options\n==============\n\n" )); |
| 9283 | printf (_("Use \"-Wl,OPTION\" to pass \"OPTION\"" |
| 9284 | " to the linker.\n\n" )); |
| 9285 | fflush (stdout); |
| 9286 | } |
| 9287 | int value = do_spec (spec: link_command_spec); |
| 9288 | if (value < 0) |
| 9289 | errorcount = 1; |
| 9290 | linker_was_run = (tmp != execution_count); |
| 9291 | } |
| 9292 | |
| 9293 | /* If options said don't run linker, |
| 9294 | complain about input files to be given to the linker. */ |
| 9295 | |
| 9296 | if (! linker_was_run && !seen_error ()) |
| 9297 | for (i = 0; (int) i < n_infiles; i++) |
| 9298 | if (explicit_link_files[i] |
| 9299 | && !(infiles[i].language && infiles[i].language[0] == '*')) |
| 9300 | { |
| 9301 | warning (0, "%s: linker input file unused because linking not done" , |
| 9302 | outfiles[i]); |
| 9303 | if (access (name: outfiles[i], F_OK) < 0) |
| 9304 | /* This is can be an indication the user specifed an errorneous |
| 9305 | separated option value, (or used the wrong prefix for an |
| 9306 | option). */ |
| 9307 | error ("%s: linker input file not found: %m" , outfiles[i]); |
| 9308 | } |
| 9309 | } |
| 9310 | |
| 9311 | /* The end of "main". */ |
| 9312 | |
| 9313 | void |
| 9314 | driver::final_actions () const |
| 9315 | { |
| 9316 | /* Delete some or all of the temporary files we made. */ |
| 9317 | |
| 9318 | if (seen_error ()) |
| 9319 | delete_failure_queue (); |
| 9320 | delete_temp_files (); |
| 9321 | |
| 9322 | if (totruncate_file != NULL && !seen_error ()) |
| 9323 | /* Truncate file specified by -truncate. |
| 9324 | Used by lto-wrapper to reduce temporary disk-space usage. */ |
| 9325 | truncate(file: totruncate_file, length: 0); |
| 9326 | |
| 9327 | if (print_help_list) |
| 9328 | { |
| 9329 | printf (format: ("\nFor bug reporting instructions, please see:\n" )); |
| 9330 | printf (format: "%s\n" , bug_report_url); |
| 9331 | } |
| 9332 | } |
| 9333 | |
| 9334 | /* Detect whether jobserver is active and working. If not drop |
| 9335 | --jobserver-auth from MAKEFLAGS. */ |
| 9336 | |
| 9337 | void |
| 9338 | driver::detect_jobserver () const |
| 9339 | { |
| 9340 | jobserver_info jinfo; |
| 9341 | if (!jinfo.is_active && !jinfo.skipped_makeflags.empty ()) |
| 9342 | xputenv (string: xstrdup (jinfo.skipped_makeflags.c_str ())); |
| 9343 | } |
| 9344 | |
| 9345 | /* Determine what the exit code of the driver should be. */ |
| 9346 | |
| 9347 | int |
| 9348 | driver::get_exit_code () const |
| 9349 | { |
| 9350 | return (signal_count != 0 ? 2 |
| 9351 | : seen_error () ? (pass_exit_codes ? greatest_status : 1) |
| 9352 | : 0); |
| 9353 | } |
| 9354 | |
| 9355 | /* Find the proper compilation spec for the file name NAME, |
| 9356 | whose length is LENGTH. LANGUAGE is the specified language, |
| 9357 | or 0 if this file is to be passed to the linker. */ |
| 9358 | |
| 9359 | static struct compiler * |
| 9360 | lookup_compiler (const char *name, size_t length, const char *language) |
| 9361 | { |
| 9362 | struct compiler *cp; |
| 9363 | |
| 9364 | /* If this was specified by the user to be a linker input, indicate that. */ |
| 9365 | if (language != 0 && language[0] == '*') |
| 9366 | return 0; |
| 9367 | |
| 9368 | /* Otherwise, look for the language, if one is spec'd. */ |
| 9369 | if (language != 0) |
| 9370 | { |
| 9371 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
| 9372 | if (cp->suffix[0] == '@' && !strcmp (s1: cp->suffix + 1, s2: language)) |
| 9373 | { |
| 9374 | if (name != NULL && strcmp (s1: name, s2: "-" ) == 0 |
| 9375 | && (strcmp (s1: cp->suffix, s2: "@c-header" ) == 0 |
| 9376 | || strcmp (s1: cp->suffix, s2: "@c++-header" ) == 0) |
| 9377 | && !have_E) |
| 9378 | fatal_error (input_location, |
| 9379 | "cannot use %<-%> as input filename for a " |
| 9380 | "precompiled header" ); |
| 9381 | |
| 9382 | return cp; |
| 9383 | } |
| 9384 | |
| 9385 | error ("language %s not recognized" , language); |
| 9386 | return 0; |
| 9387 | } |
| 9388 | |
| 9389 | /* Look for a suffix. */ |
| 9390 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
| 9391 | { |
| 9392 | if (/* The suffix `-' matches only the file name `-'. */ |
| 9393 | (!strcmp (s1: cp->suffix, s2: "-" ) && !strcmp (s1: name, s2: "-" )) |
| 9394 | || (strlen (s: cp->suffix) < length |
| 9395 | /* See if the suffix matches the end of NAME. */ |
| 9396 | && !strcmp (s1: cp->suffix, |
| 9397 | s2: name + length - strlen (s: cp->suffix)) |
| 9398 | )) |
| 9399 | break; |
| 9400 | } |
| 9401 | |
| 9402 | #if defined (OS2) ||defined (HAVE_DOS_BASED_FILE_SYSTEM) |
| 9403 | /* Look again, but case-insensitively this time. */ |
| 9404 | if (cp < compilers) |
| 9405 | for (cp = compilers + n_compilers - 1; cp >= compilers; cp--) |
| 9406 | { |
| 9407 | if (/* The suffix `-' matches only the file name `-'. */ |
| 9408 | (!strcmp (cp->suffix, "-" ) && !strcmp (name, "-" )) |
| 9409 | || (strlen (cp->suffix) < length |
| 9410 | /* See if the suffix matches the end of NAME. */ |
| 9411 | && ((!strcmp (cp->suffix, |
| 9412 | name + length - strlen (cp->suffix)) |
| 9413 | || !strpbrk (cp->suffix, "ABCDEFGHIJKLMNOPQRSTUVWXYZ" )) |
| 9414 | && !strcasecmp (cp->suffix, |
| 9415 | name + length - strlen (cp->suffix))) |
| 9416 | )) |
| 9417 | break; |
| 9418 | } |
| 9419 | #endif |
| 9420 | |
| 9421 | if (cp >= compilers) |
| 9422 | { |
| 9423 | if (cp->spec[0] != '@') |
| 9424 | /* A non-alias entry: return it. */ |
| 9425 | return cp; |
| 9426 | |
| 9427 | /* An alias entry maps a suffix to a language. |
| 9428 | Search for the language; pass 0 for NAME and LENGTH |
| 9429 | to avoid infinite recursion if language not found. */ |
| 9430 | return lookup_compiler (NULL, length: 0, language: cp->spec + 1); |
| 9431 | } |
| 9432 | return 0; |
| 9433 | } |
| 9434 | |
| 9435 | static char * |
| 9436 | save_string (const char *s, int len) |
| 9437 | { |
| 9438 | char *result = XNEWVEC (char, len + 1); |
| 9439 | |
| 9440 | gcc_checking_assert (strlen (s) >= (unsigned int) len); |
| 9441 | memcpy (dest: result, src: s, n: len); |
| 9442 | result[len] = 0; |
| 9443 | return result; |
| 9444 | } |
| 9445 | |
| 9446 | |
| 9447 | static inline void |
| 9448 | validate_switches_from_spec (const char *spec, bool user) |
| 9449 | { |
| 9450 | const char *p = spec; |
| 9451 | char c; |
| 9452 | while ((c = *p++)) |
| 9453 | if (c == '%' |
| 9454 | && (*p == '{' |
| 9455 | || *p == '<' |
| 9456 | || (*p == 'W' && *++p == '{') |
| 9457 | || (*p == '@' && *++p == '{'))) |
| 9458 | /* We have a switch spec. */ |
| 9459 | p = validate_switches (p + 1, user, *p == '{'); |
| 9460 | } |
| 9461 | |
| 9462 | static void |
| 9463 | validate_all_switches (void) |
| 9464 | { |
| 9465 | struct compiler *comp; |
| 9466 | struct spec_list *spec; |
| 9467 | |
| 9468 | for (comp = compilers; comp->spec; comp++) |
| 9469 | validate_switches_from_spec (spec: comp->spec, user: false); |
| 9470 | |
| 9471 | /* Look through the linked list of specs read from the specs file. */ |
| 9472 | for (spec = specs; spec; spec = spec->next) |
| 9473 | validate_switches_from_spec (spec: *spec->ptr_spec, user: spec->user_p); |
| 9474 | |
| 9475 | validate_switches_from_spec (spec: link_command_spec, user: false); |
| 9476 | } |
| 9477 | |
| 9478 | /* Look at the switch-name that comes after START and mark as valid |
| 9479 | all supplied switches that match it. If BRACED, handle other |
| 9480 | switches after '|' and '&', and specs after ':' until ';' or '}', |
| 9481 | going back for more switches after ';'. Without BRACED, handle |
| 9482 | only one atom. Return a pointer to whatever follows the handled |
| 9483 | items, after the closing brace if BRACED. */ |
| 9484 | |
| 9485 | static const char * |
| 9486 | validate_switches (const char *start, bool user_spec, bool braced) |
| 9487 | { |
| 9488 | const char *p = start; |
| 9489 | const char *atom; |
| 9490 | size_t len; |
| 9491 | int i; |
| 9492 | bool suffix; |
| 9493 | bool starred; |
| 9494 | |
| 9495 | #define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0) |
| 9496 | |
| 9497 | next_member: |
| 9498 | suffix = false; |
| 9499 | starred = false; |
| 9500 | |
| 9501 | SKIP_WHITE (); |
| 9502 | |
| 9503 | if (*p == '!') |
| 9504 | p++; |
| 9505 | |
| 9506 | SKIP_WHITE (); |
| 9507 | if (*p == '.' || *p == ',') |
| 9508 | suffix = true, p++; |
| 9509 | |
| 9510 | atom = p; |
| 9511 | while (ISIDNUM (*p) || *p == '-' || *p == '+' || *p == '=' |
| 9512 | || *p == ',' || *p == '.' || *p == '@') |
| 9513 | p++; |
| 9514 | len = p - atom; |
| 9515 | |
| 9516 | if (*p == '*') |
| 9517 | starred = true, p++; |
| 9518 | |
| 9519 | SKIP_WHITE (); |
| 9520 | |
| 9521 | if (!suffix) |
| 9522 | { |
| 9523 | /* Mark all matching switches as valid. */ |
| 9524 | for (i = 0; i < n_switches; i++) |
| 9525 | if (!strncmp (s1: switches[i].part1, s2: atom, n: len) |
| 9526 | && (starred || switches[i].part1[len] == '\0') |
| 9527 | && (switches[i].known || user_spec)) |
| 9528 | switches[i].validated = true; |
| 9529 | } |
| 9530 | |
| 9531 | if (!braced) |
| 9532 | return p; |
| 9533 | |
| 9534 | if (*p) p++; |
| 9535 | if (*p && (p[-1] == '|' || p[-1] == '&')) |
| 9536 | goto next_member; |
| 9537 | |
| 9538 | if (*p && p[-1] == ':') |
| 9539 | { |
| 9540 | while (*p && *p != ';' && *p != '}') |
| 9541 | { |
| 9542 | if (*p == '%') |
| 9543 | { |
| 9544 | p++; |
| 9545 | if (*p == '{' || *p == '<') |
| 9546 | p = validate_switches (start: p+1, user_spec, braced: *p == '{'); |
| 9547 | else if (p[0] == 'W' && p[1] == '{') |
| 9548 | p = validate_switches (start: p+2, user_spec, braced: true); |
| 9549 | else if (p[0] == '@' && p[1] == '{') |
| 9550 | p = validate_switches (start: p+2, user_spec, braced: true); |
| 9551 | } |
| 9552 | else |
| 9553 | p++; |
| 9554 | } |
| 9555 | |
| 9556 | if (*p) p++; |
| 9557 | if (*p && p[-1] == ';') |
| 9558 | goto next_member; |
| 9559 | } |
| 9560 | |
| 9561 | return p; |
| 9562 | #undef SKIP_WHITE |
| 9563 | } |
| 9564 | |
| 9565 | struct mdswitchstr |
| 9566 | { |
| 9567 | const char *str; |
| 9568 | int len; |
| 9569 | }; |
| 9570 | |
| 9571 | static struct mdswitchstr *mdswitches; |
| 9572 | static int n_mdswitches; |
| 9573 | |
| 9574 | /* Check whether a particular argument was used. The first time we |
| 9575 | canonicalize the switches to keep only the ones we care about. */ |
| 9576 | |
| 9577 | struct used_arg_t |
| 9578 | { |
| 9579 | public: |
| 9580 | int operator () (const char *p, int len); |
| 9581 | void finalize (); |
| 9582 | |
| 9583 | private: |
| 9584 | struct mswitchstr |
| 9585 | { |
| 9586 | const char *str; |
| 9587 | const char *replace; |
| 9588 | int len; |
| 9589 | int rep_len; |
| 9590 | }; |
| 9591 | |
| 9592 | mswitchstr *mswitches; |
| 9593 | int n_mswitches; |
| 9594 | |
| 9595 | }; |
| 9596 | |
| 9597 | used_arg_t used_arg; |
| 9598 | |
| 9599 | int |
| 9600 | used_arg_t::operator () (const char *p, int len) |
| 9601 | { |
| 9602 | int i, j; |
| 9603 | |
| 9604 | if (!mswitches) |
| 9605 | { |
| 9606 | struct mswitchstr *matches; |
| 9607 | const char *q; |
| 9608 | int cnt = 0; |
| 9609 | |
| 9610 | /* Break multilib_matches into the component strings of string |
| 9611 | and replacement string. */ |
| 9612 | for (q = multilib_matches; *q != '\0'; q++) |
| 9613 | if (*q == ';') |
| 9614 | cnt++; |
| 9615 | |
| 9616 | matches |
| 9617 | = (struct mswitchstr *) alloca ((sizeof (struct mswitchstr)) * cnt); |
| 9618 | i = 0; |
| 9619 | q = multilib_matches; |
| 9620 | while (*q != '\0') |
| 9621 | { |
| 9622 | matches[i].str = q; |
| 9623 | while (*q != ' ') |
| 9624 | { |
| 9625 | if (*q == '\0') |
| 9626 | { |
| 9627 | invalid_matches: |
| 9628 | fatal_error (input_location, "multilib spec %qs is invalid" , |
| 9629 | multilib_matches); |
| 9630 | } |
| 9631 | q++; |
| 9632 | } |
| 9633 | matches[i].len = q - matches[i].str; |
| 9634 | |
| 9635 | matches[i].replace = ++q; |
| 9636 | while (*q != ';' && *q != '\0') |
| 9637 | { |
| 9638 | if (*q == ' ') |
| 9639 | goto invalid_matches; |
| 9640 | q++; |
| 9641 | } |
| 9642 | matches[i].rep_len = q - matches[i].replace; |
| 9643 | i++; |
| 9644 | if (*q == ';') |
| 9645 | q++; |
| 9646 | } |
| 9647 | |
| 9648 | /* Now build a list of the replacement string for switches that we care |
| 9649 | about. Make sure we allocate at least one entry. This prevents |
| 9650 | xmalloc from calling fatal, and prevents us from re-executing this |
| 9651 | block of code. */ |
| 9652 | mswitches |
| 9653 | = XNEWVEC (struct mswitchstr, n_mdswitches + (n_switches ? n_switches : 1)); |
| 9654 | for (i = 0; i < n_switches; i++) |
| 9655 | if ((switches[i].live_cond & SWITCH_IGNORE) == 0) |
| 9656 | { |
| 9657 | int xlen = strlen (s: switches[i].part1); |
| 9658 | for (j = 0; j < cnt; j++) |
| 9659 | if (xlen == matches[j].len |
| 9660 | && ! strncmp (s1: switches[i].part1, s2: matches[j].str, n: xlen)) |
| 9661 | { |
| 9662 | mswitches[n_mswitches].str = matches[j].replace; |
| 9663 | mswitches[n_mswitches].len = matches[j].rep_len; |
| 9664 | mswitches[n_mswitches].replace = (char *) 0; |
| 9665 | mswitches[n_mswitches].rep_len = 0; |
| 9666 | n_mswitches++; |
| 9667 | break; |
| 9668 | } |
| 9669 | } |
| 9670 | |
| 9671 | /* Add MULTILIB_DEFAULTS switches too, as long as they were not present |
| 9672 | on the command line nor any options mutually incompatible with |
| 9673 | them. */ |
| 9674 | for (i = 0; i < n_mdswitches; i++) |
| 9675 | { |
| 9676 | const char *r; |
| 9677 | |
| 9678 | for (q = multilib_options; *q != '\0'; *q && q++) |
| 9679 | { |
| 9680 | while (*q == ' ') |
| 9681 | q++; |
| 9682 | |
| 9683 | r = q; |
| 9684 | while (strncmp (s1: q, s2: mdswitches[i].str, n: mdswitches[i].len) != 0 |
| 9685 | || strchr (s: " /" , c: q[mdswitches[i].len]) == NULL) |
| 9686 | { |
| 9687 | while (*q != ' ' && *q != '/' && *q != '\0') |
| 9688 | q++; |
| 9689 | if (*q != '/') |
| 9690 | break; |
| 9691 | q++; |
| 9692 | } |
| 9693 | |
| 9694 | if (*q != ' ' && *q != '\0') |
| 9695 | { |
| 9696 | while (*r != ' ' && *r != '\0') |
| 9697 | { |
| 9698 | q = r; |
| 9699 | while (*q != ' ' && *q != '/' && *q != '\0') |
| 9700 | q++; |
| 9701 | |
| 9702 | if (used_arg (r, q - r)) |
| 9703 | break; |
| 9704 | |
| 9705 | if (*q != '/') |
| 9706 | { |
| 9707 | mswitches[n_mswitches].str = mdswitches[i].str; |
| 9708 | mswitches[n_mswitches].len = mdswitches[i].len; |
| 9709 | mswitches[n_mswitches].replace = (char *) 0; |
| 9710 | mswitches[n_mswitches].rep_len = 0; |
| 9711 | n_mswitches++; |
| 9712 | break; |
| 9713 | } |
| 9714 | |
| 9715 | r = q + 1; |
| 9716 | } |
| 9717 | break; |
| 9718 | } |
| 9719 | } |
| 9720 | } |
| 9721 | } |
| 9722 | |
| 9723 | for (i = 0; i < n_mswitches; i++) |
| 9724 | if (len == mswitches[i].len && ! strncmp (s1: p, s2: mswitches[i].str, n: len)) |
| 9725 | return 1; |
| 9726 | |
| 9727 | return 0; |
| 9728 | } |
| 9729 | |
| 9730 | void used_arg_t::finalize () |
| 9731 | { |
| 9732 | XDELETEVEC (mswitches); |
| 9733 | mswitches = NULL; |
| 9734 | n_mswitches = 0; |
| 9735 | } |
| 9736 | |
| 9737 | |
| 9738 | static int |
| 9739 | default_arg (const char *p, int len) |
| 9740 | { |
| 9741 | int i; |
| 9742 | |
| 9743 | for (i = 0; i < n_mdswitches; i++) |
| 9744 | if (len == mdswitches[i].len && ! strncmp (s1: p, s2: mdswitches[i].str, n: len)) |
| 9745 | return 1; |
| 9746 | |
| 9747 | return 0; |
| 9748 | } |
| 9749 | |
| 9750 | /* Use multilib_dir as key to find corresponding multilib_os_dir and |
| 9751 | multiarch_dir. */ |
| 9752 | |
| 9753 | static void |
| 9754 | find_multilib_os_dir_by_multilib_dir (const char *multilib_dir, |
| 9755 | const char **p_multilib_os_dir, |
| 9756 | const char **p_multiarch_dir) |
| 9757 | { |
| 9758 | const char *p = multilib_select; |
| 9759 | unsigned int this_path_len; |
| 9760 | const char *this_path; |
| 9761 | int ok = 0; |
| 9762 | |
| 9763 | while (*p != '\0') |
| 9764 | { |
| 9765 | /* Ignore newlines. */ |
| 9766 | if (*p == '\n') |
| 9767 | { |
| 9768 | ++p; |
| 9769 | continue; |
| 9770 | } |
| 9771 | |
| 9772 | /* Get the initial path. */ |
| 9773 | this_path = p; |
| 9774 | while (*p != ' ') |
| 9775 | { |
| 9776 | if (*p == '\0') |
| 9777 | { |
| 9778 | fatal_error (input_location, "multilib select %qs %qs is invalid" , |
| 9779 | multilib_select, multilib_reuse); |
| 9780 | } |
| 9781 | ++p; |
| 9782 | } |
| 9783 | this_path_len = p - this_path; |
| 9784 | |
| 9785 | ok = 0; |
| 9786 | |
| 9787 | /* Skip any arguments, we don't care at this stage. */ |
| 9788 | while (*++p != ';'); |
| 9789 | |
| 9790 | if (this_path_len != 1 |
| 9791 | || this_path[0] != '.') |
| 9792 | { |
| 9793 | char *new_multilib_dir = XNEWVEC (char, this_path_len + 1); |
| 9794 | char *q; |
| 9795 | |
| 9796 | strncpy (dest: new_multilib_dir, src: this_path, n: this_path_len); |
| 9797 | new_multilib_dir[this_path_len] = '\0'; |
| 9798 | q = strchr (s: new_multilib_dir, c: ':'); |
| 9799 | if (q != NULL) |
| 9800 | *q = '\0'; |
| 9801 | |
| 9802 | if (strcmp (s1: new_multilib_dir, s2: multilib_dir) == 0) |
| 9803 | ok = 1; |
| 9804 | } |
| 9805 | |
| 9806 | /* Found matched multilib_dir, update multilib_os_dir and |
| 9807 | multiarch_dir. */ |
| 9808 | if (ok) |
| 9809 | { |
| 9810 | const char *q = this_path, *end = this_path + this_path_len; |
| 9811 | |
| 9812 | while (q < end && *q != ':') |
| 9813 | q++; |
| 9814 | if (q < end) |
| 9815 | { |
| 9816 | const char *q2 = q + 1, *ml_end = end; |
| 9817 | char *new_multilib_os_dir; |
| 9818 | |
| 9819 | while (q2 < end && *q2 != ':') |
| 9820 | q2++; |
| 9821 | if (*q2 == ':') |
| 9822 | ml_end = q2; |
| 9823 | if (ml_end - q == 1) |
| 9824 | *p_multilib_os_dir = xstrdup ("." ); |
| 9825 | else |
| 9826 | { |
| 9827 | new_multilib_os_dir = XNEWVEC (char, ml_end - q); |
| 9828 | memcpy (dest: new_multilib_os_dir, src: q + 1, n: ml_end - q - 1); |
| 9829 | new_multilib_os_dir[ml_end - q - 1] = '\0'; |
| 9830 | *p_multilib_os_dir = new_multilib_os_dir; |
| 9831 | } |
| 9832 | |
| 9833 | if (q2 < end && *q2 == ':') |
| 9834 | { |
| 9835 | char *new_multiarch_dir = XNEWVEC (char, end - q2); |
| 9836 | memcpy (dest: new_multiarch_dir, src: q2 + 1, n: end - q2 - 1); |
| 9837 | new_multiarch_dir[end - q2 - 1] = '\0'; |
| 9838 | *p_multiarch_dir = new_multiarch_dir; |
| 9839 | } |
| 9840 | break; |
| 9841 | } |
| 9842 | } |
| 9843 | ++p; |
| 9844 | } |
| 9845 | } |
| 9846 | |
| 9847 | /* Work out the subdirectory to use based on the options. The format of |
| 9848 | multilib_select is a list of elements. Each element is a subdirectory |
| 9849 | name followed by a list of options followed by a semicolon. The format |
| 9850 | of multilib_exclusions is the same, but without the preceding |
| 9851 | directory. First gcc will check the exclusions, if none of the options |
| 9852 | beginning with an exclamation point are present, and all of the other |
| 9853 | options are present, then we will ignore this completely. Passing |
| 9854 | that, gcc will consider each multilib_select in turn using the same |
| 9855 | rules for matching the options. If a match is found, that subdirectory |
| 9856 | will be used. |
| 9857 | A subdirectory name is optionally followed by a colon and the corresponding |
| 9858 | multiarch name. */ |
| 9859 | |
| 9860 | static void |
| 9861 | set_multilib_dir (void) |
| 9862 | { |
| 9863 | const char *p; |
| 9864 | unsigned int this_path_len; |
| 9865 | const char *this_path, *this_arg; |
| 9866 | const char *start, *end; |
| 9867 | int not_arg; |
| 9868 | int ok, ndfltok, first; |
| 9869 | |
| 9870 | n_mdswitches = 0; |
| 9871 | start = multilib_defaults; |
| 9872 | while (*start == ' ' || *start == '\t') |
| 9873 | start++; |
| 9874 | while (*start != '\0') |
| 9875 | { |
| 9876 | n_mdswitches++; |
| 9877 | while (*start != ' ' && *start != '\t' && *start != '\0') |
| 9878 | start++; |
| 9879 | while (*start == ' ' || *start == '\t') |
| 9880 | start++; |
| 9881 | } |
| 9882 | |
| 9883 | if (n_mdswitches) |
| 9884 | { |
| 9885 | int i = 0; |
| 9886 | |
| 9887 | mdswitches = XNEWVEC (struct mdswitchstr, n_mdswitches); |
| 9888 | for (start = multilib_defaults; *start != '\0'; start = end + 1) |
| 9889 | { |
| 9890 | while (*start == ' ' || *start == '\t') |
| 9891 | start++; |
| 9892 | |
| 9893 | if (*start == '\0') |
| 9894 | break; |
| 9895 | |
| 9896 | for (end = start + 1; |
| 9897 | *end != ' ' && *end != '\t' && *end != '\0'; end++) |
| 9898 | ; |
| 9899 | |
| 9900 | obstack_grow (&multilib_obstack, start, end - start); |
| 9901 | obstack_1grow (&multilib_obstack, 0); |
| 9902 | mdswitches[i].str = XOBFINISH (&multilib_obstack, const char *); |
| 9903 | mdswitches[i++].len = end - start; |
| 9904 | |
| 9905 | if (*end == '\0') |
| 9906 | break; |
| 9907 | } |
| 9908 | } |
| 9909 | |
| 9910 | p = multilib_exclusions; |
| 9911 | while (*p != '\0') |
| 9912 | { |
| 9913 | /* Ignore newlines. */ |
| 9914 | if (*p == '\n') |
| 9915 | { |
| 9916 | ++p; |
| 9917 | continue; |
| 9918 | } |
| 9919 | |
| 9920 | /* Check the arguments. */ |
| 9921 | ok = 1; |
| 9922 | while (*p != ';') |
| 9923 | { |
| 9924 | if (*p == '\0') |
| 9925 | { |
| 9926 | invalid_exclusions: |
| 9927 | fatal_error (input_location, "multilib exclusions %qs is invalid" , |
| 9928 | multilib_exclusions); |
| 9929 | } |
| 9930 | |
| 9931 | if (! ok) |
| 9932 | { |
| 9933 | ++p; |
| 9934 | continue; |
| 9935 | } |
| 9936 | |
| 9937 | this_arg = p; |
| 9938 | while (*p != ' ' && *p != ';') |
| 9939 | { |
| 9940 | if (*p == '\0') |
| 9941 | goto invalid_exclusions; |
| 9942 | ++p; |
| 9943 | } |
| 9944 | |
| 9945 | if (*this_arg != '!') |
| 9946 | not_arg = 0; |
| 9947 | else |
| 9948 | { |
| 9949 | not_arg = 1; |
| 9950 | ++this_arg; |
| 9951 | } |
| 9952 | |
| 9953 | ok = used_arg (this_arg, p - this_arg); |
| 9954 | if (not_arg) |
| 9955 | ok = ! ok; |
| 9956 | |
| 9957 | if (*p == ' ') |
| 9958 | ++p; |
| 9959 | } |
| 9960 | |
| 9961 | if (ok) |
| 9962 | return; |
| 9963 | |
| 9964 | ++p; |
| 9965 | } |
| 9966 | |
| 9967 | first = 1; |
| 9968 | p = multilib_select; |
| 9969 | |
| 9970 | /* Append multilib reuse rules if any. With those rules, we can reuse |
| 9971 | one multilib for certain different options sets. */ |
| 9972 | if (strlen (s: multilib_reuse) > 0) |
| 9973 | p = concat (p, multilib_reuse, NULL); |
| 9974 | |
| 9975 | while (*p != '\0') |
| 9976 | { |
| 9977 | /* Ignore newlines. */ |
| 9978 | if (*p == '\n') |
| 9979 | { |
| 9980 | ++p; |
| 9981 | continue; |
| 9982 | } |
| 9983 | |
| 9984 | /* Get the initial path. */ |
| 9985 | this_path = p; |
| 9986 | while (*p != ' ') |
| 9987 | { |
| 9988 | if (*p == '\0') |
| 9989 | { |
| 9990 | invalid_select: |
| 9991 | fatal_error (input_location, "multilib select %qs %qs is invalid" , |
| 9992 | multilib_select, multilib_reuse); |
| 9993 | } |
| 9994 | ++p; |
| 9995 | } |
| 9996 | this_path_len = p - this_path; |
| 9997 | |
| 9998 | /* Check the arguments. */ |
| 9999 | ok = 1; |
| 10000 | ndfltok = 1; |
| 10001 | ++p; |
| 10002 | while (*p != ';') |
| 10003 | { |
| 10004 | if (*p == '\0') |
| 10005 | goto invalid_select; |
| 10006 | |
| 10007 | if (! ok) |
| 10008 | { |
| 10009 | ++p; |
| 10010 | continue; |
| 10011 | } |
| 10012 | |
| 10013 | this_arg = p; |
| 10014 | while (*p != ' ' && *p != ';') |
| 10015 | { |
| 10016 | if (*p == '\0') |
| 10017 | goto invalid_select; |
| 10018 | ++p; |
| 10019 | } |
| 10020 | |
| 10021 | if (*this_arg != '!') |
| 10022 | not_arg = 0; |
| 10023 | else |
| 10024 | { |
| 10025 | not_arg = 1; |
| 10026 | ++this_arg; |
| 10027 | } |
| 10028 | |
| 10029 | /* If this is a default argument, we can just ignore it. |
| 10030 | This is true even if this_arg begins with '!'. Beginning |
| 10031 | with '!' does not mean that this argument is necessarily |
| 10032 | inappropriate for this library: it merely means that |
| 10033 | there is a more specific library which uses this |
| 10034 | argument. If this argument is a default, we need not |
| 10035 | consider that more specific library. */ |
| 10036 | ok = used_arg (this_arg, p - this_arg); |
| 10037 | if (not_arg) |
| 10038 | ok = ! ok; |
| 10039 | |
| 10040 | if (! ok) |
| 10041 | ndfltok = 0; |
| 10042 | |
| 10043 | if (default_arg (p: this_arg, len: p - this_arg)) |
| 10044 | ok = 1; |
| 10045 | |
| 10046 | if (*p == ' ') |
| 10047 | ++p; |
| 10048 | } |
| 10049 | |
| 10050 | if (ok && first) |
| 10051 | { |
| 10052 | if (this_path_len != 1 |
| 10053 | || this_path[0] != '.') |
| 10054 | { |
| 10055 | char *new_multilib_dir = XNEWVEC (char, this_path_len + 1); |
| 10056 | char *q; |
| 10057 | |
| 10058 | strncpy (dest: new_multilib_dir, src: this_path, n: this_path_len); |
| 10059 | new_multilib_dir[this_path_len] = '\0'; |
| 10060 | q = strchr (s: new_multilib_dir, c: ':'); |
| 10061 | if (q != NULL) |
| 10062 | *q = '\0'; |
| 10063 | multilib_dir = new_multilib_dir; |
| 10064 | } |
| 10065 | first = 0; |
| 10066 | } |
| 10067 | |
| 10068 | if (ndfltok) |
| 10069 | { |
| 10070 | const char *q = this_path, *end = this_path + this_path_len; |
| 10071 | |
| 10072 | while (q < end && *q != ':') |
| 10073 | q++; |
| 10074 | if (q < end) |
| 10075 | { |
| 10076 | const char *q2 = q + 1, *ml_end = end; |
| 10077 | char *new_multilib_os_dir; |
| 10078 | |
| 10079 | while (q2 < end && *q2 != ':') |
| 10080 | q2++; |
| 10081 | if (*q2 == ':') |
| 10082 | ml_end = q2; |
| 10083 | if (ml_end - q == 1) |
| 10084 | multilib_os_dir = xstrdup ("." ); |
| 10085 | else |
| 10086 | { |
| 10087 | new_multilib_os_dir = XNEWVEC (char, ml_end - q); |
| 10088 | memcpy (dest: new_multilib_os_dir, src: q + 1, n: ml_end - q - 1); |
| 10089 | new_multilib_os_dir[ml_end - q - 1] = '\0'; |
| 10090 | multilib_os_dir = new_multilib_os_dir; |
| 10091 | } |
| 10092 | |
| 10093 | if (q2 < end && *q2 == ':') |
| 10094 | { |
| 10095 | char *new_multiarch_dir = XNEWVEC (char, end - q2); |
| 10096 | memcpy (dest: new_multiarch_dir, src: q2 + 1, n: end - q2 - 1); |
| 10097 | new_multiarch_dir[end - q2 - 1] = '\0'; |
| 10098 | multiarch_dir = new_multiarch_dir; |
| 10099 | } |
| 10100 | break; |
| 10101 | } |
| 10102 | } |
| 10103 | |
| 10104 | ++p; |
| 10105 | } |
| 10106 | |
| 10107 | multilib_dir = |
| 10108 | targetm_common.compute_multilib ( |
| 10109 | switches, |
| 10110 | n_switches, |
| 10111 | multilib_dir, |
| 10112 | multilib_defaults, |
| 10113 | multilib_select, |
| 10114 | multilib_matches, |
| 10115 | multilib_exclusions, |
| 10116 | multilib_reuse); |
| 10117 | |
| 10118 | if (multilib_dir == NULL && multilib_os_dir != NULL |
| 10119 | && strcmp (s1: multilib_os_dir, s2: "." ) == 0) |
| 10120 | { |
| 10121 | free (CONST_CAST (char *, multilib_os_dir)); |
| 10122 | multilib_os_dir = NULL; |
| 10123 | } |
| 10124 | else if (multilib_dir != NULL && multilib_os_dir == NULL) |
| 10125 | { |
| 10126 | /* Give second chance to search matched multilib_os_dir again by matching |
| 10127 | the multilib_dir since some target may use TARGET_COMPUTE_MULTILIB |
| 10128 | hook rather than the builtin way. */ |
| 10129 | find_multilib_os_dir_by_multilib_dir (multilib_dir, p_multilib_os_dir: &multilib_os_dir, |
| 10130 | p_multiarch_dir: &multiarch_dir); |
| 10131 | |
| 10132 | if (multilib_os_dir == NULL) |
| 10133 | multilib_os_dir = multilib_dir; |
| 10134 | } |
| 10135 | } |
| 10136 | |
| 10137 | /* Print out the multiple library subdirectory selection |
| 10138 | information. This prints out a series of lines. Each line looks |
| 10139 | like SUBDIRECTORY;@OPTION@OPTION, with as many options as is |
| 10140 | required. Only the desired options are printed out, the negative |
| 10141 | matches. The options are print without a leading dash. There are |
| 10142 | no spaces to make it easy to use the information in the shell. |
| 10143 | Each subdirectory is printed only once. This assumes the ordering |
| 10144 | generated by the genmultilib script. Also, we leave out ones that match |
| 10145 | the exclusions. */ |
| 10146 | |
| 10147 | static void |
| 10148 | print_multilib_info (void) |
| 10149 | { |
| 10150 | const char *p = multilib_select; |
| 10151 | const char *last_path = 0, *this_path; |
| 10152 | int skip; |
| 10153 | int not_arg; |
| 10154 | unsigned int last_path_len = 0; |
| 10155 | |
| 10156 | while (*p != '\0') |
| 10157 | { |
| 10158 | skip = 0; |
| 10159 | /* Ignore newlines. */ |
| 10160 | if (*p == '\n') |
| 10161 | { |
| 10162 | ++p; |
| 10163 | continue; |
| 10164 | } |
| 10165 | |
| 10166 | /* Get the initial path. */ |
| 10167 | this_path = p; |
| 10168 | while (*p != ' ') |
| 10169 | { |
| 10170 | if (*p == '\0') |
| 10171 | { |
| 10172 | invalid_select: |
| 10173 | fatal_error (input_location, |
| 10174 | "multilib select %qs is invalid" , multilib_select); |
| 10175 | } |
| 10176 | |
| 10177 | ++p; |
| 10178 | } |
| 10179 | |
| 10180 | /* When --disable-multilib was used but target defines |
| 10181 | MULTILIB_OSDIRNAMES, entries starting with .: (and not starting |
| 10182 | with .:: for multiarch configurations) are there just to find |
| 10183 | multilib_os_dir, so skip them from output. */ |
| 10184 | if (this_path[0] == '.' && this_path[1] == ':' && this_path[2] != ':') |
| 10185 | skip = 1; |
| 10186 | |
| 10187 | /* Check for matches with the multilib_exclusions. We don't bother |
| 10188 | with the '!' in either list. If any of the exclusion rules match |
| 10189 | all of its options with the select rule, we skip it. */ |
| 10190 | { |
| 10191 | const char *e = multilib_exclusions; |
| 10192 | const char *this_arg; |
| 10193 | |
| 10194 | while (*e != '\0') |
| 10195 | { |
| 10196 | int m = 1; |
| 10197 | /* Ignore newlines. */ |
| 10198 | if (*e == '\n') |
| 10199 | { |
| 10200 | ++e; |
| 10201 | continue; |
| 10202 | } |
| 10203 | |
| 10204 | /* Check the arguments. */ |
| 10205 | while (*e != ';') |
| 10206 | { |
| 10207 | const char *q; |
| 10208 | int mp = 0; |
| 10209 | |
| 10210 | if (*e == '\0') |
| 10211 | { |
| 10212 | invalid_exclusion: |
| 10213 | fatal_error (input_location, |
| 10214 | "multilib exclusion %qs is invalid" , |
| 10215 | multilib_exclusions); |
| 10216 | } |
| 10217 | |
| 10218 | if (! m) |
| 10219 | { |
| 10220 | ++e; |
| 10221 | continue; |
| 10222 | } |
| 10223 | |
| 10224 | this_arg = e; |
| 10225 | |
| 10226 | while (*e != ' ' && *e != ';') |
| 10227 | { |
| 10228 | if (*e == '\0') |
| 10229 | goto invalid_exclusion; |
| 10230 | ++e; |
| 10231 | } |
| 10232 | |
| 10233 | q = p + 1; |
| 10234 | while (*q != ';') |
| 10235 | { |
| 10236 | const char *arg; |
| 10237 | int len = e - this_arg; |
| 10238 | |
| 10239 | if (*q == '\0') |
| 10240 | goto invalid_select; |
| 10241 | |
| 10242 | arg = q; |
| 10243 | |
| 10244 | while (*q != ' ' && *q != ';') |
| 10245 | { |
| 10246 | if (*q == '\0') |
| 10247 | goto invalid_select; |
| 10248 | ++q; |
| 10249 | } |
| 10250 | |
| 10251 | if (! strncmp (s1: arg, s2: this_arg, |
| 10252 | n: (len < q - arg) ? q - arg : len) |
| 10253 | || default_arg (p: this_arg, len: e - this_arg)) |
| 10254 | { |
| 10255 | mp = 1; |
| 10256 | break; |
| 10257 | } |
| 10258 | |
| 10259 | if (*q == ' ') |
| 10260 | ++q; |
| 10261 | } |
| 10262 | |
| 10263 | if (! mp) |
| 10264 | m = 0; |
| 10265 | |
| 10266 | if (*e == ' ') |
| 10267 | ++e; |
| 10268 | } |
| 10269 | |
| 10270 | if (m) |
| 10271 | { |
| 10272 | skip = 1; |
| 10273 | break; |
| 10274 | } |
| 10275 | |
| 10276 | if (*e != '\0') |
| 10277 | ++e; |
| 10278 | } |
| 10279 | } |
| 10280 | |
| 10281 | if (! skip) |
| 10282 | { |
| 10283 | /* If this is a duplicate, skip it. */ |
| 10284 | skip = (last_path != 0 |
| 10285 | && (unsigned int) (p - this_path) == last_path_len |
| 10286 | && ! filename_ncmp (s1: last_path, s2: this_path, n: last_path_len)); |
| 10287 | |
| 10288 | last_path = this_path; |
| 10289 | last_path_len = p - this_path; |
| 10290 | } |
| 10291 | |
| 10292 | /* If all required arguments are default arguments, and no default |
| 10293 | arguments appear in the ! argument list, then we can skip it. |
| 10294 | We will already have printed a directory identical to this one |
| 10295 | which does not require that default argument. */ |
| 10296 | if (! skip) |
| 10297 | { |
| 10298 | const char *q; |
| 10299 | bool default_arg_ok = false; |
| 10300 | |
| 10301 | q = p + 1; |
| 10302 | while (*q != ';') |
| 10303 | { |
| 10304 | const char *arg; |
| 10305 | |
| 10306 | if (*q == '\0') |
| 10307 | goto invalid_select; |
| 10308 | |
| 10309 | if (*q == '!') |
| 10310 | { |
| 10311 | not_arg = 1; |
| 10312 | q++; |
| 10313 | } |
| 10314 | else |
| 10315 | not_arg = 0; |
| 10316 | arg = q; |
| 10317 | |
| 10318 | while (*q != ' ' && *q != ';') |
| 10319 | { |
| 10320 | if (*q == '\0') |
| 10321 | goto invalid_select; |
| 10322 | ++q; |
| 10323 | } |
| 10324 | |
| 10325 | if (default_arg (p: arg, len: q - arg)) |
| 10326 | { |
| 10327 | /* Stop checking if any default arguments appeared in not |
| 10328 | list. */ |
| 10329 | if (not_arg) |
| 10330 | { |
| 10331 | default_arg_ok = false; |
| 10332 | break; |
| 10333 | } |
| 10334 | |
| 10335 | default_arg_ok = true; |
| 10336 | } |
| 10337 | else if (!not_arg) |
| 10338 | { |
| 10339 | /* Stop checking if any required argument is not provided by |
| 10340 | default arguments. */ |
| 10341 | default_arg_ok = false; |
| 10342 | break; |
| 10343 | } |
| 10344 | |
| 10345 | if (*q == ' ') |
| 10346 | ++q; |
| 10347 | } |
| 10348 | |
| 10349 | /* Make sure all default argument is OK for this multi-lib set. */ |
| 10350 | if (default_arg_ok) |
| 10351 | skip = 1; |
| 10352 | else |
| 10353 | skip = 0; |
| 10354 | } |
| 10355 | |
| 10356 | if (! skip) |
| 10357 | { |
| 10358 | const char *p1; |
| 10359 | |
| 10360 | for (p1 = last_path; p1 < p && *p1 != ':'; p1++) |
| 10361 | putchar (c: *p1); |
| 10362 | putchar (c: ';'); |
| 10363 | } |
| 10364 | |
| 10365 | ++p; |
| 10366 | while (*p != ';') |
| 10367 | { |
| 10368 | int use_arg; |
| 10369 | |
| 10370 | if (*p == '\0') |
| 10371 | goto invalid_select; |
| 10372 | |
| 10373 | if (skip) |
| 10374 | { |
| 10375 | ++p; |
| 10376 | continue; |
| 10377 | } |
| 10378 | |
| 10379 | use_arg = *p != '!'; |
| 10380 | |
| 10381 | if (use_arg) |
| 10382 | putchar (c: '@'); |
| 10383 | |
| 10384 | while (*p != ' ' && *p != ';') |
| 10385 | { |
| 10386 | if (*p == '\0') |
| 10387 | goto invalid_select; |
| 10388 | if (use_arg) |
| 10389 | putchar (c: *p); |
| 10390 | ++p; |
| 10391 | } |
| 10392 | |
| 10393 | if (*p == ' ') |
| 10394 | ++p; |
| 10395 | } |
| 10396 | |
| 10397 | if (! skip) |
| 10398 | { |
| 10399 | /* If there are extra options, print them now. */ |
| 10400 | if (multilib_extra && *multilib_extra) |
| 10401 | { |
| 10402 | int print_at = true; |
| 10403 | const char *q; |
| 10404 | |
| 10405 | for (q = multilib_extra; *q != '\0'; q++) |
| 10406 | { |
| 10407 | if (*q == ' ') |
| 10408 | print_at = true; |
| 10409 | else |
| 10410 | { |
| 10411 | if (print_at) |
| 10412 | putchar (c: '@'); |
| 10413 | putchar (c: *q); |
| 10414 | print_at = false; |
| 10415 | } |
| 10416 | } |
| 10417 | } |
| 10418 | |
| 10419 | putchar (c: '\n'); |
| 10420 | } |
| 10421 | |
| 10422 | ++p; |
| 10423 | } |
| 10424 | } |
| 10425 | |
| 10426 | /* getenv built-in spec function. |
| 10427 | |
| 10428 | Returns the value of the environment variable given by its first argument, |
| 10429 | concatenated with the second argument. If the variable is not defined, a |
| 10430 | fatal error is issued unless such undefs are internally allowed, in which |
| 10431 | case the variable name prefixed by a '/' is used as the variable value. |
| 10432 | |
| 10433 | The leading '/' allows using the result at a spot where a full path would |
| 10434 | normally be expected and when the actual value doesn't really matter since |
| 10435 | undef vars are allowed. */ |
| 10436 | |
| 10437 | static const char * |
| 10438 | getenv_spec_function (int argc, const char **argv) |
| 10439 | { |
| 10440 | const char *value; |
| 10441 | const char *varname; |
| 10442 | |
| 10443 | char *result; |
| 10444 | char *ptr; |
| 10445 | size_t len; |
| 10446 | |
| 10447 | if (argc != 2) |
| 10448 | return NULL; |
| 10449 | |
| 10450 | varname = argv[0]; |
| 10451 | value = env.get (name: varname); |
| 10452 | |
| 10453 | /* If the variable isn't defined and this is allowed, craft our expected |
| 10454 | return value. Assume variable names used in specs strings don't contain |
| 10455 | any active spec character so don't need escaping. */ |
| 10456 | if (!value && spec_undefvar_allowed) |
| 10457 | { |
| 10458 | result = XNEWVAR (char, strlen(varname) + 2); |
| 10459 | sprintf (s: result, format: "/%s" , varname); |
| 10460 | return result; |
| 10461 | } |
| 10462 | |
| 10463 | if (!value) |
| 10464 | fatal_error (input_location, |
| 10465 | "environment variable %qs not defined" , varname); |
| 10466 | |
| 10467 | /* We have to escape every character of the environment variable so |
| 10468 | they are not interpreted as active spec characters. A |
| 10469 | particularly painful case is when we are reading a variable |
| 10470 | holding a windows path complete with \ separators. */ |
| 10471 | len = strlen (s: value) * 2 + strlen (s: argv[1]) + 1; |
| 10472 | result = XNEWVAR (char, len); |
| 10473 | for (ptr = result; *value; ptr += 2) |
| 10474 | { |
| 10475 | ptr[0] = '\\'; |
| 10476 | ptr[1] = *value++; |
| 10477 | } |
| 10478 | |
| 10479 | strcpy (dest: ptr, src: argv[1]); |
| 10480 | |
| 10481 | return result; |
| 10482 | } |
| 10483 | |
| 10484 | /* if-exists built-in spec function. |
| 10485 | |
| 10486 | Checks to see if the file specified by the absolute pathname in |
| 10487 | ARGS exists. Returns that pathname if found. |
| 10488 | |
| 10489 | The usual use for this function is to check for a library file |
| 10490 | (whose name has been expanded with %s). */ |
| 10491 | |
| 10492 | static const char * |
| 10493 | if_exists_spec_function (int argc, const char **argv) |
| 10494 | { |
| 10495 | /* Must have only one argument. */ |
| 10496 | if (argc == 1 && IS_ABSOLUTE_PATH (argv[0]) && ! access (name: argv[0], R_OK)) |
| 10497 | return argv[0]; |
| 10498 | |
| 10499 | return NULL; |
| 10500 | } |
| 10501 | |
| 10502 | /* if-exists-else built-in spec function. |
| 10503 | |
| 10504 | This is like if-exists, but takes an additional argument which |
| 10505 | is returned if the first argument does not exist. */ |
| 10506 | |
| 10507 | static const char * |
| 10508 | if_exists_else_spec_function (int argc, const char **argv) |
| 10509 | { |
| 10510 | /* Must have exactly two arguments. */ |
| 10511 | if (argc != 2) |
| 10512 | return NULL; |
| 10513 | |
| 10514 | if (IS_ABSOLUTE_PATH (argv[0]) && ! access (name: argv[0], R_OK)) |
| 10515 | return argv[0]; |
| 10516 | |
| 10517 | return argv[1]; |
| 10518 | } |
| 10519 | |
| 10520 | /* if-exists-then-else built-in spec function. |
| 10521 | |
| 10522 | Checks to see if the file specified by the absolute pathname in |
| 10523 | the first arg exists. Returns the second arg if so, otherwise returns |
| 10524 | the third arg if it is present. */ |
| 10525 | |
| 10526 | static const char * |
| 10527 | if_exists_then_else_spec_function (int argc, const char **argv) |
| 10528 | { |
| 10529 | |
| 10530 | /* Must have two or three arguments. */ |
| 10531 | if (argc != 2 && argc != 3) |
| 10532 | return NULL; |
| 10533 | |
| 10534 | if (IS_ABSOLUTE_PATH (argv[0]) && ! access (name: argv[0], R_OK)) |
| 10535 | return argv[1]; |
| 10536 | |
| 10537 | if (argc == 3) |
| 10538 | return argv[2]; |
| 10539 | |
| 10540 | return NULL; |
| 10541 | } |
| 10542 | |
| 10543 | /* sanitize built-in spec function. |
| 10544 | |
| 10545 | This returns non-NULL, if sanitizing address, thread or |
| 10546 | any of the undefined behavior sanitizers. */ |
| 10547 | |
| 10548 | static const char * |
| 10549 | sanitize_spec_function (int argc, const char **argv) |
| 10550 | { |
| 10551 | if (argc != 1) |
| 10552 | return NULL; |
| 10553 | |
| 10554 | if (strcmp (s1: argv[0], s2: "address" ) == 0) |
| 10555 | return (flag_sanitize & SANITIZE_USER_ADDRESS) ? "" : NULL; |
| 10556 | if (strcmp (s1: argv[0], s2: "hwaddress" ) == 0) |
| 10557 | return (flag_sanitize & SANITIZE_USER_HWADDRESS) ? "" : NULL; |
| 10558 | if (strcmp (s1: argv[0], s2: "kernel-address" ) == 0) |
| 10559 | return (flag_sanitize & SANITIZE_KERNEL_ADDRESS) ? "" : NULL; |
| 10560 | if (strcmp (s1: argv[0], s2: "kernel-hwaddress" ) == 0) |
| 10561 | return (flag_sanitize & SANITIZE_KERNEL_HWADDRESS) ? "" : NULL; |
| 10562 | if (strcmp (s1: argv[0], s2: "thread" ) == 0) |
| 10563 | return (flag_sanitize & SANITIZE_THREAD) ? "" : NULL; |
| 10564 | if (strcmp (s1: argv[0], s2: "undefined" ) == 0) |
| 10565 | return ((flag_sanitize |
| 10566 | & ~flag_sanitize_trap |
| 10567 | & (SANITIZE_UNDEFINED | SANITIZE_UNDEFINED_NONDEFAULT))) |
| 10568 | ? "" : NULL; |
| 10569 | if (strcmp (s1: argv[0], s2: "leak" ) == 0) |
| 10570 | return ((flag_sanitize |
| 10571 | & (SANITIZE_ADDRESS | SANITIZE_LEAK | SANITIZE_THREAD)) |
| 10572 | == SANITIZE_LEAK) ? "" : NULL; |
| 10573 | return NULL; |
| 10574 | } |
| 10575 | |
| 10576 | /* replace-outfile built-in spec function. |
| 10577 | |
| 10578 | This looks for the first argument in the outfiles array's name and |
| 10579 | replaces it with the second argument. */ |
| 10580 | |
| 10581 | static const char * |
| 10582 | replace_outfile_spec_function (int argc, const char **argv) |
| 10583 | { |
| 10584 | int i; |
| 10585 | /* Must have exactly two arguments. */ |
| 10586 | if (argc != 2) |
| 10587 | abort (); |
| 10588 | |
| 10589 | for (i = 0; i < n_infiles; i++) |
| 10590 | { |
| 10591 | if (outfiles[i] && !filename_cmp (s1: outfiles[i], s2: argv[0])) |
| 10592 | outfiles[i] = xstrdup (argv[1]); |
| 10593 | } |
| 10594 | return NULL; |
| 10595 | } |
| 10596 | |
| 10597 | /* remove-outfile built-in spec function. |
| 10598 | * |
| 10599 | * This looks for the first argument in the outfiles array's name and |
| 10600 | * removes it. */ |
| 10601 | |
| 10602 | static const char * |
| 10603 | remove_outfile_spec_function (int argc, const char **argv) |
| 10604 | { |
| 10605 | int i; |
| 10606 | /* Must have exactly one argument. */ |
| 10607 | if (argc != 1) |
| 10608 | abort (); |
| 10609 | |
| 10610 | for (i = 0; i < n_infiles; i++) |
| 10611 | { |
| 10612 | if (outfiles[i] && !filename_cmp (s1: outfiles[i], s2: argv[0])) |
| 10613 | outfiles[i] = NULL; |
| 10614 | } |
| 10615 | return NULL; |
| 10616 | } |
| 10617 | |
| 10618 | /* Given two version numbers, compares the two numbers. |
| 10619 | A version number must match the regular expression |
| 10620 | ([1-9][0-9]*|0)(\.([1-9][0-9]*|0))* |
| 10621 | */ |
| 10622 | static int |
| 10623 | compare_version_strings (const char *v1, const char *v2) |
| 10624 | { |
| 10625 | int rresult; |
| 10626 | regex_t r; |
| 10627 | |
| 10628 | if (regcomp (preg: &r, pattern: "^([1-9][0-9]*|0)(\\.([1-9][0-9]*|0))*$" , |
| 10629 | REG_EXTENDED | REG_NOSUB) != 0) |
| 10630 | abort (); |
| 10631 | rresult = regexec (preg: &r, string: v1, nmatch: 0, NULL, eflags: 0); |
| 10632 | if (rresult == REG_NOMATCH) |
| 10633 | fatal_error (input_location, "invalid version number %qs" , v1); |
| 10634 | else if (rresult != 0) |
| 10635 | abort (); |
| 10636 | rresult = regexec (preg: &r, string: v2, nmatch: 0, NULL, eflags: 0); |
| 10637 | if (rresult == REG_NOMATCH) |
| 10638 | fatal_error (input_location, "invalid version number %qs" , v2); |
| 10639 | else if (rresult != 0) |
| 10640 | abort (); |
| 10641 | |
| 10642 | return strverscmp (s1: v1, s2: v2); |
| 10643 | } |
| 10644 | |
| 10645 | |
| 10646 | /* version_compare built-in spec function. |
| 10647 | |
| 10648 | This takes an argument of the following form: |
| 10649 | |
| 10650 | <comparison-op> <arg1> [<arg2>] <switch> <result> |
| 10651 | |
| 10652 | and produces "result" if the comparison evaluates to true, |
| 10653 | and nothing if it doesn't. |
| 10654 | |
| 10655 | The supported <comparison-op> values are: |
| 10656 | |
| 10657 | >= true if switch is a later (or same) version than arg1 |
| 10658 | !> opposite of >= |
| 10659 | < true if switch is an earlier version than arg1 |
| 10660 | !< opposite of < |
| 10661 | >< true if switch is arg1 or later, and earlier than arg2 |
| 10662 | <> true if switch is earlier than arg1 or is arg2 or later |
| 10663 | |
| 10664 | If the switch is not present, the condition is false unless |
| 10665 | the first character of the <comparison-op> is '!'. |
| 10666 | |
| 10667 | For example, |
| 10668 | %:version-compare(>= 10.3 mmacosx-version-min= -lmx) |
| 10669 | adds -lmx if -mmacosx-version-min=10.3.9 was passed. */ |
| 10670 | |
| 10671 | static const char * |
| 10672 | version_compare_spec_function (int argc, const char **argv) |
| 10673 | { |
| 10674 | int comp1, comp2; |
| 10675 | size_t switch_len; |
| 10676 | const char *switch_value = NULL; |
| 10677 | int nargs = 1, i; |
| 10678 | bool result; |
| 10679 | |
| 10680 | if (argc < 3) |
| 10681 | fatal_error (input_location, "too few arguments to %%:version-compare" ); |
| 10682 | if (argv[0][0] == '\0') |
| 10683 | abort (); |
| 10684 | if ((argv[0][1] == '<' || argv[0][1] == '>') && argv[0][0] != '!') |
| 10685 | nargs = 2; |
| 10686 | if (argc != nargs + 3) |
| 10687 | fatal_error (input_location, "too many arguments to %%:version-compare" ); |
| 10688 | |
| 10689 | switch_len = strlen (s: argv[nargs + 1]); |
| 10690 | for (i = 0; i < n_switches; i++) |
| 10691 | if (!strncmp (s1: switches[i].part1, s2: argv[nargs + 1], n: switch_len) |
| 10692 | && check_live_switch (switchnum: i, prefix_length: switch_len)) |
| 10693 | switch_value = switches[i].part1 + switch_len; |
| 10694 | |
| 10695 | if (switch_value == NULL) |
| 10696 | comp1 = comp2 = -1; |
| 10697 | else |
| 10698 | { |
| 10699 | comp1 = compare_version_strings (v1: switch_value, v2: argv[1]); |
| 10700 | if (nargs == 2) |
| 10701 | comp2 = compare_version_strings (v1: switch_value, v2: argv[2]); |
| 10702 | else |
| 10703 | comp2 = -1; /* This value unused. */ |
| 10704 | } |
| 10705 | |
| 10706 | switch (argv[0][0] << 8 | argv[0][1]) |
| 10707 | { |
| 10708 | case '>' << 8 | '=': |
| 10709 | result = comp1 >= 0; |
| 10710 | break; |
| 10711 | case '!' << 8 | '<': |
| 10712 | result = comp1 >= 0 || switch_value == NULL; |
| 10713 | break; |
| 10714 | case '<' << 8: |
| 10715 | result = comp1 < 0; |
| 10716 | break; |
| 10717 | case '!' << 8 | '>': |
| 10718 | result = comp1 < 0 || switch_value == NULL; |
| 10719 | break; |
| 10720 | case '>' << 8 | '<': |
| 10721 | result = comp1 >= 0 && comp2 < 0; |
| 10722 | break; |
| 10723 | case '<' << 8 | '>': |
| 10724 | result = comp1 < 0 || comp2 >= 0; |
| 10725 | break; |
| 10726 | |
| 10727 | default: |
| 10728 | fatal_error (input_location, |
| 10729 | "unknown operator %qs in %%:version-compare" , argv[0]); |
| 10730 | } |
| 10731 | if (! result) |
| 10732 | return NULL; |
| 10733 | |
| 10734 | return argv[nargs + 2]; |
| 10735 | } |
| 10736 | |
| 10737 | /* %:include builtin spec function. This differs from %include in that it |
| 10738 | can be nested inside a spec, and thus be conditionalized. It takes |
| 10739 | one argument, the filename, and looks for it in the startfile path. |
| 10740 | The result is always NULL, i.e. an empty expansion. */ |
| 10741 | |
| 10742 | static const char * |
| 10743 | include_spec_function (int argc, const char **argv) |
| 10744 | { |
| 10745 | char *file; |
| 10746 | |
| 10747 | if (argc != 1) |
| 10748 | abort (); |
| 10749 | |
| 10750 | file = find_a_file (pprefix: &startfile_prefixes, name: argv[0], R_OK, do_multi: true); |
| 10751 | read_specs (filename: file ? file : argv[0], main_p: false, user_p: false); |
| 10752 | |
| 10753 | return NULL; |
| 10754 | } |
| 10755 | |
| 10756 | /* %:find-file spec function. This function replaces its argument by |
| 10757 | the file found through find_file, that is the -print-file-name gcc |
| 10758 | program option. */ |
| 10759 | static const char * |
| 10760 | find_file_spec_function (int argc, const char **argv) |
| 10761 | { |
| 10762 | const char *file; |
| 10763 | |
| 10764 | if (argc != 1) |
| 10765 | abort (); |
| 10766 | |
| 10767 | file = find_file (name: argv[0]); |
| 10768 | return file; |
| 10769 | } |
| 10770 | |
| 10771 | |
| 10772 | /* %:find-plugindir spec function. This function replaces its argument |
| 10773 | by the -iplugindir=<dir> option. `dir' is found through find_file, that |
| 10774 | is the -print-file-name gcc program option. */ |
| 10775 | static const char * |
| 10776 | find_plugindir_spec_function (int argc, const char **argv ATTRIBUTE_UNUSED) |
| 10777 | { |
| 10778 | const char *option; |
| 10779 | |
| 10780 | if (argc != 0) |
| 10781 | abort (); |
| 10782 | |
| 10783 | option = concat ("-iplugindir=" , find_file (name: "plugin" ), NULL); |
| 10784 | return option; |
| 10785 | } |
| 10786 | |
| 10787 | |
| 10788 | /* %:print-asm-header spec function. Print a banner to say that the |
| 10789 | following output is from the assembler. */ |
| 10790 | |
| 10791 | static const char * |
| 10792 | (int arg ATTRIBUTE_UNUSED, |
| 10793 | const char **argv ATTRIBUTE_UNUSED) |
| 10794 | { |
| 10795 | printf (_("Assembler options\n=================\n\n" )); |
| 10796 | printf (_("Use \"-Wa,OPTION\" to pass \"OPTION\" to the assembler.\n\n" )); |
| 10797 | fflush (stdout); |
| 10798 | return NULL; |
| 10799 | } |
| 10800 | |
| 10801 | /* Get a random number for -frandom-seed */ |
| 10802 | |
| 10803 | static unsigned HOST_WIDE_INT |
| 10804 | get_random_number (void) |
| 10805 | { |
| 10806 | unsigned HOST_WIDE_INT ret = 0; |
| 10807 | int fd; |
| 10808 | |
| 10809 | fd = open (file: "/dev/urandom" , O_RDONLY); |
| 10810 | if (fd >= 0) |
| 10811 | { |
| 10812 | read (fd: fd, buf: &ret, nbytes: sizeof (HOST_WIDE_INT)); |
| 10813 | close (fd: fd); |
| 10814 | if (ret) |
| 10815 | return ret; |
| 10816 | } |
| 10817 | |
| 10818 | /* Get some more or less random data. */ |
| 10819 | #ifdef HAVE_GETTIMEOFDAY |
| 10820 | { |
| 10821 | struct timeval tv; |
| 10822 | |
| 10823 | gettimeofday (tv: &tv, NULL); |
| 10824 | ret = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
| 10825 | } |
| 10826 | #else |
| 10827 | { |
| 10828 | time_t now = time (NULL); |
| 10829 | |
| 10830 | if (now != (time_t)-1) |
| 10831 | ret = (unsigned) now; |
| 10832 | } |
| 10833 | #endif |
| 10834 | |
| 10835 | return ret ^ getpid (); |
| 10836 | } |
| 10837 | |
| 10838 | /* %:compare-debug-dump-opt spec function. Save the last argument, |
| 10839 | expected to be the last -fdump-final-insns option, or generate a |
| 10840 | temporary. */ |
| 10841 | |
| 10842 | static const char * |
| 10843 | compare_debug_dump_opt_spec_function (int arg, |
| 10844 | const char **argv ATTRIBUTE_UNUSED) |
| 10845 | { |
| 10846 | char *ret; |
| 10847 | char *name; |
| 10848 | int which; |
| 10849 | static char random_seed[HOST_BITS_PER_WIDE_INT / 4 + 3]; |
| 10850 | |
| 10851 | if (arg != 0) |
| 10852 | fatal_error (input_location, |
| 10853 | "too many arguments to %%:compare-debug-dump-opt" ); |
| 10854 | |
| 10855 | do_spec_2 (spec: "%{fdump-final-insns=*:%*}" , NULL); |
| 10856 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 10857 | |
| 10858 | if (argbuf.length () > 0 |
| 10859 | && strcmp (s1: argv[argbuf.length () - 1], s2: "." ) != 0) |
| 10860 | { |
| 10861 | if (!compare_debug) |
| 10862 | return NULL; |
| 10863 | |
| 10864 | name = xstrdup (argv[argbuf.length () - 1]); |
| 10865 | ret = NULL; |
| 10866 | } |
| 10867 | else |
| 10868 | { |
| 10869 | if (argbuf.length () > 0) |
| 10870 | do_spec_2 (spec: "%B.gkd" , NULL); |
| 10871 | else if (!compare_debug) |
| 10872 | return NULL; |
| 10873 | else |
| 10874 | do_spec_2 (spec: "%{!save-temps*:%g.gkd}%{save-temps*:%B.gkd}" , NULL); |
| 10875 | |
| 10876 | do_spec_1 (spec: " " , inswitch: 0, NULL); |
| 10877 | |
| 10878 | gcc_assert (argbuf.length () > 0); |
| 10879 | |
| 10880 | name = xstrdup (argbuf.last ()); |
| 10881 | |
| 10882 | char *arg = quote_spec (xstrdup (name)); |
| 10883 | ret = concat ("-fdump-final-insns=" , arg, NULL); |
| 10884 | free (ptr: arg); |
| 10885 | } |
| 10886 | |
| 10887 | which = compare_debug < 0; |
| 10888 | debug_check_temp_file[which] = name; |
| 10889 | |
| 10890 | if (!which) |
| 10891 | { |
| 10892 | unsigned HOST_WIDE_INT value = get_random_number (); |
| 10893 | |
| 10894 | sprintf (s: random_seed, HOST_WIDE_INT_PRINT_HEX, value); |
| 10895 | } |
| 10896 | |
| 10897 | if (*random_seed) |
| 10898 | { |
| 10899 | char *tmp = ret; |
| 10900 | ret = concat ("%{!frandom-seed=*:-frandom-seed=" , random_seed, "} " , |
| 10901 | ret, NULL); |
| 10902 | free (ptr: tmp); |
| 10903 | } |
| 10904 | |
| 10905 | if (which) |
| 10906 | *random_seed = 0; |
| 10907 | |
| 10908 | return ret; |
| 10909 | } |
| 10910 | |
| 10911 | /* %:compare-debug-self-opt spec function. Expands to the options |
| 10912 | that are to be passed in the second compilation of |
| 10913 | compare-debug. */ |
| 10914 | |
| 10915 | static const char * |
| 10916 | compare_debug_self_opt_spec_function (int arg, |
| 10917 | const char **argv ATTRIBUTE_UNUSED) |
| 10918 | { |
| 10919 | if (arg != 0) |
| 10920 | fatal_error (input_location, |
| 10921 | "too many arguments to %%:compare-debug-self-opt" ); |
| 10922 | |
| 10923 | if (compare_debug >= 0) |
| 10924 | return NULL; |
| 10925 | |
| 10926 | return concat ("\ |
| 10927 | %<o %<MD %<MMD %<MF* %<MG %<MP %<MQ* %<MT* \ |
| 10928 | %<fdump-final-insns=* -w -S -o %j \ |
| 10929 | %{!fcompare-debug-second:-fcompare-debug-second} \ |
| 10930 | " , compare_debug_opt, NULL); |
| 10931 | } |
| 10932 | |
| 10933 | /* %:pass-through-libs spec function. Finds all -l options and input |
| 10934 | file names in the lib spec passed to it, and makes a list of them |
| 10935 | prepended with the plugin option to cause them to be passed through |
| 10936 | to the final link after all the new object files have been added. */ |
| 10937 | |
| 10938 | const char * |
| 10939 | pass_through_libs_spec_func (int argc, const char **argv) |
| 10940 | { |
| 10941 | char *prepended = xstrdup (" " ); |
| 10942 | int n; |
| 10943 | /* Shlemiel the painter's algorithm. Innately horrible, but at least |
| 10944 | we know that there will never be more than a handful of strings to |
| 10945 | concat, and it's only once per run, so it's not worth optimising. */ |
| 10946 | for (n = 0; n < argc; n++) |
| 10947 | { |
| 10948 | char *old = prepended; |
| 10949 | /* Anything that isn't an option is a full path to an output |
| 10950 | file; pass it through if it ends in '.a'. Among options, |
| 10951 | pass only -l. */ |
| 10952 | if (argv[n][0] == '-' && argv[n][1] == 'l') |
| 10953 | { |
| 10954 | const char *lopt = argv[n] + 2; |
| 10955 | /* Handle both joined and non-joined -l options. If for any |
| 10956 | reason there's a trailing -l with no joined or following |
| 10957 | arg just discard it. */ |
| 10958 | if (!*lopt && ++n >= argc) |
| 10959 | break; |
| 10960 | else if (!*lopt) |
| 10961 | lopt = argv[n]; |
| 10962 | prepended = concat (prepended, "-plugin-opt=-pass-through=-l" , |
| 10963 | lopt, " " , NULL); |
| 10964 | } |
| 10965 | else if (!strcmp (s1: ".a" , s2: argv[n] + strlen (s: argv[n]) - 2)) |
| 10966 | { |
| 10967 | prepended = concat (prepended, "-plugin-opt=-pass-through=" , |
| 10968 | argv[n], " " , NULL); |
| 10969 | } |
| 10970 | if (prepended != old) |
| 10971 | free (ptr: old); |
| 10972 | } |
| 10973 | return prepended; |
| 10974 | } |
| 10975 | |
| 10976 | static bool |
| 10977 | not_actual_file_p (const char *name) |
| 10978 | { |
| 10979 | return (strcmp (s1: name, s2: "-" ) == 0 |
| 10980 | || strcmp (s1: name, HOST_BIT_BUCKET) == 0); |
| 10981 | } |
| 10982 | |
| 10983 | /* %:dumps spec function. Take an optional argument that overrides |
| 10984 | the default extension for -dumpbase and -dumpbase-ext. |
| 10985 | Return -dumpdir, -dumpbase and -dumpbase-ext, if needed. */ |
| 10986 | const char * |
| 10987 | dumps_spec_func (int argc, const char **argv ATTRIBUTE_UNUSED) |
| 10988 | { |
| 10989 | const char *ext = dumpbase_ext; |
| 10990 | char *p; |
| 10991 | |
| 10992 | char *args[3] = { NULL, NULL, NULL }; |
| 10993 | int nargs = 0; |
| 10994 | |
| 10995 | /* Do not compute a default for -dumpbase-ext when -dumpbase was |
| 10996 | given explicitly. */ |
| 10997 | if (dumpbase && *dumpbase && !ext) |
| 10998 | ext = "" ; |
| 10999 | |
| 11000 | if (argc == 1) |
| 11001 | { |
| 11002 | /* Do not override the explicitly-specified -dumpbase-ext with |
| 11003 | the specs-provided overrider. */ |
| 11004 | if (!ext) |
| 11005 | ext = argv[0]; |
| 11006 | } |
| 11007 | else if (argc != 0) |
| 11008 | fatal_error (input_location, "too many arguments for %%:dumps" ); |
| 11009 | |
| 11010 | if (dumpdir) |
| 11011 | { |
| 11012 | p = quote_spec_arg (xstrdup (dumpdir)); |
| 11013 | args[nargs++] = concat (" -dumpdir " , p, NULL); |
| 11014 | free (ptr: p); |
| 11015 | } |
| 11016 | |
| 11017 | if (!ext) |
| 11018 | ext = input_basename + basename_length; |
| 11019 | |
| 11020 | /* Use the precomputed outbase, or compute dumpbase from |
| 11021 | input_basename, just like %b would. */ |
| 11022 | char *base; |
| 11023 | |
| 11024 | if (dumpbase && *dumpbase) |
| 11025 | { |
| 11026 | base = xstrdup (dumpbase); |
| 11027 | p = base + outbase_length; |
| 11028 | gcc_checking_assert (strncmp (base, outbase, outbase_length) == 0); |
| 11029 | gcc_checking_assert (strcmp (p, ext) == 0); |
| 11030 | } |
| 11031 | else if (outbase_length) |
| 11032 | { |
| 11033 | base = xstrndup (outbase, outbase_length); |
| 11034 | p = NULL; |
| 11035 | } |
| 11036 | else |
| 11037 | { |
| 11038 | base = xstrndup (input_basename, suffixed_basename_length); |
| 11039 | p = base + basename_length; |
| 11040 | } |
| 11041 | |
| 11042 | if (compare_debug < 0 || !p || strcmp (s1: p, s2: ext) != 0) |
| 11043 | { |
| 11044 | if (p) |
| 11045 | *p = '\0'; |
| 11046 | |
| 11047 | const char *gk; |
| 11048 | if (compare_debug < 0) |
| 11049 | gk = ".gk" ; |
| 11050 | else |
| 11051 | gk = "" ; |
| 11052 | |
| 11053 | p = concat (base, gk, ext, NULL); |
| 11054 | |
| 11055 | free (ptr: base); |
| 11056 | base = p; |
| 11057 | } |
| 11058 | |
| 11059 | base = quote_spec_arg (base); |
| 11060 | args[nargs++] = concat (" -dumpbase " , base, NULL); |
| 11061 | free (ptr: base); |
| 11062 | |
| 11063 | if (*ext) |
| 11064 | { |
| 11065 | p = quote_spec_arg (xstrdup (ext)); |
| 11066 | args[nargs++] = concat (" -dumpbase-ext " , p, NULL); |
| 11067 | free (ptr: p); |
| 11068 | } |
| 11069 | |
| 11070 | const char *ret = concat (args[0], args[1], args[2], NULL); |
| 11071 | while (nargs > 0) |
| 11072 | free (ptr: args[--nargs]); |
| 11073 | |
| 11074 | return ret; |
| 11075 | } |
| 11076 | |
| 11077 | /* Returns "" if ARGV[ARGC - 2] is greater than ARGV[ARGC-1]. |
| 11078 | Otherwise, return NULL. */ |
| 11079 | |
| 11080 | static const char * |
| 11081 | greater_than_spec_func (int argc, const char **argv) |
| 11082 | { |
| 11083 | char *converted; |
| 11084 | |
| 11085 | if (argc == 1) |
| 11086 | return NULL; |
| 11087 | |
| 11088 | gcc_assert (argc >= 2); |
| 11089 | |
| 11090 | long arg = strtol (nptr: argv[argc - 2], endptr: &converted, base: 10); |
| 11091 | gcc_assert (converted != argv[argc - 2]); |
| 11092 | |
| 11093 | long lim = strtol (nptr: argv[argc - 1], endptr: &converted, base: 10); |
| 11094 | gcc_assert (converted != argv[argc - 1]); |
| 11095 | |
| 11096 | if (arg > lim) |
| 11097 | return "" ; |
| 11098 | |
| 11099 | return NULL; |
| 11100 | } |
| 11101 | |
| 11102 | /* Returns "" if debug_info_level is greater than ARGV[ARGC-1]. |
| 11103 | Otherwise, return NULL. */ |
| 11104 | |
| 11105 | static const char * |
| 11106 | debug_level_greater_than_spec_func (int argc, const char **argv) |
| 11107 | { |
| 11108 | char *converted; |
| 11109 | |
| 11110 | if (argc != 1) |
| 11111 | fatal_error (input_location, |
| 11112 | "wrong number of arguments to %%:debug-level-gt" ); |
| 11113 | |
| 11114 | long arg = strtol (nptr: argv[0], endptr: &converted, base: 10); |
| 11115 | gcc_assert (converted != argv[0]); |
| 11116 | |
| 11117 | if (debug_info_level > arg) |
| 11118 | return "" ; |
| 11119 | |
| 11120 | return NULL; |
| 11121 | } |
| 11122 | |
| 11123 | /* Returns "" if dwarf_version is greater than ARGV[ARGC-1]. |
| 11124 | Otherwise, return NULL. */ |
| 11125 | |
| 11126 | static const char * |
| 11127 | dwarf_version_greater_than_spec_func (int argc, const char **argv) |
| 11128 | { |
| 11129 | char *converted; |
| 11130 | |
| 11131 | if (argc != 1) |
| 11132 | fatal_error (input_location, |
| 11133 | "wrong number of arguments to %%:dwarf-version-gt" ); |
| 11134 | |
| 11135 | long arg = strtol (nptr: argv[0], endptr: &converted, base: 10); |
| 11136 | gcc_assert (converted != argv[0]); |
| 11137 | |
| 11138 | if (dwarf_version > arg) |
| 11139 | return "" ; |
| 11140 | |
| 11141 | return NULL; |
| 11142 | } |
| 11143 | |
| 11144 | static void |
| 11145 | path_prefix_reset (path_prefix *prefix) |
| 11146 | { |
| 11147 | struct prefix_list *iter, *next; |
| 11148 | iter = prefix->plist; |
| 11149 | while (iter) |
| 11150 | { |
| 11151 | next = iter->next; |
| 11152 | free (ptr: const_cast <char *> (iter->prefix)); |
| 11153 | XDELETE (iter); |
| 11154 | iter = next; |
| 11155 | } |
| 11156 | prefix->plist = 0; |
| 11157 | prefix->max_len = 0; |
| 11158 | } |
| 11159 | |
| 11160 | /* The function takes 3 arguments: OPTION name, file name and location |
| 11161 | where we search for Fortran modules. |
| 11162 | When the FILE is found by find_file, return OPTION=path_to_file. */ |
| 11163 | |
| 11164 | static const char * |
| 11165 | find_fortran_preinclude_file (int argc, const char **argv) |
| 11166 | { |
| 11167 | char *result = NULL; |
| 11168 | if (argc != 3) |
| 11169 | return NULL; |
| 11170 | |
| 11171 | struct path_prefix prefixes = { .plist: 0, .max_len: 0, .name: "preinclude" }; |
| 11172 | |
| 11173 | /* Search first for 'finclude' folder location for a header file |
| 11174 | installed by the compiler (similar to omp_lib.h). */ |
| 11175 | add_prefix (pprefix: &prefixes, prefix: argv[2], NULL, priority: 0, require_machine_suffix: 0, os_multilib: 0); |
| 11176 | #ifdef TOOL_INCLUDE_DIR |
| 11177 | /* Then search: <prefix>/<target>/<include>/finclude */ |
| 11178 | add_prefix (&prefixes, TOOL_INCLUDE_DIR "/finclude/" , |
| 11179 | NULL, 0, 0, 0); |
| 11180 | #endif |
| 11181 | #ifdef NATIVE_SYSTEM_HEADER_DIR |
| 11182 | /* Then search: <sysroot>/usr/include/finclude/<multilib> */ |
| 11183 | add_sysrooted_hdrs_prefix (&prefixes, NATIVE_SYSTEM_HEADER_DIR "/finclude/" , |
| 11184 | NULL, 0, 0, 0); |
| 11185 | #endif |
| 11186 | |
| 11187 | const char *path = find_a_file (pprefix: &include_prefixes, name: argv[1], R_OK, do_multi: false); |
| 11188 | if (path != NULL) |
| 11189 | result = concat (argv[0], path, NULL); |
| 11190 | else |
| 11191 | { |
| 11192 | path = find_a_file (pprefix: &prefixes, name: argv[1], R_OK, do_multi: false); |
| 11193 | if (path != NULL) |
| 11194 | result = concat (argv[0], path, NULL); |
| 11195 | } |
| 11196 | |
| 11197 | path_prefix_reset (prefix: &prefixes); |
| 11198 | return result; |
| 11199 | } |
| 11200 | |
| 11201 | /* The function takes any number of arguments and joins them together. |
| 11202 | |
| 11203 | This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a" |
| 11204 | with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces: |
| 11205 | when doing $* replacement we first replace $* with the rest of the switch |
| 11206 | (in this case ""), and then add any arguments as arguments after the result, |
| 11207 | resulting in "-fjoined= foo.b". Using this function with e.g. |
| 11208 | %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv |
| 11209 | elements instead of separated by spaces, and we paste them together. */ |
| 11210 | |
| 11211 | static const char * |
| 11212 | join_spec_func (int argc, const char **argv) |
| 11213 | { |
| 11214 | if (argc == 1) |
| 11215 | return argv[0]; |
| 11216 | for (int i = 0; i < argc; ++i) |
| 11217 | obstack_grow (&obstack, argv[i], strlen (argv[i])); |
| 11218 | obstack_1grow (&obstack, '\0'); |
| 11219 | return XOBFINISH (&obstack, const char *); |
| 11220 | } |
| 11221 | |
| 11222 | /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string |
| 11223 | so as to precede every one of them with a backslash. Return the |
| 11224 | original string or the reallocated one. */ |
| 11225 | |
| 11226 | static inline char * |
| 11227 | quote_string (char *orig, bool (*quote_p)(char, void *), void *p) |
| 11228 | { |
| 11229 | int len, number_of_space = 0; |
| 11230 | |
| 11231 | for (len = 0; orig[len]; len++) |
| 11232 | if (quote_p (orig[len], p)) |
| 11233 | number_of_space++; |
| 11234 | |
| 11235 | if (number_of_space) |
| 11236 | { |
| 11237 | char *new_spec = (char *) xmalloc (len + number_of_space + 1); |
| 11238 | int j, k; |
| 11239 | for (j = 0, k = 0; j <= len; j++, k++) |
| 11240 | { |
| 11241 | if (quote_p (orig[j], p)) |
| 11242 | new_spec[k++] = '\\'; |
| 11243 | new_spec[k] = orig[j]; |
| 11244 | } |
| 11245 | free (ptr: orig); |
| 11246 | return new_spec; |
| 11247 | } |
| 11248 | else |
| 11249 | return orig; |
| 11250 | } |
| 11251 | |
| 11252 | /* Return true iff C is any of the characters convert_white_space |
| 11253 | should quote. */ |
| 11254 | |
| 11255 | static inline bool |
| 11256 | whitespace_to_convert_p (char c, void *) |
| 11257 | { |
| 11258 | return (c == ' ' || c == '\t'); |
| 11259 | } |
| 11260 | |
| 11261 | /* Insert backslash before spaces in ORIG (usually a file path), to |
| 11262 | avoid being broken by spec parser. |
| 11263 | |
| 11264 | This function is needed as do_spec_1 treats white space (' ' and '\t') |
| 11265 | as the end of an argument. But in case of -plugin /usr/gcc install/xxx.so, |
| 11266 | the file name should be treated as a single argument rather than being |
| 11267 | broken into multiple. Solution is to insert '\\' before the space in a |
| 11268 | file name. |
| 11269 | |
| 11270 | This function converts and only converts all occurrence of ' ' |
| 11271 | to '\\' + ' ' and '\t' to '\\' + '\t'. For example: |
| 11272 | "a b" -> "a\\ b" |
| 11273 | "a b" -> "a\\ \\ b" |
| 11274 | "a\tb" -> "a\\\tb" |
| 11275 | "a\\ b" -> "a\\\\ b" |
| 11276 | |
| 11277 | orig: input null-terminating string that was allocated by xalloc. The |
| 11278 | memory it points to might be freed in this function. Behavior undefined |
| 11279 | if ORIG wasn't xalloced or was freed already at entry. |
| 11280 | |
| 11281 | Return: ORIG if no conversion needed. Otherwise a newly allocated string |
| 11282 | that was converted from ORIG. */ |
| 11283 | |
| 11284 | static char * |
| 11285 | convert_white_space (char *orig) |
| 11286 | { |
| 11287 | return quote_string (orig, quote_p: whitespace_to_convert_p, NULL); |
| 11288 | } |
| 11289 | |
| 11290 | /* Return true iff C matches any of the spec active characters. */ |
| 11291 | static inline bool |
| 11292 | quote_spec_char_p (char c, void *) |
| 11293 | { |
| 11294 | switch (c) |
| 11295 | { |
| 11296 | case ' ': |
| 11297 | case '\t': |
| 11298 | case '\n': |
| 11299 | case '|': |
| 11300 | case '%': |
| 11301 | case '\\': |
| 11302 | return true; |
| 11303 | |
| 11304 | default: |
| 11305 | return false; |
| 11306 | } |
| 11307 | } |
| 11308 | |
| 11309 | /* Like convert_white_space, but deactivate all active spec chars by |
| 11310 | quoting them. */ |
| 11311 | |
| 11312 | static inline char * |
| 11313 | quote_spec (char *orig) |
| 11314 | { |
| 11315 | return quote_string (orig, quote_p: quote_spec_char_p, NULL); |
| 11316 | } |
| 11317 | |
| 11318 | /* Like quote_spec, but also turn an empty string into the spec for an |
| 11319 | empty argument. */ |
| 11320 | |
| 11321 | static inline char * |
| 11322 | quote_spec_arg (char *orig) |
| 11323 | { |
| 11324 | if (!*orig) |
| 11325 | { |
| 11326 | free (ptr: orig); |
| 11327 | return xstrdup ("%\"" ); |
| 11328 | } |
| 11329 | |
| 11330 | return quote_spec (orig); |
| 11331 | } |
| 11332 | |
| 11333 | /* Restore all state within gcc.cc to the initial state, so that the driver |
| 11334 | code can be safely re-run in-process. |
| 11335 | |
| 11336 | Many const char * variables are referenced by static specs (see |
| 11337 | INIT_STATIC_SPEC above). These variables are restored to their default |
| 11338 | values by a simple loop over the static specs. |
| 11339 | |
| 11340 | For other variables, we directly restore them all to their initial |
| 11341 | values (often implicitly 0). |
| 11342 | |
| 11343 | Free the various obstacks in this file, along with "opts_obstack" |
| 11344 | from opts.cc. |
| 11345 | |
| 11346 | This function also restores any environment variables that were changed. */ |
| 11347 | |
| 11348 | void |
| 11349 | driver::finalize () |
| 11350 | { |
| 11351 | env.restore (); |
| 11352 | diagnostic_finish (context: global_dc); |
| 11353 | |
| 11354 | is_cpp_driver = 0; |
| 11355 | at_file_supplied = 0; |
| 11356 | print_help_list = 0; |
| 11357 | print_version = 0; |
| 11358 | verbose_only_flag = 0; |
| 11359 | print_subprocess_help = 0; |
| 11360 | use_ld = NULL; |
| 11361 | report_times_to_file = NULL; |
| 11362 | target_system_root = DEFAULT_TARGET_SYSTEM_ROOT; |
| 11363 | target_system_root_changed = 0; |
| 11364 | target_sysroot_suffix = 0; |
| 11365 | target_sysroot_hdrs_suffix = 0; |
| 11366 | save_temps_flag = SAVE_TEMPS_NONE; |
| 11367 | save_temps_overrides_dumpdir = false; |
| 11368 | dumpdir_trailing_dash_added = false; |
| 11369 | free (ptr: dumpdir); |
| 11370 | free (ptr: dumpbase); |
| 11371 | free (ptr: dumpbase_ext); |
| 11372 | free (ptr: outbase); |
| 11373 | dumpdir = dumpbase = dumpbase_ext = outbase = NULL; |
| 11374 | dumpdir_length = outbase_length = 0; |
| 11375 | spec_machine = DEFAULT_TARGET_MACHINE; |
| 11376 | greatest_status = 1; |
| 11377 | |
| 11378 | obstack_free (&obstack, NULL); |
| 11379 | obstack_free (&opts_obstack, NULL); /* in opts.cc */ |
| 11380 | obstack_free (&collect_obstack, NULL); |
| 11381 | |
| 11382 | link_command_spec = LINK_COMMAND_SPEC; |
| 11383 | |
| 11384 | obstack_free (&multilib_obstack, NULL); |
| 11385 | |
| 11386 | user_specs_head = NULL; |
| 11387 | user_specs_tail = NULL; |
| 11388 | |
| 11389 | /* Within the "compilers" vec, the fields "suffix" and "spec" were |
| 11390 | statically allocated for the default compilers, but dynamically |
| 11391 | allocated for additional compilers. Delete them for the latter. */ |
| 11392 | for (int i = n_default_compilers; i < n_compilers; i++) |
| 11393 | { |
| 11394 | free (ptr: const_cast <char *> (compilers[i].suffix)); |
| 11395 | free (ptr: const_cast <char *> (compilers[i].spec)); |
| 11396 | } |
| 11397 | XDELETEVEC (compilers); |
| 11398 | compilers = NULL; |
| 11399 | n_compilers = 0; |
| 11400 | |
| 11401 | linker_options.truncate (size: 0); |
| 11402 | assembler_options.truncate (size: 0); |
| 11403 | preprocessor_options.truncate (size: 0); |
| 11404 | |
| 11405 | path_prefix_reset (prefix: &exec_prefixes); |
| 11406 | path_prefix_reset (prefix: &startfile_prefixes); |
| 11407 | path_prefix_reset (prefix: &include_prefixes); |
| 11408 | |
| 11409 | machine_suffix = 0; |
| 11410 | just_machine_suffix = 0; |
| 11411 | gcc_exec_prefix = 0; |
| 11412 | gcc_libexec_prefix = 0; |
| 11413 | set_static_spec_shared (spec: &md_exec_prefix, MD_EXEC_PREFIX); |
| 11414 | set_static_spec_shared (spec: &md_startfile_prefix, MD_STARTFILE_PREFIX); |
| 11415 | set_static_spec_shared (spec: &md_startfile_prefix_1, MD_STARTFILE_PREFIX_1); |
| 11416 | multilib_dir = 0; |
| 11417 | multilib_os_dir = 0; |
| 11418 | multiarch_dir = 0; |
| 11419 | |
| 11420 | /* Free any specs dynamically-allocated by set_spec. |
| 11421 | These will be at the head of the list, before the |
| 11422 | statically-allocated ones. */ |
| 11423 | if (specs) |
| 11424 | { |
| 11425 | while (specs != static_specs) |
| 11426 | { |
| 11427 | spec_list *next = specs->next; |
| 11428 | free (ptr: const_cast <char *> (specs->name)); |
| 11429 | XDELETE (specs); |
| 11430 | specs = next; |
| 11431 | } |
| 11432 | specs = 0; |
| 11433 | } |
| 11434 | for (unsigned i = 0; i < ARRAY_SIZE (static_specs); i++) |
| 11435 | { |
| 11436 | spec_list *sl = &static_specs[i]; |
| 11437 | if (sl->alloc_p) |
| 11438 | { |
| 11439 | free (ptr: const_cast <char *> (*(sl->ptr_spec))); |
| 11440 | sl->alloc_p = false; |
| 11441 | } |
| 11442 | *(sl->ptr_spec) = sl->default_ptr; |
| 11443 | } |
| 11444 | #ifdef EXTRA_SPECS |
| 11445 | extra_specs = NULL; |
| 11446 | #endif |
| 11447 | |
| 11448 | processing_spec_function = 0; |
| 11449 | |
| 11450 | clear_args (); |
| 11451 | |
| 11452 | have_c = 0; |
| 11453 | have_o = 0; |
| 11454 | |
| 11455 | temp_names = NULL; |
| 11456 | execution_count = 0; |
| 11457 | signal_count = 0; |
| 11458 | |
| 11459 | temp_filename = NULL; |
| 11460 | temp_filename_length = 0; |
| 11461 | always_delete_queue = NULL; |
| 11462 | failure_delete_queue = NULL; |
| 11463 | |
| 11464 | XDELETEVEC (switches); |
| 11465 | switches = NULL; |
| 11466 | n_switches = 0; |
| 11467 | n_switches_alloc = 0; |
| 11468 | |
| 11469 | compare_debug = 0; |
| 11470 | compare_debug_second = 0; |
| 11471 | compare_debug_opt = NULL; |
| 11472 | for (int i = 0; i < 2; i++) |
| 11473 | { |
| 11474 | switches_debug_check[i] = NULL; |
| 11475 | n_switches_debug_check[i] = 0; |
| 11476 | n_switches_alloc_debug_check[i] = 0; |
| 11477 | debug_check_temp_file[i] = NULL; |
| 11478 | } |
| 11479 | |
| 11480 | XDELETEVEC (infiles); |
| 11481 | infiles = NULL; |
| 11482 | n_infiles = 0; |
| 11483 | n_infiles_alloc = 0; |
| 11484 | |
| 11485 | combine_inputs = false; |
| 11486 | added_libraries = 0; |
| 11487 | XDELETEVEC (outfiles); |
| 11488 | outfiles = NULL; |
| 11489 | spec_lang = 0; |
| 11490 | last_language_n_infiles = 0; |
| 11491 | gcc_input_filename = NULL; |
| 11492 | input_file_number = 0; |
| 11493 | input_filename_length = 0; |
| 11494 | basename_length = 0; |
| 11495 | suffixed_basename_length = 0; |
| 11496 | input_basename = NULL; |
| 11497 | input_suffix = NULL; |
| 11498 | /* We don't need to purge "input_stat", just to unset "input_stat_set". */ |
| 11499 | input_stat_set = 0; |
| 11500 | input_file_compiler = NULL; |
| 11501 | arg_going = 0; |
| 11502 | delete_this_arg = 0; |
| 11503 | this_is_output_file = 0; |
| 11504 | this_is_library_file = 0; |
| 11505 | this_is_linker_script = 0; |
| 11506 | input_from_pipe = 0; |
| 11507 | suffix_subst = NULL; |
| 11508 | |
| 11509 | XDELETEVEC (mdswitches); |
| 11510 | mdswitches = NULL; |
| 11511 | n_mdswitches = 0; |
| 11512 | |
| 11513 | used_arg.finalize (); |
| 11514 | } |
| 11515 | |
| 11516 | /* PR jit/64810. |
| 11517 | Targets can provide configure-time default options in |
| 11518 | OPTION_DEFAULT_SPECS. The jit needs to access these, but |
| 11519 | they are expressed in the spec language. |
| 11520 | |
| 11521 | Run just enough of the driver to be able to expand these |
| 11522 | specs, and then call the callback CB on each |
| 11523 | such option. The options strings are *without* a leading |
| 11524 | '-' character e.g. ("march=x86-64"). Finally, clean up. */ |
| 11525 | |
| 11526 | void |
| 11527 | driver_get_configure_time_options (void (*cb) (const char *option, |
| 11528 | void *user_data), |
| 11529 | void *user_data) |
| 11530 | { |
| 11531 | size_t i; |
| 11532 | |
| 11533 | obstack_init (&obstack); |
| 11534 | init_opts_obstack (); |
| 11535 | n_switches = 0; |
| 11536 | |
| 11537 | for (i = 0; i < ARRAY_SIZE (option_default_specs); i++) |
| 11538 | do_option_spec (name: option_default_specs[i].name, |
| 11539 | spec: option_default_specs[i].spec); |
| 11540 | |
| 11541 | for (i = 0; (int) i < n_switches; i++) |
| 11542 | { |
| 11543 | gcc_assert (switches[i].part1); |
| 11544 | (*cb) (switches[i].part1, user_data); |
| 11545 | } |
| 11546 | |
| 11547 | obstack_free (&opts_obstack, NULL); |
| 11548 | obstack_free (&obstack, NULL); |
| 11549 | n_switches = 0; |
| 11550 | } |
| 11551 | |