From af54556ad34faad32bfe90c11ff125b3b9b62080 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 3 Apr 1998 05:57:33 +0000 Subject: [PATCH] * ld.texinfo: Completely rewrite linker script documentation. --- ld/ChangeLog | 11 + ld/ld.texinfo | 3169 +++++++++++++++++++++++++++---------------------- 2 files changed, 1731 insertions(+), 1449 deletions(-) diff --git a/ld/ChangeLog b/ld/ChangeLog index 3e9fcb3ef27..bdad02b43e6 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,14 @@ +Fri Apr 3 00:56:50 1998 Ian Lance Taylor + + * ld.texinfo: Completely rewrite linker script documentation. + +Mon Mar 30 12:47:33 1998 Ian Lance Taylor + + * configure.in: Set version to 2.9.1. + * configure: Rebuild. + + * Branched binutils 2.9. + Sat Mar 28 16:48:19 1998 Ian Lance Taylor * Makefile.am (MOSTLYCLEANFILES): Remove tmpdir. diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 03ce443362e..5acea12e95e 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -89,7 +89,7 @@ This file documents the @sc{gnu} linker ld. @menu * Overview:: Overview * Invocation:: Invocation -* Commands:: Command Language +* Scripts:: Linker Scripts @ifset GENERIC * Machine Dependent:: Machine Dependent Features @end ifset @@ -207,7 +207,7 @@ specifying a script in this way should only be used to augment the main linker script; if you want to use some command that logically can only appear once, such as the @code{SECTIONS} or @code{MEMORY} command, you must replace the default linker script using the @samp{-T} option. -@xref{Commands}. +@xref{Scripts}. For options whose names are a single letter, option arguments must either follow the option letter without intervening @@ -280,9 +280,8 @@ The default format is taken from the environment variable @ifset UsesEnvVars @xref{Environment}. @end ifset -You can also define the input -format from a script, using the command @code{TARGET}; see @ref{Option -Commands}. +You can also define the input format from a script, using the command +@code{TARGET}; see @ref{Format Commands}. @end ifclear @kindex -c @var{MRI-cmdfile} @@ -306,11 +305,10 @@ specified by any @samp{-L} options. @itemx -dc @itemx -dp These three options are equivalent; multiple forms are supported for -compatibility with other linkers. They -assign space to common symbols even if a relocatable output file is -specified (with @samp{-r}). The script command -@code{FORCE_COMMON_ALLOCATION} has the same effect. @xref{Option -Commands}. +compatibility with other linkers. They assign space to common symbols +even if a relocatable output file is specified (with @samp{-r}). The +script command @code{FORCE_COMMON_ALLOCATION} has the same effect. +@xref{Miscellaneous Commands}. @cindex entry point, from command line @kindex -e @var{entry} @@ -503,9 +501,18 @@ configured. @kindex --print-map @item -M @itemx --print-map -Print (to the standard output) a link map---diagnostic information about -where symbols are mapped by @code{ld}, and information on global common -storage allocation. +Print a link map to the standard output. A link map provides +information about the link, including the following: + +@itemize @bullet +@item +Where object files and symbols are mapped into memory. +@item +How common symbols are allocated. +@item +All archive members included in the link, with a mention of the symbol +which caused the archive member to be brought in. +@end itemize @kindex -n @cindex read-only text @@ -591,17 +598,17 @@ Print the names of the input files as @code{ld} processes them. @kindex -T @var{script} @kindex --script=@var{script} @cindex script files -@item -T @var{commandfile} -@itemx --script=@var{commandfile} -Read link commands from the file @var{commandfile}. These commands -replace @code{ld}'s default link script (rather than adding to it), so +@item -T @var{scriptfile} +@itemx --script=@var{scriptfile} +Use @var{scriptfile} as the linker script. This script replaces +@code{ld}'s default linker script (rather than adding to it), so @var{commandfile} must specify everything necessary to describe the -target format. You must use this option if you want to use a command +output file. You must use this option if you want to use a command which can only appear once in a linker script, such as the -@code{SECTIONS} or @code{MEMORY} command. @xref{Commands}. If -@var{commandfile} does not exist, @code{ld} looks for it in the -directories specified by any preceding @samp{-L} options. Multiple -@samp{-T} options accumulate. +@code{SECTIONS} or @code{MEMORY} command. @xref{Scripts}. If +@var{scriptfile} does not exist in the current directory, @code{ld} +looks for it in the directories specified by any preceding @samp{-L} +options. Multiple @samp{-T} options accumulate. @kindex -u @var{symbol} @kindex --undefined=@var{symbol} @@ -744,9 +751,9 @@ limited form of arithmetic is supported for the @var{expression} in this context: you may give a hexadecimal constant or the name of an existing symbol, or use @code{+} and @code{-} to add or subtract hexadecimal constants or symbols. If you need more elaborate expressions, consider -using the linker command language from a script (@pxref{Assignment, , -Assignment: Symbol Definitions}). @emph{Note:} there should be no -white space between @var{symbol}, the equals sign (``@key{=}''), and +using the linker command language from a script (@pxref{Assignments,, +Assignment: Symbol Definitions}). @emph{Note:} there should be no white +space between @var{symbol}, the equals sign (``@key{=}''), and @var{expression}. @cindex dynamic linker, from command line @@ -783,12 +790,10 @@ values. See the code in testsuite/ld-empic for details. @item --help Print a summary of the command-line options on the standard output and exit. -@cindex link map @kindex -Map @item -Map @var{mapfile} -Print to the file @var{mapfile} a link map---diagnostic information -about where symbols are mapped by @code{ld}, and information on global -common storage allocation. +Print a link map to the file @var{mapfile}. See the description of the +@samp{-M} option, above. @cindex memory usage @kindex --no-keep-memory @@ -926,7 +931,7 @@ happens when an @code{ld -shared} link includes a shared library as one of the input files. When the linker encounters such a dependency when doing a non-shared, -non-relocateable link, it will automatically try to locate the required +non-relocatable link, it will automatically try to locate the required shared library and include it in the link, if it is not included explicitly. In such a case, the @code{-rpath-link} option specifies the first set of directories to search. The @@ -1058,7 +1063,7 @@ Specify the name of a version script to the linker. This is typically used when creating shared libraries to specify additional information about the version heirarchy for the library being created. This option is only meaningful on ELF platforms which support shared libraries. -@xref{Version Script}. +@xref{VERSION}. @kindex --warn-comon @cindex warnings, on combining symbols @@ -1261,926 +1266,851 @@ variable is not defined, the default emulation depends upon how the linker was configured. @end ifset -@node Commands -@chapter Command Language +@node Scripts +@chapter Linker Scripts +@cindex scripts +@cindex linker scripts @cindex command files -The command language provides explicit control over the link process, -allowing complete specification of the mapping between the linker's -input files and its output. It controls: -@itemize @bullet -@item -input files -@item -file formats -@item -output file layout -@item -addresses of sections -@item -placement of common blocks -@end itemize +Every link is controlled by a @dfn{linker script}. This script is +written in the linker command language. + +The main purpose of the linker script is to describe how the sections in +the input files should be mapped into the output file, and to control +the memory layout of the output file. Most linker scripts do nothing +more than this. However, when necessary, the linker script can also +direct the linker to perform many other operations, using the commands +described below. + +The linker always uses a linker script. If you do not supply one +yourself, the linker will use a default script that is compiled into the +linker executable. You can use the @samp{--verbose} command line option +to display the default linker script. Certain command line options, +such as @samp{-r} or @samp{-N}, will affect the default linker script. + +You may supply your own linker script by using the @samp{-T} command +line option. When you do this, your linker script will replace the +default linker script. + +You may also use linker scripts implicitly by naming them as input files +to the linker, as though they were files to be linked. If the linker +opens a file which it can not recognize as an object file or as an +archive file, it will try to read it as a linker script. If the file +can not be parsed as a linker script, the linker will report an error. + +An implicit linker script will not replace the default linker script. +Typically an implicit linker script would contain only the @code{INPUT}, +@code{GROUP}, or @code{VERSION} commands. -You may supply a command file (also known as a linker script) to the -linker either explicitly through the @samp{-T} option, or implicitly as -an ordinary file. Normally you should use the @samp{-T} option. An -implicit linker script should only be used when you want to augment, -rather than replace, the default linker script; typically an implicit -linker script would consist only of @code{INPUT} or @code{GROUP} -commands. +@menu +* Basic Script Concepts:: Basic Linker Script Concepts +* Script Format:: Linker Script Format +* Simple Example:: Simple Linker Script Example +* Simple Commands:: Simple Linker Script Commands +* Assignments:: Assigning Values to Symbols +* SECTIONS:: SECTIONS Command +* MEMORY:: MEMORY Command +* PHDRS:: PHDRS Command +* VERSION:: VERSION Command +* Expressions:: Expressions in Linker Scripts +@end menu + +@node Basic Script Concepts +@section Basic Linker Script Concepts +@cindex linker script concepts +We need to define some basic concepts and vocabulary in order to +describe the linker script language. + +The linker combines input files into a single output file. The output +file and each input file are in a special data format known as an +@dfn{object file format}. Each file is called an @dfn{object file}. +The output file is often called an @dfn{executable}, but for our +purposes we will also call it an object file. Each object file has, +among other things, a list of @dfn{sections}. We sometimes refer to a +section in an input file as an @dfn{input section}; similarly, a section +in the output file is an @dfn{output section}. + +Each section in an object file has a name and a size. Most sections +also have an associated block of data, known as the @dfn{section +contents}. A section may be marked as @dfn{loadable}, which mean that +the contents should be loaded into memory when the output file is run. +A section with no contents may be @dfn{allocatable}, which means that an +area in memory should be set aside, but nothing in particular should be +loaded there (in some cases this memory must be zeroed out). A section +which is neither loadable nor allocatable typically contains some sort +of debugging information. + +Every loadable or allocatable output section has two addresses. The +first is the @dfn{VMA}, or virtual memory address. This is the address +the sectin will have when the output file is run. The second is the +@dfn{LMA}, or load memory address. This is the address at which the +section will be loaded. In most cases the two addresses will be the +same. An example of when they might be different is when a data section +is loaded into ROM, and then copied into RAM when the program starts up +(this technique is often used to initialize global variables in a ROM +based system). In this case the ROM address would be the LMA, and the +RAM address would be the VMA. + +You can see the sections in an object file by using the @code{objdump} +program with the @samp{-h} option. + +Every object file also has a list of @dfn{symbols}, known as the +@dfn{symbol table}. A symbol may be defined or undefined. Each symbol +has a name, and each defined symbol has an address, among other +information. If you compile a C or C++ program into an object file, you +will get a defined symbol for every defined function and global or +static variable. Every undefined function or global variable which is +referenced in the input file will become an undefined symbol. + +You can see the symbols in an object file by using the @code{nm} +program, or by using the @code{objdump} program with the @samp{-t} +option. + +@node Script Format +@section Linker Script Format +@cindex linker script format +Linker scripts are text files. + +You write a linker script as a series of commands. Each command is +either a keyword, possibly followed by arguments, or an assignment to a +symbol. You may separate commands using semicolons. Whitespace is +generally ignored. + +Strings such as file or format names can normally be entered directly. +If the file name contains a character such as a comma which would +otherwise serve to separate file names, you may put the file name in +double quotes. There is no way to use a double quote character in a +file name. + +You may include comments in linker scripts just as in C, delimited by +@samp{/*} and @samp{*/}. As in C, comments are syntactically equivalent +to whitespace. + +@node Simple Example +@section Simple Linker Script Example +@cindex linker script example +@cindex example of linker script +Many linker scripts are fairly simple. + +The simplest possible linker script has just one command: +@samp{SECTIONS}. You use the @samp{SECTIONS} command to describe the +memory layout of the output file. + +The @samp{SECTIONS} command is a powerful command. Here we will +describe a simple use of it. Let's assume your program consists only of +code, initialized data, and uninitialized data. These will be in the +@samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively. +Let's assume further that these are the only sections which appear in +your input files. + +For this example, let's say that the code should be loaded at address +0x10000, and that the data should start at address 0x8000000. Here is a +linker script which will do that: +@smallexample +SECTIONS +@{ + . = 0x10000; + .text : @{ *(.text) @} + . = 0x8000000; + .data : @{ *(.data) @} + .bss : @{ *(.bss) @} +@} +@end smallexample -If the linker opens a file which it cannot recognize as a supported -object or archive format, nor as a linker script, it reports an error. +You write the @samp{SECTIONS} command as the keyword @samp{SECTIONS}, +followed by a series of symbol assignments and output section +descriptions enclosed in curly braces. + +The first line in the above example sets the special symbol @samp{.}, +which is the location counter. If you do not specify the address of an +output section in some other way (other ways are described later), the +address is set from the current value of the location counter. The +location counter is then incremented by the size of the output section. + +The second line defines an output section, @samp{.text}. The colon is +required syntax which may be ignored for now. Within the curly braces +after the output section name, you list the names of the input sections +which should be placed into this output section. The @samp{*} is a +wildcard which matches any file name. The expression @samp{*(.text)} +means all @samp{.text} input sections in all input files. + +Since the location counter is @samp{0x10000} when the output section +@samp{.text} is defined, the linker will set the address of the +@samp{.text} section in the output file to be @samp{0x10000}. + +The remaining lines define the @samp{.data} and @samp{.bss} sections in +the output file. The @samp{.data} output section will be at address +@samp{0x8000000}. When the @samp{.bss} output section is defined, the +value of the location counter will be @samp{0x8000000} plus the size of +the @samp{.data} output section. The effect is that the @samp{.bss} +output section will follow immediately after the @samp{.data} output +section in memory. + +That's it! That's a simple and complete linker script. + +@node Simple Commands +@section Simple Linker Script Commands +@cindex linker script simple commands +In this section we describe the simple linker script commands. @menu -* Scripts:: Linker Scripts -* Expressions:: Expressions -* MEMORY:: MEMORY Command -* SECTIONS:: SECTIONS Command -* PHDRS:: PHDRS Command -* Entry Point:: The Entry Point -* Version Script:: Version Script -* Option Commands:: Option Commands +* Entry Point:: Setting the entry point +* File Commands:: Commands dealing with files +@ifclear SingleFormat +* Format Commands:: Commands dealing with object file formats +@end ifclear + +* Miscellaneous Commands:: Other linker script commands @end menu -@node Scripts -@section Linker Scripts -The @code{ld} command language is a collection of statements; some are -simple keywords setting a particular option, some are used to select and -group input files or name output files; and two statement -types have a fundamental and pervasive impact on the linking process. - -@cindex fundamental script commands -@cindex commands, fundamental -@cindex output file layout -@cindex layout of output file -The most fundamental command of the @code{ld} command language is the -@code{SECTIONS} command (@pxref{SECTIONS}). Every meaningful command -script must have a @code{SECTIONS} command: it specifies a -``picture'' of the output file's layout, in varying degrees of detail. -No other command is required in all cases. - -The @code{MEMORY} command complements @code{SECTIONS} by describing the -available memory in the target architecture. This command is optional; -if you don't use a @code{MEMORY} command, @code{ld} assumes sufficient -memory is available in a contiguous block for all output. -@xref{MEMORY}. - -@cindex comments -You may include comments in linker scripts just as in C: delimited -by @samp{/*} and @samp{*/}. As in C, comments are syntactically -equivalent to whitespace. +@node Entry Point +@subsection Setting the entry point +@kindex ENTRY(@var{symbol}) +@cindex start of execution +@cindex first instruction +@cindex entry point +The first instruction to execute in a program is called the @dfn{entry +point}. You can use the @code{ENTRY} linker script command to set the +entry point. The argument is a symbol name: +@smallexample +ENTRY(@var{symbol}) +@end smallexample -@node Expressions -@section Expressions -@cindex expression syntax -@cindex arithmetic -Many useful commands involve arithmetic expressions. The syntax for -expressions in the command language is identical to that of C -expressions, with the following features: +There are several ways to set the entry point. The linker will set the +entry point by trying each of the following methods in order, and +stopping when one of them succeeds: @itemize @bullet @item -All expressions evaluated as integers and -are of ``long'' or ``unsigned long'' type. +the @samp{-e} @var{entry} command-line option; @item -All constants are integers. +the @code{ENTRY(@var{symbol})} command in a linker script; @item -All of the C arithmetic operators are provided. +the value of the symbol @code{start}, if defined; @item -You may reference, define, and create global variables. +the address of the first byte of the @samp{.text} section, if present; @item -You may call special purpose built-in functions. +The address @code{0}. @end itemize -@menu -* Integers:: Integers -* Symbols:: Symbol Names -* Location Counter:: The Location Counter -* Operators:: Operators -* Evaluation:: Evaluation -* Assignment:: Assignment: Defining Symbols -* Arithmetic Functions:: Built-In Functions -* Semicolons:: Semicolon Usage -@end menu - -@node Integers -@subsection Integers -@cindex integer notation -@cindex octal integers -An octal integer is @samp{0} followed by zero or more of the octal -digits (@samp{01234567}). -@smallexample -_as_octal = 0157255; -@end smallexample - -@cindex decimal integers -A decimal integer starts with a non-zero digit followed by zero or -more digits (@samp{0123456789}). -@smallexample -_as_decimal = 57005; -@end smallexample +@node File Commands +@subsection Commands dealing with files +@cindex linker script file commands +Several linker script commands deal with files. -@cindex hexadecimal integers -@kindex 0x -A hexadecimal integer is @samp{0x} or @samp{0X} followed by one or -more hexadecimal digits chosen from @samp{0123456789abcdefABCDEF}. -@smallexample -_as_hex = 0xdead; -@end smallexample +@table @code +@item INCLUDE @var{filename} +@kindex INCLUDE @var{filename} +@cindex including a linker script +Include the linker script @var{filename} at this point. The file will +be searched for in the current directory, and in any directory specified +with the @code{-L} option. You can nest calls to @code{INCLUDE} up to +10 levels deep. -@cindex negative integers -To write a negative integer, use -the prefix operator @samp{-} (@pxref{Operators}). -@smallexample -_as_neg = -57005; -@end smallexample +@item INPUT(@var{file}, @var{file}, @dots{}) +@itemx INPUT(@var{file} @var{file} @dots{}) +@kindex INPUT(@var{files}) +@cindex input files in linker scripts +@cindex input object files in linker scripts +@cindex linker script input object files +The @code{INPUT} command directs the linker to include the named files +in the link, as though they were named on the command line. + +For example, if you always want to include @file{subr.o} any time you do +a link, but you can't be bothered to put it on every link command line, +then you can put @samp{INPUT (subr.o)} in your linker script. + +In fact, if you like, you can list all of your input files in the linker +script, and then invoke the linker with nothing but a @samp{-T} option. + +The linker will first try to open the file in the current directory. If +it is not found, the linker will search through the archive library +search path. See the description of @samp{-L} in @ref{Options,,Command +Line Options}. + +If you use @samp{INPUT (-l@var{file})}, @code{ld} will transform the +name to @code{lib@var{file}.a}, as with the command line argument +@samp{-l}. + +When you use the @code{INPUT} command in an implicit linker script, the +files will be included in the link at the point at which the linker +script file is included. This can affect archive searching. + +@item GROUP(@var{file}, @var{file}, @dots{}) +@itemx GROUP(@var{file} @var{file} @dots{}) +@kindex GROUP(@var{files}) +@cindex grouping input files +The @code{GROUP} command is like @code{INPUT}, except that the named +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 OUTPUT(@var{filename}) +@kindex OUTPUT(@var{filename}) +@cindex output file name in linker scripot +The @code{OUTPUT} command names the output file. Using +@code{OUTPUT(@var{filename})} in the linker script is exactly like using +@samp{-o @var{filename}} on the command line (@pxref{Options,,Command +Line Options}). If both are used, the command line option takes +precedence. + +You can use the @code{OUTPUT} command to define a default name for the +output file other than the usual default of @file{a.out}. + +@item SEARCH_DIR(@var{path}) +@kindex SEARCH_DIR(@var{path}) +@cindex library search path in linker script +@cindex archive search path in linker script +@cindex search path in linker script +The @code{SEARCH_DIR} command adds @var{path} to the list of paths where +@code{ld} looks for archive libraries. Using +@code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}} +on the command line (@pxref{Options,,Command Line Options}). If both +are used, then the linker will search both paths. Paths specified using +the command line option are searched first. + +@item STARTUP(@var{filename}) +@kindex STARTUP(@var{filename}) +@cindex first input file +The @code{STARTUP} command is just like the @code{INPUT} command, except +that @var{filename} will become the first input file to be linked, as +though it were specified first on the command line. This may be useful +when using a system in which the entry point is always the start of the +first file. +@end table -@cindex scaled integers -@cindex K and M integer suffixes -@cindex M and K integer suffixes -@cindex suffixes for integers -@cindex integer suffixes -Additionally the suffixes @code{K} and @code{M} may be used to scale a -constant by -@c TEXI2ROFF-KILL -@ifinfo -@c END TEXI2ROFF-KILL -@code{1024} or @code{1024*1024} -@c TEXI2ROFF-KILL -@end ifinfo -@tex -${\rm 1024}$ or ${\rm 1024}^2$ -@end tex -@c END TEXI2ROFF-KILL -respectively. For example, the following all refer to the same quantity: +@ifclear SingleFormat +@node Format Commands +@subsection Commands dealing with object file formats +A couple of linker script commands deal with object file formats. +@table @code +@item OUTPUT_FORMAT(@var{bfdname}) +@itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little}) +@kindex OUTPUT_FORMAT(@var{bfdname}) +@cindex output file format in linker script +The @code{OUTPUT_FORMAT} command names the BFD format to use for the +output file (@pxref{BFD}). Using @code{OUTPUT_FORMAT(@var{bfdname})} is +exactly like using @samp{-oformat @var{bfdname}} on the command line +(@pxref{Options,,Command Line Options}). If both are used, the command +line option takes precedence. + +You can use @code{OUTPUT_FORMAT} with three arguments to use different +formats based on the @samp{-EB} and @samp{-EL} command line options. +This permits the linker script to set the output format based on the +desired endianness. + +If neither @samp{-EB} nor @samp{-EL} are used, then the output format +will be the first argument, @var{default}. If @samp{-EB} is used, the +output format will be the second argument, @var{big}. If @samp{-EL} is +used, the output format will be the third argument, @var{little}. + +For example, the default linker script for the MIPS ELF target uses this +command: @smallexample - _fourk_1 = 4K; - _fourk_2 = 4096; - _fourk_3 = 0x1000; +OUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips) @end smallexample +This says that the default format for the output file is +@samp{elf32-bigmips}, but if the user uses the @samp{-EL} command line +option, the output file will be created in the @samp{elf32-littlemips} +format. + +@item TARGET(@var{bfdname}) +@kindex TARGET(@var{bfdname}) +@cindex input file format in linker script +The @code{TARGET} command names the BFD format to use when reading input +files. It affects subsequent @code{INPUT} and @code{GROUP} commands. +This command is like using @samp{-b @var{bfdname}} on the command line +(@pxref{Options,,Command Line Options}). If the @code{TARGET} command +is used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET} +command is also used to set the format for the output file. @xref{BFD}. +@end table +@end ifclear -@node Symbols -@subsection Symbol Names -@cindex symbol names -@cindex names -@cindex quoted symbol names -@kindex " -Unless quoted, symbol names start with a letter, underscore, or point -and may include any letters, underscores, digits, points, -and hyphens. Unquoted symbol names must not conflict with any -keywords. You can specify a symbol which contains odd characters or has -the same name as a keyword, by surrounding the symbol name in double quotes: -@smallexample - "SECTION" = 9; - "with a space" = "also with a space" + 10; -@end smallexample +@node Miscellaneous Commands +@subsection Other linker script commands +There are a few other linker scripts commands. -Since symbols can contain many non-alphabetic characters, it is safest -to delimit symbols with spaces. For example, @samp{A-B} is one symbol, -whereas @samp{A - B} is an expression involving subtraction. +@table @code +@item FORCE_COMMON_ALLOCATION +@kindex FORCE_COMMON_ALLOCATION +@cindex common allocation +This command has the same effect as the @samp{-d} command-line option: +to make @code{ld} assign space to common symbols even if a relocatable +output file is specified (@samp{-r}). -@node Location Counter -@subsection The Location Counter -@kindex . -@cindex dot -@cindex location counter -@cindex current output location -The special linker variable @dfn{dot} @samp{.} always contains the -current output location counter. Since the @code{.} always refers to -a location in an output section, it must always appear in an -expression within a @code{SECTIONS} command. The @code{.} symbol -may appear anywhere that an ordinary symbol is allowed in an -expression, but its assignments have a side effect. Assigning a value -to the @code{.} symbol will cause the location counter to be moved. -@cindex holes -This may be used to create holes in the output section. The location -counter may never be moved backwards. -@smallexample -SECTIONS -@{ - output : - @{ - file1(.text) - . = . + 1000; - file2(.text) - . += 1000; - file3(.text) - @} = 0x1234; -@} -@end smallexample -@noindent -In the previous example, @code{file1} is located at the beginning of the -output section, then there is a 1000 byte gap. Then @code{file2} -appears, also with a 1000 byte gap following before @code{file3} is -loaded. The notation @samp{= 0x1234} specifies what data to write in -the gaps (@pxref{Section Options}). +@item NOCROSSREFS(@var{section} @var{section} @dots{}) +@kindex NOCROSSREFS(@var{sections}) +@cindex cross references +This command may be used to tell @code{ld} to issue an error about any +references among certain output sections. -@iftex -@vfill -@end iftex +In certain types of programs, particularly on embedded systems when +using overlays, when one section is loaded into memory, another section +will not be. Any direct references between the two sections would be +errors. For example, it would be an error if code in one section called +a function defined in the other section. -@need 2000 -@node Operators -@subsection Operators -@cindex Operators for arithmetic -@cindex arithmetic operators -@cindex precedence in expressions -The linker recognizes the standard C set of arithmetic operators, with -the standard bindings and precedence levels: -@c TEXI2ROFF-KILL -@ifinfo -@c END TEXI2ROFF-KILL -@smallexample -precedence associativity Operators Notes -(highest) -1 left ! - ~ (1) -2 left * / % -3 left + - -4 left >> << -5 left == != > < <= >= -6 left & -7 left | -8 left && -9 left || -10 right ? : -11 right &= += -= *= /= (2) -(lowest) -@end smallexample -Notes: -(1) Prefix operators -(2) @xref{Assignment}. -@c TEXI2ROFF-KILL -@end ifinfo -@tex -\vskip \baselineskip -%"lispnarrowing" is the extra indent used generally for smallexample -\hskip\lispnarrowing\vbox{\offinterlineskip -\hrule -\halign -{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr -height2pt&\omit&&\omit&&\omit&\cr -&Precedence&& Associativity &&{\rm Operators}&\cr -height2pt&\omit&&\omit&&\omit&\cr -\noalign{\hrule} -height2pt&\omit&&\omit&&\omit&\cr -&highest&&&&&\cr -% '176 is tilde, '~' in tt font -&1&&left&&\qquad- \char'176\ !\qquad\dag&\cr -&2&&left&&* / \%&\cr -&3&&left&&+ -&\cr -&4&&left&&>> <<&\cr -&5&&left&&== != > < <= >=&\cr -&6&&left&&\&&\cr -&7&&left&&|&\cr -&8&&left&&{\&\&}&\cr -&9&&left&&||&\cr -&10&&right&&? :&\cr -&11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr -&lowest&&&&&\cr -height2pt&\omit&&\omit&&\omit&\cr} -\hrule} -@end tex -@iftex -{ -@obeylines@parskip=0pt@parindent=0pt -@dag@quad Prefix operators. -@ddag@quad @xref{Assignment}. -} -@end iftex -@c END TEXI2ROFF-KILL +The @code{NOCROSSREFS} command takes a list of output section names. If +@code{ld} detects any cross references between the sections, it reports +an error and returns a non-zero exit status. Note that the +@code{NOCROSSREFS} command uses output section names, not input section +names. -@node Evaluation -@subsection Evaluation +@ifclear SingleFormat +@item OUTPUT_ARCH(@var{bfdarch}) +@kindex OUTPUT_ARCH(@var{bfdarch}) +@cindex machine architecture +@cindex architecture +Specify a particular output machine architecture. The argument is one +of the names used by the BFD library (@pxref{BFD}). You can see the +architecture of an object file by using the @code{objdump} program with +the @samp{-f} option. +@end ifclear +@end table -@cindex lazy evaluation -@cindex expression evaluation order -The linker uses ``lazy evaluation'' for expressions; it only calculates -an expression when absolutely necessary. The linker needs the value of -the start address, and the lengths of memory regions, in order to do any -linking at all; these values are computed as soon as possible when the -linker reads in the command file. However, other values (such as symbol -values) are not known or needed until after storage allocation. Such -values are evaluated later, when other information (such as the sizes of -output sections) is available for use in the symbol assignment -expression. - -@node Assignment -@subsection Assignment: Defining Symbols +@node Assignments +@section Assigning Values to Symbols @cindex assignment in scripts @cindex symbol definition, scripts @cindex variables, defining -You may create global symbols, and assign values (addresses) to global -symbols, using any of the C assignment operators: +You may assign a value to a symbol in a linker script. This will define +the symbol as a global symbol. + +@menu +* Simple Assignments:: Simple Assignments +* PROVIDE:: PROVIDE +@end menu + +@node Simple Assignments +@subsection Simple Assignments + +You may assign to a symbol using any of the C assignment operators: @table @code -@item @var{symbol} = @var{expression} ; -@itemx @var{symbol} &= @var{expression} ; +@item @var{symbol} = @var{expression} ; @itemx @var{symbol} += @var{expression} ; @itemx @var{symbol} -= @var{expression} ; @itemx @var{symbol} *= @var{expression} ; @itemx @var{symbol} /= @var{expression} ; +@itemx @var{symbol} <<= @var{expression} ; +@itemx @var{symbol} >>= @var{expression} ; +@itemx @var{symbol} &= @var{expression} ; +@itemx @var{symbol} |= @var{expression} ; @end table -Two things distinguish assignment from other operators in @code{ld} -expressions. -@itemize @bullet -@item -Assignment may only be used at the root of an expression; -@samp{a=b+3;} is allowed, but @samp{a+b=3;} is an error. +The first case will define @var{symbol} to the value of +@var{expression}. In the other cases, @var{symbol} must already be +defined, and the value will be adjusted accordingly. -@kindex ; -@cindex semicolon -@item -You must place a trailing semicolon (``@key{;}'') at the end of an -assignment statement. -@end itemize +The special symbol name @samp{.} indicates the location counter. You +may only use this within a @code{SECTIONS} command. -Assignment statements may appear: -@itemize @bullet -@item -as commands in their own right in an @code{ld} script; or -@item -as independent statements within a @code{SECTIONS} command; or -@item -as part of the contents of a section definition in a -@code{SECTIONS} command. -@end itemize +The semicolon after @var{expression} is required. -The first two cases are equivalent in effect---both define a symbol with -an absolute address. The last case defines a symbol whose address is -relative to a particular section (@pxref{SECTIONS}). +Expressions are defined below; see @ref{Expressions}. -@cindex absolute and relocatable symbols -@cindex relocatable and absolute symbols -@cindex symbols, relocatable and absolute -When a linker expression is evaluated and assigned to a variable, it is -given either an absolute or a relocatable type. An absolute expression -type is one in which the symbol contains the value that it will have in -the output file; a relocatable expression type is one in which the -value is expressed as a fixed offset from the base of a section. - -The type of the expression is controlled by its position in the script -file. A symbol assigned within a section definition is created relative -to the base of the section; a symbol assigned in any other place is -created as an absolute symbol. Since a symbol created within a -section definition is relative to the base of the section, it -will remain relocatable if relocatable output is requested. A symbol -may be created with an absolute value even when assigned to within a -section definition by using the absolute assignment function -@code{ABSOLUTE}. For example, to create an absolute symbol whose address -is the last byte of an output section named @code{.data}: -@smallexample -SECTIONS@{ @dots{} - .data : - @{ - *(.data) - _edata = ABSOLUTE(.) ; - @} -@dots{} @} -@end smallexample +You may write symbol assignments as commands in their own right, or as +statements within a @code{SECTIONS} command, or as part of an output +section description in a @code{SECTIONS} command. + +The section of the symbol will be set from the section of the +expression; for more information, see @ref{Expression Section}. + +Here is an example showing the three different places that symbol +assignments may be used: -The linker tries to put off the evaluation of an assignment until all -the terms in the source expression are known (@pxref{Evaluation}). For -instance, the sizes of sections cannot be known until after allocation, -so assignments dependent upon these are not performed until after -allocation. Some expressions, such as those depending upon the location -counter @dfn{dot}, @samp{.} must be evaluated during allocation. If the -result of an expression is required, but the value is not available, -then an error results. For example, a script like the following @smallexample -SECTIONS @{ @dots{} - text 9+this_isnt_constant : - @{ @dots{} +floating_point = 0; +SECTIONS +@{ + .text : + @{ + *(.text) + _etext = .; @} -@dots{} @} + _bdata = (. + 3) & ~ 4; + .data : @{ *(.data) @} +@} @end smallexample -@kindex Non constant expression @noindent -will cause the error message ``@code{Non constant expression for initial -address}''. - -@cindex provide +In this example, the symbol @samp{floating_point} will be defined as +zero. The symbol @samp{_etext} will be defined as the address following +the last @samp{.text} input section. The symbol @samp{_bdata} will be +defined as the address following the @samp{.text} output section aligned +upward to a 4 byte boundary. + +@node PROVIDE +@subsection PROVIDE +@cindex PROVIDE In some cases, it is desirable for a linker script to define a symbol -only if it is referenced, and only if it is not defined by any object -included in the link. For example, traditional linkers defined the -symbol @samp{etext}. However, ANSI C requires that the user be able to -use @samp{etext} as a function name without encountering an error. -The @code{PROVIDE} keyword may be used to define a symbol, such as +only if it is referenced and is not defined by any object included in +the link. For example, traditional linkers defined the symbol +@samp{etext}. However, ANSI C requires that the user be able to use +@samp{etext} as a function name without encountering an error. The +@code{PROVIDE} keyword may be used to define a symbol, such as @samp{etext}, only if it is referenced but not defined. The syntax is @code{PROVIDE(@var{symbol} = @var{expression})}. -@node Arithmetic Functions -@subsection Arithmetic Functions -@cindex functions in expression language -The command language includes a number of built-in -functions for use in link script expressions. -@table @code -@kindex ABSOLUTE(@var{exp}) -@cindex expression, absolute -@item ABSOLUTE(@var{exp}) -Return the absolute (non-relocatable, as opposed to non-negative) value -of the expression @var{exp}. Primarily useful to assign an absolute -value to a symbol within a section definition, where symbol values are -normally section-relative. - -@kindex ADDR(@var{section}) -@cindex section address -@item ADDR(@var{section}) -Return the absolute address of the named @var{section}. Your script must -previously have defined the location of that section. In the following -example, @code{symbol_1} and @code{symbol_2} are assigned identical -values: +Here is an example of using @code{PROVIDE} to define @samp{etext}: @smallexample -@group -SECTIONS@{ @dots{} - .output1 : - @{ - start_of_output_1 = ABSOLUTE(.); - @dots{} - @} - .output : +SECTIONS +@{ + .text : @{ - symbol_1 = ADDR(.output1); - symbol_2 = start_of_output_1; + *(.text) + _etext = .; + PROVIDE(etext = .); @} -@dots{} @} -@end group -@end smallexample - -@kindex LOADADDR(@var{section}) -@cindex section load address -@item LOADADDR(@var{section}) -Return the absolute load address of the named @var{section}. This is -normally the same as @code{ADDR}, but it may be different if the -@code{AT} keyword is used in the section definition (@pxref{Section -Options}). - -@kindex ALIGN(@var{exp}) -@cindex rounding up location counter -@item ALIGN(@var{exp}) -Return the result of the current location counter (@code{.}) aligned to -the next @var{exp} boundary. @var{exp} must be an expression whose -value is a power of two. This is equivalent to -@smallexample -(. + @var{exp} - 1) & ~(@var{exp} - 1) -@end smallexample - -@code{ALIGN} doesn't change the value of the location counter---it just -does arithmetic on it. As an example, to align the output @code{.data} -section to the next @code{0x2000} byte boundary after the preceding -section and to set a variable within the section to the next -@code{0x8000} boundary after the input sections: -@smallexample -@group -SECTIONS@{ @dots{} - .data ALIGN(0x2000): @{ - *(.data) - variable = ALIGN(0x8000); - @} -@dots{} @} -@end group +@} @end smallexample -@noindent -The first use of @code{ALIGN} in this example specifies the location of -a section because it is used as the optional @var{start} attribute of a -section definition (@pxref{Section Options}). The second use simply -defines the value of a variable. - -The built-in @code{NEXT} is closely related to @code{ALIGN}. - -@kindex DEFINED(@var{symbol}) -@cindex symbol defaults -@item DEFINED(@var{symbol}) -Return 1 if @var{symbol} is in the linker global symbol table and is -defined, otherwise return 0. You can use this function to provide default -values for symbols. For example, the following command-file fragment shows how -to set a global symbol @code{begin} to the first location in the -@code{.text} section---but if a symbol called @code{begin} already -existed, its value is preserved: -@smallexample -@group -SECTIONS@{ @dots{} - .text : @{ - begin = DEFINED(begin) ? begin : . ; - @dots{} - @} -@dots{} @} -@end group -@end smallexample +In this example, if the program defines @samp{_etext}, the linker will +give a multiple definition error. If, on the other hand, the program +defines @samp{etext}, 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. -@kindex NEXT(@var{exp}) -@cindex unallocated address, next -@item NEXT(@var{exp}) -Return the next unallocated address that is a multiple of @var{exp}. -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. +@node SECTIONS +@section SECTIONS command +@kindex SECTIONS +The @code{SECTIONS} command tells the linker how to map input sections +into output sections, and how to place the output sections in memory. -@kindex SIZEOF(@var{section}) -@cindex section size -@item SIZEOF(@var{section}) -Return the size in bytes of the named @var{section}, if that section has -been allocated. In the following example, @code{symbol_1} and -@code{symbol_2} are assigned identical values: -@c What does it return if the section hasn't been allocated? 0? +The format of the @code{SECTIONS} command is: @smallexample -@group -SECTIONS@{ @dots{} - .output @{ - .start = . ; - @dots{} - .end = . ; - @} - symbol_1 = .end - .start ; - symbol_2 = SIZEOF(.output); -@dots{} @} -@end group +SECTIONS +@{ + @var{sections-command} + @var{sections-command} + @dots{} +@} @end smallexample -@kindex SIZEOF_HEADERS -@cindex header size -@kindex sizeof_headers -@item SIZEOF_HEADERS -@itemx sizeof_headers -Return the size in bytes of the output file's headers. You can use this number -as the start address of the first section, if you choose, to facilitate -paging. - -@kindex MAX -@item MAX(@var{exp1}, @var{exp2}) -Returns the maximum of @var{exp1} and @var{exp2}. - -@kindex MIN -@item MIN(@var{exp1}, @var{exp2}) -Returns the minimum of @var{exp1} and @var{exp2}. +Each @var{sections-command} may of be one of the following: -@end table +@itemize @bullet +@item +an @code{ENTRY} command (@pxref{Entry Point,,Entry command}) +@item +a symbol assignment (@pxref{Assignments}) +@item +an output section description +@item +an overlay description +@end itemize -@node Semicolons -@subsection Semicolons +The @code{ENTRY} command and symbol assignments are permitted inside the +@code{SECTIONS} command for convenience in using the location counter in +those commands. This can also make the linker script easier to +understand because you can use those commands at meaningful points in +the layout of the output file. -Semicolons (``@key{;}'') are required in the following places. In all -other places they can appear for aesthetic reasons but are otherwise ignored. +Output section descriptions and overlay descriptions are described +below. -@table @code -@item Assignment -Semicolons must appear at the end of assignment expressions. -@xref{Assignment} +If you do not use a @code{SECTIONS} command in your linker script, the +linker will place each input section into an identically named output +section in the order that the sections are first encountered in the +input files. If all input sections are present in the first file, for +example, the order of sections in the output file will match the order +in the first input file. The first section will be at address zero. -@item PHDRS -Semicolons must appear at the end of a @code{PHDRS} statement. -@xref{PHDRS} -@end table +@menu +* Output Section Description:: Output section description +* Output Section Name:: Output section name +* Output Section Address:: Output section address +* Input Section:: Input section description +* Output Section Data:: Output section data +* Output Section Keywords:: Output section keywords +* Output Section Discarding:: Output section discarding +* Output Section Attributes:: Output section attributes +* Overlay Description:: Overlay description +@end menu -@node MEMORY -@section Memory Layout -@kindex MEMORY -@cindex regions of memory -@cindex discontinuous memory -@cindex allocating memory -The linker's default configuration permits allocation of all available memory. -You can override this configuration by using the @code{MEMORY} command. The -@code{MEMORY} command describes the location and size of blocks of -memory in the target. By using it carefully, you can describe which -memory regions may be used by the linker, and which memory regions it -must avoid. The linker does not shuffle sections to fit into the -available regions, but does move the requested sections into the correct -regions and issue errors when the regions become too full. - -A command file may contain at most one use of the @code{MEMORY} -command; however, you can define as many blocks of memory within it as -you wish. The syntax is: - +@node Output Section Description +@subsection Output section description +The full description of an output section looks like this: @smallexample -@group -MEMORY +@group +@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})] @{ - @var{name} (@var{attr}) : ORIGIN = @var{origin}, LENGTH = @var{len} + @var{output-section-command} + @var{output-section-command} @dots{} - @} + @} [>@var{region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] @end group @end smallexample -@table @code -@cindex naming memory regions -@item @var{name} -is a name used internally by the linker to refer to the region. Any -symbol name may be used. The region names are stored in a separate -name space, and will not conflict with symbols, file names or section -names. Use distinct names to specify multiple regions. - -@cindex memory region attributes -@item (@var{attr}) -is an optional list of attributes that specify whether to use a -particular memory to place sections that are not listed in the linker -script. Valid attribute lists must be made up of the characters -``@code{ALIRWX}'' that match section attributes. If you omit the -attribute list, you may omit the parentheses around it as well. The -attributes currently supported are: - -@table @samp -@item @code{Letter} -@code{Section Attribute} - -@item @code{R} -Read-only sections. - -@item @code{W} -Read/write sections. - -@item @code{X} -Sections containing executable code. - -@item @code{A} -Allocated sections. - -@item @code{I} -Initialized sections. -@item @code{L} -Same as @code{I}. +Most output sections do not use most of the optional section attributes. -@item @code{!} -Invert the sense of any of the following attributes. -@end table +The whitespace around @var{section} is required, so that the section +name is unambiguous. The colon and the curly braces are also required. +The line breaks and other white space are optional. -@kindex ORIGIN = -@kindex o = -@kindex org = -@item @var{origin} -is the start address of the region in physical memory. It is -an expression that must evaluate to a constant before -memory allocation is performed. The keyword @code{ORIGIN} may be -abbreviated to @code{org} or @code{o} (but not, for example, @samp{ORG}). +Each @var{output-section-command} may be one of the following: -@kindex LENGTH = -@kindex len = -@kindex l = -@item @var{len} -is the size in bytes of the region (an expression). -The keyword @code{LENGTH} may be abbreviated to @code{len} or @code{l}. -@end table - -For example, to specify that memory has two regions available for -allocation---one starting at 0 for 256 kilobytes, and the other starting -at @code{0x40000000} for four megabytes. The @code{rom} memory region -will get all sections without an explicit memory register that are -either read-only or contain code, while the @code{ram} memory region -will get the sections. +@itemize @bullet +@item +a symbol assignment (@pxref{Assignments}) +@item +an input section description (@pxref{Input Section}) +@item +data values to include directly (@pxref{Output Section Data}) +@item +a special output section keyword (@pxref{Output Section Keywords}) +@end itemize +@node Output Section Name +@subsection Output section name +@cindex name, section +@cindex section name +The name of the output section is @var{section}. @var{section} must +meet the constraints of your output format. In formats which only +support a limited number of sections, such as @code{a.out}, the name +must be one of the names supported by the format (@code{a.out}, for +example, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the +output format supports any number of sections, but with numbers and not +names (as is the case for Oasys), the name should be supplied as a +quoted numeric string. A section name may consist of any sequence of +characters, but a name which contains any unusual characters such as +commas must be quoted. + +The output section name @samp{/DISCARD/} is special; @ref{Output Section +Discarding}. + +@node Output Section Address +@subsection Output section address +@cindex address, section +@cindex section address +The @var{address} is an expression for the VMA (the virtual memory +address) of the output section. If you do not provide @var{address}, +the linker will set it based on @var{region} if present, or otherwise +based on the current value of the location counter. + +If you provide @var{address}, the address of the output section will be +set to precisely that. If you provide neither @var{address} nor +@var{region}, then the address of the output section will be set to the +current value of the location counter aligned to the alignment +requirements of the output section. The alignment requirement of the +output section is the strictest alignment of any input section contained +within the output section. + +For example, @smallexample -@group -MEMORY - @{ - rom (rx) : ORIGIN = 0, LENGTH = 256K - ram (!rx) : org = 0x40000000, l = 4M - @} -@end group +.text . : @{ *(.text) @} @end smallexample +@noindent +and +@smallexample +.text : @{ *(.text) @} +@end smallexample +@noindent +are subtly different. The first will set the address of the +@samp{.text} output section to the current value of the location +counter. The second will set it to the current value of the location +counter aligned to the strictest alignment of a @samp{.text} input +section. + +The @var{address} may be an arbitrary expression; @ref{Expressions}. +For example, if you want to align the section on a 0x10 byte boundary, +so that the lowest four bits of the section address are zero, you could +do something like this: +@smallexample +.text ALIGN(0x10) : @{ *(.text) @} +@end smallexample +@noindent +This works because @code{ALIGN} returns the current location counter +aligned upward to the specified value. -Once you have defined a region of memory named @var{mem}, you can direct -specific output sections there by using a command ending in -@samp{>@var{mem}} within the @code{SECTIONS} command (@pxref{Section -Options}). If the combined output sections directed to a region are too -big for the region, the linker will issue an error message. - -@node SECTIONS -@section Specifying Output Sections - -@kindex SECTIONS -The @code{SECTIONS} command controls exactly where input sections are -placed into output sections, their order in the output file, and to -which output sections they are allocated. - -You may use at most one @code{SECTIONS} command in a script file, -but you can have as many statements within it as you wish. Statements -within the @code{SECTIONS} command can do one of three things: +Specifying @var{address} for a section will change the value of the +location counter. -@itemize @bullet -@item -define the entry point; +@node Input Section +@subsection Input section description +@cindex input sections +@cindex mapping input sections to output sections +The most common output section command is an input section description. -@item -assign a value to a symbol; +The input section description is the most basic linker script operation. +You use output sections to tell the linker how to lay out your program +in memory. You use input section descriptions to tell the linker how to +map the input files into your memory layout. -@item -describe the placement of a named output section, and which input -sections go into it. -@end itemize +@menu +* Input Section Basics:: Input section basics +* Input Section Wildcards:: Input section wildcard patterns +* Input Section Common:: Input section for common symbols +* Input Section Example:: Input section example +@end menu -You can also use the first two operations---defining the entry point and -defining symbols---outside the @code{SECTIONS} command: @pxref{Entry -Point}, and @ref{Assignment}. They are permitted here as well for -your convenience in reading the script, so that symbols and the entry -point can be defined at meaningful points in your output-file layout. +@node Input Section Basics +@subsubsection Input section basics +@cindex input section basics +An input section description consists of a file name optionally followed +by a list of section names in parentheses. -If you do not use a @code{SECTIONS} command, the linker places each input -section into an identically named output section in the order that the -sections are first encountered in the input files. If all input sections -are present in the first file, for example, the order of sections in the -output file will match the order in the first input file. +The file name and the section name may be wildcard patterns, which we +describe further below (@pxref{Input Section Wildcards}). -@menu -* Section Definition:: Section Definitions -* Section Placement:: Section Placement -* Section Data Expressions:: Section Data Expressions -* Section Options:: Optional Section Attributes -* Overlays:: Overlays -@end menu +The most common input section description is to include all input +sections with a particular name in the output section. For example, to +include all input @samp{.text} sections, you would write: +@smallexample +*(.text) +@end smallexample +@noindent +Here the @samp{*} is a wildcard which matches any file name. -@node Section Definition -@subsection Section Definitions -@cindex section definition -The most frequently used statement in the @code{SECTIONS} command is -the @dfn{section definition}, which specifies the -properties of an output section: its location, alignment, contents, -fill pattern, and target memory region. Most of -these specifications are optional; the simplest form of a section -definition is +There are two ways to include more than one section: @smallexample -SECTIONS @{ @dots{} - @var{secname} : @{ - @var{contents} - @} -@dots{} @} +*(.text .rdata) +*(.text) *(.rdata) @end smallexample -@cindex naming output sections @noindent -@var{secname} is the name of the output section, and @var{contents} a -specification of what goes there---for example, a list of input files or -sections of input files (@pxref{Section Placement}). The whitespace -around @var{secname} is required, so that the section name is -unambiguous. The other whitespace shown is optional. You do need the -colon @samp{:} and the braces @samp{@{@}}, however. - -@var{secname} must meet the constraints of your output format. In -formats which only support a limited number of sections, such as -@code{a.out}, the name must be one of the names supported by the format -(@code{a.out}, for example, allows only @code{.text}, @code{.data} or -@code{.bss}). If the output format supports any number of sections, but -with numbers and not names (as is the case for Oasys), the name should be -supplied as a quoted numeric string. A section name may consist of any -sequence of characters, but any name which does not conform to the standard -@code{ld} symbol name syntax must be quoted. -@xref{Symbols, , Symbol Names}. - -The special @var{secname} @samp{/DISCARD/} may be used to discard input -sections. Any sections which are assigned to an output section named -@samp{/DISCARD/} are not included in the final link output. - -The linker will not create output sections which do not have any -contents. This is for convenience when referring to input sections that -may or may not exist. For example, +The difference between these is the order in which the @samp{.text} and +@samp{.rdata} input sections will appear in the output section. In the +first example, they will be intermingled. In the second example, all +@samp{.text} input sections will appear first, followed by all +@samp{.rdata} input sections. + +You can specify a file name to include sections from a particular file. +You would do this if one or more of your files contain special data that +needs to be at a particular location in memory. For example: @smallexample -.foo @{ *(.foo) @} +data.o(.data) @end smallexample -will only create a @samp{.foo} section in the output file if there is a -@samp{.foo} section in at least one input file. -@node Section Placement -@subsection Section Placement +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: +@smallexample +data.o +@end smallexample -@cindex contents of a section -In a section definition, you can specify the contents of an output -section by listing particular input files, by listing particular -input-file sections, or by a combination of the two. You can also place -arbitrary data in the section, and define symbols relative to the -beginning of the section. +When you use a file name which 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 +though it appeared on the command line. Note that this differs from an +@code{INPUT} command, because the linker will not search for the file in +the archive search path. -The @var{contents} of a section definition may include any of the -following kinds of statement. You can include as many of these as you -like in a single section definition, separated from one another by -whitespace. +@node Input Section Wildcards +@subsubsection Input section wildcard patterns +@cindex input section wildcards +@cindex wildcard file name patterns +@cindex file name wildcard patterns +@cindex section name wildcard patterns +In an input section description, either the file name or the section +name or both may be wildcard patterns. -@table @code -@kindex @var{filename} -@cindex input files, section defn -@cindex files, including in output sections -@item @var{filename} -You may simply name a particular input file to be placed in the current -output section; @emph{all} sections from that file are placed in the -current section definition. If the file name has already been mentioned -in another section definition, with an explicit section name list, then -only those sections which have not yet been allocated are used. - -To specify a list of particular files by name: -@smallexample -.data : @{ afile.o bfile.o cfile.o @} -@end smallexample -@noindent -The example also illustrates that multiple statements can be included in -the contents of a section definition, since each file name is a separate -statement. - -@kindex @var{filename}(@var{section}) -@cindex files and sections, section defn -@item @var{filename}( @var{section} ) -@itemx @var{filename}( @var{section} , @var{section}, @dots{} ) -@itemx @var{filename}( @var{section} @var{section} @dots{} ) -You can name one or more sections from your input files, for insertion -in the current output section. If you wish to specify a list of -input-file sections inside the parentheses, separate the section names -with whitespace. - -@cindex input sections to output section -@kindex *(@var{section}) -@item * (@var{section}) -@itemx * (@var{section}, @var{section}, @dots{}) -@itemx * (@var{section} @var{section} @dots{}) -Instead of explicitly naming particular input files in a link control -script, you can refer to @emph{all} files from the @code{ld} command -line: use @samp{*} instead of a particular file name before the -parenthesized input-file section list. - -If you have already explicitly included some files by name, @samp{*} -refers to all @emph{remaining} files---those whose places in the output -file have not yet been defined. - -For example, to copy sections @code{1} through @code{4} from an Oasys file -into the @code{.text} section of an @code{a.out} file, and sections @code{13} -and @code{14} into the @code{.data} section: -@smallexample -@group -SECTIONS @{ - .text :@{ - *("1" "2" "3" "4") - @} - - .data :@{ - *("13" "14") - @} -@} -@end group -@end smallexample +The file name of @samp{*} seen in many examples is a simple wildcard +pattern for the file name. -@cindex @code{[@var{section}@dots{}]}, not supported -@samp{[ @var{section} @dots{} ]} used to be accepted as an alternate way -to specify named sections from all unallocated input files. Because -some operating systems (VMS) allow brackets in file names, that notation -is no longer supported. - -@cindex uninitialized data -@cindex commons in output -@kindex *( COMMON ) -@item @var{filename}@code{( COMMON )} -@itemx *( COMMON ) -Specify where in your output file to place uninitialized data -with this notation. @code{*(COMMON)} by itself refers to all -uninitialized data from all input files (so far as it is not yet -allocated); @var{filename}@code{(COMMON)} refers to uninitialized data -from a particular file. Both are special cases of the general -mechanisms for specifying where to place input-file sections: -@code{ld} permits you to refer to uninitialized data as if it -were in an input-file section named @code{COMMON}, regardless of the -input file's format. -@end table +The wildcard patterns are like those used by the Unix shell. -In any place where you may use a specific file or section name, you may -also use a wildcard pattern. The linker handles wildcards much as the -Unix shell does. A @samp{*} character matches any number of characters. -A @samp{?} character matches any single character. The sequence -@samp{[@var{chars}]} will match a single instance of any of the -@var{chars}; the @samp{-} character may be used to specify a range of -characters, as in @samp{[a-z]} to match any lower case letter. A -@samp{\} character may be used to quote the following character. +@table @samp +@item * +matches any number of characters +@item ? +matches any single character +@item [@var{chars}] +matches a single instance of any of the @var{chars}; the @samp{-} +character may be used to specify a range of characters, as in +@samp{[a-z]} to match any lower case letter +@item \ +quotes the following character +@end table When a file name is matched with a wildcard, the wildcard characters will not match a @samp{/} character (used to separate directory names on Unix). A pattern consisting of a single @samp{*} character is an -exception; it will always match any file name. In a section name, the -wildcard characters will match a @samp{/} character. - -Wildcards only match files which are explicitly specified on the command -line. The linker does not search directories to expand wildcards. -However, if you specify a simple file name---a name with no wildcard -characters---in a linker script, and the file name is not also specified -on the command line, the linker will attempt to open the file as though -it appeared on the command line. +exception; it will always match any file name, whether it contains a +@samp{/} or not. In a section name, the wildcard characters will match +a @samp{/} character. + +File name wildcard patterns only match files which are explicitly +specified on the command line or in an @code{INPUT} command. The linker +does not search directories to expand wildcards. + +If a file name matches more than one wildcard pattern, or if a file name +appears explicitly and is also matched by a wildcard pattern, the linker +will use the first match in the linker script. For example, this +sequence of input section descriptions is probably in error, because the +@file{data.o} rule will not be used: +@smallexample +.data : @{ *(.data) @} +.data1 : @{ data.o(.data) @} +@end smallexample -In the following example, the command script arranges the output file -into three consecutive sections, named @code{.text}, @code{.data}, and -@code{.bss}, taking the input for each from the correspondingly named -sections of all the input files: +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. +This example shows how wildcard patterns might be used to partition +files. This linker script directs the linker to place all @samp{.text} +sections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}. +The linker will place the @samp{.data} section from all files beginning +with an upper case character in @samp{.DATA}; for all other files, the +linker will place the @samp{.data} section in @samp{.data}. @smallexample @group -SECTIONS @{ +SECTIONS @{ .text : @{ *(.text) @} - .data : @{ *(.data) @} - .bss : @{ *(.bss) *(COMMON) @} -@} + .DATA : @{ [A-Z]*(.data) @} + .data : @{ *(.data) @} + .bss : @{ *(.bss) @} +@} @end group @end smallexample -The following example reads all of the sections from file @code{all.o} -and places them at the start of output section @code{outputa} which -starts at location @code{0x10000}. All of section @code{.input1} from -file @code{foo.o} follows immediately, in the same output section. All -of section @code{.input2} from @code{foo.o} goes into output section -@code{outputb}, followed by section @code{.input1} from @code{foo1.o}. -All of the remaining @code{.input1} and @code{.input2} sections from any -files are written to output section @code{outputc}. +@node Input Section Common +@subsubsection Input section for common symbols +@cindex common symbol placement +@cindex uninitialized data placement +A special notation is needed for common symbols, because in many object +file formats common symbols do not have a particular input section. The +linker treats common symbols as though they are in an input section +named @samp{COMMON}. + +You may use file names with the @samp{COMMON} section just as with any +other input sections. You can use this to place common symbols from a +particular input file in one section while common symbols from other +input files are placed in another section. + +In most cases, common symbols in input files will be placed in the +@samp{.bss} section in the output file. For example: +@smallexample +.bss @{ *(.bss) *(COMMON) @} +@end smallexample + +@cindex scommon section +@cindex small common symbols +Some object file formats have more than one type of common symbol. For +example, the MIPS ELF object file format distinguishes standard common +symbols and small common symbols. In this case, the linker will use a +different special section name for other types of common symbols. In +the case of MIPS ELF, the linker uses @samp{COMMON} for standard common +symbols and @samp{.scommon} for small common symbols. This permits you +to map the different types of common symbols into memory at different +locations. + +@cindex [COMMON] +You will sometimes see @samp{[COMMON]} in old linker scripts. This +notation is now considered obsolete. It is equivalent to +@samp{*(COMMON)}. + +@node Input Section Example +@subsubsection Input section example +The following example is a complete linker script. It tells the linker +to read all of the sections from file @file{all.o} and place them at the +start of output section @samp{outputa} which starts at location +@samp{0x10000}. All of section @samp{.input1} from file @file{foo.o} +follows immediately, in the same output section. All of section +@samp{.input2} from @file{foo.o} goes into output section +@samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}. +All of the remaining @samp{.input1} and @samp{.input2} sections from any +files are written to output section @samp{outputc}. @smallexample @group @@ -2204,259 +2134,252 @@ SECTIONS @{ @end group @end smallexample -This example shows how wildcard patterns might be used to partition -files. All @code{.text} sections are placed in @code{.text}, and all -@code{.bss} sections are placed in @code{.bss}. For all files beginning -with an upper case character, the @code{.data} section is placed into -@code{.DATA}; for all other files, the @code{.data} section is placed -into @code{.data}. +@node Output Section Data +@subsection Output section data +@cindex data +@cindex section data +@cindex output section data +@kindex BYTE(@var{expression}) +@kindex SHORT(@var{expression}) +@kindex LONG(@var{expression}) +@kindex QUAD(@var{expression}) +@kindex SQUAD(@var{expression}) +You can include explicit bytes of data in an output section by using +@code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as +an output section command. Each keyword is followed by an expression in +parentheses providing the value to store (@pxref{Expressions}). The +value of the expression is stored at the current value of the location +counter. + +The @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands +store one, two, four, and eight bytes (respectively). After storing the +bytes, the location counter is incremented by the number of bytes +stored. + +For example, this will store the byte 1 followed by the four byte value +of the symbol @samp{addr}: +@smallexample +BYTE(1) +LONG(addr) +@end smallexample + +When using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the +same; they both store an 8 byte, or 64 bit, value. When both host and +target are 32 bits, an expression is computed as 32 bits. In this case +@code{QUAD} stores a 32 bit value zero extended to 64 bits, and +@code{SQUAD} stores a 32 bit value sign extended to 64 bits. +If the object file format of the output file has an explicit endianness, +which is the normal case, the value will be stored in that endianness. +When the object file format does not have an explicit endianness, as is +true of, for example, S-records, the value will be stored in the +endianness of the first input object file. + +@kindex FILL(@var{expression}) +@cindex holes, filling +@cindex unspecified memory +You may use the @code{FILL} command to set the fill pattern for the +current section. It is followed by an expression in parentheses. Any +otherwise unspecified regions of memory within the section (for example, +gaps left due to the required alignment of input sections) are filled +with the two least significant bytes of the expression, repeated as +necessary. A @code{FILL} statement covers memory locations after the +point at which it occurs in the section definition; by including more +than one @code{FILL} statement, you can have different fill patterns in +different parts of an output section. + +This example shows how to fill unspecified regions of memory with the +value @samp{0x9090}: @smallexample -@group -SECTIONS @{ - .text : @{ *(.text) @} - .DATA : @{ [A-Z]*(.data) @} - .data : @{ *(.data) @} - .bss : @{ *(.bss) @} -@} -@end group +FILL(0x9090) @end smallexample -@node Section Data Expressions -@subsection Section Data Expressions +The @code{FILL} command is similar to the @samp{=@var{fillexp}} output +section attribute (@pxref{Output Section Fill}), but it only affects the +part of the section following the @code{FILL} command, rather than the +entire section. If both are used, the @code{FILL} command takes +precedence. -@cindex expressions in a section -The foregoing statements arrange, in your output file, data originating -from your input files. You can also place data directly in an output -section from the link command script. Most of these additional -statements involve expressions (@pxref{Expressions}). Although these -statements are shown separately here for ease of presentation, no such -segregation is needed within a section definition in the @code{SECTIONS} -command; you can intermix them freely with any of the statements we've -just described. +@node Output Section Keywords +@subsection Output section keywords +There are a couple of keywords which can appear as output section +commands. @table @code +@kindex CREATE_OBJECT_SYMBOLS @cindex input filename symbols @cindex filename symbols -@kindex CREATE_OBJECT_SYMBOLS @item CREATE_OBJECT_SYMBOLS -Create a symbol for each input file -in the current section, set to the address of the first byte of -data written from that input file. For instance, with @code{a.out} -files it is conventional to have a symbol for each input file. You can -accomplish this by defining the output @code{.text} section as follows: -@smallexample -@group -SECTIONS @{ - .text 0x2020 : - @{ - CREATE_OBJECT_SYMBOLS - *(.text) - _etext = ALIGN(0x2000); - @} - @dots{} -@} -@end group -@end smallexample - -If @code{sample.ld} is a file containing this script, and @code{a.o}, -@code{b.o}, @code{c.o}, and @code{d.o} are four input files with -contents like the following--- -@smallexample -@group -/* a.c */ +The command tells the linker to create a symbol for each input file. +The name of each symbol will be the name of the corresponding input +file. The section of each symbol will be the output section in which +the @code{CREATE_OBJECT_SYMBOLS} command appears. -afunction() @{ @} -int adata=1; -int abss; -@end group -@end smallexample +This is conventional for the a.out object file format. It is not +normally used for any other object file format. -@noindent -@samp{ld -M -T sample.ld a.o b.o c.o d.o} would create a map like this, -containing symbols matching the object file names: -@smallexample -00000000 A __DYNAMIC -00004020 B _abss -00004000 D _adata -00002020 T _afunction -00004024 B _bbss -00004008 D _bdata -00002038 T _bfunction -00004028 B _cbss -00004010 D _cdata -00002050 T _cfunction -0000402c B _dbss -00004018 D _ddata -00002068 T _dfunction -00004020 D _edata -00004030 B _end -00004000 T _etext -00002020 t a.o -00002038 t b.o -00002050 t c.o -00002068 t d.o -@end smallexample +@kindex CONSTRUCTORS +@cindex C++ constructors, arranging in link +@cindex constructors, arranging in link +@item CONSTRUCTORS +When linking using the a.out object file format, the linker uses an +unusual set construct to support C++ global constructors and +destructors. When linking object file formats which do not support +arbitrary sections, such as ECOFF and XCOFF, the linker will +automatically recognize C++ global constructors and destructors by name. +For these object file formats, the @code{CONSTRUCTORS} command tells the +linker to place constructor information in the output section where the +@code{CONSTRUCTORS} command appears. The @code{CONSTRUCTORS} command is +ignored for other object file formats. -@kindex @var{symbol} = @var{expression} ; -@kindex @var{symbol} @var{f}= @var{expression} ; -@item @var{symbol} = @var{expression} ; -@itemx @var{symbol} @var{f}= @var{expression} ; -@var{symbol} is any symbol name (@pxref{Symbols}). ``@var{f}='' -refers to any of the operators @code{&= += -= *= /=} which combine -arithmetic and assignment. +The symbol @w{@code{__CTOR_LIST__}} marks the start of the global +constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. 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 +formats @sc{gnu} C++ normally calls constructors from a subroutine +@code{__main}; a call to @code{__main} is automatically inserted into +the startup code for @code{main}. @sc{gnu} C++ normally runs +destructors either by using @code{atexit}, or directly from the function +@code{exit}. -@cindex assignment, in section defn -When you assign a value to a symbol within a particular section -definition, the value is relative to the beginning of the section -(@pxref{Assignment}). If you write +For object file formats such as @code{COFF} or @code{ELF} which support +arbitrary section names, @sc{gnu} C++ will normally arrange to put the +addresses of global constructors and destructors into the @code{.ctors} +and @code{.dtors} sections. Placing the following sequence into your +linker script will build the sort of table which the @sc{gnu} C++ +runtime code expects to see. @smallexample -@group -SECTIONS @{ - abs = 14 ; - @dots{} - .data : @{ @dots{} rel = 14 ; @dots{} @} - abs2 = 14 + ADDR(.data); - @dots{} -@} -@end group + __CTOR_LIST__ = .; + LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) + *(.ctors) + LONG(0) + __CTOR_END__ = .; + __DTOR_LIST__ = .; + LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) + *(.dtors) + LONG(0) + __DTOR_END__ = .; @end smallexample -@c FIXME: Try above example! -@noindent -@code{abs} and @code{rel} do not have the same value; @code{rel} has the -same value as @code{abs2}. - -@kindex BYTE(@var{expression}) -@kindex SHORT(@var{expression}) -@kindex LONG(@var{expression}) -@kindex QUAD(@var{expression}) -@kindex SQUAD(@var{expression}) -@cindex direct output -@item BYTE(@var{expression}) -@itemx SHORT(@var{expression}) -@itemx LONG(@var{expression}) -@itemx QUAD(@var{expression}) -@itemx SQUAD(@var{expression}) -By including one of these four statements in a section definition, you -can explicitly place one, two, four, eight unsigned, or eight signed -bytes (respectively) at the current address of that section. When using -a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the same. -When both host and target are 32 bits, @code{QUAD} uses an unsigned 32 -bit value, and @code{SQUAD} sign extends the value. Both will use the -correct endianness when writing out the value. - -@ifclear SingleFormat -Multiple-byte quantities are represented in whatever byte order is -appropriate for the output file format (@pxref{BFD}). -@end ifclear - -@kindex FILL(@var{expression}) -@cindex holes, filling -@cindex unspecified memory -@item FILL(@var{expression}) -Specify the ``fill pattern'' for the current section. Any otherwise -unspecified regions of memory within the section (for example, regions -you skip over by assigning a new value to the location counter @samp{.}) -are filled with the two least significant bytes from the -@var{expression} argument. A @code{FILL} statement covers memory -locations @emph{after} the point it occurs in the section definition; by -including more than one @code{FILL} statement, you can have different -fill patterns in different parts of an output section. +Normally the compiler and linker will handle these issues automatically, +and you will not need to concern yourself with them. However, you may +need to consider this if you are using C++ and writing your own linker +scripts. @end table -@node Section Options -@subsection Optional Section Attributes -@cindex section defn, full syntax -Here is the full syntax of a section definition, including all the -optional portions: - +@node Output Section Discarding +@subsection Output section discarding +@cindex discarding sections +@cindex sections, discarding +@cindex removing sections +The linker will not create output section which do not have any +contents. This is for convenience when referring to input sections that +may or may not be present in any of the input files. For example: @smallexample -@group -SECTIONS @{ -@dots{} -@var{secname} @var{start} BLOCK(@var{align}) (NOLOAD) : AT ( @var{ldadr} ) - @{ @var{contents} @} >@var{region} :@var{phdr} =@var{fill} -@dots{} -@} -@end group +.foo @{ *(.foo) @} @end smallexample +@noindent +will only create a @samp{.foo} section in the output file if there is a +@samp{.foo} section in at least one input file. -@var{secname} and @var{contents} are required. @xref{Section -Definition}, and @ref{Section Placement}, for details on -@var{contents}. The remaining elements---@var{start}, -@code{BLOCK(@var{align)}}, @code{(NOLOAD)}, @code{AT ( @var{ldadr} )}, -@code{>@var{region}}, @code{:@var{phdr}}, and @code{=@var{fill}}---are -all optional. +If you use anything other than an input section description as an output +section command, such as a symbol assignment, then the output section +will always be created, even if there are no matching input sections. -@table @code -@cindex start address, section -@cindex section start -@cindex section address -@item @var{start} -You can force the output section to be loaded at a specified address by -specifying @var{start} immediately following the section name. -@var{start} can be represented as any expression. The following -example generates section @var{output} at location -@code{0x40000000}: +The special output section name @samp{/DISCARD/} may be used to discard +input sections. Any input sections which are assigned to an output +section named @samp{/DISCARD/} are not included in the output file. +@node Output Section Attributes +@subsection Output section attributes +@cindex output section attributes +We showed above that the full description of an output section looked +like this: @smallexample -@group -SECTIONS @{ - @dots{} - output 0x40000000: @{ +@group +@var{section} [@var{address}] [(@var{type})] : [AT(@var{lma})] + @{ + @var{output-section-command} + @var{output-section-command} @dots{} - @} - @dots{} -@} + @} [>@var{region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] @end group @end smallexample +We've already described @var{section}, @var{address}, and +@var{output-section-command}. In this section we will describe the +remaining section attributes. + +@menu +* Output Section Type:: Output section type +* Output Section LMA:: Output section LMA +* Output Section Region:: Output section region +* Output Section Phdr:: Output section phdr +* Output Section Fill:: Output section fill +@end menu -@kindex BLOCK(@var{align}) -@cindex section alignment -@cindex aligning sections -@item BLOCK(@var{align}) -You can include @code{BLOCK()} specification to advance -the location counter @code{.} prior to the beginning of the section, so -that the section will begin at the specified alignment. @var{align} is -an expression. +@node Output Section Type +@subsubsection Output section type +Each output section may have a type. The type is a keyword in +parentheses. The following types are defined: + +@table @code +@item NOLOAD +The section should be marked as not loadable, so that it will not be +loaded into memory when the program is run. +@item DSECT +@itemx COPY +@itemx INFO +@itemx OVERLAY +These type names are supported for backward compatibility, and are +rarely used. They all have the same effect: the section should be +marked as not allocatable, so that no memory is allocated for the +section when the program is run. +@end table @kindex NOLOAD @cindex prevent unnecessary loading @cindex loading, preventing -@item (NOLOAD) -The @samp{(NOLOAD)} directive will mark a section to not be loaded at -run time. The linker will process the section normally, but will mark -it so that a program loader will not load it into memory. For example, -in the script sample below, the @code{ROM} section is addressed at -memory location @samp{0} and does not need to be loaded when the program -is run. The contents of the @code{ROM} section will appear in the -linker output file as usual. - +The linker normally sets the attributes of an output section based on +the input sections which map into it. You can override this by using +the section type. For example, in the script sample below, the +@samp{ROM} section is addressed at memory location @samp{0} and does not +need to be loaded when the program is run. The contents of the +@samp{ROM} section will appear in the linker output file as usual. @smallexample @group SECTIONS @{ - ROM 0 (NOLOAD) : @{ @dots{} @} + ROM 0 (NOLOAD) : @{ @dots{} @} @dots{} @} @end group @end smallexample -@kindex AT ( @var{ldadr} ) -@cindex specify load address -@cindex load address, specifying -@item AT ( @var{ldadr} ) -The expression @var{ldadr} that follows the @code{AT} keyword specifies -the load address of the section. The default (if you do not use the -@code{AT} keyword) is to make the load address the same as the -relocation address. This feature is designed to make it easy to build a -ROM image. For example, this @code{SECTIONS} definition creates two -output sections: one called @samp{.text}, which starts at @code{0x1000}, -and one called @samp{.mdata}, which is loaded at the end of the -@samp{.text} section even though its relocation address is -@code{0x2000}. The symbol @code{_data} is defined with the value -@code{0x2000}: +@node Output Section LMA +@subsubsection Output section LMA +@kindex AT(@var{lma}) +@cindex load address +@cindex section load address +Every section has a virtual address (VMA) and a load address (LMA); see +@ref{Basic Script Concepts}. The address expression which may appear in +an output section description sets the VMA (@pxref{Output Section +Address}). + +The linker will normally set the LMA equal to the VMA. You can change +that by using the @code{AT} keyword. The expression @var{lma} that +follows the @code{AT} keyword specifies the load address of the section. + +@cindex ROM initialized data +@cindex initialized data in ROM +This feature is designed to make it easy to build a ROM image. For +example, the following linker script creates three output sections: one +called @samp{.text}, which starts at @code{0x1000}, one called +@samp{.mdata}, which is loaded at the end of the @samp{.text} section +even though its VMA is @code{0x2000}, and one called @samp{.bss} to hold +uninitialized data at address @code{0x3000}. The symbol @code{_data} is +defined with the value @code{0x2000}, which shows that the location +counter holds the VMA value, not the LMA value. @smallexample @group @@ -2464,7 +2387,7 @@ SECTIONS @{ .text 0x1000 : @{ *(.text) _etext = . ; @} .mdata 0x2000 : - AT ( ADDR(.text) + SIZEOF ( .text ) ) + AT ( ADDR (.text) + SIZEOF (.text) ) @{ _data = . ; *(.data); _edata = . ; @} .bss 0x3000 : @{ _bstart = . ; *(.bss) *(COMMON) ; _bend = . ;@} @@ -2472,82 +2395,121 @@ SECTIONS @end group @end smallexample -The run-time initialization code (for C programs, usually @code{crt0}) -for use with a ROM generated this way has to include something like -the following, to copy the initialized data from the ROM image to its runtime -address: +The run-time initialization code for use with a program generated with +this linker script would include something like the following, to copy +the initialized data from the ROM image to its runtime address. Notice +how this code takes advantage of the symbols defined by the linker +script. @smallexample @group -char *src = _etext; -char *dst = _data; +extern char _etext, _data, _edata, _bstart, _bend; +char *src = &_etext; +char *dst = &_data; /* ROM has data at end of text; copy it. */ -while (dst < _edata) @{ +while (dst < &_edata) @{ *dst++ = *src++; @} /* Zero bss */ -for (dst = _bstart; dst< _bend; dst++) +for (dst = &_bstart; dst< &_bend; dst++) *dst = 0; @end group @end smallexample +@node Output Section Region +@subsubsection Output section region @kindex >@var{region} @cindex section, assigning to memory region @cindex memory regions and sections -@item >@var{region} -Assign this section to a previously defined region of memory. -@xref{MEMORY}. +You can assign a section to a previously defined region of memory by +using @samp{>@var{region}}. @xref{MEMORY}. + +Here is a simple example: +@smallexample +@group +MEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @} +SECTIONS @{ ROM : @{ *(.text) @} >rom @} +@end group +@end smallexample +@node Output Section Phdr +@subsubsection Output section phdr @kindex :@var{phdr} @cindex section, assigning to program header @cindex program headers and sections -@item :@var{phdr} -Assign this section to a segment described by a program header. -@xref{PHDRS}. If a section is assigned to one or more segments, then -all subsequent allocated sections will be assigned to those segments as -well, unless they use an explicitly @code{:@var{phdr}} modifier. To -prevent a section from being assigned to a segment when it would -normally default to one, use @code{:NONE}. - -@kindex =@var{fill} +You can assign a section to a previously defined program segment by +using @samp{:@var{phdr}}. @xref{PHDRS}. If a section is assigned to +one or more segments, then all subsequent allocated sections will be +assigned to those segments as well, unless they use an explicitly +@code{:@var{phdr}} modifier. To prevent a section from being assigned +to a segment when it would normally default to one, use @code{:NONE}. + +Here is a simple example: +@smallexample +@group +PHDRS @{ text PT_LOAD ; @} +SECTIONS @{ .text : @{ *(.text) @} :text @} +@end group +@end smallexample + +@node Output Section Fill +@subsubsection Output section fill +@kindex =@var{fillexp} @cindex section fill pattern @cindex fill pattern, entire section -@item =@var{fill} -Including @code{=@var{fill}} in a section definition specifies the -initial fill value for that section. You may use any expression to -specify @var{fill}. Any unallocated holes in the current output section -when written to the output file will be filled with the two least -significant bytes of the value, repeated as necessary. You can also -change the fill value with a @code{FILL} statement in the @var{contents} -of a section definition. +You can set the fill pattern for an entire section by using +@samp{=@var{fillexp}}. @var{fillexp} is an expression +(@pxref{Expressions}). Any otherwise unspecified regions of memory +within the output section (for example, gaps left due to the required +alignment of input sections) will be filled with the two least +significant bytes of the value, repeated as necessary. -@end table +You can also change the fill value with a @code{FILL} command in the +output section commands; see @ref{Output Section Data}. -@node Overlays -@subsection Overlays +Here is a simple example: +@smallexample +@group +SECTIONS @{ .text : @{ *(.text) @} =0x9090 @} +@end group +@end smallexample + +@node Overlay Description +@subsection Overlay description @kindex OVERLAY @cindex overlays - -The @code{OVERLAY} command provides an easy way to describe sections -which are to be loaded as part of a single memory image but are to be -run at the same memory address. At run time, some sort of overlay -manager will copy the overlaid sections in and out of the runtime memory -address as required, perhaps by simply manipulating addressing bits. -This approach can be useful, for example, when a certain region of -memory is faster than another. - -The @code{OVERLAY} command is used within a @code{SECTIONS} command. It -appears as follows: +An overlay description provides an easy way to describe sections which +are to be loaded as part of a single memory image but are to be run at +the same memory address. At run time, some sort of overlay manager will +copy the overlaid sections in and out of the runtime memory address as +required, perhaps by simply manipulating addressing bits. This approach +can be useful, for example, when a certain region of memory is faster +than another. + +Overlays are described using the @code{OVERLAY} command. The +@code{OVERLAY} command is used within a @code{SECTIONS} command, like an +output section description. The full syntax of the @code{OVERLAY} +command is as follows: @smallexample @group - OVERLAY @var{start} : [ NOCROSSREFS ] AT ( @var{ldaddr} ) - @{ - @var{secname1} @{ @var{contents} @} :@var{phdr} =@var{fill} - @var{secname2} @{ @var{contents} @} :@var{phdr} =@var{fill} - @dots{} - @} >@var{region} :@var{phdr} =@var{fill} +OVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )] + @{ + @var{secname1} + @{ + @var{output-section-command} + @var{output-section-command} + @dots{} + @} [:@var{phdr}@dots{}] [=@var{fill}] + @var{secname2} + @{ + @var{output-section-command} + @var{output-section-command} + @dots{} + @} [:@var{phdr}@dots{}] [=@var{fill}] + @dots{} + @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] @end group @end smallexample @@ -2563,12 +2525,12 @@ addresses of the sections are arranged such that they are consecutive in memory starting at the load address used for the @code{OVERLAY} as a whole (as with normal section definitions, the load address is optional, and defaults to the start address; the start address is also optional, -and defaults to @code{.}). +and defaults to the current value of the location counter). If the @code{NOCROSSREFS} keyword is used, and there any references among the sections, the linker will report an error. Since the sections all run at the same address, it normally does not make sense for one -section to refer directly to another. @xref{Option Commands, +section to refer directly to another. @xref{Miscellaneous Commands, NOCROSSREFS}. For each section within the @code{OVERLAY}, the linker automatically @@ -2579,12 +2541,11 @@ the section. Any characters within @var{secname} which are not legal within C identifiers are removed. C (or assembler) code may use these symbols to move the overlaid sections around as necessary. -At the end of the overlay, the value of @code{.} is set to the start -address of the overlay plus the size of the largest section. +At the end of the overlay, the value of the location counter is set to +the start address of the overlay plus the size of the largest section. Here is an example. Remember that this would appear inside a @code{SECTIONS} construct. - @smallexample @group OVERLAY 0x1000 : AT (0x4000) @@ -2594,10 +2555,10 @@ Here is an example. Remember that this would appear inside a @} @end group @end smallexample - -This will define both @code{.text0} and @code{.text1} to start at -address 0x1000. @code{.text0} will be loaded at address 0x4000, and -@code{.text1} will be loaded immediately after @code{.text0}. The +@noindent +This will define both @samp{.text0} and @samp{.text1} to start at +address 0x1000. @samp{.text0} will be loaded at address 0x4000, and +@samp{.text1} will be loaded immediately after @samp{.text0}. The following symbols will be defined: @code{__load_start_text0}, @code{__load_stop_text0}, @code{__load_start_text1}, @code{__load_stop_text1}. @@ -2629,27 +2590,148 @@ example could have been written identically as follows. @end group @end smallexample +@node MEMORY +@section MEMORY command +@kindex MEMORY +@cindex memory regions +@cindex regions of memory +@cindex allocating memory +@cindex discontinuous memory +The linker's default configuration permits allocation of all available +memory. You can override this by using the @code{MEMORY} command. + +The @code{MEMORY} command describes the location and size of blocks of +memory in the target. You can use it to describe which memory regions +may be used by the linker, and which memory regions it must avoid. You +can then assign sections to particular memory regions. The linker will +set section addresses based on the memory regions, and will warn about +regions that become too full. The linker will not shuffle sections +around to fit into the available regions. + +A linker script may contain at most one use of the @code{MEMORY} +command. However, you can define as many blocks of memory within it as +you wish. The syntax is: +@smallexample +@group +MEMORY + @{ + @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len} + @dots{} + @} +@end group +@end smallexample + +The @var{name} is a name used in the linker script to refer to the +region. The region name has no meaning outside of the linker script. +Region names are stored in a separate name space, and will not conflict +with symbol names, file names, or section names. Each memory region +must have a distinct name. + +@cindex memory region attributes +The @var{attr} string is an optional list of attributes that specify +whether to use a particular memory region for an input section which is +not explicitly mapped in the linker script. As described in +@ref{SECTIONS}, if you do not specify an output section for some input +section, the linker will create an output section with the same name as +the input section. If you define region attributes, the linker will use +them to select the memory region for the output section that it creates. + +The @var{attr} string must consist only of the following characters: +@table @samp +@item R +Read-only section +@item W +Read/write section +@item X +Executable section +@item A +Allocatable section +@item I +Initialized section +@item L +Same as @samp{I} +@item ! +Invert the sense of any of the preceding attributes +@end table + +If a unmapped section matches any of the listed attributes other than +@samp{!}, it will be placed in the memory region. The @samp{!} +attribute reverses this test, so that an unmapped section will be placed +in the memory region only if it does not match any of the listed +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}). + +@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}. + +In the following example, we specify that there are two memory regions +available for allocation: one starting at @samp{0} for 256 kilobytes, +and the other starting at @samp{0x40000000} for four megabytes. The +linker will place into the @samp{rom} memory region every section which +is not explicitly mapped into a memory region, and is either read-only +or executable. The linker will place other sections which are not +explicitly mapped into a memory region into the @samp{ram} memory +region. + +@smallexample +@group +MEMORY + @{ + rom (rx) : ORIGIN = 0, LENGTH = 256K + ram (!rx) : org = 0x40000000, l = 4M + @} +@end group +@end smallexample + +If you have defined a memory region named @samp{mem}, you can direct the +linker to place specific output sections into that memory region by +using the @samp{>@var{region}} output section attribute. @xref{Output +Section Region}. If no address was specified for the output section, +the linker will set the address to 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. + @node PHDRS -@section ELF Program Headers +@section PHDRS Command @kindex PHDRS @cindex program headers @cindex ELF program headers - -The ELF object file format uses @dfn{program headers}, which are read by -the system loader and describe how the program should be loaded into -memory. These program headers must be set correctly in order to run the -program on a native ELF system. The linker will create reasonable -program headers by default. However, in some cases, it is desirable to -specify the program headers more precisely; the @code{PHDRS} command may -be used for this purpose. When the @code{PHDRS} command is used, the -linker will not generate any program headers itself. - -The @code{PHDRS} command is only meaningful when generating an ELF -output file. It is ignored in other cases. This manual does not -describe the details of how the system loader interprets program -headers; for more information, see the ELF ABI. The program headers of -an ELF file may be displayed using the @samp{-p} option of the -@code{objdump} command. +@cindex program segments +@cindex segments, ELF +The ELF object file format uses @dfn{program headers}, also knows as +@dfn{segments}. The program headers describe how the program should be +loaded into memory. You can print them out by using the @code{objdump} +program with the @samp{-p} option. + +When you run an ELF program on a native ELF system, the system loader +reads the program headers in order to figure out how to load the +program. This will only work if the program headers are set correctly. +This manual does not describe the details of how the system loader +interprets program headers; for more information, see the ELF ABI. + +The linker will create reasonable program headers by default. However, +in some cases, you may need to specify the program headers more +precisely. You may use the @code{PHDRS} command for this purpose. When +the linker sees the @code{PHDRS} command in the linker script, it will +not create any program headers other than the ones specified. + +The linker only pays attention to the @code{PHDRS} command when +generating an ELF output file. In other cases, the linker will simply +ignore @code{PHDRS}. This is the syntax of the @code{PHDRS} command. The words @code{PHDRS}, @code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords. @@ -2665,30 +2747,34 @@ PHDRS @end smallexample The @var{name} is used only for reference in the @code{SECTIONS} command -of the linker script. It does not get put into the output file. - -Certain program header types describe segments of memory which are -loaded from the file by the system loader. In the linker script, the -contents of these segments are specified by directing allocated output -sections to be placed in the segment. To do this, the command -describing the output section in the @code{SECTIONS} command should use -@samp{:@var{name}}, where @var{name} is the name of the program header -as it appears in the @code{PHDRS} command. @xref{Section Options}. - -It is normal for certain sections to appear in more than one segment. -This merely implies that one segment of memory contains another. This -is specified by repeating @samp{:@var{name}}, using it once for each -program header in which the section is to appear. - -If a section is placed in one or more segments using @samp{:@var{name}}, -then all subsequent allocated sections which do not specify -@samp{:@var{name}} are placed in the same segments. This is for +of the linker script. It is not put into the output file. Program +header names are stored in a separate name space, and will not conflict +with symbol names, file names, or section names. Each program header +must have a distinct name. + +Certain program header types describe segments of memory which the +system loader will load from the file. In the linker script, you +specify the contents of these segments by placing allocatable output +sections in the segments. You use the @samp{:@var{phdr}} output section +attribute to place a section in a particular segment. @xref{Output +Section Phdr}. + +It is normal to put certain sections in more than one segment. This +merely implies that one segment of memory contains another. You may +repeat @samp{:@var{phdr}}, using it once for each segment which should +contain the section. + +If you place a section in one or more segments using @samp{:@var{phdr}}, +then the linker will place all subsequent allocatable sections which do +not specify @samp{:@var{phdr}} in the same segments. This is for convenience, since generally a whole set of contiguous sections will be placed in a single segment. To prevent a section from being assigned to a segment when it would normally default to one, use @code{:NONE}. -The @code{FILEHDR} and @code{PHDRS} keywords which may appear after the -program header type also indicate contents of the segment of memory. +@kindex FILEHDR +@kindex PHDRS +You may use the @code{FILEHDR} and @code{PHDRS} keywords appear after +the program header type to further describe the contents of the segment. The @code{FILEHDR} keyword means that the segment should include the ELF file header. The @code{PHDRS} keyword means that the segment should include the ELF program headers themselves. @@ -2726,20 +2812,20 @@ An expression giving the numeric type of the program header. This may be used for types not defined above. @end table -It is possible to specify that a segment should be loaded at a -particular address in memory. This is done using an @code{AT} -expression. This is identical to the @code{AT} command used in the -@code{SECTIONS} command (@pxref{Section Options}). Using the @code{AT} -command for a program header overrides any information in the -@code{SECTIONS} command. +You can specify that a segment should be loaded at a particular address +in memory by using an @code{AT} expression. This is identical to the +@code{AT} command used as an output section attribute (@pxref{Output +Section LMA}). The @code{AT} command for a program header overrides the +output section attribute. -Normally the segment flags are set based on the sections. The -@code{FLAGS} keyword may be used to explicitly specify the segment -flags. The value of @var{flags} must be an integer. It is used to -set the @code{p_flags} field of the program header. +The linker will normally set the segment flags based on the sections +which comprise the segment. You may use the @code{FLAGS} keyword to +explicitly specify the segment flags. The value of @var{flags} must be +an integer. It is used to set the @code{p_flags} field of the program +header. -Here is an example of the use of @code{PHDRS}. This shows a typical set -of program headers used on a native ELF system. +Here is an example of @code{PHDRS}. This shows a typical set of program +headers used on a native ELF system. @example @group @@ -2767,84 +2853,33 @@ SECTIONS @end group @end example -@node Entry Point -@section The Entry Point -@kindex ENTRY(@var{symbol}) -@cindex start of execution -@cindex first instruction -The linker command language includes a command specifically for -defining the first executable instruction in an output file (its -@dfn{entry point}). Its argument is a symbol name: -@smallexample -ENTRY(@var{symbol}) -@end smallexample - -Like symbol assignments, the @code{ENTRY} command may be placed either -as an independent command in the command file, or among the section -definitions within the @code{SECTIONS} command---whatever makes the most -sense for your layout. - -@cindex entry point, defaults -@code{ENTRY} is only one of several ways of choosing the entry point. -You may indicate it in any of the following ways (shown in descending -order of priority: methods higher in the list override methods lower down). -@itemize @bullet -@item -the @samp{-e} @var{entry} command-line option; -@item -the @code{ENTRY(@var{symbol})} command in a linker control script; -@item -the value of the symbol @code{start}, if present; -@item -the address of the first byte of the @code{.text} section, if present; -@item -The address @code{0}. -@end itemize - -For example, you can use these rules to generate an entry point with an -assignment statement: if no symbol @code{start} is defined within your -input files, you can simply define it, assigning it an appropriate -value--- - -@smallexample -start = 0x2020; -@end smallexample - -@noindent -The example shows an absolute address, but you can use any expression. -For example, if your input object files use some other symbol-name -convention for the entry point, you can just assign the value of -whatever symbol contains the start address to @code{start}: - -@smallexample -start = other_symbol ; -@end smallexample - -@node Version Script -@section Version Script +@node VERSION +@section VERSION Command @kindex VERSION @{script text@} @cindex symbol versions @cindex version script @cindex versions of symbols -The linker command script includes a command specifically for -specifying a version script, and is only meaningful for ELF platforms -that support shared libraries. A version script can be -build directly into the linker script that you are using, or you -can supply the version script as just another input file to the linker -at the time that you link. The command script syntax is: +The linker supports symbol versions when using ELF. Symbol versions are +only useful when using shared libraries. The dynamic linker can use +symbol versions to select a specific version of a function when it runs +a program that may have been linked against an earlier version of the +shared library. + +You can include a version script directly in the main linker script, or +you can supply the version script as an implicit linker script. You can +also use the @samp{--version-script} linker option. + +The syntax of the @code{VERSION} command is simply @smallexample -VERSION @{ version script contents @} +VERSION @{ version-script-commands @} @end smallexample -The version script can also be specified to the linker by means of the -@samp{--version-script} linker command line option. -Version scripts are only meaningful when creating shared libraries. - -The format of the version script itself is identical to that used by -Sun's linker in Solaris 2.5. Versioning is done by defining a tree of -version nodes with the names and interdependencies specified in the -version script. The version script can specify which symbols are bound -to which version nodes, and it can reduce a specified set of symbols to -local scope so that they are not globally visible outside of the shared + +The format of the version script commands is identical to that used by +Sun's linker in Solaris 2.5. The version script defines a tree of +version nodes. You specify the node names and interdependencies in the +version script. You can specify which symbols are bound to which +version nodes, and you can reduce a specified set of symbols to local +scope so that they are not globally visible outside of the shared library. The easiest way to demonstrate the version script language is with a few @@ -2869,40 +2904,41 @@ VERS_2.0 @{ @} VERS_1.2; @end smallexample -In this example, three version nodes are defined. @samp{VERS_1.1} is the -first version node defined, and has no other dependencies. The symbol -@samp{foo1} is bound to this version node, and a number of symbols -that have appeared within various object files are reduced in scope to -local so that they are not visible outside of the shared library. +This example version script defines three version nodes. The first +version node defined is @samp{VERS_1.1}; it has no other dependencies. +The script binds the symbol @samp{foo1} to @samp{VERS_1.1}. It reduces +a number of symbols to local scope so that they are not visible outside +of the shared library. -Next, the node @samp{VERS_1.2} is defined. It depends upon -@samp{VERS_1.1}. The symbol @samp{foo2} is bound to this version node. +Next, the version script defines node @samp{VERS_1.2}. This node +depends upon @samp{VERS_1.1}. The script binds the symbol @samp{foo2} +to the version node @samp{VERS_1.2}. -Finally, the node @samp{VERS_2.0} is defined. It depends upon -@samp{VERS_1.2}. The symbols @samp{bar1} and @samp{bar2} are bound to -this version node. +Finally, the version script defines node @samp{VERS_2.0}. This node +depends upon @samp{VERS_1.2}. The scripts binds the symbols @samp{bar1} +and @samp{bar2} are bound to the version node @samp{VERS_2.0}. -Symbols defined in the library which aren't specifically bound to a -version node are effectively bound to an unspecified base version of the -library. It is possible to bind all otherwise unspecified symbols to a -given version node using @samp{global: *} somewhere in the version -script. +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. -Lexically 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 could just as well have appeared in between @samp{1.1} and -@samp{1.2}. However, this would be a confusing way to write a version -script. +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 +could just as well have appeared in between @samp{1.1} and @samp{1.2}. +However, this would be a confusing way to write a version script. When you link an application against a shared library that has versioned -symbols, the application itself knows which version of each symbol it requires, -and it also knows which version nodes it needs from each shared library it is -linked against. Thus at runtime, the dynamic loader can make a quick check to -make sure that the libraries you have linked against do in fact supply all -of the version nodes that the application will need to resolve all of the -dynamic symbols. In this way it is possible for the dynamic linker to know -with certainty that all external symbols that it needs will be resolvable -without having to search for each symbol reference. +symbols, the application itself knows which version of each symbol it +requires, and it also knows which version nodes it needs from each +shared library it is linked against. Thus at runtime, the dynamic +loader can make a quick check to make sure that the libraries you have +linked against do in fact supply all of the version nodes that the +application will need to resolve all of the dynamic symbols. In this +way it is possible for the dynamic linker to know with certainty that +all external symbols that it needs will be resolvable without having to +search for each symbol reference. The symbol versioning is in effect a much more sophisticated way of doing minor version checking that SunOS does. The fundamental problem @@ -2918,25 +2954,24 @@ There are several GNU extensions to Sun's versioning approach. The first of these is the ability to bind a symbol to a version node in the source file where the symbol is defined instead of in the versioning script. This was done mainly to reduce the burden on the library -maintainer. This can be done by putting something like: - +maintainer. You can do this by putting something like: @smallexample __asm__(".symver original_foo,foo@@VERS_1.1"); @end smallexample - -in the C source file. This renamed the function @samp{original_foo} to +@noindent +in the C source file. This renames the function @samp{original_foo} to be an alias for @samp{foo} bound to the version node @samp{VERS_1.1}. The @samp{local:} directive can be used to prevent the symbol @samp{original_foo} from being exported. -The second GNU extension is to allow multiple versions of the same function -to appear in a given shared library. In this way an incompatible change to -an interface can take place without increasing the major version number of -the shared library, while still allowing applications linked against the old -interface to continue to function. +The second GNU extension is to allow multiple versions of the same +function to appear in a given shared library. In this way you can make +an incompatible change to an interface without increasing the major +version number of the shared library, while still allowing applications +linked against the old interface to continue to function. -This can only be accomplished by using multiple @samp{.symver} -directives in the assembler. An example of this would be: +To do this, you must use multiple @samp{.symver} directives in the +source file. Here is an example: @smallexample __asm__(".symver original_foo,foo@@"); @@ -2952,212 +2987,448 @@ example would define 4 C functions: @samp{original_foo}, @samp{old_foo}, When you have multiple definitions of a given symbol, there needs to be some way to specify a default version to which external references to -this symbol will be bound. This can be accomplished with the -@samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. Only one version of -a symbol can be declared 'default' in this manner - otherwise you would -effectively have multiple definitions of the same symbol. +this symbol will be bound. You can do this with the +@samp{foo@@@@VERS_2.0} type of @samp{.symver} directive. You can only +declare one version of a symbol as the default in this manner; otherwise +you would effectively have multiple definitions of the same symbol. If you wish to bind a reference to a specific version of the symbol within the shared library, you can use the aliases of convenience (i.e. @samp{old_foo}), or you can use the @samp{.symver} directive to specifically bind to an external version of the function in question. -@node Option Commands -@section Option Commands -The command language includes a number of other commands that you can -use for specialized purposes. They are similar in purpose to -command-line options. +@node Expressions +@section Expressions in Linker Scripts +@cindex expressions +@cindex arithmetic +The syntax for expressions in the linker script language is identical to +that of C expressions. All expressions are evaluated as integers. All +expressions are evaluated in the same size, which is 32 bits if both the +host and target are 32 bits, and is otherwise 64 bits. -@table @code -@kindex CONSTRUCTORS -@cindex C++ constructors, arranging in link -@cindex constructors, arranging in link -@item CONSTRUCTORS -When linking using the @code{a.out} object file format, the linker uses -an unusual set construct to support C++ global constructors and -destructors. When linking object file formats which do not support -arbitrary sections, such as @code{ECOFF} and @code{XCOFF}, the linker -will automatically recognize C++ global constructors and destructors by -name. For these object file formats, the @code{CONSTRUCTORS} command -tells the linker where this information should be placed. The -@code{CONSTRUCTORS} command is ignored for other object file formats. +You can use and set symbol values in expressions. -The symbol @w{@code{__CTOR_LIST__}} marks the start of the global -constructors, and the symbol @w{@code{__DTOR_LIST}} marks the end. 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 -formats @sc{gnu} C++ calls constructors from a subroutine @code{__main}; -a call to @code{__main} is automatically inserted into the startup code -for @code{main}. @sc{gnu} C++ runs destructors either by using -@code{atexit}, or directly from the function @code{exit}. +The linker defines several special purpose builtin functions for use in +expressions. -For object file formats such as @code{COFF} or @code{ELF} which support -multiple sections, @sc{gnu} C++ will normally arrange to put the -addresses of global constructors and destructors into the @code{.ctors} -and @code{.dtors} sections. Placing the following sequence into your -linker script will build the sort of table which the @sc{gnu} C++ -runtime code expects to see. +@menu +* Constants:: Constants +* Symbols:: Symbol Names +* Location Counter:: The Location Counter +* Operators:: Operators +* Evaluation:: Evaluation +* Expression Section:: The Section of an Expression +* Builtin Functions:: Builtin Functions +@end menu +@node Constants +@subsection Constants +@cindex integer notation +@cindex constants in linker scripts +All constants are integers. + +As in C, the linker considers an integer beginning with @samp{0} to be +octal, and an integer beginning with @samp{0x} or @samp{0X} to be +hexadecimal. The linker considers other integers to be decimal. + +@cindex scaled integers +@cindex K and M integer suffixes +@cindex M and K integer suffixes +@cindex suffixes for integers +@cindex integer suffixes +In addition, you can use the suffixes @code{K} and @code{M} to scale a +constant by +@c TEXI2ROFF-KILL +@ifinfo +@c END TEXI2ROFF-KILL +@code{1024} or @code{1024*1024} +@c TEXI2ROFF-KILL +@end ifinfo +@tex +${\rm 1024}$ or ${\rm 1024}^2$ +@end tex +@c END TEXI2ROFF-KILL +respectively. For example, the following all refer to the same quantity: @smallexample - __CTOR_LIST__ = .; - LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) - *(.ctors) - LONG(0) - __CTOR_END__ = .; - __DTOR_LIST__ = .; - LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2) - *(.dtors) - LONG(0) - __DTOR_END__ = .; + _fourk_1 = 4K; + _fourk_2 = 4096; + _fourk_3 = 0x1000; @end smallexample -Normally the compiler and linker will handle these issues automatically, -and you will not need to concern yourself with them. However, you may -need to consider this if you are using C++ and writing your own linker -scripts. +@node Symbols +@subsection Symbol Names +@cindex symbol names +@cindex names +@cindex quoted symbol names +@kindex " +Unless quoted, symbol names start with a letter, underscore, or period +and may include letters, digits, underscores, periods, and hyphens. +Unquoted symbol names must not conflict with any keywords. You can +specify a symbol which contains odd characters or has the same name as a +keyword by surrounding the symbol name in double quotes: +@smallexample + "SECTION" = 9; + "with a space" = "also with a space" + 10; +@end smallexample -@need 1000 -@kindex FLOAT -@kindex NOFLOAT -@item FLOAT -@itemx NOFLOAT -These keywords were used in some older linkers to request a particular -math subroutine library. @code{ld} doesn't use the keywords, assuming -instead that any necessary subroutines are in libraries specified using -the general mechanisms for linking to archives; but to permit the use of -scripts that were written for the older linkers, the keywords -@code{FLOAT} and @code{NOFLOAT} are accepted and ignored. +Since symbols can contain many non-alphabetic characters, it is safest +to delimit symbols with spaces. For example, @samp{A-B} is one symbol, +whereas @samp{A - B} is an expression involving subtraction. -@kindex FORCE_COMMON_ALLOCATION -@cindex common allocation -@item FORCE_COMMON_ALLOCATION -This command has the same effect as the @samp{-d} command-line option: -to make @code{ld} assign space to common symbols even if a relocatable -output file is specified (@samp{-r}). +@node Location Counter +@subsection The Location Counter +@kindex . +@cindex dot +@cindex location counter +@cindex current output location +The special linker variable @dfn{dot} @samp{.} always contains the +current output location counter. Since the @code{.} always refers to a +location in an output section, it may only appear in an expression +within a @code{SECTIONS} command. The @code{.} symbol may appear +anywhere that an ordinary symbol is allowed in an expression. -@kindex INCLUDE @var{filename} -@cindex including a linker script -@item INCLUDE @var{filename} -Include the linker script @var{filename} at this point. The file will -be searched for in the current directory, and in any directory specified -with the @code{-L} option. You can nest calls to @code{INCLUDE} up to -10 levels deep. +@cindex holes +Assigning a value to @code{.} will cause the location counter to be +moved. This may be used to create holes in the output section. The +location counter may never be moved backwards. + +@smallexample +SECTIONS +@{ + output : + @{ + file1(.text) + . = . + 1000; + file2(.text) + . += 1000; + file3(.text) + @} = 0x1234; +@} +@end smallexample +@noindent +In the previous example, the @samp{.text} section from @file{file1} is +located at the beginning of the output section @samp{output}. It is +followed by a 1000 byte gap. Then the @samp{.text} section from +@file{file2} appears, also with a 1000 byte gap following before the +@samp{.text} section from @file{file3}. The notation @samp{= 0x1234} +specifies what data to write in the gaps (@pxref{Output Section Fill}). -@kindex INPUT ( @var{files} ) -@cindex binary input files -@item INPUT ( @var{file}, @var{file}, @dots{} ) -@itemx INPUT ( @var{file} @var{file} @dots{} ) -Use this command to include binary input files in the link, without -including them in a particular section definition. -Specify the full name for each @var{file}, including @samp{.a} if -required. +@need 2000 +@node Operators +@subsection Operators +@cindex operators for arithmetic +@cindex arithmetic operators +@cindex precedence in expressions +The linker recognizes the standard C set of arithmetic operators, with +the standard bindings and precedence levels: +@c TEXI2ROFF-KILL +@ifinfo +@c END TEXI2ROFF-KILL +@smallexample +precedence associativity Operators Notes +(highest) +1 left ! - ~ (1) +2 left * / % +3 left + - +4 left >> << +5 left == != > < <= >= +6 left & +7 left | +8 left && +9 left || +10 right ? : +11 right &= += -= *= /= (2) +(lowest) +@end smallexample +Notes: +(1) Prefix operators +(2) @xref{Assignments}. +@c TEXI2ROFF-KILL +@end ifinfo +@tex +\vskip \baselineskip +%"lispnarrowing" is the extra indent used generally for smallexample +\hskip\lispnarrowing\vbox{\offinterlineskip +\hrule +\halign +{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr +height2pt&\omit&&\omit&&\omit&\cr +&Precedence&& Associativity &&{\rm Operators}&\cr +height2pt&\omit&&\omit&&\omit&\cr +\noalign{\hrule} +height2pt&\omit&&\omit&&\omit&\cr +&highest&&&&&\cr +% '176 is tilde, '~' in tt font +&1&&left&&\qquad- \char'176\ !\qquad\dag&\cr +&2&&left&&* / \%&\cr +&3&&left&&+ -&\cr +&4&&left&&>> <<&\cr +&5&&left&&== != > < <= >=&\cr +&6&&left&&\&&\cr +&7&&left&&|&\cr +&8&&left&&{\&\&}&\cr +&9&&left&&||&\cr +&10&&right&&? :&\cr +&11&&right&&\qquad\&= += -= *= /=\qquad\ddag&\cr +&lowest&&&&&\cr +height2pt&\omit&&\omit&&\omit&\cr} +\hrule} +@end tex +@iftex +{ +@obeylines@parskip=0pt@parindent=0pt +@dag@quad Prefix operators. +@ddag@quad @xref{Assignments}. +} +@end iftex +@c END TEXI2ROFF-KILL -@code{ld} searches for each @var{file} through the archive-library -search path, just as for files you specify on the command line. -See the description of @samp{-L} in @ref{Options,,Command Line -Options}. +@node Evaluation +@subsection Evaluation +@cindex lazy evaluation +@cindex expression evaluation order +The linker evaluates expressions lazily. It only computes the value of +an expression when absolutely necessary. -If you use @samp{-l@var{file}}, @code{ld} will transform the name to -@code{lib@var{file}.a} as with the command line argument @samp{-l}. +The linker needs some information, such as the value of the start +address of the first section, and the origins and lengths of memory +regions, in order to do any linking at all. These values are computed +as soon as possible when the linker reads in the linker script. -@kindex GROUP ( @var{files} ) -@cindex grouping input files -@item GROUP ( @var{file}, @var{file}, @dots{} ) -@itemx GROUP ( @var{file} @var{file} @dots{} ) -This command is like @code{INPUT}, except that the named 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}. +However, other values (such as symbol values) are not known or needed +until after storage allocation. Such values are evaluated later, when +other information (such as the sizes of output sections) is available +for use in the symbol assignment expression. -@ignore -@kindex MAP ( @var{name} ) -@item MAP ( @var{name} ) -@c MAP(...) appears to look for an F in the arg, ignoring all other -@c chars; if it finds one, it sets "map_option_f" to true. But nothing -@c checks map_option_f. Apparently a stub for the future... -@end ignore +The sizes of sections cannot be known until after allocation, so +assignments dependent upon these are not performed until after +allocation. -@kindex OUTPUT ( @var{filename} ) -@cindex naming the output file -@item OUTPUT ( @var{filename} ) -Use this command to name the link output file @var{filename}. The -effect of @code{OUTPUT(@var{filename})} is identical to the effect of -@w{@samp{-o @var{filename}}}, which overrides it. You can use this -command to supply a default output-file name other than @code{a.out}. +Some expressions, such as those depending upon the location counter +@samp{.}, must be evaluated during section allocation. -@ifclear SingleFormat -@kindex OUTPUT_ARCH ( @var{bfdname} ) -@cindex machine architecture, output -@item OUTPUT_ARCH ( @var{bfdname} ) -Specify a particular output machine architecture, with one of the names -used by the BFD back-end routines (@pxref{BFD}). This command is often -unnecessary; the architecture is most often set implicitly by either the -system BFD configuration or as a side effect of the @code{OUTPUT_FORMAT} -command. - -@kindex OUTPUT_FORMAT ( @var{bfdname} ) -@cindex format, output file -@item OUTPUT_FORMAT ( @var{bfdname} ) -When @code{ld} is configured to support multiple object code formats, -you can use this command to specify a particular output format. -@var{bfdname} is one of the names used by the BFD back-end routines -(@pxref{BFD}). The effect is identical to the effect of the -@samp{--oformat} command-line option. This selection affects only the -output file; the related command @code{TARGET} affects primarily input -files. -@end ifclear +If the result of an expression is required, but the value is not +available, then an error results. For example, a script like the +following +@smallexample +@group +SECTIONS + @{ + .text 9+this_isnt_constant : + @{ *(.text) @} + @} +@end group +@end smallexample +@noindent +will cause the error message @samp{non constant expression for initial +address}. + +@node Expression Section +@subsection The Section of an Expression +@cindex expression sections +@cindex absolute expressions +@cindex relative expressions +@cindex absolute and relocatable symbols +@cindex relocatable and absolute symbols +@cindex symbols, relocatable and absolute +When the linker evaluates an expression, the result is either absolute +or relative to some section. A relative expression is expressed as a +fixed offset from the base of a section. + +The position of the expression within the linker script determines +whether it is absolute or relative. An expression which appears within +an output section definition is relative to the base of the output +section. An expression which appears elsewhere will be absolute. + +A symbol set to a relative expression will be relocatable if you request +relocatable output using the @samp{-r} option. That means that a +further link operation may change the value of the symbol. The symbol's +section will be the section of the relative expression. + +A symbol set to an absolute expression will retain the same value +through any further link operation. The symbol will be absolute, and +will not have any particular associated section. + +You can use the builtin function @code{ABSOLUTE} to force an expression +to be absolute when it would otherwise be relative. For example, to +create an absolute symbol set to the address of the end of the output +section @samp{.data}: +@smallexample +SECTIONS + @{ + .data : @{ *(.data) _edata = ABSOLUTE(.); @} + @} +@end smallexample +@noindent +If @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the +@samp{.data} section. -@kindex SEARCH_DIR ( @var{path} ) -@cindex path for libraries -@cindex search path, libraries -@item SEARCH_DIR ( @var{path} ) -Add @var{path} to the list of paths where @code{ld} looks for -archive libraries. @code{SEARCH_DIR(@var{path})} has the same -effect as @samp{-L@var{path}} on the command line. +@node Builtin Functions +@subsection Builtin Functions +@cindex functions in expressions +The linker script language includes a number of builtin functions for +use in linker script expressions. -@kindex STARTUP ( @var{filename} ) -@cindex first input file -@item STARTUP ( @var{filename} ) -Ensure that @var{filename} is the first input file used in the link -process. +@table @code +@item ABSOLUTE(@var{exp}) +@kindex ABSOLUTE(@var{exp}) +@cindex expression, absolute +Return the absolute (non-relocatable, as opposed to non-negative) value +of the expression @var{exp}. Primarily useful to assign an absolute +value to a symbol within a section definition, where symbol values are +normally section relative. @xref{Expression Section}. -@ifclear SingleFormat -@cindex input file format -@kindex TARGET ( @var{format} ) -@item TARGET ( @var{format} ) -When @code{ld} is configured to support multiple object code formats, -you can use this command to change the input-file object code format -(like the command-line option @samp{-b} or its synonym @samp{--format}). -The argument @var{format} is one of the strings used by BFD to name -binary formats. If @code{TARGET} is specified but @code{OUTPUT_FORMAT} -is not, the last @code{TARGET} argument is also used as the default -format for the @code{ld} output file. @xref{BFD}. +@item ADDR(@var{section}) +@kindex ADDR(@var{section}) +@cindex section address in expression +Return the absolute address (the VMA) of the named @var{section}. Your +script must previously have defined the location of that section. In +the following example, @code{symbol_1} and @code{symbol_2} are assigned +identical values: +@smallexample +@group +SECTIONS @{ @dots{} + .output1 : + @{ + start_of_output_1 = ABSOLUTE(.); + @dots{} + @} + .output : + @{ + symbol_1 = ADDR(.output1); + symbol_2 = start_of_output_1; + @} +@dots{} @} +@end group +@end smallexample -@kindex GNUTARGET -If you don't use the @code{TARGET} command, @code{ld} uses the value of -the environment variable @code{GNUTARGET}, if available, to select the -output file format. If that variable is also absent, @code{ld} uses -the default format configured for your machine in the BFD libraries. -@end ifclear +@item ALIGN(@var{exp}) +@kindex ALIGN(@var{exp}) +@cindex round up location counter +@cindex align location counter +Return the location counter (@code{.}) aligned to the next @var{exp} +boundary. @var{exp} must be an expression whose value is a power of +two. This is equivalent to +@smallexample +(. + @var{exp} - 1) & ~(@var{exp} - 1) +@end smallexample -@cindex cross references -@kindex NOCROSSREFS ( @var{sections} ) -@item NOCROSSREFS ( @var{section} @var{section} @dots{} ) -This command may be used to tell @code{ld} to issue an error about any -references among certain sections. +@code{ALIGN} doesn't change the value of the location counter---it just +does arithmetic on it. Here is an example which aligns the output +@code{.data} section to the next @code{0x2000} byte boundary after the +preceding section and sets a variable within the section to the next +@code{0x8000} boundary after the input sections: +@smallexample +@group +SECTIONS @{ @dots{} + .data ALIGN(0x2000): @{ + *(.data) + variable = ALIGN(0x8000); + @} +@dots{} @} +@end group +@end smallexample +@noindent +The first use of @code{ALIGN} in this example specifies the location of +a section because it is used as the optional @var{address} attribute of +a section definition (@pxref{Output Section Address}). The second use +of @code{ALIGN} is used to defines the value of a symbol. -In certain types of programs, particularly on embedded systems, when one -section is loaded into memory, another section will not be. Any direct -references between the two sections would be errors. For example, it -would be an error if code in one section called a function defined in -the other section. +The builtin function @code{NEXT} is closely related to @code{ALIGN}. -The @code{NOCROSSREFS} command takes a list of section names. If -@code{ld} detects any cross references between the sections, it reports -an error and returns a non-zero exit status. The @code{NOCROSSREFS} -command uses output section names, defined in the @code{SECTIONS} -command. It does not use the names of input sections. +@item BLOCK(@var{exp}) +@kindex BLOCK(@var{exp}) +This is a synonym for @code{ALIGN}, for compatibility with older linker +scripts. It is most often seen when setting the address of an output +section. + +@item DEFINED(@var{symbol}) +@kindex DEFINED(@var{symbol}) +@cindex symbol defaults +Return 1 if @var{symbol} is in the linker global symbol table and is +defined, otherwise return 0. You can use this function to provide +default values for symbols. For example, the following script fragment +shows how to set a global symbol @samp{begin} to the first location in +the @samp{.text} section---but if a symbol called @samp{begin} already +existed, its value is preserved: + +@smallexample +@group +SECTIONS@{ @dots{} + .text : @{ + begin = DEFINED(begin) ? begin : . ; + @dots{} + @} +@dots{} @} +@end group +@end smallexample + +@item LOADADDR(@var{section}) +@kindex LOADADDR(@var{section}) +@cindex section load address in expression +Return the absolute LMA of the named @var{section}. This is normally +the same as @code{ADDR}, but it may be different if the @code{AT} +attribute is used in the output section definition (@pxref{Output +Section LMA}). + +@kindex MAX +@item MAX(@var{exp1}, @var{exp2}) +Returns the maximum of @var{exp1} and @var{exp2}. + +@kindex MIN +@item MIN(@var{exp1}, @var{exp2}) +Returns the minimum of @var{exp1} and @var{exp2}. + +@item NEXT(@var{exp}) +@kindex NEXT(@var{exp}) +@cindex unallocated address, next +Return the next unallocated address that is a multiple of @var{exp}. +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 SIZEOF(@var{section}) +@kindex SIZEOF(@var{section}) +@cindex section size +Return the size 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, +@code{symbol_1} and @code{symbol_2} are assigned identical values: +@smallexample +@group +SECTIONS@{ @dots{} + .output @{ + .start = . ; + @dots{} + .end = . ; + @} + symbol_1 = .end - .start ; + symbol_2 = SIZEOF(.output); +@dots{} @} +@end group +@end smallexample + +@item SIZEOF_HEADERS +@itemx sizeof_headers +@kindex SIZEOF_HEADERS +@cindex header size +Return the size in bytes of the output file's headers. This is +information which appears at the start of the output file. You can use +this number when setting the start address of the first section, if you +choose, to facilitate paging. + +@cindex not enough room for program headers +@cindex program headers, not enough room +When producing an ELF output file, if the linker script uses the +@code{SIZEOF_HEADERS} builtin function, the linker must compute the +number of program headers before it has determined all the section +addresses and sizes. If the linker later discovers that it needs +additional program headers, it will report an error @samp{not enough +room for program headers}. To avoid this error, you must avoid using +the @code{SIZEOF_HEADERS} function, or you must rework your linker +script to avoid forcing the linker to use additional program headers, or +you must define the program headers yourself using the @code{PHDRS} +command (@pxref{PHDRS}). @end table @ifset GENERIC @@ -3386,8 +3657,8 @@ You can find contact information for many support companies and individuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs distribution. -In any event, we also recommend that you send bug reports for @code{ld} -to @samp{bug-gnu-utils@@prep.ai.mit.edu}. +Otherwise, send bug reports for @code{ld} to +@samp{bug-gnu-utils@@gnu.org}. The fundamental principle of reporting bugs usefully is this: @strong{report all the facts}. If you are not sure whether to state a @@ -3539,10 +3810,10 @@ things without first using the debugger to find the facts. To aid users making the transition to @sc{gnu} @code{ld} from the MRI linker, @code{ld} can use MRI compatible linker scripts as an alternative to the more general-purpose linker scripting language -described in @ref{Commands,,Command Language}. MRI compatible linker -scripts have a much simpler command set than the scripting language -otherwise used with @code{ld}. @sc{gnu} @code{ld} supports the most -commonly used MRI linker commands; these commands are described here. +described in @ref{Scripts}. MRI compatible linker scripts have a much +simpler command set than the scripting language otherwise used with +@code{ld}. @sc{gnu} @code{ld} supports the most commonly used MRI +linker commands; these commands are described here. In general, MRI scripts aren't of much use with the @code{a.out} object file format, since it only has three sections and MRI scripts lack some -- 2.30.2