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