您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Output-Section-Keywords.html 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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>Output Section Keywords (LD)</title>
  17. <meta name="description" content="Output Section Keywords (LD)">
  18. <meta name="keywords" content="Output Section Keywords (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="SECTIONS.html#SECTIONS" rel="up" title="SECTIONS">
  26. <link href="Output-Section-Discarding.html#Output-Section-Discarding" rel="next" title="Output Section Discarding">
  27. <link href="Output-Section-Data.html#Output-Section-Data" rel="prev" title="Output Section Data">
  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="Output-Section-Keywords"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Output-Section-Discarding.html#Output-Section-Discarding" accesskey="n" rel="next">Output Section Discarding</a>, Previous: <a href="Output-Section-Data.html#Output-Section-Data" accesskey="p" rel="prev">Output Section Data</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>
  61. </div>
  62. <hr>
  63. <a name="Output-Section-Keywords-1"></a>
  64. <h4 class="subsection">3.6.6 Output Section Keywords</h4>
  65. <p>There are a couple of keywords which can appear as output section
  66. commands.
  67. </p>
  68. <dl compact="compact">
  69. <dd><a name="index-CREATE_005fOBJECT_005fSYMBOLS"></a>
  70. <a name="index-input-filename-symbols"></a>
  71. <a name="index-filename-symbols"></a>
  72. </dd>
  73. <dt><code>CREATE_OBJECT_SYMBOLS</code></dt>
  74. <dd><p>The command tells the linker to create a symbol for each input file.
  75. The name of each symbol will be the name of the corresponding input
  76. file. The section of each symbol will be the output section in which
  77. the <code>CREATE_OBJECT_SYMBOLS</code> command appears.
  78. </p>
  79. <p>This is conventional for the a.out object file format. It is not
  80. normally used for any other object file format.
  81. </p>
  82. <a name="index-CONSTRUCTORS"></a>
  83. <a name="index-C_002b_002b-constructors_002c-arranging-in-link"></a>
  84. <a name="index-constructors_002c-arranging-in-link"></a>
  85. </dd>
  86. <dt><code>CONSTRUCTORS</code></dt>
  87. <dd><p>When linking using the a.out object file format, the linker uses an
  88. unusual set construct to support C++ global constructors and
  89. destructors. When linking object file formats which do not support
  90. arbitrary sections, such as ECOFF and XCOFF, the linker will
  91. automatically recognize C++ global constructors and destructors by name.
  92. For these object file formats, the <code>CONSTRUCTORS</code> command tells the
  93. linker to place constructor information in the output section where the
  94. <code>CONSTRUCTORS</code> command appears. The <code>CONSTRUCTORS</code> command is
  95. ignored for other object file formats.
  96. </p>
  97. <p>The symbol <code><span class="nolinebreak">__CTOR_LIST__</span></code><!-- /@w --> marks the start of the global
  98. constructors, and the symbol <code><span class="nolinebreak">__CTOR_END__</span></code><!-- /@w --> marks the end.
  99. Similarly, <code><span class="nolinebreak">__DTOR_LIST__</span></code><!-- /@w --> and <code><span class="nolinebreak">__DTOR_END__</span></code><!-- /@w --> mark
  100. the start and end of the global destructors. The
  101. first word in the list is the number of entries, followed by the address
  102. of each constructor or destructor, followed by a zero word. The
  103. compiler must arrange to actually run the code. For these object file
  104. formats <small>GNU</small> C++ normally calls constructors from a subroutine
  105. <code>__main</code>; a call to <code>__main</code> is automatically inserted into
  106. the startup code for <code>main</code>. <small>GNU</small> C++ normally runs
  107. destructors either by using <code>atexit</code>, or directly from the function
  108. <code>exit</code>.
  109. </p>
  110. <p>For object file formats such as <code>COFF</code> or <code>ELF</code> which support
  111. arbitrary section names, <small>GNU</small> C++ will normally arrange to put the
  112. addresses of global constructors and destructors into the <code>.ctors</code>
  113. and <code>.dtors</code> sections. Placing the following sequence into your
  114. linker script will build the sort of table which the <small>GNU</small> C++
  115. runtime code expects to see.
  116. </p>
  117. <div class="smallexample">
  118. <pre class="smallexample"> __CTOR_LIST__ = .;
  119. LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
  120. *(.ctors)
  121. LONG(0)
  122. __CTOR_END__ = .;
  123. __DTOR_LIST__ = .;
  124. LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
  125. *(.dtors)
  126. LONG(0)
  127. __DTOR_END__ = .;
  128. </pre></div>
  129. <p>If you are using the <small>GNU</small> C++ support for initialization priority,
  130. which provides some control over the order in which global constructors
  131. are run, you must sort the constructors at link time to ensure that they
  132. are executed in the correct order. When using the <code>CONSTRUCTORS</code>
  133. command, use &lsquo;<samp>SORT_BY_NAME(CONSTRUCTORS)</samp>&rsquo; instead. When using the
  134. <code>.ctors</code> and <code>.dtors</code> sections, use &lsquo;<samp>*(SORT_BY_NAME(.ctors))</samp>&rsquo; and
  135. &lsquo;<samp>*(SORT_BY_NAME(.dtors))</samp>&rsquo; instead of just &lsquo;<samp>*(.ctors)</samp>&rsquo; and
  136. &lsquo;<samp>*(.dtors)</samp>&rsquo;.
  137. </p>
  138. <p>Normally the compiler and linker will handle these issues automatically,
  139. and you will not need to concern yourself with them. However, you may
  140. need to consider this if you are using C++ and writing your own linker
  141. scripts.
  142. </p>
  143. </dd>
  144. </dl>
  145. <hr>
  146. <div class="header">
  147. <p>
  148. Next: <a href="Output-Section-Discarding.html#Output-Section-Discarding" accesskey="n" rel="next">Output Section Discarding</a>, Previous: <a href="Output-Section-Data.html#Output-Section-Data" accesskey="p" rel="prev">Output Section Data</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>
  149. </div>
  150. </body>
  151. </html>