Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Secs-Background.html 9.3KB

il y a 3 ans
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 Assembler "as".
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3
  7. or any later version published by the Free Software Foundation;
  8. with no Invariant Sections, with no Front-Cover Texts, and with no
  9. Back-Cover Texts. A copy of the license is included in the
  10. section entitled "GNU Free Documentation License".
  11. -->
  12. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  15. <title>Secs Background (Using as)</title>
  16. <meta name="description" content="Secs Background (Using as)">
  17. <meta name="keywords" content="Secs Background (Using as)">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="AS-Index.html#AS-Index" rel="index" title="AS Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Sections.html#Sections" rel="up" title="Sections">
  25. <link href="Ld-Sections.html#Ld-Sections" rel="next" title="Ld Sections">
  26. <link href="Sections.html#Sections" rel="prev" title="Sections">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.indentedblock {margin-right: 0em}
  31. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  32. blockquote.smallquotation {font-size: smaller}
  33. div.display {margin-left: 3.2em}
  34. div.example {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.smalllisp {margin-left: 3.2em}
  39. kbd {font-style: oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nolinebreak {white-space: nowrap}
  49. span.roman {font-family: initial; font-weight: normal}
  50. span.sansserif {font-family: sans-serif; font-weight: normal}
  51. ul.no-bullet {list-style: none}
  52. -->
  53. </style>
  54. </head>
  55. <body lang="en">
  56. <a name="Secs-Background"></a>
  57. <div class="header">
  58. <p>
  59. Next: <a href="Ld-Sections.html#Ld-Sections" accesskey="n" rel="next">Ld Sections</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="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  60. </div>
  61. <hr>
  62. <a name="Background"></a>
  63. <h3 class="section">4.1 Background</h3>
  64. <p>Roughly, a section is a range of addresses, with no gaps; all data
  65. &ldquo;in&rdquo; those addresses is treated the same for some particular purpose.
  66. For example there may be a &ldquo;read only&rdquo; section.
  67. </p>
  68. <a name="index-linker_002c-and-assembler"></a>
  69. <a name="index-assembler_002c-and-linker"></a>
  70. <p>The linker <code>ld</code> reads many object files (partial programs) and
  71. combines their contents to form a runnable program. When <code>as</code>
  72. emits an object file, the partial program is assumed to start at address 0.
  73. <code>ld</code> assigns the final addresses for the partial program, so that
  74. different partial programs do not overlap. This is actually an
  75. oversimplification, but it suffices to explain how <code>as</code> uses
  76. sections.
  77. </p>
  78. <p><code>ld</code> moves blocks of bytes of your program to their run-time
  79. addresses. These blocks slide to their run-time addresses as rigid
  80. units; their length does not change and neither does the order of bytes
  81. within them. Such a rigid unit is called a <em>section</em>. Assigning
  82. run-time addresses to sections is called <em>relocation</em>. It includes
  83. the task of adjusting mentions of object-file addresses so they refer to
  84. the proper run-time addresses.
  85. For the H8/300, and for the Renesas / SuperH SH,
  86. <code>as</code> pads sections if needed to
  87. ensure they end on a word (sixteen bit) boundary.
  88. </p>
  89. <a name="index-standard-assembler-sections"></a>
  90. <p>An object file written by <code>as</code> has at least three sections, any
  91. of which may be empty. These are named <em>text</em>, <em>data</em> and
  92. <em>bss</em> sections.
  93. </p>
  94. <p>When it generates COFF or ELF output,
  95. <code>as</code> can also generate whatever other named sections you specify
  96. using the &lsquo;<samp>.section</samp>&rsquo; directive (see <a href="Section.html#Section"><code>.section</code></a>).
  97. If you do not use any directives that place output in the &lsquo;<samp>.text</samp>&rsquo;
  98. or &lsquo;<samp>.data</samp>&rsquo; sections, these sections still exist, but are empty.
  99. </p>
  100. <p>When <code>as</code> generates SOM or ELF output for the HPPA,
  101. <code>as</code> can also generate whatever other named sections you
  102. specify using the &lsquo;<samp>.space</samp>&rsquo; and &lsquo;<samp>.subspace</samp>&rsquo; directives. See
  103. <cite>HP9000 Series 800 Assembly Language Reference Manual</cite>
  104. (HP 92432-90001) for details on the &lsquo;<samp>.space</samp>&rsquo; and &lsquo;<samp>.subspace</samp>&rsquo;
  105. assembler directives.
  106. </p>
  107. <p>Additionally, <code>as</code> uses different names for the standard
  108. text, data, and bss sections when generating SOM output. Program text
  109. is placed into the &lsquo;<samp>$CODE$</samp>&rsquo; section, data into &lsquo;<samp>$DATA$</samp>&rsquo;, and
  110. BSS into &lsquo;<samp>$BSS$</samp>&rsquo;.
  111. </p>
  112. <p>Within the object file, the text section starts at address <code>0</code>, the
  113. data section follows, and the bss section follows the data section.
  114. </p>
  115. <p>When generating either SOM or ELF output files on the HPPA, the text
  116. section starts at address <code>0</code>, the data section at address
  117. <code>0x4000000</code>, and the bss section follows the data section.
  118. </p>
  119. <p>To let <code>ld</code> know which data changes when the sections are
  120. relocated, and how to change that data, <code>as</code> also writes to the
  121. object file details of the relocation needed. To perform relocation
  122. <code>ld</code> must know, each time an address in the object
  123. file is mentioned:
  124. </p><ul>
  125. <li> Where in the object file is the beginning of this reference to
  126. an address?
  127. </li><li> How long (in bytes) is this reference?
  128. </li><li> Which section does the address refer to? What is the numeric value of
  129. <div class="display">
  130. <pre class="display">(<var>address</var>) - (<var>start-address of section</var>)?
  131. </pre></div>
  132. </li><li> Is the reference to an address &ldquo;Program-Counter relative&rdquo;?
  133. </li></ul>
  134. <a name="index-addresses_002c-format-of"></a>
  135. <a name="index-section_002drelative-addressing"></a>
  136. <p>In fact, every address <code>as</code> ever uses is expressed as
  137. </p><div class="display">
  138. <pre class="display">(<var>section</var>) + (<var>offset into section</var>)
  139. </pre></div>
  140. <p>Further, most expressions <code>as</code> computes have this section-relative
  141. nature.
  142. (For some object formats, such as SOM for the HPPA, some expressions are
  143. symbol-relative instead.)
  144. </p>
  145. <p>In this manual we use the notation {<var>secname</var> <var>N</var>} to mean &ldquo;offset
  146. <var>N</var> into section <var>secname</var>.&rdquo;
  147. </p>
  148. <p>Apart from text, data and bss sections you need to know about the
  149. <em>absolute</em> section. When <code>ld</code> mixes partial programs,
  150. addresses in the absolute section remain unchanged. For example, address
  151. <code>{absolute 0}</code> is &ldquo;relocated&rdquo; to run-time address 0 by
  152. <code>ld</code>. Although the linker never arranges two partial programs&rsquo;
  153. data sections with overlapping addresses after linking, <em>by definition</em>
  154. their absolute sections must overlap. Address <code>{absolute&nbsp;239}</code> in one
  155. part of a program is always the same address when the program is running as
  156. address <code>{absolute&nbsp;239}</code> in any other part of the program.
  157. </p>
  158. <p>The idea of sections is extended to the <em>undefined</em> section. Any
  159. address whose section is unknown at assembly time is by definition
  160. rendered {undefined <var>U</var>}&mdash;where <var>U</var> is filled in later.
  161. Since numbers are always defined, the only way to generate an undefined
  162. address is to mention an undefined symbol. A reference to a named
  163. common block would be such a symbol: its value is unknown at assembly
  164. time so it has section <em>undefined</em>.
  165. </p>
  166. <p>By analogy the word <em>section</em> is used to describe groups of sections in
  167. the linked program. <code>ld</code> puts all partial programs&rsquo; text
  168. sections in contiguous addresses in the linked program. It is
  169. customary to refer to the <em>text section</em> of a program, meaning all
  170. the addresses of all partial programs&rsquo; text sections. Likewise for
  171. data and bss sections.
  172. </p>
  173. <p>Some sections are manipulated by <code>ld</code>; others are invented for
  174. use of <code>as</code> and have no meaning except during assembly.
  175. </p>
  176. <hr>
  177. <div class="header">
  178. <p>
  179. Next: <a href="Ld-Sections.html#Ld-Sections" accesskey="n" rel="next">Ld Sections</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="AS-Index.html#AS-Index" title="Index" rel="index">Index</a>]</p>
  180. </div>
  181. </body>
  182. </html>