[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dlltool
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.
The export table is generated by this program by reading in a `.def' file or scanning the `.a' and `.o' files which will be in the DLL. A `.o' file can contain information in special `.drectve' sections with export information.
Note: dlltool
is not always built as part of the
binary utilities, since it is only useful for those targets which
support DLLs.
dlltool [`-d'|`--input-def' def-file-name] [`-b'|`--base-file' base-file-name] [`-e'|`--output-exp' exports-file-name] [`-z'|`--output-def' def-file-name] [`-l'|`--output-lib' library-file-name] [`-y'|`--output-delaylib' library-file-name] [`--export-all-symbols'] [`--no-export-all-symbols'] [`--exclude-symbols' list] [`--no-default-excludes'] [`-S'|`--as' path-to-assembler] [`-f'|`--as-flags' options] [`-D'|`--dllname' name] [`-m'|`--machine' machine] [`-a'|`--add-indirect'] [`-U'|`--add-underscore'] [`--add-stdcall-underscore'] [`-k'|`--kill-at'] [`-A'|`--add-stdcall-alias'] [`-p'|`--ext-prefix-alias' prefix] [`-x'|`--no-idata4'] [`-c'|`--no-idata5'] [`--use-nul-prefixed-import-tables'] [`-I'|`--identify' library-file-name] [`--identify-strict'] [`-i'|`--interwork'] [`-n'|`--nodelete'] [`-t'|`--temp-prefix' prefix] [`-v'|`--verbose'] [`-h'|`--help'] [`-V'|`--version'] [`--no-leading-underscore'] [`--leading-underscore'] [object-file ...] |
dlltool
reads its inputs, which can come from the `-d' and
`-b' options as well as object files specified on the command
line. It then processes these inputs and if the `-e' option has
been specified it creates a exports file. If the `-l' option
has been specified it creates a library file and if the `-z' option
has been specified it creates a def file. Any or all of the `-e',
`-l' and `-z' options can be present in one invocation of
dlltool.
When creating a DLL, along with the source for the DLL, it is necessary
to have three other files. dlltool
can help with the creation of
these files.
The first file is a `.def' 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 dlltool
can be used
to create it using the `-z' option. In this case dlltool
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 `.def' file it creates.
In order to mark a function as being exported from a DLL, it needs to have an `-export:<name_of_function>' entry in the `.drectve' section of the object file. This can be done in C by using the asm() operator:
asm (".section .drectve"); asm (".ascii \"-export:my_func\""); int my_func (void) { ... } |
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 `-e' option to
dlltool
when it is creating or reading in a `.def' file.
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 `-l' option to dlltool when it is creating or reading in a `.def' file.
If the `-y' 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.
dlltool
builds the library file by hand, but it builds the
exports file by creating temporary files containing assembler statements
and then assembling these. The `-S' command line option can be
used to specify the path to the assembler that dlltool will use,
and the `-f' option can be used to pass specific flags to that
assembler. The `-n' can be used to prevent dlltool from deleting
these temporary assembler files when it is done, and if `-n' is
specified twice then this will prevent dlltool from deleting the
temporary object files it used to build the library.
Here is an example of creating a DLL from a source file `dll.c' and also creating a program (from an object file called `program.o') that uses that DLL:
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 |
dlltool
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 `-I' or `--identify' option.
The command line options have the following meanings:
-d filename
--input-def filename
-b filename
--base-file filename
-e filename
--output-exp filename
-z filename
--output-def filename
-l filename
--output-lib filename
-y filename
--output-delaylib filename
--export-all-symbols
--no-export-all-symbols
--exclude-symbols list
--no-default-excludes
-S path
--as path
-f options
--as-flags options
-D name
--dll-name name
-m machine
-machine machine
dlltool
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.
-a
--add-indirect
dlltool
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!
-U
--add-underscore
dlltool
is creating the exports file it
should prepend an underscore to the names of all exported symbols.
--no-leading-underscore
--leading-underscore
--add-stdcall-underscore
dlltool
is creating the exports file it
should prepend an underscore to the names of exported stdcall
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.
-k
--kill-at
dlltool
is creating the exports file it
should not append the string `@ <number>'. These numbers are
called ordinal numbers and they represent another way of accessing the
function in a DLL, other than by name.
-A
--add-stdcall-alias
dlltool
is creating the exports file it
should add aliases for stdcall symbols without `@ <number>'
in addition to the symbols with `@ <number>'.
-p
--ext-prefix-alias prefix
dlltool
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.
-x
--no-idata4
dlltool
is creating the exports and library
files it should omit the .idata4
section. This is for compatibility
with certain operating systems.
--use-nul-prefixed-import-tables
dlltool
is creating the exports and library
files it should prefix the .idata4
and .idata5
by zero an
element. This emulates old gnu import library generation of
dlltool
. By default this option is turned off.
-c
--no-idata5
dlltool
is creating the exports and library
files it should omit the .idata5
section. This is for compatibility
with certain operating systems.
-I filename
--identify filename
dlltool
should inspect the import library
indicated by filename and report, on stdout
, 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.
dlltool
fails if the import library does not exist or is not
actually an import library. See also `--identify-strict'.
--identify-strict
-i
--interwork
dlltool
should mark the objects in the library
file and exports file that it produces as supporting interworking
between ARM and Thumb code.
-n
--nodelete
dlltool
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.
-t prefix
--temp-prefix prefix
dlltool
use prefix when constructing the names of
temporary assembler and object files. By default, the temp file prefix
is generated from the pid.
-v
--verbose
-h
--help
-V
--version
14.1 The format of the dlltool
`.def' fileThe format of the dlltool `.def' file
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
dlltool
`.def' file A `.def' file contains any number of the following commands:
NAME
name [ ,
base ]
.exe
.
LIBRARY
name [ ,
base ]
.dll
.
Note: If you want to use LIBRARY as name then you need to quote. Otherwise
this will fail due a necessary hack for libtool (see PR binutils/13710 for more
details).
EXPORTS ( ( (
name1 [ =
name2 ] ) | (
name1 =
module-name .
external-name ) ) [ ==
its_name ]
[
integer ] [ NONAME ] [ CONSTANT ] [ DATA ] [ PRIVATE ] ) *
EXPORTS
has to be the last command in .def file, as keywords
are treated - beside LIBRARY
- as simple name-identifiers.
If you want to use LIBRARY as name then you need to quote it.
IMPORTS ( (
internal-name =
module-name .
integer ) | [
internal-name = ]
module-name .
external-name ) [ == ) its_name ]
*
IMPORTS
has to be the last command in .def file, as keywords
are treated - beside LIBRARY
- as simple name-identifiers.
If you want to use LIBRARY as name then you need to quote it.
DESCRIPTION
string
.rdata
section.
STACKSIZE
number-reserve [,
number-commit ]
HEAPSIZE
number-reserve [,
number-commit ]
--stack
or --heap
number-reserve,number-commit in the output .drectve
section. The linker will see this and act upon it.
CODE
attr +
DATA
attr +
SECTIONS (
section-name attr + ) *
--attr
section-name attr in the output
.drectve
section, where attr is one of READ
,
WRITE
, EXECUTE
or SHARED
. The linker will see
this and act upon it.
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |