xref: /dflybsd-src/contrib/binutils-2.27/ld/ld.texinfo (revision e656dc90e3d65d744d534af2f5ea88cf8101ebcf)
1*a9fa9459Szrj\input texinfo
2*a9fa9459Szrj@setfilename ld.info
3*a9fa9459Szrj@c Copyright (C) 1991-2016 Free Software Foundation, Inc.
4*a9fa9459Szrj@syncodeindex ky cp
5*a9fa9459Szrj@c man begin INCLUDE
6*a9fa9459Szrj@include configdoc.texi
7*a9fa9459Szrj@c (configdoc.texi is generated by the Makefile)
8*a9fa9459Szrj@include bfdver.texi
9*a9fa9459Szrj@c man end
10*a9fa9459Szrj
11*a9fa9459Szrj@c @smallbook
12*a9fa9459Szrj
13*a9fa9459Szrj@macro gcctabopt{body}
14*a9fa9459Szrj@code{\body\}
15*a9fa9459Szrj@end macro
16*a9fa9459Szrj
17*a9fa9459Szrj@c man begin NAME
18*a9fa9459Szrj@ifset man
19*a9fa9459Szrj@c Configure for the generation of man pages
20*a9fa9459Szrj@set UsesEnvVars
21*a9fa9459Szrj@set GENERIC
22*a9fa9459Szrj@set ARM
23*a9fa9459Szrj@set C6X
24*a9fa9459Szrj@set H8300
25*a9fa9459Szrj@set HPPA
26*a9fa9459Szrj@set I960
27*a9fa9459Szrj@set M68HC11
28*a9fa9459Szrj@set M68K
29*a9fa9459Szrj@set MIPS
30*a9fa9459Szrj@set MMIX
31*a9fa9459Szrj@set MSP430
32*a9fa9459Szrj@set NDS32
33*a9fa9459Szrj@set NIOSII
34*a9fa9459Szrj@set POWERPC
35*a9fa9459Szrj@set POWERPC64
36*a9fa9459Szrj@set Renesas
37*a9fa9459Szrj@set SPU
38*a9fa9459Szrj@set TICOFF
39*a9fa9459Szrj@set WIN32
40*a9fa9459Szrj@set XTENSA
41*a9fa9459Szrj@end ifset
42*a9fa9459Szrj@c man end
43*a9fa9459Szrj
44*a9fa9459Szrj@ifnottex
45*a9fa9459Szrj@dircategory Software development
46*a9fa9459Szrj@direntry
47*a9fa9459Szrj* Ld: (ld).                       The GNU linker.
48*a9fa9459Szrj@end direntry
49*a9fa9459Szrj@end ifnottex
50*a9fa9459Szrj
51*a9fa9459Szrj@copying
52*a9fa9459SzrjThis file documents the @sc{gnu} linker LD
53*a9fa9459Szrj@ifset VERSION_PACKAGE
54*a9fa9459Szrj@value{VERSION_PACKAGE}
55*a9fa9459Szrj@end ifset
56*a9fa9459Szrjversion @value{VERSION}.
57*a9fa9459Szrj
58*a9fa9459SzrjCopyright @copyright{} 1991-2016 Free Software Foundation, Inc.
59*a9fa9459Szrj
60*a9fa9459SzrjPermission is granted to copy, distribute and/or modify this document
61*a9fa9459Szrjunder the terms of the GNU Free Documentation License, Version 1.3
62*a9fa9459Szrjor any later version published by the Free Software Foundation;
63*a9fa9459Szrjwith no Invariant Sections, with no Front-Cover Texts, and with no
64*a9fa9459SzrjBack-Cover Texts.  A copy of the license is included in the
65*a9fa9459Szrjsection entitled ``GNU Free Documentation License''.
66*a9fa9459Szrj@end copying
67*a9fa9459Szrj@iftex
68*a9fa9459Szrj@finalout
69*a9fa9459Szrj@setchapternewpage odd
70*a9fa9459Szrj@settitle The GNU linker
71*a9fa9459Szrj@titlepage
72*a9fa9459Szrj@title The GNU linker
73*a9fa9459Szrj@sp 1
74*a9fa9459Szrj@subtitle @code{ld}
75*a9fa9459Szrj@ifset VERSION_PACKAGE
76*a9fa9459Szrj@subtitle @value{VERSION_PACKAGE}
77*a9fa9459Szrj@end ifset
78*a9fa9459Szrj@subtitle Version @value{VERSION}
79*a9fa9459Szrj@author Steve Chamberlain
80*a9fa9459Szrj@author Ian Lance Taylor
81*a9fa9459Szrj@page
82*a9fa9459Szrj
83*a9fa9459Szrj@tex
84*a9fa9459Szrj{\parskip=0pt
85*a9fa9459Szrj\hfill Red Hat Inc\par
86*a9fa9459Szrj\hfill nickc\@credhat.com, doc\@redhat.com\par
87*a9fa9459Szrj\hfill {\it The GNU linker}\par
88*a9fa9459Szrj\hfill Edited by Jeffrey Osier (jeffrey\@cygnus.com)\par
89*a9fa9459Szrj}
90*a9fa9459Szrj\global\parindent=0pt % Steve likes it this way.
91*a9fa9459Szrj@end tex
92*a9fa9459Szrj
93*a9fa9459Szrj@vskip 0pt plus 1filll
94*a9fa9459Szrj@c man begin COPYRIGHT
95*a9fa9459SzrjCopyright @copyright{} 1991-2016 Free Software Foundation, Inc.
96*a9fa9459Szrj
97*a9fa9459SzrjPermission is granted to copy, distribute and/or modify this document
98*a9fa9459Szrjunder the terms of the GNU Free Documentation License, Version 1.3
99*a9fa9459Szrjor any later version published by the Free Software Foundation;
100*a9fa9459Szrjwith no Invariant Sections, with no Front-Cover Texts, and with no
101*a9fa9459SzrjBack-Cover Texts.  A copy of the license is included in the
102*a9fa9459Szrjsection entitled ``GNU Free Documentation License''.
103*a9fa9459Szrj@c man end
104*a9fa9459Szrj
105*a9fa9459Szrj@end titlepage
106*a9fa9459Szrj@end iftex
107*a9fa9459Szrj@contents
108*a9fa9459Szrj@c FIXME: Talk about importance of *order* of args, cmds to linker!
109*a9fa9459Szrj
110*a9fa9459Szrj@ifnottex
111*a9fa9459Szrj@node Top
112*a9fa9459Szrj@top LD
113*a9fa9459SzrjThis file documents the @sc{gnu} linker ld
114*a9fa9459Szrj@ifset VERSION_PACKAGE
115*a9fa9459Szrj@value{VERSION_PACKAGE}
116*a9fa9459Szrj@end ifset
117*a9fa9459Szrjversion @value{VERSION}.
118*a9fa9459Szrj
119*a9fa9459SzrjThis document is distributed under the terms of the GNU Free
120*a9fa9459SzrjDocumentation License version 1.3.  A copy of the license is included
121*a9fa9459Szrjin the section entitled ``GNU Free Documentation License''.
122*a9fa9459Szrj
123*a9fa9459Szrj@menu
124*a9fa9459Szrj* Overview::                    Overview
125*a9fa9459Szrj* Invocation::                  Invocation
126*a9fa9459Szrj* Scripts::                     Linker Scripts
127*a9fa9459Szrj@ifset GENERIC
128*a9fa9459Szrj* Machine Dependent::           Machine Dependent Features
129*a9fa9459Szrj@end ifset
130*a9fa9459Szrj@ifclear GENERIC
131*a9fa9459Szrj@ifset H8300
132*a9fa9459Szrj* H8/300::                      ld and the H8/300
133*a9fa9459Szrj@end ifset
134*a9fa9459Szrj@ifset Renesas
135*a9fa9459Szrj* Renesas::                     ld and other Renesas micros
136*a9fa9459Szrj@end ifset
137*a9fa9459Szrj@ifset I960
138*a9fa9459Szrj* i960::                        ld and the Intel 960 family
139*a9fa9459Szrj@end ifset
140*a9fa9459Szrj@ifset ARM
141*a9fa9459Szrj* ARM::				ld and the ARM family
142*a9fa9459Szrj@end ifset
143*a9fa9459Szrj@ifset M68HC11
144*a9fa9459Szrj* M68HC11/68HC12::              ld and the Motorola 68HC11 and 68HC12 families
145*a9fa9459Szrj@end ifset
146*a9fa9459Szrj@ifset HPPA
147*a9fa9459Szrj* HPPA ELF32::                  ld and HPPA 32-bit ELF
148*a9fa9459Szrj@end ifset
149*a9fa9459Szrj@ifset M68K
150*a9fa9459Szrj* M68K::                        ld and Motorola 68K family
151*a9fa9459Szrj@end ifset
152*a9fa9459Szrj@ifset MIPS
153*a9fa9459Szrj* MIPS::                        ld and MIPS family
154*a9fa9459Szrj@end ifset
155*a9fa9459Szrj@ifset POWERPC
156*a9fa9459Szrj* PowerPC ELF32::               ld and PowerPC 32-bit ELF Support
157*a9fa9459Szrj@end ifset
158*a9fa9459Szrj@ifset POWERPC64
159*a9fa9459Szrj* PowerPC64 ELF64::             ld and PowerPC64 64-bit ELF Support
160*a9fa9459Szrj@end ifset
161*a9fa9459Szrj@ifset SPU
162*a9fa9459Szrj* SPU ELF::			ld and SPU ELF Support
163*a9fa9459Szrj@end ifset
164*a9fa9459Szrj@ifset TICOFF
165*a9fa9459Szrj* TI COFF::                     ld and the TI COFF
166*a9fa9459Szrj@end ifset
167*a9fa9459Szrj@ifset WIN32
168*a9fa9459Szrj* Win32::                       ld and WIN32 (cygwin/mingw)
169*a9fa9459Szrj@end ifset
170*a9fa9459Szrj@ifset XTENSA
171*a9fa9459Szrj* Xtensa::                      ld and Xtensa Processors
172*a9fa9459Szrj@end ifset
173*a9fa9459Szrj@end ifclear
174*a9fa9459Szrj@ifclear SingleFormat
175*a9fa9459Szrj* BFD::                         BFD
176*a9fa9459Szrj@end ifclear
177*a9fa9459Szrj@c Following blank line required for remaining bug in makeinfo conds/menus
178*a9fa9459Szrj
179*a9fa9459Szrj* Reporting Bugs::              Reporting Bugs
180*a9fa9459Szrj* MRI::                         MRI Compatible Script Files
181*a9fa9459Szrj* GNU Free Documentation License::  GNU Free Documentation License
182*a9fa9459Szrj* LD Index::                       LD Index
183*a9fa9459Szrj@end menu
184*a9fa9459Szrj@end ifnottex
185*a9fa9459Szrj
186*a9fa9459Szrj@node Overview
187*a9fa9459Szrj@chapter Overview
188*a9fa9459Szrj
189*a9fa9459Szrj@cindex @sc{gnu} linker
190*a9fa9459Szrj@cindex what is this?
191*a9fa9459Szrj
192*a9fa9459Szrj@ifset man
193*a9fa9459Szrj@c man begin SYNOPSIS
194*a9fa9459Szrjld [@b{options}] @var{objfile} @dots{}
195*a9fa9459Szrj@c man end
196*a9fa9459Szrj
197*a9fa9459Szrj@c man begin SEEALSO
198*a9fa9459Szrjar(1), nm(1), objcopy(1), objdump(1), readelf(1) and
199*a9fa9459Szrjthe Info entries for @file{binutils} and
200*a9fa9459Szrj@file{ld}.
201*a9fa9459Szrj@c man end
202*a9fa9459Szrj@end ifset
203*a9fa9459Szrj
204*a9fa9459Szrj@c man begin DESCRIPTION
205*a9fa9459Szrj
206*a9fa9459Szrj@command{ld} combines a number of object and archive files, relocates
207*a9fa9459Szrjtheir data and ties up symbol references. Usually the last step in
208*a9fa9459Szrjcompiling a program is to run @command{ld}.
209*a9fa9459Szrj
210*a9fa9459Szrj@command{ld} accepts Linker Command Language files written in
211*a9fa9459Szrja superset of AT&T's Link Editor Command Language syntax,
212*a9fa9459Szrjto provide explicit and total control over the linking process.
213*a9fa9459Szrj
214*a9fa9459Szrj@ifset man
215*a9fa9459Szrj@c For the man only
216*a9fa9459SzrjThis man page does not describe the command language; see the
217*a9fa9459Szrj@command{ld} entry in @code{info} for full details on the command
218*a9fa9459Szrjlanguage and on other aspects of the GNU linker.
219*a9fa9459Szrj@end ifset
220*a9fa9459Szrj
221*a9fa9459Szrj@ifclear SingleFormat
222*a9fa9459SzrjThis version of @command{ld} uses the general purpose BFD libraries
223*a9fa9459Szrjto operate on object files. This allows @command{ld} to read, combine, and
224*a9fa9459Szrjwrite object files in many different formats---for example, COFF or
225*a9fa9459Szrj@code{a.out}.  Different formats may be linked together to produce any
226*a9fa9459Szrjavailable kind of object file.  @xref{BFD}, for more information.
227*a9fa9459Szrj@end ifclear
228*a9fa9459Szrj
229*a9fa9459SzrjAside from its flexibility, the @sc{gnu} linker is more helpful than other
230*a9fa9459Szrjlinkers in providing diagnostic information.  Many linkers abandon
231*a9fa9459Szrjexecution immediately upon encountering an error; whenever possible,
232*a9fa9459Szrj@command{ld} continues executing, allowing you to identify other errors
233*a9fa9459Szrj(or, in some cases, to get an output file in spite of the error).
234*a9fa9459Szrj
235*a9fa9459Szrj@c man end
236*a9fa9459Szrj
237*a9fa9459Szrj@node Invocation
238*a9fa9459Szrj@chapter Invocation
239*a9fa9459Szrj
240*a9fa9459Szrj@c man begin DESCRIPTION
241*a9fa9459Szrj
242*a9fa9459SzrjThe @sc{gnu} linker @command{ld} is meant to cover a broad range of situations,
243*a9fa9459Szrjand to be as compatible as possible with other linkers.  As a result,
244*a9fa9459Szrjyou have many choices to control its behavior.
245*a9fa9459Szrj
246*a9fa9459Szrj@c man end
247*a9fa9459Szrj
248*a9fa9459Szrj@ifset UsesEnvVars
249*a9fa9459Szrj@menu
250*a9fa9459Szrj* Options::                     Command Line Options
251*a9fa9459Szrj* Environment::                 Environment Variables
252*a9fa9459Szrj@end menu
253*a9fa9459Szrj
254*a9fa9459Szrj@node Options
255*a9fa9459Szrj@section Command Line Options
256*a9fa9459Szrj@end ifset
257*a9fa9459Szrj
258*a9fa9459Szrj@cindex command line
259*a9fa9459Szrj@cindex options
260*a9fa9459Szrj
261*a9fa9459Szrj@c man begin OPTIONS
262*a9fa9459Szrj
263*a9fa9459SzrjThe linker supports a plethora of command-line options, but in actual
264*a9fa9459Szrjpractice few of them are used in any particular context.
265*a9fa9459Szrj@cindex standard Unix system
266*a9fa9459SzrjFor instance, a frequent use of @command{ld} is to link standard Unix
267*a9fa9459Szrjobject files on a standard, supported Unix system.  On such a system, to
268*a9fa9459Szrjlink a file @code{hello.o}:
269*a9fa9459Szrj
270*a9fa9459Szrj@smallexample
271*a9fa9459Szrjld -o @var{output} /lib/crt0.o hello.o -lc
272*a9fa9459Szrj@end smallexample
273*a9fa9459Szrj
274*a9fa9459SzrjThis tells @command{ld} to produce a file called @var{output} as the
275*a9fa9459Szrjresult of linking the file @code{/lib/crt0.o} with @code{hello.o} and
276*a9fa9459Szrjthe library @code{libc.a}, which will come from the standard search
277*a9fa9459Szrjdirectories.  (See the discussion of the @samp{-l} option below.)
278*a9fa9459Szrj
279*a9fa9459SzrjSome of the command-line options to @command{ld} may be specified at any
280*a9fa9459Szrjpoint in the command line.  However, options which refer to files, such
281*a9fa9459Szrjas @samp{-l} or @samp{-T}, cause the file to be read at the point at
282*a9fa9459Szrjwhich the option appears in the command line, relative to the object
283*a9fa9459Szrjfiles and other file options.  Repeating non-file options with a
284*a9fa9459Szrjdifferent argument will either have no further effect, or override prior
285*a9fa9459Szrjoccurrences (those further to the left on the command line) of that
286*a9fa9459Szrjoption.  Options which may be meaningfully specified more than once are
287*a9fa9459Szrjnoted in the descriptions below.
288*a9fa9459Szrj
289*a9fa9459Szrj@cindex object files
290*a9fa9459SzrjNon-option arguments are object files or archives which are to be linked
291*a9fa9459Szrjtogether.  They may follow, precede, or be mixed in with command-line
292*a9fa9459Szrjoptions, except that an object file argument may not be placed between
293*a9fa9459Szrjan option and its argument.
294*a9fa9459Szrj
295*a9fa9459SzrjUsually the linker is invoked with at least one object file, but you can
296*a9fa9459Szrjspecify other forms of binary input files using @samp{-l}, @samp{-R},
297*a9fa9459Szrjand the script command language.  If @emph{no} binary input files at all
298*a9fa9459Szrjare specified, the linker does not produce any output, and issues the
299*a9fa9459Szrjmessage @samp{No input files}.
300*a9fa9459Szrj
301*a9fa9459SzrjIf the linker cannot recognize the format of an object file, it will
302*a9fa9459Szrjassume that it is a linker script.  A script specified in this way
303*a9fa9459Szrjaugments the main linker script used for the link (either the default
304*a9fa9459Szrjlinker script or the one specified by using @samp{-T}).  This feature
305*a9fa9459Szrjpermits the linker to link against a file which appears to be an object
306*a9fa9459Szrjor an archive, but actually merely defines some symbol values, or uses
307*a9fa9459Szrj@code{INPUT} or @code{GROUP} to load other objects.  Specifying a
308*a9fa9459Szrjscript in this way merely augments the main linker script, with the
309*a9fa9459Szrjextra commands placed after the main script; use the @samp{-T} option
310*a9fa9459Szrjto replace the default linker script entirely, but note the effect of
311*a9fa9459Szrjthe @code{INSERT} command.  @xref{Scripts}.
312*a9fa9459Szrj
313*a9fa9459SzrjFor options whose names are a single letter,
314*a9fa9459Szrjoption arguments must either follow the option letter without intervening
315*a9fa9459Szrjwhitespace, or be given as separate arguments immediately following the
316*a9fa9459Szrjoption that requires them.
317*a9fa9459Szrj
318*a9fa9459SzrjFor options whose names are multiple letters, either one dash or two can
319*a9fa9459Szrjprecede the option name; for example, @samp{-trace-symbol} and
320*a9fa9459Szrj@samp{--trace-symbol} are equivalent.  Note---there is one exception to
321*a9fa9459Szrjthis rule.  Multiple letter options that start with a lower case 'o' can
322*a9fa9459Szrjonly be preceded by two dashes.  This is to reduce confusion with the
323*a9fa9459Szrj@samp{-o} option.  So for example @samp{-omagic} sets the output file
324*a9fa9459Szrjname to @samp{magic} whereas @samp{--omagic} sets the NMAGIC flag on the
325*a9fa9459Szrjoutput.
326*a9fa9459Szrj
327*a9fa9459SzrjArguments to multiple-letter options must either be separated from the
328*a9fa9459Szrjoption name by an equals sign, or be given as separate arguments
329*a9fa9459Szrjimmediately following the option that requires them.  For example,
330*a9fa9459Szrj@samp{--trace-symbol foo} and @samp{--trace-symbol=foo} are equivalent.
331*a9fa9459SzrjUnique abbreviations of the names of multiple-letter options are
332*a9fa9459Szrjaccepted.
333*a9fa9459Szrj
334*a9fa9459SzrjNote---if the linker is being invoked indirectly, via a compiler driver
335*a9fa9459Szrj(e.g. @samp{gcc}) then all the linker command line options should be
336*a9fa9459Szrjprefixed by @samp{-Wl,} (or whatever is appropriate for the particular
337*a9fa9459Szrjcompiler driver) like this:
338*a9fa9459Szrj
339*a9fa9459Szrj@smallexample
340*a9fa9459Szrj  gcc -Wl,--start-group foo.o bar.o -Wl,--end-group
341*a9fa9459Szrj@end smallexample
342*a9fa9459Szrj
343*a9fa9459SzrjThis is important, because otherwise the compiler driver program may
344*a9fa9459Szrjsilently drop the linker options, resulting in a bad link.  Confusion
345*a9fa9459Szrjmay also arise when passing options that require values through a
346*a9fa9459Szrjdriver, as the use of a space between option and argument acts as
347*a9fa9459Szrja separator, and causes the driver to pass only the option to the linker
348*a9fa9459Szrjand the argument to the compiler.  In this case, it is simplest to use
349*a9fa9459Szrjthe joined forms of both single- and multiple-letter options, such as:
350*a9fa9459Szrj
351*a9fa9459Szrj@smallexample
352*a9fa9459Szrj  gcc foo.o bar.o -Wl,-eENTRY -Wl,-Map=a.map
353*a9fa9459Szrj@end smallexample
354*a9fa9459Szrj
355*a9fa9459SzrjHere is a table of the generic command line switches accepted by the GNU
356*a9fa9459Szrjlinker:
357*a9fa9459Szrj
358*a9fa9459Szrj@table @gcctabopt
359*a9fa9459Szrj@include at-file.texi
360*a9fa9459Szrj
361*a9fa9459Szrj@kindex -a @var{keyword}
362*a9fa9459Szrj@item -a @var{keyword}
363*a9fa9459SzrjThis option is supported for HP/UX compatibility.  The @var{keyword}
364*a9fa9459Szrjargument must be one of the strings @samp{archive}, @samp{shared}, or
365*a9fa9459Szrj@samp{default}.  @samp{-aarchive} is functionally equivalent to
366*a9fa9459Szrj@samp{-Bstatic}, and the other two keywords are functionally equivalent
367*a9fa9459Szrjto @samp{-Bdynamic}.  This option may be used any number of times.
368*a9fa9459Szrj
369*a9fa9459Szrj@kindex --audit @var{AUDITLIB}
370*a9fa9459Szrj@item --audit @var{AUDITLIB}
371*a9fa9459SzrjAdds @var{AUDITLIB} to the @code{DT_AUDIT} entry of the dynamic section.
372*a9fa9459Szrj@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
373*a9fa9459Szrjspecified in the library.  If specified multiple times @code{DT_AUDIT}
374*a9fa9459Szrjwill contain a colon separated list of audit interfaces to use. If the linker
375*a9fa9459Szrjfinds an object with an audit entry while searching for shared libraries,
376*a9fa9459Szrjit will add a corresponding @code{DT_DEPAUDIT} entry in the output file.
377*a9fa9459SzrjThis option is only meaningful on ELF platforms supporting the rtld-audit
378*a9fa9459Szrjinterface.
379*a9fa9459Szrj
380*a9fa9459Szrj@ifset I960
381*a9fa9459Szrj@cindex architectures
382*a9fa9459Szrj@kindex -A @var{arch}
383*a9fa9459Szrj@item -A @var{architecture}
384*a9fa9459Szrj@kindex --architecture=@var{arch}
385*a9fa9459Szrj@itemx --architecture=@var{architecture}
386*a9fa9459SzrjIn the current release of @command{ld}, this option is useful only for the
387*a9fa9459SzrjIntel 960 family of architectures.  In that @command{ld} configuration, the
388*a9fa9459Szrj@var{architecture} argument identifies the particular architecture in
389*a9fa9459Szrjthe 960 family, enabling some safeguards and modifying the
390*a9fa9459Szrjarchive-library search path.  @xref{i960,,@command{ld} and the Intel 960
391*a9fa9459Szrjfamily}, for details.
392*a9fa9459Szrj
393*a9fa9459SzrjFuture releases of @command{ld} may support similar functionality for
394*a9fa9459Szrjother architecture families.
395*a9fa9459Szrj@end ifset
396*a9fa9459Szrj
397*a9fa9459Szrj@ifclear SingleFormat
398*a9fa9459Szrj@cindex binary input format
399*a9fa9459Szrj@kindex -b @var{format}
400*a9fa9459Szrj@kindex --format=@var{format}
401*a9fa9459Szrj@cindex input format
402*a9fa9459Szrj@cindex input format
403*a9fa9459Szrj@item -b @var{input-format}
404*a9fa9459Szrj@itemx --format=@var{input-format}
405*a9fa9459Szrj@command{ld} may be configured to support more than one kind of object
406*a9fa9459Szrjfile.  If your @command{ld} is configured this way, you can use the
407*a9fa9459Szrj@samp{-b} option to specify the binary format for input object files
408*a9fa9459Szrjthat follow this option on the command line.  Even when @command{ld} is
409*a9fa9459Szrjconfigured to support alternative object formats, you don't usually need
410*a9fa9459Szrjto specify this, as @command{ld} should be configured to expect as a
411*a9fa9459Szrjdefault input format the most usual format on each machine.
412*a9fa9459Szrj@var{input-format} is a text string, the name of a particular format
413*a9fa9459Szrjsupported by the BFD libraries.  (You can list the available binary
414*a9fa9459Szrjformats with @samp{objdump -i}.)
415*a9fa9459Szrj@xref{BFD}.
416*a9fa9459Szrj
417*a9fa9459SzrjYou may want to use this option if you are linking files with an unusual
418*a9fa9459Szrjbinary format.  You can also use @samp{-b} to switch formats explicitly (when
419*a9fa9459Szrjlinking object files of different formats), by including
420*a9fa9459Szrj@samp{-b @var{input-format}} before each group of object files in a
421*a9fa9459Szrjparticular format.
422*a9fa9459Szrj
423*a9fa9459SzrjThe default format is taken from the environment variable
424*a9fa9459Szrj@code{GNUTARGET}.
425*a9fa9459Szrj@ifset UsesEnvVars
426*a9fa9459Szrj@xref{Environment}.
427*a9fa9459Szrj@end ifset
428*a9fa9459SzrjYou can also define the input format from a script, using the command
429*a9fa9459Szrj@code{TARGET};
430*a9fa9459Szrj@ifclear man
431*a9fa9459Szrjsee @ref{Format Commands}.
432*a9fa9459Szrj@end ifclear
433*a9fa9459Szrj@end ifclear
434*a9fa9459Szrj
435*a9fa9459Szrj@kindex -c @var{MRI-cmdfile}
436*a9fa9459Szrj@kindex --mri-script=@var{MRI-cmdfile}
437*a9fa9459Szrj@cindex compatibility, MRI
438*a9fa9459Szrj@item -c @var{MRI-commandfile}
439*a9fa9459Szrj@itemx --mri-script=@var{MRI-commandfile}
440*a9fa9459SzrjFor compatibility with linkers produced by MRI, @command{ld} accepts script
441*a9fa9459Szrjfiles written in an alternate, restricted command language, described in
442*a9fa9459Szrj@ifclear man
443*a9fa9459Szrj@ref{MRI,,MRI Compatible Script Files}.
444*a9fa9459Szrj@end ifclear
445*a9fa9459Szrj@ifset man
446*a9fa9459Szrjthe MRI Compatible Script Files section of GNU ld documentation.
447*a9fa9459Szrj@end ifset
448*a9fa9459SzrjIntroduce MRI script files with
449*a9fa9459Szrjthe option @samp{-c}; use the @samp{-T} option to run linker
450*a9fa9459Szrjscripts written in the general-purpose @command{ld} scripting language.
451*a9fa9459SzrjIf @var{MRI-cmdfile} does not exist, @command{ld} looks for it in the directories
452*a9fa9459Szrjspecified by any @samp{-L} options.
453*a9fa9459Szrj
454*a9fa9459Szrj@cindex common allocation
455*a9fa9459Szrj@kindex -d
456*a9fa9459Szrj@kindex -dc
457*a9fa9459Szrj@kindex -dp
458*a9fa9459Szrj@item -d
459*a9fa9459Szrj@itemx -dc
460*a9fa9459Szrj@itemx -dp
461*a9fa9459SzrjThese three options are equivalent; multiple forms are supported for
462*a9fa9459Szrjcompatibility with other linkers.  They assign space to common symbols
463*a9fa9459Szrjeven if a relocatable output file is specified (with @samp{-r}).  The
464*a9fa9459Szrjscript command @code{FORCE_COMMON_ALLOCATION} has the same effect.
465*a9fa9459Szrj@xref{Miscellaneous Commands}.
466*a9fa9459Szrj
467*a9fa9459Szrj@kindex --depaudit @var{AUDITLIB}
468*a9fa9459Szrj@kindex -P @var{AUDITLIB}
469*a9fa9459Szrj@item --depaudit @var{AUDITLIB}
470*a9fa9459Szrj@itemx -P @var{AUDITLIB}
471*a9fa9459SzrjAdds @var{AUDITLIB} to the @code{DT_DEPAUDIT} entry of the dynamic section.
472*a9fa9459Szrj@var{AUDITLIB} is not checked for existence, nor will it use the DT_SONAME
473*a9fa9459Szrjspecified in the library.  If specified multiple times @code{DT_DEPAUDIT}
474*a9fa9459Szrjwill contain a colon separated list of audit interfaces to use.  This
475*a9fa9459Szrjoption is only meaningful on ELF platforms supporting the rtld-audit interface.
476*a9fa9459SzrjThe -P option is provided for Solaris compatibility.
477*a9fa9459Szrj
478*a9fa9459Szrj@cindex entry point, from command line
479*a9fa9459Szrj@kindex -e @var{entry}
480*a9fa9459Szrj@kindex --entry=@var{entry}
481*a9fa9459Szrj@item -e @var{entry}
482*a9fa9459Szrj@itemx --entry=@var{entry}
483*a9fa9459SzrjUse @var{entry} as the explicit symbol for beginning execution of your
484*a9fa9459Szrjprogram, rather than the default entry point.  If there is no symbol
485*a9fa9459Szrjnamed @var{entry}, the linker will try to parse @var{entry} as a number,
486*a9fa9459Szrjand use that as the entry address (the number will be interpreted in
487*a9fa9459Szrjbase 10; you may use a leading @samp{0x} for base 16, or a leading
488*a9fa9459Szrj@samp{0} for base 8).  @xref{Entry Point}, for a discussion of defaults
489*a9fa9459Szrjand other ways of specifying the entry point.
490*a9fa9459Szrj
491*a9fa9459Szrj@kindex --exclude-libs
492*a9fa9459Szrj@item --exclude-libs @var{lib},@var{lib},...
493*a9fa9459SzrjSpecifies a list of archive libraries from which symbols should not be automatically
494*a9fa9459Szrjexported.  The library names may be delimited by commas or colons.  Specifying
495*a9fa9459Szrj@code{--exclude-libs ALL} excludes symbols in all archive libraries from
496*a9fa9459Szrjautomatic export.  This option is available only for the i386 PE targeted
497*a9fa9459Szrjport of the linker and for ELF targeted ports.  For i386 PE, symbols
498*a9fa9459Szrjexplicitly listed in a .def file are still exported, regardless of this
499*a9fa9459Szrjoption.  For ELF targeted ports, symbols affected by this option will
500*a9fa9459Szrjbe treated as hidden.
501*a9fa9459Szrj
502*a9fa9459Szrj@kindex --exclude-modules-for-implib
503*a9fa9459Szrj@item --exclude-modules-for-implib @var{module},@var{module},...
504*a9fa9459SzrjSpecifies a list of object files or archive members, from which symbols
505*a9fa9459Szrjshould not be automatically exported, but which should be copied wholesale
506*a9fa9459Szrjinto the import library being generated during the link.  The module names
507*a9fa9459Szrjmay be delimited by commas or colons, and must match exactly the filenames
508*a9fa9459Szrjused by @command{ld} to open the files; for archive members, this is simply
509*a9fa9459Szrjthe member name, but for object files the name listed must include and
510*a9fa9459Szrjmatch precisely any path used to specify the input file on the linker's
511*a9fa9459Szrjcommand-line.  This option is available only for the i386 PE targeted port
512*a9fa9459Szrjof the linker.  Symbols explicitly listed in a .def file are still exported,
513*a9fa9459Szrjregardless of this option.
514*a9fa9459Szrj
515*a9fa9459Szrj@cindex dynamic symbol table
516*a9fa9459Szrj@kindex -E
517*a9fa9459Szrj@kindex --export-dynamic
518*a9fa9459Szrj@kindex --no-export-dynamic
519*a9fa9459Szrj@item -E
520*a9fa9459Szrj@itemx --export-dynamic
521*a9fa9459Szrj@itemx --no-export-dynamic
522*a9fa9459SzrjWhen creating a dynamically linked executable, using the @option{-E}
523*a9fa9459Szrjoption or the @option{--export-dynamic} option causes the linker to add
524*a9fa9459Szrjall symbols to the dynamic symbol table.  The dynamic symbol table is the
525*a9fa9459Szrjset of symbols which are visible from dynamic objects at run time.
526*a9fa9459Szrj
527*a9fa9459SzrjIf you do not use either of these options (or use the
528*a9fa9459Szrj@option{--no-export-dynamic} option to restore the default behavior), the
529*a9fa9459Szrjdynamic symbol table will normally contain only those symbols which are
530*a9fa9459Szrjreferenced by some dynamic object mentioned in the link.
531*a9fa9459Szrj
532*a9fa9459SzrjIf you use @code{dlopen} to load a dynamic object which needs to refer
533*a9fa9459Szrjback to the symbols defined by the program, rather than some other
534*a9fa9459Szrjdynamic object, then you will probably need to use this option when
535*a9fa9459Szrjlinking the program itself.
536*a9fa9459Szrj
537*a9fa9459SzrjYou can also use the dynamic list to control what symbols should
538*a9fa9459Szrjbe added to the dynamic symbol table if the output format supports it.
539*a9fa9459SzrjSee the description of @samp{--dynamic-list}.
540*a9fa9459Szrj
541*a9fa9459SzrjNote that this option is specific to ELF targeted ports.  PE targets
542*a9fa9459Szrjsupport a similar function to export all symbols from a DLL or EXE; see
543*a9fa9459Szrjthe description of @samp{--export-all-symbols} below.
544*a9fa9459Szrj
545*a9fa9459Szrj@ifclear SingleFormat
546*a9fa9459Szrj@cindex big-endian objects
547*a9fa9459Szrj@cindex endianness
548*a9fa9459Szrj@kindex -EB
549*a9fa9459Szrj@item -EB
550*a9fa9459SzrjLink big-endian objects.  This affects the default output format.
551*a9fa9459Szrj
552*a9fa9459Szrj@cindex little-endian objects
553*a9fa9459Szrj@kindex -EL
554*a9fa9459Szrj@item -EL
555*a9fa9459SzrjLink little-endian objects.  This affects the default output format.
556*a9fa9459Szrj@end ifclear
557*a9fa9459Szrj
558*a9fa9459Szrj@kindex -f @var{name}
559*a9fa9459Szrj@kindex --auxiliary=@var{name}
560*a9fa9459Szrj@item -f @var{name}
561*a9fa9459Szrj@itemx --auxiliary=@var{name}
562*a9fa9459SzrjWhen creating an ELF shared object, set the internal DT_AUXILIARY field
563*a9fa9459Szrjto the specified name.  This tells the dynamic linker that the symbol
564*a9fa9459Szrjtable of the shared object should be used as an auxiliary filter on the
565*a9fa9459Szrjsymbol table of the shared object @var{name}.
566*a9fa9459Szrj
567*a9fa9459SzrjIf you later link a program against this filter object, then, when you
568*a9fa9459Szrjrun the program, the dynamic linker will see the DT_AUXILIARY field.  If
569*a9fa9459Szrjthe dynamic linker resolves any symbols from the filter object, it will
570*a9fa9459Szrjfirst check whether there is a definition in the shared object
571*a9fa9459Szrj@var{name}.  If there is one, it will be used instead of the definition
572*a9fa9459Szrjin the filter object.  The shared object @var{name} need not exist.
573*a9fa9459SzrjThus the shared object @var{name} may be used to provide an alternative
574*a9fa9459Szrjimplementation of certain functions, perhaps for debugging or for
575*a9fa9459Szrjmachine specific performance.
576*a9fa9459Szrj
577*a9fa9459SzrjThis option may be specified more than once.  The DT_AUXILIARY entries
578*a9fa9459Szrjwill be created in the order in which they appear on the command line.
579*a9fa9459Szrj
580*a9fa9459Szrj@kindex -F @var{name}
581*a9fa9459Szrj@kindex --filter=@var{name}
582*a9fa9459Szrj@item -F @var{name}
583*a9fa9459Szrj@itemx --filter=@var{name}
584*a9fa9459SzrjWhen creating an ELF shared object, set the internal DT_FILTER field to
585*a9fa9459Szrjthe specified name.  This tells the dynamic linker that the symbol table
586*a9fa9459Szrjof the shared object which is being created should be used as a filter
587*a9fa9459Szrjon the symbol table of the shared object @var{name}.
588*a9fa9459Szrj
589*a9fa9459SzrjIf you later link a program against this filter object, then, when you
590*a9fa9459Szrjrun the program, the dynamic linker will see the DT_FILTER field.  The
591*a9fa9459Szrjdynamic linker will resolve symbols according to the symbol table of the
592*a9fa9459Szrjfilter object as usual, but it will actually link to the definitions
593*a9fa9459Szrjfound in the shared object @var{name}.  Thus the filter object can be
594*a9fa9459Szrjused to select a subset of the symbols provided by the object
595*a9fa9459Szrj@var{name}.
596*a9fa9459Szrj
597*a9fa9459SzrjSome older linkers used the @option{-F} option throughout a compilation
598*a9fa9459Szrjtoolchain for specifying object-file format for both input and output
599*a9fa9459Szrjobject files.
600*a9fa9459Szrj@ifclear SingleFormat
601*a9fa9459SzrjThe @sc{gnu} linker uses other mechanisms for this purpose: the
602*a9fa9459Szrj@option{-b}, @option{--format}, @option{--oformat} options, the
603*a9fa9459Szrj@code{TARGET} command in linker scripts, and the @code{GNUTARGET}
604*a9fa9459Szrjenvironment variable.
605*a9fa9459Szrj@end ifclear
606*a9fa9459SzrjThe @sc{gnu} linker will ignore the @option{-F} option when not
607*a9fa9459Szrjcreating an ELF shared object.
608*a9fa9459Szrj
609*a9fa9459Szrj@cindex finalization function
610*a9fa9459Szrj@kindex -fini=@var{name}
611*a9fa9459Szrj@item -fini=@var{name}
612*a9fa9459SzrjWhen creating an ELF executable or shared object, call NAME when the
613*a9fa9459Szrjexecutable or shared object is unloaded, by setting DT_FINI to the
614*a9fa9459Szrjaddress of the function.  By default, the linker uses @code{_fini} as
615*a9fa9459Szrjthe function to call.
616*a9fa9459Szrj
617*a9fa9459Szrj@kindex -g
618*a9fa9459Szrj@item -g
619*a9fa9459SzrjIgnored.  Provided for compatibility with other tools.
620*a9fa9459Szrj
621*a9fa9459Szrj@kindex -G @var{value}
622*a9fa9459Szrj@kindex --gpsize=@var{value}
623*a9fa9459Szrj@cindex object size
624*a9fa9459Szrj@item -G @var{value}
625*a9fa9459Szrj@itemx --gpsize=@var{value}
626*a9fa9459SzrjSet the maximum size of objects to be optimized using the GP register to
627*a9fa9459Szrj@var{size}.  This is only meaningful for object file formats such as
628*a9fa9459SzrjMIPS ELF that support putting large and small objects into different
629*a9fa9459Szrjsections.  This is ignored for other object file formats.
630*a9fa9459Szrj
631*a9fa9459Szrj@cindex runtime library name
632*a9fa9459Szrj@kindex -h @var{name}
633*a9fa9459Szrj@kindex -soname=@var{name}
634*a9fa9459Szrj@item -h @var{name}
635*a9fa9459Szrj@itemx -soname=@var{name}
636*a9fa9459SzrjWhen creating an ELF shared object, set the internal DT_SONAME field to
637*a9fa9459Szrjthe specified name.  When an executable is linked with a shared object
638*a9fa9459Szrjwhich has a DT_SONAME field, then when the executable is run the dynamic
639*a9fa9459Szrjlinker will attempt to load the shared object specified by the DT_SONAME
640*a9fa9459Szrjfield rather than the using the file name given to the linker.
641*a9fa9459Szrj
642*a9fa9459Szrj@kindex -i
643*a9fa9459Szrj@cindex incremental link
644*a9fa9459Szrj@item -i
645*a9fa9459SzrjPerform an incremental link (same as option @samp{-r}).
646*a9fa9459Szrj
647*a9fa9459Szrj@cindex initialization function
648*a9fa9459Szrj@kindex -init=@var{name}
649*a9fa9459Szrj@item -init=@var{name}
650*a9fa9459SzrjWhen creating an ELF executable or shared object, call NAME when the
651*a9fa9459Szrjexecutable or shared object is loaded, by setting DT_INIT to the address
652*a9fa9459Szrjof the function.  By default, the linker uses @code{_init} as the
653*a9fa9459Szrjfunction to call.
654*a9fa9459Szrj
655*a9fa9459Szrj@cindex archive files, from cmd line
656*a9fa9459Szrj@kindex -l @var{namespec}
657*a9fa9459Szrj@kindex --library=@var{namespec}
658*a9fa9459Szrj@item -l @var{namespec}
659*a9fa9459Szrj@itemx --library=@var{namespec}
660*a9fa9459SzrjAdd the archive or object file specified by @var{namespec} to the
661*a9fa9459Szrjlist of files to link.  This option may be used any number of times.
662*a9fa9459SzrjIf @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
663*a9fa9459Szrjwill search the library path for a file called @var{filename}, otherwise it
664*a9fa9459Szrjwill search the library path for a file called @file{lib@var{namespec}.a}.
665*a9fa9459Szrj
666*a9fa9459SzrjOn systems which support shared libraries, @command{ld} may also search for
667*a9fa9459Szrjfiles other than @file{lib@var{namespec}.a}.  Specifically, on ELF
668*a9fa9459Szrjand SunOS systems, @command{ld} will search a directory for a library
669*a9fa9459Szrjcalled @file{lib@var{namespec}.so} before searching for one called
670*a9fa9459Szrj@file{lib@var{namespec}.a}.  (By convention, a @code{.so} extension
671*a9fa9459Szrjindicates a shared library.)  Note that this behavior does not apply
672*a9fa9459Szrjto @file{:@var{filename}}, which always specifies a file called
673*a9fa9459Szrj@var{filename}.
674*a9fa9459Szrj
675*a9fa9459SzrjThe linker will search an archive only once, at the location where it is
676*a9fa9459Szrjspecified on the command line.  If the archive defines a symbol which
677*a9fa9459Szrjwas undefined in some object which appeared before the archive on the
678*a9fa9459Szrjcommand line, the linker will include the appropriate file(s) from the
679*a9fa9459Szrjarchive.  However, an undefined symbol in an object appearing later on
680*a9fa9459Szrjthe command line will not cause the linker to search the archive again.
681*a9fa9459Szrj
682*a9fa9459SzrjSee the @option{-(} option for a way to force the linker to search
683*a9fa9459Szrjarchives multiple times.
684*a9fa9459Szrj
685*a9fa9459SzrjYou may list the same archive multiple times on the command line.
686*a9fa9459Szrj
687*a9fa9459Szrj@ifset GENERIC
688*a9fa9459SzrjThis type of archive searching is standard for Unix linkers.  However,
689*a9fa9459Szrjif you are using @command{ld} on AIX, note that it is different from the
690*a9fa9459Szrjbehaviour of the AIX linker.
691*a9fa9459Szrj@end ifset
692*a9fa9459Szrj
693*a9fa9459Szrj@cindex search directory, from cmd line
694*a9fa9459Szrj@kindex -L @var{dir}
695*a9fa9459Szrj@kindex --library-path=@var{dir}
696*a9fa9459Szrj@item -L @var{searchdir}
697*a9fa9459Szrj@itemx --library-path=@var{searchdir}
698*a9fa9459SzrjAdd path @var{searchdir} to the list of paths that @command{ld} will search
699*a9fa9459Szrjfor archive libraries and @command{ld} control scripts.  You may use this
700*a9fa9459Szrjoption any number of times.  The directories are searched in the order
701*a9fa9459Szrjin which they are specified on the command line.  Directories specified
702*a9fa9459Szrjon the command line are searched before the default directories.  All
703*a9fa9459Szrj@option{-L} options apply to all @option{-l} options, regardless of the
704*a9fa9459Szrjorder in which the options appear.  @option{-L} options do not affect
705*a9fa9459Szrjhow @command{ld} searches for a linker script unless @option{-T}
706*a9fa9459Szrjoption is specified.
707*a9fa9459Szrj
708*a9fa9459SzrjIf @var{searchdir} begins with @code{=}, then the @code{=} will be replaced
709*a9fa9459Szrjby the @dfn{sysroot prefix}, controlled by the @samp{--sysroot} option, or
710*a9fa9459Szrjspecified when the linker is configured.
711*a9fa9459Szrj
712*a9fa9459Szrj@ifset UsesEnvVars
713*a9fa9459SzrjThe default set of paths searched (without being specified with
714*a9fa9459Szrj@samp{-L}) depends on which emulation mode @command{ld} is using, and in
715*a9fa9459Szrjsome cases also on how it was configured.  @xref{Environment}.
716*a9fa9459Szrj@end ifset
717*a9fa9459Szrj
718*a9fa9459SzrjThe paths can also be specified in a link script with the
719*a9fa9459Szrj@code{SEARCH_DIR} command.  Directories specified this way are searched
720*a9fa9459Szrjat the point in which the linker script appears in the command line.
721*a9fa9459Szrj
722*a9fa9459Szrj@cindex emulation
723*a9fa9459Szrj@kindex -m @var{emulation}
724*a9fa9459Szrj@item -m @var{emulation}
725*a9fa9459SzrjEmulate the @var{emulation} linker.  You can list the available
726*a9fa9459Szrjemulations with the @samp{--verbose} or @samp{-V} options.
727*a9fa9459Szrj
728*a9fa9459SzrjIf the @samp{-m} option is not used, the emulation is taken from the
729*a9fa9459Szrj@code{LDEMULATION} environment variable, if that is defined.
730*a9fa9459Szrj
731*a9fa9459SzrjOtherwise, the default emulation depends upon how the linker was
732*a9fa9459Szrjconfigured.
733*a9fa9459Szrj
734*a9fa9459Szrj@cindex link map
735*a9fa9459Szrj@kindex -M
736*a9fa9459Szrj@kindex --print-map
737*a9fa9459Szrj@item -M
738*a9fa9459Szrj@itemx --print-map
739*a9fa9459SzrjPrint a link map to the standard output.  A link map provides
740*a9fa9459Szrjinformation about the link, including the following:
741*a9fa9459Szrj
742*a9fa9459Szrj@itemize @bullet
743*a9fa9459Szrj@item
744*a9fa9459SzrjWhere object files are mapped into memory.
745*a9fa9459Szrj@item
746*a9fa9459SzrjHow common symbols are allocated.
747*a9fa9459Szrj@item
748*a9fa9459SzrjAll archive members included in the link, with a mention of the symbol
749*a9fa9459Szrjwhich caused the archive member to be brought in.
750*a9fa9459Szrj@item
751*a9fa9459SzrjThe values assigned to symbols.
752*a9fa9459Szrj
753*a9fa9459SzrjNote - symbols whose values are computed by an expression which
754*a9fa9459Szrjinvolves a reference to a previous value of the same symbol may not
755*a9fa9459Szrjhave correct result displayed in the link map.  This is because the
756*a9fa9459Szrjlinker discards intermediate results and only retains the final value
757*a9fa9459Szrjof an expression.  Under such circumstances the linker will display
758*a9fa9459Szrjthe final value enclosed by square brackets.  Thus for example a
759*a9fa9459Szrjlinker script containing:
760*a9fa9459Szrj
761*a9fa9459Szrj@smallexample
762*a9fa9459Szrj   foo = 1
763*a9fa9459Szrj   foo = foo * 4
764*a9fa9459Szrj   foo = foo + 8
765*a9fa9459Szrj@end smallexample
766*a9fa9459Szrj
767*a9fa9459Szrjwill produce the following output in the link map if the @option{-M}
768*a9fa9459Szrjoption is used:
769*a9fa9459Szrj
770*a9fa9459Szrj@smallexample
771*a9fa9459Szrj   0x00000001                foo = 0x1
772*a9fa9459Szrj   [0x0000000c]                foo = (foo * 0x4)
773*a9fa9459Szrj   [0x0000000c]                foo = (foo + 0x8)
774*a9fa9459Szrj@end smallexample
775*a9fa9459Szrj
776*a9fa9459SzrjSee @ref{Expressions} for more information about expressions in linker
777*a9fa9459Szrjscripts.
778*a9fa9459Szrj@end itemize
779*a9fa9459Szrj
780*a9fa9459Szrj@kindex -n
781*a9fa9459Szrj@cindex read-only text
782*a9fa9459Szrj@cindex NMAGIC
783*a9fa9459Szrj@kindex --nmagic
784*a9fa9459Szrj@item -n
785*a9fa9459Szrj@itemx --nmagic
786*a9fa9459SzrjTurn off page alignment of sections, and disable linking against shared
787*a9fa9459Szrjlibraries.  If the output format supports Unix style magic numbers,
788*a9fa9459Szrjmark the output as @code{NMAGIC}.
789*a9fa9459Szrj
790*a9fa9459Szrj@kindex -N
791*a9fa9459Szrj@kindex --omagic
792*a9fa9459Szrj@cindex read/write from cmd line
793*a9fa9459Szrj@cindex OMAGIC
794*a9fa9459Szrj@item -N
795*a9fa9459Szrj@itemx --omagic
796*a9fa9459SzrjSet the text and data sections to be readable and writable.  Also, do
797*a9fa9459Szrjnot page-align the data segment, and disable linking against shared
798*a9fa9459Szrjlibraries.  If the output format supports Unix style magic numbers,
799*a9fa9459Szrjmark the output as @code{OMAGIC}. Note: Although a writable text section
800*a9fa9459Szrjis allowed for PE-COFF targets, it does not conform to the format
801*a9fa9459Szrjspecification published by Microsoft.
802*a9fa9459Szrj
803*a9fa9459Szrj@kindex --no-omagic
804*a9fa9459Szrj@cindex OMAGIC
805*a9fa9459Szrj@item --no-omagic
806*a9fa9459SzrjThis option negates most of the effects of the @option{-N} option.  It
807*a9fa9459Szrjsets the text section to be read-only, and forces the data segment to
808*a9fa9459Szrjbe page-aligned.  Note - this option does not enable linking against
809*a9fa9459Szrjshared libraries.  Use @option{-Bdynamic} for this.
810*a9fa9459Szrj
811*a9fa9459Szrj@kindex -o @var{output}
812*a9fa9459Szrj@kindex --output=@var{output}
813*a9fa9459Szrj@cindex naming the output file
814*a9fa9459Szrj@item -o @var{output}
815*a9fa9459Szrj@itemx --output=@var{output}
816*a9fa9459SzrjUse @var{output} as the name for the program produced by @command{ld}; if this
817*a9fa9459Szrjoption is not specified, the name @file{a.out} is used by default.  The
818*a9fa9459Szrjscript command @code{OUTPUT} can also specify the output file name.
819*a9fa9459Szrj
820*a9fa9459Szrj@kindex -O @var{level}
821*a9fa9459Szrj@cindex generating optimized output
822*a9fa9459Szrj@item -O @var{level}
823*a9fa9459SzrjIf @var{level} is a numeric values greater than zero @command{ld} optimizes
824*a9fa9459Szrjthe output.  This might take significantly longer and therefore probably
825*a9fa9459Szrjshould only be enabled for the final binary.  At the moment this
826*a9fa9459Szrjoption only affects ELF shared library generation.  Future releases of
827*a9fa9459Szrjthe linker may make more use of this option.  Also currently there is
828*a9fa9459Szrjno difference in the linker's behaviour for different non-zero values
829*a9fa9459Szrjof this option.  Again this may change with future releases.
830*a9fa9459Szrj
831*a9fa9459Szrj@kindex --push-state
832*a9fa9459Szrj@cindex push state governing input file handling
833*a9fa9459Szrj@item --push-state
834*a9fa9459SzrjThe @option{--push-state} allows to preserve the current state of the
835*a9fa9459Szrjflags which govern the input file handling so that they can all be
836*a9fa9459Szrjrestored with one corresponding @option{--pop-state} option.
837*a9fa9459Szrj
838*a9fa9459SzrjThe option which are covered are: @option{-Bdynamic}, @option{-Bstatic},
839*a9fa9459Szrj@option{-dn}, @option{-dy}, @option{-call_shared}, @option{-non_shared},
840*a9fa9459Szrj@option{-static}, @option{-N}, @option{-n}, @option{--whole-archive},
841*a9fa9459Szrj@option{--no-whole-archive}, @option{-r}, @option{-Ur},
842*a9fa9459Szrj@option{--copy-dt-needed-entries}, @option{--no-copy-dt-needed-entries},
843*a9fa9459Szrj@option{--as-needed}, @option{--no-as-needed}, and @option{-a}.
844*a9fa9459Szrj
845*a9fa9459SzrjOne target for this option are specifications for @file{pkg-config}.  When
846*a9fa9459Szrjused with the @option{--libs} option all possibly needed libraries are
847*a9fa9459Szrjlisted and then possibly linked with all the time.  It is better to return
848*a9fa9459Szrjsomething as follows:
849*a9fa9459Szrj
850*a9fa9459Szrj@smallexample
851*a9fa9459Szrj-Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state
852*a9fa9459Szrj@end smallexample
853*a9fa9459Szrj
854*a9fa9459Szrj@kindex --pop-state
855*a9fa9459Szrj@cindex pop state governing input file handling
856*a9fa9459SzrjUndoes the effect of --push-state, restores the previous values of the
857*a9fa9459Szrjflags governing input file handling.
858*a9fa9459Szrj
859*a9fa9459Szrj@kindex -q
860*a9fa9459Szrj@kindex --emit-relocs
861*a9fa9459Szrj@cindex retain relocations in final executable
862*a9fa9459Szrj@item -q
863*a9fa9459Szrj@itemx --emit-relocs
864*a9fa9459SzrjLeave relocation sections and contents in fully linked executables.
865*a9fa9459SzrjPost link analysis and optimization tools may need this information in
866*a9fa9459Szrjorder to perform correct modifications of executables.  This results
867*a9fa9459Szrjin larger executables.
868*a9fa9459Szrj
869*a9fa9459SzrjThis option is currently only supported on ELF platforms.
870*a9fa9459Szrj
871*a9fa9459Szrj@kindex --force-dynamic
872*a9fa9459Szrj@cindex forcing the creation of dynamic sections
873*a9fa9459Szrj@item --force-dynamic
874*a9fa9459SzrjForce the output file to have dynamic sections.  This option is specific
875*a9fa9459Szrjto VxWorks targets.
876*a9fa9459Szrj
877*a9fa9459Szrj@cindex partial link
878*a9fa9459Szrj@cindex relocatable output
879*a9fa9459Szrj@kindex -r
880*a9fa9459Szrj@kindex --relocatable
881*a9fa9459Szrj@item -r
882*a9fa9459Szrj@itemx --relocatable
883*a9fa9459SzrjGenerate relocatable output---i.e., generate an output file that can in
884*a9fa9459Szrjturn serve as input to @command{ld}.  This is often called @dfn{partial
885*a9fa9459Szrjlinking}.  As a side effect, in environments that support standard Unix
886*a9fa9459Szrjmagic numbers, this option also sets the output file's magic number to
887*a9fa9459Szrj@code{OMAGIC}.
888*a9fa9459Szrj@c ; see @option{-N}.
889*a9fa9459SzrjIf this option is not specified, an absolute file is produced.  When
890*a9fa9459Szrjlinking C++ programs, this option @emph{will not} resolve references to
891*a9fa9459Szrjconstructors; to do that, use @samp{-Ur}.
892*a9fa9459Szrj
893*a9fa9459SzrjWhen an input file does not have the same format as the output file,
894*a9fa9459Szrjpartial linking is only supported if that input file does not contain any
895*a9fa9459Szrjrelocations.  Different output formats can have further restrictions; for
896*a9fa9459Szrjexample some @code{a.out}-based formats do not support partial linking
897*a9fa9459Szrjwith input files in other formats at all.
898*a9fa9459Szrj
899*a9fa9459SzrjThis option does the same thing as @samp{-i}.
900*a9fa9459Szrj
901*a9fa9459Szrj@kindex -R @var{file}
902*a9fa9459Szrj@kindex --just-symbols=@var{file}
903*a9fa9459Szrj@cindex symbol-only input
904*a9fa9459Szrj@item -R @var{filename}
905*a9fa9459Szrj@itemx --just-symbols=@var{filename}
906*a9fa9459SzrjRead symbol names and their addresses from @var{filename}, but do not
907*a9fa9459Szrjrelocate it or include it in the output.  This allows your output file
908*a9fa9459Szrjto refer symbolically to absolute locations of memory defined in other
909*a9fa9459Szrjprograms.  You may use this option more than once.
910*a9fa9459Szrj
911*a9fa9459SzrjFor compatibility with other ELF linkers, if the @option{-R} option is
912*a9fa9459Szrjfollowed by a directory name, rather than a file name, it is treated as
913*a9fa9459Szrjthe @option{-rpath} option.
914*a9fa9459Szrj
915*a9fa9459Szrj@kindex -s
916*a9fa9459Szrj@kindex --strip-all
917*a9fa9459Szrj@cindex strip all symbols
918*a9fa9459Szrj@item -s
919*a9fa9459Szrj@itemx --strip-all
920*a9fa9459SzrjOmit all symbol information from the output file.
921*a9fa9459Szrj
922*a9fa9459Szrj@kindex -S
923*a9fa9459Szrj@kindex --strip-debug
924*a9fa9459Szrj@cindex strip debugger symbols
925*a9fa9459Szrj@item -S
926*a9fa9459Szrj@itemx --strip-debug
927*a9fa9459SzrjOmit debugger symbol information (but not all symbols) from the output file.
928*a9fa9459Szrj
929*a9fa9459Szrj@kindex -t
930*a9fa9459Szrj@kindex --trace
931*a9fa9459Szrj@cindex input files, displaying
932*a9fa9459Szrj@item -t
933*a9fa9459Szrj@itemx --trace
934*a9fa9459SzrjPrint the names of the input files as @command{ld} processes them.
935*a9fa9459Szrj
936*a9fa9459Szrj@kindex -T @var{script}
937*a9fa9459Szrj@kindex --script=@var{script}
938*a9fa9459Szrj@cindex script files
939*a9fa9459Szrj@item -T @var{scriptfile}
940*a9fa9459Szrj@itemx --script=@var{scriptfile}
941*a9fa9459SzrjUse @var{scriptfile} as the linker script.  This script replaces
942*a9fa9459Szrj@command{ld}'s default linker script (rather than adding to it), so
943*a9fa9459Szrj@var{commandfile} must specify everything necessary to describe the
944*a9fa9459Szrjoutput file.  @xref{Scripts}.  If @var{scriptfile} does not exist in
945*a9fa9459Szrjthe current directory, @code{ld} looks for it in the directories
946*a9fa9459Szrjspecified by any preceding @samp{-L} options.  Multiple @samp{-T}
947*a9fa9459Szrjoptions accumulate.
948*a9fa9459Szrj
949*a9fa9459Szrj@kindex -dT @var{script}
950*a9fa9459Szrj@kindex --default-script=@var{script}
951*a9fa9459Szrj@cindex script files
952*a9fa9459Szrj@item -dT @var{scriptfile}
953*a9fa9459Szrj@itemx --default-script=@var{scriptfile}
954*a9fa9459SzrjUse @var{scriptfile} as the default linker script.  @xref{Scripts}.
955*a9fa9459Szrj
956*a9fa9459SzrjThis option is similar to the @option{--script} option except that
957*a9fa9459Szrjprocessing of the script is delayed until after the rest of the
958*a9fa9459Szrjcommand line has been processed.  This allows options placed after the
959*a9fa9459Szrj@option{--default-script} option on the command line to affect the
960*a9fa9459Szrjbehaviour of the linker script, which can be important when the linker
961*a9fa9459Szrjcommand line cannot be directly controlled by the user.  (eg because
962*a9fa9459Szrjthe command line is being constructed by another tool, such as
963*a9fa9459Szrj@samp{gcc}).
964*a9fa9459Szrj
965*a9fa9459Szrj@kindex -u @var{symbol}
966*a9fa9459Szrj@kindex --undefined=@var{symbol}
967*a9fa9459Szrj@cindex undefined symbol
968*a9fa9459Szrj@item -u @var{symbol}
969*a9fa9459Szrj@itemx --undefined=@var{symbol}
970*a9fa9459SzrjForce @var{symbol} to be entered in the output file as an undefined
971*a9fa9459Szrjsymbol.  Doing this may, for example, trigger linking of additional
972*a9fa9459Szrjmodules from standard libraries.  @samp{-u} may be repeated with
973*a9fa9459Szrjdifferent option arguments to enter additional undefined symbols.  This
974*a9fa9459Szrjoption is equivalent to the @code{EXTERN} linker script command.
975*a9fa9459Szrj
976*a9fa9459SzrjIf this option is being used to force additional modules to be pulled
977*a9fa9459Szrjinto the link, and if it is an error for the symbol to remain
978*a9fa9459Szrjundefined, then the option @option{--require-defined} should be used
979*a9fa9459Szrjinstead.
980*a9fa9459Szrj
981*a9fa9459Szrj@kindex --require-defined=@var{symbol}
982*a9fa9459Szrj@cindex symbols, require defined
983*a9fa9459Szrj@cindex defined symbol
984*a9fa9459Szrj@item --require-defined=@var{symbol}
985*a9fa9459SzrjRequire that @var{symbol} is defined in the output file.  This option
986*a9fa9459Szrjis the same as option @option{--undefined} except that if @var{symbol}
987*a9fa9459Szrjis not defined in the output file then the linker will issue an error
988*a9fa9459Szrjand exit.  The same effect can be achieved in a linker script by using
989*a9fa9459Szrj@code{EXTERN}, @code{ASSERT} and @code{DEFINED} together.  This option
990*a9fa9459Szrjcan be used multiple times to require additional symbols.
991*a9fa9459Szrj
992*a9fa9459Szrj@kindex -Ur
993*a9fa9459Szrj@cindex constructors
994*a9fa9459Szrj@item -Ur
995*a9fa9459SzrjFor anything other than C++ programs, this option is equivalent to
996*a9fa9459Szrj@samp{-r}: it generates relocatable output---i.e., an output file that can in
997*a9fa9459Szrjturn serve as input to @command{ld}.  When linking C++ programs, @samp{-Ur}
998*a9fa9459Szrj@emph{does} resolve references to constructors, unlike @samp{-r}.
999*a9fa9459SzrjIt does not work to use @samp{-Ur} on files that were themselves linked
1000*a9fa9459Szrjwith @samp{-Ur}; once the constructor table has been built, it cannot
1001*a9fa9459Szrjbe added to.  Use @samp{-Ur} only for the last partial link, and
1002*a9fa9459Szrj@samp{-r} for the others.
1003*a9fa9459Szrj
1004*a9fa9459Szrj@kindex --orphan-handling=@var{MODE}
1005*a9fa9459Szrj@cindex orphan sections
1006*a9fa9459Szrj@cindex sections, orphan
1007*a9fa9459Szrj@item --orphan-handling=@var{MODE}
1008*a9fa9459SzrjControl how orphan sections are handled.  An orphan section is one not
1009*a9fa9459Szrjspecifically mentioned in a linker script.  @xref{Orphan Sections}.
1010*a9fa9459Szrj
1011*a9fa9459Szrj@var{MODE} can have any of the following values:
1012*a9fa9459Szrj
1013*a9fa9459Szrj@table @code
1014*a9fa9459Szrj@item place
1015*a9fa9459SzrjOrphan sections are placed into a suitable output section following
1016*a9fa9459Szrjthe strategy described in @ref{Orphan Sections}.  The option
1017*a9fa9459Szrj@samp{--unique} also effects how sections are placed.
1018*a9fa9459Szrj
1019*a9fa9459Szrj@item discard
1020*a9fa9459SzrjAll orphan sections are discarded, by placing them in the
1021*a9fa9459Szrj@samp{/DISCARD/} section (@pxref{Output Section Discarding}).
1022*a9fa9459Szrj
1023*a9fa9459Szrj@item warn
1024*a9fa9459SzrjThe linker will place the orphan section as for @code{place} and also
1025*a9fa9459Szrjissue a warning.
1026*a9fa9459Szrj
1027*a9fa9459Szrj@item error
1028*a9fa9459SzrjThe linker will exit with an error if any orphan section is found.
1029*a9fa9459Szrj@end table
1030*a9fa9459Szrj
1031*a9fa9459SzrjThe default if @samp{--orphan-handling} is not given is @code{place}.
1032*a9fa9459Szrj
1033*a9fa9459Szrj@kindex --unique[=@var{SECTION}]
1034*a9fa9459Szrj@item --unique[=@var{SECTION}]
1035*a9fa9459SzrjCreates a separate output section for every input section matching
1036*a9fa9459Szrj@var{SECTION}, or if the optional wildcard @var{SECTION} argument is
1037*a9fa9459Szrjmissing, for every orphan input section.  An orphan section is one not
1038*a9fa9459Szrjspecifically mentioned in a linker script.  You may use this option
1039*a9fa9459Szrjmultiple times on the command line;  It prevents the normal merging of
1040*a9fa9459Szrjinput sections with the same name, overriding output section assignments
1041*a9fa9459Szrjin a linker script.
1042*a9fa9459Szrj
1043*a9fa9459Szrj@kindex -v
1044*a9fa9459Szrj@kindex -V
1045*a9fa9459Szrj@kindex --version
1046*a9fa9459Szrj@cindex version
1047*a9fa9459Szrj@item -v
1048*a9fa9459Szrj@itemx --version
1049*a9fa9459Szrj@itemx -V
1050*a9fa9459SzrjDisplay the version number for @command{ld}.  The @option{-V} option also
1051*a9fa9459Szrjlists the supported emulations.
1052*a9fa9459Szrj
1053*a9fa9459Szrj@kindex -x
1054*a9fa9459Szrj@kindex --discard-all
1055*a9fa9459Szrj@cindex deleting local symbols
1056*a9fa9459Szrj@item -x
1057*a9fa9459Szrj@itemx --discard-all
1058*a9fa9459SzrjDelete all local symbols.
1059*a9fa9459Szrj
1060*a9fa9459Szrj@kindex -X
1061*a9fa9459Szrj@kindex --discard-locals
1062*a9fa9459Szrj@cindex local symbols, deleting
1063*a9fa9459Szrj@item -X
1064*a9fa9459Szrj@itemx --discard-locals
1065*a9fa9459SzrjDelete all temporary local symbols.  (These symbols start with
1066*a9fa9459Szrjsystem-specific local label prefixes, typically @samp{.L} for ELF systems
1067*a9fa9459Szrjor @samp{L} for traditional a.out systems.)
1068*a9fa9459Szrj
1069*a9fa9459Szrj@kindex -y @var{symbol}
1070*a9fa9459Szrj@kindex --trace-symbol=@var{symbol}
1071*a9fa9459Szrj@cindex symbol tracing
1072*a9fa9459Szrj@item -y @var{symbol}
1073*a9fa9459Szrj@itemx --trace-symbol=@var{symbol}
1074*a9fa9459SzrjPrint the name of each linked file in which @var{symbol} appears.  This
1075*a9fa9459Szrjoption may be given any number of times.  On many systems it is necessary
1076*a9fa9459Szrjto prepend an underscore.
1077*a9fa9459Szrj
1078*a9fa9459SzrjThis option is useful when you have an undefined symbol in your link but
1079*a9fa9459Szrjdon't know where the reference is coming from.
1080*a9fa9459Szrj
1081*a9fa9459Szrj@kindex -Y @var{path}
1082*a9fa9459Szrj@item -Y @var{path}
1083*a9fa9459SzrjAdd @var{path} to the default library search path.  This option exists
1084*a9fa9459Szrjfor Solaris compatibility.
1085*a9fa9459Szrj
1086*a9fa9459Szrj@kindex -z @var{keyword}
1087*a9fa9459Szrj@item -z @var{keyword}
1088*a9fa9459SzrjThe recognized keywords are:
1089*a9fa9459Szrj@table @samp
1090*a9fa9459Szrj
1091*a9fa9459Szrj@item combreloc
1092*a9fa9459SzrjCombines multiple reloc sections and sorts them to make dynamic symbol
1093*a9fa9459Szrjlookup caching possible.
1094*a9fa9459Szrj
1095*a9fa9459Szrj@item common
1096*a9fa9459SzrjGenerate common symbols with the STT_COMMON type druing a relocatable
1097*a9fa9459Szrjlink.
1098*a9fa9459Szrj
1099*a9fa9459Szrj@item defs
1100*a9fa9459SzrjDisallows undefined symbols in object files.  Undefined symbols in
1101*a9fa9459Szrjshared libraries are still allowed.
1102*a9fa9459Szrj
1103*a9fa9459Szrj@item execstack
1104*a9fa9459SzrjMarks the object as requiring executable stack.
1105*a9fa9459Szrj
1106*a9fa9459Szrj@item global
1107*a9fa9459SzrjThis option is only meaningful when building a shared object.  It makes
1108*a9fa9459Szrjthe symbols defined by this shared object available for symbol resolution
1109*a9fa9459Szrjof subsequently loaded libraries.
1110*a9fa9459Szrj
1111*a9fa9459Szrj@item initfirst
1112*a9fa9459SzrjThis option is only meaningful when building a shared object.
1113*a9fa9459SzrjIt marks the object so that its runtime initialization will occur
1114*a9fa9459Szrjbefore the runtime initialization of any other objects brought into
1115*a9fa9459Szrjthe process at the same time.  Similarly the runtime finalization of
1116*a9fa9459Szrjthe object will occur after the runtime finalization of any other
1117*a9fa9459Szrjobjects.
1118*a9fa9459Szrj
1119*a9fa9459Szrj@item interpose
1120*a9fa9459SzrjMarks the object that its symbol table interposes before all symbols
1121*a9fa9459Szrjbut the primary executable.
1122*a9fa9459Szrj
1123*a9fa9459Szrj@item lazy
1124*a9fa9459SzrjWhen generating an executable or shared library, mark it to tell the
1125*a9fa9459Szrjdynamic linker to defer function call resolution to the point when
1126*a9fa9459Szrjthe function is called (lazy binding), rather than at load time.
1127*a9fa9459SzrjLazy binding is the default.
1128*a9fa9459Szrj
1129*a9fa9459Szrj@item loadfltr
1130*a9fa9459SzrjMarks  the object that its filters be processed immediately at
1131*a9fa9459Szrjruntime.
1132*a9fa9459Szrj
1133*a9fa9459Szrj@item muldefs
1134*a9fa9459SzrjAllows multiple definitions.
1135*a9fa9459Szrj
1136*a9fa9459Szrj@item nocombreloc
1137*a9fa9459SzrjDisables multiple reloc sections combining.
1138*a9fa9459Szrj
1139*a9fa9459Szrj@item nocommon
1140*a9fa9459SzrjGenerate common symbols with the STT_OBJECT type druing a relocatable
1141*a9fa9459Szrjlink.
1142*a9fa9459Szrj
1143*a9fa9459Szrj@item nocopyreloc
1144*a9fa9459SzrjDisable linker generated .dynbss variables used in place of variables
1145*a9fa9459Szrjdefined in shared libraries.  May result in dynamic text relocations.
1146*a9fa9459Szrj
1147*a9fa9459Szrj@item nodefaultlib
1148*a9fa9459SzrjMarks the object that the search for dependencies of this object will
1149*a9fa9459Szrjignore any default library search paths.
1150*a9fa9459Szrj
1151*a9fa9459Szrj@item nodelete
1152*a9fa9459SzrjMarks the object shouldn't be unloaded at runtime.
1153*a9fa9459Szrj
1154*a9fa9459Szrj@item nodlopen
1155*a9fa9459SzrjMarks the object not available to @code{dlopen}.
1156*a9fa9459Szrj
1157*a9fa9459Szrj@item nodump
1158*a9fa9459SzrjMarks the object can not be dumped by @code{dldump}.
1159*a9fa9459Szrj
1160*a9fa9459Szrj@item noexecstack
1161*a9fa9459SzrjMarks the object as not requiring executable stack.
1162*a9fa9459Szrj
1163*a9fa9459Szrj@item text
1164*a9fa9459SzrjTreat DT_TEXTREL in shared object as error.
1165*a9fa9459Szrj
1166*a9fa9459Szrj@item notext
1167*a9fa9459SzrjDon't treat DT_TEXTREL in shared object as error.
1168*a9fa9459Szrj
1169*a9fa9459Szrj@item textoff
1170*a9fa9459SzrjDon't treat DT_TEXTREL in shared object as error.
1171*a9fa9459Szrj
1172*a9fa9459Szrj@item norelro
1173*a9fa9459SzrjDon't create an ELF @code{PT_GNU_RELRO} segment header in the object.
1174*a9fa9459Szrj
1175*a9fa9459Szrj@item now
1176*a9fa9459SzrjWhen generating an executable or shared library, mark it to tell the
1177*a9fa9459Szrjdynamic linker to resolve all symbols when the program is started, or
1178*a9fa9459Szrjwhen the shared library is linked to using dlopen, instead of
1179*a9fa9459Szrjdeferring function call resolution to the point when the function is
1180*a9fa9459Szrjfirst called.
1181*a9fa9459Szrj
1182*a9fa9459Szrj@item origin
1183*a9fa9459SzrjMarks the object may contain $ORIGIN.
1184*a9fa9459Szrj
1185*a9fa9459Szrj@item relro
1186*a9fa9459SzrjCreate an ELF @code{PT_GNU_RELRO} segment header in the object.
1187*a9fa9459Szrj
1188*a9fa9459Szrj@item max-page-size=@var{value}
1189*a9fa9459SzrjSet the emulation maximum page size to @var{value}.
1190*a9fa9459Szrj
1191*a9fa9459Szrj@item common-page-size=@var{value}
1192*a9fa9459SzrjSet the emulation common page size to @var{value}.
1193*a9fa9459Szrj
1194*a9fa9459Szrj@item stack-size=@var{value}
1195*a9fa9459SzrjSpecify a stack size for in an ELF @code{PT_GNU_STACK} segment.
1196*a9fa9459SzrjSpecifying zero will override any default non-zero sized
1197*a9fa9459Szrj@code{PT_GNU_STACK} segment creation.
1198*a9fa9459Szrj
1199*a9fa9459Szrj@item bndplt
1200*a9fa9459SzrjAlways generate BND prefix in PLT entries. Supported for Linux/x86_64.
1201*a9fa9459Szrj
1202*a9fa9459Szrj@item noextern-protected-data
1203*a9fa9459SzrjDon't treat protected data symbol as external when building shared
1204*a9fa9459Szrjlibrary.  This option overrides linker backend default.  It can be used
1205*a9fa9459Szrjto workaround incorrect relocations against protected data symbols
1206*a9fa9459Szrjgenerated by compiler.  Updates on protected data symbols by another
1207*a9fa9459Szrjmodule aren't visible to the resulting shared library.  Supported for
1208*a9fa9459Szrji386 and x86-64.
1209*a9fa9459Szrj
1210*a9fa9459Szrj@item nodynamic-undefined-weak
1211*a9fa9459SzrjDon't treat undefined weak symbols as dynamic when building executable.
1212*a9fa9459SzrjThis option overrides linker backend default.  It can be used to avoid
1213*a9fa9459Szrjdynamic relocations against undefined weak symbols in executable.
1214*a9fa9459SzrjSupported for i386 and x86-64.
1215*a9fa9459Szrj
1216*a9fa9459Szrj@item noreloc-overflow
1217*a9fa9459SzrjDisable relocation overflow check.  This can be used to disable
1218*a9fa9459Szrjrelocation overflow check if there will be no dynamic relocation
1219*a9fa9459Szrjoverflow at run-time.  Supported for x86_64.
1220*a9fa9459Szrj
1221*a9fa9459Szrj@item call-nop=prefix-addr
1222*a9fa9459Szrj@itemx call-nop=prefix-nop
1223*a9fa9459Szrj@itemx call-nop=suffix-nop
1224*a9fa9459Szrj@itemx call-nop=prefix-@var{byte}
1225*a9fa9459Szrj@itemx call-nop=suffix-@var{byte}
1226*a9fa9459SzrjSpecify the 1-byte @code{NOP} padding when transforming indirect call
1227*a9fa9459Szrjto a locally defined function, foo, via its GOT slot.
1228*a9fa9459Szrj@option{call-nop=prefix-addr} generates @code{0x67 call foo}.
1229*a9fa9459Szrj@option{call-nop=prefix-nop} generates @code{0x90 call foo}.
1230*a9fa9459Szrj@option{call-nop=suffix-nop} generates @code{call foo 0x90}.
1231*a9fa9459Szrj@option{call-nop=prefix-@var{byte}} generates @code{@var{byte} call foo}.
1232*a9fa9459Szrj@option{call-nop=suffix-@var{byte}} generates @code{call foo @var{byte}}.
1233*a9fa9459SzrjSupported for i386 and x86_64.
1234*a9fa9459Szrj
1235*a9fa9459Szrj@end table
1236*a9fa9459Szrj
1237*a9fa9459SzrjOther keywords are ignored for Solaris compatibility.
1238*a9fa9459Szrj
1239*a9fa9459Szrj@kindex -(
1240*a9fa9459Szrj@cindex groups of archives
1241*a9fa9459Szrj@item -( @var{archives} -)
1242*a9fa9459Szrj@itemx --start-group @var{archives} --end-group
1243*a9fa9459SzrjThe @var{archives} should be a list of archive files.  They may be
1244*a9fa9459Szrjeither explicit file names, or @samp{-l} options.
1245*a9fa9459Szrj
1246*a9fa9459SzrjThe specified archives are searched repeatedly until no new undefined
1247*a9fa9459Szrjreferences are created.  Normally, an archive is searched only once in
1248*a9fa9459Szrjthe order that it is specified on the command line.  If a symbol in that
1249*a9fa9459Szrjarchive is needed to resolve an undefined symbol referred to by an
1250*a9fa9459Szrjobject in an archive that appears later on the command line, the linker
1251*a9fa9459Szrjwould not be able to resolve that reference.  By grouping the archives,
1252*a9fa9459Szrjthey all be searched repeatedly until all possible references are
1253*a9fa9459Szrjresolved.
1254*a9fa9459Szrj
1255*a9fa9459SzrjUsing this option has a significant performance cost.  It is best to use
1256*a9fa9459Szrjit only when there are unavoidable circular references between two or
1257*a9fa9459Szrjmore archives.
1258*a9fa9459Szrj
1259*a9fa9459Szrj@kindex --accept-unknown-input-arch
1260*a9fa9459Szrj@kindex --no-accept-unknown-input-arch
1261*a9fa9459Szrj@item --accept-unknown-input-arch
1262*a9fa9459Szrj@itemx --no-accept-unknown-input-arch
1263*a9fa9459SzrjTells the linker to accept input files whose architecture cannot be
1264*a9fa9459Szrjrecognised.  The assumption is that the user knows what they are doing
1265*a9fa9459Szrjand deliberately wants to link in these unknown input files.  This was
1266*a9fa9459Szrjthe default behaviour of the linker, before release 2.14.  The default
1267*a9fa9459Szrjbehaviour from release 2.14 onwards is to reject such input files, and
1268*a9fa9459Szrjso the @samp{--accept-unknown-input-arch} option has been added to
1269*a9fa9459Szrjrestore the old behaviour.
1270*a9fa9459Szrj
1271*a9fa9459Szrj@kindex --as-needed
1272*a9fa9459Szrj@kindex --no-as-needed
1273*a9fa9459Szrj@item --as-needed
1274*a9fa9459Szrj@itemx --no-as-needed
1275*a9fa9459SzrjThis option affects ELF DT_NEEDED tags for dynamic libraries mentioned
1276*a9fa9459Szrjon the command line after the @option{--as-needed} option.  Normally
1277*a9fa9459Szrjthe linker will add a DT_NEEDED tag for each dynamic library mentioned
1278*a9fa9459Szrjon the command line, regardless of whether the library is actually
1279*a9fa9459Szrjneeded or not.  @option{--as-needed} causes a DT_NEEDED tag to only be
1280*a9fa9459Szrjemitted for a library that @emph{at that point in the link} satisfies a
1281*a9fa9459Szrjnon-weak undefined symbol reference from a regular object file or, if
1282*a9fa9459Szrjthe library is not found in the DT_NEEDED lists of other needed libraries, a
1283*a9fa9459Szrjnon-weak undefined symbol reference from another needed dynamic library.
1284*a9fa9459SzrjObject files or libraries appearing on the command line @emph{after}
1285*a9fa9459Szrjthe library in question do not affect whether the library is seen as
1286*a9fa9459Szrjneeded.  This is similar to the rules for extraction of object files
1287*a9fa9459Szrjfrom archives.  @option{--no-as-needed} restores the default behaviour.
1288*a9fa9459Szrj
1289*a9fa9459Szrj@kindex --add-needed
1290*a9fa9459Szrj@kindex --no-add-needed
1291*a9fa9459Szrj@item --add-needed
1292*a9fa9459Szrj@itemx --no-add-needed
1293*a9fa9459SzrjThese two options have been deprecated because of the similarity of
1294*a9fa9459Szrjtheir names to the @option{--as-needed} and @option{--no-as-needed}
1295*a9fa9459Szrjoptions.  They have been replaced by @option{--copy-dt-needed-entries}
1296*a9fa9459Szrjand @option{--no-copy-dt-needed-entries}.
1297*a9fa9459Szrj
1298*a9fa9459Szrj@kindex -assert @var{keyword}
1299*a9fa9459Szrj@item -assert @var{keyword}
1300*a9fa9459SzrjThis option is ignored for SunOS compatibility.
1301*a9fa9459Szrj
1302*a9fa9459Szrj@kindex -Bdynamic
1303*a9fa9459Szrj@kindex -dy
1304*a9fa9459Szrj@kindex -call_shared
1305*a9fa9459Szrj@item -Bdynamic
1306*a9fa9459Szrj@itemx -dy
1307*a9fa9459Szrj@itemx -call_shared
1308*a9fa9459SzrjLink against dynamic libraries.  This is only meaningful on platforms
1309*a9fa9459Szrjfor which shared libraries are supported.  This option is normally the
1310*a9fa9459Szrjdefault on such platforms.  The different variants of this option are
1311*a9fa9459Szrjfor compatibility with various systems.  You may use this option
1312*a9fa9459Szrjmultiple times on the command line: it affects library searching for
1313*a9fa9459Szrj@option{-l} options which follow it.
1314*a9fa9459Szrj
1315*a9fa9459Szrj@kindex -Bgroup
1316*a9fa9459Szrj@item -Bgroup
1317*a9fa9459SzrjSet the @code{DF_1_GROUP} flag in the @code{DT_FLAGS_1} entry in the dynamic
1318*a9fa9459Szrjsection.  This causes the runtime linker to handle lookups in this
1319*a9fa9459Szrjobject and its dependencies to be performed only inside the group.
1320*a9fa9459Szrj@option{--unresolved-symbols=report-all} is implied.  This option is
1321*a9fa9459Szrjonly meaningful on ELF platforms which support shared libraries.
1322*a9fa9459Szrj
1323*a9fa9459Szrj@kindex -Bstatic
1324*a9fa9459Szrj@kindex -dn
1325*a9fa9459Szrj@kindex -non_shared
1326*a9fa9459Szrj@kindex -static
1327*a9fa9459Szrj@item -Bstatic
1328*a9fa9459Szrj@itemx -dn
1329*a9fa9459Szrj@itemx -non_shared
1330*a9fa9459Szrj@itemx -static
1331*a9fa9459SzrjDo not link against shared libraries.  This is only meaningful on
1332*a9fa9459Szrjplatforms for which shared libraries are supported.  The different
1333*a9fa9459Szrjvariants of this option are for compatibility with various systems.  You
1334*a9fa9459Szrjmay use this option multiple times on the command line: it affects
1335*a9fa9459Szrjlibrary searching for @option{-l} options which follow it.  This
1336*a9fa9459Szrjoption also implies @option{--unresolved-symbols=report-all}.  This
1337*a9fa9459Szrjoption can be used with @option{-shared}.  Doing so means that a
1338*a9fa9459Szrjshared library is being created but that all of the library's external
1339*a9fa9459Szrjreferences must be resolved by pulling in entries from static
1340*a9fa9459Szrjlibraries.
1341*a9fa9459Szrj
1342*a9fa9459Szrj@kindex -Bsymbolic
1343*a9fa9459Szrj@item -Bsymbolic
1344*a9fa9459SzrjWhen creating a shared library, bind references to global symbols to the
1345*a9fa9459Szrjdefinition within the shared library, if any.  Normally, it is possible
1346*a9fa9459Szrjfor a program linked against a shared library to override the definition
1347*a9fa9459Szrjwithin the shared library.  This option can also be used with the
1348*a9fa9459Szrj@option{--export-dynamic} option, when creating a position independent
1349*a9fa9459Szrjexecutable, to bind references to global symbols to the definition within
1350*a9fa9459Szrjthe executable.  This option is only meaningful on ELF platforms which
1351*a9fa9459Szrjsupport shared libraries and position independent executables.
1352*a9fa9459Szrj
1353*a9fa9459Szrj@kindex -Bsymbolic-functions
1354*a9fa9459Szrj@item -Bsymbolic-functions
1355*a9fa9459SzrjWhen creating a shared library, bind references to global function
1356*a9fa9459Szrjsymbols to the definition within the shared library, if any.
1357*a9fa9459SzrjThis option can also be used with the @option{--export-dynamic} option,
1358*a9fa9459Szrjwhen creating a position independent executable, to bind references
1359*a9fa9459Szrjto global function symbols to the definition within the executable.
1360*a9fa9459SzrjThis option is only meaningful on ELF platforms which support shared
1361*a9fa9459Szrjlibraries and position independent executables.
1362*a9fa9459Szrj
1363*a9fa9459Szrj@kindex --dynamic-list=@var{dynamic-list-file}
1364*a9fa9459Szrj@item --dynamic-list=@var{dynamic-list-file}
1365*a9fa9459SzrjSpecify the name of a dynamic list file to the linker.  This is
1366*a9fa9459Szrjtypically used when creating shared libraries to specify a list of
1367*a9fa9459Szrjglobal symbols whose references shouldn't be bound to the definition
1368*a9fa9459Szrjwithin the shared library, or creating dynamically linked executables
1369*a9fa9459Szrjto specify a list of symbols which should be added to the symbol table
1370*a9fa9459Szrjin the executable.  This option is only meaningful on ELF platforms
1371*a9fa9459Szrjwhich support shared libraries.
1372*a9fa9459Szrj
1373*a9fa9459SzrjThe format of the dynamic list is the same as the version node without
1374*a9fa9459Szrjscope and node name.  See @ref{VERSION} for more information.
1375*a9fa9459Szrj
1376*a9fa9459Szrj@kindex --dynamic-list-data
1377*a9fa9459Szrj@item --dynamic-list-data
1378*a9fa9459SzrjInclude all global data symbols to the dynamic list.
1379*a9fa9459Szrj
1380*a9fa9459Szrj@kindex --dynamic-list-cpp-new
1381*a9fa9459Szrj@item --dynamic-list-cpp-new
1382*a9fa9459SzrjProvide the builtin dynamic list for C++ operator new and delete.  It
1383*a9fa9459Szrjis mainly useful for building shared libstdc++.
1384*a9fa9459Szrj
1385*a9fa9459Szrj@kindex --dynamic-list-cpp-typeinfo
1386*a9fa9459Szrj@item --dynamic-list-cpp-typeinfo
1387*a9fa9459SzrjProvide the builtin dynamic list for C++ runtime type identification.
1388*a9fa9459Szrj
1389*a9fa9459Szrj@kindex --check-sections
1390*a9fa9459Szrj@kindex --no-check-sections
1391*a9fa9459Szrj@item --check-sections
1392*a9fa9459Szrj@itemx --no-check-sections
1393*a9fa9459SzrjAsks the linker @emph{not} to check section addresses after they have
1394*a9fa9459Szrjbeen assigned to see if there are any overlaps.  Normally the linker will
1395*a9fa9459Szrjperform this check, and if it finds any overlaps it will produce
1396*a9fa9459Szrjsuitable error messages.  The linker does know about, and does make
1397*a9fa9459Szrjallowances for sections in overlays.  The default behaviour can be
1398*a9fa9459Szrjrestored by using the command line switch @option{--check-sections}.
1399*a9fa9459SzrjSection overlap is not usually checked for relocatable links.  You can
1400*a9fa9459Szrjforce checking in that case by using the @option{--check-sections}
1401*a9fa9459Szrjoption.
1402*a9fa9459Szrj
1403*a9fa9459Szrj@kindex --copy-dt-needed-entries
1404*a9fa9459Szrj@kindex --no-copy-dt-needed-entries
1405*a9fa9459Szrj@item --copy-dt-needed-entries
1406*a9fa9459Szrj@itemx --no-copy-dt-needed-entries
1407*a9fa9459SzrjThis option affects the treatment of dynamic libraries referred to
1408*a9fa9459Szrjby DT_NEEDED tags @emph{inside} ELF dynamic libraries mentioned on the
1409*a9fa9459Szrjcommand line.  Normally the linker won't add a DT_NEEDED tag to the
1410*a9fa9459Szrjoutput binary for each library mentioned in a DT_NEEDED tag in an
1411*a9fa9459Szrjinput dynamic library.  With @option{--copy-dt-needed-entries}
1412*a9fa9459Szrjspecified on the command line however any dynamic libraries that
1413*a9fa9459Szrjfollow it will have their DT_NEEDED entries added.  The default
1414*a9fa9459Szrjbehaviour can be restored with @option{--no-copy-dt-needed-entries}.
1415*a9fa9459Szrj
1416*a9fa9459SzrjThis option also has an effect on the resolution of symbols in dynamic
1417*a9fa9459Szrjlibraries.  With @option{--copy-dt-needed-entries} dynamic libraries
1418*a9fa9459Szrjmentioned on the command line will be recursively searched, following
1419*a9fa9459Szrjtheir DT_NEEDED tags to other libraries, in order to resolve symbols
1420*a9fa9459Szrjrequired by the output binary.  With the default setting however
1421*a9fa9459Szrjthe searching of dynamic libraries that follow it will stop with the
1422*a9fa9459Szrjdynamic library itself.  No DT_NEEDED links will be traversed to resolve
1423*a9fa9459Szrjsymbols.
1424*a9fa9459Szrj
1425*a9fa9459Szrj@cindex cross reference table
1426*a9fa9459Szrj@kindex --cref
1427*a9fa9459Szrj@item --cref
1428*a9fa9459SzrjOutput a cross reference table.  If a linker map file is being
1429*a9fa9459Szrjgenerated, the cross reference table is printed to the map file.
1430*a9fa9459SzrjOtherwise, it is printed on the standard output.
1431*a9fa9459Szrj
1432*a9fa9459SzrjThe format of the table is intentionally simple, so that it may be
1433*a9fa9459Szrjeasily processed by a script if necessary.  The symbols are printed out,
1434*a9fa9459Szrjsorted by name.  For each symbol, a list of file names is given.  If the
1435*a9fa9459Szrjsymbol is defined, the first file listed is the location of the
1436*a9fa9459Szrjdefinition.  If the symbol is defined as a common value then any files
1437*a9fa9459Szrjwhere this happens appear next.  Finally any files that reference the
1438*a9fa9459Szrjsymbol are listed.
1439*a9fa9459Szrj
1440*a9fa9459Szrj@cindex common allocation
1441*a9fa9459Szrj@kindex --no-define-common
1442*a9fa9459Szrj@item --no-define-common
1443*a9fa9459SzrjThis option inhibits the assignment of addresses to common symbols.
1444*a9fa9459SzrjThe script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect.
1445*a9fa9459Szrj@xref{Miscellaneous Commands}.
1446*a9fa9459Szrj
1447*a9fa9459SzrjThe @samp{--no-define-common} option allows decoupling
1448*a9fa9459Szrjthe decision to assign addresses to Common symbols from the choice
1449*a9fa9459Szrjof the output file type; otherwise a non-Relocatable output type
1450*a9fa9459Szrjforces assigning addresses to Common symbols.
1451*a9fa9459SzrjUsing @samp{--no-define-common} allows Common symbols that are referenced
1452*a9fa9459Szrjfrom a shared library to be assigned addresses only in the main program.
1453*a9fa9459SzrjThis eliminates the unused duplicate space in the shared library,
1454*a9fa9459Szrjand also prevents any possible confusion over resolving to the wrong
1455*a9fa9459Szrjduplicate when there are many dynamic modules with specialized search
1456*a9fa9459Szrjpaths for runtime symbol resolution.
1457*a9fa9459Szrj
1458*a9fa9459Szrj@cindex symbols, from command line
1459*a9fa9459Szrj@kindex --defsym=@var{symbol}=@var{exp}
1460*a9fa9459Szrj@item --defsym=@var{symbol}=@var{expression}
1461*a9fa9459SzrjCreate a global symbol in the output file, containing the absolute
1462*a9fa9459Szrjaddress given by @var{expression}.  You may use this option as many
1463*a9fa9459Szrjtimes as necessary to define multiple symbols in the command line.  A
1464*a9fa9459Szrjlimited form of arithmetic is supported for the @var{expression} in this
1465*a9fa9459Szrjcontext: you may give a hexadecimal constant or the name of an existing
1466*a9fa9459Szrjsymbol, or use @code{+} and @code{-} to add or subtract hexadecimal
1467*a9fa9459Szrjconstants or symbols.  If you need more elaborate expressions, consider
1468*a9fa9459Szrjusing the linker command language from a script (@pxref{Assignments}).
1469*a9fa9459Szrj@emph{Note:} there should be no white space between @var{symbol}, the
1470*a9fa9459Szrjequals sign (``@key{=}''), and @var{expression}.
1471*a9fa9459Szrj
1472*a9fa9459Szrj@cindex demangling, from command line
1473*a9fa9459Szrj@kindex --demangle[=@var{style}]
1474*a9fa9459Szrj@kindex --no-demangle
1475*a9fa9459Szrj@item --demangle[=@var{style}]
1476*a9fa9459Szrj@itemx --no-demangle
1477*a9fa9459SzrjThese options control whether to demangle symbol names in error messages
1478*a9fa9459Szrjand other output.  When the linker is told to demangle, it tries to
1479*a9fa9459Szrjpresent symbol names in a readable fashion: it strips leading
1480*a9fa9459Szrjunderscores if they are used by the object file format, and converts C++
1481*a9fa9459Szrjmangled symbol names into user readable names.  Different compilers have
1482*a9fa9459Szrjdifferent mangling styles.  The optional demangling style argument can be used
1483*a9fa9459Szrjto choose an appropriate demangling style for your compiler.  The linker will
1484*a9fa9459Szrjdemangle by default unless the environment variable @samp{COLLECT_NO_DEMANGLE}
1485*a9fa9459Szrjis set.  These options may be used to override the default.
1486*a9fa9459Szrj
1487*a9fa9459Szrj@cindex dynamic linker, from command line
1488*a9fa9459Szrj@kindex -I@var{file}
1489*a9fa9459Szrj@kindex --dynamic-linker=@var{file}
1490*a9fa9459Szrj@item -I@var{file}
1491*a9fa9459Szrj@itemx --dynamic-linker=@var{file}
1492*a9fa9459SzrjSet the name of the dynamic linker.  This is only meaningful when
1493*a9fa9459Szrjgenerating dynamically linked ELF executables.  The default dynamic
1494*a9fa9459Szrjlinker is normally correct; don't use this unless you know what you are
1495*a9fa9459Szrjdoing.
1496*a9fa9459Szrj
1497*a9fa9459Szrj@kindex --no-dynamic-linker
1498*a9fa9459Szrj@item --no-dynamic-linker
1499*a9fa9459SzrjWhen producing an executable file, omit the request for a dynamic
1500*a9fa9459Szrjlinker to be used at load-time.  This is only meaningful for ELF
1501*a9fa9459Szrjexecutables that contain dynamic relocations, and usually requires
1502*a9fa9459Szrjentry point code that is capable of processing these relocations.
1503*a9fa9459Szrj
1504*a9fa9459Szrj@kindex --fatal-warnings
1505*a9fa9459Szrj@kindex --no-fatal-warnings
1506*a9fa9459Szrj@item --fatal-warnings
1507*a9fa9459Szrj@itemx --no-fatal-warnings
1508*a9fa9459SzrjTreat all warnings as errors.  The default behaviour can be restored
1509*a9fa9459Szrjwith the option @option{--no-fatal-warnings}.
1510*a9fa9459Szrj
1511*a9fa9459Szrj@kindex --force-exe-suffix
1512*a9fa9459Szrj@item  --force-exe-suffix
1513*a9fa9459SzrjMake sure that an output file has a .exe suffix.
1514*a9fa9459Szrj
1515*a9fa9459SzrjIf a successfully built fully linked output file does not have a
1516*a9fa9459Szrj@code{.exe} or @code{.dll} suffix, this option forces the linker to copy
1517*a9fa9459Szrjthe output file to one of the same name with a @code{.exe} suffix. This
1518*a9fa9459Szrjoption is useful when using unmodified Unix makefiles on a Microsoft
1519*a9fa9459SzrjWindows host, since some versions of Windows won't run an image unless
1520*a9fa9459Szrjit ends in a @code{.exe} suffix.
1521*a9fa9459Szrj
1522*a9fa9459Szrj@kindex --gc-sections
1523*a9fa9459Szrj@kindex --no-gc-sections
1524*a9fa9459Szrj@cindex garbage collection
1525*a9fa9459Szrj@item --gc-sections
1526*a9fa9459Szrj@itemx --no-gc-sections
1527*a9fa9459SzrjEnable garbage collection of unused input sections.  It is ignored on
1528*a9fa9459Szrjtargets that do not support this option.  The default behaviour (of not
1529*a9fa9459Szrjperforming this garbage collection) can be restored by specifying
1530*a9fa9459Szrj@samp{--no-gc-sections} on the command line.  Note that garbage
1531*a9fa9459Szrjcollection for COFF and PE format targets is supported, but the
1532*a9fa9459Szrjimplementation is currently considered to be experimental.
1533*a9fa9459Szrj
1534*a9fa9459Szrj@samp{--gc-sections} decides which input sections are used by
1535*a9fa9459Szrjexamining symbols and relocations.  The section containing the entry
1536*a9fa9459Szrjsymbol and all sections containing symbols undefined on the
1537*a9fa9459Szrjcommand-line will be kept, as will sections containing symbols
1538*a9fa9459Szrjreferenced by dynamic objects.  Note that when building shared
1539*a9fa9459Szrjlibraries, the linker must assume that any visible symbol is
1540*a9fa9459Szrjreferenced.  Once this initial set of sections has been determined,
1541*a9fa9459Szrjthe linker recursively marks as used any section referenced by their
1542*a9fa9459Szrjrelocations.  See @samp{--entry} and @samp{--undefined}.
1543*a9fa9459Szrj
1544*a9fa9459SzrjThis option can be set when doing a partial link (enabled with option
1545*a9fa9459Szrj@samp{-r}).  In this case the root of symbols kept must be explicitly
1546*a9fa9459Szrjspecified either by an @samp{--entry} or @samp{--undefined} option or by
1547*a9fa9459Szrja @code{ENTRY} command in the linker script.
1548*a9fa9459Szrj
1549*a9fa9459Szrj@kindex --print-gc-sections
1550*a9fa9459Szrj@kindex --no-print-gc-sections
1551*a9fa9459Szrj@cindex garbage collection
1552*a9fa9459Szrj@item --print-gc-sections
1553*a9fa9459Szrj@itemx --no-print-gc-sections
1554*a9fa9459SzrjList all sections removed by garbage collection.  The listing is
1555*a9fa9459Szrjprinted on stderr.  This option is only effective if garbage
1556*a9fa9459Szrjcollection has been enabled via the @samp{--gc-sections}) option.  The
1557*a9fa9459Szrjdefault behaviour (of not listing the sections that are removed) can
1558*a9fa9459Szrjbe restored by specifying @samp{--no-print-gc-sections} on the command
1559*a9fa9459Szrjline.
1560*a9fa9459Szrj
1561*a9fa9459Szrj@kindex --print-output-format
1562*a9fa9459Szrj@cindex output format
1563*a9fa9459Szrj@item --print-output-format
1564*a9fa9459SzrjPrint the name of the default output format (perhaps influenced by
1565*a9fa9459Szrjother command-line options).  This is the string that would appear
1566*a9fa9459Szrjin an @code{OUTPUT_FORMAT} linker script command (@pxref{File Commands}).
1567*a9fa9459Szrj
1568*a9fa9459Szrj@kindex --print-memory-usage
1569*a9fa9459Szrj@cindex memory usage
1570*a9fa9459Szrj@item --print-memory-usage
1571*a9fa9459SzrjPrint used size, total size and used size of memory regions created with
1572*a9fa9459Szrjthe @ref{MEMORY} command.  This is useful on embedded targets to have a
1573*a9fa9459Szrjquick view of amount of free memory.  The format of the output has one
1574*a9fa9459Szrjheadline and one line per region.  It is both human readable and easily
1575*a9fa9459Szrjparsable by tools.  Here is an example of an output:
1576*a9fa9459Szrj
1577*a9fa9459Szrj@smallexample
1578*a9fa9459SzrjMemory region         Used Size  Region Size  %age Used
1579*a9fa9459Szrj             ROM:        256 KB         1 MB     25.00%
1580*a9fa9459Szrj             RAM:          32 B         2 GB      0.00%
1581*a9fa9459Szrj@end smallexample
1582*a9fa9459Szrj
1583*a9fa9459Szrj@cindex help
1584*a9fa9459Szrj@cindex usage
1585*a9fa9459Szrj@kindex --help
1586*a9fa9459Szrj@item --help
1587*a9fa9459SzrjPrint a summary of the command-line options on the standard output and exit.
1588*a9fa9459Szrj
1589*a9fa9459Szrj@kindex --target-help
1590*a9fa9459Szrj@item --target-help
1591*a9fa9459SzrjPrint a summary of all target specific options on the standard output and exit.
1592*a9fa9459Szrj
1593*a9fa9459Szrj@kindex -Map=@var{mapfile}
1594*a9fa9459Szrj@item -Map=@var{mapfile}
1595*a9fa9459SzrjPrint a link map to the file @var{mapfile}.  See the description of the
1596*a9fa9459Szrj@option{-M} option, above.
1597*a9fa9459Szrj
1598*a9fa9459Szrj@cindex memory usage
1599*a9fa9459Szrj@kindex --no-keep-memory
1600*a9fa9459Szrj@item --no-keep-memory
1601*a9fa9459Szrj@command{ld} normally optimizes for speed over memory usage by caching the
1602*a9fa9459Szrjsymbol tables of input files in memory.  This option tells @command{ld} to
1603*a9fa9459Szrjinstead optimize for memory usage, by rereading the symbol tables as
1604*a9fa9459Szrjnecessary.  This may be required if @command{ld} runs out of memory space
1605*a9fa9459Szrjwhile linking a large executable.
1606*a9fa9459Szrj
1607*a9fa9459Szrj@kindex --no-undefined
1608*a9fa9459Szrj@kindex -z defs
1609*a9fa9459Szrj@item --no-undefined
1610*a9fa9459Szrj@itemx -z defs
1611*a9fa9459SzrjReport unresolved symbol references from regular object files.  This
1612*a9fa9459Szrjis done even if the linker is creating a non-symbolic shared library.
1613*a9fa9459SzrjThe switch @option{--[no-]allow-shlib-undefined} controls the
1614*a9fa9459Szrjbehaviour for reporting unresolved references found in shared
1615*a9fa9459Szrjlibraries being linked in.
1616*a9fa9459Szrj
1617*a9fa9459Szrj@kindex --allow-multiple-definition
1618*a9fa9459Szrj@kindex -z muldefs
1619*a9fa9459Szrj@item --allow-multiple-definition
1620*a9fa9459Szrj@itemx -z muldefs
1621*a9fa9459SzrjNormally when a symbol is defined multiple times, the linker will
1622*a9fa9459Szrjreport a fatal error. These options allow multiple definitions and the
1623*a9fa9459Szrjfirst definition will be used.
1624*a9fa9459Szrj
1625*a9fa9459Szrj@kindex --allow-shlib-undefined
1626*a9fa9459Szrj@kindex --no-allow-shlib-undefined
1627*a9fa9459Szrj@item --allow-shlib-undefined
1628*a9fa9459Szrj@itemx --no-allow-shlib-undefined
1629*a9fa9459SzrjAllows or disallows undefined symbols in shared libraries.
1630*a9fa9459SzrjThis switch is similar to @option{--no-undefined} except that it
1631*a9fa9459Szrjdetermines the behaviour when the undefined symbols are in a
1632*a9fa9459Szrjshared library rather than a regular object file.  It does not affect
1633*a9fa9459Szrjhow undefined symbols in regular object files are handled.
1634*a9fa9459Szrj
1635*a9fa9459SzrjThe default behaviour is to report errors for any undefined symbols
1636*a9fa9459Szrjreferenced in shared libraries if the linker is being used to create
1637*a9fa9459Szrjan executable, but to allow them if the linker is being used to create
1638*a9fa9459Szrja shared library.
1639*a9fa9459Szrj
1640*a9fa9459SzrjThe reasons for allowing undefined symbol references in shared
1641*a9fa9459Szrjlibraries specified at link time are that:
1642*a9fa9459Szrj
1643*a9fa9459Szrj@itemize @bullet
1644*a9fa9459Szrj@item
1645*a9fa9459SzrjA shared library specified at link time may not be the same as the one
1646*a9fa9459Szrjthat is available at load time, so the symbol might actually be
1647*a9fa9459Szrjresolvable at load time.
1648*a9fa9459Szrj@item
1649*a9fa9459SzrjThere are some operating systems, eg BeOS and HPPA, where undefined
1650*a9fa9459Szrjsymbols in shared libraries are normal.
1651*a9fa9459Szrj
1652*a9fa9459SzrjThe BeOS kernel for example patches shared libraries at load time to
1653*a9fa9459Szrjselect whichever function is most appropriate for the current
1654*a9fa9459Szrjarchitecture.  This is used, for example, to dynamically select an
1655*a9fa9459Szrjappropriate memset function.
1656*a9fa9459Szrj@end itemize
1657*a9fa9459Szrj
1658*a9fa9459Szrj@kindex --no-undefined-version
1659*a9fa9459Szrj@item --no-undefined-version
1660*a9fa9459SzrjNormally when a symbol has an undefined version, the linker will ignore
1661*a9fa9459Szrjit. This option disallows symbols with undefined version and a fatal error
1662*a9fa9459Szrjwill be issued instead.
1663*a9fa9459Szrj
1664*a9fa9459Szrj@kindex --default-symver
1665*a9fa9459Szrj@item --default-symver
1666*a9fa9459SzrjCreate and use a default symbol version (the soname) for unversioned
1667*a9fa9459Szrjexported symbols.
1668*a9fa9459Szrj
1669*a9fa9459Szrj@kindex --default-imported-symver
1670*a9fa9459Szrj@item --default-imported-symver
1671*a9fa9459SzrjCreate and use a default symbol version (the soname) for unversioned
1672*a9fa9459Szrjimported symbols.
1673*a9fa9459Szrj
1674*a9fa9459Szrj@kindex --no-warn-mismatch
1675*a9fa9459Szrj@item --no-warn-mismatch
1676*a9fa9459SzrjNormally @command{ld} will give an error if you try to link together input
1677*a9fa9459Szrjfiles that are mismatched for some reason, perhaps because they have
1678*a9fa9459Szrjbeen compiled for different processors or for different endiannesses.
1679*a9fa9459SzrjThis option tells @command{ld} that it should silently permit such possible
1680*a9fa9459Szrjerrors.  This option should only be used with care, in cases when you
1681*a9fa9459Szrjhave taken some special action that ensures that the linker errors are
1682*a9fa9459Szrjinappropriate.
1683*a9fa9459Szrj
1684*a9fa9459Szrj@kindex --no-warn-search-mismatch
1685*a9fa9459Szrj@item --no-warn-search-mismatch
1686*a9fa9459SzrjNormally @command{ld} will give a warning if it finds an incompatible
1687*a9fa9459Szrjlibrary during a library search.  This option silences the warning.
1688*a9fa9459Szrj
1689*a9fa9459Szrj@kindex --no-whole-archive
1690*a9fa9459Szrj@item --no-whole-archive
1691*a9fa9459SzrjTurn off the effect of the @option{--whole-archive} option for subsequent
1692*a9fa9459Szrjarchive files.
1693*a9fa9459Szrj
1694*a9fa9459Szrj@cindex output file after errors
1695*a9fa9459Szrj@kindex --noinhibit-exec
1696*a9fa9459Szrj@item --noinhibit-exec
1697*a9fa9459SzrjRetain the executable output file whenever it is still usable.
1698*a9fa9459SzrjNormally, the linker will not produce an output file if it encounters
1699*a9fa9459Szrjerrors during the link process; it exits without writing an output file
1700*a9fa9459Szrjwhen it issues any error whatsoever.
1701*a9fa9459Szrj
1702*a9fa9459Szrj@kindex -nostdlib
1703*a9fa9459Szrj@item -nostdlib
1704*a9fa9459SzrjOnly search library directories explicitly specified on the
1705*a9fa9459Szrjcommand line.  Library directories specified in linker scripts
1706*a9fa9459Szrj(including linker scripts specified on the command line) are ignored.
1707*a9fa9459Szrj
1708*a9fa9459Szrj@ifclear SingleFormat
1709*a9fa9459Szrj@kindex --oformat=@var{output-format}
1710*a9fa9459Szrj@item --oformat=@var{output-format}
1711*a9fa9459Szrj@command{ld} may be configured to support more than one kind of object
1712*a9fa9459Szrjfile.  If your @command{ld} is configured this way, you can use the
1713*a9fa9459Szrj@samp{--oformat} option to specify the binary format for the output
1714*a9fa9459Szrjobject file.  Even when @command{ld} is configured to support alternative
1715*a9fa9459Szrjobject formats, you don't usually need to specify this, as @command{ld}
1716*a9fa9459Szrjshould be configured to produce as a default output format the most
1717*a9fa9459Szrjusual format on each machine.  @var{output-format} is a text string, the
1718*a9fa9459Szrjname of a particular format supported by the BFD libraries.  (You can
1719*a9fa9459Szrjlist the available binary formats with @samp{objdump -i}.)  The script
1720*a9fa9459Szrjcommand @code{OUTPUT_FORMAT} can also specify the output format, but
1721*a9fa9459Szrjthis option overrides it.  @xref{BFD}.
1722*a9fa9459Szrj@end ifclear
1723*a9fa9459Szrj
1724*a9fa9459Szrj@kindex -pie
1725*a9fa9459Szrj@kindex --pic-executable
1726*a9fa9459Szrj@item -pie
1727*a9fa9459Szrj@itemx --pic-executable
1728*a9fa9459Szrj@cindex position independent executables
1729*a9fa9459SzrjCreate a position independent executable.  This is currently only supported on
1730*a9fa9459SzrjELF platforms.  Position independent executables are similar to shared
1731*a9fa9459Szrjlibraries in that they are relocated by the dynamic linker to the virtual
1732*a9fa9459Szrjaddress the OS chooses for them (which can vary between invocations).  Like
1733*a9fa9459Szrjnormal dynamically linked executables they can be executed and symbols
1734*a9fa9459Szrjdefined in the executable cannot be overridden by shared libraries.
1735*a9fa9459Szrj
1736*a9fa9459Szrj@kindex -qmagic
1737*a9fa9459Szrj@item -qmagic
1738*a9fa9459SzrjThis option is ignored for Linux compatibility.
1739*a9fa9459Szrj
1740*a9fa9459Szrj@kindex -Qy
1741*a9fa9459Szrj@item -Qy
1742*a9fa9459SzrjThis option is ignored for SVR4 compatibility.
1743*a9fa9459Szrj
1744*a9fa9459Szrj@kindex --relax
1745*a9fa9459Szrj@cindex synthesizing linker
1746*a9fa9459Szrj@cindex relaxing addressing modes
1747*a9fa9459Szrj@cindex --no-relax
1748*a9fa9459Szrj@item --relax
1749*a9fa9459Szrj@itemx --no-relax
1750*a9fa9459SzrjAn option with machine dependent effects.
1751*a9fa9459Szrj@ifset GENERIC
1752*a9fa9459SzrjThis option is only supported on a few targets.
1753*a9fa9459Szrj@end ifset
1754*a9fa9459Szrj@ifset H8300
1755*a9fa9459Szrj@xref{H8/300,,@command{ld} and the H8/300}.
1756*a9fa9459Szrj@end ifset
1757*a9fa9459Szrj@ifset I960
1758*a9fa9459Szrj@xref{i960,, @command{ld} and the Intel 960 family}.
1759*a9fa9459Szrj@end ifset
1760*a9fa9459Szrj@ifset XTENSA
1761*a9fa9459Szrj@xref{Xtensa,, @command{ld} and Xtensa Processors}.
1762*a9fa9459Szrj@end ifset
1763*a9fa9459Szrj@ifset M68HC11
1764*a9fa9459Szrj@xref{M68HC11/68HC12,,@command{ld} and the 68HC11 and 68HC12}.
1765*a9fa9459Szrj@end ifset
1766*a9fa9459Szrj@ifset NIOSII
1767*a9fa9459Szrj@xref{Nios II,,@command{ld} and the Altera Nios II}.
1768*a9fa9459Szrj@end ifset
1769*a9fa9459Szrj@ifset POWERPC
1770*a9fa9459Szrj@xref{PowerPC ELF32,,@command{ld} and PowerPC 32-bit ELF Support}.
1771*a9fa9459Szrj@end ifset
1772*a9fa9459Szrj
1773*a9fa9459SzrjOn some platforms the @samp{--relax} option performs target specific,
1774*a9fa9459Szrjglobal optimizations that become possible when the linker resolves
1775*a9fa9459Szrjaddressing in the program, such as relaxing address modes,
1776*a9fa9459Szrjsynthesizing new instructions, selecting shorter version of current
1777*a9fa9459Szrjinstructions, and combining constant values.
1778*a9fa9459Szrj
1779*a9fa9459SzrjOn some platforms these link time global optimizations may make symbolic
1780*a9fa9459Szrjdebugging of the resulting executable impossible.
1781*a9fa9459Szrj@ifset GENERIC
1782*a9fa9459SzrjThis is known to be the case for the Matsushita MN10200 and MN10300
1783*a9fa9459Szrjfamily of processors.
1784*a9fa9459Szrj@end ifset
1785*a9fa9459Szrj
1786*a9fa9459Szrj@ifset GENERIC
1787*a9fa9459SzrjOn platforms where this is not supported, @samp{--relax} is accepted,
1788*a9fa9459Szrjbut ignored.
1789*a9fa9459Szrj@end ifset
1790*a9fa9459Szrj
1791*a9fa9459SzrjOn platforms where @samp{--relax} is accepted the option
1792*a9fa9459Szrj@samp{--no-relax} can be used to disable the feature.
1793*a9fa9459Szrj
1794*a9fa9459Szrj@cindex retaining specified symbols
1795*a9fa9459Szrj@cindex stripping all but some symbols
1796*a9fa9459Szrj@cindex symbols, retaining selectively
1797*a9fa9459Szrj@kindex --retain-symbols-file=@var{filename}
1798*a9fa9459Szrj@item --retain-symbols-file=@var{filename}
1799*a9fa9459SzrjRetain @emph{only} the symbols listed in the file @var{filename},
1800*a9fa9459Szrjdiscarding all others.  @var{filename} is simply a flat file, with one
1801*a9fa9459Szrjsymbol name per line.  This option is especially useful in environments
1802*a9fa9459Szrj@ifset GENERIC
1803*a9fa9459Szrj(such as VxWorks)
1804*a9fa9459Szrj@end ifset
1805*a9fa9459Szrjwhere a large global symbol table is accumulated gradually, to conserve
1806*a9fa9459Szrjrun-time memory.
1807*a9fa9459Szrj
1808*a9fa9459Szrj@samp{--retain-symbols-file} does @emph{not} discard undefined symbols,
1809*a9fa9459Szrjor symbols needed for relocations.
1810*a9fa9459Szrj
1811*a9fa9459SzrjYou may only specify @samp{--retain-symbols-file} once in the command
1812*a9fa9459Szrjline.  It overrides @samp{-s} and @samp{-S}.
1813*a9fa9459Szrj
1814*a9fa9459Szrj@ifset GENERIC
1815*a9fa9459Szrj@item -rpath=@var{dir}
1816*a9fa9459Szrj@cindex runtime library search path
1817*a9fa9459Szrj@kindex -rpath=@var{dir}
1818*a9fa9459SzrjAdd a directory to the runtime library search path.  This is used when
1819*a9fa9459Szrjlinking an ELF executable with shared objects.  All @option{-rpath}
1820*a9fa9459Szrjarguments are concatenated and passed to the runtime linker, which uses
1821*a9fa9459Szrjthem to locate shared objects at runtime.  The @option{-rpath} option is
1822*a9fa9459Szrjalso used when locating shared objects which are needed by shared
1823*a9fa9459Szrjobjects explicitly included in the link; see the description of the
1824*a9fa9459Szrj@option{-rpath-link} option.  If @option{-rpath} is not used when linking an
1825*a9fa9459SzrjELF executable, the contents of the environment variable
1826*a9fa9459Szrj@code{LD_RUN_PATH} will be used if it is defined.
1827*a9fa9459Szrj
1828*a9fa9459SzrjThe @option{-rpath} option may also be used on SunOS.  By default, on
1829*a9fa9459SzrjSunOS, the linker will form a runtime search path out of all the
1830*a9fa9459Szrj@option{-L} options it is given.  If a @option{-rpath} option is used, the
1831*a9fa9459Szrjruntime search path will be formed exclusively using the @option{-rpath}
1832*a9fa9459Szrjoptions, ignoring the @option{-L} options.  This can be useful when using
1833*a9fa9459Szrjgcc, which adds many @option{-L} options which may be on NFS mounted
1834*a9fa9459Szrjfile systems.
1835*a9fa9459Szrj
1836*a9fa9459SzrjFor compatibility with other ELF linkers, if the @option{-R} option is
1837*a9fa9459Szrjfollowed by a directory name, rather than a file name, it is treated as
1838*a9fa9459Szrjthe @option{-rpath} option.
1839*a9fa9459Szrj@end ifset
1840*a9fa9459Szrj
1841*a9fa9459Szrj@ifset GENERIC
1842*a9fa9459Szrj@cindex link-time runtime library search path
1843*a9fa9459Szrj@kindex -rpath-link=@var{dir}
1844*a9fa9459Szrj@item -rpath-link=@var{dir}
1845*a9fa9459SzrjWhen using ELF or SunOS, one shared library may require another.  This
1846*a9fa9459Szrjhappens when an @code{ld -shared} link includes a shared library as one
1847*a9fa9459Szrjof the input files.
1848*a9fa9459Szrj
1849*a9fa9459SzrjWhen the linker encounters such a dependency when doing a non-shared,
1850*a9fa9459Szrjnon-relocatable link, it will automatically try to locate the required
1851*a9fa9459Szrjshared library and include it in the link, if it is not included
1852*a9fa9459Szrjexplicitly.  In such a case, the @option{-rpath-link} option
1853*a9fa9459Szrjspecifies the first set of directories to search.  The
1854*a9fa9459Szrj@option{-rpath-link} option may specify a sequence of directory names
1855*a9fa9459Szrjeither by specifying a list of names separated by colons, or by
1856*a9fa9459Szrjappearing multiple times.
1857*a9fa9459Szrj
1858*a9fa9459SzrjThis option should be used with caution as it overrides the search path
1859*a9fa9459Szrjthat may have been hard compiled into a shared library. In such a case it
1860*a9fa9459Szrjis possible to use unintentionally a different search path than the
1861*a9fa9459Szrjruntime linker would do.
1862*a9fa9459Szrj
1863*a9fa9459SzrjThe linker uses the following search paths to locate required shared
1864*a9fa9459Szrjlibraries:
1865*a9fa9459Szrj@enumerate
1866*a9fa9459Szrj@item
1867*a9fa9459SzrjAny directories specified by @option{-rpath-link} options.
1868*a9fa9459Szrj@item
1869*a9fa9459SzrjAny directories specified by @option{-rpath} options.  The difference
1870*a9fa9459Szrjbetween @option{-rpath} and @option{-rpath-link} is that directories
1871*a9fa9459Szrjspecified by @option{-rpath} options are included in the executable and
1872*a9fa9459Szrjused at runtime, whereas the @option{-rpath-link} option is only effective
1873*a9fa9459Szrjat link time. Searching @option{-rpath} in this way is only supported
1874*a9fa9459Szrjby native linkers and cross linkers which have been configured with
1875*a9fa9459Szrjthe @option{--with-sysroot} option.
1876*a9fa9459Szrj@item
1877*a9fa9459SzrjOn an ELF system, for native linkers, if the @option{-rpath} and
1878*a9fa9459Szrj@option{-rpath-link} options were not used, search the contents of the
1879*a9fa9459Szrjenvironment variable @code{LD_RUN_PATH}.
1880*a9fa9459Szrj@item
1881*a9fa9459SzrjOn SunOS, if the @option{-rpath} option was not used, search any
1882*a9fa9459Szrjdirectories specified using @option{-L} options.
1883*a9fa9459Szrj@item
1884*a9fa9459SzrjFor a native linker, search the contents of the environment
1885*a9fa9459Szrjvariable @code{LD_LIBRARY_PATH}.
1886*a9fa9459Szrj@item
1887*a9fa9459SzrjFor a native ELF linker, the directories in @code{DT_RUNPATH} or
1888*a9fa9459Szrj@code{DT_RPATH} of a shared library are searched for shared
1889*a9fa9459Szrjlibraries needed by it. The @code{DT_RPATH} entries are ignored if
1890*a9fa9459Szrj@code{DT_RUNPATH} entries exist.
1891*a9fa9459Szrj@item
1892*a9fa9459SzrjThe default directories, normally @file{/lib} and @file{/usr/lib}.
1893*a9fa9459Szrj@item
1894*a9fa9459SzrjFor a native linker on an ELF system, if the file @file{/etc/ld.so.conf}
1895*a9fa9459Szrjexists, the list of directories found in that file.
1896*a9fa9459Szrj@end enumerate
1897*a9fa9459Szrj
1898*a9fa9459SzrjIf the required shared library is not found, the linker will issue a
1899*a9fa9459Szrjwarning and continue with the link.
1900*a9fa9459Szrj@end ifset
1901*a9fa9459Szrj
1902*a9fa9459Szrj@kindex -shared
1903*a9fa9459Szrj@kindex -Bshareable
1904*a9fa9459Szrj@item -shared
1905*a9fa9459Szrj@itemx -Bshareable
1906*a9fa9459Szrj@cindex shared libraries
1907*a9fa9459SzrjCreate a shared library.  This is currently only supported on ELF, XCOFF
1908*a9fa9459Szrjand SunOS platforms.  On SunOS, the linker will automatically create a
1909*a9fa9459Szrjshared library if the @option{-e} option is not used and there are
1910*a9fa9459Szrjundefined symbols in the link.
1911*a9fa9459Szrj
1912*a9fa9459Szrj@kindex --sort-common
1913*a9fa9459Szrj@item --sort-common
1914*a9fa9459Szrj@itemx --sort-common=ascending
1915*a9fa9459Szrj@itemx --sort-common=descending
1916*a9fa9459SzrjThis option tells @command{ld} to sort the common symbols by alignment in
1917*a9fa9459Szrjascending or descending order when it places them in the appropriate output
1918*a9fa9459Szrjsections.  The symbol alignments considered are sixteen-byte or larger,
1919*a9fa9459Szrjeight-byte, four-byte, two-byte, and one-byte. This is to prevent gaps
1920*a9fa9459Szrjbetween symbols due to alignment constraints.  If no sorting order is
1921*a9fa9459Szrjspecified, then descending order is assumed.
1922*a9fa9459Szrj
1923*a9fa9459Szrj@kindex --sort-section=name
1924*a9fa9459Szrj@item --sort-section=name
1925*a9fa9459SzrjThis option will apply @code{SORT_BY_NAME} to all wildcard section
1926*a9fa9459Szrjpatterns in the linker script.
1927*a9fa9459Szrj
1928*a9fa9459Szrj@kindex --sort-section=alignment
1929*a9fa9459Szrj@item --sort-section=alignment
1930*a9fa9459SzrjThis option will apply @code{SORT_BY_ALIGNMENT} to all wildcard section
1931*a9fa9459Szrjpatterns in the linker script.
1932*a9fa9459Szrj
1933*a9fa9459Szrj@kindex --split-by-file
1934*a9fa9459Szrj@item --split-by-file[=@var{size}]
1935*a9fa9459SzrjSimilar to @option{--split-by-reloc} but creates a new output section for
1936*a9fa9459Szrjeach input file when @var{size} is reached.  @var{size} defaults to a
1937*a9fa9459Szrjsize of 1 if not given.
1938*a9fa9459Szrj
1939*a9fa9459Szrj@kindex --split-by-reloc
1940*a9fa9459Szrj@item --split-by-reloc[=@var{count}]
1941*a9fa9459SzrjTries to creates extra sections in the output file so that no single
1942*a9fa9459Szrjoutput section in the file contains more than @var{count} relocations.
1943*a9fa9459SzrjThis is useful when generating huge relocatable files for downloading into
1944*a9fa9459Szrjcertain real time kernels with the COFF object file format; since COFF
1945*a9fa9459Szrjcannot represent more than 65535 relocations in a single section.  Note
1946*a9fa9459Szrjthat this will fail to work with object file formats which do not
1947*a9fa9459Szrjsupport arbitrary sections.  The linker will not split up individual
1948*a9fa9459Szrjinput sections for redistribution, so if a single input section contains
1949*a9fa9459Szrjmore than @var{count} relocations one output section will contain that
1950*a9fa9459Szrjmany relocations.  @var{count} defaults to a value of 32768.
1951*a9fa9459Szrj
1952*a9fa9459Szrj@kindex --stats
1953*a9fa9459Szrj@item --stats
1954*a9fa9459SzrjCompute and display statistics about the operation of the linker, such
1955*a9fa9459Szrjas execution time and memory usage.
1956*a9fa9459Szrj
1957*a9fa9459Szrj@kindex --sysroot=@var{directory}
1958*a9fa9459Szrj@item --sysroot=@var{directory}
1959*a9fa9459SzrjUse @var{directory} as the location of the sysroot, overriding the
1960*a9fa9459Szrjconfigure-time default.  This option is only supported by linkers
1961*a9fa9459Szrjthat were configured using @option{--with-sysroot}.
1962*a9fa9459Szrj
1963*a9fa9459Szrj@kindex --traditional-format
1964*a9fa9459Szrj@cindex traditional format
1965*a9fa9459Szrj@item --traditional-format
1966*a9fa9459SzrjFor some targets, the output of @command{ld} is different in some ways from
1967*a9fa9459Szrjthe output of some existing linker.  This switch requests @command{ld} to
1968*a9fa9459Szrjuse the traditional format instead.
1969*a9fa9459Szrj
1970*a9fa9459Szrj@cindex dbx
1971*a9fa9459SzrjFor example, on SunOS, @command{ld} combines duplicate entries in the
1972*a9fa9459Szrjsymbol string table.  This can reduce the size of an output file with
1973*a9fa9459Szrjfull debugging information by over 30 percent.  Unfortunately, the SunOS
1974*a9fa9459Szrj@code{dbx} program can not read the resulting program (@code{gdb} has no
1975*a9fa9459Szrjtrouble).  The @samp{--traditional-format} switch tells @command{ld} to not
1976*a9fa9459Szrjcombine duplicate entries.
1977*a9fa9459Szrj
1978*a9fa9459Szrj@kindex --section-start=@var{sectionname}=@var{org}
1979*a9fa9459Szrj@item --section-start=@var{sectionname}=@var{org}
1980*a9fa9459SzrjLocate a section in the output file at the absolute
1981*a9fa9459Szrjaddress given by @var{org}.  You may use this option as many
1982*a9fa9459Szrjtimes as necessary to locate multiple sections in the command
1983*a9fa9459Szrjline.
1984*a9fa9459Szrj@var{org} must be a single hexadecimal integer;
1985*a9fa9459Szrjfor compatibility with other linkers, you may omit the leading
1986*a9fa9459Szrj@samp{0x} usually associated with hexadecimal values.  @emph{Note:} there
1987*a9fa9459Szrjshould be no white space between @var{sectionname}, the equals
1988*a9fa9459Szrjsign (``@key{=}''), and @var{org}.
1989*a9fa9459Szrj
1990*a9fa9459Szrj@kindex -Tbss=@var{org}
1991*a9fa9459Szrj@kindex -Tdata=@var{org}
1992*a9fa9459Szrj@kindex -Ttext=@var{org}
1993*a9fa9459Szrj@cindex segment origins, cmd line
1994*a9fa9459Szrj@item -Tbss=@var{org}
1995*a9fa9459Szrj@itemx -Tdata=@var{org}
1996*a9fa9459Szrj@itemx -Ttext=@var{org}
1997*a9fa9459SzrjSame as @option{--section-start}, with @code{.bss}, @code{.data} or
1998*a9fa9459Szrj@code{.text} as the @var{sectionname}.
1999*a9fa9459Szrj
2000*a9fa9459Szrj@kindex -Ttext-segment=@var{org}
2001*a9fa9459Szrj@item -Ttext-segment=@var{org}
2002*a9fa9459Szrj@cindex text segment origin, cmd line
2003*a9fa9459SzrjWhen creating an ELF executable, it will set the address of the first
2004*a9fa9459Szrjbyte of the text segment.
2005*a9fa9459Szrj
2006*a9fa9459Szrj@kindex -Trodata-segment=@var{org}
2007*a9fa9459Szrj@item -Trodata-segment=@var{org}
2008*a9fa9459Szrj@cindex rodata segment origin, cmd line
2009*a9fa9459SzrjWhen creating an ELF executable or shared object for a target where
2010*a9fa9459Szrjthe read-only data is in its own segment separate from the executable
2011*a9fa9459Szrjtext, it will set the address of the first byte of the read-only data segment.
2012*a9fa9459Szrj
2013*a9fa9459Szrj@kindex -Tldata-segment=@var{org}
2014*a9fa9459Szrj@item -Tldata-segment=@var{org}
2015*a9fa9459Szrj@cindex ldata segment origin, cmd line
2016*a9fa9459SzrjWhen creating an ELF executable or shared object for x86-64 medium memory
2017*a9fa9459Szrjmodel, it will set the address of the first byte of the ldata segment.
2018*a9fa9459Szrj
2019*a9fa9459Szrj@kindex --unresolved-symbols
2020*a9fa9459Szrj@item --unresolved-symbols=@var{method}
2021*a9fa9459SzrjDetermine how to handle unresolved symbols.  There are four possible
2022*a9fa9459Szrjvalues for @samp{method}:
2023*a9fa9459Szrj
2024*a9fa9459Szrj@table @samp
2025*a9fa9459Szrj@item ignore-all
2026*a9fa9459SzrjDo not report any unresolved symbols.
2027*a9fa9459Szrj
2028*a9fa9459Szrj@item report-all
2029*a9fa9459SzrjReport all unresolved symbols.  This is the default.
2030*a9fa9459Szrj
2031*a9fa9459Szrj@item ignore-in-object-files
2032*a9fa9459SzrjReport unresolved symbols that are contained in shared libraries, but
2033*a9fa9459Szrjignore them if they come from regular object files.
2034*a9fa9459Szrj
2035*a9fa9459Szrj@item ignore-in-shared-libs
2036*a9fa9459SzrjReport unresolved symbols that come from regular object files, but
2037*a9fa9459Szrjignore them if they come from shared libraries.  This can be useful
2038*a9fa9459Szrjwhen creating a dynamic binary and it is known that all the shared
2039*a9fa9459Szrjlibraries that it should be referencing are included on the linker's
2040*a9fa9459Szrjcommand line.
2041*a9fa9459Szrj@end table
2042*a9fa9459Szrj
2043*a9fa9459SzrjThe behaviour for shared libraries on their own can also be controlled
2044*a9fa9459Szrjby the @option{--[no-]allow-shlib-undefined} option.
2045*a9fa9459Szrj
2046*a9fa9459SzrjNormally the linker will generate an error message for each reported
2047*a9fa9459Szrjunresolved symbol but the option @option{--warn-unresolved-symbols}
2048*a9fa9459Szrjcan change this to a warning.
2049*a9fa9459Szrj
2050*a9fa9459Szrj@kindex --verbose[=@var{NUMBER}]
2051*a9fa9459Szrj@cindex verbose[=@var{NUMBER}]
2052*a9fa9459Szrj@item --dll-verbose
2053*a9fa9459Szrj@itemx --verbose[=@var{NUMBER}]
2054*a9fa9459SzrjDisplay the version number for @command{ld} and list the linker emulations
2055*a9fa9459Szrjsupported.  Display which input files can and cannot be opened.  Display
2056*a9fa9459Szrjthe linker script being used by the linker. If the optional @var{NUMBER}
2057*a9fa9459Szrjargument > 1, plugin symbol status will also be displayed.
2058*a9fa9459Szrj
2059*a9fa9459Szrj@kindex --version-script=@var{version-scriptfile}
2060*a9fa9459Szrj@cindex version script, symbol versions
2061*a9fa9459Szrj@item --version-script=@var{version-scriptfile}
2062*a9fa9459SzrjSpecify the name of a version script to the linker.  This is typically
2063*a9fa9459Szrjused when creating shared libraries to specify additional information
2064*a9fa9459Szrjabout the version hierarchy for the library being created.  This option
2065*a9fa9459Szrjis only fully supported on ELF platforms which support shared libraries;
2066*a9fa9459Szrjsee @ref{VERSION}.  It is partially supported on PE platforms, which can
2067*a9fa9459Szrjuse version scripts to filter symbol visibility in auto-export mode: any
2068*a9fa9459Szrjsymbols marked @samp{local} in the version script will not be exported.
2069*a9fa9459Szrj@xref{WIN32}.
2070*a9fa9459Szrj
2071*a9fa9459Szrj@kindex --warn-common
2072*a9fa9459Szrj@cindex warnings, on combining symbols
2073*a9fa9459Szrj@cindex combining symbols, warnings on
2074*a9fa9459Szrj@item --warn-common
2075*a9fa9459SzrjWarn when a common symbol is combined with another common symbol or with
2076*a9fa9459Szrja symbol definition.  Unix linkers allow this somewhat sloppy practice,
2077*a9fa9459Szrjbut linkers on some other operating systems do not.  This option allows
2078*a9fa9459Szrjyou to find potential problems from combining global symbols.
2079*a9fa9459SzrjUnfortunately, some C libraries use this practice, so you may get some
2080*a9fa9459Szrjwarnings about symbols in the libraries as well as in your programs.
2081*a9fa9459Szrj
2082*a9fa9459SzrjThere are three kinds of global symbols, illustrated here by C examples:
2083*a9fa9459Szrj
2084*a9fa9459Szrj@table @samp
2085*a9fa9459Szrj@item int i = 1;
2086*a9fa9459SzrjA definition, which goes in the initialized data section of the output
2087*a9fa9459Szrjfile.
2088*a9fa9459Szrj
2089*a9fa9459Szrj@item extern int i;
2090*a9fa9459SzrjAn undefined reference, which does not allocate space.
2091*a9fa9459SzrjThere must be either a definition or a common symbol for the
2092*a9fa9459Szrjvariable somewhere.
2093*a9fa9459Szrj
2094*a9fa9459Szrj@item int i;
2095*a9fa9459SzrjA common symbol.  If there are only (one or more) common symbols for a
2096*a9fa9459Szrjvariable, it goes in the uninitialized data area of the output file.
2097*a9fa9459SzrjThe linker merges multiple common symbols for the same variable into a
2098*a9fa9459Szrjsingle symbol.  If they are of different sizes, it picks the largest
2099*a9fa9459Szrjsize.  The linker turns a common symbol into a declaration, if there is
2100*a9fa9459Szrja definition of the same variable.
2101*a9fa9459Szrj@end table
2102*a9fa9459Szrj
2103*a9fa9459SzrjThe @samp{--warn-common} option can produce five kinds of warnings.
2104*a9fa9459SzrjEach warning consists of a pair of lines: the first describes the symbol
2105*a9fa9459Szrjjust encountered, and the second describes the previous symbol
2106*a9fa9459Szrjencountered with the same name.  One or both of the two symbols will be
2107*a9fa9459Szrja common symbol.
2108*a9fa9459Szrj
2109*a9fa9459Szrj@enumerate
2110*a9fa9459Szrj@item
2111*a9fa9459SzrjTurning a common symbol into a reference, because there is already a
2112*a9fa9459Szrjdefinition for the symbol.
2113*a9fa9459Szrj@smallexample
2114*a9fa9459Szrj@var{file}(@var{section}): warning: common of `@var{symbol}'
2115*a9fa9459Szrj   overridden by definition
2116*a9fa9459Szrj@var{file}(@var{section}): warning: defined here
2117*a9fa9459Szrj@end smallexample
2118*a9fa9459Szrj
2119*a9fa9459Szrj@item
2120*a9fa9459SzrjTurning a common symbol into a reference, because a later definition for
2121*a9fa9459Szrjthe symbol is encountered.  This is the same as the previous case,
2122*a9fa9459Szrjexcept that the symbols are encountered in a different order.
2123*a9fa9459Szrj@smallexample
2124*a9fa9459Szrj@var{file}(@var{section}): warning: definition of `@var{symbol}'
2125*a9fa9459Szrj   overriding common
2126*a9fa9459Szrj@var{file}(@var{section}): warning: common is here
2127*a9fa9459Szrj@end smallexample
2128*a9fa9459Szrj
2129*a9fa9459Szrj@item
2130*a9fa9459SzrjMerging a common symbol with a previous same-sized common symbol.
2131*a9fa9459Szrj@smallexample
2132*a9fa9459Szrj@var{file}(@var{section}): warning: multiple common
2133*a9fa9459Szrj   of `@var{symbol}'
2134*a9fa9459Szrj@var{file}(@var{section}): warning: previous common is here
2135*a9fa9459Szrj@end smallexample
2136*a9fa9459Szrj
2137*a9fa9459Szrj@item
2138*a9fa9459SzrjMerging a common symbol with a previous larger common symbol.
2139*a9fa9459Szrj@smallexample
2140*a9fa9459Szrj@var{file}(@var{section}): warning: common of `@var{symbol}'
2141*a9fa9459Szrj   overridden by larger common
2142*a9fa9459Szrj@var{file}(@var{section}): warning: larger common is here
2143*a9fa9459Szrj@end smallexample
2144*a9fa9459Szrj
2145*a9fa9459Szrj@item
2146*a9fa9459SzrjMerging a common symbol with a previous smaller common symbol.  This is
2147*a9fa9459Szrjthe same as the previous case, except that the symbols are
2148*a9fa9459Szrjencountered in a different order.
2149*a9fa9459Szrj@smallexample
2150*a9fa9459Szrj@var{file}(@var{section}): warning: common of `@var{symbol}'
2151*a9fa9459Szrj   overriding smaller common
2152*a9fa9459Szrj@var{file}(@var{section}): warning: smaller common is here
2153*a9fa9459Szrj@end smallexample
2154*a9fa9459Szrj@end enumerate
2155*a9fa9459Szrj
2156*a9fa9459Szrj@kindex --warn-constructors
2157*a9fa9459Szrj@item --warn-constructors
2158*a9fa9459SzrjWarn if any global constructors are used.  This is only useful for a few
2159*a9fa9459Szrjobject file formats.  For formats like COFF or ELF, the linker can not
2160*a9fa9459Szrjdetect the use of global constructors.
2161*a9fa9459Szrj
2162*a9fa9459Szrj@kindex --warn-multiple-gp
2163*a9fa9459Szrj@item --warn-multiple-gp
2164*a9fa9459SzrjWarn if multiple global pointer values are required in the output file.
2165*a9fa9459SzrjThis is only meaningful for certain processors, such as the Alpha.
2166*a9fa9459SzrjSpecifically, some processors put large-valued constants in a special
2167*a9fa9459Szrjsection.  A special register (the global pointer) points into the middle
2168*a9fa9459Szrjof this section, so that constants can be loaded efficiently via a
2169*a9fa9459Szrjbase-register relative addressing mode.  Since the offset in
2170*a9fa9459Szrjbase-register relative mode is fixed and relatively small (e.g., 16
2171*a9fa9459Szrjbits), this limits the maximum size of the constant pool.  Thus, in
2172*a9fa9459Szrjlarge programs, it is often necessary to use multiple global pointer
2173*a9fa9459Szrjvalues in order to be able to address all possible constants.  This
2174*a9fa9459Szrjoption causes a warning to be issued whenever this case occurs.
2175*a9fa9459Szrj
2176*a9fa9459Szrj@kindex --warn-once
2177*a9fa9459Szrj@cindex warnings, on undefined symbols
2178*a9fa9459Szrj@cindex undefined symbols, warnings on
2179*a9fa9459Szrj@item --warn-once
2180*a9fa9459SzrjOnly warn once for each undefined symbol, rather than once per module
2181*a9fa9459Szrjwhich refers to it.
2182*a9fa9459Szrj
2183*a9fa9459Szrj@kindex --warn-section-align
2184*a9fa9459Szrj@cindex warnings, on section alignment
2185*a9fa9459Szrj@cindex section alignment, warnings on
2186*a9fa9459Szrj@item --warn-section-align
2187*a9fa9459SzrjWarn if the address of an output section is changed because of
2188*a9fa9459Szrjalignment.  Typically, the alignment will be set by an input section.
2189*a9fa9459SzrjThe address will only be changed if it not explicitly specified; that
2190*a9fa9459Szrjis, if the @code{SECTIONS} command does not specify a start address for
2191*a9fa9459Szrjthe section (@pxref{SECTIONS}).
2192*a9fa9459Szrj
2193*a9fa9459Szrj@kindex --warn-shared-textrel
2194*a9fa9459Szrj@item --warn-shared-textrel
2195*a9fa9459SzrjWarn if the linker adds a DT_TEXTREL to a shared object.
2196*a9fa9459Szrj
2197*a9fa9459Szrj@kindex --warn-alternate-em
2198*a9fa9459Szrj@item --warn-alternate-em
2199*a9fa9459SzrjWarn if an object has alternate ELF machine code.
2200*a9fa9459Szrj
2201*a9fa9459Szrj@kindex --warn-unresolved-symbols
2202*a9fa9459Szrj@item --warn-unresolved-symbols
2203*a9fa9459SzrjIf the linker is going to report an unresolved symbol (see the option
2204*a9fa9459Szrj@option{--unresolved-symbols}) it will normally generate an error.
2205*a9fa9459SzrjThis option makes it generate a warning instead.
2206*a9fa9459Szrj
2207*a9fa9459Szrj@kindex --error-unresolved-symbols
2208*a9fa9459Szrj@item --error-unresolved-symbols
2209*a9fa9459SzrjThis restores the linker's default behaviour of generating errors when
2210*a9fa9459Szrjit is reporting unresolved symbols.
2211*a9fa9459Szrj
2212*a9fa9459Szrj@kindex --whole-archive
2213*a9fa9459Szrj@cindex including an entire archive
2214*a9fa9459Szrj@item --whole-archive
2215*a9fa9459SzrjFor each archive mentioned on the command line after the
2216*a9fa9459Szrj@option{--whole-archive} option, include every object file in the archive
2217*a9fa9459Szrjin the link, rather than searching the archive for the required object
2218*a9fa9459Szrjfiles.  This is normally used to turn an archive file into a shared
2219*a9fa9459Szrjlibrary, forcing every object to be included in the resulting shared
2220*a9fa9459Szrjlibrary.  This option may be used more than once.
2221*a9fa9459Szrj
2222*a9fa9459SzrjTwo notes when using this option from gcc: First, gcc doesn't know
2223*a9fa9459Szrjabout this option, so you have to use @option{-Wl,-whole-archive}.
2224*a9fa9459SzrjSecond, don't forget to use @option{-Wl,-no-whole-archive} after your
2225*a9fa9459Szrjlist of archives, because gcc will add its own list of archives to
2226*a9fa9459Szrjyour link and you may not want this flag to affect those as well.
2227*a9fa9459Szrj
2228*a9fa9459Szrj@kindex --wrap=@var{symbol}
2229*a9fa9459Szrj@item --wrap=@var{symbol}
2230*a9fa9459SzrjUse a wrapper function for @var{symbol}.  Any undefined reference to
2231*a9fa9459Szrj@var{symbol} will be resolved to @code{__wrap_@var{symbol}}.  Any
2232*a9fa9459Szrjundefined reference to @code{__real_@var{symbol}} will be resolved to
2233*a9fa9459Szrj@var{symbol}.
2234*a9fa9459Szrj
2235*a9fa9459SzrjThis can be used to provide a wrapper for a system function.  The
2236*a9fa9459Szrjwrapper function should be called @code{__wrap_@var{symbol}}.  If it
2237*a9fa9459Szrjwishes to call the system function, it should call
2238*a9fa9459Szrj@code{__real_@var{symbol}}.
2239*a9fa9459Szrj
2240*a9fa9459SzrjHere is a trivial example:
2241*a9fa9459Szrj
2242*a9fa9459Szrj@smallexample
2243*a9fa9459Szrjvoid *
2244*a9fa9459Szrj__wrap_malloc (size_t c)
2245*a9fa9459Szrj@{
2246*a9fa9459Szrj  printf ("malloc called with %zu\n", c);
2247*a9fa9459Szrj  return __real_malloc (c);
2248*a9fa9459Szrj@}
2249*a9fa9459Szrj@end smallexample
2250*a9fa9459Szrj
2251*a9fa9459SzrjIf you link other code with this file using @option{--wrap malloc}, then
2252*a9fa9459Szrjall calls to @code{malloc} will call the function @code{__wrap_malloc}
2253*a9fa9459Szrjinstead.  The call to @code{__real_malloc} in @code{__wrap_malloc} will
2254*a9fa9459Szrjcall the real @code{malloc} function.
2255*a9fa9459Szrj
2256*a9fa9459SzrjYou may wish to provide a @code{__real_malloc} function as well, so that
2257*a9fa9459Szrjlinks without the @option{--wrap} option will succeed.  If you do this,
2258*a9fa9459Szrjyou should not put the definition of @code{__real_malloc} in the same
2259*a9fa9459Szrjfile as @code{__wrap_malloc}; if you do, the assembler may resolve the
2260*a9fa9459Szrjcall before the linker has a chance to wrap it to @code{malloc}.
2261*a9fa9459Szrj
2262*a9fa9459Szrj@kindex --eh-frame-hdr
2263*a9fa9459Szrj@item --eh-frame-hdr
2264*a9fa9459SzrjRequest creation of @code{.eh_frame_hdr} section and ELF
2265*a9fa9459Szrj@code{PT_GNU_EH_FRAME} segment header.
2266*a9fa9459Szrj
2267*a9fa9459Szrj@kindex --ld-generated-unwind-info
2268*a9fa9459Szrj@item --no-ld-generated-unwind-info
2269*a9fa9459SzrjRequest creation of @code{.eh_frame} unwind info for linker
2270*a9fa9459Szrjgenerated code sections like PLT.  This option is on by default
2271*a9fa9459Szrjif linker generated unwind info is supported.
2272*a9fa9459Szrj
2273*a9fa9459Szrj@kindex --enable-new-dtags
2274*a9fa9459Szrj@kindex --disable-new-dtags
2275*a9fa9459Szrj@item --enable-new-dtags
2276*a9fa9459Szrj@itemx --disable-new-dtags
2277*a9fa9459SzrjThis linker can create the new dynamic tags in ELF. But the older ELF
2278*a9fa9459Szrjsystems may not understand them. If you specify
2279*a9fa9459Szrj@option{--enable-new-dtags}, the new dynamic tags will be created as needed
2280*a9fa9459Szrjand older dynamic tags will be omitted.
2281*a9fa9459SzrjIf you specify @option{--disable-new-dtags}, no new dynamic tags will be
2282*a9fa9459Szrjcreated. By default, the new dynamic tags are not created. Note that
2283*a9fa9459Szrjthose options are only available for ELF systems.
2284*a9fa9459Szrj
2285*a9fa9459Szrj@kindex --hash-size=@var{number}
2286*a9fa9459Szrj@item --hash-size=@var{number}
2287*a9fa9459SzrjSet the default size of the linker's hash tables to a prime number
2288*a9fa9459Szrjclose to @var{number}.  Increasing this value can reduce the length of
2289*a9fa9459Szrjtime it takes the linker to perform its tasks, at the expense of
2290*a9fa9459Szrjincreasing the linker's memory requirements.  Similarly reducing this
2291*a9fa9459Szrjvalue can reduce the memory requirements at the expense of speed.
2292*a9fa9459Szrj
2293*a9fa9459Szrj@kindex --hash-style=@var{style}
2294*a9fa9459Szrj@item --hash-style=@var{style}
2295*a9fa9459SzrjSet the type of linker's hash table(s).  @var{style} can be either
2296*a9fa9459Szrj@code{sysv} for classic ELF @code{.hash} section, @code{gnu} for
2297*a9fa9459Szrjnew style GNU @code{.gnu.hash} section or @code{both} for both
2298*a9fa9459Szrjthe classic ELF @code{.hash} and new style GNU @code{.gnu.hash}
2299*a9fa9459Szrjhash tables.  The default is @code{sysv}.
2300*a9fa9459Szrj
2301*a9fa9459Szrj@kindex --compress-debug-sections=none
2302*a9fa9459Szrj@kindex --compress-debug-sections=zlib
2303*a9fa9459Szrj@kindex --compress-debug-sections=zlib-gnu
2304*a9fa9459Szrj@kindex --compress-debug-sections=zlib-gabi
2305*a9fa9459Szrj@item --compress-debug-sections=none
2306*a9fa9459Szrj@itemx --compress-debug-sections=zlib
2307*a9fa9459Szrj@itemx --compress-debug-sections=zlib-gnu
2308*a9fa9459Szrj@itemx --compress-debug-sections=zlib-gabi
2309*a9fa9459SzrjOn ELF platforms , these options control how DWARF debug sections are
2310*a9fa9459Szrjcompressed using zlib.  @option{--compress-debug-sections=none} doesn't
2311*a9fa9459Szrjcompress DWARF debug sections.
2312*a9fa9459Szrj@option{--compress-debug-sections=zlib-gnu} compresses DWARF debug
2313*a9fa9459Szrjsections and rename debug section names to begin with @samp{.zdebug}
2314*a9fa9459Szrjinstead of @samp{.debug}.  @option{--compress-debug-sections=zlib}
2315*a9fa9459Szrjand @option{--compress-debug-sections=zlib-gabi}
2316*a9fa9459Szrjcompress DWARF debug sections with SHF_COMPRESSED from the ELF ABI.
2317*a9fa9459SzrjThe default behaviour varies depending upon the target involved and
2318*a9fa9459Szrjthe configure options used to build the toolchain.  The default can be
2319*a9fa9459Szrjdetermined by examing the output from the linker's @option{--help} option.
2320*a9fa9459Szrj
2321*a9fa9459Szrj@kindex --reduce-memory-overheads
2322*a9fa9459Szrj@item --reduce-memory-overheads
2323*a9fa9459SzrjThis option reduces memory requirements at ld runtime, at the expense of
2324*a9fa9459Szrjlinking speed.  This was introduced to select the old O(n^2) algorithm
2325*a9fa9459Szrjfor link map file generation, rather than the new O(n) algorithm which uses
2326*a9fa9459Szrjabout 40% more memory for symbol storage.
2327*a9fa9459Szrj
2328*a9fa9459SzrjAnother effect of the switch is to set the default hash table size to
2329*a9fa9459Szrj1021, which again saves memory at the cost of lengthening the linker's
2330*a9fa9459Szrjrun time.  This is not done however if the @option{--hash-size} switch
2331*a9fa9459Szrjhas been used.
2332*a9fa9459Szrj
2333*a9fa9459SzrjThe @option{--reduce-memory-overheads} switch may be also be used to
2334*a9fa9459Szrjenable other tradeoffs in future versions of the linker.
2335*a9fa9459Szrj
2336*a9fa9459Szrj@kindex --build-id
2337*a9fa9459Szrj@kindex --build-id=@var{style}
2338*a9fa9459Szrj@item --build-id
2339*a9fa9459Szrj@itemx --build-id=@var{style}
2340*a9fa9459SzrjRequest the creation of a @code{.note.gnu.build-id} ELF note section
2341*a9fa9459Szrjor a @code{.buildid} COFF section.  The contents of the note are
2342*a9fa9459Szrjunique bits identifying this linked file.  @var{style} can be
2343*a9fa9459Szrj@code{uuid} to use 128 random bits, @code{sha1} to use a 160-bit
2344*a9fa9459Szrj@sc{SHA1} hash on the normative parts of the output contents,
2345*a9fa9459Szrj@code{md5} to use a 128-bit @sc{MD5} hash on the normative parts of
2346*a9fa9459Szrjthe output contents, or @code{0x@var{hexstring}} to use a chosen bit
2347*a9fa9459Szrjstring specified as an even number of hexadecimal digits (@code{-} and
2348*a9fa9459Szrj@code{:} characters between digit pairs are ignored).  If @var{style}
2349*a9fa9459Szrjis omitted, @code{sha1} is used.
2350*a9fa9459Szrj
2351*a9fa9459SzrjThe @code{md5} and @code{sha1} styles produces an identifier
2352*a9fa9459Szrjthat is always the same in an identical output file, but will be
2353*a9fa9459Szrjunique among all nonidentical output files.  It is not intended
2354*a9fa9459Szrjto be compared as a checksum for the file's contents.  A linked
2355*a9fa9459Szrjfile may be changed later by other tools, but the build ID bit
2356*a9fa9459Szrjstring identifying the original linked file does not change.
2357*a9fa9459Szrj
2358*a9fa9459SzrjPassing @code{none} for @var{style} disables the setting from any
2359*a9fa9459Szrj@code{--build-id} options earlier on the command line.
2360*a9fa9459Szrj@end table
2361*a9fa9459Szrj
2362*a9fa9459Szrj@c man end
2363*a9fa9459Szrj
2364*a9fa9459Szrj@subsection Options Specific to i386 PE Targets
2365*a9fa9459Szrj
2366*a9fa9459Szrj@c man begin OPTIONS
2367*a9fa9459Szrj
2368*a9fa9459SzrjThe i386 PE linker supports the @option{-shared} option, which causes
2369*a9fa9459Szrjthe output to be a dynamically linked library (DLL) instead of a
2370*a9fa9459Szrjnormal executable.  You should name the output @code{*.dll} when you
2371*a9fa9459Szrjuse this option.  In addition, the linker fully supports the standard
2372*a9fa9459Szrj@code{*.def} files, which may be specified on the linker command line
2373*a9fa9459Szrjlike an object file (in fact, it should precede archives it exports
2374*a9fa9459Szrjsymbols from, to ensure that they get linked in, just like a normal
2375*a9fa9459Szrjobject file).
2376*a9fa9459Szrj
2377*a9fa9459SzrjIn addition to the options common to all targets, the i386 PE linker
2378*a9fa9459Szrjsupport additional command line options that are specific to the i386
2379*a9fa9459SzrjPE target.  Options that take values may be separated from their
2380*a9fa9459Szrjvalues by either a space or an equals sign.
2381*a9fa9459Szrj
2382*a9fa9459Szrj@table @gcctabopt
2383*a9fa9459Szrj
2384*a9fa9459Szrj@kindex --add-stdcall-alias
2385*a9fa9459Szrj@item --add-stdcall-alias
2386*a9fa9459SzrjIf given, symbols with a stdcall suffix (@@@var{nn}) will be exported
2387*a9fa9459Szrjas-is and also with the suffix stripped.
2388*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2389*a9fa9459Szrj
2390*a9fa9459Szrj@kindex --base-file
2391*a9fa9459Szrj@item --base-file @var{file}
2392*a9fa9459SzrjUse @var{file} as the name of a file in which to save the base
2393*a9fa9459Szrjaddresses of all the relocations needed for generating DLLs with
2394*a9fa9459Szrj@file{dlltool}.
2395*a9fa9459Szrj[This is an i386 PE specific option]
2396*a9fa9459Szrj
2397*a9fa9459Szrj@kindex --dll
2398*a9fa9459Szrj@item --dll
2399*a9fa9459SzrjCreate a DLL instead of a regular executable.  You may also use
2400*a9fa9459Szrj@option{-shared} or specify a @code{LIBRARY} in a given @code{.def}
2401*a9fa9459Szrjfile.
2402*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2403*a9fa9459Szrj
2404*a9fa9459Szrj@kindex --enable-long-section-names
2405*a9fa9459Szrj@kindex --disable-long-section-names
2406*a9fa9459Szrj@item --enable-long-section-names
2407*a9fa9459Szrj@itemx --disable-long-section-names
2408*a9fa9459SzrjThe PE variants of the COFF object format add an extension that permits
2409*a9fa9459Szrjthe use of section names longer than eight characters, the normal limit
2410*a9fa9459Szrjfor COFF.  By default, these names are only allowed in object files, as
2411*a9fa9459Szrjfully-linked executable images do not carry the COFF string table required
2412*a9fa9459Szrjto support the longer names.  As a GNU extension, it is possible to
2413*a9fa9459Szrjallow their use in executable images as well, or to (probably pointlessly!)
2414*a9fa9459Szrjdisallow it in object files, by using these two options.  Executable images
2415*a9fa9459Szrjgenerated with these long section names are slightly non-standard, carrying
2416*a9fa9459Szrjas they do a string table, and may generate confusing output when examined
2417*a9fa9459Szrjwith non-GNU PE-aware tools, such as file viewers and dumpers.  However,
2418*a9fa9459SzrjGDB relies on the use of PE long section names to find Dwarf-2 debug
2419*a9fa9459Szrjinformation sections in an executable image at runtime, and so if neither
2420*a9fa9459Szrjoption is specified on the command-line, @command{ld} will enable long
2421*a9fa9459Szrjsection names, overriding the default and technically correct behaviour,
2422*a9fa9459Szrjwhen it finds the presence of debug information while linking an executable
2423*a9fa9459Szrjimage and not stripping symbols.
2424*a9fa9459Szrj[This option is valid for all PE targeted ports of the linker]
2425*a9fa9459Szrj
2426*a9fa9459Szrj@kindex --enable-stdcall-fixup
2427*a9fa9459Szrj@kindex --disable-stdcall-fixup
2428*a9fa9459Szrj@item --enable-stdcall-fixup
2429*a9fa9459Szrj@itemx --disable-stdcall-fixup
2430*a9fa9459SzrjIf the link finds a symbol that it cannot resolve, it will attempt to
2431*a9fa9459Szrjdo ``fuzzy linking'' by looking for another defined symbol that differs
2432*a9fa9459Szrjonly in the format of the symbol name (cdecl vs stdcall) and will
2433*a9fa9459Szrjresolve that symbol by linking to the match.  For example, the
2434*a9fa9459Szrjundefined symbol @code{_foo} might be linked to the function
2435*a9fa9459Szrj@code{_foo@@12}, or the undefined symbol @code{_bar@@16} might be linked
2436*a9fa9459Szrjto the function @code{_bar}.  When the linker does this, it prints a
2437*a9fa9459Szrjwarning, since it normally should have failed to link, but sometimes
2438*a9fa9459Szrjimport libraries generated from third-party dlls may need this feature
2439*a9fa9459Szrjto be usable.  If you specify @option{--enable-stdcall-fixup}, this
2440*a9fa9459Szrjfeature is fully enabled and warnings are not printed.  If you specify
2441*a9fa9459Szrj@option{--disable-stdcall-fixup}, this feature is disabled and such
2442*a9fa9459Szrjmismatches are considered to be errors.
2443*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2444*a9fa9459Szrj
2445*a9fa9459Szrj@kindex --leading-underscore
2446*a9fa9459Szrj@kindex --no-leading-underscore
2447*a9fa9459Szrj@item --leading-underscore
2448*a9fa9459Szrj@itemx --no-leading-underscore
2449*a9fa9459SzrjFor most targets default symbol-prefix is an underscore and is defined
2450*a9fa9459Szrjin target's description. By this option it is possible to
2451*a9fa9459Szrjdisable/enable the default underscore symbol-prefix.
2452*a9fa9459Szrj
2453*a9fa9459Szrj@cindex DLLs, creating
2454*a9fa9459Szrj@kindex --export-all-symbols
2455*a9fa9459Szrj@item --export-all-symbols
2456*a9fa9459SzrjIf given, all global symbols in the objects used to build a DLL will
2457*a9fa9459Szrjbe exported by the DLL.  Note that this is the default if there
2458*a9fa9459Szrjotherwise wouldn't be any exported symbols.  When symbols are
2459*a9fa9459Szrjexplicitly exported via DEF files or implicitly exported via function
2460*a9fa9459Szrjattributes, the default is to not export anything else unless this
2461*a9fa9459Szrjoption is given.  Note that the symbols @code{DllMain@@12},
2462*a9fa9459Szrj@code{DllEntryPoint@@0}, @code{DllMainCRTStartup@@12}, and
2463*a9fa9459Szrj@code{impure_ptr} will not be automatically
2464*a9fa9459Szrjexported.  Also, symbols imported from other DLLs will not be
2465*a9fa9459Szrjre-exported, nor will symbols specifying the DLL's internal layout
2466*a9fa9459Szrjsuch as those beginning with @code{_head_} or ending with
2467*a9fa9459Szrj@code{_iname}.  In addition, no symbols from @code{libgcc},
2468*a9fa9459Szrj@code{libstd++}, @code{libmingw32}, or @code{crtX.o} will be exported.
2469*a9fa9459SzrjSymbols whose names begin with @code{__rtti_} or @code{__builtin_} will
2470*a9fa9459Szrjnot be exported, to help with C++ DLLs.  Finally, there is an
2471*a9fa9459Szrjextensive list of cygwin-private symbols that are not exported
2472*a9fa9459Szrj(obviously, this applies on when building DLLs for cygwin targets).
2473*a9fa9459SzrjThese cygwin-excludes are: @code{_cygwin_dll_entry@@12},
2474*a9fa9459Szrj@code{_cygwin_crt0_common@@8}, @code{_cygwin_noncygwin_dll_entry@@12},
2475*a9fa9459Szrj@code{_fmode}, @code{_impure_ptr}, @code{cygwin_attach_dll},
2476*a9fa9459Szrj@code{cygwin_premain0}, @code{cygwin_premain1}, @code{cygwin_premain2},
2477*a9fa9459Szrj@code{cygwin_premain3}, and @code{environ}.
2478*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2479*a9fa9459Szrj
2480*a9fa9459Szrj@kindex --exclude-symbols
2481*a9fa9459Szrj@item --exclude-symbols @var{symbol},@var{symbol},...
2482*a9fa9459SzrjSpecifies a list of symbols which should not be automatically
2483*a9fa9459Szrjexported.  The symbol names may be delimited by commas or colons.
2484*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2485*a9fa9459Szrj
2486*a9fa9459Szrj@kindex --exclude-all-symbols
2487*a9fa9459Szrj@item --exclude-all-symbols
2488*a9fa9459SzrjSpecifies no symbols should be automatically exported.
2489*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2490*a9fa9459Szrj
2491*a9fa9459Szrj@kindex --file-alignment
2492*a9fa9459Szrj@item --file-alignment
2493*a9fa9459SzrjSpecify the file alignment.  Sections in the file will always begin at
2494*a9fa9459Szrjfile offsets which are multiples of this number.  This defaults to
2495*a9fa9459Szrj512.
2496*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2497*a9fa9459Szrj
2498*a9fa9459Szrj@cindex heap size
2499*a9fa9459Szrj@kindex --heap
2500*a9fa9459Szrj@item --heap @var{reserve}
2501*a9fa9459Szrj@itemx --heap @var{reserve},@var{commit}
2502*a9fa9459SzrjSpecify the number of bytes of memory to reserve (and optionally commit)
2503*a9fa9459Szrjto be used as heap for this program.  The default is 1MB reserved, 4K
2504*a9fa9459Szrjcommitted.
2505*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2506*a9fa9459Szrj
2507*a9fa9459Szrj@cindex image base
2508*a9fa9459Szrj@kindex --image-base
2509*a9fa9459Szrj@item --image-base @var{value}
2510*a9fa9459SzrjUse @var{value} as the base address of your program or dll.  This is
2511*a9fa9459Szrjthe lowest memory location that will be used when your program or dll
2512*a9fa9459Szrjis loaded.  To reduce the need to relocate and improve performance of
2513*a9fa9459Szrjyour dlls, each should have a unique base address and not overlap any
2514*a9fa9459Szrjother dlls.  The default is 0x400000 for executables, and 0x10000000
2515*a9fa9459Szrjfor dlls.
2516*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2517*a9fa9459Szrj
2518*a9fa9459Szrj@kindex --kill-at
2519*a9fa9459Szrj@item --kill-at
2520*a9fa9459SzrjIf given, the stdcall suffixes (@@@var{nn}) will be stripped from
2521*a9fa9459Szrjsymbols before they are exported.
2522*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2523*a9fa9459Szrj
2524*a9fa9459Szrj@kindex --large-address-aware
2525*a9fa9459Szrj@item --large-address-aware
2526*a9fa9459SzrjIf given, the appropriate bit in the ``Characteristics'' field of the COFF
2527*a9fa9459Szrjheader is set to indicate that this executable supports virtual addresses
2528*a9fa9459Szrjgreater than 2 gigabytes.  This should be used in conjunction with the /3GB
2529*a9fa9459Szrjor /USERVA=@var{value} megabytes switch in the ``[operating systems]''
2530*a9fa9459Szrjsection of the BOOT.INI.  Otherwise, this bit has no effect.
2531*a9fa9459Szrj[This option is specific to PE targeted ports of the linker]
2532*a9fa9459Szrj
2533*a9fa9459Szrj@kindex --disable-large-address-aware
2534*a9fa9459Szrj@item --disable-large-address-aware
2535*a9fa9459SzrjReverts the effect of a previous @samp{--large-address-aware} option.
2536*a9fa9459SzrjThis is useful if @samp{--large-address-aware} is always set by the compiler
2537*a9fa9459Szrjdriver (e.g. Cygwin gcc) and the executable does not support virtual
2538*a9fa9459Szrjaddresses greater than 2 gigabytes.
2539*a9fa9459Szrj[This option is specific to PE targeted ports of the linker]
2540*a9fa9459Szrj
2541*a9fa9459Szrj@kindex --major-image-version
2542*a9fa9459Szrj@item --major-image-version @var{value}
2543*a9fa9459SzrjSets the major number of the ``image version''.  Defaults to 1.
2544*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2545*a9fa9459Szrj
2546*a9fa9459Szrj@kindex --major-os-version
2547*a9fa9459Szrj@item --major-os-version @var{value}
2548*a9fa9459SzrjSets the major number of the ``os version''.  Defaults to 4.
2549*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2550*a9fa9459Szrj
2551*a9fa9459Szrj@kindex --major-subsystem-version
2552*a9fa9459Szrj@item --major-subsystem-version @var{value}
2553*a9fa9459SzrjSets the major number of the ``subsystem version''.  Defaults to 4.
2554*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2555*a9fa9459Szrj
2556*a9fa9459Szrj@kindex --minor-image-version
2557*a9fa9459Szrj@item --minor-image-version @var{value}
2558*a9fa9459SzrjSets the minor number of the ``image version''.  Defaults to 0.
2559*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2560*a9fa9459Szrj
2561*a9fa9459Szrj@kindex --minor-os-version
2562*a9fa9459Szrj@item --minor-os-version @var{value}
2563*a9fa9459SzrjSets the minor number of the ``os version''.  Defaults to 0.
2564*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2565*a9fa9459Szrj
2566*a9fa9459Szrj@kindex --minor-subsystem-version
2567*a9fa9459Szrj@item --minor-subsystem-version @var{value}
2568*a9fa9459SzrjSets the minor number of the ``subsystem version''.  Defaults to 0.
2569*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2570*a9fa9459Szrj
2571*a9fa9459Szrj@cindex DEF files, creating
2572*a9fa9459Szrj@cindex DLLs, creating
2573*a9fa9459Szrj@kindex --output-def
2574*a9fa9459Szrj@item --output-def @var{file}
2575*a9fa9459SzrjThe linker will create the file @var{file} which will contain a DEF
2576*a9fa9459Szrjfile corresponding to the DLL the linker is generating.  This DEF file
2577*a9fa9459Szrj(which should be called @code{*.def}) may be used to create an import
2578*a9fa9459Szrjlibrary with @code{dlltool} or may be used as a reference to
2579*a9fa9459Szrjautomatically or implicitly exported symbols.
2580*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2581*a9fa9459Szrj
2582*a9fa9459Szrj@cindex DLLs, creating
2583*a9fa9459Szrj@kindex --out-implib
2584*a9fa9459Szrj@item --out-implib @var{file}
2585*a9fa9459SzrjThe linker will create the file @var{file} which will contain an
2586*a9fa9459Szrjimport lib corresponding to the DLL the linker is generating. This
2587*a9fa9459Szrjimport lib (which should be called @code{*.dll.a} or @code{*.a}
2588*a9fa9459Szrjmay be used to link clients against the generated DLL; this behaviour
2589*a9fa9459Szrjmakes it possible to skip a separate @code{dlltool} import library
2590*a9fa9459Szrjcreation step.
2591*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2592*a9fa9459Szrj
2593*a9fa9459Szrj@kindex --enable-auto-image-base
2594*a9fa9459Szrj@item --enable-auto-image-base
2595*a9fa9459Szrj@itemx --enable-auto-image-base=@var{value}
2596*a9fa9459SzrjAutomatically choose the image base for DLLs, optionally starting with base
2597*a9fa9459Szrj@var{value}, unless one is specified using the @code{--image-base} argument.
2598*a9fa9459SzrjBy using a hash generated from the dllname to create unique image bases
2599*a9fa9459Szrjfor each DLL, in-memory collisions and relocations which can delay program
2600*a9fa9459Szrjexecution are avoided.
2601*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2602*a9fa9459Szrj
2603*a9fa9459Szrj@kindex --disable-auto-image-base
2604*a9fa9459Szrj@item --disable-auto-image-base
2605*a9fa9459SzrjDo not automatically generate a unique image base.  If there is no
2606*a9fa9459Szrjuser-specified image base (@code{--image-base}) then use the platform
2607*a9fa9459Szrjdefault.
2608*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2609*a9fa9459Szrj
2610*a9fa9459Szrj@cindex DLLs, linking to
2611*a9fa9459Szrj@kindex --dll-search-prefix
2612*a9fa9459Szrj@item --dll-search-prefix @var{string}
2613*a9fa9459SzrjWhen linking dynamically to a dll without an import library,
2614*a9fa9459Szrjsearch for @code{<string><basename>.dll} in preference to
2615*a9fa9459Szrj@code{lib<basename>.dll}. This behaviour allows easy distinction
2616*a9fa9459Szrjbetween DLLs built for the various "subplatforms": native, cygwin,
2617*a9fa9459Szrjuwin, pw, etc.  For instance, cygwin DLLs typically use
2618*a9fa9459Szrj@code{--dll-search-prefix=cyg}.
2619*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2620*a9fa9459Szrj
2621*a9fa9459Szrj@kindex --enable-auto-import
2622*a9fa9459Szrj@item --enable-auto-import
2623*a9fa9459SzrjDo sophisticated linking of @code{_symbol} to @code{__imp__symbol} for
2624*a9fa9459SzrjDATA imports from DLLs, and create the necessary thunking symbols when
2625*a9fa9459Szrjbuilding the import libraries with those DATA exports. Note: Use of the
2626*a9fa9459Szrj'auto-import' extension will cause the text section of the image file
2627*a9fa9459Szrjto be made writable. This does not conform to the PE-COFF format
2628*a9fa9459Szrjspecification published by Microsoft.
2629*a9fa9459Szrj
2630*a9fa9459SzrjNote - use of the 'auto-import' extension will also cause read only
2631*a9fa9459Szrjdata which would normally be placed into the .rdata section to be
2632*a9fa9459Szrjplaced into the .data section instead.  This is in order to work
2633*a9fa9459Szrjaround a problem with consts that is described here:
2634*a9fa9459Szrjhttp://www.cygwin.com/ml/cygwin/2004-09/msg01101.html
2635*a9fa9459Szrj
2636*a9fa9459SzrjUsing 'auto-import' generally will 'just work' -- but sometimes you may
2637*a9fa9459Szrjsee this message:
2638*a9fa9459Szrj
2639*a9fa9459Szrj"variable '<var>' can't be auto-imported. Please read the
2640*a9fa9459Szrjdocumentation for ld's @code{--enable-auto-import} for details."
2641*a9fa9459Szrj
2642*a9fa9459SzrjThis message occurs when some (sub)expression accesses an address
2643*a9fa9459Szrjultimately given by the sum of two constants (Win32 import tables only
2644*a9fa9459Szrjallow one).  Instances where this may occur include accesses to member
2645*a9fa9459Szrjfields of struct variables imported from a DLL, as well as using a
2646*a9fa9459Szrjconstant index into an array variable imported from a DLL.  Any
2647*a9fa9459Szrjmultiword variable (arrays, structs, long long, etc) may trigger
2648*a9fa9459Szrjthis error condition.  However, regardless of the exact data type
2649*a9fa9459Szrjof the offending exported variable, ld will always detect it, issue
2650*a9fa9459Szrjthe warning, and exit.
2651*a9fa9459Szrj
2652*a9fa9459SzrjThere are several ways to address this difficulty, regardless of the
2653*a9fa9459Szrjdata type of the exported variable:
2654*a9fa9459Szrj
2655*a9fa9459SzrjOne way is to use --enable-runtime-pseudo-reloc switch. This leaves the task
2656*a9fa9459Szrjof adjusting references in your client code for runtime environment, so
2657*a9fa9459Szrjthis method works only when runtime environment supports this feature.
2658*a9fa9459Szrj
2659*a9fa9459SzrjA second solution is to force one of the 'constants' to be a variable --
2660*a9fa9459Szrjthat is, unknown and un-optimizable at compile time.  For arrays,
2661*a9fa9459Szrjthere are two possibilities: a) make the indexee (the array's address)
2662*a9fa9459Szrja variable, or b) make the 'constant' index a variable.  Thus:
2663*a9fa9459Szrj
2664*a9fa9459Szrj@example
2665*a9fa9459Szrjextern type extern_array[];
2666*a9fa9459Szrjextern_array[1] -->
2667*a9fa9459Szrj   @{ volatile type *t=extern_array; t[1] @}
2668*a9fa9459Szrj@end example
2669*a9fa9459Szrj
2670*a9fa9459Szrjor
2671*a9fa9459Szrj
2672*a9fa9459Szrj@example
2673*a9fa9459Szrjextern type extern_array[];
2674*a9fa9459Szrjextern_array[1] -->
2675*a9fa9459Szrj   @{ volatile int t=1; extern_array[t] @}
2676*a9fa9459Szrj@end example
2677*a9fa9459Szrj
2678*a9fa9459SzrjFor structs (and most other multiword data types) the only option
2679*a9fa9459Szrjis to make the struct itself (or the long long, or the ...) variable:
2680*a9fa9459Szrj
2681*a9fa9459Szrj@example
2682*a9fa9459Szrjextern struct s extern_struct;
2683*a9fa9459Szrjextern_struct.field -->
2684*a9fa9459Szrj   @{ volatile struct s *t=&extern_struct; t->field @}
2685*a9fa9459Szrj@end example
2686*a9fa9459Szrj
2687*a9fa9459Szrjor
2688*a9fa9459Szrj
2689*a9fa9459Szrj@example
2690*a9fa9459Szrjextern long long extern_ll;
2691*a9fa9459Szrjextern_ll -->
2692*a9fa9459Szrj  @{ volatile long long * local_ll=&extern_ll; *local_ll @}
2693*a9fa9459Szrj@end example
2694*a9fa9459Szrj
2695*a9fa9459SzrjA third method of dealing with this difficulty is to abandon
2696*a9fa9459Szrj'auto-import' for the offending symbol and mark it with
2697*a9fa9459Szrj@code{__declspec(dllimport)}.  However, in practice that
2698*a9fa9459Szrjrequires using compile-time #defines to indicate whether you are
2699*a9fa9459Szrjbuilding a DLL, building client code that will link to the DLL, or
2700*a9fa9459Szrjmerely building/linking to a static library.   In making the choice
2701*a9fa9459Szrjbetween the various methods of resolving the 'direct address with
2702*a9fa9459Szrjconstant offset' problem, you should consider typical real-world usage:
2703*a9fa9459Szrj
2704*a9fa9459SzrjOriginal:
2705*a9fa9459Szrj@example
2706*a9fa9459Szrj--foo.h
2707*a9fa9459Szrjextern int arr[];
2708*a9fa9459Szrj--foo.c
2709*a9fa9459Szrj#include "foo.h"
2710*a9fa9459Szrjvoid main(int argc, char **argv)@{
2711*a9fa9459Szrj  printf("%d\n",arr[1]);
2712*a9fa9459Szrj@}
2713*a9fa9459Szrj@end example
2714*a9fa9459Szrj
2715*a9fa9459SzrjSolution 1:
2716*a9fa9459Szrj@example
2717*a9fa9459Szrj--foo.h
2718*a9fa9459Szrjextern int arr[];
2719*a9fa9459Szrj--foo.c
2720*a9fa9459Szrj#include "foo.h"
2721*a9fa9459Szrjvoid main(int argc, char **argv)@{
2722*a9fa9459Szrj  /* This workaround is for win32 and cygwin; do not "optimize" */
2723*a9fa9459Szrj  volatile int *parr = arr;
2724*a9fa9459Szrj  printf("%d\n",parr[1]);
2725*a9fa9459Szrj@}
2726*a9fa9459Szrj@end example
2727*a9fa9459Szrj
2728*a9fa9459SzrjSolution 2:
2729*a9fa9459Szrj@example
2730*a9fa9459Szrj--foo.h
2731*a9fa9459Szrj/* Note: auto-export is assumed (no __declspec(dllexport)) */
2732*a9fa9459Szrj#if (defined(_WIN32) || defined(__CYGWIN__)) && \
2733*a9fa9459Szrj  !(defined(FOO_BUILD_DLL) || defined(FOO_STATIC))
2734*a9fa9459Szrj#define FOO_IMPORT __declspec(dllimport)
2735*a9fa9459Szrj#else
2736*a9fa9459Szrj#define FOO_IMPORT
2737*a9fa9459Szrj#endif
2738*a9fa9459Szrjextern FOO_IMPORT int arr[];
2739*a9fa9459Szrj--foo.c
2740*a9fa9459Szrj#include "foo.h"
2741*a9fa9459Szrjvoid main(int argc, char **argv)@{
2742*a9fa9459Szrj  printf("%d\n",arr[1]);
2743*a9fa9459Szrj@}
2744*a9fa9459Szrj@end example
2745*a9fa9459Szrj
2746*a9fa9459SzrjA fourth way to avoid this problem is to re-code your
2747*a9fa9459Szrjlibrary to use a functional interface rather than a data interface
2748*a9fa9459Szrjfor the offending variables (e.g. set_foo() and get_foo() accessor
2749*a9fa9459Szrjfunctions).
2750*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2751*a9fa9459Szrj
2752*a9fa9459Szrj@kindex --disable-auto-import
2753*a9fa9459Szrj@item --disable-auto-import
2754*a9fa9459SzrjDo not attempt to do sophisticated linking of @code{_symbol} to
2755*a9fa9459Szrj@code{__imp__symbol} for DATA imports from DLLs.
2756*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2757*a9fa9459Szrj
2758*a9fa9459Szrj@kindex --enable-runtime-pseudo-reloc
2759*a9fa9459Szrj@item --enable-runtime-pseudo-reloc
2760*a9fa9459SzrjIf your code contains expressions described in --enable-auto-import section,
2761*a9fa9459Szrjthat is, DATA imports from DLL with non-zero offset, this switch will create
2762*a9fa9459Szrja vector of 'runtime pseudo relocations' which can be used by runtime
2763*a9fa9459Szrjenvironment to adjust references to such data in your client code.
2764*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2765*a9fa9459Szrj
2766*a9fa9459Szrj@kindex --disable-runtime-pseudo-reloc
2767*a9fa9459Szrj@item --disable-runtime-pseudo-reloc
2768*a9fa9459SzrjDo not create pseudo relocations for non-zero offset DATA imports from
2769*a9fa9459SzrjDLLs.
2770*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2771*a9fa9459Szrj
2772*a9fa9459Szrj@kindex --enable-extra-pe-debug
2773*a9fa9459Szrj@item --enable-extra-pe-debug
2774*a9fa9459SzrjShow additional debug info related to auto-import symbol thunking.
2775*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2776*a9fa9459Szrj
2777*a9fa9459Szrj@kindex --section-alignment
2778*a9fa9459Szrj@item --section-alignment
2779*a9fa9459SzrjSets the section alignment.  Sections in memory will always begin at
2780*a9fa9459Szrjaddresses which are a multiple of this number.  Defaults to 0x1000.
2781*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2782*a9fa9459Szrj
2783*a9fa9459Szrj@cindex stack size
2784*a9fa9459Szrj@kindex --stack
2785*a9fa9459Szrj@item --stack @var{reserve}
2786*a9fa9459Szrj@itemx --stack @var{reserve},@var{commit}
2787*a9fa9459SzrjSpecify the number of bytes of memory to reserve (and optionally commit)
2788*a9fa9459Szrjto be used as stack for this program.  The default is 2MB reserved, 4K
2789*a9fa9459Szrjcommitted.
2790*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2791*a9fa9459Szrj
2792*a9fa9459Szrj@kindex --subsystem
2793*a9fa9459Szrj@item --subsystem @var{which}
2794*a9fa9459Szrj@itemx --subsystem @var{which}:@var{major}
2795*a9fa9459Szrj@itemx --subsystem @var{which}:@var{major}.@var{minor}
2796*a9fa9459SzrjSpecifies the subsystem under which your program will execute.  The
2797*a9fa9459Szrjlegal values for @var{which} are @code{native}, @code{windows},
2798*a9fa9459Szrj@code{console}, @code{posix}, and @code{xbox}.  You may optionally set
2799*a9fa9459Szrjthe subsystem version also.  Numeric values are also accepted for
2800*a9fa9459Szrj@var{which}.
2801*a9fa9459Szrj[This option is specific to the i386 PE targeted port of the linker]
2802*a9fa9459Szrj
2803*a9fa9459SzrjThe following options set flags in the @code{DllCharacteristics} field
2804*a9fa9459Szrjof the PE file header:
2805*a9fa9459Szrj[These options are specific to PE targeted ports of the linker]
2806*a9fa9459Szrj
2807*a9fa9459Szrj@kindex --high-entropy-va
2808*a9fa9459Szrj@item --high-entropy-va
2809*a9fa9459SzrjImage is compatible with 64-bit address space layout randomization
2810*a9fa9459Szrj(ASLR).
2811*a9fa9459Szrj
2812*a9fa9459Szrj@kindex --dynamicbase
2813*a9fa9459Szrj@item --dynamicbase
2814*a9fa9459SzrjThe image base address may be relocated using address space layout
2815*a9fa9459Szrjrandomization (ASLR).  This feature was introduced with MS Windows
2816*a9fa9459SzrjVista for i386 PE targets.
2817*a9fa9459Szrj
2818*a9fa9459Szrj@kindex --forceinteg
2819*a9fa9459Szrj@item --forceinteg
2820*a9fa9459SzrjCode integrity checks are enforced.
2821*a9fa9459Szrj
2822*a9fa9459Szrj@kindex --nxcompat
2823*a9fa9459Szrj@item --nxcompat
2824*a9fa9459SzrjThe image is compatible with the Data Execution Prevention.
2825*a9fa9459SzrjThis feature was introduced with MS Windows XP SP2 for i386 PE targets.
2826*a9fa9459Szrj
2827*a9fa9459Szrj@kindex --no-isolation
2828*a9fa9459Szrj@item --no-isolation
2829*a9fa9459SzrjAlthough the image understands isolation, do not isolate the image.
2830*a9fa9459Szrj
2831*a9fa9459Szrj@kindex --no-seh
2832*a9fa9459Szrj@item --no-seh
2833*a9fa9459SzrjThe image does not use SEH. No SE handler may be called from
2834*a9fa9459Szrjthis image.
2835*a9fa9459Szrj
2836*a9fa9459Szrj@kindex --no-bind
2837*a9fa9459Szrj@item --no-bind
2838*a9fa9459SzrjDo not bind this image.
2839*a9fa9459Szrj
2840*a9fa9459Szrj@kindex --wdmdriver
2841*a9fa9459Szrj@item --wdmdriver
2842*a9fa9459SzrjThe driver uses the MS Windows Driver Model.
2843*a9fa9459Szrj
2844*a9fa9459Szrj@kindex --tsaware
2845*a9fa9459Szrj@item --tsaware
2846*a9fa9459SzrjThe image is Terminal Server aware.
2847*a9fa9459Szrj
2848*a9fa9459Szrj@kindex --insert-timestamp
2849*a9fa9459Szrj@item --insert-timestamp
2850*a9fa9459Szrj@itemx --no-insert-timestamp
2851*a9fa9459SzrjInsert a real timestamp into the image.  This is the default behaviour
2852*a9fa9459Szrjas it matches legacy code and it means that the image will work with
2853*a9fa9459Szrjother, proprietary tools.  The problem with this default is that it
2854*a9fa9459Szrjwill result in slightly different images being produced each time the
2855*a9fa9459Szrjsame sources are linked.  The option @option{--no-insert-timestamp}
2856*a9fa9459Szrjcan be used to insert a zero value for the timestamp, this ensuring
2857*a9fa9459Szrjthat binaries produced from identical sources will compare
2858*a9fa9459Szrjidentically.
2859*a9fa9459Szrj@end table
2860*a9fa9459Szrj
2861*a9fa9459Szrj@c man end
2862*a9fa9459Szrj
2863*a9fa9459Szrj@ifset C6X
2864*a9fa9459Szrj@subsection Options specific to C6X uClinux targets
2865*a9fa9459Szrj
2866*a9fa9459Szrj@c man begin OPTIONS
2867*a9fa9459Szrj
2868*a9fa9459SzrjThe C6X uClinux target uses a binary format called DSBT to support shared
2869*a9fa9459Szrjlibraries.  Each shared library in the system needs to have a unique index;
2870*a9fa9459Szrjall executables use an index of 0.
2871*a9fa9459Szrj
2872*a9fa9459Szrj@table @gcctabopt
2873*a9fa9459Szrj
2874*a9fa9459Szrj@kindex --dsbt-size
2875*a9fa9459Szrj@item --dsbt-size @var{size}
2876*a9fa9459SzrjThis option sets the number of entries in the DSBT of the current executable
2877*a9fa9459Szrjor shared library to @var{size}.  The default is to create a table with 64
2878*a9fa9459Szrjentries.
2879*a9fa9459Szrj
2880*a9fa9459Szrj@kindex --dsbt-index
2881*a9fa9459Szrj@item --dsbt-index @var{index}
2882*a9fa9459SzrjThis option sets the DSBT index of the current executable or shared library
2883*a9fa9459Szrjto @var{index}.  The default is 0, which is appropriate for generating
2884*a9fa9459Szrjexecutables.  If a shared library is generated with a DSBT index of 0, the
2885*a9fa9459Szrj@code{R_C6000_DSBT_INDEX} relocs are copied into the output file.
2886*a9fa9459Szrj
2887*a9fa9459Szrj@kindex --no-merge-exidx-entries
2888*a9fa9459SzrjThe @samp{--no-merge-exidx-entries} switch disables the merging of adjacent
2889*a9fa9459Szrjexidx entries in frame unwind info.
2890*a9fa9459Szrj
2891*a9fa9459Szrj@end table
2892*a9fa9459Szrj
2893*a9fa9459Szrj@c man end
2894*a9fa9459Szrj@end ifset
2895*a9fa9459Szrj
2896*a9fa9459Szrj@ifset M68HC11
2897*a9fa9459Szrj@subsection Options specific to Motorola 68HC11 and 68HC12 targets
2898*a9fa9459Szrj
2899*a9fa9459Szrj@c man begin OPTIONS
2900*a9fa9459Szrj
2901*a9fa9459SzrjThe 68HC11 and 68HC12 linkers support specific options to control the
2902*a9fa9459Szrjmemory bank switching mapping and trampoline code generation.
2903*a9fa9459Szrj
2904*a9fa9459Szrj@table @gcctabopt
2905*a9fa9459Szrj
2906*a9fa9459Szrj@kindex --no-trampoline
2907*a9fa9459Szrj@item --no-trampoline
2908*a9fa9459SzrjThis option disables the generation of trampoline. By default a trampoline
2909*a9fa9459Szrjis generated for each far function which is called using a @code{jsr}
2910*a9fa9459Szrjinstruction (this happens when a pointer to a far function is taken).
2911*a9fa9459Szrj
2912*a9fa9459Szrj@kindex --bank-window
2913*a9fa9459Szrj@item --bank-window @var{name}
2914*a9fa9459SzrjThis option indicates to the linker the name of the memory region in
2915*a9fa9459Szrjthe @samp{MEMORY} specification that describes the memory bank window.
2916*a9fa9459SzrjThe definition of such region is then used by the linker to compute
2917*a9fa9459Szrjpaging and addresses within the memory window.
2918*a9fa9459Szrj
2919*a9fa9459Szrj@end table
2920*a9fa9459Szrj
2921*a9fa9459Szrj@c man end
2922*a9fa9459Szrj@end ifset
2923*a9fa9459Szrj
2924*a9fa9459Szrj@ifset M68K
2925*a9fa9459Szrj@subsection Options specific to Motorola 68K target
2926*a9fa9459Szrj
2927*a9fa9459Szrj@c man begin OPTIONS
2928*a9fa9459Szrj
2929*a9fa9459SzrjThe following options are supported to control handling of GOT generation
2930*a9fa9459Szrjwhen linking for 68K targets.
2931*a9fa9459Szrj
2932*a9fa9459Szrj@table @gcctabopt
2933*a9fa9459Szrj
2934*a9fa9459Szrj@kindex --got
2935*a9fa9459Szrj@item --got=@var{type}
2936*a9fa9459SzrjThis option tells the linker which GOT generation scheme to use.
2937*a9fa9459Szrj@var{type} should be one of @samp{single}, @samp{negative},
2938*a9fa9459Szrj@samp{multigot} or @samp{target}.  For more information refer to the
2939*a9fa9459SzrjInfo entry for @file{ld}.
2940*a9fa9459Szrj
2941*a9fa9459Szrj@end table
2942*a9fa9459Szrj
2943*a9fa9459Szrj@c man end
2944*a9fa9459Szrj@end ifset
2945*a9fa9459Szrj
2946*a9fa9459Szrj@ifset MIPS
2947*a9fa9459Szrj@subsection Options specific to MIPS targets
2948*a9fa9459Szrj
2949*a9fa9459Szrj@c man begin OPTIONS
2950*a9fa9459Szrj
2951*a9fa9459SzrjThe following options are supported to control microMIPS instruction
2952*a9fa9459Szrjgeneration when linking for MIPS targets.
2953*a9fa9459Szrj
2954*a9fa9459Szrj@table @gcctabopt
2955*a9fa9459Szrj
2956*a9fa9459Szrj@kindex --insn32
2957*a9fa9459Szrj@item --insn32
2958*a9fa9459Szrj@kindex --no-insn32
2959*a9fa9459Szrj@itemx --no-insn32
2960*a9fa9459SzrjThese options control the choice of microMIPS instructions used in code
2961*a9fa9459Szrjgenerated by the linker, such as that in the PLT or lazy binding stubs,
2962*a9fa9459Szrjor in relaxation.  If @samp{--insn32} is used, then the linker only uses
2963*a9fa9459Szrj32-bit instruction encodings.  By default or if @samp{--no-insn32} is
2964*a9fa9459Szrjused, all instruction encodings are used, including 16-bit ones where
2965*a9fa9459Szrjpossible.
2966*a9fa9459Szrj
2967*a9fa9459Szrj@end table
2968*a9fa9459Szrj
2969*a9fa9459Szrj@c man end
2970*a9fa9459Szrj@end ifset
2971*a9fa9459Szrj
2972*a9fa9459Szrj@ifset UsesEnvVars
2973*a9fa9459Szrj@node Environment
2974*a9fa9459Szrj@section Environment Variables
2975*a9fa9459Szrj
2976*a9fa9459Szrj@c man begin ENVIRONMENT
2977*a9fa9459Szrj
2978*a9fa9459SzrjYou can change the behaviour of @command{ld} with the environment variables
2979*a9fa9459Szrj@ifclear SingleFormat
2980*a9fa9459Szrj@code{GNUTARGET},
2981*a9fa9459Szrj@end ifclear
2982*a9fa9459Szrj@code{LDEMULATION} and @code{COLLECT_NO_DEMANGLE}.
2983*a9fa9459Szrj
2984*a9fa9459Szrj@ifclear SingleFormat
2985*a9fa9459Szrj@kindex GNUTARGET
2986*a9fa9459Szrj@cindex default input format
2987*a9fa9459Szrj@code{GNUTARGET} determines the input-file object format if you don't
2988*a9fa9459Szrjuse @samp{-b} (or its synonym @samp{--format}).  Its value should be one
2989*a9fa9459Szrjof the BFD names for an input format (@pxref{BFD}).  If there is no
2990*a9fa9459Szrj@code{GNUTARGET} in the environment, @command{ld} uses the natural format
2991*a9fa9459Szrjof the target. If @code{GNUTARGET} is set to @code{default} then BFD
2992*a9fa9459Szrjattempts to discover the input format by examining binary input files;
2993*a9fa9459Szrjthis method often succeeds, but there are potential ambiguities, since
2994*a9fa9459Szrjthere is no method of ensuring that the magic number used to specify
2995*a9fa9459Szrjobject-file formats is unique.  However, the configuration procedure for
2996*a9fa9459SzrjBFD on each system places the conventional format for that system first
2997*a9fa9459Szrjin the search-list, so ambiguities are resolved in favor of convention.
2998*a9fa9459Szrj@end ifclear
2999*a9fa9459Szrj
3000*a9fa9459Szrj@kindex LDEMULATION
3001*a9fa9459Szrj@cindex default emulation
3002*a9fa9459Szrj@cindex emulation, default
3003*a9fa9459Szrj@code{LDEMULATION} determines the default emulation if you don't use the
3004*a9fa9459Szrj@samp{-m} option.  The emulation can affect various aspects of linker
3005*a9fa9459Szrjbehaviour, particularly the default linker script.  You can list the
3006*a9fa9459Szrjavailable emulations with the @samp{--verbose} or @samp{-V} options.  If
3007*a9fa9459Szrjthe @samp{-m} option is not used, and the @code{LDEMULATION} environment
3008*a9fa9459Szrjvariable is not defined, the default emulation depends upon how the
3009*a9fa9459Szrjlinker was configured.
3010*a9fa9459Szrj
3011*a9fa9459Szrj@kindex COLLECT_NO_DEMANGLE
3012*a9fa9459Szrj@cindex demangling, default
3013*a9fa9459SzrjNormally, the linker will default to demangling symbols.  However, if
3014*a9fa9459Szrj@code{COLLECT_NO_DEMANGLE} is set in the environment, then it will
3015*a9fa9459Szrjdefault to not demangling symbols.  This environment variable is used in
3016*a9fa9459Szrja similar fashion by the @code{gcc} linker wrapper program.  The default
3017*a9fa9459Szrjmay be overridden by the @samp{--demangle} and @samp{--no-demangle}
3018*a9fa9459Szrjoptions.
3019*a9fa9459Szrj
3020*a9fa9459Szrj@c man end
3021*a9fa9459Szrj@end ifset
3022*a9fa9459Szrj
3023*a9fa9459Szrj@node Scripts
3024*a9fa9459Szrj@chapter Linker Scripts
3025*a9fa9459Szrj
3026*a9fa9459Szrj@cindex scripts
3027*a9fa9459Szrj@cindex linker scripts
3028*a9fa9459Szrj@cindex command files
3029*a9fa9459SzrjEvery link is controlled by a @dfn{linker script}.  This script is
3030*a9fa9459Szrjwritten in the linker command language.
3031*a9fa9459Szrj
3032*a9fa9459SzrjThe main purpose of the linker script is to describe how the sections in
3033*a9fa9459Szrjthe input files should be mapped into the output file, and to control
3034*a9fa9459Szrjthe memory layout of the output file.  Most linker scripts do nothing
3035*a9fa9459Szrjmore than this.  However, when necessary, the linker script can also
3036*a9fa9459Szrjdirect the linker to perform many other operations, using the commands
3037*a9fa9459Szrjdescribed below.
3038*a9fa9459Szrj
3039*a9fa9459SzrjThe linker always uses a linker script.  If you do not supply one
3040*a9fa9459Szrjyourself, the linker will use a default script that is compiled into the
3041*a9fa9459Szrjlinker executable.  You can use the @samp{--verbose} command line option
3042*a9fa9459Szrjto display the default linker script.  Certain command line options,
3043*a9fa9459Szrjsuch as @samp{-r} or @samp{-N}, will affect the default linker script.
3044*a9fa9459Szrj
3045*a9fa9459SzrjYou may supply your own linker script by using the @samp{-T} command
3046*a9fa9459Szrjline option.  When you do this, your linker script will replace the
3047*a9fa9459Szrjdefault linker script.
3048*a9fa9459Szrj
3049*a9fa9459SzrjYou may also use linker scripts implicitly by naming them as input files
3050*a9fa9459Szrjto the linker, as though they were files to be linked.  @xref{Implicit
3051*a9fa9459SzrjLinker Scripts}.
3052*a9fa9459Szrj
3053*a9fa9459Szrj@menu
3054*a9fa9459Szrj* Basic Script Concepts::	Basic Linker Script Concepts
3055*a9fa9459Szrj* Script Format::		Linker Script Format
3056*a9fa9459Szrj* Simple Example::		Simple Linker Script Example
3057*a9fa9459Szrj* Simple Commands::		Simple Linker Script Commands
3058*a9fa9459Szrj* Assignments::			Assigning Values to Symbols
3059*a9fa9459Szrj* SECTIONS::			SECTIONS Command
3060*a9fa9459Szrj* MEMORY::			MEMORY Command
3061*a9fa9459Szrj* PHDRS::			PHDRS Command
3062*a9fa9459Szrj* VERSION::			VERSION Command
3063*a9fa9459Szrj* Expressions::			Expressions in Linker Scripts
3064*a9fa9459Szrj* Implicit Linker Scripts::	Implicit Linker Scripts
3065*a9fa9459Szrj@end menu
3066*a9fa9459Szrj
3067*a9fa9459Szrj@node Basic Script Concepts
3068*a9fa9459Szrj@section Basic Linker Script Concepts
3069*a9fa9459Szrj@cindex linker script concepts
3070*a9fa9459SzrjWe need to define some basic concepts and vocabulary in order to
3071*a9fa9459Szrjdescribe the linker script language.
3072*a9fa9459Szrj
3073*a9fa9459SzrjThe linker combines input files into a single output file.  The output
3074*a9fa9459Szrjfile and each input file are in a special data format known as an
3075*a9fa9459Szrj@dfn{object file format}.  Each file is called an @dfn{object file}.
3076*a9fa9459SzrjThe output file is often called an @dfn{executable}, but for our
3077*a9fa9459Szrjpurposes we will also call it an object file.  Each object file has,
3078*a9fa9459Szrjamong other things, a list of @dfn{sections}.  We sometimes refer to a
3079*a9fa9459Szrjsection in an input file as an @dfn{input section}; similarly, a section
3080*a9fa9459Szrjin the output file is an @dfn{output section}.
3081*a9fa9459Szrj
3082*a9fa9459SzrjEach section in an object file has a name and a size.  Most sections
3083*a9fa9459Szrjalso have an associated block of data, known as the @dfn{section
3084*a9fa9459Szrjcontents}.  A section may be marked as @dfn{loadable}, which means that
3085*a9fa9459Szrjthe contents should be loaded into memory when the output file is run.
3086*a9fa9459SzrjA section with no contents may be @dfn{allocatable}, which means that an
3087*a9fa9459Szrjarea in memory should be set aside, but nothing in particular should be
3088*a9fa9459Szrjloaded there (in some cases this memory must be zeroed out).  A section
3089*a9fa9459Szrjwhich is neither loadable nor allocatable typically contains some sort
3090*a9fa9459Szrjof debugging information.
3091*a9fa9459Szrj
3092*a9fa9459SzrjEvery loadable or allocatable output section has two addresses.  The
3093*a9fa9459Szrjfirst is the @dfn{VMA}, or virtual memory address.  This is the address
3094*a9fa9459Szrjthe section will have when the output file is run.  The second is the
3095*a9fa9459Szrj@dfn{LMA}, or load memory address.  This is the address at which the
3096*a9fa9459Szrjsection will be loaded.  In most cases the two addresses will be the
3097*a9fa9459Szrjsame.  An example of when they might be different is when a data section
3098*a9fa9459Szrjis loaded into ROM, and then copied into RAM when the program starts up
3099*a9fa9459Szrj(this technique is often used to initialize global variables in a ROM
3100*a9fa9459Szrjbased system).  In this case the ROM address would be the LMA, and the
3101*a9fa9459SzrjRAM address would be the VMA.
3102*a9fa9459Szrj
3103*a9fa9459SzrjYou can see the sections in an object file by using the @code{objdump}
3104*a9fa9459Szrjprogram with the @samp{-h} option.
3105*a9fa9459Szrj
3106*a9fa9459SzrjEvery object file also has a list of @dfn{symbols}, known as the
3107*a9fa9459Szrj@dfn{symbol table}.  A symbol may be defined or undefined.  Each symbol
3108*a9fa9459Szrjhas a name, and each defined symbol has an address, among other
3109*a9fa9459Szrjinformation.  If you compile a C or C++ program into an object file, you
3110*a9fa9459Szrjwill get a defined symbol for every defined function and global or
3111*a9fa9459Szrjstatic variable.  Every undefined function or global variable which is
3112*a9fa9459Szrjreferenced in the input file will become an undefined symbol.
3113*a9fa9459Szrj
3114*a9fa9459SzrjYou can see the symbols in an object file by using the @code{nm}
3115*a9fa9459Szrjprogram, or by using the @code{objdump} program with the @samp{-t}
3116*a9fa9459Szrjoption.
3117*a9fa9459Szrj
3118*a9fa9459Szrj@node Script Format
3119*a9fa9459Szrj@section Linker Script Format
3120*a9fa9459Szrj@cindex linker script format
3121*a9fa9459SzrjLinker scripts are text files.
3122*a9fa9459Szrj
3123*a9fa9459SzrjYou write a linker script as a series of commands.  Each command is
3124*a9fa9459Szrjeither a keyword, possibly followed by arguments, or an assignment to a
3125*a9fa9459Szrjsymbol.  You may separate commands using semicolons.  Whitespace is
3126*a9fa9459Szrjgenerally ignored.
3127*a9fa9459Szrj
3128*a9fa9459SzrjStrings such as file or format names can normally be entered directly.
3129*a9fa9459SzrjIf the file name contains a character such as a comma which would
3130*a9fa9459Szrjotherwise serve to separate file names, you may put the file name in
3131*a9fa9459Szrjdouble quotes.  There is no way to use a double quote character in a
3132*a9fa9459Szrjfile name.
3133*a9fa9459Szrj
3134*a9fa9459SzrjYou may include comments in linker scripts just as in C, delimited by
3135*a9fa9459Szrj@samp{/*} and @samp{*/}.  As in C, comments are syntactically equivalent
3136*a9fa9459Szrjto whitespace.
3137*a9fa9459Szrj
3138*a9fa9459Szrj@node Simple Example
3139*a9fa9459Szrj@section Simple Linker Script Example
3140*a9fa9459Szrj@cindex linker script example
3141*a9fa9459Szrj@cindex example of linker script
3142*a9fa9459SzrjMany linker scripts are fairly simple.
3143*a9fa9459Szrj
3144*a9fa9459SzrjThe simplest possible linker script has just one command:
3145*a9fa9459Szrj@samp{SECTIONS}.  You use the @samp{SECTIONS} command to describe the
3146*a9fa9459Szrjmemory layout of the output file.
3147*a9fa9459Szrj
3148*a9fa9459SzrjThe @samp{SECTIONS} command is a powerful command.  Here we will
3149*a9fa9459Szrjdescribe a simple use of it.  Let's assume your program consists only of
3150*a9fa9459Szrjcode, initialized data, and uninitialized data.  These will be in the
3151*a9fa9459Szrj@samp{.text}, @samp{.data}, and @samp{.bss} sections, respectively.
3152*a9fa9459SzrjLet's assume further that these are the only sections which appear in
3153*a9fa9459Szrjyour input files.
3154*a9fa9459Szrj
3155*a9fa9459SzrjFor this example, let's say that the code should be loaded at address
3156*a9fa9459Szrj0x10000, and that the data should start at address 0x8000000.  Here is a
3157*a9fa9459Szrjlinker script which will do that:
3158*a9fa9459Szrj@smallexample
3159*a9fa9459SzrjSECTIONS
3160*a9fa9459Szrj@{
3161*a9fa9459Szrj  . = 0x10000;
3162*a9fa9459Szrj  .text : @{ *(.text) @}
3163*a9fa9459Szrj  . = 0x8000000;
3164*a9fa9459Szrj  .data : @{ *(.data) @}
3165*a9fa9459Szrj  .bss : @{ *(.bss) @}
3166*a9fa9459Szrj@}
3167*a9fa9459Szrj@end smallexample
3168*a9fa9459Szrj
3169*a9fa9459SzrjYou write the @samp{SECTIONS} command as the keyword @samp{SECTIONS},
3170*a9fa9459Szrjfollowed by a series of symbol assignments and output section
3171*a9fa9459Szrjdescriptions enclosed in curly braces.
3172*a9fa9459Szrj
3173*a9fa9459SzrjThe first line inside the @samp{SECTIONS} command of the above example
3174*a9fa9459Szrjsets the value of the special symbol @samp{.}, which is the location
3175*a9fa9459Szrjcounter.  If you do not specify the address of an output section in some
3176*a9fa9459Szrjother way (other ways are described later), the address is set from the
3177*a9fa9459Szrjcurrent value of the location counter.  The location counter is then
3178*a9fa9459Szrjincremented by the size of the output section.  At the start of the
3179*a9fa9459Szrj@samp{SECTIONS} command, the location counter has the value @samp{0}.
3180*a9fa9459Szrj
3181*a9fa9459SzrjThe second line defines an output section, @samp{.text}.  The colon is
3182*a9fa9459Szrjrequired syntax which may be ignored for now.  Within the curly braces
3183*a9fa9459Szrjafter the output section name, you list the names of the input sections
3184*a9fa9459Szrjwhich should be placed into this output section.  The @samp{*} is a
3185*a9fa9459Szrjwildcard which matches any file name.  The expression @samp{*(.text)}
3186*a9fa9459Szrjmeans all @samp{.text} input sections in all input files.
3187*a9fa9459Szrj
3188*a9fa9459SzrjSince the location counter is @samp{0x10000} when the output section
3189*a9fa9459Szrj@samp{.text} is defined, the linker will set the address of the
3190*a9fa9459Szrj@samp{.text} section in the output file to be @samp{0x10000}.
3191*a9fa9459Szrj
3192*a9fa9459SzrjThe remaining lines define the @samp{.data} and @samp{.bss} sections in
3193*a9fa9459Szrjthe output file.  The linker will place the @samp{.data} output section
3194*a9fa9459Szrjat address @samp{0x8000000}.  After the linker places the @samp{.data}
3195*a9fa9459Szrjoutput section, the value of the location counter will be
3196*a9fa9459Szrj@samp{0x8000000} plus the size of the @samp{.data} output section.  The
3197*a9fa9459Szrjeffect is that the linker will place the @samp{.bss} output section
3198*a9fa9459Szrjimmediately after the @samp{.data} output section in memory.
3199*a9fa9459Szrj
3200*a9fa9459SzrjThe linker will ensure that each output section has the required
3201*a9fa9459Szrjalignment, by increasing the location counter if necessary.  In this
3202*a9fa9459Szrjexample, the specified addresses for the @samp{.text} and @samp{.data}
3203*a9fa9459Szrjsections will probably satisfy any alignment constraints, but the linker
3204*a9fa9459Szrjmay have to create a small gap between the @samp{.data} and @samp{.bss}
3205*a9fa9459Szrjsections.
3206*a9fa9459Szrj
3207*a9fa9459SzrjThat's it!  That's a simple and complete linker script.
3208*a9fa9459Szrj
3209*a9fa9459Szrj@node Simple Commands
3210*a9fa9459Szrj@section Simple Linker Script Commands
3211*a9fa9459Szrj@cindex linker script simple commands
3212*a9fa9459SzrjIn this section we describe the simple linker script commands.
3213*a9fa9459Szrj
3214*a9fa9459Szrj@menu
3215*a9fa9459Szrj* Entry Point::			Setting the entry point
3216*a9fa9459Szrj* File Commands::		Commands dealing with files
3217*a9fa9459Szrj@ifclear SingleFormat
3218*a9fa9459Szrj* Format Commands::		Commands dealing with object file formats
3219*a9fa9459Szrj@end ifclear
3220*a9fa9459Szrj
3221*a9fa9459Szrj* REGION_ALIAS::		Assign alias names to memory regions
3222*a9fa9459Szrj* Miscellaneous Commands::	Other linker script commands
3223*a9fa9459Szrj@end menu
3224*a9fa9459Szrj
3225*a9fa9459Szrj@node Entry Point
3226*a9fa9459Szrj@subsection Setting the Entry Point
3227*a9fa9459Szrj@kindex ENTRY(@var{symbol})
3228*a9fa9459Szrj@cindex start of execution
3229*a9fa9459Szrj@cindex first instruction
3230*a9fa9459Szrj@cindex entry point
3231*a9fa9459SzrjThe first instruction to execute in a program is called the @dfn{entry
3232*a9fa9459Szrjpoint}.  You can use the @code{ENTRY} linker script command to set the
3233*a9fa9459Szrjentry point.  The argument is a symbol name:
3234*a9fa9459Szrj@smallexample
3235*a9fa9459SzrjENTRY(@var{symbol})
3236*a9fa9459Szrj@end smallexample
3237*a9fa9459Szrj
3238*a9fa9459SzrjThere are several ways to set the entry point.  The linker will set the
3239*a9fa9459Szrjentry point by trying each of the following methods in order, and
3240*a9fa9459Szrjstopping when one of them succeeds:
3241*a9fa9459Szrj@itemize @bullet
3242*a9fa9459Szrj@item
3243*a9fa9459Szrjthe @samp{-e} @var{entry} command-line option;
3244*a9fa9459Szrj@item
3245*a9fa9459Szrjthe @code{ENTRY(@var{symbol})} command in a linker script;
3246*a9fa9459Szrj@item
3247*a9fa9459Szrjthe value of a target specific symbol, if it is defined;  For many
3248*a9fa9459Szrjtargets this is @code{start}, but PE and BeOS based systems for example
3249*a9fa9459Szrjcheck a list of possible entry symbols, matching the first one found.
3250*a9fa9459Szrj@item
3251*a9fa9459Szrjthe address of the first byte of the @samp{.text} section, if present;
3252*a9fa9459Szrj@item
3253*a9fa9459SzrjThe address @code{0}.
3254*a9fa9459Szrj@end itemize
3255*a9fa9459Szrj
3256*a9fa9459Szrj@node File Commands
3257*a9fa9459Szrj@subsection Commands Dealing with Files
3258*a9fa9459Szrj@cindex linker script file commands
3259*a9fa9459SzrjSeveral linker script commands deal with files.
3260*a9fa9459Szrj
3261*a9fa9459Szrj@table @code
3262*a9fa9459Szrj@item INCLUDE @var{filename}
3263*a9fa9459Szrj@kindex INCLUDE @var{filename}
3264*a9fa9459Szrj@cindex including a linker script
3265*a9fa9459SzrjInclude the linker script @var{filename} at this point.  The file will
3266*a9fa9459Szrjbe searched for in the current directory, and in any directory specified
3267*a9fa9459Szrjwith the @option{-L} option.  You can nest calls to @code{INCLUDE} up to
3268*a9fa9459Szrj10 levels deep.
3269*a9fa9459Szrj
3270*a9fa9459SzrjYou can place @code{INCLUDE} directives at the top level, in @code{MEMORY} or
3271*a9fa9459Szrj@code{SECTIONS} commands, or in output section descriptions.
3272*a9fa9459Szrj
3273*a9fa9459Szrj@item INPUT(@var{file}, @var{file}, @dots{})
3274*a9fa9459Szrj@itemx INPUT(@var{file} @var{file} @dots{})
3275*a9fa9459Szrj@kindex INPUT(@var{files})
3276*a9fa9459Szrj@cindex input files in linker scripts
3277*a9fa9459Szrj@cindex input object files in linker scripts
3278*a9fa9459Szrj@cindex linker script input object files
3279*a9fa9459SzrjThe @code{INPUT} command directs the linker to include the named files
3280*a9fa9459Szrjin the link, as though they were named on the command line.
3281*a9fa9459Szrj
3282*a9fa9459SzrjFor example, if you always want to include @file{subr.o} any time you do
3283*a9fa9459Szrja link, but you can't be bothered to put it on every link command line,
3284*a9fa9459Szrjthen you can put @samp{INPUT (subr.o)} in your linker script.
3285*a9fa9459Szrj
3286*a9fa9459SzrjIn fact, if you like, you can list all of your input files in the linker
3287*a9fa9459Szrjscript, and then invoke the linker with nothing but a @samp{-T} option.
3288*a9fa9459Szrj
3289*a9fa9459SzrjIn case a @dfn{sysroot prefix} is configured, and the filename starts
3290*a9fa9459Szrjwith the @samp{/} character, and the script being processed was
3291*a9fa9459Szrjlocated inside the @dfn{sysroot prefix}, the filename will be looked
3292*a9fa9459Szrjfor in the @dfn{sysroot prefix}.  Otherwise, the linker will try to
3293*a9fa9459Szrjopen the file in the current directory.  If it is not found, the
3294*a9fa9459Szrjlinker will search through the archive library search path.
3295*a9fa9459SzrjThe @dfn{sysroot prefix} can also be forced by specifying @code{=}
3296*a9fa9459Szrjas the first character in the filename path.  See also the
3297*a9fa9459Szrjdescription of @samp{-L} in @ref{Options,,Command Line Options}.
3298*a9fa9459Szrj
3299*a9fa9459SzrjIf you use @samp{INPUT (-l@var{file})}, @command{ld} will transform the
3300*a9fa9459Szrjname to @code{lib@var{file}.a}, as with the command line argument
3301*a9fa9459Szrj@samp{-l}.
3302*a9fa9459Szrj
3303*a9fa9459SzrjWhen you use the @code{INPUT} command in an implicit linker script, the
3304*a9fa9459Szrjfiles will be included in the link at the point at which the linker
3305*a9fa9459Szrjscript file is included.  This can affect archive searching.
3306*a9fa9459Szrj
3307*a9fa9459Szrj@item GROUP(@var{file}, @var{file}, @dots{})
3308*a9fa9459Szrj@itemx GROUP(@var{file} @var{file} @dots{})
3309*a9fa9459Szrj@kindex GROUP(@var{files})
3310*a9fa9459Szrj@cindex grouping input files
3311*a9fa9459SzrjThe @code{GROUP} command is like @code{INPUT}, except that the named
3312*a9fa9459Szrjfiles should all be archives, and they are searched repeatedly until no
3313*a9fa9459Szrjnew undefined references are created.  See the description of @samp{-(}
3314*a9fa9459Szrjin @ref{Options,,Command Line Options}.
3315*a9fa9459Szrj
3316*a9fa9459Szrj@item AS_NEEDED(@var{file}, @var{file}, @dots{})
3317*a9fa9459Szrj@itemx AS_NEEDED(@var{file} @var{file} @dots{})
3318*a9fa9459Szrj@kindex AS_NEEDED(@var{files})
3319*a9fa9459SzrjThis construct can appear only inside of the @code{INPUT} or @code{GROUP}
3320*a9fa9459Szrjcommands, among other filenames.  The files listed will be handled
3321*a9fa9459Szrjas if they appear directly in the @code{INPUT} or @code{GROUP} commands,
3322*a9fa9459Szrjwith the exception of ELF shared libraries, that will be added only
3323*a9fa9459Szrjwhen they are actually needed.  This construct essentially enables
3324*a9fa9459Szrj@option{--as-needed} option for all the files listed inside of it
3325*a9fa9459Szrjand restores previous @option{--as-needed} resp. @option{--no-as-needed}
3326*a9fa9459Szrjsetting afterwards.
3327*a9fa9459Szrj
3328*a9fa9459Szrj@item OUTPUT(@var{filename})
3329*a9fa9459Szrj@kindex OUTPUT(@var{filename})
3330*a9fa9459Szrj@cindex output file name in linker script
3331*a9fa9459SzrjThe @code{OUTPUT} command names the output file.  Using
3332*a9fa9459Szrj@code{OUTPUT(@var{filename})} in the linker script is exactly like using
3333*a9fa9459Szrj@samp{-o @var{filename}} on the command line (@pxref{Options,,Command
3334*a9fa9459SzrjLine Options}).  If both are used, the command line option takes
3335*a9fa9459Szrjprecedence.
3336*a9fa9459Szrj
3337*a9fa9459SzrjYou can use the @code{OUTPUT} command to define a default name for the
3338*a9fa9459Szrjoutput file other than the usual default of @file{a.out}.
3339*a9fa9459Szrj
3340*a9fa9459Szrj@item SEARCH_DIR(@var{path})
3341*a9fa9459Szrj@kindex SEARCH_DIR(@var{path})
3342*a9fa9459Szrj@cindex library search path in linker script
3343*a9fa9459Szrj@cindex archive search path in linker script
3344*a9fa9459Szrj@cindex search path in linker script
3345*a9fa9459SzrjThe @code{SEARCH_DIR} command adds @var{path} to the list of paths where
3346*a9fa9459Szrj@command{ld} looks for archive libraries.  Using
3347*a9fa9459Szrj@code{SEARCH_DIR(@var{path})} is exactly like using @samp{-L @var{path}}
3348*a9fa9459Szrjon the command line (@pxref{Options,,Command Line Options}).  If both
3349*a9fa9459Szrjare used, then the linker will search both paths.  Paths specified using
3350*a9fa9459Szrjthe command line option are searched first.
3351*a9fa9459Szrj
3352*a9fa9459Szrj@item STARTUP(@var{filename})
3353*a9fa9459Szrj@kindex STARTUP(@var{filename})
3354*a9fa9459Szrj@cindex first input file
3355*a9fa9459SzrjThe @code{STARTUP} command is just like the @code{INPUT} command, except
3356*a9fa9459Szrjthat @var{filename} will become the first input file to be linked, as
3357*a9fa9459Szrjthough it were specified first on the command line.  This may be useful
3358*a9fa9459Szrjwhen using a system in which the entry point is always the start of the
3359*a9fa9459Szrjfirst file.
3360*a9fa9459Szrj@end table
3361*a9fa9459Szrj
3362*a9fa9459Szrj@ifclear SingleFormat
3363*a9fa9459Szrj@node Format Commands
3364*a9fa9459Szrj@subsection Commands Dealing with Object File Formats
3365*a9fa9459SzrjA couple of linker script commands deal with object file formats.
3366*a9fa9459Szrj
3367*a9fa9459Szrj@table @code
3368*a9fa9459Szrj@item OUTPUT_FORMAT(@var{bfdname})
3369*a9fa9459Szrj@itemx OUTPUT_FORMAT(@var{default}, @var{big}, @var{little})
3370*a9fa9459Szrj@kindex OUTPUT_FORMAT(@var{bfdname})
3371*a9fa9459Szrj@cindex output file format in linker script
3372*a9fa9459SzrjThe @code{OUTPUT_FORMAT} command names the BFD format to use for the
3373*a9fa9459Szrjoutput file (@pxref{BFD}).  Using @code{OUTPUT_FORMAT(@var{bfdname})} is
3374*a9fa9459Szrjexactly like using @samp{--oformat @var{bfdname}} on the command line
3375*a9fa9459Szrj(@pxref{Options,,Command Line Options}).  If both are used, the command
3376*a9fa9459Szrjline option takes precedence.
3377*a9fa9459Szrj
3378*a9fa9459SzrjYou can use @code{OUTPUT_FORMAT} with three arguments to use different
3379*a9fa9459Szrjformats based on the @samp{-EB} and @samp{-EL} command line options.
3380*a9fa9459SzrjThis permits the linker script to set the output format based on the
3381*a9fa9459Szrjdesired endianness.
3382*a9fa9459Szrj
3383*a9fa9459SzrjIf neither @samp{-EB} nor @samp{-EL} are used, then the output format
3384*a9fa9459Szrjwill be the first argument, @var{default}.  If @samp{-EB} is used, the
3385*a9fa9459Szrjoutput format will be the second argument, @var{big}.  If @samp{-EL} is
3386*a9fa9459Szrjused, the output format will be the third argument, @var{little}.
3387*a9fa9459Szrj
3388*a9fa9459SzrjFor example, the default linker script for the MIPS ELF target uses this
3389*a9fa9459Szrjcommand:
3390*a9fa9459Szrj@smallexample
3391*a9fa9459SzrjOUTPUT_FORMAT(elf32-bigmips, elf32-bigmips, elf32-littlemips)
3392*a9fa9459Szrj@end smallexample
3393*a9fa9459SzrjThis says that the default format for the output file is
3394*a9fa9459Szrj@samp{elf32-bigmips}, but if the user uses the @samp{-EL} command line
3395*a9fa9459Szrjoption, the output file will be created in the @samp{elf32-littlemips}
3396*a9fa9459Szrjformat.
3397*a9fa9459Szrj
3398*a9fa9459Szrj@item TARGET(@var{bfdname})
3399*a9fa9459Szrj@kindex TARGET(@var{bfdname})
3400*a9fa9459Szrj@cindex input file format in linker script
3401*a9fa9459SzrjThe @code{TARGET} command names the BFD format to use when reading input
3402*a9fa9459Szrjfiles.  It affects subsequent @code{INPUT} and @code{GROUP} commands.
3403*a9fa9459SzrjThis command is like using @samp{-b @var{bfdname}} on the command line
3404*a9fa9459Szrj(@pxref{Options,,Command Line Options}).  If the @code{TARGET} command
3405*a9fa9459Szrjis used but @code{OUTPUT_FORMAT} is not, then the last @code{TARGET}
3406*a9fa9459Szrjcommand is also used to set the format for the output file.  @xref{BFD}.
3407*a9fa9459Szrj@end table
3408*a9fa9459Szrj@end ifclear
3409*a9fa9459Szrj
3410*a9fa9459Szrj@node REGION_ALIAS
3411*a9fa9459Szrj@subsection Assign alias names to memory regions
3412*a9fa9459Szrj@kindex REGION_ALIAS(@var{alias}, @var{region})
3413*a9fa9459Szrj@cindex region alias
3414*a9fa9459Szrj@cindex region names
3415*a9fa9459Szrj
3416*a9fa9459SzrjAlias names can be added to existing memory regions created with the
3417*a9fa9459Szrj@ref{MEMORY} command.  Each name corresponds to at most one memory region.
3418*a9fa9459Szrj
3419*a9fa9459Szrj@smallexample
3420*a9fa9459SzrjREGION_ALIAS(@var{alias}, @var{region})
3421*a9fa9459Szrj@end smallexample
3422*a9fa9459Szrj
3423*a9fa9459SzrjThe @code{REGION_ALIAS} function creates an alias name @var{alias} for the
3424*a9fa9459Szrjmemory region @var{region}.  This allows a flexible mapping of output sections
3425*a9fa9459Szrjto memory regions.  An example follows.
3426*a9fa9459Szrj
3427*a9fa9459SzrjSuppose we have an application for embedded systems which come with various
3428*a9fa9459Szrjmemory storage devices.  All have a general purpose, volatile memory @code{RAM}
3429*a9fa9459Szrjthat allows code execution or data storage.  Some may have a read-only,
3430*a9fa9459Szrjnon-volatile memory @code{ROM} that allows code execution and read-only data
3431*a9fa9459Szrjaccess.  The last variant is a read-only, non-volatile memory @code{ROM2} with
3432*a9fa9459Szrjread-only data access and no code execution capability.  We have four output
3433*a9fa9459Szrjsections:
3434*a9fa9459Szrj
3435*a9fa9459Szrj@itemize @bullet
3436*a9fa9459Szrj@item
3437*a9fa9459Szrj@code{.text} program code;
3438*a9fa9459Szrj@item
3439*a9fa9459Szrj@code{.rodata} read-only data;
3440*a9fa9459Szrj@item
3441*a9fa9459Szrj@code{.data} read-write initialized data;
3442*a9fa9459Szrj@item
3443*a9fa9459Szrj@code{.bss} read-write zero initialized data.
3444*a9fa9459Szrj@end itemize
3445*a9fa9459Szrj
3446*a9fa9459SzrjThe goal is to provide a linker command file that contains a system independent
3447*a9fa9459Szrjpart defining the output sections and a system dependent part mapping the
3448*a9fa9459Szrjoutput sections to the memory regions available on the system.  Our embedded
3449*a9fa9459Szrjsystems come with three different memory setups @code{A}, @code{B} and
3450*a9fa9459Szrj@code{C}:
3451*a9fa9459Szrj@multitable @columnfractions .25 .25 .25 .25
3452*a9fa9459Szrj@item Section @tab Variant A @tab Variant B @tab Variant C
3453*a9fa9459Szrj@item .text @tab RAM @tab ROM @tab ROM
3454*a9fa9459Szrj@item .rodata @tab RAM @tab ROM @tab ROM2
3455*a9fa9459Szrj@item .data @tab RAM @tab RAM/ROM @tab RAM/ROM2
3456*a9fa9459Szrj@item .bss @tab RAM @tab RAM @tab RAM
3457*a9fa9459Szrj@end multitable
3458*a9fa9459SzrjThe notation @code{RAM/ROM} or @code{RAM/ROM2} means that this section is
3459*a9fa9459Szrjloaded into region @code{ROM} or @code{ROM2} respectively.  Please note that
3460*a9fa9459Szrjthe load address of the @code{.data} section starts in all three variants at
3461*a9fa9459Szrjthe end of the @code{.rodata} section.
3462*a9fa9459Szrj
3463*a9fa9459SzrjThe base linker script that deals with the output sections follows.  It
3464*a9fa9459Szrjincludes the system dependent @code{linkcmds.memory} file that describes the
3465*a9fa9459Szrjmemory layout:
3466*a9fa9459Szrj@smallexample
3467*a9fa9459SzrjINCLUDE linkcmds.memory
3468*a9fa9459Szrj
3469*a9fa9459SzrjSECTIONS
3470*a9fa9459Szrj  @{
3471*a9fa9459Szrj    .text :
3472*a9fa9459Szrj      @{
3473*a9fa9459Szrj        *(.text)
3474*a9fa9459Szrj      @} > REGION_TEXT
3475*a9fa9459Szrj    .rodata :
3476*a9fa9459Szrj      @{
3477*a9fa9459Szrj        *(.rodata)
3478*a9fa9459Szrj        rodata_end = .;
3479*a9fa9459Szrj      @} > REGION_RODATA
3480*a9fa9459Szrj    .data : AT (rodata_end)
3481*a9fa9459Szrj      @{
3482*a9fa9459Szrj        data_start = .;
3483*a9fa9459Szrj        *(.data)
3484*a9fa9459Szrj      @} > REGION_DATA
3485*a9fa9459Szrj    data_size = SIZEOF(.data);
3486*a9fa9459Szrj    data_load_start = LOADADDR(.data);
3487*a9fa9459Szrj    .bss :
3488*a9fa9459Szrj      @{
3489*a9fa9459Szrj        *(.bss)
3490*a9fa9459Szrj      @} > REGION_BSS
3491*a9fa9459Szrj  @}
3492*a9fa9459Szrj@end smallexample
3493*a9fa9459Szrj
3494*a9fa9459SzrjNow we need three different @code{linkcmds.memory} files to define memory
3495*a9fa9459Szrjregions and alias names.  The content of @code{linkcmds.memory} for the three
3496*a9fa9459Szrjvariants @code{A}, @code{B} and @code{C}:
3497*a9fa9459Szrj@table @code
3498*a9fa9459Szrj@item A
3499*a9fa9459SzrjHere everything goes into the @code{RAM}.
3500*a9fa9459Szrj@smallexample
3501*a9fa9459SzrjMEMORY
3502*a9fa9459Szrj  @{
3503*a9fa9459Szrj    RAM : ORIGIN = 0, LENGTH = 4M
3504*a9fa9459Szrj  @}
3505*a9fa9459Szrj
3506*a9fa9459SzrjREGION_ALIAS("REGION_TEXT", RAM);
3507*a9fa9459SzrjREGION_ALIAS("REGION_RODATA", RAM);
3508*a9fa9459SzrjREGION_ALIAS("REGION_DATA", RAM);
3509*a9fa9459SzrjREGION_ALIAS("REGION_BSS", RAM);
3510*a9fa9459Szrj@end smallexample
3511*a9fa9459Szrj@item B
3512*a9fa9459SzrjProgram code and read-only data go into the @code{ROM}.  Read-write data goes
3513*a9fa9459Szrjinto the @code{RAM}.  An image of the initialized data is loaded into the
3514*a9fa9459Szrj@code{ROM} and will be copied during system start into the @code{RAM}.
3515*a9fa9459Szrj@smallexample
3516*a9fa9459SzrjMEMORY
3517*a9fa9459Szrj  @{
3518*a9fa9459Szrj    ROM : ORIGIN = 0, LENGTH = 3M
3519*a9fa9459Szrj    RAM : ORIGIN = 0x10000000, LENGTH = 1M
3520*a9fa9459Szrj  @}
3521*a9fa9459Szrj
3522*a9fa9459SzrjREGION_ALIAS("REGION_TEXT", ROM);
3523*a9fa9459SzrjREGION_ALIAS("REGION_RODATA", ROM);
3524*a9fa9459SzrjREGION_ALIAS("REGION_DATA", RAM);
3525*a9fa9459SzrjREGION_ALIAS("REGION_BSS", RAM);
3526*a9fa9459Szrj@end smallexample
3527*a9fa9459Szrj@item C
3528*a9fa9459SzrjProgram code goes into the @code{ROM}.  Read-only data goes into the
3529*a9fa9459Szrj@code{ROM2}.  Read-write data goes into the @code{RAM}.  An image of the
3530*a9fa9459Szrjinitialized data is loaded into the @code{ROM2} and will be copied during
3531*a9fa9459Szrjsystem start into the @code{RAM}.
3532*a9fa9459Szrj@smallexample
3533*a9fa9459SzrjMEMORY
3534*a9fa9459Szrj  @{
3535*a9fa9459Szrj    ROM : ORIGIN = 0, LENGTH = 2M
3536*a9fa9459Szrj    ROM2 : ORIGIN = 0x10000000, LENGTH = 1M
3537*a9fa9459Szrj    RAM : ORIGIN = 0x20000000, LENGTH = 1M
3538*a9fa9459Szrj  @}
3539*a9fa9459Szrj
3540*a9fa9459SzrjREGION_ALIAS("REGION_TEXT", ROM);
3541*a9fa9459SzrjREGION_ALIAS("REGION_RODATA", ROM2);
3542*a9fa9459SzrjREGION_ALIAS("REGION_DATA", RAM);
3543*a9fa9459SzrjREGION_ALIAS("REGION_BSS", RAM);
3544*a9fa9459Szrj@end smallexample
3545*a9fa9459Szrj@end table
3546*a9fa9459Szrj
3547*a9fa9459SzrjIt is possible to write a common system initialization routine to copy the
3548*a9fa9459Szrj@code{.data} section from @code{ROM} or @code{ROM2} into the @code{RAM} if
3549*a9fa9459Szrjnecessary:
3550*a9fa9459Szrj@smallexample
3551*a9fa9459Szrj#include <string.h>
3552*a9fa9459Szrj
3553*a9fa9459Szrjextern char data_start [];
3554*a9fa9459Szrjextern char data_size [];
3555*a9fa9459Szrjextern char data_load_start [];
3556*a9fa9459Szrj
3557*a9fa9459Szrjvoid copy_data(void)
3558*a9fa9459Szrj@{
3559*a9fa9459Szrj  if (data_start != data_load_start)
3560*a9fa9459Szrj    @{
3561*a9fa9459Szrj      memcpy(data_start, data_load_start, (size_t) data_size);
3562*a9fa9459Szrj    @}
3563*a9fa9459Szrj@}
3564*a9fa9459Szrj@end smallexample
3565*a9fa9459Szrj
3566*a9fa9459Szrj@node Miscellaneous Commands
3567*a9fa9459Szrj@subsection Other Linker Script Commands
3568*a9fa9459SzrjThere are a few other linker scripts commands.
3569*a9fa9459Szrj
3570*a9fa9459Szrj@table @code
3571*a9fa9459Szrj@item ASSERT(@var{exp}, @var{message})
3572*a9fa9459Szrj@kindex ASSERT
3573*a9fa9459Szrj@cindex assertion in linker script
3574*a9fa9459SzrjEnsure that @var{exp} is non-zero.  If it is zero, then exit the linker
3575*a9fa9459Szrjwith an error code, and print @var{message}.
3576*a9fa9459Szrj
3577*a9fa9459SzrjNote that assertions are checked before the final stages of linking
3578*a9fa9459Szrjtake place.  This means that expressions involving symbols PROVIDEd
3579*a9fa9459Szrjinside section definitions will fail if the user has not set values
3580*a9fa9459Szrjfor those symbols.  The only exception to this rule is PROVIDEd
3581*a9fa9459Szrjsymbols that just reference dot.  Thus an assertion like this:
3582*a9fa9459Szrj
3583*a9fa9459Szrj@smallexample
3584*a9fa9459Szrj  .stack :
3585*a9fa9459Szrj  @{
3586*a9fa9459Szrj    PROVIDE (__stack = .);
3587*a9fa9459Szrj    PROVIDE (__stack_size = 0x100);
3588*a9fa9459Szrj    ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
3589*a9fa9459Szrj  @}
3590*a9fa9459Szrj@end smallexample
3591*a9fa9459Szrj
3592*a9fa9459Szrjwill fail if @code{__stack_size} is not defined elsewhere.  Symbols
3593*a9fa9459SzrjPROVIDEd outside of section definitions are evaluated earlier, so they
3594*a9fa9459Szrjcan be used inside ASSERTions.  Thus:
3595*a9fa9459Szrj
3596*a9fa9459Szrj@smallexample
3597*a9fa9459Szrj  PROVIDE (__stack_size = 0x100);
3598*a9fa9459Szrj  .stack :
3599*a9fa9459Szrj  @{
3600*a9fa9459Szrj    PROVIDE (__stack = .);
3601*a9fa9459Szrj    ASSERT ((__stack > (_end + __stack_size)), "Error: No room left for the stack");
3602*a9fa9459Szrj  @}
3603*a9fa9459Szrj@end smallexample
3604*a9fa9459Szrj
3605*a9fa9459Szrjwill work.
3606*a9fa9459Szrj
3607*a9fa9459Szrj@item EXTERN(@var{symbol} @var{symbol} @dots{})
3608*a9fa9459Szrj@kindex EXTERN
3609*a9fa9459Szrj@cindex undefined symbol in linker script
3610*a9fa9459SzrjForce @var{symbol} to be entered in the output file as an undefined
3611*a9fa9459Szrjsymbol.  Doing this may, for example, trigger linking of additional
3612*a9fa9459Szrjmodules from standard libraries.  You may list several @var{symbol}s for
3613*a9fa9459Szrjeach @code{EXTERN}, and you may use @code{EXTERN} multiple times.  This
3614*a9fa9459Szrjcommand has the same effect as the @samp{-u} command-line option.
3615*a9fa9459Szrj
3616*a9fa9459Szrj@item FORCE_COMMON_ALLOCATION
3617*a9fa9459Szrj@kindex FORCE_COMMON_ALLOCATION
3618*a9fa9459Szrj@cindex common allocation in linker script
3619*a9fa9459SzrjThis command has the same effect as the @samp{-d} command-line option:
3620*a9fa9459Szrjto make @command{ld} assign space to common symbols even if a relocatable
3621*a9fa9459Szrjoutput file is specified (@samp{-r}).
3622*a9fa9459Szrj
3623*a9fa9459Szrj@item INHIBIT_COMMON_ALLOCATION
3624*a9fa9459Szrj@kindex INHIBIT_COMMON_ALLOCATION
3625*a9fa9459Szrj@cindex common allocation in linker script
3626*a9fa9459SzrjThis command has the same effect as the @samp{--no-define-common}
3627*a9fa9459Szrjcommand-line option: to make @code{ld} omit the assignment of addresses
3628*a9fa9459Szrjto common symbols even for a non-relocatable output file.
3629*a9fa9459Szrj
3630*a9fa9459Szrj@item INSERT [ AFTER | BEFORE ] @var{output_section}
3631*a9fa9459Szrj@kindex INSERT
3632*a9fa9459Szrj@cindex insert user script into default script
3633*a9fa9459SzrjThis command is typically used in a script specified by @samp{-T} to
3634*a9fa9459Szrjaugment the default @code{SECTIONS} with, for example, overlays.  It
3635*a9fa9459Szrjinserts all prior linker script statements after (or before)
3636*a9fa9459Szrj@var{output_section}, and also causes @samp{-T} to not override the
3637*a9fa9459Szrjdefault linker script.  The exact insertion point is as for orphan
3638*a9fa9459Szrjsections.  @xref{Location Counter}.  The insertion happens after the
3639*a9fa9459Szrjlinker has mapped input sections to output sections.  Prior to the
3640*a9fa9459Szrjinsertion, since @samp{-T} scripts are parsed before the default
3641*a9fa9459Szrjlinker script, statements in the @samp{-T} script occur before the
3642*a9fa9459Szrjdefault linker script statements in the internal linker representation
3643*a9fa9459Szrjof the script.  In particular, input section assignments will be made
3644*a9fa9459Szrjto @samp{-T} output sections before those in the default script.  Here
3645*a9fa9459Szrjis an example of how a @samp{-T} script using @code{INSERT} might look:
3646*a9fa9459Szrj
3647*a9fa9459Szrj@smallexample
3648*a9fa9459SzrjSECTIONS
3649*a9fa9459Szrj@{
3650*a9fa9459Szrj  OVERLAY :
3651*a9fa9459Szrj  @{
3652*a9fa9459Szrj    .ov1 @{ ov1*(.text) @}
3653*a9fa9459Szrj    .ov2 @{ ov2*(.text) @}
3654*a9fa9459Szrj  @}
3655*a9fa9459Szrj@}
3656*a9fa9459SzrjINSERT AFTER .text;
3657*a9fa9459Szrj@end smallexample
3658*a9fa9459Szrj
3659*a9fa9459Szrj@item NOCROSSREFS(@var{section} @var{section} @dots{})
3660*a9fa9459Szrj@kindex NOCROSSREFS(@var{sections})
3661*a9fa9459Szrj@cindex cross references
3662*a9fa9459SzrjThis command may be used to tell @command{ld} to issue an error about any
3663*a9fa9459Szrjreferences among certain output sections.
3664*a9fa9459Szrj
3665*a9fa9459SzrjIn certain types of programs, particularly on embedded systems when
3666*a9fa9459Szrjusing overlays, when one section is loaded into memory, another section
3667*a9fa9459Szrjwill not be.  Any direct references between the two sections would be
3668*a9fa9459Szrjerrors.  For example, it would be an error if code in one section called
3669*a9fa9459Szrja function defined in the other section.
3670*a9fa9459Szrj
3671*a9fa9459SzrjThe @code{NOCROSSREFS} command takes a list of output section names.  If
3672*a9fa9459Szrj@command{ld} detects any cross references between the sections, it reports
3673*a9fa9459Szrjan error and returns a non-zero exit status.  Note that the
3674*a9fa9459Szrj@code{NOCROSSREFS} command uses output section names, not input section
3675*a9fa9459Szrjnames.
3676*a9fa9459Szrj
3677*a9fa9459Szrj@item NOCROSSREFS_TO(@var{tosection} @var{fromsection} @dots{})
3678*a9fa9459Szrj@kindex NOCROSSREFS_TO(@var{tosection} @var{fromsections})
3679*a9fa9459Szrj@cindex cross references
3680*a9fa9459SzrjThis command may be used to tell @command{ld} to issue an error about any
3681*a9fa9459Szrjreferences to one section from a list of other sections.
3682*a9fa9459Szrj
3683*a9fa9459SzrjThe @code{NOCROSSREFS} command is useful when ensuring that two or more
3684*a9fa9459Szrjoutput sections are entirely independent but there are situations where
3685*a9fa9459Szrja one-way dependency is needed. For example, in a multi-core application
3686*a9fa9459Szrjthere may be shared code that can be called from each core but for safety
3687*a9fa9459Szrjmust never call back.
3688*a9fa9459Szrj
3689*a9fa9459SzrjThe @code{NOCROSSREFS_TO} command takes a list of output section names.
3690*a9fa9459SzrjThe first section can not be referenced from any of the other sections.
3691*a9fa9459SzrjIf @command{ld} detects any references to the first section from any of
3692*a9fa9459Szrjthe other sections, it reports an error and returns a non-zero exit
3693*a9fa9459Szrjstatus.  Note that the @code{NOCROSSREFS_TO} command uses output section
3694*a9fa9459Szrjnames, not input section names.
3695*a9fa9459Szrj
3696*a9fa9459Szrj@ifclear SingleFormat
3697*a9fa9459Szrj@item OUTPUT_ARCH(@var{bfdarch})
3698*a9fa9459Szrj@kindex OUTPUT_ARCH(@var{bfdarch})
3699*a9fa9459Szrj@cindex machine architecture
3700*a9fa9459Szrj@cindex architecture
3701*a9fa9459SzrjSpecify a particular output machine architecture.  The argument is one
3702*a9fa9459Szrjof the names used by the BFD library (@pxref{BFD}).  You can see the
3703*a9fa9459Szrjarchitecture of an object file by using the @code{objdump} program with
3704*a9fa9459Szrjthe @samp{-f} option.
3705*a9fa9459Szrj@end ifclear
3706*a9fa9459Szrj
3707*a9fa9459Szrj@item LD_FEATURE(@var{string})
3708*a9fa9459Szrj@kindex LD_FEATURE(@var{string})
3709*a9fa9459SzrjThis command may be used to modify @command{ld} behavior.  If
3710*a9fa9459Szrj@var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
3711*a9fa9459Szrjin a script are simply treated as numbers everywhere.
3712*a9fa9459Szrj@xref{Expression Section}.
3713*a9fa9459Szrj@end table
3714*a9fa9459Szrj
3715*a9fa9459Szrj@node Assignments
3716*a9fa9459Szrj@section Assigning Values to Symbols
3717*a9fa9459Szrj@cindex assignment in scripts
3718*a9fa9459Szrj@cindex symbol definition, scripts
3719*a9fa9459Szrj@cindex variables, defining
3720*a9fa9459SzrjYou may assign a value to a symbol in a linker script.  This will define
3721*a9fa9459Szrjthe symbol and place it into the symbol table with a global scope.
3722*a9fa9459Szrj
3723*a9fa9459Szrj@menu
3724*a9fa9459Szrj* Simple Assignments::		Simple Assignments
3725*a9fa9459Szrj* HIDDEN::			HIDDEN
3726*a9fa9459Szrj* PROVIDE::			PROVIDE
3727*a9fa9459Szrj* PROVIDE_HIDDEN::		PROVIDE_HIDDEN
3728*a9fa9459Szrj* Source Code Reference::	How to use a linker script defined symbol in source code
3729*a9fa9459Szrj@end menu
3730*a9fa9459Szrj
3731*a9fa9459Szrj@node Simple Assignments
3732*a9fa9459Szrj@subsection Simple Assignments
3733*a9fa9459Szrj
3734*a9fa9459SzrjYou may assign to a symbol using any of the C assignment operators:
3735*a9fa9459Szrj
3736*a9fa9459Szrj@table @code
3737*a9fa9459Szrj@item @var{symbol} = @var{expression} ;
3738*a9fa9459Szrj@itemx @var{symbol} += @var{expression} ;
3739*a9fa9459Szrj@itemx @var{symbol} -= @var{expression} ;
3740*a9fa9459Szrj@itemx @var{symbol} *= @var{expression} ;
3741*a9fa9459Szrj@itemx @var{symbol} /= @var{expression} ;
3742*a9fa9459Szrj@itemx @var{symbol} <<= @var{expression} ;
3743*a9fa9459Szrj@itemx @var{symbol} >>= @var{expression} ;
3744*a9fa9459Szrj@itemx @var{symbol} &= @var{expression} ;
3745*a9fa9459Szrj@itemx @var{symbol} |= @var{expression} ;
3746*a9fa9459Szrj@end table
3747*a9fa9459Szrj
3748*a9fa9459SzrjThe first case will define @var{symbol} to the value of
3749*a9fa9459Szrj@var{expression}.  In the other cases, @var{symbol} must already be
3750*a9fa9459Szrjdefined, and the value will be adjusted accordingly.
3751*a9fa9459Szrj
3752*a9fa9459SzrjThe special symbol name @samp{.} indicates the location counter.  You
3753*a9fa9459Szrjmay only use this within a @code{SECTIONS} command.  @xref{Location Counter}.
3754*a9fa9459Szrj
3755*a9fa9459SzrjThe semicolon after @var{expression} is required.
3756*a9fa9459Szrj
3757*a9fa9459SzrjExpressions are defined below; see @ref{Expressions}.
3758*a9fa9459Szrj
3759*a9fa9459SzrjYou may write symbol assignments as commands in their own right, or as
3760*a9fa9459Szrjstatements within a @code{SECTIONS} command, or as part of an output
3761*a9fa9459Szrjsection description in a @code{SECTIONS} command.
3762*a9fa9459Szrj
3763*a9fa9459SzrjThe section of the symbol will be set from the section of the
3764*a9fa9459Szrjexpression; for more information, see @ref{Expression Section}.
3765*a9fa9459Szrj
3766*a9fa9459SzrjHere is an example showing the three different places that symbol
3767*a9fa9459Szrjassignments may be used:
3768*a9fa9459Szrj
3769*a9fa9459Szrj@smallexample
3770*a9fa9459Szrjfloating_point = 0;
3771*a9fa9459SzrjSECTIONS
3772*a9fa9459Szrj@{
3773*a9fa9459Szrj  .text :
3774*a9fa9459Szrj    @{
3775*a9fa9459Szrj      *(.text)
3776*a9fa9459Szrj      _etext = .;
3777*a9fa9459Szrj    @}
3778*a9fa9459Szrj  _bdata = (. + 3) & ~ 3;
3779*a9fa9459Szrj  .data : @{ *(.data) @}
3780*a9fa9459Szrj@}
3781*a9fa9459Szrj@end smallexample
3782*a9fa9459Szrj@noindent
3783*a9fa9459SzrjIn this example, the symbol @samp{floating_point} will be defined as
3784*a9fa9459Szrjzero.  The symbol @samp{_etext} will be defined as the address following
3785*a9fa9459Szrjthe last @samp{.text} input section.  The symbol @samp{_bdata} will be
3786*a9fa9459Szrjdefined as the address following the @samp{.text} output section aligned
3787*a9fa9459Szrjupward to a 4 byte boundary.
3788*a9fa9459Szrj
3789*a9fa9459Szrj@node HIDDEN
3790*a9fa9459Szrj@subsection HIDDEN
3791*a9fa9459Szrj@cindex HIDDEN
3792*a9fa9459SzrjFor ELF targeted ports, define a symbol that will be hidden and won't be
3793*a9fa9459Szrjexported.  The syntax is @code{HIDDEN(@var{symbol} = @var{expression})}.
3794*a9fa9459Szrj
3795*a9fa9459SzrjHere is the example from @ref{Simple Assignments}, rewritten to use
3796*a9fa9459Szrj@code{HIDDEN}:
3797*a9fa9459Szrj
3798*a9fa9459Szrj@smallexample
3799*a9fa9459SzrjHIDDEN(floating_point = 0);
3800*a9fa9459SzrjSECTIONS
3801*a9fa9459Szrj@{
3802*a9fa9459Szrj  .text :
3803*a9fa9459Szrj    @{
3804*a9fa9459Szrj      *(.text)
3805*a9fa9459Szrj      HIDDEN(_etext = .);
3806*a9fa9459Szrj    @}
3807*a9fa9459Szrj  HIDDEN(_bdata = (. + 3) & ~ 3);
3808*a9fa9459Szrj  .data : @{ *(.data) @}
3809*a9fa9459Szrj@}
3810*a9fa9459Szrj@end smallexample
3811*a9fa9459Szrj@noindent
3812*a9fa9459SzrjIn this case none of the three symbols will be visible outside this module.
3813*a9fa9459Szrj
3814*a9fa9459Szrj@node PROVIDE
3815*a9fa9459Szrj@subsection PROVIDE
3816*a9fa9459Szrj@cindex PROVIDE
3817*a9fa9459SzrjIn some cases, it is desirable for a linker script to define a symbol
3818*a9fa9459Szrjonly if it is referenced and is not defined by any object included in
3819*a9fa9459Szrjthe link.  For example, traditional linkers defined the symbol
3820*a9fa9459Szrj@samp{etext}.  However, ANSI C requires that the user be able to use
3821*a9fa9459Szrj@samp{etext} as a function name without encountering an error.  The
3822*a9fa9459Szrj@code{PROVIDE} keyword may be used to define a symbol, such as
3823*a9fa9459Szrj@samp{etext}, only if it is referenced but not defined.  The syntax is
3824*a9fa9459Szrj@code{PROVIDE(@var{symbol} = @var{expression})}.
3825*a9fa9459Szrj
3826*a9fa9459SzrjHere is an example of using @code{PROVIDE} to define @samp{etext}:
3827*a9fa9459Szrj@smallexample
3828*a9fa9459SzrjSECTIONS
3829*a9fa9459Szrj@{
3830*a9fa9459Szrj  .text :
3831*a9fa9459Szrj    @{
3832*a9fa9459Szrj      *(.text)
3833*a9fa9459Szrj      _etext = .;
3834*a9fa9459Szrj      PROVIDE(etext = .);
3835*a9fa9459Szrj    @}
3836*a9fa9459Szrj@}
3837*a9fa9459Szrj@end smallexample
3838*a9fa9459Szrj
3839*a9fa9459SzrjIn this example, if the program defines @samp{_etext} (with a leading
3840*a9fa9459Szrjunderscore), the linker will give a multiple definition error.  If, on
3841*a9fa9459Szrjthe other hand, the program defines @samp{etext} (with no leading
3842*a9fa9459Szrjunderscore), the linker will silently use the definition in the program.
3843*a9fa9459SzrjIf the program references @samp{etext} but does not define it, the
3844*a9fa9459Szrjlinker will use the definition in the linker script.
3845*a9fa9459Szrj
3846*a9fa9459Szrj@node PROVIDE_HIDDEN
3847*a9fa9459Szrj@subsection PROVIDE_HIDDEN
3848*a9fa9459Szrj@cindex PROVIDE_HIDDEN
3849*a9fa9459SzrjSimilar to @code{PROVIDE}.  For ELF targeted ports, the symbol will be
3850*a9fa9459Szrjhidden and won't be exported.
3851*a9fa9459Szrj
3852*a9fa9459Szrj@node Source Code Reference
3853*a9fa9459Szrj@subsection Source Code Reference
3854*a9fa9459Szrj
3855*a9fa9459SzrjAccessing a linker script defined variable from source code is not
3856*a9fa9459Szrjintuitive.  In particular a linker script symbol is not equivalent to
3857*a9fa9459Szrja variable declaration in a high level language, it is instead a
3858*a9fa9459Szrjsymbol that does not have a value.
3859*a9fa9459Szrj
3860*a9fa9459SzrjBefore going further, it is important to note that compilers often
3861*a9fa9459Szrjtransform names in the source code into different names when they are
3862*a9fa9459Szrjstored in the symbol table.  For example, Fortran compilers commonly
3863*a9fa9459Szrjprepend or append an underscore, and C++ performs extensive @samp{name
3864*a9fa9459Szrjmangling}.  Therefore there might be a discrepancy between the name
3865*a9fa9459Szrjof a variable as it is used in source code and the name of the same
3866*a9fa9459Szrjvariable as it is defined in a linker script.  For example in C a
3867*a9fa9459Szrjlinker script variable might be referred to as:
3868*a9fa9459Szrj
3869*a9fa9459Szrj@smallexample
3870*a9fa9459Szrj  extern int foo;
3871*a9fa9459Szrj@end smallexample
3872*a9fa9459Szrj
3873*a9fa9459SzrjBut in the linker script it might be defined as:
3874*a9fa9459Szrj
3875*a9fa9459Szrj@smallexample
3876*a9fa9459Szrj  _foo = 1000;
3877*a9fa9459Szrj@end smallexample
3878*a9fa9459Szrj
3879*a9fa9459SzrjIn the remaining examples however it is assumed that no name
3880*a9fa9459Szrjtransformation has taken place.
3881*a9fa9459Szrj
3882*a9fa9459SzrjWhen a symbol is declared in a high level language such as C, two
3883*a9fa9459Szrjthings happen.  The first is that the compiler reserves enough space
3884*a9fa9459Szrjin the program's memory to hold the @emph{value} of the symbol.  The
3885*a9fa9459Szrjsecond is that the compiler creates an entry in the program's symbol
3886*a9fa9459Szrjtable which holds the symbol's @emph{address}.  ie the symbol table
3887*a9fa9459Szrjcontains the address of the block of memory holding the symbol's
3888*a9fa9459Szrjvalue.  So for example the following C declaration, at file scope:
3889*a9fa9459Szrj
3890*a9fa9459Szrj@smallexample
3891*a9fa9459Szrj  int foo = 1000;
3892*a9fa9459Szrj@end smallexample
3893*a9fa9459Szrj
3894*a9fa9459Szrjcreates an entry called @samp{foo} in the symbol table.  This entry
3895*a9fa9459Szrjholds the address of an @samp{int} sized block of memory where the
3896*a9fa9459Szrjnumber 1000 is initially stored.
3897*a9fa9459Szrj
3898*a9fa9459SzrjWhen a program references a symbol the compiler generates code that
3899*a9fa9459Szrjfirst accesses the symbol table to find the address of the symbol's
3900*a9fa9459Szrjmemory block and then code to read the value from that memory block.
3901*a9fa9459SzrjSo:
3902*a9fa9459Szrj
3903*a9fa9459Szrj@smallexample
3904*a9fa9459Szrj  foo = 1;
3905*a9fa9459Szrj@end smallexample
3906*a9fa9459Szrj
3907*a9fa9459Szrjlooks up the symbol @samp{foo} in the symbol table, gets the address
3908*a9fa9459Szrjassociated with this symbol and then writes the value 1 into that
3909*a9fa9459Szrjaddress.  Whereas:
3910*a9fa9459Szrj
3911*a9fa9459Szrj@smallexample
3912*a9fa9459Szrj  int * a = & foo;
3913*a9fa9459Szrj@end smallexample
3914*a9fa9459Szrj
3915*a9fa9459Szrjlooks up the symbol @samp{foo} in the symbol table, gets its address
3916*a9fa9459Szrjand then copies this address into the block of memory associated with
3917*a9fa9459Szrjthe variable @samp{a}.
3918*a9fa9459Szrj
3919*a9fa9459SzrjLinker scripts symbol declarations, by contrast, create an entry in
3920*a9fa9459Szrjthe symbol table but do not assign any memory to them.  Thus they are
3921*a9fa9459Szrjan address without a value.  So for example the linker script definition:
3922*a9fa9459Szrj
3923*a9fa9459Szrj@smallexample
3924*a9fa9459Szrj  foo = 1000;
3925*a9fa9459Szrj@end smallexample
3926*a9fa9459Szrj
3927*a9fa9459Szrjcreates an entry in the symbol table called @samp{foo} which holds
3928*a9fa9459Szrjthe address of memory location 1000, but nothing special is stored at
3929*a9fa9459Szrjaddress 1000.  This means that you cannot access the @emph{value} of a
3930*a9fa9459Szrjlinker script defined symbol - it has no value - all you can do is
3931*a9fa9459Szrjaccess the @emph{address} of a linker script defined symbol.
3932*a9fa9459Szrj
3933*a9fa9459SzrjHence when you are using a linker script defined symbol in source code
3934*a9fa9459Szrjyou should always take the address of the symbol, and never attempt to
3935*a9fa9459Szrjuse its value.  For example suppose you want to copy the contents of a
3936*a9fa9459Szrjsection of memory called .ROM into a section called .FLASH and the
3937*a9fa9459Szrjlinker script contains these declarations:
3938*a9fa9459Szrj
3939*a9fa9459Szrj@smallexample
3940*a9fa9459Szrj@group
3941*a9fa9459Szrj  start_of_ROM   = .ROM;
3942*a9fa9459Szrj  end_of_ROM     = .ROM + sizeof (.ROM);
3943*a9fa9459Szrj  start_of_FLASH = .FLASH;
3944*a9fa9459Szrj@end group
3945*a9fa9459Szrj@end smallexample
3946*a9fa9459Szrj
3947*a9fa9459SzrjThen the C source code to perform the copy would be:
3948*a9fa9459Szrj
3949*a9fa9459Szrj@smallexample
3950*a9fa9459Szrj@group
3951*a9fa9459Szrj  extern char start_of_ROM, end_of_ROM, start_of_FLASH;
3952*a9fa9459Szrj
3953*a9fa9459Szrj  memcpy (& start_of_FLASH, & start_of_ROM, & end_of_ROM - & start_of_ROM);
3954*a9fa9459Szrj@end group
3955*a9fa9459Szrj@end smallexample
3956*a9fa9459Szrj
3957*a9fa9459SzrjNote the use of the @samp{&} operators.  These are correct.
3958*a9fa9459SzrjAlternatively the symbols can be treated as the names of vectors or
3959*a9fa9459Szrjarrays and then the code will again work as expected:
3960*a9fa9459Szrj
3961*a9fa9459Szrj@smallexample
3962*a9fa9459Szrj@group
3963*a9fa9459Szrj  extern char start_of_ROM[], end_of_ROM[], start_of_FLASH[];
3964*a9fa9459Szrj
3965*a9fa9459Szrj  memcpy (start_of_FLASH, start_of_ROM, end_of_ROM - start_of_ROM);
3966*a9fa9459Szrj@end group
3967*a9fa9459Szrj@end smallexample
3968*a9fa9459Szrj
3969*a9fa9459SzrjNote how using this method does not require the use of @samp{&}
3970*a9fa9459Szrjoperators.
3971*a9fa9459Szrj
3972*a9fa9459Szrj@node SECTIONS
3973*a9fa9459Szrj@section SECTIONS Command
3974*a9fa9459Szrj@kindex SECTIONS
3975*a9fa9459SzrjThe @code{SECTIONS} command tells the linker how to map input sections
3976*a9fa9459Szrjinto output sections, and how to place the output sections in memory.
3977*a9fa9459Szrj
3978*a9fa9459SzrjThe format of the @code{SECTIONS} command is:
3979*a9fa9459Szrj@smallexample
3980*a9fa9459SzrjSECTIONS
3981*a9fa9459Szrj@{
3982*a9fa9459Szrj  @var{sections-command}
3983*a9fa9459Szrj  @var{sections-command}
3984*a9fa9459Szrj  @dots{}
3985*a9fa9459Szrj@}
3986*a9fa9459Szrj@end smallexample
3987*a9fa9459Szrj
3988*a9fa9459SzrjEach @var{sections-command} may of be one of the following:
3989*a9fa9459Szrj
3990*a9fa9459Szrj@itemize @bullet
3991*a9fa9459Szrj@item
3992*a9fa9459Szrjan @code{ENTRY} command (@pxref{Entry Point,,Entry command})
3993*a9fa9459Szrj@item
3994*a9fa9459Szrja symbol assignment (@pxref{Assignments})
3995*a9fa9459Szrj@item
3996*a9fa9459Szrjan output section description
3997*a9fa9459Szrj@item
3998*a9fa9459Szrjan overlay description
3999*a9fa9459Szrj@end itemize
4000*a9fa9459Szrj
4001*a9fa9459SzrjThe @code{ENTRY} command and symbol assignments are permitted inside the
4002*a9fa9459Szrj@code{SECTIONS} command for convenience in using the location counter in
4003*a9fa9459Szrjthose commands.  This can also make the linker script easier to
4004*a9fa9459Szrjunderstand because you can use those commands at meaningful points in
4005*a9fa9459Szrjthe layout of the output file.
4006*a9fa9459Szrj
4007*a9fa9459SzrjOutput section descriptions and overlay descriptions are described
4008*a9fa9459Szrjbelow.
4009*a9fa9459Szrj
4010*a9fa9459SzrjIf you do not use a @code{SECTIONS} command in your linker script, the
4011*a9fa9459Szrjlinker will place each input section into an identically named output
4012*a9fa9459Szrjsection in the order that the sections are first encountered in the
4013*a9fa9459Szrjinput files.  If all input sections are present in the first file, for
4014*a9fa9459Szrjexample, the order of sections in the output file will match the order
4015*a9fa9459Szrjin the first input file.  The first section will be at address zero.
4016*a9fa9459Szrj
4017*a9fa9459Szrj@menu
4018*a9fa9459Szrj* Output Section Description::	Output section description
4019*a9fa9459Szrj* Output Section Name::		Output section name
4020*a9fa9459Szrj* Output Section Address::	Output section address
4021*a9fa9459Szrj* Input Section::		Input section description
4022*a9fa9459Szrj* Output Section Data::		Output section data
4023*a9fa9459Szrj* Output Section Keywords::	Output section keywords
4024*a9fa9459Szrj* Output Section Discarding::	Output section discarding
4025*a9fa9459Szrj* Output Section Attributes::	Output section attributes
4026*a9fa9459Szrj* Overlay Description::		Overlay description
4027*a9fa9459Szrj@end menu
4028*a9fa9459Szrj
4029*a9fa9459Szrj@node Output Section Description
4030*a9fa9459Szrj@subsection Output Section Description
4031*a9fa9459SzrjThe full description of an output section looks like this:
4032*a9fa9459Szrj@smallexample
4033*a9fa9459Szrj@group
4034*a9fa9459Szrj@var{section} [@var{address}] [(@var{type})] :
4035*a9fa9459Szrj  [AT(@var{lma})]
4036*a9fa9459Szrj  [ALIGN(@var{section_align}) | ALIGN_WITH_INPUT]
4037*a9fa9459Szrj  [SUBALIGN(@var{subsection_align})]
4038*a9fa9459Szrj  [@var{constraint}]
4039*a9fa9459Szrj  @{
4040*a9fa9459Szrj    @var{output-section-command}
4041*a9fa9459Szrj    @var{output-section-command}
4042*a9fa9459Szrj    @dots{}
4043*a9fa9459Szrj  @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}] [,]
4044*a9fa9459Szrj@end group
4045*a9fa9459Szrj@end smallexample
4046*a9fa9459Szrj
4047*a9fa9459SzrjMost output sections do not use most of the optional section attributes.
4048*a9fa9459Szrj
4049*a9fa9459SzrjThe whitespace around @var{section} is required, so that the section
4050*a9fa9459Szrjname is unambiguous.  The colon and the curly braces are also required.
4051*a9fa9459SzrjThe comma at the end may be required if a @var{fillexp} is used and
4052*a9fa9459Szrjthe next @var{sections-command} looks like a continuation of the expression.
4053*a9fa9459SzrjThe line breaks and other white space are optional.
4054*a9fa9459Szrj
4055*a9fa9459SzrjEach @var{output-section-command} may be one of the following:
4056*a9fa9459Szrj
4057*a9fa9459Szrj@itemize @bullet
4058*a9fa9459Szrj@item
4059*a9fa9459Szrja symbol assignment (@pxref{Assignments})
4060*a9fa9459Szrj@item
4061*a9fa9459Szrjan input section description (@pxref{Input Section})
4062*a9fa9459Szrj@item
4063*a9fa9459Szrjdata values to include directly (@pxref{Output Section Data})
4064*a9fa9459Szrj@item
4065*a9fa9459Szrja special output section keyword (@pxref{Output Section Keywords})
4066*a9fa9459Szrj@end itemize
4067*a9fa9459Szrj
4068*a9fa9459Szrj@node Output Section Name
4069*a9fa9459Szrj@subsection Output Section Name
4070*a9fa9459Szrj@cindex name, section
4071*a9fa9459Szrj@cindex section name
4072*a9fa9459SzrjThe name of the output section is @var{section}.  @var{section} must
4073*a9fa9459Szrjmeet the constraints of your output format.  In formats which only
4074*a9fa9459Szrjsupport a limited number of sections, such as @code{a.out}, the name
4075*a9fa9459Szrjmust be one of the names supported by the format (@code{a.out}, for
4076*a9fa9459Szrjexample, allows only @samp{.text}, @samp{.data} or @samp{.bss}). If the
4077*a9fa9459Szrjoutput format supports any number of sections, but with numbers and not
4078*a9fa9459Szrjnames (as is the case for Oasys), the name should be supplied as a
4079*a9fa9459Szrjquoted numeric string.  A section name may consist of any sequence of
4080*a9fa9459Szrjcharacters, but a name which contains any unusual characters such as
4081*a9fa9459Szrjcommas must be quoted.
4082*a9fa9459Szrj
4083*a9fa9459SzrjThe output section name @samp{/DISCARD/} is special; @ref{Output Section
4084*a9fa9459SzrjDiscarding}.
4085*a9fa9459Szrj
4086*a9fa9459Szrj@node Output Section Address
4087*a9fa9459Szrj@subsection Output Section Address
4088*a9fa9459Szrj@cindex address, section
4089*a9fa9459Szrj@cindex section address
4090*a9fa9459SzrjThe @var{address} is an expression for the VMA (the virtual memory
4091*a9fa9459Szrjaddress) of the output section.  This address is optional, but if it
4092*a9fa9459Szrjis provided then the output address will be set exactly as specified.
4093*a9fa9459Szrj
4094*a9fa9459SzrjIf the output address is not specified then one will be chosen for the
4095*a9fa9459Szrjsection, based on the heuristic below.  This address will be adjusted
4096*a9fa9459Szrjto fit the alignment requirement of the output section.  The
4097*a9fa9459Szrjalignment requirement is the strictest alignment of any input section
4098*a9fa9459Szrjcontained within the output section.
4099*a9fa9459Szrj
4100*a9fa9459SzrjThe output section address heuristic is as follows:
4101*a9fa9459Szrj
4102*a9fa9459Szrj@itemize @bullet
4103*a9fa9459Szrj@item
4104*a9fa9459SzrjIf an output memory @var{region} is set for the section then it
4105*a9fa9459Szrjis added to this region and its address will be the next free address
4106*a9fa9459Szrjin that region.
4107*a9fa9459Szrj
4108*a9fa9459Szrj@item
4109*a9fa9459SzrjIf the MEMORY command has been used to create a list of memory
4110*a9fa9459Szrjregions then the first region which has attributes compatible with the
4111*a9fa9459Szrjsection is selected to contain it.  The section's output address will
4112*a9fa9459Szrjbe the next free address in that region; @ref{MEMORY}.
4113*a9fa9459Szrj
4114*a9fa9459Szrj@item
4115*a9fa9459SzrjIf no memory regions were specified, or none match the section then
4116*a9fa9459Szrjthe output address will be based on the current value of the location
4117*a9fa9459Szrjcounter.
4118*a9fa9459Szrj@end itemize
4119*a9fa9459Szrj
4120*a9fa9459Szrj@noindent
4121*a9fa9459SzrjFor example:
4122*a9fa9459Szrj
4123*a9fa9459Szrj@smallexample
4124*a9fa9459Szrj.text . : @{ *(.text) @}
4125*a9fa9459Szrj@end smallexample
4126*a9fa9459Szrj
4127*a9fa9459Szrj@noindent
4128*a9fa9459Szrjand
4129*a9fa9459Szrj
4130*a9fa9459Szrj@smallexample
4131*a9fa9459Szrj.text : @{ *(.text) @}
4132*a9fa9459Szrj@end smallexample
4133*a9fa9459Szrj
4134*a9fa9459Szrj@noindent
4135*a9fa9459Szrjare subtly different.  The first will set the address of the
4136*a9fa9459Szrj@samp{.text} output section to the current value of the location
4137*a9fa9459Szrjcounter.  The second will set it to the current value of the location
4138*a9fa9459Szrjcounter aligned to the strictest alignment of any of the @samp{.text}
4139*a9fa9459Szrjinput sections.
4140*a9fa9459Szrj
4141*a9fa9459SzrjThe @var{address} may be an arbitrary expression; @ref{Expressions}.
4142*a9fa9459SzrjFor example, if you want to align the section on a 0x10 byte boundary,
4143*a9fa9459Szrjso that the lowest four bits of the section address are zero, you could
4144*a9fa9459Szrjdo something like this:
4145*a9fa9459Szrj@smallexample
4146*a9fa9459Szrj.text ALIGN(0x10) : @{ *(.text) @}
4147*a9fa9459Szrj@end smallexample
4148*a9fa9459Szrj@noindent
4149*a9fa9459SzrjThis works because @code{ALIGN} returns the current location counter
4150*a9fa9459Szrjaligned upward to the specified value.
4151*a9fa9459Szrj
4152*a9fa9459SzrjSpecifying @var{address} for a section will change the value of the
4153*a9fa9459Szrjlocation counter, provided that the section is non-empty.  (Empty
4154*a9fa9459Szrjsections are ignored).
4155*a9fa9459Szrj
4156*a9fa9459Szrj@node Input Section
4157*a9fa9459Szrj@subsection Input Section Description
4158*a9fa9459Szrj@cindex input sections
4159*a9fa9459Szrj@cindex mapping input sections to output sections
4160*a9fa9459SzrjThe most common output section command is an input section description.
4161*a9fa9459Szrj
4162*a9fa9459SzrjThe input section description is the most basic linker script operation.
4163*a9fa9459SzrjYou use output sections to tell the linker how to lay out your program
4164*a9fa9459Szrjin memory.  You use input section descriptions to tell the linker how to
4165*a9fa9459Szrjmap the input files into your memory layout.
4166*a9fa9459Szrj
4167*a9fa9459Szrj@menu
4168*a9fa9459Szrj* Input Section Basics::	Input section basics
4169*a9fa9459Szrj* Input Section Wildcards::	Input section wildcard patterns
4170*a9fa9459Szrj* Input Section Common::	Input section for common symbols
4171*a9fa9459Szrj* Input Section Keep::		Input section and garbage collection
4172*a9fa9459Szrj* Input Section Example::	Input section example
4173*a9fa9459Szrj@end menu
4174*a9fa9459Szrj
4175*a9fa9459Szrj@node Input Section Basics
4176*a9fa9459Szrj@subsubsection Input Section Basics
4177*a9fa9459Szrj@cindex input section basics
4178*a9fa9459SzrjAn input section description consists of a file name optionally followed
4179*a9fa9459Szrjby a list of section names in parentheses.
4180*a9fa9459Szrj
4181*a9fa9459SzrjThe file name and the section name may be wildcard patterns, which we
4182*a9fa9459Szrjdescribe further below (@pxref{Input Section Wildcards}).
4183*a9fa9459Szrj
4184*a9fa9459SzrjThe most common input section description is to include all input
4185*a9fa9459Szrjsections with a particular name in the output section.  For example, to
4186*a9fa9459Szrjinclude all input @samp{.text} sections, you would write:
4187*a9fa9459Szrj@smallexample
4188*a9fa9459Szrj*(.text)
4189*a9fa9459Szrj@end smallexample
4190*a9fa9459Szrj@noindent
4191*a9fa9459SzrjHere the @samp{*} is a wildcard which matches any file name.  To exclude a list
4192*a9fa9459Szrjof files from matching the file name wildcard, EXCLUDE_FILE may be used to
4193*a9fa9459Szrjmatch all files except the ones specified in the EXCLUDE_FILE list.  For
4194*a9fa9459Szrjexample:
4195*a9fa9459Szrj@smallexample
4196*a9fa9459Szrj*(EXCLUDE_FILE (*crtend.o *otherfile.o) .ctors)
4197*a9fa9459Szrj@end smallexample
4198*a9fa9459Szrjwill cause all .ctors sections from all files except @file{crtend.o} and
4199*a9fa9459Szrj@file{otherfile.o} to be included.
4200*a9fa9459Szrj
4201*a9fa9459SzrjThere are two ways to include more than one section:
4202*a9fa9459Szrj@smallexample
4203*a9fa9459Szrj*(.text .rdata)
4204*a9fa9459Szrj*(.text) *(.rdata)
4205*a9fa9459Szrj@end smallexample
4206*a9fa9459Szrj@noindent
4207*a9fa9459SzrjThe difference between these is the order in which the @samp{.text} and
4208*a9fa9459Szrj@samp{.rdata} input sections will appear in the output section.  In the
4209*a9fa9459Szrjfirst example, they will be intermingled, appearing in the same order as
4210*a9fa9459Szrjthey are found in the linker input.  In the second example, all
4211*a9fa9459Szrj@samp{.text} input sections will appear first, followed by all
4212*a9fa9459Szrj@samp{.rdata} input sections.
4213*a9fa9459Szrj
4214*a9fa9459SzrjYou can specify a file name to include sections from a particular file.
4215*a9fa9459SzrjYou would do this if one or more of your files contain special data that
4216*a9fa9459Szrjneeds to be at a particular location in memory.  For example:
4217*a9fa9459Szrj@smallexample
4218*a9fa9459Szrjdata.o(.data)
4219*a9fa9459Szrj@end smallexample
4220*a9fa9459Szrj
4221*a9fa9459SzrjTo refine the sections that are included based on the section flags
4222*a9fa9459Szrjof an input section, INPUT_SECTION_FLAGS may be used.
4223*a9fa9459Szrj
4224*a9fa9459SzrjHere is a simple example for using Section header flags for ELF sections:
4225*a9fa9459Szrj
4226*a9fa9459Szrj@smallexample
4227*a9fa9459Szrj@group
4228*a9fa9459SzrjSECTIONS @{
4229*a9fa9459Szrj  .text : @{ INPUT_SECTION_FLAGS (SHF_MERGE & SHF_STRINGS) *(.text) @}
4230*a9fa9459Szrj  .text2 :  @{ INPUT_SECTION_FLAGS (!SHF_WRITE) *(.text) @}
4231*a9fa9459Szrj@}
4232*a9fa9459Szrj@end group
4233*a9fa9459Szrj@end smallexample
4234*a9fa9459Szrj
4235*a9fa9459SzrjIn this example, the output section @samp{.text} will be comprised of any
4236*a9fa9459Szrjinput section matching the name *(.text) whose section header flags
4237*a9fa9459Szrj@code{SHF_MERGE} and @code{SHF_STRINGS} are set.  The output section
4238*a9fa9459Szrj@samp{.text2} will be comprised of any input section matching the name *(.text)
4239*a9fa9459Szrjwhose section header flag @code{SHF_WRITE} is clear.
4240*a9fa9459Szrj
4241*a9fa9459SzrjYou can also specify files within archives by writing a pattern
4242*a9fa9459Szrjmatching the archive, a colon, then the pattern matching the file,
4243*a9fa9459Szrjwith no whitespace around the colon.
4244*a9fa9459Szrj
4245*a9fa9459Szrj@table @samp
4246*a9fa9459Szrj@item archive:file
4247*a9fa9459Szrjmatches file within archive
4248*a9fa9459Szrj@item archive:
4249*a9fa9459Szrjmatches the whole archive
4250*a9fa9459Szrj@item :file
4251*a9fa9459Szrjmatches file but not one in an archive
4252*a9fa9459Szrj@end table
4253*a9fa9459Szrj
4254*a9fa9459SzrjEither one or both of @samp{archive} and @samp{file} can contain shell
4255*a9fa9459Szrjwildcards.  On DOS based file systems, the linker will assume that a
4256*a9fa9459Szrjsingle letter followed by a colon is a drive specifier, so
4257*a9fa9459Szrj@samp{c:myfile.o} is a simple file specification, not @samp{myfile.o}
4258*a9fa9459Szrjwithin an archive called @samp{c}.  @samp{archive:file} filespecs may
4259*a9fa9459Szrjalso be used within an @code{EXCLUDE_FILE} list, but may not appear in
4260*a9fa9459Szrjother linker script contexts.  For instance, you cannot extract a file
4261*a9fa9459Szrjfrom an archive by using @samp{archive:file} in an @code{INPUT}
4262*a9fa9459Szrjcommand.
4263*a9fa9459Szrj
4264*a9fa9459SzrjIf you use a file name without a list of sections, then all sections in
4265*a9fa9459Szrjthe input file will be included in the output section.  This is not
4266*a9fa9459Szrjcommonly done, but it may by useful on occasion.  For example:
4267*a9fa9459Szrj@smallexample
4268*a9fa9459Szrjdata.o
4269*a9fa9459Szrj@end smallexample
4270*a9fa9459Szrj
4271*a9fa9459SzrjWhen you use a file name which is not an @samp{archive:file} specifier
4272*a9fa9459Szrjand does not contain any wild card
4273*a9fa9459Szrjcharacters, the linker will first see if you also specified the file
4274*a9fa9459Szrjname on the linker command line or in an @code{INPUT} command.  If you
4275*a9fa9459Szrjdid not, the linker will attempt to open the file as an input file, as
4276*a9fa9459Szrjthough it appeared on the command line.  Note that this differs from an
4277*a9fa9459Szrj@code{INPUT} command, because the linker will not search for the file in
4278*a9fa9459Szrjthe archive search path.
4279*a9fa9459Szrj
4280*a9fa9459Szrj@node Input Section Wildcards
4281*a9fa9459Szrj@subsubsection Input Section Wildcard Patterns
4282*a9fa9459Szrj@cindex input section wildcards
4283*a9fa9459Szrj@cindex wildcard file name patterns
4284*a9fa9459Szrj@cindex file name wildcard patterns
4285*a9fa9459Szrj@cindex section name wildcard patterns
4286*a9fa9459SzrjIn an input section description, either the file name or the section
4287*a9fa9459Szrjname or both may be wildcard patterns.
4288*a9fa9459Szrj
4289*a9fa9459SzrjThe file name of @samp{*} seen in many examples is a simple wildcard
4290*a9fa9459Szrjpattern for the file name.
4291*a9fa9459Szrj
4292*a9fa9459SzrjThe wildcard patterns are like those used by the Unix shell.
4293*a9fa9459Szrj
4294*a9fa9459Szrj@table @samp
4295*a9fa9459Szrj@item *
4296*a9fa9459Szrjmatches any number of characters
4297*a9fa9459Szrj@item ?
4298*a9fa9459Szrjmatches any single character
4299*a9fa9459Szrj@item [@var{chars}]
4300*a9fa9459Szrjmatches a single instance of any of the @var{chars}; the @samp{-}
4301*a9fa9459Szrjcharacter may be used to specify a range of characters, as in
4302*a9fa9459Szrj@samp{[a-z]} to match any lower case letter
4303*a9fa9459Szrj@item \
4304*a9fa9459Szrjquotes the following character
4305*a9fa9459Szrj@end table
4306*a9fa9459Szrj
4307*a9fa9459SzrjWhen a file name is matched with a wildcard, the wildcard characters
4308*a9fa9459Szrjwill not match a @samp{/} character (used to separate directory names on
4309*a9fa9459SzrjUnix).  A pattern consisting of a single @samp{*} character is an
4310*a9fa9459Szrjexception; it will always match any file name, whether it contains a
4311*a9fa9459Szrj@samp{/} or not.  In a section name, the wildcard characters will match
4312*a9fa9459Szrja @samp{/} character.
4313*a9fa9459Szrj
4314*a9fa9459SzrjFile name wildcard patterns only match files which are explicitly
4315*a9fa9459Szrjspecified on the command line or in an @code{INPUT} command.  The linker
4316*a9fa9459Szrjdoes not search directories to expand wildcards.
4317*a9fa9459Szrj
4318*a9fa9459SzrjIf a file name matches more than one wildcard pattern, or if a file name
4319*a9fa9459Szrjappears explicitly and is also matched by a wildcard pattern, the linker
4320*a9fa9459Szrjwill use the first match in the linker script.  For example, this
4321*a9fa9459Szrjsequence of input section descriptions is probably in error, because the
4322*a9fa9459Szrj@file{data.o} rule will not be used:
4323*a9fa9459Szrj@smallexample
4324*a9fa9459Szrj.data : @{ *(.data) @}
4325*a9fa9459Szrj.data1 : @{ data.o(.data) @}
4326*a9fa9459Szrj@end smallexample
4327*a9fa9459Szrj
4328*a9fa9459Szrj@cindex SORT_BY_NAME
4329*a9fa9459SzrjNormally, the linker will place files and sections matched by wildcards
4330*a9fa9459Szrjin the order in which they are seen during the link.  You can change
4331*a9fa9459Szrjthis by using the @code{SORT_BY_NAME} keyword, which appears before a wildcard
4332*a9fa9459Szrjpattern in parentheses (e.g., @code{SORT_BY_NAME(.text*)}).  When the
4333*a9fa9459Szrj@code{SORT_BY_NAME} keyword is used, the linker will sort the files or sections
4334*a9fa9459Szrjinto ascending order by name before placing them in the output file.
4335*a9fa9459Szrj
4336*a9fa9459Szrj@cindex SORT_BY_ALIGNMENT
4337*a9fa9459Szrj@code{SORT_BY_ALIGNMENT} is very similar to @code{SORT_BY_NAME}. The
4338*a9fa9459Szrjdifference is @code{SORT_BY_ALIGNMENT} will sort sections into
4339*a9fa9459Szrjdescending order by alignment before placing them in the output file.
4340*a9fa9459SzrjLarger alignments are placed before smaller alignments in order to
4341*a9fa9459Szrjreduce the amount of padding necessary.
4342*a9fa9459Szrj
4343*a9fa9459Szrj@cindex SORT_BY_INIT_PRIORITY
4344*a9fa9459Szrj@code{SORT_BY_INIT_PRIORITY} is very similar to @code{SORT_BY_NAME}. The
4345*a9fa9459Szrjdifference is @code{SORT_BY_INIT_PRIORITY} will sort sections into
4346*a9fa9459Szrjascending order by numerical value of the GCC init_priority attribute
4347*a9fa9459Szrjencoded in the section name before placing them in the output file.
4348*a9fa9459Szrj
4349*a9fa9459Szrj@cindex SORT
4350*a9fa9459Szrj@code{SORT} is an alias for @code{SORT_BY_NAME}.
4351*a9fa9459Szrj
4352*a9fa9459SzrjWhen there are nested section sorting commands in linker script, there
4353*a9fa9459Szrjcan be at most 1 level of nesting for section sorting commands.
4354*a9fa9459Szrj
4355*a9fa9459Szrj@enumerate
4356*a9fa9459Szrj@item
4357*a9fa9459Szrj@code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
4358*a9fa9459SzrjIt will sort the input sections by name first, then by alignment if two
4359*a9fa9459Szrjsections have the same name.
4360*a9fa9459Szrj@item
4361*a9fa9459Szrj@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
4362*a9fa9459SzrjIt will sort the input sections by alignment first, then by name if two
4363*a9fa9459Szrjsections have the same alignment.
4364*a9fa9459Szrj@item
4365*a9fa9459Szrj@code{SORT_BY_NAME} (@code{SORT_BY_NAME} (wildcard section pattern)) is
4366*a9fa9459Szrjtreated the same as @code{SORT_BY_NAME} (wildcard section pattern).
4367*a9fa9459Szrj@item
4368*a9fa9459Szrj@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern))
4369*a9fa9459Szrjis treated the same as @code{SORT_BY_ALIGNMENT} (wildcard section pattern).
4370*a9fa9459Szrj@item
4371*a9fa9459SzrjAll other nested section sorting commands are invalid.
4372*a9fa9459Szrj@end enumerate
4373*a9fa9459Szrj
4374*a9fa9459SzrjWhen both command line section sorting option and linker script
4375*a9fa9459Szrjsection sorting command are used, section sorting command always
4376*a9fa9459Szrjtakes precedence over the command line option.
4377*a9fa9459Szrj
4378*a9fa9459SzrjIf the section sorting command in linker script isn't nested, the
4379*a9fa9459Szrjcommand line option will make the section sorting command to be
4380*a9fa9459Szrjtreated as nested sorting command.
4381*a9fa9459Szrj
4382*a9fa9459Szrj@enumerate
4383*a9fa9459Szrj@item
4384*a9fa9459Szrj@code{SORT_BY_NAME} (wildcard section pattern ) with
4385*a9fa9459Szrj@option{--sort-sections alignment} is equivalent to
4386*a9fa9459Szrj@code{SORT_BY_NAME} (@code{SORT_BY_ALIGNMENT} (wildcard section pattern)).
4387*a9fa9459Szrj@item
4388*a9fa9459Szrj@code{SORT_BY_ALIGNMENT} (wildcard section pattern) with
4389*a9fa9459Szrj@option{--sort-section name} is equivalent to
4390*a9fa9459Szrj@code{SORT_BY_ALIGNMENT} (@code{SORT_BY_NAME} (wildcard section pattern)).
4391*a9fa9459Szrj@end enumerate
4392*a9fa9459Szrj
4393*a9fa9459SzrjIf the section sorting command in linker script is nested, the
4394*a9fa9459Szrjcommand line option will be ignored.
4395*a9fa9459Szrj
4396*a9fa9459Szrj@cindex SORT_NONE
4397*a9fa9459Szrj@code{SORT_NONE} disables section sorting by ignoring the command line
4398*a9fa9459Szrjsection sorting option.
4399*a9fa9459Szrj
4400*a9fa9459SzrjIf you ever get confused about where input sections are going, use the
4401*a9fa9459Szrj@samp{-M} linker option to generate a map file.  The map file shows
4402*a9fa9459Szrjprecisely how input sections are mapped to output sections.
4403*a9fa9459Szrj
4404*a9fa9459SzrjThis example shows how wildcard patterns might be used to partition
4405*a9fa9459Szrjfiles.  This linker script directs the linker to place all @samp{.text}
4406*a9fa9459Szrjsections in @samp{.text} and all @samp{.bss} sections in @samp{.bss}.
4407*a9fa9459SzrjThe linker will place the @samp{.data} section from all files beginning
4408*a9fa9459Szrjwith an upper case character in @samp{.DATA}; for all other files, the
4409*a9fa9459Szrjlinker will place the @samp{.data} section in @samp{.data}.
4410*a9fa9459Szrj@smallexample
4411*a9fa9459Szrj@group
4412*a9fa9459SzrjSECTIONS @{
4413*a9fa9459Szrj  .text : @{ *(.text) @}
4414*a9fa9459Szrj  .DATA : @{ [A-Z]*(.data) @}
4415*a9fa9459Szrj  .data : @{ *(.data) @}
4416*a9fa9459Szrj  .bss : @{ *(.bss) @}
4417*a9fa9459Szrj@}
4418*a9fa9459Szrj@end group
4419*a9fa9459Szrj@end smallexample
4420*a9fa9459Szrj
4421*a9fa9459Szrj@node Input Section Common
4422*a9fa9459Szrj@subsubsection Input Section for Common Symbols
4423*a9fa9459Szrj@cindex common symbol placement
4424*a9fa9459Szrj@cindex uninitialized data placement
4425*a9fa9459SzrjA special notation is needed for common symbols, because in many object
4426*a9fa9459Szrjfile formats common symbols do not have a particular input section.  The
4427*a9fa9459Szrjlinker treats common symbols as though they are in an input section
4428*a9fa9459Szrjnamed @samp{COMMON}.
4429*a9fa9459Szrj
4430*a9fa9459SzrjYou may use file names with the @samp{COMMON} section just as with any
4431*a9fa9459Szrjother input sections.  You can use this to place common symbols from a
4432*a9fa9459Szrjparticular input file in one section while common symbols from other
4433*a9fa9459Szrjinput files are placed in another section.
4434*a9fa9459Szrj
4435*a9fa9459SzrjIn most cases, common symbols in input files will be placed in the
4436*a9fa9459Szrj@samp{.bss} section in the output file.  For example:
4437*a9fa9459Szrj@smallexample
4438*a9fa9459Szrj.bss @{ *(.bss) *(COMMON) @}
4439*a9fa9459Szrj@end smallexample
4440*a9fa9459Szrj
4441*a9fa9459Szrj@cindex scommon section
4442*a9fa9459Szrj@cindex small common symbols
4443*a9fa9459SzrjSome object file formats have more than one type of common symbol.  For
4444*a9fa9459Szrjexample, the MIPS ELF object file format distinguishes standard common
4445*a9fa9459Szrjsymbols and small common symbols.  In this case, the linker will use a
4446*a9fa9459Szrjdifferent special section name for other types of common symbols.  In
4447*a9fa9459Szrjthe case of MIPS ELF, the linker uses @samp{COMMON} for standard common
4448*a9fa9459Szrjsymbols and @samp{.scommon} for small common symbols.  This permits you
4449*a9fa9459Szrjto map the different types of common symbols into memory at different
4450*a9fa9459Szrjlocations.
4451*a9fa9459Szrj
4452*a9fa9459Szrj@cindex [COMMON]
4453*a9fa9459SzrjYou will sometimes see @samp{[COMMON]} in old linker scripts.  This
4454*a9fa9459Szrjnotation is now considered obsolete.  It is equivalent to
4455*a9fa9459Szrj@samp{*(COMMON)}.
4456*a9fa9459Szrj
4457*a9fa9459Szrj@node Input Section Keep
4458*a9fa9459Szrj@subsubsection Input Section and Garbage Collection
4459*a9fa9459Szrj@cindex KEEP
4460*a9fa9459Szrj@cindex garbage collection
4461*a9fa9459SzrjWhen link-time garbage collection is in use (@samp{--gc-sections}),
4462*a9fa9459Szrjit is often useful to mark sections that should not be eliminated.
4463*a9fa9459SzrjThis is accomplished by surrounding an input section's wildcard entry
4464*a9fa9459Szrjwith @code{KEEP()}, as in @code{KEEP(*(.init))} or
4465*a9fa9459Szrj@code{KEEP(SORT_BY_NAME(*)(.ctors))}.
4466*a9fa9459Szrj
4467*a9fa9459Szrj@node Input Section Example
4468*a9fa9459Szrj@subsubsection Input Section Example
4469*a9fa9459SzrjThe following example is a complete linker script.  It tells the linker
4470*a9fa9459Szrjto read all of the sections from file @file{all.o} and place them at the
4471*a9fa9459Szrjstart of output section @samp{outputa} which starts at location
4472*a9fa9459Szrj@samp{0x10000}.  All of section @samp{.input1} from file @file{foo.o}
4473*a9fa9459Szrjfollows immediately, in the same output section.  All of section
4474*a9fa9459Szrj@samp{.input2} from @file{foo.o} goes into output section
4475*a9fa9459Szrj@samp{outputb}, followed by section @samp{.input1} from @file{foo1.o}.
4476*a9fa9459SzrjAll of the remaining @samp{.input1} and @samp{.input2} sections from any
4477*a9fa9459Szrjfiles are written to output section @samp{outputc}.
4478*a9fa9459Szrj
4479*a9fa9459Szrj@smallexample
4480*a9fa9459Szrj@group
4481*a9fa9459SzrjSECTIONS @{
4482*a9fa9459Szrj  outputa 0x10000 :
4483*a9fa9459Szrj    @{
4484*a9fa9459Szrj    all.o
4485*a9fa9459Szrj    foo.o (.input1)
4486*a9fa9459Szrj    @}
4487*a9fa9459Szrj@end group
4488*a9fa9459Szrj@group
4489*a9fa9459Szrj  outputb :
4490*a9fa9459Szrj    @{
4491*a9fa9459Szrj    foo.o (.input2)
4492*a9fa9459Szrj    foo1.o (.input1)
4493*a9fa9459Szrj    @}
4494*a9fa9459Szrj@end group
4495*a9fa9459Szrj@group
4496*a9fa9459Szrj  outputc :
4497*a9fa9459Szrj    @{
4498*a9fa9459Szrj    *(.input1)
4499*a9fa9459Szrj    *(.input2)
4500*a9fa9459Szrj    @}
4501*a9fa9459Szrj@}
4502*a9fa9459Szrj@end group
4503*a9fa9459Szrj@end smallexample
4504*a9fa9459Szrj
4505*a9fa9459Szrj@node Output Section Data
4506*a9fa9459Szrj@subsection Output Section Data
4507*a9fa9459Szrj@cindex data
4508*a9fa9459Szrj@cindex section data
4509*a9fa9459Szrj@cindex output section data
4510*a9fa9459Szrj@kindex BYTE(@var{expression})
4511*a9fa9459Szrj@kindex SHORT(@var{expression})
4512*a9fa9459Szrj@kindex LONG(@var{expression})
4513*a9fa9459Szrj@kindex QUAD(@var{expression})
4514*a9fa9459Szrj@kindex SQUAD(@var{expression})
4515*a9fa9459SzrjYou can include explicit bytes of data in an output section by using
4516*a9fa9459Szrj@code{BYTE}, @code{SHORT}, @code{LONG}, @code{QUAD}, or @code{SQUAD} as
4517*a9fa9459Szrjan output section command.  Each keyword is followed by an expression in
4518*a9fa9459Szrjparentheses providing the value to store (@pxref{Expressions}).  The
4519*a9fa9459Szrjvalue of the expression is stored at the current value of the location
4520*a9fa9459Szrjcounter.
4521*a9fa9459Szrj
4522*a9fa9459SzrjThe @code{BYTE}, @code{SHORT}, @code{LONG}, and @code{QUAD} commands
4523*a9fa9459Szrjstore one, two, four, and eight bytes (respectively).  After storing the
4524*a9fa9459Szrjbytes, the location counter is incremented by the number of bytes
4525*a9fa9459Szrjstored.
4526*a9fa9459Szrj
4527*a9fa9459SzrjFor example, this will store the byte 1 followed by the four byte value
4528*a9fa9459Szrjof the symbol @samp{addr}:
4529*a9fa9459Szrj@smallexample
4530*a9fa9459SzrjBYTE(1)
4531*a9fa9459SzrjLONG(addr)
4532*a9fa9459Szrj@end smallexample
4533*a9fa9459Szrj
4534*a9fa9459SzrjWhen using a 64 bit host or target, @code{QUAD} and @code{SQUAD} are the
4535*a9fa9459Szrjsame; they both store an 8 byte, or 64 bit, value.  When both host and
4536*a9fa9459Szrjtarget are 32 bits, an expression is computed as 32 bits.  In this case
4537*a9fa9459Szrj@code{QUAD} stores a 32 bit value zero extended to 64 bits, and
4538*a9fa9459Szrj@code{SQUAD} stores a 32 bit value sign extended to 64 bits.
4539*a9fa9459Szrj
4540*a9fa9459SzrjIf the object file format of the output file has an explicit endianness,
4541*a9fa9459Szrjwhich is the normal case, the value will be stored in that endianness.
4542*a9fa9459SzrjWhen the object file format does not have an explicit endianness, as is
4543*a9fa9459Szrjtrue of, for example, S-records, the value will be stored in the
4544*a9fa9459Szrjendianness of the first input object file.
4545*a9fa9459Szrj
4546*a9fa9459SzrjNote---these commands only work inside a section description and not
4547*a9fa9459Szrjbetween them, so the following will produce an error from the linker:
4548*a9fa9459Szrj@smallexample
4549*a9fa9459SzrjSECTIONS @{@ .text : @{@ *(.text) @}@ LONG(1) .data : @{@ *(.data) @}@ @}@
4550*a9fa9459Szrj@end smallexample
4551*a9fa9459Szrjwhereas this will work:
4552*a9fa9459Szrj@smallexample
4553*a9fa9459SzrjSECTIONS @{@ .text : @{@ *(.text) ; LONG(1) @}@ .data : @{@ *(.data) @}@ @}@
4554*a9fa9459Szrj@end smallexample
4555*a9fa9459Szrj
4556*a9fa9459Szrj@kindex FILL(@var{expression})
4557*a9fa9459Szrj@cindex holes, filling
4558*a9fa9459Szrj@cindex unspecified memory
4559*a9fa9459SzrjYou may use the @code{FILL} command to set the fill pattern for the
4560*a9fa9459Szrjcurrent section.  It is followed by an expression in parentheses.  Any
4561*a9fa9459Szrjotherwise unspecified regions of memory within the section (for example,
4562*a9fa9459Szrjgaps left due to the required alignment of input sections) are filled
4563*a9fa9459Szrjwith the value of the expression, repeated as
4564*a9fa9459Szrjnecessary.  A @code{FILL} statement covers memory locations after the
4565*a9fa9459Szrjpoint at which it occurs in the section definition; by including more
4566*a9fa9459Szrjthan one @code{FILL} statement, you can have different fill patterns in
4567*a9fa9459Szrjdifferent parts of an output section.
4568*a9fa9459Szrj
4569*a9fa9459SzrjThis example shows how to fill unspecified regions of memory with the
4570*a9fa9459Szrjvalue @samp{0x90}:
4571*a9fa9459Szrj@smallexample
4572*a9fa9459SzrjFILL(0x90909090)
4573*a9fa9459Szrj@end smallexample
4574*a9fa9459Szrj
4575*a9fa9459SzrjThe @code{FILL} command is similar to the @samp{=@var{fillexp}} output
4576*a9fa9459Szrjsection attribute, but it only affects the
4577*a9fa9459Szrjpart of the section following the @code{FILL} command, rather than the
4578*a9fa9459Szrjentire section.  If both are used, the @code{FILL} command takes
4579*a9fa9459Szrjprecedence.  @xref{Output Section Fill}, for details on the fill
4580*a9fa9459Szrjexpression.
4581*a9fa9459Szrj
4582*a9fa9459Szrj@node Output Section Keywords
4583*a9fa9459Szrj@subsection Output Section Keywords
4584*a9fa9459SzrjThere are a couple of keywords which can appear as output section
4585*a9fa9459Szrjcommands.
4586*a9fa9459Szrj
4587*a9fa9459Szrj@table @code
4588*a9fa9459Szrj@kindex CREATE_OBJECT_SYMBOLS
4589*a9fa9459Szrj@cindex input filename symbols
4590*a9fa9459Szrj@cindex filename symbols
4591*a9fa9459Szrj@item CREATE_OBJECT_SYMBOLS
4592*a9fa9459SzrjThe command tells the linker to create a symbol for each input file.
4593*a9fa9459SzrjThe name of each symbol will be the name of the corresponding input
4594*a9fa9459Szrjfile.  The section of each symbol will be the output section in which
4595*a9fa9459Szrjthe @code{CREATE_OBJECT_SYMBOLS} command appears.
4596*a9fa9459Szrj
4597*a9fa9459SzrjThis is conventional for the a.out object file format.  It is not
4598*a9fa9459Szrjnormally used for any other object file format.
4599*a9fa9459Szrj
4600*a9fa9459Szrj@kindex CONSTRUCTORS
4601*a9fa9459Szrj@cindex C++ constructors, arranging in link
4602*a9fa9459Szrj@cindex constructors, arranging in link
4603*a9fa9459Szrj@item CONSTRUCTORS
4604*a9fa9459SzrjWhen linking using the a.out object file format, the linker uses an
4605*a9fa9459Szrjunusual set construct to support C++ global constructors and
4606*a9fa9459Szrjdestructors.  When linking object file formats which do not support
4607*a9fa9459Szrjarbitrary sections, such as ECOFF and XCOFF, the linker will
4608*a9fa9459Szrjautomatically recognize C++ global constructors and destructors by name.
4609*a9fa9459SzrjFor these object file formats, the @code{CONSTRUCTORS} command tells the
4610*a9fa9459Szrjlinker to place constructor information in the output section where the
4611*a9fa9459Szrj@code{CONSTRUCTORS} command appears.  The @code{CONSTRUCTORS} command is
4612*a9fa9459Szrjignored for other object file formats.
4613*a9fa9459Szrj
4614*a9fa9459SzrjThe symbol @w{@code{__CTOR_LIST__}} marks the start of the global
4615*a9fa9459Szrjconstructors, and the symbol @w{@code{__CTOR_END__}} marks the end.
4616*a9fa9459SzrjSimilarly, @w{@code{__DTOR_LIST__}} and @w{@code{__DTOR_END__}} mark
4617*a9fa9459Szrjthe start and end of the global destructors.  The
4618*a9fa9459Szrjfirst word in the list is the number of entries, followed by the address
4619*a9fa9459Szrjof each constructor or destructor, followed by a zero word.  The
4620*a9fa9459Szrjcompiler must arrange to actually run the code.  For these object file
4621*a9fa9459Szrjformats @sc{gnu} C++ normally calls constructors from a subroutine
4622*a9fa9459Szrj@code{__main}; a call to @code{__main} is automatically inserted into
4623*a9fa9459Szrjthe startup code for @code{main}.  @sc{gnu} C++ normally runs
4624*a9fa9459Szrjdestructors either by using @code{atexit}, or directly from the function
4625*a9fa9459Szrj@code{exit}.
4626*a9fa9459Szrj
4627*a9fa9459SzrjFor object file formats such as @code{COFF} or @code{ELF} which support
4628*a9fa9459Szrjarbitrary section names, @sc{gnu} C++ will normally arrange to put the
4629*a9fa9459Szrjaddresses of global constructors and destructors into the @code{.ctors}
4630*a9fa9459Szrjand @code{.dtors} sections.  Placing the following sequence into your
4631*a9fa9459Szrjlinker script will build the sort of table which the @sc{gnu} C++
4632*a9fa9459Szrjruntime code expects to see.
4633*a9fa9459Szrj
4634*a9fa9459Szrj@smallexample
4635*a9fa9459Szrj      __CTOR_LIST__ = .;
4636*a9fa9459Szrj      LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
4637*a9fa9459Szrj      *(.ctors)
4638*a9fa9459Szrj      LONG(0)
4639*a9fa9459Szrj      __CTOR_END__ = .;
4640*a9fa9459Szrj      __DTOR_LIST__ = .;
4641*a9fa9459Szrj      LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
4642*a9fa9459Szrj      *(.dtors)
4643*a9fa9459Szrj      LONG(0)
4644*a9fa9459Szrj      __DTOR_END__ = .;
4645*a9fa9459Szrj@end smallexample
4646*a9fa9459Szrj
4647*a9fa9459SzrjIf you are using the @sc{gnu} C++ support for initialization priority,
4648*a9fa9459Szrjwhich provides some control over the order in which global constructors
4649*a9fa9459Szrjare run, you must sort the constructors at link time to ensure that they
4650*a9fa9459Szrjare executed in the correct order.  When using the @code{CONSTRUCTORS}
4651*a9fa9459Szrjcommand, use @samp{SORT_BY_NAME(CONSTRUCTORS)} instead.  When using the
4652*a9fa9459Szrj@code{.ctors} and @code{.dtors} sections, use @samp{*(SORT_BY_NAME(.ctors))} and
4653*a9fa9459Szrj@samp{*(SORT_BY_NAME(.dtors))} instead of just @samp{*(.ctors)} and
4654*a9fa9459Szrj@samp{*(.dtors)}.
4655*a9fa9459Szrj
4656*a9fa9459SzrjNormally the compiler and linker will handle these issues automatically,
4657*a9fa9459Szrjand you will not need to concern yourself with them.  However, you may
4658*a9fa9459Szrjneed to consider this if you are using C++ and writing your own linker
4659*a9fa9459Szrjscripts.
4660*a9fa9459Szrj
4661*a9fa9459Szrj@end table
4662*a9fa9459Szrj
4663*a9fa9459Szrj@node Output Section Discarding
4664*a9fa9459Szrj@subsection Output Section Discarding
4665*a9fa9459Szrj@cindex discarding sections
4666*a9fa9459Szrj@cindex sections, discarding
4667*a9fa9459Szrj@cindex removing sections
4668*a9fa9459SzrjThe linker will not normally create output sections with no contents.
4669*a9fa9459SzrjThis is for convenience when referring to input sections that may or
4670*a9fa9459Szrjmay not be present in any of the input files.  For example:
4671*a9fa9459Szrj@smallexample
4672*a9fa9459Szrj.foo : @{ *(.foo) @}
4673*a9fa9459Szrj@end smallexample
4674*a9fa9459Szrj@noindent
4675*a9fa9459Szrjwill only create a @samp{.foo} section in the output file if there is a
4676*a9fa9459Szrj@samp{.foo} section in at least one input file, and if the input
4677*a9fa9459Szrjsections are not all empty.  Other link script directives that allocate
4678*a9fa9459Szrjspace in an output section will also create the output section.  So
4679*a9fa9459Szrjtoo will assignments to dot even if the assignment does not create
4680*a9fa9459Szrjspace, except for @samp{. = 0}, @samp{. = . + 0}, @samp{. = sym},
4681*a9fa9459Szrj@samp{. = . + sym} and @samp{. = ALIGN (. != 0, expr, 1)} when
4682*a9fa9459Szrj@samp{sym} is an absolute symbol of value 0 defined in the script.
4683*a9fa9459SzrjThis allows you to force output of an empty section with @samp{. = .}.
4684*a9fa9459Szrj
4685*a9fa9459SzrjThe linker will ignore address assignments (@pxref{Output Section Address})
4686*a9fa9459Szrjon discarded output sections, except when the linker script defines
4687*a9fa9459Szrjsymbols in the output section.  In that case the linker will obey
4688*a9fa9459Szrjthe address assignments, possibly advancing dot even though the
4689*a9fa9459Szrjsection is discarded.
4690*a9fa9459Szrj
4691*a9fa9459Szrj@cindex /DISCARD/
4692*a9fa9459SzrjThe special output section name @samp{/DISCARD/} may be used to discard
4693*a9fa9459Szrjinput sections.  Any input sections which are assigned to an output
4694*a9fa9459Szrjsection named @samp{/DISCARD/} are not included in the output file.
4695*a9fa9459Szrj
4696*a9fa9459Szrj@node Output Section Attributes
4697*a9fa9459Szrj@subsection Output Section Attributes
4698*a9fa9459Szrj@cindex output section attributes
4699*a9fa9459SzrjWe showed above that the full description of an output section looked
4700*a9fa9459Szrjlike this:
4701*a9fa9459Szrj
4702*a9fa9459Szrj@smallexample
4703*a9fa9459Szrj@group
4704*a9fa9459Szrj@var{section} [@var{address}] [(@var{type})] :
4705*a9fa9459Szrj  [AT(@var{lma})]
4706*a9fa9459Szrj  [ALIGN(@var{section_align})]
4707*a9fa9459Szrj  [SUBALIGN(@var{subsection_align})]
4708*a9fa9459Szrj  [@var{constraint}]
4709*a9fa9459Szrj  @{
4710*a9fa9459Szrj    @var{output-section-command}
4711*a9fa9459Szrj    @var{output-section-command}
4712*a9fa9459Szrj    @dots{}
4713*a9fa9459Szrj  @} [>@var{region}] [AT>@var{lma_region}] [:@var{phdr} :@var{phdr} @dots{}] [=@var{fillexp}]
4714*a9fa9459Szrj@end group
4715*a9fa9459Szrj@end smallexample
4716*a9fa9459Szrj
4717*a9fa9459SzrjWe've already described @var{section}, @var{address}, and
4718*a9fa9459Szrj@var{output-section-command}.  In this section we will describe the
4719*a9fa9459Szrjremaining section attributes.
4720*a9fa9459Szrj
4721*a9fa9459Szrj@menu
4722*a9fa9459Szrj* Output Section Type::		Output section type
4723*a9fa9459Szrj* Output Section LMA::		Output section LMA
4724*a9fa9459Szrj* Forced Output Alignment::	Forced Output Alignment
4725*a9fa9459Szrj* Forced Input Alignment::	Forced Input Alignment
4726*a9fa9459Szrj* Output Section Constraint::   Output section constraint
4727*a9fa9459Szrj* Output Section Region::	Output section region
4728*a9fa9459Szrj* Output Section Phdr::		Output section phdr
4729*a9fa9459Szrj* Output Section Fill::		Output section fill
4730*a9fa9459Szrj@end menu
4731*a9fa9459Szrj
4732*a9fa9459Szrj@node Output Section Type
4733*a9fa9459Szrj@subsubsection Output Section Type
4734*a9fa9459SzrjEach output section may have a type.  The type is a keyword in
4735*a9fa9459Szrjparentheses.  The following types are defined:
4736*a9fa9459Szrj
4737*a9fa9459Szrj@table @code
4738*a9fa9459Szrj@item NOLOAD
4739*a9fa9459SzrjThe section should be marked as not loadable, so that it will not be
4740*a9fa9459Szrjloaded into memory when the program is run.
4741*a9fa9459Szrj@item DSECT
4742*a9fa9459Szrj@itemx COPY
4743*a9fa9459Szrj@itemx INFO
4744*a9fa9459Szrj@itemx OVERLAY
4745*a9fa9459SzrjThese type names are supported for backward compatibility, and are
4746*a9fa9459Szrjrarely used.  They all have the same effect: the section should be
4747*a9fa9459Szrjmarked as not allocatable, so that no memory is allocated for the
4748*a9fa9459Szrjsection when the program is run.
4749*a9fa9459Szrj@end table
4750*a9fa9459Szrj
4751*a9fa9459Szrj@kindex NOLOAD
4752*a9fa9459Szrj@cindex prevent unnecessary loading
4753*a9fa9459Szrj@cindex loading, preventing
4754*a9fa9459SzrjThe linker normally sets the attributes of an output section based on
4755*a9fa9459Szrjthe input sections which map into it.  You can override this by using
4756*a9fa9459Szrjthe section type.  For example, in the script sample below, the
4757*a9fa9459Szrj@samp{ROM} section is addressed at memory location @samp{0} and does not
4758*a9fa9459Szrjneed to be loaded when the program is run.
4759*a9fa9459Szrj@smallexample
4760*a9fa9459Szrj@group
4761*a9fa9459SzrjSECTIONS @{
4762*a9fa9459Szrj  ROM 0 (NOLOAD) : @{ @dots{} @}
4763*a9fa9459Szrj  @dots{}
4764*a9fa9459Szrj@}
4765*a9fa9459Szrj@end group
4766*a9fa9459Szrj@end smallexample
4767*a9fa9459Szrj
4768*a9fa9459Szrj@node Output Section LMA
4769*a9fa9459Szrj@subsubsection Output Section LMA
4770*a9fa9459Szrj@kindex AT>@var{lma_region}
4771*a9fa9459Szrj@kindex AT(@var{lma})
4772*a9fa9459Szrj@cindex load address
4773*a9fa9459Szrj@cindex section load address
4774*a9fa9459SzrjEvery section has a virtual address (VMA) and a load address (LMA); see
4775*a9fa9459Szrj@ref{Basic Script Concepts}.  The virtual address is specified by the
4776*a9fa9459Szrj@pxref{Output Section Address} described earlier.  The load address is
4777*a9fa9459Szrjspecified by the @code{AT} or @code{AT>} keywords.  Specifying a load
4778*a9fa9459Szrjaddress is optional.
4779*a9fa9459Szrj
4780*a9fa9459SzrjThe @code{AT} keyword takes an expression as an argument.  This
4781*a9fa9459Szrjspecifies the exact load address of the section.  The @code{AT>} keyword
4782*a9fa9459Szrjtakes the name of a memory region as an argument.  @xref{MEMORY}.  The
4783*a9fa9459Szrjload address of the section is set to the next free address in the
4784*a9fa9459Szrjregion, aligned to the section's alignment requirements.
4785*a9fa9459Szrj
4786*a9fa9459SzrjIf neither @code{AT} nor @code{AT>} is specified for an allocatable
4787*a9fa9459Szrjsection, the linker will use the following heuristic to determine the
4788*a9fa9459Szrjload address:
4789*a9fa9459Szrj
4790*a9fa9459Szrj@itemize @bullet
4791*a9fa9459Szrj@item
4792*a9fa9459SzrjIf the section has a specific VMA address, then this is used as
4793*a9fa9459Szrjthe LMA address as well.
4794*a9fa9459Szrj
4795*a9fa9459Szrj@item
4796*a9fa9459SzrjIf the section is not allocatable then its LMA is set to its VMA.
4797*a9fa9459Szrj
4798*a9fa9459Szrj@item
4799*a9fa9459SzrjOtherwise if a memory region can be found that is compatible
4800*a9fa9459Szrjwith the current section, and this region contains at least one
4801*a9fa9459Szrjsection, then the LMA is set so the difference between the
4802*a9fa9459SzrjVMA and LMA is the same as the difference between the VMA and LMA of
4803*a9fa9459Szrjthe last section in the located region.
4804*a9fa9459Szrj
4805*a9fa9459Szrj@item
4806*a9fa9459SzrjIf no memory regions have been declared then a default region
4807*a9fa9459Szrjthat covers the entire address space is used in the previous step.
4808*a9fa9459Szrj
4809*a9fa9459Szrj@item
4810*a9fa9459SzrjIf no suitable region could be found, or there was no previous
4811*a9fa9459Szrjsection then the LMA is set equal to the VMA.
4812*a9fa9459Szrj@end itemize
4813*a9fa9459Szrj
4814*a9fa9459Szrj@cindex ROM initialized data
4815*a9fa9459Szrj@cindex initialized data in ROM
4816*a9fa9459SzrjThis feature is designed to make it easy to build a ROM image.  For
4817*a9fa9459Szrjexample, the following linker script creates three output sections: one
4818*a9fa9459Szrjcalled @samp{.text}, which starts at @code{0x1000}, one called
4819*a9fa9459Szrj@samp{.mdata}, which is loaded at the end of the @samp{.text} section
4820*a9fa9459Szrjeven though its VMA is @code{0x2000}, and one called @samp{.bss} to hold
4821*a9fa9459Szrjuninitialized data at address @code{0x3000}.  The symbol @code{_data} is
4822*a9fa9459Szrjdefined with the value @code{0x2000}, which shows that the location
4823*a9fa9459Szrjcounter holds the VMA value, not the LMA value.
4824*a9fa9459Szrj
4825*a9fa9459Szrj@smallexample
4826*a9fa9459Szrj@group
4827*a9fa9459SzrjSECTIONS
4828*a9fa9459Szrj  @{
4829*a9fa9459Szrj  .text 0x1000 : @{ *(.text) _etext = . ; @}
4830*a9fa9459Szrj  .mdata 0x2000 :
4831*a9fa9459Szrj    AT ( ADDR (.text) + SIZEOF (.text) )
4832*a9fa9459Szrj    @{ _data = . ; *(.data); _edata = . ;  @}
4833*a9fa9459Szrj  .bss 0x3000 :
4834*a9fa9459Szrj    @{ _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;@}
4835*a9fa9459Szrj@}
4836*a9fa9459Szrj@end group
4837*a9fa9459Szrj@end smallexample
4838*a9fa9459Szrj
4839*a9fa9459SzrjThe run-time initialization code for use with a program generated with
4840*a9fa9459Szrjthis linker script would include something like the following, to copy
4841*a9fa9459Szrjthe initialized data from the ROM image to its runtime address.  Notice
4842*a9fa9459Szrjhow this code takes advantage of the symbols defined by the linker
4843*a9fa9459Szrjscript.
4844*a9fa9459Szrj
4845*a9fa9459Szrj@smallexample
4846*a9fa9459Szrj@group
4847*a9fa9459Szrjextern char _etext, _data, _edata, _bstart, _bend;
4848*a9fa9459Szrjchar *src = &_etext;
4849*a9fa9459Szrjchar *dst = &_data;
4850*a9fa9459Szrj
4851*a9fa9459Szrj/* ROM has data at end of text; copy it.  */
4852*a9fa9459Szrjwhile (dst < &_edata)
4853*a9fa9459Szrj  *dst++ = *src++;
4854*a9fa9459Szrj
4855*a9fa9459Szrj/* Zero bss.  */
4856*a9fa9459Szrjfor (dst = &_bstart; dst< &_bend; dst++)
4857*a9fa9459Szrj  *dst = 0;
4858*a9fa9459Szrj@end group
4859*a9fa9459Szrj@end smallexample
4860*a9fa9459Szrj
4861*a9fa9459Szrj@node Forced Output Alignment
4862*a9fa9459Szrj@subsubsection Forced Output Alignment
4863*a9fa9459Szrj@kindex ALIGN(@var{section_align})
4864*a9fa9459Szrj@cindex forcing output section alignment
4865*a9fa9459Szrj@cindex output section alignment
4866*a9fa9459SzrjYou can increase an output section's alignment by using ALIGN.  As an
4867*a9fa9459Szrjalternative you can enforce that the difference between the VMA and LMA remains
4868*a9fa9459Szrjintact throughout this output section with the ALIGN_WITH_INPUT attribute.
4869*a9fa9459Szrj
4870*a9fa9459Szrj@node Forced Input Alignment
4871*a9fa9459Szrj@subsubsection Forced Input Alignment
4872*a9fa9459Szrj@kindex SUBALIGN(@var{subsection_align})
4873*a9fa9459Szrj@cindex forcing input section alignment
4874*a9fa9459Szrj@cindex input section alignment
4875*a9fa9459SzrjYou can force input section alignment within an output section by using
4876*a9fa9459SzrjSUBALIGN.  The value specified overrides any alignment given by input
4877*a9fa9459Szrjsections, whether larger or smaller.
4878*a9fa9459Szrj
4879*a9fa9459Szrj@node Output Section Constraint
4880*a9fa9459Szrj@subsubsection Output Section Constraint
4881*a9fa9459Szrj@kindex ONLY_IF_RO
4882*a9fa9459Szrj@kindex ONLY_IF_RW
4883*a9fa9459Szrj@cindex constraints on output sections
4884*a9fa9459SzrjYou can specify that an output section should only be created if all
4885*a9fa9459Szrjof its input sections are read-only or all of its input sections are
4886*a9fa9459Szrjread-write by using the keyword @code{ONLY_IF_RO} and
4887*a9fa9459Szrj@code{ONLY_IF_RW} respectively.
4888*a9fa9459Szrj
4889*a9fa9459Szrj@node Output Section Region
4890*a9fa9459Szrj@subsubsection Output Section Region
4891*a9fa9459Szrj@kindex >@var{region}
4892*a9fa9459Szrj@cindex section, assigning to memory region
4893*a9fa9459Szrj@cindex memory regions and sections
4894*a9fa9459SzrjYou can assign a section to a previously defined region of memory by
4895*a9fa9459Szrjusing @samp{>@var{region}}.  @xref{MEMORY}.
4896*a9fa9459Szrj
4897*a9fa9459SzrjHere is a simple example:
4898*a9fa9459Szrj@smallexample
4899*a9fa9459Szrj@group
4900*a9fa9459SzrjMEMORY @{ rom : ORIGIN = 0x1000, LENGTH = 0x1000 @}
4901*a9fa9459SzrjSECTIONS @{ ROM : @{ *(.text) @} >rom @}
4902*a9fa9459Szrj@end group
4903*a9fa9459Szrj@end smallexample
4904*a9fa9459Szrj
4905*a9fa9459Szrj@node Output Section Phdr
4906*a9fa9459Szrj@subsubsection Output Section Phdr
4907*a9fa9459Szrj@kindex :@var{phdr}
4908*a9fa9459Szrj@cindex section, assigning to program header
4909*a9fa9459Szrj@cindex program headers and sections
4910*a9fa9459SzrjYou can assign a section to a previously defined program segment by
4911*a9fa9459Szrjusing @samp{:@var{phdr}}.  @xref{PHDRS}.  If a section is assigned to
4912*a9fa9459Szrjone or more segments, then all subsequent allocated sections will be
4913*a9fa9459Szrjassigned to those segments as well, unless they use an explicitly
4914*a9fa9459Szrj@code{:@var{phdr}} modifier.  You can use @code{:NONE} to tell the
4915*a9fa9459Szrjlinker to not put the section in any segment at all.
4916*a9fa9459Szrj
4917*a9fa9459SzrjHere is a simple example:
4918*a9fa9459Szrj@smallexample
4919*a9fa9459Szrj@group
4920*a9fa9459SzrjPHDRS @{ text PT_LOAD ; @}
4921*a9fa9459SzrjSECTIONS @{ .text : @{ *(.text) @} :text @}
4922*a9fa9459Szrj@end group
4923*a9fa9459Szrj@end smallexample
4924*a9fa9459Szrj
4925*a9fa9459Szrj@node Output Section Fill
4926*a9fa9459Szrj@subsubsection Output Section Fill
4927*a9fa9459Szrj@kindex =@var{fillexp}
4928*a9fa9459Szrj@cindex section fill pattern
4929*a9fa9459Szrj@cindex fill pattern, entire section
4930*a9fa9459SzrjYou can set the fill pattern for an entire section by using
4931*a9fa9459Szrj@samp{=@var{fillexp}}.  @var{fillexp} is an expression
4932*a9fa9459Szrj(@pxref{Expressions}).  Any otherwise unspecified regions of memory
4933*a9fa9459Szrjwithin the output section (for example, gaps left due to the required
4934*a9fa9459Szrjalignment of input sections) will be filled with the value, repeated as
4935*a9fa9459Szrjnecessary.  If the fill expression is a simple hex number, ie. a string
4936*a9fa9459Szrjof hex digit starting with @samp{0x} and without a trailing @samp{k} or @samp{M}, then
4937*a9fa9459Szrjan arbitrarily long sequence of hex digits can be used to specify the
4938*a9fa9459Szrjfill pattern;  Leading zeros become part of the pattern too.  For all
4939*a9fa9459Szrjother cases, including extra parentheses or a unary @code{+}, the fill
4940*a9fa9459Szrjpattern is the four least significant bytes of the value of the
4941*a9fa9459Szrjexpression.  In all cases, the number is big-endian.
4942*a9fa9459Szrj
4943*a9fa9459SzrjYou can also change the fill value with a @code{FILL} command in the
4944*a9fa9459Szrjoutput section commands; (@pxref{Output Section Data}).
4945*a9fa9459Szrj
4946*a9fa9459SzrjHere is a simple example:
4947*a9fa9459Szrj@smallexample
4948*a9fa9459Szrj@group
4949*a9fa9459SzrjSECTIONS @{ .text : @{ *(.text) @} =0x90909090 @}
4950*a9fa9459Szrj@end group
4951*a9fa9459Szrj@end smallexample
4952*a9fa9459Szrj
4953*a9fa9459Szrj@node Overlay Description
4954*a9fa9459Szrj@subsection Overlay Description
4955*a9fa9459Szrj@kindex OVERLAY
4956*a9fa9459Szrj@cindex overlays
4957*a9fa9459SzrjAn overlay description provides an easy way to describe sections which
4958*a9fa9459Szrjare to be loaded as part of a single memory image but are to be run at
4959*a9fa9459Szrjthe same memory address.  At run time, some sort of overlay manager will
4960*a9fa9459Szrjcopy the overlaid sections in and out of the runtime memory address as
4961*a9fa9459Szrjrequired, perhaps by simply manipulating addressing bits.  This approach
4962*a9fa9459Szrjcan be useful, for example, when a certain region of memory is faster
4963*a9fa9459Szrjthan another.
4964*a9fa9459Szrj
4965*a9fa9459SzrjOverlays are described using the @code{OVERLAY} command.  The
4966*a9fa9459Szrj@code{OVERLAY} command is used within a @code{SECTIONS} command, like an
4967*a9fa9459Szrjoutput section description.  The full syntax of the @code{OVERLAY}
4968*a9fa9459Szrjcommand is as follows:
4969*a9fa9459Szrj@smallexample
4970*a9fa9459Szrj@group
4971*a9fa9459SzrjOVERLAY [@var{start}] : [NOCROSSREFS] [AT ( @var{ldaddr} )]
4972*a9fa9459Szrj  @{
4973*a9fa9459Szrj    @var{secname1}
4974*a9fa9459Szrj      @{
4975*a9fa9459Szrj        @var{output-section-command}
4976*a9fa9459Szrj        @var{output-section-command}
4977*a9fa9459Szrj        @dots{}
4978*a9fa9459Szrj      @} [:@var{phdr}@dots{}] [=@var{fill}]
4979*a9fa9459Szrj    @var{secname2}
4980*a9fa9459Szrj      @{
4981*a9fa9459Szrj        @var{output-section-command}
4982*a9fa9459Szrj        @var{output-section-command}
4983*a9fa9459Szrj        @dots{}
4984*a9fa9459Szrj      @} [:@var{phdr}@dots{}] [=@var{fill}]
4985*a9fa9459Szrj    @dots{}
4986*a9fa9459Szrj  @} [>@var{region}] [:@var{phdr}@dots{}] [=@var{fill}] [,]
4987*a9fa9459Szrj@end group
4988*a9fa9459Szrj@end smallexample
4989*a9fa9459Szrj
4990*a9fa9459SzrjEverything is optional except @code{OVERLAY} (a keyword), and each
4991*a9fa9459Szrjsection must have a name (@var{secname1} and @var{secname2} above).  The
4992*a9fa9459Szrjsection definitions within the @code{OVERLAY} construct are identical to
4993*a9fa9459Szrjthose within the general @code{SECTIONS} construct (@pxref{SECTIONS}),
4994*a9fa9459Szrjexcept that no addresses and no memory regions may be defined for
4995*a9fa9459Szrjsections within an @code{OVERLAY}.
4996*a9fa9459Szrj
4997*a9fa9459SzrjThe comma at the end may be required if a @var{fill} is used and
4998*a9fa9459Szrjthe next @var{sections-command} looks like a continuation of the expression.
4999*a9fa9459Szrj
5000*a9fa9459SzrjThe sections are all defined with the same starting address.  The load
5001*a9fa9459Szrjaddresses of the sections are arranged such that they are consecutive in
5002*a9fa9459Szrjmemory starting at the load address used for the @code{OVERLAY} as a
5003*a9fa9459Szrjwhole (as with normal section definitions, the load address is optional,
5004*a9fa9459Szrjand defaults to the start address; the start address is also optional,
5005*a9fa9459Szrjand defaults to the current value of the location counter).
5006*a9fa9459Szrj
5007*a9fa9459SzrjIf the @code{NOCROSSREFS} keyword is used, and there are any
5008*a9fa9459Szrjreferences among the sections, the linker will report an error.  Since
5009*a9fa9459Szrjthe sections all run at the same address, it normally does not make
5010*a9fa9459Szrjsense for one section to refer directly to another.
5011*a9fa9459Szrj@xref{Miscellaneous Commands, NOCROSSREFS}.
5012*a9fa9459Szrj
5013*a9fa9459SzrjFor each section within the @code{OVERLAY}, the linker automatically
5014*a9fa9459Szrjprovides two symbols.  The symbol @code{__load_start_@var{secname}} is
5015*a9fa9459Szrjdefined as the starting load address of the section.  The symbol
5016*a9fa9459Szrj@code{__load_stop_@var{secname}} is defined as the final load address of
5017*a9fa9459Szrjthe section.  Any characters within @var{secname} which are not legal
5018*a9fa9459Szrjwithin C identifiers are removed.  C (or assembler) code may use these
5019*a9fa9459Szrjsymbols to move the overlaid sections around as necessary.
5020*a9fa9459Szrj
5021*a9fa9459SzrjAt the end of the overlay, the value of the location counter is set to
5022*a9fa9459Szrjthe start address of the overlay plus the size of the largest section.
5023*a9fa9459Szrj
5024*a9fa9459SzrjHere is an example.  Remember that this would appear inside a
5025*a9fa9459Szrj@code{SECTIONS} construct.
5026*a9fa9459Szrj@smallexample
5027*a9fa9459Szrj@group
5028*a9fa9459Szrj  OVERLAY 0x1000 : AT (0x4000)
5029*a9fa9459Szrj   @{
5030*a9fa9459Szrj     .text0 @{ o1/*.o(.text) @}
5031*a9fa9459Szrj     .text1 @{ o2/*.o(.text) @}
5032*a9fa9459Szrj   @}
5033*a9fa9459Szrj@end group
5034*a9fa9459Szrj@end smallexample
5035*a9fa9459Szrj@noindent
5036*a9fa9459SzrjThis will define both @samp{.text0} and @samp{.text1} to start at
5037*a9fa9459Szrjaddress 0x1000.  @samp{.text0} will be loaded at address 0x4000, and
5038*a9fa9459Szrj@samp{.text1} will be loaded immediately after @samp{.text0}.  The
5039*a9fa9459Szrjfollowing symbols will be defined if referenced: @code{__load_start_text0},
5040*a9fa9459Szrj@code{__load_stop_text0}, @code{__load_start_text1},
5041*a9fa9459Szrj@code{__load_stop_text1}.
5042*a9fa9459Szrj
5043*a9fa9459SzrjC code to copy overlay @code{.text1} into the overlay area might look
5044*a9fa9459Szrjlike the following.
5045*a9fa9459Szrj
5046*a9fa9459Szrj@smallexample
5047*a9fa9459Szrj@group
5048*a9fa9459Szrj  extern char __load_start_text1, __load_stop_text1;
5049*a9fa9459Szrj  memcpy ((char *) 0x1000, &__load_start_text1,
5050*a9fa9459Szrj          &__load_stop_text1 - &__load_start_text1);
5051*a9fa9459Szrj@end group
5052*a9fa9459Szrj@end smallexample
5053*a9fa9459Szrj
5054*a9fa9459SzrjNote that the @code{OVERLAY} command is just syntactic sugar, since
5055*a9fa9459Szrjeverything it does can be done using the more basic commands.  The above
5056*a9fa9459Szrjexample could have been written identically as follows.
5057*a9fa9459Szrj
5058*a9fa9459Szrj@smallexample
5059*a9fa9459Szrj@group
5060*a9fa9459Szrj  .text0 0x1000 : AT (0x4000) @{ o1/*.o(.text) @}
5061*a9fa9459Szrj  PROVIDE (__load_start_text0 = LOADADDR (.text0));
5062*a9fa9459Szrj  PROVIDE (__load_stop_text0 = LOADADDR (.text0) + SIZEOF (.text0));
5063*a9fa9459Szrj  .text1 0x1000 : AT (0x4000 + SIZEOF (.text0)) @{ o2/*.o(.text) @}
5064*a9fa9459Szrj  PROVIDE (__load_start_text1 = LOADADDR (.text1));
5065*a9fa9459Szrj  PROVIDE (__load_stop_text1 = LOADADDR (.text1) + SIZEOF (.text1));
5066*a9fa9459Szrj  . = 0x1000 + MAX (SIZEOF (.text0), SIZEOF (.text1));
5067*a9fa9459Szrj@end group
5068*a9fa9459Szrj@end smallexample
5069*a9fa9459Szrj
5070*a9fa9459Szrj@node MEMORY
5071*a9fa9459Szrj@section MEMORY Command
5072*a9fa9459Szrj@kindex MEMORY
5073*a9fa9459Szrj@cindex memory regions
5074*a9fa9459Szrj@cindex regions of memory
5075*a9fa9459Szrj@cindex allocating memory
5076*a9fa9459Szrj@cindex discontinuous memory
5077*a9fa9459SzrjThe linker's default configuration permits allocation of all available
5078*a9fa9459Szrjmemory.  You can override this by using the @code{MEMORY} command.
5079*a9fa9459Szrj
5080*a9fa9459SzrjThe @code{MEMORY} command describes the location and size of blocks of
5081*a9fa9459Szrjmemory in the target.  You can use it to describe which memory regions
5082*a9fa9459Szrjmay be used by the linker, and which memory regions it must avoid.  You
5083*a9fa9459Szrjcan then assign sections to particular memory regions.  The linker will
5084*a9fa9459Szrjset section addresses based on the memory regions, and will warn about
5085*a9fa9459Szrjregions that become too full.  The linker will not shuffle sections
5086*a9fa9459Szrjaround to fit into the available regions.
5087*a9fa9459Szrj
5088*a9fa9459SzrjA linker script may contain many uses of the @code{MEMORY} command,
5089*a9fa9459Szrjhowever, all memory blocks defined are treated as if they were
5090*a9fa9459Szrjspecified inside a single @code{MEMORY} command.  The syntax for
5091*a9fa9459Szrj@code{MEMORY} is:
5092*a9fa9459Szrj@smallexample
5093*a9fa9459Szrj@group
5094*a9fa9459SzrjMEMORY
5095*a9fa9459Szrj  @{
5096*a9fa9459Szrj    @var{name} [(@var{attr})] : ORIGIN = @var{origin}, LENGTH = @var{len}
5097*a9fa9459Szrj    @dots{}
5098*a9fa9459Szrj  @}
5099*a9fa9459Szrj@end group
5100*a9fa9459Szrj@end smallexample
5101*a9fa9459Szrj
5102*a9fa9459SzrjThe @var{name} is a name used in the linker script to refer to the
5103*a9fa9459Szrjregion.  The region name has no meaning outside of the linker script.
5104*a9fa9459SzrjRegion names are stored in a separate name space, and will not conflict
5105*a9fa9459Szrjwith symbol names, file names, or section names.  Each memory region
5106*a9fa9459Szrjmust have a distinct name within the @code{MEMORY} command.  However you can
5107*a9fa9459Szrjadd later alias names to existing memory regions with the @ref{REGION_ALIAS}
5108*a9fa9459Szrjcommand.
5109*a9fa9459Szrj
5110*a9fa9459Szrj@cindex memory region attributes
5111*a9fa9459SzrjThe @var{attr} string is an optional list of attributes that specify
5112*a9fa9459Szrjwhether to use a particular memory region for an input section which is
5113*a9fa9459Szrjnot explicitly mapped in the linker script.  As described in
5114*a9fa9459Szrj@ref{SECTIONS}, if you do not specify an output section for some input
5115*a9fa9459Szrjsection, the linker will create an output section with the same name as
5116*a9fa9459Szrjthe input section.  If you define region attributes, the linker will use
5117*a9fa9459Szrjthem to select the memory region for the output section that it creates.
5118*a9fa9459Szrj
5119*a9fa9459SzrjThe @var{attr} string must consist only of the following characters:
5120*a9fa9459Szrj@table @samp
5121*a9fa9459Szrj@item R
5122*a9fa9459SzrjRead-only section
5123*a9fa9459Szrj@item W
5124*a9fa9459SzrjRead/write section
5125*a9fa9459Szrj@item X
5126*a9fa9459SzrjExecutable section
5127*a9fa9459Szrj@item A
5128*a9fa9459SzrjAllocatable section
5129*a9fa9459Szrj@item I
5130*a9fa9459SzrjInitialized section
5131*a9fa9459Szrj@item L
5132*a9fa9459SzrjSame as @samp{I}
5133*a9fa9459Szrj@item !
5134*a9fa9459SzrjInvert the sense of any of the attributes that follow
5135*a9fa9459Szrj@end table
5136*a9fa9459Szrj
5137*a9fa9459SzrjIf a unmapped section matches any of the listed attributes other than
5138*a9fa9459Szrj@samp{!}, it will be placed in the memory region.  The @samp{!}
5139*a9fa9459Szrjattribute reverses this test, so that an unmapped section will be placed
5140*a9fa9459Szrjin the memory region only if it does not match any of the listed
5141*a9fa9459Szrjattributes.
5142*a9fa9459Szrj
5143*a9fa9459Szrj@kindex ORIGIN =
5144*a9fa9459Szrj@kindex o =
5145*a9fa9459Szrj@kindex org =
5146*a9fa9459SzrjThe @var{origin} is an numerical expression for the start address of
5147*a9fa9459Szrjthe memory region.  The expression must evaluate to a constant and it
5148*a9fa9459Szrjcannot involve any symbols.  The keyword @code{ORIGIN} may be
5149*a9fa9459Szrjabbreviated to @code{org} or @code{o} (but not, for example,
5150*a9fa9459Szrj@code{ORG}).
5151*a9fa9459Szrj
5152*a9fa9459Szrj@kindex LENGTH =
5153*a9fa9459Szrj@kindex len =
5154*a9fa9459Szrj@kindex l =
5155*a9fa9459SzrjThe @var{len} is an expression for the size in bytes of the memory
5156*a9fa9459Szrjregion.  As with the @var{origin} expression, the expression must
5157*a9fa9459Szrjbe numerical only and must evaluate to a constant.  The keyword
5158*a9fa9459Szrj@code{LENGTH} may be abbreviated to @code{len} or @code{l}.
5159*a9fa9459Szrj
5160*a9fa9459SzrjIn the following example, we specify that there are two memory regions
5161*a9fa9459Szrjavailable for allocation: one starting at @samp{0} for 256 kilobytes,
5162*a9fa9459Szrjand the other starting at @samp{0x40000000} for four megabytes.  The
5163*a9fa9459Szrjlinker will place into the @samp{rom} memory region every section which
5164*a9fa9459Szrjis not explicitly mapped into a memory region, and is either read-only
5165*a9fa9459Szrjor executable.  The linker will place other sections which are not
5166*a9fa9459Szrjexplicitly mapped into a memory region into the @samp{ram} memory
5167*a9fa9459Szrjregion.
5168*a9fa9459Szrj
5169*a9fa9459Szrj@smallexample
5170*a9fa9459Szrj@group
5171*a9fa9459SzrjMEMORY
5172*a9fa9459Szrj  @{
5173*a9fa9459Szrj    rom (rx)  : ORIGIN = 0, LENGTH = 256K
5174*a9fa9459Szrj    ram (!rx) : org = 0x40000000, l = 4M
5175*a9fa9459Szrj  @}
5176*a9fa9459Szrj@end group
5177*a9fa9459Szrj@end smallexample
5178*a9fa9459Szrj
5179*a9fa9459SzrjOnce you define a memory region, you can direct the linker to place
5180*a9fa9459Szrjspecific output sections into that memory region by using the
5181*a9fa9459Szrj@samp{>@var{region}} output section attribute.  For example, if you have
5182*a9fa9459Szrja memory region named @samp{mem}, you would use @samp{>mem} in the
5183*a9fa9459Szrjoutput section definition.  @xref{Output Section Region}.  If no address
5184*a9fa9459Szrjwas specified for the output section, the linker will set the address to
5185*a9fa9459Szrjthe next available address within the memory region.  If the combined
5186*a9fa9459Szrjoutput sections directed to a memory region are too large for the
5187*a9fa9459Szrjregion, the linker will issue an error message.
5188*a9fa9459Szrj
5189*a9fa9459SzrjIt is possible to access the origin and length of a memory in an
5190*a9fa9459Szrjexpression via the @code{ORIGIN(@var{memory})} and
5191*a9fa9459Szrj@code{LENGTH(@var{memory})} functions:
5192*a9fa9459Szrj
5193*a9fa9459Szrj@smallexample
5194*a9fa9459Szrj@group
5195*a9fa9459Szrj  _fstack = ORIGIN(ram) + LENGTH(ram) - 4;
5196*a9fa9459Szrj@end group
5197*a9fa9459Szrj@end smallexample
5198*a9fa9459Szrj
5199*a9fa9459Szrj@node PHDRS
5200*a9fa9459Szrj@section PHDRS Command
5201*a9fa9459Szrj@kindex PHDRS
5202*a9fa9459Szrj@cindex program headers
5203*a9fa9459Szrj@cindex ELF program headers
5204*a9fa9459Szrj@cindex program segments
5205*a9fa9459Szrj@cindex segments, ELF
5206*a9fa9459SzrjThe ELF object file format uses @dfn{program headers}, also knows as
5207*a9fa9459Szrj@dfn{segments}.  The program headers describe how the program should be
5208*a9fa9459Szrjloaded into memory.  You can print them out by using the @code{objdump}
5209*a9fa9459Szrjprogram with the @samp{-p} option.
5210*a9fa9459Szrj
5211*a9fa9459SzrjWhen you run an ELF program on a native ELF system, the system loader
5212*a9fa9459Szrjreads the program headers in order to figure out how to load the
5213*a9fa9459Szrjprogram.  This will only work if the program headers are set correctly.
5214*a9fa9459SzrjThis manual does not describe the details of how the system loader
5215*a9fa9459Szrjinterprets program headers; for more information, see the ELF ABI.
5216*a9fa9459Szrj
5217*a9fa9459SzrjThe linker will create reasonable program headers by default.  However,
5218*a9fa9459Szrjin some cases, you may need to specify the program headers more
5219*a9fa9459Szrjprecisely.  You may use the @code{PHDRS} command for this purpose.  When
5220*a9fa9459Szrjthe linker sees the @code{PHDRS} command in the linker script, it will
5221*a9fa9459Szrjnot create any program headers other than the ones specified.
5222*a9fa9459Szrj
5223*a9fa9459SzrjThe linker only pays attention to the @code{PHDRS} command when
5224*a9fa9459Szrjgenerating an ELF output file.  In other cases, the linker will simply
5225*a9fa9459Szrjignore @code{PHDRS}.
5226*a9fa9459Szrj
5227*a9fa9459SzrjThis is the syntax of the @code{PHDRS} command.  The words @code{PHDRS},
5228*a9fa9459Szrj@code{FILEHDR}, @code{AT}, and @code{FLAGS} are keywords.
5229*a9fa9459Szrj
5230*a9fa9459Szrj@smallexample
5231*a9fa9459Szrj@group
5232*a9fa9459SzrjPHDRS
5233*a9fa9459Szrj@{
5234*a9fa9459Szrj  @var{name} @var{type} [ FILEHDR ] [ PHDRS ] [ AT ( @var{address} ) ]
5235*a9fa9459Szrj        [ FLAGS ( @var{flags} ) ] ;
5236*a9fa9459Szrj@}
5237*a9fa9459Szrj@end group
5238*a9fa9459Szrj@end smallexample
5239*a9fa9459Szrj
5240*a9fa9459SzrjThe @var{name} is used only for reference in the @code{SECTIONS} command
5241*a9fa9459Szrjof the linker script.  It is not put into the output file.  Program
5242*a9fa9459Szrjheader names are stored in a separate name space, and will not conflict
5243*a9fa9459Szrjwith symbol names, file names, or section names.  Each program header
5244*a9fa9459Szrjmust have a distinct name.  The headers are processed in order and it
5245*a9fa9459Szrjis usual for them to map to sections in ascending load address order.
5246*a9fa9459Szrj
5247*a9fa9459SzrjCertain program header types describe segments of memory which the
5248*a9fa9459Szrjsystem loader will load from the file.  In the linker script, you
5249*a9fa9459Szrjspecify the contents of these segments by placing allocatable output
5250*a9fa9459Szrjsections in the segments.  You use the @samp{:@var{phdr}} output section
5251*a9fa9459Szrjattribute to place a section in a particular segment.  @xref{Output
5252*a9fa9459SzrjSection Phdr}.
5253*a9fa9459Szrj
5254*a9fa9459SzrjIt is normal to put certain sections in more than one segment.  This
5255*a9fa9459Szrjmerely implies that one segment of memory contains another.  You may
5256*a9fa9459Szrjrepeat @samp{:@var{phdr}}, using it once for each segment which should
5257*a9fa9459Szrjcontain the section.
5258*a9fa9459Szrj
5259*a9fa9459SzrjIf you place a section in one or more segments using @samp{:@var{phdr}},
5260*a9fa9459Szrjthen the linker will place all subsequent allocatable sections which do
5261*a9fa9459Szrjnot specify @samp{:@var{phdr}} in the same segments.  This is for
5262*a9fa9459Szrjconvenience, since generally a whole set of contiguous sections will be
5263*a9fa9459Szrjplaced in a single segment.  You can use @code{:NONE} to override the
5264*a9fa9459Szrjdefault segment and tell the linker to not put the section in any
5265*a9fa9459Szrjsegment at all.
5266*a9fa9459Szrj
5267*a9fa9459Szrj@kindex FILEHDR
5268*a9fa9459Szrj@kindex PHDRS
5269*a9fa9459SzrjYou may use the @code{FILEHDR} and @code{PHDRS} keywords after
5270*a9fa9459Szrjthe program header type to further describe the contents of the segment.
5271*a9fa9459SzrjThe @code{FILEHDR} keyword means that the segment should include the ELF
5272*a9fa9459Szrjfile header.  The @code{PHDRS} keyword means that the segment should
5273*a9fa9459Szrjinclude the ELF program headers themselves.  If applied to a loadable
5274*a9fa9459Szrjsegment (@code{PT_LOAD}), all prior loadable segments must have one of
5275*a9fa9459Szrjthese keywords.
5276*a9fa9459Szrj
5277*a9fa9459SzrjThe @var{type} may be one of the following.  The numbers indicate the
5278*a9fa9459Szrjvalue of the keyword.
5279*a9fa9459Szrj
5280*a9fa9459Szrj@table @asis
5281*a9fa9459Szrj@item @code{PT_NULL} (0)
5282*a9fa9459SzrjIndicates an unused program header.
5283*a9fa9459Szrj
5284*a9fa9459Szrj@item @code{PT_LOAD} (1)
5285*a9fa9459SzrjIndicates that this program header describes a segment to be loaded from
5286*a9fa9459Szrjthe file.
5287*a9fa9459Szrj
5288*a9fa9459Szrj@item @code{PT_DYNAMIC} (2)
5289*a9fa9459SzrjIndicates a segment where dynamic linking information can be found.
5290*a9fa9459Szrj
5291*a9fa9459Szrj@item @code{PT_INTERP} (3)
5292*a9fa9459SzrjIndicates a segment where the name of the program interpreter may be
5293*a9fa9459Szrjfound.
5294*a9fa9459Szrj
5295*a9fa9459Szrj@item @code{PT_NOTE} (4)
5296*a9fa9459SzrjIndicates a segment holding note information.
5297*a9fa9459Szrj
5298*a9fa9459Szrj@item @code{PT_SHLIB} (5)
5299*a9fa9459SzrjA reserved program header type, defined but not specified by the ELF
5300*a9fa9459SzrjABI.
5301*a9fa9459Szrj
5302*a9fa9459Szrj@item @code{PT_PHDR} (6)
5303*a9fa9459SzrjIndicates a segment where the program headers may be found.
5304*a9fa9459Szrj
5305*a9fa9459Szrj@item @var{expression}
5306*a9fa9459SzrjAn expression giving the numeric type of the program header.  This may
5307*a9fa9459Szrjbe used for types not defined above.
5308*a9fa9459Szrj@end table
5309*a9fa9459Szrj
5310*a9fa9459SzrjYou can specify that a segment should be loaded at a particular address
5311*a9fa9459Szrjin memory by using an @code{AT} expression.  This is identical to the
5312*a9fa9459Szrj@code{AT} command used as an output section attribute (@pxref{Output
5313*a9fa9459SzrjSection LMA}).  The @code{AT} command for a program header overrides the
5314*a9fa9459Szrjoutput section attribute.
5315*a9fa9459Szrj
5316*a9fa9459SzrjThe linker will normally set the segment flags based on the sections
5317*a9fa9459Szrjwhich comprise the segment.  You may use the @code{FLAGS} keyword to
5318*a9fa9459Szrjexplicitly specify the segment flags.  The value of @var{flags} must be
5319*a9fa9459Szrjan integer.  It is used to set the @code{p_flags} field of the program
5320*a9fa9459Szrjheader.
5321*a9fa9459Szrj
5322*a9fa9459SzrjHere is an example of @code{PHDRS}.  This shows a typical set of program
5323*a9fa9459Szrjheaders used on a native ELF system.
5324*a9fa9459Szrj
5325*a9fa9459Szrj@example
5326*a9fa9459Szrj@group
5327*a9fa9459SzrjPHDRS
5328*a9fa9459Szrj@{
5329*a9fa9459Szrj  headers PT_PHDR PHDRS ;
5330*a9fa9459Szrj  interp PT_INTERP ;
5331*a9fa9459Szrj  text PT_LOAD FILEHDR PHDRS ;
5332*a9fa9459Szrj  data PT_LOAD ;
5333*a9fa9459Szrj  dynamic PT_DYNAMIC ;
5334*a9fa9459Szrj@}
5335*a9fa9459Szrj
5336*a9fa9459SzrjSECTIONS
5337*a9fa9459Szrj@{
5338*a9fa9459Szrj  . = SIZEOF_HEADERS;
5339*a9fa9459Szrj  .interp : @{ *(.interp) @} :text :interp
5340*a9fa9459Szrj  .text : @{ *(.text) @} :text
5341*a9fa9459Szrj  .rodata : @{ *(.rodata) @} /* defaults to :text */
5342*a9fa9459Szrj  @dots{}
5343*a9fa9459Szrj  . = . + 0x1000; /* move to a new page in memory */
5344*a9fa9459Szrj  .data : @{ *(.data) @} :data
5345*a9fa9459Szrj  .dynamic : @{ *(.dynamic) @} :data :dynamic
5346*a9fa9459Szrj  @dots{}
5347*a9fa9459Szrj@}
5348*a9fa9459Szrj@end group
5349*a9fa9459Szrj@end example
5350*a9fa9459Szrj
5351*a9fa9459Szrj@node VERSION
5352*a9fa9459Szrj@section VERSION Command
5353*a9fa9459Szrj@kindex VERSION @{script text@}
5354*a9fa9459Szrj@cindex symbol versions
5355*a9fa9459Szrj@cindex version script
5356*a9fa9459Szrj@cindex versions of symbols
5357*a9fa9459SzrjThe linker supports symbol versions when using ELF.  Symbol versions are
5358*a9fa9459Szrjonly useful when using shared libraries.  The dynamic linker can use
5359*a9fa9459Szrjsymbol versions to select a specific version of a function when it runs
5360*a9fa9459Szrja program that may have been linked against an earlier version of the
5361*a9fa9459Szrjshared library.
5362*a9fa9459Szrj
5363*a9fa9459SzrjYou can include a version script directly in the main linker script, or
5364*a9fa9459Szrjyou can supply the version script as an implicit linker script.  You can
5365*a9fa9459Szrjalso use the @samp{--version-script} linker option.
5366*a9fa9459Szrj
5367*a9fa9459SzrjThe syntax of the @code{VERSION} command is simply
5368*a9fa9459Szrj@smallexample
5369*a9fa9459SzrjVERSION @{ version-script-commands @}
5370*a9fa9459Szrj@end smallexample
5371*a9fa9459Szrj
5372*a9fa9459SzrjThe format of the version script commands is identical to that used by
5373*a9fa9459SzrjSun's linker in Solaris 2.5.  The version script defines a tree of
5374*a9fa9459Szrjversion nodes.  You specify the node names and interdependencies in the
5375*a9fa9459Szrjversion script.  You can specify which symbols are bound to which
5376*a9fa9459Szrjversion nodes, and you can reduce a specified set of symbols to local
5377*a9fa9459Szrjscope so that they are not globally visible outside of the shared
5378*a9fa9459Szrjlibrary.
5379*a9fa9459Szrj
5380*a9fa9459SzrjThe easiest way to demonstrate the version script language is with a few
5381*a9fa9459Szrjexamples.
5382*a9fa9459Szrj
5383*a9fa9459Szrj@smallexample
5384*a9fa9459SzrjVERS_1.1 @{
5385*a9fa9459Szrj	 global:
5386*a9fa9459Szrj		 foo1;
5387*a9fa9459Szrj	 local:
5388*a9fa9459Szrj		 old*;
5389*a9fa9459Szrj		 original*;
5390*a9fa9459Szrj		 new*;
5391*a9fa9459Szrj@};
5392*a9fa9459Szrj
5393*a9fa9459SzrjVERS_1.2 @{
5394*a9fa9459Szrj		 foo2;
5395*a9fa9459Szrj@} VERS_1.1;
5396*a9fa9459Szrj
5397*a9fa9459SzrjVERS_2.0 @{
5398*a9fa9459Szrj		 bar1; bar2;
5399*a9fa9459Szrj	 extern "C++" @{
5400*a9fa9459Szrj		 ns::*;
5401*a9fa9459Szrj		 "f(int, double)";
5402*a9fa9459Szrj	 @};
5403*a9fa9459Szrj@} VERS_1.2;
5404*a9fa9459Szrj@end smallexample
5405*a9fa9459Szrj
5406*a9fa9459SzrjThis example version script defines three version nodes.  The first
5407*a9fa9459Szrjversion node defined is @samp{VERS_1.1}; it has no other dependencies.
5408*a9fa9459SzrjThe script binds the symbol @samp{foo1} to @samp{VERS_1.1}.  It reduces
5409*a9fa9459Szrja number of symbols to local scope so that they are not visible outside
5410*a9fa9459Szrjof the shared library; this is done using wildcard patterns, so that any
5411*a9fa9459Szrjsymbol whose name begins with @samp{old}, @samp{original}, or @samp{new}
5412*a9fa9459Szrjis matched.  The wildcard patterns available are the same as those used
5413*a9fa9459Szrjin the shell when matching filenames (also known as ``globbing'').
5414*a9fa9459SzrjHowever, if you specify the symbol name inside double quotes, then the
5415*a9fa9459Szrjname is treated as literal, rather than as a glob pattern.
5416*a9fa9459Szrj
5417*a9fa9459SzrjNext, the version script defines node @samp{VERS_1.2}.  This node
5418*a9fa9459Szrjdepends upon @samp{VERS_1.1}.  The script binds the symbol @samp{foo2}
5419*a9fa9459Szrjto the version node @samp{VERS_1.2}.
5420*a9fa9459Szrj
5421*a9fa9459SzrjFinally, the version script defines node @samp{VERS_2.0}.  This node
5422*a9fa9459Szrjdepends upon @samp{VERS_1.2}.  The scripts binds the symbols @samp{bar1}
5423*a9fa9459Szrjand @samp{bar2} are bound to the version node @samp{VERS_2.0}.
5424*a9fa9459Szrj
5425*a9fa9459SzrjWhen the linker finds a symbol defined in a library which is not
5426*a9fa9459Szrjspecifically bound to a version node, it will effectively bind it to an
5427*a9fa9459Szrjunspecified base version of the library.  You can bind all otherwise
5428*a9fa9459Szrjunspecified symbols to a given version node by using @samp{global: *;}
5429*a9fa9459Szrjsomewhere in the version script.  Note that it's slightly crazy to use
5430*a9fa9459Szrjwildcards in a global spec except on the last version node.  Global
5431*a9fa9459Szrjwildcards elsewhere run the risk of accidentally adding symbols to the
5432*a9fa9459Szrjset exported for an old version.  That's wrong since older versions
5433*a9fa9459Szrjought to have a fixed set of symbols.
5434*a9fa9459Szrj
5435*a9fa9459SzrjThe names of the version nodes have no specific meaning other than what
5436*a9fa9459Szrjthey might suggest to the person reading them.  The @samp{2.0} version
5437*a9fa9459Szrjcould just as well have appeared in between @samp{1.1} and @samp{1.2}.
5438*a9fa9459SzrjHowever, this would be a confusing way to write a version script.
5439*a9fa9459Szrj
5440*a9fa9459SzrjNode name can be omitted, provided it is the only version node
5441*a9fa9459Szrjin the version script.  Such version script doesn't assign any versions to
5442*a9fa9459Szrjsymbols, only selects which symbols will be globally visible out and which
5443*a9fa9459Szrjwon't.
5444*a9fa9459Szrj
5445*a9fa9459Szrj@smallexample
5446*a9fa9459Szrj@{ global: foo; bar; local: *; @};
5447*a9fa9459Szrj@end smallexample
5448*a9fa9459Szrj
5449*a9fa9459SzrjWhen you link an application against a shared library that has versioned
5450*a9fa9459Szrjsymbols, the application itself knows which version of each symbol it
5451*a9fa9459Szrjrequires, and it also knows which version nodes it needs from each
5452*a9fa9459Szrjshared library it is linked against.  Thus at runtime, the dynamic
5453*a9fa9459Szrjloader can make a quick check to make sure that the libraries you have
5454*a9fa9459Szrjlinked against do in fact supply all of the version nodes that the
5455*a9fa9459Szrjapplication will need to resolve all of the dynamic symbols.  In this
5456*a9fa9459Szrjway it is possible for the dynamic linker to know with certainty that
5457*a9fa9459Szrjall external symbols that it needs will be resolvable without having to
5458*a9fa9459Szrjsearch for each symbol reference.
5459*a9fa9459Szrj
5460*a9fa9459SzrjThe symbol versioning is in effect a much more sophisticated way of
5461*a9fa9459Szrjdoing minor version checking that SunOS does.  The fundamental problem
5462*a9fa9459Szrjthat is being addressed here is that typically references to external
5463*a9fa9459Szrjfunctions are bound on an as-needed basis, and are not all bound when
5464*a9fa9459Szrjthe application starts up.  If a shared library is out of date, a
5465*a9fa9459Szrjrequired interface may be missing; when the application tries to use
5466*a9fa9459Szrjthat interface, it may suddenly and unexpectedly fail.  With symbol
5467*a9fa9459Szrjversioning, the user will get a warning when they start their program if
5468*a9fa9459Szrjthe libraries being used with the application are too old.
5469*a9fa9459Szrj
5470*a9fa9459SzrjThere are several GNU extensions to Sun's versioning approach.  The
5471*a9fa9459Szrjfirst of these is the ability to bind a symbol to a version node in the
5472*a9fa9459Szrjsource file where the symbol is defined instead of in the versioning
5473*a9fa9459Szrjscript.  This was done mainly to reduce the burden on the library
5474*a9fa9459Szrjmaintainer.  You can do this by putting something like:
5475*a9fa9459Szrj@smallexample
5476*a9fa9459Szrj__asm__(".symver original_foo,foo@@VERS_1.1");
5477*a9fa9459Szrj@end smallexample
5478*a9fa9459Szrj@noindent
5479*a9fa9459Szrjin the C source file.  This renames the function @samp{original_foo} to
5480*a9fa9459Szrjbe an alias for @samp{foo} bound to the version node @samp{VERS_1.1}.
5481*a9fa9459SzrjThe @samp{local:} directive can be used to prevent the symbol
5482*a9fa9459Szrj@samp{original_foo} from being exported. A @samp{.symver} directive
5483*a9fa9459Szrjtakes precedence over a version script.
5484*a9fa9459Szrj
5485*a9fa9459SzrjThe second GNU extension is to allow multiple versions of the same
5486*a9fa9459Szrjfunction to appear in a given shared library.  In this way you can make
5487*a9fa9459Szrjan incompatible change to an interface without increasing the major
5488*a9fa9459Szrjversion number of the shared library, while still allowing applications
5489*a9fa9459Szrjlinked against the old interface to continue to function.
5490*a9fa9459Szrj
5491*a9fa9459SzrjTo do this, you must use multiple @samp{.symver} directives in the
5492*a9fa9459Szrjsource file.  Here is an example:
5493*a9fa9459Szrj
5494*a9fa9459Szrj@smallexample
5495*a9fa9459Szrj__asm__(".symver original_foo,foo@@");
5496*a9fa9459Szrj__asm__(".symver old_foo,foo@@VERS_1.1");
5497*a9fa9459Szrj__asm__(".symver old_foo1,foo@@VERS_1.2");
5498*a9fa9459Szrj__asm__(".symver new_foo,foo@@@@VERS_2.0");
5499*a9fa9459Szrj@end smallexample
5500*a9fa9459Szrj
5501*a9fa9459SzrjIn this example, @samp{foo@@} represents the symbol @samp{foo} bound to the
5502*a9fa9459Szrjunspecified base version of the symbol.  The source file that contains this
5503*a9fa9459Szrjexample would define 4 C functions: @samp{original_foo}, @samp{old_foo},
5504*a9fa9459Szrj@samp{old_foo1}, and @samp{new_foo}.
5505*a9fa9459Szrj
5506*a9fa9459SzrjWhen you have multiple definitions of a given symbol, there needs to be
5507*a9fa9459Szrjsome way to specify a default version to which external references to
5508*a9fa9459Szrjthis symbol will be bound.  You can do this with the
5509*a9fa9459Szrj@samp{foo@@@@VERS_2.0} type of @samp{.symver} directive.  You can only
5510*a9fa9459Szrjdeclare one version of a symbol as the default in this manner; otherwise
5511*a9fa9459Szrjyou would effectively have multiple definitions of the same symbol.
5512*a9fa9459Szrj
5513*a9fa9459SzrjIf you wish to bind a reference to a specific version of the symbol
5514*a9fa9459Szrjwithin the shared library, you can use the aliases of convenience
5515*a9fa9459Szrj(i.e., @samp{old_foo}), or you can use the @samp{.symver} directive to
5516*a9fa9459Szrjspecifically bind to an external version of the function in question.
5517*a9fa9459Szrj
5518*a9fa9459SzrjYou can also specify the language in the version script:
5519*a9fa9459Szrj
5520*a9fa9459Szrj@smallexample
5521*a9fa9459SzrjVERSION extern "lang" @{ version-script-commands @}
5522*a9fa9459Szrj@end smallexample
5523*a9fa9459Szrj
5524*a9fa9459SzrjThe supported @samp{lang}s are @samp{C}, @samp{C++}, and @samp{Java}.
5525*a9fa9459SzrjThe linker will iterate over the list of symbols at the link time and
5526*a9fa9459Szrjdemangle them according to @samp{lang} before matching them to the
5527*a9fa9459Szrjpatterns specified in @samp{version-script-commands}.  The default
5528*a9fa9459Szrj@samp{lang} is @samp{C}.
5529*a9fa9459Szrj
5530*a9fa9459SzrjDemangled names may contains spaces and other special characters.  As
5531*a9fa9459Szrjdescribed above, you can use a glob pattern to match demangled names,
5532*a9fa9459Szrjor you can use a double-quoted string to match the string exactly.  In
5533*a9fa9459Szrjthe latter case, be aware that minor differences (such as differing
5534*a9fa9459Szrjwhitespace) between the version script and the demangler output will
5535*a9fa9459Szrjcause a mismatch.  As the exact string generated by the demangler
5536*a9fa9459Szrjmight change in the future, even if the mangled name does not, you
5537*a9fa9459Szrjshould check that all of your version directives are behaving as you
5538*a9fa9459Szrjexpect when you upgrade.
5539*a9fa9459Szrj
5540*a9fa9459Szrj@node Expressions
5541*a9fa9459Szrj@section Expressions in Linker Scripts
5542*a9fa9459Szrj@cindex expressions
5543*a9fa9459Szrj@cindex arithmetic
5544*a9fa9459SzrjThe syntax for expressions in the linker script language is identical to
5545*a9fa9459Szrjthat of C expressions.  All expressions are evaluated as integers.  All
5546*a9fa9459Szrjexpressions are evaluated in the same size, which is 32 bits if both the
5547*a9fa9459Szrjhost and target are 32 bits, and is otherwise 64 bits.
5548*a9fa9459Szrj
5549*a9fa9459SzrjYou can use and set symbol values in expressions.
5550*a9fa9459Szrj
5551*a9fa9459SzrjThe linker defines several special purpose builtin functions for use in
5552*a9fa9459Szrjexpressions.
5553*a9fa9459Szrj
5554*a9fa9459Szrj@menu
5555*a9fa9459Szrj* Constants::			Constants
5556*a9fa9459Szrj* Symbolic Constants::          Symbolic constants
5557*a9fa9459Szrj* Symbols::			Symbol Names
5558*a9fa9459Szrj* Orphan Sections::		Orphan Sections
5559*a9fa9459Szrj* Location Counter::		The Location Counter
5560*a9fa9459Szrj* Operators::			Operators
5561*a9fa9459Szrj* Evaluation::			Evaluation
5562*a9fa9459Szrj* Expression Section::		The Section of an Expression
5563*a9fa9459Szrj* Builtin Functions::		Builtin Functions
5564*a9fa9459Szrj@end menu
5565*a9fa9459Szrj
5566*a9fa9459Szrj@node Constants
5567*a9fa9459Szrj@subsection Constants
5568*a9fa9459Szrj@cindex integer notation
5569*a9fa9459Szrj@cindex constants in linker scripts
5570*a9fa9459SzrjAll constants are integers.
5571*a9fa9459Szrj
5572*a9fa9459SzrjAs in C, the linker considers an integer beginning with @samp{0} to be
5573*a9fa9459Szrjoctal, and an integer beginning with @samp{0x} or @samp{0X} to be
5574*a9fa9459Szrjhexadecimal.  Alternatively the linker accepts suffixes of @samp{h} or
5575*a9fa9459Szrj@samp{H} for hexadecimal, @samp{o} or @samp{O} for octal, @samp{b} or
5576*a9fa9459Szrj@samp{B} for binary and @samp{d} or @samp{D} for decimal.  Any integer
5577*a9fa9459Szrjvalue without a prefix or a suffix is considered to be decimal.
5578*a9fa9459Szrj
5579*a9fa9459Szrj@cindex scaled integers
5580*a9fa9459Szrj@cindex K and M integer suffixes
5581*a9fa9459Szrj@cindex M and K integer suffixes
5582*a9fa9459Szrj@cindex suffixes for integers
5583*a9fa9459Szrj@cindex integer suffixes
5584*a9fa9459SzrjIn addition, you can use the suffixes @code{K} and @code{M} to scale a
5585*a9fa9459Szrjconstant by
5586*a9fa9459Szrj@c TEXI2ROFF-KILL
5587*a9fa9459Szrj@ifnottex
5588*a9fa9459Szrj@c END TEXI2ROFF-KILL
5589*a9fa9459Szrj@code{1024} or @code{1024*1024}
5590*a9fa9459Szrj@c TEXI2ROFF-KILL
5591*a9fa9459Szrj@end ifnottex
5592*a9fa9459Szrj@tex
5593*a9fa9459Szrj${\rm 1024}$ or ${\rm 1024}^2$
5594*a9fa9459Szrj@end tex
5595*a9fa9459Szrj@c END TEXI2ROFF-KILL
5596*a9fa9459Szrjrespectively.  For example, the following
5597*a9fa9459Szrjall refer to the same quantity:
5598*a9fa9459Szrj
5599*a9fa9459Szrj@smallexample
5600*a9fa9459Szrj_fourk_1 = 4K;
5601*a9fa9459Szrj_fourk_2 = 4096;
5602*a9fa9459Szrj_fourk_3 = 0x1000;
5603*a9fa9459Szrj_fourk_4 = 10000o;
5604*a9fa9459Szrj@end smallexample
5605*a9fa9459Szrj
5606*a9fa9459SzrjNote - the @code{K} and @code{M} suffixes cannot be used in
5607*a9fa9459Szrjconjunction with the base suffixes mentioned above.
5608*a9fa9459Szrj
5609*a9fa9459Szrj@node Symbolic Constants
5610*a9fa9459Szrj@subsection Symbolic Constants
5611*a9fa9459Szrj@cindex symbolic constants
5612*a9fa9459Szrj@kindex CONSTANT
5613*a9fa9459SzrjIt is possible to refer to target specific constants via the use of
5614*a9fa9459Szrjthe @code{CONSTANT(@var{name})} operator, where @var{name} is one of:
5615*a9fa9459Szrj
5616*a9fa9459Szrj@table @code
5617*a9fa9459Szrj@item MAXPAGESIZE
5618*a9fa9459Szrj@kindex MAXPAGESIZE
5619*a9fa9459SzrjThe target's maximum page size.
5620*a9fa9459Szrj
5621*a9fa9459Szrj@item COMMONPAGESIZE
5622*a9fa9459Szrj@kindex COMMONPAGESIZE
5623*a9fa9459SzrjThe target's default page size.
5624*a9fa9459Szrj@end table
5625*a9fa9459Szrj
5626*a9fa9459SzrjSo for example:
5627*a9fa9459Szrj
5628*a9fa9459Szrj@smallexample
5629*a9fa9459Szrj  .text ALIGN (CONSTANT (MAXPAGESIZE)) : @{ *(.text) @}
5630*a9fa9459Szrj@end smallexample
5631*a9fa9459Szrj
5632*a9fa9459Szrjwill create a text section aligned to the largest page boundary
5633*a9fa9459Szrjsupported by the target.
5634*a9fa9459Szrj
5635*a9fa9459Szrj@node Symbols
5636*a9fa9459Szrj@subsection Symbol Names
5637*a9fa9459Szrj@cindex symbol names
5638*a9fa9459Szrj@cindex names
5639*a9fa9459Szrj@cindex quoted symbol names
5640*a9fa9459Szrj@kindex "
5641*a9fa9459SzrjUnless quoted, symbol names start with a letter, underscore, or period
5642*a9fa9459Szrjand may include letters, digits, underscores, periods, and hyphens.
5643*a9fa9459SzrjUnquoted symbol names must not conflict with any keywords.  You can
5644*a9fa9459Szrjspecify a symbol which contains odd characters or has the same name as a
5645*a9fa9459Szrjkeyword by surrounding the symbol name in double quotes:
5646*a9fa9459Szrj@smallexample
5647*a9fa9459Szrj"SECTION" = 9;
5648*a9fa9459Szrj"with a space" = "also with a space" + 10;
5649*a9fa9459Szrj@end smallexample
5650*a9fa9459Szrj
5651*a9fa9459SzrjSince symbols can contain many non-alphabetic characters, it is safest
5652*a9fa9459Szrjto delimit symbols with spaces.  For example, @samp{A-B} is one symbol,
5653*a9fa9459Szrjwhereas @samp{A - B} is an expression involving subtraction.
5654*a9fa9459Szrj
5655*a9fa9459Szrj@node Orphan Sections
5656*a9fa9459Szrj@subsection Orphan Sections
5657*a9fa9459Szrj@cindex orphan
5658*a9fa9459SzrjOrphan sections are sections present in the input files which
5659*a9fa9459Szrjare not explicitly placed into the output file by the linker
5660*a9fa9459Szrjscript.  The linker will still copy these sections into the
5661*a9fa9459Szrjoutput file, but it has to guess as to where they should be
5662*a9fa9459Szrjplaced.  The linker uses a simple heuristic to do this.  It
5663*a9fa9459Szrjattempts to place orphan sections after non-orphan sections of the
5664*a9fa9459Szrjsame attribute, such as code vs data, loadable vs non-loadable, etc.
5665*a9fa9459SzrjIf there is not enough room to do this then it places
5666*a9fa9459Szrjat the end of the file.
5667*a9fa9459Szrj
5668*a9fa9459SzrjFor ELF targets, the attribute of the section includes section type as
5669*a9fa9459Szrjwell as section flag.
5670*a9fa9459Szrj
5671*a9fa9459SzrjThe command line options @samp{--orphan-handling} and @samp{--unique}
5672*a9fa9459Szrj(@pxref{Options,,Command Line Options}) can be used to control which
5673*a9fa9459Szrjoutput sections an orphan is placed in.
5674*a9fa9459Szrj
5675*a9fa9459SzrjIf an orphaned section's name is representable as a C identifier then
5676*a9fa9459Szrjthe linker will automatically @pxref{PROVIDE} two symbols:
5677*a9fa9459Szrj__start_SECNAME and __stop_SECNAME, where SECNAME is the name of the
5678*a9fa9459Szrjsection.  These indicate the start address and end address of the
5679*a9fa9459Szrjorphaned section respectively.  Note: most section names are not
5680*a9fa9459Szrjrepresentable as C identifiers because they contain a @samp{.}
5681*a9fa9459Szrjcharacter.
5682*a9fa9459Szrj
5683*a9fa9459Szrj@node Location Counter
5684*a9fa9459Szrj@subsection The Location Counter
5685*a9fa9459Szrj@kindex .
5686*a9fa9459Szrj@cindex dot
5687*a9fa9459Szrj@cindex location counter
5688*a9fa9459Szrj@cindex current output location
5689*a9fa9459SzrjThe special linker variable @dfn{dot} @samp{.} always contains the
5690*a9fa9459Szrjcurrent output location counter.  Since the @code{.} always refers to a
5691*a9fa9459Szrjlocation in an output section, it may only appear in an expression
5692*a9fa9459Szrjwithin a @code{SECTIONS} command.  The @code{.} symbol may appear
5693*a9fa9459Szrjanywhere that an ordinary symbol is allowed in an expression.
5694*a9fa9459Szrj
5695*a9fa9459Szrj@cindex holes
5696*a9fa9459SzrjAssigning a value to @code{.} will cause the location counter to be
5697*a9fa9459Szrjmoved.  This may be used to create holes in the output section.  The
5698*a9fa9459Szrjlocation counter may not be moved backwards inside an output section,
5699*a9fa9459Szrjand may not be moved backwards outside of an output section if so
5700*a9fa9459Szrjdoing creates areas with overlapping LMAs.
5701*a9fa9459Szrj
5702*a9fa9459Szrj@smallexample
5703*a9fa9459SzrjSECTIONS
5704*a9fa9459Szrj@{
5705*a9fa9459Szrj  output :
5706*a9fa9459Szrj    @{
5707*a9fa9459Szrj      file1(.text)
5708*a9fa9459Szrj      . = . + 1000;
5709*a9fa9459Szrj      file2(.text)
5710*a9fa9459Szrj      . += 1000;
5711*a9fa9459Szrj      file3(.text)
5712*a9fa9459Szrj    @} = 0x12345678;
5713*a9fa9459Szrj@}
5714*a9fa9459Szrj@end smallexample
5715*a9fa9459Szrj@noindent
5716*a9fa9459SzrjIn the previous example, the @samp{.text} section from @file{file1} is
5717*a9fa9459Szrjlocated at the beginning of the output section @samp{output}.  It is
5718*a9fa9459Szrjfollowed by a 1000 byte gap.  Then the @samp{.text} section from
5719*a9fa9459Szrj@file{file2} appears, also with a 1000 byte gap following before the
5720*a9fa9459Szrj@samp{.text} section from @file{file3}.  The notation @samp{= 0x12345678}
5721*a9fa9459Szrjspecifies what data to write in the gaps (@pxref{Output Section Fill}).
5722*a9fa9459Szrj
5723*a9fa9459Szrj@cindex dot inside sections
5724*a9fa9459SzrjNote: @code{.} actually refers to the byte offset from the start of the
5725*a9fa9459Szrjcurrent containing object.  Normally this is the @code{SECTIONS}
5726*a9fa9459Szrjstatement, whose start address is 0, hence @code{.} can be used as an
5727*a9fa9459Szrjabsolute address.  If @code{.} is used inside a section description
5728*a9fa9459Szrjhowever, it refers to the byte offset from the start of that section,
5729*a9fa9459Szrjnot an absolute address.  Thus in a script like this:
5730*a9fa9459Szrj
5731*a9fa9459Szrj@smallexample
5732*a9fa9459SzrjSECTIONS
5733*a9fa9459Szrj@{
5734*a9fa9459Szrj    . = 0x100
5735*a9fa9459Szrj    .text: @{
5736*a9fa9459Szrj      *(.text)
5737*a9fa9459Szrj      . = 0x200
5738*a9fa9459Szrj    @}
5739*a9fa9459Szrj    . = 0x500
5740*a9fa9459Szrj    .data: @{
5741*a9fa9459Szrj      *(.data)
5742*a9fa9459Szrj      . += 0x600
5743*a9fa9459Szrj    @}
5744*a9fa9459Szrj@}
5745*a9fa9459Szrj@end smallexample
5746*a9fa9459Szrj
5747*a9fa9459SzrjThe @samp{.text} section will be assigned a starting address of 0x100
5748*a9fa9459Szrjand a size of exactly 0x200 bytes, even if there is not enough data in
5749*a9fa9459Szrjthe @samp{.text} input sections to fill this area.  (If there is too
5750*a9fa9459Szrjmuch data, an error will be produced because this would be an attempt to
5751*a9fa9459Szrjmove @code{.} backwards).  The @samp{.data} section will start at 0x500
5752*a9fa9459Szrjand it will have an extra 0x600 bytes worth of space after the end of
5753*a9fa9459Szrjthe values from the @samp{.data} input sections and before the end of
5754*a9fa9459Szrjthe @samp{.data} output section itself.
5755*a9fa9459Szrj
5756*a9fa9459Szrj@cindex dot outside sections
5757*a9fa9459SzrjSetting symbols to the value of the location counter outside of an
5758*a9fa9459Szrjoutput section statement can result in unexpected values if the linker
5759*a9fa9459Szrjneeds to place orphan sections.  For example, given the following:
5760*a9fa9459Szrj
5761*a9fa9459Szrj@smallexample
5762*a9fa9459SzrjSECTIONS
5763*a9fa9459Szrj@{
5764*a9fa9459Szrj    start_of_text = . ;
5765*a9fa9459Szrj    .text: @{ *(.text) @}
5766*a9fa9459Szrj    end_of_text = . ;
5767*a9fa9459Szrj
5768*a9fa9459Szrj    start_of_data = . ;
5769*a9fa9459Szrj    .data: @{ *(.data) @}
5770*a9fa9459Szrj    end_of_data = . ;
5771*a9fa9459Szrj@}
5772*a9fa9459Szrj@end smallexample
5773*a9fa9459Szrj
5774*a9fa9459SzrjIf the linker needs to place some input section, e.g. @code{.rodata},
5775*a9fa9459Szrjnot mentioned in the script, it might choose to place that section
5776*a9fa9459Szrjbetween @code{.text} and @code{.data}.  You might think the linker
5777*a9fa9459Szrjshould place @code{.rodata} on the blank line in the above script, but
5778*a9fa9459Szrjblank lines are of no particular significance to the linker.  As well,
5779*a9fa9459Szrjthe linker doesn't associate the above symbol names with their
5780*a9fa9459Szrjsections.  Instead, it assumes that all assignments or other
5781*a9fa9459Szrjstatements belong to the previous output section, except for the
5782*a9fa9459Szrjspecial case of an assignment to @code{.}.  I.e., the linker will
5783*a9fa9459Szrjplace the orphan @code{.rodata} section as if the script was written
5784*a9fa9459Szrjas follows:
5785*a9fa9459Szrj
5786*a9fa9459Szrj@smallexample
5787*a9fa9459SzrjSECTIONS
5788*a9fa9459Szrj@{
5789*a9fa9459Szrj    start_of_text = . ;
5790*a9fa9459Szrj    .text: @{ *(.text) @}
5791*a9fa9459Szrj    end_of_text = . ;
5792*a9fa9459Szrj
5793*a9fa9459Szrj    start_of_data = . ;
5794*a9fa9459Szrj    .rodata: @{ *(.rodata) @}
5795*a9fa9459Szrj    .data: @{ *(.data) @}
5796*a9fa9459Szrj    end_of_data = . ;
5797*a9fa9459Szrj@}
5798*a9fa9459Szrj@end smallexample
5799*a9fa9459Szrj
5800*a9fa9459SzrjThis may or may not be the script author's intention for the value of
5801*a9fa9459Szrj@code{start_of_data}.  One way to influence the orphan section
5802*a9fa9459Szrjplacement is to assign the location counter to itself, as the linker
5803*a9fa9459Szrjassumes that an assignment to @code{.} is setting the start address of
5804*a9fa9459Szrja following output section and thus should be grouped with that
5805*a9fa9459Szrjsection.  So you could write:
5806*a9fa9459Szrj
5807*a9fa9459Szrj@smallexample
5808*a9fa9459SzrjSECTIONS
5809*a9fa9459Szrj@{
5810*a9fa9459Szrj    start_of_text = . ;
5811*a9fa9459Szrj    .text: @{ *(.text) @}
5812*a9fa9459Szrj    end_of_text = . ;
5813*a9fa9459Szrj
5814*a9fa9459Szrj    . = . ;
5815*a9fa9459Szrj    start_of_data = . ;
5816*a9fa9459Szrj    .data: @{ *(.data) @}
5817*a9fa9459Szrj    end_of_data = . ;
5818*a9fa9459Szrj@}
5819*a9fa9459Szrj@end smallexample
5820*a9fa9459Szrj
5821*a9fa9459SzrjNow, the orphan @code{.rodata} section will be placed between
5822*a9fa9459Szrj@code{end_of_text} and @code{start_of_data}.
5823*a9fa9459Szrj
5824*a9fa9459Szrj@need 2000
5825*a9fa9459Szrj@node Operators
5826*a9fa9459Szrj@subsection Operators
5827*a9fa9459Szrj@cindex operators for arithmetic
5828*a9fa9459Szrj@cindex arithmetic operators
5829*a9fa9459Szrj@cindex precedence in expressions
5830*a9fa9459SzrjThe linker recognizes the standard C set of arithmetic operators, with
5831*a9fa9459Szrjthe standard bindings and precedence levels:
5832*a9fa9459Szrj@c TEXI2ROFF-KILL
5833*a9fa9459Szrj@ifnottex
5834*a9fa9459Szrj@c END TEXI2ROFF-KILL
5835*a9fa9459Szrj@smallexample
5836*a9fa9459Szrjprecedence      associativity   Operators                Notes
5837*a9fa9459Szrj(highest)
5838*a9fa9459Szrj1               left            !  -  ~                  (1)
5839*a9fa9459Szrj2               left            *  /  %
5840*a9fa9459Szrj3               left            +  -
5841*a9fa9459Szrj4               left            >>  <<
5842*a9fa9459Szrj5               left            ==  !=  >  <  <=  >=
5843*a9fa9459Szrj6               left            &
5844*a9fa9459Szrj7               left            |
5845*a9fa9459Szrj8               left            &&
5846*a9fa9459Szrj9               left            ||
5847*a9fa9459Szrj10              right           ? :
5848*a9fa9459Szrj11              right           &=  +=  -=  *=  /=       (2)
5849*a9fa9459Szrj(lowest)
5850*a9fa9459Szrj@end smallexample
5851*a9fa9459SzrjNotes:
5852*a9fa9459Szrj(1) Prefix operators
5853*a9fa9459Szrj(2) @xref{Assignments}.
5854*a9fa9459Szrj@c TEXI2ROFF-KILL
5855*a9fa9459Szrj@end ifnottex
5856*a9fa9459Szrj@tex
5857*a9fa9459Szrj\vskip \baselineskip
5858*a9fa9459Szrj%"lispnarrowing" is the extra indent used generally for smallexample
5859*a9fa9459Szrj\hskip\lispnarrowing\vbox{\offinterlineskip
5860*a9fa9459Szrj\hrule
5861*a9fa9459Szrj\halign
5862*a9fa9459Szrj{\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ #\ \hfil&\vrule#&\strut\hfil\ {\tt #}\ \hfil&\vrule#\cr
5863*a9fa9459Szrjheight2pt&\omit&&\omit&&\omit&\cr
5864*a9fa9459Szrj&Precedence&&  Associativity  &&{\rm Operators}&\cr
5865*a9fa9459Szrjheight2pt&\omit&&\omit&&\omit&\cr
5866*a9fa9459Szrj\noalign{\hrule}
5867*a9fa9459Szrjheight2pt&\omit&&\omit&&\omit&\cr
5868*a9fa9459Szrj&highest&&&&&\cr
5869*a9fa9459Szrj% '176 is tilde, '~' in tt font
5870*a9fa9459Szrj&1&&left&&\qquad-          \char'176\      !\qquad\dag&\cr
5871*a9fa9459Szrj&2&&left&&*          /        \%&\cr
5872*a9fa9459Szrj&3&&left&&+          -&\cr
5873*a9fa9459Szrj&4&&left&&>>         <<&\cr
5874*a9fa9459Szrj&5&&left&&==         !=       >      <      <=      >=&\cr
5875*a9fa9459Szrj&6&&left&&\&&\cr
5876*a9fa9459Szrj&7&&left&&|&\cr
5877*a9fa9459Szrj&8&&left&&{\&\&}&\cr
5878*a9fa9459Szrj&9&&left&&||&\cr
5879*a9fa9459Szrj&10&&right&&?        :&\cr
5880*a9fa9459Szrj&11&&right&&\qquad\&=      +=       -=     *=     /=\qquad\ddag&\cr
5881*a9fa9459Szrj&lowest&&&&&\cr
5882*a9fa9459Szrjheight2pt&\omit&&\omit&&\omit&\cr}
5883*a9fa9459Szrj\hrule}
5884*a9fa9459Szrj@end tex
5885*a9fa9459Szrj@iftex
5886*a9fa9459Szrj{
5887*a9fa9459Szrj@obeylines@parskip=0pt@parindent=0pt
5888*a9fa9459Szrj@dag@quad Prefix operators.
5889*a9fa9459Szrj@ddag@quad @xref{Assignments}.
5890*a9fa9459Szrj}
5891*a9fa9459Szrj@end iftex
5892*a9fa9459Szrj@c END TEXI2ROFF-KILL
5893*a9fa9459Szrj
5894*a9fa9459Szrj@node Evaluation
5895*a9fa9459Szrj@subsection Evaluation
5896*a9fa9459Szrj@cindex lazy evaluation
5897*a9fa9459Szrj@cindex expression evaluation order
5898*a9fa9459SzrjThe linker evaluates expressions lazily.  It only computes the value of
5899*a9fa9459Szrjan expression when absolutely necessary.
5900*a9fa9459Szrj
5901*a9fa9459SzrjThe linker needs some information, such as the value of the start
5902*a9fa9459Szrjaddress of the first section, and the origins and lengths of memory
5903*a9fa9459Szrjregions, in order to do any linking at all.  These values are computed
5904*a9fa9459Szrjas soon as possible when the linker reads in the linker script.
5905*a9fa9459Szrj
5906*a9fa9459SzrjHowever, other values (such as symbol values) are not known or needed
5907*a9fa9459Szrjuntil after storage allocation.  Such values are evaluated later, when
5908*a9fa9459Szrjother information (such as the sizes of output sections) is available
5909*a9fa9459Szrjfor use in the symbol assignment expression.
5910*a9fa9459Szrj
5911*a9fa9459SzrjThe sizes of sections cannot be known until after allocation, so
5912*a9fa9459Szrjassignments dependent upon these are not performed until after
5913*a9fa9459Szrjallocation.
5914*a9fa9459Szrj
5915*a9fa9459SzrjSome expressions, such as those depending upon the location counter
5916*a9fa9459Szrj@samp{.}, must be evaluated during section allocation.
5917*a9fa9459Szrj
5918*a9fa9459SzrjIf the result of an expression is required, but the value is not
5919*a9fa9459Szrjavailable, then an error results.  For example, a script like the
5920*a9fa9459Szrjfollowing
5921*a9fa9459Szrj@smallexample
5922*a9fa9459Szrj@group
5923*a9fa9459SzrjSECTIONS
5924*a9fa9459Szrj  @{
5925*a9fa9459Szrj    .text 9+this_isnt_constant :
5926*a9fa9459Szrj      @{ *(.text) @}
5927*a9fa9459Szrj  @}
5928*a9fa9459Szrj@end group
5929*a9fa9459Szrj@end smallexample
5930*a9fa9459Szrj@noindent
5931*a9fa9459Szrjwill cause the error message @samp{non constant expression for initial
5932*a9fa9459Szrjaddress}.
5933*a9fa9459Szrj
5934*a9fa9459Szrj@node Expression Section
5935*a9fa9459Szrj@subsection The Section of an Expression
5936*a9fa9459Szrj@cindex expression sections
5937*a9fa9459Szrj@cindex absolute expressions
5938*a9fa9459Szrj@cindex relative expressions
5939*a9fa9459Szrj@cindex absolute and relocatable symbols
5940*a9fa9459Szrj@cindex relocatable and absolute symbols
5941*a9fa9459Szrj@cindex symbols, relocatable and absolute
5942*a9fa9459SzrjAddresses and symbols may be section relative, or absolute.  A section
5943*a9fa9459Szrjrelative symbol is relocatable.  If you request relocatable output
5944*a9fa9459Szrjusing the @samp{-r} option, a further link operation may change the
5945*a9fa9459Szrjvalue of a section relative symbol.  On the other hand, an absolute
5946*a9fa9459Szrjsymbol will retain the same value throughout any further link
5947*a9fa9459Szrjoperations.
5948*a9fa9459Szrj
5949*a9fa9459SzrjSome terms in linker expressions are addresses.  This is true of
5950*a9fa9459Szrjsection relative symbols and for builtin functions that return an
5951*a9fa9459Szrjaddress, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
5952*a9fa9459Szrj@code{SEGMENT_START}.  Other terms are simply numbers, or are builtin
5953*a9fa9459Szrjfunctions that return a non-address value, such as @code{LENGTH}.
5954*a9fa9459SzrjOne complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
5955*a9fa9459Szrj(@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
5956*a9fa9459Szrjdifferently depending on their location, for compatibility with older
5957*a9fa9459Szrjversions of @code{ld}.  Expressions appearing outside an output
5958*a9fa9459Szrjsection definition treat all numbers as absolute addresses.
5959*a9fa9459SzrjExpressions appearing inside an output section definition treat
5960*a9fa9459Szrjabsolute symbols as numbers.  If @code{LD_FEATURE ("SANE_EXPR")} is
5961*a9fa9459Szrjgiven, then absolute symbols and numbers are simply treated as numbers
5962*a9fa9459Szrjeverywhere.
5963*a9fa9459Szrj
5964*a9fa9459SzrjIn the following simple example,
5965*a9fa9459Szrj
5966*a9fa9459Szrj@smallexample
5967*a9fa9459Szrj@group
5968*a9fa9459SzrjSECTIONS
5969*a9fa9459Szrj  @{
5970*a9fa9459Szrj    . = 0x100;
5971*a9fa9459Szrj    __executable_start = 0x100;
5972*a9fa9459Szrj    .data :
5973*a9fa9459Szrj    @{
5974*a9fa9459Szrj      . = 0x10;
5975*a9fa9459Szrj      __data_start = 0x10;
5976*a9fa9459Szrj      *(.data)
5977*a9fa9459Szrj    @}
5978*a9fa9459Szrj    @dots{}
5979*a9fa9459Szrj  @}
5980*a9fa9459Szrj@end group
5981*a9fa9459Szrj@end smallexample
5982*a9fa9459Szrj
5983*a9fa9459Szrjboth @code{.} and @code{__executable_start} are set to the absolute
5984*a9fa9459Szrjaddress 0x100 in the first two assignments, then both @code{.} and
5985*a9fa9459Szrj@code{__data_start} are set to 0x10 relative to the @code{.data}
5986*a9fa9459Szrjsection in the second two assignments.
5987*a9fa9459Szrj
5988*a9fa9459SzrjFor expressions involving numbers, relative addresses and absolute
5989*a9fa9459Szrjaddresses, ld follows these rules to evaluate terms:
5990*a9fa9459Szrj
5991*a9fa9459Szrj@itemize @bullet
5992*a9fa9459Szrj@item
5993*a9fa9459SzrjUnary operations on an absolute address or number, and binary
5994*a9fa9459Szrjoperations on two absolute addresses or two numbers, or between one
5995*a9fa9459Szrjabsolute address and a number, apply the operator to the value(s).
5996*a9fa9459Szrj@item
5997*a9fa9459SzrjUnary operations on a relative address, and binary operations on two
5998*a9fa9459Szrjrelative addresses in the same section or between one relative address
5999*a9fa9459Szrjand a number, apply the operator to the offset part of the address(es).
6000*a9fa9459Szrj@item
6001*a9fa9459SzrjOther binary operations, that is, between two relative addresses not
6002*a9fa9459Szrjin the same section, or between a relative address and an absolute
6003*a9fa9459Szrjaddress, first convert any non-absolute term to an absolute address
6004*a9fa9459Szrjbefore applying the operator.
6005*a9fa9459Szrj@end itemize
6006*a9fa9459Szrj
6007*a9fa9459SzrjThe result section of each sub-expression is as follows:
6008*a9fa9459Szrj
6009*a9fa9459Szrj@itemize @bullet
6010*a9fa9459Szrj@item
6011*a9fa9459SzrjAn operation involving only numbers results in a number.
6012*a9fa9459Szrj@item
6013*a9fa9459SzrjThe result of comparisons, @samp{&&} and @samp{||} is also a number.
6014*a9fa9459Szrj@item
6015*a9fa9459SzrjThe result of other binary arithmetic and logical operations on two
6016*a9fa9459Szrjrelative addresses in the same section or two absolute addresses
6017*a9fa9459Szrj(after above conversions) is also a number.
6018*a9fa9459Szrj@item
6019*a9fa9459SzrjThe result of other operations on relative addresses or one
6020*a9fa9459Szrjrelative address and a number, is a relative address in the same
6021*a9fa9459Szrjsection as the relative operand(s).
6022*a9fa9459Szrj@item
6023*a9fa9459SzrjThe result of other operations on absolute addresses (after above
6024*a9fa9459Szrjconversions) is an absolute address.
6025*a9fa9459Szrj@end itemize
6026*a9fa9459Szrj
6027*a9fa9459SzrjYou can use the builtin function @code{ABSOLUTE} to force an expression
6028*a9fa9459Szrjto be absolute when it would otherwise be relative.  For example, to
6029*a9fa9459Szrjcreate an absolute symbol set to the address of the end of the output
6030*a9fa9459Szrjsection @samp{.data}:
6031*a9fa9459Szrj@smallexample
6032*a9fa9459SzrjSECTIONS
6033*a9fa9459Szrj  @{
6034*a9fa9459Szrj    .data : @{ *(.data) _edata = ABSOLUTE(.); @}
6035*a9fa9459Szrj  @}
6036*a9fa9459Szrj@end smallexample
6037*a9fa9459Szrj@noindent
6038*a9fa9459SzrjIf @samp{ABSOLUTE} were not used, @samp{_edata} would be relative to the
6039*a9fa9459Szrj@samp{.data} section.
6040*a9fa9459Szrj
6041*a9fa9459SzrjUsing @code{LOADADDR} also forces an expression absolute, since this
6042*a9fa9459Szrjparticular builtin function returns an absolute address.
6043*a9fa9459Szrj
6044*a9fa9459Szrj@node Builtin Functions
6045*a9fa9459Szrj@subsection Builtin Functions
6046*a9fa9459Szrj@cindex functions in expressions
6047*a9fa9459SzrjThe linker script language includes a number of builtin functions for
6048*a9fa9459Szrjuse in linker script expressions.
6049*a9fa9459Szrj
6050*a9fa9459Szrj@table @code
6051*a9fa9459Szrj@item ABSOLUTE(@var{exp})
6052*a9fa9459Szrj@kindex ABSOLUTE(@var{exp})
6053*a9fa9459Szrj@cindex expression, absolute
6054*a9fa9459SzrjReturn the absolute (non-relocatable, as opposed to non-negative) value
6055*a9fa9459Szrjof the expression @var{exp}.  Primarily useful to assign an absolute
6056*a9fa9459Szrjvalue to a symbol within a section definition, where symbol values are
6057*a9fa9459Szrjnormally section relative.  @xref{Expression Section}.
6058*a9fa9459Szrj
6059*a9fa9459Szrj@item ADDR(@var{section})
6060*a9fa9459Szrj@kindex ADDR(@var{section})
6061*a9fa9459Szrj@cindex section address in expression
6062*a9fa9459SzrjReturn the address (VMA) of the named @var{section}.  Your
6063*a9fa9459Szrjscript must previously have defined the location of that section.  In
6064*a9fa9459Szrjthe following example, @code{start_of_output_1}, @code{symbol_1} and
6065*a9fa9459Szrj@code{symbol_2} are assigned equivalent values, except that
6066*a9fa9459Szrj@code{symbol_1} will be relative to the @code{.output1} section while
6067*a9fa9459Szrjthe other two will be absolute:
6068*a9fa9459Szrj@smallexample
6069*a9fa9459Szrj@group
6070*a9fa9459SzrjSECTIONS @{ @dots{}
6071*a9fa9459Szrj  .output1 :
6072*a9fa9459Szrj    @{
6073*a9fa9459Szrj    start_of_output_1 = ABSOLUTE(.);
6074*a9fa9459Szrj    @dots{}
6075*a9fa9459Szrj    @}
6076*a9fa9459Szrj  .output :
6077*a9fa9459Szrj    @{
6078*a9fa9459Szrj    symbol_1 = ADDR(.output1);
6079*a9fa9459Szrj    symbol_2 = start_of_output_1;
6080*a9fa9459Szrj    @}
6081*a9fa9459Szrj@dots{} @}
6082*a9fa9459Szrj@end group
6083*a9fa9459Szrj@end smallexample
6084*a9fa9459Szrj
6085*a9fa9459Szrj@item ALIGN(@var{align})
6086*a9fa9459Szrj@itemx ALIGN(@var{exp},@var{align})
6087*a9fa9459Szrj@kindex ALIGN(@var{align})
6088*a9fa9459Szrj@kindex ALIGN(@var{exp},@var{align})
6089*a9fa9459Szrj@cindex round up location counter
6090*a9fa9459Szrj@cindex align location counter
6091*a9fa9459Szrj@cindex round up expression
6092*a9fa9459Szrj@cindex align expression
6093*a9fa9459SzrjReturn the location counter (@code{.}) or arbitrary expression aligned
6094*a9fa9459Szrjto the next @var{align} boundary.  The single operand @code{ALIGN}
6095*a9fa9459Szrjdoesn't change the value of the location counter---it just does
6096*a9fa9459Szrjarithmetic on it.  The two operand @code{ALIGN} allows an arbitrary
6097*a9fa9459Szrjexpression to be aligned upwards (@code{ALIGN(@var{align})} is
6098*a9fa9459Szrjequivalent to @code{ALIGN(ABSOLUTE(.), @var{align})}).
6099*a9fa9459Szrj
6100*a9fa9459SzrjHere is an example which aligns the output @code{.data} section to the
6101*a9fa9459Szrjnext @code{0x2000} byte boundary after the preceding section and sets a
6102*a9fa9459Szrjvariable within the section to the next @code{0x8000} boundary after the
6103*a9fa9459Szrjinput sections:
6104*a9fa9459Szrj@smallexample
6105*a9fa9459Szrj@group
6106*a9fa9459SzrjSECTIONS @{ @dots{}
6107*a9fa9459Szrj  .data ALIGN(0x2000): @{
6108*a9fa9459Szrj    *(.data)
6109*a9fa9459Szrj    variable = ALIGN(0x8000);
6110*a9fa9459Szrj  @}
6111*a9fa9459Szrj@dots{} @}
6112*a9fa9459Szrj@end group
6113*a9fa9459Szrj@end smallexample
6114*a9fa9459Szrj@noindent
6115*a9fa9459SzrjThe first use of @code{ALIGN} in this example specifies the location of
6116*a9fa9459Szrja section because it is used as the optional @var{address} attribute of
6117*a9fa9459Szrja section definition (@pxref{Output Section Address}).  The second use
6118*a9fa9459Szrjof @code{ALIGN} is used to defines the value of a symbol.
6119*a9fa9459Szrj
6120*a9fa9459SzrjThe builtin function @code{NEXT} is closely related to @code{ALIGN}.
6121*a9fa9459Szrj
6122*a9fa9459Szrj@item ALIGNOF(@var{section})
6123*a9fa9459Szrj@kindex ALIGNOF(@var{section})
6124*a9fa9459Szrj@cindex section alignment
6125*a9fa9459SzrjReturn the alignment in bytes of the named @var{section}, if that section has
6126*a9fa9459Szrjbeen allocated.  If the section has not been allocated when this is
6127*a9fa9459Szrjevaluated, the linker will report an error. In the following example,
6128*a9fa9459Szrjthe alignment of the @code{.output} section is stored as the first
6129*a9fa9459Szrjvalue in that section.
6130*a9fa9459Szrj@smallexample
6131*a9fa9459Szrj@group
6132*a9fa9459SzrjSECTIONS@{ @dots{}
6133*a9fa9459Szrj  .output @{
6134*a9fa9459Szrj    LONG (ALIGNOF (.output))
6135*a9fa9459Szrj    @dots{}
6136*a9fa9459Szrj    @}
6137*a9fa9459Szrj@dots{} @}
6138*a9fa9459Szrj@end group
6139*a9fa9459Szrj@end smallexample
6140*a9fa9459Szrj
6141*a9fa9459Szrj@item BLOCK(@var{exp})
6142*a9fa9459Szrj@kindex BLOCK(@var{exp})
6143*a9fa9459SzrjThis is a synonym for @code{ALIGN}, for compatibility with older linker
6144*a9fa9459Szrjscripts.  It is most often seen when setting the address of an output
6145*a9fa9459Szrjsection.
6146*a9fa9459Szrj
6147*a9fa9459Szrj@item DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
6148*a9fa9459Szrj@kindex DATA_SEGMENT_ALIGN(@var{maxpagesize}, @var{commonpagesize})
6149*a9fa9459SzrjThis is equivalent to either
6150*a9fa9459Szrj@smallexample
6151*a9fa9459Szrj(ALIGN(@var{maxpagesize}) + (. & (@var{maxpagesize} - 1)))
6152*a9fa9459Szrj@end smallexample
6153*a9fa9459Szrjor
6154*a9fa9459Szrj@smallexample
6155*a9fa9459Szrj(ALIGN(@var{maxpagesize})
6156*a9fa9459Szrj + ((. + @var{commonpagesize} - 1) & (@var{maxpagesize} - @var{commonpagesize})))
6157*a9fa9459Szrj@end smallexample
6158*a9fa9459Szrj@noindent
6159*a9fa9459Szrjdepending on whether the latter uses fewer @var{commonpagesize} sized pages
6160*a9fa9459Szrjfor the data segment (area between the result of this expression and
6161*a9fa9459Szrj@code{DATA_SEGMENT_END}) than the former or not.
6162*a9fa9459SzrjIf the latter form is used, it means @var{commonpagesize} bytes of runtime
6163*a9fa9459Szrjmemory will be saved at the expense of up to @var{commonpagesize} wasted
6164*a9fa9459Szrjbytes in the on-disk file.
6165*a9fa9459Szrj
6166*a9fa9459SzrjThis expression can only be used directly in @code{SECTIONS} commands, not in
6167*a9fa9459Szrjany output section descriptions and only once in the linker script.
6168*a9fa9459Szrj@var{commonpagesize} should be less or equal to @var{maxpagesize} and should
6169*a9fa9459Szrjbe the system page size the object wants to be optimized for (while still
6170*a9fa9459Szrjworking on system page sizes up to @var{maxpagesize}).
6171*a9fa9459Szrj
6172*a9fa9459Szrj@noindent
6173*a9fa9459SzrjExample:
6174*a9fa9459Szrj@smallexample
6175*a9fa9459Szrj  . = DATA_SEGMENT_ALIGN(0x10000, 0x2000);
6176*a9fa9459Szrj@end smallexample
6177*a9fa9459Szrj
6178*a9fa9459Szrj@item DATA_SEGMENT_END(@var{exp})
6179*a9fa9459Szrj@kindex DATA_SEGMENT_END(@var{exp})
6180*a9fa9459SzrjThis defines the end of data segment for @code{DATA_SEGMENT_ALIGN}
6181*a9fa9459Szrjevaluation purposes.
6182*a9fa9459Szrj
6183*a9fa9459Szrj@smallexample
6184*a9fa9459Szrj  . = DATA_SEGMENT_END(.);
6185*a9fa9459Szrj@end smallexample
6186*a9fa9459Szrj
6187*a9fa9459Szrj@item DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
6188*a9fa9459Szrj@kindex DATA_SEGMENT_RELRO_END(@var{offset}, @var{exp})
6189*a9fa9459SzrjThis defines the end of the @code{PT_GNU_RELRO} segment when
6190*a9fa9459Szrj@samp{-z relro} option is used.
6191*a9fa9459SzrjWhen @samp{-z relro} option is not present, @code{DATA_SEGMENT_RELRO_END}
6192*a9fa9459Szrjdoes nothing, otherwise @code{DATA_SEGMENT_ALIGN} is padded so that
6193*a9fa9459Szrj@var{exp} + @var{offset} is aligned to the most commonly used page
6194*a9fa9459Szrjboundary for particular target.  If present in the linker script,
6195*a9fa9459Szrjit must always come in between @code{DATA_SEGMENT_ALIGN} and
6196*a9fa9459Szrj@code{DATA_SEGMENT_END}.  Evaluates to the second argument plus any
6197*a9fa9459Szrjpadding needed at the end of the @code{PT_GNU_RELRO} segment due to
6198*a9fa9459Szrjsection alignment.
6199*a9fa9459Szrj
6200*a9fa9459Szrj@smallexample
6201*a9fa9459Szrj  . = DATA_SEGMENT_RELRO_END(24, .);
6202*a9fa9459Szrj@end smallexample
6203*a9fa9459Szrj
6204*a9fa9459Szrj@item DEFINED(@var{symbol})
6205*a9fa9459Szrj@kindex DEFINED(@var{symbol})
6206*a9fa9459Szrj@cindex symbol defaults
6207*a9fa9459SzrjReturn 1 if @var{symbol} is in the linker global symbol table and is
6208*a9fa9459Szrjdefined before the statement using DEFINED in the script, otherwise
6209*a9fa9459Szrjreturn 0.  You can use this function to provide
6210*a9fa9459Szrjdefault values for symbols.  For example, the following script fragment
6211*a9fa9459Szrjshows how to set a global symbol @samp{begin} to the first location in
6212*a9fa9459Szrjthe @samp{.text} section---but if a symbol called @samp{begin} already
6213*a9fa9459Szrjexisted, its value is preserved:
6214*a9fa9459Szrj
6215*a9fa9459Szrj@smallexample
6216*a9fa9459Szrj@group
6217*a9fa9459SzrjSECTIONS @{ @dots{}
6218*a9fa9459Szrj  .text : @{
6219*a9fa9459Szrj    begin = DEFINED(begin) ? begin : . ;
6220*a9fa9459Szrj    @dots{}
6221*a9fa9459Szrj  @}
6222*a9fa9459Szrj  @dots{}
6223*a9fa9459Szrj@}
6224*a9fa9459Szrj@end group
6225*a9fa9459Szrj@end smallexample
6226*a9fa9459Szrj
6227*a9fa9459Szrj@item LENGTH(@var{memory})
6228*a9fa9459Szrj@kindex LENGTH(@var{memory})
6229*a9fa9459SzrjReturn the length of the memory region named @var{memory}.
6230*a9fa9459Szrj
6231*a9fa9459Szrj@item LOADADDR(@var{section})
6232*a9fa9459Szrj@kindex LOADADDR(@var{section})
6233*a9fa9459Szrj@cindex section load address in expression
6234*a9fa9459SzrjReturn the absolute LMA of the named @var{section}.  (@pxref{Output
6235*a9fa9459SzrjSection LMA}).
6236*a9fa9459Szrj
6237*a9fa9459Szrj@item LOG2CEIL(@var{exp})
6238*a9fa9459Szrj@kindex LOG2CEIL(@var{exp})
6239*a9fa9459SzrjReturn the binary logarithm of @var{exp} rounded towards infinity.
6240*a9fa9459Szrj@code{LOG2CEIL(0)} returns 0.
6241*a9fa9459Szrj
6242*a9fa9459Szrj@kindex MAX
6243*a9fa9459Szrj@item MAX(@var{exp1}, @var{exp2})
6244*a9fa9459SzrjReturns the maximum of @var{exp1} and @var{exp2}.
6245*a9fa9459Szrj
6246*a9fa9459Szrj@kindex MIN
6247*a9fa9459Szrj@item MIN(@var{exp1}, @var{exp2})
6248*a9fa9459SzrjReturns the minimum of @var{exp1} and @var{exp2}.
6249*a9fa9459Szrj
6250*a9fa9459Szrj@item NEXT(@var{exp})
6251*a9fa9459Szrj@kindex NEXT(@var{exp})
6252*a9fa9459Szrj@cindex unallocated address, next
6253*a9fa9459SzrjReturn the next unallocated address that is a multiple of @var{exp}.
6254*a9fa9459SzrjThis function is closely related to @code{ALIGN(@var{exp})}; unless you
6255*a9fa9459Szrjuse the @code{MEMORY} command to define discontinuous memory for the
6256*a9fa9459Szrjoutput file, the two functions are equivalent.
6257*a9fa9459Szrj
6258*a9fa9459Szrj@item ORIGIN(@var{memory})
6259*a9fa9459Szrj@kindex ORIGIN(@var{memory})
6260*a9fa9459SzrjReturn the origin of the memory region named @var{memory}.
6261*a9fa9459Szrj
6262*a9fa9459Szrj@item SEGMENT_START(@var{segment}, @var{default})
6263*a9fa9459Szrj@kindex SEGMENT_START(@var{segment}, @var{default})
6264*a9fa9459SzrjReturn the base address of the named @var{segment}.  If an explicit
6265*a9fa9459Szrjvalue has already been given for this segment (with a command-line
6266*a9fa9459Szrj@samp{-T} option) then that value will be returned otherwise the value
6267*a9fa9459Szrjwill be @var{default}.  At present, the @samp{-T} command-line option
6268*a9fa9459Szrjcan only be used to set the base address for the ``text'', ``data'', and
6269*a9fa9459Szrj``bss'' sections, but you can use @code{SEGMENT_START} with any segment
6270*a9fa9459Szrjname.
6271*a9fa9459Szrj
6272*a9fa9459Szrj@item SIZEOF(@var{section})
6273*a9fa9459Szrj@kindex SIZEOF(@var{section})
6274*a9fa9459Szrj@cindex section size
6275*a9fa9459SzrjReturn the size in bytes of the named @var{section}, if that section has
6276*a9fa9459Szrjbeen allocated.  If the section has not been allocated when this is
6277*a9fa9459Szrjevaluated, the linker will report an error.  In the following example,
6278*a9fa9459Szrj@code{symbol_1} and @code{symbol_2} are assigned identical values:
6279*a9fa9459Szrj@smallexample
6280*a9fa9459Szrj@group
6281*a9fa9459SzrjSECTIONS@{ @dots{}
6282*a9fa9459Szrj  .output @{
6283*a9fa9459Szrj    .start = . ;
6284*a9fa9459Szrj    @dots{}
6285*a9fa9459Szrj    .end = . ;
6286*a9fa9459Szrj    @}
6287*a9fa9459Szrj  symbol_1 = .end - .start ;
6288*a9fa9459Szrj  symbol_2 = SIZEOF(.output);
6289*a9fa9459Szrj@dots{} @}
6290*a9fa9459Szrj@end group
6291*a9fa9459Szrj@end smallexample
6292*a9fa9459Szrj
6293*a9fa9459Szrj@item SIZEOF_HEADERS
6294*a9fa9459Szrj@itemx sizeof_headers
6295*a9fa9459Szrj@kindex SIZEOF_HEADERS
6296*a9fa9459Szrj@cindex header size
6297*a9fa9459SzrjReturn the size in bytes of the output file's headers.  This is
6298*a9fa9459Szrjinformation which appears at the start of the output file.  You can use
6299*a9fa9459Szrjthis number when setting the start address of the first section, if you
6300*a9fa9459Szrjchoose, to facilitate paging.
6301*a9fa9459Szrj
6302*a9fa9459Szrj@cindex not enough room for program headers
6303*a9fa9459Szrj@cindex program headers, not enough room
6304*a9fa9459SzrjWhen producing an ELF output file, if the linker script uses the
6305*a9fa9459Szrj@code{SIZEOF_HEADERS} builtin function, the linker must compute the
6306*a9fa9459Szrjnumber of program headers before it has determined all the section
6307*a9fa9459Szrjaddresses and sizes.  If the linker later discovers that it needs
6308*a9fa9459Szrjadditional program headers, it will report an error @samp{not enough
6309*a9fa9459Szrjroom for program headers}.  To avoid this error, you must avoid using
6310*a9fa9459Szrjthe @code{SIZEOF_HEADERS} function, or you must rework your linker
6311*a9fa9459Szrjscript to avoid forcing the linker to use additional program headers, or
6312*a9fa9459Szrjyou must define the program headers yourself using the @code{PHDRS}
6313*a9fa9459Szrjcommand (@pxref{PHDRS}).
6314*a9fa9459Szrj@end table
6315*a9fa9459Szrj
6316*a9fa9459Szrj@node Implicit Linker Scripts
6317*a9fa9459Szrj@section Implicit Linker Scripts
6318*a9fa9459Szrj@cindex implicit linker scripts
6319*a9fa9459SzrjIf you specify a linker input file which the linker can not recognize as
6320*a9fa9459Szrjan object file or an archive file, it will try to read the file as a
6321*a9fa9459Szrjlinker script.  If the file can not be parsed as a linker script, the
6322*a9fa9459Szrjlinker will report an error.
6323*a9fa9459Szrj
6324*a9fa9459SzrjAn implicit linker script will not replace the default linker script.
6325*a9fa9459Szrj
6326*a9fa9459SzrjTypically an implicit linker script would contain only symbol
6327*a9fa9459Szrjassignments, or the @code{INPUT}, @code{GROUP}, or @code{VERSION}
6328*a9fa9459Szrjcommands.
6329*a9fa9459Szrj
6330*a9fa9459SzrjAny input files read because of an implicit linker script will be read
6331*a9fa9459Szrjat the position in the command line where the implicit linker script was
6332*a9fa9459Szrjread.  This can affect archive searching.
6333*a9fa9459Szrj
6334*a9fa9459Szrj@ifset GENERIC
6335*a9fa9459Szrj@node Machine Dependent
6336*a9fa9459Szrj@chapter Machine Dependent Features
6337*a9fa9459Szrj
6338*a9fa9459Szrj@cindex machine dependencies
6339*a9fa9459Szrj@command{ld} has additional features on some platforms; the following
6340*a9fa9459Szrjsections describe them.  Machines where @command{ld} has no additional
6341*a9fa9459Szrjfunctionality are not listed.
6342*a9fa9459Szrj
6343*a9fa9459Szrj@menu
6344*a9fa9459Szrj@ifset H8300
6345*a9fa9459Szrj* H8/300::                      @command{ld} and the H8/300
6346*a9fa9459Szrj@end ifset
6347*a9fa9459Szrj@ifset I960
6348*a9fa9459Szrj* i960::                        @command{ld} and the Intel 960 family
6349*a9fa9459Szrj@end ifset
6350*a9fa9459Szrj@ifset M68HC11
6351*a9fa9459Szrj* M68HC11/68HC12::		@code{ld} and the Motorola 68HC11 and 68HC12 families
6352*a9fa9459Szrj@end ifset
6353*a9fa9459Szrj@ifset ARM
6354*a9fa9459Szrj* ARM::				@command{ld} and the ARM family
6355*a9fa9459Szrj@end ifset
6356*a9fa9459Szrj@ifset HPPA
6357*a9fa9459Szrj* HPPA ELF32::                  @command{ld} and HPPA 32-bit ELF
6358*a9fa9459Szrj@end ifset
6359*a9fa9459Szrj@ifset M68K
6360*a9fa9459Szrj* M68K::			@command{ld} and the Motorola 68K family
6361*a9fa9459Szrj@end ifset
6362*a9fa9459Szrj@ifset MIPS
6363*a9fa9459Szrj* MIPS::			@command{ld} and the MIPS family
6364*a9fa9459Szrj@end ifset
6365*a9fa9459Szrj@ifset MMIX
6366*a9fa9459Szrj* MMIX::			@command{ld} and MMIX
6367*a9fa9459Szrj@end ifset
6368*a9fa9459Szrj@ifset MSP430
6369*a9fa9459Szrj* MSP430::			@command{ld} and MSP430
6370*a9fa9459Szrj@end ifset
6371*a9fa9459Szrj@ifset NDS32
6372*a9fa9459Szrj* NDS32::			@command{ld} and NDS32
6373*a9fa9459Szrj@end ifset
6374*a9fa9459Szrj@ifset NIOSII
6375*a9fa9459Szrj* Nios II::			@command{ld} and the Altera Nios II
6376*a9fa9459Szrj@end ifset
6377*a9fa9459Szrj@ifset POWERPC
6378*a9fa9459Szrj* PowerPC ELF32::		@command{ld} and PowerPC 32-bit ELF Support
6379*a9fa9459Szrj@end ifset
6380*a9fa9459Szrj@ifset POWERPC64
6381*a9fa9459Szrj* PowerPC64 ELF64::		@command{ld} and PowerPC64 64-bit ELF Support
6382*a9fa9459Szrj@end ifset
6383*a9fa9459Szrj@ifset SPU
6384*a9fa9459Szrj* SPU ELF::			@command{ld} and SPU ELF Support
6385*a9fa9459Szrj@end ifset
6386*a9fa9459Szrj@ifset TICOFF
6387*a9fa9459Szrj* TI COFF::                     @command{ld} and TI COFF
6388*a9fa9459Szrj@end ifset
6389*a9fa9459Szrj@ifset WIN32
6390*a9fa9459Szrj* WIN32::                       @command{ld} and WIN32 (cygwin/mingw)
6391*a9fa9459Szrj@end ifset
6392*a9fa9459Szrj@ifset XTENSA
6393*a9fa9459Szrj* Xtensa::                      @command{ld} and Xtensa Processors
6394*a9fa9459Szrj@end ifset
6395*a9fa9459Szrj@end menu
6396*a9fa9459Szrj@end ifset
6397*a9fa9459Szrj
6398*a9fa9459Szrj@ifset H8300
6399*a9fa9459Szrj@ifclear GENERIC
6400*a9fa9459Szrj@raisesections
6401*a9fa9459Szrj@end ifclear
6402*a9fa9459Szrj
6403*a9fa9459Szrj@node H8/300
6404*a9fa9459Szrj@section @command{ld} and the H8/300
6405*a9fa9459Szrj
6406*a9fa9459Szrj@cindex H8/300 support
6407*a9fa9459SzrjFor the H8/300, @command{ld} can perform these global optimizations when
6408*a9fa9459Szrjyou specify the @samp{--relax} command-line option.
6409*a9fa9459Szrj
6410*a9fa9459Szrj@table @emph
6411*a9fa9459Szrj@cindex relaxing on H8/300
6412*a9fa9459Szrj@item relaxing address modes
6413*a9fa9459Szrj@command{ld} finds all @code{jsr} and @code{jmp} instructions whose
6414*a9fa9459Szrjtargets are within eight bits, and turns them into eight-bit
6415*a9fa9459Szrjprogram-counter relative @code{bsr} and @code{bra} instructions,
6416*a9fa9459Szrjrespectively.
6417*a9fa9459Szrj
6418*a9fa9459Szrj@cindex synthesizing on H8/300
6419*a9fa9459Szrj@item synthesizing instructions
6420*a9fa9459Szrj@c FIXME: specifically mov.b, or any mov instructions really? -> mov.b only, at least on H8, H8H, H8S
6421*a9fa9459Szrj@command{ld} finds all @code{mov.b} instructions which use the
6422*a9fa9459Szrjsixteen-bit absolute address form, but refer to the top
6423*a9fa9459Szrjpage of memory, and changes them to use the eight-bit address form.
6424*a9fa9459Szrj(That is: the linker turns @samp{mov.b @code{@@}@var{aa}:16} into
6425*a9fa9459Szrj@samp{mov.b @code{@@}@var{aa}:8} whenever the address @var{aa} is in the
6426*a9fa9459Szrjtop page of memory).
6427*a9fa9459Szrj
6428*a9fa9459Szrj@command{ld} finds all @code{mov} instructions which use the register
6429*a9fa9459Szrjindirect with 32-bit displacement addressing mode, but use a small
6430*a9fa9459Szrjdisplacement inside 16-bit displacement range, and changes them to use
6431*a9fa9459Szrjthe 16-bit displacement form.  (That is: the linker turns @samp{mov.b
6432*a9fa9459Szrj@code{@@}@var{d}:32,ERx} into @samp{mov.b @code{@@}@var{d}:16,ERx}
6433*a9fa9459Szrjwhenever the displacement @var{d} is in the 16 bit signed integer
6434*a9fa9459Szrjrange. Only implemented in ELF-format ld).
6435*a9fa9459Szrj
6436*a9fa9459Szrj@item bit manipulation instructions
6437*a9fa9459Szrj@command{ld} finds all bit manipulation instructions like @code{band, bclr,
6438*a9fa9459Szrjbiand, bild, bior, bist, bixor, bld, bnot, bor, bset, bst, btst, bxor}
6439*a9fa9459Szrjwhich use 32 bit and 16 bit absolute address form, but refer to the top
6440*a9fa9459Szrjpage of memory, and changes them to use the 8 bit address form.
6441*a9fa9459Szrj(That is: the linker turns @samp{bset #xx:3,@code{@@}@var{aa}:32} into
6442*a9fa9459Szrj@samp{bset #xx:3,@code{@@}@var{aa}:8} whenever the address @var{aa} is in
6443*a9fa9459Szrjthe top page of memory).
6444*a9fa9459Szrj
6445*a9fa9459Szrj@item system control instructions
6446*a9fa9459Szrj@command{ld} finds all @code{ldc.w, stc.w} instructions which use the
6447*a9fa9459Szrj32 bit absolute address form, but refer to the top page of memory, and
6448*a9fa9459Szrjchanges them to use 16 bit address form.
6449*a9fa9459Szrj(That is: the linker turns @samp{ldc.w @code{@@}@var{aa}:32,ccr} into
6450*a9fa9459Szrj@samp{ldc.w @code{@@}@var{aa}:16,ccr} whenever the address @var{aa} is in
6451*a9fa9459Szrjthe top page of memory).
6452*a9fa9459Szrj@end table
6453*a9fa9459Szrj
6454*a9fa9459Szrj@ifclear GENERIC
6455*a9fa9459Szrj@lowersections
6456*a9fa9459Szrj@end ifclear
6457*a9fa9459Szrj@end ifset
6458*a9fa9459Szrj
6459*a9fa9459Szrj@ifclear GENERIC
6460*a9fa9459Szrj@ifset Renesas
6461*a9fa9459Szrj@c This stuff is pointless to say unless you're especially concerned
6462*a9fa9459Szrj@c with Renesas chips; don't enable it for generic case, please.
6463*a9fa9459Szrj@node Renesas
6464*a9fa9459Szrj@chapter @command{ld} and Other Renesas Chips
6465*a9fa9459Szrj
6466*a9fa9459Szrj@command{ld} also supports the Renesas (formerly Hitachi) H8/300H,
6467*a9fa9459SzrjH8/500, and SH chips.  No special features, commands, or command-line
6468*a9fa9459Szrjoptions are required for these chips.
6469*a9fa9459Szrj@end ifset
6470*a9fa9459Szrj@end ifclear
6471*a9fa9459Szrj
6472*a9fa9459Szrj@ifset I960
6473*a9fa9459Szrj@ifclear GENERIC
6474*a9fa9459Szrj@raisesections
6475*a9fa9459Szrj@end ifclear
6476*a9fa9459Szrj
6477*a9fa9459Szrj@node i960
6478*a9fa9459Szrj@section @command{ld} and the Intel 960 Family
6479*a9fa9459Szrj
6480*a9fa9459Szrj@cindex i960 support
6481*a9fa9459Szrj
6482*a9fa9459SzrjYou can use the @samp{-A@var{architecture}} command line option to
6483*a9fa9459Szrjspecify one of the two-letter names identifying members of the 960
6484*a9fa9459Szrjfamily; the option specifies the desired output target, and warns of any
6485*a9fa9459Szrjincompatible instructions in the input files.  It also modifies the
6486*a9fa9459Szrjlinker's search strategy for archive libraries, to support the use of
6487*a9fa9459Szrjlibraries specific to each particular architecture, by including in the
6488*a9fa9459Szrjsearch loop names suffixed with the string identifying the architecture.
6489*a9fa9459Szrj
6490*a9fa9459SzrjFor example, if your @command{ld} command line included @w{@samp{-ACA}} as
6491*a9fa9459Szrjwell as @w{@samp{-ltry}}, the linker would look (in its built-in search
6492*a9fa9459Szrjpaths, and in any paths you specify with @samp{-L}) for a library with
6493*a9fa9459Szrjthe names
6494*a9fa9459Szrj
6495*a9fa9459Szrj@smallexample
6496*a9fa9459Szrj@group
6497*a9fa9459Szrjtry
6498*a9fa9459Szrjlibtry.a
6499*a9fa9459Szrjtryca
6500*a9fa9459Szrjlibtryca.a
6501*a9fa9459Szrj@end group
6502*a9fa9459Szrj@end smallexample
6503*a9fa9459Szrj
6504*a9fa9459Szrj@noindent
6505*a9fa9459SzrjThe first two possibilities would be considered in any event; the last
6506*a9fa9459Szrjtwo are due to the use of @w{@samp{-ACA}}.
6507*a9fa9459Szrj
6508*a9fa9459SzrjYou can meaningfully use @samp{-A} more than once on a command line, since
6509*a9fa9459Szrjthe 960 architecture family allows combination of target architectures; each
6510*a9fa9459Szrjuse will add another pair of name variants to search for when @w{@samp{-l}}
6511*a9fa9459Szrjspecifies a library.
6512*a9fa9459Szrj
6513*a9fa9459Szrj@cindex @option{--relax} on i960
6514*a9fa9459Szrj@cindex relaxing on i960
6515*a9fa9459Szrj@command{ld} supports the @samp{--relax} option for the i960 family.  If
6516*a9fa9459Szrjyou specify @samp{--relax}, @command{ld} finds all @code{balx} and
6517*a9fa9459Szrj@code{calx} instructions whose targets are within 24 bits, and turns
6518*a9fa9459Szrjthem into 24-bit program-counter relative @code{bal} and @code{cal}
6519*a9fa9459Szrjinstructions, respectively.  @command{ld} also turns @code{cal}
6520*a9fa9459Szrjinstructions into @code{bal} instructions when it determines that the
6521*a9fa9459Szrjtarget subroutine is a leaf routine (that is, the target subroutine does
6522*a9fa9459Szrjnot itself call any subroutines).
6523*a9fa9459Szrj
6524*a9fa9459Szrj@ifclear GENERIC
6525*a9fa9459Szrj@lowersections
6526*a9fa9459Szrj@end ifclear
6527*a9fa9459Szrj@end ifset
6528*a9fa9459Szrj
6529*a9fa9459Szrj@ifset ARM
6530*a9fa9459Szrj@ifclear GENERIC
6531*a9fa9459Szrj@raisesections
6532*a9fa9459Szrj@end ifclear
6533*a9fa9459Szrj
6534*a9fa9459Szrj@ifset M68HC11
6535*a9fa9459Szrj@ifclear GENERIC
6536*a9fa9459Szrj@raisesections
6537*a9fa9459Szrj@end ifclear
6538*a9fa9459Szrj
6539*a9fa9459Szrj@node M68HC11/68HC12
6540*a9fa9459Szrj@section @command{ld} and the Motorola 68HC11 and 68HC12 families
6541*a9fa9459Szrj
6542*a9fa9459Szrj@cindex M68HC11 and 68HC12 support
6543*a9fa9459Szrj
6544*a9fa9459Szrj@subsection Linker Relaxation
6545*a9fa9459Szrj
6546*a9fa9459SzrjFor the Motorola 68HC11, @command{ld} can perform these global
6547*a9fa9459Szrjoptimizations when you specify the @samp{--relax} command-line option.
6548*a9fa9459Szrj
6549*a9fa9459Szrj@table @emph
6550*a9fa9459Szrj@cindex relaxing on M68HC11
6551*a9fa9459Szrj@item relaxing address modes
6552*a9fa9459Szrj@command{ld} finds all @code{jsr} and @code{jmp} instructions whose
6553*a9fa9459Szrjtargets are within eight bits, and turns them into eight-bit
6554*a9fa9459Szrjprogram-counter relative @code{bsr} and @code{bra} instructions,
6555*a9fa9459Szrjrespectively.
6556*a9fa9459Szrj
6557*a9fa9459Szrj@command{ld} also looks at all 16-bit extended addressing modes and
6558*a9fa9459Szrjtransforms them in a direct addressing mode when the address is in
6559*a9fa9459Szrjpage 0 (between 0 and 0x0ff).
6560*a9fa9459Szrj
6561*a9fa9459Szrj@item relaxing gcc instruction group
6562*a9fa9459SzrjWhen @command{gcc} is called with @option{-mrelax}, it can emit group
6563*a9fa9459Szrjof instructions that the linker can optimize to use a 68HC11 direct
6564*a9fa9459Szrjaddressing mode. These instructions consists of @code{bclr} or
6565*a9fa9459Szrj@code{bset} instructions.
6566*a9fa9459Szrj
6567*a9fa9459Szrj@end table
6568*a9fa9459Szrj
6569*a9fa9459Szrj@subsection Trampoline Generation
6570*a9fa9459Szrj
6571*a9fa9459Szrj@cindex trampoline generation on M68HC11
6572*a9fa9459Szrj@cindex trampoline generation on M68HC12
6573*a9fa9459SzrjFor 68HC11 and 68HC12, @command{ld} can generate trampoline code to
6574*a9fa9459Szrjcall a far function using a normal @code{jsr} instruction. The linker
6575*a9fa9459Szrjwill also change the relocation to some far function to use the
6576*a9fa9459Szrjtrampoline address instead of the function address. This is typically the
6577*a9fa9459Szrjcase when a pointer to a function is taken. The pointer will in fact
6578*a9fa9459Szrjpoint to the function trampoline.
6579*a9fa9459Szrj
6580*a9fa9459Szrj@ifclear GENERIC
6581*a9fa9459Szrj@lowersections
6582*a9fa9459Szrj@end ifclear
6583*a9fa9459Szrj@end ifset
6584*a9fa9459Szrj
6585*a9fa9459Szrj@node ARM
6586*a9fa9459Szrj@section @command{ld} and the ARM family
6587*a9fa9459Szrj
6588*a9fa9459Szrj@cindex ARM interworking support
6589*a9fa9459Szrj@kindex --support-old-code
6590*a9fa9459SzrjFor the ARM, @command{ld} will generate code stubs to allow functions calls
6591*a9fa9459Szrjbetween ARM and Thumb code.  These stubs only work with code that has
6592*a9fa9459Szrjbeen compiled and assembled with the @samp{-mthumb-interwork} command
6593*a9fa9459Szrjline option.  If it is necessary to link with old ARM object files or
6594*a9fa9459Szrjlibraries, which have not been compiled with the -mthumb-interwork
6595*a9fa9459Szrjoption then the @samp{--support-old-code} command line switch should be
6596*a9fa9459Szrjgiven to the linker.  This will make it generate larger stub functions
6597*a9fa9459Szrjwhich will work with non-interworking aware ARM code.  Note, however,
6598*a9fa9459Szrjthe linker does not support generating stubs for function calls to
6599*a9fa9459Szrjnon-interworking aware Thumb code.
6600*a9fa9459Szrj
6601*a9fa9459Szrj@cindex thumb entry point
6602*a9fa9459Szrj@cindex entry point, thumb
6603*a9fa9459Szrj@kindex --thumb-entry=@var{entry}
6604*a9fa9459SzrjThe @samp{--thumb-entry} switch is a duplicate of the generic
6605*a9fa9459Szrj@samp{--entry} switch, in that it sets the program's starting address.
6606*a9fa9459SzrjBut it also sets the bottom bit of the address, so that it can be
6607*a9fa9459Szrjbranched to using a BX instruction, and the program will start
6608*a9fa9459Szrjexecuting in Thumb mode straight away.
6609*a9fa9459Szrj
6610*a9fa9459Szrj@cindex PE import table prefixing
6611*a9fa9459Szrj@kindex --use-nul-prefixed-import-tables
6612*a9fa9459SzrjThe @samp{--use-nul-prefixed-import-tables} switch is specifying, that
6613*a9fa9459Szrjthe import tables idata4 and idata5 have to be generated with a zero
6614*a9fa9459Szrjelement prefix for import libraries. This is the old style to generate
6615*a9fa9459Szrjimport tables. By default this option is turned off.
6616*a9fa9459Szrj
6617*a9fa9459Szrj@cindex BE8
6618*a9fa9459Szrj@kindex --be8
6619*a9fa9459SzrjThe @samp{--be8} switch instructs @command{ld} to generate BE8 format
6620*a9fa9459Szrjexecutables.  This option is only valid when linking big-endian
6621*a9fa9459Szrjobjects - ie ones which have been assembled with the @option{-EB}
6622*a9fa9459Szrjoption.  The resulting image will contain big-endian data and
6623*a9fa9459Szrjlittle-endian code.
6624*a9fa9459Szrj
6625*a9fa9459Szrj@cindex TARGET1
6626*a9fa9459Szrj@kindex --target1-rel
6627*a9fa9459Szrj@kindex --target1-abs
6628*a9fa9459SzrjThe @samp{R_ARM_TARGET1} relocation is typically used for entries in the
6629*a9fa9459Szrj@samp{.init_array} section.  It is interpreted as either @samp{R_ARM_REL32}
6630*a9fa9459Szrjor @samp{R_ARM_ABS32}, depending on the target.  The @samp{--target1-rel}
6631*a9fa9459Szrjand @samp{--target1-abs} switches override the default.
6632*a9fa9459Szrj
6633*a9fa9459Szrj@cindex TARGET2
6634*a9fa9459Szrj@kindex --target2=@var{type}
6635*a9fa9459SzrjThe @samp{--target2=type} switch overrides the default definition of the
6636*a9fa9459Szrj@samp{R_ARM_TARGET2} relocation.  Valid values for @samp{type}, their
6637*a9fa9459Szrjmeanings, and target defaults are as follows:
6638*a9fa9459Szrj@table @samp
6639*a9fa9459Szrj@item rel
6640*a9fa9459Szrj@samp{R_ARM_REL32} (arm*-*-elf, arm*-*-eabi)
6641*a9fa9459Szrj@item abs
6642*a9fa9459Szrj@samp{R_ARM_ABS32} (arm*-*-symbianelf)
6643*a9fa9459Szrj@item got-rel
6644*a9fa9459Szrj@samp{R_ARM_GOT_PREL} (arm*-*-linux, arm*-*-*bsd)
6645*a9fa9459Szrj@end table
6646*a9fa9459Szrj
6647*a9fa9459Szrj@cindex FIX_V4BX
6648*a9fa9459Szrj@kindex --fix-v4bx
6649*a9fa9459SzrjThe @samp{R_ARM_V4BX} relocation (defined by the ARM AAELF
6650*a9fa9459Szrjspecification) enables objects compiled for the ARMv4 architecture to be
6651*a9fa9459Szrjinterworking-safe when linked with other objects compiled for ARMv4t, but
6652*a9fa9459Szrjalso allows pure ARMv4 binaries to be built from the same ARMv4 objects.
6653*a9fa9459Szrj
6654*a9fa9459SzrjIn the latter case, the switch @option{--fix-v4bx} must be passed to the
6655*a9fa9459Szrjlinker, which causes v4t @code{BX rM} instructions to be rewritten as
6656*a9fa9459Szrj@code{MOV PC,rM}, since v4 processors do not have a @code{BX} instruction.
6657*a9fa9459Szrj
6658*a9fa9459SzrjIn the former case, the switch should not be used, and @samp{R_ARM_V4BX}
6659*a9fa9459Szrjrelocations are ignored.
6660*a9fa9459Szrj
6661*a9fa9459Szrj@cindex FIX_V4BX_INTERWORKING
6662*a9fa9459Szrj@kindex --fix-v4bx-interworking
6663*a9fa9459SzrjReplace @code{BX rM} instructions identified by @samp{R_ARM_V4BX}
6664*a9fa9459Szrjrelocations with a branch to the following veneer:
6665*a9fa9459Szrj
6666*a9fa9459Szrj@smallexample
6667*a9fa9459SzrjTST rM, #1
6668*a9fa9459SzrjMOVEQ PC, rM
6669*a9fa9459SzrjBX Rn
6670*a9fa9459Szrj@end smallexample
6671*a9fa9459Szrj
6672*a9fa9459SzrjThis allows generation of libraries/applications that work on ARMv4 cores
6673*a9fa9459Szrjand are still interworking safe.  Note that the above veneer clobbers the
6674*a9fa9459Szrjcondition flags, so may cause incorrect program behavior in rare cases.
6675*a9fa9459Szrj
6676*a9fa9459Szrj@cindex USE_BLX
6677*a9fa9459Szrj@kindex --use-blx
6678*a9fa9459SzrjThe @samp{--use-blx} switch enables the linker to use ARM/Thumb
6679*a9fa9459SzrjBLX instructions (available on ARMv5t and above) in various
6680*a9fa9459Szrjsituations. Currently it is used to perform calls via the PLT from Thumb
6681*a9fa9459Szrjcode using BLX rather than using BX and a mode-switching stub before
6682*a9fa9459Szrjeach PLT entry. This should lead to such calls executing slightly faster.
6683*a9fa9459Szrj
6684*a9fa9459SzrjThis option is enabled implicitly for SymbianOS, so there is no need to
6685*a9fa9459Szrjspecify it if you are using that target.
6686*a9fa9459Szrj
6687*a9fa9459Szrj@cindex VFP11_DENORM_FIX
6688*a9fa9459Szrj@kindex --vfp11-denorm-fix
6689*a9fa9459SzrjThe @samp{--vfp11-denorm-fix} switch enables a link-time workaround for a
6690*a9fa9459Szrjbug in certain VFP11 coprocessor hardware, which sometimes allows
6691*a9fa9459Szrjinstructions with denorm operands (which must be handled by support code)
6692*a9fa9459Szrjto have those operands overwritten by subsequent instructions before
6693*a9fa9459Szrjthe support code can read the intended values.
6694*a9fa9459Szrj
6695*a9fa9459SzrjThe bug may be avoided in scalar mode if you allow at least one
6696*a9fa9459Szrjintervening instruction between a VFP11 instruction which uses a register
6697*a9fa9459Szrjand another instruction which writes to the same register, or at least two
6698*a9fa9459Szrjintervening instructions if vector mode is in use. The bug only affects
6699*a9fa9459Szrjfull-compliance floating-point mode: you do not need this workaround if
6700*a9fa9459Szrjyou are using "runfast" mode. Please contact ARM for further details.
6701*a9fa9459Szrj
6702*a9fa9459SzrjIf you know you are using buggy VFP11 hardware, you can
6703*a9fa9459Szrjenable this workaround by specifying the linker option
6704*a9fa9459Szrj@samp{--vfp-denorm-fix=scalar} if you are using the VFP11 scalar
6705*a9fa9459Szrjmode only, or @samp{--vfp-denorm-fix=vector} if you are using
6706*a9fa9459Szrjvector mode (the latter also works for scalar code). The default is
6707*a9fa9459Szrj@samp{--vfp-denorm-fix=none}.
6708*a9fa9459Szrj
6709*a9fa9459SzrjIf the workaround is enabled, instructions are scanned for
6710*a9fa9459Szrjpotentially-troublesome sequences, and a veneer is created for each
6711*a9fa9459Szrjsuch sequence which may trigger the erratum. The veneer consists of the
6712*a9fa9459Szrjfirst instruction of the sequence and a branch back to the subsequent
6713*a9fa9459Szrjinstruction. The original instruction is then replaced with a branch to
6714*a9fa9459Szrjthe veneer. The extra cycles required to call and return from the veneer
6715*a9fa9459Szrjare sufficient to avoid the erratum in both the scalar and vector cases.
6716*a9fa9459Szrj
6717*a9fa9459Szrj@cindex ARM1176 erratum workaround
6718*a9fa9459Szrj@kindex --fix-arm1176
6719*a9fa9459Szrj@kindex --no-fix-arm1176
6720*a9fa9459SzrjThe @samp{--fix-arm1176} switch enables a link-time workaround for an erratum
6721*a9fa9459Szrjin certain ARM1176 processors.  The workaround is enabled by default if you
6722*a9fa9459Szrjare targeting ARM v6 (excluding ARM v6T2) or earlier.  It can be disabled
6723*a9fa9459Szrjunconditionally by specifying @samp{--no-fix-arm1176}.
6724*a9fa9459Szrj
6725*a9fa9459SzrjFurther information is available in the ``ARM1176JZ-S and ARM1176JZF-S
6726*a9fa9459SzrjProgrammer Advice Notice'' available on the ARM documentation website at:
6727*a9fa9459Szrjhttp://infocenter.arm.com/.
6728*a9fa9459Szrj
6729*a9fa9459Szrj@cindex STM32L4xx erratum workaround
6730*a9fa9459Szrj@kindex --fix-stm32l4xx-629360
6731*a9fa9459Szrj
6732*a9fa9459SzrjThe @samp{--fix-stm32l4xx-629360} switch enables a link-time
6733*a9fa9459Szrjworkaround for a bug in the bus matrix / memory controller for some of
6734*a9fa9459Szrjthe STM32 Cortex-M4 based products (STM32L4xx).  When accessing
6735*a9fa9459Szrjoff-chip memory via the affected bus for bus reads of 9 words or more,
6736*a9fa9459Szrjthe bus can generate corrupt data and/or abort.  These are only
6737*a9fa9459Szrjcore-initiated accesses (not DMA), and might affect any access:
6738*a9fa9459Szrjinteger loads such as LDM, POP and floating-point loads such as VLDM,
6739*a9fa9459SzrjVPOP.  Stores are not affected.
6740*a9fa9459Szrj
6741*a9fa9459SzrjThe bug can be avoided by splitting memory accesses into the
6742*a9fa9459Szrjnecessary chunks to keep bus reads below 8 words.
6743*a9fa9459Szrj
6744*a9fa9459SzrjThe workaround is not enabled by default, this is equivalent to use
6745*a9fa9459Szrj@samp{--fix-stm32l4xx-629360=none}.  If you know you are using buggy
6746*a9fa9459SzrjSTM32L4xx hardware, you can enable the workaround by specifying the
6747*a9fa9459Szrjlinker option @samp{--fix-stm32l4xx-629360}, or the equivalent
6748*a9fa9459Szrj@samp{--fix-stm32l4xx-629360=default}.
6749*a9fa9459Szrj
6750*a9fa9459SzrjIf the workaround is enabled, instructions are scanned for
6751*a9fa9459Szrjpotentially-troublesome sequences, and a veneer is created for each
6752*a9fa9459Szrjsuch sequence which may trigger the erratum.  The veneer consists in a
6753*a9fa9459Szrjreplacement sequence emulating the behaviour of the original one and a
6754*a9fa9459Szrjbranch back to the subsequent instruction.  The original instruction is
6755*a9fa9459Szrjthen replaced with a branch to the veneer.
6756*a9fa9459Szrj
6757*a9fa9459SzrjThe workaround does not always preserve the memory access order for
6758*a9fa9459Szrjthe LDMDB instruction, when the instruction loads the PC.
6759*a9fa9459Szrj
6760*a9fa9459SzrjThe workaround is not able to handle problematic instructions when
6761*a9fa9459Szrjthey are in the middle of an IT block, since a branch is not allowed
6762*a9fa9459Szrjthere.  In that case, the linker reports a warning and no replacement
6763*a9fa9459Szrjoccurs.
6764*a9fa9459Szrj
6765*a9fa9459SzrjThe workaround is not able to replace problematic instructions with a
6766*a9fa9459SzrjPC-relative branch instruction if the @samp{.text} section is too
6767*a9fa9459Szrjlarge.  In that case, when the branch that replaces the original code
6768*a9fa9459Szrjcannot be encoded, the linker reports a warning and no replacement
6769*a9fa9459Szrjoccurs.
6770*a9fa9459Szrj
6771*a9fa9459Szrj@cindex NO_ENUM_SIZE_WARNING
6772*a9fa9459Szrj@kindex --no-enum-size-warning
6773*a9fa9459SzrjThe @option{--no-enum-size-warning} switch prevents the linker from
6774*a9fa9459Szrjwarning when linking object files that specify incompatible EABI
6775*a9fa9459Szrjenumeration size attributes.  For example, with this switch enabled,
6776*a9fa9459Szrjlinking of an object file using 32-bit enumeration values with another
6777*a9fa9459Szrjusing enumeration values fitted into the smallest possible space will
6778*a9fa9459Szrjnot be diagnosed.
6779*a9fa9459Szrj
6780*a9fa9459Szrj@cindex NO_WCHAR_SIZE_WARNING
6781*a9fa9459Szrj@kindex --no-wchar-size-warning
6782*a9fa9459SzrjThe @option{--no-wchar-size-warning} switch prevents the linker from
6783*a9fa9459Szrjwarning when linking object files that specify incompatible EABI
6784*a9fa9459Szrj@code{wchar_t} size attributes.  For example, with this switch enabled,
6785*a9fa9459Szrjlinking of an object file using 32-bit @code{wchar_t} values with another
6786*a9fa9459Szrjusing 16-bit @code{wchar_t} values will not be diagnosed.
6787*a9fa9459Szrj
6788*a9fa9459Szrj@cindex PIC_VENEER
6789*a9fa9459Szrj@kindex --pic-veneer
6790*a9fa9459SzrjThe @samp{--pic-veneer} switch makes the linker use PIC sequences for
6791*a9fa9459SzrjARM/Thumb interworking veneers, even if the rest of the binary
6792*a9fa9459Szrjis not PIC.  This avoids problems on uClinux targets where
6793*a9fa9459Szrj@samp{--emit-relocs} is used to generate relocatable binaries.
6794*a9fa9459Szrj
6795*a9fa9459Szrj@cindex STUB_GROUP_SIZE
6796*a9fa9459Szrj@kindex --stub-group-size=@var{N}
6797*a9fa9459SzrjThe linker will automatically generate and insert small sequences of
6798*a9fa9459Szrjcode into a linked ARM ELF executable whenever an attempt is made to
6799*a9fa9459Szrjperform a function call to a symbol that is too far away.  The
6800*a9fa9459Szrjplacement of these sequences of instructions - called stubs - is
6801*a9fa9459Szrjcontrolled by the command line option @option{--stub-group-size=N}.
6802*a9fa9459SzrjThe placement is important because a poor choice can create a need for
6803*a9fa9459Szrjduplicate stubs, increasing the code size.  The linker will try to
6804*a9fa9459Szrjgroup stubs together in order to reduce interruptions to the flow of
6805*a9fa9459Szrjcode, but it needs guidance as to how big these groups should be and
6806*a9fa9459Szrjwhere they should be placed.
6807*a9fa9459Szrj
6808*a9fa9459SzrjThe value of @samp{N}, the parameter to the
6809*a9fa9459Szrj@option{--stub-group-size=} option controls where the stub groups are
6810*a9fa9459Szrjplaced.  If it is negative then all stubs are placed after the first
6811*a9fa9459Szrjbranch that needs them.  If it is positive then the stubs can be
6812*a9fa9459Szrjplaced either before or after the branches that need them.  If the
6813*a9fa9459Szrjvalue of @samp{N} is 1 (either +1 or -1) then the linker will choose
6814*a9fa9459Szrjexactly where to place groups of stubs, using its built in heuristics.
6815*a9fa9459SzrjA value of @samp{N} greater than 1 (or smaller than -1) tells the
6816*a9fa9459Szrjlinker that a single group of stubs can service at most @samp{N} bytes
6817*a9fa9459Szrjfrom the input sections.
6818*a9fa9459Szrj
6819*a9fa9459SzrjThe default, if @option{--stub-group-size=} is not specified, is
6820*a9fa9459Szrj@samp{N = +1}.
6821*a9fa9459Szrj
6822*a9fa9459SzrjFarcalls stubs insertion is fully supported for the ARM-EABI target
6823*a9fa9459Szrjonly, because it relies on object files properties not present
6824*a9fa9459Szrjotherwise.
6825*a9fa9459Szrj
6826*a9fa9459Szrj@cindex Cortex-A8 erratum workaround
6827*a9fa9459Szrj@kindex --fix-cortex-a8
6828*a9fa9459Szrj@kindex --no-fix-cortex-a8
6829*a9fa9459SzrjThe @samp{--fix-cortex-a8} switch enables a link-time workaround for an erratum in certain Cortex-A8 processors.  The workaround is enabled by default if you are targeting the ARM v7-A architecture profile.  It can be enabled otherwise by specifying @samp{--fix-cortex-a8}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a8}.
6830*a9fa9459Szrj
6831*a9fa9459SzrjThe erratum only affects Thumb-2 code.  Please contact ARM for further details.
6832*a9fa9459Szrj
6833*a9fa9459Szrj@cindex Cortex-A53 erratum 835769 workaround
6834*a9fa9459Szrj@kindex --fix-cortex-a53-835769
6835*a9fa9459Szrj@kindex --no-fix-cortex-a53-835769
6836*a9fa9459SzrjThe @samp{--fix-cortex-a53-835769} switch enables a link-time workaround for erratum 835769 present on certain early revisions of Cortex-A53 processors.  The workaround is disabled by default.  It can be enabled by specifying @samp{--fix-cortex-a53-835769}, or disabled unconditionally by specifying @samp{--no-fix-cortex-a53-835769}.
6837*a9fa9459Szrj
6838*a9fa9459SzrjPlease contact ARM for further details.
6839*a9fa9459Szrj
6840*a9fa9459Szrj@kindex --merge-exidx-entries
6841*a9fa9459Szrj@kindex --no-merge-exidx-entries
6842*a9fa9459Szrj@cindex Merging exidx entries
6843*a9fa9459SzrjThe @samp{--no-merge-exidx-entries} switch disables the merging of adjacent exidx entries in debuginfo.
6844*a9fa9459Szrj
6845*a9fa9459Szrj@kindex --long-plt
6846*a9fa9459Szrj@cindex 32-bit PLT entries
6847*a9fa9459SzrjThe @samp{--long-plt} option enables the use of 16 byte PLT entries
6848*a9fa9459Szrjwhich support up to 4Gb of code.  The default is to use 12 byte PLT
6849*a9fa9459Szrjentries which only support 512Mb of code.
6850*a9fa9459Szrj
6851*a9fa9459Szrj@kindex --no-apply-dynamic-relocs
6852*a9fa9459Szrj@cindex AArch64 rela addend
6853*a9fa9459SzrjThe @samp{--no-apply-dynamic-relocs} option makes AArch64 linker do not apply
6854*a9fa9459Szrjlink-time values for dynamic relocations.
6855*a9fa9459Szrj
6856*a9fa9459Szrj@ifclear GENERIC
6857*a9fa9459Szrj@lowersections
6858*a9fa9459Szrj@end ifclear
6859*a9fa9459Szrj@end ifset
6860*a9fa9459Szrj
6861*a9fa9459Szrj@ifset HPPA
6862*a9fa9459Szrj@ifclear GENERIC
6863*a9fa9459Szrj@raisesections
6864*a9fa9459Szrj@end ifclear
6865*a9fa9459Szrj
6866*a9fa9459Szrj@node HPPA ELF32
6867*a9fa9459Szrj@section @command{ld} and HPPA 32-bit ELF Support
6868*a9fa9459Szrj@cindex HPPA multiple sub-space stubs
6869*a9fa9459Szrj@kindex --multi-subspace
6870*a9fa9459SzrjWhen generating a shared library, @command{ld} will by default generate
6871*a9fa9459Szrjimport stubs suitable for use with a single sub-space application.
6872*a9fa9459SzrjThe @samp{--multi-subspace} switch causes @command{ld} to generate export
6873*a9fa9459Szrjstubs, and different (larger) import stubs suitable for use with
6874*a9fa9459Szrjmultiple sub-spaces.
6875*a9fa9459Szrj
6876*a9fa9459Szrj@cindex HPPA stub grouping
6877*a9fa9459Szrj@kindex --stub-group-size=@var{N}
6878*a9fa9459SzrjLong branch stubs and import/export stubs are placed by @command{ld} in
6879*a9fa9459Szrjstub sections located between groups of input sections.
6880*a9fa9459Szrj@samp{--stub-group-size} specifies the maximum size of a group of input
6881*a9fa9459Szrjsections handled by one stub section.  Since branch offsets are signed,
6882*a9fa9459Szrja stub section may serve two groups of input sections, one group before
6883*a9fa9459Szrjthe stub section, and one group after it.  However, when using
6884*a9fa9459Szrjconditional branches that require stubs, it may be better (for branch
6885*a9fa9459Szrjprediction) that stub sections only serve one group of input sections.
6886*a9fa9459SzrjA negative value for @samp{N} chooses this scheme, ensuring that
6887*a9fa9459Szrjbranches to stubs always use a negative offset.  Two special values of
6888*a9fa9459Szrj@samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
6889*a9fa9459Szrj@command{ld} to automatically size input section groups for the branch types
6890*a9fa9459Szrjdetected, with the same behaviour regarding stub placement as other
6891*a9fa9459Szrjpositive or negative values of @samp{N} respectively.
6892*a9fa9459Szrj
6893*a9fa9459SzrjNote that @samp{--stub-group-size} does not split input sections.  A
6894*a9fa9459Szrjsingle input section larger than the group size specified will of course
6895*a9fa9459Szrjcreate a larger group (of one section).  If input sections are too
6896*a9fa9459Szrjlarge, it may not be possible for a branch to reach its stub.
6897*a9fa9459Szrj
6898*a9fa9459Szrj@ifclear GENERIC
6899*a9fa9459Szrj@lowersections
6900*a9fa9459Szrj@end ifclear
6901*a9fa9459Szrj@end ifset
6902*a9fa9459Szrj
6903*a9fa9459Szrj@ifset M68K
6904*a9fa9459Szrj@ifclear GENERIC
6905*a9fa9459Szrj@raisesections
6906*a9fa9459Szrj@end ifclear
6907*a9fa9459Szrj
6908*a9fa9459Szrj@node M68K
6909*a9fa9459Szrj@section @command{ld} and the Motorola 68K family
6910*a9fa9459Szrj
6911*a9fa9459Szrj@cindex Motorola 68K GOT generation
6912*a9fa9459Szrj@kindex --got=@var{type}
6913*a9fa9459SzrjThe @samp{--got=@var{type}} option lets you choose the GOT generation scheme.
6914*a9fa9459SzrjThe choices are @samp{single}, @samp{negative}, @samp{multigot} and
6915*a9fa9459Szrj@samp{target}.  When @samp{target} is selected the linker chooses
6916*a9fa9459Szrjthe default GOT generation scheme for the current target.
6917*a9fa9459Szrj@samp{single} tells the linker to generate a single GOT with
6918*a9fa9459Szrjentries only at non-negative offsets.
6919*a9fa9459Szrj@samp{negative} instructs the linker to generate a single GOT with
6920*a9fa9459Szrjentries at both negative and positive offsets.  Not all environments
6921*a9fa9459Szrjsupport such GOTs.
6922*a9fa9459Szrj@samp{multigot} allows the linker to generate several GOTs in the
6923*a9fa9459Szrjoutput file.  All GOT references from a single input object
6924*a9fa9459Szrjfile access the same GOT, but references from different input object
6925*a9fa9459Szrjfiles might access different GOTs.  Not all environments support such GOTs.
6926*a9fa9459Szrj
6927*a9fa9459Szrj@ifclear GENERIC
6928*a9fa9459Szrj@lowersections
6929*a9fa9459Szrj@end ifclear
6930*a9fa9459Szrj@end ifset
6931*a9fa9459Szrj
6932*a9fa9459Szrj@ifset MIPS
6933*a9fa9459Szrj@ifclear GENERIC
6934*a9fa9459Szrj@raisesections
6935*a9fa9459Szrj@end ifclear
6936*a9fa9459Szrj
6937*a9fa9459Szrj@node MIPS
6938*a9fa9459Szrj@section @command{ld} and the MIPS family
6939*a9fa9459Szrj
6940*a9fa9459Szrj@cindex MIPS microMIPS instruction choice selection
6941*a9fa9459Szrj@kindex --insn32
6942*a9fa9459Szrj@kindex --no-insn32
6943*a9fa9459SzrjThe @samp{--insn32} and @samp{--no-insn32} options control the choice of
6944*a9fa9459SzrjmicroMIPS instructions used in code generated by the linker, such as that
6945*a9fa9459Szrjin the PLT or lazy binding stubs, or in relaxation.  If @samp{--insn32} is
6946*a9fa9459Szrjused, then the linker only uses 32-bit instruction encodings.  By default
6947*a9fa9459Szrjor if @samp{--no-insn32} is used, all instruction encodings are used,
6948*a9fa9459Szrjincluding 16-bit ones where possible.
6949*a9fa9459Szrj
6950*a9fa9459Szrj@ifclear GENERIC
6951*a9fa9459Szrj@lowersections
6952*a9fa9459Szrj@end ifclear
6953*a9fa9459Szrj@end ifset
6954*a9fa9459Szrj
6955*a9fa9459Szrj@ifset MMIX
6956*a9fa9459Szrj@ifclear GENERIC
6957*a9fa9459Szrj@raisesections
6958*a9fa9459Szrj@end ifclear
6959*a9fa9459Szrj
6960*a9fa9459Szrj@node MMIX
6961*a9fa9459Szrj@section @code{ld} and MMIX
6962*a9fa9459SzrjFor MMIX, there is a choice of generating @code{ELF} object files or
6963*a9fa9459Szrj@code{mmo} object files when linking.  The simulator @code{mmix}
6964*a9fa9459Szrjunderstands the @code{mmo} format.  The binutils @code{objcopy} utility
6965*a9fa9459Szrjcan translate between the two formats.
6966*a9fa9459Szrj
6967*a9fa9459SzrjThere is one special section, the @samp{.MMIX.reg_contents} section.
6968*a9fa9459SzrjContents in this section is assumed to correspond to that of global
6969*a9fa9459Szrjregisters, and symbols referring to it are translated to special symbols,
6970*a9fa9459Szrjequal to registers.  In a final link, the start address of the
6971*a9fa9459Szrj@samp{.MMIX.reg_contents} section corresponds to the first allocated
6972*a9fa9459Szrjglobal register multiplied by 8.  Register @code{$255} is not included in
6973*a9fa9459Szrjthis section; it is always set to the program entry, which is at the
6974*a9fa9459Szrjsymbol @code{Main} for @code{mmo} files.
6975*a9fa9459Szrj
6976*a9fa9459SzrjGlobal symbols with the prefix @code{__.MMIX.start.}, for example
6977*a9fa9459Szrj@code{__.MMIX.start..text} and @code{__.MMIX.start..data} are special.
6978*a9fa9459SzrjThe default linker script uses these to set the default start address
6979*a9fa9459Szrjof a section.
6980*a9fa9459Szrj
6981*a9fa9459SzrjInitial and trailing multiples of zero-valued 32-bit words in a section,
6982*a9fa9459Szrjare left out from an mmo file.
6983*a9fa9459Szrj
6984*a9fa9459Szrj@ifclear GENERIC
6985*a9fa9459Szrj@lowersections
6986*a9fa9459Szrj@end ifclear
6987*a9fa9459Szrj@end ifset
6988*a9fa9459Szrj
6989*a9fa9459Szrj@ifset MSP430
6990*a9fa9459Szrj@ifclear GENERIC
6991*a9fa9459Szrj@raisesections
6992*a9fa9459Szrj@end ifclear
6993*a9fa9459Szrj
6994*a9fa9459Szrj@node  MSP430
6995*a9fa9459Szrj@section @code{ld} and MSP430
6996*a9fa9459SzrjFor the MSP430 it is possible to select the MPU architecture.  The flag @samp{-m [mpu type]}
6997*a9fa9459Szrjwill select an appropriate linker script for selected MPU type.  (To get a list of known MPUs
6998*a9fa9459Szrjjust pass @samp{-m help} option to the linker).
6999*a9fa9459Szrj
7000*a9fa9459Szrj@cindex MSP430 extra sections
7001*a9fa9459SzrjThe linker will recognize some extra sections which are MSP430 specific:
7002*a9fa9459Szrj
7003*a9fa9459Szrj@table @code
7004*a9fa9459Szrj@item @samp{.vectors}
7005*a9fa9459SzrjDefines a portion of ROM where interrupt vectors located.
7006*a9fa9459Szrj
7007*a9fa9459Szrj@item @samp{.bootloader}
7008*a9fa9459SzrjDefines the bootloader portion of the ROM (if applicable).  Any code
7009*a9fa9459Szrjin this section will be uploaded to the MPU.
7010*a9fa9459Szrj
7011*a9fa9459Szrj@item @samp{.infomem}
7012*a9fa9459SzrjDefines an information memory section (if applicable).  Any code in
7013*a9fa9459Szrjthis section will be uploaded to the MPU.
7014*a9fa9459Szrj
7015*a9fa9459Szrj@item @samp{.infomemnobits}
7016*a9fa9459SzrjThis is the same as the @samp{.infomem} section except that any code
7017*a9fa9459Szrjin this section will not be uploaded to the MPU.
7018*a9fa9459Szrj
7019*a9fa9459Szrj@item @samp{.noinit}
7020*a9fa9459SzrjDenotes a portion of RAM located above @samp{.bss} section.
7021*a9fa9459Szrj
7022*a9fa9459SzrjThe last two sections are used by gcc.
7023*a9fa9459Szrj@end table
7024*a9fa9459Szrj
7025*a9fa9459Szrj@ifclear GENERIC
7026*a9fa9459Szrj@lowersections
7027*a9fa9459Szrj@end ifclear
7028*a9fa9459Szrj@end ifset
7029*a9fa9459Szrj
7030*a9fa9459Szrj@ifset NDS32
7031*a9fa9459Szrj@ifclear GENERIC
7032*a9fa9459Szrj@raisesections
7033*a9fa9459Szrj@end ifclear
7034*a9fa9459Szrj
7035*a9fa9459Szrj@node NDS32
7036*a9fa9459Szrj@section @code{ld} and NDS32
7037*a9fa9459Szrj@kindex relaxing on NDS32
7038*a9fa9459SzrjFor NDS32, there are some options to select relaxation behavior.  The linker
7039*a9fa9459Szrjrelaxes objects according to these options.
7040*a9fa9459Szrj
7041*a9fa9459Szrj@table @code
7042*a9fa9459Szrj@item @samp{--m[no-]fp-as-gp}
7043*a9fa9459SzrjDisable/enable fp-as-gp relaxation.
7044*a9fa9459Szrj
7045*a9fa9459Szrj@item @samp{--mexport-symbols=FILE}
7046*a9fa9459SzrjExporting symbols and their address into FILE as linker script.
7047*a9fa9459Szrj
7048*a9fa9459Szrj@item @samp{--m[no-]ex9}
7049*a9fa9459SzrjDisable/enable link-time EX9 relaxation.
7050*a9fa9459Szrj
7051*a9fa9459Szrj@item @samp{--mexport-ex9=FILE}
7052*a9fa9459SzrjExport the EX9 table after linking.
7053*a9fa9459Szrj
7054*a9fa9459Szrj@item @samp{--mimport-ex9=FILE}
7055*a9fa9459SzrjImport the Ex9 table for EX9 relaxation.
7056*a9fa9459Szrj
7057*a9fa9459Szrj@item @samp{--mupdate-ex9}
7058*a9fa9459SzrjUpdate the existing EX9 table.
7059*a9fa9459Szrj
7060*a9fa9459Szrj@item @samp{--mex9-limit=NUM}
7061*a9fa9459SzrjMaximum number of entries in the ex9 table.
7062*a9fa9459Szrj
7063*a9fa9459Szrj@item @samp{--mex9-loop-aware}
7064*a9fa9459SzrjAvoid generating the EX9 instruction inside the loop.
7065*a9fa9459Szrj
7066*a9fa9459Szrj@item @samp{--m[no-]ifc}
7067*a9fa9459SzrjDisable/enable the link-time IFC optimization.
7068*a9fa9459Szrj
7069*a9fa9459Szrj@item @samp{--mifc-loop-aware}
7070*a9fa9459SzrjAvoid generating the IFC instruction inside the loop.
7071*a9fa9459Szrj@end table
7072*a9fa9459Szrj
7073*a9fa9459Szrj@ifclear GENERIC
7074*a9fa9459Szrj@lowersections
7075*a9fa9459Szrj@end ifclear
7076*a9fa9459Szrj@end ifset
7077*a9fa9459Szrj
7078*a9fa9459Szrj@ifset NIOSII
7079*a9fa9459Szrj@ifclear GENERIC
7080*a9fa9459Szrj@raisesections
7081*a9fa9459Szrj@end ifclear
7082*a9fa9459Szrj
7083*a9fa9459Szrj@node Nios II
7084*a9fa9459Szrj@section @command{ld} and the Altera Nios II
7085*a9fa9459Szrj@cindex Nios II call relaxation
7086*a9fa9459Szrj@kindex --relax on Nios II
7087*a9fa9459Szrj
7088*a9fa9459SzrjCall and immediate jump instructions on Nios II processors are limited to
7089*a9fa9459Szrjtransferring control to addresses in the same 256MB memory segment,
7090*a9fa9459Szrjwhich may result in @command{ld} giving
7091*a9fa9459Szrj@samp{relocation truncated to fit} errors with very large programs.
7092*a9fa9459SzrjThe command-line option @option{--relax} enables the generation of
7093*a9fa9459Szrjtrampolines that can access the entire 32-bit address space for calls
7094*a9fa9459Szrjoutside the normal @code{call} and @code{jmpi} address range.  These
7095*a9fa9459Szrjtrampolines are inserted at section boundaries, so may not themselves
7096*a9fa9459Szrjbe reachable if an input section and its associated call trampolines are
7097*a9fa9459Szrjlarger than 256MB.
7098*a9fa9459Szrj
7099*a9fa9459SzrjThe @option{--relax} option is enabled by default unless @option{-r}
7100*a9fa9459Szrjis also specified.  You can disable trampoline generation by using the
7101*a9fa9459Szrj@option{--no-relax} linker option.  You can also disable this optimization
7102*a9fa9459Szrjlocally by using the @samp{set .noat} directive in assembly-language
7103*a9fa9459Szrjsource files, as the linker-inserted trampolines use the @code{at}
7104*a9fa9459Szrjregister as a temporary.
7105*a9fa9459Szrj
7106*a9fa9459SzrjNote that the linker @option{--relax} option is independent of assembler
7107*a9fa9459Szrjrelaxation options, and that using the GNU assembler's @option{-relax-all}
7108*a9fa9459Szrjoption interferes with the linker's more selective call instruction relaxation.
7109*a9fa9459Szrj
7110*a9fa9459Szrj@ifclear GENERIC
7111*a9fa9459Szrj@lowersections
7112*a9fa9459Szrj@end ifclear
7113*a9fa9459Szrj@end ifset
7114*a9fa9459Szrj
7115*a9fa9459Szrj@ifset POWERPC
7116*a9fa9459Szrj@ifclear GENERIC
7117*a9fa9459Szrj@raisesections
7118*a9fa9459Szrj@end ifclear
7119*a9fa9459Szrj
7120*a9fa9459Szrj@node PowerPC ELF32
7121*a9fa9459Szrj@section @command{ld} and PowerPC 32-bit ELF Support
7122*a9fa9459Szrj@cindex PowerPC long branches
7123*a9fa9459Szrj@kindex --relax on PowerPC
7124*a9fa9459SzrjBranches on PowerPC processors are limited to a signed 26-bit
7125*a9fa9459Szrjdisplacement, which may result in @command{ld} giving
7126*a9fa9459Szrj@samp{relocation truncated to fit} errors with very large programs.
7127*a9fa9459Szrj@samp{--relax} enables the generation of trampolines that can access
7128*a9fa9459Szrjthe entire 32-bit address space.  These trampolines are inserted at
7129*a9fa9459Szrjsection boundaries, so may not themselves be reachable if an input
7130*a9fa9459Szrjsection exceeds 33M in size.  You may combine @samp{-r} and
7131*a9fa9459Szrj@samp{--relax} to add trampolines in a partial link.  In that case
7132*a9fa9459Szrjboth branches to undefined symbols and inter-section branches are also
7133*a9fa9459Szrjconsidered potentially out of range, and trampolines inserted.
7134*a9fa9459Szrj
7135*a9fa9459Szrj@cindex PowerPC ELF32 options
7136*a9fa9459Szrj@table @option
7137*a9fa9459Szrj@cindex PowerPC PLT
7138*a9fa9459Szrj@kindex --bss-plt
7139*a9fa9459Szrj@item --bss-plt
7140*a9fa9459SzrjCurrent PowerPC GCC accepts a @samp{-msecure-plt} option that
7141*a9fa9459Szrjgenerates code capable of using a newer PLT and GOT layout that has
7142*a9fa9459Szrjthe security advantage of no executable section ever needing to be
7143*a9fa9459Szrjwritable and no writable section ever being executable.  PowerPC
7144*a9fa9459Szrj@command{ld} will generate this layout, including stubs to access the
7145*a9fa9459SzrjPLT, if all input files (including startup and static libraries) were
7146*a9fa9459Szrjcompiled with @samp{-msecure-plt}.  @samp{--bss-plt} forces the old
7147*a9fa9459SzrjBSS PLT (and GOT layout) which can give slightly better performance.
7148*a9fa9459Szrj
7149*a9fa9459Szrj@kindex --secure-plt
7150*a9fa9459Szrj@item --secure-plt
7151*a9fa9459Szrj@command{ld} will use the new PLT and GOT layout if it is linking new
7152*a9fa9459Szrj@samp{-fpic} or @samp{-fPIC} code, but does not do so automatically
7153*a9fa9459Szrjwhen linking non-PIC code.  This option requests the new PLT and GOT
7154*a9fa9459Szrjlayout.  A warning will be given if some object file requires the old
7155*a9fa9459Szrjstyle BSS PLT.
7156*a9fa9459Szrj
7157*a9fa9459Szrj@cindex PowerPC GOT
7158*a9fa9459Szrj@kindex --sdata-got
7159*a9fa9459Szrj@item --sdata-got
7160*a9fa9459SzrjThe new secure PLT and GOT are placed differently relative to other
7161*a9fa9459Szrjsections compared to older BSS PLT and GOT placement.  The location of
7162*a9fa9459Szrj@code{.plt} must change because the new secure PLT is an initialized
7163*a9fa9459Szrjsection while the old PLT is uninitialized.  The reason for the
7164*a9fa9459Szrj@code{.got} change is more subtle:  The new placement allows
7165*a9fa9459Szrj@code{.got} to be read-only in applications linked with
7166*a9fa9459Szrj@samp{-z relro -z now}.  However, this placement means that
7167*a9fa9459Szrj@code{.sdata} cannot always be used in shared libraries, because the
7168*a9fa9459SzrjPowerPC ABI accesses @code{.sdata} in shared libraries from the GOT
7169*a9fa9459Szrjpointer.  @samp{--sdata-got} forces the old GOT placement.  PowerPC
7170*a9fa9459SzrjGCC doesn't use @code{.sdata} in shared libraries, so this option is
7171*a9fa9459Szrjreally only useful for other compilers that may do so.
7172*a9fa9459Szrj
7173*a9fa9459Szrj@cindex PowerPC stub symbols
7174*a9fa9459Szrj@kindex --emit-stub-syms
7175*a9fa9459Szrj@item --emit-stub-syms
7176*a9fa9459SzrjThis option causes @command{ld} to label linker stubs with a local
7177*a9fa9459Szrjsymbol that encodes the stub type and destination.
7178*a9fa9459Szrj
7179*a9fa9459Szrj@cindex PowerPC TLS optimization
7180*a9fa9459Szrj@kindex --no-tls-optimize
7181*a9fa9459Szrj@item --no-tls-optimize
7182*a9fa9459SzrjPowerPC @command{ld} normally performs some optimization of code
7183*a9fa9459Szrjsequences used to access Thread-Local Storage.  Use this option to
7184*a9fa9459Szrjdisable the optimization.
7185*a9fa9459Szrj@end table
7186*a9fa9459Szrj
7187*a9fa9459Szrj@ifclear GENERIC
7188*a9fa9459Szrj@lowersections
7189*a9fa9459Szrj@end ifclear
7190*a9fa9459Szrj@end ifset
7191*a9fa9459Szrj
7192*a9fa9459Szrj@ifset POWERPC64
7193*a9fa9459Szrj@ifclear GENERIC
7194*a9fa9459Szrj@raisesections
7195*a9fa9459Szrj@end ifclear
7196*a9fa9459Szrj
7197*a9fa9459Szrj@node PowerPC64 ELF64
7198*a9fa9459Szrj@section @command{ld} and PowerPC64 64-bit ELF Support
7199*a9fa9459Szrj
7200*a9fa9459Szrj@cindex PowerPC64 ELF64 options
7201*a9fa9459Szrj@table @option
7202*a9fa9459Szrj@cindex PowerPC64 stub grouping
7203*a9fa9459Szrj@kindex --stub-group-size
7204*a9fa9459Szrj@item --stub-group-size
7205*a9fa9459SzrjLong branch stubs, PLT call stubs  and TOC adjusting stubs are placed
7206*a9fa9459Szrjby @command{ld} in stub sections located between groups of input sections.
7207*a9fa9459Szrj@samp{--stub-group-size} specifies the maximum size of a group of input
7208*a9fa9459Szrjsections handled by one stub section.  Since branch offsets are signed,
7209*a9fa9459Szrja stub section may serve two groups of input sections, one group before
7210*a9fa9459Szrjthe stub section, and one group after it.  However, when using
7211*a9fa9459Szrjconditional branches that require stubs, it may be better (for branch
7212*a9fa9459Szrjprediction) that stub sections only serve one group of input sections.
7213*a9fa9459SzrjA negative value for @samp{N} chooses this scheme, ensuring that
7214*a9fa9459Szrjbranches to stubs always use a negative offset.  Two special values of
7215*a9fa9459Szrj@samp{N} are recognized, @samp{1} and @samp{-1}.  These both instruct
7216*a9fa9459Szrj@command{ld} to automatically size input section groups for the branch types
7217*a9fa9459Szrjdetected, with the same behaviour regarding stub placement as other
7218*a9fa9459Szrjpositive or negative values of @samp{N} respectively.
7219*a9fa9459Szrj
7220*a9fa9459SzrjNote that @samp{--stub-group-size} does not split input sections.  A
7221*a9fa9459Szrjsingle input section larger than the group size specified will of course
7222*a9fa9459Szrjcreate a larger group (of one section).  If input sections are too
7223*a9fa9459Szrjlarge, it may not be possible for a branch to reach its stub.
7224*a9fa9459Szrj
7225*a9fa9459Szrj@cindex PowerPC64 stub symbols
7226*a9fa9459Szrj@kindex --emit-stub-syms
7227*a9fa9459Szrj@item --emit-stub-syms
7228*a9fa9459SzrjThis option causes @command{ld} to label linker stubs with a local
7229*a9fa9459Szrjsymbol that encodes the stub type and destination.
7230*a9fa9459Szrj
7231*a9fa9459Szrj@cindex PowerPC64 dot symbols
7232*a9fa9459Szrj@kindex --dotsyms
7233*a9fa9459Szrj@kindex --no-dotsyms
7234*a9fa9459Szrj@item --dotsyms
7235*a9fa9459Szrj@itemx --no-dotsyms
7236*a9fa9459SzrjThese two options control how @command{ld} interprets version patterns
7237*a9fa9459Szrjin a version script.  Older PowerPC64 compilers emitted both a
7238*a9fa9459Szrjfunction descriptor symbol with the same name as the function, and a
7239*a9fa9459Szrjcode entry symbol with the name prefixed by a dot (@samp{.}).  To
7240*a9fa9459Szrjproperly version a function @samp{foo}, the version script thus needs
7241*a9fa9459Szrjto control both @samp{foo} and @samp{.foo}.  The option
7242*a9fa9459Szrj@samp{--dotsyms}, on by default, automatically adds the required
7243*a9fa9459Szrjdot-prefixed patterns.  Use @samp{--no-dotsyms} to disable this
7244*a9fa9459Szrjfeature.
7245*a9fa9459Szrj
7246*a9fa9459Szrj@cindex PowerPC64 register save/restore functions
7247*a9fa9459Szrj@kindex --save-restore-funcs
7248*a9fa9459Szrj@kindex --no-save-restore-funcs
7249*a9fa9459Szrj@item --save-restore-funcs
7250*a9fa9459Szrj@itemx --no-save-restore-funcs
7251*a9fa9459SzrjThese two options control whether PowerPC64 @command{ld} automatically
7252*a9fa9459Szrjprovides out-of-line register save and restore functions used by
7253*a9fa9459Szrj@samp{-Os} code.  The default is to provide any such referenced
7254*a9fa9459Szrjfunction for a normal final link, and to not do so for a relocatable
7255*a9fa9459Szrjlink.
7256*a9fa9459Szrj
7257*a9fa9459Szrj@cindex PowerPC64 TLS optimization
7258*a9fa9459Szrj@kindex --no-tls-optimize
7259*a9fa9459Szrj@item --no-tls-optimize
7260*a9fa9459SzrjPowerPC64 @command{ld} normally performs some optimization of code
7261*a9fa9459Szrjsequences used to access Thread-Local Storage.  Use this option to
7262*a9fa9459Szrjdisable the optimization.
7263*a9fa9459Szrj
7264*a9fa9459Szrj@cindex PowerPC64 __tls_get_addr optimization
7265*a9fa9459Szrj@kindex --tls-get-addr-optimize
7266*a9fa9459Szrj@kindex --no-tls-get-addr-optimize
7267*a9fa9459Szrj@item --tls-get-addr-optimize
7268*a9fa9459Szrj@itemx --no-tls-get-addr-optimize
7269*a9fa9459SzrjThese options control whether PowerPC64 @command{ld} uses a special
7270*a9fa9459Szrjstub to call __tls_get_addr.  PowerPC64 glibc 2.22 and later support
7271*a9fa9459Szrjan optimization that allows the second and subsequent calls to
7272*a9fa9459Szrj@code{__tls_get_addr} for a given symbol to be resolved by the special
7273*a9fa9459Szrjstub without calling in to glibc.  By default the linker enables this
7274*a9fa9459Szrjoption when glibc advertises the availability of __tls_get_addr_opt.
7275*a9fa9459SzrjForcing this option on when using an older glibc won't do much besides
7276*a9fa9459Szrjslow down your applications, but may be useful if linking an
7277*a9fa9459Szrjapplication against an older glibc with the expectation that it will
7278*a9fa9459Szrjnormally be used on systems having a newer glibc.
7279*a9fa9459Szrj
7280*a9fa9459Szrj@cindex PowerPC64 OPD optimization
7281*a9fa9459Szrj@kindex --no-opd-optimize
7282*a9fa9459Szrj@item --no-opd-optimize
7283*a9fa9459SzrjPowerPC64 @command{ld} normally removes @code{.opd} section entries
7284*a9fa9459Szrjcorresponding to deleted link-once functions, or functions removed by
7285*a9fa9459Szrjthe action of @samp{--gc-sections} or linker script @code{/DISCARD/}.
7286*a9fa9459SzrjUse this option to disable @code{.opd} optimization.
7287*a9fa9459Szrj
7288*a9fa9459Szrj@cindex PowerPC64 OPD spacing
7289*a9fa9459Szrj@kindex --non-overlapping-opd
7290*a9fa9459Szrj@item --non-overlapping-opd
7291*a9fa9459SzrjSome PowerPC64 compilers have an option to generate compressed
7292*a9fa9459Szrj@code{.opd} entries spaced 16 bytes apart, overlapping the third word,
7293*a9fa9459Szrjthe static chain pointer (unused in C) with the first word of the next
7294*a9fa9459Szrjentry.  This option expands such entries to the full 24 bytes.
7295*a9fa9459Szrj
7296*a9fa9459Szrj@cindex PowerPC64 TOC optimization
7297*a9fa9459Szrj@kindex --no-toc-optimize
7298*a9fa9459Szrj@item --no-toc-optimize
7299*a9fa9459SzrjPowerPC64 @command{ld} normally removes unused @code{.toc} section
7300*a9fa9459Szrjentries.  Such entries are detected by examining relocations that
7301*a9fa9459Szrjreference the TOC in code sections.  A reloc in a deleted code section
7302*a9fa9459Szrjmarks a TOC word as unneeded, while a reloc in a kept code section
7303*a9fa9459Szrjmarks a TOC word as needed.  Since the TOC may reference itself, TOC
7304*a9fa9459Szrjrelocs are also examined.  TOC words marked as both needed and
7305*a9fa9459Szrjunneeded will of course be kept.  TOC words without any referencing
7306*a9fa9459Szrjreloc are assumed to be part of a multi-word entry, and are kept or
7307*a9fa9459Szrjdiscarded as per the nearest marked preceding word.  This works
7308*a9fa9459Szrjreliably for compiler generated code, but may be incorrect if assembly
7309*a9fa9459Szrjcode is used to insert TOC entries.  Use this option to disable the
7310*a9fa9459Szrjoptimization.
7311*a9fa9459Szrj
7312*a9fa9459Szrj@cindex PowerPC64 multi-TOC
7313*a9fa9459Szrj@kindex --no-multi-toc
7314*a9fa9459Szrj@item --no-multi-toc
7315*a9fa9459SzrjIf given any toc option besides @code{-mcmodel=medium} or
7316*a9fa9459Szrj@code{-mcmodel=large}, PowerPC64 GCC generates code for a TOC model
7317*a9fa9459Szrjwhere TOC
7318*a9fa9459Szrjentries are accessed with a 16-bit offset from r2.  This limits the
7319*a9fa9459Szrjtotal TOC size to 64K.  PowerPC64 @command{ld} extends this limit by
7320*a9fa9459Szrjgrouping code sections such that each group uses less than 64K for its
7321*a9fa9459SzrjTOC entries, then inserts r2 adjusting stubs between inter-group
7322*a9fa9459Szrjcalls.  @command{ld} does not split apart input sections, so cannot
7323*a9fa9459Szrjhelp if a single input file has a @code{.toc} section that exceeds
7324*a9fa9459Szrj64K, most likely from linking multiple files with @command{ld -r}.
7325*a9fa9459SzrjUse this option to turn off this feature.
7326*a9fa9459Szrj
7327*a9fa9459Szrj@cindex PowerPC64 TOC sorting
7328*a9fa9459Szrj@kindex --no-toc-sort
7329*a9fa9459Szrj@item --no-toc-sort
7330*a9fa9459SzrjBy default, @command{ld} sorts TOC sections so that those whose file
7331*a9fa9459Szrjhappens to have a section called @code{.init} or @code{.fini} are
7332*a9fa9459Szrjplaced first, followed by TOC sections referenced by code generated
7333*a9fa9459Szrjwith PowerPC64 gcc's @code{-mcmodel=small}, and lastly TOC sections
7334*a9fa9459Szrjreferenced only by code generated with PowerPC64 gcc's
7335*a9fa9459Szrj@code{-mcmodel=medium} or @code{-mcmodel=large} options.  Doing this
7336*a9fa9459Szrjresults in better TOC grouping for multi-TOC.  Use this option to turn
7337*a9fa9459Szrjoff this feature.
7338*a9fa9459Szrj
7339*a9fa9459Szrj@cindex PowerPC64 PLT stub alignment
7340*a9fa9459Szrj@kindex --plt-align
7341*a9fa9459Szrj@kindex --no-plt-align
7342*a9fa9459Szrj@item --plt-align
7343*a9fa9459Szrj@itemx --no-plt-align
7344*a9fa9459SzrjUse these options to control whether individual PLT call stubs are
7345*a9fa9459Szrjpadded so that they don't cross a 32-byte boundary, or to the
7346*a9fa9459Szrjspecified power of two boundary when using @code{--plt-align=}.  Note
7347*a9fa9459Szrjthat this isn't alignment in the usual sense.  By default PLT call
7348*a9fa9459Szrjstubs are packed tightly.
7349*a9fa9459Szrj
7350*a9fa9459Szrj@cindex PowerPC64 PLT call stub static chain
7351*a9fa9459Szrj@kindex --plt-static-chain
7352*a9fa9459Szrj@kindex --no-plt-static-chain
7353*a9fa9459Szrj@item --plt-static-chain
7354*a9fa9459Szrj@itemx --no-plt-static-chain
7355*a9fa9459SzrjUse these options to control whether PLT call stubs load the static
7356*a9fa9459Szrjchain pointer (r11).  @code{ld} defaults to not loading the static
7357*a9fa9459Szrjchain since there is never any need to do so on a PLT call.
7358*a9fa9459Szrj
7359*a9fa9459Szrj@cindex PowerPC64 PLT call stub thread safety
7360*a9fa9459Szrj@kindex --plt-thread-safe
7361*a9fa9459Szrj@kindex --no-plt-thread-safe
7362*a9fa9459Szrj@item --plt-thread-safe
7363*a9fa9459Szrj@itemx --no-thread-safe
7364*a9fa9459SzrjWith power7's weakly ordered memory model, it is possible when using
7365*a9fa9459Szrjlazy binding for ld.so to update a plt entry in one thread and have
7366*a9fa9459Szrjanother thread see the individual plt entry words update in the wrong
7367*a9fa9459Szrjorder, despite ld.so carefully writing in the correct order and using
7368*a9fa9459Szrjmemory write barriers.  To avoid this we need some sort of read
7369*a9fa9459Szrjbarrier in the call stub, or use LD_BIND_NOW=1.  By default, @code{ld}
7370*a9fa9459Szrjlooks for calls to commonly used functions that create threads, and if
7371*a9fa9459Szrjseen, adds the necessary barriers.  Use these options to change the
7372*a9fa9459Szrjdefault behaviour.
7373*a9fa9459Szrj@end table
7374*a9fa9459Szrj
7375*a9fa9459Szrj@ifclear GENERIC
7376*a9fa9459Szrj@lowersections
7377*a9fa9459Szrj@end ifclear
7378*a9fa9459Szrj@end ifset
7379*a9fa9459Szrj
7380*a9fa9459Szrj@ifset SPU
7381*a9fa9459Szrj@ifclear GENERIC
7382*a9fa9459Szrj@raisesections
7383*a9fa9459Szrj@end ifclear
7384*a9fa9459Szrj
7385*a9fa9459Szrj@node SPU ELF
7386*a9fa9459Szrj@section @command{ld} and SPU ELF Support
7387*a9fa9459Szrj
7388*a9fa9459Szrj@cindex SPU ELF options
7389*a9fa9459Szrj@table @option
7390*a9fa9459Szrj
7391*a9fa9459Szrj@cindex SPU plugins
7392*a9fa9459Szrj@kindex --plugin
7393*a9fa9459Szrj@item --plugin
7394*a9fa9459SzrjThis option marks an executable as a PIC plugin module.
7395*a9fa9459Szrj
7396*a9fa9459Szrj@cindex SPU overlays
7397*a9fa9459Szrj@kindex --no-overlays
7398*a9fa9459Szrj@item --no-overlays
7399*a9fa9459SzrjNormally, @command{ld} recognizes calls to functions within overlay
7400*a9fa9459Szrjregions, and redirects such calls to an overlay manager via a stub.
7401*a9fa9459Szrj@command{ld} also provides a built-in overlay manager.  This option
7402*a9fa9459Szrjturns off all this special overlay handling.
7403*a9fa9459Szrj
7404*a9fa9459Szrj@cindex SPU overlay stub symbols
7405*a9fa9459Szrj@kindex --emit-stub-syms
7406*a9fa9459Szrj@item --emit-stub-syms
7407*a9fa9459SzrjThis option causes @command{ld} to label overlay stubs with a local
7408*a9fa9459Szrjsymbol that encodes the stub type and destination.
7409*a9fa9459Szrj
7410*a9fa9459Szrj@cindex SPU extra overlay stubs
7411*a9fa9459Szrj@kindex --extra-overlay-stubs
7412*a9fa9459Szrj@item --extra-overlay-stubs
7413*a9fa9459SzrjThis option causes @command{ld} to add overlay call stubs on all
7414*a9fa9459Szrjfunction calls out of overlay regions.  Normally stubs are not added
7415*a9fa9459Szrjon calls to non-overlay regions.
7416*a9fa9459Szrj
7417*a9fa9459Szrj@cindex SPU local store size
7418*a9fa9459Szrj@kindex --local-store=lo:hi
7419*a9fa9459Szrj@item --local-store=lo:hi
7420*a9fa9459Szrj@command{ld} usually checks that a final executable for SPU fits in
7421*a9fa9459Szrjthe address range 0 to 256k.  This option may be used to change the
7422*a9fa9459Szrjrange.  Disable the check entirely with @option{--local-store=0:0}.
7423*a9fa9459Szrj
7424*a9fa9459Szrj@cindex SPU
7425*a9fa9459Szrj@kindex --stack-analysis
7426*a9fa9459Szrj@item --stack-analysis
7427*a9fa9459SzrjSPU local store space is limited.  Over-allocation of stack space
7428*a9fa9459Szrjunnecessarily limits space available for code and data, while
7429*a9fa9459Szrjunder-allocation results in runtime failures.  If given this option,
7430*a9fa9459Szrj@command{ld} will provide an estimate of maximum stack usage.
7431*a9fa9459Szrj@command{ld} does this by examining symbols in code sections to
7432*a9fa9459Szrjdetermine the extents of functions, and looking at function prologues
7433*a9fa9459Szrjfor stack adjusting instructions.  A call-graph is created by looking
7434*a9fa9459Szrjfor relocations on branch instructions.  The graph is then searched
7435*a9fa9459Szrjfor the maximum stack usage path.  Note that this analysis does not
7436*a9fa9459Szrjfind calls made via function pointers, and does not handle recursion
7437*a9fa9459Szrjand other cycles in the call graph.  Stack usage may be
7438*a9fa9459Szrjunder-estimated if your code makes such calls.  Also, stack usage for
7439*a9fa9459Szrjdynamic allocation, e.g. alloca, will not be detected.  If a link map
7440*a9fa9459Szrjis requested, detailed information about each function's stack usage
7441*a9fa9459Szrjand calls will be given.
7442*a9fa9459Szrj
7443*a9fa9459Szrj@cindex SPU
7444*a9fa9459Szrj@kindex --emit-stack-syms
7445*a9fa9459Szrj@item --emit-stack-syms
7446*a9fa9459SzrjThis option, if given along with @option{--stack-analysis} will result
7447*a9fa9459Szrjin @command{ld} emitting stack sizing symbols for each function.
7448*a9fa9459SzrjThese take the form @code{__stack_<function_name>} for global
7449*a9fa9459Szrjfunctions, and @code{__stack_<number>_<function_name>} for static
7450*a9fa9459Szrjfunctions.  @code{<number>} is the section id in hex.  The value of
7451*a9fa9459Szrjsuch symbols is the stack requirement for the corresponding function.
7452*a9fa9459SzrjThe symbol size will be zero, type @code{STT_NOTYPE}, binding
7453*a9fa9459Szrj@code{STB_LOCAL}, and section @code{SHN_ABS}.
7454*a9fa9459Szrj@end table
7455*a9fa9459Szrj
7456*a9fa9459Szrj@ifclear GENERIC
7457*a9fa9459Szrj@lowersections
7458*a9fa9459Szrj@end ifclear
7459*a9fa9459Szrj@end ifset
7460*a9fa9459Szrj
7461*a9fa9459Szrj@ifset TICOFF
7462*a9fa9459Szrj@ifclear GENERIC
7463*a9fa9459Szrj@raisesections
7464*a9fa9459Szrj@end ifclear
7465*a9fa9459Szrj
7466*a9fa9459Szrj@node TI COFF
7467*a9fa9459Szrj@section @command{ld}'s Support for Various TI COFF Versions
7468*a9fa9459Szrj@cindex TI COFF versions
7469*a9fa9459Szrj@kindex --format=@var{version}
7470*a9fa9459SzrjThe @samp{--format} switch allows selection of one of the various
7471*a9fa9459SzrjTI COFF versions.  The latest of this writing is 2; versions 0 and 1 are
7472*a9fa9459Szrjalso supported.  The TI COFF versions also vary in header byte-order
7473*a9fa9459Szrjformat; @command{ld} will read any version or byte order, but the output
7474*a9fa9459Szrjheader format depends on the default specified by the specific target.
7475*a9fa9459Szrj
7476*a9fa9459Szrj@ifclear GENERIC
7477*a9fa9459Szrj@lowersections
7478*a9fa9459Szrj@end ifclear
7479*a9fa9459Szrj@end ifset
7480*a9fa9459Szrj
7481*a9fa9459Szrj@ifset WIN32
7482*a9fa9459Szrj@ifclear GENERIC
7483*a9fa9459Szrj@raisesections
7484*a9fa9459Szrj@end ifclear
7485*a9fa9459Szrj
7486*a9fa9459Szrj@node WIN32
7487*a9fa9459Szrj@section @command{ld} and WIN32 (cygwin/mingw)
7488*a9fa9459Szrj
7489*a9fa9459SzrjThis section describes some of the win32 specific @command{ld} issues.
7490*a9fa9459SzrjSee @ref{Options,,Command Line Options} for detailed description of the
7491*a9fa9459Szrjcommand line options mentioned here.
7492*a9fa9459Szrj
7493*a9fa9459Szrj@table @emph
7494*a9fa9459Szrj@cindex import libraries
7495*a9fa9459Szrj@item import libraries
7496*a9fa9459SzrjThe standard Windows linker creates and uses so-called import
7497*a9fa9459Szrjlibraries, which contains information for linking to dll's.  They are
7498*a9fa9459Szrjregular static archives and are handled as any other static
7499*a9fa9459Szrjarchive.  The cygwin and mingw ports of @command{ld} have specific
7500*a9fa9459Szrjsupport for creating such libraries provided with the
7501*a9fa9459Szrj@samp{--out-implib} command line option.
7502*a9fa9459Szrj
7503*a9fa9459Szrj@item   exporting DLL symbols
7504*a9fa9459Szrj@cindex exporting DLL symbols
7505*a9fa9459SzrjThe cygwin/mingw @command{ld} has several ways to export symbols for dll's.
7506*a9fa9459Szrj
7507*a9fa9459Szrj@table @emph
7508*a9fa9459Szrj@item   using auto-export functionality
7509*a9fa9459Szrj@cindex using auto-export functionality
7510*a9fa9459SzrjBy default @command{ld} exports symbols with the auto-export functionality,
7511*a9fa9459Szrjwhich is controlled by the following command line options:
7512*a9fa9459Szrj
7513*a9fa9459Szrj@itemize
7514*a9fa9459Szrj@item --export-all-symbols   [This is the default]
7515*a9fa9459Szrj@item --exclude-symbols
7516*a9fa9459Szrj@item --exclude-libs
7517*a9fa9459Szrj@item --exclude-modules-for-implib
7518*a9fa9459Szrj@item --version-script
7519*a9fa9459Szrj@end itemize
7520*a9fa9459Szrj
7521*a9fa9459SzrjWhen auto-export is in operation, @command{ld} will export all the non-local
7522*a9fa9459Szrj(global and common) symbols it finds in a DLL, with the exception of a few
7523*a9fa9459Szrjsymbols known to belong to the system's runtime and libraries.  As it will
7524*a9fa9459Szrjoften not be desirable to export all of a DLL's symbols, which may include
7525*a9fa9459Szrjprivate functions that are not part of any public interface, the command-line
7526*a9fa9459Szrjoptions listed above may be used to filter symbols out from the list for
7527*a9fa9459Szrjexporting.  The @samp{--output-def} option can be used in order to see the
7528*a9fa9459Szrjfinal list of exported symbols with all exclusions taken into effect.
7529*a9fa9459Szrj
7530*a9fa9459SzrjIf @samp{--export-all-symbols} is not given explicitly on the
7531*a9fa9459Szrjcommand line, then the default auto-export behavior will be @emph{disabled}
7532*a9fa9459Szrjif either of the following are true:
7533*a9fa9459Szrj
7534*a9fa9459Szrj@itemize
7535*a9fa9459Szrj@item A DEF file is used.
7536*a9fa9459Szrj@item Any symbol in any object file was marked with the __declspec(dllexport) attribute.
7537*a9fa9459Szrj@end itemize
7538*a9fa9459Szrj
7539*a9fa9459Szrj@item   using a DEF file
7540*a9fa9459Szrj@cindex using a DEF file
7541*a9fa9459SzrjAnother way of exporting symbols is using a DEF file.  A DEF file is
7542*a9fa9459Szrjan ASCII file containing definitions of symbols which should be
7543*a9fa9459Szrjexported when a dll is created.  Usually it is named @samp{<dll
7544*a9fa9459Szrjname>.def} and is added as any other object file to the linker's
7545*a9fa9459Szrjcommand line.  The file's name must end in @samp{.def} or @samp{.DEF}.
7546*a9fa9459Szrj
7547*a9fa9459Szrj@example
7548*a9fa9459Szrjgcc -o <output> <objectfiles> <dll name>.def
7549*a9fa9459Szrj@end example
7550*a9fa9459Szrj
7551*a9fa9459SzrjUsing a DEF file turns off the normal auto-export behavior, unless the
7552*a9fa9459Szrj@samp{--export-all-symbols} option is also used.
7553*a9fa9459Szrj
7554*a9fa9459SzrjHere is an example of a DEF file for a shared library called @samp{xyz.dll}:
7555*a9fa9459Szrj
7556*a9fa9459Szrj@example
7557*a9fa9459SzrjLIBRARY "xyz.dll" BASE=0x20000000
7558*a9fa9459Szrj
7559*a9fa9459SzrjEXPORTS
7560*a9fa9459Szrjfoo
7561*a9fa9459Szrjbar
7562*a9fa9459Szrj_bar = bar
7563*a9fa9459Szrjanother_foo = abc.dll.afoo
7564*a9fa9459Szrjvar1 DATA
7565*a9fa9459Szrjdoo = foo == foo2
7566*a9fa9459Szrjeoo DATA == var1
7567*a9fa9459Szrj@end example
7568*a9fa9459Szrj
7569*a9fa9459SzrjThis example defines a DLL with a non-default base address and seven
7570*a9fa9459Szrjsymbols in the export table. The third exported symbol @code{_bar} is an
7571*a9fa9459Szrjalias for the second. The fourth symbol, @code{another_foo} is resolved
7572*a9fa9459Szrjby "forwarding" to another module and treating it as an alias for
7573*a9fa9459Szrj@code{afoo} exported from the DLL @samp{abc.dll}. The final symbol
7574*a9fa9459Szrj@code{var1} is declared to be a data object. The @samp{doo} symbol in
7575*a9fa9459Szrjexport library is an alias of @samp{foo}, which gets the string name
7576*a9fa9459Szrjin export table @samp{foo2}. The @samp{eoo} symbol is an data export
7577*a9fa9459Szrjsymbol, which gets in export table the name @samp{var1}.
7578*a9fa9459Szrj
7579*a9fa9459SzrjThe optional @code{LIBRARY <name>} command indicates the @emph{internal}
7580*a9fa9459Szrjname of the output DLL. If @samp{<name>} does not include a suffix,
7581*a9fa9459Szrjthe default library suffix, @samp{.DLL} is appended.
7582*a9fa9459Szrj
7583*a9fa9459SzrjWhen the .DEF file is used to build an application, rather than a
7584*a9fa9459Szrjlibrary, the @code{NAME <name>} command should be used instead of
7585*a9fa9459Szrj@code{LIBRARY}. If @samp{<name>} does not include a suffix, the default
7586*a9fa9459Szrjexecutable suffix, @samp{.EXE} is appended.
7587*a9fa9459Szrj
7588*a9fa9459SzrjWith either @code{LIBRARY <name>} or @code{NAME <name>} the optional
7589*a9fa9459Szrjspecification @code{BASE = <number>} may be used to specify a
7590*a9fa9459Szrjnon-default base address for the image.
7591*a9fa9459Szrj
7592*a9fa9459SzrjIf neither @code{LIBRARY <name>} nor  @code{NAME <name>} is specified,
7593*a9fa9459Szrjor they specify an empty string, the internal name is the same as the
7594*a9fa9459Szrjfilename specified on the command line.
7595*a9fa9459Szrj
7596*a9fa9459SzrjThe complete specification of an export symbol is:
7597*a9fa9459Szrj
7598*a9fa9459Szrj@example
7599*a9fa9459SzrjEXPORTS
7600*a9fa9459Szrj  ( (  ( <name1> [ = <name2> ] )
7601*a9fa9459Szrj     | ( <name1> = <module-name> . <external-name>))
7602*a9fa9459Szrj  [ @@ <integer> ] [NONAME] [DATA] [CONSTANT] [PRIVATE] [== <name3>] ) *
7603*a9fa9459Szrj@end example
7604*a9fa9459Szrj
7605*a9fa9459SzrjDeclares @samp{<name1>} as an exported symbol from the DLL, or declares
7606*a9fa9459Szrj@samp{<name1>} as an exported alias for @samp{<name2>}; or declares
7607*a9fa9459Szrj@samp{<name1>} as a "forward" alias for the symbol
7608*a9fa9459Szrj@samp{<external-name>} in the DLL @samp{<module-name>}.
7609*a9fa9459SzrjOptionally, the symbol may be exported by the specified ordinal
7610*a9fa9459Szrj@samp{<integer>} alias. The optional @samp{<name3>} is the to be used
7611*a9fa9459Szrjstring in import/export table for the symbol.
7612*a9fa9459Szrj
7613*a9fa9459SzrjThe optional keywords that follow the declaration indicate:
7614*a9fa9459Szrj
7615*a9fa9459Szrj@code{NONAME}: Do not put the symbol name in the DLL's export table.  It
7616*a9fa9459Szrjwill still be exported by its ordinal alias (either the value specified
7617*a9fa9459Szrjby the .def specification or, otherwise, the value assigned by the
7618*a9fa9459Szrjlinker). The symbol name, however, does remain visible in the import
7619*a9fa9459Szrjlibrary (if any), unless @code{PRIVATE} is also specified.
7620*a9fa9459Szrj
7621*a9fa9459Szrj@code{DATA}: The symbol is a variable or object, rather than a function.
7622*a9fa9459SzrjThe import lib will export only an indirect reference to @code{foo} as
7623*a9fa9459Szrjthe symbol @code{_imp__foo} (ie, @code{foo} must be resolved as
7624*a9fa9459Szrj@code{*_imp__foo}).
7625*a9fa9459Szrj
7626*a9fa9459Szrj@code{CONSTANT}: Like @code{DATA}, but put the undecorated @code{foo} as
7627*a9fa9459Szrjwell as @code{_imp__foo} into the import library. Both refer to the
7628*a9fa9459Szrjread-only import address table's pointer to the variable, not to the
7629*a9fa9459Szrjvariable itself. This can be dangerous. If the user code fails to add
7630*a9fa9459Szrjthe @code{dllimport} attribute and also fails to explicitly add the
7631*a9fa9459Szrjextra indirection that the use of the attribute enforces, the
7632*a9fa9459Szrjapplication will behave unexpectedly.
7633*a9fa9459Szrj
7634*a9fa9459Szrj@code{PRIVATE}: Put the symbol in the DLL's export table, but do not put
7635*a9fa9459Szrjit into the static import library used to resolve imports at link time. The
7636*a9fa9459Szrjsymbol can still be imported using the @code{LoadLibrary/GetProcAddress}
7637*a9fa9459SzrjAPI at runtime or by by using the GNU ld extension of linking directly to
7638*a9fa9459Szrjthe DLL without an import library.
7639*a9fa9459Szrj
7640*a9fa9459SzrjSee ld/deffilep.y in the binutils sources for the full specification of
7641*a9fa9459Szrjother DEF file statements
7642*a9fa9459Szrj
7643*a9fa9459Szrj@cindex creating a DEF file
7644*a9fa9459SzrjWhile linking a shared dll, @command{ld} is able to create a DEF file
7645*a9fa9459Szrjwith the @samp{--output-def <file>} command line option.
7646*a9fa9459Szrj
7647*a9fa9459Szrj@item   Using decorations
7648*a9fa9459Szrj@cindex Using decorations
7649*a9fa9459SzrjAnother way of marking symbols for export is to modify the source code
7650*a9fa9459Szrjitself, so that when building the DLL each symbol to be exported is
7651*a9fa9459Szrjdeclared as:
7652*a9fa9459Szrj
7653*a9fa9459Szrj@example
7654*a9fa9459Szrj__declspec(dllexport) int a_variable
7655*a9fa9459Szrj__declspec(dllexport) void a_function(int with_args)
7656*a9fa9459Szrj@end example
7657*a9fa9459Szrj
7658*a9fa9459SzrjAll such symbols will be exported from the DLL.  If, however,
7659*a9fa9459Szrjany of the object files in the DLL contain symbols decorated in
7660*a9fa9459Szrjthis way, then the normal auto-export behavior is disabled, unless
7661*a9fa9459Szrjthe @samp{--export-all-symbols} option is also used.
7662*a9fa9459Szrj
7663*a9fa9459SzrjNote that object files that wish to access these symbols must @emph{not}
7664*a9fa9459Szrjdecorate them with dllexport.  Instead, they should use dllimport,
7665*a9fa9459Szrjinstead:
7666*a9fa9459Szrj
7667*a9fa9459Szrj@example
7668*a9fa9459Szrj__declspec(dllimport) int a_variable
7669*a9fa9459Szrj__declspec(dllimport) void a_function(int with_args)
7670*a9fa9459Szrj@end example
7671*a9fa9459Szrj
7672*a9fa9459SzrjThis complicates the structure of library header files, because
7673*a9fa9459Szrjwhen included by the library itself the header must declare the
7674*a9fa9459Szrjvariables and functions as dllexport, but when included by client
7675*a9fa9459Szrjcode the header must declare them as dllimport.  There are a number
7676*a9fa9459Szrjof idioms that are typically used to do this; often client code can
7677*a9fa9459Szrjomit the __declspec() declaration completely.  See
7678*a9fa9459Szrj@samp{--enable-auto-import} and @samp{automatic data imports} for more
7679*a9fa9459Szrjinformation.
7680*a9fa9459Szrj@end table
7681*a9fa9459Szrj
7682*a9fa9459Szrj@cindex automatic data imports
7683*a9fa9459Szrj@item automatic data imports
7684*a9fa9459SzrjThe standard Windows dll format supports data imports from dlls only
7685*a9fa9459Szrjby adding special decorations (dllimport/dllexport), which let the
7686*a9fa9459Szrjcompiler produce specific assembler instructions to deal with this
7687*a9fa9459Szrjissue.  This increases the effort necessary to port existing Un*x
7688*a9fa9459Szrjcode to these platforms, especially for large
7689*a9fa9459Szrjc++ libraries and applications.  The auto-import feature, which was
7690*a9fa9459Szrjinitially provided by Paul Sokolovsky, allows one to omit the
7691*a9fa9459Szrjdecorations to achieve a behavior that conforms to that on POSIX/Un*x
7692*a9fa9459Szrjplatforms. This feature is enabled with the @samp{--enable-auto-import}
7693*a9fa9459Szrjcommand-line option, although it is enabled by default on cygwin/mingw.
7694*a9fa9459SzrjThe @samp{--enable-auto-import} option itself now serves mainly to
7695*a9fa9459Szrjsuppress any warnings that are ordinarily emitted when linked objects
7696*a9fa9459Szrjtrigger the feature's use.
7697*a9fa9459Szrj
7698*a9fa9459Szrjauto-import of variables does not always work flawlessly without
7699*a9fa9459Szrjadditional assistance.  Sometimes, you will see this message
7700*a9fa9459Szrj
7701*a9fa9459Szrj"variable '<var>' can't be auto-imported. Please read the
7702*a9fa9459Szrjdocumentation for ld's @code{--enable-auto-import} for details."
7703*a9fa9459Szrj
7704*a9fa9459SzrjThe @samp{--enable-auto-import} documentation explains why this error
7705*a9fa9459Szrjoccurs, and several methods that can be used to overcome this difficulty.
7706*a9fa9459SzrjOne of these methods is the @emph{runtime pseudo-relocs} feature, described
7707*a9fa9459Szrjbelow.
7708*a9fa9459Szrj
7709*a9fa9459Szrj@cindex runtime pseudo-relocation
7710*a9fa9459SzrjFor complex variables imported from DLLs (such as structs or classes),
7711*a9fa9459Szrjobject files typically contain a base address for the variable and an
7712*a9fa9459Szrjoffset (@emph{addend}) within the variable--to specify a particular
7713*a9fa9459Szrjfield or public member, for instance.  Unfortunately, the runtime loader used
7714*a9fa9459Szrjin win32 environments is incapable of fixing these references at runtime
7715*a9fa9459Szrjwithout the additional information supplied by dllimport/dllexport decorations.
7716*a9fa9459SzrjThe standard auto-import feature described above is unable to resolve these
7717*a9fa9459Szrjreferences.
7718*a9fa9459Szrj
7719*a9fa9459SzrjThe @samp{--enable-runtime-pseudo-relocs} switch allows these references to
7720*a9fa9459Szrjbe resolved without error, while leaving the task of adjusting the references
7721*a9fa9459Szrjthemselves (with their non-zero addends) to specialized code provided by the
7722*a9fa9459Szrjruntime environment.  Recent versions of the cygwin and mingw environments and
7723*a9fa9459Szrjcompilers provide this runtime support; older versions do not.  However, the
7724*a9fa9459Szrjsupport is only necessary on the developer's platform; the compiled result will
7725*a9fa9459Szrjrun without error on an older system.
7726*a9fa9459Szrj
7727*a9fa9459Szrj@samp{--enable-runtime-pseudo-relocs} is not the default; it must be explicitly
7728*a9fa9459Szrjenabled as needed.
7729*a9fa9459Szrj
7730*a9fa9459Szrj@cindex direct linking to a dll
7731*a9fa9459Szrj@item direct linking to a dll
7732*a9fa9459SzrjThe cygwin/mingw ports of @command{ld} support the direct linking,
7733*a9fa9459Szrjincluding data symbols, to a dll without the usage of any import
7734*a9fa9459Szrjlibraries.  This is much faster and uses much less memory than does the
7735*a9fa9459Szrjtraditional import library method, especially when linking large
7736*a9fa9459Szrjlibraries or applications.  When @command{ld} creates an import lib, each
7737*a9fa9459Szrjfunction or variable exported from the dll is stored in its own bfd, even
7738*a9fa9459Szrjthough a single bfd could contain many exports.  The overhead involved in
7739*a9fa9459Szrjstoring, loading, and processing so many bfd's is quite large, and explains the
7740*a9fa9459Szrjtremendous time, memory, and storage needed to link against particularly
7741*a9fa9459Szrjlarge or complex libraries when using import libs.
7742*a9fa9459Szrj
7743*a9fa9459SzrjLinking directly to a dll uses no extra command-line switches other than
7744*a9fa9459Szrj@samp{-L} and @samp{-l}, because @command{ld} already searches for a number
7745*a9fa9459Szrjof names to match each library.  All that is needed from the developer's
7746*a9fa9459Szrjperspective is an understanding of this search, in order to force ld to
7747*a9fa9459Szrjselect the dll instead of an import library.
7748*a9fa9459Szrj
7749*a9fa9459Szrj
7750*a9fa9459SzrjFor instance, when ld is called with the argument @samp{-lxxx} it will attempt
7751*a9fa9459Szrjto find, in the first directory of its search path,
7752*a9fa9459Szrj
7753*a9fa9459Szrj@example
7754*a9fa9459Szrjlibxxx.dll.a
7755*a9fa9459Szrjxxx.dll.a
7756*a9fa9459Szrjlibxxx.a
7757*a9fa9459Szrjxxx.lib
7758*a9fa9459Szrjcygxxx.dll (*)
7759*a9fa9459Szrjlibxxx.dll
7760*a9fa9459Szrjxxx.dll
7761*a9fa9459Szrj@end example
7762*a9fa9459Szrj
7763*a9fa9459Szrjbefore moving on to the next directory in the search path.
7764*a9fa9459Szrj
7765*a9fa9459Szrj(*) Actually, this is not @samp{cygxxx.dll} but in fact is @samp{<prefix>xxx.dll},
7766*a9fa9459Szrjwhere @samp{<prefix>} is set by the @command{ld} option
7767*a9fa9459Szrj@samp{--dll-search-prefix=<prefix>}. In the case of cygwin, the standard gcc spec
7768*a9fa9459Szrjfile includes @samp{--dll-search-prefix=cyg}, so in effect we actually search for
7769*a9fa9459Szrj@samp{cygxxx.dll}.
7770*a9fa9459Szrj
7771*a9fa9459SzrjOther win32-based unix environments, such as mingw or pw32, may use other
7772*a9fa9459Szrj@samp{<prefix>}es, although at present only cygwin makes use of this feature.  It
7773*a9fa9459Szrjwas originally intended to help avoid name conflicts among dll's built for the
7774*a9fa9459Szrjvarious win32/un*x environments, so that (for example) two versions of a zlib dll
7775*a9fa9459Szrjcould coexist on the same machine.
7776*a9fa9459Szrj
7777*a9fa9459SzrjThe generic cygwin/mingw path layout uses a @samp{bin} directory for
7778*a9fa9459Szrjapplications and dll's and a @samp{lib} directory for the import
7779*a9fa9459Szrjlibraries (using cygwin nomenclature):
7780*a9fa9459Szrj
7781*a9fa9459Szrj@example
7782*a9fa9459Szrjbin/
7783*a9fa9459Szrj	cygxxx.dll
7784*a9fa9459Szrjlib/
7785*a9fa9459Szrj	libxxx.dll.a   (in case of dll's)
7786*a9fa9459Szrj	libxxx.a       (in case of static archive)
7787*a9fa9459Szrj@end example
7788*a9fa9459Szrj
7789*a9fa9459SzrjLinking directly to a dll without using the import library can be
7790*a9fa9459Szrjdone two ways:
7791*a9fa9459Szrj
7792*a9fa9459Szrj1. Use the dll directly by adding the @samp{bin} path to the link line
7793*a9fa9459Szrj@example
7794*a9fa9459Szrjgcc -Wl,-verbose  -o a.exe -L../bin/ -lxxx
7795*a9fa9459Szrj@end example
7796*a9fa9459Szrj
7797*a9fa9459SzrjHowever, as the dll's often have version numbers appended to their names
7798*a9fa9459Szrj(@samp{cygncurses-5.dll}) this will often fail, unless one specifies
7799*a9fa9459Szrj@samp{-L../bin -lncurses-5} to include the version.  Import libs are generally
7800*a9fa9459Szrjnot versioned, and do not have this difficulty.
7801*a9fa9459Szrj
7802*a9fa9459Szrj2. Create a symbolic link from the dll to a file in the @samp{lib}
7803*a9fa9459Szrjdirectory according to the above mentioned search pattern.  This
7804*a9fa9459Szrjshould be used to avoid unwanted changes in the tools needed for
7805*a9fa9459Szrjmaking the app/dll.
7806*a9fa9459Szrj
7807*a9fa9459Szrj@example
7808*a9fa9459Szrjln -s bin/cygxxx.dll lib/[cyg|lib|]xxx.dll[.a]
7809*a9fa9459Szrj@end example
7810*a9fa9459Szrj
7811*a9fa9459SzrjThen you can link without any make environment changes.
7812*a9fa9459Szrj
7813*a9fa9459Szrj@example
7814*a9fa9459Szrjgcc -Wl,-verbose  -o a.exe -L../lib/ -lxxx
7815*a9fa9459Szrj@end example
7816*a9fa9459Szrj
7817*a9fa9459SzrjThis technique also avoids the version number problems, because the following is
7818*a9fa9459Szrjperfectly legal
7819*a9fa9459Szrj
7820*a9fa9459Szrj@example
7821*a9fa9459Szrjbin/
7822*a9fa9459Szrj	cygxxx-5.dll
7823*a9fa9459Szrjlib/
7824*a9fa9459Szrj	libxxx.dll.a -> ../bin/cygxxx-5.dll
7825*a9fa9459Szrj@end example
7826*a9fa9459Szrj
7827*a9fa9459SzrjLinking directly to a dll without using an import lib will work
7828*a9fa9459Szrjeven when auto-import features are exercised, and even when
7829*a9fa9459Szrj@samp{--enable-runtime-pseudo-relocs} is used.
7830*a9fa9459Szrj
7831*a9fa9459SzrjGiven the improvements in speed and memory usage, one might justifiably
7832*a9fa9459Szrjwonder why import libraries are used at all.  There are three reasons:
7833*a9fa9459Szrj
7834*a9fa9459Szrj1. Until recently, the link-directly-to-dll functionality did @emph{not}
7835*a9fa9459Szrjwork with auto-imported data.
7836*a9fa9459Szrj
7837*a9fa9459Szrj2. Sometimes it is necessary to include pure static objects within the
7838*a9fa9459Szrjimport library (which otherwise contains only bfd's for indirection
7839*a9fa9459Szrjsymbols that point to the exports of a dll).  Again, the import lib
7840*a9fa9459Szrjfor the cygwin kernel makes use of this ability, and it is not
7841*a9fa9459Szrjpossible to do this without an import lib.
7842*a9fa9459Szrj
7843*a9fa9459Szrj3. Symbol aliases can only be resolved using an import lib.  This is
7844*a9fa9459Szrjcritical when linking against OS-supplied dll's (eg, the win32 API)
7845*a9fa9459Szrjin which symbols are usually exported as undecorated aliases of their
7846*a9fa9459Szrjstdcall-decorated assembly names.
7847*a9fa9459Szrj
7848*a9fa9459SzrjSo, import libs are not going away.  But the ability to replace
7849*a9fa9459Szrjtrue import libs with a simple symbolic link to (or a copy of)
7850*a9fa9459Szrja dll, in many cases, is a useful addition to the suite of tools
7851*a9fa9459Szrjbinutils makes available to the win32 developer.  Given the
7852*a9fa9459Szrjmassive improvements in memory requirements during linking, storage
7853*a9fa9459Szrjrequirements, and linking speed, we expect that many developers
7854*a9fa9459Szrjwill soon begin to use this feature whenever possible.
7855*a9fa9459Szrj
7856*a9fa9459Szrj@item symbol aliasing
7857*a9fa9459Szrj@table @emph
7858*a9fa9459Szrj@item adding additional names
7859*a9fa9459SzrjSometimes, it is useful to export symbols with additional names.
7860*a9fa9459SzrjA symbol @samp{foo} will be exported as @samp{foo}, but it can also be
7861*a9fa9459Szrjexported as @samp{_foo} by using special directives in the DEF file
7862*a9fa9459Szrjwhen creating the dll.  This will affect also the optional created
7863*a9fa9459Szrjimport library.  Consider the following DEF file:
7864*a9fa9459Szrj
7865*a9fa9459Szrj@example
7866*a9fa9459SzrjLIBRARY "xyz.dll" BASE=0x61000000
7867*a9fa9459Szrj
7868*a9fa9459SzrjEXPORTS
7869*a9fa9459Szrjfoo
7870*a9fa9459Szrj_foo = foo
7871*a9fa9459Szrj@end example
7872*a9fa9459Szrj
7873*a9fa9459SzrjThe line @samp{_foo = foo} maps the symbol @samp{foo} to @samp{_foo}.
7874*a9fa9459Szrj
7875*a9fa9459SzrjAnother method for creating a symbol alias is to create it in the
7876*a9fa9459Szrjsource code using the "weak" attribute:
7877*a9fa9459Szrj
7878*a9fa9459Szrj@example
7879*a9fa9459Szrjvoid foo () @{ /* Do something.  */; @}
7880*a9fa9459Szrjvoid _foo () __attribute__ ((weak, alias ("foo")));
7881*a9fa9459Szrj@end example
7882*a9fa9459Szrj
7883*a9fa9459SzrjSee the gcc manual for more information about attributes and weak
7884*a9fa9459Szrjsymbols.
7885*a9fa9459Szrj
7886*a9fa9459Szrj@item renaming symbols
7887*a9fa9459SzrjSometimes it is useful to rename exports.  For instance, the cygwin
7888*a9fa9459Szrjkernel does this regularly.  A symbol @samp{_foo} can be exported as
7889*a9fa9459Szrj@samp{foo} but not as @samp{_foo} by using special directives in the
7890*a9fa9459SzrjDEF file. (This will also affect the import library, if it is
7891*a9fa9459Szrjcreated).  In the following example:
7892*a9fa9459Szrj
7893*a9fa9459Szrj@example
7894*a9fa9459SzrjLIBRARY "xyz.dll" BASE=0x61000000
7895*a9fa9459Szrj
7896*a9fa9459SzrjEXPORTS
7897*a9fa9459Szrj_foo = foo
7898*a9fa9459Szrj@end example
7899*a9fa9459Szrj
7900*a9fa9459SzrjThe line @samp{_foo = foo} maps the exported symbol @samp{foo} to
7901*a9fa9459Szrj@samp{_foo}.
7902*a9fa9459Szrj@end table
7903*a9fa9459Szrj
7904*a9fa9459SzrjNote: using a DEF file disables the default auto-export behavior,
7905*a9fa9459Szrjunless the @samp{--export-all-symbols} command line option is used.
7906*a9fa9459SzrjIf, however, you are trying to rename symbols, then you should list
7907*a9fa9459Szrj@emph{all} desired exports in the DEF file, including the symbols
7908*a9fa9459Szrjthat are not being renamed, and do @emph{not} use the
7909*a9fa9459Szrj@samp{--export-all-symbols} option.  If you list only the
7910*a9fa9459Szrjrenamed symbols in the DEF file, and use @samp{--export-all-symbols}
7911*a9fa9459Szrjto handle the other symbols, then the both the new names @emph{and}
7912*a9fa9459Szrjthe original names for the renamed symbols will be exported.
7913*a9fa9459SzrjIn effect, you'd be aliasing those symbols, not renaming them,
7914*a9fa9459Szrjwhich is probably not what you wanted.
7915*a9fa9459Szrj
7916*a9fa9459Szrj@cindex weak externals
7917*a9fa9459Szrj@item weak externals
7918*a9fa9459SzrjThe Windows object format, PE, specifies a form of weak symbols called
7919*a9fa9459Szrjweak externals.  When a weak symbol is linked and the symbol is not
7920*a9fa9459Szrjdefined, the weak symbol becomes an alias for some other symbol.  There
7921*a9fa9459Szrjare three variants of weak externals:
7922*a9fa9459Szrj@itemize
7923*a9fa9459Szrj@item Definition is searched for in objects and libraries, historically
7924*a9fa9459Szrjcalled lazy externals.
7925*a9fa9459Szrj@item Definition is searched for only in other objects, not in libraries.
7926*a9fa9459SzrjThis form is not presently implemented.
7927*a9fa9459Szrj@item No search; the symbol is an alias.  This form is not presently
7928*a9fa9459Szrjimplemented.
7929*a9fa9459Szrj@end itemize
7930*a9fa9459SzrjAs a GNU extension, weak symbols that do not specify an alternate symbol
7931*a9fa9459Szrjare supported.  If the symbol is undefined when linking, the symbol
7932*a9fa9459Szrjuses a default value.
7933*a9fa9459Szrj
7934*a9fa9459Szrj@cindex aligned common symbols
7935*a9fa9459Szrj@item aligned common symbols
7936*a9fa9459SzrjAs a GNU extension to the PE file format, it is possible to specify the
7937*a9fa9459Szrjdesired alignment for a common symbol.  This information is conveyed from
7938*a9fa9459Szrjthe assembler or compiler to the linker by means of GNU-specific commands
7939*a9fa9459Szrjcarried in the object file's @samp{.drectve} section, which are recognized
7940*a9fa9459Szrjby @command{ld} and respected when laying out the common symbols.  Native
7941*a9fa9459Szrjtools will be able to process object files employing this GNU extension,
7942*a9fa9459Szrjbut will fail to respect the alignment instructions, and may issue noisy
7943*a9fa9459Szrjwarnings about unknown linker directives.
7944*a9fa9459Szrj
7945*a9fa9459Szrj@end table
7946*a9fa9459Szrj
7947*a9fa9459Szrj@ifclear GENERIC
7948*a9fa9459Szrj@lowersections
7949*a9fa9459Szrj@end ifclear
7950*a9fa9459Szrj@end ifset
7951*a9fa9459Szrj
7952*a9fa9459Szrj@ifset XTENSA
7953*a9fa9459Szrj@ifclear GENERIC
7954*a9fa9459Szrj@raisesections
7955*a9fa9459Szrj@end ifclear
7956*a9fa9459Szrj
7957*a9fa9459Szrj@node Xtensa
7958*a9fa9459Szrj@section @code{ld} and Xtensa Processors
7959*a9fa9459Szrj
7960*a9fa9459Szrj@cindex Xtensa processors
7961*a9fa9459SzrjThe default @command{ld} behavior for Xtensa processors is to interpret
7962*a9fa9459Szrj@code{SECTIONS} commands so that lists of explicitly named sections in a
7963*a9fa9459Szrjspecification with a wildcard file will be interleaved when necessary to
7964*a9fa9459Szrjkeep literal pools within the range of PC-relative load offsets.  For
7965*a9fa9459Szrjexample, with the command:
7966*a9fa9459Szrj
7967*a9fa9459Szrj@smallexample
7968*a9fa9459SzrjSECTIONS
7969*a9fa9459Szrj@{
7970*a9fa9459Szrj  .text : @{
7971*a9fa9459Szrj    *(.literal .text)
7972*a9fa9459Szrj  @}
7973*a9fa9459Szrj@}
7974*a9fa9459Szrj@end smallexample
7975*a9fa9459Szrj
7976*a9fa9459Szrj@noindent
7977*a9fa9459Szrj@command{ld} may interleave some of the @code{.literal}
7978*a9fa9459Szrjand @code{.text} sections from different object files to ensure that the
7979*a9fa9459Szrjliteral pools are within the range of PC-relative load offsets.  A valid
7980*a9fa9459Szrjinterleaving might place the @code{.literal} sections from an initial
7981*a9fa9459Szrjgroup of files followed by the @code{.text} sections of that group of
7982*a9fa9459Szrjfiles.  Then, the @code{.literal} sections from the rest of the files
7983*a9fa9459Szrjand the @code{.text} sections from the rest of the files would follow.
7984*a9fa9459Szrj
7985*a9fa9459Szrj@cindex @option{--relax} on Xtensa
7986*a9fa9459Szrj@cindex relaxing on Xtensa
7987*a9fa9459SzrjRelaxation is enabled by default for the Xtensa version of @command{ld} and
7988*a9fa9459Szrjprovides two important link-time optimizations.  The first optimization
7989*a9fa9459Szrjis to combine identical literal values to reduce code size.  A redundant
7990*a9fa9459Szrjliteral will be removed and all the @code{L32R} instructions that use it
7991*a9fa9459Szrjwill be changed to reference an identical literal, as long as the
7992*a9fa9459Szrjlocation of the replacement literal is within the offset range of all
7993*a9fa9459Szrjthe @code{L32R} instructions.  The second optimization is to remove
7994*a9fa9459Szrjunnecessary overhead from assembler-generated ``longcall'' sequences of
7995*a9fa9459Szrj@code{L32R}/@code{CALLX@var{n}} when the target functions are within
7996*a9fa9459Szrjrange of direct @code{CALL@var{n}} instructions.
7997*a9fa9459Szrj
7998*a9fa9459SzrjFor each of these cases where an indirect call sequence can be optimized
7999*a9fa9459Szrjto a direct call, the linker will change the @code{CALLX@var{n}}
8000*a9fa9459Szrjinstruction to a @code{CALL@var{n}} instruction, remove the @code{L32R}
8001*a9fa9459Szrjinstruction, and remove the literal referenced by the @code{L32R}
8002*a9fa9459Szrjinstruction if it is not used for anything else.  Removing the
8003*a9fa9459Szrj@code{L32R} instruction always reduces code size but can potentially
8004*a9fa9459Szrjhurt performance by changing the alignment of subsequent branch targets.
8005*a9fa9459SzrjBy default, the linker will always preserve alignments, either by
8006*a9fa9459Szrjswitching some instructions between 24-bit encodings and the equivalent
8007*a9fa9459Szrjdensity instructions or by inserting a no-op in place of the @code{L32R}
8008*a9fa9459Szrjinstruction that was removed.  If code size is more important than
8009*a9fa9459Szrjperformance, the @option{--size-opt} option can be used to prevent the
8010*a9fa9459Szrjlinker from widening density instructions or inserting no-ops, except in
8011*a9fa9459Szrja few cases where no-ops are required for correctness.
8012*a9fa9459Szrj
8013*a9fa9459SzrjThe following Xtensa-specific command-line options can be used to
8014*a9fa9459Szrjcontrol the linker:
8015*a9fa9459Szrj
8016*a9fa9459Szrj@cindex Xtensa options
8017*a9fa9459Szrj@table @option
8018*a9fa9459Szrj@item --size-opt
8019*a9fa9459SzrjWhen optimizing indirect calls to direct calls, optimize for code size
8020*a9fa9459Szrjmore than performance.  With this option, the linker will not insert
8021*a9fa9459Szrjno-ops or widen density instructions to preserve branch target
8022*a9fa9459Szrjalignment.  There may still be some cases where no-ops are required to
8023*a9fa9459Szrjpreserve the correctness of the code.
8024*a9fa9459Szrj@end table
8025*a9fa9459Szrj
8026*a9fa9459Szrj@ifclear GENERIC
8027*a9fa9459Szrj@lowersections
8028*a9fa9459Szrj@end ifclear
8029*a9fa9459Szrj@end ifset
8030*a9fa9459Szrj
8031*a9fa9459Szrj@ifclear SingleFormat
8032*a9fa9459Szrj@node BFD
8033*a9fa9459Szrj@chapter BFD
8034*a9fa9459Szrj
8035*a9fa9459Szrj@cindex back end
8036*a9fa9459Szrj@cindex object file management
8037*a9fa9459Szrj@cindex object formats available
8038*a9fa9459Szrj@kindex objdump -i
8039*a9fa9459SzrjThe linker accesses object and archive files using the BFD libraries.
8040*a9fa9459SzrjThese libraries allow the linker to use the same routines to operate on
8041*a9fa9459Szrjobject files whatever the object file format.  A different object file
8042*a9fa9459Szrjformat can be supported simply by creating a new BFD back end and adding
8043*a9fa9459Szrjit to the library.  To conserve runtime memory, however, the linker and
8044*a9fa9459Szrjassociated tools are usually configured to support only a subset of the
8045*a9fa9459Szrjobject file formats available.  You can use @code{objdump -i}
8046*a9fa9459Szrj(@pxref{objdump,,objdump,binutils.info,The GNU Binary Utilities}) to
8047*a9fa9459Szrjlist all the formats available for your configuration.
8048*a9fa9459Szrj
8049*a9fa9459Szrj@cindex BFD requirements
8050*a9fa9459Szrj@cindex requirements for BFD
8051*a9fa9459SzrjAs with most implementations, BFD is a compromise between
8052*a9fa9459Szrjseveral conflicting requirements. The major factor influencing
8053*a9fa9459SzrjBFD design was efficiency: any time used converting between
8054*a9fa9459Szrjformats is time which would not have been spent had BFD not
8055*a9fa9459Szrjbeen involved. This is partly offset by abstraction payback; since
8056*a9fa9459SzrjBFD simplifies applications and back ends, more time and care
8057*a9fa9459Szrjmay be spent optimizing algorithms for a greater speed.
8058*a9fa9459Szrj
8059*a9fa9459SzrjOne minor artifact of the BFD solution which you should bear in
8060*a9fa9459Szrjmind is the potential for information loss.  There are two places where
8061*a9fa9459Szrjuseful information can be lost using the BFD mechanism: during
8062*a9fa9459Szrjconversion and during output. @xref{BFD information loss}.
8063*a9fa9459Szrj
8064*a9fa9459Szrj@menu
8065*a9fa9459Szrj* BFD outline::                 How it works: an outline of BFD
8066*a9fa9459Szrj@end menu
8067*a9fa9459Szrj
8068*a9fa9459Szrj@node BFD outline
8069*a9fa9459Szrj@section How It Works: An Outline of BFD
8070*a9fa9459Szrj@cindex opening object files
8071*a9fa9459Szrj@include bfdsumm.texi
8072*a9fa9459Szrj@end ifclear
8073*a9fa9459Szrj
8074*a9fa9459Szrj@node Reporting Bugs
8075*a9fa9459Szrj@chapter Reporting Bugs
8076*a9fa9459Szrj@cindex bugs in @command{ld}
8077*a9fa9459Szrj@cindex reporting bugs in @command{ld}
8078*a9fa9459Szrj
8079*a9fa9459SzrjYour bug reports play an essential role in making @command{ld} reliable.
8080*a9fa9459Szrj
8081*a9fa9459SzrjReporting a bug may help you by bringing a solution to your problem, or
8082*a9fa9459Szrjit may not.  But in any case the principal function of a bug report is
8083*a9fa9459Szrjto help the entire community by making the next version of @command{ld}
8084*a9fa9459Szrjwork better.  Bug reports are your contribution to the maintenance of
8085*a9fa9459Szrj@command{ld}.
8086*a9fa9459Szrj
8087*a9fa9459SzrjIn order for a bug report to serve its purpose, you must include the
8088*a9fa9459Szrjinformation that enables us to fix the bug.
8089*a9fa9459Szrj
8090*a9fa9459Szrj@menu
8091*a9fa9459Szrj* Bug Criteria::                Have you found a bug?
8092*a9fa9459Szrj* Bug Reporting::               How to report bugs
8093*a9fa9459Szrj@end menu
8094*a9fa9459Szrj
8095*a9fa9459Szrj@node Bug Criteria
8096*a9fa9459Szrj@section Have You Found a Bug?
8097*a9fa9459Szrj@cindex bug criteria
8098*a9fa9459Szrj
8099*a9fa9459SzrjIf you are not sure whether you have found a bug, here are some guidelines:
8100*a9fa9459Szrj
8101*a9fa9459Szrj@itemize @bullet
8102*a9fa9459Szrj@cindex fatal signal
8103*a9fa9459Szrj@cindex linker crash
8104*a9fa9459Szrj@cindex crash of linker
8105*a9fa9459Szrj@item
8106*a9fa9459SzrjIf the linker gets a fatal signal, for any input whatever, that is a
8107*a9fa9459Szrj@command{ld} bug.  Reliable linkers never crash.
8108*a9fa9459Szrj
8109*a9fa9459Szrj@cindex error on valid input
8110*a9fa9459Szrj@item
8111*a9fa9459SzrjIf @command{ld} produces an error message for valid input, that is a bug.
8112*a9fa9459Szrj
8113*a9fa9459Szrj@cindex invalid input
8114*a9fa9459Szrj@item
8115*a9fa9459SzrjIf @command{ld} does not produce an error message for invalid input, that
8116*a9fa9459Szrjmay be a bug.  In the general case, the linker can not verify that
8117*a9fa9459Szrjobject files are correct.
8118*a9fa9459Szrj
8119*a9fa9459Szrj@item
8120*a9fa9459SzrjIf you are an experienced user of linkers, your suggestions for
8121*a9fa9459Szrjimprovement of @command{ld} are welcome in any case.
8122*a9fa9459Szrj@end itemize
8123*a9fa9459Szrj
8124*a9fa9459Szrj@node Bug Reporting
8125*a9fa9459Szrj@section How to Report Bugs
8126*a9fa9459Szrj@cindex bug reports
8127*a9fa9459Szrj@cindex @command{ld} bugs, reporting
8128*a9fa9459Szrj
8129*a9fa9459SzrjA number of companies and individuals offer support for @sc{gnu}
8130*a9fa9459Szrjproducts.  If you obtained @command{ld} from a support organization, we
8131*a9fa9459Szrjrecommend you contact that organization first.
8132*a9fa9459Szrj
8133*a9fa9459SzrjYou can find contact information for many support companies and
8134*a9fa9459Szrjindividuals in the file @file{etc/SERVICE} in the @sc{gnu} Emacs
8135*a9fa9459Szrjdistribution.
8136*a9fa9459Szrj
8137*a9fa9459Szrj@ifset BUGURL
8138*a9fa9459SzrjOtherwise, send bug reports for @command{ld} to
8139*a9fa9459Szrj@value{BUGURL}.
8140*a9fa9459Szrj@end ifset
8141*a9fa9459Szrj
8142*a9fa9459SzrjThe fundamental principle of reporting bugs usefully is this:
8143*a9fa9459Szrj@strong{report all the facts}.  If you are not sure whether to state a
8144*a9fa9459Szrjfact or leave it out, state it!
8145*a9fa9459Szrj
8146*a9fa9459SzrjOften people omit facts because they think they know what causes the
8147*a9fa9459Szrjproblem and assume that some details do not matter.  Thus, you might
8148*a9fa9459Szrjassume that the name of a symbol you use in an example does not
8149*a9fa9459Szrjmatter.  Well, probably it does not, but one cannot be sure.  Perhaps
8150*a9fa9459Szrjthe bug is a stray memory reference which happens to fetch from the
8151*a9fa9459Szrjlocation where that name is stored in memory; perhaps, if the name
8152*a9fa9459Szrjwere different, the contents of that location would fool the linker
8153*a9fa9459Szrjinto doing the right thing despite the bug.  Play it safe and give a
8154*a9fa9459Szrjspecific, complete example.  That is the easiest thing for you to do,
8155*a9fa9459Szrjand the most helpful.
8156*a9fa9459Szrj
8157*a9fa9459SzrjKeep in mind that the purpose of a bug report is to enable us to fix
8158*a9fa9459Szrjthe bug if it is new to us.  Therefore, always write your bug reports
8159*a9fa9459Szrjon the assumption that the bug has not been reported previously.
8160*a9fa9459Szrj
8161*a9fa9459SzrjSometimes people give a few sketchy facts and ask, ``Does this ring a
8162*a9fa9459Szrjbell?''  This cannot help us fix a bug, so it is basically useless.  We
8163*a9fa9459Szrjrespond by asking for enough details to enable us to investigate.
8164*a9fa9459SzrjYou might as well expedite matters by sending them to begin with.
8165*a9fa9459Szrj
8166*a9fa9459SzrjTo enable us to fix the bug, you should include all these things:
8167*a9fa9459Szrj
8168*a9fa9459Szrj@itemize @bullet
8169*a9fa9459Szrj@item
8170*a9fa9459SzrjThe version of @command{ld}.  @command{ld} announces it if you start it with
8171*a9fa9459Szrjthe @samp{--version} argument.
8172*a9fa9459Szrj
8173*a9fa9459SzrjWithout this, we will not know whether there is any point in looking for
8174*a9fa9459Szrjthe bug in the current version of @command{ld}.
8175*a9fa9459Szrj
8176*a9fa9459Szrj@item
8177*a9fa9459SzrjAny patches you may have applied to the @command{ld} source, including any
8178*a9fa9459Szrjpatches made to the @code{BFD} library.
8179*a9fa9459Szrj
8180*a9fa9459Szrj@item
8181*a9fa9459SzrjThe type of machine you are using, and the operating system name and
8182*a9fa9459Szrjversion number.
8183*a9fa9459Szrj
8184*a9fa9459Szrj@item
8185*a9fa9459SzrjWhat compiler (and its version) was used to compile @command{ld}---e.g.
8186*a9fa9459Szrj``@code{gcc-2.7}''.
8187*a9fa9459Szrj
8188*a9fa9459Szrj@item
8189*a9fa9459SzrjThe command arguments you gave the linker to link your example and
8190*a9fa9459Szrjobserve the bug.  To guarantee you will not omit something important,
8191*a9fa9459Szrjlist them all.  A copy of the Makefile (or the output from make) is
8192*a9fa9459Szrjsufficient.
8193*a9fa9459Szrj
8194*a9fa9459SzrjIf we were to try to guess the arguments, we would probably guess wrong
8195*a9fa9459Szrjand then we might not encounter the bug.
8196*a9fa9459Szrj
8197*a9fa9459Szrj@item
8198*a9fa9459SzrjA complete input file, or set of input files, that will reproduce the
8199*a9fa9459Szrjbug.  It is generally most helpful to send the actual object files
8200*a9fa9459Szrjprovided that they are reasonably small.  Say no more than 10K.  For
8201*a9fa9459Szrjbigger files you can either make them available by FTP or HTTP or else
8202*a9fa9459Szrjstate that you are willing to send the object file(s) to whomever
8203*a9fa9459Szrjrequests them.  (Note - your email will be going to a mailing list, so
8204*a9fa9459Szrjwe do not want to clog it up with large attachments).  But small
8205*a9fa9459Szrjattachments are best.
8206*a9fa9459Szrj
8207*a9fa9459SzrjIf the source files were assembled using @code{gas} or compiled using
8208*a9fa9459Szrj@code{gcc}, then it may be OK to send the source files rather than the
8209*a9fa9459Szrjobject files.  In this case, be sure to say exactly what version of
8210*a9fa9459Szrj@code{gas} or @code{gcc} was used to produce the object files.  Also say
8211*a9fa9459Szrjhow @code{gas} or @code{gcc} were configured.
8212*a9fa9459Szrj
8213*a9fa9459Szrj@item
8214*a9fa9459SzrjA description of what behavior you observe that you believe is
8215*a9fa9459Szrjincorrect.  For example, ``It gets a fatal signal.''
8216*a9fa9459Szrj
8217*a9fa9459SzrjOf course, if the bug is that @command{ld} gets a fatal signal, then we
8218*a9fa9459Szrjwill certainly notice it.  But if the bug is incorrect output, we might
8219*a9fa9459Szrjnot notice unless it is glaringly wrong.  You might as well not give us
8220*a9fa9459Szrja chance to make a mistake.
8221*a9fa9459Szrj
8222*a9fa9459SzrjEven if the problem you experience is a fatal signal, you should still
8223*a9fa9459Szrjsay so explicitly.  Suppose something strange is going on, such as, your
8224*a9fa9459Szrjcopy of @command{ld} is out of sync, or you have encountered a bug in the
8225*a9fa9459SzrjC library on your system.  (This has happened!)  Your copy might crash
8226*a9fa9459Szrjand ours would not.  If you told us to expect a crash, then when ours
8227*a9fa9459Szrjfails to crash, we would know that the bug was not happening for us.  If
8228*a9fa9459Szrjyou had not told us to expect a crash, then we would not be able to draw
8229*a9fa9459Szrjany conclusion from our observations.
8230*a9fa9459Szrj
8231*a9fa9459Szrj@item
8232*a9fa9459SzrjIf you wish to suggest changes to the @command{ld} source, send us context
8233*a9fa9459Szrjdiffs, as generated by @code{diff} with the @samp{-u}, @samp{-c}, or
8234*a9fa9459Szrj@samp{-p} option.  Always send diffs from the old file to the new file.
8235*a9fa9459SzrjIf you even discuss something in the @command{ld} source, refer to it by
8236*a9fa9459Szrjcontext, not by line number.
8237*a9fa9459Szrj
8238*a9fa9459SzrjThe line numbers in our development sources will not match those in your
8239*a9fa9459Szrjsources.  Your line numbers would convey no useful information to us.
8240*a9fa9459Szrj@end itemize
8241*a9fa9459Szrj
8242*a9fa9459SzrjHere are some things that are not necessary:
8243*a9fa9459Szrj
8244*a9fa9459Szrj@itemize @bullet
8245*a9fa9459Szrj@item
8246*a9fa9459SzrjA description of the envelope of the bug.
8247*a9fa9459Szrj
8248*a9fa9459SzrjOften people who encounter a bug spend a lot of time investigating
8249*a9fa9459Szrjwhich changes to the input file will make the bug go away and which
8250*a9fa9459Szrjchanges will not affect it.
8251*a9fa9459Szrj
8252*a9fa9459SzrjThis is often time consuming and not very useful, because the way we
8253*a9fa9459Szrjwill find the bug is by running a single example under the debugger
8254*a9fa9459Szrjwith breakpoints, not by pure deduction from a series of examples.
8255*a9fa9459SzrjWe recommend that you save your time for something else.
8256*a9fa9459Szrj
8257*a9fa9459SzrjOf course, if you can find a simpler example to report @emph{instead}
8258*a9fa9459Szrjof the original one, that is a convenience for us.  Errors in the
8259*a9fa9459Szrjoutput will be easier to spot, running under the debugger will take
8260*a9fa9459Szrjless time, and so on.
8261*a9fa9459Szrj
8262*a9fa9459SzrjHowever, simplification is not vital; if you do not want to do this,
8263*a9fa9459Szrjreport the bug anyway and send us the entire test case you used.
8264*a9fa9459Szrj
8265*a9fa9459Szrj@item
8266*a9fa9459SzrjA patch for the bug.
8267*a9fa9459Szrj
8268*a9fa9459SzrjA patch for the bug does help us if it is a good one.  But do not omit
8269*a9fa9459Szrjthe necessary information, such as the test case, on the assumption that
8270*a9fa9459Szrja patch is all we need.  We might see problems with your patch and decide
8271*a9fa9459Szrjto fix the problem another way, or we might not understand it at all.
8272*a9fa9459Szrj
8273*a9fa9459SzrjSometimes with a program as complicated as @command{ld} it is very hard to
8274*a9fa9459Szrjconstruct an example that will make the program follow a certain path
8275*a9fa9459Szrjthrough the code.  If you do not send us the example, we will not be
8276*a9fa9459Szrjable to construct one, so we will not be able to verify that the bug is
8277*a9fa9459Szrjfixed.
8278*a9fa9459Szrj
8279*a9fa9459SzrjAnd if we cannot understand what bug you are trying to fix, or why your
8280*a9fa9459Szrjpatch should be an improvement, we will not install it.  A test case will
8281*a9fa9459Szrjhelp us to understand.
8282*a9fa9459Szrj
8283*a9fa9459Szrj@item
8284*a9fa9459SzrjA guess about what the bug is or what it depends on.
8285*a9fa9459Szrj
8286*a9fa9459SzrjSuch guesses are usually wrong.  Even we cannot guess right about such
8287*a9fa9459Szrjthings without first using the debugger to find the facts.
8288*a9fa9459Szrj@end itemize
8289*a9fa9459Szrj
8290*a9fa9459Szrj@node MRI
8291*a9fa9459Szrj@appendix MRI Compatible Script Files
8292*a9fa9459Szrj@cindex MRI compatibility
8293*a9fa9459SzrjTo aid users making the transition to @sc{gnu} @command{ld} from the MRI
8294*a9fa9459Szrjlinker, @command{ld} can use MRI compatible linker scripts as an
8295*a9fa9459Szrjalternative to the more general-purpose linker scripting language
8296*a9fa9459Szrjdescribed in @ref{Scripts}.  MRI compatible linker scripts have a much
8297*a9fa9459Szrjsimpler command set than the scripting language otherwise used with
8298*a9fa9459Szrj@command{ld}.  @sc{gnu} @command{ld} supports the most commonly used MRI
8299*a9fa9459Szrjlinker commands; these commands are described here.
8300*a9fa9459Szrj
8301*a9fa9459SzrjIn general, MRI scripts aren't of much use with the @code{a.out} object
8302*a9fa9459Szrjfile format, since it only has three sections and MRI scripts lack some
8303*a9fa9459Szrjfeatures to make use of them.
8304*a9fa9459Szrj
8305*a9fa9459SzrjYou can specify a file containing an MRI-compatible script using the
8306*a9fa9459Szrj@samp{-c} command-line option.
8307*a9fa9459Szrj
8308*a9fa9459SzrjEach command in an MRI-compatible script occupies its own line; each
8309*a9fa9459Szrjcommand line starts with the keyword that identifies the command (though
8310*a9fa9459Szrjblank lines are also allowed for punctuation).  If a line of an
8311*a9fa9459SzrjMRI-compatible script begins with an unrecognized keyword, @command{ld}
8312*a9fa9459Szrjissues a warning message, but continues processing the script.
8313*a9fa9459Szrj
8314*a9fa9459SzrjLines beginning with @samp{*} are comments.
8315*a9fa9459Szrj
8316*a9fa9459SzrjYou can write these commands using all upper-case letters, or all
8317*a9fa9459Szrjlower case; for example, @samp{chip} is the same as @samp{CHIP}.
8318*a9fa9459SzrjThe following list shows only the upper-case form of each command.
8319*a9fa9459Szrj
8320*a9fa9459Szrj@table @code
8321*a9fa9459Szrj@cindex @code{ABSOLUTE} (MRI)
8322*a9fa9459Szrj@item ABSOLUTE @var{secname}
8323*a9fa9459Szrj@itemx ABSOLUTE @var{secname}, @var{secname}, @dots{} @var{secname}
8324*a9fa9459SzrjNormally, @command{ld} includes in the output file all sections from all
8325*a9fa9459Szrjthe input files.  However, in an MRI-compatible script, you can use the
8326*a9fa9459Szrj@code{ABSOLUTE} command to restrict the sections that will be present in
8327*a9fa9459Szrjyour output program.  If the @code{ABSOLUTE} command is used at all in a
8328*a9fa9459Szrjscript, then only the sections named explicitly in @code{ABSOLUTE}
8329*a9fa9459Szrjcommands will appear in the linker output.  You can still use other
8330*a9fa9459Szrjinput sections (whatever you select on the command line, or using
8331*a9fa9459Szrj@code{LOAD}) to resolve addresses in the output file.
8332*a9fa9459Szrj
8333*a9fa9459Szrj@cindex @code{ALIAS} (MRI)
8334*a9fa9459Szrj@item ALIAS @var{out-secname}, @var{in-secname}
8335*a9fa9459SzrjUse this command to place the data from input section @var{in-secname}
8336*a9fa9459Szrjin a section called @var{out-secname} in the linker output file.
8337*a9fa9459Szrj
8338*a9fa9459Szrj@var{in-secname} may be an integer.
8339*a9fa9459Szrj
8340*a9fa9459Szrj@cindex @code{ALIGN} (MRI)
8341*a9fa9459Szrj@item ALIGN @var{secname} = @var{expression}
8342*a9fa9459SzrjAlign the section called @var{secname} to @var{expression}.  The
8343*a9fa9459Szrj@var{expression} should be a power of two.
8344*a9fa9459Szrj
8345*a9fa9459Szrj@cindex @code{BASE} (MRI)
8346*a9fa9459Szrj@item BASE @var{expression}
8347*a9fa9459SzrjUse the value of @var{expression} as the lowest address (other than
8348*a9fa9459Szrjabsolute addresses) in the output file.
8349*a9fa9459Szrj
8350*a9fa9459Szrj@cindex @code{CHIP} (MRI)
8351*a9fa9459Szrj@item CHIP @var{expression}
8352*a9fa9459Szrj@itemx CHIP @var{expression}, @var{expression}
8353*a9fa9459SzrjThis command does nothing; it is accepted only for compatibility.
8354*a9fa9459Szrj
8355*a9fa9459Szrj@cindex @code{END} (MRI)
8356*a9fa9459Szrj@item END
8357*a9fa9459SzrjThis command does nothing whatever; it's only accepted for compatibility.
8358*a9fa9459Szrj
8359*a9fa9459Szrj@cindex @code{FORMAT} (MRI)
8360*a9fa9459Szrj@item FORMAT @var{output-format}
8361*a9fa9459SzrjSimilar to the @code{OUTPUT_FORMAT} command in the more general linker
8362*a9fa9459Szrjlanguage, but restricted to one of these output formats:
8363*a9fa9459Szrj
8364*a9fa9459Szrj@enumerate
8365*a9fa9459Szrj@item
8366*a9fa9459SzrjS-records, if @var{output-format} is @samp{S}
8367*a9fa9459Szrj
8368*a9fa9459Szrj@item
8369*a9fa9459SzrjIEEE, if @var{output-format} is @samp{IEEE}
8370*a9fa9459Szrj
8371*a9fa9459Szrj@item
8372*a9fa9459SzrjCOFF (the @samp{coff-m68k} variant in BFD), if @var{output-format} is
8373*a9fa9459Szrj@samp{COFF}
8374*a9fa9459Szrj@end enumerate
8375*a9fa9459Szrj
8376*a9fa9459Szrj@cindex @code{LIST} (MRI)
8377*a9fa9459Szrj@item LIST @var{anything}@dots{}
8378*a9fa9459SzrjPrint (to the standard output file) a link map, as produced by the
8379*a9fa9459Szrj@command{ld} command-line option @samp{-M}.
8380*a9fa9459Szrj
8381*a9fa9459SzrjThe keyword @code{LIST} may be followed by anything on the
8382*a9fa9459Szrjsame line, with no change in its effect.
8383*a9fa9459Szrj
8384*a9fa9459Szrj@cindex @code{LOAD} (MRI)
8385*a9fa9459Szrj@item LOAD @var{filename}
8386*a9fa9459Szrj@itemx LOAD @var{filename}, @var{filename}, @dots{} @var{filename}
8387*a9fa9459SzrjInclude one or more object file @var{filename} in the link; this has the
8388*a9fa9459Szrjsame effect as specifying @var{filename} directly on the @command{ld}
8389*a9fa9459Szrjcommand line.
8390*a9fa9459Szrj
8391*a9fa9459Szrj@cindex @code{NAME} (MRI)
8392*a9fa9459Szrj@item NAME @var{output-name}
8393*a9fa9459Szrj@var{output-name} is the name for the program produced by @command{ld}; the
8394*a9fa9459SzrjMRI-compatible command @code{NAME} is equivalent to the command-line
8395*a9fa9459Szrjoption @samp{-o} or the general script language command @code{OUTPUT}.
8396*a9fa9459Szrj
8397*a9fa9459Szrj@cindex @code{ORDER} (MRI)
8398*a9fa9459Szrj@item ORDER @var{secname}, @var{secname}, @dots{} @var{secname}
8399*a9fa9459Szrj@itemx ORDER @var{secname} @var{secname} @var{secname}
8400*a9fa9459SzrjNormally, @command{ld} orders the sections in its output file in the
8401*a9fa9459Szrjorder in which they first appear in the input files.  In an MRI-compatible
8402*a9fa9459Szrjscript, you can override this ordering with the @code{ORDER} command.  The
8403*a9fa9459Szrjsections you list with @code{ORDER} will appear first in your output
8404*a9fa9459Szrjfile, in the order specified.
8405*a9fa9459Szrj
8406*a9fa9459Szrj@cindex @code{PUBLIC} (MRI)
8407*a9fa9459Szrj@item PUBLIC @var{name}=@var{expression}
8408*a9fa9459Szrj@itemx PUBLIC @var{name},@var{expression}
8409*a9fa9459Szrj@itemx PUBLIC @var{name} @var{expression}
8410*a9fa9459SzrjSupply a value (@var{expression}) for external symbol
8411*a9fa9459Szrj@var{name} used in the linker input files.
8412*a9fa9459Szrj
8413*a9fa9459Szrj@cindex @code{SECT} (MRI)
8414*a9fa9459Szrj@item SECT @var{secname}, @var{expression}
8415*a9fa9459Szrj@itemx SECT @var{secname}=@var{expression}
8416*a9fa9459Szrj@itemx SECT @var{secname} @var{expression}
8417*a9fa9459SzrjYou can use any of these three forms of the @code{SECT} command to
8418*a9fa9459Szrjspecify the start address (@var{expression}) for section @var{secname}.
8419*a9fa9459SzrjIf you have more than one @code{SECT} statement for the same
8420*a9fa9459Szrj@var{secname}, only the @emph{first} sets the start address.
8421*a9fa9459Szrj@end table
8422*a9fa9459Szrj
8423*a9fa9459Szrj@node GNU Free Documentation License
8424*a9fa9459Szrj@appendix GNU Free Documentation License
8425*a9fa9459Szrj@include fdl.texi
8426*a9fa9459Szrj
8427*a9fa9459Szrj@node LD Index
8428*a9fa9459Szrj@unnumbered LD Index
8429*a9fa9459Szrj
8430*a9fa9459Szrj@printindex cp
8431*a9fa9459Szrj
8432*a9fa9459Szrj@tex
8433*a9fa9459Szrj% I think something like @@colophon should be in texinfo.  In the
8434*a9fa9459Szrj% meantime:
8435*a9fa9459Szrj\long\def\colophon{\hbox to0pt{}\vfill
8436*a9fa9459Szrj\centerline{The body of this manual is set in}
8437*a9fa9459Szrj\centerline{\fontname\tenrm,}
8438*a9fa9459Szrj\centerline{with headings in {\bf\fontname\tenbf}}
8439*a9fa9459Szrj\centerline{and examples in {\tt\fontname\tentt}.}
8440*a9fa9459Szrj\centerline{{\it\fontname\tenit\/} and}
8441*a9fa9459Szrj\centerline{{\sl\fontname\tensl\/}}
8442*a9fa9459Szrj\centerline{are used for emphasis.}\vfill}
8443*a9fa9459Szrj\page\colophon
8444*a9fa9459Szrj% Blame: doc@@cygnus.com, 28mar91.
8445*a9fa9459Szrj@end tex
8446*a9fa9459Szrj
8447*a9fa9459Szrj@bye
8448