1.3 Specs: how the driver writes a command line
GCC 15.2.0. To run the commands: an installed compiler for GNU/Linux.
You pass -static-libgcc and the link line changes. You go looking for the code
that implements it, and there is none. There is no if (static_libgcc) anywhere
in the link path, no function that consults a flag and appends a library. What
you find instead is a string:
%{static|static-libgcc|static-pie:-lgcc -lgcc_eh}%{!static:%{!static-libgcc: …
GCC's driver builds every command line by expanding templates written in a small
%-escape language, which works like printf for command lines, with
conditionals and function calls added. Once you can read and write that
language, you can change a toolchain's link behaviour without rebuilding it, and
explain why options such as -static-libgcc and -nostdlib behave the way they
do. The mechanism has three parts: a table of named specs, % directives that
read the table and the command line, and specs files that rewrite the table.
The GCC manual documents the language under Spec Files.
This chapter assumes Chapter 1.1, for -### and the
spec strings in Listings 1.1-1 and 1.1-2, and
Chapter 1.2, for the sysroot, multilibs and
GCC's own library directory, lib/gcc/<target>/<version>/.
The spec table: -dumpspecs, struct spec_list and set_spec
A spec is a named entry in a table that the driver holds in memory: a name,
and the template text currently bound to it. Name references read this table
and specs files write to it, so its layout decides what an override can
change. -dumpspecs, which the GCC manual lists under
Developer Options, prints the whole table, and every line that
starts with * is a name:
$ gcc -dumpspecs | grep '^\*' # every name your driver has
$ gcc -dumpspecs | sed -n '/^\*libgcc:/,/^$/p' # one name and its value
The table is a linked list of struct spec_list. Its comment keeps name and
ptr first so that a target's EXTRA_SPECS can initialise entries, and the
field that %G depends on is ptr_spec:
struct spec_list
{
/* The following 2 fields must be first */
/* to allow EXTRA_SPECS to be initialized */
const char *name; /* name of the spec. */
const char *ptr; /* available ptr if no static pointer */
...
const char **ptr_spec; /* pointer to the spec itself. */
Listing 1.3-1: struct spec_list (gcc/gcc.cc:1685-1700).
An entry does not hold its text. ptr_spec points at the C variable that holds
the text, and the static array static_specs[] seeds the table with one such
pointer per name:
INIT_STATIC_SPEC ("libgcc", &libgcc_spec),
INIT_STATIC_SPEC ("startfile", &startfile_spec),
Listing 1.3-2: two entries from static_specs[]
(gcc/gcc.cc:1729-1730; the array begins at
:1707).
Every change to a spec, from a target's override, a -specs= file or the
driver's own startup rewriting, goes through one function and writes through
that pointer (set_spec, gcc/gcc.cc:2066). Nothing else keeps a
copy of the text, and that indirection is why %G can expand text that appears
nowhere in the source.
Which spec names exist: static_specs[] and EXTRA_SPECS
The spec names that exist before any specs file is read are fixed when GCC is
built, and no external file declares them. Knowing them tells you what a specs
file can override and what a directive such as %G refers to. These are the
names that most specs use, each with the one-letter alias that a spec can write
instead of %(name):
| Name | Alias | Holds |
|---|---|---|
cpp | %C | options for the preprocessor |
cc1 / cc1plus | %1 / %2 | options for the C / C++ compiler proper |
asm | %a | options for the assembler |
link | %l | options for the linker |
lib | %L | the default system libraries, usually -lc |
libgcc | %G | GCC's helper library, -lgcc and related libraries |
startfile | %S | objects linked before yours |
endfile | %E | objects linked after yours |
link_command | none | the whole link template (Listing 1.3-6), of which link is one part |
Another spec uses a name by reference, and a specs file overrides it.
%(link) expands the link spec in place, and %l means the same through its
alias. The names themselves come from three sources, all compiled into the
driver:
| Source | Contributes |
|---|---|
static_specs[] in gcc/gcc.cc:1707 | the universal names above, on every target |
target OS headers, e.g. gcc/config/gnu-user.h | #define STARTFILE_SPEC …, which replaces a default |
target CPU headers, e.g. gcc/config/aarch64/aarch64.h | #define EXTRA_SPECS …, which adds names such as asm_cpu_spec |
Two GCCs built from the same source for different targets therefore behave
differently, because their headers #define different specs. For the same
reason, -dumpspecs output is target-specific: an aarch64-none-elf-gcc and an
x86_64-linux-gnu-gcc list different names.
Reading a %{…} conditional: the libgcc spec
A %{…} conditional tests the command line, and nested conditionals express
every choice a spec makes. Listing 1.1-1 ended with one,
%{!fsyntax-only:%(invoke_as)}, which expands the invoke_as spec unless
-fsyntax-only was given. The libgcc spec from the hook is a larger
example, and reading it shows what -static-libgcc does to the link.
A conditional names an option without its leading dash, so %{static:…} tests
-static, and the forms below write opt for such a name. On a target with a
shared libgcc, the libgcc value, reflowed onto four lines for reading, is
roughly:
%{static|static-libgcc|static-pie:-lgcc -lgcc_eh}
%{!static:%{!static-libgcc:%{!static-pie:
%{!shared-libgcc:-lgcc --as-needed -lgcc_s --no-as-needed}
%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}}}}
-dumpspecs prints the value on one line. A newline in a spec ends one
program's command line, as Chapter 1.1 showed, so a
value written into a specs file belongs on one line.
Two forms make up the whole value. %{opt:X} emits X if -opt was given, and
%{!opt:X} emits it if -opt was not. Everything else is nesting, and three
details make the nesting readable:
|means or. The first line fires if any of-static,-static-libgccor-static-piewas given.- There is no
&&. Nesting negations expresses and-not:%{!opt1:%{!opt2:X}}. - The output half can contain conditionals, because
Xin%{opt:X}is more spec text, expanded recursively. That is why%{shared-libgcc:-lgcc_s%{!shared: -lgcc}}appends-lgcconly when you are not building a shared object.
A third form does not appear in this value, but target specs use it often. A
; separates arms, and an arm with an empty condition is the default, so
%{msoft-float:-soft;:-hard} emits -soft for -msoft-float and -hard
otherwise. Chapter 1.7 shows a glibc startfile spec
that picks among five crt1 variants this way.
Evaluated for each command, the libgcc value gives the static or shared
libgcc that the GCC manual documents for -static-libgcc and -shared-libgcc
under Link Options:
| Your command | libgcc expands to |
|---|---|
gcc foo.o | -lgcc --as-needed -lgcc_s --no-as-needed |
gcc -static-libgcc foo.o | -lgcc -lgcc_eh |
gcc -static foo.o | -lgcc -lgcc_eh |
gcc -shared-libgcc foo.o | -lgcc_s -lgcc |
gcc -shared -shared-libgcc foo.o | -lgcc_s |
libgcc.a holds helpers that each linked object may copy, and libgcc_eh.a and
libgcc_s.so.1 hold the code that must exist once per process.
Chapter 4.2 explains the split.
--as-needed and --no-as-needed are configure's defaults. With GNU ld 2.28 or
later, configure picks --push-state --as-needed and --pop-state instead
(gcc/configure.ac:6574-6587), so that is what a current
GNU/Linux link line shows.
-### prints the link line with this value expanded, and one pipeline picks out
the libgcc options for -static-libgcc:
$ gcc -### -static-libgcc foo.o 2>&1 | tr ' ' '\n' | grep lgcc
It prints -lgcc and -lgcc_eh, the table's -static-libgcc row, chosen by a
conditional and not by C code in the link path.
Why %G names a slot, not a value
%G expands the current value of the libgcc slot, not the text of the
LIBGCC_SPEC macro that the slot started from. The difference matters because
the driver rewrites the slot at startup on targets with a shared libgcc, so the
macro in the source is not what the link uses. The arrow %G → LIBGCC_SPEC in
secondhand explanations is not an equality, because four distinct things share
that name:
| # | Thing | Kind | Where |
|---|---|---|---|
| 1 | LIBGCC_SPEC | a C preprocessor macro, overridable by the target | gcc.cc:878-889 |
| 2 | libgcc_spec | a C variable, initialised from the macro | gcc.cc:1217 |
| 3 | "libgcc" | the name that variable is registered under | gcc.cc:1729 |
| 4 | %G | a directive meaning "expand whatever is registered as libgcc" | gcc.cc:6813 |
The directive's implementation is two lines:
case 'G':
value = do_spec_1 (libgcc_spec, 0, NULL);
Listing 1.3-3: %G (gcc/gcc.cc:6813-6814). do_spec_1 is the
expander.
For libgcc, ptr_spec is &libgcc_spec (Listing 1.3-2), and every set_spec
call writes into that variable. %G reads the same variable, so it sees the
latest value. It is equivalent to %(libgcc), whose handler resolves the name
through the same table (gcc.cc:6931). The variable starts with
the value of the default LIBGCC_SPEC, which holds a single option:
#define LIBGCC_SPEC "-lgcc"
Listing 1.3-4: the default LIBGCC_SPEC (gcc/gcc.cc:887).
On a target configured with ENABLE_SHARED_LIBGCC, the driver walks that string
at startup, looks for the literal -lgcc and replaces it:
const char *p = libgcc_spec;
int in_sep = 1;
/* Transform the extant libgcc_spec into one that uses the shared libgcc
when given the proper command line arguments. */
while (*p)
{
if (in_sep && *p == '-' && startswith (p, "-lgcc"))
{
init_gcc_specs (&obstack,
"-lgcc_s"
Listing 1.3-5: the shared-libgcc rewrite (gcc/gcc.cc:1922-1932).
init_gcc_specs assembles the replacement text
(gcc/gcc.cc:1816-1851). The text depends on
USE_LD_AS_NEEDED and LINK_EH_SPEC, so it differs between targets. That is
why the libgcc value in the conditional section is only roughly right, and why
you run -dumpspecs on your own toolchain.
LINK_COMMAND_SPEC: template order is link order
LINK_COMMAND_SPEC is the template for the whole link, and the order of its
directives is the order of the link command line. It also holds the guards that
-nostdlib and its relatives fail. Reading it shows why your objects sit
between the start files and the end files, and what each of those options
removes. Trimmed to what matters, with a note on each line:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S: ← only when actually linking
%(linker) %l ← collect2/ld, then the link spec
%X %{o*} %{e*} ← your -Wl, options; -o; -e
%{!nostdlib:%{!r:%{!nostartfiles:%S}}} ← startfile: crt1 crti crtbegin
%o ← YOUR object files
%{!nostdlib:%{!r:%{!nodefaultlibs:
%(link_gcc_c_sequence)}}} ← expands to %G %L %G
%{!nostdlib:%{!r:%{!nostartfiles:%E}}} ← endfile: crtend crtn
%{T*} }}}}}}
Listing 1.3-6: LINK_COMMAND_SPEC, abridged
(gcc/gcc.cc:1159-1178).
Through the aliases in the names table, each %G that
%(link_gcc_c_sequence) expands to is the whole libgcc conditional. Three
properties of the link follow from the listing.
Link order. %S, %o, the libraries and %E reach the linker in that
order. The startfile and endfile split exists because %S and %E sit on
opposite sides of your object files, and Chapter 1.7
follows that order through a real link.
Guards. -nostdlib, -nostartfiles, -nodefaultlibs and -r are guards,
not C code: an option that you pass fails its %{!…:} guard, and the text
inside the guard disappears. If you pass -nostartfiles, it removes the %S
line and the %E line: crt1, crti and crtbegin, and also crtend and crtn. In
the abridged listing, -nodefaultlibs guards only the %(link_gcc_c_sequence)
line, so libgcc and the C library go but the start and end files stay.
-nostdlib and -r sit in all three guards, so either one removes all three
lines.
Chapter 1.10 builds the full truth table
and checks it with -###.
Overridable pieces. A target customises one small name, not this whole
string. The %G %L %G order lives in its own spec so that a port can change it,
and the comment above it says so:
/* 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 %{!nolibc:%L %G}"
#endif
Listing 1.3-7: LINK_GCC_C_SEQUENCE_SPEC
(gcc/gcc.cc:987-992).
%G appears twice in that value, once before %L and once after it.
Chapter 1.7 explains why the C library sits between
two copies of libgcc.
%D, %R, %M and %I: directives that read driver state
The directives %D, %R, %M and %I read the driver's own state: its
library search list, its sysroot, its multilib directory and its header
directories. A spec does not show those values.
Spec Files documents what each directive emits, and the table
adds what it reads and which option prints it.
| Directive | Reads | Emits | Print it with |
|---|---|---|---|
%D | the library search list | one -L per directory | -print-search-dirs |
%R | the sysroot | the bare path | -print-sysroot |
%M | the multilib OS directory | ., ../lib32, ../lib64 | -print-multi-os-directory |
%I | GCC's own header directories | -isystem …/include, …/include-fixed | -print-file-name=include |
%X %Y %Z | your -Wl, / -Wa, / -Wp, options | them, prefix stripped | -### |
Chapter 1.6 explains the multilib directories that %M
names. include-fixed/ holds patched copies of the system's headers, which
Chapter 1.8 explains.
The long comment that defines the language documents %D and %R in the
driver's own words:
%D Dump out a -L option for each directory in startfile_prefixes.
If multilib_dir is set, extra entries are generated with it affixed.
...
%R Output the concatenation of target_system_root and
target_sysroot_suffix.
Listing 1.3-8: two directives, self-documented
(gcc/gcc.cc:592-593 and :599-600).
startfile_prefixes in that comment is the list the table calls the library
search list. -print-search-dirs prints it on its libraries: line, and
Chapter 1.5 shows how the driver builds it.
%R is the sysroot mechanism for specs. Chapter 1.2
showed that a sysroot is a string prepended to certain paths, and %R is where a
spec writes that prepending. A target that wants sysroot-relative link behaviour
puts %R in its spec, and one that does not leaves it out. The implementation is
the concatenation that the comment describes (gcc.cc:6819-6830).
%i, %o, %g and %s: directives that name files
Directives such as %i, %o, %g and %s name files instead of options:
inputs, outputs, temporaries and files found on the library search list. They
put file names on the command lines that -### prints, including the objects
that %o places in the link template.
| Directive | Names |
|---|---|
%i | the input file for this step |
%o | all output files, which in the link are your .o files |
%O | the object suffix, .o |
%s | the name before it, looked up in the library search list |
%g… %u… %U… %j… | temporary files, differing in whether the name is shared or unique |
Chapter 1.1 showed the driver inventing a name for the
scratch .s file that carries assembly from cc1 to as. That name comes from
%|.s and %m.s in Listing 1.1-2. %| and %m act as %g unless -pipe is
given, and with -pipe, %| expands to - and %m to nothing
(gcc.cc:6340-6367). A %g name is shared, so two separate
programs agree on a file that nobody named:
$ gcc -### hello.c 2>&1 | grep -o '/tmp/cc[A-Za-z0-9]*\.s'
The command prints the same /tmp/cc….s name twice, once from the cc1 line
and once from the as line. Chapter 1.4
follows these temporary files.
%s: one search list for libc and libgcc startfiles
%s looks up the word before it in the library search list and substitutes
the full path it finds, so crt1.o%s puts the path of crt1.o on the command
line. One list serves the start files of two owners, the C library and GCC, and
the spec does not say which owner supplies which file. A startfile spec shows the
asymmetry:
crt1.o%s crti.o%s crtbegin.o%s
└─ from libc ─────┘ └─ from libgcc ─┘
All three names are written the same way, yet crt1.o comes from the C
library's sysroot and crtbegin.o from GCC's own library directory,
lib/gcc/<target>/<version>/, next to libgcc. The driver's comment defines %s
as a search of one list:
%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.
Listing 1.3-9: %s (gcc/gcc.cc:571-573).
-print-file-name searches the same list for one name, so it shows which
owner's directory supplied each file:
$ gcc -print-file-name=crt1.o # the libc half
$ gcc -print-file-name=crtbegin.o # the libgcc half
If the search fails, -print-file-name prints the bare name back with no
error. Chapter 1.5 uses that echo to tell a
broken sysroot from a broken prefix.
Spec language summary with %(name), %{…} and %:function()
Name references, conditionals and function calls make up the rest of the spec
language, and a specs file can use all three. The driver documents the whole
language in a 230-line comment (gcc/gcc.cc:471-700).
Name references. %(name) expands any name. The one-letter aliases, such as
%G for libgcc, are in the names table.
Conditionals. The %{…} forms, with opt for an option name without its
leading dash, are these:
| Form | Meaning |
|---|---|
%{opt} | emit -opt if it was given |
%{opt*} | emit every switch starting -opt, arguments included |
%{opt:X} | emit X if -opt was given |
%{!opt:X} | emit X if -opt was not given |
%{opt1|opt2:X} | emit X if -opt1 or -opt2 was given |
%{.sfx:X} | emit X if the input file has suffix .sfx |
%{opt1:X;opt2:Y;:Z} | if / else-if / else, with Z as the default arm |
The case '{' branch of the expander hands every conditional to one function,
handle_braces (gcc.cc:6840, :7267). A
backslash escapes a character, so the colon in %{std=iso9899\:1999:X} is part
of the option name. Without the backslash, that colon would end the condition and
start the :X text.
Function calls. %:name(args) calls a function that the expander looks up in
a registry:
static const struct spec_function static_spec_functions[] =
{
{ "getenv", getenv_spec_function },
{ "if-exists", if_exists_spec_function },
...
Listing 1.3-10: the spec-function table
(gcc/gcc.cc:1775-1801), dispatched at
case ':', :6846.
Among the useful ones, %:getenv(VAR SUFFIX), %:if-exists(f) and
%:if-exists-else(a b) pick a file that is present, and
%:include(libgomp.spec) pulls in another specs file mid-expansion.
%:version-compare(...) gates on the OS version, as Darwin's specs do,
%:sanitize(address) tests which sanitizer is on, and %:gt,
%:debug-level-gt and %:dwarf-version-gt compare numbers. The returned
string is processed again as spec text. Used as a predicate,
%{%:function(args):X} emits X when the function returns something non-empty.
The table ends with EXTRA_SPEC_FUNCTIONS, so a port can add its own.
Writing a specs file for -specs=
A specs file passed with -specs= rewrites entries in the spec table, so it
changes a toolchain's behaviour without a rebuild. ARM's nano.specs is one
such file. Each entry replaces the slot it names, so if you add one option under
*link:, the target's link value is lost unless the entry appends with + or
keeps the old value with %rename. The GCC manual documents the file format
under Spec Files, and the -specs= option under
Overall Options.
*libgcc:
-lgcc -lgcc_eh
*startfile:
+ my-extra-crt.o
Listing 1.3-11: a two-entry specs file.
The syntax is *name: alone on a line, the value on the lines that follow, and a
blank line to end the entry. A value that starts with + followed by white
space appends to the old value instead of replacing it, and that test is one
line of C:
*(sl->ptr_spec) = ((spec[0] == '+' && ISSPACE ((unsigned char)spec[1]))
? concat (old_spec, spec + 1, NULL)
: xstrdup (spec));
Listing 1.3-12: replace or append, in set_spec
(gcc/gcc.cc:2106-2108).
Without the white space, set_spec takes the xstrdup branch: the old value is
replaced, and the new one starts with a literal +. + my-extra-crt.o in
Listing 1.3-11 appends to startfile, but +my-extra-crt.o would replace it.
That name also has no %s, so the driver passes my-extra-crt.o as written
instead of searching for it.
Two directives work only in a file, not in a spec. %rename old new moves a
spec's text to a new name (gcc.cc:2454), and %include FILE and
%include_noerr FILE splice in another file (:2411).
%rename keeps the old value under a new name, so the new value can refer to
it. Rename the original out of the way, then reference it:
%rename link old_link
*link:
%(old_link) -extra-flag
Listing 1.3-13: the wrapping idiom.
The new link value expands %(old_link) first and adds -extra-flag after
it, which + -extra-flag would also do. %rename also allows what + cannot,
new text before the old value, because the new value can name the old one at
any position.
A specs file may also create a name that did not exist, because set_spec adds
the entry when it finds none (gcc.cc:2066). A new name has an
effect only when another spec references it with %(name), as the new link
value does with %(old_link). Several -specs= options apply in the order
given, and -### shows the command lines that result:
$ gcc -specs=my.specs -### hello.c # see exactly what your override did
Spec precedence: compiled-in values, the specs file and -specs=
Specs reach the table from four sources, and a later source replaces what an earlier one wrote under the same name. The order decides which value a link uses when a target header, the driver and a specs file all set the same name. From first to last:
-
Compiled-in values. The defaults in
gcc.cc, and the replacements for them in the target's config headers. Both are fixed when GCC is built. -
Driver startup rewrites. The
libgccrewrite of Listing 1.3-5 is the one you are most likely to meet, and it is what makes-static-libgccwork at all. -
An installed
specsfile, in GCC's library directory,lib/gcc/<target>/<version>/(gcc.cc:8496-8499). GCC does not ship one by default, but if one is present it rewrites the toolchain with no diagnostic. -
-specs=FILEon the command line, in command-line order (gcc.cc:8633-8640).
--with-specs bypasses the table, as the section on self specs shows. To find
out whether an installed specs file is in play, look in the directory that
holds libgcc.a:
$ ls "$(dirname "$(gcc -print-libgcc-file-name)")"/specs
ls reports no such file on a toolchain that has none.
Checking specs with -dumpspecs and -###
Two commands answer most questions about specs: -dumpspecs shows what the
table holds, and -### shows what the driver does with it. When the two
disagree, something outside the table is at work, such as a self spec from
--with-specs.
$ gcc -dumpspecs # the whole table, current values
$ gcc -### hello.c # every expanded command line, nothing run
$ gcc -specs=my.specs -### hello.c # what your override actually did
-dumpspecs prints the table only after the driver has initialised it:
case OPT_dumpspecs:
{
struct spec_list *sl;
init_spec ();
for (sl = specs; sl; sl = sl->next)
printf ("*%s:\n%s\n\n", sl->name, *(sl->ptr_spec));
if (link_command_spec)
printf ("*link_command:\n%s\n\n", link_command_spec);
exit (0);
}
Listing 1.3-14: -dumpspecs (gcc/gcc.cc:4216-4226).
init_spec () runs first, with any startup rewrite the target does, such as
Listing 1.3-5, so -dumpspecs shows the live slots, not the macro text in the
source. The printf writes each entry as *name:, the value and a blank line,
which is the specs-file format. An entry copied from the dump can therefore be
edited and passed back with -specs=.
The driver also has a compile-time DEBUG_SPECS macro that prints every
%(name) expansion and every set_spec call
(gcc.cc:2110-2113). It works only in a driver rebuilt with the
macro defined, so it is a last resort.
--with-specs and self specs: options -dumpspecs cannot show
--with-specs adds its options through a self spec, which rewrites the driver's
argument list and never touches the spec table, so -dumpspecs cannot show
them. A toolchain configured this way passes options that no entry in the dump
explains, and -### shows them on each command line.
| Mechanism | What it does | In -dumpspecs? |
|---|---|---|
| built-in specs | the compiled-in table | yes |
--with-specs=… at configure time | rewrites the command line | no |
-specs=FILE at run time | reads a file into the table at startup | not by a plain -dumpspecs |
The install manual documents --with-specs under
Configuration as "additional command line driver SPECS".
--with-specs becomes CONFIGURE_SPECS
(gcc/configure.ac:1084-1089), which lands in an array of self
specs. A self spec is expanded against the driver's own arguments, and its
output rewrites them: it can add a switch, and %<opt removes -opt
(Chapter 1.9).
static const char *const driver_self_specs[] = {
"%{fdump-final-insns:-fdump-final-insns=.} %<fdump-final-insns",
DRIVER_SELF_SPECS, CONFIGURE_SPECS, GOMP_SELF_SPECS, GTM_SELF_SPECS,
Listing 1.3-15: driver_self_specs[] (gcc/gcc.cc:1361-1364),
applied at :8528-8529.
The first entry uses both forms: a conditional that adds a switch, and
%<fdump-final-insns, which removes one. CONFIGURE_SPECS sits in the same
array, so a --with-specs value can do both.
Three things to carry away
Every command line is a template, and the template's order is the command
line's order. Options such as -static-libgcc and -nostdlib are
conditionals in it, not C code.
A spec name is a slot, not a value. %G expands whatever the libgcc slot
holds after startup, which on shared-libgcc targets is not LIBGCC_SPEC's text.
Read -dumpspecs, not the macro.
A specs file rewrites a slot without a rebuild. *name: replaces the value,
+ appends, and %rename keeps the old value for a wrapper. Check the result
with -###.
Things that surprise people
+my-extra-crt.o replaces the value, and + my-extra-crt.o appends.
set_spec appends only when white space follows the +, and otherwise keeps
the + as text (Listing 1.3-12).
An installed specs file in GCC's library directory overrides the built-in
table. The driver reads it at startup with no diagnostic.
--with-specs never appears in -dumpspecs. It rewrites the argument list
through driver_self_specs, so only -### shows its effect.
Documentation coverage
The spec language has its own manual node, Spec Files
(gcc/doc/invoke.texi:37290), which documents the directives. It does not
cover:
- That
%Gexpands a mutable slot rather than the macro's text, and that the slot is rewritten at startup on shared-libgcc targets. The manual describes%Gas processingLIBGCC_SPEC, which is true only before startup. - That an installed
specsfile overrides the built-in table. - That
--with-specsrewrites your command line viadriver_self_specsrather than editing the table, and therefore cannot appear in-dumpspecs. - That a value appends only when its
+is followed by white space. The manual says only that the first character is+(invoke.texi:37340-37341), andset_specalso tests the next character (Listing 1.3-12).
Next: Chapter 1.4, From suffix to compiler: inputs, -x and temporary files,
how the driver decides what each input file is, and how it names the files
between programs.