Search notes:

gcc -f

-f… options specify machine-independent flags.
Because of their nature, most -f options have a positive and a negative form (-fopt and -fno-opt)
If compiling with -S to produce assembly output, adding the -fverbose-asm flag adds extra inline-commentary to the produced file to make it more readable.
-fpreprocessed indicates that a translation unit was already preprocessed.
-fshort-wchar to override the type that underlies wchar_t to a short unsigned int.
-fpic and -fPIC
-fsanitize=address (for example to detect stack overflows).
-ftree-vectorize is an optimization (which is implied with -O3 or -Ofast): It tries to vectorize loops using the selected ISA if possible.
TODO: -fpie, -fomit-frame-pointer

-finstrument-functions

//
//  
//  //   use -g flag for addr2line
//  gcc -g -finstrument-functions instrument-functions.c
//
//  // Link with -ldl for dladdr()
//  gcc -finstrument-functions instrument-functions.c -ldl
//

//
//  Using addr2line
//     make sure executable is compiled with -g
//     Use -e to specify executable
//     use -f to show function name
//     execute addr2line with hex representation of addr, for
//     example:
//
//        addr2line  -f -e a.out   0x400641

#include <stdio.h>

#ifdef TRY_dladdr
// define __USE_GNU because apparently dladdr is an extension of GNU.
#define __USE_GNU
#include <dlfcn.h>
#endif



#ifdef TRY_dladdr
void  __attribute__((no_instrument_function)) print_enter_exit(const char* enter_exit, void* func, void* caller) {

  Dl_info dlinfo;
  dladdr(func, &dlinfo);

  printf("** %-5s %-20s, caller: %p\n", enter_exit, dlinfo.dli_sname, caller);

}
#endif

void  __attribute__((no_instrument_function))  // Use this attribute so that this function is not traced
      __cyg_profile_func_enter                 // OSX: use profile_func_enter
   (
    void* func,   // Address of function start. Can be looked up in symbol table with addr2line.
    void* caller  // 
   )
{
//print_enter_exit("enter", func, caller);
  printf("** Entered function %p, caller: %p\n", func, caller);
}

void __attribute__((no_instrument_function))
     __cyg_profile_func_exit                 // OSX: use profile_func_exit
      (
         void* func,
         void* caller
      ) {
  printf("** Leaving function %p, caller: %p\n", func, caller);
}

void
  __attribute__((no_instrument_function)) // Don't trace f4()
  f4() {

    printf("f4\n");

}

void f3() {
  printf("f3\n");
  f4();
}

void f2(int p) {
  printf("f2, p=%d\n", p);
  if (!p) {
    f3();
  }
  f4();
}

void f1(int p) {

  printf("f1, p=%d\n", p);
  if (p) {
     f2(p-1);
  }
  else {
     f3();
     f4();
  }

}

int main() {

  for (int i=0; i<=2; i++) {
     f1(i);
     f4();
  }

}
Github repository about-gcc, path: /options/f/instrument-functions.c

-ftrapv

//
//  gcc -ftrapv trapv.c
//
//    Apparently, there's a bug with -ftrapv:
//      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35412
//      https://stackoverflow.com/questions/20851061/how-to-make-gcc-ftrapv-work

#include <limits.h>
#include <stdio.h>

int main() {

    int i = INT_MAX;

    printf("i = %d\n", i);

 // -ftrapv causes the program to abort on
 // a signed integer overflow.
    i++;
    printf("i = %d\n", i);

}
Github repository about-gcc, path: /options/f/trapv.c

Flags

