Anchored-Addresses.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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>GNU Compiler Collection (GCC) Internals: Anchored Addresses</title>
  20. <meta name="description" content="GNU Compiler Collection (GCC) Internals: Anchored Addresses">
  21. <meta name="keywords" content="GNU Compiler Collection (GCC) Internals: Anchored Addresses">
  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="Target-Macros.html#Target-Macros" rel="up" title="Target Macros">
  30. <link href="Condition-Code.html#Condition-Code" rel="next" title="Condition Code">
  31. <link href="Addressing-Modes.html#Addressing-Modes" rel="prev" title="Addressing Modes">
  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="Anchored-Addresses"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Condition-Code.html#Condition-Code" accesskey="n" rel="next">Condition Code</a>, Previous: <a href="Addressing-Modes.html#Addressing-Modes" accesskey="p" rel="prev">Addressing Modes</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>
  66. </div>
  67. <hr>
  68. <a name="Anchored-Addresses-1"></a>
  69. <h3 class="section">17.14 Anchored Addresses</h3>
  70. <a name="index-anchored-addresses"></a>
  71. <a name="index-_002dfsection_002danchors-1"></a>
  72. <p>GCC usually addresses every static object as a separate entity.
  73. For example, if we have:
  74. </p>
  75. <div class="smallexample">
  76. <pre class="smallexample">static int a, b, c;
  77. int foo (void) { return a + b + c; }
  78. </pre></div>
  79. <p>the code for <code>foo</code> will usually calculate three separate symbolic
  80. addresses: those of <code>a</code>, <code>b</code> and <code>c</code>. On some targets,
  81. it would be better to calculate just one symbolic address and access
  82. the three variables relative to it. The equivalent pseudocode would
  83. be something like:
  84. </p>
  85. <div class="smallexample">
  86. <pre class="smallexample">int foo (void)
  87. {
  88. register int *xr = &amp;x;
  89. return xr[&amp;a - &amp;x] + xr[&amp;b - &amp;x] + xr[&amp;c - &amp;x];
  90. }
  91. </pre></div>
  92. <p>(which isn&rsquo;t valid C). We refer to shared addresses like <code>x</code> as
  93. &ldquo;section anchors&rdquo;. Their use is controlled by <samp>-fsection-anchors</samp>.
  94. </p>
  95. <p>The hooks below describe the target properties that GCC needs to know
  96. in order to make effective use of section anchors. It won&rsquo;t use
  97. section anchors at all unless either <code>TARGET_MIN_ANCHOR_OFFSET</code>
  98. or <code>TARGET_MAX_ANCHOR_OFFSET</code> is set to a nonzero value.
  99. </p>
  100. <dl>
  101. <dt><a name="index-TARGET_005fMIN_005fANCHOR_005fOFFSET"></a>Target Hook: <em>HOST_WIDE_INT</em> <strong>TARGET_MIN_ANCHOR_OFFSET</strong></dt>
  102. <dd><p>The minimum offset that should be applied to a section anchor.
  103. On most targets, it should be the smallest offset that can be
  104. applied to a base register while still giving a legitimate address
  105. for every mode. The default value is 0.
  106. </p></dd></dl>
  107. <dl>
  108. <dt><a name="index-TARGET_005fMAX_005fANCHOR_005fOFFSET"></a>Target Hook: <em>HOST_WIDE_INT</em> <strong>TARGET_MAX_ANCHOR_OFFSET</strong></dt>
  109. <dd><p>Like <code>TARGET_MIN_ANCHOR_OFFSET</code>, but the maximum (inclusive)
  110. offset that should be applied to section anchors. The default
  111. value is 0.
  112. </p></dd></dl>
  113. <dl>
  114. <dt><a name="index-TARGET_005fASM_005fOUTPUT_005fANCHOR"></a>Target Hook: <em>void</em> <strong>TARGET_ASM_OUTPUT_ANCHOR</strong> <em>(rtx <var>x</var>)</em></dt>
  115. <dd><p>Write the assembly code to define section anchor <var>x</var>, which is a
  116. <code>SYMBOL_REF</code> for which &lsquo;<samp>SYMBOL_REF_ANCHOR_P (<var>x</var>)</samp>&rsquo; is true.
  117. The hook is called with the assembly output position set to the beginning
  118. of <code>SYMBOL_REF_BLOCK (<var>x</var>)</code>.
  119. </p>
  120. <p>If <code>ASM_OUTPUT_DEF</code> is available, the hook&rsquo;s default definition uses
  121. it to define the symbol as &lsquo;<samp>. + SYMBOL_REF_BLOCK_OFFSET (<var>x</var>)</samp>&rsquo;.
  122. If <code>ASM_OUTPUT_DEF</code> is not available, the hook&rsquo;s default definition
  123. is <code>NULL</code>, which disables the use of section anchors altogether.
  124. </p></dd></dl>
  125. <dl>
  126. <dt><a name="index-TARGET_005fUSE_005fANCHORS_005fFOR_005fSYMBOL_005fP"></a>Target Hook: <em>bool</em> <strong>TARGET_USE_ANCHORS_FOR_SYMBOL_P</strong> <em>(const_rtx <var>x</var>)</em></dt>
  127. <dd><p>Return true if GCC should attempt to use anchors to access <code>SYMBOL_REF</code>
  128. <var>x</var>. You can assume &lsquo;<samp>SYMBOL_REF_HAS_BLOCK_INFO_P (<var>x</var>)</samp>&rsquo; and
  129. &lsquo;<samp>!SYMBOL_REF_ANCHOR_P (<var>x</var>)</samp>&rsquo;.
  130. </p>
  131. <p>The default version is correct for most targets, but you might need to
  132. intercept this hook to handle things like target-specific attributes
  133. or target-specific sections.
  134. </p></dd></dl>
  135. <hr>
  136. <div class="header">
  137. <p>
  138. Next: <a href="Condition-Code.html#Condition-Code" accesskey="n" rel="next">Condition Code</a>, Previous: <a href="Addressing-Modes.html#Addressing-Modes" accesskey="p" rel="prev">Addressing Modes</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>
  139. </div>
  140. </body>
  141. </html>