You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
16KB

  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>Target Attributes (GNU Compiler Collection (GCC) Internals)</title>
  21. <meta name="description" content="Target Attributes (GNU Compiler Collection (GCC) Internals)">
  22. <meta name="keywords" content="Target Attributes (GNU Compiler Collection (GCC) Internals)">
  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="Target-Macros.html#Target-Macros" rel="up" title="Target Macros">
  30. <link href="Emulated-TLS.html#Emulated-TLS" rel="next" title="Emulated TLS">
  31. <link href="Mode-Switching.html#Mode-Switching" rel="prev" title="Mode Switching">
  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="Target-Attributes"></a>
  62. <div class="header">
  63. <p>
  64. Next: <a href="Emulated-TLS.html#Emulated-TLS" accesskey="n" rel="next">Emulated TLS</a>, Previous: <a href="Mode-Switching.html#Mode-Switching" accesskey="p" rel="prev">Mode Switching</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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="Defining-target_002dspecific-uses-of-_005f_005fattribute_005f_005f"></a>
  68. <h3 class="section">18.24 Defining target-specific uses of <code>__attribute__</code></h3>
  69. <a name="index-target-attributes"></a>
  70. <a name="index-machine-attributes"></a>
  71. <a name="index-attributes_002c-target_002dspecific"></a>
  72. <p>Target-specific attributes may be defined for functions, data and types.
  73. These are described using the following target hooks; they also need to
  74. be documented in <samp>extend.texi</samp>.
  75. </p>
  76. <dl>
  77. <dt><a name="index-TARGET_005fATTRIBUTE_005fTABLE"></a>Target Hook: <em>const struct attribute_spec *</em> <strong>TARGET_ATTRIBUTE_TABLE</strong></dt>
  78. <dd><p>If defined, this target hook points to an array of &lsquo;<samp>struct
  79. attribute_spec</samp>&rsquo; (defined in <samp>tree-core.h</samp>) specifying the machine
  80. specific attributes for this target and some of the restrictions on the
  81. entities to which these attributes are applied and the arguments they
  82. take.
  83. </p></dd></dl>
  84. <dl>
  85. <dt><a name="index-TARGET_005fATTRIBUTE_005fTAKES_005fIDENTIFIER_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_ATTRIBUTE_TAKES_IDENTIFIER_P</strong> <em>(const_tree <var>name</var>)</em></dt>
  86. <dd><p>If defined, this target hook is a function which returns true if the
  87. machine-specific attribute named <var>name</var> expects an identifier
  88. given as its first argument to be passed on as a plain identifier, not
  89. subjected to name lookup. If this is not defined, the default is
  90. false for all machine-specific attributes.
  91. </p></dd></dl>
  92. <dl>
  93. <dt><a name="index-TARGET_005fCOMP_005fTYPE_005fATTRIBUTES"></a>Target Hook: <em>int</em> <strong>TARGET_COMP_TYPE_ATTRIBUTES</strong> <em>(const_tree <var>type1</var>, const_tree <var>type2</var>)</em></dt>
  94. <dd><p>If defined, this target hook is a function which returns zero if the attributes on
  95. <var>type1</var> and <var>type2</var> are incompatible, one if they are compatible,
  96. and two if they are nearly compatible (which causes a warning to be
  97. generated). If this is not defined, machine-specific attributes are
  98. supposed always to be compatible.
  99. </p></dd></dl>
  100. <dl>
  101. <dt><a name="index-TARGET_005fSET_005fDEFAULT_005fTYPE_005fATTRIBUTES"></a>Target Hook: <em>void</em> <strong>TARGET_SET_DEFAULT_TYPE_ATTRIBUTES</strong> <em>(tree <var>type</var>)</em></dt>
  102. <dd><p>If defined, this target hook is a function which assigns default attributes to
  103. the newly defined <var>type</var>.
  104. </p></dd></dl>
  105. <dl>
  106. <dt><a name="index-TARGET_005fMERGE_005fTYPE_005fATTRIBUTES"></a>Target Hook: <em>tree</em> <strong>TARGET_MERGE_TYPE_ATTRIBUTES</strong> <em>(tree <var>type1</var>, tree <var>type2</var>)</em></dt>
  107. <dd><p>Define this target hook if the merging of type attributes needs special
  108. handling. If defined, the result is a list of the combined
  109. <code>TYPE_ATTRIBUTES</code> of <var>type1</var> and <var>type2</var>. It is assumed
  110. that <code>comptypes</code> has already been called and returned 1. This
  111. function may call <code>merge_attributes</code> to handle machine-independent
  112. merging.
  113. </p></dd></dl>
  114. <dl>
  115. <dt><a name="index-TARGET_005fMERGE_005fDECL_005fATTRIBUTES"></a>Target Hook: <em>tree</em> <strong>TARGET_MERGE_DECL_ATTRIBUTES</strong> <em>(tree <var>olddecl</var>, tree <var>newdecl</var>)</em></dt>
  116. <dd><p>Define this target hook if the merging of decl attributes needs special
  117. handling. If defined, the result is a list of the combined
  118. <code>DECL_ATTRIBUTES</code> of <var>olddecl</var> and <var>newdecl</var>.
  119. <var>newdecl</var> is a duplicate declaration of <var>olddecl</var>. Examples of
  120. when this is needed are when one attribute overrides another, or when an
  121. attribute is nullified by a subsequent definition. This function may
  122. call <code>merge_attributes</code> to handle machine-independent merging.
  123. </p>
  124. <a name="index-TARGET_005fDLLIMPORT_005fDECL_005fATTRIBUTES"></a>
  125. <p>If the only target-specific handling you require is &lsquo;<samp>dllimport</samp>&rsquo;
  126. for Microsoft Windows targets, you should define the macro
  127. <code>TARGET_DLLIMPORT_DECL_ATTRIBUTES</code> to <code>1</code>. The compiler
  128. will then define a function called
  129. <code>merge_dllimport_decl_attributes</code> which can then be defined as
  130. the expansion of <code>TARGET_MERGE_DECL_ATTRIBUTES</code>. You can also
  131. add <code>handle_dll_attribute</code> in the attribute table for your port
  132. to perform initial processing of the &lsquo;<samp>dllimport</samp>&rsquo; and
  133. &lsquo;<samp>dllexport</samp>&rsquo; attributes. This is done in <samp>i386/cygwin.h</samp> and
  134. <samp>i386/i386.c</samp>, for example.
  135. </p></dd></dl>
  136. <dl>
  137. <dt><a name="index-TARGET_005fVALID_005fDLLIMPORT_005fATTRIBUTE_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_VALID_DLLIMPORT_ATTRIBUTE_P</strong> <em>(const_tree <var>decl</var>)</em></dt>
  138. <dd><p><var>decl</var> is a variable or function with <code>__attribute__((dllimport))</code> specified. Use this hook if the target needs to add extra validation checks to <code>handle_dll_attribute</code>.
  139. </p></dd></dl>
  140. <dl>
  141. <dt><a name="index-TARGET_005fDECLSPEC"></a>Macro: <strong>TARGET_DECLSPEC</strong></dt>
  142. <dd><p>Define this macro to a nonzero value if you want to treat
  143. <code>__declspec(X)</code> as equivalent to <code>__attribute((X))</code>. By
  144. default, this behavior is enabled only for targets that define
  145. <code>TARGET_DLLIMPORT_DECL_ATTRIBUTES</code>. The current implementation
  146. of <code>__declspec</code> is via a built-in macro, but you should not rely
  147. on this implementation detail.
  148. </p></dd></dl>
  149. <dl>
  150. <dt><a name="index-TARGET_005fINSERT_005fATTRIBUTES"></a>Target Hook: <em>void</em> <strong>TARGET_INSERT_ATTRIBUTES</strong> <em>(tree <var>node</var>, tree *<var>attr_ptr</var>)</em></dt>
  151. <dd><p>Define this target hook if you want to be able to add attributes to a decl
  152. when it is being created. This is normally useful for back ends which
  153. wish to implement a pragma by using the attributes which correspond to
  154. the pragma&rsquo;s effect. The <var>node</var> argument is the decl which is being
  155. created. The <var>attr_ptr</var> argument is a pointer to the attribute list
  156. for this decl. The list itself should not be modified, since it may be
  157. shared with other decls, but attributes may be chained on the head of
  158. the list and <code>*<var>attr_ptr</var></code> modified to point to the new
  159. attributes, or a copy of the list may be made if further changes are
  160. needed.
  161. </p></dd></dl>
  162. <dl>
  163. <dt><a name="index-TARGET_005fHANDLE_005fGENERIC_005fATTRIBUTE"></a>Target Hook: <em>tree</em> <strong>TARGET_HANDLE_GENERIC_ATTRIBUTE</strong> <em>(tree *<var>node</var>, tree <var>name</var>, tree <var>args</var>, int <var>flags</var>, bool *<var>no_add_attrs</var>)</em></dt>
  164. <dd><p>Define this target hook if you want to be able to perform additional
  165. target-specific processing of an attribute which is handled generically
  166. by a front end. The arguments are the same as those which are passed to
  167. attribute handlers. So far this only affects the <var>noinit</var> and
  168. <var>section</var> attribute.
  169. </p></dd></dl>
  170. <dl>
  171. <dt><a name="index-TARGET_005fFUNCTION_005fATTRIBUTE_005fINLINABLE_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_FUNCTION_ATTRIBUTE_INLINABLE_P</strong> <em>(const_tree <var>fndecl</var>)</em></dt>
  172. <dd><a name="index-inlining"></a>
  173. <p>This target hook returns <code>true</code> if it is OK to inline <var>fndecl</var>
  174. into the current function, despite its having target-specific
  175. attributes, <code>false</code> otherwise. By default, if a function has a
  176. target specific attribute attached to it, it will not be inlined.
  177. </p></dd></dl>
  178. <dl>
  179. <dt><a name="index-TARGET_005fOPTION_005fVALID_005fATTRIBUTE_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_OPTION_VALID_ATTRIBUTE_P</strong> <em>(tree <var>fndecl</var>, tree <var>name</var>, tree <var>args</var>, int <var>flags</var>)</em></dt>
  180. <dd><p>This hook is called to parse <code>attribute(target(&quot;...&quot;))</code>, which
  181. allows setting target-specific options on individual functions.
  182. These function-specific options may differ
  183. from the options specified on the command line. The hook should return
  184. <code>true</code> if the options are valid.
  185. </p>
  186. <p>The hook should set the <code>DECL_FUNCTION_SPECIFIC_TARGET</code> field in
  187. the function declaration to hold a pointer to a target-specific
  188. <code>struct cl_target_option</code> structure.
  189. </p></dd></dl>
  190. <dl>
  191. <dt><a name="index-TARGET_005fOPTION_005fSAVE"></a>Target Hook: <em>void</em> <strong>TARGET_OPTION_SAVE</strong> <em>(struct cl_target_option *<var>ptr</var>, struct gcc_options *<var>opts</var>)</em></dt>
  192. <dd><p>This hook is called to save any additional target-specific information
  193. in the <code>struct cl_target_option</code> structure for function-specific
  194. options from the <code>struct gcc_options</code> structure.
  195. See <a href="Option-file-format.html#Option-file-format">Option file format</a>.
  196. </p></dd></dl>
  197. <dl>
  198. <dt><a name="index-TARGET_005fOPTION_005fRESTORE"></a>Target Hook: <em>void</em> <strong>TARGET_OPTION_RESTORE</strong> <em>(struct gcc_options *<var>opts</var>, struct cl_target_option *<var>ptr</var>)</em></dt>
  199. <dd><p>This hook is called to restore any additional target-specific
  200. information in the <code>struct cl_target_option</code> structure for
  201. function-specific options to the <code>struct gcc_options</code> structure.
  202. </p></dd></dl>
  203. <dl>
  204. <dt><a name="index-TARGET_005fOPTION_005fPOST_005fSTREAM_005fIN"></a>Target Hook: <em>void</em> <strong>TARGET_OPTION_POST_STREAM_IN</strong> <em>(struct cl_target_option *<var>ptr</var>)</em></dt>
  205. <dd><p>This hook is called to update target-specific information in the
  206. <code>struct cl_target_option</code> structure after it is streamed in from
  207. LTO bytecode.
  208. </p></dd></dl>
  209. <dl>
  210. <dt><a name="index-TARGET_005fOPTION_005fPRINT"></a>Target Hook: <em>void</em> <strong>TARGET_OPTION_PRINT</strong> <em>(FILE *<var>file</var>, int <var>indent</var>, struct cl_target_option *<var>ptr</var>)</em></dt>
  211. <dd><p>This hook is called to print any additional target-specific
  212. information in the <code>struct cl_target_option</code> structure for
  213. function-specific options.
  214. </p></dd></dl>
  215. <dl>
  216. <dt><a name="index-TARGET_005fOPTION_005fPRAGMA_005fPARSE"></a>Target Hook: <em>bool</em> <strong>TARGET_OPTION_PRAGMA_PARSE</strong> <em>(tree <var>args</var>, tree <var>pop_target</var>)</em></dt>
  217. <dd><p>This target hook parses the options for <code>#pragma GCC target</code>, which
  218. sets the target-specific options for functions that occur later in the
  219. input stream. The options accepted should be the same as those handled by the
  220. <code>TARGET_OPTION_VALID_ATTRIBUTE_P</code> hook.
  221. </p></dd></dl>
  222. <dl>
  223. <dt><a name="index-TARGET_005fOPTION_005fOVERRIDE"></a>Target Hook: <em>void</em> <strong>TARGET_OPTION_OVERRIDE</strong> <em>(void)</em></dt>
  224. <dd><p>Sometimes certain combinations of command options do not make sense on
  225. a particular target machine. You can override the hook
  226. <code>TARGET_OPTION_OVERRIDE</code> to take account of this. This hooks is called
  227. once just after all the command options have been parsed.
  228. </p>
  229. <p>Don&rsquo;t use this hook to turn on various extra optimizations for
  230. <samp>-O</samp>. That is what <code>TARGET_OPTION_OPTIMIZATION</code> is for.
  231. </p>
  232. <p>If you need to do something whenever the optimization level is
  233. changed via the optimize attribute or pragma, see
  234. <code>TARGET_OVERRIDE_OPTIONS_AFTER_CHANGE</code>
  235. </p></dd></dl>
  236. <dl>
  237. <dt><a name="index-TARGET_005fOPTION_005fFUNCTION_005fVERSIONS"></a>Target Hook: <em>bool</em> <strong>TARGET_OPTION_FUNCTION_VERSIONS</strong> <em>(tree <var>decl1</var>, tree <var>decl2</var>)</em></dt>
  238. <dd><p>This target hook returns <code>true</code> if <var>DECL1</var> and <var>DECL2</var> are
  239. versions of the same function. <var>DECL1</var> and <var>DECL2</var> are function
  240. versions if and only if they have the same function signature and
  241. different target specific attributes, that is, they are compiled for
  242. different target machines.
  243. </p></dd></dl>
  244. <dl>
  245. <dt><a name="index-TARGET_005fCAN_005fINLINE_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_CAN_INLINE_P</strong> <em>(tree <var>caller</var>, tree <var>callee</var>)</em></dt>
  246. <dd><p>This target hook returns <code>false</code> if the <var>caller</var> function
  247. cannot inline <var>callee</var>, based on target specific information. By
  248. default, inlining is not allowed if the callee function has function
  249. specific target options and the caller does not use the same options.
  250. </p></dd></dl>
  251. <dl>
  252. <dt><a name="index-TARGET_005fRELAYOUT_005fFUNCTION"></a>Target Hook: <em>void</em> <strong>TARGET_RELAYOUT_FUNCTION</strong> <em>(tree <var>fndecl</var>)</em></dt>
  253. <dd><p>This target hook fixes function <var>fndecl</var> after attributes are processed. Default does nothing. On ARM, the default function&rsquo;s alignment is updated with the attribute target.
  254. </p></dd></dl>
  255. <hr>
  256. <div class="header">
  257. <p>
  258. Next: <a href="Emulated-TLS.html#Emulated-TLS" accesskey="n" rel="next">Emulated TLS</a>, Previous: <a href="Mode-Switching.html#Mode-Switching" accesskey="p" rel="prev">Mode Switching</a>, Up: <a href="Target-Macros.html#Target-Macros" accesskey="u" rel="up">Target Macros</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>
  259. </div>
  260. </body>
  261. </html>