Section-Output.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 BFD library.
  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 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being "GNU General Public License" and "Funding
  9. Free Software", the Front-Cover texts being (a) (see below), and with
  10. the Back-Cover Texts being (b) (see below). A copy of the license is
  11. included in the section entitled "GNU Free Documentation License".
  12. (a) The FSF's Front-Cover Text is:
  13. A GNU Manual
  14. (b) The FSF's Back-Cover Text is:
  15. You have freedom to copy and modify this GNU Manual, like GNU
  16. software. Copies published by the Free Software Foundation raise
  17. funds for GNU development. -->
  18. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  19. <head>
  20. <title>Untitled Document: Section Output</title>
  21. <meta name="description" content="Untitled Document: Section Output">
  22. <meta name="keywords" content="Untitled Document: Section Output">
  23. <meta name="resource-type" content="document">
  24. <meta name="distribution" content="global">
  25. <meta name="Generator" content="makeinfo">
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  27. <link href="index.html#Top" rel="start" title="Top">
  28. <link href="BFD-Index.html#BFD-Index" rel="index" title="BFD Index">
  29. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  30. <link href="Sections.html#Sections" rel="up" title="Sections">
  31. <link href="typedef-asection.html#typedef-asection" rel="next" title="typedef asection">
  32. <link href="Section-Input.html#Section-Input" rel="prev" title="Section Input">
  33. <style type="text/css">
  34. <!--
  35. a.summary-letter {text-decoration: none}
  36. blockquote.smallquotation {font-size: smaller}
  37. div.display {margin-left: 3.2em}
  38. div.example {margin-left: 3.2em}
  39. div.indentedblock {margin-left: 3.2em}
  40. div.lisp {margin-left: 3.2em}
  41. div.smalldisplay {margin-left: 3.2em}
  42. div.smallexample {margin-left: 3.2em}
  43. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  44. div.smalllisp {margin-left: 3.2em}
  45. kbd {font-style:oblique}
  46. pre.display {font-family: inherit}
  47. pre.format {font-family: inherit}
  48. pre.menu-comment {font-family: serif}
  49. pre.menu-preformatted {font-family: serif}
  50. pre.smalldisplay {font-family: inherit; font-size: smaller}
  51. pre.smallexample {font-size: smaller}
  52. pre.smallformat {font-family: inherit; font-size: smaller}
  53. pre.smalllisp {font-size: smaller}
  54. span.nocodebreak {white-space:nowrap}
  55. span.nolinebreak {white-space:nowrap}
  56. span.roman {font-family:serif; font-weight:normal}
  57. span.sansserif {font-family:sans-serif; font-weight:normal}
  58. ul.no-bullet {list-style: none}
  59. -->
  60. </style>
  61. </head>
  62. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  63. <a name="Section-Output"></a>
  64. <div class="header">
  65. <p>
  66. Next: <a href="typedef-asection.html#typedef-asection" accesskey="n" rel="next">typedef asection</a>, Previous: <a href="Section-Input.html#Section-Input" accesskey="p" rel="prev">Section Input</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="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  67. </div>
  68. <hr>
  69. <a name="Section-output"></a>
  70. <h4 class="subsection">2.6.2 Section output</h4>
  71. <p>To write a new object style BFD, the various sections to be
  72. written have to be created. They are attached to the BFD in
  73. the same way as input sections; data is written to the
  74. sections using <code>bfd_set_section_contents</code>.
  75. </p>
  76. <p>Any program that creates or combines sections (e.g., the assembler
  77. and linker) must use the <code>asection</code> fields <code>output_section</code> and
  78. <code>output_offset</code> to indicate the file sections to which each
  79. section must be written. (If the section is being created from
  80. scratch, <code>output_section</code> should probably point to the section
  81. itself and <code>output_offset</code> should probably be zero.)
  82. </p>
  83. <p>The data to be written comes from input sections attached
  84. (via <code>output_section</code> pointers) to
  85. the output sections. The output section structure can be
  86. considered a filter for the input section: the output section
  87. determines the vma of the output data and the name, but the
  88. input section determines the offset into the output section of
  89. the data to be written.
  90. </p>
  91. <p>E.g., to create a section &quot;O&quot;, starting at 0x100, 0x123 long,
  92. containing two subsections, &quot;A&quot; at offset 0x0 (i.e., at vma
  93. 0x100) and &quot;B&quot; at offset 0x20 (i.e., at vma 0x120) the <code>asection</code>
  94. structures would look like:
  95. </p>
  96. <div class="example">
  97. <pre class="example"> section name &quot;A&quot;
  98. output_offset 0x00
  99. size 0x20
  100. output_section -----------&gt; section name &quot;O&quot;
  101. | vma 0x100
  102. section name &quot;B&quot; | size 0x123
  103. output_offset 0x20 |
  104. size 0x103 |
  105. output_section --------|
  106. </pre></div>
  107. <a name="Link-orders"></a>
  108. <h4 class="subsection">2.6.3 Link orders</h4>
  109. <p>The data within a section is stored in a <em>link_order</em>.
  110. These are much like the fixups in <code>gas</code>. The link_order
  111. abstraction allows a section to grow and shrink within itself.
  112. </p>
  113. <p>A link_order knows how big it is, and which is the next
  114. link_order and where the raw data for it is; it also points to
  115. a list of relocations which apply to it.
  116. </p>
  117. <p>The link_order is used by the linker to perform relaxing on
  118. final code. The compiler creates code which is as big as
  119. necessary to make it work without relaxing, and the user can
  120. select whether to relax. Sometimes relaxing takes a lot of
  121. time. The linker runs around the relocations to see if any
  122. are attached to data which can be shrunk, if so it does it on
  123. a link_order by link_order basis.
  124. </p>
  125. <hr>
  126. <div class="header">
  127. <p>
  128. Next: <a href="typedef-asection.html#typedef-asection" accesskey="n" rel="next">typedef asection</a>, Previous: <a href="Section-Input.html#Section-Input" accesskey="p" rel="prev">Section Input</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="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  129. </div>
  130. </body>
  131. </html>