home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / binutils-2.7-src.tgz / tar.out / fsf / binutils / ld / ld.info-1 (.txt) < prev    next >
GNU Info File  |  1996-09-28  |  48KB  |  904 lines

  1. This is Info file ld.info, produced by Makeinfo-1.55 from the input
  2. file ./ld.texinfo.
  3. START-INFO-DIR-ENTRY
  4. * Ld: (ld).                       The GNU linker.
  5. END-INFO-DIR-ENTRY
  6.    This file documents the GNU linker LD.
  7.    Copyright (C) 1991, 92, 93, 94, 95, 1996 Free Software Foundation,
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided also
  13. that the entire resulting derived work is distributed under the terms
  14. of a permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions.
  18. File: ld.info,  Node: Top,  Next: Overview,  Prev: (DIR),  Up: (DIR)
  19. Using ld
  20. ********
  21.    This file documents the GNU linker ld.
  22. * Menu:
  23. * Overview::                    Overview
  24. * Invocation::                  Invocation
  25. * Commands::                    Command Language
  26. * Machine Dependent::           Machine Dependent Features
  27. * BFD::                         BFD
  28. * MRI::                         MRI Compatible Script Files
  29. * Index::                       Index
  30. File: ld.info,  Node: Overview,  Next: Invocation,  Prev: Top,  Up: Top
  31. Overview
  32. ********
  33.    `ld' combines a number of object and archive files, relocates their
  34. data and ties up symbol references. Usually the last step in compiling
  35. a program is to run `ld'.
  36.    `ld' accepts Linker Command Language files written in a superset of
  37. AT&T's Link Editor Command Language syntax, to provide explicit and
  38. total control over the linking process.
  39.    This version of `ld' uses the general purpose BFD libraries to
  40. operate on object files. This allows `ld' to read, combine, and write
  41. object files in many different formats--for example, COFF or `a.out'.
  42. Different formats may be linked together to produce any available kind
  43. of object file.  *Note BFD::, for more information.
  44.    Aside from its flexibility, the GNU linker is more helpful than other
  45. linkers in providing diagnostic information.  Many linkers abandon
  46. execution immediately upon encountering an error; whenever possible,
  47. `ld' continues executing, allowing you to identify other errors (or, in
  48. some cases, to get an output file in spite of the error).
  49. File: ld.info,  Node: Invocation,  Next: Commands,  Prev: Overview,  Up: Top
  50. Invocation
  51. **********
  52.    The GNU linker `ld' is meant to cover a broad range of situations,
  53. and to be as compatible as possible with other linkers.  As a result,
  54. you have many choices to control its behavior.
  55. * Menu:
  56. * Options::                     Command Line Options
  57. * Environment::                 Environment Variables
  58. File: ld.info,  Node: Options,  Next: Environment,  Up: Invocation
  59. Command Line Options
  60. ====================
  61.    The linker supports a plethora of command-line options, but in actual
  62. practice few of them are used in any particular context.  For instance,
  63. a frequent use of `ld' is to link standard Unix object files on a
  64. standard, supported Unix system.  On such a system, to link a file
  65. `hello.o':
  66.      ld -o OUTPUT /lib/crt0.o hello.o -lc
  67.    This tells `ld' to produce a file called OUTPUT as the result of
  68. linking the file `/lib/crt0.o' with `hello.o' and the library `libc.a',
  69. which will come from the standard search directories.  (See the
  70. discussion of the `-l' option below.)
  71.    The command-line options to `ld' may be specified in any order, and
  72. may be repeated at will.  Repeating most options with a different
  73. argument will either have no further effect, or override prior
  74. occurrences (those further to the left on the command line) of that
  75. option.  Options which may be meaningfully specified more than once are
  76. noted in the descriptions below.
  77.    Non-option arguments are objects files which are to be linked
  78. together.  They may follow, precede, or be mixed in with command-line
  79. options, except that an object file argument may not be placed between
  80. an option and its argument.
  81.    Usually the linker is invoked with at least one object file, but you
  82. can specify other forms of binary input files using `-l', `-R', and the
  83. script command language.  If *no* binary input files at all are
  84. specified, the linker does not produce any output, and issues the
  85. message `No input files'.
  86.    If the linker can not recognize the format of an object file, it will
  87. assume that it is a linker script.  A script specified in this way
  88. augments the main linker script used for the link (either the default
  89. linker script or the one specified by using `-T').  This feature
  90. permits the linker to link against a file which appears to be an object
  91. or an archive, but actually merely defines some symbol values, or uses
  92. `INPUT' or `GROUP' to load other objects.  *Note Commands::.
  93.    For options whose names are a single letter, option arguments must
  94. either follow the option letter without intervening whitespace, or be
  95. given as separate arguments immediately following the option that
  96. requires them.
  97.    For options whose names are multiple letters, either one dash or two
  98. can precede the option name; for example, `--oformat' and `-oformat'
  99. are equivalent.  Arguments to multiple-letter options must either be
  100. separated from the option name by an equals sign, or be given as
  101. separate arguments immediately following the option that requires them.
  102. For example, `--oformat srec' and `--oformat=srec' are equivalent.
  103. Unique abbreviations of the names of multiple-letter options are
  104. accepted.
  105. `-aKEYWORD'
  106.      This option is supported for HP/UX compatibility.  The KEYWORD
  107.      argument must be one of the strings `archive', `shared', or
  108.      `default'.  `-aarchive' is functionally equivalent to `-Bstatic',
  109.      and the other two keywords are functionally equivalent to
  110.      `-Bdynamic'.  This option may be used any number of times.
  111. `-AARCHITECTURE'
  112. `--architecture=ARCHITECTURE'
  113.      In the current release of `ld', this option is useful only for the
  114.      Intel 960 family of architectures.  In that `ld' configuration, the
  115.      ARCHITECTURE argument identifies the particular architecture in
  116.      the 960 family, enabling some safeguards and modifying the
  117.      archive-library search path.  *Note `ld' and the Intel 960 family:
  118.      i960, for details.
  119.      Future releases of `ld' may support similar functionality for
  120.      other architecture families.
  121. `-b INPUT-FORMAT'
  122. `--format=INPUT-FORMAT'
  123.      `ld' may be configured to support more than one kind of object
  124.      file.  If your `ld' is configured this way, you can use the `-b'
  125.      option to specify the binary format for input object files that
  126.      follow this option on the command line.  Even when `ld' is
  127.      configured to support alternative object formats, you don't
  128.      usually need to specify this, as `ld' should be configured to
  129.      expect as a default input format the most usual format on each
  130.      machine.  INPUT-FORMAT is a text string, the name of a particular
  131.      format supported by the BFD libraries.  (You can list the
  132.      available binary formats with `objdump -i'.) *Note BFD::.
  133.      You may want to use this option if you are linking files with an
  134.      unusual binary format.  You can also use `-b' to switch formats
  135.      explicitly (when linking object files of different formats), by
  136.      including `-b INPUT-FORMAT' before each group of object files in a
  137.      particular format.
  138.      The default format is taken from the environment variable
  139.      `GNUTARGET'.  *Note Environment::.  You can also define the input
  140.      format from a script, using the command `TARGET'; see *Note Option
  141.      Commands::.
  142. `-c MRI-COMMANDFILE'
  143. `--mri-script=MRI-COMMANDFILE'
  144.      For compatibility with linkers produced by MRI, `ld' accepts script
  145.      files written in an alternate, restricted command language,
  146.      described in *Note MRI Compatible Script Files: MRI.  Introduce
  147.      MRI script files with the option `-c'; use the `-T' option to run
  148.      linker scripts written in the general-purpose `ld' scripting
  149.      language.  If MRI-CMDFILE does not exist, `ld' looks for it in the
  150.      directories specified by any `-L' options.
  151. `-dc'
  152. `-dp'
  153.      These three options are equivalent; multiple forms are supported
  154.      for compatibility with other linkers.  They assign space to common
  155.      symbols even if a relocatable output file is specified (with
  156.      `-r').  The script command `FORCE_COMMON_ALLOCATION' has the same
  157.      effect.  *Note Option Commands::.
  158. `-e ENTRY'
  159. `--entry=ENTRY'
  160.      Use ENTRY as the explicit symbol for beginning execution of your
  161.      program, rather than the default entry point. *Note Entry Point::,
  162.      for a discussion of defaults and other ways of specifying the
  163.      entry point.
  164. `-export-dynamic'
  165.      When creating a dynamically linked executable, add all symbols to
  166.      the dynamic symbol table.  Normally, the dynamic symbol table
  167.      contains only symbols which are used by a dynamic object.  This
  168.      option is needed for some uses of `dlopen'.
  169. `-FFORMAT'
  170.      Ignored.  Some older linkers used this option throughout a
  171.      compilation toolchain for specifying object-file format for both
  172.      input and output object files.  The mechanisms `ld' uses for this
  173.      purpose (the `-b' or `-format' options for input files, `-oformat'
  174.      option or the `TARGET' command in linker scripts for output files,
  175.      the `GNUTARGET' environment variable) are more flexible, but `ld'
  176.      accepts the `-F' option for compatibility with scripts written to
  177.      call the old linker.
  178. `--force-exe-suffix'
  179.      Make sure that an output file has a .exe suffix.
  180.      If a successfully built fully linked output file does not have a
  181.      `.exe' or `.dll' suffix, this option forces the linker to copy the
  182.      output file to one of the same name with a `.exe' suffix. This
  183.      option is useful when using unmodified Unix makefiles on a
  184.      Microsoft Windows host, since some versions of Windows won't run
  185.      an image unless it ends in a `.exe' suffix.
  186.      Ignored.  Provided for compatibility with other tools.
  187. `-GVALUE'
  188. `--gpsize=VALUE'
  189.      Set the maximum size of objects to be optimized using the GP
  190.      register to SIZE.  This is only meaningful for object file formats
  191.      such as MIPS ECOFF which supports putting large and small objects
  192.      into different sections.  This is ignored for other object file
  193.      formats.
  194. `-hNAME'
  195. `-soname=NAME'
  196.      When creating an ELF shared object, set the internal DT_SONAME
  197.      field to the specified name.  When an executable is linked with a
  198.      shared object which has a DT_SONAME field, then when the
  199.      executable is run the dynamic linker will attempt to load the
  200.      shared object specified by the DT_SONAME field rather than the
  201.      using the file name given to the linker.
  202.      Perform an incremental link (same as option `-r').
  203. `-lARCHIVE'
  204. `--library=ARCHIVE'
  205.      Add archive file ARCHIVE to the list of files to link.  This
  206.      option may be used any number of times.  `ld' will search its
  207.      path-list for occurrences of `libARCHIVE.a' for every ARCHIVE
  208.      specified.  File extensions other than `.a' may be used on certain
  209.      systems.
  210. `-LSEARCHDIR'
  211. `--library-path=SEARCHDIR'
  212.      Add path SEARCHDIR to the list of paths that `ld' will search for
  213.      archive libraries and `ld' control scripts.  You may use this
  214.      option any number of times.  The directories are searched in the
  215.      order in which they are specified on the command line.
  216.      Directories specified on the command line are searched before the
  217.      default directories.  All `-L' options apply to all `-l' options,
  218.      regardless of the order in which the options appear.
  219.      The default set of paths searched (without being specified with
  220.      `-L') depends on which emulation mode `ld' is using, and in some
  221.      cases also on how it was configured.  *Note Environment::.
  222.      The paths can also be specified in a link script with the
  223.      `SEARCH_DIR' command.  Directories specified this way are searched
  224.      at the point in which the linker script appears in the command
  225.      line.
  226. `-mEMULATION'
  227.      Emulate the EMULATION linker.  You can list the available
  228.      emulations with the `--verbose' or `-V' options.  The default
  229.      depends on how your `ld' was configured.
  230. `--print-map'
  231.      Print (to the standard output) a link map--diagnostic information
  232.      about where symbols are mapped by `ld', and information on global
  233.      common storage allocation.
  234. `--nmagic'
  235.      Set the text segment to be read only, and mark the output as
  236.      `NMAGIC' if possible.
  237. `--omagic'
  238.      Set the text and data sections to be readable and writable.  Also,
  239.      do not page-align the data segment.  If the output format supports
  240.      Unix style magic numbers, mark the output as `OMAGIC'.
  241. `-o OUTPUT'
  242. `--output=OUTPUT'
  243.      Use OUTPUT as the name for the program produced by `ld'; if this
  244.      option is not specified, the name `a.out' is used by default.  The
  245.      script command `OUTPUT' can also specify the output file name.
  246. `--relocateable'
  247.      Generate relocatable output--i.e., generate an output file that
  248.      can in turn serve as input to `ld'.  This is often called "partial
  249.      linking".  As a side effect, in environments that support standard
  250.      Unix magic numbers, this option also sets the output file's magic
  251.      number to `OMAGIC'.  If this option is not specified, an absolute
  252.      file is produced.  When linking C++ programs, this option *will
  253.      not* resolve references to constructors; to do that, use `-Ur'.
  254.      This option does the same thing as `-i'.
  255. `-R FILENAME'
  256. `--just-symbols=FILENAME'
  257.      Read symbol names and their addresses from FILENAME, but do not
  258.      relocate it or include it in the output.  This allows your output
  259.      file to refer symbolically to absolute locations of memory defined
  260.      in other programs.  You may use this option more than once.
  261.      For compatibility with other ELF linkers, if the `-R' option is
  262.      followed by a directory name, rather than a file name, it is
  263.      treated as the `-rpath' option.
  264. `--strip-all'
  265.      Omit all symbol information from the output file.
  266. `--strip-debug'
  267.      Omit debugger symbol information (but not all symbols) from the
  268.      output file.
  269. `--trace'
  270.      Print the names of the input files as `ld' processes them.
  271. `-T COMMANDFILE'
  272. `--script=COMMANDFILE'
  273.      Read link commands from the file COMMANDFILE.  These commands
  274.      replace `ld''s default link script (rather than adding to it), so
  275.      COMMANDFILE must specify everything necessary to describe the
  276.      target format.  *Note Commands::.  If COMMANDFILE does not exist,
  277.      `ld' looks for it in the directories specified by any preceding
  278.      `-L' options.  Multiple `-T' options accumulate.
  279. `-u SYMBOL'
  280. `--undefined=SYMBOL'
  281.      Force SYMBOL to be entered in the output file as an undefined
  282.      symbol.  Doing this may, for example, trigger linking of
  283.      additional modules from standard libraries.  `-u' may be repeated
  284.      with different option arguments to enter additional undefined
  285.      symbols.
  286. `--version'
  287.      Display the version number for `ld'.  The `-V' option also lists
  288.      the supported emulations.
  289. `--discard-all'
  290.      Delete all local symbols.
  291. `--discard-locals'
  292.      Delete all temporary local symbols.  For most targets, this is all
  293.      local symbols whose names begin with `L'.
  294. `-y SYMBOL'
  295. `--trace-symbol=SYMBOL'
  296.      Print the name of each linked file in which SYMBOL appears.  This
  297.      option may be given any number of times.  On many systems it is
  298.      necessary to prepend an underscore.
  299.      This option is useful when you have an undefined symbol in your
  300.      link but don't know where the reference is coming from.
  301. `-Y PATH'
  302.      Add PATH to the default library search path.  This option exists
  303.      for Solaris compatibility.
  304. `-z KEYWORD'
  305.      This option is ignored for Solaris compatibility.
  306. `-( ARCHIVES -)'
  307. `--start-group ARCHIVES --end-group'
  308.      The ARCHIVES should be a list of archive files.  They may be
  309.      either explicit file names, or `-l' options.
  310.      The specified archives are searched repeatedly until no new
  311.      undefined references are created.  Normally, an archive is
  312.      searched only once in the order that it is specified on the
  313.      command line.  If a symbol in that archive is needed to resolve an
  314.      undefined symbol referred to by an object in an archive that
  315.      appears later on the command line, the linker would not be able to
  316.      resolve that reference.  By grouping the archives, they all be
  317.      searched repeatedly until all possible references are resolved.
  318.      Using this option has a significant performance cost.  It is best
  319.      to use it only when there are unavoidable circular references
  320.      between two or more archives.
  321. `-assert KEYWORD'
  322.      This option is ignored for SunOS compatibility.
  323. `-Bdynamic'
  324. `-dy'
  325. `-call_shared'
  326.      Link against dynamic libraries.  This is only meaningful on
  327.      platforms for which shared libraries are supported.  This option
  328.      is normally the default on such platforms.  The different variants
  329.      of this option are for compatibility with various systems.  You
  330.      may use this option multiple times on the command line: it affects
  331.      library searching for `-l' options which follow it.
  332. `-Bstatic'
  333. `-dn'
  334. `-non_shared'
  335. `-static'
  336.      Do not link against shared libraries.  This is only meaningful on
  337.      platforms for which shared libraries are supported.  The different
  338.      variants of this option are for compatibility with various
  339.      systems.  You may use this option multiple times on the command
  340.      line: it affects library searching for `-l' options which follow
  341.      it.
  342. `-Bsymbolic'
  343.      When creating a shared library, bind references to global symbols
  344.      to the definition within the shared library, if any.  Normally, it
  345.      is possible for a program linked against a shared library to
  346.      override the definition within the shared library.  This option is
  347.      only meaningful on ELF platforms which support shared libraries.
  348. `--cref'
  349.      Output a cross reference table.  If a linker map file is being
  350.      generated, the cross reference table is printed to the map file.
  351.      Otherwise, it is printed on the standard output.
  352.      The format of the table is intentionally simple, so that it may be
  353.      easily processed by a script if necessary.  The symbols are
  354.      printed out, sorted by name.  For each symbol, a list of file
  355.      names is given.  If the symbol is defined, the first file listed
  356.      is the location of the definition.  The remaining files contain
  357.      references to the symbol.
  358. `--defsym SYMBOL=EXPRESSION'
  359.      Create a global symbol in the output file, containing the absolute
  360.      address given by EXPRESSION.  You may use this option as many
  361.      times as necessary to define multiple symbols in the command line.
  362.      A limited form of arithmetic is supported for the EXPRESSION in
  363.      this context: you may give a hexadecimal constant or the name of
  364.      an existing symbol, or use `+' and `-' to add or subtract
  365.      hexadecimal constants or symbols.  If you need more elaborate
  366.      expressions, consider using the linker command language from a
  367.      script (*note Assignment: Symbol Definitions: Assignment.).
  368.      *Note:*  there should be no white space between SYMBOL, the equals
  369.      sign ("="), and EXPRESSION.
  370. `--dynamic-linker FILE'
  371.      Set the name of the dynamic linker.  This is only meaningful when
  372.      generating dynamically linked ELF executables.  The default dynamic
  373.      linker is normally correct; don't use this unless you know what
  374.      you are doing.
  375. `-EB'
  376.      Link big-endian objects.  This affects the default output format.
  377. `-EL'
  378.      Link little-endian objects.  This affects the default output
  379.      format.
  380. `-embedded-relocs'
  381.      This option is only meaningful when linking MIPS embedded PIC code,
  382.      generated by the -membedded-pic option to the GNU compiler and
  383.      assembler.  It causes the linker to create a table which may be
  384.      used at runtime to relocate any data which was statically
  385.      initialized to pointer values.  See the code in testsuite/ld-empic
  386.      for details.
  387. `--help'
  388.      Print a summary of the command-line options on the standard output
  389.      and exit.
  390. `-Map MAPFILE'
  391.      Print to the file MAPFILE a link map--diagnostic information about
  392.      where symbols are mapped by `ld', and information on global common
  393.      storage allocation.
  394. `--no-keep-memory'
  395.      `ld' normally optimizes for speed over memory usage by caching the
  396.      symbol tables of input files in memory.  This option tells `ld' to
  397.      instead optimize for memory usage, by rereading the symbol tables
  398.      as necessary.  This may be required if `ld' runs out of memory
  399.      space while linking a large executable.
  400. `--no-whole-archive'
  401.      Turn off the effect of the `--whole-archive' option for subsequent
  402.      archive files.
  403. `--noinhibit-exec'
  404.      Retain the executable output file whenever it is still usable.
  405.      Normally, the linker will not produce an output file if it
  406.      encounters errors during the link process; it exits without
  407.      writing an output file when it issues any error whatsoever.
  408. `-oformat OUTPUT-FORMAT'
  409.      `ld' may be configured to support more than one kind of object
  410.      file.  If your `ld' is configured this way, you can use the
  411.      `-oformat' option to specify the binary format for the output
  412.      object file.  Even when `ld' is configured to support alternative
  413.      object formats, you don't usually need to specify this, as `ld'
  414.      should be configured to produce as a default output format the most
  415.      usual format on each machine.  OUTPUT-FORMAT is a text string, the
  416.      name of a particular format supported by the BFD libraries.  (You
  417.      can list the available binary formats with `objdump -i'.)  The
  418.      script command `OUTPUT_FORMAT' can also specify the output format,
  419.      but this option overrides it.  *Note BFD::.
  420. `-qmagic'
  421.      This option is ignored for Linux compatibility.
  422. `-Qy'
  423.      This option is ignored for SVR4 compatibility.
  424. `--relax'
  425.      An option with machine dependent effects.  This option is only
  426.      supported on a few targets.  *Note `ld' and the H8/300: H8/300.
  427.      *Note `ld' and the Intel 960 family: i960.
  428.      On some platforms, the `--relax' option performs global
  429.      optimizations that become possible when the linker resolves
  430.      addressing in the program, such as relaxing address modes and
  431.      synthesizing new instructions in the output object file.
  432.      On platforms where this is not supported, `-relax' is accepted, but
  433.      ignored.
  434. `--retain-symbols-file FILENAME'
  435.      Retain *only* the symbols listed in the file FILENAME, discarding
  436.      all others.  FILENAME is simply a flat file, with one symbol name
  437.      per line.  This option is especially useful in environments (such
  438.      as VxWorks) where a large global symbol table is accumulated
  439.      gradually, to conserve run-time memory.
  440.      `-retain-symbols-file' does *not* discard undefined symbols, or
  441.      symbols needed for relocations.
  442.      You may only specify `-retain-symbols-file' once in the command
  443.      line.  It overrides `-s' and `-S'.
  444. `-rpath DIR'
  445.      Add a directory to the runtime library search path.  This is used
  446.      when linking an ELF executable with shared objects.  All `-rpath'
  447.      arguments are concatenated and passed to the runtime linker, which
  448.      uses them to locate shared objects at runtime.  The `-rpath'
  449.      option is also used when locating shared objects which are needed
  450.      by shared objects explicitly included in the link; see the
  451.      description of the `-rpath-link' option.  If `-rpath' is not used
  452.      when linking an ELF executable, the contents of the environment
  453.      variable `LD_RUN_PATH' will be used if it is defined.
  454.      The `-rpath' option may also be used on SunOS.  By default, on
  455.      SunOS, the linker will form a runtime search patch out of all the
  456.      `-L' options it is given.  If a `-rpath' option is used, the
  457.      runtime search path will be formed exclusively using the `-rpath'
  458.      options, ignoring the `-L' options.  This can be useful when using
  459.      gcc, which adds many `-L' options which may be on NFS mounted
  460.      filesystems.
  461.      For compatibility with other ELF linkers, if the `-R' option is
  462.      followed by a directory name, rather than a file name, it is
  463.      treated as the `-rpath' option.
  464. `-rpath-link DIR'
  465.      When using ELF or SunOS, one shared library may require another.
  466.      This happens when an `ld -shared' link includes a shared library
  467.      as one of the input files.
  468.      When the linker encounters such a dependency when doing a
  469.      non-shared, non-relocateable link, it will automatically try to
  470.      locate the required shared library and include it in the link, if
  471.      it is not included explicitly.  In such a case, the `-rpath-link'
  472.      option specifies the first set of directories to search.  The
  473.      `-rpath-link' option may specify a sequence of directory names
  474.      either by specifying a list of names separated by colons, or by
  475.      appearing multiple times.
  476.      The linker uses the following search paths to locate required
  477.      shared libraries.
  478.        1. Any directories specified by `-rpath-link' options.
  479.        2. Any directories specified by `-rpath' options.  The difference
  480.           between `-rpath' and `-rpath-link' is that directories
  481.           specified by `-rpath' options are included in the executable
  482.           and used at runtime, whereas the `-rpath-link' option is only
  483.           effective at link time.
  484.        3. On an ELF system, if the `-rpath' and `rpath-link' options
  485.           were not used, search the contents of the environment variable
  486.           `LD_RUN_PATH'.
  487.        4. On SunOS, if the `-rpath' option was not used, search any
  488.           directories specified using `-L' options.
  489.        5. For a native linker, the contents of the environment variable
  490.           `LD_LIBRARY_PATH'.
  491.        6. The default directories, normally `/lib' and `/usr/lib'.
  492.      If the required shared library is not found, the linker will issue
  493.      a warning and continue with the link.
  494. `-shared'
  495. `-Bshareable'
  496.      Create a shared library.  This is currently only supported on ELF,
  497.      XCOFF and SunOS platforms.  On SunOS, the linker will
  498.      automatically create a shared library if the `-e' option is not
  499.      used and there are undefined symbols in the link.
  500. `--sort-common'
  501.      This option tells `ld' to sort the common symbols by size when it
  502.      places them in the appropriate output sections.  First come all
  503.      the one byte symbols, then all the two bytes, then all the four
  504.      bytes, and then everything else.  This is to prevent gaps between
  505.      symbols due to alignment constraints.
  506. `--split-by-file'
  507.      Similar to `--split-by-reloc' but creates a new output section for
  508.      each input file.
  509. `--split-by-reloc COUNT'
  510.      Trys to creates extra sections in the output file so that no single
  511.      output section in the file contains more than COUNT relocations.
  512.      This is useful when generating huge relocatable for downloading
  513.      into certain real time kernels with the COFF object file format;
  514.      since COFF cannot represent more than 65535 relocations in a
  515.      single section.  Note that this will fail to work with object file
  516.      formats which do not support arbitrary sections.  The linker will
  517.      not split up individual input sections for redistribution, so if a
  518.      single input section contains more than COUNT relocations one
  519.      output section will contain that many relocations.
  520. `--stats'
  521.      Compute and display statistics about the operation of the linker,
  522.      such as execution time and memory usage.
  523. `-traditional-format'
  524.      For some targets, the output of `ld' is different in some ways from
  525.      the output of some existing linker.  This switch requests `ld' to
  526.      use the traditional format instead.
  527.      For example, on SunOS, `ld' combines duplicate entries in the
  528.      symbol string table.  This can reduce the size of an output file
  529.      with full debugging information by over 30 percent.
  530.      Unfortunately, the SunOS `dbx' program can not read the resulting
  531.      program (`gdb' has no trouble).  The `-traditional-format' switch
  532.      tells `ld' to not combine duplicate entries.
  533. `-Tbss ORG'
  534. `-Tdata ORG'
  535. `-Ttext ORG'
  536.      Use ORG as the starting address for--respectively--the `bss',
  537.      `data', or the `text' segment of the output file.  ORG must be a
  538.      single hexadecimal integer; for compatibility with other linkers,
  539.      you may omit the leading `0x' usually associated with hexadecimal
  540.      values.
  541. `-Ur'
  542.      For anything other than C++ programs, this option is equivalent to
  543.      `-r': it generates relocatable output--i.e., an output file that
  544.      can in turn serve as input to `ld'.  When linking C++ programs,
  545.      `-Ur' *does* resolve references to constructors, unlike `-r'.  It
  546.      does not work to use `-Ur' on files that were themselves linked
  547.      with `-Ur'; once the constructor table has been built, it cannot
  548.      be added to.  Use `-Ur' only for the last partial link, and `-r'
  549.      for the others.
  550. `--verbose'
  551.      Display the version number for `ld' and list the linker emulations
  552.      supported.  Display which input files can and cannot be opened.
  553.      Display the linker script if using a default builtin script.
  554. `-warn-common'
  555.      Warn when a common symbol is combined with another common symbol
  556.      or with a symbol definition.  Unix linkers allow this somewhat
  557.      sloppy practice, but linkers on some other operating systems do
  558.      not.  This option allows you to find potential problems from
  559.      combining global symbols.  Unfortunately, some C libraries use
  560.      this practice, so you may get some warnings about symbols in the
  561.      libraries as well as in your programs.
  562.      There are three kinds of global symbols, illustrated here by C
  563.      examples:
  564.     `int i = 1;'
  565.           A definition, which goes in the initialized data section of
  566.           the output file.
  567.     `extern int i;'
  568.           An undefined reference, which does not allocate space.  There
  569.           must be either a definition or a common symbol for the
  570.           variable somewhere.
  571.     `int i;'
  572.           A common symbol.  If there are only (one or more) common
  573.           symbols for a variable, it goes in the uninitialized data
  574.           area of the output file.  The linker merges multiple common
  575.           symbols for the same variable into a single symbol.  If they
  576.           are of different sizes, it picks the largest size.  The
  577.           linker turns a common symbol into a declaration, if there is
  578.           a definition of the same variable.
  579.      The `-warn-common' option can produce five kinds of warnings.  Each
  580.      warning consists of a pair of lines: the first describes the
  581.      symbol just encountered, and the second describes the previous
  582.      symbol encountered with the same name.  One or both of the two
  583.      symbols will be a common symbol.
  584.        1. Turning a common symbol into a reference, because there is
  585.           already a definition for the symbol.
  586.                FILE(SECTION): warning: common of `SYMBOL'
  587.                   overridden by definition
  588.                FILE(SECTION): warning: defined here
  589.        2. Turning a common symbol into a reference, because a later
  590.           definition for the symbol is encountered.  This is the same
  591.           as the previous case, except that the symbols are encountered
  592.           in a different order.
  593.                FILE(SECTION): warning: definition of `SYMBOL'
  594.                   overriding common
  595.                FILE(SECTION): warning: common is here
  596.        3. Merging a common symbol with a previous same-sized common
  597.           symbol.
  598.                FILE(SECTION): warning: multiple common
  599.                   of `SYMBOL'
  600.                FILE(SECTION): warning: previous common is here
  601.        4. Merging a common symbol with a previous larger common symbol.
  602.                FILE(SECTION): warning: common of `SYMBOL'
  603.                   overridden by larger common
  604.                FILE(SECTION): warning: larger common is here
  605.        5. Merging a common symbol with a previous smaller common
  606.           symbol.  This is the same as the previous case, except that
  607.           the symbols are encountered in a different order.
  608.                FILE(SECTION): warning: common of `SYMBOL'
  609.                   overriding smaller common
  610.                FILE(SECTION): warning: smaller common is here
  611. `-warn-constructors'
  612.      Warn if any global constructors are used.  This is only useful for
  613.      a few object file formats.  For formats like COFF or ELF, the
  614.      linker can not detect the use of global constructors.
  615. `-warn-multiple-gp'
  616.      Warn if multiple global pointer values are required in the output
  617.      file.  This is only meaningful for certain processors, such as the
  618.      Alpha.  Specifically, some processors put large-valued constants
  619.      in a special section.  A special register (the global pointer)
  620.      points into the middle of this section, so that constants can be
  621.      loaded efficiently via a base-register relative addressing mode.
  622.      Since the offset in base-register relative mode is fixed and
  623.      relatively small (e.g., 16 bits), this limits the maximum size of
  624.      the constant pool.  Thus, in large programs, it is often necessary
  625.      to use multiple global pointer values in order to be able to
  626.      address all possible constants.  This option causes a warning to
  627.      be issued whenever this case occurs.
  628. `-warn-once'
  629.      Only warn once for each undefined symbol, rather than once per
  630.      module which refers to it.
  631. `--whole-archive'
  632.      For each archive mentioned on the command line after the
  633.      `--whole-archive' option, include every object file in the archive
  634.      in the link, rather than searching the archive for the required
  635.      object files.  This is normally used to turn an archive file into
  636.      a shared library, forcing every object to be included in the
  637.      resulting shared library.  This option may be used more than once.
  638. `--wrap SYMBOL'
  639.      Use a wrapper function for SYMBOL.  Any undefined reference to
  640.      SYMBOL will be resolved to `__wrap_SYMBOL'.  Any undefined
  641.      reference to `__real_SYMBOL' will be resolved to SYMBOL.
  642.      This can be used to provide a wrapper for a system function.  The
  643.      wrapper function should be called `__wrap_SYMBOL'.  If it wishes
  644.      to call the system function, it should call `__real_SYMBOL'.
  645.      Here is a trivial example:
  646.           void *
  647.           __wrap_malloc (int c)
  648.           {
  649.             printf ("malloc called with %ld\n", c);
  650.             return __real_malloc (c);
  651.           }
  652.      If you link other code with this file using `--wrap malloc', then
  653.      all calls to `malloc' will call the function `__wrap_malloc'
  654.      instead.  The call to `__real_malloc' in `__wrap_malloc' will call
  655.      the real `malloc' function.
  656.      You may wish to provide a `__real_malloc' function as well, so that
  657.      links without the `--wrap' option will succeed.  If you do this,
  658.      you should not put the definition of `__real_malloc' in the same
  659.      file as `__wrap_malloc'; if you do, the assembler may resolve the
  660.      call before the linker has a chance to wrap it to `malloc'.
  661. File: ld.info,  Node: Environment,  Prev: Options,  Up: Invocation
  662. Environment Variables
  663. =====================
  664.    You can change the behavior of `ld' with the environment variable
  665. `GNUTARGET'.
  666.    `GNUTARGET' determines the input-file object format if you don't use
  667. `-b' (or its synonym `-format').  Its value should be one of the BFD
  668. names for an input format (*note BFD::.).  If there is no `GNUTARGET'
  669. in the environment, `ld' uses the natural format of the target. If
  670. `GNUTARGET' is set to `default' then BFD attempts to discover the input
  671. format by examining binary input files; this method often succeeds, but
  672. there are potential ambiguities, since there is no method of ensuring
  673. that the magic number used to specify object-file formats is unique.
  674. However, the configuration procedure for BFD on each system places the
  675. conventional format for that system first in the search-list, so
  676. ambiguities are resolved in favor of convention.
  677. File: ld.info,  Node: Commands,  Next: Machine Dependent,  Prev: Invocation,  Up: Top
  678. Command Language
  679. ****************
  680.    The command language provides explicit control over the link process,
  681. allowing complete specification of the mapping between the linker's
  682. input files and its output.  It controls:
  683.    * input files
  684.    * file formats
  685.    * output file layout
  686.    * addresses of sections
  687.    * placement of common blocks
  688.    You may supply a command file (also known as a link script) to the
  689. linker either explicitly through the `-T' option, or implicitly as an
  690. ordinary file. If the linker opens a file which it cannot recognize as
  691. a supported object or archive format, it reports an error.
  692. * Menu:
  693. * Scripts::                     Linker Scripts
  694. * Expressions::                 Expressions
  695. * MEMORY::                      MEMORY Command
  696. * SECTIONS::                    SECTIONS Command
  697. * PHDRS::            PHDRS Command
  698. * Entry Point::                 The Entry Point
  699. * Option Commands::             Option Commands
  700. File: ld.info,  Node: Scripts,  Next: Expressions,  Up: Commands
  701. Linker Scripts
  702. ==============
  703.    The `ld' command language is a collection of statements; some are
  704. simple keywords setting a particular option, some are used to select and
  705. group input files or name output files; and two statement types have a
  706. fundamental and pervasive impact on the linking process.
  707.    The most fundamental command of the `ld' command language is the
  708. `SECTIONS' command (*note SECTIONS::.).  Every meaningful command
  709. script must have a `SECTIONS' command: it specifies a "picture" of the
  710. output file's layout, in varying degrees of detail.  No other command
  711. is required in all cases.
  712.    The `MEMORY' command complements `SECTIONS' by describing the
  713. available memory in the target architecture.  This command is optional;
  714. if you don't use a `MEMORY' command, `ld' assumes sufficient memory is
  715. available in a contiguous block for all output.  *Note MEMORY::.
  716.    You may include comments in linker scripts just as in C: delimited
  717. by `/*' and `*/'.  As in C, comments are syntactically equivalent to
  718. whitespace.
  719. File: ld.info,  Node: Expressions,  Next: MEMORY,  Prev: Scripts,  Up: Commands
  720. Expressions
  721. ===========
  722.    Many useful commands involve arithmetic expressions.  The syntax for
  723. expressions in the command language is identical to that of C
  724. expressions, with the following features:
  725.    * All expressions evaluated as integers and are of "long" or
  726.      "unsigned long" type.
  727.    * All constants are integers.
  728.    * All of the C arithmetic operators are provided.
  729.    * You may reference, define, and create global variables.
  730.    * You may call special purpose built-in functions.
  731. * Menu:
  732. * Integers::                    Integers
  733. * Symbols::                     Symbol Names
  734. * Location Counter::            The Location Counter
  735. * Operators::                   Operators
  736. * Evaluation::                  Evaluation
  737. * Assignment::                  Assignment: Defining Symbols
  738. * Arithmetic Functions::        Built-In Functions
  739. * Semicolons::                  Semicolon Usage
  740. File: ld.info,  Node: Integers,  Next: Symbols,  Up: Expressions
  741. Integers
  742. --------
  743.    An octal integer is `0' followed by zero or more of the octal digits
  744. (`01234567').
  745.      _as_octal = 0157255;
  746.    A decimal integer starts with a non-zero digit followed by zero or
  747. more digits (`0123456789').
  748.      _as_decimal = 57005;
  749.    A hexadecimal integer is `0x' or `0X' followed by one or more
  750. hexadecimal digits chosen from `0123456789abcdefABCDEF'.
  751.      _as_hex = 0xdead;
  752.    To write a negative integer, use the prefix operator `-' (*note
  753. Operators::.).
  754.      _as_neg = -57005;
  755.    Additionally the suffixes `K' and `M' may be used to scale a
  756. constant by `1024' or `1024*1024' respectively. For example, the
  757. following all refer to the same quantity:
  758.              _fourk_1 = 4K;
  759.              _fourk_2 = 4096;
  760.              _fourk_3 = 0x1000;
  761. File: ld.info,  Node: Symbols,  Next: Location Counter,  Prev: Integers,  Up: Expressions
  762. Symbol Names
  763. ------------
  764.    Unless quoted, symbol names start with a letter, underscore, or point
  765. and may include any letters, underscores, digits, points, and hyphens.
  766. Unquoted symbol names must not conflict with any keywords.  You can
  767. specify a symbol which contains odd characters or has the same name as
  768. a keyword, by surrounding the symbol name in double quotes:
  769.              "SECTION" = 9;
  770.              "with a space" = "also with a space" + 10;
  771.    Since symbols can contain many non-alphabetic characters, it is
  772. safest to delimit symbols with spaces.  For example, `A-B' is one
  773. symbol, whereas `A - B' is an expression involving subtraction.
  774. File: ld.info,  Node: Location Counter,  Next: Operators,  Prev: Symbols,  Up: Expressions
  775. The Location Counter
  776. --------------------
  777.    The special linker variable "dot" `.' always contains the current
  778. output location counter. Since the `.' always refers to a location in
  779. an output section, it must always appear in an expression within a
  780. `SECTIONS' command. The `.' symbol may appear anywhere that an ordinary
  781. symbol is allowed in an expression, but its assignments have a side
  782. effect. Assigning a value to the `.' symbol will cause the location
  783. counter to be moved.  This may be used to create holes in the output
  784. section.  The location counter may never be moved backwards.
  785.      SECTIONS
  786.      {
  787.        output :
  788.        {
  789.        file1(.text)
  790.        . = . + 1000;
  791.        file2(.text)
  792.        . += 1000;
  793.        file3(.text)
  794.        } = 0x1234;
  795.      }
  796. In the previous example, `file1' is located at the beginning of the
  797. output section, then there is a 1000 byte gap.  Then `file2' appears,
  798. also with a 1000 byte gap following before `file3' is loaded.  The
  799. notation `= 0x1234' specifies what data to write in the gaps (*note
  800. Section Options::.).
  801. File: ld.info,  Node: Operators,  Next: Evaluation,  Prev: Location Counter,  Up: Expressions
  802. Operators
  803. ---------
  804.    The linker recognizes  the standard C set of arithmetic operators,
  805. with the standard bindings and precedence levels:
  806.      precedence      associativity   Operators                Notes
  807.      (highest)
  808.      1               left            !  -  ~                  (1)
  809.      2               left            *  /  %
  810.      3               left            +  -
  811.      4               left            >>  <<
  812.      5               left            ==  !=  >  <  <=  >=
  813.      6               left            &
  814.      7               left            |
  815.      8               left            &&
  816.      9               left            ||
  817.      10              right           ? :
  818.      11              right           &=  +=  -=  *=  /=       (2)
  819.      (lowest)
  820.    Notes: (1) Prefix operators (2) *Note Assignment::.
  821. File: ld.info,  Node: Evaluation,  Next: Assignment,  Prev: Operators,  Up: Expressions
  822. Evaluation
  823. ----------
  824.    The linker uses "lazy evaluation" for expressions; it only calculates
  825. an expression when absolutely necessary.  The linker needs the value of
  826. the start address, and the lengths of memory regions, in order to do any
  827. linking at all; these values are computed as soon as possible when the
  828. linker reads in the command file.  However, other values (such as symbol
  829. values) are not known or needed until after storage allocation.  Such
  830. values are evaluated later, when other information (such as the sizes of
  831. output sections) is available for use in the symbol assignment
  832. expression.
  833. File: ld.info,  Node: Assignment,  Next: Arithmetic Functions,  Prev: Evaluation,  Up: Expressions
  834. Assignment: Defining Symbols
  835. ----------------------------
  836.    You may create global symbols, and assign values (addresses) to
  837. global symbols, using any of the C assignment operators:
  838. `SYMBOL  = EXPRESSION ;'
  839. `SYMBOL &= EXPRESSION ;'
  840. `SYMBOL += EXPRESSION ;'
  841. `SYMBOL -= EXPRESSION ;'
  842. `SYMBOL *= EXPRESSION ;'
  843. `SYMBOL /= EXPRESSION ;'
  844.    Two things distinguish assignment from other operators in `ld'
  845. expressions.
  846.    * Assignment may only be used at the root of an expression; `a=b+3;'
  847.      is allowed, but `a+b=3;' is an error.
  848.    * You must place a trailing semicolon (";") at the end of an
  849.      assignment statement.
  850.    Assignment statements may appear:
  851.    * as commands in their own right in an `ld' script; or
  852.    * as independent statements within a `SECTIONS' command; or
  853.    * as part of the contents of a section definition in a `SECTIONS'
  854.      command.
  855.    The first two cases are equivalent in effect--both define a symbol
  856. with an absolute address.  The last case defines a symbol whose address
  857. is relative to a particular section (*note SECTIONS::.).
  858.    When a linker expression is evaluated and assigned to a variable, it
  859. is given either an absolute or a relocatable type. An absolute
  860. expression type is one in which the symbol contains the value that it
  861. will have in the output file; a relocatable expression type is one in
  862. which the value is expressed as a fixed offset from the base of a
  863. section.
  864.    The type of the expression is controlled by its position in the
  865. script file.  A symbol assigned within a section definition is created
  866. relative to the base of the section; a symbol assigned in any other
  867. place is created as an absolute symbol. Since a symbol created within a
  868. section definition is relative to the base of the section, it will
  869. remain relocatable if relocatable output is requested.  A symbol may be
  870. created with an absolute value even when assigned to within a section
  871. definition by using the absolute assignment function `ABSOLUTE'.  For
  872. example, to create an absolute symbol whose address is the last byte of
  873. an output section named `.data':
  874.      SECTIONS{ ...
  875.        .data :
  876.          {
  877.            *(.data)
  878.            _edata = ABSOLUTE(.) ;
  879.          }
  880.      ... }
  881.    The linker tries to put off the evaluation of an assignment until all
  882. the terms in the source expression are known (*note Evaluation::.).  For
  883. instance, the sizes of sections cannot be known until after allocation,
  884. so assignments dependent upon these are not performed until after
  885. allocation. Some expressions, such as those depending upon the location
  886. counter "dot", `.' must be evaluated during allocation. If the result
  887. of an expression is required, but the value is not available, then an
  888. error results.  For example, a script like the following
  889.      SECTIONS { ...
  890.        text 9+this_isnt_constant :
  891.          { ...
  892.          }
  893.      ... }
  894. will cause the error message "`Non constant expression for initial
  895. address'".
  896.    In some cases, it is desirable for a linker script to define a symbol
  897. only if it is referenced, and only if it is not defined by any object
  898. included in the link.  For example, traditional linkers defined the
  899. symbol `etext'.  However, ANSI C requires that the user be able to use
  900. `etext' as a function name without encountering an error.  The
  901. `PROVIDE' keyword may be used to define a symbol, such as `etext', only
  902. if it is referenced but not defined.  The syntax is `PROVIDE(SYMBOL =
  903. EXPRESSION)'.
  904.