Instrumentation-Options.html 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2017 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Funding Free Software", the Front-Cover
  8. Texts being (a) (see below), and with the Back-Cover Texts being (b)
  9. (see below). A copy of the license is included in the section entitled
  10. "GNU Free Documentation License".
  11. (a) The FSF's Front-Cover Text is:
  12. A GNU Manual
  13. (b) The FSF's Back-Cover Text is:
  14. You have freedom to copy and modify this GNU Manual, like GNU
  15. software. Copies published by the Free Software Foundation raise
  16. funds for GNU development. -->
  17. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  18. <head>
  19. <title>Using the GNU Compiler Collection (GCC): Instrumentation Options</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Instrumentation Options">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Instrumentation Options">
  22. <meta name="resource-type" content="document">
  23. <meta name="distribution" content="global">
  24. <meta name="Generator" content="makeinfo">
  25. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  26. <link href="index.html#Top" rel="start" title="Top">
  27. <link href="Option-Index.html#Option-Index" rel="index" title="Option Index">
  28. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  29. <link href="Invoking-GCC.html#Invoking-GCC" rel="up" title="Invoking GCC">
  30. <link href="Preprocessor-Options.html#Preprocessor-Options" rel="next" title="Preprocessor Options">
  31. <link href="Optimize-Options.html#Optimize-Options" rel="prev" title="Optimize Options">
  32. <style type="text/css">
  33. <!--
  34. a.summary-letter {text-decoration: none}
  35. blockquote.smallquotation {font-size: smaller}
  36. div.display {margin-left: 3.2em}
  37. div.example {margin-left: 3.2em}
  38. div.indentedblock {margin-left: 3.2em}
  39. div.lisp {margin-left: 3.2em}
  40. div.smalldisplay {margin-left: 3.2em}
  41. div.smallexample {margin-left: 3.2em}
  42. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  43. div.smalllisp {margin-left: 3.2em}
  44. kbd {font-style:oblique}
  45. pre.display {font-family: inherit}
  46. pre.format {font-family: inherit}
  47. pre.menu-comment {font-family: serif}
  48. pre.menu-preformatted {font-family: serif}
  49. pre.smalldisplay {font-family: inherit; font-size: smaller}
  50. pre.smallexample {font-size: smaller}
  51. pre.smallformat {font-family: inherit; font-size: smaller}
  52. pre.smalllisp {font-size: smaller}
  53. span.nocodebreak {white-space:nowrap}
  54. span.nolinebreak {white-space:nowrap}
  55. span.roman {font-family:serif; font-weight:normal}
  56. span.sansserif {font-family:sans-serif; font-weight:normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  62. <a name="Instrumentation-Options"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Preprocessor-Options.html#Preprocessor-Options" accesskey="n" rel="next">Preprocessor Options</a>, Previous: <a href="Optimize-Options.html#Optimize-Options" accesskey="p" rel="prev">Optimize Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Program-Instrumentation-Options"></a>
  69. <h3 class="section">3.11 Program Instrumentation Options</h3>
  70. <a name="index-instrumentation-options"></a>
  71. <a name="index-program-instrumentation-options"></a>
  72. <a name="index-run_002dtime-error-checking-options"></a>
  73. <a name="index-profiling-options"></a>
  74. <a name="index-options_002c-program-instrumentation"></a>
  75. <a name="index-options_002c-run_002dtime-error-checking"></a>
  76. <a name="index-options_002c-profiling"></a>
  77. <p>GCC supports a number of command-line options that control adding
  78. run-time instrumentation to the code it normally generates.
  79. For example, one purpose of instrumentation is collect profiling
  80. statistics for use in finding program hot spots, code coverage
  81. analysis, or profile-guided optimizations.
  82. Another class of program instrumentation is adding run-time checking
  83. to detect programming errors like invalid pointer
  84. dereferences or out-of-bounds array accesses, as well as deliberately
  85. hostile attacks such as stack smashing or C++ vtable hijacking.
  86. There is also a general hook which can be used to implement other
  87. forms of tracing or function-level instrumentation for debug or
  88. program analysis purposes.
  89. </p>
  90. <dl compact="compact">
  91. <dd><a name="index-prof"></a>
  92. </dd>
  93. <dt><code>-p</code></dt>
  94. <dd><a name="index-p"></a>
  95. <p>Generate extra code to write profile information suitable for the
  96. analysis program <code>prof</code>. You must use this option when compiling
  97. the source files you want data about, and you must also use it when
  98. linking.
  99. </p>
  100. <a name="index-gprof"></a>
  101. </dd>
  102. <dt><code>-pg</code></dt>
  103. <dd><a name="index-pg"></a>
  104. <p>Generate extra code to write profile information suitable for the
  105. analysis program <code>gprof</code>. You must use this option when compiling
  106. the source files you want data about, and you must also use it when
  107. linking.
  108. </p>
  109. </dd>
  110. <dt><code>-fprofile-arcs</code></dt>
  111. <dd><a name="index-fprofile_002darcs"></a>
  112. <p>Add code so that program flow <em>arcs</em> are instrumented. During
  113. execution the program records how many times each branch and call is
  114. executed and how many times it is taken or returns. On targets that support
  115. constructors with priority support, profiling properly handles constructors,
  116. destructors and C++ constructors (and destructors) of classes which are used
  117. as a type of a global variable.
  118. </p>
  119. <p>When the compiled
  120. program exits it saves this data to a file called
  121. <samp><var>auxname</var>.gcda</samp> for each source file. The data may be used for
  122. profile-directed optimizations (<samp>-fbranch-probabilities</samp>), or for
  123. test coverage analysis (<samp>-ftest-coverage</samp>). Each object file&rsquo;s
  124. <var>auxname</var> is generated from the name of the output file, if
  125. explicitly specified and it is not the final executable, otherwise it is
  126. the basename of the source file. In both cases any suffix is removed
  127. (e.g. <samp>foo.gcda</samp> for input file <samp>dir/foo.c</samp>, or
  128. <samp>dir/foo.gcda</samp> for output file specified as <samp>-o dir/foo.o</samp>).
  129. See <a href="Cross_002dprofiling.html#Cross_002dprofiling">Cross-profiling</a>.
  130. </p>
  131. <a name="index-gcov"></a>
  132. </dd>
  133. <dt><code>--coverage</code></dt>
  134. <dd><a name="index-coverage"></a>
  135. <p>This option is used to compile and link code instrumented for coverage
  136. analysis. The option is a synonym for <samp>-fprofile-arcs</samp>
  137. <samp>-ftest-coverage</samp> (when compiling) and <samp>-lgcov</samp> (when
  138. linking). See the documentation for those options for more details.
  139. </p>
  140. <ul>
  141. <li> Compile the source files with <samp>-fprofile-arcs</samp> plus optimization
  142. and code generation options. For test coverage analysis, use the
  143. additional <samp>-ftest-coverage</samp> option. You do not need to profile
  144. every source file in a program.
  145. </li><li> Link your object files with <samp>-lgcov</samp> or <samp>-fprofile-arcs</samp>
  146. (the latter implies the former).
  147. </li><li> Run the program on a representative workload to generate the arc profile
  148. information. This may be repeated any number of times. You can run
  149. concurrent instances of your program, and provided that the file system
  150. supports locking, the data files will be correctly updated. Unless
  151. a strict ISO C dialect option is in effect, <code>fork</code> calls are
  152. detected and correctly handled without double counting.
  153. </li><li> For profile-directed optimizations, compile the source files again with
  154. the same optimization and code generation options plus
  155. <samp>-fbranch-probabilities</samp> (see <a href="Optimize-Options.html#Optimize-Options">Options that
  156. Control Optimization</a>).
  157. </li><li> For test coverage analysis, use <code>gcov</code> to produce human readable
  158. information from the <samp>.gcno</samp> and <samp>.gcda</samp> files. Refer to the
  159. <code>gcov</code> documentation for further information.
  160. </li></ul>
  161. <p>With <samp>-fprofile-arcs</samp>, for each function of your program GCC
  162. creates a program flow graph, then finds a spanning tree for the graph.
  163. Only arcs that are not on the spanning tree have to be instrumented: the
  164. compiler adds code to count the number of times that these arcs are
  165. executed. When an arc is the only exit or only entrance to a block, the
  166. instrumentation code can be added to the block; otherwise, a new basic
  167. block must be created to hold the instrumentation code.
  168. </p>
  169. </dd>
  170. <dt><code>-ftest-coverage</code></dt>
  171. <dd><a name="index-ftest_002dcoverage"></a>
  172. <p>Produce a notes file that the <code>gcov</code> code-coverage utility
  173. (see <a href="Gcov.html#Gcov"><code>gcov</code>&mdash;a Test Coverage Program</a>) can use to
  174. show program coverage. Each source file&rsquo;s note file is called
  175. <samp><var>auxname</var>.gcno</samp>. Refer to the <samp>-fprofile-arcs</samp> option
  176. above for a description of <var>auxname</var> and instructions on how to
  177. generate test coverage data. Coverage data matches the source files
  178. more closely if you do not optimize.
  179. </p>
  180. </dd>
  181. <dt><code>-fprofile-dir=<var>path</var></code></dt>
  182. <dd><a name="index-fprofile_002ddir"></a>
  183. <p>Set the directory to search for the profile data files in to <var>path</var>.
  184. This option affects only the profile data generated by
  185. <samp>-fprofile-generate</samp>, <samp>-ftest-coverage</samp>, <samp>-fprofile-arcs</samp>
  186. and used by <samp>-fprofile-use</samp> and <samp>-fbranch-probabilities</samp>
  187. and its related options. Both absolute and relative paths can be used.
  188. By default, GCC uses the current directory as <var>path</var>, thus the
  189. profile data file appears in the same directory as the object file.
  190. </p>
  191. </dd>
  192. <dt><code>-fprofile-generate</code></dt>
  193. <dt><code>-fprofile-generate=<var>path</var></code></dt>
  194. <dd><a name="index-fprofile_002dgenerate"></a>
  195. <p>Enable options usually used for instrumenting application to produce
  196. profile useful for later recompilation with profile feedback based
  197. optimization. You must use <samp>-fprofile-generate</samp> both when
  198. compiling and when linking your program.
  199. </p>
  200. <p>The following options are enabled: <samp>-fprofile-arcs</samp>, <samp>-fprofile-values</samp>, <samp>-fvpt</samp>.
  201. </p>
  202. <p>If <var>path</var> is specified, GCC looks at the <var>path</var> to find
  203. the profile feedback data files. See <samp>-fprofile-dir</samp>.
  204. </p>
  205. <p>To optimize the program based on the collected profile information, use
  206. <samp>-fprofile-use</samp>. See <a href="Optimize-Options.html#Optimize-Options">Optimize Options</a>, for more information.
  207. </p>
  208. </dd>
  209. <dt><code>-fprofile-update=<var>method</var></code></dt>
  210. <dd><a name="index-fprofile_002dupdate"></a>
  211. <p>Alter the update method for an application instrumented for profile
  212. feedback based optimization. The <var>method</var> argument should be one of
  213. &lsquo;<samp>single</samp>&rsquo;, &lsquo;<samp>atomic</samp>&rsquo; or &lsquo;<samp>prefer-atomic</samp>&rsquo;.
  214. The first one is useful for single-threaded applications,
  215. while the second one prevents profile corruption by emitting thread-safe code.
  216. </p>
  217. <p><strong>Warning:</strong> When an application does not properly join all threads
  218. (or creates an detached thread), a profile file can be still corrupted.
  219. </p>
  220. <p>Using &lsquo;<samp>prefer-atomic</samp>&rsquo; would be transformed either to &lsquo;<samp>atomic</samp>&rsquo;,
  221. when supported by a target, or to &lsquo;<samp>single</samp>&rsquo; otherwise. The GCC driver
  222. automatically selects &lsquo;<samp>prefer-atomic</samp>&rsquo; when <samp>-pthread</samp>
  223. is present in the command line.
  224. </p>
  225. </dd>
  226. <dt><code>-fsanitize=address</code></dt>
  227. <dd><a name="index-fsanitize_003daddress"></a>
  228. <p>Enable AddressSanitizer, a fast memory error detector.
  229. Memory access instructions are instrumented to detect
  230. out-of-bounds and use-after-free bugs.
  231. The option enables <samp>-fsanitize-address-use-after-scope</samp>.
  232. See <a href="https://github.com/google/sanitizers/wiki/AddressSanitizer">https://github.com/google/sanitizers/wiki/AddressSanitizer</a> for
  233. more details. The run-time behavior can be influenced using the
  234. <code>ASAN_OPTIONS</code> environment variable. When set to <code>help=1</code>,
  235. the available options are shown at startup of the instrumented program. See
  236. <a href="https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags">https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags</a>
  237. for a list of supported options.
  238. The option cannot be combined with <samp>-fsanitize=thread</samp>
  239. and/or <samp>-fcheck-pointer-bounds</samp>.
  240. </p>
  241. </dd>
  242. <dt><code>-fsanitize=kernel-address</code></dt>
  243. <dd><a name="index-fsanitize_003dkernel_002daddress"></a>
  244. <p>Enable AddressSanitizer for Linux kernel.
  245. See <a href="https://github.com/google/kasan/wiki">https://github.com/google/kasan/wiki</a> for more details.
  246. The option cannot be combined with <samp>-fcheck-pointer-bounds</samp>.
  247. </p>
  248. </dd>
  249. <dt><code>-fsanitize=thread</code></dt>
  250. <dd><a name="index-fsanitize_003dthread"></a>
  251. <p>Enable ThreadSanitizer, a fast data race detector.
  252. Memory access instructions are instrumented to detect
  253. data race bugs. See <a href="https://github.com/google/sanitizers/wiki#threadsanitizer">https://github.com/google/sanitizers/wiki#threadsanitizer</a> for more
  254. details. The run-time behavior can be influenced using the <code>TSAN_OPTIONS</code>
  255. environment variable; see
  256. <a href="https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags">https://github.com/google/sanitizers/wiki/ThreadSanitizerFlags</a> for a list of
  257. supported options.
  258. The option cannot be combined with <samp>-fsanitize=address</samp>,
  259. <samp>-fsanitize=leak</samp> and/or <samp>-fcheck-pointer-bounds</samp>.
  260. </p>
  261. <p>Note that sanitized atomic builtins cannot throw exceptions when
  262. operating on invalid memory addresses with non-call exceptions
  263. (<samp>-fnon-call-exceptions</samp>).
  264. </p>
  265. </dd>
  266. <dt><code>-fsanitize=leak</code></dt>
  267. <dd><a name="index-fsanitize_003dleak"></a>
  268. <p>Enable LeakSanitizer, a memory leak detector.
  269. This option only matters for linking of executables and
  270. the executable is linked against a library that overrides <code>malloc</code>
  271. and other allocator functions. See
  272. <a href="https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer">https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer</a> for more
  273. details. The run-time behavior can be influenced using the
  274. <code>LSAN_OPTIONS</code> environment variable.
  275. The option cannot be combined with <samp>-fsanitize=thread</samp>.
  276. </p>
  277. </dd>
  278. <dt><code>-fsanitize=undefined</code></dt>
  279. <dd><a name="index-fsanitize_003dundefined"></a>
  280. <p>Enable UndefinedBehaviorSanitizer, a fast undefined behavior detector.
  281. Various computations are instrumented to detect undefined behavior
  282. at runtime. Current suboptions are:
  283. </p>
  284. <dl compact="compact">
  285. <dt><code>-fsanitize=shift</code></dt>
  286. <dd><a name="index-fsanitize_003dshift"></a>
  287. <p>This option enables checking that the result of a shift operation is
  288. not undefined. Note that what exactly is considered undefined differs
  289. slightly between C and C++, as well as between ISO C90 and C99, etc.
  290. This option has two suboptions, <samp>-fsanitize=shift-base</samp> and
  291. <samp>-fsanitize=shift-exponent</samp>.
  292. </p>
  293. </dd>
  294. <dt><code>-fsanitize=shift-exponent</code></dt>
  295. <dd><a name="index-fsanitize_003dshift_002dexponent"></a>
  296. <p>This option enables checking that the second argument of a shift operation
  297. is not negative and is smaller than the precision of the promoted first
  298. argument.
  299. </p>
  300. </dd>
  301. <dt><code>-fsanitize=shift-base</code></dt>
  302. <dd><a name="index-fsanitize_003dshift_002dbase"></a>
  303. <p>If the second argument of a shift operation is within range, check that the
  304. result of a shift operation is not undefined. Note that what exactly is
  305. considered undefined differs slightly between C and C++, as well as between
  306. ISO C90 and C99, etc.
  307. </p>
  308. </dd>
  309. <dt><code>-fsanitize=integer-divide-by-zero</code></dt>
  310. <dd><a name="index-fsanitize_003dinteger_002ddivide_002dby_002dzero"></a>
  311. <p>Detect integer division by zero as well as <code>INT_MIN / -1</code> division.
  312. </p>
  313. </dd>
  314. <dt><code>-fsanitize=unreachable</code></dt>
  315. <dd><a name="index-fsanitize_003dunreachable"></a>
  316. <p>With this option, the compiler turns the <code>__builtin_unreachable</code>
  317. call into a diagnostics message call instead. When reaching the
  318. <code>__builtin_unreachable</code> call, the behavior is undefined.
  319. </p>
  320. </dd>
  321. <dt><code>-fsanitize=vla-bound</code></dt>
  322. <dd><a name="index-fsanitize_003dvla_002dbound"></a>
  323. <p>This option instructs the compiler to check that the size of a variable
  324. length array is positive.
  325. </p>
  326. </dd>
  327. <dt><code>-fsanitize=null</code></dt>
  328. <dd><a name="index-fsanitize_003dnull"></a>
  329. <p>This option enables pointer checking. Particularly, the application
  330. built with this option turned on will issue an error message when it
  331. tries to dereference a NULL pointer, or if a reference (possibly an
  332. rvalue reference) is bound to a NULL pointer, or if a method is invoked
  333. on an object pointed by a NULL pointer.
  334. </p>
  335. </dd>
  336. <dt><code>-fsanitize=return</code></dt>
  337. <dd><a name="index-fsanitize_003dreturn"></a>
  338. <p>This option enables return statement checking. Programs
  339. built with this option turned on will issue an error message
  340. when the end of a non-void function is reached without actually
  341. returning a value. This option works in C++ only.
  342. </p>
  343. </dd>
  344. <dt><code>-fsanitize=signed-integer-overflow</code></dt>
  345. <dd><a name="index-fsanitize_003dsigned_002dinteger_002doverflow"></a>
  346. <p>This option enables signed integer overflow checking. We check that
  347. the result of <code>+</code>, <code>*</code>, and both unary and binary <code>-</code>
  348. does not overflow in the signed arithmetics. Note, integer promotion
  349. rules must be taken into account. That is, the following is not an
  350. overflow:
  351. </p><div class="smallexample">
  352. <pre class="smallexample">signed char a = SCHAR_MAX;
  353. a++;
  354. </pre></div>
  355. </dd>
  356. <dt><code>-fsanitize=bounds</code></dt>
  357. <dd><a name="index-fsanitize_003dbounds"></a>
  358. <p>This option enables instrumentation of array bounds. Various out of bounds
  359. accesses are detected. Flexible array members, flexible array member-like
  360. arrays, and initializers of variables with static storage are not instrumented.
  361. The option cannot be combined with <samp>-fcheck-pointer-bounds</samp>.
  362. </p>
  363. </dd>
  364. <dt><code>-fsanitize=bounds-strict</code></dt>
  365. <dd><a name="index-fsanitize_003dbounds_002dstrict"></a>
  366. <p>This option enables strict instrumentation of array bounds. Most out of bounds
  367. accesses are detected, including flexible array members and flexible array
  368. member-like arrays. Initializers of variables with static storage are not
  369. instrumented. The option cannot be combined
  370. with <samp>-fcheck-pointer-bounds</samp>.
  371. </p>
  372. </dd>
  373. <dt><code>-fsanitize=alignment</code></dt>
  374. <dd><a name="index-fsanitize_003dalignment"></a>
  375. <p>This option enables checking of alignment of pointers when they are
  376. dereferenced, or when a reference is bound to insufficiently aligned target,
  377. or when a method or constructor is invoked on insufficiently aligned object.
  378. </p>
  379. </dd>
  380. <dt><code>-fsanitize=object-size</code></dt>
  381. <dd><a name="index-fsanitize_003dobject_002dsize"></a>
  382. <p>This option enables instrumentation of memory references using the
  383. <code>__builtin_object_size</code> function. Various out of bounds pointer
  384. accesses are detected.
  385. </p>
  386. </dd>
  387. <dt><code>-fsanitize=float-divide-by-zero</code></dt>
  388. <dd><a name="index-fsanitize_003dfloat_002ddivide_002dby_002dzero"></a>
  389. <p>Detect floating-point division by zero. Unlike other similar options,
  390. <samp>-fsanitize=float-divide-by-zero</samp> is not enabled by
  391. <samp>-fsanitize=undefined</samp>, since floating-point division by zero can
  392. be a legitimate way of obtaining infinities and NaNs.
  393. </p>
  394. </dd>
  395. <dt><code>-fsanitize=float-cast-overflow</code></dt>
  396. <dd><a name="index-fsanitize_003dfloat_002dcast_002doverflow"></a>
  397. <p>This option enables floating-point type to integer conversion checking.
  398. We check that the result of the conversion does not overflow.
  399. Unlike other similar options, <samp>-fsanitize=float-cast-overflow</samp> is
  400. not enabled by <samp>-fsanitize=undefined</samp>.
  401. This option does not work well with <code>FE_INVALID</code> exceptions enabled.
  402. </p>
  403. </dd>
  404. <dt><code>-fsanitize=nonnull-attribute</code></dt>
  405. <dd><a name="index-fsanitize_003dnonnull_002dattribute"></a>
  406. <p>This option enables instrumentation of calls, checking whether null values
  407. are not passed to arguments marked as requiring a non-null value by the
  408. <code>nonnull</code> function attribute.
  409. </p>
  410. </dd>
  411. <dt><code>-fsanitize=returns-nonnull-attribute</code></dt>
  412. <dd><a name="index-fsanitize_003dreturns_002dnonnull_002dattribute"></a>
  413. <p>This option enables instrumentation of return statements in functions
  414. marked with <code>returns_nonnull</code> function attribute, to detect returning
  415. of null values from such functions.
  416. </p>
  417. </dd>
  418. <dt><code>-fsanitize=bool</code></dt>
  419. <dd><a name="index-fsanitize_003dbool"></a>
  420. <p>This option enables instrumentation of loads from bool. If a value other
  421. than 0/1 is loaded, a run-time error is issued.
  422. </p>
  423. </dd>
  424. <dt><code>-fsanitize=enum</code></dt>
  425. <dd><a name="index-fsanitize_003denum"></a>
  426. <p>This option enables instrumentation of loads from an enum type. If
  427. a value outside the range of values for the enum type is loaded,
  428. a run-time error is issued.
  429. </p>
  430. </dd>
  431. <dt><code>-fsanitize=vptr</code></dt>
  432. <dd><a name="index-fsanitize_003dvptr"></a>
  433. <p>This option enables instrumentation of C++ member function calls, member
  434. accesses and some conversions between pointers to base and derived classes,
  435. to verify the referenced object has the correct dynamic type.
  436. </p>
  437. </dd>
  438. </dl>
  439. <p>While <samp>-ftrapv</samp> causes traps for signed overflows to be emitted,
  440. <samp>-fsanitize=undefined</samp> gives a diagnostic message.
  441. This currently works only for the C family of languages.
  442. </p>
  443. </dd>
  444. <dt><code>-fno-sanitize=all</code></dt>
  445. <dd><a name="index-fno_002dsanitize_003dall"></a>
  446. <p>This option disables all previously enabled sanitizers.
  447. <samp>-fsanitize=all</samp> is not allowed, as some sanitizers cannot be used
  448. together.
  449. </p>
  450. </dd>
  451. <dt><code>-fasan-shadow-offset=<var>number</var></code></dt>
  452. <dd><a name="index-fasan_002dshadow_002doffset"></a>
  453. <p>This option forces GCC to use custom shadow offset in AddressSanitizer checks.
  454. It is useful for experimenting with different shadow memory layouts in
  455. Kernel AddressSanitizer.
  456. </p>
  457. </dd>
  458. <dt><code>-fsanitize-sections=<var>s1</var>,<var>s2</var>,...</code></dt>
  459. <dd><a name="index-fsanitize_002dsections"></a>
  460. <p>Sanitize global variables in selected user-defined sections. <var>si</var> may
  461. contain wildcards.
  462. </p>
  463. </dd>
  464. <dt><code>-fsanitize-recover<span class="roman">[</span>=<var>opts</var><span class="roman">]</span></code></dt>
  465. <dd><a name="index-fsanitize_002drecover"></a>
  466. <a name="index-fno_002dsanitize_002drecover"></a>
  467. <p><samp>-fsanitize-recover=</samp> controls error recovery mode for sanitizers
  468. mentioned in comma-separated list of <var>opts</var>. Enabling this option
  469. for a sanitizer component causes it to attempt to continue
  470. running the program as if no error happened. This means multiple
  471. runtime errors can be reported in a single program run, and the exit
  472. code of the program may indicate success even when errors
  473. have been reported. The <samp>-fno-sanitize-recover=</samp> option
  474. can be used to alter
  475. this behavior: only the first detected error is reported
  476. and program then exits with a non-zero exit code.
  477. </p>
  478. <p>Currently this feature only works for <samp>-fsanitize=undefined</samp> (and its suboptions
  479. except for <samp>-fsanitize=unreachable</samp> and <samp>-fsanitize=return</samp>),
  480. <samp>-fsanitize=float-cast-overflow</samp>, <samp>-fsanitize=float-divide-by-zero</samp>,
  481. <samp>-fsanitize=bounds-strict</samp>,
  482. <samp>-fsanitize=kernel-address</samp> and <samp>-fsanitize=address</samp>.
  483. For these sanitizers error recovery is turned on by default,
  484. except <samp>-fsanitize=address</samp>, for which this feature is experimental.
  485. <samp>-fsanitize-recover=all</samp> and <samp>-fno-sanitize-recover=all</samp> is also
  486. accepted, the former enables recovery for all sanitizers that support it,
  487. the latter disables recovery for all sanitizers that support it.
  488. </p>
  489. <p>Even if a recovery mode is turned on the compiler side, it needs to be also
  490. enabled on the runtime library side, otherwise the failures are still fatal.
  491. The runtime library defaults to <code>halt_on_error=0</code> for
  492. ThreadSanitizer and UndefinedBehaviorSanitizer, while default value for
  493. AddressSanitizer is <code>halt_on_error=1</code>. This can be overridden through
  494. setting the <code>halt_on_error</code> flag in the corresponding environment variable.
  495. </p>
  496. <p>Syntax without an explicit <var>opts</var> parameter is deprecated. It is
  497. equivalent to specifying an <var>opts</var> list of:
  498. </p>
  499. <div class="smallexample">
  500. <pre class="smallexample">undefined,float-cast-overflow,float-divide-by-zero,bounds-strict
  501. </pre></div>
  502. </dd>
  503. <dt><code>-fsanitize-address-use-after-scope</code></dt>
  504. <dd><a name="index-fsanitize_002daddress_002duse_002dafter_002dscope"></a>
  505. <p>Enable sanitization of local variables to detect use-after-scope bugs.
  506. The option sets <samp>-fstack-reuse</samp> to &lsquo;<samp>none</samp>&rsquo;.
  507. </p>
  508. </dd>
  509. <dt><code>-fsanitize-undefined-trap-on-error</code></dt>
  510. <dd><a name="index-fsanitize_002dundefined_002dtrap_002don_002derror"></a>
  511. <p>The <samp>-fsanitize-undefined-trap-on-error</samp> option instructs the compiler to
  512. report undefined behavior using <code>__builtin_trap</code> rather than
  513. a <code>libubsan</code> library routine. The advantage of this is that the
  514. <code>libubsan</code> library is not needed and is not linked in, so this
  515. is usable even in freestanding environments.
  516. </p>
  517. </dd>
  518. <dt><code>-fsanitize-coverage=trace-pc</code></dt>
  519. <dd><a name="index-fsanitize_002dcoverage_003dtrace_002dpc"></a>
  520. <p>Enable coverage-guided fuzzing code instrumentation.
  521. Inserts a call to <code>__sanitizer_cov_trace_pc</code> into every basic block.
  522. </p>
  523. </dd>
  524. <dt><code>-fbounds-check</code></dt>
  525. <dd><a name="index-fbounds_002dcheck"></a>
  526. <p>For front ends that support it, generate additional code to check that
  527. indices used to access arrays are within the declared range. This is
  528. currently only supported by the Fortran front end, where this option
  529. defaults to false.
  530. </p>
  531. </dd>
  532. <dt><code>-fcheck-pointer-bounds</code></dt>
  533. <dd><a name="index-fcheck_002dpointer_002dbounds"></a>
  534. <a name="index-fno_002dcheck_002dpointer_002dbounds"></a>
  535. <a name="index-Pointer-Bounds-Checker-options"></a>
  536. <p>Enable Pointer Bounds Checker instrumentation. Each memory reference
  537. is instrumented with checks of the pointer used for memory access against
  538. bounds associated with that pointer.
  539. </p>
  540. <p>Currently there
  541. is only an implementation for Intel MPX available, thus x86 GNU/Linux target
  542. and <samp>-mmpx</samp> are required to enable this feature.
  543. MPX-based instrumentation requires
  544. a runtime library to enable MPX in hardware and handle bounds
  545. violation signals. By default when <samp>-fcheck-pointer-bounds</samp>
  546. and <samp>-mmpx</samp> options are used to link a program, the GCC driver
  547. links against the <samp>libmpx</samp> and <samp>libmpxwrappers</samp> libraries.
  548. Bounds checking on calls to dynamic libraries requires a linker
  549. with <samp>-z bndplt</samp> support; if GCC was configured with a linker
  550. without support for this option (including the Gold linker and older
  551. versions of ld), a warning is given if you link with <samp>-mmpx</samp>
  552. without also specifying <samp>-static</samp>, since the overall effectiveness
  553. of the bounds checking protection is reduced.
  554. See also <samp>-static-libmpxwrappers</samp>.
  555. </p>
  556. <p>MPX-based instrumentation
  557. may be used for debugging and also may be included in production code
  558. to increase program security. Depending on usage, you may
  559. have different requirements for the runtime library. The current version
  560. of the MPX runtime library is more oriented for use as a debugging
  561. tool. MPX runtime library usage implies <samp>-lpthread</samp>. See
  562. also <samp>-static-libmpx</samp>. The runtime library behavior can be
  563. influenced using various <code>CHKP_RT_*</code> environment variables. See
  564. <a href="https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler">https://gcc.gnu.org/wiki/Intel%20MPX%20support%20in%20the%20GCC%20compiler</a>
  565. for more details.
  566. </p>
  567. <p>Generated instrumentation may be controlled by various
  568. <samp>-fchkp-*</samp> options and by the <code>bnd_variable_size</code>
  569. structure field attribute (see <a href="Type-Attributes.html#Type-Attributes">Type Attributes</a>) and
  570. <code>bnd_legacy</code>, and <code>bnd_instrument</code> function attributes
  571. (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>). GCC also provides a number of built-in
  572. functions for controlling the Pointer Bounds Checker. See <a href="Pointer-Bounds-Checker-builtins.html#Pointer-Bounds-Checker-builtins">Pointer Bounds Checker builtins</a>, for more information.
  573. </p>
  574. </dd>
  575. <dt><code>-fchkp-check-incomplete-type</code></dt>
  576. <dd><a name="index-fchkp_002dcheck_002dincomplete_002dtype"></a>
  577. <a name="index-fno_002dchkp_002dcheck_002dincomplete_002dtype"></a>
  578. <p>Generate pointer bounds checks for variables with incomplete type.
  579. Enabled by default.
  580. </p>
  581. </dd>
  582. <dt><code>-fchkp-narrow-bounds</code></dt>
  583. <dd><a name="index-fchkp_002dnarrow_002dbounds"></a>
  584. <a name="index-fno_002dchkp_002dnarrow_002dbounds"></a>
  585. <p>Controls bounds used by Pointer Bounds Checker for pointers to object
  586. fields. If narrowing is enabled then field bounds are used. Otherwise
  587. object bounds are used. See also <samp>-fchkp-narrow-to-innermost-array</samp>
  588. and <samp>-fchkp-first-field-has-own-bounds</samp>. Enabled by default.
  589. </p>
  590. </dd>
  591. <dt><code>-fchkp-first-field-has-own-bounds</code></dt>
  592. <dd><a name="index-fchkp_002dfirst_002dfield_002dhas_002down_002dbounds"></a>
  593. <a name="index-fno_002dchkp_002dfirst_002dfield_002dhas_002down_002dbounds"></a>
  594. <p>Forces Pointer Bounds Checker to use narrowed bounds for the address of the
  595. first field in the structure. By default a pointer to the first field has
  596. the same bounds as a pointer to the whole structure.
  597. </p>
  598. </dd>
  599. <dt><code>-fchkp-flexible-struct-trailing-arrays</code></dt>
  600. <dd><a name="index-fchkp_002dflexible_002dstruct_002dtrailing_002darrays"></a>
  601. <a name="index-fno_002dchkp_002dflexible_002dstruct_002dtrailing_002darrays"></a>
  602. <p>Forces Pointer Bounds Checker to treat all trailing arrays in structures as
  603. possibly flexible. By default only array fields with zero length or that are
  604. marked with attribute bnd_variable_size are treated as flexible.
  605. </p>
  606. </dd>
  607. <dt><code>-fchkp-narrow-to-innermost-array</code></dt>
  608. <dd><a name="index-fchkp_002dnarrow_002dto_002dinnermost_002darray"></a>
  609. <a name="index-fno_002dchkp_002dnarrow_002dto_002dinnermost_002darray"></a>
  610. <p>Forces Pointer Bounds Checker to use bounds of the innermost arrays in
  611. case of nested static array access. By default this option is disabled and
  612. bounds of the outermost array are used.
  613. </p>
  614. </dd>
  615. <dt><code>-fchkp-optimize</code></dt>
  616. <dd><a name="index-fchkp_002doptimize"></a>
  617. <a name="index-fno_002dchkp_002doptimize"></a>
  618. <p>Enables Pointer Bounds Checker optimizations. Enabled by default at
  619. optimization levels <samp>-O</samp>, <samp>-O2</samp>, <samp>-O3</samp>.
  620. </p>
  621. </dd>
  622. <dt><code>-fchkp-use-fast-string-functions</code></dt>
  623. <dd><a name="index-fchkp_002duse_002dfast_002dstring_002dfunctions"></a>
  624. <a name="index-fno_002dchkp_002duse_002dfast_002dstring_002dfunctions"></a>
  625. <p>Enables use of <code>*_nobnd</code> versions of string functions (not copying bounds)
  626. by Pointer Bounds Checker. Disabled by default.
  627. </p>
  628. </dd>
  629. <dt><code>-fchkp-use-nochk-string-functions</code></dt>
  630. <dd><a name="index-fchkp_002duse_002dnochk_002dstring_002dfunctions"></a>
  631. <a name="index-fno_002dchkp_002duse_002dnochk_002dstring_002dfunctions"></a>
  632. <p>Enables use of <code>*_nochk</code> versions of string functions (not checking bounds)
  633. by Pointer Bounds Checker. Disabled by default.
  634. </p>
  635. </dd>
  636. <dt><code>-fchkp-use-static-bounds</code></dt>
  637. <dd><a name="index-fchkp_002duse_002dstatic_002dbounds"></a>
  638. <a name="index-fno_002dchkp_002duse_002dstatic_002dbounds"></a>
  639. <p>Allow Pointer Bounds Checker to generate static bounds holding
  640. bounds of static variables. Enabled by default.
  641. </p>
  642. </dd>
  643. <dt><code>-fchkp-use-static-const-bounds</code></dt>
  644. <dd><a name="index-fchkp_002duse_002dstatic_002dconst_002dbounds"></a>
  645. <a name="index-fno_002dchkp_002duse_002dstatic_002dconst_002dbounds"></a>
  646. <p>Use statically-initialized bounds for constant bounds instead of
  647. generating them each time they are required. By default enabled when
  648. <samp>-fchkp-use-static-bounds</samp> is enabled.
  649. </p>
  650. </dd>
  651. <dt><code>-fchkp-treat-zero-dynamic-size-as-infinite</code></dt>
  652. <dd><a name="index-fchkp_002dtreat_002dzero_002ddynamic_002dsize_002das_002dinfinite"></a>
  653. <a name="index-fno_002dchkp_002dtreat_002dzero_002ddynamic_002dsize_002das_002dinfinite"></a>
  654. <p>With this option, objects with incomplete type whose
  655. dynamically-obtained size is zero are treated as having infinite size
  656. instead by Pointer Bounds
  657. Checker. This option may be helpful if a program is linked with a library
  658. missing size information for some symbols. Disabled by default.
  659. </p>
  660. </dd>
  661. <dt><code>-fchkp-check-read</code></dt>
  662. <dd><a name="index-fchkp_002dcheck_002dread"></a>
  663. <a name="index-fno_002dchkp_002dcheck_002dread"></a>
  664. <p>Instructs Pointer Bounds Checker to generate checks for all read
  665. accesses to memory. Enabled by default.
  666. </p>
  667. </dd>
  668. <dt><code>-fchkp-check-write</code></dt>
  669. <dd><a name="index-fchkp_002dcheck_002dwrite"></a>
  670. <a name="index-fno_002dchkp_002dcheck_002dwrite"></a>
  671. <p>Instructs Pointer Bounds Checker to generate checks for all write
  672. accesses to memory. Enabled by default.
  673. </p>
  674. </dd>
  675. <dt><code>-fchkp-store-bounds</code></dt>
  676. <dd><a name="index-fchkp_002dstore_002dbounds"></a>
  677. <a name="index-fno_002dchkp_002dstore_002dbounds"></a>
  678. <p>Instructs Pointer Bounds Checker to generate bounds stores for
  679. pointer writes. Enabled by default.
  680. </p>
  681. </dd>
  682. <dt><code>-fchkp-instrument-calls</code></dt>
  683. <dd><a name="index-fchkp_002dinstrument_002dcalls"></a>
  684. <a name="index-fno_002dchkp_002dinstrument_002dcalls"></a>
  685. <p>Instructs Pointer Bounds Checker to pass pointer bounds to calls.
  686. Enabled by default.
  687. </p>
  688. </dd>
  689. <dt><code>-fchkp-instrument-marked-only</code></dt>
  690. <dd><a name="index-fchkp_002dinstrument_002dmarked_002donly"></a>
  691. <a name="index-fno_002dchkp_002dinstrument_002dmarked_002donly"></a>
  692. <p>Instructs Pointer Bounds Checker to instrument only functions
  693. marked with the <code>bnd_instrument</code> attribute
  694. (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>). Disabled by default.
  695. </p>
  696. </dd>
  697. <dt><code>-fchkp-use-wrappers</code></dt>
  698. <dd><a name="index-fchkp_002duse_002dwrappers"></a>
  699. <a name="index-fno_002dchkp_002duse_002dwrappers"></a>
  700. <p>Allows Pointer Bounds Checker to replace calls to built-in functions
  701. with calls to wrapper functions. When <samp>-fchkp-use-wrappers</samp>
  702. is used to link a program, the GCC driver automatically links
  703. against <samp>libmpxwrappers</samp>. See also <samp>-static-libmpxwrappers</samp>.
  704. Enabled by default.
  705. </p>
  706. </dd>
  707. <dt><code>-fstack-protector</code></dt>
  708. <dd><a name="index-fstack_002dprotector"></a>
  709. <p>Emit extra code to check for buffer overflows, such as stack smashing
  710. attacks. This is done by adding a guard variable to functions with
  711. vulnerable objects. This includes functions that call <code>alloca</code>, and
  712. functions with buffers larger than 8 bytes. The guards are initialized
  713. when a function is entered and then checked when the function exits.
  714. If a guard check fails, an error message is printed and the program exits.
  715. </p>
  716. </dd>
  717. <dt><code>-fstack-protector-all</code></dt>
  718. <dd><a name="index-fstack_002dprotector_002dall"></a>
  719. <p>Like <samp>-fstack-protector</samp> except that all functions are protected.
  720. </p>
  721. </dd>
  722. <dt><code>-fstack-protector-strong</code></dt>
  723. <dd><a name="index-fstack_002dprotector_002dstrong"></a>
  724. <p>Like <samp>-fstack-protector</samp> but includes additional functions to
  725. be protected &mdash; those that have local array definitions, or have
  726. references to local frame addresses.
  727. </p>
  728. </dd>
  729. <dt><code>-fstack-protector-explicit</code></dt>
  730. <dd><a name="index-fstack_002dprotector_002dexplicit"></a>
  731. <p>Like <samp>-fstack-protector</samp> but only protects those functions which
  732. have the <code>stack_protect</code> attribute.
  733. </p>
  734. </dd>
  735. <dt><code>-fstack-check</code></dt>
  736. <dd><a name="index-fstack_002dcheck"></a>
  737. <p>Generate code to verify that you do not go beyond the boundary of the
  738. stack. You should specify this flag if you are running in an
  739. environment with multiple threads, but you only rarely need to specify it in
  740. a single-threaded environment since stack overflow is automatically
  741. detected on nearly all systems if there is only one stack.
  742. </p>
  743. <p>Note that this switch does not actually cause checking to be done; the
  744. operating system or the language runtime must do that. The switch causes
  745. generation of code to ensure that they see the stack being extended.
  746. </p>
  747. <p>You can additionally specify a string parameter: &lsquo;<samp>no</samp>&rsquo; means no
  748. checking, &lsquo;<samp>generic</samp>&rsquo; means force the use of old-style checking,
  749. &lsquo;<samp>specific</samp>&rsquo; means use the best checking method and is equivalent
  750. to bare <samp>-fstack-check</samp>.
  751. </p>
  752. <p>Old-style checking is a generic mechanism that requires no specific
  753. target support in the compiler but comes with the following drawbacks:
  754. </p>
  755. <ol>
  756. <li> Modified allocation strategy for large objects: they are always
  757. allocated dynamically if their size exceeds a fixed threshold.
  758. </li><li> Fixed limit on the size of the static frame of functions: when it is
  759. topped by a particular function, stack checking is not reliable and
  760. a warning is issued by the compiler.
  761. </li><li> Inefficiency: because of both the modified allocation strategy and the
  762. generic implementation, code performance is hampered.
  763. </li></ol>
  764. <p>Note that old-style stack checking is also the fallback method for
  765. &lsquo;<samp>specific</samp>&rsquo; if no target support has been added in the compiler.
  766. </p>
  767. </dd>
  768. <dt><code>-fstack-limit-register=<var>reg</var></code></dt>
  769. <dt><code>-fstack-limit-symbol=<var>sym</var></code></dt>
  770. <dt><code>-fno-stack-limit</code></dt>
  771. <dd><a name="index-fstack_002dlimit_002dregister"></a>
  772. <a name="index-fstack_002dlimit_002dsymbol"></a>
  773. <a name="index-fno_002dstack_002dlimit"></a>
  774. <p>Generate code to ensure that the stack does not grow beyond a certain value,
  775. either the value of a register or the address of a symbol. If a larger
  776. stack is required, a signal is raised at run time. For most targets,
  777. the signal is raised before the stack overruns the boundary, so
  778. it is possible to catch the signal without taking special precautions.
  779. </p>
  780. <p>For instance, if the stack starts at absolute address &lsquo;<samp>0x80000000</samp>&rsquo;
  781. and grows downwards, you can use the flags
  782. <samp>-fstack-limit-symbol=__stack_limit</samp> and
  783. <samp>-Wl,--defsym,__stack_limit=0x7ffe0000</samp> to enforce a stack limit
  784. of 128KB. Note that this may only work with the GNU linker.
  785. </p>
  786. <p>You can locally override stack limit checking by using the
  787. <code>no_stack_limit</code> function attribute (see <a href="Function-Attributes.html#Function-Attributes">Function Attributes</a>).
  788. </p>
  789. </dd>
  790. <dt><code>-fsplit-stack</code></dt>
  791. <dd><a name="index-fsplit_002dstack"></a>
  792. <p>Generate code to automatically split the stack before it overflows.
  793. The resulting program has a discontiguous stack which can only
  794. overflow if the program is unable to allocate any more memory. This
  795. is most useful when running threaded programs, as it is no longer
  796. necessary to calculate a good stack size to use for each thread. This
  797. is currently only implemented for the x86 targets running
  798. GNU/Linux.
  799. </p>
  800. <p>When code compiled with <samp>-fsplit-stack</samp> calls code compiled
  801. without <samp>-fsplit-stack</samp>, there may not be much stack space
  802. available for the latter code to run. If compiling all code,
  803. including library code, with <samp>-fsplit-stack</samp> is not an option,
  804. then the linker can fix up these calls so that the code compiled
  805. without <samp>-fsplit-stack</samp> always has a large stack. Support for
  806. this is implemented in the gold linker in GNU binutils release 2.21
  807. and later.
  808. </p>
  809. </dd>
  810. <dt><code>-fvtable-verify=<span class="roman">[</span>std<span class="roman">|</span>preinit<span class="roman">|</span>none<span class="roman">]</span></code></dt>
  811. <dd><a name="index-fvtable_002dverify"></a>
  812. <p>This option is only available when compiling C++ code.
  813. It turns on (or off, if using <samp>-fvtable-verify=none</samp>) the security
  814. feature that verifies at run time, for every virtual call, that
  815. the vtable pointer through which the call is made is valid for the type of
  816. the object, and has not been corrupted or overwritten. If an invalid vtable
  817. pointer is detected at run time, an error is reported and execution of the
  818. program is immediately halted.
  819. </p>
  820. <p>This option causes run-time data structures to be built at program startup,
  821. which are used for verifying the vtable pointers.
  822. The options &lsquo;<samp>std</samp>&rsquo; and &lsquo;<samp>preinit</samp>&rsquo;
  823. control the timing of when these data structures are built. In both cases the
  824. data structures are built before execution reaches <code>main</code>. Using
  825. <samp>-fvtable-verify=std</samp> causes the data structures to be built after
  826. shared libraries have been loaded and initialized.
  827. <samp>-fvtable-verify=preinit</samp> causes them to be built before shared
  828. libraries have been loaded and initialized.
  829. </p>
  830. <p>If this option appears multiple times in the command line with different
  831. values specified, &lsquo;<samp>none</samp>&rsquo; takes highest priority over both &lsquo;<samp>std</samp>&rsquo; and
  832. &lsquo;<samp>preinit</samp>&rsquo;; &lsquo;<samp>preinit</samp>&rsquo; takes priority over &lsquo;<samp>std</samp>&rsquo;.
  833. </p>
  834. </dd>
  835. <dt><code>-fvtv-debug</code></dt>
  836. <dd><a name="index-fvtv_002ddebug"></a>
  837. <p>When used in conjunction with <samp>-fvtable-verify=std</samp> or
  838. <samp>-fvtable-verify=preinit</samp>, causes debug versions of the
  839. runtime functions for the vtable verification feature to be called.
  840. This flag also causes the compiler to log information about which
  841. vtable pointers it finds for each class.
  842. This information is written to a file named <samp>vtv_set_ptr_data.log</samp>
  843. in the directory named by the environment variable <code>VTV_LOGS_DIR</code>
  844. if that is defined or the current working directory otherwise.
  845. </p>
  846. <p>Note: This feature <em>appends</em> data to the log file. If you want a fresh log
  847. file, be sure to delete any existing one.
  848. </p>
  849. </dd>
  850. <dt><code>-fvtv-counts</code></dt>
  851. <dd><a name="index-fvtv_002dcounts"></a>
  852. <p>This is a debugging flag. When used in conjunction with
  853. <samp>-fvtable-verify=std</samp> or <samp>-fvtable-verify=preinit</samp>, this
  854. causes the compiler to keep track of the total number of virtual calls
  855. it encounters and the number of verifications it inserts. It also
  856. counts the number of calls to certain run-time library functions
  857. that it inserts and logs this information for each compilation unit.
  858. The compiler writes this information to a file named
  859. <samp>vtv_count_data.log</samp> in the directory named by the environment
  860. variable <code>VTV_LOGS_DIR</code> if that is defined or the current working
  861. directory otherwise. It also counts the size of the vtable pointer sets
  862. for each class, and writes this information to <samp>vtv_class_set_sizes.log</samp>
  863. in the same directory.
  864. </p>
  865. <p>Note: This feature <em>appends</em> data to the log files. To get fresh log
  866. files, be sure to delete any existing ones.
  867. </p>
  868. </dd>
  869. <dt><code>-finstrument-functions</code></dt>
  870. <dd><a name="index-finstrument_002dfunctions"></a>
  871. <p>Generate instrumentation calls for entry and exit to functions. Just
  872. after function entry and just before function exit, the following
  873. profiling functions are called with the address of the current
  874. function and its call site. (On some platforms,
  875. <code>__builtin_return_address</code> does not work beyond the current
  876. function, so the call site information may not be available to the
  877. profiling functions otherwise.)
  878. </p>
  879. <div class="smallexample">
  880. <pre class="smallexample">void __cyg_profile_func_enter (void *this_fn,
  881. void *call_site);
  882. void __cyg_profile_func_exit (void *this_fn,
  883. void *call_site);
  884. </pre></div>
  885. <p>The first argument is the address of the start of the current function,
  886. which may be looked up exactly in the symbol table.
  887. </p>
  888. <p>This instrumentation is also done for functions expanded inline in other
  889. functions. The profiling calls indicate where, conceptually, the
  890. inline function is entered and exited. This means that addressable
  891. versions of such functions must be available. If all your uses of a
  892. function are expanded inline, this may mean an additional expansion of
  893. code size. If you use <code>extern inline</code> in your C code, an
  894. addressable version of such functions must be provided. (This is
  895. normally the case anyway, but if you get lucky and the optimizer always
  896. expands the functions inline, you might have gotten away without
  897. providing static copies.)
  898. </p>
  899. <p>A function may be given the attribute <code>no_instrument_function</code>, in
  900. which case this instrumentation is not done. This can be used, for
  901. example, for the profiling functions listed above, high-priority
  902. interrupt routines, and any functions from which the profiling functions
  903. cannot safely be called (perhaps signal handlers, if the profiling
  904. routines generate output or allocate memory).
  905. </p>
  906. </dd>
  907. <dt><code>-finstrument-functions-exclude-file-list=<var>file</var>,<var>file</var>,&hellip;</code></dt>
  908. <dd><a name="index-finstrument_002dfunctions_002dexclude_002dfile_002dlist"></a>
  909. <p>Set the list of functions that are excluded from instrumentation (see
  910. the description of <samp>-finstrument-functions</samp>). If the file that
  911. contains a function definition matches with one of <var>file</var>, then
  912. that function is not instrumented. The match is done on substrings:
  913. if the <var>file</var> parameter is a substring of the file name, it is
  914. considered to be a match.
  915. </p>
  916. <p>For example:
  917. </p>
  918. <div class="smallexample">
  919. <pre class="smallexample">-finstrument-functions-exclude-file-list=/bits/stl,include/sys
  920. </pre></div>
  921. <p>excludes any inline function defined in files whose pathnames
  922. contain <samp>/bits/stl</samp> or <samp>include/sys</samp>.
  923. </p>
  924. <p>If, for some reason, you want to include letter &lsquo;<samp>,</samp>&rsquo; in one of
  925. <var>sym</var>, write &lsquo;<samp>\,</samp>&rsquo;. For example,
  926. <samp>-finstrument-functions-exclude-file-list='\,\,tmp'</samp>
  927. (note the single quote surrounding the option).
  928. </p>
  929. </dd>
  930. <dt><code>-finstrument-functions-exclude-function-list=<var>sym</var>,<var>sym</var>,&hellip;</code></dt>
  931. <dd><a name="index-finstrument_002dfunctions_002dexclude_002dfunction_002dlist"></a>
  932. <p>This is similar to <samp>-finstrument-functions-exclude-file-list</samp>,
  933. but this option sets the list of function names to be excluded from
  934. instrumentation. The function name to be matched is its user-visible
  935. name, such as <code>vector&lt;int&gt; blah(const vector&lt;int&gt; &amp;)</code>, not the
  936. internal mangled name (e.g., <code>_Z4blahRSt6vectorIiSaIiEE</code>). The
  937. match is done on substrings: if the <var>sym</var> parameter is a substring
  938. of the function name, it is considered to be a match. For C99 and C++
  939. extended identifiers, the function name must be given in UTF-8, not
  940. using universal character names.
  941. </p>
  942. </dd>
  943. </dl>
  944. <hr>
  945. <div class="header">
  946. <p>
  947. Next: <a href="Preprocessor-Options.html#Preprocessor-Options" accesskey="n" rel="next">Preprocessor Options</a>, Previous: <a href="Optimize-Options.html#Optimize-Options" accesskey="p" rel="prev">Optimize Options</a>, Up: <a href="Invoking-GCC.html#Invoking-GCC" accesskey="u" rel="up">Invoking GCC</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html#Option-Index" title="Index" rel="index">Index</a>]</p>
  948. </div>
  949. </body>
  950. </html>