Ld-Sections.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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-2017 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 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>Using as: Ld Sections</title>
  15. <meta name="description" content="Using as: Ld Sections">
  16. <meta name="keywords" content="Using as: Ld Sections">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  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="As-Sections.html#As-Sections" rel="next" title="As Sections">
  26. <link href="Secs-Background.html#Secs-Background" rel="prev" title="Secs Background">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  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.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; 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" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Ld-Sections"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="As-Sections.html#As-Sections" accesskey="n" rel="next">As Sections</a>, Previous: <a href="Secs-Background.html#Secs-Background" accesskey="p" rel="prev">Secs Background</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>
  61. </div>
  62. <hr>
  63. <a name="Linker-Sections"></a>
  64. <h3 class="section">4.2 Linker Sections</h3>
  65. <p><code>ld</code> deals with just four kinds of sections, summarized below.
  66. </p>
  67. <dl compact="compact">
  68. <dd>
  69. <a name="index-named-sections"></a>
  70. <a name="index-sections_002c-named"></a>
  71. </dd>
  72. <dt><strong>named sections</strong></dt>
  73. <dd><a name="index-text-section"></a>
  74. <a name="index-data-section"></a>
  75. </dd>
  76. <dt><strong>text section</strong></dt>
  77. <dt><strong>data section</strong></dt>
  78. <dd><p>These sections hold your program. <code>as</code> and <code>ld</code> treat them as
  79. separate but equal sections. Anything you can say of one section is
  80. true of another.
  81. When the program is running, however, it is
  82. customary for the text section to be unalterable. The
  83. text section is often shared among processes: it contains
  84. instructions, constants and the like. The data section of a running
  85. program is usually alterable: for example, C variables would be stored
  86. in the data section.
  87. </p>
  88. <a name="index-bss-section"></a>
  89. </dd>
  90. <dt><strong>bss section</strong></dt>
  91. <dd><p>This section contains zeroed bytes when your program begins running. It
  92. is used to hold uninitialized variables or common storage. The length of
  93. each partial program&rsquo;s bss section is important, but because it starts
  94. out containing zeroed bytes there is no need to store explicit zero
  95. bytes in the object file. The bss section was invented to eliminate
  96. those explicit zeros from object files.
  97. </p>
  98. <a name="index-absolute-section"></a>
  99. </dd>
  100. <dt><strong>absolute section</strong></dt>
  101. <dd><p>Address 0 of this section is always &ldquo;relocated&rdquo; to runtime address 0.
  102. This is useful if you want to refer to an address that <code>ld</code> must
  103. not change when relocating. In this sense we speak of absolute
  104. addresses being &ldquo;unrelocatable&rdquo;: they do not change during relocation.
  105. </p>
  106. <a name="index-undefined-section"></a>
  107. </dd>
  108. <dt><strong>undefined section</strong></dt>
  109. <dd><p>This &ldquo;section&rdquo; is a catch-all for address references to objects not in
  110. the preceding sections.
  111. </p></dd>
  112. </dl>
  113. <a name="index-relocation-example"></a>
  114. <p>An idealized example of three relocatable sections follows.
  115. The example uses the traditional section names &lsquo;<samp>.text</samp>&rsquo; and &lsquo;<samp>.data</samp>&rsquo;.
  116. Memory addresses are on the horizontal axis.
  117. </p>
  118. <div class="smallexample">
  119. <pre class="smallexample"> +-----+----+--+
  120. partial program # 1: |ttttt|dddd|00|
  121. +-----+----+--+
  122. text data bss
  123. seg. seg. seg.
  124. +---+---+---+
  125. partial program # 2: |TTT|DDD|000|
  126. +---+---+---+
  127. +--+---+-----+--+----+---+-----+~~
  128. linked program: | |TTT|ttttt| |dddd|DDD|00000|
  129. +--+---+-----+--+----+---+-----+~~
  130. addresses: 0 &hellip;
  131. </pre></div>
  132. <hr>
  133. <div class="header">
  134. <p>
  135. Next: <a href="As-Sections.html#As-Sections" accesskey="n" rel="next">As Sections</a>, Previous: <a href="Secs-Background.html#Secs-Background" accesskey="p" rel="prev">Secs Background</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>
  136. </div>
  137. </body>
  138. </html>