3.4.2 Commands Dealing with Files
- Include the linker script filename at this point. The file will
be searched for in the current directory, and in any directory specified
with the -L option. You can nest calls to
INCLUDEup to 10 levels deep.
You can place
INCLUDEdirectives at the top level, in
SECTIONScommands, or in output section descriptions.
INPUTcommand directs the linker to include the named files in the link, as though they were named on the command line.
For example, if you always want to include subr.o any time you do a link, but you can't be bothered to put it on every link command line, then you can put INPUT (subr.o) in your linker script.
In fact, if you like, you can list all of your input files in the linker script, and then invoke the linker with nothing but a -T option.
In case a sysroot prefix is configured, and the filename starts with the / character, and the script being processed was located inside the sysroot prefix, the filename will be looked for in the sysroot prefix. Otherwise, the linker will try to open the file in the current directory. If it is not found, the linker will search through the archive library search path. See the description of -L in Command Line Options.
If you use INPUT (-lfile), ld will transform the name to
.a, as with the command line argument -l.
When you use the
INPUTcommand in an implicit linker script, the files will be included in the link at the point at which the linker script file is included. This can affect archive searching.
GROUPcommand is like
INPUT, except that the named files should all be archives, and they are searched repeatedly until no new undefined references are created. See the description of -( in Command Line Options.
- This construct can appear only inside of the
GROUPcommands, among other filenames. The files listed will be handled as if they appear directly in the
GROUPcommands, with the exception of ELF shared libraries, that will be added only when they are actually needed. This construct essentially enables --as-needed option for all the files listed inside of it and restores previous --as-needed resp. --no-as-needed setting afterwards.
OUTPUTcommand names the output file. Using
)in the linker script is exactly like using -o filename on the command line (see Command Line Options). If both are used, the command line option takes precedence.
You can use the
OUTPUTcommand to define a default name for the output file other than the usual default of a.out.
SEARCH_DIRcommand adds path to the list of paths where ld looks for archive libraries. Using
)is exactly like using -L path on the command line (see Command Line Options). If both are used, then the linker will search both paths. Paths specified using the command line option are searched first.
STARTUPcommand is just like the
INPUTcommand, except that filename will become the first input file to be linked, as though it were specified first on the command line. This may be useful when using a system in which the entry point is always the start of the first file.