--- ld/ld.texinfo 2002-12-27 10:55:29.000000000 +0100 +++ ld/ld.texinfo.2 2002-12-27 11:08:15.000000000 +0100 @@ -4449,6 +4449,8 @@ @section @command{ld} and WIN32 (cygwin/mingw) This section describes some of the win32 specific @command{ld} issues. +See @ref{Options,,Command Line Options} for detailled decription of used +command line options. @table @emph @cindex import libraries @@ -4460,6 +4462,54 @@ support for creating such libraries provided with the @samp{--out-implib} command line option. +@item exporting dll symbols +@cindex exporting dll symbols +The cygwin/mingw @command{ld} has several ways to export symbols for dll's. + +@table @emph +@item using auto-export functionality +@cindex using auto-export functionality +By default @command{ld} exports symbols with the auto-export functionality, +which is controlled by the following command line options: + +@example +--export-all-symbols (is set by default) +--exclude-symbols +--exclude-libs +@end example + +@item using a DEF file +@cindex using a DEF file +Another way of exporting symbols is using a DEF file. A DEF file is a special +formatted ascii file containing definitions of symbols, which should be exported, +when a a dll is created. Usually it is named @samp{.def} and is added +as any other objectfile to the link line. + +@example +gcc -o +@end example + +See an example of a DEF file for a shared library called @samp{xyz.dll}: + +@example +LIBRARY "xyz.dll" BASE=0x10000000 + +EXPORTS +foo +bar +_bar = bar +@end example + +This example defines a base address and three symbols. +The third symbol is an alias for the second. For the whole format +specification see ld/deffilep.y in the binutils sources. + +@item creating a def file +@cindex creating a def file +While linking a shared dll, ld is able to create a def file with the +@samp{--output-def } command line option. +@end table + @cindex automatic data imports @item automatic data imports The standard Windows dll format supports data imports from dlls only @@ -4609,18 +4659,12 @@ @samp{--enable-runtime-pseudo-relocs} is used. Given the improvements in speed and memory usage, one might justifiably -wonder why import libraries are used at all. There are three reasons: +wonder why import libraries are used at all. There are two reasons: 1. Until recently, the link-directly-to-dll functionality did @emph{not} work with auto-imported data. -2. Sometimes, it is useful to rename exports. For instance, the cygwin -kernel does this regularly: a symbol @samp{_foo} will be exported as -@samp{_foo}, but also as @samp{foo} by using special directives in the -DEF file when creating the import library. This ability is not -present without import libs. - -3. Also, it's sometimes necessary to include pure static objects +2. Sometimes it is necessary to include pure static objects within the import library (which otherwise contains only bfd's for indirection symbols that point to the exports of a dll). Again, the import lib for the cygwin kernel makes use of this ability, and @@ -4633,6 +4677,61 @@ massive improvements in memory requirements during linking, storage requirements, and linking speed, we expect that many developers will soon begin to use this feature whenever possible. + +@item symbol aliasing +@table @emph +@item adding additional names +Sometimes, it is useful to export symbol with additional names. +A symbol @samp{foo} will be exported as @samp{foo}, but also as +@samp{_foo} by using special directives in the DEF file when creating +the dll (which will affect also the optional created import library). +See the following example: + +@example +$cat xyz.def +LIBRARY "xyz.dll" BASE=0x61000000 + +EXPORTS +foo +_foo = foo +@end example + +The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}. + +Another way instead of adding a DEF file is by using the following recipe: +in your source code add a prototype with the "weak" attribute. + +@example +void thefunction () @{ /* do something */; @} +void aliasforfunction () __attribute__ ((weak, alias ("thefunction"))); +@end example + +This has the same effect as using a DEF file, but needs no DEF file. +In the created dll (and if choosed in the import library) the symbol +@samp{thefunction} and the symbol @samp{aliasforfunction} are defined. +See the gcc manual for more information. + +@item renaming symbols +Sometimes, it is useful to rename exports. For instance, the cygwin +kernel does this regularly: a symbol @samp{_foo} will be exported as +@samp{foo}, but not as @samp{_foo} by using special directives in the +DEF file when creating the dll (which will alos affect the optional +created import library). +See the following example: + +@example +$cat xyz.def +LIBRARY "xyz.dll" BASE=0x61000000 + +EXPORTS +_foo = foo +@end example + +The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}. +@end table + +Note: using a DEF file overrides any other symbol defining except you are +using the @samp{--export-all-symbols} command line options. @end table @ifclear GENERIC