DLLTOOL(1)

πŸ“¦ version 2.22~msp20120406, in ubuntu jammy

πŸ’– DLLTOOL(1) πŸ’–

ok so bestie, welcome to dlltool β€” a lil GNU Development Tools girlie whose whole job is making the files you need to build and use DLLs. no cap. let's get into it ✨


🌸 NAME 🌸

dlltool β€” create files needed to build and use DLLs.


πŸŽ€ SYNOPSIS πŸŽ€

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 ...]

✨ DESCRIPTION ✨

ok so picture this: dlltool reads its inputs, and those inputs can come from the -d and -b options, plus any object files you drop on the command line. it then does its lil processing thing, and:

  • if you passed -e, it creates an exports file 🫢
  • if you passed -l, it creates a library file πŸ’…
  • if you passed -z, it creates a def file ✨

and the gag is, any or all of -e, -l and -z can show up in one single invocation of dlltool. iconique. multiple slays at once, we love to see it.


so when you're creating a DLL, alongside the source for the DLL itself, you lowkey need three other files. and bestie, dlltool is literally here to help you make them. πŸ’–

the first file is a .def file. this one specifies which functions are exported from the DLL, which functions the DLL imports, and so on. it's a text file β€” you can absolutely hand-write it, or you can let dlltool create it for you with the -z option. in that case, dlltool scans the object files you specified on its command line, looking for those functions that have been specially marked as being exported, and then it drops entries for them into the .def file it creates. πŸ¦‹

ok so 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. you can do this in C using the asm() operator, like this:

          asm (".section .drectve");
          asm (".ascii \"-export:my_func\"");

          int my_func (void) { ... }

the second file you need for DLL creation is an exports file. this one gets 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. it's a binary file, and you can create it by giving the -e option to dlltool when it's creating or reading in a .def file. 🌈

the third file you need for DLL creation is the library file that programs will link with in order to access the functions in the DLL β€” aka an import library. you can create this one by giving the -l option to dlltool when it's creating or reading in a .def file. ⭐


ok now if you specify the -y option, dlltool generates a delay-import library that you can use instead of the normal import library. this lets a program 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. iykyk πŸ’…


so here's the tea on how it actually builds stuff: dlltool builds the library file by hand, but it builds the exports file by creating temporary files containing assembler statements and then assembling those. and guess what, you get knobs for that:

  • -S on the command line lets you specify the path to the assembler that dlltool will use πŸ”§
  • -f lets you pass specific flags to that assembler
  • -n can be used to prevent dlltool from deleting these temporary assembler files when it's done
  • and if -n is specified twice, that will prevent dlltool from deleting the temporary object files it used to build the library πŸ‘‘

ok bestie here's a whole example of creating a DLL from a source file dll.c AND 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

no notes, she ate. πŸ”₯


and one more lil thing: 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 for that. πŸ‘€


heads up bestie, this is only part 1 of the page β€” there's more coming, don't go anywhere πŸ’–

πŸŽ€ OPTIONS πŸŽ€

