* bfd/bfd-in.h (bfd_elf32_arm_set_target_relocs): Update prototype.
[deliverable/binutils-gdb.git] / ld / ld.texinfo
index ceaecd1182410147be924b7876b528f231985feb..7860e2505914a435095c31bd253099782d398f94 100644 (file)
@@ -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 Free Software Foundation, Inc.
+@c 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 @syncodeindex ky cp
 @include configdoc.texi
 @c (configdoc.texi is generated by the Makefile)
@@ -152,6 +152,9 @@ section entitled ``GNU Free Documentation License''.
 @ifset HPPA
 * HPPA ELF32::                  ld and HPPA 32-bit ELF
 @end ifset
+@ifset M68HC11
+* M68HC11/68HC12::              ld and the Motorola 68HC11 and 68HC12 families
+@end ifset
 @ifset TICOFF
 * TI COFF::                     ld and the TI COFF
 @end ifset
@@ -446,6 +449,17 @@ base 10; you may use a leading @samp{0x} for base 16, or a leading
 @samp{0} for base 8).  @xref{Entry Point}, for a discussion of defaults
 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
+@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
+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.
+
 @cindex dynamic symbol table
 @kindex -E
 @kindex --export-dynamic
@@ -980,10 +994,23 @@ This option affects ELF DT_NEEDED tags for dynamic libraries mentioned
 on the command line after the @option{--as-needed} option.  Normally,
 the linker will add a DT_NEEDED tag for each dynamic library mentioned
 on the command line, regardless of whether the library is actually
-needed. @option{--as-needed} causes DT_NEEDED tags to only be emitted
-for libraries that satisfy some reference from regular objects.
+needed.  @option{--as-needed} causes DT_NEEDED tags to only be emitted
+for libraries that satisfy some symbol reference from regular objects
+which is undefined at the point that the library was linked.
 @option{--no-as-needed} restores the default behaviour.
 
+@kindex --add-needed
+@kindex --no-add-needed
+@item --add-needed
+@itemx --no-add-needed
+This option affects the treatment of dynamic libraries from ELF
+DT_NEEDED tags in dynamic libraries mentioned on the command line after
+the @option{--no-add-needed} option.  Normally, the linker will add
+a DT_NEEDED tag for each dynamic library from DT_NEEDED tags.
+@option{--no-add-needed} causes DT_NEEDED tags will never be emitted
+for those libraries from DT_NEEDED tags. @option{--add-needed} restores
+the default behaviour.
+
 @kindex -assert @var{keyword}
 @item -assert @var{keyword}
 This option is ignored for SunOS compatibility.
@@ -1208,6 +1235,16 @@ Normally when a symbol has an undefined version, the linker will ignore
 it. This option disallows symbols with undefined version and a fatal error
 will be issued instead.
 
+@kindex --default-symver
+@item --default-symver
+Create and use a default symbol version (the soname) for unversioned
+exported symbols.
+
+@kindex --default-imported-symver
+@item --default-imported-symver
+Create and use a default symbol version (the soname) for unversioned
+imported symbols.
+
 @kindex --no-warn-mismatch
 @item --no-warn-mismatch
 Normally @command{ld} will give an error if you try to link together input
@@ -1290,6 +1327,9 @@ This option is only supported on a few targets.
 @ifset XTENSA
 @xref{Xtensa,, @command{ld} and Xtensa Processors}.
 @end ifset
+@ifset M68HC11
+@xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
+@end ifset
 
 On some platforms, the @samp{--relax} option performs global
 optimizations that become possible when the linker resolves addressing
@@ -1431,6 +1471,16 @@ 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.
 
+@kindex --sort-section name
+@item --sort-section name
+This option will apply @code{SORT_BY_NAME} to all wildcard section
+patterns in the linker script.
+
+@kindex --sort-section alignment
+@item --sort-section alignment
+This option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
+patterns in the linker script.
+
 @kindex --split-by-file
 @item --split-by-file [@var{size}]
 Similar to @option{--split-by-reloc} but creates a new output section for
@@ -1455,6 +1505,12 @@ many relocations.  @var{count} defaults to a value of 32768.
 Compute and display statistics about the operation of the linker, such
 as execution time and memory usage.
 
+@kindex --sysroot
+@item --sysroot=@var{directory}
+Use @var{directory} as the location of the sysroot, overriding the
+configure-time default.  This option is only supported by linkers
+that were configured using @option{--with-sysroot}.
+
 @kindex --traditional-format
 @cindex traditional format
 @item --traditional-format
@@ -1662,6 +1718,10 @@ The address will only be changed if it not explicitly specified; that
 is, if the @code{SECTIONS} command does not specify a start address for
 the section (@pxref{SECTIONS}).
 
+@kindex --warn-shared-textrel
+@item --warn-shared-textrel
+Warn if the linker adds a DT_TEXTREL to a shared object.  
+
 @kindex --warn-unresolved-symbols
 @item --warn-unresolved-symbols
 If the linker is going to report an unresolved symbol (see the option
@@ -1734,6 +1794,28 @@ If you specify @option{--disable-new-dtags}, no new dynamic tags will be
 created. By default, the new dynamic tags are not created. Note that
 those options are only available for ELF systems.
 
+@kindex --hash-size=@var{number}
+Set the default size of the linker's hash tables to a prime number
+close to @var{number}.  Increasing this value can reduce the length of
+time it takes the linker to perform its tasks, at the expense of
+increasing the linker's memory requirements.  Similarly reducing this
+value can reduce the memory requirements at the expense of speed.
+
+@kindex --reduce-memory-overheads
+@item --reduce-memory-overheads
+This option reduces memory requirements at ld runtime, at the expense of
+linking speed.  This was introduced to to select the old O(n^2) algorithm
+for link map file generation, rather than the new O(n) algorithm which uses
+about 40% more memory for symbol storage.
+
+Another affect of the switch is to set the default hash table size to
+1021, which again saves memory at the cost of lengthening the linker's
+run time.  This is not done however if the @option{--hash-size} switch
+has been used.
+
+The @option{--reduce-memory-overheads} switch may be also be used to
+enable other tradeoffs in future versions of the linker.
+
 @end table
 
 @c man end
@@ -1830,15 +1912,6 @@ Specifies a list of symbols which should not be automatically
 exported.  The symbol names may be delimited by commas or colons.
 [This option is specific to the i386 PE targeted port of the linker]
 
-@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
-@code{--exclude-libs ALL} excludes symbols in all archive libraries from
-automatic export. Symbols explicitly listed in a .def file are still exported,
-regardless of this option. 
-[This option is specific to the i386 PE targeted port of the linker]
-
 @kindex --file-alignment
 @item --file-alignment
 Specify the file alignment.  Sections in the file will always begin at
@@ -2131,14 +2204,43 @@ committed.
 @itemx --subsystem @var{which}:@var{major}.@var{minor}
 Specifies the subsystem under which your program will execute.  The
 legal values for @var{which} are @code{native}, @code{windows},
-@code{console}, and @code{posix}.  You may optionally set the
-subsystem version also.
+@code{console}, @code{posix}, and @code{xbox}.  You may optionally set
+the subsystem version also.  Numeric values are also accepted for
+@var{which}.
 [This option is specific to the i386 PE targeted port of the linker]
 
 @end table
 
 @c man end
 
+@ifset M68HC11
+@subsection Options specific to Motorola 68HC11 and 68HC12 targets
+
+@c man begin OPTIONS
+
+The 68HC11 and 68HC12 linkers support specific options to control the
+memory bank switching mapping and trampoline code generation.
+
+@table @gcctabopt
+
+@kindex --no-trampoline
+@item --no-trampoline
+This option disables the generation of trampoline. By default a trampoline
+is generated for each far function which is called using a @code{jsr}
+instruction (this happens when a pointer to a far function is taken).
+
+@kindex --bank-window
+@item --bank-window @var{name}
+This option indicates to the linker the name of the memory region in
+the @samp{MEMORY} specification that describes the memory bank window.
+The definition of such region is then used by the linker to compute
+paging and addresses within the memory window.
+
+@end table
+
+@c man end
+@end ifset
+
 @ifset UsesEnvVars
 @node Environment
 @section Environment Variables
@@ -2475,6 +2577,18 @@ files should all be archives, and they are searched repeatedly until no
 new undefined references are created.  See the description of @samp{-(}
 in @ref{Options,,Command Line Options}.
 
+@item AS_NEEDED(@var{file}, @var{file}, @dots{})
+@itemx AS_NEEDED(@var{file} @var{file} @dots{})
+@kindex AS_NEEDED(@var{files})
+This construct can appear only inside of the @code{INPUT} or @code{GROUP}
+commands, among other filenames.  The files listed will be handled
+as if they appear directly in the @code{INPUT} or @code{GROUP} commands,
+with the exception of ELF shared libraries, that will be added only
+when they are actually needed.  This construct essentially enables
+@option{--as-needed} option for all the files listed inside of it
+and restores previous @option{--as-needed} resp. @option{--no-as-needed}
+setting afterwards.
+
 @item OUTPUT(@var{filename})
 @kindex OUTPUT(@var{filename})
 @cindex output file name in linker scripot
@@ -2627,11 +2741,12 @@ the @samp{-f} option.
 @cindex symbol definition, scripts
 @cindex variables, defining
 You may assign a value to a symbol in a linker script.  This will define
-the symbol as a global symbol.
+the symbol and place it into the symbol table with a global scope.
 
 @menu
 * Simple Assignments::         Simple Assignments
 * PROVIDE::                    PROVIDE
+* Source Code Reference::      How to use a linker script defined symbol in source code
 @end menu
 
 @node Simple Assignments
@@ -2656,7 +2771,7 @@ The first case will define @var{symbol} to the value of
 defined, and the value will be adjusted accordingly.
 
 The special symbol name @samp{.} indicates the location counter.  You
-may only use this within a @code{SECTIONS} command.
+may only use this within a @code{SECTIONS} command.  @xref{Location Counter}.
 
 The semicolon after @var{expression} is required.
 
@@ -2724,6 +2839,113 @@ underscore), the linker will silently use the definition in the program.
 If the program references @samp{etext} but does not define it, the
 linker will use the definition in the linker script.
 
+@node Source Code Reference
+@subsection Source Code Reference
+
+Accessing a linker script defined variable from source code is not
+intuitive.  In particular a linker script symbol is not equivalent to
+a variable declaration in a high level language, it is instead a
+symbol that does not have a value.
+
+Before going further, it is important to note that compilers often
+transform names in the source code into different names when they are
+stored in the symbol table.  For example, Fortran compilers commonly
+prepend or append an underscore, and C++ performs extensive @samp{name
+mangling}.  Therefore there might be a discrepancy between the name
+of a variable as it is used in source code and the name of the same
+variable as it is defined in a linker script.  For example in C a
+linker script variable might be referred to as:
+
+@smallexample
+  extern int foo;
+@end smallexample
+
+But in the linker script it might be defined as:
+
+@smallexample
+  _foo = 1000;
+@end smallexample
+
+In the remaining examples however it is assumed that no name
+transformation has taken place.
+
+When a symbol is declared in a high level language such as C, two
+things happen.  The first is that the compiler reserves enough space
+in the program's memory to hold the @emph{value} of the symbol.  The
+second is that the compiler creates an entry in the program's symbol
+table which holds the symbol's @emph{address}.  ie the symbol table
+contains the address of the block of memory holding the symbol's
+value.  So for example the following C declaration, at file scope:
+
+@smallexample
+  int foo = 1000;
+@end smallexample
+
+creates a entry called @samp{foo} in the symbol table.  This entry
+holds the address of an @samp{int} sized block of memory where the
+number 1000 is initially stored.
+
+When a program references a symbol the compiler generates code that
+first accesses the symbol table to find the address of the symbol's
+memory block and then code to read the value from that memory block.
+So:
+
+@smallexample
+  foo = 1;
+@end smallexample
+
+looks up the symbol @samp{foo} in the symbol table, gets the address
+associated with this symbol and then writes the value 1 into that
+address.  Whereas:
+
+@smallexample
+  int * a = & foo;
+@end smallexample
+
+looks up the symbol @samp{foo} in the symbol table, gets it address
+and then copies this address into the block of memory associated with
+the variable @samp{a}.
+
+Linker scripts symbol declarations, by contrast, create an entry in
+the symbol table but do not assign any memory to them.  Thus they are
+an address without a value.  So for example the linker script definition:
+
+@smallexample
+  foo = 1000;
+@end smallexample
+
+creates an entry in the symbol table called @samp{foo} which holds
+the address of memory location 1000, but nothing special is stored at
+address 1000.  This means that you cannot access the @emph{value} of a
+linker script defined symbol - it has no value - all you can do is
+access the @emph{address} of a linker script defined symbol.
+
+Hence when you are using a linker script defined symbol in source code
+you should always take the address of the symbol, and never attempt to
+use its value.  For example suppose you want to copy the contents of a
+section of memory called .ROM into a section called .FLASH and the
+linker script contains these declarations:
+
+@smallexample
+@group
+  start_of_ROM   = .ROM;
+  end_of_ROM     = .ROM + sizeof (.ROM) - 1;
+  start_of_FLASH = .FLASH;
+@end group
+@end smallexample
+
+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
+
+Note the use of the @samp{&} operators.  These are correct.
+
 @node SECTIONS
 @section SECTIONS Command
 @kindex SECTIONS
@@ -3008,14 +3230,66 @@ sequence of input section descriptions is probably in error, because the
 .data1 : @{ data.o(.data) @}
 @end smallexample
 
-@cindex SORT
+@cindex SORT_BY_NAME
 Normally, the linker will place files and sections matched by wildcards
 in the order in which they are seen during the link.  You can change
-this by using the @code{SORT} keyword, which appears before a wildcard
-pattern in parentheses (e.g., @code{SORT(.text*)}).  When the
-@code{SORT} keyword is used, the linker will sort the files or sections
+this by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
+pattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}).  When the
+@code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
 into ascending order by name before placing them in the output file.
 
+@cindex SORT_BY_ALIGNMENT
+@code{SORT_BY_ALIGNMENT} is very similar to @code{SORT_BY_NAME}. The
+difference is @code{SORT_BY_ALIGNMENT} will sort sections into
+ascending order by alignment before placing them in the output file.
+
+@cindex SORT
+@code{SORT} is an alias for @code{SORT_BY_NAME}.
+
+When there are nested section sorting commands in linker script, there
+can be at most 1 level of nesting for section sorting commands.
+
+@enumerate
+@item
+@code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
+It will sort the input sections by name first, then by alignment if 2
+sections have the same name.
+@item
+@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
+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 
+treated the same as @code{SORT_BY_NAME} (wildcard section pattern).
+@item
+@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
+is treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
+@item
+All other nested section sorting commands are invalid.
+@end enumerate
+
+When both command line section sorting option and linker script
+section sorting command are used, section sorting command always
+takes precedence over the command line option.
+
+If the section sorting command in linker script isn't nested, the
+command line option will make the section sorting command to be
+treated as nested sorting command.
+
+@enumerate
+@item
+@code{SORT_BY_NAME} (wildcard section pattern ) with
+@option{--sort-sections alignment} is equivalent to
+@code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
+@item
+@code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
+@option{--sort-section name} is equivalent to
+@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
+@end enumerate
+
+If the section sorting command in linker script is nested, the
+command line option will be ignored.
+
 If you ever get confused about where input sections are going, use the
 @samp{-M} linker option to generate a map file.  The map file shows
 precisely how input sections are mapped to output sections.
