OSDN Git Service

2001-08-27 Vladimir Makarov <vmakarov@touchme.toronto.redhat.com>
[pf3gnuchains/gcc-fork.git] / gcc / doc / gcc.texi
1 \input texinfo  @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename gcc.info
4 @c @setfilename usegcc.info
5 @c @setfilename portgcc.info
6 @c To produce the full manual, use the "gcc.info" setfilename, and
7 @c make sure the following do NOT begin with '@c' (and the @clear lines DO)
8 @set INTERNALS
9 @set USING
10 @c To produce a user-only manual, use the "usegcc.info" setfilename, and
11 @c make sure the following does NOT begin with '@c':
12 @c @clear INTERNALS
13 @c To produce a porter-only manual, use the "portgcc.info" setfilename,
14 @c and make sure the following does NOT begin with '@c':
15 @c @clear USING
16
17 @c (For FSF printing, turn on smallbook, comment out finalout below;
18 @c that is all that is needed.)
19
20 @c 6/27/96 FSF DO wants smallbook fmt for 1st bound edition.
21 @c @smallbook
22
23 @c i also commented out the finalout command, so if there *are* any
24 @c overfulls, you'll (hopefully) see the rectangle in the right hand
25 @c margin. -mew 15june93
26 @c @finalout
27
28 @c NOTE: checks/things to do:
29 @c
30 @c -have bob do a search in all seven files for "mew" (ideally --mew,
31 @c  but i may have forgotten the occasional "--"..).
32 @c     Just checked... all have `--'!  Bob 22Jul96
33 @c     Use this to search:   grep -n '\-\-mew' *.texi
34 @c -item/itemx, text after all (sub/sub)section titles, etc..
35 @c -consider putting the lists of options on pp 17--> etc in columns or
36 @c  some such.
37 @c -overfulls.  do a search for "mew" in the files, and you will see
38 @c   overfulls that i noted but could not deal with.
39 @c -have to add text:  beginning of chapter 8
40
41 @c
42 @c anything else?                       --mew 10feb93
43
44 @c For consistency, use the following:
45 @c - "back end" as a noun, "back-end" as an adjective.
46 @c - "bit-field" not "bitfield" or "bit field" (following the C and C++
47 @c   standards).
48 @c - "built-in" as an adjective ("built-in function"), or sometimes
49 @c   "built in", not "builtin" (which isn't a word).
50 @c - "front end" as a noun, "front-end" as an adjective.
51 @c - "GCC" for the GNU Compiler Collection, both generally
52 @c   and as the GNU C Compiler in the context of compiling C;
53 @c   "G++" for the C++ compiler; "gcc" and "g++" (lowercase),
54 @c   marked up with @command, for the commands for compilation when the
55 @c   emphasis is on those; "GNU C" and "GNU C++" for language dialects;
56 @c   and try to avoid the older term "GNU CC".
57
58 @macro gcctabopt{body}
59 @code{\body\}
60 @end macro
61 @macro gccoptlist{body}
62 @smallexample
63 \body\
64 @end smallexample
65 @end macro
66 @c Makeinfo handles the above macro OK, TeX needs manual line breaks;
67 @c they get lost at some point in handling the macro.  But if @macro is
68 @c used here rather than @alias, it produces double line breaks.
69 @iftex
70 @alias gol = *
71 @end iftex
72 @ifnottex
73 @macro gol
74 @end macro
75 @end ifnottex
76
77 @ifset INTERNALS
78 @ifset USING
79 @settitle Using and Porting the GNU Compiler Collection (GCC)
80 @end ifset
81 @end ifset
82 @c seems reasonable to assume at least one of INTERNALS or USING is set...
83 @ifclear INTERNALS
84 @settitle Using the GNU Compiler Collection
85 @end ifclear
86 @ifclear USING
87 @settitle Porting the GNU Compiler Collection
88 @end ifclear
89
90 @c Create a separate index for command line options.
91 @defcodeindex op
92 @c Merge the standard indexes into a single one.
93 @syncodeindex fn cp
94 @syncodeindex vr cp
95 @syncodeindex ky cp
96 @syncodeindex pg cp
97 @syncodeindex tp cp
98
99 @c %**end of header
100
101 @c Use with @@smallbook.
102
103 @c Cause even numbered pages to be printed on the left hand side of
104 @c the page and odd numbered pages to be printed on the right hand
105 @c side of the page.  Using this, you can print on both sides of a
106 @c sheet of paper and have the text on the same part of the sheet.
107
108 @c The text on right hand pages is pushed towards the right hand
109 @c margin and the text on left hand pages is pushed toward the left
110 @c hand margin.
111 @c (To provide the reverse effect, set bindingoffset to -0.75in.)
112
113 @c @tex
114 @c \global\bindingoffset=0.75in
115 @c \global\normaloffset =0.75in
116 @c @end tex
117
118 @c Change the font used for @def... commands, since the default
119 @c proportional one used is bad for names starting __.
120 @tex
121 \global\setfont\defbf\ttbshape{10}{\magstep1}
122 @end tex
123
124 @ifnottex
125 @dircategory Programming
126 @direntry
127 * gcc: (gcc).                  The GNU Compiler Collection.
128 @end direntry
129 @ifset INTERNALS
130 @ifset USING
131 This file documents the use and the internals of the GNU compiler.
132 @end ifset
133 @end ifset
134 @ifclear USING
135 This file documents the internals of the GNU compiler.
136 @end ifclear
137 @ifclear INTERNALS
138 This file documents the use of the GNU compiler.
139 @end ifclear
140 @sp 1
141 Published by the Free Software Foundation@*
142 59 Temple Place - Suite 330@*
143 Boston, MA 02111-1307 USA
144 @sp 1
145 @c When you update the list of years below, search for copyright{} and
146 @c update the other copy too.
147 Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
148 1999, 2000, 2001 Free Software Foundation, Inc.
149 @sp 1
150 Permission is granted to copy, distribute and/or modify this document
151 under the terms of the GNU Free Documentation License, Version 1.1 or
152 any later version published by the Free Software Foundation; with the
153 Invariant Sections being ``GNU General Public License'' and ``Funding
154 Free Software'', the Front-Cover texts being (a) (see below), and with
155 the Back-Cover Texts being (b) (see below).  A copy of the license is
156 included in the section entitled ``GNU Free Documentation License''.
157
158 (a) The FSF's Front-Cover Text is:
159
160      A GNU Manual
161
162 (b) The FSF's Back-Cover Text is:
163
164      You have freedom to copy and modify this GNU Manual, like GNU
165      software.  Copies published by the Free Software Foundation raise
166      funds for GNU development.
167 @end ifnottex
168
169 @setchapternewpage odd
170 @c @finalout
171 @titlepage
172 @ifset INTERNALS
173 @ifset USING
174 @center @titlefont{Using and Porting the GNU Compiler Collection}
175
176 @end ifset
177 @end ifset
178 @ifclear INTERNALS
179 @title Using the GNU Compiler Collection
180 @end ifclear
181 @ifclear USING
182 @title Porting the GNU Compiler Collection
183 @end ifclear
184 @sp 2
185 @center Richard M. Stallman
186 @sp 3
187 @center Last updated 22 June 2001
188 @sp 1
189 @c The version number appears five times more in this file.
190
191 @center for GCC 3.1
192 @page
193 @vskip 0pt plus 1filll
194 Copyright @copyright{} 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1998,
195 1999, 2000, 2001  Free Software Foundation, Inc.
196 @sp 2
197 For GCC Version 3.1@*
198 @sp 1
199 Published by the Free Software Foundation @*
200 59 Temple Place---Suite 330@*
201 Boston, MA 02111-1307, USA@*
202 Last printed April, 1998.@*
203 Printed copies are available for $50 each.@*
204 ISBN 1-882114-37-X
205 @sp 1
206 Permission is granted to copy, distribute and/or modify this document
207 under the terms of the GNU Free Documentation License, Version 1.1 or
208 any later version published by the Free Software Foundation; with the
209 Invariant Sections being ``GNU General Public License'', the Front-Cover
210 texts being (a) (see below), and with the Back-Cover Texts being (b)
211 (see below).  A copy of the license is included in the section entitled
212 ``GNU Free Documentation License''.
213
214 (a) The FSF's Front-Cover Text is:
215
216      A GNU Manual
217
218 (b) The FSF's Back-Cover Text is:
219
220      You have freedom to copy and modify this GNU Manual, like GNU
221      software.  Copies published by the Free Software Foundation raise
222      funds for GNU development.
223 @end titlepage
224 @summarycontents
225 @contents
226 @page
227
228 @node Top, G++ and GCC,, (DIR)
229 @top Introduction
230 @cindex introduction
231
232 @ifset INTERNALS
233 @ifset USING
234 This manual documents how to run, install and port the GNU
235 compiler, as well as its new features and incompatibilities, and how to
236 report bugs.  It corresponds to GCC version 3.1.
237 @end ifset
238 @end ifset
239
240 @ifclear INTERNALS
241 This manual documents how to run and install the GNU compiler,
242 as well as its new features and incompatibilities, and how to report
243 bugs.  It corresponds to GCC version 3.1.
244 @end ifclear
245 @ifclear USING
246 This manual documents how to port the GNU compiler,
247 as well as its new features and incompatibilities, and how to report
248 bugs.  It corresponds to GCC version 3.1.
249 @end ifclear
250
251 @menu
252 @ifset USING
253 * G++ and GCC::     You can compile C or C++ programs.
254 * Standards::       Language standards supported by GCC.
255 * Invoking GCC::    Command options supported by @samp{gcc}.
256 * Installation::    How to configure, compile and install GCC.
257 * C Implementation:: How GCC implements the ISO C specification.
258 * C Extensions::    GNU extensions to the C language family.
259 * C++ Extensions::  GNU extensions to the C++ language.
260 * Objective-C::     GNU Objective-C runtime features.
261 * Gcov::            gcov: a GCC test coverage program.
262 * Trouble::         If you have trouble installing GCC.
263 * Bugs::            How, why and where to report bugs.
264 * Service::         How to find suppliers of support for GCC.
265 * Contributing::    How to contribute to testing and developing GCC.
266 * VMS::             Using GCC on VMS.
267 * Makefile::        Additional Makefile and configure information.
268 @end ifset
269 @ifset INTERNALS
270 * Portability::     Goals of GCC's portability features.
271 * Interface::       Function-call interface of GCC output.
272 * Passes::          Order of passes, what they do, and what each file is for.
273 * Trees::           The source representation used by the C and C++ front ends.
274 * RTL::             The intermediate representation that most passes work on.
275 * Machine Desc::    How to write machine description instruction patterns.
276 * Target Macros::   How to write the machine description C macros and functions.
277 * Config::          Writing the @file{xm-@var{machine}.h} file.
278 * Fragments::       Writing the @file{t-@var{target}} and @file{x-@var{host}} files.
279 @end ifset
280
281 * Funding::         How to help assure funding for free software.
282 * GNU/Linux::       Linux and the GNU Project
283
284 * Copying::         GNU General Public License says
285                      how you can copy and share GCC.
286 * GNU Free Documentation License:: How you can copy and share this manual.
287 * Contributors::    People who have contributed to GCC.
288
289 * Option Index::    Index to command line options.
290 * Index::           Index of concepts and symbol names.
291 @end menu
292
293 @ifset USING
294 @node G++ and GCC
295 @chapter Compile C, C++, Objective-C, Fortran, Java or CHILL
296
297 @cindex Objective-C
298 @cindex Fortran
299 @cindex Java
300 @cindex CHILL
301 Several versions of the compiler (C, C++, Objective-C, Fortran, Java
302 and CHILL) are integrated; this is why we use the name
303 ``GNU Compiler Collection''.  GCC can compile programs written in any of these
304 languages.  The Fortran, CHILL, and Java compilers are described in
305 separate manuals.
306
307 @cindex GCC
308 ``GCC'' is a common shorthand term for the GNU Compiler Collection.  This is both
309 the most general name for the compiler, and the name used when the
310 emphasis is on compiling C programs (as the abbreviation formerly
311 stood for ``GNU C Compiler'').
312
313 @cindex C++
314 @cindex G++
315 When referring to C++ compilation, it is usual to call the compiler
316 ``G++''.  Since there is only one compiler, it is also accurate to call
317 it ``GCC'' no matter what the language context; however, the term
318 ``G++'' is more useful when the emphasis is on compiling C++ programs.
319
320 We use the name ``GCC'' to refer to the compilation system as a
321 whole, and more specifically to the language-independent part of the
322 compiler.  For example, we refer to the optimization options as
323 affecting the behavior of ``GCC'' or sometimes just ``the compiler''.
324
325 Front ends for other languages, such as Ada 95 and Pascal exist but
326 have not yet been integrated into GCC@.  These front ends, like that for C++,
327 are built in subdirectories of GCC and link to it.  The result is an
328 integrated compiler that can compile programs written in C, C++,
329 Objective-C, or any of the languages for which you have installed front
330 ends.
331
332 In this manual, we only discuss the options for the C, Objective-C, and
333 C++ compilers and those of the GCC core.  Consult the documentation
334 of the other front ends for the options to use when compiling programs
335 written in other languages.
336
337 @cindex compiler compared to C++ preprocessor
338 @cindex intermediate C version, nonexistent
339 @cindex C intermediate output, nonexistent
340 G++ is a @emph{compiler}, not merely a preprocessor.  G++ builds object
341 code directly from your C++ program source.  There is no intermediate C
342 version of the program.  (By contrast, for example, some other
343 implementations use a program that generates a C program from your C++
344 source.)  Avoiding an intermediate C representation of the program means
345 that you get better object code, and better debugging information.  The
346 GNU debugger, GDB, works with this information in the object code to
347 give you comprehensive C++ source-level editing capabilities
348 (@pxref{C,,C and C++,gdb.info, Debugging with GDB}).
349
350 @c FIXME!  Someone who knows something about Objective-C ought to put in
351 @c a paragraph or two about it here, and move the index entry down when
352 @c there is more to point to than the general mention in the 1st par.
353
354 @node Standards
355 @chapter Language Standards Supported by GCC
356 @cindex C standard
357 @cindex C standards
358 @cindex ANSI C standard
359 @cindex ANSI C
360 @cindex ANSI C89
361 @cindex C89
362 @cindex ANSI X3.159-1989
363 @cindex X3.159-1989
364 @cindex ISO C standard
365 @cindex ISO C
366 @cindex ISO C89
367 @cindex ISO C90
368 @cindex ISO/IEC 9899
369 @cindex ISO 9899
370 @cindex C90
371 @cindex ISO C94
372 @cindex C94
373 @cindex ISO C95
374 @cindex C95
375 @cindex ISO C99
376 @cindex C99
377 @cindex ISO C9X
378 @cindex C9X
379 @cindex Technical Corrigenda
380 @cindex TC1
381 @cindex Technical Corrigendum 1
382 @cindex TC2
383 @cindex Technical Corrigendum 2
384 @cindex AMD1
385 @cindex freestanding implementation
386 @cindex freestanding environment
387 @cindex hosted implementation
388 @cindex hosted environment
389 @findex __STDC_HOSTED__
390
391 For each language compiled by GCC for which there is a standard, GCC
392 attempts to follow one or more versions of that standard, possibly
393 with some exceptions, and possibly with some extensions.
394
395 GCC supports three versions of the C standard, although support for
396 the most recent version is not yet complete.
397
398 @opindex std
399 @opindex ansi
400 @opindex pedantic
401 @opindex pedantic-errors
402 The original ANSI C standard (X3.159-1989) was ratified in 1989 and
403 published in 1990.  This standard was ratified as an ISO standard
404 (ISO/IEC 9899:1990) later in 1990.  There were no technical
405 differences between these publications, although the sections of the
406 ANSI standard were renumbered and became clauses in the ISO standard.
407 This standard, in both its forms, is commonly known as @dfn{C89}, or
408 occasionally as @dfn{C90}, from the dates of ratification.  The ANSI
409 standard, but not the ISO standard, also came with a Rationale
410 document.  To select this standard in GCC, use one of the options
411 @option{-ansi}, @option{-std=c89} or @option{-std=iso9899:1990}; to obtain
412 all the diagnostics required by the standard, you should also specify
413 @option{-pedantic} (or @option{-pedantic-errors} if you want them to be
414 errors rather than warnings).  @xref{C Dialect Options,,Options
415 Controlling C Dialect}.
416
417 Errors in the 1990 ISO C standard were corrected in two Technical
418 Corrigenda published in 1994 and 1996.  GCC does not support the
419 uncorrected version.
420
421 An amendment to the 1990 standard was published in 1995.  This
422 amendment added digraphs and @code{__STDC_VERSION__} to the language,
423 but otherwise concerned the library.  This amendment is commonly known
424 as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
425 @dfn{C95}.  To select this standard in GCC, use the option
426 @option{-std=iso9899:199409} (with, as for other standard versions,
427 @option{-pedantic} to receive all required diagnostics).
428
429 A new edition of the ISO C standard was published in 1999 as ISO/IEC
430 9899:1999, and is commonly known as @dfn{C99}.  GCC has incomplete
431 support for this standard version; see
432 @uref{http://gcc.gnu.org/c99status.html} for details.  To select this
433 standard, use @option{-std=c99} or @option{-std=iso9899:1999}.  (While in
434 development, drafts of this standard version were referred to as
435 @dfn{C9X}.)
436
437 @opindex traditional
438 GCC also has some limited support for traditional (pre-ISO) C with the
439 @option{-traditional} option.  This support may be of use for compiling
440 some very old programs that have not been updated to ISO C, but should
441 not be used for new programs.  It will not work with some modern C
442 libraries such as the GNU C library.
443
444 By default, GCC provides some extensions to the C language that on
445 rare occasions conflict with the C standard.  @xref{C
446 Extensions,,Extensions to the C Language Family}.  Use of the
447 @option{-std} options listed above will disable these extensions where
448 they conflict with the C standard version selected.  You may also
449 select an extended version of the C language explicitly with
450 @option{-std=gnu89} (for C89 with GNU extensions) or @option{-std=gnu99}
451 (for C99 with GNU extensions).  The default, if no C language dialect
452 options are given, is @option{-std=gnu89}; this will change to
453 @option{-std=gnu99} in some future release when the C99 support is
454 complete.  Some features that are part of the C99 standard are
455 accepted as extensions in C89 mode.
456
457 The ISO C standard defines (in clause 4) two classes of conforming
458 implementation.  A @dfn{conforming hosted implementation} supports the
459 whole standard including all the library facilities; a @dfn{conforming
460 freestanding implementation} is only required to provide certain
461 library facilities: those in @code{<float.h>}, @code{<limits.h>},
462 @code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
463 @code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
464 @code{<stdint.h>}.  In addition, complex types, added in C99, are not
465 required for freestanding implementations.  The standard also defines
466 two environments for programs, a @dfn{freestanding environment},
467 required of all implementations and which may not have library
468 facilities beyond those required of freestanding implementations,
469 where the handling of program startup and termination are
470 implementation-defined, and a @dfn{hosted environment}, which is not
471 required, in which all the library facilities are provided and startup
472 is through a function @code{int main (void)} or @code{int main (int,
473 char *[])}.  An OS kernel would be a freestanding environment; a
474 program using the facilities of an operating system would normally be
475 in a hosted implementation.
476
477 @opindex ffreestanding
478 GCC aims towards being usable as a conforming freestanding
479 implementation, or as the compiler for a conforming hosted
480 implementation.  By default, it will act as the compiler for a hosted
481 implementation, defining @code{__STDC_HOSTED__} as @code{1} and
482 presuming that when the names of ISO C functions are used, they have
483 the semantics defined in the standard.  To make it act as a conforming
484 freestanding implementation for a freestanding environment, use the
485 option @option{-ffreestanding}; it will then define
486 @code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
487 meanings of function names from the standard library.  To build an OS
488 kernel, you may well still need to make your own arrangements for
489 linking and startup.  @xref{C Dialect Options,,Options Controlling C
490 Dialect}.
491
492 GCC does not provide the library facilities required only of hosted
493 implementations, nor yet all the facilities required by C99 of
494 freestanding implementations; to use the facilities of a hosted
495 environment, you will need to find them elsewhere (for example, in the
496 GNU C library).  @xref{Standard Libraries,,Standard Libraries}.
497
498 For references to Technical Corrigenda, Rationale documents and
499 information concerning the history of C that is available online, see
500 @uref{http://gcc.gnu.org/readings.html}
501
502 @c FIXME: details of C++ standard.
503
504 There is no formal written standard for Objective-C@.  The most
505 authoritative manual is ``Object-Oriented Programming and the
506 Objective-C Language'', available at a number of web sites;
507 @uref{http://developer.apple.com/techpubs/macosx/Cocoa/ObjectiveC/} has a
508 recent version, while @uref{http://www.toodarkpark.org/computers/objc/}
509 is an older example.  @uref{http://www.gnustep.org} includes useful
510 information as well.
511
512 @xref{Language,,The GNU Fortran Language, g77, Using and Porting GNU
513 Fortran}, for details of the Fortran language supported by GCC@.
514
515 @xref{Compatibility,,Compatibility with the Java Platform, gcj, GNU gcj},
516 for details of compatibility between @code{gcj} and the Java Platform.
517
518 @xref{References,,Language Definition References, chill, GNU Chill},
519 for details of the CHILL standard.
520
521 @include invoke.texi
522
523 @include install-old.texi
524
525 @include extend.texi
526
527 @include objc.texi
528
529 @include gcov.texi
530
531 @node Trouble
532 @chapter Known Causes of Trouble with GCC
533 @cindex bugs, known
534 @cindex installation trouble
535 @cindex known causes of trouble
536
537 This section describes known problems that affect users of GCC@.  Most
538 of these are not GCC bugs per se---if they were, we would fix them.
539 But the result for a user may be like the result of a bug.
540
541 Some of these problems are due to bugs in other software, some are
542 missing features that are too much work to add, and some are places
543 where people's opinions differ as to what is best.
544
545 @menu
546 * Actual Bugs::               Bugs we will fix later.
547 * Cross-Compiler Problems::   Common problems of cross compiling with GCC.
548 * Interoperation::      Problems using GCC with other compilers,
549                            and with certain linkers, assemblers and debuggers.
550 * External Bugs::       Problems compiling certain programs.
551 * Incompatibilities::   GCC is incompatible with traditional C.
552 * Fixed Headers::       GCC uses corrected versions of system header files.
553                            This is necessary, but doesn't always work smoothly.
554 * Standard Libraries::  GCC uses the system C library, which might not be
555                            compliant with the ISO C standard.
556 * Disappointments::     Regrettable things we can't change, but not quite bugs.
557 * C++ Misunderstandings::     Common misunderstandings with GNU C++.
558 * Protoize Caveats::    Things to watch out for when using @code{protoize}.
559 * Non-bugs::            Things we think are right, but some others disagree.
560 * Warnings and Errors:: Which problems in your code get warnings,
561                          and which get errors.
562 @end menu
563
564 @node Actual Bugs
565 @section Actual Bugs We Haven't Fixed Yet
566
567 @itemize @bullet
568 @item
569 The @code{fixincludes} script interacts badly with automounters; if the
570 directory of system header files is automounted, it tends to be
571 unmounted while @code{fixincludes} is running.  This would seem to be a
572 bug in the automounter.  We don't know any good way to work around it.
573
574 @item
575 The @code{fixproto} script will sometimes add prototypes for the
576 @code{sigsetjmp} and @code{siglongjmp} functions that reference the
577 @code{jmp_buf} type before that type is defined.  To work around this,
578 edit the offending file and place the typedef in front of the
579 prototypes.
580
581 @item
582 @opindex pedantic-errors
583 When @option{-pedantic-errors} is specified, GCC will incorrectly give
584 an error message when a function name is specified in an expression
585 involving the comma operator.
586 @end itemize
587
588 @node Cross-Compiler Problems
589 @section Cross-Compiler Problems
590
591 You may run into problems with cross compilation on certain machines,
592 for several reasons.
593
594 @itemize @bullet
595 @item
596 Cross compilation can run into trouble for certain machines because
597 some target machines' assemblers require floating point numbers to be
598 written as @emph{integer} constants in certain contexts.
599
600 The compiler writes these integer constants by examining the floating
601 point value as an integer and printing that integer, because this is
602 simple to write and independent of the details of the floating point
603 representation.  But this does not work if the compiler is running on
604 a different machine with an incompatible floating point format, or
605 even a different byte-ordering.
606
607 In addition, correct constant folding of floating point values
608 requires representing them in the target machine's format.
609 (The C standard does not quite require this, but in practice
610 it is the only way to win.)
611
612 It is now possible to overcome these problems by defining macros such
613 as @code{REAL_VALUE_TYPE}.  But doing so is a substantial amount of
614 work for each target machine.
615 @ifset INTERNALS
616 @xref{Cross-compilation}.
617 @end ifset
618 @ifclear INTERNALS
619 @xref{Cross-compilation,,Cross Compilation and Floating Point Format,
620 gcc.info, Using and Porting GCC}.
621 @end ifclear
622
623 @item
624 At present, the program @file{mips-tfile} which adds debug
625 support to object files on MIPS systems does not work in a cross
626 compile environment.
627 @end itemize
628
629 @node Interoperation
630 @section Interoperation
631
632 This section lists various difficulties encountered in using GCC
633 together with other compilers or with the assemblers, linkers,
634 libraries and debuggers on certain systems.
635
636 @itemize @bullet
637 @item
638 Objective-C does not work on the RS/6000.
639
640 @item
641 G++ does not do name mangling in the same way as other C++
642 compilers.  This means that object files compiled with one compiler
643 cannot be used with another.
644
645 This effect is intentional, to protect you from more subtle problems.
646 Compilers differ as to many internal details of C++ implementation,
647 including: how class instances are laid out, how multiple inheritance is
648 implemented, and how virtual function calls are handled.  If the name
649 encoding were made the same, your programs would link against libraries
650 provided from other compilers---but the programs would then crash when
651 run.  Incompatible libraries are then detected at link time, rather than
652 at run time.
653
654 @item
655 Older GDB versions sometimes fail to read the output of GCC version
656 2.  If you have trouble, get GDB version 4.4 or later.
657
658 @item
659 @cindex DBX
660 DBX rejects some files produced by GCC, though it accepts similar
661 constructs in output from PCC@.  Until someone can supply a coherent
662 description of what is valid DBX input and what is not, there is
663 nothing I can do about these problems.  You are on your own.
664
665 @item
666 The GNU assembler (GAS) does not support PIC@.  To generate PIC code, you
667 must use some other assembler, such as @file{/bin/as}.
668
669 @item
670 On some BSD systems, including some versions of Ultrix, use of profiling
671 causes static variable destructors (currently used only in C++) not to
672 be run.
673
674 @ignore
675 @cindex @code{vfork}, for the Sun-4
676 @item
677 There is a bug in @code{vfork} on the Sun-4 which causes the registers
678 of the child process to clobber those of the parent.  Because of this,
679 programs that call @code{vfork} are likely to lose when compiled
680 optimized with GCC when the child code alters registers which contain
681 C variables in the parent.  This affects variables which are live in the
682 parent across the call to @code{vfork}.
683
684 If you encounter this, you can work around the problem by declaring
685 variables @code{volatile} in the function that calls @code{vfork}, until
686 the problem goes away, or by not declaring them @code{register} and not
687 using @option{-O} for those source files.
688 @end ignore
689
690 @item
691 On some SGI systems, when you use @option{-lgl_s} as an option,
692 it gets translated magically to @samp{-lgl_s -lX11_s -lc_s}.
693 Naturally, this does not happen when you use GCC@.
694 You must specify all three options explicitly.
695
696 @item
697 On a Sparc, GCC aligns all values of type @code{double} on an 8-byte
698 boundary, and it expects every @code{double} to be so aligned.  The Sun
699 compiler usually gives @code{double} values 8-byte alignment, with one
700 exception: function arguments of type @code{double} may not be aligned.
701
702 As a result, if a function compiled with Sun CC takes the address of an
703 argument of type @code{double} and passes this pointer of type
704 @code{double *} to a function compiled with GCC, dereferencing the
705 pointer may cause a fatal signal.
706
707 One way to solve this problem is to compile your entire program with GCC@.
708 Another solution is to modify the function that is compiled with
709 Sun CC to copy the argument into a local variable; local variables
710 are always properly aligned.  A third solution is to modify the function
711 that uses the pointer to dereference it via the following function
712 @code{access_double} instead of directly with @samp{*}:
713
714 @smallexample
715 inline double
716 access_double (double *unaligned_ptr)
717 @{
718   union d2i @{ double d; int i[2]; @};
719
720   union d2i *p = (union d2i *) unaligned_ptr;
721   union d2i u;
722
723   u.i[0] = p->i[0];
724   u.i[1] = p->i[1];
725
726   return u.d;
727 @}
728 @end smallexample
729
730 @noindent
731 Storing into the pointer can be done likewise with the same union.
732
733 @item
734 On Solaris, the @code{malloc} function in the @file{libmalloc.a} library
735 may allocate memory that is only 4 byte aligned.  Since GCC on the
736 Sparc assumes that doubles are 8 byte aligned, this may result in a
737 fatal signal if doubles are stored in memory allocated by the
738 @file{libmalloc.a} library.
739
740 The solution is to not use the @file{libmalloc.a} library.  Use instead
741 @code{malloc} and related functions from @file{libc.a}; they do not have
742 this problem.
743
744 @item
745 Sun forgot to include a static version of @file{libdl.a} with some
746 versions of SunOS (mainly 4.1).  This results in undefined symbols when
747 linking static binaries (that is, if you use @option{-static}).  If you
748 see undefined symbols @code{_dlclose}, @code{_dlsym} or @code{_dlopen}
749 when linking, compile and link against the file
750 @file{mit/util/misc/dlsym.c} from the MIT version of X windows.
751
752 @item
753 The 128-bit long double format that the Sparc port supports currently
754 works by using the architecturally defined quad-word floating point
755 instructions.  Since there is no hardware that supports these
756 instructions they must be emulated by the operating system.  Long
757 doubles do not work in Sun OS versions 4.0.3 and earlier, because the
758 kernel emulator uses an obsolete and incompatible format.  Long doubles
759 do not work in Sun OS version 4.1.1 due to a problem in a Sun library.
760 Long doubles do work on Sun OS versions 4.1.2 and higher, but GCC
761 does not enable them by default.  Long doubles appear to work in Sun OS
762 5.x (Solaris 2.x).
763
764 @item
765 On HP-UX version 9.01 on the HP PA, the HP compiler @code{cc} does not
766 compile GCC correctly.  We do not yet know why.  However, GCC
767 compiled on earlier HP-UX versions works properly on HP-UX 9.01 and can
768 compile itself properly on 9.01.
769
770 @item
771 On the HP PA machine, ADB sometimes fails to work on functions compiled
772 with GCC@.  Specifically, it fails to work on functions that use
773 @code{alloca} or variable-size arrays.  This is because GCC doesn't
774 generate HP-UX unwind descriptors for such functions.  It may even be
775 impossible to generate them.
776
777 @item
778 Debugging (@option{-g}) is not supported on the HP PA machine, unless you use
779 the preliminary GNU tools (@pxref{Installation}).
780
781 @item
782 Taking the address of a label may generate errors from the HP-UX
783 PA assembler.  GAS for the PA does not have this problem.
784
785 @item
786 Using floating point parameters for indirect calls to static functions
787 will not work when using the HP assembler.  There simply is no way for GCC
788 to specify what registers hold arguments for static functions when using
789 the HP assembler.  GAS for the PA does not have this problem.
790
791 @item
792 In extremely rare cases involving some very large functions you may
793 receive errors from the HP linker complaining about an out of bounds
794 unconditional branch offset.  This used to occur more often in previous
795 versions of GCC, but is now exceptionally rare.  If you should run
796 into it, you can work around by making your function smaller.
797
798 @item
799 GCC compiled code sometimes emits warnings from the HP-UX assembler of
800 the form:
801
802 @smallexample
803 (warning) Use of GR3 when
804   frame >= 8192 may cause conflict.
805 @end smallexample
806
807 These warnings are harmless and can be safely ignored.
808
809 @item
810 The current version of the assembler (@file{/bin/as}) for the RS/6000
811 has certain problems that prevent the @option{-g} option in GCC from
812 working.  Note that @file{Makefile.in} uses @option{-g} by default when
813 compiling @file{libgcc2.c}.
814
815 IBM has produced a fixed version of the assembler.  The upgraded
816 assembler unfortunately was not included in any of the AIX 3.2 update
817 PTF releases (3.2.2, 3.2.3, or 3.2.3e).  Users of AIX 3.1 should request
818 PTF U403044 from IBM and users of AIX 3.2 should request PTF U416277.
819 See the file @file{README.RS6000} for more details on these updates.
820
821 You can test for the presence of a fixed assembler by using the
822 command
823
824 @smallexample
825 as -u < /dev/null
826 @end smallexample
827
828 @noindent
829 If the command exits normally, the assembler fix already is installed.
830 If the assembler complains that @option{-u} is an unknown flag, you need to
831 order the fix.
832
833 @item
834 On the IBM RS/6000, compiling code of the form
835
836 @smallexample
837 extern int foo;
838
839 @dots{} foo @dots{}
840
841 static int foo;
842 @end smallexample
843
844 @noindent
845 will cause the linker to report an undefined symbol @code{foo}.
846 Although this behavior differs from most other systems, it is not a
847 bug because redefining an @code{extern} variable as @code{static}
848 is undefined in ISO C@.
849
850 @item
851 AIX on the RS/6000 provides support (NLS) for environments outside of
852 the United States.  Compilers and assemblers use NLS to support
853 locale-specific representations of various objects including
854 floating-point numbers (@samp{.} vs @samp{,} for separating decimal fractions).
855 There have been problems reported where the library linked with GCC does
856 not produce the same floating-point formats that the assembler accepts.
857 If you have this problem, set the @env{LANG} environment variable to
858 @samp{C} or @samp{En_US}.
859
860 @item
861 @opindex fdollars-in-identifiers
862 Even if you specify @option{-fdollars-in-identifiers},
863 you cannot successfully use @samp{$} in identifiers on the RS/6000 due
864 to a restriction in the IBM assembler.  GAS supports these
865 identifiers.
866
867 @item
868 On the RS/6000, XLC version 1.3.0.0 will miscompile @file{jump.c}.  XLC
869 version 1.3.0.1 or later fixes this problem.  You can obtain XLC-1.3.0.2
870 by requesting PTF 421749 from IBM@.
871
872 @item
873 @opindex mno-serialize-volatile
874 There is an assembler bug in versions of DG/UX prior to 5.4.2.01 that
875 occurs when the @samp{fldcr} instruction is used.  GCC uses
876 @samp{fldcr} on the 88100 to serialize volatile memory references.  Use
877 the option @option{-mno-serialize-volatile} if your version of the
878 assembler has this bug.
879
880 @item
881 On VMS, GAS versions 1.38.1 and earlier may cause spurious warning
882 messages from the linker.  These warning messages complain of mismatched
883 psect attributes.  You can ignore them.  @xref{VMS Install}.
884
885 @item
886 On NewsOS version 3, if you include both of the files @file{stddef.h}
887 and @file{sys/types.h}, you get an error because there are two typedefs
888 of @code{size_t}.  You should change @file{sys/types.h} by adding these
889 lines around the definition of @code{size_t}:
890
891 @smallexample
892 #ifndef _SIZE_T
893 #define _SIZE_T
894 @var{actual-typedef-here}
895 #endif
896 @end smallexample
897
898 @cindex Alliant
899 @item
900 On the Alliant, the system's own convention for returning structures
901 and unions is unusual, and is not compatible with GCC no matter
902 what options are used.
903
904 @cindex RT PC
905 @cindex IBM RT PC
906 @item
907 @opindex mhc-struct-return
908 On the IBM RT PC, the MetaWare HighC compiler (hc) uses a different
909 convention for structure and union returning.  Use the option
910 @option{-mhc-struct-return} to tell GCC to use a convention compatible
911 with it.
912
913 @cindex VAX calling convention
914 @cindex Ultrix calling convention
915 @item
916 @opindex fcall-saved
917 On Ultrix, the Fortran compiler expects registers 2 through 5 to be saved
918 by function calls.  However, the C compiler uses conventions compatible
919 with BSD Unix: registers 2 through 5 may be clobbered by function calls.
920
921 GCC uses the same convention as the Ultrix C compiler.  You can use
922 these options to produce code compatible with the Fortran compiler:
923
924 @smallexample
925 -fcall-saved-r2 -fcall-saved-r3 -fcall-saved-r4 -fcall-saved-r5
926 @end smallexample
927
928 @item
929 On the WE32k, you may find that programs compiled with GCC do not
930 work with the standard shared C library.  You may need to link with
931 the ordinary C compiler.  If you do so, you must specify the following
932 options:
933
934 @smallexample
935 -L/usr/local/lib/gcc-lib/we32k-att-sysv/2.8.1 -lgcc -lc_s
936 @end smallexample
937
938 The first specifies where to find the library @file{libgcc.a}
939 specified with the @option{-lgcc} option.
940
941 GCC does linking by invoking @command{ld}, just as @command{cc} does, and
942 there is no reason why it @emph{should} matter which compilation program
943 you use to invoke @command{ld}.  If someone tracks this problem down,
944 it can probably be fixed easily.
945
946 @item
947 On the Alpha, you may get assembler errors about invalid syntax as a
948 result of floating point constants.  This is due to a bug in the C
949 library functions @code{ecvt}, @code{fcvt} and @code{gcvt}.  Given valid
950 floating point numbers, they sometimes print @samp{NaN}.
951
952 @item
953 On Irix 4.0.5F (and perhaps in some other versions), an assembler bug
954 sometimes reorders instructions incorrectly when optimization is turned
955 on.  If you think this may be happening to you, try using the GNU
956 assembler; GAS version 2.1 supports ECOFF on Irix.
957
958 @opindex noasmopt
959 Or use the @option{-noasmopt} option when you compile GCC with itself,
960 and then again when you compile your program.  (This is a temporary
961 kludge to turn off assembler optimization on Irix.)  If this proves to
962 be what you need, edit the assembler spec in the file @file{specs} so
963 that it unconditionally passes @option{-O0} to the assembler, and never
964 passes @option{-O2} or @option{-O3}.
965 @end itemize
966
967 @node External Bugs
968 @section Problems Compiling Certain Programs
969
970 @c prevent bad page break with this line
971 Certain programs have problems compiling.
972
973 @itemize @bullet
974 @item
975 Parse errors may occur compiling X11 on a Decstation running Ultrix 4.2
976 because of problems in DEC's versions of the X11 header files
977 @file{X11/Xlib.h} and @file{X11/Xutil.h}.  People recommend adding
978 @option{-I/usr/include/mit} to use the MIT versions of the header files,
979 using the @option{-traditional} switch to turn off ISO C, or fixing the
980 header files by adding this:
981
982 @example
983 #ifdef __STDC__
984 #define NeedFunctionPrototypes 0
985 #endif
986 @end example
987
988 @item
989 On various 386 Unix systems derived from System V, including SCO, ISC,
990 and ESIX, you may get error messages about running out of virtual memory
991 while compiling certain programs.
992
993 You can prevent this problem by linking GCC with the GNU malloc
994 (which thus replaces the malloc that comes with the system).  GNU malloc
995 is available as a separate package, and also in the file
996 @file{src/gmalloc.c} in the GNU Emacs 19 distribution.
997
998 If you have installed GNU malloc as a separate library package, use this
999 option when you relink GCC:
1000
1001 @example
1002 MALLOC=/usr/local/lib/libgmalloc.a
1003 @end example
1004
1005 Alternatively, if you have compiled @file{gmalloc.c} from Emacs 19, copy
1006 the object file to @file{gmalloc.o} and use this option when you relink
1007 GCC:
1008
1009 @example
1010 MALLOC=gmalloc.o
1011 @end example
1012 @end itemize
1013
1014 @node Incompatibilities
1015 @section Incompatibilities of GCC
1016 @cindex incompatibilities of GCC
1017 @opindex traditional
1018
1019 There are several noteworthy incompatibilities between GNU C and K&R
1020 (non-ISO) versions of C@.  The @option{-traditional} option
1021 eliminates many of these incompatibilities, @emph{but not all}, by
1022 telling GCC to behave like a K&R C compiler.
1023
1024 @itemize @bullet
1025 @cindex string constants
1026 @cindex read-only strings
1027 @cindex shared strings
1028 @item
1029 GCC normally makes string constants read-only.  If several
1030 identical-looking string constants are used, GCC stores only one
1031 copy of the string.
1032
1033 @cindex @code{mktemp}, and constant strings
1034 One consequence is that you cannot call @code{mktemp} with a string
1035 constant argument.  The function @code{mktemp} always alters the
1036 string its argument points to.
1037
1038 @cindex @code{sscanf}, and constant strings
1039 @cindex @code{fscanf}, and constant strings
1040 @cindex @code{scanf}, and constant strings
1041 Another consequence is that @code{sscanf} does not work on some systems
1042 when passed a string constant as its format control string or input.
1043 This is because @code{sscanf} incorrectly tries to write into the string
1044 constant.  Likewise @code{fscanf} and @code{scanf}.
1045
1046 @opindex fwritable-strings
1047 The best solution to these problems is to change the program to use
1048 @code{char}-array variables with initialization strings for these
1049 purposes instead of string constants.  But if this is not possible,
1050 you can use the @option{-fwritable-strings} flag, which directs GCC
1051 to handle string constants the same way most C compilers do.
1052 @option{-traditional} also has this effect, among others.
1053
1054 @item
1055 @code{-2147483648} is positive.
1056
1057 This is because 2147483648 cannot fit in the type @code{int}, so
1058 (following the ISO C rules) its data type is @code{unsigned long int}.
1059 Negating this value yields 2147483648 again.
1060
1061 @item
1062 GCC does not substitute macro arguments when they appear inside of
1063 string constants.  For example, the following macro in GCC
1064
1065 @example
1066 #define foo(a) "a"
1067 @end example
1068
1069 @noindent
1070 will produce output @code{"a"} regardless of what the argument @var{a} is.
1071
1072 The @option{-traditional} option directs GCC to handle such cases
1073 (among others) in the old-fashioned (non-ISO) fashion.
1074
1075 @cindex @code{setjmp} incompatibilities
1076 @cindex @code{longjmp} incompatibilities
1077 @item
1078 When you use @code{setjmp} and @code{longjmp}, the only automatic
1079 variables guaranteed to remain valid are those declared
1080 @code{volatile}.  This is a consequence of automatic register
1081 allocation.  Consider this function:
1082
1083 @example
1084 jmp_buf j;
1085
1086 foo ()
1087 @{
1088   int a, b;
1089
1090   a = fun1 ();
1091   if (setjmp (j))
1092     return a;
1093
1094   a = fun2 ();
1095   /* @r{@code{longjmp (j)} may occur in @code{fun3}.} */
1096   return a + fun3 ();
1097 @}
1098 @end example
1099
1100 Here @code{a} may or may not be restored to its first value when the
1101 @code{longjmp} occurs.  If @code{a} is allocated in a register, then
1102 its first value is restored; otherwise, it keeps the last value stored
1103 in it.
1104
1105 @opindex W
1106 If you use the @option{-W} option with the @option{-O} option, you will
1107 get a warning when GCC thinks such a problem might be possible.
1108
1109 The @option{-traditional} option directs GCC to put variables in
1110 the stack by default, rather than in registers, in functions that
1111 call @code{setjmp}.  This results in the behavior found in
1112 traditional C compilers.
1113
1114 @item
1115 Programs that use preprocessing directives in the middle of macro
1116 arguments do not work with GCC@.  For example, a program like this
1117 will not work:
1118
1119 @example
1120 @group
1121 foobar (
1122 #define luser
1123         hack)
1124 @end group
1125 @end example
1126
1127 ISO C does not permit such a construct.  It would make sense to support
1128 it when @option{-traditional} is used, but it is too much work to
1129 implement.
1130
1131 @item
1132 K&R compilers allow comments to cross over an inclusion boundary
1133 (i.e.@: started in an include file and ended in the including file).  I think
1134 this would be quite ugly and can't imagine it could be needed.
1135
1136 @cindex external declaration scope
1137 @cindex scope of external declarations
1138 @cindex declaration scope
1139 @item
1140 Declarations of external variables and functions within a block apply
1141 only to the block containing the declaration.  In other words, they
1142 have the same scope as any other declaration in the same place.
1143
1144 In some other C compilers, a @code{extern} declaration affects all the
1145 rest of the file even if it happens within a block.
1146
1147 The @option{-traditional} option directs GCC to treat all @code{extern}
1148 declarations as global, like traditional compilers.
1149
1150 @item
1151 In traditional C, you can combine @code{long}, etc., with a typedef name,
1152 as shown here:
1153
1154 @example
1155 typedef int foo;
1156 typedef long foo bar;
1157 @end example
1158
1159 In ISO C, this is not allowed: @code{long} and other type modifiers
1160 require an explicit @code{int}.  Because this criterion is expressed
1161 by Bison grammar rules rather than C code, the @option{-traditional}
1162 flag cannot alter it.
1163
1164 @cindex typedef names as function parameters
1165 @item
1166 PCC allows typedef names to be used as function parameters.  The
1167 difficulty described immediately above applies here too.
1168
1169 @item
1170 When in @option{-traditional} mode, GCC allows the following erroneous
1171 pair of declarations to appear together in a given scope:
1172
1173 @example
1174 typedef int foo;
1175 typedef foo foo;
1176 @end example
1177
1178 @item
1179 GCC treats all characters of identifiers as significant, even when in
1180 @option{-traditional} mode.  According to K&R-1 (2.2), ``No more than the
1181 first eight characters are significant, although more may be used.''.
1182 Also according to K&R-1 (2.2), ``An identifier is a sequence of letters
1183 and digits; the first character must be a letter.  The underscore _
1184 counts as a letter.'', but GCC also allows dollar signs in identifiers.
1185
1186 @cindex whitespace
1187 @item
1188 PCC allows whitespace in the middle of compound assignment operators
1189 such as @samp{+=}.  GCC, following the ISO standard, does not
1190 allow this.  The difficulty described immediately above applies here
1191 too.
1192
1193 @cindex apostrophes
1194 @cindex '
1195 @item
1196 GCC complains about unterminated character constants inside of
1197 preprocessing conditionals that fail.  Some programs have English
1198 comments enclosed in conditionals that are guaranteed to fail; if these
1199 comments contain apostrophes, GCC will probably report an error.  For
1200 example, this code would produce an error:
1201
1202 @example
1203 #if 0
1204 You can't expect this to work.
1205 #endif
1206 @end example
1207
1208 The best solution to such a problem is to put the text into an actual
1209 C comment delimited by @samp{/*@dots{}*/}.  However,
1210 @option{-traditional} suppresses these error messages.
1211
1212 @item
1213 Many user programs contain the declaration @samp{long time ();}.  In the
1214 past, the system header files on many systems did not actually declare
1215 @code{time}, so it did not matter what type your program declared it to
1216 return.  But in systems with ISO C headers, @code{time} is declared to
1217 return @code{time_t}, and if that is not the same as @code{long}, then
1218 @samp{long time ();} is erroneous.
1219
1220 The solution is to change your program to use appropriate system headers
1221 (@code{<time.h>} on systems with ISO C headers) and not to declare
1222 @code{time} if the system header files declare it, or failing that to
1223 use @code{time_t} as the return type of @code{time}.
1224
1225 @cindex @code{float} as function value type
1226 @item
1227 When compiling functions that return @code{float}, PCC converts it to
1228 a double.  GCC actually returns a @code{float}.  If you are concerned
1229 with PCC compatibility, you should declare your functions to return
1230 @code{double}; you might as well say what you mean.
1231
1232 @cindex structures
1233 @cindex unions
1234 @item
1235 When compiling functions that return structures or unions, GCC
1236 output code normally uses a method different from that used on most
1237 versions of Unix.  As a result, code compiled with GCC cannot call
1238 a structure-returning function compiled with PCC, and vice versa.
1239
1240 The method used by GCC is as follows: a structure or union which is
1241 1, 2, 4 or 8 bytes long is returned like a scalar.  A structure or union
1242 with any other size is stored into an address supplied by the caller
1243 (usually in a special, fixed register, but on some machines it is passed
1244 on the stack).  The machine-description macros @code{STRUCT_VALUE} and
1245 @code{STRUCT_INCOMING_VALUE} tell GCC where to pass this address.
1246
1247 By contrast, PCC on most target machines returns structures and unions
1248 of any size by copying the data into an area of static storage, and then
1249 returning the address of that storage as if it were a pointer value.
1250 The caller must copy the data from that memory area to the place where
1251 the value is wanted.  GCC does not use this method because it is
1252 slower and nonreentrant.
1253
1254 On some newer machines, PCC uses a reentrant convention for all
1255 structure and union returning.  GCC on most of these machines uses a
1256 compatible convention when returning structures and unions in memory,
1257 but still returns small structures and unions in registers.
1258
1259 @opindex fpcc-struct-return
1260 You can tell GCC to use a compatible convention for all structure and
1261 union returning with the option @option{-fpcc-struct-return}.
1262
1263 @cindex preprocessing tokens
1264 @cindex preprocessing numbers
1265 @item
1266 GCC complains about program fragments such as @samp{0x74ae-0x4000}
1267 which appear to be two hexadecimal constants separated by the minus
1268 operator.  Actually, this string is a single @dfn{preprocessing token}.
1269 Each such token must correspond to one token in C@.  Since this does not,
1270 GCC prints an error message.  Although it may appear obvious that what
1271 is meant is an operator and two values, the ISO C standard specifically
1272 requires that this be treated as erroneous.
1273
1274 A @dfn{preprocessing token} is a @dfn{preprocessing number} if it
1275 begins with a digit and is followed by letters, underscores, digits,
1276 periods and @samp{e+}, @samp{e-}, @samp{E+}, @samp{E-}, @samp{p+},
1277 @samp{p-}, @samp{P+}, or @samp{P-} character sequences.  (In strict C89
1278 mode, the sequences @samp{p+}, @samp{p-}, @samp{P+} and @samp{P-} cannot
1279 appear in preprocessing numbers.)
1280
1281 To make the above program fragment valid, place whitespace in front of
1282 the minus sign.  This whitespace will end the preprocessing number.
1283 @end itemize
1284
1285 @node Fixed Headers
1286 @section Fixed Header Files
1287
1288 GCC needs to install corrected versions of some system header files.
1289 This is because most target systems have some header files that won't
1290 work with GCC unless they are changed.  Some have bugs, some are
1291 incompatible with ISO C, and some depend on special features of other
1292 compilers.
1293
1294 Installing GCC automatically creates and installs the fixed header
1295 files, by running a program called @code{fixincludes} (or for certain
1296 targets an alternative such as @code{fixinc.svr4}).  Normally, you
1297 don't need to pay attention to this.  But there are cases where it
1298 doesn't do the right thing automatically.
1299
1300 @itemize @bullet
1301 @item
1302 If you update the system's header files, such as by installing a new
1303 system version, the fixed header files of GCC are not automatically
1304 updated.  The easiest way to update them is to reinstall GCC@.  (If
1305 you want to be clever, look in the makefile and you can find a
1306 shortcut.)
1307
1308 @item
1309 On some systems, in particular SunOS 4, header file directories contain
1310 machine-specific symbolic links in certain places.  This makes it
1311 possible to share most of the header files among hosts running the
1312 same version of SunOS 4 on different machine models.
1313
1314 The programs that fix the header files do not understand this special
1315 way of using symbolic links; therefore, the directory of fixed header
1316 files is good only for the machine model used to build it.
1317
1318 In SunOS 4, only programs that look inside the kernel will notice the
1319 difference between machine models.  Therefore, for most purposes, you
1320 need not be concerned about this.
1321
1322 It is possible to make separate sets of fixed header files for the
1323 different machine models, and arrange a structure of symbolic links so
1324 as to use the proper set, but you'll have to do this by hand.
1325
1326 @item
1327 On Lynxos, GCC by default does not fix the header files.  This is
1328 because bugs in the shell cause the @code{fixincludes} script to fail.
1329
1330 This means you will encounter problems due to bugs in the system header
1331 files.  It may be no comfort that they aren't GCC's fault, but it
1332 does mean that there's nothing for us to do about them.
1333 @end itemize
1334
1335 @node Standard Libraries
1336 @section Standard Libraries
1337
1338 @opindex Wall
1339 GCC by itself attempts to be a conforming freestanding implementation.
1340 @xref{Standards,,Language Standards Supported by GCC}, for details of
1341 what this means.  Beyond the library facilities required of such an
1342 implementation, the rest of the C library is supplied by the vendor of
1343 the operating system.  If that C library doesn't conform to the C
1344 standards, then your programs might get warnings (especially when using
1345 @option{-Wall}) that you don't expect.
1346
1347 For example, the @code{sprintf} function on SunOS 4.1.3 returns
1348 @code{char *} while the C standard says that @code{sprintf} returns an
1349 @code{int}.  The @code{fixincludes} program could make the prototype for
1350 this function match the Standard, but that would be wrong, since the
1351 function will still return @code{char *}.
1352
1353 If you need a Standard compliant library, then you need to find one, as
1354 GCC does not provide one.  The GNU C library (called @code{glibc})
1355 provides ISO C, POSIX, BSD, SystemV and X/Open compatibility for
1356 GNU/Linux and HURD-based GNU systems; no recent version of it supports
1357 other systems, though some very old versions did.  Version 2.2 of the
1358 GNU C library includes nearly complete C99 support.  You could also ask
1359 your operating system vendor if newer libraries are available.
1360
1361 @node Disappointments
1362 @section Disappointments and Misunderstandings
1363
1364 These problems are perhaps regrettable, but we don't know any practical
1365 way around them.
1366
1367 @itemize @bullet
1368 @item
1369 Certain local variables aren't recognized by debuggers when you compile
1370 with optimization.
1371
1372 This occurs because sometimes GCC optimizes the variable out of
1373 existence.  There is no way to tell the debugger how to compute the
1374 value such a variable ``would have had'', and it is not clear that would
1375 be desirable anyway.  So GCC simply does not mention the eliminated
1376 variable when it writes debugging information.
1377
1378 You have to expect a certain amount of disagreement between the
1379 executable and your source code, when you use optimization.
1380
1381 @cindex conflicting types
1382 @cindex scope of declaration
1383 @item
1384 Users often think it is a bug when GCC reports an error for code
1385 like this:
1386
1387 @example
1388 int foo (struct mumble *);
1389
1390 struct mumble @{ @dots{} @};
1391
1392 int foo (struct mumble *x)
1393 @{ @dots{} @}
1394 @end example
1395
1396 This code really is erroneous, because the scope of @code{struct
1397 mumble} in the prototype is limited to the argument list containing it.
1398 It does not refer to the @code{struct mumble} defined with file scope
1399 immediately below---they are two unrelated types with similar names in
1400 different scopes.
1401
1402 But in the definition of @code{foo}, the file-scope type is used
1403 because that is available to be inherited.  Thus, the definition and
1404 the prototype do not match, and you get an error.
1405
1406 This behavior may seem silly, but it's what the ISO standard specifies.
1407 It is easy enough for you to make your code work by moving the
1408 definition of @code{struct mumble} above the prototype.  It's not worth
1409 being incompatible with ISO C just to avoid an error for the example
1410 shown above.
1411
1412 @item
1413 Accesses to bit-fields even in volatile objects works by accessing larger
1414 objects, such as a byte or a word.  You cannot rely on what size of
1415 object is accessed in order to read or write the bit-field; it may even
1416 vary for a given bit-field according to the precise usage.
1417
1418 If you care about controlling the amount of memory that is accessed, use
1419 volatile but do not use bit-fields.
1420
1421 @item
1422 GCC comes with shell scripts to fix certain known problems in system
1423 header files.  They install corrected copies of various header files in
1424 a special directory where only GCC will normally look for them.  The
1425 scripts adapt to various systems by searching all the system header
1426 files for the problem cases that we know about.
1427
1428 If new system header files are installed, nothing automatically arranges
1429 to update the corrected header files.  You will have to reinstall GCC
1430 to fix the new header files.  More specifically, go to the build
1431 directory and delete the files @file{stmp-fixinc} and
1432 @file{stmp-headers}, and the subdirectory @code{include}; then do
1433 @samp{make install} again.
1434
1435 @item
1436 @cindex floating point precision
1437 On 68000 and x86 systems, for instance, you can get paradoxical results
1438 if you test the precise values of floating point numbers.  For example,
1439 you can find that a floating point value which is not a NaN is not equal
1440 to itself.  This results from the fact that the floating point registers
1441 hold a few more bits of precision than fit in a @code{double} in memory.
1442 Compiled code moves values between memory and floating point registers
1443 at its convenience, and moving them into memory truncates them.
1444
1445 @opindex ffloat-store
1446 You can partially avoid this problem by using the @option{-ffloat-store}
1447 option (@pxref{Optimize Options}).
1448
1449 @item
1450 On the MIPS, variable argument functions using @file{varargs.h}
1451 cannot have a floating point value for the first argument.  The
1452 reason for this is that in the absence of a prototype in scope,
1453 if the first argument is a floating point, it is passed in a
1454 floating point register, rather than an integer register.
1455
1456 If the code is rewritten to use the ISO standard @file{stdarg.h}
1457 method of variable arguments, and the prototype is in scope at
1458 the time of the call, everything will work fine.
1459
1460 @item
1461 On the H8/300 and H8/300H, variable argument functions must be
1462 implemented using the ISO standard @file{stdarg.h} method of
1463 variable arguments.  Furthermore, calls to functions using @file{stdarg.h}
1464 variable arguments must have a prototype for the called function
1465 in scope at the time of the call.
1466 @end itemize
1467
1468 @node C++ Misunderstandings
1469 @section Common Misunderstandings with GNU C++
1470
1471 @cindex misunderstandings in C++
1472 @cindex surprises in C++
1473 @cindex C++ misunderstandings
1474 C++ is a complex language and an evolving one, and its standard
1475 definition (the ISO C++ standard) was only recently completed.  As a
1476 result, your C++ compiler may occasionally surprise you, even when its
1477 behavior is correct.  This section discusses some areas that frequently
1478 give rise to questions of this sort.
1479
1480 @menu
1481 * Static Definitions::  Static member declarations are not definitions
1482 * Temporaries::         Temporaries may vanish before you expect
1483 * Copy Assignment::     Copy Assignment operators copy virtual bases twice
1484 @end menu
1485
1486 @node Static Definitions
1487 @subsection Declare @emph{and} Define Static Members
1488
1489 @cindex C++ static data, declaring and defining
1490 @cindex static data in C++, declaring and defining
1491 @cindex declaring static data in C++
1492 @cindex defining static data in C++
1493 When a class has static data members, it is not enough to @emph{declare}
1494 the static member; you must also @emph{define} it.  For example:
1495
1496 @example
1497 class Foo
1498 @{
1499   @dots{}
1500   void method();
1501   static int bar;
1502 @};
1503 @end example
1504
1505 This declaration only establishes that the class @code{Foo} has an
1506 @code{int} named @code{Foo::bar}, and a member function named
1507 @code{Foo::method}.  But you still need to define @emph{both}
1508 @code{method} and @code{bar} elsewhere.  According to the ISO
1509 standard, you must supply an initializer in one (and only one) source
1510 file, such as:
1511
1512 @example
1513 int Foo::bar = 0;
1514 @end example
1515
1516 Other C++ compilers may not correctly implement the standard behavior.
1517 As a result, when you switch to @code{g++} from one of these compilers,
1518 you may discover that a program that appeared to work correctly in fact
1519 does not conform to the standard: @code{g++} reports as undefined
1520 symbols any static data members that lack definitions.
1521
1522 @node Temporaries
1523 @subsection Temporaries May Vanish Before You Expect
1524
1525 @cindex temporaries, lifetime of
1526 @cindex portions of temporary objects, pointers to
1527 It is dangerous to use pointers or references to @emph{portions} of a
1528 temporary object.  The compiler may very well delete the object before
1529 you expect it to, leaving a pointer to garbage.  The most common place
1530 where this problem crops up is in classes like string classes,
1531 especially ones that define a conversion function to type @code{char *}
1532 or @code{const char *}---which is one reason why the standard
1533 @code{string} class requires you to call the @code{c_str} member
1534 function.  However, any class that returns a pointer to some internal
1535 structure is potentially subject to this problem.
1536
1537 For example, a program may use a function @code{strfunc} that returns
1538 @code{string} objects, and another function @code{charfunc} that
1539 operates on pointers to @code{char}:
1540
1541 @example
1542 string strfunc ();
1543 void charfunc (const char *);
1544
1545 void
1546 f ()
1547 @{
1548   const char *p = strfunc().c_str();
1549   @dots{}
1550   charfunc (p);
1551   @dots{}
1552   charfunc (p);
1553 @}
1554 @end example
1555
1556 @noindent
1557 In this situation, it may seem reasonable to save a pointer to the C
1558 string returned by the @code{c_str} member function and use that rather
1559 than call @code{c_str} repeatedly.  However, the temporary string
1560 created by the call to @code{strfunc} is destroyed after @code{p} is
1561 initialized, at which point @code{p} is left pointing to freed memory.
1562
1563 Code like this may run successfully under some other compilers,
1564 particularly obsolete cfront-based compilers that delete temporaries
1565 along with normal local variables.  However, the GNU C++ behavior is
1566 standard-conforming, so if your program depends on late destruction of
1567 temporaries it is not portable.
1568
1569 The safe way to write such code is to give the temporary a name, which
1570 forces it to remain until the end of the scope of the name.  For
1571 example:
1572
1573 @example
1574 string& tmp = strfunc ();
1575 charfunc (tmp.c_str ());
1576 @end example
1577
1578 @node Copy Assignment
1579 @subsection Implicit Copy-Assignment for Virtual Bases
1580
1581 When a base class is virtual, only one subobject of the base class
1582 belongs to each full object.  Also, the constructors and destructors are
1583 invoked only once, and called from the most-derived class.  However, such
1584 objects behave unspecified when being assigned.  For example:
1585
1586 @example
1587 struct Base@{
1588   char *name;
1589   Base(char *n) : name(strdup(n))@{@}
1590   Base& operator= (const Base& other)@{
1591    free (name);
1592    name = strdup (other.name);
1593   @}
1594 @};
1595
1596 struct A:virtual Base@{
1597   int val;
1598   A():Base("A")@{@}
1599 @};
1600
1601 struct B:virtual Base@{
1602   int bval;
1603   B():Base("B")@{@}
1604 @};
1605
1606 struct Derived:public A, public B@{
1607   Derived():Base("Derived")@{@}
1608 @};
1609
1610 void func(Derived &d1, Derived &d2)
1611 @{
1612   d1 = d2;
1613 @}
1614 @end example
1615
1616 The C++ standard specifies that @samp{Base::Base} is only called once
1617 when constructing or copy-constructing a Derived object.  It is
1618 unspecified whether @samp{Base::operator=} is called more than once when
1619 the implicit copy-assignment for Derived objects is invoked (as it is
1620 inside @samp{func} in the example).
1621
1622 g++ implements the ``intuitive'' algorithm for copy-assignment: assign all
1623 direct bases, then assign all members.  In that algorithm, the virtual
1624 base subobject can be encountered many times.  In the example, copying
1625 proceeds in the following order: @samp{val}, @samp{name} (via
1626 @code{strdup}), @samp{bval}, and @samp{name} again.
1627
1628 If application code relies on copy-assignment, a user-defined
1629 copy-assignment operator removes any uncertainties.  With such an
1630 operator, the application can define whether and how the virtual base
1631 subobject is assigned.
1632
1633 @node Protoize Caveats
1634 @section Caveats of using @command{protoize}
1635
1636 The conversion programs @command{protoize} and @command{unprotoize} can
1637 sometimes change a source file in a way that won't work unless you
1638 rearrange it.
1639
1640 @itemize @bullet
1641 @item
1642 @command{protoize} can insert references to a type name or type tag before
1643 the definition, or in a file where they are not defined.
1644
1645 If this happens, compiler error messages should show you where the new
1646 references are, so fixing the file by hand is straightforward.
1647
1648 @item
1649 There are some C constructs which @command{protoize} cannot figure out.
1650 For example, it can't determine argument types for declaring a
1651 pointer-to-function variable; this you must do by hand.  @command{protoize}
1652 inserts a comment containing @samp{???} each time it finds such a
1653 variable; so you can find all such variables by searching for this
1654 string.  ISO C does not require declaring the argument types of
1655 pointer-to-function types.
1656
1657 @item
1658 Using @command{unprotoize} can easily introduce bugs.  If the program
1659 relied on prototypes to bring about conversion of arguments, these
1660 conversions will not take place in the program without prototypes.
1661 One case in which you can be sure @command{unprotoize} is safe is when
1662 you are removing prototypes that were made with @command{protoize}; if
1663 the program worked before without any prototypes, it will work again
1664 without them.
1665
1666 @opindex Wconversion
1667 You can find all the places where this problem might occur by compiling
1668 the program with the @option{-Wconversion} option.  It prints a warning
1669 whenever an argument is converted.
1670
1671 @item
1672 Both conversion programs can be confused if there are macro calls in and
1673 around the text to be converted.  In other words, the standard syntax
1674 for a declaration or definition must not result from expanding a macro.
1675 This problem is inherent in the design of C and cannot be fixed.  If
1676 only a few functions have confusing macro calls, you can easily convert
1677 them manually.
1678
1679 @item
1680 @command{protoize} cannot get the argument types for a function whose
1681 definition was not actually compiled due to preprocessing conditionals.
1682 When this happens, @command{protoize} changes nothing in regard to such
1683 a function.  @command{protoize} tries to detect such instances and warn
1684 about them.
1685
1686 You can generally work around this problem by using @command{protoize} step
1687 by step, each time specifying a different set of @option{-D} options for
1688 compilation, until all of the functions have been converted.  There is
1689 no automatic way to verify that you have got them all, however.
1690
1691 @item
1692 Confusion may result if there is an occasion to convert a function
1693 declaration or definition in a region of source code where there is more
1694 than one formal parameter list present.  Thus, attempts to convert code
1695 containing multiple (conditionally compiled) versions of a single
1696 function header (in the same vicinity) may not produce the desired (or
1697 expected) results.
1698
1699 If you plan on converting source files which contain such code, it is
1700 recommended that you first make sure that each conditionally compiled
1701 region of source code which contains an alternative function header also
1702 contains at least one additional follower token (past the final right
1703 parenthesis of the function header).  This should circumvent the
1704 problem.
1705
1706 @item
1707 @command{unprotoize} can become confused when trying to convert a function
1708 definition or declaration which contains a declaration for a
1709 pointer-to-function formal argument which has the same name as the
1710 function being defined or declared.  We recommend you avoid such choices
1711 of formal parameter names.
1712
1713 @item
1714 You might also want to correct some of the indentation by hand and break
1715 long lines.  (The conversion programs don't write lines longer than
1716 eighty characters in any case.)
1717 @end itemize
1718
1719 @node Non-bugs
1720 @section Certain Changes We Don't Want to Make
1721
1722 This section lists changes that people frequently request, but which
1723 we do not make because we think GCC is better without them.
1724
1725 @itemize @bullet
1726 @item
1727 Checking the number and type of arguments to a function which has an
1728 old-fashioned definition and no prototype.
1729
1730 Such a feature would work only occasionally---only for calls that appear
1731 in the same file as the called function, following the definition.  The
1732 only way to check all calls reliably is to add a prototype for the
1733 function.  But adding a prototype eliminates the motivation for this
1734 feature.  So the feature is not worthwhile.
1735
1736 @item
1737 Warning about using an expression whose type is signed as a shift count.
1738
1739 Shift count operands are probably signed more often than unsigned.
1740 Warning about this would cause far more annoyance than good.
1741
1742 @item
1743 Warning about assigning a signed value to an unsigned variable.
1744
1745 Such assignments must be very common; warning about them would cause
1746 more annoyance than good.
1747
1748 @item
1749 Warning when a non-void function value is ignored.
1750
1751 Coming as I do from a Lisp background, I balk at the idea that there is
1752 something dangerous about discarding a value.  There are functions that
1753 return values which some callers may find useful; it makes no sense to
1754 clutter the program with a cast to @code{void} whenever the value isn't
1755 useful.
1756
1757 @item
1758 @opindex fshort-enums
1759 Making @option{-fshort-enums} the default.
1760
1761 This would cause storage layout to be incompatible with most other C
1762 compilers.  And it doesn't seem very important, given that you can get
1763 the same result in other ways.  The case where it matters most is when
1764 the enumeration-valued object is inside a structure, and in that case
1765 you can specify a field width explicitly.
1766
1767 @item
1768 Making bit-fields unsigned by default on particular machines where ``the
1769 ABI standard'' says to do so.
1770
1771 The ISO C standard leaves it up to the implementation whether a bit-field
1772 declared plain @code{int} is signed or not.  This in effect creates two
1773 alternative dialects of C@.
1774
1775 @opindex fsigned-bitfields
1776 @opindex funsigned-bitfields
1777 The GNU C compiler supports both dialects; you can specify the signed
1778 dialect with @option{-fsigned-bitfields} and the unsigned dialect with
1779 @option{-funsigned-bitfields}.  However, this leaves open the question of
1780 which dialect to use by default.
1781
1782 Currently, the preferred dialect makes plain bit-fields signed, because
1783 this is simplest.  Since @code{int} is the same as @code{signed int} in
1784 every other context, it is cleanest for them to be the same in bit-fields
1785 as well.
1786
1787 Some computer manufacturers have published Application Binary Interface
1788 standards which specify that plain bit-fields should be unsigned.  It is
1789 a mistake, however, to say anything about this issue in an ABI@.  This is
1790 because the handling of plain bit-fields distinguishes two dialects of C@.
1791 Both dialects are meaningful on every type of machine.  Whether a
1792 particular object file was compiled using signed bit-fields or unsigned
1793 is of no concern to other object files, even if they access the same
1794 bit-fields in the same data structures.
1795
1796 A given program is written in one or the other of these two dialects.
1797 The program stands a chance to work on most any machine if it is
1798 compiled with the proper dialect.  It is unlikely to work at all if
1799 compiled with the wrong dialect.
1800
1801 Many users appreciate the GNU C compiler because it provides an
1802 environment that is uniform across machines.  These users would be
1803 inconvenienced if the compiler treated plain bit-fields differently on
1804 certain machines.
1805
1806 Occasionally users write programs intended only for a particular machine
1807 type.  On these occasions, the users would benefit if the GNU C compiler
1808 were to support by default the same dialect as the other compilers on
1809 that machine.  But such applications are rare.  And users writing a
1810 program to run on more than one type of machine cannot possibly benefit
1811 from this kind of compatibility.
1812
1813 This is why GCC does and will treat plain bit-fields in the same
1814 fashion on all types of machines (by default).
1815
1816 There are some arguments for making bit-fields unsigned by default on all
1817 machines.  If, for example, this becomes a universal de facto standard,
1818 it would make sense for GCC to go along with it.  This is something
1819 to be considered in the future.
1820
1821 (Of course, users strongly concerned about portability should indicate
1822 explicitly in each bit-field whether it is signed or not.  In this way,
1823 they write programs which have the same meaning in both C dialects.)
1824
1825 @item
1826 @opindex ansi
1827 @opindex traditional
1828 @opindex std
1829 Undefining @code{__STDC__} when @option{-ansi} is not used.
1830
1831 Currently, GCC defines @code{__STDC__} as long as you don't use
1832 @option{-traditional}.  This provides good results in practice.
1833
1834 Programmers normally use conditionals on @code{__STDC__} to ask whether
1835 it is safe to use certain features of ISO C, such as function
1836 prototypes or ISO token concatenation.  Since plain @command{gcc} supports
1837 all the features of ISO C, the correct answer to these questions is
1838 ``yes''.
1839
1840 Some users try to use @code{__STDC__} to check for the availability of
1841 certain library facilities.  This is actually incorrect usage in an ISO
1842 C program, because the ISO C standard says that a conforming
1843 freestanding implementation should define @code{__STDC__} even though it
1844 does not have the library facilities.  @samp{gcc -ansi -pedantic} is a
1845 conforming freestanding implementation, and it is therefore required to
1846 define @code{__STDC__}, even though it does not come with an ISO C
1847 library.
1848
1849 Sometimes people say that defining @code{__STDC__} in a compiler that
1850 does not completely conform to the ISO C standard somehow violates the
1851 standard.  This is illogical.  The standard is a standard for compilers
1852 that claim to support ISO C, such as @samp{gcc -ansi}---not for other
1853 compilers such as plain @command{gcc}.  Whatever the ISO C standard says
1854 is relevant to the design of plain @command{gcc} without @option{-ansi} only
1855 for pragmatic reasons, not as a requirement.
1856
1857 GCC normally defines @code{__STDC__} to be 1, and in addition
1858 defines @code{__STRICT_ANSI__} if you specify the @option{-ansi} option,
1859 or a @option{-std} option for strict conformance to some version of ISO C@.
1860 On some hosts, system include files use a different convention, where
1861 @code{__STDC__} is normally 0, but is 1 if the user specifies strict
1862 conformance to the C Standard.  GCC follows the host convention when
1863 processing system include files, but when processing user files it follows
1864 the usual GNU C convention.
1865
1866 @item
1867 Undefining @code{__STDC__} in C++.
1868
1869 Programs written to compile with C++-to-C translators get the
1870 value of @code{__STDC__} that goes with the C compiler that is
1871 subsequently used.  These programs must test @code{__STDC__}
1872 to determine what kind of C preprocessor that compiler uses:
1873 whether they should concatenate tokens in the ISO C fashion
1874 or in the traditional fashion.
1875
1876 These programs work properly with GNU C++ if @code{__STDC__} is defined.
1877 They would not work otherwise.
1878
1879 In addition, many header files are written to provide prototypes in ISO
1880 C but not in traditional C@.  Many of these header files can work without
1881 change in C++ provided @code{__STDC__} is defined.  If @code{__STDC__}
1882 is not defined, they will all fail, and will all need to be changed to
1883 test explicitly for C++ as well.
1884
1885 @item
1886 Deleting ``empty'' loops.
1887
1888 Historically, GCC has not deleted ``empty'' loops under the
1889 assumption that the most likely reason you would put one in a program is
1890 to have a delay, so deleting them will not make real programs run any
1891 faster.
1892
1893 However, the rationale here is that optimization of a nonempty loop
1894 cannot produce an empty one, which holds for C but is not always the
1895 case for C++.
1896
1897 @opindex funroll-loops
1898 Moreover, with @option{-funroll-loops} small ``empty'' loops are already
1899 removed, so the current behavior is both sub-optimal and inconsistent
1900 and will change in the future.
1901
1902 @item
1903 Making side effects happen in the same order as in some other compiler.
1904
1905 @cindex side effects, order of evaluation
1906 @cindex order of evaluation, side effects
1907 It is never safe to depend on the order of evaluation of side effects.
1908 For example, a function call like this may very well behave differently
1909 from one compiler to another:
1910
1911 @example
1912 void func (int, int);
1913
1914 int i = 2;
1915 func (i++, i++);
1916 @end example
1917
1918 There is no guarantee (in either the C or the C++ standard language
1919 definitions) that the increments will be evaluated in any particular
1920 order.  Either increment might happen first.  @code{func} might get the
1921 arguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}.
1922
1923 @item
1924 Not allowing structures with volatile fields in registers.
1925
1926 Strictly speaking, there is no prohibition in the ISO C standard
1927 against allowing structures with volatile fields in registers, but
1928 it does not seem to make any sense and is probably not what you wanted
1929 to do.  So the compiler will give an error message in this case.
1930
1931 @item
1932 Making certain warnings into errors by default.
1933
1934 Some ISO C testsuites report failure when the compiler does not produce
1935 an error message for a certain program.
1936
1937 @opindex pedantic-errors
1938 ISO C requires a ``diagnostic'' message for certain kinds of invalid
1939 programs, but a warning is defined by GCC to count as a diagnostic.  If
1940 GCC produces a warning but not an error, that is correct ISO C support.
1941 If test suites call this ``failure'', they should be run with the GCC
1942 option @option{-pedantic-errors}, which will turn these warnings into
1943 errors.
1944
1945 @end itemize
1946
1947 @node Warnings and Errors
1948 @section Warning Messages and Error Messages
1949
1950 @cindex error messages
1951 @cindex warnings vs errors
1952 @cindex messages, warning and error
1953 The GNU compiler can produce two kinds of diagnostics: errors and
1954 warnings.  Each kind has a different purpose:
1955
1956 @itemize @w{}
1957 @item
1958 @dfn{Errors} report problems that make it impossible to compile your
1959 program.  GCC reports errors with the source file name and line
1960 number where the problem is apparent.
1961
1962 @item
1963 @dfn{Warnings} report other unusual conditions in your code that
1964 @emph{may} indicate a problem, although compilation can (and does)
1965 proceed.  Warning messages also report the source file name and line
1966 number, but include the text @samp{warning:} to distinguish them
1967 from error messages.
1968 @end itemize
1969
1970 Warnings may indicate danger points where you should check to make sure
1971 that your program really does what you intend; or the use of obsolete
1972 features; or the use of nonstandard features of GNU C or C++.  Many
1973 warnings are issued only if you ask for them, with one of the @option{-W}
1974 options (for instance, @option{-Wall} requests a variety of useful
1975 warnings).
1976
1977 @opindex pedantic
1978 @opindex pedantic-errors
1979 GCC always tries to compile your program if possible; it never
1980 gratuitously rejects a program whose meaning is clear merely because
1981 (for instance) it fails to conform to a standard.  In some cases,
1982 however, the C and C++ standards specify that certain extensions are
1983 forbidden, and a diagnostic @emph{must} be issued by a conforming
1984 compiler.  The @option{-pedantic} option tells GCC to issue warnings in
1985 such cases; @option{-pedantic-errors} says to make them errors instead.
1986 This does not mean that @emph{all} non-ISO constructs get warnings
1987 or errors.
1988
1989 @xref{Warning Options,,Options to Request or Suppress Warnings}, for
1990 more detail on these and related command-line options.
1991
1992 @node Bugs
1993 @chapter Reporting Bugs
1994 @cindex bugs
1995 @cindex reporting bugs
1996
1997 Your bug reports play an essential role in making GCC reliable.
1998
1999 When you encounter a problem, the first thing to do is to see if it is
2000 already known.  @xref{Trouble}.  If it isn't known, then you should
2001 report the problem.
2002
2003 Reporting a bug may help you by bringing a solution to your problem, or
2004 it may not.  (If it does not, look in the service directory; see
2005 @ref{Service}.)  In any case, the principal function of a bug report is
2006 to help the entire community by making the next version of GCC work
2007 better.  Bug reports are your contribution to the maintenance of GCC@.
2008
2009 Since the maintainers are very overloaded, we cannot respond to every
2010 bug report.  However, if the bug has not been fixed, we are likely to
2011 send you a patch and ask you to tell us whether it works.
2012
2013 In order for a bug report to serve its purpose, you must include the
2014 information that makes for fixing the bug.
2015
2016 @menu
2017 * Criteria:  Bug Criteria.   Have you really found a bug?
2018 * Where: Bug Lists.          Where to send your bug report.
2019 * Reporting: Bug Reporting.  How to report a bug effectively.
2020 * GNATS: gccbug.             You can use a bug reporting tool.
2021 * Patches: Sending Patches.  How to send a patch for GCC.
2022 * Known: Trouble.            Known problems.
2023 * Help: Service.             Where to ask for help.
2024 @end menu
2025
2026 @node Bug Criteria,Bug Lists,,Bugs
2027 @section Have You Found a Bug?
2028 @cindex bug criteria
2029
2030 If you are not sure whether you have found a bug, here are some guidelines:
2031
2032 @itemize @bullet
2033 @cindex fatal signal
2034 @cindex core dump
2035 @item
2036 If the compiler gets a fatal signal, for any input whatever, that is a
2037 compiler bug.  Reliable compilers never crash.
2038
2039 @cindex invalid assembly code
2040 @cindex assembly code, invalid
2041 @item
2042 If the compiler produces invalid assembly code, for any input whatever
2043 (except an @code{asm} statement), that is a compiler bug, unless the
2044 compiler reports errors (not just warnings) which would ordinarily
2045 prevent the assembler from being run.
2046
2047 @cindex undefined behavior
2048 @cindex undefined function value
2049 @cindex increment operators
2050 @item
2051 If the compiler produces valid assembly code that does not correctly
2052 execute the input source code, that is a compiler bug.
2053
2054 However, you must double-check to make sure, because you may have run
2055 into an incompatibility between GNU C and traditional C
2056 (@pxref{Incompatibilities}).  These incompatibilities might be considered
2057 bugs, but they are inescapable consequences of valuable features.
2058
2059 Or you may have a program whose behavior is undefined, which happened
2060 by chance to give the desired results with another C or C++ compiler.
2061
2062 For example, in many nonoptimizing compilers, you can write @samp{x;}
2063 at the end of a function instead of @samp{return x;}, with the same
2064 results.  But the value of the function is undefined if @code{return}
2065 is omitted; it is not a bug when GCC produces different results.
2066
2067 Problems often result from expressions with two increment operators,
2068 as in @code{f (*p++, *p++)}.  Your previous compiler might have
2069 interpreted that expression the way you intended; GCC might
2070 interpret it another way.  Neither compiler is wrong.  The bug is
2071 in your code.
2072
2073 After you have localized the error to a single source line, it should
2074 be easy to check for these things.  If your program is correct and
2075 well defined, you have found a compiler bug.
2076
2077 @item
2078 If the compiler produces an error message for valid input, that is a
2079 compiler bug.
2080
2081 @cindex invalid input
2082 @item
2083 If the compiler does not produce an error message for invalid input,
2084 that is a compiler bug.  However, you should note that your idea of
2085 ``invalid input'' might be my idea of ``an extension'' or ``support
2086 for traditional practice''.
2087
2088 @item
2089 If you are an experienced user of one of the languages GCC supports, your
2090 suggestions for improvement of GCC are welcome in any case.
2091 @end itemize
2092
2093 @node Bug Lists,Bug Reporting,Bug Criteria,Bugs
2094 @section Where to Report Bugs
2095 @cindex bug report mailing lists
2096 @kindex gcc-bugs@@gcc.gnu.org or bug-gcc@@gnu.org
2097 Send bug reports for the GNU Compiler Collection to
2098 @email{gcc-bugs@@gcc.gnu.org}.  In accordance with the GNU-wide
2099 convention, in which bug reports for tool ``foo'' are sent
2100 to @samp{bug-foo@@gnu.org}, the address @email{bug-gcc@@gnu.org}
2101 may also be used; it will forward to the address given above.
2102
2103 Please read @uref{http://gcc.gnu.org/bugs.html} for additional and/or
2104 more up-to-date bug reporting instructions before you post a bug report.
2105
2106 @node Bug Reporting,gccbug,Bug Lists,Bugs
2107 @section How to Report Bugs
2108 @cindex compiler bugs, reporting
2109
2110 The fundamental principle of reporting bugs usefully is this:
2111 @strong{report all the facts}.  If you are not sure whether to state a
2112 fact or leave it out, state it!
2113
2114 Often people omit facts because they think they know what causes the
2115 problem and they conclude that some details don't matter.  Thus, you might
2116 assume that the name of the variable you use in an example does not matter.
2117 Well, probably it doesn't, but one cannot be sure.  Perhaps the bug is a
2118 stray memory reference which happens to fetch from the location where that
2119 name is stored in memory; perhaps, if the name were different, the contents
2120 of that location would fool the compiler into doing the right thing despite
2121 the bug.  Play it safe and give a specific, complete example.  That is the
2122 easiest thing for you to do, and the most helpful.
2123
2124 Keep in mind that the purpose of a bug report is to enable someone to
2125 fix the bug if it is not known.  It isn't very important what happens if
2126 the bug is already known.  Therefore, always write your bug reports on
2127 the assumption that the bug is not known.
2128
2129 Sometimes people give a few sketchy facts and ask, ``Does this ring a
2130 bell?''  This cannot help us fix a bug, so it is basically useless.  We
2131 respond by asking for enough details to enable us to investigate.
2132 You might as well expedite matters by sending them to begin with.
2133
2134 Try to make your bug report self-contained.  If we have to ask you for
2135 more information, it is best if you include all the previous information
2136 in your response, as well as the information that was missing.
2137
2138 Please report each bug in a separate message.  This makes it easier for
2139 us to track which bugs have been fixed and to forward your bugs reports
2140 to the appropriate maintainer.
2141
2142 To enable someone to investigate the bug, you should include all these
2143 things:
2144
2145 @itemize @bullet
2146 @item
2147 The version of GCC@.  You can get this by running it with the
2148 @option{-v} option.
2149
2150 Without this, we won't know whether there is any point in looking for
2151 the bug in the current version of GCC@.
2152
2153 @item
2154 A complete input file that will reproduce the bug.  If the bug is in the
2155 C preprocessor, send a source file and any header files that it
2156 requires.  If the bug is in the compiler proper (@file{cc1}), send the
2157 preprocessor output generated by adding @option{-save-temps} to the
2158 compilation command (@pxref{Debugging Options}).  When you do this, use
2159 the same @option{-I}, @option{-D} or @option{-U} options that you used in
2160 actual compilation.  Then send the @var{input}.i or @var{input}.ii files
2161 generated.
2162
2163 A single statement is not enough of an example.  In order to compile it,
2164 it must be embedded in a complete file of compiler input; and the bug
2165 might depend on the details of how this is done.
2166
2167 Without a real example one can compile, all anyone can do about your bug
2168 report is wish you luck.  It would be futile to try to guess how to
2169 provoke the bug.  For example, bugs in register allocation and reloading
2170 frequently depend on every little detail of the function they happen in.
2171
2172 Even if the input file that fails comes from a GNU program, you should
2173 still send the complete test case.  Don't ask the GCC maintainers to
2174 do the extra work of obtaining the program in question---they are all
2175 overworked as it is.  Also, the problem may depend on what is in the
2176 header files on your system; it is unreliable for the GCC maintainers
2177 to try the problem with the header files available to them.  By sending
2178 CPP output, you can eliminate this source of uncertainty and save us
2179 a certain percentage of wild goose chases.
2180
2181 @item
2182 The command arguments you gave GCC to compile that example
2183 and observe the bug.  For example, did you use @option{-O}?  To guarantee
2184 you won't omit something important, list all the options.
2185
2186 If we were to try to guess the arguments, we would probably guess wrong
2187 and then we would not encounter the bug.
2188
2189 @item
2190 The type of machine you are using, and the operating system name and
2191 version number.
2192
2193 @item
2194 The operands you gave to the @code{configure} command when you installed
2195 the compiler.
2196
2197 @item
2198 A complete list of any modifications you have made to the compiler
2199 source.  (We don't promise to investigate the bug unless it happens in
2200 an unmodified compiler.  But if you've made modifications and don't tell
2201 us, then you are sending us on a wild goose chase.)
2202
2203 Be precise about these changes.  A description in English is not
2204 enough---send a context diff for them.
2205
2206 Adding files of your own (such as a machine description for a machine we
2207 don't support) is a modification of the compiler source.
2208
2209 @item
2210 Details of any other deviations from the standard procedure for installing
2211 GCC@.
2212
2213 @item
2214 A description of what behavior you observe that you believe is
2215 incorrect.  For example, ``The compiler gets a fatal signal,'' or,
2216 ``The assembler instruction at line 208 in the output is incorrect.''
2217
2218 Of course, if the bug is that the compiler gets a fatal signal, then one
2219 can't miss it.  But if the bug is incorrect output, the maintainer might
2220 not notice unless it is glaringly wrong.  None of us has time to study
2221 all the assembler code from a 50-line C program just on the chance that
2222 one instruction might be wrong.  We need @emph{you} to do this part!
2223
2224 Even if the problem you experience is a fatal signal, you should still
2225 say so explicitly.  Suppose something strange is going on, such as, your
2226 copy of the compiler is out of synch, or you have encountered a bug in
2227 the C library on your system.  (This has happened!)  Your copy might
2228 crash and the copy here would not.  If you @i{said} to expect a crash,
2229 then when the compiler here fails to crash, we would know that the bug
2230 was not happening.  If you don't say to expect a crash, then we would
2231 not know whether the bug was happening.  We would not be able to draw
2232 any conclusion from our observations.
2233
2234 If the problem is a diagnostic when compiling GCC with some other
2235 compiler, say whether it is a warning or an error.
2236
2237 Often the observed symptom is incorrect output when your program is run.
2238 Sad to say, this is not enough information unless the program is short
2239 and simple.  None of us has time to study a large program to figure out
2240 how it would work if compiled correctly, much less which line of it was
2241 compiled wrong.  So you will have to do that.  Tell us which source line
2242 it is, and what incorrect result happens when that line is executed.  A
2243 person who understands the program can find this as easily as finding a
2244 bug in the program itself.
2245
2246 @item
2247 If you send examples of assembler code output from GCC,
2248 please use @option{-g} when you make them.  The debugging information
2249 includes source line numbers which are essential for correlating the
2250 output with the input.
2251
2252 @item
2253 If you wish to mention something in the GCC source, refer to it by
2254 context, not by line number.
2255
2256 The line numbers in the development sources don't match those in your
2257 sources.  Your line numbers would convey no useful information to the
2258 maintainers.
2259
2260 @item
2261 Additional information from a debugger might enable someone to find a
2262 problem on a machine which he does not have available.  However, you
2263 need to think when you collect this information if you want it to have
2264 any chance of being useful.
2265
2266 @cindex backtrace for bug reports
2267 For example, many people send just a backtrace, but that is never
2268 useful by itself.  A simple backtrace with arguments conveys little
2269 about GCC because the compiler is largely data-driven; the same
2270 functions are called over and over for different RTL insns, doing
2271 different things depending on the details of the insn.
2272
2273 Most of the arguments listed in the backtrace are useless because they
2274 are pointers to RTL list structure.  The numeric values of the
2275 pointers, which the debugger prints in the backtrace, have no
2276 significance whatever; all that matters is the contents of the objects
2277 they point to (and most of the contents are other such pointers).
2278
2279 In addition, most compiler passes consist of one or more loops that
2280 scan the RTL insn sequence.  The most vital piece of information about
2281 such a loop---which insn it has reached---is usually in a local variable,
2282 not in an argument.
2283
2284 @findex debug_rtx
2285 What you need to provide in addition to a backtrace are the values of
2286 the local variables for several stack frames up.  When a local
2287 variable or an argument is an RTX, first print its value and then use
2288 the GDB command @code{pr} to print the RTL expression that it points
2289 to.  (If GDB doesn't run on your machine, use your debugger to call
2290 the function @code{debug_rtx} with the RTX as an argument.)  In
2291 general, whenever a variable is a pointer, its value is no use
2292 without the data it points to.
2293 @end itemize
2294
2295 Here are some things that are not necessary:
2296
2297 @itemize @bullet
2298 @item
2299 A description of the envelope of the bug.
2300
2301 Often people who encounter a bug spend a lot of time investigating
2302 which changes to the input file will make the bug go away and which
2303 changes will not affect it.
2304
2305 This is often time consuming and not very useful, because the way we
2306 will find the bug is by running a single example under the debugger with
2307 breakpoints, not by pure deduction from a series of examples.  You might
2308 as well save your time for something else.
2309
2310 Of course, if you can find a simpler example to report @emph{instead} of
2311 the original one, that is a convenience.  Errors in the output will be
2312 easier to spot, running under the debugger will take less time, etc.
2313 Most GCC bugs involve just one function, so the most straightforward
2314 way to simplify an example is to delete all the function definitions
2315 except the one where the bug occurs.  Those earlier in the file may be
2316 replaced by external declarations if the crucial function depends on
2317 them.  (Exception: inline functions may affect compilation of functions
2318 defined later in the file.)
2319
2320 However, simplification is not vital; if you don't want to do this,
2321 report the bug anyway and send the entire test case you used.
2322
2323 @item
2324 In particular, some people insert conditionals @samp{#ifdef BUG} around
2325 a statement which, if removed, makes the bug not happen.  These are just
2326 clutter; we won't pay any attention to them anyway.  Besides, you should
2327 send us cpp output, and that can't have conditionals.
2328
2329 @item
2330 A patch for the bug.
2331
2332 A patch for the bug is useful if it is a good one.  But don't omit the
2333 necessary information, such as the test case, on the assumption that a
2334 patch is all we need.  We might see problems with your patch and decide
2335 to fix the problem another way, or we might not understand it at all.
2336
2337 Sometimes with a program as complicated as GCC it is very hard to
2338 construct an example that will make the program follow a certain path
2339 through the code.  If you don't send the example, we won't be able to
2340 construct one, so we won't be able to verify that the bug is fixed.
2341
2342 And if we can't understand what bug you are trying to fix, or why your
2343 patch should be an improvement, we won't install it.  A test case will
2344 help us to understand.
2345
2346 @xref{Sending Patches}, for guidelines on how to make it easy for us to
2347 understand and install your patches.
2348
2349 @item
2350 A guess about what the bug is or what it depends on.
2351
2352 Such guesses are usually wrong.  Even I can't guess right about such
2353 things without first using the debugger to find the facts.
2354
2355 @item
2356 A core dump file.
2357
2358 We have no way of examining a core dump for your type of machine
2359 unless we have an identical system---and if we do have one,
2360 we should be able to reproduce the crash ourselves.
2361 @end itemize
2362
2363 @node gccbug,Sending Patches, Bug Reporting, Bugs
2364 @section The gccbug script
2365 @cindex gccbug script
2366
2367 To simplify creation of bug reports, and to allow better tracking of
2368 reports, we use the GNATS bug tracking system.  Part of that system is
2369 the @code{gccbug} script.  This is a Unix shell script, so you need a
2370 shell to run it.  It is normally installed in the same directory where
2371 @code{gcc} is installed.
2372
2373 The gccbug script is derived from send-pr, @pxref{using
2374 send-pr,,Creating new Problem Reports,send-pr,Reporting Problems}.  When
2375 invoked, it starts a text editor so you can fill out the various fields
2376 of the report.  When the you quit the editor, the report is automatically
2377 send to the bug reporting address.
2378
2379 A number of fields in this bug report form are specific to GCC, and are
2380 explained at @uref{http://gcc.gnu.org/gnats.html}.
2381
2382 @node Sending Patches,, gccbug, Bugs
2383 @section Sending Patches for GCC
2384
2385 If you would like to write bug fixes or improvements for the GNU C
2386 compiler, that is very helpful.  Send suggested fixes to the patches
2387 mailing list, @email{gcc-patches@@gcc.gnu.org}.
2388
2389 Please follow these guidelines so we can study your patches efficiently.
2390 If you don't follow these guidelines, your information might still be
2391 useful, but using it will take extra work.  Maintaining GCC is a lot
2392 of work in the best of circumstances, and we can't keep up unless you do
2393 your best to help.
2394
2395 @itemize @bullet
2396 @item
2397 Send an explanation with your changes of what problem they fix or what
2398 improvement they bring about.  For a bug fix, just include a copy of the
2399 bug report, and explain why the change fixes the bug.
2400
2401 (Referring to a bug report is not as good as including it, because then
2402 we will have to look it up, and we have probably already deleted it if
2403 we've already fixed the bug.)
2404
2405 @item
2406 Always include a proper bug report for the problem you think you have
2407 fixed.  We need to convince ourselves that the change is right before
2408 installing it.  Even if it is right, we might have trouble judging it if
2409 we don't have a way to reproduce the problem.
2410
2411 @item
2412 Include all the comments that are appropriate to help people reading the
2413 source in the future understand why this change was needed.
2414
2415 @item
2416 Don't mix together changes made for different reasons.
2417 Send them @emph{individually}.
2418
2419 If you make two changes for separate reasons, then we might not want to
2420 install them both.  We might want to install just one.  If you send them
2421 all jumbled together in a single set of diffs, we have to do extra work
2422 to disentangle them---to figure out which parts of the change serve
2423 which purpose.  If we don't have time for this, we might have to ignore
2424 your changes entirely.
2425
2426 If you send each change as soon as you have written it, with its own
2427 explanation, then the two changes never get tangled up, and we can
2428 consider each one properly without any extra work to disentangle them.
2429
2430 Ideally, each change you send should be impossible to subdivide into
2431 parts that we might want to consider separately, because each of its
2432 parts gets its motivation from the other parts.
2433
2434 @item
2435 Send each change as soon as that change is finished.  Sometimes people
2436 think they are helping us by accumulating many changes to send them all
2437 together.  As explained above, this is absolutely the worst thing you
2438 could do.
2439
2440 Since you should send each change separately, you might as well send it
2441 right away.  That gives us the option of installing it immediately if it
2442 is important.
2443
2444 @item
2445 Use @samp{diff -c} to make your diffs.  Diffs without context are hard
2446 for us to install reliably.  More than that, they make it hard for us to
2447 study the diffs to decide whether we want to install them.  Unidiff
2448 format is better than contextless diffs, but not as easy to read as
2449 @option{-c} format.
2450
2451 If you have GNU diff, use @samp{diff -cp}, which shows the name of the
2452 function that each change occurs in.
2453
2454 @item
2455 Write the change log entries for your changes.  We get lots of changes,
2456 and we don't have time to do all the change log writing ourselves.
2457
2458 Read the @file{ChangeLog} file to see what sorts of information to put
2459 in, and to learn the style that we use.  The purpose of the change log
2460 is to show people where to find what was changed.  So you need to be
2461 specific about what functions you changed; in large functions, it's
2462 often helpful to indicate where within the function the change was.
2463
2464 On the other hand, once you have shown people where to find the change,
2465 you need not explain its purpose.  Thus, if you add a new function, all
2466 you need to say about it is that it is new.  If you feel that the
2467 purpose needs explaining, it probably does---but the explanation will be
2468 much more useful if you put it in comments in the code.
2469
2470 If you would like your name to appear in the header line for who made
2471 the change, send us the header line.
2472
2473 @item
2474 When you write the fix, keep in mind that we can't install a change that
2475 would break other systems.
2476
2477 People often suggest fixing a problem by changing machine-independent
2478 files such as @file{toplev.c} to do something special that a particular
2479 system needs.  Sometimes it is totally obvious that such changes would
2480 break GCC for almost all users.  We can't possibly make a change like
2481 that.  At best it might tell us how to write another patch that would
2482 solve the problem acceptably.
2483
2484 Sometimes people send fixes that @emph{might} be an improvement in
2485 general---but it is hard to be sure of this.  It's hard to install
2486 such changes because we have to study them very carefully.  Of course,
2487 a good explanation of the reasoning by which you concluded the change
2488 was correct can help convince us.
2489
2490 The safest changes are changes to the configuration files for a
2491 particular machine.  These are safe because they can't create new bugs
2492 on other machines.
2493
2494 Please help us keep up with the workload by designing the patch in a
2495 form that is good to install.
2496 @end itemize
2497
2498 @node Service
2499 @chapter How To Get Help with GCC
2500
2501 If you need help installing, using or changing GCC, there are two
2502 ways to find it:
2503
2504 @itemize @bullet
2505 @item
2506 Send a message to a suitable network mailing list.  First try
2507 @email{gcc-help@@gcc.gnu.org} (for help installing or using GCC), and if
2508 that brings no response, try @email{gcc@@gcc.gnu.org}.  For help
2509 changing GCC, ask @email{gcc@@gcc.gnu.org}.  If you think you have found
2510 a bug in GCC, please report it following the instructions at
2511 @pxref{Bug Reporting}.
2512
2513 @item
2514 Look in the service directory for someone who might help you for a fee.
2515 The service directory is found at
2516 @uref{http://www.gnu.org/prep/service.html}.
2517 @end itemize
2518
2519 @c For further information, see
2520 @c @uref{http://gcc.gnu.org/cgi-bin/fom.cgi?file=12}.
2521 @c FIXME: this URL may be too volatile, this FAQ entry needs to move to
2522 @c the regular web pages before we can uncomment the reference.
2523
2524 @node Contributing
2525 @chapter Contributing to GCC Development
2526
2527 If you would like to help pretest GCC releases to assure they work well,
2528 our current development sources are available by CVS (see
2529 @uref{http://gcc.gnu.org/cvs.html}).  Source and binary snapshots are
2530 also available for FTP; see @uref{http://gcc.gnu.org/snapshots.html}.
2531
2532 If you would like to work on improvements to GCC, please read the
2533 advice at these URLs:
2534
2535 @smallexample
2536 @uref{http://gcc.gnu.org/contribute.html} 
2537 @uref{http://gcc.gnu.org/contributewhy.html}
2538 @end smallexample
2539
2540 @noindent
2541 for information on how to make useful contributions and avoid
2542 duplication of effort.  Suggested projects are listed at
2543 @uref{http://gcc.gnu.org/projects/}.
2544
2545 @node VMS
2546 @chapter Using GCC on VMS
2547
2548 @c prevent bad page break with this line
2549 Here is how to use GCC on VMS@.
2550
2551 @menu
2552 * Include Files and VMS::  Where the preprocessor looks for the include files.
2553 * Global Declarations::    How to do globaldef, globalref and globalvalue with
2554                            GCC.
2555 * VMS Misc::               Misc information.
2556 @end menu
2557
2558 @node Include Files and VMS
2559 @section Include Files and VMS
2560
2561 @cindex include files and VMS
2562 @cindex VMS and include files
2563 @cindex header files and VMS
2564 Due to the differences between the filesystems of Unix and VMS, GCC
2565 attempts to translate file names in @samp{#include} into names that VMS
2566 will understand.  The basic strategy is to prepend a prefix to the
2567 specification of the include file, convert the whole filename to a VMS
2568 filename, and then try to open the file.  GCC tries various prefixes
2569 one by one until one of them succeeds:
2570
2571 @enumerate
2572 @item
2573 The first prefix is the @samp{GNU_CC_INCLUDE:} logical name: this is
2574 where GNU C header files are traditionally stored.  If you wish to store
2575 header files in non-standard locations, then you can assign the logical
2576 @samp{GNU_CC_INCLUDE} to be a search list, where each element of the
2577 list is suitable for use with a rooted logical.
2578
2579 @item
2580 The next prefix tried is @samp{SYS$SYSROOT:[SYSLIB.]}.  This is where
2581 VAX-C header files are traditionally stored.
2582
2583 @item
2584 If the include file specification by itself is a valid VMS filename, the
2585 preprocessor then uses this name with no prefix in an attempt to open
2586 the include file.
2587
2588 @item
2589 If the file specification is not a valid VMS filename (i.e.@: does not
2590 contain a device or a directory specifier, and contains a @samp{/}
2591 character), the preprocessor tries to convert it from Unix syntax to
2592 VMS syntax.
2593
2594 Conversion works like this: the first directory name becomes a device,
2595 and the rest of the directories are converted into VMS-format directory
2596 names.  For example, the name @file{X11/foobar.h} is
2597 translated to @file{X11:[000000]foobar.h} or @file{X11:foobar.h},
2598 whichever one can be opened.  This strategy allows you to assign a
2599 logical name to point to the actual location of the header files.
2600
2601 @item
2602 If none of these strategies succeeds, the @samp{#include} fails.
2603 @end enumerate
2604
2605 Include directives of the form:
2606
2607 @example
2608 #include foobar
2609 @end example
2610
2611 @noindent
2612 are a common source of incompatibility between VAX-C and GCC@.  VAX-C
2613 treats this much like a standard @code{#include <foobar.h>} directive.
2614 That is incompatible with the ISO C behavior implemented by GCC: to
2615 expand the name @code{foobar} as a macro.  Macro expansion should
2616 eventually yield one of the two standard formats for @code{#include}:
2617
2618 @example
2619 #include "@var{file}"
2620 #include <@var{file}>
2621 @end example
2622
2623 If you have this problem, the best solution is to modify the source to
2624 convert the @code{#include} directives to one of the two standard forms.
2625 That will work with either compiler.  If you want a quick and dirty fix,
2626 define the file names as macros with the proper expansion, like this:
2627
2628 @example
2629 #define stdio <stdio.h>
2630 @end example
2631
2632 @noindent
2633 This will work, as long as the name doesn't conflict with anything else
2634 in the program.
2635
2636 Another source of incompatibility is that VAX-C assumes that:
2637
2638 @example
2639 #include "foobar"
2640 @end example
2641
2642 @noindent
2643 is actually asking for the file @file{foobar.h}.  GCC does not
2644 make this assumption, and instead takes what you ask for literally;
2645 it tries to read the file @file{foobar}.  The best way to avoid this
2646 problem is to always specify the desired file extension in your include
2647 directives.
2648
2649 GCC for VMS is distributed with a set of include files that is
2650 sufficient to compile most general purpose programs.  Even though the
2651 GCC distribution does not contain header files to define constants
2652 and structures for some VMS system-specific functions, there is no
2653 reason why you cannot use GCC with any of these functions.  You first
2654 may have to generate or create header files, either by using the public
2655 domain utility @code{UNSDL} (which can be found on a DECUS tape), or by
2656 extracting the relevant modules from one of the system macro libraries,
2657 and using an editor to construct a C header file.
2658
2659 A @code{#include} file name cannot contain a DECNET node name.  The
2660 preprocessor reports an I/O error if you attempt to use a node name,
2661 whether explicitly, or implicitly via a logical name.
2662
2663 @node Global Declarations
2664 @section Global Declarations and VMS
2665
2666 @findex GLOBALREF
2667 @findex GLOBALDEF
2668 @findex GLOBALVALUEDEF
2669 @findex GLOBALVALUEREF
2670 GCC does not provide the @code{globalref}, @code{globaldef} and
2671 @code{globalvalue} keywords of VAX-C@.  You can get the same effect with
2672 an obscure feature of GAS, the GNU assembler.  (This requires GAS
2673 version 1.39 or later.)  The following macros allow you to use this
2674 feature in a fairly natural way:
2675
2676 @smallexample
2677 #ifdef __GNUC__
2678 #define GLOBALREF(TYPE,NAME)                      \
2679   TYPE NAME                                       \
2680   asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME)
2681 #define GLOBALDEF(TYPE,NAME,VALUE)                \
2682   TYPE NAME                                       \
2683   asm ("_$$PsectAttributes_GLOBALSYMBOL$$" #NAME) \
2684     = VALUE
2685 #define GLOBALVALUEREF(TYPE,NAME)                 \
2686   const TYPE NAME[1]                              \
2687   asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)
2688 #define GLOBALVALUEDEF(TYPE,NAME,VALUE)           \
2689   const TYPE NAME[1]                              \
2690   asm ("_$$PsectAttributes_GLOBALVALUE$$" #NAME)  \
2691     = @{VALUE@}
2692 #else
2693 #define GLOBALREF(TYPE,NAME) \
2694   globalref TYPE NAME
2695 #define GLOBALDEF(TYPE,NAME,VALUE) \
2696   globaldef TYPE NAME = VALUE
2697 #define GLOBALVALUEDEF(TYPE,NAME,VALUE) \
2698   globalvalue TYPE NAME = VALUE
2699 #define GLOBALVALUEREF(TYPE,NAME) \
2700   globalvalue TYPE NAME
2701 #endif
2702 @end smallexample
2703
2704 @noindent
2705 (The @code{_$$PsectAttributes_GLOBALSYMBOL} prefix at the start of the
2706 name is removed by the assembler, after it has modified the attributes
2707 of the symbol).  These macros are provided in the VMS binaries
2708 distribution in a header file @file{GNU_HACKS.H}.  An example of the
2709 usage is:
2710
2711 @example
2712 GLOBALREF (int, ijk);
2713 GLOBALDEF (int, jkl, 0);
2714 @end example
2715
2716 The macros @code{GLOBALREF} and @code{GLOBALDEF} cannot be used
2717 straightforwardly for arrays, since there is no way to insert the array
2718 dimension into the declaration at the right place.  However, you can
2719 declare an array with these macros if you first define a typedef for the
2720 array type, like this:
2721
2722 @example
2723 typedef int intvector[10];
2724 GLOBALREF (intvector, foo);
2725 @end example
2726
2727 Array and structure initializers will also break the macros; you can
2728 define the initializer to be a macro of its own, or you can expand the
2729 @code{GLOBALDEF} macro by hand.  You may find a case where you wish to
2730 use the @code{GLOBALDEF} macro with a large array, but you are not
2731 interested in explicitly initializing each element of the array.  In
2732 such cases you can use an initializer like: @code{@{0,@}}, which will
2733 initialize the entire array to @code{0}.
2734
2735 A shortcoming of this implementation is that a variable declared with
2736 @code{GLOBALVALUEREF} or @code{GLOBALVALUEDEF} is always an array.  For
2737 example, the declaration:
2738
2739 @example
2740 GLOBALVALUEREF(int, ijk);
2741 @end example
2742
2743 @noindent
2744 declares the variable @code{ijk} as an array of type @code{int [1]}.
2745 This is done because a globalvalue is actually a constant; its ``value''
2746 is what the linker would normally consider an address.  That is not how
2747 an integer value works in C, but it is how an array works.  So treating
2748 the symbol as an array name gives consistent results---with the
2749 exception that the value seems to have the wrong type.  @strong{Don't
2750 try to access an element of the array.}  It doesn't have any elements.
2751 The array ``address'' may not be the address of actual storage.
2752
2753 The fact that the symbol is an array may lead to warnings where the
2754 variable is used.  Insert type casts to avoid the warnings.  Here is an
2755 example; it takes advantage of the ISO C feature allowing macros that
2756 expand to use the same name as the macro itself.
2757
2758 @example
2759 GLOBALVALUEREF (int, ss$_normal);
2760 GLOBALVALUEDEF (int, xyzzy,123);
2761 #ifdef __GNUC__
2762 #define ss$_normal ((int) ss$_normal)
2763 #define xyzzy ((int) xyzzy)
2764 #endif
2765 @end example
2766
2767 Don't use @code{globaldef} or @code{globalref} with a variable whose
2768 type is an enumeration type; this is not implemented.  Instead, make the
2769 variable an integer, and use a @code{globalvaluedef} for each of the
2770 enumeration values.  An example of this would be:
2771
2772 @example
2773 #ifdef __GNUC__
2774 GLOBALDEF (int, color, 0);
2775 GLOBALVALUEDEF (int, RED, 0);
2776 GLOBALVALUEDEF (int, BLUE, 1);
2777 GLOBALVALUEDEF (int, GREEN, 3);
2778 #else
2779 enum globaldef color @{RED, BLUE, GREEN = 3@};
2780 #endif
2781 @end example
2782
2783 @node VMS Misc
2784 @section Other VMS Issues
2785
2786 @cindex exit status and VMS
2787 @cindex return value of @code{main}
2788 @cindex @code{main} and the exit status
2789 GCC automatically arranges for @code{main} to return 1 by default if
2790 you fail to specify an explicit return value.  This will be interpreted
2791 by VMS as a status code indicating a normal successful completion.
2792 Version 1 of GCC did not provide this default.
2793
2794 GCC on VMS works only with the GNU assembler, GAS@.  You need version
2795 1.37 or later of GAS in order to produce value debugging information for
2796 the VMS debugger.  Use the ordinary VMS linker with the object files
2797 produced by GAS@.
2798
2799 @cindex shared VMS run time system
2800 @cindex @file{VAXCRTL}
2801 Under previous versions of GCC, the generated code would occasionally
2802 give strange results when linked to the sharable @file{VAXCRTL} library.
2803 Now this should work.
2804
2805 A caveat for use of @code{const} global variables: the @code{const}
2806 modifier must be specified in every external declaration of the variable
2807 in all of the source files that use that variable.  Otherwise the linker
2808 will issue warnings about conflicting attributes for the variable.  Your
2809 program will still work despite the warnings, but the variable will be
2810 placed in writable storage.
2811
2812 @cindex name augmentation
2813 @cindex case sensitivity and VMS
2814 @cindex VMS and case sensitivity
2815 Although the VMS linker does distinguish between upper and lower case
2816 letters in global symbols, most VMS compilers convert all such symbols
2817 into upper case and most run-time library routines also have upper case
2818 names.  To be able to reliably call such routines, GCC (by means of
2819 the assembler GAS) converts global symbols into upper case like other
2820 VMS compilers.  However, since the usual practice in C is to distinguish
2821 case, GCC (via GAS) tries to preserve usual C behavior by augmenting
2822 each name that is not all lower case.  This means truncating the name
2823 to at most 23 characters and then adding more characters at the end
2824 which encode the case pattern of those 23.   Names which contain at
2825 least one dollar sign are an exception; they are converted directly into
2826 upper case without augmentation.
2827
2828 Name augmentation yields bad results for programs that use precompiled
2829 libraries (such as Xlib) which were generated by another compiler.  You
2830 can use the compiler option @samp{/NOCASE_HACK} to inhibit augmentation;
2831 it makes external C functions and variables case-independent as is usual
2832 on VMS@.  Alternatively, you could write all references to the functions
2833 and variables in such libraries using lower case; this will work on VMS,
2834 but is not portable to other systems.  The compiler option @samp{/NAMES}
2835 also provides control over global name handling.
2836
2837 Function and variable names are handled somewhat differently with G++.
2838 The GNU C++ compiler performs @dfn{name mangling} on function
2839 names, which means that it adds information to the function name to
2840 describe the data types of the arguments that the function takes.  One
2841 result of this is that the name of a function can become very long.
2842 Since the VMS linker only recognizes the first 31 characters in a name,
2843 special action is taken to ensure that each function and variable has a
2844 unique name that can be represented in 31 characters.
2845
2846 If the name (plus a name augmentation, if required) is less than 32
2847 characters in length, then no special action is performed.  If the name
2848 is longer than 31 characters, the assembler (GAS) will generate a
2849 hash string based upon the function name, truncate the function name to
2850 23 characters, and append the hash string to the truncated name.  If the
2851 @samp{/VERBOSE} compiler option is used, the assembler will print both
2852 the full and truncated names of each symbol that is truncated.
2853
2854 The @samp{/NOCASE_HACK} compiler option should not be used when you are
2855 compiling programs that use libg++.  libg++ has several instances of
2856 objects (i.e.  @code{Filebuf} and @code{filebuf}) which become
2857 indistinguishable in a case-insensitive environment.  This leads to
2858 cases where you need to inhibit augmentation selectively (if you were
2859 using libg++ and Xlib in the same program, for example).  There is no
2860 special feature for doing this, but you can get the result by defining a
2861 macro for each mixed case symbol for which you wish to inhibit
2862 augmentation.  The macro should expand into the lower case equivalent of
2863 itself.  For example:
2864
2865 @example
2866 #define StuDlyCapS studlycaps
2867 @end example
2868
2869 These macro definitions can be placed in a header file to minimize the
2870 number of changes to your source code.
2871
2872 @node Makefile
2873 @chapter Additional Makefile and configure information.
2874
2875 @section Makefile Targets
2876 @cindex makefile targets
2877 @cindex targets, makefile
2878
2879 @table @code
2880 @item all
2881 This is the default target.  Depending on what your build/host/target
2882 configuration is, it coordinates all the things that need to be built.
2883
2884 @item doc
2885 Produce info-formatted documentation.  Also, @code{make dvi} is
2886 available for DVI-formatted documentation, and @code{make
2887 generated-manpages} to generate man pages.
2888
2889 @item mostlyclean
2890 Delete the files made while building the compiler.
2891
2892 @item clean
2893 That, and all the other files built by @code{make all}.
2894
2895 @item distclean
2896 That, and all the files created by @code{configure}.
2897
2898 @item extraclean
2899 That, and any temporary or intermediate files, like emacs backup files.
2900
2901 @item maintainer-clean
2902 Distclean plus any file that can be generated from other files.  Note
2903 that additional tools may be required beyond what is normally needed to
2904 build gcc.
2905
2906 @item install
2907 Installs gcc.
2908
2909 @item uninstall
2910 Deletes installed files.
2911
2912 @item check
2913 Run the testsuite.  This creates a @file{testsuite} subdirectory that
2914 has various @file{.sum} and @file{.log} files containing the results of
2915 the testing.  You can run subsets with, for example, @code{make check-gcc}.
2916 You can specify specific tests by setting RUNTESTFLAGS to be the name
2917 of the @file{.exp} file, optionally followed by (for some tests) an equals
2918 and a file wildcard, like:
2919
2920 @example
2921 make check-gcc RUNTESTFLAGS="execute.exp=19980413-*"
2922 @end example
2923
2924 Note that running the testsuite may require additional tools be
2925 installed, such as TCL or dejagnu.
2926
2927 @item bootstrap
2928 Builds gcc three times---once with the native compiler, once with the
2929 native-built compiler it just built, and once with the compiler it built
2930 the second time.  In theory, the last two should produce the same
2931 results, which @code{make compare} can check.  Each step of this process
2932 is called a ``stage'', and the results of each stage @var{N}
2933 (@var{N} = 1@dots{}3) are copied to a subdirectory @file{stage@var{N}/}.
2934
2935 @item bootstrap-lean
2936 Like @code{bootstrap}, except that the various stages are removed once
2937 they're no longer needed.  This saves disk space.
2938
2939 @item bubblestrap
2940 Once bootstrapped, this incrementally rebuilds each of the three stages,
2941 one at a time.  It does this by ``bubbling'' the stages up from their
2942 subdirectories, rebuilding them, and copying them back to their
2943 subdirectories.  This will allow you to, for example, quickly rebuild a
2944 bootstrapped compiler after changing the sources, without having to do a
2945 full bootstrap.
2946
2947 @item quickstrap
2948 Rebuilds the most recently built stage.  Since each stage requires
2949 special invocation, using this target means you don't have to keep track
2950 of which stage you're on or what invocation that stage needs.
2951
2952 @item cleanstrap
2953 Removed everything (@code{make clean}) and rebuilds (@code{make bootstrap}).
2954
2955 @item stage@var{N} (@var{N} = 1@dots{}4)
2956 For each stage, moves the appropriate files to the @file{stage@var{N}}
2957 subdirectory.
2958
2959 @item unstage@var{N} (@var{N} = 1@dots{}4)
2960 Undoes the corresponding @code{stage@var{N}}.
2961
2962 @item restage@var{N} (@var{N} = 1@dots{}4)
2963 Undoes the corresponding @code{stage@var{N}} and rebuilds it with the
2964 appropriate flags.
2965
2966 @item compare
2967 Compares the results of stages 2 and 3.  This ensures that the compiler
2968 is running properly, since it should produce the same object files
2969 regardless of how it itself was compiled.
2970
2971 @end table
2972
2973 @section Configure Terms and History
2974 @cindex configure terms
2975 @cindex canadian
2976
2977 This section is not instructions for building GCC.  If you are trying to
2978 do a build, you should first read @uref{http://gcc.gnu.org/install/} or
2979 whatever installation instructions came with your source package.
2980
2981 The configure and build process has a long and colorful history, and can
2982 be confusing to anyone who doesn't know why things are the way they are.
2983 While there are other documents which describe the configuration process
2984 in detail, here are a few things that everyone working on GCC should
2985 know.
2986
2987 There are three system names that the build knows about: the machine you
2988 are building on (@dfn{build}), the machine that you are building for
2989 (@dfn{host}), and the machine that GCC will produce code for
2990 (@dfn{target}).  When you configure GCC, you specify these with
2991 @option{--build=}, @option{--host=}, and @option{--target=}.
2992
2993 Specifying the host without specifying the build should be avoided, as
2994 @command{configure} may (and once did) assume that the host you specify
2995 is also the build, which may not be true.
2996
2997 If build, host, and target are all the same, this is called a
2998 @dfn{native}.  If build and host are the same but target is different,
2999 this is called a @dfn{cross}.  If build, host, and target are all
3000 different this is called a @dfn{canadian} (for obscure reasons dealing
3001 with Canada's political party and the background of the person working
3002 on the build at that time).  If host and target are the same, but build
3003 is different, you are using a cross-compiler to build a native for a
3004 different system.  Some people call this a @dfn{host-x-host},
3005 @dfn{crossed native}, or @dfn{cross-built native}.  If build and target
3006 are the same, but host is different, you are using a cross compiler to
3007 build a cross compiler that produces code for the machine you're
3008 building on.  This is rare, so there is no common say of describing it
3009 (although I propose calling it a @dfn{crossback}).
3010
3011 If build and host are the same, the GCC you are building will also be
3012 used to build the target libraries (like @code{libstdc++}).  If build and host
3013 are different, you must have already build and installed a cross
3014 compiler that will be used to build the target libraries (if you
3015 configured with @option{--target=foo-bar}, this compiler will be called
3016 @command{foo-bar-gcc}).
3017
3018 In the case of target libraries, the machine you're building for is the
3019 machine you specified with @option{--target}.  So, build is the machine
3020 you're building on (no change there), host is the machine you're
3021 building for (the target libraries are built for the target, so host is
3022 the target you specified), and target doesn't apply (because you're not
3023 building a compiler, you're building libraries).  The configure/make
3024 process will adjust these variables as needed.  It also sets
3025 @code{$with_cross_host} to the original @option{--host} value in case you
3026 need it.
3027
3028 Libiberty, for example, is built twice.  The first time, host comes from
3029 @option{--host} and the second time host comes from @option{--target}.
3030 Historically, libiberty has not been built for the build machine,
3031 though, which causes some interesting issues with programs used to
3032 generate sources for the build.  Fixing this, so that libiberty is built
3033 three times, has long been on the to-do list.
3034
3035 @end ifset
3036
3037 @ifset INTERNALS
3038 @node Portability
3039 @chapter GCC and Portability
3040 @cindex portability
3041 @cindex GCC and portability
3042
3043 The main goal of GCC was to make a good, fast compiler for machines in
3044 the class that the GNU system aims to run on: 32-bit machines that address
3045 8-bit bytes and have several general registers.  Elegance, theoretical
3046 power and simplicity are only secondary.
3047
3048 GCC gets most of the information about the target machine from a machine
3049 description which gives an algebraic formula for each of the machine's
3050 instructions.  This is a very clean way to describe the target.  But when
3051 the compiler needs information that is difficult to express in this
3052 fashion, I have not hesitated to define an ad-hoc parameter to the machine
3053 description.  The purpose of portability is to reduce the total work needed
3054 on the compiler; it was not of interest for its own sake.
3055
3056 @cindex endianness
3057 @cindex autoincrement addressing, availability
3058 @findex abort
3059 GCC does not contain machine dependent code, but it does contain code
3060 that depends on machine parameters such as endianness (whether the most
3061 significant byte has the highest or lowest address of the bytes in a word)
3062 and the availability of autoincrement addressing.  In the RTL-generation
3063 pass, it is often necessary to have multiple strategies for generating code
3064 for a particular kind of syntax tree, strategies that are usable for different
3065 combinations of parameters.  Often I have not tried to address all possible
3066 cases, but only the common ones or only the ones that I have encountered.
3067 As a result, a new target may require additional strategies.  You will know
3068 if this happens because the compiler will call @code{abort}.  Fortunately,
3069 the new strategies can be added in a machine-independent fashion, and will
3070 affect only the target machines that need them.
3071 @end ifset
3072
3073 @ifset INTERNALS
3074 @node Interface
3075 @chapter Interfacing to GCC Output
3076 @cindex interfacing to GCC output
3077 @cindex run-time conventions
3078 @cindex function call conventions
3079 @cindex conventions, run-time
3080
3081 GCC is normally configured to use the same function calling convention
3082 normally in use on the target system.  This is done with the
3083 machine-description macros described (@pxref{Target Macros}).
3084
3085 @cindex unions, returning
3086 @cindex structures, returning
3087 @cindex returning structures and unions
3088 However, returning of structure and union values is done differently on
3089 some target machines.  As a result, functions compiled with PCC
3090 returning such types cannot be called from code compiled with GCC,
3091 and vice versa.  This does not cause trouble often because few Unix
3092 library routines return structures or unions.
3093
3094 GCC code returns structures and unions that are 1, 2, 4 or 8 bytes
3095 long in the same registers used for @code{int} or @code{double} return
3096 values.  (GCC typically allocates variables of such types in
3097 registers also.)  Structures and unions of other sizes are returned by
3098 storing them into an address passed by the caller (usually in a
3099 register).  The machine-description macros @code{STRUCT_VALUE} and
3100 @code{STRUCT_INCOMING_VALUE} tell GCC where to pass this address.
3101
3102 By contrast, PCC on most target machines returns structures and unions
3103 of any size by copying the data into an area of static storage, and then
3104 returning the address of that storage as if it were a pointer value.
3105 The caller must copy the data from that memory area to the place where
3106 the value is wanted.  This is slower than the method used by GCC, and
3107 fails to be reentrant.
3108
3109 On some target machines, such as RISC machines and the 80386, the
3110 standard system convention is to pass to the subroutine the address of
3111 where to return the value.  On these machines, GCC has been
3112 configured to be compatible with the standard compiler, when this method
3113 is used.  It may not be compatible for structures of 1, 2, 4 or 8 bytes.
3114
3115 @cindex argument passing
3116 @cindex passing arguments
3117 GCC uses the system's standard convention for passing arguments.  On
3118 some machines, the first few arguments are passed in registers; in
3119 others, all are passed on the stack.  It would be possible to use
3120 registers for argument passing on any machine, and this would probably
3121 result in a significant speedup.  But the result would be complete
3122 incompatibility with code that follows the standard convention.  So this
3123 change is practical only if you are switching to GCC as the sole C
3124 compiler for the system.  We may implement register argument passing on
3125 certain machines once we have a complete GNU system so that we can
3126 compile the libraries with GCC@.
3127
3128 On some machines (particularly the Sparc), certain types of arguments
3129 are passed ``by invisible reference''.  This means that the value is
3130 stored in memory, and the address of the memory location is passed to
3131 the subroutine.
3132
3133 @cindex @code{longjmp} and automatic variables
3134 If you use @code{longjmp}, beware of automatic variables.  ISO C says that
3135 automatic variables that are not declared @code{volatile} have undefined
3136 values after a @code{longjmp}.  And this is all GCC promises to do,
3137 because it is very difficult to restore register variables correctly, and
3138 one of GCC's features is that it can put variables in registers without
3139 your asking it to.
3140
3141 If you want a variable to be unaltered by @code{longjmp}, and you don't
3142 want to write @code{volatile} because old C compilers don't accept it,
3143 just take the address of the variable.  If a variable's address is ever
3144 taken, even if just to compute it and ignore it, then the variable cannot
3145 go in a register:
3146
3147 @example
3148 @{
3149   int careful;
3150   &careful;
3151   @dots{}
3152 @}
3153 @end example
3154
3155 @cindex arithmetic libraries
3156 @cindex math libraries
3157 @opindex msoft-float
3158 Code compiled with GCC may call certain library routines.  Most of
3159 them handle arithmetic for which there are no instructions.  This
3160 includes multiply and divide on some machines, and floating point
3161 operations on any machine for which floating point support is disabled
3162 with @option{-msoft-float}.  Some standard parts of the C library, such as
3163 @code{bcopy} or @code{memcpy}, are also called automatically.  The usual
3164 function call interface is used for calling the library routines.
3165
3166 Some of these routines can be defined in mostly machine-independent C;
3167 they appear in @file{libgcc2.c}.  Others must be hand-written in
3168 assembly language for each processor.  Wherever they are defined, they
3169 are compiled into the support library, @file{libgcc.a}, which is
3170 automatically searched when you link programs with GCC@.
3171 @end ifset
3172
3173 @ifset INTERNALS
3174 @node Passes
3175 @chapter Passes and Files of the Compiler
3176 @cindex passes and files of the compiler
3177 @cindex files and passes of the compiler
3178 @cindex compiler passes and files
3179
3180 @cindex top level of compiler
3181 The overall control structure of the compiler is in @file{toplev.c}.  This
3182 file is responsible for initialization, decoding arguments, opening and
3183 closing files, and sequencing the passes.
3184
3185 @cindex parsing pass
3186 The parsing pass is invoked only once, to parse the entire input.  A
3187 high level tree representation is then generated from the input,
3188 one function at a time.  This tree code is then transformed into RTL
3189 intermediate code, and processed.  The files involved in transforming
3190 the trees into RTL are @file{expr.c}, @file{expmed.c}, and
3191 @file{stmt.c}.
3192 @c Note, the above files aren't strictly the only files involved. It's
3193 @c all over the place (function.c, final.c,etc).  However, those are
3194 @c the files that are supposed to be directly involved, and have
3195 @c their purpose listed as such, so i've only listed them.
3196 The order of trees that are processed, is not
3197 necessarily the same order they are generated from
3198 the input, due to deferred inlining, and other considerations.
3199
3200 @findex rest_of_compilation
3201 @findex rest_of_decl_compilation
3202 Each time the parsing pass reads a complete function definition or
3203 top-level declaration, it calls either the function
3204 @code{rest_of_compilation}, or the function
3205 @code{rest_of_decl_compilation} in @file{toplev.c}, which are
3206 responsible for all further processing necessary, ending with output of
3207 the assembler language.  All other compiler passes run, in sequence,
3208 within @code{rest_of_compilation}.  When that function returns from
3209 compiling a function definition, the storage used for that function
3210 definition's compilation is entirely freed, unless it is an inline
3211 function, or was deferred for some reason (this can occur in
3212 templates, for example).
3213 @ifset USING
3214 (@pxref{Inline,,An Inline Function is As Fast As a Macro}).
3215 @end ifset
3216 @ifclear USING
3217 (@pxref{Inline,,An Inline Function is As Fast As a Macro,gcc.texi,Using GCC}).
3218 @end ifclear
3219
3220 Here is a list of all the passes of the compiler and their source files.
3221 Also included is a description of where debugging dumps can be requested
3222 with @option{-d} options.
3223
3224 @itemize @bullet
3225 @item
3226 Parsing.  This pass reads the entire text of a function definition,
3227 constructing a high level tree representation.  (Because of the semantic
3228 analysis that takes place during this pass, it does more than is
3229 formally considered to be parsing.)
3230
3231 The tree representation does not entirely follow C syntax, because it is
3232 intended to support other languages as well.
3233
3234 Language-specific data type analysis is also done in this pass, and every
3235 tree node that represents an expression has a data type attached.
3236 Variables are represented as declaration nodes.
3237
3238 The language-independent source files for parsing are
3239 @file{tree.c}, @file{fold-const.c}, and @file{stor-layout.c}.
3240 There are also header files @file{tree.h} and @file{tree.def}
3241 which define the format of the tree representation.
3242
3243 C preprocessing, for language front ends, that want or require it, is
3244 performed by cpplib, which is covered in seperate documentation.  In
3245 particular, the internals are covered in @xref{Top, ,Cpplib internals,
3246 cppinternals, Cpplib Internals}.
3247
3248 @c Avoiding overfull is tricky here.
3249 The source files to parse C are
3250 @file{c-convert.c},
3251 @file{c-decl.c},
3252 @file{c-errors.c},
3253 @file{c-lang.c},
3254 @file{c-parse.in},
3255 @file{c-aux-info.c},
3256 and
3257 @file{c-typeck.c},
3258 along with a header file
3259 @file{c-tree.h}
3260 and some files shared with Objective-C and C++.
3261
3262 The source files for parsing C++ are in @file{cp/}.
3263 They are @file{parse.y},
3264 @file{class.c},
3265 @file{cvt.c}, @file{decl.c}, @file{decl2.c},
3266 @file{except.c},
3267 @file{expr.c}, @file{init.c}, @file{lex.c},
3268 @file{method.c}, @file{ptree.c},
3269 @file{search.c}, @file{spew.c},
3270 @file{semantics.c}, @file{tree.c},
3271 @file{typeck2.c}, and
3272 @file{typeck.c}, along with header files @file{cp-tree.def},
3273 @file{cp-tree.h}, and @file{decl.h}.
3274
3275 The special source files for parsing Objective-C are in @file{objc/}.
3276 They are @file{objc-act.c}, @file{objc-tree.def}, and @file{objc-act.h}.
3277 Certain C-specific files are used for this as well.
3278
3279 The files
3280 @file{c-common.c},
3281 @file{c-common.def},
3282 @file{c-dump.c},
3283 @file{c-format.c},
3284 @file{c-pragma.c},
3285 @file{c-semantics.c},
3286 and
3287 @file{c-lex.c},
3288 along with header files
3289 @file{c-common.h},
3290 @file{c-dump.h},
3291 @file{c-lex.h},
3292 and
3293 @file{c-pragma.h},
3294 are also used for all of the above languages.
3295
3296
3297 @cindex Tree optimization
3298 @item
3299 Tree optimization.   This is the optimization of the tree
3300 representation, before converting into RTL code.
3301
3302 @cindex inline on trees, automatic
3303 Currently, the main optimization performed here is tree-based
3304 inlining.
3305 This is implemented for C++ in @file{cp/optimize.c}.  Note that
3306 tree based inlining turns off rtx based inlining (since it's more
3307 powerful, it would be a waste of time to do rtx based inlining in
3308 addition).
3309 The C front end currently does not perform tree based inlining.
3310
3311 @cindex constant folding
3312 @cindex arithmetic simplifications
3313 @cindex simplifications, arithmetic
3314 Constant folding and some arithmetic simplifications are also done
3315 during this pass, on the tree representation.
3316 The routines that perform these tasks are located in @file{fold-const.c}.
3317
3318 @cindex RTL generation
3319 @item
3320 RTL generation.  This is the conversion of syntax tree into RTL code.
3321
3322 @cindex target-parameter-dependent code
3323 This is where the bulk of target-parameter-dependent code is found,
3324 since often it is necessary for strategies to apply only when certain
3325 standard kinds of instructions are available.  The purpose of named
3326 instruction patterns is to provide this information to the RTL
3327 generation pass.
3328
3329 @cindex tail recursion optimization
3330 Optimization is done in this pass for @code{if}-conditions that are
3331 comparisons, boolean operations or conditional expressions.  Tail
3332 recursion is detected at this time also.  Decisions are made about how
3333 best to arrange loops and how to output @code{switch} statements.
3334
3335 @c Avoiding overfull is tricky here.
3336 The source files for RTL generation include
3337 @file{stmt.c},
3338 @file{calls.c},
3339 @file{expr.c},
3340 @file{explow.c},
3341 @file{expmed.c},
3342 @file{function.c},
3343 @file{optabs.c}
3344 and @file{emit-rtl.c}.
3345 Also, the file
3346 @file{insn-emit.c}, generated from the machine description by the
3347 program @code{genemit}, is used in this pass.  The header file
3348 @file{expr.h} is used for communication within this pass.
3349
3350 @findex genflags
3351 @findex gencodes
3352 The header files @file{insn-flags.h} and @file{insn-codes.h},
3353 generated from the machine description by the programs @code{genflags}
3354 and @code{gencodes}, tell this pass which standard names are available
3355 for use and which patterns correspond to them.
3356
3357 Aside from debugging information output, none of the following passes
3358 refers to the tree structure representation of the function (only
3359 part of which is saved).
3360
3361 @cindex inline on rtx, automatic
3362 The decision of whether the function can and should be expanded inline
3363 in its subsequent callers is made at the end of rtl generation.  The
3364 function must meet certain criteria, currently related to the size of
3365 the function and the types and number of parameters it has.  Note that
3366 this function may contain loops, recursive calls to itself
3367 (tail-recursive functions can be inlined!), gotos, in short, all
3368 constructs supported by GCC@.  The file @file{integrate.c} contains
3369 the code to save a function's rtl for later inlining and to inline that
3370 rtl when the function is called.  The header file @file{integrate.h}
3371 is also used for this purpose.
3372
3373 @opindex dr
3374 The option @option{-dr} causes a debugging dump of the RTL code after
3375 this pass.  This dump file's name is made by appending @samp{.rtl} to
3376 the input file name.
3377
3378 @c Should the exception handling pass be talked about here?
3379
3380 @cindex sibling call optimization
3381 @item
3382 Sibiling call optimization.   This pass performs tail recursion
3383 elimination, and tail and sibling call optimizations.  The purpose of
3384 these optimizations is to reduce the overhead of function calls,
3385 whenever possible.
3386
3387 The source file of this pass is @file{sibcall.c}
3388
3389 @opindex di
3390 The option @option{-di} causes a debugging dump of the RTL code after
3391 this pass is run.  This dump file's name is made by appending
3392 @samp{.sibling} to the input file name.
3393
3394 @cindex jump optimization
3395 @cindex unreachable code
3396 @cindex dead code
3397 @item
3398 Jump optimization.  This pass simplifies jumps to the following
3399 instruction, jumps across jumps, and jumps to jumps.  It deletes
3400 unreferenced labels and unreachable code, except that unreachable code
3401 that contains a loop is not recognized as unreachable in this pass.
3402 (Such loops are deleted later in the basic block analysis.)  It also
3403 converts some code originally written with jumps into sequences of
3404 instructions that directly set values from the results of comparisons,
3405 if the machine has such instructions.
3406
3407 Jump optimization is performed two or three times.  The first time is
3408 immediately following RTL generation.  The second time is after CSE,
3409 but only if CSE says repeated jump optimization is needed.  The
3410 last time is right before the final pass.  That time, cross-jumping
3411 and deletion of no-op move instructions are done together with the
3412 optimizations described above.
3413
3414 The source file of this pass is @file{jump.c}.
3415
3416 @opindex dj
3417 The option @option{-dj} causes a debugging dump of the RTL code after
3418 this pass is run for the first time.  This dump file's name is made by
3419 appending @samp{.jump} to the input file name.
3420
3421
3422 @cindex register use analysis
3423 @item
3424 Register scan.  This pass finds the first and last use of each
3425 register, as a guide for common subexpression elimination.  Its source
3426 is in @file{regclass.c}.
3427
3428 @cindex jump threading
3429 @item
3430 @opindex fthread-jumps
3431 Jump threading.  This pass detects a condition jump that branches to an
3432 identical or inverse test.  Such jumps can be @samp{threaded} through
3433 the second conditional test.  The source code for this pass is in
3434 @file{jump.c}.  This optimization is only performed if
3435 @option{-fthread-jumps} is enabled.
3436
3437 @cindex SSA optimizations
3438 @cindex Single Static Assignment optimizations
3439 @opindex fssa
3440 @item
3441 Static Single Assignment (SSA) based optimization passes.  The
3442 SSA conversion passes (to/from) are turned on by the @option{-fssa}
3443 option (it is also done automatically if you enable an SSA optimization pass).
3444 These passes utilize a form called Static Single Assignment.  In SSA form,
3445 each variable (pseudo register) is only set once, giving you def-use
3446 and use-def chains for free, and enabling a lot more optimization
3447 passes to be run in linear time.
3448 Conversion to and from SSA form is handled by functions in
3449 @file{ssa.c}.
3450
3451 @opindex de
3452 The option @option{-de} causes a debugging dump of the RTL code after
3453 this pass.  This dump file's name is made by appending @samp{.ssa} to
3454 the input file name.
3455 @itemize @bullet
3456 @cindex SSA Conditional Constant Propagation
3457 @cindex Conditional Constant Propagation, SSA based
3458 @cindex conditional constant propagation
3459 @opindex fssa-ccp
3460 @item
3461 SSA Conditional Constant Propagation.  Turned on by the @option{-fssa-ccp}
3462 SSA Aggressive Dead Code Elimination.  Turned on by the @option{-fssa-dce}
3463 option.  This pass performs conditional constant propagation to simplify
3464 instructions including conditional branches.  This pass is more aggressive
3465 than the constant propgation done by the CSE and GCSE pases, but operates
3466 in linear time.
3467
3468 @opindex dW
3469 The option @option{-dW} causes a debugging dump of the RTL code after
3470 this pass.  This dump file's name is made by appending @samp{.ssaccp} to
3471 the input file name.
3472
3473 @cindex SSA DCE
3474 @cindex DCE, SSA based
3475 @cindex dead code elimination
3476 @opindex fssa-dce
3477 @item
3478 SSA Aggressive Dead Code Elimination.  Turned on by the @option{-fssa-dce}
3479 option.  This pass performs elimination of code considered unnecessary because
3480 it has no externally visible effects on the program.  It operates in
3481 linear time.
3482
3483 @opindex dX
3484 The option @option{-dX} causes a debugging dump of the RTL code after
3485 this pass.  This dump file's name is made by appending @samp{.ssadce} to
3486 the input file name.
3487 @end itemize
3488
3489 @cindex common subexpression elimination
3490 @cindex constant propagation
3491 @item
3492 Common subexpression elimination.  This pass also does constant
3493 propagation.  Its source files are @file{cse.c}, and @file{cselib.c}.
3494 If constant  propagation causes conditional jumps to become
3495 unconditional or to become no-ops, jump optimization is run again when
3496 CSE is finished.
3497
3498 @opindex ds
3499 The option @option{-ds} causes a debugging dump of the RTL code after
3500 this pass.  This dump file's name is made by appending @samp{.cse} to
3501 the input file name.
3502
3503 @cindex global common subexpression elimination
3504 @cindex constant propagation
3505 @cindex copy propagation
3506 @item
3507 Global common subexpression elimination.  This pass performs two
3508 different types of GCSE  depending on whether you are optimizing for
3509 size or not (LCM based GCSE tends to increase code size for a gain in
3510 speed, while Morel-Renvoise based GCSE does not).
3511 When optimizing for size, GCSE is done using Morel-Renvoise Partial
3512 Redundancy Elimination, with the exception that it does not try to move
3513 invariants out of loops---that is left to  the loop optimization pass.
3514 If MR PRE GCSE is done, code hoisting (aka unification) is also done, as
3515 well as load motion.
3516 If you are optimizing for speed, LCM (lazy code motion) based GCSE is
3517 done.  LCM is based on the work of Knoop, Ruthing, and Steffen.  LCM
3518 based GCSE also does loop invariant code motion.  We also perform load
3519 and store motion when optimizing for speed.
3520 Regardless of which type of GCSE is used, the GCSE pass also performs
3521 global constant and  copy propagation.
3522
3523 The source file for this pass is @file{gcse.c}, and the LCM routines
3524 are in @file{lcm.c}.
3525
3526 @opindex dG
3527 The option @option{-dG} causes a debugging dump of the RTL code after
3528 this pass.  This dump file's name is made by appending @samp{.gcse} to
3529 the input file name.
3530
3531 @cindex loop optimization
3532 @cindex code motion
3533 @cindex strength-reduction
3534 @item
3535 Loop optimization.  This pass moves constant expressions out of loops,
3536 and optionally does strength-reduction and loop unrolling as well.
3537 Its source files are @file{loop.c} and @file{unroll.c}, plus the header
3538 @file{loop.h} used for communication between them.  Loop unrolling uses
3539 some functions in @file{integrate.c} and the header @file{integrate.h}.
3540 Loop dependency analysis routines are contained in @file{dependence.c}.
3541
3542 @opindex dL
3543 The option @option{-dL} causes a debugging dump of the RTL code after
3544 this pass.  This dump file's name is made by appending @samp{.loop} to
3545 the input file name.
3546
3547 @item
3548 @opindex frerun-cse-after-loop
3549 If @option{-frerun-cse-after-loop} was enabled, a second common
3550 subexpression elimination pass is performed after the loop optimization
3551 pass.  Jump threading is also done again at this time if it was specified.
3552
3553 @opindex dt
3554 The option @option{-dt} causes a debugging dump of the RTL code after
3555 this pass.  This dump file's name is made by appending @samp{.cse2} to
3556 the input file name.
3557
3558 @cindex data flow analysis
3559 @cindex analysis, data flow
3560 @cindex basic blocks
3561 @item
3562 Data flow analysis (@file{flow.c}).  This pass divides the program
3563 into basic blocks (and in the process deletes unreachable loops); then
3564 it computes which pseudo-registers are live at each point in the
3565 program, and makes the first instruction that uses a value point at
3566 the instruction that computed the value.
3567
3568 @cindex autoincrement/decrement analysis
3569 This pass also deletes computations whose results are never used, and
3570 combines memory references with add or subtract instructions to make
3571 autoincrement or autodecrement addressing.
3572
3573 @opindex df
3574 The option @option{-df} causes a debugging dump of the RTL code after
3575 this pass.  This dump file's name is made by appending @samp{.flow} to
3576 the input file name.  If stupid register allocation is in use, this
3577 dump file reflects the full results of such allocation.
3578
3579 @cindex instruction combination
3580 @item
3581 Instruction combination (@file{combine.c}).  This pass attempts to
3582 combine groups of two or three instructions that are related by data
3583 flow into single instructions.  It combines the RTL expressions for
3584 the instructions by substitution, simplifies the result using algebra,
3585 and then attempts to match the result against the machine description.
3586
3587 @opindex dc
3588 The option @option{-dc} causes a debugging dump of the RTL code after
3589 this pass.  This dump file's name is made by appending @samp{.combine}
3590 to the input file name.
3591
3592 @cindex if conversion
3593 @item
3594 If-conversion is a transformation that transforms control dependencies
3595 into data dependencies (IE it transforms conditional code into a
3596 single control stream).
3597 It is implemented in the file @file{ifcvt.c}.
3598
3599 @opindex dE
3600 The option @option{-dE} causes a debugging dump of the RTL code after
3601 this pass.  This dump file's name is made by appending @samp{.ce} to
3602 the input file name.
3603
3604 @cindex register movement
3605 @item
3606 Register movement (@file{regmove.c}).  This pass looks for cases where
3607 matching constraints would force an instruction to need a reload, and
3608 this reload would be a register to register move.  It then attempts
3609 to change the registers used by the instruction to avoid the move
3610 instruction.
3611
3612 @opindex dN
3613 The option @option{-dN} causes a debugging dump of the RTL code after
3614 this pass.  This dump file's name is made by appending @samp{.regmove}
3615 to the input file name.
3616
3617 @cindex instruction scheduling
3618 @cindex scheduling, instruction
3619 @item
3620 Instruction scheduling (@file{sched.c}).  This pass looks for
3621 instructions whose output will not be available by the time that it is
3622 used in subsequent instructions.  (Memory loads and floating point
3623 instructions often have this behavior on RISC machines).  It re-orders
3624 instructions within a basic block to try to separate the definition and
3625 use of items that otherwise would cause pipeline stalls.
3626
3627 Instruction scheduling is performed twice.  The first time is immediately
3628 after instruction combination and the second is immediately after reload.
3629
3630 @opindex dS
3631 The option @option{-dS} causes a debugging dump of the RTL code after this
3632 pass is run for the first time.  The dump file's name is made by
3633 appending @samp{.sched} to the input file name.
3634
3635 @cindex register class preference pass
3636 @item
3637 Register class preferencing.  The RTL code is scanned to find out
3638 which register class is best for each pseudo register.  The source
3639 file is @file{regclass.c}.
3640
3641 @cindex register allocation
3642 @cindex local register allocation
3643 @item
3644 Local register allocation (@file{local-alloc.c}).  This pass allocates
3645 hard registers to pseudo registers that are used only within one basic
3646 block.  Because the basic block is linear, it can use fast and
3647 powerful techniques to do a very good job.
3648
3649 @opindex dl
3650 The option @option{-dl} causes a debugging dump of the RTL code after
3651 this pass.  This dump file's name is made by appending @samp{.lreg} to
3652 the input file name.
3653
3654 @cindex global register allocation
3655 @item
3656 Global register allocation (@file{global.c}).  This pass
3657 allocates hard registers for the remaining pseudo registers (those
3658 whose life spans are not contained in one basic block).
3659
3660 @cindex reloading
3661 @item
3662 Reloading.  This pass renumbers pseudo registers with the hardware
3663 registers numbers they were allocated.  Pseudo registers that did not
3664 get hard registers are replaced with stack slots.  Then it finds
3665 instructions that are invalid because a value has failed to end up in
3666 a register, or has ended up in a register of the wrong kind.  It fixes
3667 up these instructions by reloading the problematical values
3668 temporarily into registers.  Additional instructions are generated to
3669 do the copying.
3670
3671 The reload pass also optionally eliminates the frame pointer and inserts
3672 instructions to save and restore call-clobbered registers around calls.
3673
3674 Source files are @file{reload.c} and @file{reload1.c}, plus the header
3675 @file{reload.h} used for communication between them.
3676
3677 @opindex dg
3678 The option @option{-dg} causes a debugging dump of the RTL code after
3679 this pass.  This dump file's name is made by appending @samp{.greg} to
3680 the input file name.
3681
3682 @cindex instruction scheduling
3683 @cindex scheduling, instruction
3684 @item
3685 Instruction scheduling is repeated here to try to avoid pipeline stalls
3686 due to memory loads generated for spilled pseudo registers.
3687
3688 @opindex dR
3689 The option @option{-dR} causes a debugging dump of the RTL code after
3690 this pass.  This dump file's name is made by appending @samp{.sched2}
3691 to the input file name.
3692
3693 @cindex basic block reordering
3694 @cindex reordering, block
3695 @item
3696 Basic block reordering.  This pass implements profile guided code
3697 positioning.  If profile information is not available, various types of
3698 static analysis are performed to make the predictions normally coming
3699 from the profile feedback (IE execution frequency, branch probability,
3700 etc).  It is implemented in the file @file{bb-reorder.c}, and the
3701 various prediction routines are in @file{predict.c}.
3702
3703 @opindex dB
3704 The option @option{-dB} causes a debugging dump of the RTL code after
3705 this pass.  This dump file's name is made by appending @samp{.bbro} to
3706 the input file name.
3707
3708 @cindex cross-jumping
3709 @cindex no-op move instructions
3710 @item
3711 Jump optimization is repeated, this time including cross-jumping
3712 and deletion of no-op move instructions.
3713
3714 @opindex dJ
3715 The option @option{-dJ} causes a debugging dump of the RTL code after
3716 this pass.  This dump file's name is made by appending @samp{.jump2}
3717 to the input file name.
3718
3719 @cindex delayed branch scheduling
3720 @cindex scheduling, delayed branch
3721 @item
3722 Delayed branch scheduling.  This optional pass attempts to find
3723 instructions that can go into the delay slots of other instructions,
3724 usually jumps and calls.  The source file name is @file{reorg.c}.
3725
3726 @opindex dd
3727 The option @option{-dd} causes a debugging dump of the RTL code after
3728 this pass.  This dump file's name is made by appending @samp{.dbr}
3729 to the input file name.
3730
3731 @cindex branch shortening
3732 @item
3733 Branch shortening.  On many RISC machines, branch instructions have a
3734 limited range.  Thus, longer sequences of instructions must be used for
3735 long branches.  In this pass, the compiler figures out what how far each
3736 instruction will be from each other instruction, and therefore whether
3737 the usual instructions, or the longer sequences, must be used for each
3738 branch.
3739
3740 @cindex register-to-stack conversion
3741 @item
3742 Conversion from usage of some hard registers to usage of a register
3743 stack may be done at this point.  Currently, this is supported only
3744 for the floating-point registers of the Intel 80387 coprocessor.   The
3745 source file name is @file{reg-stack.c}.
3746
3747 @opindex dk
3748 The options @option{-dk} causes a debugging dump of the RTL code after
3749 this pass.  This dump file's name is made by appending @samp{.stack}
3750 to the input file name.
3751
3752 @cindex final pass
3753 @cindex peephole optimization
3754 @item
3755 Final.  This pass outputs the assembler code for the function.  It is
3756 also responsible for identifying spurious test and compare
3757 instructions.  Machine-specific peephole optimizations are performed
3758 at the same time.  The function entry and exit sequences are generated
3759 directly as assembler code in this pass; they never exist as RTL@.
3760
3761 The source files are @file{final.c} plus @file{insn-output.c}; the
3762 latter is generated automatically from the machine description by the
3763 tool @file{genoutput}.  The header file @file{conditions.h} is used
3764 for communication between these files.
3765
3766 @cindex debugging information generation
3767 @item
3768 Debugging information output.  This is run after final because it must
3769 output the stack slot offsets for pseudo registers that did not get
3770 hard registers.  Source files are @file{dbxout.c} for DBX symbol table
3771 format, @file{sdbout.c} for SDB symbol table format,  @file{dwarfout.c}
3772 for DWARF symbol table format, and the files @file{dwarf2out.c} and
3773 @file{dwarf2asm.c} for DWARF2 symbol table format.
3774 @end itemize
3775
3776 Some additional files are used by all or many passes:
3777
3778 @itemize @bullet
3779 @item
3780 Every pass uses @file{machmode.def} and @file{machmode.h} which define
3781 the machine modes.
3782
3783 @item
3784 Several passes use @file{real.h}, which defines the default
3785 representation of floating point constants and how to operate on them.
3786
3787 @item
3788 All the passes that work with RTL use the header files @file{rtl.h}
3789 and @file{rtl.def}, and subroutines in file @file{rtl.c}.  The tools
3790 @code{gen*} also use these files to read and work with the machine
3791 description RTL@.
3792
3793 @item
3794 All the tools that read the machine description use support routines
3795 found in @file{gensupport.c}, @file{errors.c}, and @file{read-rtl.c}.
3796
3797 @findex genconfig
3798 @item
3799 Several passes refer to the header file @file{insn-config.h} which
3800 contains a few parameters (C macro definitions) generated
3801 automatically from the machine description RTL by the tool
3802 @code{genconfig}.
3803
3804 @cindex instruction recognizer
3805 @item
3806 Several passes use the instruction recognizer, which consists of
3807 @file{recog.c} and @file{recog.h}, plus the files @file{insn-recog.c}
3808 and @file{insn-extract.c} that are generated automatically from the
3809 machine description by the tools @file{genrecog} and
3810 @file{genextract}.
3811
3812 @item
3813 Several passes use the header files @file{regs.h} which defines the
3814 information recorded about pseudo register usage, and @file{basic-block.h}
3815 which defines the information recorded about basic blocks.
3816
3817 @item
3818 @file{hard-reg-set.h} defines the type @code{HARD_REG_SET}, a bit-vector
3819 with a bit for each hard register, and some macros to manipulate it.
3820 This type is just @code{int} if the machine has few enough hard registers;
3821 otherwise it is an array of @code{int} and some of the macros expand
3822 into loops.
3823
3824 @item
3825 Several passes use instruction attributes.  A definition of the
3826 attributes defined for a particular machine is in file
3827 @file{insn-attr.h}, which is generated from the machine description by
3828 the program @file{genattr}.  The file @file{insn-attrtab.c} contains
3829 subroutines to obtain the attribute values for insns and information
3830 about processor pipeline characteristics for the instruction scheduler.
3831 It is generated from the machine description by the program
3832 @file{genattrtab}.
3833 @end itemize
3834 @end ifset
3835
3836 @ifset INTERNALS
3837 @include c-tree.texi
3838 @include rtl.texi
3839 @include md.texi
3840 @include tm.texi
3841 @end ifset
3842
3843 @ifset INTERNALS
3844 @node Config
3845 @chapter The Configuration File
3846 @cindex configuration file
3847 @cindex @file{xm-@var{machine}.h}
3848
3849 The configuration file @file{xm-@var{machine}.h} contains macro
3850 definitions that describe the machine and system on which the compiler
3851 is running, unlike the definitions in @file{@var{machine}.h}, which
3852 describe the machine for which the compiler is producing output.  Most
3853 of the values in @file{xm-@var{machine}.h} are actually the same on all
3854 machines that GCC runs on, so large parts of all configuration files
3855 are identical.  But there are some macros that vary:
3856
3857 @table @code
3858 @findex USG
3859 @item USG
3860 Define this macro if the host system is System V@.
3861
3862 @findex VMS
3863 @item VMS
3864 Define this macro if the host system is VMS@.
3865
3866 @findex FATAL_EXIT_CODE
3867 @item FATAL_EXIT_CODE
3868 A C expression for the status code to be returned when the compiler
3869 exits after serious errors.  The default is the system-provided macro
3870 @samp{EXIT_FAILURE}, or @samp{1} if the system doesn't define that
3871 macro.  Define this macro only if these defaults are incorrect.
3872
3873 @findex SUCCESS_EXIT_CODE
3874 @item SUCCESS_EXIT_CODE
3875 A C expression for the status code to be returned when the compiler
3876 exits without serious errors.  (Warnings are not serious errors.)  The
3877 default is the system-provided macro @samp{EXIT_SUCCESS}, or @samp{0} if
3878 the system doesn't define that macro.  Define this macro only if these
3879 defaults are incorrect.
3880
3881 @findex HOST_WORDS_BIG_ENDIAN
3882 @item HOST_WORDS_BIG_ENDIAN
3883 Defined if the host machine stores words of multi-word values in
3884 big-endian order.  (GCC does not depend on the host byte ordering
3885 within a word.)
3886
3887 @findex HOST_FLOAT_WORDS_BIG_ENDIAN
3888 @item HOST_FLOAT_WORDS_BIG_ENDIAN
3889 Define this macro to be 1 if the host machine stores @code{DFmode},
3890 @code{XFmode} or @code{TFmode} floating point numbers in memory with the
3891 word containing the sign bit at the lowest address; otherwise, define it
3892 to be zero.
3893
3894 This macro need not be defined if the ordering is the same as for
3895 multi-word integers.
3896
3897 @findex HOST_FLOAT_FORMAT
3898 @item HOST_FLOAT_FORMAT
3899 A numeric code distinguishing the floating point format for the host
3900 machine.  See @code{TARGET_FLOAT_FORMAT} in @ref{Storage Layout} for the
3901 alternatives and default.
3902
3903 @findex HOST_BITS_PER_CHAR
3904 @item HOST_BITS_PER_CHAR
3905 A C expression for the number of bits in @code{char} on the host
3906 machine.
3907
3908 @findex HOST_BITS_PER_SHORT
3909 @item HOST_BITS_PER_SHORT
3910 A C expression for the number of bits in @code{short} on the host
3911 machine.
3912
3913 @findex HOST_BITS_PER_INT
3914 @item HOST_BITS_PER_INT
3915 A C expression for the number of bits in @code{int} on the host
3916 machine.
3917
3918 @findex HOST_BITS_PER_LONG
3919 @item HOST_BITS_PER_LONG
3920 A C expression for the number of bits in @code{long} on the host
3921 machine.
3922
3923 @findex HOST_BITS_PER_LONGLONG
3924 @item HOST_BITS_PER_LONGLONG
3925 A C expression for the number of bits in @code{long long} on the host
3926 machine.
3927
3928 @findex ONLY_INT_FIELDS
3929 @item ONLY_INT_FIELDS
3930 Define this macro to indicate that the host compiler only supports
3931 @code{int} bit-fields, rather than other integral types, including
3932 @code{enum}, as do most C compilers.
3933
3934 @findex OBSTACK_CHUNK_SIZE
3935 @item OBSTACK_CHUNK_SIZE
3936 A C expression for the size of ordinary obstack chunks.
3937 If you don't define this, a usually-reasonable default is used.
3938
3939 @findex OBSTACK_CHUNK_ALLOC
3940 @item OBSTACK_CHUNK_ALLOC
3941 The function used to allocate obstack chunks.
3942 If you don't define this, @code{xmalloc} is used.
3943
3944 @findex OBSTACK_CHUNK_FREE
3945 @item OBSTACK_CHUNK_FREE
3946 The function used to free obstack chunks.
3947 If you don't define this, @code{free} is used.
3948
3949 @findex USE_C_ALLOCA
3950 @item USE_C_ALLOCA
3951 Define this macro to indicate that the compiler is running with the
3952 @code{alloca} implemented in C@.  This version of @code{alloca} can be
3953 found in the file @file{alloca.c}; to use it, you must also alter the
3954 @file{Makefile} variable @code{ALLOCA}.  (This is done automatically
3955 for the systems on which we know it is needed.)
3956
3957 If you do define this macro, you should probably do it as follows:
3958
3959 @example
3960 #ifndef __GNUC__
3961 #define USE_C_ALLOCA
3962 #else
3963 #define alloca __builtin_alloca
3964 #endif
3965 @end example
3966
3967 @noindent
3968 so that when the compiler is compiled with GCC it uses the more
3969 efficient built-in @code{alloca} function.
3970
3971 @item FUNCTION_CONVERSION_BUG
3972 @findex FUNCTION_CONVERSION_BUG
3973 Define this macro to indicate that the host compiler does not properly
3974 handle converting a function value to a pointer-to-function when it is
3975 used in an expression.
3976
3977 @findex MULTIBYTE_CHARS
3978 @item MULTIBYTE_CHARS
3979 Define this macro to enable support for multibyte characters in the
3980 input to GCC@.  This requires that the host system support the ISO C
3981 library functions for converting multibyte characters to wide
3982 characters.
3983
3984 @findex POSIX
3985 @item POSIX
3986 Define this if your system is POSIX.1 compliant.
3987
3988 @findex PATH_SEPARATOR
3989 @item PATH_SEPARATOR
3990 Define this macro to be a C character constant representing the
3991 character used to separate components in paths.  The default value is
3992 the colon character
3993
3994 @findex DIR_SEPARATOR
3995 @item DIR_SEPARATOR
3996 If your system uses some character other than slash to separate
3997 directory names within a file specification, define this macro to be a C
3998 character constant specifying that character.  When GCC displays file
3999 names, the character you specify will be used.  GCC will test for
4000 both slash and the character you specify when parsing filenames.
4001
4002 @findex DIR_SEPARATOR_2
4003 @item DIR_SEPARATOR_2
4004 If your system uses an alternative character other than
4005 @samp{DIR_SEPARATOR} to separate directory names within a file
4006 specification, define this macro to be a C character constant specifying
4007 that character.  If you define this macro, GCC will test for slash,
4008 @samp{DIR_SEPARATOR}, and @samp{DIR_SEPARATOR_2} when parsing filenames.
4009
4010 @findex TARGET_OBJECT_SUFFIX
4011 @item TARGET_OBJECT_SUFFIX
4012 Define this macro to be a C string representing the suffix for object
4013 files on your target machine.  If you do not define this macro, GCC will
4014 use @samp{.o} as the suffix for object files.
4015
4016 @findex TARGET_EXECUTABLE_SUFFIX
4017 @item TARGET_EXECUTABLE_SUFFIX
4018 Define this macro to be a C string representing the suffix to be
4019 automatically added to executable files on your target machine.  If you
4020 do not define this macro, GCC will use the null string as the suffix for
4021 executable files.
4022
4023 @findex HOST_OBJECT_SUFFIX
4024 @item HOST_OBJECT_SUFFIX
4025 Define this macro to be a C string representing the suffix for object
4026 files on your host machine (@samp{xm-*.h}).  If you do not define this
4027 macro, GCC will use @samp{.o} as the suffix for object files.
4028
4029 @findex HOST_EXECUTABLE_SUFFIX
4030 @item HOST_EXECUTABLE_SUFFIX
4031 Define this macro to be a C string representing the suffix for
4032 executable files on your host machine (@samp{xm-*.h}).  If you do not
4033 define this macro, GCC will use the null string as the suffix for
4034 executable files.
4035
4036 @findex HOST_BIT_BUCKET
4037 @item HOST_BIT_BUCKET
4038 The name of a file or file-like object on the host system which acts as
4039 a ``bit bucket''.  If you do not define this macro, GCC will use
4040 @samp{/dev/null} as the bit bucket.  If the target does not support a
4041 bit bucket, this should be defined to the null string, or some other
4042 illegal filename.  If the bit bucket is not writable, GCC will use a
4043 temporary file instead.
4044
4045 @findex COLLECT_EXPORT_LIST
4046 @item COLLECT_EXPORT_LIST
4047 If defined, @code{collect2} will scan the individual object files
4048 specified on its command line and create an export list for the linker.
4049 Define this macro for systems like AIX, where the linker discards
4050 object files that are not referenced from @code{main} and uses export
4051 lists.
4052
4053 @findex COLLECT2_HOST_INITIALIZATION
4054 @item COLLECT2_HOST_INITIALIZATION
4055 If defined, a C statement (sans semicolon) that performs host-dependent
4056 initialization when @code{collect2} is being initialized.
4057
4058 @findex GCC_DRIVER_HOST_INITIALIZATION
4059 @item GCC_DRIVER_HOST_INITIALIZATION
4060 If defined, a C statement (sans semicolon) that performs host-dependent
4061 initialization when a compilation driver is being initialized.
4062
4063 @findex UPDATE_PATH_HOST_CANONICALIZE
4064 @item UPDATE_PATH_HOST_CANONICALIZE (@var{path})
4065 If defined, a C statement (sans semicolon) that performs host-dependent
4066 canonicalization when a path used in a compilation driver or
4067 preprocessor is canonicalized.  @var{path} is a malloc-ed path to be
4068 canonicalized.  If the C statement does canonicalize @var{path} into a
4069 different buffer, the old path should be freed and the new buffer should
4070 have been allocated with malloc.
4071 @end table
4072
4073 @findex bzero
4074 @findex bcmp
4075 In addition, configuration files for system V define @code{bcopy},
4076 @code{bzero} and @code{bcmp} as aliases.  Some files define @code{alloca}
4077 as a macro when compiled with GCC, in order to take advantage of the
4078 benefit of GCC's built-in @code{alloca}.
4079
4080 @node Fragments
4081 @chapter Makefile Fragments
4082 @cindex makefile fragment
4083
4084 When you configure GCC using the @file{configure} script
4085 (@pxref{Installation}), it will construct the file @file{Makefile} from
4086 the template file @file{Makefile.in}.  When it does this, it will
4087 incorporate makefile fragment files from the @file{config} directory,
4088 named @file{t-@var{target}} and @file{x-@var{host}}.  If these files do
4089 not exist, it means nothing needs to be added for a given target or
4090 host.
4091
4092 @menu
4093 * Target Fragment:: Writing the @file{t-@var{target}} file.
4094 * Host Fragment::   Writing the @file{x-@var{host}} file.
4095 @end menu
4096
4097 @node Target Fragment
4098 @section The Target Makefile Fragment
4099 @cindex target makefile fragment
4100 @cindex @file{t-@var{target}}
4101
4102 The target makefile fragment, @file{t-@var{target}}, defines special
4103 target dependent variables and targets used in the @file{Makefile}:
4104
4105 @table @code
4106 @findex LIBGCC2_CFLAGS
4107 @item LIBGCC2_CFLAGS
4108 Compiler flags to use when compiling @file{libgcc2.c}.
4109
4110 @findex LIB2FUNCS_EXTRA
4111 @item LIB2FUNCS_EXTRA
4112 A list of source file names to be compiled or assembled and inserted
4113 into @file{libgcc.a}.
4114
4115 @findex Floating Point Emulation
4116 @item Floating Point Emulation
4117 To have GCC include software floating point libraries in @file{libgcc.a}
4118 define @code{FPBIT} and @code{DPBIT} along with a few rules as follows:
4119 @smallexample
4120 # We want fine grained libraries, so use the new code
4121 # to build the floating point emulation libraries.
4122 FPBIT = fp-bit.c
4123 DPBIT = dp-bit.c
4124
4125
4126 fp-bit.c: $(srcdir)/config/fp-bit.c
4127         echo '#define FLOAT' > fp-bit.c
4128         cat $(srcdir)/config/fp-bit.c >> fp-bit.c
4129
4130 dp-bit.c: $(srcdir)/config/fp-bit.c
4131         cat $(srcdir)/config/fp-bit.c > dp-bit.c
4132 @end smallexample
4133
4134 You may need to provide additional #defines at the beginning of @file{fp-bit.c}
4135 and @file{dp-bit.c} to control target endianness and other options.
4136
4137
4138 @findex CRTSTUFF_T_CFLAGS
4139 @item CRTSTUFF_T_CFLAGS
4140 Special flags used when compiling @file{crtstuff.c}.
4141 @xref{Initialization}.
4142
4143 @findex CRTSTUFF_T_CFLAGS_S
4144 @item CRTSTUFF_T_CFLAGS_S
4145 Special flags used when compiling @file{crtstuff.c} for shared
4146 linking.  Used if you use @file{crtbeginS.o} and @file{crtendS.o}
4147 in @code{EXTRA-PARTS}.
4148 @xref{Initialization}.
4149
4150 @findex MULTILIB_OPTIONS
4151 @item MULTILIB_OPTIONS
4152 For some targets, invoking GCC in different ways produces objects
4153 that can not be linked together.  For example, for some targets GCC
4154 produces both big and little endian code.  For these targets, you must
4155 arrange for multiple versions of @file{libgcc.a} to be compiled, one for
4156 each set of incompatible options.  When GCC invokes the linker, it
4157 arranges to link in the right version of @file{libgcc.a}, based on
4158 the command line options used.
4159
4160 The @code{MULTILIB_OPTIONS} macro lists the set of options for which
4161 special versions of @file{libgcc.a} must be built.  Write options that
4162 are mutually incompatible side by side, separated by a slash.  Write
4163 options that may be used together separated by a space.  The build
4164 procedure will build all combinations of compatible options.
4165
4166 For example, if you set @code{MULTILIB_OPTIONS} to @samp{m68000/m68020
4167 msoft-float}, @file{Makefile} will build special versions of
4168 @file{libgcc.a} using the following sets of options:  @option{-m68000},
4169 @option{-m68020}, @option{-msoft-float}, @samp{-m68000 -msoft-float}, and
4170 @samp{-m68020 -msoft-float}.
4171
4172 @findex MULTILIB_DIRNAMES
4173 @item MULTILIB_DIRNAMES
4174 If @code{MULTILIB_OPTIONS} is used, this variable specifies the
4175 directory names that should be used to hold the various libraries.
4176 Write one element in @code{MULTILIB_DIRNAMES} for each element in
4177 @code{MULTILIB_OPTIONS}.  If @code{MULTILIB_DIRNAMES} is not used, the
4178 default value will be @code{MULTILIB_OPTIONS}, with all slashes treated
4179 as spaces.
4180
4181 For example, if @code{MULTILIB_OPTIONS} is set to @samp{m68000/m68020
4182 msoft-float}, then the default value of @code{MULTILIB_DIRNAMES} is
4183 @samp{m68000 m68020 msoft-float}.  You may specify a different value if
4184 you desire a different set of directory names.
4185
4186 @findex MULTILIB_MATCHES
4187 @item MULTILIB_MATCHES
4188 Sometimes the same option may be written in two different ways.  If an
4189 option is listed in @code{MULTILIB_OPTIONS}, GCC needs to know about
4190 any synonyms.  In that case, set @code{MULTILIB_MATCHES} to a list of
4191 items of the form @samp{option=option} to describe all relevant
4192 synonyms.  For example, @samp{m68000=mc68000 m68020=mc68020}.
4193
4194 @findex MULTILIB_EXCEPTIONS
4195 @item MULTILIB_EXCEPTIONS
4196 Sometimes when there are multiple sets of @code{MULTILIB_OPTIONS} being
4197 specified, there are combinations that should not be built.  In that
4198 case, set @code{MULTILIB_EXCEPTIONS} to be all of the switch exceptions
4199 in shell case syntax that should not be built.
4200
4201 For example, in the PowerPC embedded ABI support, it is not desirable
4202 to build libraries compiled with the @option{-mcall-aix} option
4203 and either of the @option{-fleading-underscore} or @option{-mlittle} options
4204 at the same time.  Therefore @code{MULTILIB_EXCEPTIONS} is set to
4205 @smallexample
4206 *mcall-aix/*fleading-underscore* *mlittle/*mcall-aix*
4207 @end smallexample
4208
4209 @findex MULTILIB_EXTRA_OPTS
4210 @item MULTILIB_EXTRA_OPTS
4211 Sometimes it is desirable that when building multiple versions of
4212 @file{libgcc.a} certain options should always be passed on to the
4213 compiler.  In that case, set @code{MULTILIB_EXTRA_OPTS} to be the list
4214 of options to be used for all builds.
4215 @end table
4216
4217 @node Host Fragment
4218 @section The Host Makefile Fragment
4219 @cindex host makefile fragment
4220 @cindex @file{x-@var{host}}
4221
4222 The host makefile fragment, @file{x-@var{host}}, defines special host
4223 dependent variables and targets used in the @file{Makefile}:
4224
4225 @table @code
4226 @findex CC
4227 @item CC
4228 The compiler to use when building the first stage.
4229
4230 @findex INSTALL
4231 @item INSTALL
4232 The install program to use.
4233 @end table
4234 @end ifset
4235
4236 @include funding.texi
4237
4238 @node GNU/Linux
4239 @unnumbered Linux and the GNU Project
4240
4241 Many computer users run a modified version of the GNU system every
4242 day, without realizing it.  Through a peculiar turn of events, the
4243 version of GNU which is widely used today is more often known as
4244 ``Linux'', and many users are not aware of the extent of its
4245 connection with the GNU Project.
4246
4247 There really is a Linux; it is a kernel, and these people are using
4248 it.  But you can't use a kernel by itself; a kernel is useful only as
4249 part of a whole system.  The system in which Linux is typically used
4250 is a modified variant of the GNU system---in other words, a Linux-based
4251 GNU system.
4252
4253 Many users are not fully aware of the distinction between the kernel,
4254 which is Linux, and the whole system, which they also call ``Linux''.
4255 The ambiguous use of the name doesn't promote understanding.
4256
4257 Programmers generally know that Linux is a kernel.  But since they
4258 have generally heard the whole system called ``Linux'' as well, they
4259 often envisage a history which fits that name.  For example, many
4260 believe that once Linus Torvalds finished writing the kernel, his
4261 friends looked around for other free software, and for no particular
4262 reason most everything necessary to make a Unix-like system was
4263 already available.
4264
4265 What they found was no accident---it was the GNU system.  The available
4266 free software added up to a complete system because the GNU Project
4267 had been working since 1984 to make one.  The GNU Manifesto
4268 had set forth the goal of developing a free Unix-like system, called
4269 GNU@.  By the time Linux was written, the system was almost finished.
4270
4271 Most free software projects have the goal of developing a particular
4272 program for a particular job.  For example, Linus Torvalds set out to
4273 write a Unix-like kernel (Linux); Donald Knuth set out to write a text
4274 formatter (TeX); Bob Scheifler set out to develop a window system (X
4275 Windows).  It's natural to measure the contribution of this kind of
4276 project by specific programs that came from the project.
4277
4278 If we tried to measure the GNU Project's contribution in this way,
4279 what would we conclude?  One CD-ROM vendor found that in their ``Linux
4280 distribution'', GNU software was the largest single contingent, around
4281 28% of the total source code, and this included some of the essential
4282 major components without which there could be no system.  Linux itself
4283 was about 3%.  So if you were going to pick a name for the system
4284 based on who wrote the programs in the system, the most appropriate
4285 single choice would be ``GNU''@.
4286
4287 But we don't think that is the right way to consider the question.
4288 The GNU Project was not, is not, a project to develop specific
4289 software packages.  It was not a project to develop a C compiler,
4290 although we did.  It was not a project to develop a text editor,
4291 although we developed one.  The GNU Project's aim was to develop
4292 @emph{a complete free Unix-like system}.
4293
4294 Many people have made major contributions to the free software in the
4295 system, and they all deserve credit.  But the reason it is @emph{a
4296 system}---and not just a collection of useful programs---is because the
4297 GNU Project set out to make it one.  We wrote the programs that were
4298 needed to make a @emph{complete} free system.  We wrote essential but
4299 unexciting major components, such as the assembler and linker, because
4300 you can't have a system without them.  A complete system needs more
4301 than just programming tools, so we wrote other components as well,
4302 such as the Bourne Again SHell, the PostScript interpreter
4303 Ghostscript, and the GNU C library.
4304
4305 By the early 90s we had put together the whole system aside from the
4306 kernel (and we were also working on a kernel, the GNU Hurd, which runs
4307 on top of Mach).  Developing this kernel has been a lot harder than we
4308 expected, and we are still working on finishing it.
4309
4310 Fortunately, you don't have to wait for it, because Linux is working
4311 now.  When Linus Torvalds wrote Linux, he filled the last major gap.
4312 People could then put Linux together with the GNU system to make a
4313 complete free system: a Linux-based GNU system (or GNU/Linux system,
4314 for short).
4315
4316 Putting them together sounds simple, but it was not a trivial job.
4317 The GNU C library (called glibc for short) needed substantial changes.
4318 Integrating a complete system as a distribution that would work ``out
4319 of the box'' was a big job, too.  It required addressing the issue of
4320 how to install and boot the system---a problem we had not tackled,
4321 because we hadn't yet reached that point.  The people who developed
4322 the various system distributions made a substantial contribution.
4323
4324 The GNU Project supports GNU/Linux systems as well as @emph{the}
4325 GNU system---even with funds.  We funded the rewriting of the
4326 Linux-related extensions to the GNU C library, so that now they are
4327 well integrated, and the newest GNU/Linux systems use the current
4328 library release with no changes.  We also funded an early stage of the
4329 development of Debian GNU/Linux.
4330
4331 We use Linux-based GNU systems today for most of our work, and we hope
4332 you use them too.  But please don't confuse the public by using the
4333 name ``Linux'' ambiguously.  Linux is the kernel, one of the essential
4334 major components of the system.  The system as a whole is more or less
4335 the GNU system.
4336
4337 @include gpl.texi
4338
4339 @c ---------------------------------------------------------------------
4340 @c GFDL
4341 @c ---------------------------------------------------------------------
4342
4343 @include fdl.texi
4344
4345 @node Contributors
4346 @unnumbered Contributors to GCC
4347 @cindex contributors
4348 @include contrib.texi
4349
4350 @c ---------------------------------------------------------------------
4351 @c Indexes
4352 @c ---------------------------------------------------------------------
4353
4354 @node Option Index
4355 @unnumbered Option Index
4356
4357 GCC's command line options are indexed here without any initial @samp{-}
4358 or @samp{--}.  Where an option has both positive and negative forms
4359 (such as @option{-f@var{option}} and @option{-fno-@var{option}}),
4360 relevant entries in the manual are indexed under the most appropriate
4361 form; it may sometimes be useful to look up both forms.
4362
4363 @printindex op
4364
4365 @node Index
4366 @unnumbered Index
4367
4368 @printindex cp
4369
4370 @c ---------------------------------------------------------------------
4371 @c Epilogue
4372 @c ---------------------------------------------------------------------
4373
4374 @bye