OSDN Git Service

r383@cf-ppc-macosx: monabuilder | 2008-12-23 16:04:56 +0900
[pf3gnuchains/pf3gnuchains3x.git] / gcc / doc / sourcebuild.texi
1 @c Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008 Free Software Foundation,
2 @c Inc.
3 @c This is part of the GCC manual.
4 @c For copying conditions, see the file gcc.texi.
5
6 @node Source Tree
7 @chapter Source Tree Structure and Build System
8
9 This chapter describes the structure of the GCC source tree, and how
10 GCC is built.  The user documentation for building and installing GCC
11 is in a separate manual (@uref{http://gcc.gnu.org/install/}), with
12 which it is presumed that you are familiar.
13
14 @menu
15 * Configure Terms:: Configuration terminology and history.
16 * Top Level::       The top level source directory.
17 * gcc Directory::   The @file{gcc} subdirectory.
18 * Testsuites::      The GCC testsuites.
19 @end menu
20
21 @include configterms.texi
22
23 @node Top Level
24 @section Top Level Source Directory
25
26 The top level source directory in a GCC distribution contains several
27 files and directories that are shared with other software
28 distributions such as that of GNU Binutils.  It also contains several
29 subdirectories that contain parts of GCC and its runtime libraries:
30
31 @table @file
32 @item boehm-gc
33 The Boehm conservative garbage collector, used as part of the Java
34 runtime library.
35
36 @item contrib
37 Contributed scripts that may be found useful in conjunction with GCC@.
38 One of these, @file{contrib/texi2pod.pl}, is used to generate man
39 pages from Texinfo manuals as part of the GCC build process.
40
41 @item fastjar
42 An implementation of the @command{jar} command, used with the Java
43 front end.
44
45 @item gcc
46 The main sources of GCC itself (except for runtime libraries),
47 including optimizers, support for different target architectures,
48 language front ends, and testsuites.  @xref{gcc Directory, , The
49 @file{gcc} Subdirectory}, for details.
50
51 @item include
52 Headers for the @code{libiberty} library.
53
54 @item libada
55 The Ada runtime library.
56
57 @item libcpp
58 The C preprocessor library.
59
60 @item libgfortran
61 The Fortran runtime library.
62
63 @item libffi
64 The @code{libffi} library, used as part of the Java runtime library.
65
66 @item libiberty
67 The @code{libiberty} library, used for portability and for some
68 generally useful data structures and algorithms.  @xref{Top, ,
69 Introduction, libiberty, @sc{gnu} libiberty}, for more information
70 about this library.
71
72 @item libjava
73 The Java runtime library.
74
75 @item libmudflap
76 The @code{libmudflap} library, used for instrumenting pointer and array
77 dereferencing operations.
78
79 @item libobjc
80 The Objective-C and Objective-C++ runtime library.
81
82 @item libstdc++-v3
83 The C++ runtime library.
84
85 @item maintainer-scripts
86 Scripts used by the @code{gccadmin} account on @code{gcc.gnu.org}.
87
88 @item zlib
89 The @code{zlib} compression library, used by the Java front end and as
90 part of the Java runtime library.
91 @end table
92
93 The build system in the top level directory, including how recursion
94 into subdirectories works and how building runtime libraries for
95 multilibs is handled, is documented in a separate manual, included
96 with GNU Binutils.  @xref{Top, , GNU configure and build system,
97 configure, The GNU configure and build system}, for details.
98
99 @node gcc Directory
100 @section The @file{gcc} Subdirectory
101
102 The @file{gcc} directory contains many files that are part of the C
103 sources of GCC, other files used as part of the configuration and
104 build process, and subdirectories including documentation and a
105 testsuite.  The files that are sources of GCC are documented in a
106 separate chapter.  @xref{Passes, , Passes and Files of the Compiler}.
107
108 @menu
109 * Subdirectories:: Subdirectories of @file{gcc}.
110 * Configuration::  The configuration process, and the files it uses.
111 * Build::          The build system in the @file{gcc} directory.
112 * Makefile::       Targets in @file{gcc/Makefile}.
113 * Library Files::  Library source files and headers under @file{gcc/}.
114 * Headers::        Headers installed by GCC.
115 * Documentation::  Building documentation in GCC.
116 * Front End::      Anatomy of a language front end.
117 * Back End::       Anatomy of a target back end.
118 @end menu
119
120 @node Subdirectories
121 @subsection Subdirectories of @file{gcc}
122
123 The @file{gcc} directory contains the following subdirectories:
124
125 @table @file
126 @item @var{language}
127 Subdirectories for various languages.  Directories containing a file
128 @file{config-lang.in} are language subdirectories.  The contents of
129 the subdirectories @file{cp} (for C++), @file{objc} (for Objective-C)
130 and @file{objcp} (for Objective-C++) are documented in this manual
131 (@pxref{Passes, , Passes and Files of the Compiler}); those for other
132 languages are not.  @xref{Front End, , Anatomy of a Language Front End},
133 for details of the files in these directories.
134
135 @item config
136 Configuration files for supported architectures and operating
137 systems.  @xref{Back End, , Anatomy of a Target Back End}, for
138 details of the files in this directory.
139
140 @item doc
141 Texinfo documentation for GCC, together with automatically generated
142 man pages and support for converting the installation manual to
143 HTML@.  @xref{Documentation}.
144
145 @item fixinc
146 The support for fixing system headers to work with GCC@.  See
147 @file{fixinc/README} for more information.  The headers fixed by this
148 mechanism are installed in @file{@var{libsubdir}/include}.  Along with
149 those headers, @file{README-fixinc} is also installed, as
150 @file{@var{libsubdir}/include/README}.
151
152 @item ginclude
153 System headers installed by GCC, mainly those required by the C
154 standard of freestanding implementations.  @xref{Headers, , Headers
155 Installed by GCC}, for details of when these and other headers are
156 installed.
157
158 @item intl
159 GNU @code{libintl}, from GNU @code{gettext}, for systems which do not
160 include it in libc.  Properly, this directory should be at top level,
161 parallel to the @file{gcc} directory.
162
163 @item po
164 Message catalogs with translations of messages produced by GCC into
165 various languages, @file{@var{language}.po}.  This directory also
166 contains @file{gcc.pot}, the template for these message catalogues,
167 @file{exgettext}, a wrapper around @command{gettext} to extract the
168 messages from the GCC sources and create @file{gcc.pot}, which is run
169 by @samp{make gcc.pot}, and @file{EXCLUDES}, a list of files from
170 which messages should not be extracted.
171
172 @item testsuite
173 The GCC testsuites (except for those for runtime libraries).
174 @xref{Testsuites}.
175 @end table
176
177 @node Configuration
178 @subsection Configuration in the @file{gcc} Directory
179
180 The @file{gcc} directory is configured with an Autoconf-generated
181 script @file{configure}.  The @file{configure} script is generated
182 from @file{configure.ac} and @file{aclocal.m4}.  From the files
183 @file{configure.ac} and @file{acconfig.h}, Autoheader generates the
184 file @file{config.in}.  The file @file{cstamp-h.in} is used as a
185 timestamp.
186
187 @menu
188 * Config Fragments::     Scripts used by @file{configure}.
189 * System Config::        The @file{config.build}, @file{config.host}, and
190                          @file{config.gcc} files.
191 * Configuration Files::  Files created by running @file{configure}.
192 @end menu
193
194 @node Config Fragments
195 @subsubsection Scripts Used by @file{configure}
196
197 @file{configure} uses some other scripts to help in its work:
198
199 @itemize @bullet
200 @item The standard GNU @file{config.sub} and @file{config.guess}
201 files, kept in the top level directory, are used.
202
203 @item The file @file{config.gcc} is used to handle configuration
204 specific to the particular target machine.  The file
205 @file{config.build} is used to handle configuration specific to the
206 particular build machine.  The file @file{config.host} is used to handle
207 configuration specific to the particular host machine.  (In general,
208 these should only be used for features that cannot reasonably be tested in
209 Autoconf feature tests.)
210 @xref{System Config, , The @file{config.build}; @file{config.host};
211 and @file{config.gcc} Files}, for details of the contents of these files.
212
213 @item Each language subdirectory has a file
214 @file{@var{language}/config-lang.in} that is used for
215 front-end-specific configuration.  @xref{Front End Config, , The Front
216 End @file{config-lang.in} File}, for details of this file.
217
218 @item A helper script @file{configure.frag} is used as part of
219 creating the output of @file{configure}.
220 @end itemize
221
222 @node System Config
223 @subsubsection The @file{config.build}; @file{config.host}; and @file{config.gcc} Files
224
225 The @file{config.build} file contains specific rules for particular systems
226 which GCC is built on.  This should be used as rarely as possible, as the
227 behavior of the build system can always be detected by autoconf.
228
229 The @file{config.host} file contains specific rules for particular systems
230 which GCC will run on.  This is rarely needed.
231
232 The @file{config.gcc} file contains specific rules for particular systems
233 which GCC will generate code for.  This is usually needed.
234
235 Each file has a list of the shell variables it sets, with descriptions, at the
236 top of the file.
237
238 FIXME: document the contents of these files, and what variables should
239 be set to control build, host and target configuration.
240
241 @include configfiles.texi
242
243 @node Build
244 @subsection Build System in the @file{gcc} Directory
245
246 FIXME: describe the build system, including what is built in what
247 stages.  Also list the various source files that are used in the build
248 process but aren't source files of GCC itself and so aren't documented
249 below (@pxref{Passes}).
250
251 @include makefile.texi
252
253 @node Library Files
254 @subsection Library Source Files and Headers under the @file{gcc} Directory
255
256 FIXME: list here, with explanation, all the C source files and headers
257 under the @file{gcc} directory that aren't built into the GCC
258 executable but rather are part of runtime libraries and object files,
259 such as @file{crtstuff.c} and @file{unwind-dw2.c}.  @xref{Headers, ,
260 Headers Installed by GCC}, for more information about the
261 @file{ginclude} directory.
262
263 @node Headers
264 @subsection Headers Installed by GCC
265
266 In general, GCC expects the system C library to provide most of the
267 headers to be used with it.  However, GCC will fix those headers if
268 necessary to make them work with GCC, and will install some headers
269 required of freestanding implementations.  These headers are installed
270 in @file{@var{libsubdir}/include}.  Headers for non-C runtime
271 libraries are also installed by GCC; these are not documented here.
272 (FIXME: document them somewhere.)
273
274 Several of the headers GCC installs are in the @file{ginclude}
275 directory.  These headers, @file{iso646.h},
276 @file{stdarg.h}, @file{stdbool.h}, and @file{stddef.h},
277 are installed in @file{@var{libsubdir}/include},
278 unless the target Makefile fragment (@pxref{Target Fragment})
279 overrides this by setting @code{USER_H}.
280
281 In addition to these headers and those generated by fixing system
282 headers to work with GCC, some other headers may also be installed in
283 @file{@var{libsubdir}/include}.  @file{config.gcc} may set
284 @code{extra_headers}; this specifies additional headers under
285 @file{config} to be installed on some systems.
286
287 GCC installs its own version of @code{<float.h>}, from @file{ginclude/float.h}.
288 This is done to cope with command-line options that change the
289 representation of floating point numbers.
290
291 GCC also installs its own version of @code{<limits.h>}; this is generated
292 from @file{glimits.h}, together with @file{limitx.h} and
293 @file{limity.h} if the system also has its own version of
294 @code{<limits.h>}.  (GCC provides its own header because it is
295 required of ISO C freestanding implementations, but needs to include
296 the system header from its own header as well because other standards
297 such as POSIX specify additional values to be defined in
298 @code{<limits.h>}.)  The system's @code{<limits.h>} header is used via
299 @file{@var{libsubdir}/include/syslimits.h}, which is copied from
300 @file{gsyslimits.h} if it does not need fixing to work with GCC; if it
301 needs fixing, @file{syslimits.h} is the fixed copy.
302
303 GCC can also install @code{<tgmath.h>}.  It will do this when
304 @file{config.gcc} sets @code{use_gcc_tgmath} to @code{yes}.
305
306 @node Documentation
307 @subsection Building Documentation
308
309 The main GCC documentation is in the form of manuals in Texinfo
310 format.  These are installed in Info format; DVI versions may be
311 generated by @samp{make dvi}, PDF versions by @samp{make pdf}, and
312 HTML versions by @command{make html}.  In addition, some man pages are
313 generated from the Texinfo manuals, there are some other text files
314 with miscellaneous documentation, and runtime libraries have their own
315 documentation outside the @file{gcc} directory.  FIXME: document the
316 documentation for runtime libraries somewhere.
317
318 @menu
319 * Texinfo Manuals::      GCC manuals in Texinfo format.
320 * Man Page Generation::  Generating man pages from Texinfo manuals.
321 * Miscellaneous Docs::   Miscellaneous text files with documentation.
322 @end menu
323
324 @node Texinfo Manuals
325 @subsubsection Texinfo Manuals
326
327 The manuals for GCC as a whole, and the C and C++ front ends, are in
328 files @file{doc/*.texi}.  Other front ends have their own manuals in
329 files @file{@var{language}/*.texi}.  Common files
330 @file{doc/include/*.texi} are provided which may be included in
331 multiple manuals; the following files are in @file{doc/include}:
332
333 @table @file
334 @item fdl.texi
335 The GNU Free Documentation License.
336 @item funding.texi
337 The section ``Funding Free Software''.
338 @item gcc-common.texi
339 Common definitions for manuals.
340 @item gpl.texi
341 @itemx gpl_v3.texi
342 The GNU General Public License.
343 @item texinfo.tex
344 A copy of @file{texinfo.tex} known to work with the GCC manuals.
345 @end table
346
347 DVI-formatted manuals are generated by @samp{make dvi}, which uses
348 @command{texi2dvi} (via the Makefile macro @code{$(TEXI2DVI)}).  
349 PDF-formatted manuals are generated by @samp{make pdf}, which uses
350 @command{texi2pdf} (via the Makefile macro @code{$(TEXI2PDF)}).  HTML
351 formatted manuals are generated by @command{make html}.  Info
352 manuals are generated by @samp{make info} (which is run as part of
353 a bootstrap); this generates the manuals in the source directory,
354 using @command{makeinfo} via the Makefile macro @code{$(MAKEINFO)},
355 and they are included in release distributions.
356
357 Manuals are also provided on the GCC web site, in both HTML and
358 PostScript forms.  This is done via the script
359 @file{maintainer-scripts/update_web_docs}.  Each manual to be
360 provided online must be listed in the definition of @code{MANUALS} in
361 that file; a file @file{@var{name}.texi} must only appear once in the
362 source tree, and the output manual must have the same name as the
363 source file.  (However, other Texinfo files, included in manuals but
364 not themselves the root files of manuals, may have names that appear
365 more than once in the source tree.)  The manual file
366 @file{@var{name}.texi} should only include other files in its own
367 directory or in @file{doc/include}.  HTML manuals will be generated by
368 @samp{makeinfo --html}, PostScript manuals by @command{texi2dvi}
369 and @command{dvips}, and PDF manuals by @command{texi2pdf}.
370 All Texinfo files that are parts of manuals must
371 be checked into SVN, even if they are generated files, for the
372 generation of online manuals to work.
373
374 The installation manual, @file{doc/install.texi}, is also provided on
375 the GCC web site.  The HTML version is generated by the script
376 @file{doc/install.texi2html}.
377
378 @node Man Page Generation
379 @subsubsection Man Page Generation
380
381 Because of user demand, in addition to full Texinfo manuals, man pages
382 are provided which contain extracts from those manuals.  These man
383 pages are generated from the Texinfo manuals using
384 @file{contrib/texi2pod.pl} and @command{pod2man}.  (The man page for
385 @command{g++}, @file{cp/g++.1}, just contains a @samp{.so} reference
386 to @file{gcc.1}, but all the other man pages are generated from
387 Texinfo manuals.)
388
389 Because many systems may not have the necessary tools installed to
390 generate the man pages, they are only generated if the
391 @file{configure} script detects that recent enough tools are
392 installed, and the Makefiles allow generating man pages to fail
393 without aborting the build.  Man pages are also included in release
394 distributions.  They are generated in the source directory.
395
396 Magic comments in Texinfo files starting @samp{@@c man} control what
397 parts of a Texinfo file go into a man page.  Only a subset of Texinfo
398 is supported by @file{texi2pod.pl}, and it may be necessary to add
399 support for more Texinfo features to this script when generating new
400 man pages.  To improve the man page output, some special Texinfo
401 macros are provided in @file{doc/include/gcc-common.texi} which
402 @file{texi2pod.pl} understands:
403
404 @table @code
405 @item @@gcctabopt
406 Use in the form @samp{@@table @@gcctabopt} for tables of options,
407 where for printed output the effect of @samp{@@code} is better than
408 that of @samp{@@option} but for man page output a different effect is
409 wanted.
410 @item @@gccoptlist
411 Use for summary lists of options in manuals.
412 @item @@gol
413 Use at the end of each line inside @samp{@@gccoptlist}.  This is
414 necessary to avoid problems with differences in how the
415 @samp{@@gccoptlist} macro is handled by different Texinfo formatters.
416 @end table
417
418 FIXME: describe the @file{texi2pod.pl} input language and magic
419 comments in more detail.
420
421 @node Miscellaneous Docs
422 @subsubsection Miscellaneous Documentation
423
424 In addition to the formal documentation that is installed by GCC,
425 there are several other text files with miscellaneous documentation:
426
427 @table @file
428 @item ABOUT-GCC-NLS
429 Notes on GCC's Native Language Support.  FIXME: this should be part of
430 this manual rather than a separate file.
431 @item ABOUT-NLS
432 Notes on the Free Translation Project.
433 @item COPYING
434 The GNU General Public License.
435 @item COPYING.LIB
436 The GNU Lesser General Public License.
437 @item *ChangeLog*
438 @itemx */ChangeLog*
439 Change log files for various parts of GCC@.
440 @item LANGUAGES
441 Details of a few changes to the GCC front-end interface.  FIXME: the
442 information in this file should be part of general documentation of
443 the front-end interface in this manual.
444 @item ONEWS
445 Information about new features in old versions of GCC@.  (For recent
446 versions, the information is on the GCC web site.)
447 @item README.Portability
448 Information about portability issues when writing code in GCC@.  FIXME:
449 why isn't this part of this manual or of the GCC Coding Conventions?
450 @end table
451
452 FIXME: document such files in subdirectories, at least @file{config},
453 @file{cp}, @file{objc}, @file{testsuite}.
454
455 @node Front End
456 @subsection Anatomy of a Language Front End
457
458 A front end for a language in GCC has the following parts:
459
460 @itemize @bullet
461 @item
462 A directory @file{@var{language}} under @file{gcc} containing source
463 files for that front end.  @xref{Front End Directory, , The Front End
464 @file{@var{language}} Directory}, for details.
465 @item
466 A mention of the language in the list of supported languages in
467 @file{gcc/doc/install.texi}.
468 @item
469 A mention of the name under which the language's runtime library is
470 recognized by @option{--enable-shared=@var{package}} in the
471 documentation of that option in @file{gcc/doc/install.texi}.
472 @item
473 A mention of any special prerequisites for building the front end in
474 the documentation of prerequisites in @file{gcc/doc/install.texi}.
475 @item
476 Details of contributors to that front end in
477 @file{gcc/doc/contrib.texi}.  If the details are in that front end's
478 own manual then there should be a link to that manual's list in
479 @file{contrib.texi}.
480 @item
481 Information about support for that language in
482 @file{gcc/doc/frontends.texi}.
483 @item
484 Information about standards for that language, and the front end's
485 support for them, in @file{gcc/doc/standards.texi}.  This may be a
486 link to such information in the front end's own manual.
487 @item
488 Details of source file suffixes for that language and @option{-x
489 @var{lang}} options supported, in @file{gcc/doc/invoke.texi}.
490 @item
491 Entries in @code{default_compilers} in @file{gcc.c} for source file
492 suffixes for that language.
493 @item
494 Preferably testsuites, which may be under @file{gcc/testsuite} or
495 runtime library directories.  FIXME: document somewhere how to write
496 testsuite harnesses.
497 @item
498 Probably a runtime library for the language, outside the @file{gcc}
499 directory.  FIXME: document this further.
500 @item
501 Details of the directories of any runtime libraries in
502 @file{gcc/doc/sourcebuild.texi}.
503 @end itemize
504
505 If the front end is added to the official GCC source repository, the
506 following are also necessary:
507
508 @itemize @bullet
509 @item
510 At least one Bugzilla component for bugs in that front end and runtime
511 libraries.  This category needs to be mentioned in
512 @file{gcc/gccbug.in}, as well as being added to the Bugzilla database.
513 @item
514 Normally, one or more maintainers of that front end listed in
515 @file{MAINTAINERS}.
516 @item
517 Mentions on the GCC web site in @file{index.html} and
518 @file{frontends.html}, with any relevant links on
519 @file{readings.html}.  (Front ends that are not an official part of
520 GCC may also be listed on @file{frontends.html}, with relevant links.)
521 @item
522 A news item on @file{index.html}, and possibly an announcement on the
523 @email{gcc-announce@@gcc.gnu.org} mailing list.
524 @item
525 The front end's manuals should be mentioned in
526 @file{maintainer-scripts/update_web_docs} (@pxref{Texinfo Manuals})
527 and the online manuals should be linked to from
528 @file{onlinedocs/index.html}.
529 @item
530 Any old releases or CVS repositories of the front end, before its
531 inclusion in GCC, should be made available on the GCC FTP site
532 @uref{ftp://gcc.gnu.org/pub/gcc/old-releases/}.
533 @item
534 The release and snapshot script @file{maintainer-scripts/gcc_release}
535 should be updated to generate appropriate tarballs for this front end.
536 The associated @file{maintainer-scripts/snapshot-README} and
537 @file{maintainer-scripts/snapshot-index.html} files should be updated
538 to list the tarballs and diffs for this front end.
539 @item
540 If this front end includes its own version files that include the
541 current date, @file{maintainer-scripts/update_version} should be
542 updated accordingly.
543 @end itemize
544
545 @menu
546 * Front End Directory::  The front end @file{@var{language}} directory.
547 * Front End Config::     The front end @file{config-lang.in} file.
548 @end menu
549
550 @node Front End Directory
551 @subsubsection The Front End @file{@var{language}} Directory
552
553 A front end @file{@var{language}} directory contains the source files
554 of that front end (but not of any runtime libraries, which should be
555 outside the @file{gcc} directory).  This includes documentation, and
556 possibly some subsidiary programs build alongside the front end.
557 Certain files are special and other parts of the compiler depend on
558 their names:
559
560 @table @file
561 @item config-lang.in
562 This file is required in all language subdirectories.  @xref{Front End
563 Config, , The Front End @file{config-lang.in} File}, for details of
564 its contents
565 @item Make-lang.in
566 This file is required in all language subdirectories.  It contains
567 targets @code{@var{lang}.@var{hook}} (where @code{@var{lang}} is the
568 setting of @code{language} in @file{config-lang.in}) for the following
569 values of @code{@var{hook}}, and any other Makefile rules required to
570 build those targets (which may if necessary use other Makefiles
571 specified in @code{outputs} in @file{config-lang.in}, although this is
572 deprecated).  It also adds any testsuite targets that can use the
573 standard rule in @file{gcc/Makefile.in} to the variable
574 @code{lang_checks}.
575
576 @table @code
577 @itemx all.cross
578 @itemx start.encap
579 @itemx rest.encap
580 FIXME: exactly what goes in each of these targets?
581 @item tags
582 Build an @command{etags} @file{TAGS} file in the language subdirectory
583 in the source tree.
584 @item info
585 Build info documentation for the front end, in the build directory.
586 This target is only called by @samp{make bootstrap} if a suitable
587 version of @command{makeinfo} is available, so does not need to check
588 for this, and should fail if an error occurs.
589 @item dvi
590 Build DVI documentation for the front end, in the build directory.
591 This should be done using @code{$(TEXI2DVI)}, with appropriate
592 @option{-I} arguments pointing to directories of included files.
593 @item pdf
594 Build PDF documentation for the front end, in the build directory.
595 This should be done using @code{$(TEXI2PDF)}, with appropriate
596 @option{-I} arguments pointing to directories of included files.
597 @item html
598 Build HTML documentation for the front end, in the build directory.
599 @item man
600 Build generated man pages for the front end from Texinfo manuals
601 (@pxref{Man Page Generation}), in the build directory.  This target
602 is only called if the necessary tools are available, but should ignore
603 errors so as not to stop the build if errors occur; man pages are
604 optional and the tools involved may be installed in a broken way.
605 @item install-common
606 Install everything that is part of the front end, apart from the
607 compiler executables listed in @code{compilers} in
608 @file{config-lang.in}.
609 @item install-info
610 Install info documentation for the front end, if it is present in the
611 source directory.  This target should have dependencies on info files
612 that should be installed.
613 @item install-man
614 Install man pages for the front end.  This target should ignore
615 errors.
616 @item srcextra
617 Copies its dependencies into the source directory.  This generally should
618 be used for generated files such as Bison output files which are not
619 present in CVS, but should be included in any release tarballs.  This
620 target will be executed during a bootstrap if
621 @samp{--enable-generated-files-in-srcdir} was specified as a
622 @file{configure} option.
623 @item srcinfo
624 @itemx srcman
625 Copies its dependencies into the source directory.  These targets will be
626 executed during a bootstrap if @samp{--enable-generated-files-in-srcdir}
627 was specified as a @file{configure} option.
628 @item uninstall
629 Uninstall files installed by installing the compiler.  This is
630 currently documented not to be supported, so the hook need not do
631 anything.
632 @item mostlyclean
633 @itemx clean
634 @itemx distclean
635 @itemx maintainer-clean
636 The language parts of the standard GNU
637 @samp{*clean} targets.  @xref{Standard Targets, , Standard Targets for
638 Users, standards, GNU Coding Standards}, for details of the standard
639 targets.  For GCC, @code{maintainer-clean} should delete
640 all generated files in the source directory that are not checked into
641 CVS, but should not delete anything checked into CVS@.
642 @end table
643
644 @file{Make-lang.in} must also define a variable @code{@var{lang}_OBJS}
645 to a list of host object files that are used by that language.
646
647 @item lang.opt
648 This file registers the set of switches that the front end accepts on
649 the command line, and their @option{--help} text.  @xref{Options}.
650 @item lang-specs.h
651 This file provides entries for @code{default_compilers} in
652 @file{gcc.c} which override the default of giving an error that a
653 compiler for that language is not installed.
654 @item @var{language}-tree.def
655 This file, which need not exist, defines any language-specific tree
656 codes.
657 @end table
658
659 @node Front End Config
660 @subsubsection The Front End @file{config-lang.in} File
661
662 Each language subdirectory contains a @file{config-lang.in} file.  In
663 addition the main directory contains @file{c-config-lang.in}, which
664 contains limited information for the C language.  This file is a shell
665 script that may define some variables describing the language:
666
667 @table @code
668 @item language
669 This definition must be present, and gives the name of the language
670 for some purposes such as arguments to @option{--enable-languages}.
671 @item lang_requires
672 If defined, this variable lists (space-separated) language front ends
673 other than C that this front end requires to be enabled (with the
674 names given being their @code{language} settings).  For example, the
675 Java front end depends on the C++ front end, so sets
676 @samp{lang_requires=c++}.
677 @item subdir_requires
678 If defined, this variable lists (space-separated) front end directories
679 other than C that this front end requires to be present.  For example,
680 the Objective-C++ front end uses source files from the C++ and
681 Objective-C front ends, so sets @samp{subdir_requires="cp objc"}.
682 @item target_libs
683 If defined, this variable lists (space-separated) targets in the top
684 level @file{Makefile} to build the runtime libraries for this
685 language, such as @code{target-libobjc}.
686 @item lang_dirs
687 If defined, this variable lists (space-separated) top level
688 directories (parallel to @file{gcc}), apart from the runtime libraries,
689 that should not be configured if this front end is not built.
690 @item build_by_default
691 If defined to @samp{no}, this language front end is not built unless
692 enabled in a @option{--enable-languages} argument.  Otherwise, front
693 ends are built by default, subject to any special logic in
694 @file{configure.ac} (as is present to disable the Ada front end if the
695 Ada compiler is not already installed).
696 @item boot_language
697 If defined to @samp{yes}, this front end is built in stage 1 of the
698 bootstrap.  This is only relevant to front ends written in their own
699 languages.
700 @item compilers
701 If defined, a space-separated list of compiler executables that will
702 be run by the driver.  The names here will each end
703 with @samp{\$(exeext)}.
704 @item outputs
705 If defined, a space-separated list of files that should be generated
706 by @file{configure} substituting values in them.  This mechanism can
707 be used to create a file @file{@var{language}/Makefile} from
708 @file{@var{language}/Makefile.in}, but this is deprecated, building
709 everything from the single @file{gcc/Makefile} is preferred.
710 @item gtfiles
711 If defined, a space-separated list of files that should be scanned by
712 gengtype.c to generate the garbage collection tables and routines for
713 this language.  This excludes the files that are common to all front
714 ends.  @xref{Type Information}.
715
716 @end table
717
718 @node Back End
719 @subsection Anatomy of a Target Back End
720
721 A back end for a target architecture in GCC has the following parts:
722
723 @itemize @bullet
724 @item
725 A directory @file{@var{machine}} under @file{gcc/config}, containing a
726 machine description @file{@var{machine}.md} file (@pxref{Machine Desc,
727 , Machine Descriptions}), header files @file{@var{machine}.h} and
728 @file{@var{machine}-protos.h} and a source file @file{@var{machine}.c}
729 (@pxref{Target Macros, , Target Description Macros and Functions}),
730 possibly a target Makefile fragment @file{t-@var{machine}}
731 (@pxref{Target Fragment, , The Target Makefile Fragment}), and maybe
732 some other files.  The names of these files may be changed from the
733 defaults given by explicit specifications in @file{config.gcc}.
734 @item
735 If necessary, a file @file{@var{machine}-modes.def} in the
736 @file{@var{machine}} directory, containing additional machine modes to
737 represent condition codes.  @xref{Condition Code}, for further details.
738 @item
739 An optional @file{@var{machine}.opt} file in the @file{@var{machine}}
740 directory, containing a list of target-specific options.  You can also
741 add other option files using the @code{extra_options} variable in
742 @file{config.gcc}.  @xref{Options}.
743 @item
744 Entries in @file{config.gcc} (@pxref{System Config, , The
745 @file{config.gcc} File}) for the systems with this target
746 architecture.
747 @item
748 Documentation in @file{gcc/doc/invoke.texi} for any command-line
749 options supported by this target (@pxref{Run-time Target, , Run-time
750 Target Specification}).  This means both entries in the summary table
751 of options and details of the individual options.
752 @item
753 Documentation in @file{gcc/doc/extend.texi} for any target-specific
754 attributes supported (@pxref{Target Attributes, , Defining
755 target-specific uses of @code{__attribute__}}), including where the
756 same attribute is already supported on some targets, which are
757 enumerated in the manual.
758 @item
759 Documentation in @file{gcc/doc/extend.texi} for any target-specific
760 pragmas supported.
761 @item
762 Documentation in @file{gcc/doc/extend.texi} of any target-specific
763 built-in functions supported.
764 @item
765 Documentation in @file{gcc/doc/extend.texi} of any target-specific
766 format checking styles supported.
767 @item
768 Documentation in @file{gcc/doc/md.texi} of any target-specific
769 constraint letters (@pxref{Machine Constraints, , Constraints for
770 Particular Machines}).
771 @item
772 A note in @file{gcc/doc/contrib.texi} under the person or people who
773 contributed the target support.
774 @item
775 Entries in @file{gcc/doc/install.texi} for all target triplets
776 supported with this target architecture, giving details of any special
777 notes about installation for this target, or saying that there are no
778 special notes if there are none.
779 @item
780 Possibly other support outside the @file{gcc} directory for runtime
781 libraries.  FIXME: reference docs for this.  The libstdc++ porting
782 manual needs to be installed as info for this to work, or to be a
783 chapter of this manual.
784 @end itemize
785
786 If the back end is added to the official GCC source repository, the
787 following are also necessary:
788
789 @itemize @bullet
790 @item
791 An entry for the target architecture in @file{readings.html} on the
792 GCC web site, with any relevant links.
793 @item
794 Details of the properties of the back end and target architecture in
795 @file{backends.html} on the GCC web site.
796 @item
797 A news item about the contribution of support for that target
798 architecture, in @file{index.html} on the GCC web site.
799 @item
800 Normally, one or more maintainers of that target listed in
801 @file{MAINTAINERS}.  Some existing architectures may be unmaintained,
802 but it would be unusual to add support for a target that does not have
803 a maintainer when support is added.
804 @end itemize
805
806 @node Testsuites
807 @section Testsuites
808
809 GCC contains several testsuites to help maintain compiler quality.
810 Most of the runtime libraries and language front ends in GCC have
811 testsuites.  Currently only the C language testsuites are documented
812 here; FIXME: document the others.
813
814 @menu
815 * Test Idioms::     Idioms used in testsuite code.
816 * Test Directives:: Directives used within DejaGnu tests.
817 * Ada Tests::       The Ada language testsuites.
818 * C Tests::         The C language testsuites.
819 * libgcj Tests::    The Java library testsuites.
820 * gcov Testing::    Support for testing gcov.
821 * profopt Testing:: Support for testing profile-directed optimizations.
822 * compat Testing::  Support for testing binary compatibility.
823 * Torture Tests::   Support for torture testing using multiple options.
824 @end menu
825
826 @node Test Idioms
827 @subsection Idioms Used in Testsuite Code
828
829 In general, C testcases have a trailing @file{-@var{n}.c}, starting
830 with @file{-1.c}, in case other testcases with similar names are added
831 later.  If the test is a test of some well-defined feature, it should
832 have a name referring to that feature such as
833 @file{@var{feature}-1.c}.  If it does not test a well-defined feature
834 but just happens to exercise a bug somewhere in the compiler, and a
835 bug report has been filed for this bug in the GCC bug database,
836 @file{pr@var{bug-number}-1.c} is the appropriate form of name.
837 Otherwise (for miscellaneous bugs not filed in the GCC bug database),
838 and previously more generally, test cases are named after the date on
839 which they were added.  This allows people to tell at a glance whether
840 a test failure is because of a recently found bug that has not yet
841 been fixed, or whether it may be a regression, but does not give any
842 other information about the bug or where discussion of it may be
843 found.  Some other language testsuites follow similar conventions.
844
845 In the @file{gcc.dg} testsuite, it is often necessary to test that an
846 error is indeed a hard error and not just a warning---for example,
847 where it is a constraint violation in the C standard, which must
848 become an error with @option{-pedantic-errors}.  The following idiom,
849 where the first line shown is line @var{line} of the file and the line
850 that generates the error, is used for this:
851
852 @smallexample
853 /* @{ dg-bogus "warning" "warning in place of error" @} */
854 /* @{ dg-error "@var{regexp}" "@var{message}" @{ target *-*-* @} @var{line} @} */
855 @end smallexample
856
857 It may be necessary to check that an expression is an integer constant
858 expression and has a certain value.  To check that @code{@var{E}} has
859 value @code{@var{V}}, an idiom similar to the following is used:
860
861 @smallexample
862 char x[((E) == (V) ? 1 : -1)];
863 @end smallexample
864
865 In @file{gcc.dg} tests, @code{__typeof__} is sometimes used to make
866 assertions about the types of expressions.  See, for example,
867 @file{gcc.dg/c99-condexpr-1.c}.  The more subtle uses depend on the
868 exact rules for the types of conditional expressions in the C
869 standard; see, for example, @file{gcc.dg/c99-intconst-1.c}.
870
871 It is useful to be able to test that optimizations are being made
872 properly.  This cannot be done in all cases, but it can be done where
873 the optimization will lead to code being optimized away (for example,
874 where flow analysis or alias analysis should show that certain code
875 cannot be called) or to functions not being called because they have
876 been expanded as built-in functions.  Such tests go in
877 @file{gcc.c-torture/execute}.  Where code should be optimized away, a
878 call to a nonexistent function such as @code{link_failure ()} may be
879 inserted; a definition
880
881 @smallexample
882 #ifndef __OPTIMIZE__
883 void
884 link_failure (void)
885 @{
886   abort ();
887 @}
888 #endif
889 @end smallexample
890
891 @noindent
892 will also be needed so that linking still succeeds when the test is
893 run without optimization.  When all calls to a built-in function
894 should have been optimized and no calls to the non-built-in version of
895 the function should remain, that function may be defined as
896 @code{static} to call @code{abort ()} (although redeclaring a function
897 as static may not work on all targets).
898
899 All testcases must be portable.  Target-specific testcases must have
900 appropriate code to avoid causing failures on unsupported systems;
901 unfortunately, the mechanisms for this differ by directory.
902
903 FIXME: discuss non-C testsuites here.
904
905 @node Test Directives
906 @subsection Directives used within DejaGnu tests
907
908 Test directives appear within comments in a test source file and begin
909 with @code{dg-}.  Some of these are defined within DejaGnu and others
910 are local to the GCC testsuite.
911
912 The order in which test directives appear in a test can be important:
913 directives local to GCC sometimes override information used by the
914 DejaGnu directives, which know nothing about the GCC directives, so the
915 DejaGnu directives must precede GCC directives.
916
917 Several test directives include selectors which are usually preceded by
918 the keyword @code{target} or @code{xfail}.  A selector is: one or more
919 target triplets, possibly including wildcard characters; a single
920 effective-target keyword; or a logical expression.  Depending on the
921 context, the selector specifies whether a test is skipped and reported
922 as unsupported or is expected to fail.  Use @samp{*-*-*} to match any
923 target.
924 Effective-target keywords are defined in @file{target-supports.exp} in
925 the GCC testsuite.
926
927 A selector expression appears within curly braces and uses a single
928 logical operator: one of @samp{!}, @samp{&&}, or @samp{||}.  An
929 operand is another selector expression, an effective-target keyword,
930 a single target triplet, or a list of target triplets within quotes or
931 curly braces.  For example:
932
933 @smallexample
934 @{ target @{ ! "hppa*-*-* ia64*-*-*" @} @}
935 @{ target @{ powerpc*-*-* && lp64 @} @}
936 @{ xfail @{ lp64 || vect_no_align @} @}
937 @end smallexample
938
939 @table @code
940 @item @{ dg-do @var{do-what-keyword} [@{ target/xfail @var{selector} @}] @}
941 @var{do-what-keyword} specifies how the test is compiled and whether
942 it is executed.  It is one of:
943
944 @table @code
945 @item preprocess
946 Compile with @option{-E} to run only the preprocessor.
947 @item compile
948 Compile with @option{-S} to produce an assembly code file.
949 @item assemble
950 Compile with @option{-c} to produce a relocatable object file.
951 @item link
952 Compile, assemble, and link to produce an executable file.
953 @item run
954 Produce and run an executable file, which is expected to return
955 an exit code of 0.
956 @end table
957
958 The default is @code{compile}.  That can be overridden for a set of
959 tests by redefining @code{dg-do-what-default} within the @code{.exp}
960 file for those tests.
961
962 If the directive includes the optional @samp{@{ target @var{selector} @}}
963 then the test is skipped unless the target system is included in the
964 list of target triplets or matches the effective-target keyword.
965
966 If @samp{do-what-keyword} is @code{run} and the directive includes
967 the optional @samp{@{ xfail @var{selector} @}} and the selector is met
968 then the test is expected to fail.  The @code{xfail} clause is ignored
969 for other values of @samp{do-what-keyword}; those tests can use
970 directive @code{dg-xfail-if}.
971
972 @item @{ dg-options @var{options} [@{ target @var{selector} @}] @}
973 This DejaGnu directive provides a list of compiler options, to be used
974 if the target system matches @var{selector}, that replace the default
975 options used for this set of tests.
976
977 @item @{ dg-add-options @var{feature} @dots{} @}
978 Add any compiler options that are needed to access certain features.
979 This directive does nothing on targets that enable the features by
980 default, or that don't provide them at all.  It must come after
981 all @code{dg-options} directives.
982
983 The supported values of @var{feature} are:
984 @table @code
985 @item c99_runtime
986 The target's C99 runtime (both headers and libraries).
987
988 @item mips16_attribute
989 @code{mips16} function attributes.  Only MIPS targets support this feature,
990 and only then in certain modes.
991 @end table
992
993 @item @{ dg-timeout @var{n} [@{target @var{selector} @}] @}
994 Set the time limit for the compilation and for the execution of the test
995 to the specified number of seconds.
996
997 @item @{ dg-timeout-factor @var{x} [@{ target @var{selector} @}] @}
998 Multiply the normal time limit for compilation and execution of the test
999 by the specified floating-point factor.  The normal timeout limit, in
1000 seconds, is found by searching the following in order:
1001
1002 @itemize @bullet
1003 @item the value defined by an earlier @code{dg-timeout} directive in
1004 the test
1005
1006 @item variable @var{tool_timeout} defined by the set of tests
1007
1008 @item @var{gcc},@var{timeout} set in the target board
1009
1010 @item 300
1011 @end itemize
1012
1013 @item @{ dg-skip-if @var{comment} @{ @var{selector} @} @{ @var{include-opts} @} @{ @var{exclude-opts} @} @}
1014 Skip the test if the test system is included in @var{selector} and if
1015 each of the options in @var{include-opts} is in the set of options with
1016 which the test would be compiled and if none of the options in
1017 @var{exclude-opts} is in the set of options with which the test would be
1018 compiled.
1019
1020 Use @samp{"*"} for an empty @var{include-opts} list and @samp{""} for
1021 an empty @var{exclude-opts} list.
1022
1023 @item  @{ dg-xfail-if @var{comment} @{ @var{selector} @} @{ @var{include-opts} @} @{ @var{exclude-opts} @} @}
1024 Expect the test to fail if the conditions (which are the same as for
1025 @code{dg-skip-if}) are met.  This does not affect the execute step.
1026
1027 @item  @{ dg-xfail-run-if @var{comment} @{ @var{selector} @} @{ @var{include-opts} @} @{ @var{exclude-opts} @} @}
1028 Expect the execute step of a test to fail if the conditions (which are
1029 the same as for @code{dg-skip-if}) and @code{dg-xfail-if}) are met.
1030
1031 @item @{ dg-require-@var{support} args @}
1032 Skip the test if the target does not provide the required support;
1033 see @file{gcc-dg.exp} in the GCC testsuite for the actual directives.
1034 These directives must appear after any @code{dg-do} directive in the test
1035 and before any @code{dg-additional-sources} directive.
1036 They require at least one argument, which can be an empty string if the
1037 specific procedure does not examine the argument.
1038
1039 @item @{ dg-require-effective-target @var{keyword} @}
1040 Skip the test if the test target, including current multilib flags,
1041 is not covered by the effective-target keyword.
1042 This directive must appear after any @code{dg-do} directive in the test
1043 and before any @code{dg-additional-sources} directive.
1044
1045 @item  @{ dg-shouldfail @var{comment} @{ @var{selector} @} @{ @var{include-opts} @} @{ @var{exclude-opts} @} @}
1046 Expect the test executable to return a nonzero exit status if the
1047 conditions (which are the same as for @code{dg-skip-if}) are met.
1048
1049 @item @{ dg-error @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1050 This DejaGnu directive appears on a source line that is expected to get
1051 an error message, or else specifies the source line associated with the
1052 message.  If there is no message for that line or if the text of that
1053 message is not matched by @var{regexp} then the check fails and
1054 @var{comment} is included in the @code{FAIL} message.  The check does
1055 not look for the string @samp{"error"} unless it is part of @var{regexp}.
1056
1057 @item @{ dg-warning @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1058 This DejaGnu directive appears on a source line that is expected to get
1059 a warning message, or else specifies the source line associated with the
1060 message.  If there is no message for that line or if the text of that
1061 message is not matched by @var{regexp} then the check fails and
1062 @var{comment} is included in the @code{FAIL} message.  The check does
1063 not look for the string @samp{"warning"} unless it is part of @var{regexp}.
1064
1065 @item @{ dg-message @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1066 The line is expected to get a message other than an error or warning.
1067 If there is no message for that line or if the text of that message is
1068 not matched by @var{regexp} then the check fails and @var{comment} is
1069 included in the @code{FAIL} message.
1070
1071 @item @{ dg-bogus @var{regexp} [@var{comment} [@{ target/xfail @var{selector} @} [@var{line}] @}]] @}
1072 This DejaGnu directive appears on a source line that should not get a
1073 message matching @var{regexp}, or else specifies the source line
1074 associated with the bogus message.  It is usually used with @samp{xfail}
1075 to indicate that the message is a known problem for a particular set of
1076 targets.
1077
1078 @item @{ dg-excess-errors @var{comment} [@{ target/xfail @var{selector} @}] @}
1079 This DejaGnu directive indicates that the test is expected to fail due
1080 to compiler messages that are not handled by @samp{dg-error},
1081 @samp{dg-warning} or @samp{dg-bogus}.  For this directive @samp{xfail}
1082 has the same effect as @samp{target}.
1083
1084 @item @{ dg-output @var{regexp} [@{ target/xfail @var{selector} @}] @}
1085 This DejaGnu directive compares @var{regexp} to the combined output
1086 that the test executable writes to @file{stdout} and @file{stderr}.
1087
1088 @item @{ dg-prune-output @var{regexp} @}
1089 Prune messages matching @var{regexp} from test output.
1090
1091 @item @{ dg-additional-files "@var{filelist}" @}
1092 Specify additional files, other than source files, that must be copied
1093 to the system where the compiler runs.
1094
1095 @item @{ dg-additional-sources "@var{filelist}" @}
1096 Specify additional source files to appear in the compile line
1097 following the main test file.
1098
1099 @item @{ dg-final @{ @var{local-directive} @} @}
1100 This DejaGnu directive is placed within a comment anywhere in the
1101 source file and is processed after the test has been compiled and run.
1102 Multiple @samp{dg-final} commands are processed in the order in which
1103 they appear in the source file.
1104
1105 The GCC testsuite defines the following directives to be used within
1106 @code{dg-final}.
1107
1108 @table @code
1109 @item cleanup-coverage-files
1110 Removes coverage data files generated for this test.
1111
1112 @item cleanup-repo-files
1113 Removes files generated for this test for @option{-frepo}.
1114
1115 @item cleanup-rtl-dump @var{suffix}
1116 Removes RTL dump files generated for this test.
1117
1118 @item cleanup-tree-dump @var{suffix}
1119 Removes tree dump files matching @var{suffix} which were generated for
1120 this test.
1121
1122 @item cleanup-saved-temps
1123 Removes files for the current test which were kept for @option{--save-temps}.
1124
1125 @item scan-file @var{filename} @var{regexp} [@{ target/xfail @var{selector} @}]
1126 Passes if @var{regexp} matches text in @var{filename}.
1127
1128 @item scan-file-not @var{filename} @var{regexp} [@{ target/xfail @var{selector} @}]
1129 Passes if @var{regexp} does not match text in @var{filename}.
1130
1131 @item scan-hidden @var{symbol} [@{ target/xfail @var{selector} @}]
1132 Passes if @var{symbol} is defined as a hidden symbol in the test's
1133 assembly output.
1134
1135 @item scan-not-hidden @var{symbol} [@{ target/xfail @var{selector} @}]
1136 Passes if @var{symbol} is not defined as a hidden symbol in the test's
1137 assembly output.
1138
1139 @item scan-assembler-times @var{regex} @var{num} [@{ target/xfail @var{selector} @}]
1140 Passes if @var{regex} is matched exactly @var{num} times in the test's
1141 assembler output.
1142
1143 @item scan-assembler @var{regex} [@{ target/xfail @var{selector} @}]
1144 Passes if @var{regex} matches text in the test's assembler output.
1145
1146 @item scan-assembler-not @var{regex} [@{ target/xfail @var{selector} @}]
1147 Passes if @var{regex} does not match text in the test's assembler output.
1148
1149 @item scan-assembler-dem @var{regex} [@{ target/xfail @var{selector} @}]
1150 Passes if @var{regex} matches text in the test's demangled assembler output.
1151
1152 @item scan-assembler-dem-not @var{regex} [@{ target/xfail @var{selector} @}]
1153 Passes if @var{regex} does not match text in the test's demangled assembler
1154 output.
1155
1156 @item scan-tree-dump-times @var{regex} @var{num} @var{suffix} [@{ target/xfail @var{selector} @}]
1157 Passes if @var{regex} is found exactly @var{num} times in the dump file
1158 with suffix @var{suffix}.
1159
1160 @item scan-tree-dump @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
1161 Passes if @var{regex} matches text in the dump file with suffix @var{suffix}.
1162
1163 @item scan-tree-dump-not @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
1164 Passes if @var{regex} does not match text in the dump file with suffix
1165 @var{suffix}.
1166
1167 @item scan-tree-dump-dem @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
1168 Passes if @var{regex} matches demangled text in the dump file with
1169 suffix @var{suffix}.
1170
1171 @item scan-tree-dump-dem-not @var{regex} @var{suffix} [@{ target/xfail @var{selector} @}]
1172 Passes if @var{regex} does not match demangled text in the dump file with
1173 suffix @var{suffix}.
1174
1175 @item output-exists [@{ target/xfail @var{selector} @}]
1176 Passes if compiler output file exists.
1177
1178 @item output-exists-not [@{ target/xfail @var{selector} @}]
1179 Passes if compiler output file does not exist.
1180
1181 @item run-gcov @var{sourcefile}
1182 Check line counts in @command{gcov} tests.
1183
1184 @item run-gcov [branches] [calls] @{ @var{opts} @var{sourcefile} @}
1185 Check branch and/or call counts, in addition to line counts, in
1186 @command{gcov} tests.
1187 @end table
1188 @end table
1189
1190 @node Ada Tests
1191 @subsection Ada Language Testsuites
1192
1193 The Ada testsuite includes executable tests from the ACATS 2.5
1194 testsuite, publicly available at
1195 @uref{http://www.adaic.org/compilers/acats/2.5}
1196
1197 These tests are integrated in the GCC testsuite in the
1198 @file{gcc/testsuite/ada/acats} directory, and
1199 enabled automatically when running @code{make check}, assuming
1200 the Ada language has been enabled when configuring GCC@.
1201
1202 You can also run the Ada testsuite independently, using
1203 @code{make check-ada}, or run a subset of the tests by specifying which
1204 chapter to run, e.g.:
1205
1206 @smallexample
1207 $ make check-ada CHAPTERS="c3 c9"
1208 @end smallexample
1209
1210 The tests are organized by directory, each directory corresponding to
1211 a chapter of the Ada Reference Manual.  So for example, c9 corresponds
1212 to chapter 9, which deals with tasking features of the language.
1213
1214 There is also an extra chapter called @file{gcc} containing a template for
1215 creating new executable tests.
1216
1217 The tests are run using two @command{sh} scripts: @file{run_acats} and
1218 @file{run_all.sh}.  To run the tests using a simulator or a cross
1219 target, see the small
1220 customization section at the top of @file{run_all.sh}.
1221
1222 These tests are run using the build tree: they can be run without doing
1223 a @code{make install}.
1224
1225 @node C Tests
1226 @subsection C Language Testsuites
1227
1228 GCC contains the following C language testsuites, in the
1229 @file{gcc/testsuite} directory:
1230
1231 @table @file
1232 @item gcc.dg
1233 This contains tests of particular features of the C compiler, using the
1234 more modern @samp{dg} harness.  Correctness tests for various compiler
1235 features should go here if possible.
1236
1237 Magic comments determine whether the file
1238 is preprocessed, compiled, linked or run.  In these tests, error and warning
1239 message texts are compared against expected texts or regular expressions
1240 given in comments.  These tests are run with the options @samp{-ansi -pedantic}
1241 unless other options are given in the test.  Except as noted below they
1242 are not run with multiple optimization options.
1243 @item gcc.dg/compat
1244 This subdirectory contains tests for binary compatibility using
1245 @file{compat.exp}, which in turn uses the language-independent support
1246 (@pxref{compat Testing, , Support for testing binary compatibility}).
1247 @item gcc.dg/cpp
1248 This subdirectory contains tests of the preprocessor.
1249 @item gcc.dg/debug
1250 This subdirectory contains tests for debug formats.  Tests in this
1251 subdirectory are run for each debug format that the compiler supports.
1252 @item gcc.dg/format
1253 This subdirectory contains tests of the @option{-Wformat} format
1254 checking.  Tests in this directory are run with and without
1255 @option{-DWIDE}.
1256 @item gcc.dg/noncompile
1257 This subdirectory contains tests of code that should not compile and
1258 does not need any special compilation options.  They are run with
1259 multiple optimization options, since sometimes invalid code crashes
1260 the compiler with optimization.
1261 @item gcc.dg/special
1262 FIXME: describe this.
1263
1264 @item gcc.c-torture
1265 This contains particular code fragments which have historically broken easily.
1266 These tests are run with multiple optimization options, so tests for features
1267 which only break at some optimization levels belong here.  This also contains
1268 tests to check that certain optimizations occur.  It might be worthwhile to
1269 separate the correctness tests cleanly from the code quality tests, but
1270 it hasn't been done yet.
1271
1272 @item gcc.c-torture/compat
1273 FIXME: describe this.
1274
1275 This directory should probably not be used for new tests.
1276 @item gcc.c-torture/compile
1277 This testsuite contains test cases that should compile, but do not
1278 need to link or run.  These test cases are compiled with several
1279 different combinations of optimization options.  All warnings are
1280 disabled for these test cases, so this directory is not suitable if
1281 you wish to test for the presence or absence of compiler warnings.
1282 While special options can be set, and tests disabled on specific
1283 platforms, by the use of @file{.x} files, mostly these test cases
1284 should not contain platform dependencies.  FIXME: discuss how defines
1285 such as @code{NO_LABEL_VALUES} and @code{STACK_SIZE} are used.
1286 @item gcc.c-torture/execute
1287 This testsuite contains test cases that should compile, link and run;
1288 otherwise the same comments as for @file{gcc.c-torture/compile} apply.
1289 @item gcc.c-torture/execute/ieee
1290 This contains tests which are specific to IEEE floating point.
1291 @item gcc.c-torture/unsorted
1292 FIXME: describe this.
1293
1294 This directory should probably not be used for new tests.
1295 @item gcc.c-torture/misc-tests
1296 This directory contains C tests that require special handling.  Some
1297 of these tests have individual expect files, and others share
1298 special-purpose expect files:
1299
1300 @table @file
1301 @item @code{bprob*.c}
1302 Test @option{-fbranch-probabilities} using @file{bprob.exp}, which
1303 in turn uses the generic, language-independent framework
1304 (@pxref{profopt Testing, , Support for testing profile-directed
1305 optimizations}).
1306
1307 @item @code{dg-*.c}
1308 Test the testsuite itself using @file{dg-test.exp}.
1309
1310 @item @code{gcov*.c}
1311 Test @command{gcov} output using @file{gcov.exp}, which in turn uses the
1312 language-independent support (@pxref{gcov Testing, , Support for testing gcov}).
1313
1314 @item @code{i386-pf-*.c}
1315 Test i386-specific support for data prefetch using @file{i386-prefetch.exp}.
1316 @end table
1317
1318 @end table
1319
1320 FIXME: merge in @file{testsuite/README.gcc} and discuss the format of
1321 test cases and magic comments more.
1322
1323 @node libgcj Tests
1324 @subsection The Java library testsuites.
1325
1326 Runtime tests are executed via @samp{make check} in the
1327 @file{@var{target}/libjava/testsuite} directory in the build
1328 tree.  Additional runtime tests can be checked into this testsuite.
1329
1330 Regression testing of the core packages in libgcj is also covered by the
1331 Mauve testsuite.  The @uref{http://sourceware.org/mauve/,,Mauve Project}
1332 develops tests for the Java Class Libraries.  These tests are run as part
1333 of libgcj testing by placing the Mauve tree within the libjava testsuite
1334 sources at @file{libjava/testsuite/libjava.mauve/mauve}, or by specifying
1335 the location of that tree when invoking @samp{make}, as in
1336 @samp{make MAUVEDIR=~/mauve check}.
1337
1338 To detect regressions, a mechanism in @file{mauve.exp} compares the
1339 failures for a test run against the list of expected failures in
1340 @file{libjava/testsuite/libjava.mauve/xfails} from the source hierarchy.
1341 Update this file when adding new failing tests to Mauve, or when fixing
1342 bugs in libgcj that had caused Mauve test failures.
1343
1344 We encourage developers to contribute test cases to Mauve.
1345
1346 @node gcov Testing
1347 @subsection Support for testing @command{gcov}
1348
1349 Language-independent support for testing @command{gcov}, and for checking
1350 that branch profiling produces expected values, is provided by the
1351 expect file @file{gcov.exp}.  @command{gcov} tests also rely on procedures
1352 in @file{gcc.dg.exp} to compile and run the test program.  A typical
1353 @command{gcov} test contains the following DejaGnu commands within comments:
1354
1355 @smallexample
1356 @{ dg-options "-fprofile-arcs -ftest-coverage" @}
1357 @{ dg-do run @{ target native @} @}
1358 @{ dg-final @{ run-gcov sourcefile @} @}
1359 @end smallexample
1360
1361 Checks of @command{gcov} output can include line counts, branch percentages,
1362 and call return percentages.  All of these checks are requested via
1363 commands that appear in comments in the test's source file.
1364 Commands to check line counts are processed by default.
1365 Commands to check branch percentages and call return percentages are
1366 processed if the @command{run-gcov} command has arguments @code{branches}
1367 or @code{calls}, respectively.  For example, the following specifies
1368 checking both, as well as passing @option{-b} to @command{gcov}:
1369
1370 @smallexample
1371 @{ dg-final @{ run-gcov branches calls @{ -b sourcefile @} @} @}
1372 @end smallexample
1373
1374 A line count command appears within a comment on the source line
1375 that is expected to get the specified count and has the form
1376 @code{count(@var{cnt})}.  A test should only check line counts for
1377 lines that will get the same count for any architecture.
1378
1379 Commands to check branch percentages (@code{branch}) and call
1380 return percentages (@code{returns}) are very similar to each other.
1381 A beginning command appears on or before the first of a range of
1382 lines that will report the percentage, and the ending command
1383 follows that range of lines.  The beginning command can include a
1384 list of percentages, all of which are expected to be found within
1385 the range.  A range is terminated by the next command of the same
1386 kind.  A command @code{branch(end)} or @code{returns(end)} marks
1387 the end of a range without starting a new one.  For example:
1388
1389 @smallexample
1390 if (i > 10 && j > i && j < 20)  /* @r{branch(27 50 75)} */
1391                                 /* @r{branch(end)} */
1392   foo (i, j);
1393 @end smallexample
1394
1395 For a call return percentage, the value specified is the
1396 percentage of calls reported to return.  For a branch percentage,
1397 the value is either the expected percentage or 100 minus that
1398 value, since the direction of a branch can differ depending on the
1399 target or the optimization level.
1400
1401 Not all branches and calls need to be checked.  A test should not
1402 check for branches that might be optimized away or replaced with
1403 predicated instructions.  Don't check for calls inserted by the
1404 compiler or ones that might be inlined or optimized away.
1405
1406 A single test can check for combinations of line counts, branch
1407 percentages, and call return percentages.  The command to check a
1408 line count must appear on the line that will report that count, but
1409 commands to check branch percentages and call return percentages can
1410 bracket the lines that report them.
1411
1412 @node profopt Testing
1413 @subsection Support for testing profile-directed optimizations
1414
1415 The file @file{profopt.exp} provides language-independent support for
1416 checking correct execution of a test built with profile-directed
1417 optimization.  This testing requires that a test program be built and
1418 executed twice.  The first time it is compiled to generate profile
1419 data, and the second time it is compiled to use the data that was
1420 generated during the first execution.  The second execution is to
1421 verify that the test produces the expected results.
1422
1423 To check that the optimization actually generated better code, a
1424 test can be built and run a third time with normal optimizations to
1425 verify that the performance is better with the profile-directed
1426 optimizations.  @file{profopt.exp} has the beginnings of this kind
1427 of support.
1428
1429 @file{profopt.exp} provides generic support for profile-directed
1430 optimizations.  Each set of tests that uses it provides information
1431 about a specific optimization:
1432
1433 @table @code
1434 @item tool
1435 tool being tested, e.g., @command{gcc}
1436
1437 @item profile_option
1438 options used to generate profile data
1439
1440 @item feedback_option
1441 options used to optimize using that profile data
1442
1443 @item prof_ext
1444 suffix of profile data files
1445
1446 @item PROFOPT_OPTIONS
1447 list of options with which to run each test, similar to the lists for
1448 torture tests
1449 @end table
1450
1451 @node compat Testing
1452 @subsection Support for testing binary compatibility
1453
1454 The file @file{compat.exp} provides language-independent support for
1455 binary compatibility testing.  It supports testing interoperability of
1456 two compilers that follow the same ABI, or of multiple sets of
1457 compiler options that should not affect binary compatibility.  It is
1458 intended to be used for testsuites that complement ABI testsuites.
1459
1460 A test supported by this framework has three parts, each in a
1461 separate source file: a main program and two pieces that interact
1462 with each other to split up the functionality being tested.
1463
1464 @table @file
1465 @item @var{testname}_main.@var{suffix}
1466 Contains the main program, which calls a function in file
1467 @file{@var{testname}_x.@var{suffix}}.
1468
1469 @item @var{testname}_x.@var{suffix}
1470 Contains at least one call to a function in
1471 @file{@var{testname}_y.@var{suffix}}.
1472
1473 @item @var{testname}_y.@var{suffix}
1474 Shares data with, or gets arguments from,
1475 @file{@var{testname}_x.@var{suffix}}.
1476 @end table
1477
1478 Within each test, the main program and one functional piece are
1479 compiled by the GCC under test.  The other piece can be compiled by
1480 an alternate compiler.  If no alternate compiler is specified,
1481 then all three source files are all compiled by the GCC under test.
1482 You can specify pairs of sets of compiler options.  The first element
1483 of such a pair specifies options used with the GCC under test, and the
1484 second element of the pair specifies options used with the alternate
1485 compiler.  Each test is compiled with each pair of options.
1486
1487 @file{compat.exp} defines default pairs of compiler options.
1488 These can be overridden by defining the environment variable
1489 @env{COMPAT_OPTIONS} as:
1490
1491 @smallexample
1492 COMPAT_OPTIONS="[list [list @{@var{tst1}@} @{@var{alt1}@}]
1493   @dots{}[list @{@var{tstn}@} @{@var{altn}@}]]"
1494 @end smallexample
1495
1496 where @var{tsti} and @var{alti} are lists of options, with @var{tsti}
1497 used by the compiler under test and @var{alti} used by the alternate
1498 compiler.  For example, with
1499 @code{[list [list @{-g -O0@} @{-O3@}] [list @{-fpic@} @{-fPIC -O2@}]]},
1500 the test is first built with @option{-g -O0} by the compiler under
1501 test and with @option{-O3} by the alternate compiler.  The test is
1502 built a second time using @option{-fpic} by the compiler under test
1503 and @option{-fPIC -O2} by the alternate compiler.
1504
1505 An alternate compiler is specified by defining an environment
1506 variable to be the full pathname of an installed compiler; for C
1507 define @env{ALT_CC_UNDER_TEST}, and for C++ define
1508 @env{ALT_CXX_UNDER_TEST}.  These will be written to the
1509 @file{site.exp} file used by DejaGnu.  The default is to build each
1510 test with the compiler under test using the first of each pair of
1511 compiler options from @env{COMPAT_OPTIONS}.  When
1512 @env{ALT_CC_UNDER_TEST} or
1513 @env{ALT_CXX_UNDER_TEST} is @code{same}, each test is built using
1514 the compiler under test but with combinations of the options from
1515 @env{COMPAT_OPTIONS}.
1516
1517 To run only the C++ compatibility suite using the compiler under test
1518 and another version of GCC using specific compiler options, do the
1519 following from @file{@var{objdir}/gcc}:
1520
1521 @smallexample
1522 rm site.exp
1523 make -k \
1524   ALT_CXX_UNDER_TEST=$@{alt_prefix@}/bin/g++ \
1525   COMPAT_OPTIONS="lists as shown above" \
1526   check-c++ \
1527   RUNTESTFLAGS="compat.exp"
1528 @end smallexample
1529
1530 A test that fails when the source files are compiled with different
1531 compilers, but passes when the files are compiled with the same
1532 compiler, demonstrates incompatibility of the generated code or
1533 runtime support.  A test that fails for the alternate compiler but
1534 passes for the compiler under test probably tests for a bug that was
1535 fixed in the compiler under test but is present in the alternate
1536 compiler.
1537
1538 The binary compatibility tests support a small number of test framework
1539 commands that appear within comments in a test file.
1540
1541 @table @code
1542 @item dg-require-*
1543 These commands can be used in @file{@var{testname}_main.@var{suffix}}
1544 to skip the test if specific support is not available on the target.
1545
1546 @item dg-options
1547 The specified options are used for compiling this particular source
1548 file, appended to the options from @env{COMPAT_OPTIONS}.  When this
1549 command appears in @file{@var{testname}_main.@var{suffix}} the options
1550 are also used to link the test program.
1551
1552 @item dg-xfail-if
1553 This command can be used in a secondary source file to specify that
1554 compilation is expected to fail for particular options on particular
1555 targets.
1556 @end table
1557
1558 @node Torture Tests
1559 @subsection Support for torture testing using multiple options
1560
1561 Throughout the compiler testsuite there are several directories whose
1562 tests are run multiple times, each with a different set of options.
1563 These are known as torture tests.
1564 @file{gcc/testsuite/lib/torture-options.exp} defines procedures to
1565 set up these lists:
1566
1567 @table @code
1568 @item torture-init
1569 Initialize use of torture lists.
1570 @item set-torture-options
1571 Set lists of torture options to use for tests with and without loops.
1572 Optionally combine a set of torture options with a set of other
1573 options, as is done with Objective-C runtime options.
1574 @item torture-finish
1575 Finalize use of torture lists.
1576 @end table
1577
1578 The @file{.exp} file for a set of tests that use torture options must
1579 include calls to these three procecures if:
1580
1581 @itemize @bullet
1582 @item It calls @code{gcc-dg-runtest} and overrides @var{DG_TORTURE_OPTIONS}.
1583
1584 @item It calls @var{$@{tool@}}@code{-torture} or
1585 @var{$@{tool@}}@code{-torture-execute}, where @var{tool} is @code{c},
1586 @code{fortran}, or @code{objc}.
1587
1588 @item It calls @code{dg-pch}.
1589 @end itemize
1590
1591 It is not necessary for a @file{.exp} file that calls @code{gcc-dg-runtest}
1592 to call the torture procedures if the tests should use the list in
1593 @var{DG_TORTURE_OPTIONS} defined in @file{gcc-dg.exp}.
1594
1595 Most uses of torture options can override the default lists by defining
1596 @var{TORTURE_OPTIONS} or add to the default list by defining
1597 @var{ADDITIONAL_TORTURE_OPTIONS}.  Define these in a @file{.dejagnurc}
1598 file or add them to the @file{site.exp} file; for example
1599
1600 @smallexample
1601 set ADDITIONAL_TORTURE_OPTIONS  [list \
1602   @{ -O2 -ftree-loop-linear @} \
1603   @{ -O2 -fpeel-loops @} ]
1604 @end smallexample