⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gcc.c

📁 gcc关键代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Compiler driver program that can handle many languages.   Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,   Inc.This file is part of GCC.GCC is free software; you can redistribute it and/or modify it underthe terms of the GNU General Public License as published by the FreeSoftware Foundation; either version 2, or (at your option) any laterversion.GCC is distributed in the hope that it will be useful, but WITHOUT ANYWARRANTY; without even the implied warranty of MERCHANTABILITY orFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public Licensefor more details.You should have received a copy of the GNU General Public Licensealong with GCC; see the file COPYING.  If not, write to the FreeSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA02110-1301, USA.This paragraph is here to try to keep Sun CC from dying.The number of chars here seems crucial!!!!  *//* This program is the user interface to the C compiler and possibly toother compilers.  It is used because compilation is a complicated procedurewhich involves running several programs and passing temporary files betweenthem, forwarding the users switches to those programs selectively,and deleting the temporary files at the end.CC recognizes how to compile each input file by suffixes in the file names.Once it knows which kind of compilation to perform, the procedure forcompilation is specified by a string called a "spec".  *//* A Short Introduction to Adding a Command-Line Option.   Before adding a command-line option, consider if it is really   necessary.  Each additional command-line option adds complexity and   is difficult to remove in subsequent versions.   In the following, consider adding the command-line argument   `--bar'.   1. Each command-line option is specified in the specs file.  The   notation is described below in the comment entitled "The Specs   Language".  Read it.   2. In this file, add an entry to "option_map" equating the long   `--' argument version and any shorter, single letter version.  Read   the comments in the declaration of "struct option_map" for an   explanation.  Do not omit the first `-'.   3. Look in the "specs" file to determine which program or option   list should be given the argument, e.g., "cc1_options".  Add the   appropriate syntax for the shorter option version to the   corresponding "const char *" entry in this file.  Omit the first   `-' from the option.  For example, use `-bar', rather than `--bar'.   4. If the argument takes an argument, e.g., `--baz argument1',   modify either DEFAULT_SWITCH_TAKES_ARG or   DEFAULT_WORD_SWITCH_TAKES_ARG in gcc.h.  Omit the first `-'   from `--baz'.   5. Document the option in this file's display_help().  If the   option is passed to a subprogram, modify its corresponding   function, e.g., cppinit.c:print_help() or toplev.c:display_help(),   instead.   6. Compile and test.  Make sure that your new specs file is being   read.  For example, use a debugger to investigate the value of   "specs_file" in main().  */#include "config.h"#include "system.h"#include "coretypes.h"#include "multilib.h" /* before tm.h */#include "tm.h"#include <signal.h>#if ! defined( SIGCHLD ) && defined( SIGCLD )#  define SIGCHLD SIGCLD#endif#include "xregex.h"#include "obstack.h"#include "intl.h"#include "prefix.h"#include "gcc.h"#include "flags.h"/* By default there is no special suffix for target executables.  *//* FIXME: when autoconf is fixed, remove the host check - dj */#if defined(TARGET_EXECUTABLE_SUFFIX) && defined(HOST_EXECUTABLE_SUFFIX)#define HAVE_TARGET_EXECUTABLE_SUFFIX#endif/* By default there is no special suffix for host executables.  */#ifdef HOST_EXECUTABLE_SUFFIX#define HAVE_HOST_EXECUTABLE_SUFFIX#else#define HOST_EXECUTABLE_SUFFIX ""#endif/* By default, the suffix for target object files is ".o".  */#ifdef TARGET_OBJECT_SUFFIX#define HAVE_TARGET_OBJECT_SUFFIX#else#define TARGET_OBJECT_SUFFIX ".o"#endifstatic const char dir_separator_str[] = { DIR_SEPARATOR, 0 };/* Most every one is fine with LIBRARY_PATH.  For some, it conflicts.  */#ifndef LIBRARY_PATH_ENV#define LIBRARY_PATH_ENV "LIBRARY_PATH"#endif#ifndef HAVE_KILL#define kill(p,s) raise(s)#endif/* If a stage of compilation returns an exit status >= 1,   compilation of that file ceases.  */#define MIN_FATAL_STATUS 1/* Flag set by cppspec.c to 1.  */int is_cpp_driver;/* Flag saying to pass the greatest exit code returned by a sub-process   to the calling program.  */static int pass_exit_codes;/* Definition of string containing the arguments given to configure.  */#include "configargs.h"/* Flag saying to print the directories gcc will search through looking for   programs, libraries, etc.  */static int print_search_dirs;/* Flag saying to print the full filename of this file   as found through our usual search mechanism.  */static const char *print_file_name = NULL;/* As print_file_name, but search for executable file.  */static const char *print_prog_name = NULL;/* Flag saying to print the relative path we'd use to   find libgcc.a given the current compiler flags.  */static int print_multi_directory;/* Flag saying to print the relative path we'd use to   find OS libraries given the current compiler flags.  */static int print_multi_os_directory;/* Flag saying to print the list of subdirectories and   compiler flags used to select them in a standard form.  */static int print_multi_lib;/* Flag saying to print the command line options understood by gcc and its   sub-processes.  */static int print_help_list;/* Flag indicating whether we should print the command and arguments */static int verbose_flag;/* Flag indicating whether we should ONLY print the command and   arguments (like verbose_flag) without executing the command.   Displayed arguments are quoted so that the generated command   line is suitable for execution.  This is intended for use in   shell scripts to capture the driver-generated command line.  */static int verbose_only_flag;/* Flag indicating to print target specific command line options.  */static int target_help_flag;/* Flag indicating whether we should report subprocess execution times   (if this is supported by the system - see pexecute.c).  */static int report_times;/* Nonzero means place this string before uses of /, so that include   and library files can be found in an alternate location.  */#ifdef TARGET_SYSTEM_ROOTstatic const char *target_system_root = TARGET_SYSTEM_ROOT;#elsestatic const char *target_system_root = 0;#endif/* Nonzero means pass the updated target_system_root to the compiler.  */static int target_system_root_changed;/* Nonzero means append this string to target_system_root.  */static const char *target_sysroot_suffix = 0;/* Nonzero means append this string to target_system_root for headers.  */static const char *target_sysroot_hdrs_suffix = 0;/* Nonzero means write "temp" files in source directory   and use the source file's name in them, and don't delete them.  */static int save_temps_flag;/* Nonzero means pass multiple source files to the compiler at one time.  */static int combine_flag = 0;/* Nonzero means use pipes to communicate between subprocesses.   Overridden by either of the above two flags.  */static int use_pipes;/* The compiler version.  */static const char *compiler_version;/* The target version specified with -V */static const char *const spec_version = DEFAULT_TARGET_VERSION;/* The target machine specified with -b.  */static const char *spec_machine = DEFAULT_TARGET_MACHINE;/* Nonzero if cross-compiling.   When -b is used, the value comes from the `specs' file.  */#ifdef CROSS_COMPILEstatic const char *cross_compile = "1";#elsestatic const char *cross_compile = "0";#endif#ifdef MODIFY_TARGET_NAME/* Information on how to alter the target name based on a command-line   switch.  The only case we support now is simply appending or deleting a   string to or from the end of the first part of the configuration name.  */static const struct modify_target{  const char *const sw;  const enum add_del {ADD, DELETE} add_del;  const char *const str;}modify_target[] = MODIFY_TARGET_NAME;#endif/* The number of errors that have occurred; the link phase will not be   run if this is nonzero.  */static int error_count = 0;/* Greatest exit code of sub-processes that has been encountered up to   now.  */static int greatest_status = 1;/* This is the obstack which we use to allocate many strings.  */static struct obstack obstack;/* This is the obstack to build an environment variable to pass to   collect2 that describes all of the relevant switches of what to   pass the compiler in building the list of pointers to constructors   and destructors.  */static struct obstack collect_obstack;/* Forward declaration for prototypes.  */struct path_prefix;struct prefix_list;static void init_spec (void);static void store_arg (const char *, int, int);static char *load_specs (const char *);static void read_specs (const char *, int);static void set_spec (const char *, const char *);static struct compiler *lookup_compiler (const char *, size_t, const char *);static char *build_search_list (struct path_prefix *, const char *, int);static void putenv_from_prefixes (struct path_prefix *, const char *);static int access_check (const char *, int);static char *find_a_file (struct path_prefix *, const char *, int, int);static void add_prefix (struct path_prefix *, const char *, const char *,			int, int, int);static void add_sysrooted_prefix (struct path_prefix *, const char *,				  const char *, int, int, int);static void translate_options (int *, const char *const **);static char *skip_whitespace (char *);static void delete_if_ordinary (const char *);static void delete_temp_files (void);static void delete_failure_queue (void);static void clear_failure_queue (void);static int check_live_switch (int, int);static const char *handle_braces (const char *);static inline bool input_suffix_matches (const char *, const char *);static inline bool switch_matches (const char *, const char *, int);static inline void mark_matching_switches (const char *, const char *, int);static inline void process_marked_switches (void);static const char *process_brace_body (const char *, const char *, const char *, int, int);static const struct spec_function *lookup_spec_function (const char *);static const char *eval_spec_function (const char *, const char *);static const char *handle_spec_function (const char *);static char *save_string (const char *, int);static void set_collect_gcc_options (void);static void do_spec_path (struct prefix_list *, const char *, int, int, int, const char *, const char *);static int do_spec_1 (const char *, int, const char *);static int do_spec_2 (const char *);static void do_option_spec (const char *, const char *);static void do_self_spec (const char *);static const char *find_file (const char *);static int is_directory (const char *, const char *, int);static const char *validate_switches (const char *);static void validate_all_switches (void);static inline void validate_switches_from_spec (const char *);static void give_switch (int, int);static int used_arg (const char *, int);static int default_arg (const char *, int);static void set_multilib_dir (void);static void print_multilib_info (void);static void perror_with_name (const char *);static void notice (const char *, ...) ATTRIBUTE_PRINTF_1;static void display_help (void);static void add_preprocessor_option (const char *, int);static void add_assembler_option (const char *, int);static void add_linker_option (const char *, int);static void process_command (int, const char **);static int execute (void);static void alloc_args (void);static void clear_args (void);static void fatal_error (int);#if defined(ENABLE_SHARED_LIBGCC) && !defined(REAL_LIBGCC_SPEC)static void init_gcc_specs (struct obstack *, const char *, const char *,			    const char *);#endif#if defined(HAVE_TARGET_OBJECT_SUFFIX) || defined(HAVE_TARGET_EXECUTABLE_SUFFIX)static const char *convert_filename (const char *, int, int);#endifstatic const char *if_exists_spec_function (int, const char **);static const char *if_exists_else_spec_function (int, const char **);static const char *replace_outfile_spec_function (int, const char **);static const char *version_compare_spec_function (int, const char **);/* The Specs LanguageSpecs are strings containing lines, each of which (if not blank)is made up of a program name, and arguments separated by spaces.The program name must be exact and start from root, since no pathis searched and it is unreliable to depend on the current working directory.Redirection of input or output is not supported; the subprograms mustaccept filenames saying what files to read and write.In addition, the specs can contain %-sequences to substitute variable textor for conditional text.  Here is a table of all defined %-sequences.Note that spaces are not generated automatically around the results ofexpanding these sequences; therefore, you can concatenate them togetheror with constant text in a single argument. %%	substitute one % into the program name or argument. %i     substitute the name of the input file being processed. %b     substitute the basename of the input file being processed.	This is the substring up to (and not including) the last period	and not including the directory. %B	same as %b, but include the file suffix (text after the last period). %gSUFFIX	substitute a file name that has suffix SUFFIX and is chosen	once per compilation, and mark the argument a la %d.  To reduce	exposure to denial-of-service attacks, the file name is now

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -