X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=ld%2Fld.texinfo;h=35435053b3c52e5fb15b2419f27aca226186e826;hb=258795f524fca9d5b98441b81684c331c4d721b1;hp=700662eaa3a456dad5f280c65e4e982952c80512;hpb=016687f8ba456b033639a2174da7a0fc35428eb8;p=deliverable%2Fbinutils-gdb.git diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 700662eaa3..35435053b3 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -1,7 +1,7 @@ \input texinfo @setfilename ld.info @c Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -@c 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +@c 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. @syncodeindex ky cp @c man begin INCLUDE @include configdoc.texi @@ -25,6 +25,7 @@ @set HPPA @set I960 @set M68HC11 +@set M68K @set MMIX @set MSP430 @set POWERPC @@ -45,32 +46,23 @@ END-INFO-DIR-ENTRY @end format @end ifinfo -@ifinfo +@copying This file documents the @sc{gnu} linker LD @ifset VERSION_PACKAGE @value{VERSION_PACKAGE} @end ifset version @value{VERSION}. -Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, -2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. - -@ignore +Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, +2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 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.1 +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''. - -Permission is granted to process this file through Tex and print the -results, provided the printed document carries copying permission -notice identical to this one except for the removal of this paragraph -(this paragraph not being relevant to the printed manual). - -@end ignore -@end ifinfo +@end copying @iftex @finalout @setchapternewpage odd @@ -100,10 +92,10 @@ notice identical to this one except for the removal of this paragraph @vskip 0pt plus 1filll @c man begin COPYRIGHT Copyright @copyright{} 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +2002, 2003, 2004, 2005, 2006, 2007, 2008 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.1 +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 @@ -125,8 +117,8 @@ This file documents the @sc{gnu} linker ld version @value{VERSION}. This document is distributed under the terms of the GNU Free -Documentation License. A copy of the license is included in the -section entitled ``GNU Free Documentation License''. +Documentation License version 1.3. A copy of the license is included +in the section entitled ``GNU Free Documentation License''. @menu * Overview:: Overview @@ -154,6 +146,9 @@ section entitled ``GNU Free Documentation License''. @ifset M68HC11 * M68HC11/68HC12:: ld and the Motorola 68HC11 and 68HC12 families @end ifset +@ifset M68K +* M68K:: ld and Motorola 68K family +@end ifset @ifset POWERPC * PowerPC ELF32:: ld and PowerPC 32-bit ELF Support @end ifset @@ -306,10 +301,11 @@ augments the main linker script used for the link (either the default linker script or the one specified by using @samp{-T}). This feature permits the linker to link against a file which appears to be an object or an archive, but actually merely defines some symbol values, or uses -@code{INPUT} or @code{GROUP} to load other objects. Note that -specifying a script in this way merely augments the main linker script; -use the @samp{-T} option to replace the default linker script entirely. -@xref{Scripts}. +@code{INPUT} or @code{GROUP} to load other objects. Specifying a +script in this way merely augments the main linker script, with the +extra commands placed after the main script; use the @samp{-T} option +to replace the default linker script entirely, but note the effect of +the @code{INSERT} command. @xref{Scripts}. For options whose names are a single letter, option arguments must either follow the option letter without intervening @@ -461,7 +457,7 @@ and other ways of specifying the entry point. @kindex --exclude-libs @item --exclude-libs @var{lib},@var{lib},... Specifies a list of archive libraries from which symbols should not be automatically -exported. The library names may be delimited by commas or colons. Specifying +exported. The library names may be delimited by commas or colons. Specifying @code{--exclude-libs ALL} excludes symbols in all archive libraries from automatic export. This option is available only for the i386 PE targeted port of the linker and for ELF targeted ports. For i386 PE, symbols @@ -469,6 +465,19 @@ explicitly listed in a .def file are still exported, regardless of this option. For ELF targeted ports, symbols affected by this option will be treated as hidden. +@kindex --exclude-modules-for-implib +@item --exclude-modules-for-implib @var{module},@var{module},... +Specifies a list of object files or archive members, from which symbols +should not be automatically exported, but which should be copied wholesale +into the import library being generated during the link. The module names +may be delimited by commas or colons, and must match exactly the filenames +used by @command{ld} to open the files; for archive members, this is simply +the member name, but for object files the name listed must include and +match precisely any path used to specify the input file on the linker's +command-line. This option is available only for the i386 PE targeted port +of the linker. Symbols explicitly listed in a .def file are still exported, +regardless of this option. + @cindex dynamic symbol table @kindex -E @kindex --export-dynamic @@ -767,7 +776,11 @@ script command @code{OUTPUT} can also specify the output file name. @item -O @var{level} If @var{level} is a numeric values greater than zero @command{ld} optimizes the output. This might take significantly longer and therefore probably -should only be enabled for the final binary. +should only be enabled for the final binary. At the moment this +option only affects ELF shared library generation. Future releases of +the linker may make more use of this option. Also currently there is +no difference in the linker's behaviour for different non-zero values +of this option. Again this may change with future releases. @kindex -q @kindex --emit-relocs @@ -1152,7 +1165,7 @@ platforms which support shared libraries. @kindex -Bsymbolic-functions @item -Bsymbolic-functions When creating a shared library, bind references to global function -symbols to the definition within the shared library, if any. +symbols to the definition within the shared library, if any. This option is only meaningful on ELF platforms which support shared libraries. @@ -1263,10 +1276,12 @@ generating dynamically linked ELF executables. The default dynamic linker is normally correct; don't use this unless you know what you are doing. - @kindex --fatal-warnings +@kindex --no-fatal-warnings @item --fatal-warnings -Treat all warnings as errors. +@itemx --no-fatal-warnings +Treat all warnings as errors. The default behaviour can be restored +with the option @option{--no-fatal-warnings}. @kindex --force-exe-suffix @item --force-exe-suffix @@ -1285,11 +1300,25 @@ it ends in a @code{.exe} suffix. @item --gc-sections @itemx --no-gc-sections Enable garbage collection of unused input sections. It is ignored on -targets that do not support this option. This option is not compatible -with @samp{-r} or @samp{--emit-relocs}. The default behaviour (of not +targets that do not support this option. The default behaviour (of not performing this garbage collection) can be restored by specifying @samp{--no-gc-sections} on the command line. +@samp{--gc-sections} decides which input sections are used by +examining symbols and relocations. The section containing the entry +symbol and all sections containing symbols undefined on the +command-line will be kept, as will sections containing symbols +referenced by dynamic objects. Note that when building shared +libraries, the linker must assume that any visible symbol is +referenced. Once this initial set of sections has been determined, +the linker recursively marks as used any section referenced by their +relocations. See @samp{--entry} and @samp{--undefined}. + +This option can be set when doing a partial link (enabled with option +@samp{-r}). In this case the root of symbols kept must be explicitely +specified either by an @samp{--entry} or @samp{--undefined} option or by +a @code{ENTRY} command in the linker script. + @kindex --print-gc-sections @kindex --no-print-gc-sections @cindex garbage collection @@ -1573,15 +1602,15 @@ at link time. Searching @option{-rpath} in this way is only supported by native linkers and cross linkers which have been configured with the @option{--with-sysroot} option. @item -On an ELF system, if the @option{-rpath} and @code{rpath-link} options -were not used, search the contents of the environment variable -@code{LD_RUN_PATH}. It is for the native linker only. +On an ELF system, for native linkers, if the @option{-rpath} and +@option{-rpath-link} options were not used, search the contents of the +environment variable @code{LD_RUN_PATH}. @item On SunOS, if the @option{-rpath} option was not used, search any directories specified using @option{-L} options. @item -For a native linker, the contents of the environment variable -@code{LD_LIBRARY_PATH}. +For a native linker, the search the contents of the environment +variable @code{LD_LIBRARY_PATH}. @item For a native ELF linker, the directories in @code{DT_RUNPATH} or @code{DT_RPATH} of a shared library are searched for shared @@ -1608,13 +1637,14 @@ and SunOS platforms. On SunOS, the linker will automatically create a shared library if the @option{-e} option is not used and there are undefined symbols in the link. -@item --sort-common +@item --sort-common [= ascending | descending] @kindex --sort-common -This option tells @command{ld} to sort the common symbols by size when it -places them in the appropriate output sections. First come all the one -byte symbols, then all the two byte, then all the four byte, and then -everything else. This is to prevent gaps between symbols due to -alignment constraints. +This option tells @command{ld} to sort the common symbols by alignment in +ascending or descending order when it places them in the appropriate output +sections. The symbol alignments considered are sixteen-byte or larger, +eight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps +between symbols due to alignment constraints. If no sorting order is +specified, then descending order is assumed. @kindex --sort-section name @item --sort-section name @@ -1693,6 +1723,12 @@ sign (``@key{=}''), and @var{org}. Same as --section-start, with @code{.bss}, @code{.data} or @code{.text} as the @var{sectionname}. +@kindex -Ttext-segment @var{org} +@itemx -Ttext-segment @var{org} +@cindex text segment origin, cmd line +When creating an ELF executable or shared object, it will set the address +of the first byte of the text segment. + @kindex --unresolved-symbols @item --unresolved-symbols=@var{method} Determine how to handle unresolved symbols. There are four possible @@ -1975,6 +2011,30 @@ has been used. The @option{--reduce-memory-overheads} switch may be also be used to enable other tradeoffs in future versions of the linker. +@kindex --build-id +@kindex --build-id=@var{style} +@item --build-id +@itemx --build-id=@var{style} +Request creation of @code{.note.gnu.build-id} ELF note section. +The contents of the note are unique bits identifying this linked +file. @var{style} can be @code{uuid} to use 128 random bits, +@code{sha1} to use a 160-bit @sc{SHA1} hash on the normative +parts of the output contents, @code{md5} to use a 128-bit +@sc{MD5} hash on the normative parts of the output contents, or +@code{0x@var{hexstring}} to use a chosen bit string specified as +an even number of hexadecimal digits (@code{-} and @code{:} +characters between digit pairs are ignored). If @var{style} is +omitted, @code{sha1} is used. + +The @code{md5} and @code{sha1} styles produces an identifier +that is always the same in an identical output file, but will be +unique among all nonidentical output files. It is not intended +to be compared as a checksum for the file's contents. A linked +file may be changed later by other tools, but the build ID bit +string identifying the original linked file does not change. + +Passing @code{none} for @var{style} disables the setting from any +@code{--build-id} options earlier on the command line. @end table @c man end @@ -2082,8 +2142,8 @@ file offsets which are multiples of this number. This defaults to @kindex --heap @item --heap @var{reserve} @itemx --heap @var{reserve},@var{commit} -Specify the amount of memory to reserve (and optionally commit) to be -used as heap for this program. The default is 1Mb reserved, 4K +Specify the number of bytes of memory to reserve (and optionally commit) +to be used as heap for this program. The default is 1Mb reserved, 4K committed. [This option is specific to the i386 PE targeted port of the linker] @@ -2201,6 +2261,12 @@ building the import libraries with those DATA exports. Note: Use of the to be made writable. This does not conform to the PE-COFF format specification published by Microsoft. +Note - use of the 'auto-import' extension will also cause read only +data which would normally be placed into the .rdata section to be +placed into the .data section instead. This is in order to work +around a problem with consts that is described here: +http://www.cygwin.com/ml/cygwin/2004-09/msg01101.html + Using 'auto-import' generally will 'just work' -- but sometimes you may see this message: @@ -2209,9 +2275,9 @@ documentation for ld's @code{--enable-auto-import} for details." This message occurs when some (sub)expression accesses an address ultimately given by the sum of two constants (Win32 import tables only -allow one). Instances where this may occur include accesses to member -fields of struct variables imported from a DLL, as well as using a -constant index into an array variable imported from a DLL. Any +allow one). Instances where this may occur include accesses to member +fields of struct variables imported from a DLL, as well as using a +constant index into an array variable imported from a DLL. Any multiword variable (arrays, structs, long long, etc) may trigger this error condition. However, regardless of the exact data type of the offending exported variable, ld will always detect it, issue @@ -2224,14 +2290,14 @@ One way is to use --enable-runtime-pseudo-reloc switch. This leaves the task of adjusting references in your client code for runtime environment, so this method works only when runtime environment supports this feature. -A second solution is to force one of the 'constants' to be a variable -- -that is, unknown and un-optimizable at compile time. For arrays, -there are two possibilities: a) make the indexee (the array's address) +A second solution is to force one of the 'constants' to be a variable -- +that is, unknown and un-optimizable at compile time. For arrays, +there are two possibilities: a) make the indexee (the array's address) a variable, or b) make the 'constant' index a variable. Thus: @example extern type extern_array[]; -extern_array[1] --> +extern_array[1] --> @{ volatile type *t=extern_array; t[1] @} @end example @@ -2239,16 +2305,16 @@ or @example extern type extern_array[]; -extern_array[1] --> +extern_array[1] --> @{ volatile int t=1; extern_array[t] @} @end example -For structs (and most other multiword data types) the only option +For structs (and most other multiword data types) the only option is to make the struct itself (or the long long, or the ...) variable: @example extern struct s extern_struct; -extern_struct.field --> +extern_struct.field --> @{ volatile struct s *t=&extern_struct; t->field @} @end example @@ -2261,12 +2327,12 @@ extern_ll --> @end example A third method of dealing with this difficulty is to abandon -'auto-import' for the offending symbol and mark it with +'auto-import' for the offending symbol and mark it with @code{__declspec(dllimport)}. However, in practise that requires using compile-time #defines to indicate whether you are -building a DLL, building client code that will link to the DLL, or -merely building/linking to a static library. In making the choice -between the various methods of resolving the 'direct address with +building a DLL, building client code that will link to the DLL, or +merely building/linking to a static library. In making the choice +between the various methods of resolving the 'direct address with constant offset' problem, you should consider typical real-world usage: Original: @@ -2311,7 +2377,7 @@ void main(int argc, char **argv)@{ @} @end example -A fourth way to avoid this problem is to re-code your +A fourth way to avoid this problem is to re-code your library to use a functional interface rather than a data interface for the offending variables (e.g. set_foo() and get_foo() accessor functions). @@ -2319,7 +2385,7 @@ functions). @kindex --disable-auto-import @item --disable-auto-import -Do not attempt to do sophisticated linking of @code{_symbol} to +Do not attempt to do sophisticated linking of @code{_symbol} to @code{__imp__symbol} for DATA imports from DLLs. [This option is specific to the i386 PE targeted port of the linker] @@ -2328,7 +2394,7 @@ Do not attempt to do sophisticated linking of @code{_symbol} to If your code contains expressions described in --enable-auto-import section, that is, DATA imports from DLL with non-zero offset, this switch will create a vector of 'runtime pseudo relocations' which can be used by runtime -environment to adjust references to such data in your client code. +environment to adjust references to such data in your client code. [This option is specific to the i386 PE targeted port of the linker] @kindex --disable-runtime-pseudo-reloc @@ -2352,8 +2418,8 @@ addresses which are a multiple of this number. Defaults to 0x1000. @kindex --stack @item --stack @var{reserve} @itemx --stack @var{reserve},@var{commit} -Specify the amount of memory to reserve (and optionally commit) to be -used as stack for this program. The default is 2Mb reserved, 4K +Specify the number of bytes of memory to reserve (and optionally commit) +to be used as stack for this program. The default is 2Mb reserved, 4K committed. [This option is specific to the i386 PE targeted port of the linker] @@ -2400,6 +2466,28 @@ paging and addresses within the memory window. @c man end @end ifset +@ifset M68K +@subsection Options specific to Motorola 68K target + +@c man begin OPTIONS + +The following options are supported to control handling of GOT generation +when linking for 68K targets. + +@table @gcctabopt + +@kindex --got +@item --got=@var{type} +This option tells the linker which GOT generation scheme to use. +@var{type} should be one of @samp{single}, @samp{negative}, +@samp{multigot} or @samp{target}. For more information refer to the +Info entry for @file{ld}. + +@end table + +@c man end +@end ifset + @ifset UsesEnvVars @node Environment @section Environment Variables @@ -2695,6 +2783,9 @@ be searched for in the current directory, and in any directory specified with the @option{-L} option. You can nest calls to @code{INCLUDE} up to 10 levels deep. +You can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or +@code{SECTIONS} commands, or in output section descriptions. + @item INPUT(@var{file}, @var{file}, @dots{}) @itemx INPUT(@var{file} @var{file} @dots{}) @kindex INPUT(@var{files}) @@ -2864,6 +2955,35 @@ This command has the same effect as the @samp{--no-define-common} command-line option: to make @code{ld} omit the assignment of addresses to common symbols even for a non-relocatable output file. +@item INSERT [ AFTER | BEFORE ] @var{output_section} +@kindex INSERT +@cindex insert user script into default script +This command is typically used in a script specified by @samp{-T} to +augment the default @code{SECTIONS} with, for example, overlays. It +inserts all prior linker script statements after (or before) +@var{output_section}, and also causes @samp{-T} to not override the +default linker script. The exact insertion point is as for orphan +sections. @xref{Location Counter}. The insertion happens after the +linker has mapped input sections to output sections. Prior to the +insertion, since @samp{-T} scripts are parsed before the default +linker script, statements in the @samp{-T} script occur before the +default linker script statements in the internal linker representation +of the script. In particular, input section assignments will be made +to @samp{-T} output sections before those in the default script. Here +is an example of how a @samp{-T} script using @code{INSERT} might look: + +@smallexample +SECTIONS +@{ + OVERLAY : + @{ + .ov1 @{ ov1*(.text) @} + .ov2 @{ ov2*(.text) @} + @} +@} +INSERT AFTER .text; +@end smallexample + @item NOCROSSREFS(@var{section} @var{section} @dots{}) @kindex NOCROSSREFS(@var{sections}) @cindex cross references @@ -3105,7 +3225,7 @@ Then the C source code to perform the copy would be: @smallexample @group extern char start_of_ROM, end_of_ROM, start_of_FLASH; - + memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM); @end group @end smallexample @@ -3308,7 +3428,7 @@ of files from matching the file name wildcard, EXCLUDE_FILE may be used to match all files except the ones specified in the EXCLUDE_FILE list. For example: @smallexample -(*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)) +*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors) @end smallexample will cause all .ctors sections from all files except @file{crtend.o} and @file{otherfile.o} to be included. @@ -3333,6 +3453,29 @@ needs to be at a particular location in memory. For example: data.o(.data) @end smallexample +You can also specify files within archives by writing a pattern +matching the archive, a colon, then the pattern matching the file, +with no whitespace around the colon. + +@table @samp +@item archive:file +matches file within archive +@item archive: +matches the whole archive +@item :file +matches file but not one in an archive +@end table + +Either one or both of @samp{archive} and @samp{file} can contain shell +wildcards. On DOS based file systems, the linker will assume that a +single letter followed by a colon is a drive specifier, so +@samp{c:myfile.o} is a simple file specification, not @samp{myfile.o} +within an archive called @samp{c}. @samp{archive:file} filespecs may +also be used within an @code{EXCLUDE_FILE} list, but may not appear in +other linker script contexts. For instance, you cannot extract a file +from an archive by using @samp{archive:file} in an @code{INPUT} +command. + If you use a file name without a list of sections, then all sections in the input file will be included in the output section. This is not commonly done, but it may by useful on occasion. For example: @@ -3340,7 +3483,8 @@ commonly done, but it may by useful on occasion. For example: data.o @end smallexample -When you use a file name which does not contain any wild card +When you use a file name which is not an @samp{archive:file} specifier +and does not contain any wild card characters, the linker will first see if you also specified the file name on the linker command line or in an @code{INPUT} command. If you did not, the linker will attempt to open the file as an input file, as @@ -3425,7 +3569,7 @@ sections have the same name. It will sort the input sections by alignment first, then by name if 2 sections have the same alignment. @item -@code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is +@code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is treated the same as @code{SORT_BY_NAME} (wildcard section pattern). @item @code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)) @@ -4200,12 +4344,12 @@ output sections directed to a memory region are too large for the region, the linker will issue an error message. It is possible to access the origin and length of a memory in an -expression via the @code{ORIGIN(@var{memory})} and +expression via the @code{ORIGIN(@var{memory})} and @code{LENGTH(@var{memory})} functions: @smallexample @group - _fstack = ORIGIN(ram) + LENGTH(ram) - 4; + _fstack = ORIGIN(ram) + LENGTH(ram) - 4; @end group @end smallexample @@ -4406,10 +4550,10 @@ VERS_1.2 @{ VERS_2.0 @{ bar1; bar2; - extern "C++" @{ + extern "C++" @{ ns::*; "int f(int, double)"; - @} + @} @} VERS_1.2; @end smallexample @@ -4436,7 +4580,11 @@ When the linker finds a symbol defined in a library which is not specifically bound to a version node, it will effectively bind it to an unspecified base version of the library. You can bind all otherwise unspecified symbols to a given version node by using @samp{global: *;} -somewhere in the version script. +somewhere in the version script. Note that it's slightly crazy to use +wildcards in a global spec except on the last version node. Global +wildcards elsewhere run the risk of accidentally adding symbols to the +set exported for an old version. That's wrong since older versions +ought to have a fixed set of symbols. The names of the version nodes have no specific meaning other than what they might suggest to the person reading them. The @samp{2.0} version @@ -4527,7 +4675,7 @@ You can also specify the language in the version script: VERSION extern "lang" @{ version-script-commands @} @end smallexample -The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}. +The supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}. The linker will iterate over the list of symbols at the link time and demangle them according to @samp{lang} before matching them to the patterns specified in @samp{version-script-commands}. @@ -4637,6 +4785,14 @@ at the end of the file. For ELF targets, the attribute of the section includes section type as well as section flag. +If an orphaned section's name is representable as a C identifier then +the linker will automatically @pxref{PROVIDE} two symbols: +__start_SECNAME and __end_SECNAME, where SECNAME is the name of the +section. These indicate the start address and end address of the +orphaned section respectively. Note: most section names are not +representable as C identifiers because they contain a @samp{.} +character. + @node Location Counter @subsection The Location Counter @kindex . @@ -5004,6 +5160,25 @@ of @code{ALIGN} is used to defines the value of a symbol. The builtin function @code{NEXT} is closely related to @code{ALIGN}. +@item ALIGNOF(@var{section}) +@kindex ALIGNOF(@var{section}) +@cindex section alignment +Return the alignment in bytes of the named @var{section}, if that section has +been allocated. If the section has not been allocated when this is +evaluated, the linker will report an error. In the following example, +the alignment of the @code{.output} section is stored as the first +value in that section. +@smallexample +@group +SECTIONS@{ @dots{} + .output @{ + LONG (ALIGNOF (.output)) + @dots{} + @} +@dots{} @} +@end group +@end smallexample + @item BLOCK(@var{exp}) @kindex BLOCK(@var{exp}) This is a synonym for @code{ALIGN}, for compatibility with older linker @@ -5213,6 +5388,9 @@ functionality are not listed. @ifset HPPA * HPPA ELF32:: @command{ld} and HPPA 32-bit ELF @end ifset +@ifset M68K +* M68K:: @command{ld} and the Motorola 68K family +@end ifset @ifset MMIX * MMIX:: @command{ld} and MMIX @end ifset @@ -5274,20 +5452,20 @@ page of memory, and changes them to use the eight-bit address form. top page of memory). @item bit manipulation instructions -@command{ld} finds all bit manipulation instructions like @code{band, bclr, +@command{ld} finds all bit manipulation instructions like @code{band, bclr, biand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor} -which use 32 bit and 16 bit absolute address form, but refer to the top +which use 32 bit and 16 bit absolute address form, but refer to the top page of memory, and changes them to use the 8 bit address form. (That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into -@samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in +@samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in the top page of memory). @item system control instructions -@command{ld} finds all @code{ldc.w, stc.w} instructions which use the -32 bit absolute address form, but refer to the top page of memory, and +@command{ld} finds all @code{ldc.w, stc.w} instructions which use the +32 bit absolute address form, but refer to the top page of memory, and changes them to use 16 bit address form. (That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into -@samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in +@samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in the top page of memory). @end table @@ -5412,18 +5590,11 @@ addressing mode. These instructions consists of @code{bclr} or @cindex trampoline generation on M68HC12 For 68HC11 and 68HC12, @command{ld} can generate trampoline code to call a far function using a normal @code{jsr} instruction. The linker -will also change the relocation to some far function to use the +will also change the relocation to some far function to use the trampoline address instead of the function address. This is typically the case when a pointer to a function is taken. The pointer will in fact point to the function trampoline. -@cindex PIC_VENEER -@kindex --pic-veneer -The @samp{--pic-veneer} switch makes the linker use PIC sequences for -ARM/Thumb interworking veneers, even if the rest of the binary -is not PIC. This avoids problems on uClinux targets where -@samp{--emit-relocs} is used to generate relocatable binaries. - @ifclear GENERIC @lowersections @end ifclear @@ -5454,6 +5625,13 @@ But it also sets the bottom bit of the address, so that it can be branched to using a BX instruction, and the program will start executing in Thumb mode straight away. +@cindex PE import table prefixing +@kindex --use-nul-prefixed-import-tables +The @samp{--use-nul-prefixed-import-tables} switch is specifying, that +the import tables idata4 and idata5 have to be generated with a zero +elememt prefix for import libraries. This is the old style to generate +import tables. By default this option is turned off. + @cindex BE8 @kindex --be8 The @samp{--be8} switch instructs @command{ld} to generate BE8 format @@ -5496,6 +5674,21 @@ linker, which causes v4t @code{BX rM} instructions to be rewritten as In the former case, the switch should not be used, and @samp{R_ARM_V4BX} relocations are ignored. +@cindex FIX_V4BX_INTERWORKING +@kindex --fix-v4bx-interworking +Replace @code{BX rM} instructions identified by @samp{R_ARM_V4BX} +relocations with a branch to the following veneer: + +@smallexample +TST rM, #1 +MOVEQ PC, rM +BX Rn +@end smallexample + +This allows generation of libraries/applications that work on ARMv4 cores +and are still interworking safe. Note that the above veneer clobbers the +condition flags, so may cause incorrect progrm behavior in rare cases. + @cindex USE_BLX @kindex --use-blx The @samp{--use-blx} switch enables the linker to use ARM/Thumb @@ -5539,13 +5732,59 @@ are sufficient to avoid the erratum in both the scalar and vector cases. @cindex NO_ENUM_SIZE_WARNING @kindex --no-enum-size-warning -The @samp{--no-enum-size-warning} switch prevents the linker from +The @option{--no-enum-size-warning} switch prevents the linker from warning when linking object files that specify incompatible EABI enumeration size attributes. For example, with this switch enabled, linking of an object file using 32-bit enumeration values with another using enumeration values fitted into the smallest possible space will not be diagnosed. +@cindex NO_WCHAR_SIZE_WARNING +@kindex --no-wchar-size-warning +The @option{--no-wchar-size-warning} switch prevents the linker from +warning when linking object files that specify incompatible EABI +@code{wchar_t} size attributes. For example, with this switch enabled, +linking of an object file using 32-bit @code{wchar_t} values with another +using 16-bit @code{wchar_t} values will not be diagnosed. + +@cindex PIC_VENEER +@kindex --pic-veneer +The @samp{--pic-veneer} switch makes the linker use PIC sequences for +ARM/Thumb interworking veneers, even if the rest of the binary +is not PIC. This avoids problems on uClinux targets where +@samp{--emit-relocs} is used to generate relocatable binaries. + +@cindex STUB_GROUP_SIZE +@kindex --stub-group-size=@var{N} +The linker will automatically generate and insert small sequences of +code into a linked ARM ELF executable whenever an attempt is made to +perform a function call to a symbol that is too far away. The +placement of these sequences of instructions - called stubs - is +controlled by the command line option @option{--stub-group-size=N}. +The placement is important because a poor choice can create a need for +duplicate stubs, increasing the code sizw. The linker will try to +group stubs together in order to reduce interruptions to the flow of +code, but it needs guidance as to how big these groups should be and +where they should be placed. + +The value of @samp{N}, the parameter to the +@option{--stub-group-size=} option controls where the stub groups are +placed. If it is negative then all stubs are placed before the first +branch that needs them. If it is positive then the stubs can be +placed either before or after the branches that need them. If the +value of @samp{N} is 1 (either +1 or -1) then the linker will choose +exactly where to place groups of stubs, using its built in heuristics. +A value of @samp{N} greater than 1 (or smaller than -1) tells the +linker that a single group of stubs can service at most @samp{N} bytes +from the input sections. + +The default, if @option{--stub-group-size=} is not specified, is +@samp{N = +1}. + +Farcalls stubs insertion is fully supported for the ARM-EABI target +only, because it relies on object files properties not present +otherwise. + @ifclear GENERIC @lowersections @end ifclear @@ -5593,6 +5832,35 @@ large, it may not be possible for a branch to reach its stub. @end ifclear @end ifset +@ifset M68K +@ifclear GENERIC +@raisesections +@end ifclear + +@node M68K +@section @command{ld} and the Motorola 68K family + +@cindex Motorola 68K GOT generation +@kindex --got=@var{type} +The @samp{--got=@var{type}} option lets you choose the GOT generation scheme. +The choices are @samp{single}, @samp{negative}, @samp{multigot} and +@samp{target}. When @samp{target} is selected the linker chooses +the default GOT generation scheme for the current target. +@samp{single} tells the linker to generate a single GOT with +entries only at non-negative offsets. +@samp{negative} instructs the linker to generate a single GOT with +entries at both negative and positive offsets. Not all environments +support such GOTs. +@samp{multigot} allows the linker to generate several GOTs in the +output file. All GOT references from a single input object +file access the same GOT, but references from different input object +files might access different GOTs. Not all environments support such GOTs. + +@ifclear GENERIC +@lowersections +@end ifclear +@end ifset + @ifset MMIX @ifclear GENERIC @raisesections @@ -5614,10 +5882,10 @@ global register multiplied by 8. Register @code{$255} is not included in this section; it is always set to the program entry, which is at the symbol @code{Main} for @code{mmo} files. -Symbols with the prefix @code{__.MMIX.start.}, for example -@code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special; -there must be only one each, even if they are local. The default linker -script uses these to set the default start address of a section. +Global symbols with the prefix @code{__.MMIX.start.}, for example +@code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special. +The default linker script uses these to set the default start address +of a section. Initial and trailing multiples of zero-valued 32-bit words in a section, are left out from an mmo file. @@ -5653,14 +5921,14 @@ in this section will be uploaded to the MPU. Defines an information memory section (if applicable). Any code in this section will be uploaded to the MPU. -@item @samp{.infomemnobits} +@item @samp{.infomemnobits} This is the same as the @samp{.infomem} section except that any code in this section will not be uploaded to the MPU. @item @samp{.noinit} Denotes a portion of RAM located above @samp{.bss} section. -The last two sections are used by gcc. +The last two sections are used by gcc. @end table @ifclear GENERIC @@ -5807,7 +6075,7 @@ disable the optimization. @item --no-opd-optimize PowerPC64 @command{ld} normally removes @code{.opd} section entries corresponding to deleted link-once functions, or functions removed by -the action of @samp{--gc-sections} or linker scrip @code{/DISCARD/}. +the action of @samp{--gc-sections} or linker script @code{/DISCARD/}. Use this option to disable @code{.opd} optimization. @cindex PowerPC64 OPD spacing @@ -5897,7 +6165,7 @@ on calls to non-overlay regions. the address range 0 to 256k. This option may be used to change the range. Disable the check entirely with @option{--local-store=0:0}. -@cindex SPU +@cindex SPU @kindex --stack-analysis @item --stack-analysis SPU local store space is limited. Over-allocation of stack space @@ -5916,7 +6184,7 @@ dynamic allocation, e.g. alloca, will not be detected. If a link map is requested, detailed information about each function's stack usage and calls will be given. -@cindex SPU +@cindex SPU @kindex --emit-stack-syms @item --emit-stack-syms This option, if given along with @option{--stack-analysis} will result @@ -5926,7 +6194,7 @@ functions, and @code{__stack__} for static functions. @code{} is the section id in hex. The value of such symbols is the stack requirement for the corresponding function. The symbol size will be zero, type @code{STT_NOTYPE}, binding -@code{STB_LOCAL}, and section @code{SHN_ABS}. +@code{STB_LOCAL}, and section @code{SHN_ABS}. @end table @ifclear GENERIC @@ -5962,13 +6230,13 @@ header format depends on the default specified by the specific target. @node WIN32 @section @command{ld} and WIN32 (cygwin/mingw) -This section describes some of the win32 specific @command{ld} issues. +This section describes some of the win32 specific @command{ld} issues. See @ref{Options,,Command Line Options} for detailed description of the command line options mentioned here. @table @emph -@cindex import libraries -@item import libraries +@cindex import libraries +@item import libraries The standard Windows linker creates and uses so-called import libraries, which contains information for linking to dll's. They are regular static archives and are handled as any other static @@ -5976,8 +6244,8 @@ archive. The cygwin and mingw ports of @command{ld} have specific support for creating such libraries provided with the @samp{--out-implib} command line option. -@item exporting DLL symbols -@cindex exporting DLL symbols +@item exporting DLL symbols +@cindex exporting DLL symbols The cygwin/mingw @command{ld} has several ways to export symbols for dll's. @table @emph @@ -5990,9 +6258,10 @@ which is controlled by the following command line options: @item --export-all-symbols [This is the default] @item --exclude-symbols @item --exclude-libs +@item --exclude-modules-for-implib @end itemize -If, however, @samp{--export-all-symbols} is not given explicitly on the +If, however, @samp{--export-all-symbols} is not given explicitly on the command line, then the default auto-export behavior will be @emph{disabled} if either of the following are true: @@ -6001,8 +6270,8 @@ if either of the following are true: @item Any symbol in any object file was marked with the __declspec(dllexport) attribute. @end itemize -@item using a DEF file -@cindex using a DEF file +@item using a DEF file +@cindex using a DEF file Another way of exporting symbols is using a DEF file. A DEF file is an ASCII file containing definitions of symbols which should be exported when a dll is created. Usually it is named @samp{} command should be used instead of @code{LIBRARY}. If @samp{} does not include a suffix, the default -executable suffix, @samp{.EXE} is appended. +executable suffix, @samp{.EXE} is appended. With either @code{LIBRARY } or @code{NAME } the optional specification @code{BASE = } may be used to specify a -non-default base address for the image. +non-default base address for the image. If neither @code{LIBRARY } nor @code{NAME } is specified, or they specify an empty string, the internal name is the same as the @@ -6060,7 +6329,7 @@ EXPORTS ( ( ( [ = ] ) | ( = . )) [ @@ ] [NONAME] [DATA] [CONSTANT] [PRIVATE] ) * -@end example +@end example Declares @samp{} as an exported symbol from the DLL, or declares @samp{} as an exported alias for @samp{}; or declares @@ -6095,7 +6364,7 @@ it into the static import library used to resolve imports at link time. The symbol can still be imported using the @code{LoadLibrary/GetProcAddress} API at runtime or by by using the GNU ld extension of linking directly to the DLL without an import library. - + See ld/deffilep.y in the binutils sources for the full specification of other DEF file statements @@ -6120,7 +6389,7 @@ this way, then the normal auto-export behavior is disabled, unless the @samp{--export-all-symbols} option is also used. Note that object files that wish to access these symbols must @emph{not} -decorate them with dllexport. Instead, they should use dllimport, +decorate them with dllexport. Instead, they should use dllimport, instead: @example @@ -6128,63 +6397,63 @@ __declspec(dllimport) int a_variable __declspec(dllimport) void a_function(int with_args) @end example -This complicates the structure of library header files, because -when included by the library itself the header must declare the +This complicates the structure of library header files, because +when included by the library itself the header must declare the variables and functions as dllexport, but when included by client code the header must declare them as dllimport. There are a number -of idioms that are typically used to do this; often client code can +of idioms that are typically used to do this; often client code can omit the __declspec() declaration completely. See @samp{--enable-auto-import} and @samp{automatic data imports} for more information. -@end table +@end table @cindex automatic data imports @item automatic data imports The standard Windows dll format supports data imports from dlls only by adding special decorations (dllimport/dllexport), which let the compiler produce specific assembler instructions to deal with this -issue. This increases the effort necessary to port existing Un*x +issue. This increases the effort necessary to port existing Un*x code to these platforms, especially for large c++ libraries and applications. The auto-import feature, which was -initially provided by Paul Sokolovsky, allows one to omit the +initially provided by Paul Sokolovsky, allows one to omit the decorations to achieve a behavior that conforms to that on POSIX/Un*x -platforms. This feature is enabled with the @samp{--enable-auto-import} +platforms. This feature is enabled with the @samp{--enable-auto-import} command-line option, although it is enabled by default on cygwin/mingw. The @samp{--enable-auto-import} option itself now serves mainly to suppress any warnings that are ordinarily emitted when linked objects trigger the feature's use. -auto-import of variables does not always work flawlessly without +auto-import of variables does not always work flawlessly without additional assistance. Sometimes, you will see this message -"variable '' can't be auto-imported. Please read the +"variable '' can't be auto-imported. Please read the documentation for ld's @code{--enable-auto-import} for details." -The @samp{--enable-auto-import} documentation explains why this error -occurs, and several methods that can be used to overcome this difficulty. -One of these methods is the @emph{runtime pseudo-relocs} feature, described +The @samp{--enable-auto-import} documentation explains why this error +occurs, and several methods that can be used to overcome this difficulty. +One of these methods is the @emph{runtime pseudo-relocs} feature, described below. @cindex runtime pseudo-relocation -For complex variables imported from DLLs (such as structs or classes), -object files typically contain a base address for the variable and an -offset (@emph{addend}) within the variable--to specify a particular -field or public member, for instance. Unfortunately, the runtime loader used -in win32 environments is incapable of fixing these references at runtime +For complex variables imported from DLLs (such as structs or classes), +object files typically contain a base address for the variable and an +offset (@emph{addend}) within the variable--to specify a particular +field or public member, for instance. Unfortunately, the runtime loader used +in win32 environments is incapable of fixing these references at runtime without the additional information supplied by dllimport/dllexport decorations. -The standard auto-import feature described above is unable to resolve these +The standard auto-import feature described above is unable to resolve these references. -The @samp{--enable-runtime-pseudo-relocs} switch allows these references to -be resolved without error, while leaving the task of adjusting the references -themselves (with their non-zero addends) to specialized code provided by the -runtime environment. Recent versions of the cygwin and mingw environments and -compilers provide this runtime support; older versions do not. However, the -support is only necessary on the developer's platform; the compiled result will +The @samp{--enable-runtime-pseudo-relocs} switch allows these references to +be resolved without error, while leaving the task of adjusting the references +themselves (with their non-zero addends) to specialized code provided by the +runtime environment. Recent versions of the cygwin and mingw environments and +compilers provide this runtime support; older versions do not. However, the +support is only necessary on the developer's platform; the compiled result will run without error on an older system. -@samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly -enabled as needed. +@samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly +enabled as needed. @cindex direct linking to a dll @item direct linking to a dll @@ -6192,16 +6461,16 @@ The cygwin/mingw ports of @command{ld} support the direct linking, including data symbols, to a dll without the usage of any import libraries. This is much faster and uses much less memory than does the traditional import library method, especially when linking large -libraries or applications. When @command{ld} creates an import lib, each -function or variable exported from the dll is stored in its own bfd, even -though a single bfd could contain many exports. The overhead involved in +libraries or applications. When @command{ld} creates an import lib, each +function or variable exported from the dll is stored in its own bfd, even +though a single bfd could contain many exports. The overhead involved in storing, loading, and processing so many bfd's is quite large, and explains the -tremendous time, memory, and storage needed to link against particularly +tremendous time, memory, and storage needed to link against particularly large or complex libraries when using import libs. -Linking directly to a dll uses no extra command-line switches other than +Linking directly to a dll uses no extra command-line switches other than @samp{-L} and @samp{-l}, because @command{ld} already searches for a number -of names to match each library. All that is needed from the developer's +of names to match each library. All that is needed from the developer's perspective is an understanding of this search, in order to force ld to select the dll instead of an import library. @@ -6221,14 +6490,14 @@ xxx.dll before moving on to the next directory in the search path. -(*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{xxx.dll}, -where @samp{} is set by the @command{ld} option -@samp{--dll-search-prefix=}. In the case of cygwin, the standard gcc spec -file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for +(*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{xxx.dll}, +where @samp{} is set by the @command{ld} option +@samp{--dll-search-prefix=}. In the case of cygwin, the standard gcc spec +file includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for @samp{cygxxx.dll}. -Other win32-based unix environments, such as mingw or pw32, may use other -@samp{}es, although at present only cygwin makes use of this feature. It +Other win32-based unix environments, such as mingw or pw32, may use other +@samp{}es, although at present only cygwin makes use of this feature. It was originally intended to help avoid name conflicts among dll's built for the various win32/un*x environments, so that (for example) two versions of a zlib dll could coexist on the same machine. @@ -6242,16 +6511,16 @@ bin/ cygxxx.dll lib/ libxxx.dll.a (in case of dll's) - libxxx.a (in case of static archive) + libxxx.a (in case of static archive) @end example -Linking directly to a dll without using the import library can be -done two ways: +Linking directly to a dll without using the import library can be +done two ways: 1. Use the dll directly by adding the @samp{bin} path to the link line @example gcc -Wl,-verbose -o a.exe -L../bin/ -lxxx -@end example +@end example However, as the dll's often have version numbers appended to their names (@samp{cygncurses-5.dll}) this will often fail, unless one specifies @@ -6265,13 +6534,13 @@ making the app/dll. @example ln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a] -@end example +@end example Then you can link without any make environment changes. @example gcc -Wl,-verbose -o a.exe -L../lib/ -lxxx -@end example +@end example This technique also avoids the version number problems, because the following is perfectly legal @@ -6280,7 +6549,7 @@ perfectly legal bin/ cygxxx-5.dll lib/ - libxxx.dll.a -> ../bin/cygxxx-5.dll + libxxx.dll.a -> ../bin/cygxxx-5.dll @end example Linking directly to a dll without using an import lib will work @@ -6305,71 +6574,71 @@ in which symbols are usually exported as undecorated aliases of their stdcall-decorated assembly names. So, import libs are not going away. But the ability to replace -true import libs with a simple symbolic link to (or a copy of) -a dll, in many cases, is a useful addition to the suite of tools -binutils makes available to the win32 developer. Given the +true import libs with a simple symbolic link to (or a copy of) +a dll, in many cases, is a useful addition to the suite of tools +binutils makes available to the win32 developer. Given the 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 +@item symbol aliasing @table @emph -@item adding additional names -Sometimes, it is useful to export symbols with additional names. +@item adding additional names +Sometimes, it is useful to export symbols with additional names. A symbol @samp{foo} will be exported as @samp{foo}, but it can also be exported as @samp{_foo} by using special directives in the DEF file when creating the dll. This will affect also the optional created -import library. Consider the following DEF file: +import library. Consider the following DEF file: -@example +@example LIBRARY "xyz.dll" BASE=0x61000000 EXPORTS -foo +foo _foo = foo -@end example +@end example The line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}. Another method for creating a symbol alias is to create it in the source code using the "weak" attribute: -@example -void foo () @{ /* Do something. */; @} +@example +void foo () @{ /* Do something. */; @} void _foo () __attribute__ ((weak, alias ("foo"))); -@end example +@end example See the gcc manual for more information about attributes and weak symbols. @item renaming symbols Sometimes it is useful to rename exports. For instance, the cygwin -kernel does this regularly. A symbol @samp{_foo} can be exported as +kernel does this regularly. A symbol @samp{_foo} can be exported as @samp{foo} but not as @samp{_foo} by using special directives in the DEF file. (This will also affect the import library, if it is -created). In the following example: +created). In the following example: -@example +@example LIBRARY "xyz.dll" BASE=0x61000000 EXPORTS _foo = foo -@end example +@end example The line @samp{_foo = foo} maps the exported symbol @samp{foo} to @samp{_foo}. -@end table +@end table Note: using a DEF file disables the default auto-export behavior, -unless the @samp{--export-all-symbols} command line option is used. +unless the @samp{--export-all-symbols} command line option is used. If, however, you are trying to rename symbols, then you should list -@emph{all} desired exports in the DEF file, including the symbols -that are not being renamed, and do @emph{not} use the -@samp{--export-all-symbols} option. If you list only the -renamed symbols in the DEF file, and use @samp{--export-all-symbols} -to handle the other symbols, then the both the new names @emph{and} -the original names for the renamed symbols will be exported. -In effect, you'd be aliasing those symbols, not renaming them, +@emph{all} desired exports in the DEF file, including the symbols +that are not being renamed, and do @emph{not} use the +@samp{--export-all-symbols} option. If you list only the +renamed symbols in the DEF file, and use @samp{--export-all-symbols} +to handle the other symbols, then the both the new names @emph{and} +the original names for the renamed symbols will be exported. +In effect, you'd be aliasing those symbols, not renaming them, which is probably not what you wanted. @cindex weak externals @@ -6605,7 +6874,7 @@ location where that name is stored in memory; perhaps, if the name were different, the contents of that location would fool the linker into doing the right thing despite the bug. Play it safe and give a specific, complete example. That is the easiest thing for you to do, -and the most helpful. +and the most helpful. Keep in mind that the purpose of a bug report is to enable us to fix the bug if it is new to us. Therefore, always write your bug reports @@ -6873,6 +7142,8 @@ If you have more than one @code{SECT} statement for the same @var{secname}, only the @emph{first} sets the start address. @end table +@node GNU Free Documentation License +@appendix GNU Free Documentation License @include fdl.texi @node LD Index