Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the GNU linker LD
  4. (GNU Arm Embedded Toolchain 10-2020-q4-major)
  5. version 2.35.1.
  6. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  7. Permission is granted to copy, distribute and/or modify this document
  8. under the terms of the GNU Free Documentation License, Version 1.3
  9. or any later version published by the Free Software Foundation;
  10. with no Invariant Sections, with no Front-Cover Texts, and with no
  11. Back-Cover Texts. A copy of the license is included in the
  12. section entitled "GNU Free Documentation License". -->
  13. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Expression Section (LD)</title>
  17. <meta name="description" content="Expression Section (LD)">
  18. <meta name="keywords" content="Expression Section (LD)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="LD-Index.html#LD-Index" rel="index" title="LD Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="Expressions.html#Expressions" rel="up" title="Expressions">
  26. <link href="Builtin-Functions.html#Builtin-Functions" rel="next" title="Builtin Functions">
  27. <link href="Evaluation.html#Evaluation" rel="prev" title="Evaluation">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style: oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Expression-Section"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Builtin-Functions.html#Builtin-Functions" accesskey="n" rel="next">Builtin Functions</a>, Previous: <a href="Evaluation.html#Evaluation" accesskey="p" rel="prev">Evaluation</a>, Up: <a href="Expressions.html#Expressions" accesskey="u" rel="up">Expressions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="The-Section-of-an-Expression"></a>
  64. <h4 class="subsection">3.10.8 The Section of an Expression</h4>
  65. <a name="index-expression-sections"></a>
  66. <a name="index-absolute-expressions"></a>
  67. <a name="index-relative-expressions"></a>
  68. <a name="index-absolute-and-relocatable-symbols"></a>
  69. <a name="index-relocatable-and-absolute-symbols"></a>
  70. <a name="index-symbols_002c-relocatable-and-absolute"></a>
  71. <p>Addresses and symbols may be section relative, or absolute. A section
  72. relative symbol is relocatable. If you request relocatable output
  73. using the &lsquo;<samp>-r</samp>&rsquo; option, a further link operation may change the
  74. value of a section relative symbol. On the other hand, an absolute
  75. symbol will retain the same value throughout any further link
  76. operations.
  77. </p>
  78. <p>Some terms in linker expressions are addresses. This is true of
  79. section relative symbols and for builtin functions that return an
  80. address, such as <code>ADDR</code>, <code>LOADADDR</code>, <code>ORIGIN</code> and
  81. <code>SEGMENT_START</code>. Other terms are simply numbers, or are builtin
  82. functions that return a non-address value, such as <code>LENGTH</code>.
  83. One complication is that unless you set <code>LD_FEATURE (&quot;SANE_EXPR&quot;)</code>
  84. (see <a href="Miscellaneous-Commands.html#Miscellaneous-Commands">Miscellaneous Commands</a>), numbers and absolute symbols are treated
  85. differently depending on their location, for compatibility with older
  86. versions of <code>ld</code>. Expressions appearing outside an output
  87. section definition treat all numbers as absolute addresses.
  88. Expressions appearing inside an output section definition treat
  89. absolute symbols as numbers. If <code>LD_FEATURE (&quot;SANE_EXPR&quot;)</code> is
  90. given, then absolute symbols and numbers are simply treated as numbers
  91. everywhere.
  92. </p>
  93. <p>In the following simple example,
  94. </p>
  95. <div class="smallexample">
  96. <pre class="smallexample">SECTIONS
  97. {
  98. . = 0x100;
  99. __executable_start = 0x100;
  100. .data :
  101. {
  102. . = 0x10;
  103. __data_start = 0x10;
  104. *(.data)
  105. }
  106. &hellip;
  107. }
  108. </pre></div>
  109. <p>both <code>.</code> and <code>__executable_start</code> are set to the absolute
  110. address 0x100 in the first two assignments, then both <code>.</code> and
  111. <code>__data_start</code> are set to 0x10 relative to the <code>.data</code>
  112. section in the second two assignments.
  113. </p>
  114. <p>For expressions involving numbers, relative addresses and absolute
  115. addresses, ld follows these rules to evaluate terms:
  116. </p>
  117. <ul>
  118. <li> Unary operations on an absolute address or number, and binary
  119. operations on two absolute addresses or two numbers, or between one
  120. absolute address and a number, apply the operator to the value(s).
  121. </li><li> Unary operations on a relative address, and binary operations on two
  122. relative addresses in the same section or between one relative address
  123. and a number, apply the operator to the offset part of the address(es).
  124. </li><li> Other binary operations, that is, between two relative addresses not
  125. in the same section, or between a relative address and an absolute
  126. address, first convert any non-absolute term to an absolute address
  127. before applying the operator.
  128. </li></ul>
  129. <p>The result section of each sub-expression is as follows:
  130. </p>
  131. <ul>
  132. <li> An operation involving only numbers results in a number.
  133. </li><li> The result of comparisons, &lsquo;<samp>&amp;&amp;</samp>&rsquo; and &lsquo;<samp>||</samp>&rsquo; is also a number.
  134. </li><li> The result of other binary arithmetic and logical operations on two
  135. relative addresses in the same section or two absolute addresses
  136. (after above conversions) is also a number when
  137. <code>LD_FEATURE (&quot;SANE_EXPR&quot;)</code> or inside an output section definition
  138. but an absolute address otherwise.
  139. </li><li> The result of other operations on relative addresses or one
  140. relative address and a number, is a relative address in the same
  141. section as the relative operand(s).
  142. </li><li> The result of other operations on absolute addresses (after above
  143. conversions) is an absolute address.
  144. </li></ul>
  145. <p>You can use the builtin function <code>ABSOLUTE</code> to force an expression
  146. to be absolute when it would otherwise be relative. For example, to
  147. create an absolute symbol set to the address of the end of the output
  148. section &lsquo;<samp>.data</samp>&rsquo;:
  149. </p><div class="smallexample">
  150. <pre class="smallexample">SECTIONS
  151. {
  152. .data : { *(.data) _edata = ABSOLUTE(.); }
  153. }
  154. </pre></div>
  155. <p>If &lsquo;<samp>ABSOLUTE</samp>&rsquo; were not used, &lsquo;<samp>_edata</samp>&rsquo; would be relative to the
  156. &lsquo;<samp>.data</samp>&rsquo; section.
  157. </p>
  158. <p>Using <code>LOADADDR</code> also forces an expression absolute, since this
  159. particular builtin function returns an absolute address.
  160. </p>
  161. <hr>
  162. <div class="header">
  163. <p>
  164. Next: <a href="Builtin-Functions.html#Builtin-Functions" accesskey="n" rel="next">Builtin Functions</a>, Previous: <a href="Evaluation.html#Evaluation" accesskey="p" rel="prev">Evaluation</a>, Up: <a href="Expressions.html#Expressions" accesskey="u" rel="up">Expressions</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="LD-Index.html#LD-Index" title="Index" rel="index">Index</a>]</p>
  165. </div>
  166. </body>
  167. </html>