@@ -3081,7 +3355,7 @@ When link-time garbage collection is in use (@samp{--gc-sections}),
 it is often useful to mark sections that should not be eliminated.
 This is accomplished by surrounding an input section's wildcard entry
 with @code{KEEP()}, as in @code{KEEP(*(.init))} or
-@code{KEEP(SORT(*)(.ctors))}.
+@code{KEEP(SORT_BY_NAME(*)(.ctors))}.
 
 @node Input Section Example
 @subsubsection Input Section Example
@@ -3231,7 +3505,9 @@ linker to place constructor information in the output section where the
 ignored for other object file formats.
 
 The symbol @w{@code{__CTOR_LIST__}} marks the start of the global
-constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end.  The
+constructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
+Similarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
+the start and end of the global destructors.  The
 first word in the list is the number of entries, followed by the address
 of each constructor or destructor, followed by a zero word.  The
 compiler must arrange to actually run the code.  For these object file
@@ -3265,9 +3541,9 @@ If you are using the @sc{gnu} C++ support for initialization priority,
 which provides some control over the order in which global constructors
 are run, you must sort the constructors at link time to ensure that they
 are executed in the correct order.  When using the @code{CONSTRUCTORS}
-command, use @samp{SORT(CONSTRUCTORS)} instead.  When using the
-@code{.ctors} and @code{.dtors} sections, use @samp{*(SORT(.ctors))} and
-@samp{*(SORT(.dtors))} instead of just @samp{*(.ctors)} and
+command, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead.  When using the
+@code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
+@samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
 @samp{*(.dtors)}.
 
 Normally the compiler and linker will handle these issues automatically,
@@ -3697,19 +3973,19 @@ attributes.
 @kindex ORIGIN =
 @kindex o =
 @kindex org =
-The @var{origin} is an expression for the start address of the memory
-region.  The expression must evaluate to a constant before memory
-allocation is performed, which means that you may not use any section
-relative symbols.  The keyword @code{ORIGIN} may be abbreviated to
-@code{org} or @code{o} (but not, for example, @code{ORG}).
+The @var{origin} is an numerical expression for the start address of
+the memory region.  The expression must evaluate to a constant and it
+cannot involve any symbols.  The keyword @code{ORIGIN} may be
+abbreviated to @code{org} or @code{o} (but not, for example,
+@code{ORG}).
 
 @kindex LENGTH =
 @kindex len =
 @kindex l =
 The @var{len} is an expression for the size in bytes of the memory
 region.  As with the @var{origin} expression, the expression must
-evaluate to a constant before memory allocation is performed.  The
-keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}.
+be numerical only and must evaluate to a constant.  The keyword
+@code{LENGTH} may be abbreviated to @code{len} or @code{l}.
 
 In the following example, we specify that there are two memory regions
 available for allocation: one starting at @samp{0} for 256 kilobytes,
@@ -3740,6 +4016,16 @@ the next available address within the memory region.  If the combined
 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 
+@code{LENGTH(@var{memory})} functions:
+
+@smallexample
+@group
+  _fstack = ORIGIN(ram) + LENGTH(ram) - 4;  
+@end group
+@end smallexample
+
 @node PHDRS
 @section PHDRS Command
 @kindex PHDRS
@@ -4206,6 +4492,74 @@ and it will have an extra 0x600 bytes worth of space after the end of
 the values from the @samp{.data} input sections and before the end of
 the @samp{.data} output section itself.
 
+@cindex dot outside sections
+Setting symbols to the value of the location counter outside of an
+output section statement can result in unexpected values if the linker
+needs to place orphan sections.  For example, given the following:
+
+@smallexample
+SECTIONS
+@{
+    start_of_text = . ;
+    .text: @{ *(.text) @}
+    end_of_text = . ;
+
+    start_of_data = . ;
+    .data: @{ *(.data) @}
+    end_of_data = . ;
+@}
+@end smallexample
+
+If the linker needs to place some input section, e.g. @code{.rodata},
+not mentioned in the script, it might choose to place that section
+between @code{.text} and @code{.data}.  You might think the linker
+should place @code{.rodata} on the blank line in the above script, but
+blank lines are of no particular significance to the linker.  As well,
+the linker doesn't associate the above symbol names with their
+sections.  Instead, it assumes that all assignments or other
+statements belong to the previous output section, except for the
+special case of an assignment to @code{.}.  I.e., the linker will
+place the orphan @code{.rodata} section as if the script was written
+as follows:
+
+@smallexample
+SECTIONS
+@{
+    start_of_text = . ;
+    .text: @{ *(.text) @}
+    end_of_text = . ;
+
+    start_of_data = . ;
+    .rodata: @{ *(.rodata) @}
+    .data: @{ *(.data) @}
+    end_of_data = . ;
+@}
+@end smallexample
+
+This may or may not be the script author's intention for the value of
+@code{start_of_data}.  One way to influence the orphan section
+placement is to assign the location counter to itself, as the linker
+assumes that an assignment to @code{.} is setting the start address of
+a following output section and thus should be grouped with that
+section.  So you could write:
+
+@smallexample
+SECTIONS
+@{
+    start_of_text = . ;
+    .text: @{ *(.text) @}
+    end_of_text = . ;
+
+    . = . ;
+    start_of_data = . ;
+    .data: @{ *(.data) @}
+    end_of_data = . ;
+@}
+@end smallexample
+
+Now, the orphan @code{.rodata} section will be placed between
+@code{end_of_text} and @code{start_of_data}.
+
 @need 2000
 @node Operators
 @subsection Operators
@@ -4477,6 +4831,21 @@ evaluation purposes.
   . = DATA_SEGMENT_END(.);
 @end smallexample
 
+@item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
+@kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
+This defines the end of the @code{PT_GNU_RELRO} segment when
+@samp{-z relro} option is used.  Second argument is returned.
+When @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
+does nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
+@var{exp} + @var{offset} is aligned to the most commonly used page
+boundary for particular target.  If present in the linker script,
+it must always come in between @code{DATA_SEGMENT_ALIGN} and
+@code{DATA_SEGMENT_END}.
+
+@smallexample
+  . = DATA_SEGMENT_RELRO_END(24, .);
+@end smallexample
+
 @item DEFINED(@var{symbol})
 @kindex DEFINED(@var{symbol})
 @cindex symbol defaults
@@ -4500,6 +4869,10 @@ SECTIONS @{ @dots{}
 @end group
 @end smallexample
 
+@item LENGTH(@var{memory})
+@kindex LENGTH(@var{memory})
+Return the length of the memory region named @var{memory}.
+
 @item LOADADDR(@var{section})
 @kindex LOADADDR(@var{section})
 @cindex section load address in expression
@@ -4524,6 +4897,20 @@ This function is closely related to @code{ALIGN(@var{exp})}; unless you
 use the @code{MEMORY} command to define discontinuous memory for the
 output file, the two functions are equivalent.
 
+@item ORIGIN(@var{memory})
+@kindex ORIGIN(@var{memory})
+Return the origin of the memory region named @var{memory}.
+
+@item SEGMENT_START(@var{segment}, @var{default})
+@kindex SEGMENT_START(@var{segment}, @var{default})
+Return the base address of the named @var{segment}.  If an explicit
+value has been given for this segment (with a command-line @samp{-T}
+option) that value will be returned; otherwise the value will be
+@var{default}.  At present, the @samp{-T} command-line option can only
+be used to set the base address for the ``text'', ``data'', and
+``bss'' sections, but you use @code{SEGMENT_START} with any segment
+name.
+
 @item SIZEOF(@var{section})
 @kindex SIZEOF(@var{section})
 @cindex section size
@@ -4614,6 +5001,9 @@ functionality are not listed.
 @ifset MSP430
 * MSP430::                     @command{ld} and MSP430
 @end ifset
+@ifset M68HC11
+* M68HC11/68HC12::             @code{ld} and the Motorola 68HC11 and 68HC12 families
+@end ifset
 @ifset TICOFF
 * TI COFF::                     @command{ld} and TI COFF
 @end ifset
@@ -4754,8 +5144,59 @@ not itself call any subroutines).
 @raisesections
 @end ifclear
 
+@ifset M68HC11
+@ifclear GENERIC
+@raisesections
+@end ifclear
+
+@node M68HC11/68HC12
+@section @command{ld} and the Motorola 68HC11 and 68HC12 families
+
+@cindex M68HC11 and 68HC12 support
+
+@subsection Linker Relaxation
+
+For the Motorola 68HC11, @command{ld} can perform these global
+optimizations when you specify the @samp{--relax} command-line option.
+
+@table @emph
+@cindex relaxing on M68HC11
+@item relaxing address modes
+@command{ld} finds all @code{jsr} and @code{jmp} instructions whose
+targets are within eight bits, and turns them into eight-bit
+program-counter relative @code{bsr} and @code{bra} instructions,
+respectively.
+
+@command{ld} also looks at all 16-bit extended addressing modes and
+transforms them in a direct addressing mode when the address is in
+page 0 (between 0 and 0x0ff).
+
+@item relaxing gcc instruction group
+When @command{gcc} is called with @option{-mrelax}, it can emit group
+of instructions that the linker can optimize to use a 68HC11 direct
+addressing mode. These instructions consists of @code{bclr} or
+@code{bset} instructions.
+
+@end table
+
+@subsection Trampoline Generation
+
+@cindex trampoline generation on M68HC11
+@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 
+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.
+
+@ifclear GENERIC
+@lowersections
+@end ifclear
+@end ifset
+
 @node ARM
-@section @command{ld}'s Support for Interworking Between ARM and Thumb Code
+@section @command{ld} and the ARM family
 
 @cindex ARM interworking support
 @kindex --support-old-code
@@ -4785,6 +5226,53 @@ The @samp{--be8} switch instructs @command{ld} to generate BE8 format
 executables.  This option is only valid when linking big-endian objects.
 The resulting image will contain big-endian data and little-endian code.
 
+@cindex TARGET1
+@kindex --target1-rel
+@kindex --target1-abs
+The @samp{R_ARM_TARGET1} relocation is typically used for entries in the
+@samp{.init_array} section.  It is interpreted as either @samp{R_ARM_REL32}
+or @samp{R_ARM_ABS32}, depending on the target.  The @samp{--target1-rel}
+and @samp{--target1-abs} switches override the default.
+
+@cindex TARGET2
+@kindex --target2=@var{type}
+The @samp{--target2=type} switch overrides the default definition of the
+@samp{R_ARM_TARGET2} relocation.  Valid values for @samp{type}, their
+meanings, and target defaults are as follows:
+@table @samp
+@item rel
+@samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
+@item abs
+@samp{R_ARM_ABS32} (arm*-*-symbianelf)
+@item got-rel
+@samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
+@end table
+
+@cindex FIX_V4BX
+@kindex --fix-v4bx
+The @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
+specification) enables objects compiled for the ARMv4 architecture to be
+interworking-safe when linked with other objects compiled for ARMv4t, but
+also allows pure ARMv4 binaries to be built from the same ARMv4 objects.
+
+In the latter case, the switch @option{--fix-v4bx} must be passed to the
+linker, which causes v4t @code{BX rM} instructions to be rewritten as
+@code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
+
+In the former case, the switch should not be used, and @samp{R_ARM_V4BX}
+relocations are ignored.
+
+@cindex USE_BLX
+@kindex --use-blx
+The @samp{--use-blx} switch enables the linker to use ARM/Thumb
+BLX instructions (available on ARMv5t and above) in various
+situations. Currently it is used to perform calls via the PLT from Thumb
+code using BLX rather than using BX and a mode-switching stub before
+each PLT entry. This should lead to such calls executing slightly faster.
+
+This option is enabled implicitly for SymbianOS, so there is no need to
+specify it if you are using that target.
+
 @ifclear GENERIC
 @lowersections
 @end ifclear
@@ -5270,6 +5758,24 @@ 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
+@item weak externals
+The Windows object format, PE, specifies a form of weak symbols called
+weak externals.  When a weak symbol is linked and the symbol is not
+defined, the weak symbol becomes an alias for some other symbol.  There
+are three variants of weak externals:
+@itemize
+@item Definition is searched for in objects and libraries, historically
+called lazy externals.
+@item Definition is searched for only in other objects, not in libraries.
+This form is not presently implemented.
+@item No search; the symbol is an alias.  This form is not presently
+implemented.
+@end itemize
+As a GNU extension, weak symbols that do not specify an alternate symbol
+are supported.  If the symbol is undefined when linking, the symbol
+uses a default value.
 @end table
 
 @ifclear GENERIC
@@ -5309,34 +5815,53 @@ interleaving might place the @code{.literal} sections from an initial
 group of files followed by the @code{.text} sections of that group of
 files.  Then, the @code{.literal} sections from the rest of the files
 and the @code{.text} sections from the rest of the files would follow.
-The non-interleaved order can still be specified as:
 
-@smallexample
-SECTIONS
-@{
-  .text : @{
-    *(.literal) *(.text)
-  @}
-@}
-@end smallexample
-
-@cindex @code{--relax} on Xtensa
+@cindex @option{--relax} on Xtensa
 @cindex relaxing on Xtensa
+Relaxation is enabled by default for the Xtensa version of @command{ld} and
+provides two important link-time optimizations.  The first optimization
+is to combine identical literal values to reduce code size.  A redundant
+literal will be removed and all the @code{L32R} instructions that use it
+will be changed to reference an identical literal, as long as the
+location of the replacement literal is within the offset range of all
+the @code{L32R} instructions.  The second optimization is to remove
+unnecessary overhead from assembler-generated ``longcall'' sequences of
+@code{L32R}/@code{CALLX@var{n}} when the target functions are within
+range of direct @code{CALL@var{n}} instructions.
+
+For each of these cases where an indirect call sequence can be optimized
+to a direct call, the linker will change the @code{CALLX@var{n}}
+instruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
+instruction, and remove the literal referenced by the @code{L32R}
+instruction if it is not used for anything else.  Removing the
+@code{L32R} instruction always reduces code size but can potentially
+hurt performance by changing the alignment of subsequent branch targets.
+By default, the linker will always preserve alignments, either by
+switching some instructions between 24-bit encodings and the equivalent
+density instructions or by inserting a no-op in place of the @code{L32R}
+instruction that was removed.  If code size is more important than
+performance, the @option{--size-opt} option can be used to prevent the
+linker from widening density instructions or inserting no-ops, except in
+a few cases where no-ops are required for correctness.
+
+The following Xtensa-specific command-line options can be used to
+control the linker:
+
+@cindex Xtensa options
+@table @option
 @kindex --no-relax
-The Xtensa version of @command{ld} enables the @option{--relax} option by
-default to attempt to reduce space in the output image by combining
-literals with identical values.  It also provides the
-@option{--no-relax} option to disable this optimization.  When enabled,
-the relaxation algorithm ensures that a literal will only be merged with
-another literal when the new merged literal location is within the
-offset range of all of its uses.
-
-The relaxation mechanism will also attempt to optimize
-assembler-generated ``longcall'' sequences of
-@code{L32R}/@code{CALLX@var{n}} when the target is known to fit into a
-@code{CALL@var{n}} instruction encoding.  The current optimization
-converts the sequence into @code{NOP}/@code{CALL@var{n}} and removes the
-literal referenced by the @code{L32R} instruction.
+@item --no-relax
+Since the Xtensa version of @code{ld} enables the @option{--relax} option
+by default, the @option{--no-relax} option is provided to disable
+relaxation.
+
+@item --size-opt
+When optimizing indirect calls to direct calls, optimize for code size
+more than performance.  With this option, the linker will not insert
+no-ops or widen density instructions to preserve branch target
+alignment.  There may still be some cases where no-ops are required to
+preserve the correctness of the code.
+@end table
 
 @ifclear GENERIC
 @lowersections
This page took 0.044186 seconds and 4 git commands to generate.