You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
444 lines
20 KiB
HTML
444 lines
20 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<html>
|
|
<!-- Copyright (C) 1991-2019 Free Software Foundation, Inc.
|
|
|
|
Permission is granted to copy, distribute and/or modify this document
|
|
under the terms of the GNU Free Documentation License, Version 1.3
|
|
or any later version published by the Free Software Foundation;
|
|
with no Invariant Sections, with no Front-Cover Texts, and with no
|
|
Back-Cover Texts. A copy of the license is included in the
|
|
section entitled "GNU Free Documentation License".
|
|
-->
|
|
<!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ -->
|
|
<head>
|
|
<title>dlltool (GNU Binary Utilities)</title>
|
|
|
|
<meta name="description" content="dlltool (GNU Binary Utilities)">
|
|
<meta name="keywords" content="dlltool (GNU Binary Utilities)">
|
|
<meta name="resource-type" content="document">
|
|
<meta name="distribution" content="global">
|
|
<meta name="Generator" content="makeinfo">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<link href="index.html#Top" rel="start" title="Top">
|
|
<link href="Binutils-Index.html#Binutils-Index" rel="index" title="Binutils Index">
|
|
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
|
<link href="index.html#Top" rel="up" title="Top">
|
|
<link href="def-file-format.html#def-file-format" rel="next" title="def file format">
|
|
<link href="windres.html#windres" rel="prev" title="windres">
|
|
<style type="text/css">
|
|
<!--
|
|
a.summary-letter {text-decoration: none}
|
|
blockquote.indentedblock {margin-right: 0em}
|
|
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
|
|
blockquote.smallquotation {font-size: smaller}
|
|
div.display {margin-left: 3.2em}
|
|
div.example {margin-left: 3.2em}
|
|
div.lisp {margin-left: 3.2em}
|
|
div.smalldisplay {margin-left: 3.2em}
|
|
div.smallexample {margin-left: 3.2em}
|
|
div.smalllisp {margin-left: 3.2em}
|
|
kbd {font-style: oblique}
|
|
pre.display {font-family: inherit}
|
|
pre.format {font-family: inherit}
|
|
pre.menu-comment {font-family: serif}
|
|
pre.menu-preformatted {font-family: serif}
|
|
pre.smalldisplay {font-family: inherit; font-size: smaller}
|
|
pre.smallexample {font-size: smaller}
|
|
pre.smallformat {font-family: inherit; font-size: smaller}
|
|
pre.smalllisp {font-size: smaller}
|
|
span.nolinebreak {white-space: nowrap}
|
|
span.roman {font-family: initial; font-weight: normal}
|
|
span.sansserif {font-family: sans-serif; font-weight: normal}
|
|
ul.no-bullet {list-style: none}
|
|
-->
|
|
</style>
|
|
|
|
|
|
</head>
|
|
|
|
<body lang="en">
|
|
<a name="dlltool"></a>
|
|
<div class="header">
|
|
<p>
|
|
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> [<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>
|
|
</div>
|
|
<hr>
|
|
<a name="dlltool-1"></a>
|
|
<h2 class="chapter">13 dlltool</h2>
|
|
<a name="index-DLL"></a>
|
|
<a name="index-dlltool"></a>
|
|
|
|
<p><code>dlltool</code> is used to create the files needed to create dynamic
|
|
link libraries (DLLs) on systems which understand PE format image
|
|
files such as Windows. A DLL contains an export table which contains
|
|
information that the runtime loader needs to resolve references from a
|
|
referencing program.
|
|
</p>
|
|
<p>The export table is generated by this program by reading in a
|
|
<samp>.def</samp> file or scanning the <samp>.a</samp> and <samp>.o</samp> files which
|
|
will be in the DLL. A <samp>.o</samp> file can contain information in
|
|
special ‘<samp>.drectve</samp>’ sections with export information.
|
|
</p>
|
|
<blockquote>
|
|
<p><em>Note:</em> <code>dlltool</code> is not always built as part of the
|
|
binary utilities, since it is only useful for those targets which
|
|
support DLLs.
|
|
</p></blockquote>
|
|
|
|
|
|
<div class="smallexample">
|
|
<pre class="smallexample">dlltool [<samp>-d</samp>|<samp>--input-def</samp> <var>def-file-name</var>]
|
|
[<samp>-b</samp>|<samp>--base-file</samp> <var>base-file-name</var>]
|
|
[<samp>-e</samp>|<samp>--output-exp</samp> <var>exports-file-name</var>]
|
|
[<samp>-z</samp>|<samp>--output-def</samp> <var>def-file-name</var>]
|
|
[<samp>-l</samp>|<samp>--output-lib</samp> <var>library-file-name</var>]
|
|
[<samp>-y</samp>|<samp>--output-delaylib</samp> <var>library-file-name</var>]
|
|
[<samp>--export-all-symbols</samp>] [<samp>--no-export-all-symbols</samp>]
|
|
[<samp>--exclude-symbols</samp> <var>list</var>]
|
|
[<samp>--no-default-excludes</samp>]
|
|
[<samp>-S</samp>|<samp>--as</samp> <var>path-to-assembler</var>] [<samp>-f</samp>|<samp>--as-flags</samp> <var>options</var>]
|
|
[<samp>-D</samp>|<samp>--dllname</samp> <var>name</var>] [<samp>-m</samp>|<samp>--machine</samp> <var>machine</var>]
|
|
[<samp>-a</samp>|<samp>--add-indirect</samp>]
|
|
[<samp>-U</samp>|<samp>--add-underscore</samp>] [<samp>--add-stdcall-underscore</samp>]
|
|
[<samp>-k</samp>|<samp>--kill-at</samp>] [<samp>-A</samp>|<samp>--add-stdcall-alias</samp>]
|
|
[<samp>-p</samp>|<samp>--ext-prefix-alias</samp> <var>prefix</var>]
|
|
[<samp>-x</samp>|<samp>--no-idata4</samp>] [<samp>-c</samp>|<samp>--no-idata5</samp>]
|
|
[<samp>--use-nul-prefixed-import-tables</samp>]
|
|
[<samp>-I</samp>|<samp>--identify</samp> <var>library-file-name</var>] [<samp>--identify-strict</samp>]
|
|
[<samp>-i</samp>|<samp>--interwork</samp>]
|
|
[<samp>-n</samp>|<samp>--nodelete</samp>] [<samp>-t</samp>|<samp>--temp-prefix</samp> <var>prefix</var>]
|
|
[<samp>-v</samp>|<samp>--verbose</samp>]
|
|
[<samp>-h</samp>|<samp>--help</samp>] [<samp>-V</samp>|<samp>--version</samp>]
|
|
[<samp>--no-leading-underscore</samp>] [<samp>--leading-underscore</samp>]
|
|
[object-file …]
|
|
</pre></div>
|
|
|
|
|
|
<p><code>dlltool</code> reads its inputs, which can come from the <samp>-d</samp> and
|
|
<samp>-b</samp> options as well as object files specified on the command
|
|
line. It then processes these inputs and if the <samp>-e</samp> option has
|
|
been specified it creates a exports file. If the <samp>-l</samp> option
|
|
has been specified it creates a library file and if the <samp>-z</samp> option
|
|
has been specified it creates a def file. Any or all of the <samp>-e</samp>,
|
|
<samp>-l</samp> and <samp>-z</samp> options can be present in one invocation of
|
|
dlltool.
|
|
</p>
|
|
<p>When creating a DLL, along with the source for the DLL, it is necessary
|
|
to have three other files. <code>dlltool</code> can help with the creation of
|
|
these files.
|
|
</p>
|
|
<p>The first file is a <samp>.def</samp> file which specifies which functions are
|
|
exported from the DLL, which functions the DLL imports, and so on. This
|
|
is a text file and can be created by hand, or <code>dlltool</code> can be used
|
|
to create it using the <samp>-z</samp> option. In this case <code>dlltool</code>
|
|
will scan the object files specified on its command line looking for
|
|
those functions which have been specially marked as being exported and
|
|
put entries for them in the <samp>.def</samp> file it creates.
|
|
</p>
|
|
<p>In order to mark a function as being exported from a DLL, it needs to
|
|
have an <samp>-export:<name_of_function></samp> entry in the ‘<samp>.drectve</samp>’
|
|
section of the object file. This can be done in C by using the
|
|
asm() operator:
|
|
</p>
|
|
<div class="smallexample">
|
|
<pre class="smallexample"> asm (".section .drectve");
|
|
asm (".ascii \"-export:my_func\"");
|
|
|
|
int my_func (void) { … }
|
|
</pre></div>
|
|
|
|
<p>The second file needed for DLL creation is an exports file. This file
|
|
is linked with the object files that make up the body of the DLL and it
|
|
handles the interface between the DLL and the outside world. This is a
|
|
binary file and it can be created by giving the <samp>-e</samp> option to
|
|
<code>dlltool</code> when it is creating or reading in a <samp>.def</samp> file.
|
|
</p>
|
|
<p>The third file needed for DLL creation is the library file that programs
|
|
will link with in order to access the functions in the DLL (an ‘import
|
|
library’). This file can be created by giving the <samp>-l</samp> option to
|
|
dlltool when it is creating or reading in a <samp>.def</samp> file.
|
|
</p>
|
|
<p>If the <samp>-y</samp> option is specified, dlltool generates a delay-import
|
|
library that can be used instead of the normal import library to allow
|
|
a program to link to the dll only as soon as an imported function is
|
|
called for the first time. The resulting executable will need to be
|
|
linked to the static delayimp library containing __delayLoadHelper2(),
|
|
which in turn will import LoadLibraryA and GetProcAddress from kernel32.
|
|
</p>
|
|
<p><code>dlltool</code> builds the library file by hand, but it builds the
|
|
exports file by creating temporary files containing assembler statements
|
|
and then assembling these. The <samp>-S</samp> command-line option can be
|
|
used to specify the path to the assembler that dlltool will use,
|
|
and the <samp>-f</samp> option can be used to pass specific flags to that
|
|
assembler. The <samp>-n</samp> can be used to prevent dlltool from deleting
|
|
these temporary assembler files when it is done, and if <samp>-n</samp> is
|
|
specified twice then this will prevent dlltool from deleting the
|
|
temporary object files it used to build the library.
|
|
</p>
|
|
<p>Here is an example of creating a DLL from a source file ‘<samp>dll.c</samp>’ and
|
|
also creating a program (from an object file called ‘<samp>program.o</samp>’)
|
|
that uses that DLL:
|
|
</p>
|
|
<div class="smallexample">
|
|
<pre class="smallexample"> gcc -c dll.c
|
|
dlltool -e exports.o -l dll.lib dll.o
|
|
gcc dll.o exports.o -o dll.dll
|
|
gcc program.o dll.lib -o program
|
|
</pre></div>
|
|
|
|
|
|
<p><code>dlltool</code> may also be used to query an existing import library
|
|
to determine the name of the DLL to which it is associated. See the
|
|
description of the <samp>-I</samp> or <samp>--identify</samp> option.
|
|
</p>
|
|
|
|
|
|
<p>The command-line options have the following meanings:
|
|
</p>
|
|
<dl compact="compact">
|
|
<dt><code>-d <var>filename</var></code></dt>
|
|
<dt><code>--input-def <var>filename</var></code></dt>
|
|
<dd><a name="index-input-_002edef-file"></a>
|
|
<p>Specifies the name of a <samp>.def</samp> file to be read in and processed.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-b <var>filename</var></code></dt>
|
|
<dt><code>--base-file <var>filename</var></code></dt>
|
|
<dd><a name="index-base-files"></a>
|
|
<p>Specifies the name of a base file to be read in and processed. The
|
|
contents of this file will be added to the relocation section in the
|
|
exports file generated by dlltool.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-e <var>filename</var></code></dt>
|
|
<dt><code>--output-exp <var>filename</var></code></dt>
|
|
<dd><p>Specifies the name of the export file to be created by dlltool.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-z <var>filename</var></code></dt>
|
|
<dt><code>--output-def <var>filename</var></code></dt>
|
|
<dd><p>Specifies the name of the <samp>.def</samp> file to be created by dlltool.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-l <var>filename</var></code></dt>
|
|
<dt><code>--output-lib <var>filename</var></code></dt>
|
|
<dd><p>Specifies the name of the library file to be created by dlltool.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-y <var>filename</var></code></dt>
|
|
<dt><code>--output-delaylib <var>filename</var></code></dt>
|
|
<dd><p>Specifies the name of the delay-import library file to be created by dlltool.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--export-all-symbols</code></dt>
|
|
<dd><p>Treat all global and weak defined symbols found in the input object
|
|
files as symbols to be exported. There is a small list of symbols which
|
|
are not exported by default; see the <samp>--no-default-excludes</samp>
|
|
option. You may add to the list of symbols to not export by using the
|
|
<samp>--exclude-symbols</samp> option.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--no-export-all-symbols</code></dt>
|
|
<dd><p>Only export symbols explicitly listed in an input <samp>.def</samp> file or in
|
|
‘<samp>.drectve</samp>’ sections in the input object files. This is the default
|
|
behaviour. The ‘<samp>.drectve</samp>’ sections are created by ‘<samp>dllexport</samp>’
|
|
attributes in the source code.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--exclude-symbols <var>list</var></code></dt>
|
|
<dd><p>Do not export the symbols in <var>list</var>. This is a list of symbol names
|
|
separated by comma or colon characters. The symbol names should not
|
|
contain a leading underscore. This is only meaningful when
|
|
<samp>--export-all-symbols</samp> is used.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--no-default-excludes</code></dt>
|
|
<dd><p>When <samp>--export-all-symbols</samp> is used, it will by default avoid
|
|
exporting certain special symbols. The current list of symbols to avoid
|
|
exporting is ‘<samp>DllMain@12</samp>’, ‘<samp>DllEntryPoint@0</samp>’,
|
|
‘<samp>impure_ptr</samp>’. You may use the <samp>--no-default-excludes</samp> option
|
|
to go ahead and export these special symbols. This is only meaningful
|
|
when <samp>--export-all-symbols</samp> is used.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-S <var>path</var></code></dt>
|
|
<dt><code>--as <var>path</var></code></dt>
|
|
<dd><p>Specifies the path, including the filename, of the assembler to be used
|
|
to create the exports file.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-f <var>options</var></code></dt>
|
|
<dt><code>--as-flags <var>options</var></code></dt>
|
|
<dd><p>Specifies any specific command-line options to be passed to the
|
|
assembler when building the exports file. This option will work even if
|
|
the <samp>-S</samp> option is not used. This option only takes one argument,
|
|
and if it occurs more than once on the command line, then later
|
|
occurrences will override earlier occurrences. So if it is necessary to
|
|
pass multiple options to the assembler they should be enclosed in
|
|
double quotes.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-D <var>name</var></code></dt>
|
|
<dt><code>--dll-name <var>name</var></code></dt>
|
|
<dd><p>Specifies the name to be stored in the <samp>.def</samp> file as the name of
|
|
the DLL when the <samp>-e</samp> option is used. If this option is not
|
|
present, then the filename given to the <samp>-e</samp> option will be
|
|
used as the name of the DLL.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-m <var>machine</var></code></dt>
|
|
<dt><code>-machine <var>machine</var></code></dt>
|
|
<dd><p>Specifies the type of machine for which the library file should be
|
|
built. <code>dlltool</code> has a built in default type, depending upon how
|
|
it was created, but this option can be used to override that. This is
|
|
normally only useful when creating DLLs for an ARM processor, when the
|
|
contents of the DLL are actually encode using Thumb instructions.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-a</code></dt>
|
|
<dt><code>--add-indirect</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
|
|
should add a section which allows the exported functions to be
|
|
referenced without using the import library. Whatever the hell that
|
|
means!
|
|
</p>
|
|
</dd>
|
|
<dt><code>-U</code></dt>
|
|
<dt><code>--add-underscore</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
|
|
should prepend an underscore to the names of <em>all</em> exported symbols.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--no-leading-underscore</code></dt>
|
|
<dt><code>--leading-underscore</code></dt>
|
|
<dd><p>Specifies whether standard symbol should be forced to be prefixed, or
|
|
not.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--add-stdcall-underscore</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
|
|
should prepend an underscore to the names of exported <em>stdcall</em>
|
|
functions. Variable names and non-stdcall function names are not modified.
|
|
This option is useful when creating GNU-compatible import libs for third
|
|
party DLLs that were built with MS-Windows tools.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-k</code></dt>
|
|
<dt><code>--kill-at</code></dt>
|
|
<dd><p>Specifies that ‘<samp>@<number></samp>’ suffixes should be omitted from the names
|
|
of stdcall functions that will be imported from the DLL. This is
|
|
useful when creating an import library for a DLL which exports stdcall
|
|
functions but without the usual ‘<samp>@<number></samp>’ symbol name suffix.
|
|
</p>
|
|
<p>This does not change the naming of symbols provided by the import library
|
|
to programs linked against it, but only the entries in the import table
|
|
(ie the .idata section).
|
|
</p>
|
|
</dd>
|
|
<dt><code>-A</code></dt>
|
|
<dt><code>--add-stdcall-alias</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports file it
|
|
should add aliases for stdcall symbols without ‘<samp>@ <number></samp>’
|
|
in addition to the symbols with ‘<samp>@ <number></samp>’.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-p</code></dt>
|
|
<dt><code>--ext-prefix-alias <var>prefix</var></code></dt>
|
|
<dd><p>Causes <code>dlltool</code> to create external aliases for all DLL
|
|
imports with the specified prefix. The aliases are created for both
|
|
external and import symbols with no leading underscore.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-x</code></dt>
|
|
<dt><code>--no-idata4</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
|
|
files it should omit the <code>.idata4</code> section. This is for compatibility
|
|
with certain operating systems.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--use-nul-prefixed-import-tables</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
|
|
files it should prefix the <code>.idata4</code> and <code>.idata5</code> by zero an
|
|
element. This emulates old gnu import library generation of
|
|
<code>dlltool</code>. By default this option is turned off.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-c</code></dt>
|
|
<dt><code>--no-idata5</code></dt>
|
|
<dd><p>Specifies that when <code>dlltool</code> is creating the exports and library
|
|
files it should omit the <code>.idata5</code> section. This is for compatibility
|
|
with certain operating systems.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-I <var>filename</var></code></dt>
|
|
<dt><code>--identify <var>filename</var></code></dt>
|
|
<dd><p>Specifies that <code>dlltool</code> should inspect the import library
|
|
indicated by <var>filename</var> and report, on <code>stdout</code>, the name(s)
|
|
of the associated DLL(s). This can be performed in addition to any
|
|
other operations indicated by the other options and arguments.
|
|
<code>dlltool</code> fails if the import library does not exist or is not
|
|
actually an import library. See also <samp>--identify-strict</samp>.
|
|
</p>
|
|
</dd>
|
|
<dt><code>--identify-strict</code></dt>
|
|
<dd><p>Modifies the behavior of the <samp>--identify</samp> option, such
|
|
that an error is reported if <var>filename</var> is associated with
|
|
more than one DLL.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-i</code></dt>
|
|
<dt><code>--interwork</code></dt>
|
|
<dd><p>Specifies that <code>dlltool</code> should mark the objects in the library
|
|
file and exports file that it produces as supporting interworking
|
|
between ARM and Thumb code.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-n</code></dt>
|
|
<dt><code>--nodelete</code></dt>
|
|
<dd><p>Makes <code>dlltool</code> preserve the temporary assembler files it used to
|
|
create the exports file. If this option is repeated then dlltool will
|
|
also preserve the temporary object files it uses to create the library
|
|
file.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-t <var>prefix</var></code></dt>
|
|
<dt><code>--temp-prefix <var>prefix</var></code></dt>
|
|
<dd><p>Makes <code>dlltool</code> use <var>prefix</var> when constructing the names of
|
|
temporary assembler and object files. By default, the temp file prefix
|
|
is generated from the pid.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-v</code></dt>
|
|
<dt><code>--verbose</code></dt>
|
|
<dd><p>Make dlltool describe what it is doing.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-h</code></dt>
|
|
<dt><code>--help</code></dt>
|
|
<dd><p>Displays a list of command-line options and then exits.
|
|
</p>
|
|
</dd>
|
|
<dt><code>-V</code></dt>
|
|
<dt><code>--version</code></dt>
|
|
<dd><p>Displays dlltool’s version number and then exits.
|
|
</p>
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
<table class="menu" border="0" cellspacing="0">
|
|
<tr><td align="left" valign="top">• <a href="def-file-format.html#def-file-format" accesskey="1">def file format</a>:</td><td> </td><td align="left" valign="top">The format of the dlltool <samp>.def</samp> file
|
|
</td></tr>
|
|
</table>
|
|
|
|
<hr>
|
|
<div class="header">
|
|
<p>
|
|
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> [<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>
|
|
</div>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|