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

237 行
9.6KB

  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>PHDRS (LD)</title>
  17. <meta name="description" content="PHDRS (LD)">
  18. <meta name="keywords" content="PHDRS (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="Scripts.html#Scripts" rel="up" title="Scripts">
  26. <link href="VERSION.html#VERSION" rel="next" title="VERSION">
  27. <link href="MEMORY.html#MEMORY" rel="prev" title="MEMORY">
  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="PHDRS"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="VERSION.html#VERSION" accesskey="n" rel="next">VERSION</a>, Previous: <a href="MEMORY.html#MEMORY" accesskey="p" rel="prev">MEMORY</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</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="PHDRS-Command"></a>
  64. <h3 class="section">3.8 PHDRS Command</h3>
  65. <a name="index-PHDRS"></a>
  66. <a name="index-program-headers"></a>
  67. <a name="index-ELF-program-headers"></a>
  68. <a name="index-program-segments"></a>
  69. <a name="index-segments_002c-ELF"></a>
  70. <p>The ELF object file format uses <em>program headers</em>, also knows as
  71. <em>segments</em>. The program headers describe how the program should be
  72. loaded into memory. You can print them out by using the <code>objdump</code>
  73. program with the &lsquo;<samp>-p</samp>&rsquo; option.
  74. </p>
  75. <p>When you run an ELF program on a native ELF system, the system loader
  76. reads the program headers in order to figure out how to load the
  77. program. This will only work if the program headers are set correctly.
  78. This manual does not describe the details of how the system loader
  79. interprets program headers; for more information, see the ELF ABI.
  80. </p>
  81. <p>The linker will create reasonable program headers by default. However,
  82. in some cases, you may need to specify the program headers more
  83. precisely. You may use the <code>PHDRS</code> command for this purpose. When
  84. the linker sees the <code>PHDRS</code> command in the linker script, it will
  85. not create any program headers other than the ones specified.
  86. </p>
  87. <p>The linker only pays attention to the <code>PHDRS</code> command when
  88. generating an ELF output file. In other cases, the linker will simply
  89. ignore <code>PHDRS</code>.
  90. </p>
  91. <p>This is the syntax of the <code>PHDRS</code> command. The words <code>PHDRS</code>,
  92. <code>FILEHDR</code>, <code>AT</code>, and <code>FLAGS</code> are keywords.
  93. </p>
  94. <div class="smallexample">
  95. <pre class="smallexample">PHDRS
  96. {
  97. <var>name</var> <var>type</var> [ FILEHDR ] [ PHDRS ] [ AT ( <var>address</var> ) ]
  98. [ FLAGS ( <var>flags</var> ) ] ;
  99. }
  100. </pre></div>
  101. <p>The <var>name</var> is used only for reference in the <code>SECTIONS</code> command
  102. of the linker script. It is not put into the output file. Program
  103. header names are stored in a separate name space, and will not conflict
  104. with symbol names, file names, or section names. Each program header
  105. must have a distinct name. The headers are processed in order and it
  106. is usual for them to map to sections in ascending load address order.
  107. </p>
  108. <p>Certain program header types describe segments of memory which the
  109. system loader will load from the file. In the linker script, you
  110. specify the contents of these segments by placing allocatable output
  111. sections in the segments. You use the &lsquo;<samp>:<var>phdr</var></samp>&rsquo; output section
  112. attribute to place a section in a particular segment. See <a href="Output-Section-Phdr.html#Output-Section-Phdr">Output Section Phdr</a>.
  113. </p>
  114. <p>It is normal to put certain sections in more than one segment. This
  115. merely implies that one segment of memory contains another. You may
  116. repeat &lsquo;<samp>:<var>phdr</var></samp>&rsquo;, using it once for each segment which should
  117. contain the section.
  118. </p>
  119. <p>If you place a section in one or more segments using &lsquo;<samp>:<var>phdr</var></samp>&rsquo;,
  120. then the linker will place all subsequent allocatable sections which do
  121. not specify &lsquo;<samp>:<var>phdr</var></samp>&rsquo; in the same segments. This is for
  122. convenience, since generally a whole set of contiguous sections will be
  123. placed in a single segment. You can use <code>:NONE</code> to override the
  124. default segment and tell the linker to not put the section in any
  125. segment at all.
  126. </p>
  127. <a name="index-FILEHDR"></a>
  128. <a name="index-PHDRS-1"></a>
  129. <p>You may use the <code>FILEHDR</code> and <code>PHDRS</code> keywords after
  130. the program header type to further describe the contents of the segment.
  131. The <code>FILEHDR</code> keyword means that the segment should include the ELF
  132. file header. The <code>PHDRS</code> keyword means that the segment should
  133. include the ELF program headers themselves. If applied to a loadable
  134. segment (<code>PT_LOAD</code>), all prior loadable segments must have one of
  135. these keywords.
  136. </p>
  137. <p>The <var>type</var> may be one of the following. The numbers indicate the
  138. value of the keyword.
  139. </p>
  140. <dl compact="compact">
  141. <dt><code>PT_NULL</code> (0)</dt>
  142. <dd><p>Indicates an unused program header.
  143. </p>
  144. </dd>
  145. <dt><code>PT_LOAD</code> (1)</dt>
  146. <dd><p>Indicates that this program header describes a segment to be loaded from
  147. the file.
  148. </p>
  149. </dd>
  150. <dt><code>PT_DYNAMIC</code> (2)</dt>
  151. <dd><p>Indicates a segment where dynamic linking information can be found.
  152. </p>
  153. </dd>
  154. <dt><code>PT_INTERP</code> (3)</dt>
  155. <dd><p>Indicates a segment where the name of the program interpreter may be
  156. found.
  157. </p>
  158. </dd>
  159. <dt><code>PT_NOTE</code> (4)</dt>
  160. <dd><p>Indicates a segment holding note information.
  161. </p>
  162. </dd>
  163. <dt><code>PT_SHLIB</code> (5)</dt>
  164. <dd><p>A reserved program header type, defined but not specified by the ELF
  165. ABI.
  166. </p>
  167. </dd>
  168. <dt><code>PT_PHDR</code> (6)</dt>
  169. <dd><p>Indicates a segment where the program headers may be found.
  170. </p>
  171. </dd>
  172. <dt><code>PT_TLS</code> (7)</dt>
  173. <dd><p>Indicates a segment containing thread local storage.
  174. </p>
  175. </dd>
  176. <dt><var>expression</var></dt>
  177. <dd><p>An expression giving the numeric type of the program header. This may
  178. be used for types not defined above.
  179. </p></dd>
  180. </dl>
  181. <p>You can specify that a segment should be loaded at a particular address
  182. in memory by using an <code>AT</code> expression. This is identical to the
  183. <code>AT</code> command used as an output section attribute (see <a href="Output-Section-LMA.html#Output-Section-LMA">Output Section LMA</a>). The <code>AT</code> command for a program header overrides the
  184. output section attribute.
  185. </p>
  186. <p>The linker will normally set the segment flags based on the sections
  187. which comprise the segment. You may use the <code>FLAGS</code> keyword to
  188. explicitly specify the segment flags. The value of <var>flags</var> must be
  189. an integer. It is used to set the <code>p_flags</code> field of the program
  190. header.
  191. </p>
  192. <p>Here is an example of <code>PHDRS</code>. This shows a typical set of program
  193. headers used on a native ELF system.
  194. </p>
  195. <div class="example">
  196. <pre class="example">PHDRS
  197. {
  198. headers PT_PHDR PHDRS ;
  199. interp PT_INTERP ;
  200. text PT_LOAD FILEHDR PHDRS ;
  201. data PT_LOAD ;
  202. dynamic PT_DYNAMIC ;
  203. }
  204. SECTIONS
  205. {
  206. . = SIZEOF_HEADERS;
  207. .interp : { *(.interp) } :text :interp
  208. .text : { *(.text) } :text
  209. .rodata : { *(.rodata) } /* defaults to :text */
  210. &hellip;
  211. . = . + 0x1000; /* move to a new page in memory */
  212. .data : { *(.data) } :data
  213. .dynamic : { *(.dynamic) } :data :dynamic
  214. &hellip;
  215. }
  216. </pre></div>
  217. <hr>
  218. <div class="header">
  219. <p>
  220. Next: <a href="VERSION.html#VERSION" accesskey="n" rel="next">VERSION</a>, Previous: <a href="MEMORY.html#MEMORY" accesskey="p" rel="prev">MEMORY</a>, Up: <a href="Scripts.html#Scripts" accesskey="u" rel="up">Scripts</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>
  221. </div>
  222. </body>
  223. </html>