okay bestie, here's what every single command line option actually means. no gatekeeping, no skipping, we're doing all of them πŸ’–

  • -d filename, --input-def filename β€” names the .def file that dlltool should read in and process. that's the input, the source of truth, the moment.
  • -b filename, --base-file filename β€” names a base file to read in and process. whatever's inside it gets added to the relocation section in the exports file that dlltool generates.
  • -e filename, --output-exp filename β€” names the export file dlltool is gonna create. this is the output, the glow-up result ✨
  • -z filename, --output-def filename β€” names the .def file dlltool is gonna create.
  • -l filename, --output-lib filename β€” names the library file dlltool is gonna create.
  • -y filename, --output-delaylib filename β€” names the delay-import library file dlltool is gonna create. delayed, but make it fashion πŸ¦‹
  • --export-all-symbols β€” treats every global and weak defined symbol found in the input object files as a symbol to be exported. there's a small list of symbols that are NOT exported by default β€” peep --no-default-excludes for that tea. and if you wanna add more symbols to the do-not-export pile, that's what --exclude-symbols is for.
  • --no-export-all-symbols β€” only exports symbols that are explicitly listed in an input .def file, or in .drectve sections in the input object files. this is the default behaviour, bestie, so if you didn't ask for anything else, this is what you're getting. and those .drectve sections? they're created by dllexport attributes in the source code. iconic.
  • --exclude-symbols list β€” do NOT export the symbols in list. it's a list of symbol names separated by comma or colon characters. the symbol names should not contain a leading underscore. this only does anything meaningful when --export-all-symbols is being used, so don't come for it otherwise πŸ’…
  • --no-default-excludes β€” when --export-all-symbols is used, dlltool will by default avoid exporting certain special symbols. the current list of symbols it avoids exporting is DllMain@12, DllEntryPoint@0, impure_ptr. you can use the --no-default-excludes option to go ahead and export these special symbols anyway. again: this is only meaningful when --export-all-symbols is used.
  • -S path, --as path β€” specifies the path, including the filename, of the assembler that's gonna 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 one works even if you didn't use the -S option, so it's lowkey independent like that. it only takes one argument, and if it shows up more than once on the command line, the later occurrences override the earlier ones. so if you need to pass multiple options to the assembler, wrap them in double quotes, okay? okay 🫢
  • -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. and if you don't use this option? then the filename you gave to -e gets used as the name of the DLL instead. no biggie.
  • -m machine, -machine machine β€” specifies the type of machine the library file should be built for. dlltool has a built in default type that depends on how it was created, but this option overrides that. this is normally only useful when you're creating DLLs for an ARM processor, when the contents of the DLL are actually encoded using Thumb instructions.
  • -a, --add-indirect β€” when dlltool is creating the exports file, it should add a section that allows the exported functions to be referenced without using the import library. whatever the hell that means! 😭 (that's the manpage's words, not mine, I'm just the messenger)
  • -U, --add-underscore β€” when dlltool is creating the exports file, it should prepend an underscore to the names of all exported symbols. little underscore, big difference.
  • --no-leading-underscore, --leading-underscore β€” specifies whether a standard symbol should be forced to be prefixed, or not. pick your fighter.
  • --add-stdcall-underscore β€” 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 one's useful when you're creating GNU-compatible import libs for third party DLLs that were built with MS-Windows tools. slay for interop πŸ’œ
  • -k, --kill-at β€” when dlltool is creating the exports file, it should not append the string @ <number>. those numbers are called ordinal numbers, and they represent another way of accessing the function in a DLL, other than by name. so yeah, you're killing the @.
  • -A, --add-stdcall-alias β€” when dlltool is creating the exports file, it should add aliases for stdcall symbols without @ <number>, in addition to the symbols with @ <number>. both. and. periodt.
  • -p, --ext-prefix-alias prefix β€” makes dlltool create external aliases for all DLL imports with the specified prefix. the aliases get created for both external and import symbols with no leading underscore.
  • -x, --no-idata4 β€” when dlltool is creating the exports and library files, it should omit the .idata4 section. this exists for compatibility with certain operating systems, so don't touch it unless you know you need it.
  • --use-nul-prefixed-import-tables β€” when dlltool is creating the exports and library files, it should prefix the .idata4 and .idata5 by zero an element. this emulates the old gnu import library generation of dlltool. by default this option is turned off.
  • -c, --no-idata5 β€” when dlltool is creating the exports and library files, it should omit the .idata5 section. again: this is for compatibility with certain operating systems.
  • -I filename, --identify filename β€” tells dlltool to inspect the import library indicated by filename and report, on stdout, the name(s) of the associated DLL(s). this can be done in addition to any other operations indicated by the other options and arguments, so it stacks. dlltool fails if the import library does not exist or is not actually an import library. see also --identify-strict.
  • --identify-strict β€” modifies the behaviour of the --identify option, such that an error is reported if filename is associated with more than one DLL. one DLL only, bestie, we're monogamous here.
  • -i, --interwork β€” tells dlltool to 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. and if you repeat this option, dlltool will also preserve the temporary object files it uses to create the library file. double hoarding, double the vibes πŸ™ˆ
  • -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 β€” makes dlltool describe what it is doing. it's giving commentary, it's giving narrator energy πŸ‘‘
  • -h, --help β€” displays a list of command line options and then exits. classic.
  • -V, --version β€” displays dlltool's version number and then exits.
  • @file β€” reads command-line options from file. the options that get read are inserted in place of the original @file option. if file does not exist, or cannot be read, then the option will be treated literally, and not removed.

options in file are separated by whitespace. a whitespace character may be included in an option by surrounding the entire option in either single or double quotes. any character (including a backslash) may be included by prefixing the character to be included with a backslash. and the file may itself contain additional @file options β€” any such options will be processed recursively. it's files all the way down πŸŒ€


🌈 SEE ALSO 🌈

the Info pages for binutils. go read 'em, they're right there.


Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 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".


and that's the whole page, bestie!! πŸ’– this was binutils-2.21.1, dated 2011-06-27, and it's DLLTOOL(1) β€” you read the entire thing, no skimming, I'm so proud of you. go forth and build your DLLs, main character πŸ¦‹βœ¨

πŸ“¦ where this page comes from