ldint.html 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  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 internals of the GNU linker ld.
  4. Copyright (C) 1992-2024 Free Software Foundation, Inc.
  5. Contributed by Cygnus Support.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with the
  9. Invariant Sections being "GNU General Public License" and "Funding
  10. Free Software", the Front-Cover texts being (a) (see below), and with
  11. the Back-Cover Texts being (b) (see below). A copy of the license is
  12. included in the section entitled "GNU Free Documentation License".
  13. (a) The FSF's Front-Cover Text is:
  14. A GNU Manual
  15. (b) The FSF's Back-Cover Text is:
  16. You have freedom to copy and modify this GNU Manual, like GNU
  17. software. Copies published by the Free Software Foundation raise
  18. funds for GNU development. -->
  19. <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
  20. <head>
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <title>Untitled Document</title>
  23. <meta name="description" content="Untitled Document">
  24. <meta name="keywords" content="Untitled Document">
  25. <meta name="resource-type" content="document">
  26. <meta name="distribution" content="global">
  27. <meta name="Generator" content="makeinfo">
  28. <link href="#Top" rel="start" title="Top">
  29. <link href="#SEC_Contents" rel="contents" title="Table of Contents">
  30. <style type="text/css">
  31. <!--
  32. a.summary-letter {text-decoration: none}
  33. blockquote.indentedblock {margin-right: 0em}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. kbd {font-style: oblique}
  38. pre.display {font-family: inherit}
  39. pre.format {font-family: inherit}
  40. pre.menu-comment {font-family: serif}
  41. pre.menu-preformatted {font-family: serif}
  42. span.nolinebreak {white-space: nowrap}
  43. span.roman {font-family: initial; font-weight: normal}
  44. span.sansserif {font-family: sans-serif; font-weight: normal}
  45. ul.no-bullet {list-style: none}
  46. -->
  47. </style>
  48. </head>
  49. <body lang="en">
  50. <span id="Top"></span><div class="header">
  51. <p>
  52. Next: <a href="#README" accesskey="n" rel="next">README</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  53. </div>
  54. <span id="SEC_Top"></span>
  55. <p>This file documents the internals of the GNU linker <code>ld</code>. It is a
  56. collection of miscellaneous information with little form at this point.
  57. Mostly, it is a repository into which you can put information about
  58. GNU <code>ld</code> as you discover it (or as you design changes to <code>ld</code>).
  59. </p>
  60. <p>This document is distributed under the terms of the GNU Free
  61. Documentation License. A copy of the license is included in the
  62. section entitled &quot;GNU Free Documentation License&quot;.
  63. </p>
  64. <table class="menu" border="0" cellspacing="0">
  65. <tr><td align="left" valign="top">&bull; <a href="#README" accesskey="1">README</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The README File
  66. </td></tr>
  67. <tr><td align="left" valign="top">&bull; <a href="#Emulations" accesskey="2">Emulations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How linker emulations are generated
  68. </td></tr>
  69. <tr><td align="left" valign="top">&bull; <a href="#Emulation-Walkthrough" accesskey="3">Emulation Walkthrough</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">A Walkthrough of a Typical Emulation
  70. </td></tr>
  71. <tr><td align="left" valign="top">&bull; <a href="#Architecture-Specific" accesskey="4">Architecture Specific</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Some Architecture Specific Notes
  72. </td></tr>
  73. <tr><td align="left" valign="top">&bull; <a href="#GNU-Free-Documentation-License" accesskey="5">GNU Free Documentation License</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">GNU Free Documentation License
  74. </td></tr>
  75. </table>
  76. <hr>
  77. <span id="README"></span><div class="header">
  78. <p>
  79. Next: <a href="#Emulations" accesskey="n" rel="next">Emulations</a>, Previous: <a href="#Top" accesskey="p" rel="prev">Top</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  80. </div>
  81. <span id="The-README-File"></span><h2 class="chapter">1 The <samp>README</samp> File</h2>
  82. <p>Check the <samp>README</samp> file; it often has useful information that does not
  83. appear anywhere else in the directory.
  84. </p>
  85. <hr>
  86. <span id="Emulations"></span><div class="header">
  87. <p>
  88. Next: <a href="#Emulation-Walkthrough" accesskey="n" rel="next">Emulation Walkthrough</a>, Previous: <a href="#README" accesskey="p" rel="prev">README</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  89. </div>
  90. <span id="How-linker-emulations-are-generated"></span><h2 class="chapter">2 How linker emulations are generated</h2>
  91. <p>Each linker target has an <em>emulation</em>. The emulation includes the
  92. default linker script, and certain emulations also modify certain types
  93. of linker behaviour.
  94. </p>
  95. <p>Emulations are created during the build process by the shell script
  96. <samp>genscripts.sh</samp>.
  97. </p>
  98. <p>The <samp>genscripts.sh</samp> script starts by reading a file in the
  99. <samp>emulparams</samp> directory. This is a shell script which sets various
  100. shell variables used by <samp>genscripts.sh</samp> and the other shell scripts
  101. it invokes.
  102. </p>
  103. <p>The <samp>genscripts.sh</samp> script will invoke a shell script in the
  104. <samp>scripttempl</samp> directory in order to create default linker scripts
  105. written in the linker command language. The <samp>scripttempl</samp> script
  106. will be invoked 5 (or, in some cases, 6) times, with different
  107. assignments to shell variables, to create different default scripts.
  108. The choice of script is made based on the command-line options.
  109. </p>
  110. <p>After creating the scripts, <samp>genscripts.sh</samp> will invoke yet another
  111. shell script, this time in the <samp>emultempl</samp> directory. That shell
  112. script will create the emulation source file, which contains C code.
  113. This C code permits the linker emulation to override various linker
  114. behaviours. Most targets use the generic emulation code, which is in
  115. <samp>emultempl/generic.em</samp>.
  116. </p>
  117. <p>To summarize, <samp>genscripts.sh</samp> reads three shell scripts: an
  118. emulation parameters script in the <samp>emulparams</samp> directory, a linker
  119. script generation script in the <samp>scripttempl</samp> directory, and an
  120. emulation source file generation script in the <samp>emultempl</samp>
  121. directory.
  122. </p>
  123. <p>For example, the Sun 4 linker sets up variables in
  124. <samp>emulparams/sun4.sh</samp>, creates linker scripts using
  125. <samp>scripttempl/aout.sc</samp>, and creates the emulation code using
  126. <samp>emultempl/sunos.em</samp>.
  127. </p>
  128. <p>Note that the linker can support several emulations simultaneously,
  129. depending upon how it is configured. An emulation can be selected with
  130. the <code>-m</code> option. The <code>-V</code> option will list all supported
  131. emulations.
  132. </p>
  133. <table class="menu" border="0" cellspacing="0">
  134. <tr><td align="left" valign="top">&bull; <a href="#emulation-parameters" accesskey="1">emulation parameters</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"><samp>emulparams</samp> scripts
  135. </td></tr>
  136. <tr><td align="left" valign="top">&bull; <a href="#linker-scripts" accesskey="2">linker scripts</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"><samp>scripttempl</samp> scripts
  137. </td></tr>
  138. <tr><td align="left" valign="top">&bull; <a href="#linker-emulations" accesskey="3">linker emulations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top"><samp>emultempl</samp> scripts
  139. </td></tr>
  140. </table>
  141. <hr>
  142. <span id="emulation-parameters"></span><div class="header">
  143. <p>
  144. Next: <a href="#linker-scripts" accesskey="n" rel="next">linker scripts</a>, Up: <a href="#Emulations" accesskey="u" rel="up">Emulations</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  145. </div>
  146. <span id="emulparams-scripts"></span><h3 class="section">2.1 <samp>emulparams</samp> scripts</h3>
  147. <p>Each target selects a particular file in the <samp>emulparams</samp> directory
  148. by setting the shell variable <code>targ_emul</code> in <samp>configure.tgt</samp>.
  149. This shell variable is used by the <samp>configure</samp> script to control
  150. building an emulation source file.
  151. </p>
  152. <p>Certain conventions are enforced. Suppose the <code>targ_emul</code> variable
  153. is set to <var>emul</var> in <samp>configure.tgt</samp>. The name of the emulation
  154. shell script will be <samp>emulparams/<var>emul</var>.sh</samp>. The
  155. <samp>Makefile</samp> must have a target named <samp>e<var>emul</var>.c</samp>; this
  156. target must depend upon <samp>emulparams/<var>emul</var>.sh</samp>, as well as the
  157. appropriate scripts in the <samp>scripttempl</samp> and <samp>emultempl</samp>
  158. directories. The <samp>Makefile</samp> target must invoke <code>GENSCRIPTS</code>
  159. with two arguments: <var>emul</var>, and the value of the make variable
  160. <code>tdir_<var>emul</var></code>. The value of the latter variable will be set by
  161. the <samp>configure</samp> script, and is used to set the default target
  162. directory to search.
  163. </p>
  164. <p>By convention, the <samp>emulparams/<var>emul</var>.sh</samp> shell script should
  165. only set shell variables. It may set shell variables which are to be
  166. interpreted by the <samp>scripttempl</samp> and the <samp>emultempl</samp> scripts.
  167. Certain shell variables are interpreted directly by the
  168. <samp>genscripts.sh</samp> script.
  169. </p>
  170. <p>Here is a list of shell variables interpreted by <samp>genscripts.sh</samp>,
  171. as well as some conventional shell variables interpreted by the
  172. <samp>scripttempl</samp> and <samp>emultempl</samp> scripts.
  173. </p>
  174. <dl compact="compact">
  175. <dt><code>SCRIPT_NAME</code></dt>
  176. <dd><p>This is the name of the <samp>scripttempl</samp> script to use. If
  177. <code>SCRIPT_NAME</code> is set to <var>script</var>, <samp>genscripts.sh</samp> will use
  178. the script <samp>scripttempl/<var>script</var>.sc</samp>.
  179. </p>
  180. </dd>
  181. <dt><code>TEMPLATE_NAME</code></dt>
  182. <dd><p>This is the name of the <samp>emultempl</samp> script to use. If
  183. <code>TEMPLATE_NAME</code> is set to <var>template</var>, <samp>genscripts.sh</samp> will
  184. use the script <samp>emultempl/<var>template</var>.em</samp>. If this variable is
  185. not set, the default value is &lsquo;<samp>generic</samp>&rsquo;.
  186. </p>
  187. </dd>
  188. <dt><code>GENERATE_SHLIB_SCRIPT</code></dt>
  189. <dd><p>If this is set to a nonempty string, <samp>genscripts.sh</samp> will invoke
  190. the <samp>scripttempl</samp> script an extra time to create a shared library
  191. script. <a href="#linker-scripts">linker scripts</a>.
  192. </p>
  193. </dd>
  194. <dt><code>OUTPUT_FORMAT</code></dt>
  195. <dd><p>This is normally set to indicate the BFD output format use (e.g.,
  196. &lsquo;<samp>&quot;a.out-sunos-big&quot;</samp>&rsquo;. The <samp>scripttempl</samp> script will normally
  197. use it in an <code>OUTPUT_FORMAT</code> expression in the linker script.
  198. </p>
  199. </dd>
  200. <dt><code>ARCH</code></dt>
  201. <dd><p>This is normally set to indicate the architecture to use (e.g.,
  202. &lsquo;<samp>sparc</samp>&rsquo;). The <samp>scripttempl</samp> script will normally use it in an
  203. <code>OUTPUT_ARCH</code> expression in the linker script.
  204. </p>
  205. </dd>
  206. <dt><code>ENTRY</code></dt>
  207. <dd><p>Some <samp>scripttempl</samp> scripts use this to set the entry address, in an
  208. <code>ENTRY</code> expression in the linker script.
  209. </p>
  210. </dd>
  211. <dt><code>TEXT_START_ADDR</code></dt>
  212. <dd><p>Some <samp>scripttempl</samp> scripts use this to set the start address of the
  213. &lsquo;<samp>.text</samp>&rsquo; section.
  214. </p>
  215. </dd>
  216. <dt><code>SEGMENT_SIZE</code></dt>
  217. <dd><p>The <samp>genscripts.sh</samp> script uses this to set the default value of
  218. <code>DATA_ALIGNMENT</code> when running the <samp>scripttempl</samp> script.
  219. </p>
  220. </dd>
  221. <dt><code>TARGET_PAGE_SIZE</code></dt>
  222. <dd><p>If <code>SEGMENT_SIZE</code> is not defined, the <samp>genscripts.sh</samp> script
  223. uses this to define it.
  224. </p>
  225. </dd>
  226. <dt><code>ALIGNMENT</code></dt>
  227. <dd><p>Some <samp>scripttempl</samp> scripts set this to a number to pass to
  228. <code>ALIGN</code> to set the required alignment for the <code>end</code> symbol.
  229. </p></dd>
  230. </dl>
  231. <hr>
  232. <span id="linker-scripts"></span><div class="header">
  233. <p>
  234. Next: <a href="#linker-emulations" accesskey="n" rel="next">linker emulations</a>, Previous: <a href="#emulation-parameters" accesskey="p" rel="prev">emulation parameters</a>, Up: <a href="#Emulations" accesskey="u" rel="up">Emulations</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  235. </div>
  236. <span id="scripttempl-scripts"></span><h3 class="section">2.2 <samp>scripttempl</samp> scripts</h3>
  237. <p>Each linker target uses a <samp>scripttempl</samp> script to generate the
  238. default linker scripts. The name of the <samp>scripttempl</samp> script is
  239. set by the <code>SCRIPT_NAME</code> variable in the <samp>emulparams</samp> script.
  240. If <code>SCRIPT_NAME</code> is set to <var>script</var>, <code>genscripts.sh</code> will
  241. invoke <samp>scripttempl/<var>script</var>.sc</samp>.
  242. </p>
  243. <p>The <samp>genscripts.sh</samp> script will invoke the <samp>scripttempl</samp>
  244. script 5 to 9 times. Each time it will set the shell variable
  245. <code>LD_FLAG</code> to a different value. When the linker is run, the
  246. options used will direct it to select a particular script. (Script
  247. selection is controlled by the <code>get_script</code> emulation entry point;
  248. this describes the conventional behaviour).
  249. </p>
  250. <p>The <samp>scripttempl</samp> script should just write a linker script, written
  251. in the linker command language, to standard output. If the emulation
  252. name&ndash;the name of the <samp>emulparams</samp> file without the <samp>.sc</samp>
  253. extension&ndash;is <var>emul</var>, then the output will be directed to
  254. <samp>ldscripts/<var>emul</var>.<var>extension</var></samp> in the build directory,
  255. where <var>extension</var> changes each time the <samp>scripttempl</samp> script is
  256. invoked.
  257. </p>
  258. <p>Here is the list of values assigned to <code>LD_FLAG</code>.
  259. </p>
  260. <dl compact="compact">
  261. <dt><code>(empty)</code></dt>
  262. <dd><p>The script generated is used by default (when none of the following
  263. cases apply). The output has an extension of <samp>.x</samp>.
  264. </p></dd>
  265. <dt><code>n</code></dt>
  266. <dd><p>The script generated is used when the linker is invoked with the
  267. <code>-n</code> option. The output has an extension of <samp>.xn</samp>.
  268. </p></dd>
  269. <dt><code>N</code></dt>
  270. <dd><p>The script generated is used when the linker is invoked with the
  271. <code>-N</code> option. The output has an extension of <samp>.xbn</samp>.
  272. </p></dd>
  273. <dt><code>r</code></dt>
  274. <dd><p>The script generated is used when the linker is invoked with the
  275. <code>-r</code> option. The output has an extension of <samp>.xr</samp>.
  276. </p></dd>
  277. <dt><code>u</code></dt>
  278. <dd><p>The script generated is used when the linker is invoked with the
  279. <code>-Ur</code> option. The output has an extension of <samp>.xu</samp>.
  280. </p></dd>
  281. <dt><code>shared</code></dt>
  282. <dd><p>The <samp>scripttempl</samp> script is only invoked with <code>LD_FLAG</code> set to
  283. this value if <code>GENERATE_SHLIB_SCRIPT</code> is defined in the
  284. <samp>emulparams</samp> file. The <samp>emultempl</samp> script must arrange to use
  285. this script at the appropriate time, normally when the linker is invoked
  286. with the <code>-shared</code> option. The output has an extension of
  287. <samp>.xs</samp>.
  288. </p></dd>
  289. <dt><code>c</code></dt>
  290. <dd><p>The <samp>scripttempl</samp> script is only invoked with <code>LD_FLAG</code> set to
  291. this value if <code>GENERATE_COMBRELOC_SCRIPT</code> is defined in the
  292. <samp>emulparams</samp> file or if <code>SCRIPT_NAME</code> is <code>elf</code>. The
  293. <samp>emultempl</samp> script must arrange to use this script at the appropriate
  294. time, normally when the linker is invoked with the <code>-z combreloc</code>
  295. option. The output has an extension of
  296. <samp>.xc</samp>.
  297. </p></dd>
  298. <dt><code>cshared</code></dt>
  299. <dd><p>The <samp>scripttempl</samp> script is only invoked with <code>LD_FLAG</code> set to
  300. this value if <code>GENERATE_COMBRELOC_SCRIPT</code> is defined in the
  301. <samp>emulparams</samp> file or if <code>SCRIPT_NAME</code> is <code>elf</code> and
  302. <code>GENERATE_SHLIB_SCRIPT</code> is defined in the <samp>emulparams</samp> file.
  303. The <samp>emultempl</samp> script must arrange to use this script at the
  304. appropriate time, normally when the linker is invoked with the <code>-shared
  305. -z combreloc</code> option. The output has an extension of <samp>.xsc</samp>.
  306. </p></dd>
  307. <dt><code>auto_import</code></dt>
  308. <dd><p>The <samp>scripttempl</samp> script is only invoked with <code>LD_FLAG</code> set to
  309. this value if <code>GENERATE_AUTO_IMPORT_SCRIPT</code> is defined in the
  310. <samp>emulparams</samp> file. The <samp>emultempl</samp> script must arrange to
  311. use this script at the appropriate time, normally when the linker is
  312. invoked with the <code>--enable-auto-import</code> option. The output has
  313. an extension of <samp>.xa</samp>.
  314. </p></dd>
  315. </dl>
  316. <p>Besides the shell variables set by the <samp>emulparams</samp> script, and the
  317. <code>LD_FLAG</code> variable, the <samp>genscripts.sh</samp> script will set
  318. certain variables for each run of the <samp>scripttempl</samp> script.
  319. </p>
  320. <dl compact="compact">
  321. <dt><code>RELOCATING</code></dt>
  322. <dd><p>This will be set to a non-empty string when the linker is doing a final
  323. relocation (e.g., all scripts other than <code>-r</code> and <code>-Ur</code>).
  324. </p>
  325. </dd>
  326. <dt><code>CONSTRUCTING</code></dt>
  327. <dd><p>This will be set to a non-empty string when the linker is building
  328. global constructor and destructor tables (e.g., all scripts other than
  329. <code>-r</code>).
  330. </p>
  331. </dd>
  332. <dt><code>DATA_ALIGNMENT</code></dt>
  333. <dd><p>This will be set to an <code>ALIGN</code> expression when the output should be
  334. page aligned, or to &lsquo;<samp>.</samp>&rsquo; when generating the <code>-N</code> script.
  335. </p>
  336. </dd>
  337. <dt><code>CREATE_SHLIB</code></dt>
  338. <dd><p>This will be set to a non-empty string when generating a <code>-shared</code>
  339. script.
  340. </p>
  341. </dd>
  342. <dt><code>COMBRELOC</code></dt>
  343. <dd><p>This will be set to a non-empty string when generating <code>-z combreloc</code>
  344. scripts to a temporary file name which can be used during script generation.
  345. </p></dd>
  346. </dl>
  347. <p>The conventional way to write a <samp>scripttempl</samp> script is to first
  348. set a few shell variables, and then write out a linker script using
  349. <code>cat</code> with a here document. The linker script will use variable
  350. substitutions, based on the above variables and those set in the
  351. <samp>emulparams</samp> script, to control its behaviour.
  352. </p>
  353. <p>When there are parts of the <samp>scripttempl</samp> script which should only
  354. be run when doing a final relocation, they should be enclosed within a
  355. variable substitution based on <code>RELOCATING</code>. For example, on many
  356. targets special symbols such as <code>_end</code> should be defined when doing
  357. a final link. Naturally, those symbols should not be defined when doing
  358. a relocatable link using <code>-r</code>. The <samp>scripttempl</samp> script
  359. could use a construct like this to define those symbols:
  360. </p><div class="example">
  361. <pre class="example"> ${RELOCATING+ _end = .;}
  362. </pre></div>
  363. <p>This will do the symbol assignment only if the <code>RELOCATING</code>
  364. variable is defined.
  365. </p>
  366. <p>The basic job of the linker script is to put the sections in the correct
  367. order, and at the correct memory addresses. For some targets, the
  368. linker script may have to do some other operations.
  369. </p>
  370. <p>For example, on most MIPS platforms, the linker is responsible for
  371. defining the special symbol <code>_gp</code>, used to initialize the
  372. <code>$gp</code> register. It must be set to the start of the small data
  373. section plus <code>0x8000</code>. Naturally, it should only be defined when
  374. doing a final relocation. This will typically be done like this:
  375. </p><div class="example">
  376. <pre class="example"> ${RELOCATING+ _gp = ALIGN(16) + 0x8000;}
  377. </pre></div>
  378. <p>This line would appear just before the sections which compose the small
  379. data section (&lsquo;<samp>.sdata</samp>&rsquo;, &lsquo;<samp>.sbss</samp>&rsquo;). All those sections would be
  380. contiguous in memory.
  381. </p>
  382. <p>Many COFF systems build constructor tables in the linker script. The
  383. compiler will arrange to output the address of each global constructor
  384. in a &lsquo;<samp>.ctor</samp>&rsquo; section, and the address of each global destructor in
  385. a &lsquo;<samp>.dtor</samp>&rsquo; section (this is done by defining
  386. <code>ASM_OUTPUT_CONSTRUCTOR</code> and <code>ASM_OUTPUT_DESTRUCTOR</code> in the
  387. <code>gcc</code> configuration files). The <code>gcc</code> runtime support
  388. routines expect the constructor table to be named <code>__CTOR_LIST__</code>.
  389. They expect it to be a list of words, with the first word being the
  390. count of the number of entries. There should be a trailing zero word.
  391. (Actually, the count may be -1 if the trailing word is present, and the
  392. trailing word may be omitted if the count is correct, but, as the
  393. <code>gcc</code> behaviour has changed slightly over the years, it is safest
  394. to provide both). Here is a typical way that might be handled in a
  395. <samp>scripttempl</samp> file.
  396. </p><div class="example">
  397. <pre class="example"> ${CONSTRUCTING+ __CTOR_LIST__ = .;}
  398. ${CONSTRUCTING+ LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)}
  399. ${CONSTRUCTING+ *(.ctors)}
  400. ${CONSTRUCTING+ LONG(0)}
  401. ${CONSTRUCTING+ __CTOR_END__ = .;}
  402. ${CONSTRUCTING+ __DTOR_LIST__ = .;}
  403. ${CONSTRUCTING+ LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)}
  404. ${CONSTRUCTING+ *(.dtors)}
  405. ${CONSTRUCTING+ LONG(0)}
  406. ${CONSTRUCTING+ __DTOR_END__ = .;}
  407. </pre></div>
  408. <p>The use of <code>CONSTRUCTING</code> ensures that these linker script commands
  409. will only appear when the linker is supposed to be building the
  410. constructor and destructor tables. This example is written for a target
  411. which uses 4 byte pointers.
  412. </p>
  413. <p>Embedded systems often need to set a stack address. This is normally
  414. best done by using the <code>PROVIDE</code> construct with a default stack
  415. address. This permits the user to easily override the stack address
  416. using the <code>--defsym</code> option. Here is an example:
  417. </p><div class="example">
  418. <pre class="example"> ${RELOCATING+ PROVIDE (__stack = 0x80000000);}
  419. </pre></div>
  420. <p>The value of the symbol <code>__stack</code> would then be used in the startup
  421. code to initialize the stack pointer.
  422. </p>
  423. <hr>
  424. <span id="linker-emulations"></span><div class="header">
  425. <p>
  426. Previous: <a href="#linker-scripts" accesskey="p" rel="prev">linker scripts</a>, Up: <a href="#Emulations" accesskey="u" rel="up">Emulations</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  427. </div>
  428. <span id="emultempl-scripts"></span><h3 class="section">2.3 <samp>emultempl</samp> scripts</h3>
  429. <p>Each linker target uses an <samp>emultempl</samp> script to generate the
  430. emulation code. The name of the <samp>emultempl</samp> script is set by the
  431. <code>TEMPLATE_NAME</code> variable in the <samp>emulparams</samp> script. If the
  432. <code>TEMPLATE_NAME</code> variable is not set, the default is
  433. &lsquo;<samp>generic</samp>&rsquo;. If the value of <code>TEMPLATE_NAME</code> is <var>template</var>,
  434. <samp>genscripts.sh</samp> will use <samp>emultempl/<var>template</var>.em</samp>.
  435. </p>
  436. <p>Most targets use the generic <samp>emultempl</samp> script,
  437. <samp>emultempl/generic.em</samp>. A different <samp>emultempl</samp> script is
  438. only needed if the linker must support unusual actions, such as linking
  439. against shared libraries.
  440. </p>
  441. <p>The <samp>emultempl</samp> script is normally written as a simple invocation
  442. of <code>cat</code> with a here document. The document will use a few
  443. variable substitutions. Typically each function names uses a
  444. substitution involving <code>EMULATION_NAME</code>, for ease of debugging when
  445. the linker supports multiple emulations.
  446. </p>
  447. <p>Every function and variable in the emitted file should be static. The
  448. only globally visible object must be named
  449. <code>ld_<var>EMULATION_NAME</var>_emulation</code>, where <var>EMULATION_NAME</var> is
  450. the name of the emulation set in <samp>configure.tgt</samp> (this is also the
  451. name of the <samp>emulparams</samp> file without the <samp>.sh</samp> extension).
  452. The <samp>genscripts.sh</samp> script will set the shell variable
  453. <code>EMULATION_NAME</code> before invoking the <samp>emultempl</samp> script.
  454. </p>
  455. <p>The <code>ld_<var>EMULATION_NAME</var>_emulation</code> variable must be a
  456. <code>struct ld_emulation_xfer_struct</code>, as defined in <samp>ldemul.h</samp>.
  457. It defines a set of function pointers which are invoked by the linker,
  458. as well as strings for the emulation name (normally set from the shell
  459. variable <code>EMULATION_NAME</code> and the default BFD target name (normally
  460. set from the shell variable <code>OUTPUT_FORMAT</code> which is normally set
  461. by the <samp>emulparams</samp> file).
  462. </p>
  463. <p>The <samp>genscripts.sh</samp> script will set the shell variable
  464. <code>COMPILE_IN</code> when it invokes the <samp>emultempl</samp> script for the
  465. default emulation. In this case, the <samp>emultempl</samp> script should
  466. include the linker scripts directly, and return them from the
  467. <code>get_scripts</code> entry point. When the emulation is not the default,
  468. the <code>get_scripts</code> entry point should just return a file name. See
  469. <samp>emultempl/generic.em</samp> for an example of how this is done.
  470. </p>
  471. <p>At some point, the linker emulation entry points should be documented.
  472. </p>
  473. <hr>
  474. <span id="Emulation-Walkthrough"></span><div class="header">
  475. <p>
  476. Next: <a href="#Architecture-Specific" accesskey="n" rel="next">Architecture Specific</a>, Previous: <a href="#Emulations" accesskey="p" rel="prev">Emulations</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  477. </div>
  478. <span id="A-Walkthrough-of-a-Typical-Emulation"></span><h2 class="chapter">3 A Walkthrough of a Typical Emulation</h2>
  479. <p>This chapter is to help people who are new to the way emulations
  480. interact with the linker, or who are suddenly thrust into the position
  481. of having to work with existing emulations. It will discuss the files
  482. you need to be aware of. It will tell you when the given &quot;hooks&quot; in
  483. the emulation will be called. It will, hopefully, give you enough
  484. information about when and how things happen that you&rsquo;ll be able to
  485. get by. As always, the source is the definitive reference to this.
  486. </p>
  487. <p>The starting point for the linker is in <samp>ldmain.c</samp> where
  488. <code>main</code> is defined. The bulk of the code that&rsquo;s emulation
  489. specific will initially be in <code>emultempl/<var>emulation</var>.em</code> but
  490. will end up in <code>e<var>emulation</var>.c</code> when the build is done.
  491. Most of the work to select and interface with emulations is in
  492. <code>ldemul.h</code> and <code>ldemul.c</code>. Specifically, <code>ldemul.h</code>
  493. defines the <code>ld_emulation_xfer_struct</code> structure your emulation
  494. exports.
  495. </p>
  496. <p>Your emulation file exports a symbol
  497. <code>ld_<var>EMULATION_NAME</var>_emulation</code>. If your emulation is
  498. selected (it usually is, since usually there&rsquo;s only one),
  499. <code>ldemul.c</code> sets the variable <var>ld_emulation</var> to point to it.
  500. <code>ldemul.c</code> also defines a number of API functions that interface
  501. to your emulation, like <code>ldemul_after_parse</code> which simply calls
  502. your <code>ld_<var>EMULATION</var>_emulation.after_parse</code> function. For
  503. the rest of this section, the functions will be mentioned, but you
  504. should assume the indirect reference to your emulation also.
  505. </p>
  506. <p>We will also skip or gloss over parts of the link process that don&rsquo;t
  507. relate to emulations, like setting up internationalization.
  508. </p>
  509. <p>After initialization, <code>main</code> selects an emulation by pre-scanning
  510. the command-line arguments. It calls <code>ldemul_choose_target</code> to
  511. choose a target. If you set <code>choose_target</code> to
  512. <code>ldemul_default_target</code>, it picks your <code>target_name</code> by
  513. default.
  514. </p>
  515. <p><code>main</code> calls <code>ldemul_before_parse</code>, then <code>parse_args</code>.
  516. <code>parse_args</code> calls <code>ldemul_parse_args</code> for each arg, which
  517. must update the <code>getopt</code> globals if it recognizes the argument.
  518. If the emulation doesn&rsquo;t recognize it, then parse_args checks to see
  519. if it recognizes it.
  520. </p>
  521. <p>Now that the emulation has had access to all its command-line options,
  522. <code>main</code> calls <code>ldemul_set_symbols</code>. This can be used for any
  523. initialization that may be affected by options. It is also supposed
  524. to set up any variables needed by the emulation script.
  525. </p>
  526. <p><code>main</code> now calls <code>ldemul_get_script</code> to get the emulation
  527. script to use (based on arguments, no doubt, see <a href="#Emulations">Emulations</a>) and
  528. runs it. While parsing, <code>ldgram.y</code> may call <code>ldemul_hll</code> or
  529. <code>ldemul_syslib</code> to handle the <code>HLL</code> or <code>SYSLIB</code>
  530. commands. It may call <code>ldemul_unrecognized_file</code> if you asked
  531. the linker to link a file it doesn&rsquo;t recognize. It will call
  532. <code>ldemul_recognized_file</code> for each file it does recognize, in case
  533. the emulation wants to handle some files specially. All the while,
  534. it&rsquo;s loading the files (possibly calling
  535. <code>ldemul_open_dynamic_archive</code>) and symbols and stuff. After it&rsquo;s
  536. done reading the script, <code>main</code> calls <code>ldemul_after_parse</code>.
  537. Use the after-parse hook to set up anything that depends on stuff the
  538. script might have set up, like the entry point.
  539. </p>
  540. <p><code>main</code> next calls <code>lang_process</code> in <code>ldlang.c</code>. This
  541. appears to be the main core of the linking itself, as far as emulation
  542. hooks are concerned(*). It first opens the output file&rsquo;s BFD, calling
  543. <code>ldemul_set_output_arch</code>, and calls
  544. <code>ldemul_create_output_section_statements</code> in case you need to use
  545. other means to find or create object files (i.e. shared libraries
  546. found on a path, or fake stub objects). Despite the name, nobody
  547. creates output sections here.
  548. </p>
  549. <p>(*) In most cases, the BFD library does the bulk of the actual
  550. linking, handling symbol tables, symbol resolution, relocations, and
  551. building the final output file. See the BFD reference for all the
  552. details. Your emulation is usually concerned more with managing
  553. things at the file and section level, like &quot;put this here, add this
  554. section&quot;, etc.
  555. </p>
  556. <p>Next, the objects to be linked are opened and BFDs created for them,
  557. and <code>ldemul_after_open</code> is called. At this point, you have all
  558. the objects and symbols loaded, but none of the data has been placed
  559. yet.
  560. </p>
  561. <p>Next comes the Big Linking Thingy (except for the parts BFD does).
  562. All input sections are mapped to output sections according to the
  563. script. If a section doesn&rsquo;t get mapped by default,
  564. <code>ldemul_place_orphan</code> will get called to figure out where it goes.
  565. Next it figures out the offsets for each section, calling
  566. <code>ldemul_before_allocation</code> before and
  567. <code>ldemul_after_allocation</code> after deciding where each input section
  568. ends up in the output sections.
  569. </p>
  570. <p>The last part of <code>lang_process</code> is to figure out all the symbols&rsquo;
  571. values. After assigning final values to the symbols,
  572. <code>ldemul_finish</code> is called, and after that, any undefined symbols
  573. are turned into fatal errors.
  574. </p>
  575. <p>OK, back to <code>main</code>, which calls <code>ldwrite</code> in
  576. <samp>ldwrite.c</samp>. <code>ldwrite</code> calls BFD&rsquo;s final_link, which does
  577. all the relocation fixups and writes the output bfd to disk, and we&rsquo;re
  578. done.
  579. </p>
  580. <p>In summary,
  581. </p>
  582. <ul>
  583. <li> <code>main()</code> in <samp>ldmain.c</samp>
  584. </li><li> <samp>emultempl/<var>EMULATION</var>.em</samp> has your code
  585. </li><li> <code>ldemul_choose_target</code> (defaults to your <code>target_name</code>)
  586. </li><li> <code>ldemul_before_parse</code>
  587. </li><li> Parse argv, calls <code>ldemul_parse_args</code> for each
  588. </li><li> <code>ldemul_set_symbols</code>
  589. </li><li> <code>ldemul_get_script</code>
  590. </li><li> parse script
  591. <ul>
  592. <li> may call <code>ldemul_hll</code> or <code>ldemul_syslib</code>
  593. </li><li> may call <code>ldemul_open_dynamic_archive</code>
  594. </li></ul>
  595. </li><li> <code>ldemul_after_parse</code>
  596. </li><li> <code>lang_process()</code> in <samp>ldlang.c</samp>
  597. <ul>
  598. <li> create <code>output_bfd</code>
  599. </li><li> <code>ldemul_set_output_arch</code>
  600. </li><li> <code>ldemul_create_output_section_statements</code>
  601. </li><li> read objects, create input bfds - all symbols exist, but have no values
  602. </li><li> may call <code>ldemul_unrecognized_file</code>
  603. </li><li> will call <code>ldemul_recognized_file</code>
  604. </li><li> <code>ldemul_after_open</code>
  605. </li><li> map input sections to output sections
  606. </li><li> may call <code>ldemul_place_orphan</code> for remaining sections
  607. </li><li> <code>ldemul_before_allocation</code>
  608. </li><li> gives input sections offsets into output sections, places output sections
  609. </li><li> <code>ldemul_after_allocation</code> - section addresses valid
  610. </li><li> assigns values to symbols
  611. </li><li> <code>ldemul_finish</code> - symbol values valid
  612. </li></ul>
  613. </li><li> output bfd is written to disk
  614. </li></ul>
  615. <hr>
  616. <span id="Architecture-Specific"></span><div class="header">
  617. <p>
  618. Next: <a href="#GNU-Free-Documentation-License" accesskey="n" rel="next">GNU Free Documentation License</a>, Previous: <a href="#Emulation-Walkthrough" accesskey="p" rel="prev">Emulation Walkthrough</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  619. </div>
  620. <span id="Some-Architecture-Specific-Notes"></span><h2 class="chapter">4 Some Architecture Specific Notes</h2>
  621. <p>This is the place for notes on the behavior of <code>ld</code> on
  622. specific platforms. Currently, only Intel x86 is documented (and
  623. of that, only the auto-import behavior for DLLs).
  624. </p>
  625. <table class="menu" border="0" cellspacing="0">
  626. <tr><td align="left" valign="top">&bull; <a href="#ix86" accesskey="1">ix86</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Intel x86
  627. </td></tr>
  628. </table>
  629. <hr>
  630. <span id="ix86"></span><div class="header">
  631. <p>
  632. Up: <a href="#Architecture-Specific" accesskey="u" rel="up">Architecture Specific</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  633. </div>
  634. <span id="Intel-x86"></span><h3 class="section">4.1 Intel x86</h3>
  635. <dl compact="compact">
  636. <dd><p><code>ld</code> can create DLLs that operate with various runtimes available
  637. on a common x86 operating system. These runtimes include native (using
  638. the mingw &quot;platform&quot;), cygwin, and pw.
  639. </p>
  640. </dd>
  641. <dt><em>auto-import from DLLs</em></dt>
  642. <dd><ol>
  643. <li> With this feature on, DLL clients can import variables from DLL
  644. without any concern from their side (for example, without any source
  645. code modifications). Auto-import can be enabled using the
  646. <code>--enable-auto-import</code> flag, or disabled via the
  647. <code>--disable-auto-import</code> flag. Auto-import is disabled by default.
  648. </li><li> This is done completely in bounds of the PE specification (to be fair,
  649. there&rsquo;s a minor violation of the spec at one point, but in practice
  650. auto-import works on all known variants of that common x86 operating
  651. system) So, the resulting DLL can be used with any other PE
  652. compiler/linker.
  653. </li><li> Auto-import is fully compatible with standard import method, in which
  654. variables are decorated using attribute modifiers. Libraries of either
  655. type may be mixed together.
  656. </li><li> Overhead (space): 8 bytes per imported symbol, plus 20 for each
  657. reference to it; Overhead (load time): negligible; Overhead
  658. (virtual/physical memory): should be less than effect of DLL
  659. relocation.
  660. </li></ol>
  661. <p>Motivation
  662. </p>
  663. <p>The obvious and only way to get rid of dllimport insanity is
  664. to make client access variable directly in the DLL, bypassing
  665. the extra dereference imposed by ordinary DLL runtime linking.
  666. I.e., whenever client contains something like
  667. </p>
  668. <p><code>mov dll_var,%eax,</code>
  669. </p>
  670. <p>address of dll_var in the command should be relocated to point
  671. into loaded DLL. The aim is to make OS loader do so, and than
  672. make ld help with that. Import section of PE made following
  673. way: there&rsquo;s a vector of structures each describing imports
  674. from particular DLL. Each such structure points to two other
  675. parallel vectors: one holding imported names, and one which
  676. will hold address of corresponding imported name. So, the
  677. solution is de-vectorize these structures, making import
  678. locations be sparse and pointing directly into code.
  679. </p>
  680. <p>Implementation
  681. </p>
  682. <p>For each reference of data symbol to be imported from DLL (to
  683. set of which belong symbols with name &lt;sym&gt;, if __imp_&lt;sym&gt; is
  684. found in implib), the import fixup entry is generated. That
  685. entry is of type IMAGE_IMPORT_DESCRIPTOR and stored in .idata$3
  686. subsection. Each fixup entry contains pointer to symbol&rsquo;s address
  687. within .text section (marked with __fuN_&lt;sym&gt; symbol, where N is
  688. integer), pointer to DLL name (so, DLL name is referenced by
  689. multiple entries), and pointer to symbol name thunk. Symbol name
  690. thunk is singleton vector (__nm_th_&lt;symbol&gt;) pointing to
  691. IMAGE_IMPORT_BY_NAME structure (__nm_&lt;symbol&gt;) directly containing
  692. imported name. Here comes that &quot;om the edge&quot; problem mentioned above:
  693. PE specification rambles that name vector (OriginalFirstThunk) should
  694. run in parallel with addresses vector (FirstThunk), i.e. that they
  695. should have same number of elements and terminated with zero. We violate
  696. this, since FirstThunk points directly into machine code. But in
  697. practice, OS loader implemented the sane way: it goes thru
  698. OriginalFirstThunk and puts addresses to FirstThunk, not something
  699. else. It once again should be noted that dll and symbol name
  700. structures are reused across fixup entries and should be there
  701. anyway to support standard import stuff, so sustained overhead is
  702. 20 bytes per reference. Other question is whether having several
  703. IMAGE_IMPORT_DESCRIPTORS for the same DLL is possible. Answer is yes,
  704. it is done even by native compiler/linker (libth32&rsquo;s functions are in
  705. fact resident in windows9x kernel32.dll, so if you use it, you have
  706. two IMAGE_IMPORT_DESCRIPTORS for kernel32.dll). Yet other question is
  707. whether referencing the same PE structures several times is valid.
  708. The answer is why not, prohibiting that (detecting violation) would
  709. require more work on behalf of loader than not doing it.
  710. </p>
  711. </dd>
  712. </dl>
  713. <hr>
  714. <span id="GNU-Free-Documentation-License"></span><div class="header">
  715. <p>
  716. Previous: <a href="#Architecture-Specific" accesskey="p" rel="prev">Architecture Specific</a>, Up: <a href="#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p>
  717. </div>
  718. <span id="GNU-Free-Documentation-License-1"></span><h2 class="chapter">5 GNU Free Documentation License</h2>
  719. <div align="center">Version 1.3, 3 November 2008
  720. </div>
  721. <div class="display">
  722. <pre class="display">Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
  723. <a href="http://fsf.org/">http://fsf.org/</a>
  724. Everyone is permitted to copy and distribute verbatim copies
  725. of this license document, but changing it is not allowed.
  726. </pre></div>
  727. <ol start="0">
  728. <li> PREAMBLE
  729. <p>The purpose of this License is to make a manual, textbook, or other
  730. functional and useful document <em>free</em> in the sense of freedom: to
  731. assure everyone the effective freedom to copy and redistribute it,
  732. with or without modifying it, either commercially or noncommercially.
  733. Secondarily, this License preserves for the author and publisher a way
  734. to get credit for their work, while not being considered responsible
  735. for modifications made by others.
  736. </p>
  737. <p>This License is a kind of &ldquo;copyleft&rdquo;, which means that derivative
  738. works of the document must themselves be free in the same sense. It
  739. complements the GNU General Public License, which is a copyleft
  740. license designed for free software.
  741. </p>
  742. <p>We have designed this License in order to use it for manuals for free
  743. software, because free software needs free documentation: a free
  744. program should come with manuals providing the same freedoms that the
  745. software does. But this License is not limited to software manuals;
  746. it can be used for any textual work, regardless of subject matter or
  747. whether it is published as a printed book. We recommend this License
  748. principally for works whose purpose is instruction or reference.
  749. </p>
  750. </li><li> APPLICABILITY AND DEFINITIONS
  751. <p>This License applies to any manual or other work, in any medium, that
  752. contains a notice placed by the copyright holder saying it can be
  753. distributed under the terms of this License. Such a notice grants a
  754. world-wide, royalty-free license, unlimited in duration, to use that
  755. work under the conditions stated herein. The &ldquo;Document&rdquo;, below,
  756. refers to any such manual or work. Any member of the public is a
  757. licensee, and is addressed as &ldquo;you&rdquo;. You accept the license if you
  758. copy, modify or distribute the work in a way requiring permission
  759. under copyright law.
  760. </p>
  761. <p>A &ldquo;Modified Version&rdquo; of the Document means any work containing the
  762. Document or a portion of it, either copied verbatim, or with
  763. modifications and/or translated into another language.
  764. </p>
  765. <p>A &ldquo;Secondary Section&rdquo; is a named appendix or a front-matter section
  766. of the Document that deals exclusively with the relationship of the
  767. publishers or authors of the Document to the Document&rsquo;s overall
  768. subject (or to related matters) and contains nothing that could fall
  769. directly within that overall subject. (Thus, if the Document is in
  770. part a textbook of mathematics, a Secondary Section may not explain
  771. any mathematics.) The relationship could be a matter of historical
  772. connection with the subject or with related matters, or of legal,
  773. commercial, philosophical, ethical or political position regarding
  774. them.
  775. </p>
  776. <p>The &ldquo;Invariant Sections&rdquo; are certain Secondary Sections whose titles
  777. are designated, as being those of Invariant Sections, in the notice
  778. that says that the Document is released under this License. If a
  779. section does not fit the above definition of Secondary then it is not
  780. allowed to be designated as Invariant. The Document may contain zero
  781. Invariant Sections. If the Document does not identify any Invariant
  782. Sections then there are none.
  783. </p>
  784. <p>The &ldquo;Cover Texts&rdquo; are certain short passages of text that are listed,
  785. as Front-Cover Texts or Back-Cover Texts, in the notice that says that
  786. the Document is released under this License. A Front-Cover Text may
  787. be at most 5 words, and a Back-Cover Text may be at most 25 words.
  788. </p>
  789. <p>A &ldquo;Transparent&rdquo; copy of the Document means a machine-readable copy,
  790. represented in a format whose specification is available to the
  791. general public, that is suitable for revising the document
  792. straightforwardly with generic text editors or (for images composed of
  793. pixels) generic paint programs or (for drawings) some widely available
  794. drawing editor, and that is suitable for input to text formatters or
  795. for automatic translation to a variety of formats suitable for input
  796. to text formatters. A copy made in an otherwise Transparent file
  797. format whose markup, or absence of markup, has been arranged to thwart
  798. or discourage subsequent modification by readers is not Transparent.
  799. An image format is not Transparent if used for any substantial amount
  800. of text. A copy that is not &ldquo;Transparent&rdquo; is called &ldquo;Opaque&rdquo;.
  801. </p>
  802. <p>Examples of suitable formats for Transparent copies include plain
  803. <small>ASCII</small> without markup, Texinfo input format, LaTeX input
  804. format, <acronym>SGML</acronym> or <acronym>XML</acronym> using a publicly available
  805. <acronym>DTD</acronym>, and standard-conforming simple <acronym>HTML</acronym>,
  806. PostScript or <acronym>PDF</acronym> designed for human modification. Examples
  807. of transparent image formats include <acronym>PNG</acronym>, <acronym>XCF</acronym> and
  808. <acronym>JPG</acronym>. Opaque formats include proprietary formats that can be
  809. read and edited only by proprietary word processors, <acronym>SGML</acronym> or
  810. <acronym>XML</acronym> for which the <acronym>DTD</acronym> and/or processing tools are
  811. not generally available, and the machine-generated <acronym>HTML</acronym>,
  812. PostScript or <acronym>PDF</acronym> produced by some word processors for
  813. output purposes only.
  814. </p>
  815. <p>The &ldquo;Title Page&rdquo; means, for a printed book, the title page itself,
  816. plus such following pages as are needed to hold, legibly, the material
  817. this License requires to appear in the title page. For works in
  818. formats which do not have any title page as such, &ldquo;Title Page&rdquo; means
  819. the text near the most prominent appearance of the work&rsquo;s title,
  820. preceding the beginning of the body of the text.
  821. </p>
  822. <p>The &ldquo;publisher&rdquo; means any person or entity that distributes copies
  823. of the Document to the public.
  824. </p>
  825. <p>A section &ldquo;Entitled XYZ&rdquo; means a named subunit of the Document whose
  826. title either is precisely XYZ or contains XYZ in parentheses following
  827. text that translates XYZ in another language. (Here XYZ stands for a
  828. specific section name mentioned below, such as &ldquo;Acknowledgements&rdquo;,
  829. &ldquo;Dedications&rdquo;, &ldquo;Endorsements&rdquo;, or &ldquo;History&rdquo;.) To &ldquo;Preserve the Title&rdquo;
  830. of such a section when you modify the Document means that it remains a
  831. section &ldquo;Entitled XYZ&rdquo; according to this definition.
  832. </p>
  833. <p>The Document may include Warranty Disclaimers next to the notice which
  834. states that this License applies to the Document. These Warranty
  835. Disclaimers are considered to be included by reference in this
  836. License, but only as regards disclaiming warranties: any other
  837. implication that these Warranty Disclaimers may have is void and has
  838. no effect on the meaning of this License.
  839. </p>
  840. </li><li> VERBATIM COPYING
  841. <p>You may copy and distribute the Document in any medium, either
  842. commercially or noncommercially, provided that this License, the
  843. copyright notices, and the license notice saying this License applies
  844. to the Document are reproduced in all copies, and that you add no other
  845. conditions whatsoever to those of this License. You may not use
  846. technical measures to obstruct or control the reading or further
  847. copying of the copies you make or distribute. However, you may accept
  848. compensation in exchange for copies. If you distribute a large enough
  849. number of copies you must also follow the conditions in section 3.
  850. </p>
  851. <p>You may also lend copies, under the same conditions stated above, and
  852. you may publicly display copies.
  853. </p>
  854. </li><li> COPYING IN QUANTITY
  855. <p>If you publish printed copies (or copies in media that commonly have
  856. printed covers) of the Document, numbering more than 100, and the
  857. Document&rsquo;s license notice requires Cover Texts, you must enclose the
  858. copies in covers that carry, clearly and legibly, all these Cover
  859. Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on
  860. the back cover. Both covers must also clearly and legibly identify
  861. you as the publisher of these copies. The front cover must present
  862. the full title with all words of the title equally prominent and
  863. visible. You may add other material on the covers in addition.
  864. Copying with changes limited to the covers, as long as they preserve
  865. the title of the Document and satisfy these conditions, can be treated
  866. as verbatim copying in other respects.
  867. </p>
  868. <p>If the required texts for either cover are too voluminous to fit
  869. legibly, you should put the first ones listed (as many as fit
  870. reasonably) on the actual cover, and continue the rest onto adjacent
  871. pages.
  872. </p>
  873. <p>If you publish or distribute Opaque copies of the Document numbering
  874. more than 100, you must either include a machine-readable Transparent
  875. copy along with each Opaque copy, or state in or with each Opaque copy
  876. a computer-network location from which the general network-using
  877. public has access to download using public-standard network protocols
  878. a complete Transparent copy of the Document, free of added material.
  879. If you use the latter option, you must take reasonably prudent steps,
  880. when you begin distribution of Opaque copies in quantity, to ensure
  881. that this Transparent copy will remain thus accessible at the stated
  882. location until at least one year after the last time you distribute an
  883. Opaque copy (directly or through your agents or retailers) of that
  884. edition to the public.
  885. </p>
  886. <p>It is requested, but not required, that you contact the authors of the
  887. Document well before redistributing any large number of copies, to give
  888. them a chance to provide you with an updated version of the Document.
  889. </p>
  890. </li><li> MODIFICATIONS
  891. <p>You may copy and distribute a Modified Version of the Document under
  892. the conditions of sections 2 and 3 above, provided that you release
  893. the Modified Version under precisely this License, with the Modified
  894. Version filling the role of the Document, thus licensing distribution
  895. and modification of the Modified Version to whoever possesses a copy
  896. of it. In addition, you must do these things in the Modified Version:
  897. </p>
  898. <ol type="A" start="1">
  899. <li> Use in the Title Page (and on the covers, if any) a title distinct
  900. from that of the Document, and from those of previous versions
  901. (which should, if there were any, be listed in the History section
  902. of the Document). You may use the same title as a previous version
  903. if the original publisher of that version gives permission.
  904. </li><li> List on the Title Page, as authors, one or more persons or entities
  905. responsible for authorship of the modifications in the Modified
  906. Version, together with at least five of the principal authors of the
  907. Document (all of its principal authors, if it has fewer than five),
  908. unless they release you from this requirement.
  909. </li><li> State on the Title page the name of the publisher of the
  910. Modified Version, as the publisher.
  911. </li><li> Preserve all the copyright notices of the Document.
  912. </li><li> Add an appropriate copyright notice for your modifications
  913. adjacent to the other copyright notices.
  914. </li><li> Include, immediately after the copyright notices, a license notice
  915. giving the public permission to use the Modified Version under the
  916. terms of this License, in the form shown in the Addendum below.
  917. </li><li> Preserve in that license notice the full lists of Invariant Sections
  918. and required Cover Texts given in the Document&rsquo;s license notice.
  919. </li><li> Include an unaltered copy of this License.
  920. </li><li> Preserve the section Entitled &ldquo;History&rdquo;, Preserve its Title, and add
  921. to it an item stating at least the title, year, new authors, and
  922. publisher of the Modified Version as given on the Title Page. If
  923. there is no section Entitled &ldquo;History&rdquo; in the Document, create one
  924. stating the title, year, authors, and publisher of the Document as
  925. given on its Title Page, then add an item describing the Modified
  926. Version as stated in the previous sentence.
  927. </li><li> Preserve the network location, if any, given in the Document for
  928. public access to a Transparent copy of the Document, and likewise
  929. the network locations given in the Document for previous versions
  930. it was based on. These may be placed in the &ldquo;History&rdquo; section.
  931. You may omit a network location for a work that was published at
  932. least four years before the Document itself, or if the original
  933. publisher of the version it refers to gives permission.
  934. </li><li> For any section Entitled &ldquo;Acknowledgements&rdquo; or &ldquo;Dedications&rdquo;, Preserve
  935. the Title of the section, and preserve in the section all the
  936. substance and tone of each of the contributor acknowledgements and/or
  937. dedications given therein.
  938. </li><li> Preserve all the Invariant Sections of the Document,
  939. unaltered in their text and in their titles. Section numbers
  940. or the equivalent are not considered part of the section titles.
  941. </li><li> Delete any section Entitled &ldquo;Endorsements&rdquo;. Such a section
  942. may not be included in the Modified Version.
  943. </li><li> Do not retitle any existing section to be Entitled &ldquo;Endorsements&rdquo; or
  944. to conflict in title with any Invariant Section.
  945. </li><li> Preserve any Warranty Disclaimers.
  946. </li></ol>
  947. <p>If the Modified Version includes new front-matter sections or
  948. appendices that qualify as Secondary Sections and contain no material
  949. copied from the Document, you may at your option designate some or all
  950. of these sections as invariant. To do this, add their titles to the
  951. list of Invariant Sections in the Modified Version&rsquo;s license notice.
  952. These titles must be distinct from any other section titles.
  953. </p>
  954. <p>You may add a section Entitled &ldquo;Endorsements&rdquo;, provided it contains
  955. nothing but endorsements of your Modified Version by various
  956. parties&mdash;for example, statements of peer review or that the text has
  957. been approved by an organization as the authoritative definition of a
  958. standard.
  959. </p>
  960. <p>You may add a passage of up to five words as a Front-Cover Text, and a
  961. passage of up to 25 words as a Back-Cover Text, to the end of the list
  962. of Cover Texts in the Modified Version. Only one passage of
  963. Front-Cover Text and one of Back-Cover Text may be added by (or
  964. through arrangements made by) any one entity. If the Document already
  965. includes a cover text for the same cover, previously added by you or
  966. by arrangement made by the same entity you are acting on behalf of,
  967. you may not add another; but you may replace the old one, on explicit
  968. permission from the previous publisher that added the old one.
  969. </p>
  970. <p>The author(s) and publisher(s) of the Document do not by this License
  971. give permission to use their names for publicity for or to assert or
  972. imply endorsement of any Modified Version.
  973. </p>
  974. </li><li> COMBINING DOCUMENTS
  975. <p>You may combine the Document with other documents released under this
  976. License, under the terms defined in section 4 above for modified
  977. versions, provided that you include in the combination all of the
  978. Invariant Sections of all of the original documents, unmodified, and
  979. list them all as Invariant Sections of your combined work in its
  980. license notice, and that you preserve all their Warranty Disclaimers.
  981. </p>
  982. <p>The combined work need only contain one copy of this License, and
  983. multiple identical Invariant Sections may be replaced with a single
  984. copy. If there are multiple Invariant Sections with the same name but
  985. different contents, make the title of each such section unique by
  986. adding at the end of it, in parentheses, the name of the original
  987. author or publisher of that section if known, or else a unique number.
  988. Make the same adjustment to the section titles in the list of
  989. Invariant Sections in the license notice of the combined work.
  990. </p>
  991. <p>In the combination, you must combine any sections Entitled &ldquo;History&rdquo;
  992. in the various original documents, forming one section Entitled
  993. &ldquo;History&rdquo;; likewise combine any sections Entitled &ldquo;Acknowledgements&rdquo;,
  994. and any sections Entitled &ldquo;Dedications&rdquo;. You must delete all
  995. sections Entitled &ldquo;Endorsements.&rdquo;
  996. </p>
  997. </li><li> COLLECTIONS OF DOCUMENTS
  998. <p>You may make a collection consisting of the Document and other documents
  999. released under this License, and replace the individual copies of this
  1000. License in the various documents with a single copy that is included in
  1001. the collection, provided that you follow the rules of this License for
  1002. verbatim copying of each of the documents in all other respects.
  1003. </p>
  1004. <p>You may extract a single document from such a collection, and distribute
  1005. it individually under this License, provided you insert a copy of this
  1006. License into the extracted document, and follow this License in all
  1007. other respects regarding verbatim copying of that document.
  1008. </p>
  1009. </li><li> AGGREGATION WITH INDEPENDENT WORKS
  1010. <p>A compilation of the Document or its derivatives with other separate
  1011. and independent documents or works, in or on a volume of a storage or
  1012. distribution medium, is called an &ldquo;aggregate&rdquo; if the copyright
  1013. resulting from the compilation is not used to limit the legal rights
  1014. of the compilation&rsquo;s users beyond what the individual works permit.
  1015. When the Document is included in an aggregate, this License does not
  1016. apply to the other works in the aggregate which are not themselves
  1017. derivative works of the Document.
  1018. </p>
  1019. <p>If the Cover Text requirement of section 3 is applicable to these
  1020. copies of the Document, then if the Document is less than one half of
  1021. the entire aggregate, the Document&rsquo;s Cover Texts may be placed on
  1022. covers that bracket the Document within the aggregate, or the
  1023. electronic equivalent of covers if the Document is in electronic form.
  1024. Otherwise they must appear on printed covers that bracket the whole
  1025. aggregate.
  1026. </p>
  1027. </li><li> TRANSLATION
  1028. <p>Translation is considered a kind of modification, so you may
  1029. distribute translations of the Document under the terms of section 4.
  1030. Replacing Invariant Sections with translations requires special
  1031. permission from their copyright holders, but you may include
  1032. translations of some or all Invariant Sections in addition to the
  1033. original versions of these Invariant Sections. You may include a
  1034. translation of this License, and all the license notices in the
  1035. Document, and any Warranty Disclaimers, provided that you also include
  1036. the original English version of this License and the original versions
  1037. of those notices and disclaimers. In case of a disagreement between
  1038. the translation and the original version of this License or a notice
  1039. or disclaimer, the original version will prevail.
  1040. </p>
  1041. <p>If a section in the Document is Entitled &ldquo;Acknowledgements&rdquo;,
  1042. &ldquo;Dedications&rdquo;, or &ldquo;History&rdquo;, the requirement (section 4) to Preserve
  1043. its Title (section 1) will typically require changing the actual
  1044. title.
  1045. </p>
  1046. </li><li> TERMINATION
  1047. <p>You may not copy, modify, sublicense, or distribute the Document
  1048. except as expressly provided under this License. Any attempt
  1049. otherwise to copy, modify, sublicense, or distribute it is void, and
  1050. will automatically terminate your rights under this License.
  1051. </p>
  1052. <p>However, if you cease all violation of this License, then your license
  1053. from a particular copyright holder is reinstated (a) provisionally,
  1054. unless and until the copyright holder explicitly and finally
  1055. terminates your license, and (b) permanently, if the copyright holder
  1056. fails to notify you of the violation by some reasonable means prior to
  1057. 60 days after the cessation.
  1058. </p>
  1059. <p>Moreover, your license from a particular copyright holder is
  1060. reinstated permanently if the copyright holder notifies you of the
  1061. violation by some reasonable means, this is the first time you have
  1062. received notice of violation of this License (for any work) from that
  1063. copyright holder, and you cure the violation prior to 30 days after
  1064. your receipt of the notice.
  1065. </p>
  1066. <p>Termination of your rights under this section does not terminate the
  1067. licenses of parties who have received copies or rights from you under
  1068. this License. If your rights have been terminated and not permanently
  1069. reinstated, receipt of a copy of some or all of the same material does
  1070. not give you any rights to use it.
  1071. </p>
  1072. </li><li> FUTURE REVISIONS OF THIS LICENSE
  1073. <p>The Free Software Foundation may publish new, revised versions
  1074. of the GNU Free Documentation License from time to time. Such new
  1075. versions will be similar in spirit to the present version, but may
  1076. differ in detail to address new problems or concerns. See
  1077. <a href="http://www.gnu.org/copyleft/">http://www.gnu.org/copyleft/</a>.
  1078. </p>
  1079. <p>Each version of the License is given a distinguishing version number.
  1080. If the Document specifies that a particular numbered version of this
  1081. License &ldquo;or any later version&rdquo; applies to it, you have the option of
  1082. following the terms and conditions either of that specified version or
  1083. of any later version that has been published (not as a draft) by the
  1084. Free Software Foundation. If the Document does not specify a version
  1085. number of this License, you may choose any version ever published (not
  1086. as a draft) by the Free Software Foundation. If the Document
  1087. specifies that a proxy can decide which future versions of this
  1088. License can be used, that proxy&rsquo;s public statement of acceptance of a
  1089. version permanently authorizes you to choose that version for the
  1090. Document.
  1091. </p>
  1092. </li><li> RELICENSING
  1093. <p>&ldquo;Massive Multiauthor Collaboration Site&rdquo; (or &ldquo;MMC Site&rdquo;) means any
  1094. World Wide Web server that publishes copyrightable works and also
  1095. provides prominent facilities for anybody to edit those works. A
  1096. public wiki that anybody can edit is an example of such a server. A
  1097. &ldquo;Massive Multiauthor Collaboration&rdquo; (or &ldquo;MMC&rdquo;) contained in the
  1098. site means any set of copyrightable works thus published on the MMC
  1099. site.
  1100. </p>
  1101. <p>&ldquo;CC-BY-SA&rdquo; means the Creative Commons Attribution-Share Alike 3.0
  1102. license published by Creative Commons Corporation, a not-for-profit
  1103. corporation with a principal place of business in San Francisco,
  1104. California, as well as future copyleft versions of that license
  1105. published by that same organization.
  1106. </p>
  1107. <p>&ldquo;Incorporate&rdquo; means to publish or republish a Document, in whole or
  1108. in part, as part of another Document.
  1109. </p>
  1110. <p>An MMC is &ldquo;eligible for relicensing&rdquo; if it is licensed under this
  1111. License, and if all works that were first published under this License
  1112. somewhere other than this MMC, and subsequently incorporated in whole
  1113. or in part into the MMC, (1) had no cover texts or invariant sections,
  1114. and (2) were thus incorporated prior to November 1, 2008.
  1115. </p>
  1116. <p>The operator of an MMC Site may republish an MMC contained in the site
  1117. under CC-BY-SA on the same site at any time before August 1, 2009,
  1118. provided the MMC is eligible for relicensing.
  1119. </p>
  1120. </li></ol>
  1121. <span id="ADDENDUM_003a-How-to-use-this-License-for-your-documents"></span><h3 class="heading">ADDENDUM: How to use this License for your documents</h3>
  1122. <p>To use this License in a document you have written, include a copy of
  1123. the License in the document and put the following copyright and
  1124. license notices just after the title page:
  1125. </p>
  1126. <div class="example">
  1127. <pre class="example"> Copyright (C) <var>year</var> <var>your name</var>.
  1128. Permission is granted to copy, distribute and/or modify this document
  1129. under the terms of the GNU Free Documentation License, Version 1.3
  1130. or any later version published by the Free Software Foundation;
  1131. with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
  1132. Texts. A copy of the license is included in the section entitled ``GNU
  1133. Free Documentation License''.
  1134. </pre></div>
  1135. <p>If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts,
  1136. replace the &ldquo;with&hellip;Texts.&rdquo; line with this:
  1137. </p>
  1138. <div class="example">
  1139. <pre class="example"> with the Invariant Sections being <var>list their titles</var>, with
  1140. the Front-Cover Texts being <var>list</var>, and with the Back-Cover Texts
  1141. being <var>list</var>.
  1142. </pre></div>
  1143. <p>If you have Invariant Sections without Cover Texts, or some other
  1144. combination of the three, merge those two alternatives to suit the
  1145. situation.
  1146. </p>
  1147. <p>If your document contains nontrivial examples of program code, we
  1148. recommend releasing these examples in parallel under your choice of
  1149. free software license, such as the GNU General Public License,
  1150. to permit their use in free software.
  1151. </p>
  1152. <span id="SEC_Contents"></span>
  1153. <h2 class="contents-heading">Table of Contents</h2>
  1154. <div class="contents">
  1155. <ul class="no-bullet">
  1156. <li><a id="toc-The-README-File" href="#README">1 The <samp>README</samp> File</a></li>
  1157. <li><a id="toc-How-linker-emulations-are-generated" href="#Emulations">2 How linker emulations are generated</a>
  1158. <ul class="no-bullet">
  1159. <li><a id="toc-emulparams-scripts" href="#emulation-parameters">2.1 <samp>emulparams</samp> scripts</a></li>
  1160. <li><a id="toc-scripttempl-scripts" href="#linker-scripts">2.2 <samp>scripttempl</samp> scripts</a></li>
  1161. <li><a id="toc-emultempl-scripts" href="#linker-emulations">2.3 <samp>emultempl</samp> scripts</a></li>
  1162. </ul></li>
  1163. <li><a id="toc-A-Walkthrough-of-a-Typical-Emulation" href="#Emulation-Walkthrough">3 A Walkthrough of a Typical Emulation</a></li>
  1164. <li><a id="toc-Some-Architecture-Specific-Notes" href="#Architecture-Specific">4 Some Architecture Specific Notes</a>
  1165. <ul class="no-bullet">
  1166. <li><a id="toc-Intel-x86" href="#ix86">4.1 Intel x86</a></li>
  1167. </ul></li>
  1168. <li><a id="toc-GNU-Free-Documentation-License-1" href="#GNU-Free-Documentation-License">5 GNU Free Documentation License</a></li>
  1169. </ul>
  1170. </div>
  1171. <hr>
  1172. </body>
  1173. </html>