Some flags are automatically enabled depending on the optimization level (-On).
Name -On
align-functions 2 Not enabled with -Os. See also -falign-jumps
align-jumps 2 Not enabled with -Os. See also -falign-functions
align-labels 2 Not enabled with -Os. See also -falign-loops
align-loops 2 Not enabled with -Os. See also -falign-labels
auto-inc-dec 1
branch-count-reg 1
caller-saves 2
code-hoisting 2
combine-stack-adjustments 1
compare-elim 1
cprop-registers 1
crossjumping 2
cse-follow-jumps 2 See also -fcse-skip-blocks
cse-skip-bloks 2 See also -fcse-follow-jumps
dce 1
defer-pop 1
delayed-branch 1
delete-null-pointer-checks 2
devirtualize 2
devirtualize-speculatively 2
dse 1
expensive-optimizations 2
finite-loops 2
forward-propagate 1
gcse-after-reload 3
gcse -fgcse-lm 2
guess-branch-probability 1
hoist-adjacent-loads 2
if-conversion 1
if-conversion2 1
indirect-inlining 2
inline-functions 2
inline-functions-called-once 1
inline-small-functions 2
ipa-bit-cp 2
ipa-cp 2
ipa-cp-clone 3
ipa-icf 2
ipa-modref 1
ipa-profile 1
ipa-pure-const 1
ipa-ra 2
ipa-reference 1
ipa-reference-addressable 1
ipa-sra 2 sra = scalar replacement of aggregates
ipa-vrp 2
isolate-erroneous-paths-dereference 2
loop-interchange 3
loop-unroll-and-jam 3
lra-remat 2
merge-constants 1
move-loop-invariants 1
move-loop-stores 1
omit-frame-pointer 1
optimize-sibling-calls 2
optimize-strlen 2
partial-inlining 2
peel-loops 3
peephole2 2
predictive-commoning 3
reorder-blocks 1
reorder-blocks-algorithm=stc 2 Not enabled with -Os.
reorder-blocks-and-partition 2
reorder-functions 2
rerun-cse-after-loop 2
sched-interblock 2
sched-spec 2
schedule-insns 2
schedule-insns2 2
shrink-wrap 1
shrink-wrap-separate 1
split-loops 3
split-paths 3
split-wide-types 1
ssa-backprop 1
ssa-phiopt 1
store-merging 2
strict-aliasing 2
thread-jumps 2
tree-bit-ccp 1
tree-builtin-call-dce 2
tree-ccp 1
tree-ch 1
tree-coalesce-vars 1
tree-copy-prop 1
tree-dce 1
tree-dominator-opts 1
tree-dse 1
tree-forwprop 1
tree-fre 1
tree-loop-distribution 3
tree-loop-vectorize 2
tree-partial-pre 3
tree-phiprop 1
tree-pre 2
tree-pta 1
tree-scev-cprop 1
tree-sink 1
tree-slp-vectorize 2
tree-slsr 1
tree-sra 1
tree-switch-conversion 2 See also -ftree-tail-merge
tree-tail-merge 2 See also -ftree-switch-conversion
tree-ter 1
tree-vrp 2
unit-at-a-time 1
unswitch-loops 3
vect-cost-model=dynamic 3
vect-cost-model=very-cheap 2
version-loops-for-strides 3
fast-math fast
allow-store-data-races fast
stack-arrays fast Fortran specific
analyzer Static analysis of program flow which looks for «interesting» interprocedural paths through the code - issues warnings for problems found on them. (See also the -Wanalyzer-… options)
diagnostics-color[=WHEN]
diagnostics-column-origin=ORIGIN
diagnostics-column-unit=UNIT
diagnostics-escape-format=FORMAT
diagnostics-format=FORMAT
diagnostics-generate-patch
diagnostics-minimum-margin-width=width
diagnostics-parseable-fixits
diagnostics-path-format=KIND
diagnostics-plain-output
diagnostics-show-location=… once or every-line
diagnostics-show-path-depths
diagnostics-show-template-tree
diagnostics-text-art-charset=CHARSET
diagnostics-urls[=WHEN]
message-length=n
no-diagnostics-json-formatting
no-diagnostics-show-caret
no-diagnostics-show-cwe See also -fanalyzer
no-diagnostics-show-labels
no-diagnostics-show-line-numbers
no-diagnostics-show-option
no-diagnostics-show-rules
no-elide-type
no-show-column
syntax-only
max-errors=n
permissive
dump-…
dump-ipa-analyzer Dumps the gimple representation
dump-tree-vect=out.file Dumps the tree vectorization pass output
no-eliminate-unused-debug-symbols
emit-class-debug-always
no-merge-debug-strings
debug-prefix-map=old=new
var-tracking
var-tracking-assignments
debug-types-section
emit-struct-debug-baseonly
emit-struct-debug-reduced
emit-struct-debug-detailed[=spec-list]
no-dwarf2-cfi-asm
no-eliminate-unused-debug-types
prefetch-loop-arrays Not enabled with -Os (but is it enabled with -O2 ?)
reorder-blocks-algorithm=stc
semantic-interposition Turned off with -Ofast
fp-contract=style
inline-limit=n
inline-stringops[=fn]
no-inline
aggressive-loop-optimizations
associative-math
auto-inc-dec
auto-profile=path
branch-probabilities
caller-saves
code-hoisting
combine-stack-adjustments
compare-elim
condition-coverage
conserve-stack
cprop-registers
crossjumping
cse-follow-jumps
cse-skip-blocks
cx-fortran-rules
cx-limited-range
cx-limited-range
data-sections
dce
declone-ctor-dtor
delayed-branch
delete-null-pointer-checks
devirtualize
devirtualize-at-ltrans
devirtualize-speculatively
dse
dump-tree-*-details
excess-precision=fast
excess-precision=standard
excess-precision=style
expensive-optimizations
fast-math
fat-lto-objects
finite-loops
finite-math-only
float-store
fold-mem-offsets
function-sections
gcse
gcse-after-reload
gcse-las
gcse-lm
gcse-sm
graphite-identity
hoist-adjacent-loads
if-conversion
if-conversion2
inline-functions
inline-small-functions
ipa-bit-cp
ipa-cp
ipa-cp-clone
ipa-icf
ipa-icf
ipa-modref
ipa-profile
ipa-pta
ipa-pure-const
ipa-ra
ipa-reference
ipa-reference-addressable
ipa-stack-alignment
ipa-strict-aliasing
ipa-vrp
ira-algorithm=algorithm
ira-hoist-pressure
ira-loop-pressure
ira-region=region
isolate-erroneous-paths-dereference
ivopts
keep-inline-functions
keep-static-consts
keep-static-functions
lifetime-dse=0
limit-function-alignment
linker-output=nolto-rel)
live-patching=inline-clone
live-patching=level
live-range-shrinkage
loop-block
loop-interchange
loop-nest-optimize
loop-parallelize-all
loop-strip-mine
loop-unroll-and-jam
lra-remat
lto-compression-level=n
lto[=n]
lto-partition=alg
merge-all-constants
merge-constants
min-function-alignment
min-function-alignment
modulo-sched
modulo-sched-allow-regmoves
move-loop-invariants
move-loop-stores
no-align-functions
no-align-jumps
no-align-labels
no-align-loops
no-allocation-dce
no-branch-count-reg
no-fat-lto-objects
no-fold-mem-offsets
no-fp-int-builtin-inexact
no-function-cse
no-guess-branch-probability
no-ira-share-save-slots
no-ira-share-spill-slots
no-keep-inline-dllexport
no-lifetime-dse
no-math-errno
no-peephole
no-peephole2
no-printf-return-value
no-sched-interblock
no-sched-spec
no-semantic-interposition
no-signed-zeros
no-strict-overflow
no-toplevel-reorder
no-toplevel-reorder
no-trapping-math
no-trapping-math
no-trapv
no-zero-initialized-in-bss
partial-inlining
peel-loops
peephole
pic
PIC
PIC
pic/-fPIC
PIC/-fpic
predictive-commoning
prefetch-loop-arrays
printf-return-value
profile-abs-path
profile-arcs
profile-correction
profile-dir=path
profile-generate
profile-generate=path
profile-info-section
profile-info-section=name
profile-note
profile-partial-training
profile-reorder-functions
profile-use
profile-use=path
profile-values
reciprocal-math
reciprocal-math
ree
rename-registers
reorder-blocks
reorder-blocks-algorithm=algorithm
reorder-blocks-and-partition
reorder-functions
rerun-cse-after-loop
reschedule-modulo-scheduled-loops
rounding-math
rounding-math
sanitize=address
sanitize=hwaddress
sanitize=kernel-hwaddress
sanitize=unreachable
sched2-use-superblocks
sched-critical-path-heuristic
sched-dep-count-heuristic
sched-group-heuristic
sched-last-insn-heuristic
sched-pressure
sched-rank-heuristic
sched-spec-insn-heuristic
sched-spec-load
sched-spec-load-dangerous
sched-stalled-insns=n
sched-stalled-insns-dep=n
schedule-fusion
schedule-insns
schedule-insns2
section-anchors
selective-scheduling2
sel-sched-pipelining
sel-sched-pipelining-outer-loops
semantic-interposition
shrink-wrap
shrink-wrap-separate
signaling-nans
simd-cost-model=model
single-precision-constant
split-ivs-in-unroller
split-loops
split-paths
split-wide-types
split-wide-types-early
ssa-backprop
ssa-phiopt
stdarg-opt
store-merging
strict-aliasing
test-coverage
thread-jumps
toplevel-reorder
tracer
trapping-math
tree-bit-ccp
tree-builtin-call-dce
tree-ccp
tree-ch
tree-coalesce-vars
tree-copy-prop
tree-dce
tree-dominator-opts
tree-dse
tree-forwprop
tree-fre
tree-loop-distribute-patterns
tree-loop-distribution
tree-loop-if-convert
tree-loop-im
tree-loop-ivcanon
tree-loop-linear
tree-loop-optimize
tree-loop-vectorize
tree-parallelize-loops=n
tree-partial-pre
tree-phiprop
tree-pre
tree-pta
tree-reassoc
tree-scev-cprop
tree-sink
tree-slp-vectorize
tree-slp-vectorize
tree-slsr
tree-sra
tree-switch-conversion
tree-tail-merge
tree-ter
tree-vectorize
tree-vrp
trivial-auto-var-init=choice
unconstrained-commons
unit-at-a-time
unreachable-traps
unroll-all-loops
unroll-loops
unsafe-math-optimizations
unswitch-loops
use-linker-plugin
variable-expansion-in-unroller
vect-cost-model=dynamic
vect-cost-model=model
version-loops-for-strides
vpt
web
whole-program
zero-call-used-regs=choice
profile-arcs
condition-coverage
test-coverage
profile-abs-path
profile-dir=path
profile-arcs
profile-note
profile-generate
profile-generate=path
inline-functions
profile-use
profile-info-section
profile-info-section=name
profile-note=path
profile-prefix-path=path
profile-prefix-map=old=new
profile-update=method
profile-filter-files=regex
profile-exclude-files=regex
profile-reproducible=[multithreaded|parallel-runs|serial]
sanitize=address
sanitize=hwaddress
sanitize=kernel-address
sanitize=hwaddress
sanitize=thread
sanitize=kernel-hwaddress
sanitize=pointer-compare
sanitize=thread
sanitize=pointer-subtract
sanitize=shadow-call-stack
sanitize=thread
sanitize=leak
sanitize=undefined
sanitize=leak
sanitize=shift
sanitize=shift-exponent
sanitize=shift-base
sanitize=integer-divide-by-zero
sanitize=unreachable
sanitize=vla-bound
sanitize=null
sanitize=return
sanitize=signed-integer-overflow
sanitize=bounds
sanitize=bounds-strict
sanitize=alignment
sanitize=object-size
sanitize=float-divide-by-zero
sanitize=undefined
sanitize=float-cast-overflow
sanitize=nonnull-attribute
sanitize=returns-nonnull-attribute
sanitize=bool
sanitize=enum
sanitize=vptr
sanitize=pointer-overflow
sanitize=builtin
sanitize=undefined
no-sanitize=all
asan-shadow-offset=number
sanitize-sections=s1
sanitize-recover[=opts]
sanitize-recover=
sanitize=float-cast-overflow
sanitize=address
sanitize-recover=all
sanitize-address-use-after-scope
sanitize-trap[=opts]
sanitize=float-divide-by-zero
sanitize-trap=all
sanitize-undefined-trap-on-error
sanitize-coverage=trace-pc
sanitize-coverage=trace-cmp
cf-protection=[full|branch|return|none|check]
harden-compares
harden-conditional-branches
harden-control-flow-redundancy
hardcfr-skip-leaf
hardcfr-check-exceptions
hardcfr-check-returning-calls
hardcfr-check-noreturn-calls=[always|no-xthrow|nothrow|never]
hardened
trivial-auto-var-init=zero
PIE
stack-clash-protection
cf-protection=full
hardened
stack-protector
stack-protector-all
stack-protector-strong
stack-protector-explicit
stack-check
stack-clash-protection
stack-limit-register=reg
stack-limit-symbol=sym
no-stack-limit
split-stack
strub=disable
strub=strict
strub=relaxed
strub=at-calls
strub=internal
strub=all
vtable-verify=[std|preinit|none]
vtv-debug
vtv-counts
instrument-functions
vtable-verify=std
instrument-functions-once
instrument-functions-exclude-file-list=file
instrument-functions-exclude-file-list=/bits/stl
instrument-functions-exclude-function-list=sym
patchable-function-entry=N…
preprocessed
directives-only
asynchronous-unwind-tables
callgraph-info Callgraph information in common VCG format on per object basis
callgraph-info=MARKERS
call-saved-reg
call-used-reg
checking
checking=n
common
compare-debug=
compare-debug[=opts]
compare-debug-second
dbg-cnt=counter-value-list
dbg-cnt-list
debug-cpp
delete-dead-exceptions
directives-only
disable-ipa-inline
disable-ipa-pass
disable-kind-pass=range-list
disable-rtl-gcse2=foo
disable-rtl-pass
disable-rtl-pass=range-list
disable-tree-ccp1
disable-tree-einline
disable-tree-pass
disable-tree-pass=range-list
dollars-in-identifiers
dump-
dump-debug
dump-earlydebug
dump-final-insns[=file]
dump-ipa-switch
dump-ipa-switch-options
dump-lang
dump-lang-all
dump-lang-switch
dump-lang-switch-options
dump-lang-switch-options=filename
dump-noaddr
dump-passes
dump-rtl-alignments
dump-rtl-all
dump-rtl-asmcons
dump-rtl-auto_inc_dec
dump-rtl-barriers
dump-rtl-bbpart
dump-rtl-bbro
dump-rtl-btl1
dump-rtl-btl2
dump-rtl-bypass
dump-rtl-ce1
dump-rtl-ce2
dump-rtl-ce3
dump-rtl-combine
dump-rtl-compgotos
dump-rtl-cprop_hardreg
dump-rtl-csa
dump-rtl-cse1
dump-rtl-cse2
dump-rtl-dbr
dump-rtl-dce
dump-rtl-dce1
dump-rtl-dce2
dump-rtl-dfinish
dump-rtl-dfinit
dump-rtl-eh
dump-rtl-eh_ranges
dump-rtl-expand
dump-rtl-fwprop1
dump-rtl-fwprop2
dump-rtl-gcse1
dump-rtl-gcse2
dump-rtl-init-regs
dump-rtl-initvals
dump-rtl-into_cfglayout
dump-rtl-ira
dump-rtl-jump
dump-rtl-loop2
dump-rtl-mach
dump-rtl-mode_sw
dump-rtl-outof_cfglayout
dump-rtl-pass
dump-rtl-pass=filename
dump-rtl-peephole2
dump-rtl-postreload
dump-rtl-pro_and_epilogue
dump-rtl-ree
dump-rtl-regclass
dump-rtl-rnreg
dump-rtl-sched1
dump-rtl-sched2
dump-rtl-seqabstr
dump-rtl-shorten
dump-rtl-sibling
dump-rtl-sms
dump-rtl-split1
dump-rtl-split2
dump-rtl-split3
dump-rtl-split4
dump-rtl-split5
dump-rtl-stack
dump-rtl-subreg1
dump-rtl-subreg2
dump-rtl-subregs_of_mode_finish
dump-rtl-subregs_of_mode_init
dump-rtl-unshare
dump-rtl-vartrack
dump-rtl-vregs
dump-rtl-web
dump-statistics-option
dump-tree-all
dump-tree-switch
dump-tree-switch-options
dump-tree-switch-options=filename
dump-unnumbered
dump-unnumbered-links
enable-ipa-pass
enable-kind-pass
enable-rtl-pass
enable-rtl-pass=range-list
enable-tree-cunroll=1
enable-tree-pass
enable-tree-pass=range-list
enable-tree-unroll
exceptions
exec-charset=charset
extended-identifiers
fixed-reg
inhibit-size-directive
input-charset=charset
ira-verbose=n
large-source-files
leading-underscore
linker-output=type
lto-report
lto-report-wpa
macro-prefix-map=old=new
max-include-depth=depth
mem-report
mem-report-wpa
multiflags
no-bit-tests
no-canonical-system-headers
no-gnu-unique
no-ident
no-jump-tables
non-call-exceptions
no-plt Don't use PLT for external function calls in position-independent code.
no-trampolines
no-verbose-asm
opt-info
opt-info-options
opt-info-options=filename
pack-struct[=n]
pcc-struct-return
pch-deps
pch-preprocess
pic
PIC
pie
PIE
post-ipa-mem-report
pre-ipa-mem-report
preprocessed
profile-report
random-seed=string
record-gcc-switches
reg-struct-return
report-bug
save-optimization-record
sched-verbose=n
short-enums
short-wchar
stack-reuse=reuse-level
stack-usage
stats
strict-overflow
strict-volatile-bitfields
sync-libcalls
tabstop=width
time-report
time-report-details
tls-model=model
track-macro-expansion[=level]
trampoline-impl=heap
trampoline-impl=[stack|heap]
trampolines
trapv
unwind-tables
use-ld=bfd
use-ld=gold
use-ld=lld
use-ld=mold
var-tracking-assignments-toggle
verbose-asm
visibility=[default|internal|hidden|protected]
visibility=hidden
wide-exec-charset=charset
working-directory
wrapv
wrapv-pointer
lto See also collect2 and lto1

See also

GCC options

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759398266, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/GCC/options/f/index(951): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78