home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / gcc.info-3 (.txt) < prev    next >
GNU Info File  |  1995-11-26  |  48KB  |  941 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.55 from the input
  2. file gcc.texi.
  3.    This file documents the use and the internals of the GNU compiler.
  4.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  5. Boston, MA 02111-1307 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995 Free Software
  7. Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided also
  13. that the sections entitled "GNU General Public License," "Funding for
  14. Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
  15. included exactly as in the original, and provided that the entire
  16. resulting derived work is distributed under the terms of a permission
  17. notice identical to this one.
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the above conditions for modified
  20. versions, except that the sections entitled "GNU General Public
  21. License," "Funding for Free Software," and "Protect Your Freedom--Fight
  22. `Look And Feel'", and this permission notice, may be included in
  23. translations approved by the Free Software Foundation instead of in the
  24. original English.
  25. File: gcc.info,  Node: Warning Options,  Next: Debugging Options,  Prev: C++ Dialect Options,  Up: Invoking GCC
  26. Options to Request or Suppress Warnings
  27. =======================================
  28.    Warnings are diagnostic messages that report constructions which are
  29. not inherently erroneous but which are risky or suggest there may have
  30. been an error.
  31.    You can request many specific warnings with options beginning `-W',
  32. for example `-Wimplicit' to request warnings on implicit declarations.
  33. Each of these specific warning options also has a negative form
  34. beginning `-Wno-' to turn off warnings; for example, `-Wno-implicit'.
  35. This manual lists only one of the two forms, whichever is not the
  36. default.
  37.    These options control the amount and kinds of warnings produced by
  38. GNU CC:
  39. `-fsyntax-only'
  40.      Check the code for syntax errors, but don't do anything beyond
  41.      that.
  42. `-pedantic'
  43.      Issue all the warnings demanded by strict ANSI standard C; reject
  44.      all programs that use forbidden extensions.
  45.      Valid ANSI standard C programs should compile properly with or
  46.      without this option (though a rare few will require `-ansi').
  47.      However, without this option, certain GNU extensions and
  48.      traditional C features are supported as well.  With this option,
  49.      they are rejected.
  50.      `-pedantic' does not cause warning messages for use of the
  51.      alternate keywords whose names begin and end with `__'.  Pedantic
  52.      warnings are also disabled in the expression that follows
  53.      `__extension__'.  However, only system header files should use
  54.      these escape routes; application programs should avoid them.
  55.      *Note Alternate Keywords::.
  56.      This option is not intended to be useful; it exists only to satisfy
  57.      pedants who would otherwise claim that GNU CC fails to support the
  58.      ANSI standard.
  59.      Some users try to use `-pedantic' to check programs for strict ANSI
  60.      C conformance.  They soon find that it does not do quite what they
  61.      want: it finds some non-ANSI practices, but not all--only those
  62.      for which ANSI C *requires* a diagnostic.
  63.      A feature to report any failure to conform to ANSI C might be
  64.      useful in some instances, but would require considerable
  65.      additional work and would be quite different from `-pedantic'.  We
  66.      recommend, rather, that users take advantage of the extensions of
  67.      GNU C and disregard the limitations of other compilers.  Aside
  68.      from certain supercomputers and obsolete small machines, there is
  69.      less and less reason ever to use any other C compiler other than
  70.      for bootstrapping GNU CC.
  71. `-pedantic-errors'
  72.      Like `-pedantic', except that errors are produced rather than
  73.      warnings.
  74.      Inhibit all warning messages.
  75. `-Wno-import'
  76.      Inhibit warning messages about the use of `#import'.
  77. `-Wchar-subscripts'
  78.      Warn if an array subscript has type `char'.  This is a common cause
  79.      of error, as programmers often forget that this type is signed on
  80.      some machines.
  81. `-Wcomment'
  82.      Warn whenever a comment-start sequence `/*' appears in a comment.
  83. `-Wformat'
  84.      Check calls to `printf' and `scanf', etc., to make sure that the
  85.      arguments supplied have types appropriate to the format string
  86.      specified.
  87. `-Wimplicit'
  88.      Warn whenever a function or parameter is implicitly declared.
  89. `-Wparentheses'
  90.      Warn if parentheses are omitted in certain contexts, such as when
  91.      there is an assignment in a context where a truth value is
  92.      expected, or when operators are nested whose precedence people
  93.      often get confused about.
  94. `-Wreturn-type'
  95.      Warn whenever a function is defined with a return-type that
  96.      defaults to `int'.  Also warn about any `return' statement with no
  97.      return-value in a function whose return-type is not `void'.
  98. `-Wswitch'
  99.      Warn whenever a `switch' statement has an index of enumeral type
  100.      and lacks a `case' for one or more of the named codes of that
  101.      enumeration.  (The presence of a `default' label prevents this
  102.      warning.)  `case' labels outside the enumeration range also
  103.      provoke warnings when this option is used.
  104. `-Wtrigraphs'
  105.      Warn if any trigraphs are encountered (assuming they are enabled).
  106. `-Wunused'
  107.      Warn whenever a variable is unused aside from its declaration,
  108.      whenever a function is declared static but never defined, whenever
  109.      a label is declared but not used, and whenever a statement
  110.      computes a result that is explicitly not used.
  111.      To suppress this warning for an expression, simply cast it to
  112.      void.  For unused variables and parameters, use the `unused'
  113.      attribute (*note Variable Attributes::.).
  114. `-Wuninitialized'
  115.      An automatic variable is used without first being initialized.
  116.      These warnings are possible only in optimizing compilation,
  117.      because they require data flow information that is computed only
  118.      when optimizing.  If you don't specify `-O', you simply won't get
  119.      these warnings.
  120.      These warnings occur only for variables that are candidates for
  121.      register allocation.  Therefore, they do not occur for a variable
  122.      that is declared `volatile', or whose address is taken, or whose
  123.      size is other than 1, 2, 4 or 8 bytes.  Also, they do not occur for
  124.      structures, unions or arrays, even when they are in registers.
  125.      Note that there may be no warning about a variable that is used
  126.      only to compute a value that itself is never used, because such
  127.      computations may be deleted by data flow analysis before the
  128.      warnings are printed.
  129.      These warnings are made optional because GNU CC is not smart
  130.      enough to see all the reasons why the code might be correct
  131.      despite appearing to have an error.  Here is one example of how
  132.      this can happen:
  133.           {
  134.             int x;
  135.             switch (y)
  136.               {
  137.               case 1: x = 1;
  138.                 break;
  139.               case 2: x = 4;
  140.                 break;
  141.               case 3: x = 5;
  142.               }
  143.             foo (x);
  144.           }
  145.      If the value of `y' is always 1, 2 or 3, then `x' is always
  146.      initialized, but GNU CC doesn't know this.  Here is another common
  147.      case:
  148.           {
  149.             int save_y;
  150.             if (change_y) save_y = y, y = new_y;
  151.             ...
  152.             if (change_y) y = save_y;
  153.           }
  154.      This has no bug because `save_y' is used only if it is set.
  155.      Some spurious warnings can be avoided if you declare all the
  156.      functions you use that never return as `noreturn'.  *Note Function
  157.      Attributes::.
  158. `-Wenum-clash'
  159.      Warn about conversion between different enumeration types.  (C++
  160.      only).
  161. `-Wreorder (C++ only)'
  162.      Warn when the order of member initializers given in the code does
  163.      not match the order in which they must be executed.  For instance:
  164.           struct A {
  165.             int i;
  166.             int j;
  167.             A(): j (0), i (1) { }
  168.           };
  169.      Here the compiler will warn that the member initializers for `i'
  170.      and `j' will be rearranged to match the declaration order of the
  171.      members.
  172. `-Wtemplate-debugging'
  173.      When using templates in a C++ program, warn if debugging is not yet
  174.      fully available (C++ only).
  175. `-Wall'
  176.      All of the above `-W' options combined.  These are all the options
  177.      which pertain to usage that we recommend avoiding and that we
  178.      believe is easy to avoid, even in conjunction with macros.
  179.    The remaining `-W...' options are not implied by `-Wall' because
  180. they warn about constructions that we consider reasonable to use, on
  181. occasion, in clean programs.
  182.      Print extra warning messages for these events:
  183.         * A nonvolatile automatic variable might be changed by a call to
  184.           `longjmp'.  These warnings as well are possible only in
  185.           optimizing compilation.
  186.           The compiler sees only the calls to `setjmp'.  It cannot know
  187.           where `longjmp' will be called; in fact, a signal handler
  188.           could call it at any point in the code.  As a result, you may
  189.           get a warning even when there is in fact no problem because
  190.           `longjmp' cannot in fact be called at the place which would
  191.           cause a problem.
  192.         * A function can return either with or without a value.
  193.           (Falling off the end of the function body is considered
  194.           returning without a value.)  For example, this function would
  195.           evoke such a warning:
  196.                foo (a)
  197.                {
  198.                  if (a > 0)
  199.                    return a;
  200.                }
  201.         * An expression-statement or the left-hand side of a comma
  202.           expression contains no side effects.  To suppress the
  203.           warning, cast the unused expression to void.  For example, an
  204.           expression such as `x[i,j]' will cause a warning, but
  205.           `x[(void)i,j]' will not.
  206.         * An unsigned value is compared against zero with `<' or `<='.
  207.         * A comparison like `x<=y<=z' appears; this is equivalent to
  208.           `(x<=y ? 1 : 0) <= z', which is a different interpretation
  209.           from that of ordinary mathematical notation.
  210.         * Storage-class specifiers like `static' are not the first
  211.           things in a declaration.  According to the C Standard, this
  212.           usage is obsolescent.
  213.         * If `-Wall' or `-Wunused' is also specified, warn about unused
  214.           arguments.
  215.         * An aggregate has a partly bracketed initializer.  For
  216.           example, the following code would evoke such a warning,
  217.           because braces are missing around the initializer for `x.h':
  218.                struct s { int f, g; };
  219.                struct t { struct s h; int i; };
  220.                struct t x = { 1, 2, 3 };
  221. `-Wtraditional'
  222.      Warn about certain constructs that behave differently in
  223.      traditional and ANSI C.
  224.         * Macro arguments occurring within string constants in the
  225.           macro body.  These would substitute the argument in
  226.           traditional C, but are part of the constant in ANSI C.
  227.         * A function declared external in one block and then used after
  228.           the end of the block.
  229.         * A `switch' statement has an operand of type `long'.
  230. `-Wshadow'
  231.      Warn whenever a local variable shadows another local variable.
  232. `-Wid-clash-LEN'
  233.      Warn whenever two distinct identifiers match in the first LEN
  234.      characters.  This may help you prepare a program that will compile
  235.      with certain obsolete, brain-damaged compilers.
  236. `-Wlarger-than-LEN'
  237.      Warn whenever an object of larger than LEN bytes is defined.
  238. `-Wpointer-arith'
  239.      Warn about anything that depends on the "size of" a function type
  240.      or of `void'.  GNU C assigns these types a size of 1, for
  241.      convenience in calculations with `void *' pointers and pointers to
  242.      functions.
  243. `-Wbad-function-cast'
  244.      Warn whenever a function call is cast to a non-matching type.  For
  245.      example, warn if `int malloc()' is cast to `anything *'.
  246. `-Wcast-qual'
  247.      Warn whenever a pointer is cast so as to remove a type qualifier
  248.      from the target type.  For example, warn if a `const char *' is
  249.      cast to an ordinary `char *'.
  250. `-Wcast-align'
  251.      Warn whenever a pointer is cast such that the required alignment
  252.      of the target is increased.  For example, warn if a `char *' is
  253.      cast to an `int *' on machines where integers can only be accessed
  254.      at two- or four-byte boundaries.
  255. `-Wwrite-strings'
  256.      Give string constants the type `const char[LENGTH]' so that
  257.      copying the address of one into a non-`const' `char *' pointer
  258.      will get a warning.  These warnings will help you find at compile
  259.      time code that can try to write into a string constant, but only
  260.      if you have been very careful about using `const' in declarations
  261.      and prototypes.  Otherwise, it will just be a nuisance; this is
  262.      why we did not make `-Wall' request these warnings.
  263. `-Wconversion'
  264.      Warn if a prototype causes a type conversion that is different
  265.      from what would happen to the same argument in the absence of a
  266.      prototype.  This includes conversions of fixed point to floating
  267.      and vice versa, and conversions changing the width or signedness
  268.      of a fixed point argument except when the same as the default
  269.      promotion.
  270.      Also, warn if a negative integer constant expression is implicitly
  271.      converted to an unsigned type.  For example, warn about the
  272.      assignment `x = -1' if `x' is unsigned.  But do not warn about
  273.      explicit casts like `(unsigned) -1'.
  274. `-Waggregate-return'
  275.      Warn if any functions that return structures or unions are defined
  276.      or called.  (In languages where you can return an array, this also
  277.      elicits a warning.)
  278. `-Wstrict-prototypes'
  279.      Warn if a function is declared or defined without specifying the
  280.      argument types.  (An old-style function definition is permitted
  281.      without a warning if preceded by a declaration which specifies the
  282.      argument types.)
  283. `-Wmissing-prototypes'
  284.      Warn if a global function is defined without a previous prototype
  285.      declaration.  This warning is issued even if the definition itself
  286.      provides a prototype.  The aim is to detect global functions that
  287.      fail to be declared in header files.
  288. `-Wmissing-declarations'
  289.      Warn if a global function is defined without a previous
  290.      declaration.  Do so even if the definition itself provides a
  291.      prototype.  Use this option to detect global functions that are
  292.      not declared in header files.
  293. `-Wredundant-decls'
  294.      Warn if anything is declared more than once in the same scope,
  295.      even in cases where multiple declaration is valid and changes
  296.      nothing.
  297. `-Wnested-externs'
  298.      Warn if an `extern' declaration is encountered within an function.
  299. `-Winline'
  300.      Warn if a function can not be inlined, and either it was declared
  301.      as inline, or else the `-finline-functions' option was given.
  302. `-Woverloaded-virtual'
  303.      Warn when a derived class function declaration may be an error in
  304.      defining a virtual function (C++ only).  In a derived class, the
  305.      definitions of virtual functions must match the type signature of a
  306.      virtual function declared in the base class.  With this option, the
  307.      compiler warns when you define a function with the same name as a
  308.      virtual function, but with a type signature that does not match any
  309.      declarations from the base class.
  310. `-Wsynth (C++ only)'
  311.      Warn when g++'s synthesis behavior does not match that of cfront.
  312.      For instance:
  313.           struct A {
  314.             operator int ();
  315.             A& operator = (int);
  316.           };
  317.           
  318.           main ()
  319.           {
  320.             A a,b;
  321.             a = b;
  322.           }
  323.      In this example, g++ will synthesize a default `A& operator =
  324.      (const A&);', while cfront will use the user-defined `operator ='.
  325. `-Werror'
  326.      Make all warnings into errors.
  327. File: gcc.info,  Node: Debugging Options,  Next: Optimize Options,  Prev: Warning Options,  Up: Invoking GCC
  328. Options for Debugging Your Program or GNU CC
  329. ============================================
  330.    GNU CC has various special options that are used for debugging
  331. either your program or GCC:
  332.      Produce debugging information in the operating system's native
  333.      format (stabs, COFF, XCOFF, or DWARF).  GDB can work with this
  334.      debugging information.
  335.      On most systems that use stabs format, `-g' enables use of extra
  336.      debugging information that only GDB can use; this extra information
  337.      makes debugging work better in GDB but will probably make other
  338.      debuggers crash or refuse to read the program.  If you want to
  339.      control for certain whether to generate the extra information, use
  340.      `-gstabs+', `-gstabs', `-gxcoff+', `-gxcoff', `-gdwarf+', or
  341.      `-gdwarf' (see below).
  342.      Unlike most other C compilers, GNU CC allows you to use `-g' with
  343.      `-O'.  The shortcuts taken by optimized code may occasionally
  344.      produce surprising results: some variables you declared may not
  345.      exist at all; flow of control may briefly move where you did not
  346.      expect it; some statements may not be executed because they
  347.      compute constant results or their values were already at hand;
  348.      some statements may execute in different places because they were
  349.      moved out of loops.
  350.      Nevertheless it proves possible to debug optimized output.  This
  351.      makes it reasonable to use the optimizer for programs that might
  352.      have bugs.
  353.      The following options are useful when GNU CC is generated with the
  354.      capability for more than one debugging format.
  355. `-ggdb'
  356.      Produce debugging information in the native format (if that is
  357.      supported), including GDB extensions if at all possible.
  358. `-gstabs'
  359.      Produce debugging information in stabs format (if that is
  360.      supported), without GDB extensions.  This is the format used by
  361.      DBX on most BSD systems.  On MIPS, Alpha and System V Release 4
  362.      systems this option produces stabs debugging output which is not
  363.      understood by DBX or SDB.  On System V Release 4 systems this
  364.      option requires the GNU assembler.
  365. `-gstabs+'
  366.      Produce debugging information in stabs format (if that is
  367.      supported), using GNU extensions understood only by the GNU
  368.      debugger (GDB).  The use of these extensions is likely to make
  369.      other debuggers crash or refuse to read the program.
  370. `-gcoff'
  371.      Produce debugging information in COFF format (if that is
  372.      supported).  This is the format used by SDB on most System V
  373.      systems prior to System V Release 4.
  374. `-gxcoff'
  375.      Produce debugging information in XCOFF format (if that is
  376.      supported).  This is the format used by the DBX debugger on IBM
  377.      RS/6000 systems.
  378. `-gxcoff+'
  379.      Produce debugging information in XCOFF format (if that is
  380.      supported), using GNU extensions understood only by the GNU
  381.      debugger (GDB).  The use of these extensions is likely to make
  382.      other debuggers crash or refuse to read the program, and may cause
  383.      assemblers other than the GNU assembler (GAS) to fail with an
  384.      error.
  385. `-gdwarf'
  386.      Produce debugging information in DWARF format (if that is
  387.      supported).  This is the format used by SDB on most System V
  388.      Release 4 systems.
  389. `-gdwarf+'
  390.      Produce debugging information in DWARF format (if that is
  391.      supported), using GNU extensions understood only by the GNU
  392.      debugger (GDB).  The use of these extensions is likely to make
  393.      other debuggers crash or refuse to read the program.
  394. `-gLEVEL'
  395. `-ggdbLEVEL'
  396. `-gstabsLEVEL'
  397. `-gcoffLEVEL'
  398. `-gxcoffLEVEL'
  399. `-gdwarfLEVEL'
  400.      Request debugging information and also use LEVEL to specify how
  401.      much information.  The default level is 2.
  402.      Level 1 produces minimal information, enough for making backtraces
  403.      in parts of the program that you don't plan to debug.  This
  404.      includes descriptions of functions and external variables, but no
  405.      information about local variables and no line numbers.
  406.      Level 3 includes extra information, such as all the macro
  407.      definitions present in the program.  Some debuggers support macro
  408.      expansion when you use `-g3'.
  409.      Generate extra code to write profile information suitable for the
  410.      analysis program `prof'.  You must use this option when compiling
  411.      the source files you want data about, and you must also use it when
  412.      linking.
  413. `-pg'
  414.      Generate extra code to write profile information suitable for the
  415.      analysis program `gprof'.  You must use this option when compiling
  416.      the source files you want data about, and you must also use it when
  417.      linking.
  418.      Generate extra code to write profile information for basic blocks,
  419.      which will record the number of times each basic block is
  420.      executed, the basic block start address, and the function name
  421.      containing the basic block.  If `-g' is used, the line number and
  422.      filename of the start of the basic block will also be recorded.
  423.      If not overridden by the machine description, the default action is
  424.      to append to the text file `bb.out'.
  425.      This data could be analyzed by a program like `tcov'.  Note,
  426.      however, that the format of the data is not what `tcov' expects.
  427.      Eventually GNU `gprof' should be extended to process this data.
  428. `-dLETTERS'
  429.      Says to make debugging dumps during compilation at times specified
  430.      by LETTERS.  This is used for debugging the compiler.  The file
  431.      names for most of the dumps are made by appending a word to the
  432.      source file name (e.g.  `foo.c.rtl' or `foo.c.jump').  Here are the
  433.      possible letters for use in LETTERS, and their meanings:
  434.     `M'
  435.           Dump all macro definitions, at the end of preprocessing, and
  436.           write no output.
  437.     `N'
  438.           Dump all macro names, at the end of preprocessing.
  439.     `D'
  440.           Dump all macro definitions, at the end of preprocessing, in
  441.           addition to normal output.
  442.     `y'
  443.           Dump debugging information during parsing, to standard error.
  444.     `r'
  445.           Dump after RTL generation, to `FILE.rtl'.
  446.     `x'
  447.           Just generate RTL for a function instead of compiling it.
  448.           Usually used with `r'.
  449.     `j'
  450.           Dump after first jump optimization, to `FILE.jump'.
  451.     `s'
  452.           Dump after CSE (including the jump optimization that sometimes
  453.           follows CSE), to `FILE.cse'.
  454.     `L'
  455.           Dump after loop optimization, to `FILE.loop'.
  456.     `t'
  457.           Dump after the second CSE pass (including the jump
  458.           optimization that sometimes follows CSE), to `FILE.cse2'.
  459.     `f'
  460.           Dump after flow analysis, to `FILE.flow'.
  461.     `c'
  462.           Dump after instruction combination, to the file
  463.           `FILE.combine'.
  464.     `S'
  465.           Dump after the first instruction scheduling pass, to
  466.           `FILE.sched'.
  467.     `l'
  468.           Dump after local register allocation, to `FILE.lreg'.
  469.     `g'
  470.           Dump after global register allocation, to `FILE.greg'.
  471.     `R'
  472.           Dump after the second instruction scheduling pass, to
  473.           `FILE.sched2'.
  474.     `J'
  475.           Dump after last jump optimization, to `FILE.jump2'.
  476.     `d'
  477.           Dump after delayed branch scheduling, to `FILE.dbr'.
  478.     `k'
  479.           Dump after conversion from registers to stack, to
  480.           `FILE.stack'.
  481.     `a'
  482.           Produce all the dumps listed above.
  483.     `m'
  484.           Print statistics on memory usage, at the end of the run, to
  485.           standard error.
  486.     `p'
  487.           Annotate the assembler output with a comment indicating which
  488.           pattern and alternative was used.
  489. `-fpretend-float'
  490.      When running a cross-compiler, pretend that the target machine
  491.      uses the same floating point format as the host machine.  This
  492.      causes incorrect output of the actual floating constants, but the
  493.      actual instruction sequence will probably be the same as GNU CC
  494.      would make when running on the target machine.
  495. `-save-temps'
  496.      Store the usual "temporary" intermediate files permanently; place
  497.      them in the current directory and name them based on the source
  498.      file.  Thus, compiling `foo.c' with `-c -save-temps' would produce
  499.      files `foo.i' and `foo.s', as well as `foo.o'.
  500. `-print-file-name=LIBRARY'
  501.      Print the full absolute name of the library file LIBRARY that
  502.      would be used when linking--and don't do anything else.  With this
  503.      option, GNU CC does not compile or link anything; it just prints
  504.      the file name.
  505. `-print-prog-name=PROGRAM'
  506.      Like `-print-file-name', but searches for a program such as `cpp'.
  507. `-print-libgcc-file-name'
  508.      Same as `-print-file-name=libgcc.a'.
  509.      This is useful when you use `-nostdlib' or `-nodefaultlibs' but
  510.      you do want to link with `libgcc.a'.  You can do
  511.           gcc -nostdlib FILES... `gcc -print-libgcc-file-name`
  512. `-print-search-dirs'
  513.      Print the name of the configured installation directory and a list
  514.      of program and library directories gcc will search--and don't do
  515.      anything else.
  516.      This is useful when gcc prints the error message `installation
  517.      problem, cannot exec cpp: No such file or directory'.  To resolve
  518.      this you either need to put `cpp' and the other compiler
  519.      components where gcc expects to find them, or you can set the
  520.      environment variable `GCC_EXEC_PREFIX' to the directory where you
  521.      installed them.  Don't forget the trailing '/'.  *Note Environment
  522.      Variables::.
  523. File: gcc.info,  Node: Optimize Options,  Next: Preprocessor Options,  Prev: Debugging Options,  Up: Invoking GCC
  524. Options That Control Optimization
  525. =================================
  526.    These options control various sorts of optimizations:
  527. `-O1'
  528.      Optimize.  Optimizing compilation takes somewhat more time, and a
  529.      lot more memory for a large function.
  530.      Without `-O', the compiler's goal is to reduce the cost of
  531.      compilation and to make debugging produce the expected results.
  532.      Statements are independent: if you stop the program with a
  533.      breakpoint between statements, you can then assign a new value to
  534.      any variable or change the program counter to any other statement
  535.      in the function and get exactly the results you would expect from
  536.      the source code.
  537.      Without `-O', the compiler only allocates variables declared
  538.      `register' in registers.  The resulting compiled code is a little
  539.      worse than produced by PCC without `-O'.
  540.      With `-O', the compiler tries to reduce code size and execution
  541.      time.
  542.      When you specify `-O', the compiler turns on `-fthread-jumps' and
  543.      `-fdefer-pop' on all machines.  The compiler turns on
  544.      `-fdelayed-branch' on machines that have delay slots, and
  545.      `-fomit-frame-pointer' on machines that can support debugging even
  546.      without a frame pointer.  On some machines the compiler also turns
  547.      on other flags.
  548. `-O2'
  549.      Optimize even more.  GNU CC performs nearly all supported
  550.      optimizations that do not involve a space-speed tradeoff.  The
  551.      compiler does not perform loop unrolling or function inlining when
  552.      you specify `-O2'.  As compared to `-O', this option increases
  553.      both compilation time and the performance of the generated code.
  554.      `-O2' turns on all optional optimizations except for loop unrolling
  555.      and function inlining.  It also turns on the `-fforce-mem' option
  556.      on all machines and frame pointer elimination on machines where
  557.      doing so does not interfere with debugging.
  558. `-O3'
  559.      Optimize yet more.  `-O3' turns on all optimizations specified by
  560.      `-O2' and also turns on the `inline-functions' option.
  561. `-O0'
  562.      Do not optimize.
  563.      If you use multiple `-O' options, with or without level numbers,
  564.      the last such option is the one that is effective.
  565.    Options of the form `-fFLAG' specify machine-independent flags.
  566. Most flags have both positive and negative forms; the negative form of
  567. `-ffoo' would be `-fno-foo'.  In the table below, only one of the forms
  568. is listed--the one which is not the default.  You can figure out the
  569. other form by either removing `no-' or adding it.
  570. `-ffloat-store'
  571.      Do not store floating point variables in registers, and inhibit
  572.      other options that might change whether a floating point value is
  573.      taken from a register or memory.
  574.      This option prevents undesirable excess precision on machines such
  575.      as the 68000 where the floating registers (of the 68881) keep more
  576.      precision than a `double' is supposed to have.  For most programs,
  577.      the excess precision does only good, but a few programs rely on the
  578.      precise definition of IEEE floating point.  Use `-ffloat-store' for
  579.      such programs.
  580. `-fno-default-inline'
  581.      Do not make member functions inline by default merely because they
  582.      are defined inside the class scope (C++ only).  Otherwise, when
  583.      you specify `-O', member functions defined inside class scope are
  584.      compiled inline by default; i.e., you don't need to add `inline'
  585.      in front of the member function name.
  586. `-fno-defer-pop'
  587.      Always pop the arguments to each function call as soon as that
  588.      function returns.  For machines which must pop arguments after a
  589.      function call, the compiler normally lets arguments accumulate on
  590.      the stack for several function calls and pops them all at once.
  591. `-fforce-mem'
  592.      Force memory operands to be copied into registers before doing
  593.      arithmetic on them.  This produces better code by making all memory
  594.      references potential common subexpressions.  When they are not
  595.      common subexpressions, instruction combination should eliminate
  596.      the separate register-load.  The `-O2' option turns on this option.
  597. `-fforce-addr'
  598.      Force memory address constants to be copied into registers before
  599.      doing arithmetic on them.  This may produce better code just as
  600.      `-fforce-mem' may.
  601. `-fomit-frame-pointer'
  602.      Don't keep the frame pointer in a register for functions that
  603.      don't need one.  This avoids the instructions to save, set up and
  604.      restore frame pointers; it also makes an extra register available
  605.      in many functions.  *It also makes debugging impossible on some
  606.      machines.*
  607.      On some machines, such as the Vax, this flag has no effect, because
  608.      the standard calling sequence automatically handles the frame
  609.      pointer and nothing is saved by pretending it doesn't exist.  The
  610.      machine-description macro `FRAME_POINTER_REQUIRED' controls
  611.      whether a target machine supports this flag.  *Note Registers::.
  612. `-fno-inline'
  613.      Don't pay attention to the `inline' keyword.  Normally this option
  614.      is used to keep the compiler from expanding any functions inline.
  615.      Note that if you are not optimizing, no functions can be expanded
  616.      inline.
  617. `-finline-functions'
  618.      Integrate all simple functions into their callers.  The compiler
  619.      heuristically decides which functions are simple enough to be worth
  620.      integrating in this way.
  621.      If all calls to a given function are integrated, and the function
  622.      is declared `static', then the function is normally not output as
  623.      assembler code in its own right.
  624. `-fkeep-inline-functions'
  625.      Even if all calls to a given function are integrated, and the
  626.      function is declared `static', nevertheless output a separate
  627.      run-time callable version of the function.
  628. `-fno-function-cse'
  629.      Do not put function addresses in registers; make each instruction
  630.      that calls a constant function contain the function's address
  631.      explicitly.
  632.      This option results in less efficient code, but some strange hacks
  633.      that alter the assembler output may be confused by the
  634.      optimizations performed when this option is not used.
  635. `-ffast-math'
  636.      This option allows GCC to violate some ANSI or IEEE rules and/or
  637.      specifications in the interest of optimizing code for speed.  For
  638.      example, it allows the compiler to assume arguments to the `sqrt'
  639.      function are non-negative numbers and that no floating-point values
  640.      are NaNs.
  641.      This option should never be turned on by any `-O' option since it
  642.      can result in incorrect output for programs which depend on an
  643.      exact implementation of IEEE or ANSI rules/specifications for math
  644.      functions.
  645.    The following options control specific optimizations.  The `-O2'
  646. option turns on all of these optimizations except `-funroll-loops' and
  647. `-funroll-all-loops'.  On most machines, the `-O' option turns on the
  648. `-fthread-jumps' and `-fdelayed-branch' options, but specific machines
  649. may handle it differently.
  650.    You can use the following flags in the rare cases when "fine-tuning"
  651. of optimizations to be performed is desired.
  652. `-fstrength-reduce'
  653.      Perform the optimizations of loop strength reduction and
  654.      elimination of iteration variables.
  655. `-fthread-jumps'
  656.      Perform optimizations where we check to see if a jump branches to a
  657.      location where another comparison subsumed by the first is found.
  658.      If so, the first branch is redirected to either the destination of
  659.      the second branch or a point immediately following it, depending
  660.      on whether the condition is known to be true or false.
  661. `-fcse-follow-jumps'
  662.      In common subexpression elimination, scan through jump instructions
  663.      when the target of the jump is not reached by any other path.  For
  664.      example, when CSE encounters an `if' statement with an `else'
  665.      clause, CSE will follow the jump when the condition tested is
  666.      false.
  667. `-fcse-skip-blocks'
  668.      This is similar to `-fcse-follow-jumps', but causes CSE to follow
  669.      jumps which conditionally skip over blocks.  When CSE encounters a
  670.      simple `if' statement with no else clause, `-fcse-skip-blocks'
  671.      causes CSE to follow the jump around the body of the `if'.
  672. `-frerun-cse-after-loop'
  673.      Re-run common subexpression elimination after loop optimizations
  674.      has been performed.
  675. `-fexpensive-optimizations'
  676.      Perform a number of minor optimizations that are relatively
  677.      expensive.
  678. `-fdelayed-branch'
  679.      If supported for the target machine, attempt to reorder
  680.      instructions to exploit instruction slots available after delayed
  681.      branch instructions.
  682. `-fschedule-insns'
  683.      If supported for the target machine, attempt to reorder
  684.      instructions to eliminate execution stalls due to required data
  685.      being unavailable.  This helps machines that have slow floating
  686.      point or memory load instructions by allowing other instructions
  687.      to be issued until the result of the load or floating point
  688.      instruction is required.
  689. `-fschedule-insns2'
  690.      Similar to `-fschedule-insns', but requests an additional pass of
  691.      instruction scheduling after register allocation has been done.
  692.      This is especially useful on machines with a relatively small
  693.      number of registers and where memory load instructions take more
  694.      than one cycle.
  695. `-fcaller-saves'
  696.      Enable values to be allocated in registers that will be clobbered
  697.      by function calls, by emitting extra instructions to save and
  698.      restore the registers around such calls.  Such allocation is done
  699.      only when it seems to result in better code than would otherwise
  700.      be produced.
  701.      This option is enabled by default on certain machines, usually
  702.      those which have no call-preserved registers to use instead.
  703. `-funroll-loops'
  704.      Perform the optimization of loop unrolling.  This is only done for
  705.      loops whose number of iterations can be determined at compile time
  706.      or run time.  `-funroll-loop' implies both `-fstrength-reduce' and
  707.      `-frerun-cse-after-loop'.
  708. `-funroll-all-loops'
  709.      Perform the optimization of loop unrolling.  This is done for all
  710.      loops and usually makes programs run more slowly.
  711.      `-funroll-all-loops' implies `-fstrength-reduce' as well as
  712.      `-frerun-cse-after-loop'.
  713. `-fno-peephole'
  714.      Disable any machine-specific peephole optimizations.
  715. File: gcc.info,  Node: Preprocessor Options,  Next: Assembler Options,  Prev: Optimize Options,  Up: Invoking GCC
  716. Options Controlling the Preprocessor
  717. ====================================
  718.    These options control the C preprocessor, which is run on each C
  719. source file before actual compilation.
  720.    If you use the `-E' option, nothing is done except preprocessing.
  721. Some of these options make sense only together with `-E' because they
  722. cause the preprocessor output to be unsuitable for actual compilation.
  723. `-include FILE'
  724.      Process FILE as input before processing the regular input file.
  725.      In effect, the contents of FILE are compiled first.  Any `-D' and
  726.      `-U' options on the command line are always processed before
  727.      `-include FILE', regardless of the order in which they are
  728.      written.  All the `-include' and `-imacros' options are processed
  729.      in the order in which they are written.
  730. `-imacros FILE'
  731.      Process FILE as input, discarding the resulting output, before
  732.      processing the regular input file.  Because the output generated
  733.      from FILE is discarded, the only effect of `-imacros FILE' is to
  734.      make the macros defined in FILE available for use in the main
  735.      input.
  736.      Any `-D' and `-U' options on the command line are always processed
  737.      before `-imacros FILE', regardless of the order in which they are
  738.      written.  All the `-include' and `-imacros' options are processed
  739.      in the order in which they are written.
  740. `-idirafter DIR'
  741.      Add the directory DIR to the second include path.  The directories
  742.      on the second include path are searched when a header file is not
  743.      found in any of the directories in the main include path (the one
  744.      that `-I' adds to).
  745. `-iprefix PREFIX'
  746.      Specify PREFIX as the prefix for subsequent `-iwithprefix' options.
  747. `-iwithprefix DIR'
  748.      Add a directory to the second include path.  The directory's name
  749.      is made by concatenating PREFIX and DIR, where PREFIX was
  750.      specified previously with `-iprefix'.  If you have not specified a
  751.      prefix yet, the directory containing the installed passes of the
  752.      compiler is used as the default.
  753. `-iwithprefixbefore DIR'
  754.      Add a directory to the main include path.  The directory's name is
  755.      made by concatenating PREFIX and DIR, as in the case of
  756.      `-iwithprefix'.
  757. `-isystem DIR'
  758.      Add a directory to the beginning of the second include path,
  759.      marking it as a system directory, so that it gets the same special
  760.      treatment as is applied to the standard system directories.
  761. `-nostdinc'
  762.      Do not search the standard system directories for header files.
  763.      Only the directories you have specified with `-I' options (and the
  764.      current directory, if appropriate) are searched.  *Note Directory
  765.      Options::, for information on `-I'.
  766.      By using both `-nostdinc' and `-I-', you can limit the include-file
  767.      search path to only those directories you specify explicitly.
  768. `-undef'
  769.      Do not predefine any nonstandard macros.  (Including architecture
  770.      flags).
  771.      Run only the C preprocessor.  Preprocess all the C source files
  772.      specified and output the results to standard output or to the
  773.      specified output file.
  774.      Tell the preprocessor not to discard comments.  Used with the `-E'
  775.      option.
  776.      Tell the preprocessor not to generate `#line' directives.  Used
  777.      with the `-E' option.
  778.      Tell the preprocessor to output a rule suitable for `make'
  779.      describing the dependencies of each object file.  For each source
  780.      file, the preprocessor outputs one `make'-rule whose target is the
  781.      object file name for that source file and whose dependencies are
  782.      all the `#include' header files it uses.  This rule may be a
  783.      single line or may be continued with `\'-newline if it is long.
  784.      The list of rules is printed on standard output instead of the
  785.      preprocessed C program.
  786.      `-M' implies `-E'.
  787.      Another way to specify output of a `make' rule is by setting the
  788.      environment variable `DEPENDENCIES_OUTPUT' (*note Environment
  789.      Variables::.).
  790. `-MM'
  791.      Like `-M' but the output mentions only the user header files
  792.      included with `#include "FILE"'.  System header files included
  793.      with `#include <FILE>' are omitted.
  794. `-MD'
  795.      Like `-M' but the dependency information is written to a file made
  796.      by replacing ".c" with ".d" at the end of the input file names.
  797.      This is in addition to compiling the file as specified--`-MD' does
  798.      not inhibit ordinary compilation the way `-M' does.
  799.      In Mach, you can use the utility `md' to merge multiple dependency
  800.      files into a single dependency file suitable for using with the
  801.      `make' command.
  802. `-MMD'
  803.      Like `-MD' except mention only user header files, not system
  804.      header files.
  805. `-MG'
  806.      Treat missing header files as generated files and assume they live
  807.      in the same directory as the source file.  If you specify `-MG',
  808.      you must also specify either `-M' or `-MM'.  `-MG' is not
  809.      supported with `-MD' or `-MMD'.
  810.      Print the name of each header file used, in addition to other
  811.      normal activities.
  812. `-AQUESTION(ANSWER)'
  813.      Assert the answer ANSWER for QUESTION, in case it is tested with a
  814.      preprocessing conditional such as `#if #QUESTION(ANSWER)'.  `-A-'
  815.      disables the standard assertions that normally describe the target
  816.      machine.
  817. `-DMACRO'
  818.      Define macro MACRO with the string `1' as its definition.
  819. `-DMACRO=DEFN'
  820.      Define macro MACRO as DEFN.  All instances of `-D' on the command
  821.      line are processed before any `-U' options.
  822. `-UMACRO'
  823.      Undefine macro MACRO.  `-U' options are evaluated after all `-D'
  824.      options, but before any `-include' and `-imacros' options.
  825. `-dM'
  826.      Tell the preprocessor to output only a list of the macro
  827.      definitions that are in effect at the end of preprocessing.  Used
  828.      with the `-E' option.
  829. `-dD'
  830.      Tell the preprocessing to pass all macro definitions into the
  831.      output, in their proper sequence in the rest of the output.
  832. `-dN'
  833.      Like `-dD' except that the macro arguments and contents are
  834.      omitted.  Only `#define NAME' is included in the output.
  835. `-trigraphs'
  836.      Support ANSI C trigraphs.  The `-ansi' option also has this effect.
  837. `-Wp,OPTION'
  838.      Pass OPTION as an option to the preprocessor.  If OPTION contains
  839.      commas, it is split into multiple options at the commas.
  840. File: gcc.info,  Node: Assembler Options,  Next: Link Options,  Prev: Preprocessor Options,  Up: Invoking GCC
  841. Passing Options to the Assembler
  842. ================================
  843.    You can pass options to the assembler.
  844. `-Wa,OPTION'
  845.      Pass OPTION as an option to the assembler.  If OPTION contains
  846.      commas, it is split into multiple options at the commas.
  847. File: gcc.info,  Node: Link Options,  Next: Directory Options,  Prev: Assembler Options,  Up: Invoking GCC
  848. Options for Linking
  849. ===================
  850.    These options come into play when the compiler links object files
  851. into an executable output file.  They are meaningless if the compiler is
  852. not doing a link step.
  853. `OBJECT-FILE-NAME'
  854.      A file name that does not end in a special recognized suffix is
  855.      considered to name an object file or library.  (Object files are
  856.      distinguished from libraries by the linker according to the file
  857.      contents.)  If linking is done, these object files are used as
  858.      input to the linker.
  859.      If any of these options is used, then the linker is not run, and
  860.      object file names should not be used as arguments.  *Note Overall
  861.      Options::.
  862. `-lLIBRARY'
  863.      Search the library named LIBRARY when linking.
  864.      It makes a difference where in the command you write this option;
  865.      the linker searches processes libraries and object files in the
  866.      order they are specified.  Thus, `foo.o -lz bar.o' searches
  867.      library `z' after file `foo.o' but before `bar.o'.  If `bar.o'
  868.      refers to functions in `z', those functions may not be loaded.
  869.      The linker searches a standard list of directories for the library,
  870.      which is actually a file named `libLIBRARY.a'.  The linker then
  871.      uses this file as if it had been specified precisely by name.
  872.      The directories searched include several standard system
  873.      directories plus any that you specify with `-L'.
  874.      Normally the files found this way are library files--archive files
  875.      whose members are object files.  The linker handles an archive
  876.      file by scanning through it for members which define symbols that
  877.      have so far been referenced but not defined.  But if the file that
  878.      is found is an ordinary object file, it is linked in the usual
  879.      fashion.  The only difference between using an `-l' option and
  880.      specifying a file name is that `-l' surrounds LIBRARY with `lib'
  881.      and `.a' and searches several directories.
  882. `-lobjc'
  883.      You need this special case of the `-l' option in order to link an
  884.      Objective C program.
  885. `-nostartfiles'
  886.      Do not use the standard system startup files when linking.  The
  887.      standard system libraries are used normally, unless `-nostdlib' or
  888.      `-nodefaultlibs' is used.
  889. `-nodefaultlibs'
  890.      Do not use the standard system libraries when linking.  Only the
  891.      libraries you specify will be passed to the linker.  The standard
  892.      startup files are used normally, unless `-nostartfiles' is used.
  893. `-nostdlib'
  894.      Do not use the standard system startup files or libraries when
  895.      linking.  No startup files and only the libraries you specify will
  896.      be passed to the linker.
  897.      One of the standard libraries bypassed by `-nostdlib' and
  898.      `-nodefaultlibs' is `libgcc.a', a library of internal subroutines
  899.      that GNU CC uses to overcome shortcomings of particular machines,
  900.      or special needs for some languages.  (*Note Interfacing to GNU CC
  901.      Output: Interface, for more discussion of `libgcc.a'.) In most
  902.      cases, you need `libgcc.a' even when you want to avoid other
  903.      standard libraries.  In other words, when you specify `-nostdlib'
  904.      or `-nodefaultlibs' you should usually specify `-lgcc' as well.
  905.      This ensures that you have no unresolved references to internal
  906.      GNU CC library subroutines.  (For example, `__main', used to
  907.      ensure C++ constructors will be called; *note `collect2':
  908.      Collect2..)
  909.      Remove all symbol table and relocation information from the
  910.      executable.
  911. `-static'
  912.      On systems that support dynamic linking, this prevents linking
  913.      with the shared libraries.  On other systems, this option has no
  914.      effect.
  915. `-shared'
  916.      Produce a shared object which can then be linked with other
  917.      objects to form an executable.  Only a few systems support this
  918.      option.
  919. `-symbolic'
  920.      Bind references to global symbols when building a shared object.
  921.      Warn about any unresolved references (unless overridden by the
  922.      link editor option `-Xlinker -z -Xlinker defs').  Only a few
  923.      systems support this option.
  924. `-Xlinker OPTION'
  925.      Pass OPTION as an option to the linker.  You can use this to
  926.      supply system-specific linker options which GNU CC does not know
  927.      how to recognize.
  928.      If you want to pass an option that takes an argument, you must use
  929.      `-Xlinker' twice, once for the option and once for the argument.
  930.      For example, to pass `-assert definitions', you must write
  931.      `-Xlinker -assert -Xlinker definitions'.  It does not work to write
  932.      `-Xlinker "-assert definitions"', because this passes the entire
  933.      string as a single argument, which is not what the linker expects.
  934. `-Wl,OPTION'
  935.      Pass OPTION as an option to the linker.  If OPTION contains
  936.      commas, it is split into multiple options at the commas.
  937. `-u SYMBOL'
  938.      Pretend the symbol SYMBOL is undefined, to force linking of
  939.      library modules to define it.  You can use `-u' multiple times with
  940.      different symbols to force loading of additional library modules.
  941.