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

📄 spec-files.html

📁 自己收集的linux入门到学懂高级编程书集 包括linux程序设计第三版
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html lang="en"><head><title>Using the GNU Compiler Collection (GCC)</title><meta http-equiv="Content-Type" content="text/html"><meta name="description" content="Using the GNU Compiler Collection (GCC)"><meta name="generator" content="makeinfo 4.6"><!--Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   <p>Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.2 orany later version published by the Free Software Foundation; with theInvariant Sections being "GNU General Public License" and "FundingFree Software", the Front-Cover texts being (a) (see below), and withthe Back-Cover Texts being (b) (see below).  A copy of the license isincluded in the section entitled "GNU Free Documentation License".   <p>(a) The FSF's Front-Cover Text is:   <p>A GNU Manual   <p>(b) The FSF's Back-Cover Text is:   <p>You have freedom to copy and modify this GNU Manual, like GNU     software.  Copies published by the Free Software Foundation raise     funds for GNU development.--><meta http-equiv="Content-Style-Type" content="text/css"><style type="text/css"><!--  pre.display { font-family:inherit }  pre.format  { font-family:inherit }  pre.smalldisplay { font-family:inherit; font-size:smaller }  pre.smallformat  { font-family:inherit; font-size:smaller }  pre.smallexample { font-size:smaller }  pre.smalllisp    { font-size:smaller }--></style></head><body><div class="node"><p>Node:&nbsp;<a name="Spec%20Files">Spec Files</a>,Next:&nbsp;<a rel="next" accesskey="n" href="Target-Options.html#Target%20Options">Target Options</a>,Previous:&nbsp;<a rel="previous" accesskey="p" href="Directory-Options.html#Directory%20Options">Directory Options</a>,Up:&nbsp;<a rel="up" accesskey="u" href="Invoking-GCC.html#Invoking%20GCC">Invoking GCC</a><hr><br></div><h3 class="section">Specifying subprocesses and the switches to pass to them</h3><p><code>gcc</code> is a driver program.  It performs its job by invoking asequence of other programs to do the work of compiling, assembling andlinking.  GCC interprets its command-line parameters and uses these todeduce which programs it should invoke, and which command-line optionsit ought to place on their command lines.  This behavior is controlledby <dfn>spec strings</dfn>.  In most cases there is one spec string for eachprogram that GCC can invoke, but a few programs have multiple specstrings to control their behavior.  The spec strings built into GCC canbe overridden by using the <code>-specs=</code> command-line switch to specifya spec file.   <p><dfn>Spec files</dfn> are plaintext files that are used to construct specstrings.  They consist of a sequence of directives separated by blanklines.  The type of directive is determined by the first non-whitespacecharacter on the line and it can be one of the following:     <dl><dt><code>%</code><var>command</var><code></code>     <dd>Issues a <var>command</var> to the spec file processor.  The commands that canappear here are:          <dl><dt><code>%include &lt;</code><var>file</var><code>&gt;</code>          <dd>Search for <var>file</var> and insert its text at the current point in thespecs file.          <br><dt><code>%include_noerr &lt;</code><var>file</var><code>&gt;</code>          <dd>Just like <code>%include</code>, but do not generate an error message if the includefile cannot be found.          <br><dt><code>%rename </code><var>old_name</var><code> </code><var>new_name</var><code></code>          <dd>Rename the spec string <var>old_name</var> to <var>new_name</var>.     </dl>     <br><dt><code>*[</code><var>spec_name</var><code>]:</code>     <dd>This tells the compiler to create, override or delete the named specstring.  All lines after this directive up to the next directive orblank line are considered to be the text for the spec string.  If thisresults in an empty string then the spec will be deleted.  (Or, if thespec did not exist, then nothing will happened.)  Otherwise, if the specdoes not currently exist a new spec will be created.  If the spec doesexist then its contents will be overridden by the text of thisdirective, unless the first character of that text is the <code>+</code>character, in which case the text will be appended to the spec.     <br><dt><code>[</code><var>suffix</var><code>]:</code>     <dd>Creates a new <code>[</code><var>suffix</var><code>] spec</code> pair.  All lines after this directiveand up to the next directive or blank line are considered to make up thespec string for the indicated suffix.  When the compiler encounters aninput file with the named suffix, it will processes the spec string inorder to work out how to compile that file.  For example:     <pre class="smallexample">          .ZZ:          z-compile -input %i          </pre>     <p>This says that any input file whose name ends in <code>.ZZ</code> should bepassed to the program <code>z-compile</code>, which should be invoked with thecommand-line switch <code>-input</code> and with the result of performing the<code>%i</code> substitution.  (See below.)     <p>As an alternative to providing a spec string, the text that follows asuffix directive can be one of the following:          <dl><dt><code>@</code><var>language</var><code></code>          <dd>This says that the suffix is an alias for a known <var>language</var>.  This issimilar to using the <code>-x</code> command-line switch to GCC to specify alanguage explicitly.  For example:          <pre class="smallexample">               .ZZ:               @c++               </pre>          <p>Says that .ZZ files are, in fact, C++ source files.          <br><dt><code>#</code><var>name</var><code></code>          <dd>This causes an error messages saying:          <pre class="smallexample">               <var>name</var> compiler not installed on this system.               </pre>          </dl>     <p>GCC already has an extensive list of suffixes built into it. This directive will add an entry to the end of the list of suffixes, butsince the list is searched from the end backwards, it is effectivelypossible to override earlier entries using this technique.   </dl>   <p>GCC has the following spec strings built into it.  Spec files canoverride these strings or create their own.  Note that individualtargets can also add their own spec strings to this list.<pre class="smallexample">     asm          Options to pass to the assembler     asm_final    Options to pass to the assembler post-processor     cpp          Options to pass to the C preprocessor     cc1          Options to pass to the C compiler     cc1plus      Options to pass to the C++ compiler     endfile      Object files to include at the end of the link     link         Options to pass to the linker     lib          Libraries to include on the command line to the linker     libgcc       Decides which GCC support library to pass to the linker     linker       Sets the name of the linker     predefines   Defines to be passed to the C preprocessor     signed_char  Defines to pass to CPP to say whether <code>char</code> is signed                  by default     startfile    Object files to include at the start of the link     </pre>   <p>Here is a small example of a spec file:<pre class="smallexample">     %rename lib                 old_lib          *lib:     --start-group -lgcc -lc -leval1 --end-group %(old_lib)     </pre>   <p>This example renames the spec called <code>lib</code> to <code>old_lib</code> andthen overrides the previous definition of <code>lib</code> with a new one. The new definition adds in some extra command-line options beforeincluding the text of the old definition.   <p><dfn>Spec strings</dfn> are a list of command-line options to be passed to theircorresponding program.  In addition, the spec strings can contain<code>%</code>-prefixed sequences to substitute variable text or toconditionally insert text into the command line.  Using these constructsit is possible to generate quite complex command lines.   <p>Here is a table of all defined <code>%</code>-sequences for specstrings.  Note that spaces are not generated automatically around theresults of expanding these sequences.  Therefore you can concatenate themtogether or combine them with constant text in a single argument.     <dl><dt><code>%%</code>     <dd>Substitute one <code>%</code> into the program name or argument.     <br><dt><code>%i</code>     <dd>Substitute the name of the input file being processed.     <br><dt><code>%b</code>     <dd>Substitute the basename of the input file being processed. This is the substring up to (and not including) the last periodand not including the directory.     <br><dt><code>%B</code>     <dd>This is the same as <code>%b</code>, but include the file suffix (text afterthe last period).     <br><dt><code>%d</code>     <dd>Marks the argument containing or following the <code>%d</code> as atemporary file name, so that that file will be deleted if GCC exitssuccessfully.  Unlike <code>%g</code>, this contributes no text to theargument.     <br><dt><code>%g</code><var>suffix</var><code></code>     <dd>Substitute a file name that has suffix <var>suffix</var> and is chosenonce per compilation, and mark the argument in the same way as<code>%d</code>.  To reduce exposure to denial-of-service attacks, the filename is now chosen in a way that is hard to predict even when previouslychosen file names are known.  For example, <code>%g.s ... %g.o ... %g.s</code>might turn into <code>ccUVUUAU.s ccXYAXZ12.o ccUVUUAU.s</code>.  <var>suffix</var> matchesthe regexp <code>[.A-Za-z]*</code> or the special string <code>%O</code>, which istreated exactly as if <code>%O</code> had been preprocessed.  Previously, <code>%g</code>was simply substituted with a file name chosen once per compilation,without regard to any appended suffix (which was therefore treatedjust like ordinary text), making such attacks more likely to succeed.     <br><dt><code>%u</code><var>suffix</var><code></code>     <dd>Like <code>%g</code>, but generates a new temporary file name even if<code>%u</code><var>suffix</var><code></code> was already seen.     <br><dt><code>%U</code><var>suffix</var><code></code>     <dd>Substitutes the last file name generated with <code>%u</code><var>suffix</var><code></code>, generating anew one if there is no such last file name.  In the absence of any<code>%u</code><var>suffix</var><code></code>, this is just like <code>%g</code><var>suffix</var><code></code>, except they don't sharethe same suffix <em>space</em>, so <code>%g.s ... %U.s ... %g.s ... %U.s</code>would involve the generation of two distinct file names, onefor each <code>%g.s</code> and another for each <code>%U.s</code>.  Previously, <code>%U</code> wassimply substituted with a file name chosen for the previous <code>%u</code>,without regard to any appended suffix.     <br><dt><code>%j</code><var>suffix</var><code></code>     <dd>Substitutes the name of the <code>HOST_BIT_BUCKET</code>, if any, and if it iswritable, and if save-temps is off; otherwise, substitute the nameof a temporary file, just like <code>%u</code>.  This temporary file is notmeant for communication between processes, but rather as a junkdisposal mechanism.     <br><dt><code>%|</code><var>suffix</var><code></code>     <dd><dt><code>%m</code><var>suffix</var><code></code>     <dd>Like <code>%g</code>, except if <code>-pipe</code> is in effect.  In that case<code>%|</code> substitutes a single dash and <code>%m</code> substitutes nothing atall.  These are the two most common ways to instruct a program that itshould read from standard input or write to standard output.  If youneed something more elaborate you can use an <code>%{pipe:X}</code>construct: see for example <code>f/lang-specs.h</code>.     <br><dt><code>%.</code><var>SUFFIX</var><code></code>     <dd>Substitutes <var>.SUFFIX</var> for the suffixes of a matched switch's argswhen it is subsequently output with <code>%*</code>.  <var>SUFFIX</var> isterminated by the next space or %.     <br><dt><code>%w</code>     <dd>Marks the argument containing or following the <code>%w</code> as thedesignated output file of this compilation.  This puts the argumentinto the sequence of arguments that <code>%o</code> will substitute later.     <br><dt><code>%o</code>     <dd>Substitutes the names of all the output files, with spacesautomatically placed around them.  You should write spacesaround the <code>%o</code> as well or the results are undefined. <code>%o</code> is for use in the specs for running the linker. Input files whose names have no recognized suffix are not compiledat all, but they are included among the output files, so they willbe linked.

⌨️ 快捷键说明

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