No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

792 líneas
35KB

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