選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

267 行
13KB

  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>VERSION (LD)</title>
  17. <meta name="description" content="VERSION (LD)">
  18. <meta name="keywords" content="VERSION (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="Expressions.html#Expressions" rel="next" title="Expressions">
  27. <link href="PHDRS.html#PHDRS" rel="prev" title="PHDRS">
  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="VERSION"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Previous: <a href="PHDRS.html#PHDRS" accesskey="p" rel="prev">PHDRS</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="VERSION-Command"></a>
  64. <h3 class="section">3.9 VERSION Command</h3>
  65. <a name="index-VERSION-_007bscript-text_007d"></a>
  66. <a name="index-symbol-versions"></a>
  67. <a name="index-version-script"></a>
  68. <a name="index-versions-of-symbols"></a>
  69. <p>The linker supports symbol versions when using ELF. Symbol versions are
  70. only useful when using shared libraries. The dynamic linker can use
  71. symbol versions to select a specific version of a function when it runs
  72. a program that may have been linked against an earlier version of the
  73. shared library.
  74. </p>
  75. <p>You can include a version script directly in the main linker script, or
  76. you can supply the version script as an implicit linker script. You can
  77. also use the &lsquo;<samp>--version-script</samp>&rsquo; linker option.
  78. </p>
  79. <p>The syntax of the <code>VERSION</code> command is simply
  80. </p><div class="smallexample">
  81. <pre class="smallexample">VERSION { version-script-commands }
  82. </pre></div>
  83. <p>The format of the version script commands is identical to that used by
  84. Sun&rsquo;s linker in Solaris 2.5. The version script defines a tree of
  85. version nodes. You specify the node names and interdependencies in the
  86. version script. You can specify which symbols are bound to which
  87. version nodes, and you can reduce a specified set of symbols to local
  88. scope so that they are not globally visible outside of the shared
  89. library.
  90. </p>
  91. <p>The easiest way to demonstrate the version script language is with a few
  92. examples.
  93. </p>
  94. <div class="smallexample">
  95. <pre class="smallexample">VERS_1.1 {
  96. global:
  97. foo1;
  98. local:
  99. old*;
  100. original*;
  101. new*;
  102. };
  103. VERS_1.2 {
  104. foo2;
  105. } VERS_1.1;
  106. VERS_2.0 {
  107. bar1; bar2;
  108. extern &quot;C++&quot; {
  109. ns::*;
  110. &quot;f(int, double)&quot;;
  111. };
  112. } VERS_1.2;
  113. </pre></div>
  114. <p>This example version script defines three version nodes. The first
  115. version node defined is &lsquo;<samp>VERS_1.1</samp>&rsquo;; it has no other dependencies.
  116. The script binds the symbol &lsquo;<samp>foo1</samp>&rsquo; to &lsquo;<samp>VERS_1.1</samp>&rsquo;. It reduces
  117. a number of symbols to local scope so that they are not visible outside
  118. of the shared library; this is done using wildcard patterns, so that any
  119. symbol whose name begins with &lsquo;<samp>old</samp>&rsquo;, &lsquo;<samp>original</samp>&rsquo;, or &lsquo;<samp>new</samp>&rsquo;
  120. is matched. The wildcard patterns available are the same as those used
  121. in the shell when matching filenames (also known as &ldquo;globbing&rdquo;).
  122. However, if you specify the symbol name inside double quotes, then the
  123. name is treated as literal, rather than as a glob pattern.
  124. </p>
  125. <p>Next, the version script defines node &lsquo;<samp>VERS_1.2</samp>&rsquo;. This node
  126. depends upon &lsquo;<samp>VERS_1.1</samp>&rsquo;. The script binds the symbol &lsquo;<samp>foo2</samp>&rsquo;
  127. to the version node &lsquo;<samp>VERS_1.2</samp>&rsquo;.
  128. </p>
  129. <p>Finally, the version script defines node &lsquo;<samp>VERS_2.0</samp>&rsquo;. This node
  130. depends upon &lsquo;<samp>VERS_1.2</samp>&rsquo;. The scripts binds the symbols &lsquo;<samp>bar1</samp>&rsquo;
  131. and &lsquo;<samp>bar2</samp>&rsquo; are bound to the version node &lsquo;<samp>VERS_2.0</samp>&rsquo;.
  132. </p>
  133. <p>When the linker finds a symbol defined in a library which is not
  134. specifically bound to a version node, it will effectively bind it to an
  135. unspecified base version of the library. You can bind all otherwise
  136. unspecified symbols to a given version node by using &lsquo;<samp>global: *;</samp>&rsquo;
  137. somewhere in the version script. Note that it&rsquo;s slightly crazy to use
  138. wildcards in a global spec except on the last version node. Global
  139. wildcards elsewhere run the risk of accidentally adding symbols to the
  140. set exported for an old version. That&rsquo;s wrong since older versions
  141. ought to have a fixed set of symbols.
  142. </p>
  143. <p>The names of the version nodes have no specific meaning other than what
  144. they might suggest to the person reading them. The &lsquo;<samp>2.0</samp>&rsquo; version
  145. could just as well have appeared in between &lsquo;<samp>1.1</samp>&rsquo; and &lsquo;<samp>1.2</samp>&rsquo;.
  146. However, this would be a confusing way to write a version script.
  147. </p>
  148. <p>Node name can be omitted, provided it is the only version node
  149. in the version script. Such version script doesn&rsquo;t assign any versions to
  150. symbols, only selects which symbols will be globally visible out and which
  151. won&rsquo;t.
  152. </p>
  153. <div class="smallexample">
  154. <pre class="smallexample">{ global: foo; bar; local: *; };
  155. </pre></div>
  156. <p>When you link an application against a shared library that has versioned
  157. symbols, the application itself knows which version of each symbol it
  158. requires, and it also knows which version nodes it needs from each
  159. shared library it is linked against. Thus at runtime, the dynamic
  160. loader can make a quick check to make sure that the libraries you have
  161. linked against do in fact supply all of the version nodes that the
  162. application will need to resolve all of the dynamic symbols. In this
  163. way it is possible for the dynamic linker to know with certainty that
  164. all external symbols that it needs will be resolvable without having to
  165. search for each symbol reference.
  166. </p>
  167. <p>The symbol versioning is in effect a much more sophisticated way of
  168. doing minor version checking that SunOS does. The fundamental problem
  169. that is being addressed here is that typically references to external
  170. functions are bound on an as-needed basis, and are not all bound when
  171. the application starts up. If a shared library is out of date, a
  172. required interface may be missing; when the application tries to use
  173. that interface, it may suddenly and unexpectedly fail. With symbol
  174. versioning, the user will get a warning when they start their program if
  175. the libraries being used with the application are too old.
  176. </p>
  177. <p>There are several GNU extensions to Sun&rsquo;s versioning approach. The
  178. first of these is the ability to bind a symbol to a version node in the
  179. source file where the symbol is defined instead of in the versioning
  180. script. This was done mainly to reduce the burden on the library
  181. maintainer. You can do this by putting something like:
  182. </p><div class="smallexample">
  183. <pre class="smallexample">__asm__(&quot;.symver original_foo,foo@VERS_1.1&quot;);
  184. </pre></div>
  185. <p>in the C source file. This renames the function &lsquo;<samp>original_foo</samp>&rsquo; to
  186. be an alias for &lsquo;<samp>foo</samp>&rsquo; bound to the version node &lsquo;<samp>VERS_1.1</samp>&rsquo;.
  187. The &lsquo;<samp>local:</samp>&rsquo; directive can be used to prevent the symbol
  188. &lsquo;<samp>original_foo</samp>&rsquo; from being exported. A &lsquo;<samp>.symver</samp>&rsquo; directive
  189. takes precedence over a version script.
  190. </p>
  191. <p>The second GNU extension is to allow multiple versions of the same
  192. function to appear in a given shared library. In this way you can make
  193. an incompatible change to an interface without increasing the major
  194. version number of the shared library, while still allowing applications
  195. linked against the old interface to continue to function.
  196. </p>
  197. <p>To do this, you must use multiple &lsquo;<samp>.symver</samp>&rsquo; directives in the
  198. source file. Here is an example:
  199. </p>
  200. <div class="smallexample">
  201. <pre class="smallexample">__asm__(&quot;.symver original_foo,foo@&quot;);
  202. __asm__(&quot;.symver old_foo,foo@VERS_1.1&quot;);
  203. __asm__(&quot;.symver old_foo1,foo@VERS_1.2&quot;);
  204. __asm__(&quot;.symver new_foo,foo@@VERS_2.0&quot;);
  205. </pre></div>
  206. <p>In this example, &lsquo;<samp>foo@</samp>&rsquo; represents the symbol &lsquo;<samp>foo</samp>&rsquo; bound to the
  207. unspecified base version of the symbol. The source file that contains this
  208. example would define 4 C functions: &lsquo;<samp>original_foo</samp>&rsquo;, &lsquo;<samp>old_foo</samp>&rsquo;,
  209. &lsquo;<samp>old_foo1</samp>&rsquo;, and &lsquo;<samp>new_foo</samp>&rsquo;.
  210. </p>
  211. <p>When you have multiple definitions of a given symbol, there needs to be
  212. some way to specify a default version to which external references to
  213. this symbol will be bound. You can do this with the
  214. &lsquo;<samp>foo@@VERS_2.0</samp>&rsquo; type of &lsquo;<samp>.symver</samp>&rsquo; directive. You can only
  215. declare one version of a symbol as the default in this manner; otherwise
  216. you would effectively have multiple definitions of the same symbol.
  217. </p>
  218. <p>If you wish to bind a reference to a specific version of the symbol
  219. within the shared library, you can use the aliases of convenience
  220. (i.e., &lsquo;<samp>old_foo</samp>&rsquo;), or you can use the &lsquo;<samp>.symver</samp>&rsquo; directive to
  221. specifically bind to an external version of the function in question.
  222. </p>
  223. <p>You can also specify the language in the version script:
  224. </p>
  225. <div class="smallexample">
  226. <pre class="smallexample">VERSION extern &quot;lang&quot; { version-script-commands }
  227. </pre></div>
  228. <p>The supported &lsquo;<samp>lang</samp>&rsquo;s are &lsquo;<samp>C</samp>&rsquo;, &lsquo;<samp>C++</samp>&rsquo;, and &lsquo;<samp>Java</samp>&rsquo;.
  229. The linker will iterate over the list of symbols at the link time and
  230. demangle them according to &lsquo;<samp>lang</samp>&rsquo; before matching them to the
  231. patterns specified in &lsquo;<samp>version-script-commands</samp>&rsquo;. The default
  232. &lsquo;<samp>lang</samp>&rsquo; is &lsquo;<samp>C</samp>&rsquo;.
  233. </p>
  234. <p>Demangled names may contains spaces and other special characters. As
  235. described above, you can use a glob pattern to match demangled names,
  236. or you can use a double-quoted string to match the string exactly. In
  237. the latter case, be aware that minor differences (such as differing
  238. whitespace) between the version script and the demangler output will
  239. cause a mismatch. As the exact string generated by the demangler
  240. might change in the future, even if the mangled name does not, you
  241. should check that all of your version directives are behaving as you
  242. expect when you upgrade.
  243. </p>
  244. <hr>
  245. <div class="header">
  246. <p>
  247. Next: <a href="Expressions.html#Expressions" accesskey="n" rel="next">Expressions</a>, Previous: <a href="PHDRS.html#PHDRS" accesskey="p" rel="prev">PHDRS</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>
  248. </div>
  249. </body>
  250. </html>