File: binutils.info, Node: dlltool, Next: readelf, Prev: windres, Up: Top 14 dlltool ********** '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' Specifies the name of a '.def' file to be read in and processed. '-b FILENAME' '--base-file FILENAME' 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. '-e FILENAME' '--output-exp FILENAME' Specifies the name of the export file to be created by dlltool. '-z FILENAME' '--output-def FILENAME' Specifies the name of the '.def' file to be created by dlltool. '-l FILENAME' '--output-lib FILENAME' Specifies the name of the library file to be created by dlltool. '-y FILENAME' '--output-delaylib FILENAME' Specifies the name of the delay-import library file to be created by dlltool. '--export-all-symbols' 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 '--no-default-excludes' option. You may add to the list of symbols to not export by using the '--exclude-symbols' option. '--no-export-all-symbols' Only export symbols explicitly listed in an input '.def' file or in '.drectve' sections in the input object files. This is the default behaviour. The '.drectve' sections are created by 'dllexport' attributes in the source code. '--exclude-symbols LIST' Do not export the symbols in LIST. 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 '--export-all-symbols' is used. '--no-default-excludes' When '--export-all-symbols' is used, it will by default avoid exporting certain special symbols. The current list of symbols to avoid exporting is 'DllMain@12', 'DllEntryPoint@0', 'impure_ptr'. You may use the '--no-default-excludes' option to go ahead and export these special symbols. This is only meaningful when '--export-all-symbols' is used. '-S PATH' '--as PATH' Specifies the path, including the filename, of the assembler to be used to create the exports file. '-f OPTIONS' '--as-flags OPTIONS' Specifies any specific command line options to be passed to the assembler when building the exports file. This option will work even if the '-S' 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. '-D NAME' '--dll-name NAME' Specifies the name to be stored in the '.def' file as the name of the DLL when the '-e' option is used. If this option is not present, then the filename given to the '-e' option will be used as the name of the DLL. '-m MACHINE' '-machine MACHINE' Specifies the type of machine for which the library file should be built. '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' Specifies that when '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' Specifies that when 'dlltool' is creating the exports file it should prepend an underscore to the names of _all_ exported symbols. '--no-leading-underscore' '--leading-underscore' Specifies whether standard symbol should be forced to be prefixed, or not. '--add-stdcall-underscore' Specifies that when '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' Specifies that '@<number>' 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 '@<number>' symbol name suffix. 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). '-A' '--add-stdcall-alias' Specifies that when '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' Causes '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' Specifies that when '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' Specifies that when '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' Specifies that when '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' Specifies that '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' Modifies the behavior of the '--identify' option, such that an error is reported if FILENAME is associated with more than one DLL. '-i' '--interwork' Specifies that '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' Makes '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' Makes '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' Make dlltool describe what it is doing. '-h' '--help' Displays a list of command line options and then exits. '-V' '--version' Displays dlltool's version number and then exits. * Menu: * def file format:: The format of the dlltool '.def' file File: binutils.info, Node: def file format, Up: dlltool 14.1 The format of the 'dlltool' '.def' file ============================================ A '.def' file contains any number of the following commands: 'NAME' NAME '[ ,' BASE ']' The result is going to be named NAME'.exe'. 'LIBRARY' NAME '[ ,' BASE ']' The result is going to be named NAME'.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 ] ) *' Declares NAME1 as an exported symbol from the DLL, with optional ordinal number INTEGER, or declares NAME1 as an alias (forward) of the function EXTERNAL-NAME in the DLL. If ITS_NAME is specified, this name is used as string in export table. MODULE-NAME. Note: The '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 ] *' Declares that EXTERNAL-NAME or the exported function whose ordinal number is INTEGER is to be imported from the file MODULE-NAME. If INTERNAL-NAME is specified then this is the name that the imported function will be referred to in the body of the DLL. If ITS_NAME is specified, this name is used as string in import table. Note: The '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 Puts STRING into the output '.exp' file in the '.rdata' section. 'STACKSIZE' NUMBER-RESERVE '[, ' NUMBER-COMMIT ']' 'HEAPSIZE' NUMBER-RESERVE '[, ' NUMBER-COMMIT ']' Generates '--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' + ) *' Generates '--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.
Generated by $Id: phpMan.php,v 4.55 2007/09/05 04:42:51 chedong Exp $ Author: Che Dong
On Apache
Under GNU General Public License
2024-04-20 06:37 @3.19.56.45 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)