Next: , Previous: Compiling Programs, Up: Compiling with gcc


3.2 Switches for gcc

The gcc command accepts switches that control the compilation process. These switches are fully described in this section. First we briefly list all the switches, in alphabetical order, then we describe the switches in more detail in functionally grouped sections.

More switches exist for GCC than those documented here, especially for specific targets. However, their use is not recommended as they may change code generation in ways that are incompatible with the Ada run-time library, or can cause inconsistencies between compilation units.

-b target
Compile your program to run on target, which is the name of a system configuration. You must have a GNAT cross-compiler built if target is not the same as your host system.
-Bdir
Load compiler executables (for example, gnat1, the Ada compiler) from dir instead of the default location. Only use this switch when multiple versions of the GNAT compiler are available. See Options for Directory Search, for further details. You would normally use the -b or -V switch instead.
-c
Compile. Always use this switch when compiling Ada programs.

Note: for some other languages when using gcc, notably in the case of C and C++, it is possible to use use gcc without a -c switch to compile and link in one step. In the case of GNAT, you cannot use this approach, because the binder must be run and gcc cannot be used to run the GNAT binder.

-fcallgraph-info[=su,da]
Makes the compiler output callgraph information for the program, on a per-file basis. The information is generated in the VCG format. It can be decorated with additional, per-node and/or per-edge information, if a list of comma-separated markers is additionally specified. When the su marker is specified, the callgraph is decorated with stack usage information; it is equivalent to -fstack-usage. When the da marker is specified, the callgraph is decorated with information about dynamically allocated objects.
-fdump-scos
Generates SCO (Source Coverage Obligation) information in the ALI file. This information is used by advanced coverage tools. See unit SCOs in the compiler sources for details in files scos.ads and scos.adb.
-fdump-xref
Generates cross reference information in GLI files for C and C++ sources. The GLI files have the same syntax as the ALI files for Ada, and can be used for source navigation in IDEs and on the command line using e.g. gnatxref and the --ext=gli switch.
-flto[=n]
Enables Link Time Optimization. This switch must be used in conjunction with the traditional -Ox switches and instructs the compiler to defer most optimizations until the link stage. The advantage of this approach is that the compiler can do a whole-program analysis and choose the best interprocedural optimization strategy based on a complete view of the program, instead of a fragmentary view with the usual approach. This can also speed up the compilation of huge programs and reduce the size of the final executable, compared with a per-unit compilation with full inlining across modules enabled with the -gnatn2 switch. The drawback of this approach is that it may require much more memory. The switch, as well as the accompanying -Ox switches, must be specified both for the compilation and the link phases. If the n parameter is specified, the optimization and final code generation at link time are executed using n parallel jobs by means of an installed make program.
-fno-inline
Suppresses all inlining, even if other optimization or inlining switches are set. This includes suppression of inlining that results from the use of the pragma Inline_Always. Any occurrences of pragma Inline or Inline_Always are ignored, and -gnatn and -gnatN have no effects if this switch is present. Note that inlining can also be suppressed on a finer-grained basis with pragma No_Inline.
-fno-inline-functions
Suppresses automatic inlining of subprograms, which is enabled if -O3 is used.
-fno-inline-small-functions
Suppresses automatic inlining of small subprograms, which is enabled if -O2 is used.
-fno-inline-functions-called-once
Suppresses inlining of subprograms local to the unit and called once from within it, which is enabled if -O1 is used.
-fno-ivopts
Suppresses high-level loop induction variable optimizations, which are enabled if -O1 is used. These optimizations are generally profitable but, for some specific cases of loops with numerous uses of the iteration variable that follow a common pattern, they may end up destroying the regularity that could be exploited at a lower level and thus producing inferior code.
-fno-strict-aliasing
Causes the compiler to avoid assumptions regarding non-aliasing of objects of different types. See Optimization and Strict Aliasing for details.
-fstack-check
Activates stack checking. See Stack Overflow Checking for details.
-fstack-usage
Makes the compiler output stack usage information for the program, on a per-subprogram basis. See Static Stack Usage Analysis for details.
-g
Generate debugging information. This information is stored in the object file and copied from there to the final executable file by the linker, where it can be read by the debugger. You must use the -g switch if you plan on using the debugger.
-gnat83
Enforce Ada 83 restrictions.
-gnat95
Enforce Ada 95 restrictions.
-gnat05
Allow full Ada 2005 features.
-gnat2005
Allow full Ada 2005 features (same as -gnat05)
-gnat12

