Transcription of The GNU linker
1 The GNU linkerld(Sourcery G++Lite 2010q1-188)Version ChamberlainIan Lance TaylorRed Hat GNU linkerEdited by Jeffrey Osier 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002, 2003, 2004, 2005, 2006,2007, 2008, 2009 Free Software Foundation, is granted to copy, distribute and/or modify this document under the terms ofthe GNU Free Documentation License, Version or any later version published by theFree Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and withno Back-Cover Texts. A copy of the license is included in the section entitled GNU FreeDocumentation License.
2 ITable of Contents1 Command Line Options Specific to i386 PE Options specific to Motorola 68HC11 and 68HC12 Options specific to Motorola 68K Environment linker Basic linker Script linker Script Simple linker Script Simple linker Script Setting the Entry Commands Dealing with Commands Dealing with Object File Assign alias names to memory Other linker Script Assigning Values to Simple Source Code SECTIONS Output Section Output Section Output Section Input Section Input Section Input Section Wildcard Input Section for Common Input Section and Garbage Input Section Output Section Output Section Output Section Output Section Output Section Output Section Forced Output GNU Forced Input Output Section Output Section Output Section Output Section Overlay MEMORY PHDRS VERSION Expressions in linker Symbolic Symbol Orphan The Location
3 The Section of an Builtin Implicit linker Machine Dependent the H8 the Intel 960 the Motorola 68HC11 and 68HC12 linker Trampoline the ARM HPPA 32-bit ELF the Motorola 68K PowerPC 32-bit ELF PowerPC64 64-bit ELF SPU ELF s Support for Various TI COFF WIN32 (cygwin/mingw).. Xtensa How It Works: An Outline of Information The BFD canonical object-file Reporting Have You Found a Bug?.. How to Report AMRI Compatible Script BGNU Free Documentation : How to use this License for your 1: Overview11 Overviewldcombines a number of object and archive files, relocates their data and ties up symbolreferences.
4 Usually the last step in compiling a program is to linker Command Language files written in a superset of AT&T s Link EditorCommand Language syntax, to provide explicit and total control over the linking version oflduses the general purpose BFD libraries to operate on object files. Thisallowsldto read, combine, and write object files in many different formats for example,COFF Different formats may be linked together to produce any available kind ofobject file. SeeChapter 5 [BFD], page 93, for more from its flexibility, thegnulinker is more helpful than other linkers in providingdiagnostic information.
5 Many linkers abandon execution immediately upon encounteringan error; whenever possible,ldcontinues executing, allowing you to identify other errors(or, in some cases, to get an output file in spite of the error).Chapter 2: Invocation32 InvocationThegnulinkerldis meant to cover a broad range of situations, and to be as compatibleas possible with other linkers . As a result, you have many choices to control its Command Line OptionsThe linker supports a plethora of command-line options, but in actual practice few of themare used in any particular context.
6 For instance, a frequent use ofldis to link standardUnix object files on a standard, supported Unix system. On such a system, to link a :ld -ooutput/ -lcThis tellsldto produce a file calledoutputas the result of linking the file/ the , which will come from the standard search directories.(See the discussion of the -l option below.)Some of the command-line options toldmay be specified at any point in the commandline. However, options which refer to files, such as -l or -T , cause the file to be read atthe point at which the option appears in the command line, relative to the object files andother file options.
7 Repeating non-file options with a different argument will either have nofurther effect, or override prior occurrences (those further to the left on the command line)of that option. Options which may be meaningfully specified more than once are noted inthe descriptions arguments are object files or archives which are to be linked together. Theymay follow, precede, or be mixed in with command-line options, except that an object fileargument may not be placed between an option and its the linker is invoked with at least one object file, but you can specify other formsof binary input files using -l , -R , and the script command language.
8 Ifnobinary inputfiles at all are specified, the linker does not produce any output, and issues the message Noinput files .If the linker cannot recognize the format of an object file, it will assume that it is a linkerscript. A script specified in this way augments the main linker script used for the link(either the default linker script or the one specified by using -T ). This feature permits thelinker to link against a file which appears to be an object or an archive, but actually merelydefines some symbol values, or usesINPUTorGROUPto load other objects.
9 Specifying ascript in this way merely augments the main linker script, with the extra commands placedafter the main script; use the -T option to replace the default linker script entirely, butnote the effect of theINSERT command. SeeChapter 3 [Scripts], page options whose names are a single letter, option arguments must either follow the op-tion letter without intervening whitespace, or be given as separate arguments immediatelyfollowing the option that requires options whose names are multiple letters, either one dash or two can precede the optionname; for example, -trace-symbol and --trace-symbol are equivalent.
10 Note there isone exception to this rule. Multiple letter options that start with a lower case o can onlybe preceded by two dashes. This is to reduce confusion with the -o option. So for example -omagic sets the output file name to magic whereas --omagic sets the NMAGIC flagon the GNU linkerArguments to multiple-letter options must either be separated from the option name byan equals sign, or be given as separate arguments immediately following the option thatrequires them. For example, --trace-symbol foo and --trace-symbol=foo are equiv-alent.