dlltool.html 20 KB

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