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

📄 spec-files.html

📁 gcc手册
💻 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.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,

1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.2 or

any later version published by the Free Software Foundation; with the

Invariant Sections being "GNU General Public License" and "Funding

Free Software", the Front-Cover texts being (a) (see below), and with

the Back-Cover Texts being (b) (see below).  A copy of the license is

included 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.-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Spec%20Files">Spec Files</a>,

Next:<a rel="next" accesskey="n" href="Target-Options.html#Target%20Options">Target Options</a>,

Previous:<a rel="previous" accesskey="p" href="Directory-Options.html#Directory%20Options">Directory Options</a>,

Up:<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 a

sequence of other programs to do the work of compiling, assembling and

linking.  GCC interprets its command-line parameters and uses these to

deduce which programs it should invoke, and which command-line options

it ought to place on their command lines.  This behavior is controlled

by <dfn>spec strings</dfn>.  In most cases there is one spec string for each

program that GCC can invoke, but a few programs have multiple spec

strings to control their behavior.  The spec strings built into GCC can

be overridden by using the <code>-specs=</code> command-line switch to specify

a spec file.



   <p><dfn>Spec files</dfn> are plaintext files that are used to construct spec

strings.  They consist of a sequence of directives separated by blank

lines.  The type of directive is determined by the first non-whitespace

character 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 can

appear 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 the

specs 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 include

file 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 spec

string.  All lines after this directive up to the next directive or

blank line are considered to be the text for the spec string.  If this

results in an empty string then the spec will be deleted.  (Or, if the

spec did not exist, then nothing will happened.)  Otherwise, if the spec

does not currently exist a new spec will be created.  If the spec does

exist then its contents will be overridden by the text of this

directive, 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 directive

and up to the next directive or blank line are considered to make up the

spec string for the indicated suffix.  When the compiler encounters an

input file with the named suffix, it will processes the spec string in

order 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 be

passed to the program <code>z-compile</code>, which should be invoked with the

command-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 a

suffix 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 is

similar to using the <code>-x</code> command-line switch to GCC to specify a

language 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, but

since the list is searched from the end backwards, it is effectively

possible to override earlier entries using this technique.



   </dl>



   <p>GCC has the following spec strings built into it.  Spec files can

override these strings or create their own.  Note that individual

targets 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> and

then overrides the previous definition of <code>lib</code> with a new one. 

The new definition adds in some extra command-line options before

including the text of the old definition.



   <p><dfn>Spec strings</dfn> are a list of command-line options to be passed to their

corresponding program.  In addition, the spec strings can contain

<code>%</code>-prefixed sequences to substitute variable text or to

conditionally insert text into the command line.  Using these constructs

it is possible to generate quite complex command lines.



   <p>Here is a table of all defined <code>%</code>-sequences for spec

strings.  Note that spaces are not generated automatically around the

results of expanding these sequences.  Therefore you can concatenate them

together 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 period

and not including the directory.



     <br><dt><code>%B</code>

     <dd>This is the same as <code>%b</code>, but include the file suffix (text after

the last period).



     <br><dt><code>%d</code>

     <dd>Marks the argument containing or following the <code>%d</code> as a

temporary file name, so that that file will be deleted if GCC exits

successfully.  Unlike <code>%g</code>, this contributes no text to the

argument.



     <br><dt><code>%g</code><var>suffix</var><code></code>

     <dd>Substitute a file name that has suffix <var>suffix</var> and is chosen

once per compilation, and mark the argument in the same way as

<code>%d</code>.  To reduce exposure to denial-of-service attacks, the file

name is now chosen in a way that is hard to predict even when previously

chosen 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> matches

the regexp <code>[.A-Za-z]*</code> or the special string <code>%O</code>, which is

treated 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 treated

just 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 a

new 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 share

the 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, one

for each <code>%g.s</code> and another for each <code>%U.s</code>.  Previously, <code>%U</code> was

simply 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 is

writable, and if save-temps is off; otherwise, substitute the name

of a temporary file, just like <code>%u</code>.  This temporary file is not

meant for communication between processes, but rather as a junk

disposal mechanism.



     <br><dt><code>%.</code><var>SUFFIX</var><code></code>

     <dd>Substitutes <var>.SUFFIX</var> for the suffixes of a matched switch's args

when it is subsequently output with <code>%*</code>.  <var>SUFFIX</var> is

terminated by the next space or %.



     <br><dt><code>%w</code>

     <dd>Marks the argument containing or following the <code>%w</code> as the

designated output file of this compilation.  This puts the argument

into 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 spaces

automatically placed around them.  You should write spaces

around 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 compiled

at all, but they are included among the output files, so they will

be linked.



     <br><dt><code>%O</code>

     <dd>Substitutes the suffix for object files.  Note that this is

handled specially when it immediately follows <code>%g, %u, or %U</code>,

because of the need for those to form complete file names.  The

handling is such that <code>%O</code> is treated exactly as if it had already

been substituted, except that <code>%g, %u, and %U</code> do not currently

support additional <var>suffix</var> characters following <code>%O</code> as they would

following, for example, <code>.o</code>.



     <br><dt><code>%p</code>

     <dd>Substitutes the standard macro predefinitions for the

⌨️ 快捷键说明

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