Code-Gen-Options.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  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): Code Gen Options</title>
  20. <meta name="description" content="Using the GNU Compiler Collection (GCC): Code Gen Options">
  21. <meta name="keywords" content="Using the GNU Compiler Collection (GCC): Code Gen 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="Developer-Options.html#Developer-Options" rel="next" title="Developer Options">
  31. <link href="Directory-Options.html#Directory-Options" rel="prev" title="Directory 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="Code-Gen-Options"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Developer-Options.html#Developer-Options" accesskey="n" rel="next">Developer Options</a>, Previous: <a href="Directory-Options.html#Directory-Options" accesskey="p" rel="prev">Directory 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="Options-for-Code-Generation-Conventions"></a>
  69. <h3 class="section">3.16 Options for Code Generation Conventions</h3>
  70. <a name="index-code-generation-conventions"></a>
  71. <a name="index-options_002c-code-generation"></a>
  72. <a name="index-run_002dtime-options"></a>
  73. <p>These machine-independent options control the interface conventions
  74. used in code generation.
  75. </p>
  76. <p>Most of them have both positive and negative forms; the negative form
  77. of <samp>-ffoo</samp> is <samp>-fno-foo</samp>. In the table below, only
  78. one of the forms is listed&mdash;the one that is not the default. You
  79. can figure out the other form by either removing &lsquo;<samp>no-</samp>&rsquo; or adding
  80. it.
  81. </p>
  82. <dl compact="compact">
  83. <dt><code>-fstack-reuse=<var>reuse-level</var></code></dt>
  84. <dd><a name="index-fstack_005freuse"></a>
  85. <p>This option controls stack space reuse for user declared local/auto variables
  86. and compiler generated temporaries. <var>reuse_level</var> can be &lsquo;<samp>all</samp>&rsquo;,
  87. &lsquo;<samp>named_vars</samp>&rsquo;, or &lsquo;<samp>none</samp>&rsquo;. &lsquo;<samp>all</samp>&rsquo; enables stack reuse for all
  88. local variables and temporaries, &lsquo;<samp>named_vars</samp>&rsquo; enables the reuse only for
  89. user defined local variables with names, and &lsquo;<samp>none</samp>&rsquo; disables stack reuse
  90. completely. The default value is &lsquo;<samp>all</samp>&rsquo;. The option is needed when the
  91. program extends the lifetime of a scoped local variable or a compiler generated
  92. temporary beyond the end point defined by the language. When a lifetime of
  93. a variable ends, and if the variable lives in memory, the optimizing compiler
  94. has the freedom to reuse its stack space with other temporaries or scoped
  95. local variables whose live range does not overlap with it. Legacy code extending
  96. local lifetime is likely to break with the stack reuse optimization.
  97. </p>
  98. <p>For example,
  99. </p>
  100. <div class="smallexample">
  101. <pre class="smallexample"> int *p;
  102. {
  103. int local1;
  104. p = &amp;local1;
  105. local1 = 10;
  106. ....
  107. }
  108. {
  109. int local2;
  110. local2 = 20;
  111. ...
  112. }
  113. if (*p == 10) // out of scope use of local1
  114. {
  115. }
  116. </pre></div>
  117. <p>Another example:
  118. </p><div class="smallexample">
  119. <pre class="smallexample">
  120. struct A
  121. {
  122. A(int k) : i(k), j(k) { }
  123. int i;
  124. int j;
  125. };
  126. A *ap;
  127. void foo(const A&amp; ar)
  128. {
  129. ap = &amp;ar;
  130. }
  131. void bar()
  132. {
  133. foo(A(10)); // temp object's lifetime ends when foo returns
  134. {
  135. A a(20);
  136. ....
  137. }
  138. ap-&gt;i+= 10; // ap references out of scope temp whose space
  139. // is reused with a. What is the value of ap-&gt;i?
  140. }
  141. </pre></div>
  142. <p>The lifetime of a compiler generated temporary is well defined by the C++
  143. standard. When a lifetime of a temporary ends, and if the temporary lives
  144. in memory, the optimizing compiler has the freedom to reuse its stack
  145. space with other temporaries or scoped local variables whose live range
  146. does not overlap with it. However some of the legacy code relies on
  147. the behavior of older compilers in which temporaries&rsquo; stack space is
  148. not reused, the aggressive stack reuse can lead to runtime errors. This
  149. option is used to control the temporary stack reuse optimization.
  150. </p>
  151. </dd>
  152. <dt><code>-ftrapv</code></dt>
  153. <dd><a name="index-ftrapv"></a>
  154. <p>This option generates traps for signed overflow on addition, subtraction,
  155. multiplication operations.
  156. The options <samp>-ftrapv</samp> and <samp>-fwrapv</samp> override each other, so using
  157. <samp>-ftrapv</samp> <samp>-fwrapv</samp> on the command-line results in
  158. <samp>-fwrapv</samp> being effective. Note that only active options override, so
  159. using <samp>-ftrapv</samp> <samp>-fwrapv</samp> <samp>-fno-wrapv</samp> on the command-line
  160. results in <samp>-ftrapv</samp> being effective.
  161. </p>
  162. </dd>
  163. <dt><code>-fwrapv</code></dt>
  164. <dd><a name="index-fwrapv"></a>
  165. <p>This option instructs the compiler to assume that signed arithmetic
  166. overflow of addition, subtraction and multiplication wraps around
  167. using twos-complement representation. This flag enables some optimizations
  168. and disables others.
  169. The options <samp>-ftrapv</samp> and <samp>-fwrapv</samp> override each other, so using
  170. <samp>-ftrapv</samp> <samp>-fwrapv</samp> on the command-line results in
  171. <samp>-fwrapv</samp> being effective. Note that only active options override, so
  172. using <samp>-ftrapv</samp> <samp>-fwrapv</samp> <samp>-fno-wrapv</samp> on the command-line
  173. results in <samp>-ftrapv</samp> being effective.
  174. </p>
  175. </dd>
  176. <dt><code>-fexceptions</code></dt>
  177. <dd><a name="index-fexceptions"></a>
  178. <p>Enable exception handling. Generates extra code needed to propagate
  179. exceptions. For some targets, this implies GCC generates frame
  180. unwind information for all functions, which can produce significant data
  181. size overhead, although it does not affect execution. If you do not
  182. specify this option, GCC enables it by default for languages like
  183. C++ that normally require exception handling, and disables it for
  184. languages like C that do not normally require it. However, you may need
  185. to enable this option when compiling C code that needs to interoperate
  186. properly with exception handlers written in C++. You may also wish to
  187. disable this option if you are compiling older C++ programs that don&rsquo;t
  188. use exception handling.
  189. </p>
  190. </dd>
  191. <dt><code>-fnon-call-exceptions</code></dt>
  192. <dd><a name="index-fnon_002dcall_002dexceptions"></a>
  193. <p>Generate code that allows trapping instructions to throw exceptions.
  194. Note that this requires platform-specific runtime support that does
  195. not exist everywhere. Moreover, it only allows <em>trapping</em>
  196. instructions to throw exceptions, i.e. memory references or floating-point
  197. instructions. It does not allow exceptions to be thrown from
  198. arbitrary signal handlers such as <code>SIGALRM</code>.
  199. </p>
  200. </dd>
  201. <dt><code>-fdelete-dead-exceptions</code></dt>
  202. <dd><a name="index-fdelete_002ddead_002dexceptions"></a>
  203. <p>Consider that instructions that may throw exceptions but don&rsquo;t otherwise
  204. contribute to the execution of the program can be optimized away.
  205. This option is enabled by default for the Ada front end, as permitted by
  206. the Ada language specification.
  207. Optimization passes that cause dead exceptions to be removed are enabled independently at different optimization levels.
  208. </p>
  209. </dd>
  210. <dt><code>-funwind-tables</code></dt>
  211. <dd><a name="index-funwind_002dtables"></a>
  212. <p>Similar to <samp>-fexceptions</samp>, except that it just generates any needed
  213. static data, but does not affect the generated code in any other way.
  214. You normally do not need to enable this option; instead, a language processor
  215. that needs this handling enables it on your behalf.
  216. </p>
  217. </dd>
  218. <dt><code>-fasynchronous-unwind-tables</code></dt>
  219. <dd><a name="index-fasynchronous_002dunwind_002dtables"></a>
  220. <p>Generate unwind table in DWARF format, if supported by target machine. The
  221. table is exact at each instruction boundary, so it can be used for stack
  222. unwinding from asynchronous events (such as debugger or garbage collector).
  223. </p>
  224. </dd>
  225. <dt><code>-fno-gnu-unique</code></dt>
  226. <dd><a name="index-fno_002dgnu_002dunique"></a>
  227. <p>On systems with recent GNU assembler and C library, the C++ compiler
  228. uses the <code>STB_GNU_UNIQUE</code> binding to make sure that definitions
  229. of template static data members and static local variables in inline
  230. functions are unique even in the presence of <code>RTLD_LOCAL</code>; this
  231. is necessary to avoid problems with a library used by two different
  232. <code>RTLD_LOCAL</code> plugins depending on a definition in one of them and
  233. therefore disagreeing with the other one about the binding of the
  234. symbol. But this causes <code>dlclose</code> to be ignored for affected
  235. DSOs; if your program relies on reinitialization of a DSO via
  236. <code>dlclose</code> and <code>dlopen</code>, you can use
  237. <samp>-fno-gnu-unique</samp>.
  238. </p>
  239. </dd>
  240. <dt><code>-fpcc-struct-return</code></dt>
  241. <dd><a name="index-fpcc_002dstruct_002dreturn"></a>
  242. <p>Return &ldquo;short&rdquo; <code>struct</code> and <code>union</code> values in memory like
  243. longer ones, rather than in registers. This convention is less
  244. efficient, but it has the advantage of allowing intercallability between
  245. GCC-compiled files and files compiled with other compilers, particularly
  246. the Portable C Compiler (pcc).
  247. </p>
  248. <p>The precise convention for returning structures in memory depends
  249. on the target configuration macros.
  250. </p>
  251. <p>Short structures and unions are those whose size and alignment match
  252. that of some integer type.
  253. </p>
  254. <p><strong>Warning:</strong> code compiled with the <samp>-fpcc-struct-return</samp>
  255. switch is not binary compatible with code compiled with the
  256. <samp>-freg-struct-return</samp> switch.
  257. Use it to conform to a non-default application binary interface.
  258. </p>
  259. </dd>
  260. <dt><code>-freg-struct-return</code></dt>
  261. <dd><a name="index-freg_002dstruct_002dreturn"></a>
  262. <p>Return <code>struct</code> and <code>union</code> values in registers when possible.
  263. This is more efficient for small structures than
  264. <samp>-fpcc-struct-return</samp>.
  265. </p>
  266. <p>If you specify neither <samp>-fpcc-struct-return</samp> nor
  267. <samp>-freg-struct-return</samp>, GCC defaults to whichever convention is
  268. standard for the target. If there is no standard convention, GCC
  269. defaults to <samp>-fpcc-struct-return</samp>, except on targets where GCC is
  270. the principal compiler. In those cases, we can choose the standard, and
  271. we chose the more efficient register return alternative.
  272. </p>
  273. <p><strong>Warning:</strong> code compiled with the <samp>-freg-struct-return</samp>
  274. switch is not binary compatible with code compiled with the
  275. <samp>-fpcc-struct-return</samp> switch.
  276. Use it to conform to a non-default application binary interface.
  277. </p>
  278. </dd>
  279. <dt><code>-fshort-enums</code></dt>
  280. <dd><a name="index-fshort_002denums"></a>
  281. <p>Allocate to an <code>enum</code> type only as many bytes as it needs for the
  282. declared range of possible values. Specifically, the <code>enum</code> type
  283. is equivalent to the smallest integer type that has enough room.
  284. </p>
  285. <p><strong>Warning:</strong> the <samp>-fshort-enums</samp> switch causes GCC to generate
  286. code that is not binary compatible with code generated without that switch.
  287. Use it to conform to a non-default application binary interface.
  288. </p>
  289. </dd>
  290. <dt><code>-fshort-wchar</code></dt>
  291. <dd><a name="index-fshort_002dwchar"></a>
  292. <p>Override the underlying type for <code>wchar_t</code> to be <code>short
  293. unsigned int</code> instead of the default for the target. This option is
  294. useful for building programs to run under WINE.
  295. </p>
  296. <p><strong>Warning:</strong> the <samp>-fshort-wchar</samp> switch causes GCC to generate
  297. code that is not binary compatible with code generated without that switch.
  298. Use it to conform to a non-default application binary interface.
  299. </p>
  300. </dd>
  301. <dt><code>-fno-common</code></dt>
  302. <dd><a name="index-fno_002dcommon"></a>
  303. <a name="index-tentative-definitions"></a>
  304. <p>In C code, this option controls the placement of global variables
  305. defined without an initializer, known as <em>tentative definitions</em>
  306. in the C standard. Tentative definitions are distinct from declarations
  307. of a variable with the <code>extern</code> keyword, which do not allocate storage.
  308. </p>
  309. <p>Unix C compilers have traditionally allocated storage for
  310. uninitialized global variables in a common block. This allows the
  311. linker to resolve all tentative definitions of the same variable
  312. in different compilation units to the same object, or to a non-tentative
  313. definition.
  314. This is the behavior specified by <samp>-fcommon</samp>, and is the default for
  315. GCC on most targets.
  316. On the other hand, this behavior is not required by ISO
  317. C, and on some targets may carry a speed or code size penalty on
  318. variable references.
  319. </p>
  320. <p>The <samp>-fno-common</samp> option specifies that the compiler should instead
  321. place uninitialized global variables in the data section of the object file.
  322. This inhibits the merging of tentative definitions by the linker so
  323. you get a multiple-definition error if the same
  324. variable is defined in more than one compilation unit.
  325. Compiling with <samp>-fno-common</samp> is useful on targets for which
  326. it provides better performance, or if you wish to verify that the
  327. program will work on other systems that always treat uninitialized
  328. variable definitions this way.
  329. </p>
  330. </dd>
  331. <dt><code>-fno-ident</code></dt>
  332. <dd><a name="index-fno_002dident"></a>
  333. <p>Ignore the <code>#ident</code> directive.
  334. </p>
  335. </dd>
  336. <dt><code>-finhibit-size-directive</code></dt>
  337. <dd><a name="index-finhibit_002dsize_002ddirective"></a>
  338. <p>Don&rsquo;t output a <code>.size</code> assembler directive, or anything else that
  339. would cause trouble if the function is split in the middle, and the
  340. two halves are placed at locations far apart in memory. This option is
  341. used when compiling <samp>crtstuff.c</samp>; you should not need to use it
  342. for anything else.
  343. </p>
  344. </dd>
  345. <dt><code>-fverbose-asm</code></dt>
  346. <dd><a name="index-fverbose_002dasm"></a>
  347. <p>Put extra commentary information in the generated assembly code to
  348. make it more readable. This option is generally only of use to those
  349. who actually need to read the generated assembly code (perhaps while
  350. debugging the compiler itself).
  351. </p>
  352. <p><samp>-fno-verbose-asm</samp>, the default, causes the
  353. extra information to be omitted and is useful when comparing two assembler
  354. files.
  355. </p>
  356. <p>The added comments include:
  357. </p>
  358. <ul>
  359. <li> information on the compiler version and command-line options,
  360. </li><li> the source code lines associated with the assembly instructions,
  361. in the form FILENAME:LINENUMBER:CONTENT OF LINE,
  362. </li><li> hints on which high-level expressions correspond to
  363. the various assembly instruction operands.
  364. </li></ul>
  365. <p>For example, given this C source file:
  366. </p>
  367. <div class="smallexample">
  368. <pre class="smallexample">int test (int n)
  369. {
  370. int i;
  371. int total = 0;
  372. for (i = 0; i &lt; n; i++)
  373. total += i * i;
  374. return total;
  375. }
  376. </pre></div>
  377. <p>compiling to (x86_64) assembly via <samp>-S</samp> and emitting the result
  378. direct to stdout via <samp>-o</samp> <samp>-</samp>
  379. </p>
  380. <div class="smallexample">
  381. <pre class="smallexample">gcc -S test.c -fverbose-asm -Os -o -
  382. </pre></div>
  383. <p>gives output similar to this:
  384. </p>
  385. <div class="smallexample">
  386. <pre class="smallexample"> .file &quot;test.c&quot;
  387. # GNU C11 (GCC) version 7.0.0 20160809 (experimental) (x86_64-pc-linux-gnu)
  388. [...snip...]
  389. # options passed:
  390. [...snip...]
  391. .text
  392. .globl test
  393. .type test, @function
  394. test:
  395. .LFB0:
  396. .cfi_startproc
  397. # test.c:4: int total = 0;
  398. xorl %eax, %eax # &lt;retval&gt;
  399. # test.c:6: for (i = 0; i &lt; n; i++)
  400. xorl %edx, %edx # i
  401. .L2:
  402. # test.c:6: for (i = 0; i &lt; n; i++)
  403. cmpl %edi, %edx # n, i
  404. jge .L5 #,
  405. # test.c:7: total += i * i;
  406. movl %edx, %ecx # i, tmp92
  407. imull %edx, %ecx # i, tmp92
  408. # test.c:6: for (i = 0; i &lt; n; i++)
  409. incl %edx # i
  410. # test.c:7: total += i * i;
  411. addl %ecx, %eax # tmp92, &lt;retval&gt;
  412. jmp .L2 #
  413. .L5:
  414. # test.c:10: }
  415. ret
  416. .cfi_endproc
  417. .LFE0:
  418. .size test, .-test
  419. .ident &quot;GCC: (GNU) 7.0.0 20160809 (experimental)&quot;
  420. .section .note.GNU-stack,&quot;&quot;,@progbits
  421. </pre></div>
  422. <p>The comments are intended for humans rather than machines and hence the
  423. precise format of the comments is subject to change.
  424. </p>
  425. </dd>
  426. <dt><code>-frecord-gcc-switches</code></dt>
  427. <dd><a name="index-frecord_002dgcc_002dswitches"></a>
  428. <p>This switch causes the command line used to invoke the
  429. compiler to be recorded into the object file that is being created.
  430. This switch is only implemented on some targets and the exact format
  431. of the recording is target and binary file format dependent, but it
  432. usually takes the form of a section containing ASCII text. This
  433. switch is related to the <samp>-fverbose-asm</samp> switch, but that
  434. switch only records information in the assembler output file as
  435. comments, so it never reaches the object file.
  436. See also <samp>-grecord-gcc-switches</samp> for another
  437. way of storing compiler options into the object file.
  438. </p>
  439. </dd>
  440. <dt><code>-fpic</code></dt>
  441. <dd><a name="index-fpic"></a>
  442. <a name="index-global-offset-table"></a>
  443. <a name="index-PIC"></a>
  444. <p>Generate position-independent code (PIC) suitable for use in a shared
  445. library, if supported for the target machine. Such code accesses all
  446. constant addresses through a global offset table (GOT). The dynamic
  447. loader resolves the GOT entries when the program starts (the dynamic
  448. loader is not part of GCC; it is part of the operating system). If
  449. the GOT size for the linked executable exceeds a machine-specific
  450. maximum size, you get an error message from the linker indicating that
  451. <samp>-fpic</samp> does not work; in that case, recompile with <samp>-fPIC</samp>
  452. instead. (These maximums are 8k on the SPARC, 28k on AArch64 and 32k
  453. on the m68k and RS/6000. The x86 has no such limit.)
  454. </p>
  455. <p>Position-independent code requires special support, and therefore works
  456. only on certain machines. For the x86, GCC supports PIC for System V
  457. but not for the Sun 386i. Code generated for the IBM RS/6000 is always
  458. position-independent.
  459. </p>
  460. <p>When this flag is set, the macros <code>__pic__</code> and <code>__PIC__</code>
  461. are defined to 1.
  462. </p>
  463. </dd>
  464. <dt><code>-fPIC</code></dt>
  465. <dd><a name="index-fPIC"></a>
  466. <p>If supported for the target machine, emit position-independent code,
  467. suitable for dynamic linking and avoiding any limit on the size of the
  468. global offset table. This option makes a difference on AArch64, m68k,
  469. PowerPC and SPARC.
  470. </p>
  471. <p>Position-independent code requires special support, and therefore works
  472. only on certain machines.
  473. </p>
  474. <p>When this flag is set, the macros <code>__pic__</code> and <code>__PIC__</code>
  475. are defined to 2.
  476. </p>
  477. </dd>
  478. <dt><code>-fpie</code></dt>
  479. <dt><code>-fPIE</code></dt>
  480. <dd><a name="index-fpie"></a>
  481. <a name="index-fPIE"></a>
  482. <p>These options are similar to <samp>-fpic</samp> and <samp>-fPIC</samp>, but
  483. generated position independent code can be only linked into executables.
  484. Usually these options are used when <samp>-pie</samp> GCC option is
  485. used during linking.
  486. </p>
  487. <p><samp>-fpie</samp> and <samp>-fPIE</samp> both define the macros
  488. <code>__pie__</code> and <code>__PIE__</code>. The macros have the value 1
  489. for <samp>-fpie</samp> and 2 for <samp>-fPIE</samp>.
  490. </p>
  491. </dd>
  492. <dt><code>-fno-plt</code></dt>
  493. <dd><a name="index-fno_002dplt"></a>
  494. <p>Do not use the PLT for external function calls in position-independent code.
  495. Instead, load the callee address at call sites from the GOT and branch to it.
  496. This leads to more efficient code by eliminating PLT stubs and exposing
  497. GOT loads to optimizations. On architectures such as 32-bit x86 where
  498. PLT stubs expect the GOT pointer in a specific register, this gives more
  499. register allocation freedom to the compiler.
  500. Lazy binding requires use of the PLT;
  501. with <samp>-fno-plt</samp> all external symbols are resolved at load time.
  502. </p>
  503. <p>Alternatively, the function attribute <code>noplt</code> can be used to avoid calls
  504. through the PLT for specific external functions.
  505. </p>
  506. <p>In position-dependent code, a few targets also convert calls to
  507. functions that are marked to not use the PLT to use the GOT instead.
  508. </p>
  509. </dd>
  510. <dt><code>-fno-jump-tables</code></dt>
  511. <dd><a name="index-fno_002djump_002dtables"></a>
  512. <p>Do not use jump tables for switch statements even where it would be
  513. more efficient than other code generation strategies. This option is
  514. of use in conjunction with <samp>-fpic</samp> or <samp>-fPIC</samp> for
  515. building code that forms part of a dynamic linker and cannot
  516. reference the address of a jump table. On some targets, jump tables
  517. do not require a GOT and this option is not needed.
  518. </p>
  519. </dd>
  520. <dt><code>-ffixed-<var>reg</var></code></dt>
  521. <dd><a name="index-ffixed"></a>
  522. <p>Treat the register named <var>reg</var> as a fixed register; generated code
  523. should never refer to it (except perhaps as a stack pointer, frame
  524. pointer or in some other fixed role).
  525. </p>
  526. <p><var>reg</var> must be the name of a register. The register names accepted
  527. are machine-specific and are defined in the <code>REGISTER_NAMES</code>
  528. macro in the machine description macro file.
  529. </p>
  530. <p>This flag does not have a negative form, because it specifies a
  531. three-way choice.
  532. </p>
  533. </dd>
  534. <dt><code>-fcall-used-<var>reg</var></code></dt>
  535. <dd><a name="index-fcall_002dused"></a>
  536. <p>Treat the register named <var>reg</var> as an allocable register that is
  537. clobbered by function calls. It may be allocated for temporaries or
  538. variables that do not live across a call. Functions compiled this way
  539. do not save and restore the register <var>reg</var>.
  540. </p>
  541. <p>It is an error to use this flag with the frame pointer or stack pointer.
  542. Use of this flag for other registers that have fixed pervasive roles in
  543. the machine&rsquo;s execution model produces disastrous results.
  544. </p>
  545. <p>This flag does not have a negative form, because it specifies a
  546. three-way choice.
  547. </p>
  548. </dd>
  549. <dt><code>-fcall-saved-<var>reg</var></code></dt>
  550. <dd><a name="index-fcall_002dsaved"></a>
  551. <p>Treat the register named <var>reg</var> as an allocable register saved by
  552. functions. It may be allocated even for temporaries or variables that
  553. live across a call. Functions compiled this way save and restore
  554. the register <var>reg</var> if they use it.
  555. </p>
  556. <p>It is an error to use this flag with the frame pointer or stack pointer.
  557. Use of this flag for other registers that have fixed pervasive roles in
  558. the machine&rsquo;s execution model produces disastrous results.
  559. </p>
  560. <p>A different sort of disaster results from the use of this flag for
  561. a register in which function values may be returned.
  562. </p>
  563. <p>This flag does not have a negative form, because it specifies a
  564. three-way choice.
  565. </p>
  566. </dd>
  567. <dt><code>-fpack-struct[=<var>n</var>]</code></dt>
  568. <dd><a name="index-fpack_002dstruct"></a>
  569. <p>Without a value specified, pack all structure members together without
  570. holes. When a value is specified (which must be a small power of two), pack
  571. structure members according to this value, representing the maximum
  572. alignment (that is, objects with default alignment requirements larger than
  573. this are output potentially unaligned at the next fitting location.
  574. </p>
  575. <p><strong>Warning:</strong> the <samp>-fpack-struct</samp> switch causes GCC to generate
  576. code that is not binary compatible with code generated without that switch.
  577. Additionally, it makes the code suboptimal.
  578. Use it to conform to a non-default application binary interface.
  579. </p>
  580. </dd>
  581. <dt><code>-fleading-underscore</code></dt>
  582. <dd><a name="index-fleading_002dunderscore"></a>
  583. <p>This option and its counterpart, <samp>-fno-leading-underscore</samp>, forcibly
  584. change the way C symbols are represented in the object file. One use
  585. is to help link with legacy assembly code.
  586. </p>
  587. <p><strong>Warning:</strong> the <samp>-fleading-underscore</samp> switch causes GCC to
  588. generate code that is not binary compatible with code generated without that
  589. switch. Use it to conform to a non-default application binary interface.
  590. Not all targets provide complete support for this switch.
  591. </p>
  592. </dd>
  593. <dt><code>-ftls-model=<var>model</var></code></dt>
  594. <dd><a name="index-ftls_002dmodel"></a>
  595. <p>Alter the thread-local storage model to be used (see <a href="Thread_002dLocal.html#Thread_002dLocal">Thread-Local</a>).
  596. The <var>model</var> argument should be one of &lsquo;<samp>global-dynamic</samp>&rsquo;,
  597. &lsquo;<samp>local-dynamic</samp>&rsquo;, &lsquo;<samp>initial-exec</samp>&rsquo; or &lsquo;<samp>local-exec</samp>&rsquo;.
  598. Note that the choice is subject to optimization: the compiler may use
  599. a more efficient model for symbols not visible outside of the translation
  600. unit, or if <samp>-fpic</samp> is not given on the command line.
  601. </p>
  602. <p>The default without <samp>-fpic</samp> is &lsquo;<samp>initial-exec</samp>&rsquo;; with
  603. <samp>-fpic</samp> the default is &lsquo;<samp>global-dynamic</samp>&rsquo;.
  604. </p>
  605. </dd>
  606. <dt><code>-ftrampolines</code></dt>
  607. <dd><a name="index-ftrampolines"></a>
  608. <p>For targets that normally need trampolines for nested functions, always
  609. generate them instead of using descriptors. Otherwise, for targets that
  610. do not need them, like for example HP-PA or IA-64, do nothing.
  611. </p>
  612. <p>A trampoline is a small piece of code that is created at run time on the
  613. stack when the address of a nested function is taken, and is used to call
  614. the nested function indirectly. Therefore, it requires the stack to be
  615. made executable in order for the program to work properly.
  616. </p>
  617. <p><samp>-fno-trampolines</samp> is enabled by default on a language by language
  618. basis to let the compiler avoid generating them, if it computes that this
  619. is safe, and replace them with descriptors. Descriptors are made up of data
  620. only, but the generated code must be prepared to deal with them. As of this
  621. writing, <samp>-fno-trampolines</samp> is enabled by default only for Ada.
  622. </p>
  623. <p>Moreover, code compiled with <samp>-ftrampolines</samp> and code compiled with
  624. <samp>-fno-trampolines</samp> are not binary compatible if nested functions are
  625. present. This option must therefore be used on a program-wide basis and be
  626. manipulated with extreme care.
  627. </p>
  628. </dd>
  629. <dt><code>-fvisibility=<span class="roman">[</span>default<span class="roman">|</span>internal<span class="roman">|</span>hidden<span class="roman">|</span>protected<span class="roman">]</span></code></dt>
  630. <dd><a name="index-fvisibility"></a>
  631. <p>Set the default ELF image symbol visibility to the specified option&mdash;all
  632. symbols are marked with this unless overridden within the code.
  633. Using this feature can very substantially improve linking and
  634. load times of shared object libraries, produce more optimized
  635. code, provide near-perfect API export and prevent symbol clashes.
  636. It is <strong>strongly</strong> recommended that you use this in any shared objects
  637. you distribute.
  638. </p>
  639. <p>Despite the nomenclature, &lsquo;<samp>default</samp>&rsquo; always means public; i.e.,
  640. available to be linked against from outside the shared object.
  641. &lsquo;<samp>protected</samp>&rsquo; and &lsquo;<samp>internal</samp>&rsquo; are pretty useless in real-world
  642. usage so the only other commonly used option is &lsquo;<samp>hidden</samp>&rsquo;.
  643. The default if <samp>-fvisibility</samp> isn&rsquo;t specified is
  644. &lsquo;<samp>default</samp>&rsquo;, i.e., make every symbol public.
  645. </p>
  646. <p>A good explanation of the benefits offered by ensuring ELF
  647. symbols have the correct visibility is given by &ldquo;How To Write
  648. Shared Libraries&rdquo; by Ulrich Drepper (which can be found at
  649. <a href="https://www.akkadia.org/drepper/">https://www.akkadia.org/drepper/</a><!-- /@w -->)&mdash;however a superior
  650. solution made possible by this option to marking things hidden when
  651. the default is public is to make the default hidden and mark things
  652. public. This is the norm with DLLs on Windows and with <samp>-fvisibility=hidden</samp>
  653. and <code>__attribute__ ((visibility(&quot;default&quot;)))</code> instead of
  654. <code>__declspec(dllexport)</code> you get almost identical semantics with
  655. identical syntax. This is a great boon to those working with
  656. cross-platform projects.
  657. </p>
  658. <p>For those adding visibility support to existing code, you may find
  659. <code>#pragma GCC visibility</code> of use. This works by you enclosing
  660. the declarations you wish to set visibility for with (for example)
  661. <code>#pragma GCC visibility push(hidden)</code> and
  662. <code>#pragma GCC visibility pop</code>.
  663. Bear in mind that symbol visibility should be viewed <strong>as
  664. part of the API interface contract</strong> and thus all new code should
  665. always specify visibility when it is not the default; i.e., declarations
  666. only for use within the local DSO should <strong>always</strong> be marked explicitly
  667. as hidden as so to avoid PLT indirection overheads&mdash;making this
  668. abundantly clear also aids readability and self-documentation of the code.
  669. Note that due to ISO C++ specification requirements, <code>operator new</code> and
  670. <code>operator delete</code> must always be of default visibility.
  671. </p>
  672. <p>Be aware that headers from outside your project, in particular system
  673. headers and headers from any other library you use, may not be
  674. expecting to be compiled with visibility other than the default. You
  675. may need to explicitly say <code>#pragma GCC visibility push(default)</code>
  676. before including any such headers.
  677. </p>
  678. <p><code>extern</code> declarations are not affected by <samp>-fvisibility</samp>, so
  679. a lot of code can be recompiled with <samp>-fvisibility=hidden</samp> with
  680. no modifications. However, this means that calls to <code>extern</code>
  681. functions with no explicit visibility use the PLT, so it is more
  682. effective to use <code>__attribute ((visibility))</code> and/or
  683. <code>#pragma GCC visibility</code> to tell the compiler which <code>extern</code>
  684. declarations should be treated as hidden.
  685. </p>
  686. <p>Note that <samp>-fvisibility</samp> does affect C++ vague linkage
  687. entities. This means that, for instance, an exception class that is
  688. be thrown between DSOs must be explicitly marked with default
  689. visibility so that the &lsquo;<samp>type_info</samp>&rsquo; nodes are unified between
  690. the DSOs.
  691. </p>
  692. <p>An overview of these techniques, their benefits and how to use them
  693. is at <a href="http://gcc.gnu.org/wiki/Visibility">http://gcc.gnu.org/wiki/Visibility</a>.
  694. </p>
  695. </dd>
  696. <dt><code>-fstrict-volatile-bitfields</code></dt>
  697. <dd><a name="index-fstrict_002dvolatile_002dbitfields"></a>
  698. <p>This option should be used if accesses to volatile bit-fields (or other
  699. structure fields, although the compiler usually honors those types
  700. anyway) should use a single access of the width of the
  701. field&rsquo;s type, aligned to a natural alignment if possible. For
  702. example, targets with memory-mapped peripheral registers might require
  703. all such accesses to be 16 bits wide; with this flag you can
  704. declare all peripheral bit-fields as <code>unsigned short</code> (assuming short
  705. is 16 bits on these targets) to force GCC to use 16-bit accesses
  706. instead of, perhaps, a more efficient 32-bit access.
  707. </p>
  708. <p>If this option is disabled, the compiler uses the most efficient
  709. instruction. In the previous example, that might be a 32-bit load
  710. instruction, even though that accesses bytes that do not contain
  711. any portion of the bit-field, or memory-mapped registers unrelated to
  712. the one being updated.
  713. </p>
  714. <p>In some cases, such as when the <code>packed</code> attribute is applied to a
  715. structure field, it may not be possible to access the field with a single
  716. read or write that is correctly aligned for the target machine. In this
  717. case GCC falls back to generating multiple accesses rather than code that
  718. will fault or truncate the result at run time.
  719. </p>
  720. <p>Note: Due to restrictions of the C/C++11 memory model, write accesses are
  721. not allowed to touch non bit-field members. It is therefore recommended
  722. to define all bits of the field&rsquo;s type as bit-field members.
  723. </p>
  724. <p>The default value of this option is determined by the application binary
  725. interface for the target processor.
  726. </p>
  727. </dd>
  728. <dt><code>-fsync-libcalls</code></dt>
  729. <dd><a name="index-fsync_002dlibcalls"></a>
  730. <p>This option controls whether any out-of-line instance of the <code>__sync</code>
  731. family of functions may be used to implement the C++11 <code>__atomic</code>
  732. family of functions.
  733. </p>
  734. <p>The default value of this option is enabled, thus the only useful form
  735. of the option is <samp>-fno-sync-libcalls</samp>. This option is used in
  736. the implementation of the <samp>libatomic</samp> runtime library.
  737. </p>
  738. </dd>
  739. </dl>
  740. <hr>
  741. <div class="header">
  742. <p>
  743. Next: <a href="Developer-Options.html#Developer-Options" accesskey="n" rel="next">Developer Options</a>, Previous: <a href="Directory-Options.html#Directory-Options" accesskey="p" rel="prev">Directory 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>
  744. </div>
  745. </body>
  746. </html>