-gnat2012
Allow full Ada 2012 features (same as -gnat12)
-gnata
Assertions enabled. Pragma Assert and pragma Debug to be activated. Note that these pragmas can also be controlled using the configuration pragmas Assertion_Policy and Debug_Policy. It also activates pragmas Check, Precondition, and Postcondition. Note that these pragmas can also be controlled using the configuration pragma Check_Policy. In Ada 2012, it also activates all assertions defined in the RM as aspects: preconditions, postconditions, type invariants and (sub)type predicates. In all Ada modes, corresponding pragmas for type invariants and (sub)type predicates are also activated.
-gnatA
Avoid processing gnat.adc. If a gnat.adc file is present, it will be ignored.
-gnatb
Generate brief messages to stderr even if verbose mode set.
-gnatB
Assume no invalid (bad) values except for 'Valid attribute use (see Validity Checking).
-gnatc
Check syntax and semantics only (no code generation attempted). When the compiler is invoked by gnatmake, if the switch -gnatc is only given to the compiler (after -cargs or in package Compiler of the project file, gnatmake will fail because it will not find the object file after compilation. If gnatmake is called with -gnatc as a builder switch (before -cargs or in package Builder of the project file) then gnatmake will not fail because it will not look for the object files after compilation, and it will not try to build and link. This switch may not be given if a previous -gnatR switch has been given, since -gnatR requires that the code generator be called to complete determination of representation information.
-gnatC
Generate CodePeer intermediate format (no code generation attempted). This switch will generate an intermediate representation suitable for use by CodePeer (.scil files). This switch is not compatible with code generation (it will, among other things, disable some switches such as -gnatn, and enable others such as -gnata).
-gnatd
Specify debug options for the compiler. The string of characters after the -gnatd specify the specific debug options. The possible characters are 0-9, a-z, A-Z, optionally preceded by a dot. See compiler source file debug.adb for details of the implemented debug options. Certain debug options are relevant to applications programmers, and these are documented at appropriate points in this users guide.
-gnatD
Create expanded source files for source level debugging. This switch also suppress generation of cross-reference information (see -gnatx). Note that this switch is not allowed if a previous -gnatR switch has been given, since these two switches are not compatible.
-gnateA
Check that the actual parameters of a subprogram call are not aliases of one another. To qualify as aliasing, the actuals must denote objects of a composite type, their memory locations must be identical or overlapping, and at least one of the corresponding formal parameters must be of mode OUT or IN OUT.
          type Rec_Typ is record
             Data : Integer := 0;
          end record;
          
          function Self (Val : Rec_Typ) return Rec_Typ is
          begin
             return Val;
          end Self;
          
          procedure Detect_Aliasing (Val_1 : in out Rec_Typ; Val_2 : Rec_Typ) is
          begin
             null;
          end Detect_Aliasing;
          
          Obj : Rec_Typ;
          
          Detect_Aliasing (Obj, Obj);
          Detect_Aliasing (Obj, Self (Obj));

In the example above, the first call to Detect_Aliasing fails with a Program_Error at runtime because the actuals for Val_1 and Val_2 denote the same object. The second call executes without raising an exception because Self(Obj) produces an anonymous object which does not share the memory location of Obj.

-gnatec=path
Specify a configuration pragma file (the equal sign is optional) (see The Configuration Pragmas Files).
-gnateC
Generate CodePeer messages in a compiler-like format. This switch is only effective if -gnatcC is also specified and requires an installation of CodePeer.
-gnated
Disable atomic synchronization
-gnateDsymbol[=value]
Defines a symbol, associated with value, for preprocessing. (see Integrated Preprocessing).
-gnateE
Generate extra information in exception messages. In particular, display extra column information and the value and range associated with index and range check failures, and extra column information for access checks. In cases where the compiler is able to determine at compile time that a check will fail, it gives a warning, and the extra information is not produced at run time.
-gnatef
Display full source path name in brief error messages.
-gnateF
Check for overflow on all floating-point operations, including those for unconstrained predefined types. See description of pragma Check_Float_Overflow in GNAT RM.
-gnateG
Save result of preprocessing in a text file.
-gnateinnn
Set maximum number of instantiations during compilation of a single unit to nnn. This may be useful in increasing the default maximum of 8000 for the rare case when a single unit legitimately exceeds this limit.
-gnateInnn
Indicates that the source is a multi-unit source and that the index of the unit to compile is nnn. nnn needs to be a positive number and need to be a valid index in the multi-unit source.
-gnatel
This switch can be used with the static elaboration model to issue info messages showing where implicit pragma Elaborate and pragma Elaborate_All are generated. This is useful in diagnosing elaboration circularities caused by these implicit pragmas when using the static elaboration model. See See the section in this guide on elaboration checking for further details. These messages are not generated by default, and are intended only for temporary use when debugging circularity problems.
-gnateL
This switch turns off the info messages about implicit elaboration pragmas.
-gnatem=path
Specify a mapping file (the equal sign is optional) (see Units to Sources Mapping Files).
-gnatep=file
Specify a preprocessing data file (the equal sign is optional) (see Integrated Preprocessing).
-gnateP
Turn categorization dependency errors into warnings. Ada requires that units that WITH one another have compatible categories, for example a Pure unit cannot WITH a Preelaborate unit. If this switch is used, these errors become warnings (which can be ignored, or suppressed in the usual manner). This can be useful in some specialized circumstances such as the temporary use of special test software.
-gnateS
Synonym of -fdump-scos, kept for backwards compatibility.
-gnatet=path
Generate target dependent information. The format of the output file is described in the section about switch -gnateT.
-gnateT=path
Read target dependent information, such as endianness or sizes and alignments of base type. If this switch is passed, the default target dependent information of the compiler is replaced by the one read from the input file. This is used by tools other than the compiler, e.g. to do semantic analysis of programs that will run on some other target than the machine on which the tool is run.

The following target dependent values should be defined, where Nat denotes a natural integer value, Pos denotes a positive integer value, and fields marked with a question mark are boolean fields, where a value of 0 is False, and a value of 1 is True:

          Bits_BE                    : Nat; -- Bits stored big-endian?
          Bits_Per_Unit              : Pos; -- Bits in a storage unit
          Bits_Per_Word              : Pos; -- Bits in a word
          Bytes_BE                   : Nat; -- Bytes stored big-endian?
          Char_Size                  : Pos; -- Standard.Character'Size
          Double_Float_Alignment     : Nat; -- Alignment of double float
          Double_Scalar_Alignment    : Nat; -- Alignment of double length scalar
          Double_Size                : Pos; -- Standard.Long_Float'Size
          Float_Size                 : Pos; -- Standard.Float'Size
          Float_Words_BE             : Nat; -- Float words stored big-endian?
          Int_Size                   : Pos; -- Standard.Integer'Size
          Long_Double_Size           : Pos; -- Standard.Long_Long_Float'Size
          Long_Long_Size             : Pos; -- Standard.Long_Long_Integer'Size
          Long_Size                  : Pos; -- Standard.Long_Integer'Size
          Maximum_Alignment          : Pos; -- Maximum permitted alignment
          Max_Unaligned_Field        : Pos; -- Maximum size for unaligned bit field
          Pointer_Size               : Pos; -- System.Address'Size
          Short_Enums                : Nat; -- Short foreign convention enums?
          Short_Size                 : Pos; -- Standard.Short_Integer'Size
          Strict_Alignment           : Nat; -- Strict alignment?
          System_Allocator_Alignment : Nat; -- Alignment for malloc calls
          Wchar_T_Size               : Pos; -- Interfaces.C.wchar_t'Size
          Words_BE                   : Nat; -- Words stored big-endian?

The format of the input file is as follows. First come the values of the variables defined above, with one line per value:

          name  value

where name is the name of the parameter, spelled out in full, and cased as in the above list, and value is an unsigned decimal integer. Two or more blanks separates the name from the value.

All the variables must be present, in alphabetical order (i.e. the same order as the list above).

Then there is a blank line to separate the two parts of the file. Then come the lines showing the floating-point types to be registered, with one line per registered mode:

          name  digs float_rep size alignment

where name is the string name of the type (which can have single spaces embedded in the name (e.g. long double), digs is the number of digits for the floating-point type, float_rep is the float representation (I/V/A for IEEE-754-Binary, Vax_Native, AAMP), size is the size in bits, alignment is the alignment in bits. The name is followed by at least two blanks, fields are separated by at least one blank, and a LF character immediately follows the alignment field.

Here is an example of a target parameterization file:

          Bits_BE                       0
          Bits_Per_Unit                 8
          Bits_Per_Word                64
          Bytes_BE                      0
          Char_Size                     8
          Double_Float_Alignment        0
          Double_Scalar_Alignment       0
          Double_Size                  64
          Float_Size                   32
          Float_Words_BE                0
          Int_Size                     64
          Long_Double_Size            128
          Long_Long_Size               64
          Long_Size                    64
          Maximum_Alignment            16
          Max_Unaligned_Field          64
          Pointer_Size                 64
          Short_Size                   16
          Strict_Alignment              0
          System_Allocator_Alignment   16
          Wchar_T_Size                 32
          Words_BE                      0
          
          float         15  I  64  64
          double        15  I  64  64
          long double   18  I  80 128
          TF            33  I 128 128

-gnateu
Ignore unrecognized validity, warning, and style switches that appear after this switch is given. This may be useful when compiling sources developed on a later version of the compiler with an earlier version. Of course the earlier version must support this switch.
-gnateV
Check that all actual parameters of a subprogram call are valid according to the rules of validity checking (see Validity Checking).
-gnateY
Ignore all STYLE_CHECKS pragmas. Full legality checks are still carried out, but the pragmas have no effect on what style checks are active. This allows all style checking options to be controlled from the command line.
-gnatE
Full dynamic elaboration checks.
-gnatf
Full errors. Multiple errors per line, all undefined references, do not attempt to suppress cascaded errors.
-gnatF
Externals names are folded to all uppercase.
-gnatg
Internal GNAT implementation mode. This should not be used for applications programs, it is intended only for use by the compiler and its run-time library. For documentation, see the GNAT sources. Note that -gnatg implies -gnatw.ge and -gnatyg so that all standard warnings and all standard style options are turned on. All warnings and style messages are treated as errors.
-gnatG=nn
List generated expanded code in source form.
-gnath
Output usage information. The output is written to stdout.
-gnatic
Identifier character set (c=1/2/3/4/8/9/p/f/n/w). For details of the possible selections for c, see Character Set Control.
-gnatI
Ignore representation clauses. When this switch is used, representation clauses are treated as comments. This is useful when initially porting code where you want to ignore rep clause problems, and also for compiling foreign code (particularly for use with ASIS). The representation clauses that are ignored are: enumeration_representation_clause, record_representation_clause, and attribute_definition_clause for the following attributes: Address, Alignment, Bit_Order, Component_Size, Machine_Radix, Object_Size, Size, Small, Stream_Size, and Value_Size. Note that this option should be used only for compiling – the code is likely to malfunction at run time.

Note that when -gnatct is used to generate trees for input into ASIS tools, these representation clauses are removed from the tree and ignored. This means that the tool will not see them.

-gnatjnn
Reformat error messages to fit on nn character lines
-gnatk=n
Limit file names to n (1-999) characters (k = krunch).
-gnatl
Output full source listing with embedded error messages.
-gnatL
Used in conjunction with -gnatG or -gnatD to intersperse original source lines (as comment lines with line numbers) in the expanded source output.
-gnatm=n
Limit number of detected error or warning messages to n where n is in the range 1..999999. The default setting if no switch is given is 9999. If the number of warnings reaches this limit, then a message is output and further warnings are suppressed, but the compilation is continued. If the number of error messages reaches this limit, then a message is output and the compilation is abandoned. The equal sign here is optional. A value of zero means that no limit applies.
-gnatn[12]
Activate inlining for subprograms for which pragma Inline is specified. This inlining is performed by the GCC back-end. An optional digit sets the inlining level: 1 for moderate inlining across modules or 2 for full inlining across modules. If no inlining level is specified, the compiler will pick it based on the optimization level.
-gnatN
Activate front end inlining for subprograms for which pragma Inline is specified. This inlining is performed by the front end and will be visible in the -gnatG output.

When using a gcc-based back end (in practice this means using any version of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of -gnatN is deprecated, and the use of -gnatn is preferred. Historically front end inlining was more extensive than the gcc back end inlining, but that is no longer the case.

-gnato??
Set default mode for handling generation of code to avoid intermediate arithmetic overflow. Here `??' is two digits, a single digit, or nothing. Each digit is one of the digits `1' through `3':

If only one digit appears then it applies to all cases; if two digits are given, then the first applies outside assertions, and the second within assertions.

If no digits follow the -gnato, then it is equivalent to -gnato11, causing all intermediate overflows to be handled in strict mode.

This switch also causes arithmetic overflow checking to be performed (as though pragma Unsuppress (Overflow_Mode) has been specified.

The default if no option -gnato is given is that overflow handling is in STRICT mode (computations done using the base type), and that overflow checking is suppressed.

Note that division by zero is a separate check that is not controlled by this switch (division by zero checking is on by default).

See also Specifying the Desired Mode.

-gnatp
Suppress all checks. See Run-Time Checks for details. This switch has no effect if cancelled by a subsequent -gnat-p switch.
-gnat-p
Cancel effect of previous -gnatp switch.
-gnatP
Enable polling. This is required on some systems (notably Windows NT) to obtain asynchronous abort and asynchronous transfer of control capability. See Pragma Polling, for full details.
-gnatq
Don't quit. Try semantics, even if parse errors.
-gnatQ
Don't quit. Generate ALI and tree files even if illegalities.
-gnatr
Treat pragma Restrictions as Restriction_Warnings.
-gnatR[0/1/2/3[s]]
Output representation information for declared types and objects. Note that this switch is not allowed if a previous -gnatD switch has been given, since these two switches are not compatible.
-gnatRm[s]
Output convention and parameter passing mechanisms for all subprograms.
-gnats
Syntax check only.
-gnatS
Print package Standard.
-gnatt
Generate tree output file.
-gnatTnnn
All compiler tables start at nnn times usual starting size.
-gnatu
List units for this compilation.
-gnatU
Tag all error messages with the unique string “error:”
-gnatv
Verbose mode. Full error output with source lines to stdout.
-gnatV
Control level of validity checking (see Validity Checking).
-gnatwxxx
Warning mode where xxx is a string of option letters that denotes the exact warnings that are enabled or disabled (see Warning Message Control).
-gnatWe
Wide character encoding method (e=n/h/u/s/e/8).
-gnatx
Suppress generation of cross-reference information.
-gnatX
Enable GNAT implementation extensions and latest Ada version.
-gnaty
Enable built-in style checks (see Style Checking).
-gnatzm
Distribution stub generation and compilation (m=r/c for receiver/caller stubs).
-Idir
Direct GNAT to search the dir directory for source files needed by the current compilation (see Search Paths and the Run-Time Library (RTL)).
-I-
Except for the source file named in the command line, do not look for source files in the directory containing the source file named in the command line (see Search Paths and the Run-Time Library (RTL)).
-mbig-switch
This standard gcc switch causes the compiler to use larger offsets in its jump table representation for case statements. This may result in less efficient code, but is sometimes necessary (for example on HP-UX targets) in order to compile large and/or nested case statements.
-o file
This switch is used in gcc to redirect the generated object file and its associated ALI file. Beware of this switch with GNAT, because it may cause the object file and ALI file to have different names which in turn may confuse the binder and the linker.
-nostdinc
Inhibit the search of the default location for the GNAT Run Time Library (RTL) source files.
-nostdlib
Inhibit the search of the default location for the GNAT Run Time Library (RTL) ALI files.
-O[n]
n controls the optimization level.
n = 0
No optimization, the default setting if no -O appears
n = 1
Normal optimization, the default if you specify -O without an operand. A good compromise between code quality and compilation time.
n = 2
Extensive optimization, may improve execution time, possibly at the cost of substantially increased compilation time.
n = 3
Same as -O2, and also includes inline expansion for small subprograms in the same unit.
n = s
Optimize space usage

See also Optimization Levels.

-pass-exit-codes
Catch exit codes from the compiler and use the most meaningful as exit status.
--RTS=rts-path
Specifies the default location of the runtime library. Same meaning as the equivalent gnatmake flag (see Switches for gnatmake).
-S
Used in place of -c to cause the assembler source file to be generated, using .s as the extension, instead of the object file. This may be useful if you need to examine the generated assembly code.
-fverbose-asm
Used in conjunction with -S to cause the generated assembly code file to be annotated with variable names, making it significantly easier to follow.
-v
Show commands generated by the gcc driver. Normally used only for debugging purposes or if you need to be sure what version of the compiler you are executing.
-V ver
Execute ver version of the compiler. This is the gcc version, not the GNAT version.
-w
Turn off warnings generated by the back end of the compiler. Use of this switch also causes the default for front end warnings to be set to suppress (as though -gnatws had appeared at the start of the options).

You may combine a sequence of GNAT switches into a single switch. For example, the combined switch

     -gnatofi3

is equivalent to specifying the following sequence of switches:

     -gnato -gnatf -gnati3

The following restrictions apply to the combination of switches in this manner: