Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

444 rindas
20KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1991-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3
  6. or any later version published by the Free Software Foundation;
  7. with no Invariant Sections, with no Front-Cover Texts, and with no
  8. Back-Cover Texts. A copy of the license is included in the
  9. section entitled "GNU Free Documentation License".
  10. -->
  11. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  12. <head>
  13. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  14. <title>dlltool (GNU Binary Utilities)</title>
  15. <meta name="description" content="dlltool (GNU Binary Utilities)">
  16. <meta name="keywords" content="dlltool (GNU Binary Utilities)">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <link href="index.html#Top" rel="start" title="Top">
  21. <link href="Binutils-Index.html#Binutils-Index" rel="index" title="Binutils Index">
  22. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  23. <link href="index.html#Top" rel="up" title="Top">
  24. <link href="def-file-format.html#def-file-format" rel="next" title="def file format">
  25. <link href="windres.html#windres" rel="prev" title="windres">
  26. <style type="text/css">
  27. <!--
  28. a.summary-letter {text-decoration: none}
  29. blockquote.indentedblock {margin-right: 0em}
  30. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smalllisp {margin-left: 3.2em}
  38. kbd {font-style: oblique}
  39. pre.display {font-family: inherit}
  40. pre.format {font-family: inherit}
  41. pre.menu-comment {font-family: serif}
  42. pre.menu-preformatted {font-family: serif}
  43. pre.smalldisplay {font-family: inherit; font-size: smaller}
  44. pre.smallexample {font-size: smaller}
  45. pre.smallformat {font-family: inherit; font-size: smaller}
  46. pre.smalllisp {font-size: smaller}
  47. span.nolinebreak {white-space: nowrap}
  48. span.roman {font-family: initial; font-weight: normal}
  49. span.sansserif {font-family: sans-serif; font-weight: normal}
  50. ul.no-bullet {list-style: none}
  51. -->
  52. </style>
  53. </head>
  54. <body lang="en">
  55. <a name="dlltool"></a>
  56. <div class="header">
  57. <p>
  58. Next: <a href="readelf.html#readelf" accesskey="n" rel="next">readelf</a>, Previous: <a href="windres.html#windres" accesskey="p" rel="prev">windres</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
  59. </div>
  60. <hr>
  61. <a name="dlltool-1"></a>
  62. <h2 class="chapter">13 dlltool</h2>
  63. <a name="index-DLL"></a>
  64. <a name="index-dlltool"></a>
  65. <p><code>dlltool</code> is used to create the files needed to create dynamic
  66. link libraries (DLLs) on systems which understand PE format image
  67. files such as Windows. A DLL contains an export table which contains
  68. information that the runtime loader needs to resolve references from a
  69. referencing program.
  70. </p>
  71. <p>The export table is generated by this program by reading in a
  72. <samp>.def</samp> file or scanning the <samp>.a</samp> and <samp>.o</samp> files which
  73. will be in the DLL. A <samp>.o</samp> file can contain information in
  74. special &lsquo;<samp>.drectve</samp>&rsquo; sections with export information.
  75. </p>
  76. <blockquote>
  77. <p><em>Note:</em> <code>dlltool</code> is not always built as part of the
  78. binary utilities, since it is only useful for those targets which
  79. support DLLs.
  80. </p></blockquote>
  81. <div class="smallexample">
  82. <pre class="smallexample">dlltool [<samp>-d</samp>|<samp>--input-def</samp> <var>def-file-name</var>]
  83. [<samp>-b</samp>|<samp>--base-file</samp> <var>base-file-name</var>]
  84. [<samp>-e</samp>|<samp>--output-exp</samp> <var>exports-file-name</var>]
  85. [<samp>-z</samp>|<samp>--output-def</samp> <var>def-file-name</var>]
  86. [<samp>-l</samp>|<samp>--output-lib</samp> <var>library-file-name</var>]
  87. [<samp>-y</samp>|<samp>--output-delaylib</samp> <var>library-file-name</var>]
  88. [<samp>--export-all-symbols</samp>] [<samp>--no-export-all-symbols</samp>]
  89. [<samp>--exclude-symbols</samp> <var>list</var>]
  90. [<samp>--no-default-excludes</samp>]
  91. [<samp>-S</samp>|<samp>--as</samp> <var>path-to-assembler</var>] [<samp>-f</samp>|<samp>--as-flags</samp> <var>options</var>]
  92. [<samp>-D</samp>|<samp>--dllname</samp> <var>name</var>] [<samp>-m</samp>|<samp>--machine</samp> <var>machine</var>]
  93. [<samp>-a</samp>|<samp>--add-indirect</samp>]
  94. [<samp>-U</samp>|<samp>--add-underscore</samp>] [<samp>--add-stdcall-underscore</samp>]
  95. [<samp>-k</samp>|<samp>--kill-at</samp>] [<samp>-A</samp>|<samp>--add-stdcall-alias</samp>]
  96. [<samp>-p</samp>|<samp>--ext-prefix-alias</samp> <var>prefix</var>]
  97. [<samp>-x</samp>|<samp>--no-idata4</samp>] [<samp>-c</samp>|<samp>--no-idata5</samp>]
  98. [<samp>--use-nul-prefixed-import-tables</samp>]
  99. [<samp>-I</samp>|<samp>--identify</samp> <var>library-file-name</var>] [<samp>--identify-strict</samp>]
  100. [<samp>-i</samp>|<samp>--interwork</samp>]
  101. [<samp>-n</samp>|<samp>--nodelete</samp>] [<samp>-t</samp>|<samp>--temp-prefix</samp> <var>prefix</var>]
  102. [<samp>-v</samp>|<samp>--verbose</samp>]
  103. [<samp>-h</samp>|<samp>--help</samp>] [<samp>-V</samp>|<samp>--version</samp>]
  104. [<samp>--no-leading-underscore</samp>] [<samp>--leading-underscore</samp>]
  105. [object-file &hellip;]
  106. </pre></div>
  107. <p><code>dlltool</code> reads its inputs, which can come from the <samp>-d</samp> and
  108. <samp>-b</samp> options as well as object files specified on the command
  109. line. It then processes these inputs and if the <samp>-e</samp> option has
  110. been specified it creates a exports file. If the <samp>-l</samp> option
  111. has been specified it creates a library file and if the <samp>-z</samp> option
  112. has been specified it creates a def file. Any or all of the <samp>-e</samp>,
  113. <samp>-l</samp> and <samp>-z</samp> options can be present in one invocation of
  114. dlltool.
  115. </p>
  116. <p>When creating a DLL, along with the source for the DLL, it is necessary
  117. to have three other files. <code>dlltool</code> can help with the creation of
  118. these files.
  119. </p>
  120. <p>The first file is a <samp>.def</samp> file which specifies which functions are
  121. exported from the DLL, which functions the DLL imports, and so on. This
  122. is a text file and can be created by hand, or <code>dlltool</code> can be used
  123. to create it using the <samp>-z</samp> option. In this case <code>dlltool</code>
  124. will scan the object files specified on its command line looking for
  125. those functions which have been specially marked as being exported and
  126. put entries for them in the <samp>.def</samp> file it creates.
  127. </p>
  128. <p>In order to mark a function as being exported from a DLL, it needs to
  129. have an <samp>-export:&lt;name_of_function&gt;</samp> entry in the &lsquo;<samp>.drectve</samp>&rsquo;
  130. section of the object file. This can be done in C by using the
  131. asm() operator:
  132. </p>
  133. <div class="smallexample">
  134. <pre class="smallexample"> asm (&quot;.section .drectve&quot;);
  135. asm (&quot;.ascii \&quot;-export:my_func\&quot;&quot;);
  136. int my_func (void) { &hellip; }
  137. </pre></div>
  138. <p>The second file needed for DLL creation is an exports file. This file
  139. is linked with the object files that make up the body of the DLL and it
  140. handles the interface between the DLL and the outside world. This is a
  141. binary file and it can be created by giving the <samp>-e</samp> option to
  142. <code>dlltool</code> when it is creating or reading in a <samp>.def</samp> file.
  143. </p>
  144. <p>The third file needed for DLL creation is the library file that programs
  145. will link with in order to access the functions in the DLL (an &lsquo;import
  146. library&rsquo;). This file can be created by giving the <samp>-l</samp> option to
  147. dlltool when it is creating or reading in a <samp>.def</samp> file.
  148. </p>
  149. <p>If the <samp>-y</samp> option is specified, dlltool generates a delay-import
  150. library that can be used instead of the normal import library to allow
  151. a program to link to the dll only as soon as an imported function is
  152. called for the first time. The resulting executable will need to be
  153. linked to the static delayimp library containing __delayLoadHelper2(),
  154. which in turn will import LoadLibraryA and GetProcAddress from kernel32.
  155. </p>
  156. <p><code>dlltool</code> builds the library file by hand, but it builds the
  157. exports file by creating temporary files containing assembler statements
  158. and then assembling these. The <samp>-S</samp> command-line option can be
  159. used to specify the path to the assembler that dlltool will use,
  160. and the <samp>-f</samp> option can be used to pass specific flags to that
  161. assembler. The <samp>-n</samp> can be used to prevent dlltool from deleting
  162. these temporary assembler files when it is done, and if <samp>-n</samp> is
  163. specified twice then this will prevent dlltool from deleting the
  164. temporary object files it used to build the library.
  165. </p>
  166. <p>Here is an example of creating a DLL from a source file &lsquo;<samp>dll.c</samp>&rsquo; and
  167. also creating a program (from an object file called &lsquo;<samp>program.o</samp>&rsquo;)
  168. that uses that DLL:
  169. </p>
  170. <div class="smallexample">
  171. <pre class="smallexample"> gcc -c dll.c
  172. dlltool -e exports.o -l dll.lib dll.o
  173. gcc dll.o exports.o -o dll.dll
  174. gcc program.o dll.lib -o program
  175. </pre></div>
  176. <p><code>dlltool</code> may also be used to query an existing import library
  177. to determine the name of the DLL to which it is associated. See the
  178. description of the <samp>-I</samp> or <samp>--identify</samp> option.
  179. </p>
  180. <p>The command-line options have the following meanings:
  181. </p>
  182. <dl compact="compact">
  183. <dt><code>-d <var>filename</var></code></dt>
  184. <dt><code>--input-def <var>filename</var></code></dt>
  185. <dd><a name="index-input-_002edef-file"></a>
  186. <p>Specifies the name of a <samp>.def</samp> file to be read in and processed.
  187. </p>
  188. </dd>
  189. <dt><code>-b <var>filename</var></code></dt>
  190. <dt><code>--base-file <var>filename</var></code></dt>
  191. <dd><a name="index-base-files"></a>
  192. <p>Specifies the name of a base file to be read in and processed. The
  193. contents of this file will be added to the relocation section in the
  194. exports file generated by dlltool.
  195. </p>
  196. </dd>
  197. <dt><code>-e <var>filename</var></code></dt>
  198. <dt><code>--output-exp <var>filename</var></code></dt>
  199. <dd><p>Specifies the name of the export file to be created by dlltool.
  200. </p>
  201. </dd>
  202. <dt><code>-z <var>filename</var></code></dt>
  203. <dt><code>--output-def <var>filename</var></code></dt>
  204. <dd><p>Specifies the name of the <samp>.def</samp> file to be created by dlltool.
  205. </p>
  206. </dd>
  207. <dt><code>-l <var>filename</var></code></dt>
  208. <dt><code>--output-lib <var>filename</var></code></dt>
  209. <dd><p>Specifies the name of the library file to be created by dlltool.
  210. </p>
  211. </dd>
  212. <dt><code>-y <var>filename</var></code></dt>
  213. <dt><code>--output-delaylib <var>filename</var></code></dt>
  214. <dd><p>Specifies the name of the delay-import library file to be created by dlltool.
  215. </p>
  216. </dd>
  217. <dt><code>--export-all-symbols</code></dt>
  218. <dd><p>Treat all global and weak defined symbols found in the input object
  219. files as symbols to be exported. There is a small list of symbols which
  220. are not exported by default; see the <samp>--no-default-excludes</samp>
  221. option. You may add to the list of symbols to not export by using the
  222. <samp>--exclude-symbols</samp> option.
  223. </p>
  224. </dd>
  225. <dt><code>--no-export-all-symbols</code></dt>
  226. <dd><p>Only export symbols explicitly listed in an input <samp>.def</samp> file or in
  227. &lsquo;<samp>.drectve</samp>&rsquo; sections in the input object files. This is the default
  228. behaviour. The &lsquo;<samp>.drectve</samp>&rsquo; sections are created by &lsquo;<samp>dllexport</samp>&rsquo;
  229. attributes in the source code.
  230. </p>
  231. </dd>
  232. <dt><code>--exclude-symbols <var>list</var></code></dt>
  233. <dd><p>Do not export the symbols in <var>list</var>. This is a list of symbol names
  234. separated by comma or colon characters. The symbol names should not
  235. contain a leading underscore. This is only meaningful when
  236. <samp>--export-all-symbols</samp> is used.
  237. </p>
  238. </dd>
  239. <dt><code>--no-default-excludes</code></dt>
  240. <dd><p>When <samp>--export-all-symbols</samp> is used, it will by default avoid
  241. exporting certain special symbols. The current list of symbols to avoid
  242. exporting is &lsquo;<samp>DllMain@12</samp>&rsquo;, &lsquo;<samp>DllEntryPoint@0</samp>&rsquo;,
  243. &lsquo;<samp>impure_ptr</samp>&rsquo;. You may use the <samp>--no-default-excludes</samp> option
  244. to go ahead and export these special symbols. This is only meaningful
  245. when <samp>--export-all-symbols</samp> is used.
  246. </p>
  247. </dd>
  248. <dt><code>-S <var>path</var></code></dt>
  249. <dt><code>--as <var>path</var></code></dt>
  250. <dd><p>Specifies the path, including the filename, of the assembler to be used
  251. to create the exports file.
  252. </p>
  253. </dd>
  254. <dt><code>-f <var>options</var></code></dt>
  255. <dt><code>--as-flags <var>options</var></code></dt>
  256. <dd><p>Specifies any specific command-line options to be passed to the
  257. assembler when building the exports file. This option will work even if
  258. the <samp>-S</samp> option is not used. This option only takes one argument,
  259. and if it occurs more than once on the command line, then later
  260. occurrences will override earlier occurrences. So if it is necessary to
  261. pass multiple options to the assembler they should be enclosed in
  262. double quotes.
  263. </p>
  264. </dd>
  265. <dt><code>-D <var>name</var></code></dt>
  266. <dt><code>--dll-name <var>name</var></code></dt>
  267. <dd><p>Specifies the name to be stored in the <samp>.def</samp> file as the name of
  268. the DLL when the <samp>-e</samp> option is used. If this option is not
  269. present, then the filename given to the <samp>-e</samp> option will be
  270. used as the name of the DLL.
  271. </p>
  272. </dd>
  273. <dt><code>-m <var>machine</var></code></dt>
  274. <dt><code>-machine <var>machine</var></code></dt>
  275. <dd><p>Specifies the type of machine for which the library file should be
  276. built. <code>dlltool</code> has a built in default type, depending upon how
  277. it was created, but this option can be used to override that. This is
  278. normally only useful when creating DLLs for an ARM processor, when the
  279. contents of the DLL are actually encode using Thumb instructions.
  280. </p>
  281. </dd>
  282. <dt><code>-a</code></dt>
  283. <dt><code>--add-indirect</code></dt>
  284. <dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
  285. should add a section which allows the exported functions to be
  286. referenced without using the import library. Whatever the hell that
  287. means!
  288. </p>
  289. </dd>
  290. <dt><code>-U</code></dt>
  291. <dt><code>--add-underscore</code></dt>
  292. <dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
  293. should prepend an underscore to the names of <em>all</em> exported symbols.
  294. </p>
  295. </dd>
  296. <dt><code>--no-leading-underscore</code></dt>
  297. <dt><code>--leading-underscore</code></dt>
  298. <dd><p>Specifies whether standard symbol should be forced to be prefixed, or
  299. not.
  300. </p>
  301. </dd>
  302. <dt><code>--add-stdcall-underscore</code></dt>
  303. <dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
  304. should prepend an underscore to the names of exported <em>stdcall</em>
  305. functions. Variable names and non-stdcall function names are not modified.
  306. This option is useful when creating GNU-compatible import libs for third
  307. party DLLs that were built with MS-Windows tools.
  308. </p>
  309. </dd>
  310. <dt><code>-k</code></dt>
  311. <dt><code>--kill-at</code></dt>
  312. <dd><p>Specifies that &lsquo;<samp>@&lt;number&gt;</samp>&rsquo; suffixes should be omitted from the names
  313. of stdcall functions that will be imported from the DLL. This is
  314. useful when creating an import library for a DLL which exports stdcall
  315. functions but without the usual &lsquo;<samp>@&lt;number&gt;</samp>&rsquo; symbol name suffix.
  316. </p>
  317. <p>This does not change the naming of symbols provided by the import library
  318. to programs linked against it, but only the entries in the import table
  319. (ie the .idata section).
  320. </p>
  321. </dd>
  322. <dt><code>-A</code></dt>
  323. <dt><code>--add-stdcall-alias</code></dt>
  324. <dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
  325. should add aliases for stdcall symbols without &lsquo;<samp>@ &lt;number&gt;</samp>&rsquo;
  326. in addition to the symbols with &lsquo;<samp>@ &lt;number&gt;</samp>&rsquo;.
  327. </p>
  328. </dd>
  329. <dt><code>-p</code></dt>
  330. <dt><code>--ext-prefix-alias <var>prefix</var></code></dt>
  331. <dd><p>Causes <code>dlltool</code> to create external aliases for all DLL
  332. imports with the specified prefix. The aliases are created for both
  333. external and import symbols with no leading underscore.
  334. </p>
  335. </dd>
  336. <dt><code>-x</code></dt>
  337. <dt><code>--no-idata4</code></dt>
  338. <dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
  339. files it should omit the <code>.idata4</code> section. This is for compatibility
  340. with certain operating systems.
  341. </p>
  342. </dd>
  343. <dt><code>--use-nul-prefixed-import-tables</code></dt>
  344. <dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
  345. files it should prefix the <code>.idata4</code> and <code>.idata5</code> by zero an
  346. element. This emulates old gnu import library generation of
  347. <code>dlltool</code>. By default this option is turned off.
  348. </p>
  349. </dd>
  350. <dt><code>-c</code></dt>
  351. <dt><code>--no-idata5</code></dt>
  352. <dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
  353. files it should omit the <code>.idata5</code> section. This is for compatibility
  354. with certain operating systems.
  355. </p>
  356. </dd>
  357. <dt><code>-I <var>filename</var></code></dt>
  358. <dt><code>--identify <var>filename</var></code></dt>
  359. <dd><p>Specifies that <code>dlltool</code> should inspect the import library
  360. indicated by <var>filename</var> and report, on <code>stdout</code>, the name(s)
  361. of the associated DLL(s). This can be performed in addition to any
  362. other operations indicated by the other options and arguments.
  363. <code>dlltool</code> fails if the import library does not exist or is not
  364. actually an import library. See also <samp>--identify-strict</samp>.
  365. </p>
  366. </dd>
  367. <dt><code>--identify-strict</code></dt>
  368. <dd><p>Modifies the behavior of the <samp>--identify</samp> option, such
  369. that an error is reported if <var>filename</var> is associated with
  370. more than one DLL.
  371. </p>
  372. </dd>
  373. <dt><code>-i</code></dt>
  374. <dt><code>--interwork</code></dt>
  375. <dd><p>Specifies that <code>dlltool</code> should mark the objects in the library
  376. file and exports file that it produces as supporting interworking
  377. between ARM and Thumb code.
  378. </p>
  379. </dd>
  380. <dt><code>-n</code></dt>
  381. <dt><code>--nodelete</code></dt>
  382. <dd><p>Makes <code>dlltool</code> preserve the temporary assembler files it used to
  383. create the exports file. If this option is repeated then dlltool will
  384. also preserve the temporary object files it uses to create the library
  385. file.
  386. </p>
  387. </dd>
  388. <dt><code>-t <var>prefix</var></code></dt>
  389. <dt><code>--temp-prefix <var>prefix</var></code></dt>
  390. <dd><p>Makes <code>dlltool</code> use <var>prefix</var> when constructing the names of
  391. temporary assembler and object files. By default, the temp file prefix
  392. is generated from the pid.
  393. </p>
  394. </dd>
  395. <dt><code>-v</code></dt>
  396. <dt><code>--verbose</code></dt>
  397. <dd><p>Make dlltool describe what it is doing.
  398. </p>
  399. </dd>
  400. <dt><code>-h</code></dt>
  401. <dt><code>--help</code></dt>
  402. <dd><p>Displays a list of command-line options and then exits.
  403. </p>
  404. </dd>
  405. <dt><code>-V</code></dt>
  406. <dt><code>--version</code></dt>
  407. <dd><p>Displays dlltool&rsquo;s version number and then exits.
  408. </p>
  409. </dd>
  410. </dl>
  411. <table class="menu" border="0" cellspacing="0">
  412. <tr><td align="left" valign="top">&bull; <a href="def-file-format.html#def-file-format" accesskey="1">def file format</a>:</td><td>&nbsp;&nbsp;</td><td align="left" valign="top">The format of the dlltool <samp>.def</samp> file
  413. </td></tr>
  414. </table>
  415. <hr>
  416. <div class="header">
  417. <p>
  418. Next: <a href="readelf.html#readelf" accesskey="n" rel="next">readelf</a>, Previous: <a href="windres.html#windres" accesskey="p" rel="prev">windres</a>, Up: <a href="index.html#Top" accesskey="u" rel="up">Top</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Binutils-Index.html#Binutils-Index" title="Index" rel="index">Index</a>]</p>
  419. </div>
  420. </body>
  421. </html>