Output-Section-Address.html 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 Binutils)
  5. version 2.28.
  6. Copyright (C) 1991-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>LD: Output Section Address</title>
  16. <meta name="description" content="LD: Output Section Address">
  17. <meta name="keywords" content="LD: Output Section Address">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
  26. <link href="Input-Section.html#Input-Section" rel="next" title="Input Section">
  27. <link href="Output-Section-Name.html#Output-Section-Name" rel="prev" title="Output Section Name">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="Output-Section-Address"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="Input-Section.html#Input-Section" accesskey="n" rel="next">Input Section</a>, Previous: <a href="Output-Section-Name.html#Output-Section-Name" accesskey="p" rel="prev">Output Section Name</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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>
  62. </div>
  63. <hr>
  64. <a name="Output-Section-Address-1"></a>
  65. <h4 class="subsection">3.6.3 Output Section Address</h4>
  66. <a name="index-address_002c-section"></a>
  67. <a name="index-section-address"></a>
  68. <p>The <var>address</var> is an expression for the VMA (the virtual memory
  69. address) of the output section. This address is optional, but if it
  70. is provided then the output address will be set exactly as specified.
  71. </p>
  72. <p>If the output address is not specified then one will be chosen for the
  73. section, based on the heuristic below. This address will be adjusted
  74. to fit the alignment requirement of the output section. The
  75. alignment requirement is the strictest alignment of any input section
  76. contained within the output section.
  77. </p>
  78. <p>The output section address heuristic is as follows:
  79. </p>
  80. <ul>
  81. <li> If an output memory <var>region</var> is set for the section then it
  82. is added to this region and its address will be the next free address
  83. in that region.
  84. </li><li> If the MEMORY command has been used to create a list of memory
  85. regions then the first region which has attributes compatible with the
  86. section is selected to contain it. The section&rsquo;s output address will
  87. be the next free address in that region; <a href="MEMORY.html#MEMORY">MEMORY</a>.
  88. </li><li> If no memory regions were specified, or none match the section then
  89. the output address will be based on the current value of the location
  90. counter.
  91. </li></ul>
  92. <p>For example:
  93. </p>
  94. <div class="smallexample">
  95. <pre class="smallexample">.text . : { *(.text) }
  96. </pre></div>
  97. <p>and
  98. </p>
  99. <div class="smallexample">
  100. <pre class="smallexample">.text : { *(.text) }
  101. </pre></div>
  102. <p>are subtly different. The first will set the address of the
  103. &lsquo;<samp>.text</samp>&rsquo; output section to the current value of the location
  104. counter. The second will set it to the current value of the location
  105. counter aligned to the strictest alignment of any of the &lsquo;<samp>.text</samp>&rsquo;
  106. input sections.
  107. </p>
  108. <p>The <var>address</var> may be an arbitrary expression; <a href="Expressions.html#Expressions">Expressions</a>.
  109. For example, if you want to align the section on a 0x10 byte boundary,
  110. so that the lowest four bits of the section address are zero, you could
  111. do something like this:
  112. </p><div class="smallexample">
  113. <pre class="smallexample">.text ALIGN(0x10) : { *(.text) }
  114. </pre></div>
  115. <p>This works because <code>ALIGN</code> returns the current location counter
  116. aligned upward to the specified value.
  117. </p>
  118. <p>Specifying <var>address</var> for a section will change the value of the
  119. location counter, provided that the section is non-empty. (Empty
  120. sections are ignored).
  121. </p>
  122. <hr>
  123. <div class="header">
  124. <p>
  125. Next: <a href="Input-Section.html#Input-Section" accesskey="n" rel="next">Input Section</a>, Previous: <a href="Output-Section-Name.html#Output-Section-Name" accesskey="p" rel="prev">Output Section Name</a>, Up: <a href="SECTIONS.html#SECTIONS" accesskey="u" rel="up">SECTIONS</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>
  126. </div>
  127. </body>
  128. </html>