GCC has various special options that are used for debugging either your program or GCC:
-g
On most systems that use stabs format, -g
enables use of extra debugging information that only GDB can use; this extra information makes debugging work better in GDB but probably makes other debuggers crash or refuse to read the program. If you want to control for certain whether to generate the extra information, use -gstabs+
, -gstabs
, -gxcoff+
, -gxcoff
, or -gvms
(see below).
GCC allows you to use -g
with -O
. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values are already at hand; some statements may execute in different places because they have been moved out of loops.
Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.
The following options are useful when GCC is generated with the capability for more than one debugging format.
-gsplit-dwarf
-ggdb
-gpubnames
-ggnu-pubnames
-gstabs
-feliminate-unused-debug-symbols
-femit-class-debug-always
-fdebug-types-section
.debug_types
section instead of making them part of the .debug_info
section. It is more efficient to put them in a separate comdat sections since the linker can then remove duplicates. But not all DWARF consumers support .debug_types
sections yet and on some objects .debug_types
produces larger instead of smaller debugging information. -gstabs+
-gcoff
-gxcoff
-gxcoff+
-gdwarf-
version
Note that with DWARF Version 2, some ports require and always use some non-conflicting DWARF 3 extensions in the unwind tables.
Version 4 may require GDB 7.0 and -fvar-tracking-assignments
for maximum benefit.
-grecord-gcc-switches
-frecord-gcc-switches
for another way of storing compiler options into the object file. This is the default. -gno-record-gcc-switches
-gstrict-dwarf
-gno-strict-dwarf
-gz
[=
type]
none
’ (don't compress debug sections), ‘zlib
’ (use zlib compression in ELF gABI format), or ‘zlib-gnu
’ (use zlib compression in traditional GNU format). If the linker doesn't support writing compressed debug sections, the option is rejected. Otherwise, if the assembler does not support them, -gz
is silently ignored when producing object files. -gvms
-g
level-ggdb
level-gstabs
level-gcoff
level-gxcoff
level-gvms
level
Level 0 produces no debug information at all. Thus, -g0
negates -g
.
Level 1 produces minimal information, enough for making backtraces in parts of the program that you don't plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables.
Level 3 includes extra information, such as all the macro definitions present in the program. Some debuggers support macro expansion when you use -g3
.
-gdwarf-2
does not accept a concatenated debug level, because GCC used to support an option -gdwarf
that meant to generate debug information in version 1 of the DWARF format (which is very different from version 2), and it would have been too confusing. That debug format is long obsolete, but the option cannot be changed now. Instead use an additional -glevel option to change the debug level for DWARF.
-gtoggle
-fcompare-debug
. -fsanitize=address
ASAN_OPTIONS
environment variable. When set to help=1
, the available options are shown at startup of the instrumended program. See https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags for a list of supported options. -fsanitize=kernel-address
-fsanitize=thread
TSAN_OPTIONS
environment variable; see https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags for a list of supported options. -fsanitize=leak
-fsanitize=address
nor -fsanitize=thread
is used. In that case the executable is linked against a library that overrides malloc
and other allocator functions. See https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer for more details. The run-time behavior can be influenced using the LSAN_OPTIONS
environment variable. -fsanitize=undefined
-fsanitize=shift
-fsanitize=integer-divide-by-zero
INT_MIN / -1
division. -fsanitize=unreachable
__builtin_unreachable
call into a diagnostics message call instead. When reaching the __builtin_unreachable
call, the behavior is undefined. -fsanitize=vla-bound
-fsanitize=null
-fsanitize=return
-fsanitize=signed-integer-overflow
+
, *
, and both unary and binary -
does not overflow in the signed arithmetics. Note, integer promotion rules must be taken into account. That is, the following is not an overflow: signed char a = SCHAR_MAX; a++;
-fsanitize=bounds
-fsanitize=alignment
-fsanitize=object-size
__builtin_object_size
function. Various out of bounds pointer accesses are detected. -fsanitize=float-divide-by-zero
-fsanitize=float-divide-by-zero
is not enabled by -fsanitize=undefined
, since floating-point division by zero can be a legitimate way of obtaining infinities and NaNs. -fsanitize=float-cast-overflow
-fsanitize=float-cast-overflow
is not enabled by -fsanitize=undefined
. This option does not work well with FE_INVALID
exceptions enabled. -fsanitize=nonnull-attribute
nonnull
function attribute. -fsanitize=returns-nonnull-attribute
returns_nonnull
function attribute, to detect returning of null values from such functions. -fsanitize=bool
-fsanitize=enum
-fsanitize=vptr
While -ftrapv
causes traps for signed overflows to be emitted, -fsanitize=undefined
gives a diagnostic message. This currently works only for the C family of languages.
-fno-sanitize=all
-fsanitize=all
is not allowed, as some sanitizers cannot be used together. -fasan-shadow-offset=
number
-fsanitize-recover
[=
opts]
-fsanitize-recover=
controls error recovery mode for sanitizers mentioned in comma-separated list of opts. Enabling this option for a sanitizer component causes it to attempt to continue running the program as if no error happened. This means multiple runtime errors can be reported in a single program run, and the exit code of the program may indicate success even when errors have been reported. The -fno-sanitize-recover=
option can be used to alter this behavior: only the first detected error is reported and program then exits with a non-zero exit code. Currently this feature only works for -fsanitize=undefined
(and its suboptions except for -fsanitize=unreachable
and -fsanitize=return
), -fsanitize=float-cast-overflow
, -fsanitize=float-divide-by-zero
and -fsanitize=kernel-address
. For these sanitizers error recovery is turned on by default. -fsanitize-recover=all
and -fno-sanitize-recover=all
is also accepted, the former enables recovery for all sanitizers that support it, the latter disables recovery for all sanitizers that support it.
Syntax without explicit opts parameter is deprecated. It is equivalent to
-fsanitize-recover=undefined,float-cast-overflow,float-divide-by-zero
Similarly -fno-sanitize-recover
is equivalent to
-fno-sanitize-recover=undefined,float-cast-overflow,float-divide-by-zero
-fsanitize-undefined-trap-on-error
-fsanitize-undefined-trap-on-error
option instructs the compiler to report undefined behavior using __builtin_trap
rather than a libubsan
library routine. The advantage of this is that the libubsan
library is not needed and is not linked in, so this is usable even in freestanding environments. -fcheck-pointer-bounds
Currently there is only an implementation for Intel MPX available, thus x86 target and -mmpx
are required to enable this feature. MPX-based instrumentation requires a runtime library to enable MPX in hardware and handle bounds violation signals. By default when -fcheck-pointer-bounds
and -mmpx
options are used to link a program, the GCC driver links against the libmpx
runtime library and libmpxwrappers
library. It also passes '-z bndplt' to a linker in case it supports this option (which is checked on libmpx configuration). Note that old versions of linker may ignore option. Gold linker doesn't support '-z bndplt' option. With no '-z bndplt' support in linker all calls to dynamic libraries lose passed bounds reducing overall protection level. It's highly recommended to use linker with '-z bndplt' support. In case such linker is not available it is adviced to always use -static-libmpxwrappers
for better protection level or use -static
to completely avoid external calls to dynamic libraries. MPX-based instrumentation may be used for debugging and also may be included in production code to increase program security. Depending on usage, you may have different requirements for the runtime library. The current version of the MPX runtime library is more oriented for use as a debugging tool. MPX runtime library usage implies -lpthread
. See also -static-libmpx
. The runtime library behavior can be influenced using various CHKP_RT_*
environment variables. See https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler for more details.
Generated instrumentation may be controlled by various -fchkp-*
options and by the bnd_variable_size
structure field attribute (see Type Attributes) and bnd_legacy
, and bnd_instrument
function attributes (see Function Attributes). GCC also provides a number of built-in functions for controlling the Pointer Bounds Checker. See Pointer Bounds Checker builtins, for more information.
-fchkp-check-incomplete-type
-fchkp-narrow-bounds
-fchkp-narrow-to-innermost-array
and -fchkp-first-field-has-own-bounds
. Enabled by default. -fchkp-first-field-has-own-bounds
-fchkp-narrow-to-innermost-array
-fchkp-optimize
-O
, -O2
, -O3
. -fchkp-use-fast-string-functions
*_nobnd
versions of string functions (not copying bounds) by Pointer Bounds Checker. Disabled by default. -fchkp-use-nochk-string-functions
*_nochk
versions of string functions (not checking bounds) by Pointer Bounds Checker. Disabled by default. -fchkp-use-static-bounds
-fchkp-use-static-const-bounds
-fchkp-use-static-bounds
is enabled. -fchkp-treat-zero-dynamic-size-as-infinite
-fchkp-check-read
-fchkp-check-write
-fchkp-store-bounds
-fchkp-instrument-calls
-fchkp-instrument-marked-only
bnd_instrument
attribute (see Function Attributes). Disabled by default. -fchkp-use-wrappers
-fchkp-use-wrappers
is used to link a program, the GCC driver automatically links against libmpxwrappers
. See also -static-libmpxwrappers
. Enabled by default. -fdump-final-insns
[=
file]
.
), the name of the dump file is determined by appending .gkd
to the compilation output file name. -fcompare-debug
[=
opts]
-fcompare-debug-second
to the arguments passed to the second compilation. Dump the final internal representation in both compilations, and print an error if they differ. If the equal sign is omitted, the default -gtoggle
is used.
The environment variable GCC_COMPARE_DEBUG
, if defined, non-empty and nonzero, implicitly enables -fcompare-debug
. If GCC_COMPARE_DEBUG
is defined to a string starting with a dash, then it is used for opts, otherwise the default -gtoggle
is used.
-fcompare-debug=
, with the equal sign but without opts, is equivalent to -fno-compare-debug
, which disables the dumping of the final representation and the second compilation, preventing even GCC_COMPARE_DEBUG
from taking effect.
To verify full coverage during -fcompare-debug
testing, set GCC_COMPARE_DEBUG
to say -fcompare-debug-not-overridden
, which GCC rejects as an invalid option in any actual compilation (rather than preprocessing, assembly or linking). To get just a warning, setting GCC_COMPARE_DEBUG
to ‘-w%n-fcompare-debug not overridden
’ will do.
-fcompare-debug-second
-fcompare-debug
, along with options to silence warnings, and omitting other options that would cause side-effect compiler outputs to files or to the standard output. Dump files and preserved temporary files are renamed so as to contain the .gk
additional extension during the second compilation, to avoid overwriting those generated by the first. When this option is passed to the compiler driver, it causes the first compilation to be skipped, which makes it useful for little other than debugging the compiler proper.
-feliminate-dwarf2-dups
-gdwarf-2
. -femit-struct-debug-baseonly
This option substantially reduces the size of debugging information, but at significant potential loss in type information to the debugger. See -femit-struct-debug-reduced
for a less aggressive option. See -femit-struct-debug-detailed
for more detailed control.
This option works only with DWARF 2.
-femit-struct-debug-reduced
This option significantly reduces the size of debugging information, with some potential loss in type information to the debugger. See -femit-struct-debug-baseonly
for a more aggressive option. See -femit-struct-debug-detailed
for more detailed control.
This option works only with DWARF 2.
-femit-struct-debug-detailed
[=
spec-list]
This option is a detailed version of -femit-struct-debug-reduced
and -femit-struct-debug-baseonly
, which serves for most needs.
A specification has the syntax [‘dir:
’|‘ind:
’][‘ord:
’|‘gen:
’](‘any
’|‘sys
’|‘base
’|‘none
’)
The optional first word limits the specification to structs that are used directly (‘dir:
’) or used indirectly (‘ind:
’). A struct type is used directly when it is the type of a variable, member. Indirect uses arise through pointers to structs. That is, when use of an incomplete struct is valid, the use is indirect. An example is ‘struct one direct; struct two * indirect;
’.
The optional second word limits the specification to ordinary structs (‘ord:
’) or generic structs (‘gen:
’). Generic structs are a bit complicated to explain. For C++, these are non-explicit specializations of template classes, or non-template classes within the above. Other programming languages have generics, but -femit-struct-debug-detailed
does not yet implement them.
The third word specifies the source files for those structs for which the compiler should emit debug information. The values ‘none
’ and ‘any
’ have the normal meaning. The value ‘base
’ means that the base of name of the file in which the type declaration appears must match the base of the name of the main compilation file. In practice, this means that when compiling foo.c
, debug information is generated for types declared in that file and foo.h
, but not other header files. The value ‘sys
’ means those types satisfying ‘base
’ or declared in system or compiler headers.
You may need to experiment to determine the best settings for your application.
The default is -femit-struct-debug-detailed=all
.
This option works only with DWARF 2.
-fno-merge-debug-strings
-fdebug-prefix-map=
old=
new
-fno-dwarf2-cfi-asm
.eh_frame
section instead of using GAS .cfi_*
directives.
-p
prof
. You must use this option when compiling the source files you want data about, and you must also use it when linking.
-pg
gprof
. You must use this option when compiling the source files you want data about, and you must also use it when linking. -Q
-ftime-report
-fmem-report
-fmem-report-wpa
-fpre-ipa-mem-report
-fpost-ipa-mem-report
-fprofile-report
-fstack-usage
.su
to the auxname. auxname is generated from the name of the output file, if explicitly specified and it is not an executable, otherwise it is the basename of the source file. An entry is made up of three fields: static
, dynamic
, bounded
. The qualifier static
means that the function manipulates the stack statically: a fixed number of bytes are allocated for the frame on function entry and released on function exit; no stack adjustments are otherwise made in the function. The second field is this fixed number of bytes.
The qualifier dynamic
means that the function manipulates the stack dynamically: in addition to the static allocation described above, stack adjustments are made in the body of the function, for example to push/pop arguments around function calls. If the qualifier bounded
is also present, the amount of these adjustments is bounded at compile time and the second field is an upper bound of the total amount of stack used by the function. If it is not present, the amount of these adjustments is not bounded at compile time and the second field only represents the bounded part.
-fprofile-arcs
-fbranch-probabilities
), or for test coverage analysis (-ftest-coverage
). Each object file's auxname is generated from the name of the output file, if explicitly specified and it is not the final executable, otherwise it is the basename of the source file. In both cases any suffix is removed (e.g. foo.gcda
for input file dir/foo.c
, or dir/foo.gcda
for output file specified as -o dir/foo.o
). See Cross-profiling.
--coverage
-fprofile-arcs
-ftest-coverage
(when compiling) and -lgcov
(when linking). See the documentation for those options for more details. -fprofile-arcs
plus optimization and code generation options. For test coverage analysis, use the additional -ftest-coverage
option. You do not need to profile every source file in a program. -lgcov
or -fprofile-arcs
(the latter implies the former). fork
calls are detected and correctly handled (double counting will not happen). -fbranch-probabilities
(see Options that Control Optimization). gcov
to produce human readable information from the .gcno
and .gcda
files. Refer to the gcov
documentation for further information. With -fprofile-arcs
, for each function of your program GCC creates a program flow graph, then finds a spanning tree for the graph. Only arcs that are not on the spanning tree have to be instrumented: the compiler adds code to count the number of times that these arcs are executed. When an arc is the only exit or only entrance to a block, the instrumentation code can be added to the block; otherwise, a new basic block must be created to hold the instrumentation code.
-ftest-coverage
gcov
code-coverage utility (see gcov
—a Test Coverage Program) can use to show program coverage. Each source file's note file is called auxname.gcno. Refer to the -fprofile-arcs
option above for a description of auxname and instructions on how to generate test coverage data. Coverage data matches the source files more closely if you do not optimize. -fdbg-cnt-list
-fdbg-cnt=
counter-value-list
UINT_MAX
; thus dbg_cnt
returns true always unless the upper bound is set by this option. For example, with -fdbg-cnt=dce:10,tail_call:0
, dbg_cnt(dce)
returns true only for first 10 invocations. -fenable-
kind-
pass-fdisable-
kind-
pass=
range-list
-fdisable-ipa-
pass
-fdisable-rtl-
pass-fdisable-rtl-
pass=
range-list
-fdump-passes
. -fdisable-tree-
pass-fdisable-tree-
pass=
range-list
-fdisable-rtl
for the description of option arguments. -fenable-ipa-
pass
-fenable-rtl-
pass-fenable-rtl-
pass=
range-list
-fdisable-rtl
for option argument description and examples. -fenable-tree-
pass-fenable-tree-
pass=
range-list
-fdisable-rtl
for the description of option arguments. Here are some examples showing uses of these options.
# disable ccp1 for all functions -fdisable-tree-ccp1 # disable complete unroll for function whose cgraph node uid is 1 -fenable-tree-cunroll=1 # disable gcse2 for functions at the following ranges [1,1], # [300,400], and [400,1000] # disable gcse2 for functions foo and foo2 -fdisable-rtl-gcse2=foo,foo2 # disable early inlining -fdisable-tree-einline # disable ipa inlining -fdisable-ipa-inline # enable tree full unroll -fenable-tree-unroll
-d
letters-fdump-rtl-
pass-fdump-rtl-
pass=
filename
-E
is used for preprocessing. Debug dumps can be enabled with a -fdump-rtl
switch or some -d
option letters. Here are the possible letters for use in pass and letters, and their meanings:
-fdump-rtl-alignments
-fdump-rtl-asmcons
-fdump-rtl-auto_inc_dec
-fdump-rtl-barriers
-fdump-rtl-bbpart
-fdump-rtl-bbro
-fdump-rtl-btl1
-fdump-rtl-btl2
-fdump-rtl-btl1
and -fdump-rtl-btl2
enable dumping after the two branch target load optimization passes. -fdump-rtl-bypass
-fdump-rtl-combine
-fdump-rtl-compgotos
-fdump-rtl-ce1
-fdump-rtl-ce2
-fdump-rtl-ce3
-fdump-rtl-ce1
, -fdump-rtl-ce2
, and -fdump-rtl-ce3
enable dumping after the three if conversion passes. -fdump-rtl-cprop_hardreg
-fdump-rtl-csa
-fdump-rtl-cse1
-fdump-rtl-cse2
-fdump-rtl-cse1
and -fdump-rtl-cse2
enable dumping after the two common subexpression elimination passes. -fdump-rtl-dce
-fdump-rtl-dbr
-fdump-rtl-dce1
-fdump-rtl-dce2
-fdump-rtl-dce1
and -fdump-rtl-dce2
enable dumping after the two dead store elimination passes. -fdump-rtl-eh
-fdump-rtl-eh_ranges
-fdump-rtl-expand
-fdump-rtl-fwprop1
-fdump-rtl-fwprop2
-fdump-rtl-fwprop1
and -fdump-rtl-fwprop2
enable dumping after the two forward propagation passes. -fdump-rtl-gcse1
-fdump-rtl-gcse2
-fdump-rtl-gcse1
and -fdump-rtl-gcse2
enable dumping after global common subexpression elimination. -fdump-rtl-init-regs
-fdump-rtl-initvals
-fdump-rtl-into_cfglayout
-fdump-rtl-ira
-fdump-rtl-jump
-fdump-rtl-loop2
-fdump-rtl-loop2
enables dumping after the rtl loop optimization passes. -fdump-rtl-mach
-fdump-rtl-mode_sw
-fdump-rtl-rnreg
-fdump-rtl-outof_cfglayout
-fdump-rtl-peephole2
-fdump-rtl-postreload
-fdump-rtl-pro_and_epilogue
-fdump-rtl-sched1
-fdump-rtl-sched2
-fdump-rtl-sched1
and -fdump-rtl-sched2
enable dumping after the basic block scheduling passes. -fdump-rtl-ree
-fdump-rtl-seqabstr
-fdump-rtl-shorten
-fdump-rtl-sibling
-fdump-rtl-split1
-fdump-rtl-split2
-fdump-rtl-split3
-fdump-rtl-split4
-fdump-rtl-split5
-fdump-rtl-sms
-fdump-rtl-stack
-fdump-rtl-subreg1
-fdump-rtl-subreg2
-fdump-rtl-subreg1
and -fdump-rtl-subreg2
enable dumping after the two subreg expansion passes. -fdump-rtl-unshare
-fdump-rtl-vartrack
-fdump-rtl-vregs
-fdump-rtl-web
-fdump-rtl-regclass
-fdump-rtl-subregs_of_mode_init
-fdump-rtl-subregs_of_mode_finish
-fdump-rtl-dfinit
-fdump-rtl-dfinish
-da
-fdump-rtl-all
-dA
-dD
-dH
-dp
-dP
-dp
annotation. -dx
-fdump-rtl-expand
. -fdump-noaddr
-freport-bug
-fdump-unnumbered
-g
. -fdump-unnumbered-links
-d
option above), suppress instruction numbers for the links to the previous and next instructions in a sequence. -fdump-translation-unit
(C++ only)-fdump-translation-unit-
options (C++ only)
.tu
to the source file name, and the file is created in the same directory as the output file. If the ‘-options’ form is used, options controls the details of the dump as described for the -fdump-tree
options. -fdump-class-hierarchy
(C++ only)-fdump-class-hierarchy-
options (C++ only)
.class
to the source file name, and the file is created in the same directory as the output file. If the ‘-options’ form is used, options controls the details of the dump as described for the -fdump-tree
options. -fdump-ipa-
switch
all
’cgraph
’inline
’-fdump-passes
-fdump-statistics-
option
.statistics
’ to the source file name, and the file is created in the same directory as the output file. If the ‘-option’ form is used, ‘-stats
’ causes counters to be summed over the whole compilation unit while ‘-details
’ dumps every event as the passes generate them. The default with no option is to sum counters for each function compiled. -fdump-tree-
switch-fdump-tree-
switch-
options-fdump-tree-
switch-
options=
filename
-
’ separated options which control the details of the dump. Not all options are applicable to all dumps; those that are not meaningful are ignored. The following options are available address
’asmname
’DECL_ASSEMBLER_NAME
has been set for a given decl, use that in the dump instead of DECL_NAME
. Its primary use is ease of use working backward from mangled names in the assembly file. slim
’When dumping pretty-printed trees, this option inhibits dumping the bodies of control structures.
When dumping RTL, print the RTL in slim (condensed) form instead of the default LISP-like representation.
raw
’details
’stats
’blocks
’graph
’This option currently only works for RTL dumps, and the RTL is always dumped in slim form.
vops
’lineno
’uid
’DECL_UID
) for each variable. verbose
’eh
’scev
’optimized
’missed
’note
’stdout
and stderr
are treated specially and are considered already open standard streams. For example, gcc -O2 -ftree-vectorize -fdump-tree-vect-blocks=foo.dump -fdump-tree-pre=stderr file.c
outputs vectorizer dump into foo.dump
, while the PRE dump is output on to stderr
. If two conflicting dump filenames are given for the same pass, then the latter option overrides the earlier one.
all
’raw
, slim
, verbose
and lineno
. optall
’optimized
, missed
, and note
. The following tree dumps are possible:
original
’optimized
’gimple
’.gimple
to the source file name. cfg
’.cfg
to the source file name. ch
’.ch
to the source file name. ssa
’.ssa
to the source file name. alias
’.alias
to the source file name. ccp
’.ccp
to the source file name. storeccp
’.storeccp
to the source file name. pre
’.pre
to the source file name. fre
’.fre
to the source file name. copyprop
’.copyprop
to the source file name. store_copyprop
’.store_copyprop
to the source file name. dce
’.dce
to the source file name. sra
’.sra
to the source file name. sink
’.sink
to the source file name. dom
’.dom
to the source file name. dse
’.dse
to the source file name. phiopt
’.phiopt
to the source file name. forwprop
’.forwprop
to the source file name. copyrename
’.copyrename
to the source file name. nrv
’.nrv
to the source file name. vect
’.vect
to the source file name. slp
’.slp
to the source file name. vrp
’.vrp
to the source file name. all
’-fopt-info
-fopt-info-
options-fopt-info-
options=
filename
-
’ separated option keywords to select the dump details and optimizations. The options can be divided into two groups: options describing the verbosity of the dump, and options describing which optimizations should be included. The options from both the groups can be freely mixed as they are non-overlapping. However, in case of any conflicts, the later options override the earlier options on the command line.
The following options control the dump verbosity:
optimized
’missed
’note
’all
’optimized
’, ‘missed
’, and ‘note
’. One or more of the following option keywords can be used to describe a group of optimizations:
ipa
’loop
’inline
’vec
’optall
’If options is omitted, it defaults to ‘optimized-optall
’, which means to dump all info about successful optimizations from all the passes.
If the filename is provided, then the dumps from all the applicable optimizations are concatenated into the filename. Otherwise the dump is output onto stderr
. Though multiple -fopt-info
options are accepted, only one of them can include a filename. If other filenames are provided then all but the first such option are ignored.
Note that the output filename is overwritten in case of multiple translation units. If a combined output from multiple translation units is desired, stderr
should be used instead.
In the following example, the optimization info is output to stderr
:
gcc -O3 -fopt-info
This example:
gcc -O3 -fopt-info-missed=missed.all
outputs missed optimization report from all the passes into missed.all
, and this one:
gcc -O2 -ftree-vectorize -fopt-info-vec-missed
prints information about missed optimization opportunities from vectorization passes on stderr
. Note that -fopt-info-vec-missed
is equivalent to -fopt-info-missed-vec
.
As another example,
gcc -O3 -fopt-info-inline-optimized-missed=inline.txt
outputs information about missed optimizations as well as optimized locations from all the inlining passes into inline.txt
.
Finally, consider:
gcc -fopt-info-vec-missed=vec.miss -fopt-info-loop-optimized=loop.opt
Here the two output filenames vec.miss
and loop.opt
are in conflict since only one output file is allowed. In this case, only the first option takes effect and the subsequent options are ignored. Thus only vec.miss
is produced which contains dumps from the vectorizer about missed opportunities.
-frandom-seed=
string
-frandom-seed
option to produce reproducibly identical object files. The string can either be a number (decimal, octal or hex) or an arbitrary string (in which case it's converted to a number by computing CRC32).
The string should be different for every file you compile.
-fsched-verbose=
n
-fdump-rtl-sched1
or -fdump-rtl-sched2
is specified, in which case it is output to the usual dump listing file, .sched1
or .sched2
respectively. However for n greater than nine, the output is always printed to standard error. For n greater than zero, -fsched-verbose
outputs the same information as -fdump-rtl-sched1
and -fdump-rtl-sched2
. For n greater than one, it also output basic block probabilities, detailed ready list information and unit/insn info. For n greater than two, it includes RTL at abort point, control-flow and regions info. And for n over four, -fsched-verbose
also includes dependence info.
-save-temps
-save-temps=cwd
foo.c
with -c -save-temps
produces files foo.i
and foo.s
, as well as foo.o
. This creates a preprocessed foo.i
output file even though the compiler now normally uses an integrated preprocessor. When used in combination with the -x
command-line option, -save-temps
is sensible enough to avoid over writing an input source file with the same extension as an intermediate file. The corresponding intermediate file may be obtained by renaming the source file before using -save-temps
.
If you invoke GCC in parallel, compiling several different source files that share a common base name in different subdirectories or the same source file compiled for multiple output destinations, it is likely that the different parallel compilers will interfere with each other, and overwrite the temporary files. For instance:
gcc -save-temps -o outdir1/foo.o indir1/foo.c& gcc -save-temps -o outdir2/foo.o indir2/foo.c&
may result in foo.i
and foo.o
being written to simultaneously by both compilers.
-save-temps=obj
-o
option is used, the temporary files are based on the object file. If the -o
option is not used, the -save-temps=obj
switch behaves like -save-temps
. For example:
gcc -save-temps=obj -c foo.c gcc -save-temps=obj -c bar.c -o dir/xbar.o gcc -save-temps=obj foobar.c -o dir2/yfoobar
creates foo.i
, foo.s
, dir/xbar.i
, dir/xbar.s
, dir2/yfoobar.i
, dir2/yfoobar.s
, and dir2/yfoobar.o
.
-time
[=
file]
Without the specification of an output file, the output looks like this:
# cc1 0.12 0.01 # as 0.00 0.01
The first number on each line is the “user time”, that is time spent executing the program itself. The second number is “system time”, time spent executing operating system routines on behalf of the program. Both numbers are in seconds.
With the specification of an output file, the output is appended to the named file, and it looks like this:
0.12 0.01 cc1 options 0.00 0.01 as options
The “user time” and the “system time” are moved before the program name, and the options passed to the program are displayed, so that one can later tell what file was being compiled, and with which options.
-fvar-tracking
It is enabled by default when compiling with optimization (-Os
, -O
, -O2
, ...), debugging information (-g
) and the debug info format supports it.
-fvar-tracking-assignments
-gdwarf-4
is recommended along with it. It can be enabled even if var-tracking is disabled, in which case annotations are created and maintained, but discarded at the end. By default, this flag is enabled together with -fvar-tracking
, except when selective scheduling is enabled.
-fvar-tracking-assignments-toggle
-fvar-tracking-assignments
, in the same way that -gtoggle
toggles -g
. -print-file-name=
library
-print-multi-directory
GCC_EXEC_PREFIX
. -print-multi-lib
;
’, and each switch starts with an ‘@
’ instead of the ‘-
’, without spaces between multiple switches. This is supposed to ease shell processing. -print-multi-os-directory
lib
subdirectory. If OS libraries are present in the lib
subdirectory and no multilibs are used, this is usually just .
, if OS libraries are present in libsuffix sibling directories this prints e.g. ../lib64
, ../lib
or ../lib32
, or if OS libraries are present in lib/subdir subdirectories it prints e.g. amd64
, sparcv9
or ev6
. -print-multiarch
lib
subdirectory. -print-prog-name=
program
-print-file-name
, but searches for a program such as cpp
. -print-libgcc-file-name
-print-file-name=libgcc.a
. This is useful when you use -nostdlib
or -nodefaultlibs
but you do want to link with libgcc.a
. You can do:
gcc -nostdlib files... `gcc -print-libgcc-file-name`
-print-search-dirs
gcc
searches—and don't do anything else. This is useful when gcc
prints the error message ‘installation problem, cannot exec cpp0: No such file or directory
’. To resolve this you either need to put cpp0
and the other compiler components where gcc
expects to find them, or you can set the environment variable GCC_EXEC_PREFIX
to the directory where you installed them. Don't forget the trailing ‘/
’. See Environment Variables.
-print-sysroot
--sysroot
option, possibly with an extra suffix that depends on compilation options. If no target sysroot is specified, the option prints nothing. -print-sysroot-headers-suffix
-dumpmachine
i686-pc-linux-gnu
’)—and don't do anything else. -dumpversion
3.0
)—and don't do anything else. -dumpspecs
-fno-eliminate-unused-debug-types
© Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Debugging-Options.html