📄 gcc.c
字号:
chosen in a way that is hard to predict even when previously chosen file names are known. For example, `%g.s ... %g.o ... %g.s' might turn into `ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s'. SUFFIX matches the regexp "[.0-9A-Za-z]*%O"; "%O" is treated exactly as if it had been pre-processed. Previously, %g was simply substituted with a file name chosen once per compilation, without regard to any appended suffix (which was therefore treated just like ordinary text), making such attacks more likely to succeed. %|SUFFIX like %g, but if -pipe is in effect, expands simply to "-". %mSUFFIX like %g, but if -pipe is in effect, expands to nothing. (We have both %| and %m to accommodate differences between system assemblers; see the AS_NEEDS_DASH_FOR_PIPED_INPUT target macro.) %uSUFFIX like %g, but generates a new temporary file name even if %uSUFFIX was already seen. %USUFFIX substitutes the last file name generated with %uSUFFIX, generating a new one if there is no such last file name. In the absence of any %uSUFFIX, this is just like %gSUFFIX, except they don't share the same suffix "space", so `%g.s ... %U.s ... %g.s ... %U.s' would involve the generation of two distinct file names, one for each `%g.s' and another for each `%U.s'. Previously, %U was simply substituted with a file name chosen for the previous %u, without regard to any appended suffix. %jSUFFIX substitutes the name of the HOST_BIT_BUCKET, if any, and if it is writable, and if save-temps is off; otherwise, substitute the name of a temporary file, just like %u. This temporary file is not meant for communication between processes, but rather as a junk disposal mechanism. %.SUFFIX substitutes .SUFFIX for the suffixes of a matched switch's args when it is subsequently output with %*. SUFFIX is terminated by the next space or %. %d marks the argument containing or following the %d as a temporary file name, so that that file will be deleted if CC exits successfully. Unlike %g, this contributes no text to the argument. %w marks the argument containing or following the %w as the "output file" of this compilation. This puts the argument into the sequence of arguments that %o will substitute later. %V indicates that this compilation produces no "output file". %W{...} like %{...} but mark last argument supplied within as a file to be deleted on failure. %o substitutes the names of all the output files, with spaces automatically placed around them. You should write spaces around the %o as well or the results are undefined. %o is for use in the specs for running the linker. Input files whose names have no recognized suffix are not compiled at all, but they are included among the output files, so they will be linked. %O substitutes the suffix for object files. Note that this is handled specially when it immediately follows %g, %u, or %U (with or without a suffix argument) because of the need for those to form complete file names. The handling is such that %O is treated exactly as if it had already been substituted, except that %g, %u, and %U do not currently support additional SUFFIX characters following %O as they would following, for example, `.o'. %I Substitute any of -iprefix (made from GCC_EXEC_PREFIX), -isysroot (made from TARGET_SYSTEM_ROOT), and -isystem (made from COMPILER_PATH and -B options) as necessary. %s current argument is the name of a library or startup file of some sort. Search for that file in a standard list of directories and substitute the full name found. %eSTR Print STR as an error message. STR is terminated by a newline. Use this when inconsistent options are detected. %nSTR Print STR as a notice. STR is terminated by a newline. %x{OPTION} Accumulate an option for %X. %X Output the accumulated linker options specified by compilations. %Y Output the accumulated assembler options specified by compilations. %Z Output the accumulated preprocessor options specified by compilations. %a process ASM_SPEC as a spec. This allows config.h to specify part of the spec for running as. %A process ASM_FINAL_SPEC as a spec. A capital A is actually used here. This can be used to run a post-processor after the assembler has done its job. %D Dump out a -L option for each directory in startfile_prefixes. If multilib_dir is set, extra entries are generated with it affixed. %l process LINK_SPEC as a spec. %L process LIB_SPEC as a spec. %G process LIBGCC_SPEC as a spec. %R Output the concatenation of target_system_root and target_sysroot_suffix. %S process STARTFILE_SPEC as a spec. A capital S is actually used here. %E process ENDFILE_SPEC as a spec. A capital E is actually used here. %C process CPP_SPEC as a spec. %1 process CC1_SPEC as a spec. %2 process CC1PLUS_SPEC as a spec. %* substitute the variable part of a matched option. (See below.) Note that each comma in the substituted string is replaced by a single space. %<S remove all occurrences of -S from the command line. Note - this command is position dependent. % commands in the spec string before this one will see -S, % commands in the spec string after this one will not. %<S* remove all occurrences of all switches beginning with -S from the command line. %:function(args) Call the named function FUNCTION, passing it ARGS. ARGS is first processed as a nested spec string, then split into an argument vector in the usual fashion. The function returns a string which is processed as if it had appeared literally as part of the current spec. %{S} substitutes the -S switch, if that switch was given to CC. If that switch was not specified, this substitutes nothing. Here S is a metasyntactic variable. %{S*} substitutes all the switches specified to CC whose names start with -S. This is used for -o, -I, etc; switches that take arguments. CC considers `-o foo' as being one switch whose name starts with `o'. %{o*} would substitute this text, including the space; thus, two arguments would be generated. %{S*&T*} likewise, but preserve order of S and T options (the order of S and T in the spec is not significant). Can be any number of ampersand-separated variables; for each the wild card is optional. Useful for CPP as %{D*&U*&A*}. %{S:X} substitutes X, if the -S switch was given to CC. %{!S:X} substitutes X, if the -S switch was NOT given to CC. %{S*:X} substitutes X if one or more switches whose names start with -S was given to CC. Normally X is substituted only once, no matter how many such switches appeared. However, if %* appears somewhere in X, then X will be substituted once for each matching switch, with the %* replaced by the part of that switch that matched the '*'. %{.S:X} substitutes X, if processing a file with suffix S. %{!.S:X} substitutes X, if NOT processing a file with suffix S. %{S|T:X} substitutes X if either -S or -T was given to CC. This may be combined with !, ., and * as above binding stronger than the OR. If %* appears in X, all of the alternatives must be starred, and only the first matching alternative is substituted. %{S:X; if S was given to CC, substitutes X; T:Y; else if T was given to CC, substitutes Y; :D} else substitutes D. There can be as many clauses as you need. This may be combined with ., !, |, and * as above. %(Spec) processes a specification defined in a specs file as *Spec: %[Spec] as above, but put __ around -D argumentsThe conditional text X in a %{S:X} or similar construct may containother nested % constructs or spaces, or even newlines. They areprocessed as usual, as described above. Trailing white space in X isignored. White space may also appear anywhere on the left side of thecolon in these constructs, except between . or * and the correspondingword.The -O, -f, -m, and -W switches are handled specifically in theseconstructs. If another value of -O or the negated form of a -f, -m, or-W switch is found later in the command line, the earlier switchvalue is ignored, except with {S*} where S is just one letter; thispasses all matching options.The character | at the beginning of the predicate text is used to indicatethat a command should be piped to the following command, but only if -pipeis specified.Note that it is built into CC which switches take arguments and whichdo not. You might think it would be useful to generalize this toallow each compiler's spec to say which switches take arguments. Butthis cannot be done in a consistent fashion. CC cannot even decidewhich input files have been specified without knowing which switchestake arguments, and it must know which input files to compile in orderto tell which compilers to run.CC also knows implicitly that arguments starting in `-l' are to betreated as compiler output files, and passed to the linker in theirproper position among the other output files. *//* Define the macros used for specs %a, %l, %L, %S, %C, %1. *//* config.h can define ASM_SPEC to provide extra args to the assembler or extra switch-translations. */#ifndef ASM_SPEC#define ASM_SPEC ""#endif/* config.h can define ASM_FINAL_SPEC to run a post processor after the assembler has run. */#ifndef ASM_FINAL_SPEC#define ASM_FINAL_SPEC ""#endif/* config.h can define CPP_SPEC to provide extra args to the C preprocessor or extra switch-translations. */#ifndef CPP_SPEC#define CPP_SPEC ""#endif/* config.h can define CC1_SPEC to provide extra args to cc1 and cc1plus or extra switch-translations. */#ifndef CC1_SPEC#define CC1_SPEC ""#endif/* config.h can define CC1PLUS_SPEC to provide extra args to cc1plus or extra switch-translations. */#ifndef CC1PLUS_SPEC#define CC1PLUS_SPEC ""#endif/* config.h can define LINK_SPEC to provide extra args to the linker or extra switch-translations. */#ifndef LINK_SPEC#define LINK_SPEC ""#endif/* config.h can define LIB_SPEC to override the default libraries. */#ifndef LIB_SPEC#define LIB_SPEC "%{!shared:%{g*:-lg} %{!p:%{!pg:-lc}}%{p:-lc_p}%{pg:-lc_p}}"#endif/* mudflap specs */#ifndef MFWRAP_SPEC/* XXX: valid only for GNU ld *//* XXX: should exactly match hooks provided by libmudflap.a */#define MFWRAP_SPEC " %{static: %{fmudflap|fmudflapth: \ --wrap=malloc --wrap=free --wrap=calloc --wrap=realloc\ --wrap=mmap --wrap=munmap --wrap=alloca\} %{fmudflapth: --wrap=pthread_create\}} %{fmudflap|fmudflapth: --wrap=main}"#endif#ifndef MFLIB_SPEC#define MFLIB_SPEC "%{fmudflap|fmudflapth: -export-dynamic}"#endif/* config.h can define LIBGCC_SPEC to override how and when libgcc.a is included. */#ifndef LIBGCC_SPEC#if defined(REAL_LIBGCC_SPEC)#define LIBGCC_SPEC REAL_LIBGCC_SPEC#elif defined(LINK_LIBGCC_SPECIAL_1)/* Have gcc do the search for libgcc.a. */#define LIBGCC_SPEC "libgcc.a%s"#else#define LIBGCC_SPEC "-lgcc"#endif#endif/* config.h can define STARTFILE_SPEC to override the default crt0 files. */#ifndef STARTFILE_SPEC#define STARTFILE_SPEC \ "%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}"#endif/* config.h can define SWITCHES_NEED_SPACES to control which options require spaces between the option and the argument. */#ifndef SWITCHES_NEED_SPACES#define SWITCHES_NEED_SPACES ""#endif/* config.h can define ENDFILE_SPEC to override the default crtn files. */#ifndef ENDFILE_SPEC#define ENDFILE_SPEC ""#endif#ifndef LINKER_NAME#define LINKER_NAME "collect2"#endif/* Define ASM_DEBUG_SPEC to be a spec suitable for translating '-g' to the assembler. */#ifndef ASM_DEBUG_SPEC# if defined(DBX_DEBUGGING_INFO) && defined(DWARF2_DEBUGGING_INFO) \ && defined(HAVE_AS_GDWARF2_DEBUG_FLAG) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)# define ASM_DEBUG_SPEC \ (PREFERRED_DEBUGGING_TYPE == DBX_DEBUG \ ? "%{gdwarf-2*:--gdwarf2}%{!gdwarf-2*:%{g*:--gstabs}}" \ : "%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}")# else# if defined(DBX_DEBUGGING_INFO) && defined(HAVE_AS_GSTABS_DEBUG_FLAG)# define ASM_DEBUG_SPEC "%{g*:--gstabs}"# endif# if defined(DWARF2_DEBUGGING_INFO) && defined(HAVE_AS_GDWARF2_DEBUG_FLAG)# define ASM_DEBUG_SPEC "%{g*:--gdwarf2}"# endif# endif#endif#ifndef ASM_DEBUG_SPEC# define ASM_DEBUG_SPEC ""#endif/* Here is the spec for running the linker, after compiling all files. *//* This is overridable by the target in case they need to specify the -lgcc and -lc order specially, yet not require them to override all of LINK_COMMAND_SPEC. */#ifndef LINK_GCC_C_SEQUENCE_SPEC#define LINK_GCC_C_SEQUENCE_SPEC "%G %L %G"#endif#ifndef LINK_SSP_SPEC#ifdef TARGET_LIBC_PROVIDES_SSP#define LINK_SSP_SPEC "%{fstack-protector:}"#else#define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all:-lssp_nonshared -lssp}"#endif#endif#ifndef LINK_PIE_SPEC#ifdef HAVE_LD_PIE#define LINK_PIE_SPEC "%{pie:-pie} "#else#define LINK_PIE_SPEC "%{pie:} "#endif#endif/* -u* was put back because both BSD and SysV seem to support it. *//* %{static:} simply prevents an error message if the target machine doesn't handle -static. *//* We want %{T*} after %{L*} and %D so that it can be used to specify linker scripts which exist in user specified directories, or in standard directories. */#ifndef LINK_COMMAND_SPEC#define LINK_COMMAND_SPEC "\%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S:\ %(linker) %l " LINK_PIE_SPEC "%X %{o*} %{A} %{d} %{e*} %{m} %{N} %{n} %{r}\ %{s} %{t} %{u*} %{x} %{z} %{Z} %{!A:%{!nostdlib:%{!nostartfiles:%S}}}\ %{static:} %{L*} %(mfwrap) %(link_libgcc) %o %(mflib)\ %{fprofile-arcs|fprofile-generate|coverage:-lgcov}\ %{!nostdlib:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}\ %{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*} }}}}}}"#endif#ifndef LINK_LIBGCC_SPEC/* Generate -L options for startfile prefix list. */# define LINK_LIBGCC_SPEC "%D"#endif#ifndef STARTFILE_PREFIX_SPEC# define STARTFILE_PREFIX_SPEC ""#endif#ifndef SYSROOT_SPEC# define SYSROOT_SPEC "--sysroot=%R"#endif#ifndef SYSROOT_SUFFIX_SPEC# define SYSROOT_SUFFIX_SPEC ""#endif#ifndef SYSROOT_HEADERS_SUFFIX_SPEC# define SYSROOT_HEADERS_SUFFIX_SPEC ""#endifstatic const char *asm_debug;static const char *cpp_spec = CPP_SPEC;static const char *cc1_spec = CC1_SPEC;static const char *cc1plus_spec = CC1PLUS_SPEC;static const char *link_gcc_c_sequence_spec = LINK_GCC_C_SEQUENCE_SPEC;static const char *link_ssp_spec = LINK_SSP_SPEC;static const char *asm_spec = ASM_SPEC;static const char *asm_final_spec = ASM_FINAL_SPEC;static const char *link_spec = LINK_SPEC;static const char *lib_spec = LIB_SPEC;static const char *mfwrap_spec = MFWRAP_SPEC;static const char *mflib_spec = MFLIB_SPEC;static const char *libgcc_spec = LIBGCC_SPEC;static const char *endfile_spec = ENDFILE_SPEC;static const char *startfile_spec = STARTFILE_SPEC;static const char *switches_need_spaces = SWITCHES_NEED_SPACES;static const char *linker_name_spec = LINKER_NAME;static const char *link_command_spec = LINK_COMMAND_SPEC;static const char *link_libgcc_spec = LINK_LIBGCC_SPEC;static const char *startfile_prefix_spec = STARTFILE_PREFIX_SPEC;static const char *sysroot_spec = SYSROOT_SPEC;static const char *sysroot_suffix_spec = SYSROOT_SUFFIX_SPEC;static const char *sysroot_hdrs_suffix_spec = SYSROOT_HEADERS_SUFFIX_SPEC;/* Standard options to cpp, cc1, and as, to reduce duplication in specs. There should be no need to override these in target dependent files, but we need to copy them to the specs file so that newer versions of the GCC driver can correctly drive older tool chains with the appropriate -B options. *//* When cpplib handles traditional preprocessing, get rid of this, and call cc1 (or cc1obj in objc/lang-specs.h) from the main specs so
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -