options.texi 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. @c Copyright (C) 2003-2015 Free Software Foundation, Inc.
  2. @c This is part of the GCC manual.
  3. @c For copying conditions, see the file gcc.texi.
  4. @node Options
  5. @chapter Option specification files
  6. @cindex option specification files
  7. @cindex @samp{optc-gen.awk}
  8. Most GCC command-line options are described by special option
  9. definition files, the names of which conventionally end in
  10. @code{.opt}. This chapter describes the format of these files.
  11. @menu
  12. * Option file format:: The general layout of the files
  13. * Option properties:: Supported option properties
  14. @end menu
  15. @node Option file format
  16. @section Option file format
  17. Option files are a simple list of records in which each field occupies
  18. its own line and in which the records themselves are separated by
  19. blank lines. Comments may appear on their own line anywhere within
  20. the file and are preceded by semicolons. Whitespace is allowed before
  21. the semicolon.
  22. The files can contain the following types of record:
  23. @itemize @bullet
  24. @item
  25. A language definition record. These records have two fields: the
  26. string @samp{Language} and the name of the language. Once a language
  27. has been declared in this way, it can be used as an option property.
  28. @xref{Option properties}.
  29. @item
  30. A target specific save record to save additional information. These
  31. records have two fields: the string @samp{TargetSave}, and a
  32. declaration type to go in the @code{cl_target_option} structure.
  33. @item
  34. A variable record to define a variable used to store option
  35. information. These records have two fields: the string
  36. @samp{Variable}, and a declaration of the type and name of the
  37. variable, optionally with an initializer (but without any trailing
  38. @samp{;}). These records may be used for variables used for many
  39. options where declaring the initializer in a single option definition
  40. record, or duplicating it in many records, would be inappropriate, or
  41. for variables set in option handlers rather than referenced by
  42. @code{Var} properties.
  43. @item
  44. A variable record to define a variable used to store option
  45. information. These records have two fields: the string
  46. @samp{TargetVariable}, and a declaration of the type and name of the
  47. variable, optionally with an initializer (but without any trailing
  48. @samp{;}). @samp{TargetVariable} is a combination of @samp{Variable}
  49. and @samp{TargetSave} records in that the variable is defined in the
  50. @code{gcc_options} structure, but these variables are also stored in
  51. the @code{cl_target_option} structure. The variables are saved in the
  52. target save code and restored in the target restore code.
  53. @item
  54. A variable record to record any additional files that the
  55. @file{options.h} file should include. This is useful to provide
  56. enumeration or structure definitions needed for target variables.
  57. These records have two fields: the string @samp{HeaderInclude} and the
  58. name of the include file.
  59. @item
  60. A variable record to record any additional files that the
  61. @file{options.c} or @file{options-save.c} file should include. This
  62. is useful to provide
  63. inline functions needed for target variables and/or @code{#ifdef}
  64. sequences to properly set up the initialization. These records have
  65. two fields: the string @samp{SourceInclude} and the name of the
  66. include file.
  67. @item
  68. An enumeration record to define a set of strings that may be used as
  69. arguments to an option or options. These records have three fields:
  70. the string @samp{Enum}, a space-separated list of properties and help
  71. text used to describe the set of strings in @option{--help} output.
  72. Properties use the same format as option properties; the following are
  73. valid:
  74. @table @code
  75. @item Name(@var{name})
  76. This property is required; @var{name} must be a name (suitable for use
  77. in C identifiers) used to identify the set of strings in @code{Enum}
  78. option properties.
  79. @item Type(@var{type})
  80. This property is required; @var{type} is the C type for variables set
  81. by options using this enumeration together with @code{Var}.
  82. @item UnknownError(@var{message})
  83. The message @var{message} will be used as an error message if the
  84. argument is invalid; for enumerations without @code{UnknownError}, a
  85. generic error message is used. @var{message} should contain a single
  86. @samp{%qs} format, which will be used to format the invalid argument.
  87. @end table
  88. @item
  89. An enumeration value record to define one of the strings in a set
  90. given in an @samp{Enum} record. These records have two fields: the
  91. string @samp{EnumValue} and a space-separated list of properties.
  92. Properties use the same format as option properties; the following are
  93. valid:
  94. @table @code
  95. @item Enum(@var{name})
  96. This property is required; @var{name} says which @samp{Enum} record
  97. this @samp{EnumValue} record corresponds to.
  98. @item String(@var{string})
  99. This property is required; @var{string} is the string option argument
  100. being described by this record.
  101. @item Value(@var{value})
  102. This property is required; it says what value (representable as
  103. @code{int}) should be used for the given string.
  104. @item Canonical
  105. This property is optional. If present, it says the present string is
  106. the canonical one among all those with the given value. Other strings
  107. yielding that value will be mapped to this one so specs do not need to
  108. handle them.
  109. @item DriverOnly
  110. This property is optional. If present, the present string will only
  111. be accepted by the driver. This is used for cases such as
  112. @option{-march=native} that are processed by the driver so that
  113. @samp{gcc -v} shows how the options chosen depended on the system on
  114. which the compiler was run.
  115. @end table
  116. @item
  117. An option definition record. These records have the following fields:
  118. @enumerate
  119. @item
  120. the name of the option, with the leading ``-'' removed
  121. @item
  122. a space-separated list of option properties (@pxref{Option properties})
  123. @item
  124. the help text to use for @option{--help} (omitted if the second field
  125. contains the @code{Undocumented} property).
  126. @end enumerate
  127. By default, all options beginning with ``f'', ``W'' or ``m'' are
  128. implicitly assumed to take a ``no-'' form. This form should not be
  129. listed separately. If an option beginning with one of these letters
  130. does not have a ``no-'' form, you can use the @code{RejectNegative}
  131. property to reject it.
  132. The help text is automatically line-wrapped before being displayed.
  133. Normally the name of the option is printed on the left-hand side of
  134. the output and the help text is printed on the right. However, if the
  135. help text contains a tab character, the text to the left of the tab is
  136. used instead of the option's name and the text to the right of the
  137. tab forms the help text. This allows you to elaborate on what type
  138. of argument the option takes.
  139. @item
  140. A target mask record. These records have one field of the form
  141. @samp{Mask(@var{x})}. The options-processing script will automatically
  142. allocate a bit in @code{target_flags} (@pxref{Run-time Target}) for
  143. each mask name @var{x} and set the macro @code{MASK_@var{x}} to the
  144. appropriate bitmask. It will also declare a @code{TARGET_@var{x}}
  145. macro that has the value 1 when bit @code{MASK_@var{x}} is set and
  146. 0 otherwise.
  147. They are primarily intended to declare target masks that are not
  148. associated with user options, either because these masks represent
  149. internal switches or because the options are not available on all
  150. configurations and yet the masks always need to be defined.
  151. @end itemize
  152. @node Option properties
  153. @section Option properties
  154. The second field of an option record can specify any of the following
  155. properties. When an option takes an argument, it is enclosed in parentheses
  156. following the option property name. The parser that handles option files
  157. is quite simplistic, and will be tricked by any nested parentheses within
  158. the argument text itself; in this case, the entire option argument can
  159. be wrapped in curly braces within the parentheses to demarcate it, e.g.:
  160. @smallexample
  161. Condition(@{defined (USE_CYGWIN_LIBSTDCXX_WRAPPERS)@})
  162. @end smallexample
  163. @table @code
  164. @item Common
  165. The option is available for all languages and targets.
  166. @item Target
  167. The option is available for all languages but is target-specific.
  168. @item Driver
  169. The option is handled by the compiler driver using code not shared
  170. with the compilers proper (@file{cc1} etc.).
  171. @item @var{language}
  172. The option is available when compiling for the given language.
  173. It is possible to specify several different languages for the same
  174. option. Each @var{language} must have been declared by an earlier
  175. @code{Language} record. @xref{Option file format}.
  176. @item RejectDriver
  177. The option is only handled by the compilers proper (@file{cc1} etc.)@:
  178. and should not be accepted by the driver.
  179. @item RejectNegative
  180. The option does not have a ``no-'' form. All options beginning with
  181. ``f'', ``W'' or ``m'' are assumed to have a ``no-'' form unless this
  182. property is used.
  183. @item Negative(@var{othername})
  184. The option will turn off another option @var{othername}, which is
  185. the option name with the leading ``-'' removed. This chain action will
  186. propagate through the @code{Negative} property of the option to be
  187. turned off.
  188. As a consequence, if you have a group of mutually-exclusive
  189. options, their @code{Negative} properties should form a circular chain.
  190. For example, if options @option{-@var{a}}, @option{-@var{b}} and
  191. @option{-@var{c}} are mutually exclusive, their respective @code{Negative}
  192. properties should be @samp{Negative(@var{b})}, @samp{Negative(@var{c})}
  193. and @samp{Negative(@var{a})}.
  194. @item Joined
  195. @itemx Separate
  196. The option takes a mandatory argument. @code{Joined} indicates
  197. that the option and argument can be included in the same @code{argv}
  198. entry (as with @code{-mflush-func=@var{name}}, for example).
  199. @code{Separate} indicates that the option and argument can be
  200. separate @code{argv} entries (as with @code{-o}). An option is
  201. allowed to have both of these properties.
  202. @item JoinedOrMissing
  203. The option takes an optional argument. If the argument is given,
  204. it will be part of the same @code{argv} entry as the option itself.
  205. This property cannot be used alongside @code{Joined} or @code{Separate}.
  206. @item MissingArgError(@var{message})
  207. For an option marked @code{Joined} or @code{Separate}, the message
  208. @var{message} will be used as an error message if the mandatory
  209. argument is missing; for options without @code{MissingArgError}, a
  210. generic error message is used. @var{message} should contain a single
  211. @samp{%qs} format, which will be used to format the name of the option
  212. passed.
  213. @item Args(@var{n})
  214. For an option marked @code{Separate}, indicate that it takes @var{n}
  215. arguments. The default is 1.
  216. @item UInteger
  217. The option's argument is a non-negative integer. The option parser
  218. will check and convert the argument before passing it to the relevant
  219. option handler. @code{UInteger} should also be used on options like
  220. @code{-falign-loops} where both @code{-falign-loops} and
  221. @code{-falign-loops}=@var{n} are supported to make sure the saved
  222. options are given a full integer.
  223. @item ToLower
  224. The option's argument should be converted to lowercase as part of
  225. putting it in canonical form, and before comparing with the strings
  226. indicated by any @code{Enum} property.
  227. @item NoDriverArg
  228. For an option marked @code{Separate}, the option only takes an
  229. argument in the compiler proper, not in the driver. This is for
  230. compatibility with existing options that are used both directly and
  231. via @option{-Wp,}; new options should not have this property.
  232. @item Var(@var{var})
  233. The state of this option should be stored in variable @var{var}
  234. (actually a macro for @code{global_options.x_@var{var}}).
  235. The way that the state is stored depends on the type of option:
  236. @itemize @bullet
  237. @item
  238. If the option uses the @code{Mask} or @code{InverseMask} properties,
  239. @var{var} is the integer variable that contains the mask.
  240. @item
  241. If the option is a normal on/off switch, @var{var} is an integer
  242. variable that is nonzero when the option is enabled. The options
  243. parser will set the variable to 1 when the positive form of the
  244. option is used and 0 when the ``no-'' form is used.
  245. @item
  246. If the option takes an argument and has the @code{UInteger} property,
  247. @var{var} is an integer variable that stores the value of the argument.
  248. @item
  249. If the option takes an argument and has the @code{Enum} property,
  250. @var{var} is a variable (type given in the @code{Type} property of the
  251. @samp{Enum} record whose @code{Name} property has the same argument as
  252. the @code{Enum} property of this option) that stores the value of the
  253. argument.
  254. @item
  255. If the option has the @code{Defer} property, @var{var} is a pointer to
  256. a @code{VEC(cl_deferred_option,heap)} that stores the option for later
  257. processing. (@var{var} is declared with type @code{void *} and needs
  258. to be cast to @code{VEC(cl_deferred_option,heap)} before use.)
  259. @item
  260. Otherwise, if the option takes an argument, @var{var} is a pointer to
  261. the argument string. The pointer will be null if the argument is optional
  262. and wasn't given.
  263. @end itemize
  264. The option-processing script will usually zero-initialize @var{var}.
  265. You can modify this behavior using @code{Init}.
  266. @item Var(@var{var}, @var{set})
  267. The option controls an integer variable @var{var} and is active when
  268. @var{var} equals @var{set}. The option parser will set @var{var} to
  269. @var{set} when the positive form of the option is used and @code{!@var{set}}
  270. when the ``no-'' form is used.
  271. @var{var} is declared in the same way as for the single-argument form
  272. described above.
  273. @item Init(@var{value})
  274. The variable specified by the @code{Var} property should be statically
  275. initialized to @var{value}. If more than one option using the same
  276. variable specifies @code{Init}, all must specify the same initializer.
  277. @item Mask(@var{name})
  278. The option is associated with a bit in the @code{target_flags}
  279. variable (@pxref{Run-time Target}) and is active when that bit is set.
  280. You may also specify @code{Var} to select a variable other than
  281. @code{target_flags}.
  282. The options-processing script will automatically allocate a unique bit
  283. for the option. If the option is attached to @samp{target_flags},
  284. the script will set the macro @code{MASK_@var{name}} to the appropriate
  285. bitmask. It will also declare a @code{TARGET_@var{name}} macro that has
  286. the value 1 when the option is active and 0 otherwise. If you use @code{Var}
  287. to attach the option to a different variable, the bitmask macro with be
  288. called @code{OPTION_MASK_@var{name}}.
  289. @item InverseMask(@var{othername})
  290. @itemx InverseMask(@var{othername}, @var{thisname})
  291. The option is the inverse of another option that has the
  292. @code{Mask(@var{othername})} property. If @var{thisname} is given,
  293. the options-processing script will declare a @code{TARGET_@var{thisname}}
  294. macro that is 1 when the option is active and 0 otherwise.
  295. @item Enum(@var{name})
  296. The option's argument is a string from the set of strings associated
  297. with the corresponding @samp{Enum} record. The string is checked and
  298. converted to the integer specified in the corresponding
  299. @samp{EnumValue} record before being passed to option handlers.
  300. @item Defer
  301. The option should be stored in a vector, specified with @code{Var},
  302. for later processing.
  303. @item Alias(@var{opt})
  304. @itemx Alias(@var{opt}, @var{arg})
  305. @itemx Alias(@var{opt}, @var{posarg}, @var{negarg})
  306. The option is an alias for @option{-@var{opt}} (or the negative form
  307. of that option, depending on @code{NegativeAlias}). In the first form,
  308. any argument passed to the alias is considered to be passed to
  309. @option{-@var{opt}}, and @option{-@var{opt}} is considered to be
  310. negated if the alias is used in negated form. In the second form, the
  311. alias may not be negated or have an argument, and @var{posarg} is
  312. considered to be passed as an argument to @option{-@var{opt}}. In the
  313. third form, the alias may not have an argument, if the alias is used
  314. in the positive form then @var{posarg} is considered to be passed to
  315. @option{-@var{opt}}, and if the alias is used in the negative form
  316. then @var{negarg} is considered to be passed to @option{-@var{opt}}.
  317. Aliases should not specify @code{Var} or @code{Mask} or
  318. @code{UInteger}. Aliases should normally specify the same languages
  319. as the target of the alias; the flags on the target will be used to
  320. determine any diagnostic for use of an option for the wrong language,
  321. while those on the alias will be used to identify what command-line
  322. text is the option and what text is any argument to that option.
  323. When an @code{Alias} definition is used for an option, driver specs do
  324. not need to handle it and no @samp{OPT_} enumeration value is defined
  325. for it; only the canonical form of the option will be seen in those
  326. places.
  327. @item NegativeAlias
  328. For an option marked with @code{Alias(@var{opt})}, the option is
  329. considered to be an alias for the positive form of @option{-@var{opt}}
  330. if negated and for the negative form of @option{-@var{opt}} if not
  331. negated. @code{NegativeAlias} may not be used with the forms of
  332. @code{Alias} taking more than one argument.
  333. @item Ignore
  334. This option is ignored apart from printing any warning specified using
  335. @code{Warn}. The option will not be seen by specs and no @samp{OPT_}
  336. enumeration value is defined for it.
  337. @item SeparateAlias
  338. For an option marked with @code{Joined}, @code{Separate} and
  339. @code{Alias}, the option only acts as an alias when passed a separate
  340. argument; with a joined argument it acts as a normal option, with an
  341. @samp{OPT_} enumeration value. This is for compatibility with the
  342. Java @option{-d} option and should not be used for new options.
  343. @item Warn(@var{message})
  344. If this option is used, output the warning @var{message}.
  345. @var{message} is a format string, either taking a single operand with
  346. a @samp{%qs} format which is the option name, or not taking any
  347. operands, which is passed to the @samp{warning} function. If an alias
  348. is marked @code{Warn}, the target of the alias must not also be marked
  349. @code{Warn}.
  350. @item Report
  351. The state of the option should be printed by @option{-fverbose-asm}.
  352. @item Warning
  353. This is a warning option and should be shown as such in
  354. @option{--help} output. This flag does not currently affect anything
  355. other than @option{--help}.
  356. @item Optimization
  357. This is an optimization option. It should be shown as such in
  358. @option{--help} output, and any associated variable named using
  359. @code{Var} should be saved and restored when the optimization level is
  360. changed with @code{optimize} attributes.
  361. @item Undocumented
  362. The option is deliberately missing documentation and should not
  363. be included in the @option{--help} output.
  364. @item Condition(@var{cond})
  365. The option should only be accepted if preprocessor condition
  366. @var{cond} is true. Note that any C declarations associated with the
  367. option will be present even if @var{cond} is false; @var{cond} simply
  368. controls whether the option is accepted and whether it is printed in
  369. the @option{--help} output.
  370. @item Save
  371. Build the @code{cl_target_option} structure to hold a copy of the
  372. option, add the functions @code{cl_target_option_save} and
  373. @code{cl_target_option_restore} to save and restore the options.
  374. @item SetByCombined
  375. The option may also be set by a combined option such as
  376. @option{-ffast-math}. This causes the @code{gcc_options} struct to
  377. have a field @code{frontend_set_@var{name}}, where @code{@var{name}}
  378. is the name of the field holding the value of this option (without the
  379. leading @code{x_}). This gives the front end a way to indicate that
  380. the value has been set explicitly and should not be changed by the
  381. combined option. For example, some front ends use this to prevent
  382. @option{-ffast-math} and @option{-fno-fast-math} from changing the
  383. value of @option{-fmath-errno} for languages that do not use
  384. @code{errno}.
  385. @item EnabledBy(@var{opt})
  386. @itemx EnabledBy(@var{opt} || @var{opt2})
  387. @itemx EnabledBy(@var{opt} && @var{opt2})
  388. If not explicitly set, the option is set to the value of
  389. @option{-@var{opt}}; multiple options can be given, separated by
  390. @code{||}. The third form using @code{&&} specifies that the option is
  391. only set if both @var{opt} and @var{opt2} are set.
  392. @item LangEnabledBy(@var{language}, @var{opt})
  393. @itemx LangEnabledBy(@var{language}, @var{opt}, @var{posarg}, @var{negarg})
  394. When compiling for the given language, the option is set to the value
  395. of @option{-@var{opt}}, if not explicitly set. @var{opt} can be also a list
  396. of @code{||} separated options. In the second form, if
  397. @var{opt} is used in the positive form then @var{posarg} is considered
  398. to be passed to the option, and if @var{opt} is used in the negative
  399. form then @var{negarg} is considered to be passed to the option. It
  400. is possible to specify several different languages. Each
  401. @var{language} must have been declared by an earlier @code{Language}
  402. record. @xref{Option file format}.
  403. @item NoDWARFRecord
  404. The option is omitted from the producer string written by
  405. @option{-grecord-gcc-switches}.
  406. @item PchIgnore
  407. Even if this is a target option, this option will not be recorded / compared
  408. to determine if a precompiled header file matches.
  409. @item CPP(@var{var})
  410. The state of this option should be kept in sync with the preprocessor
  411. option @var{var}. If this property is set, then properties @code{Var}
  412. and @code{Init} must be set as well.
  413. @item CppReason(@var{CPP_W_Enum})
  414. This warning option corresponds to @code{cpplib.h} warning reason code
  415. @var{CPP_W_Enum}. This should only be used for warning options of the
  416. C-family front-ends.
  417. @end table