Home Explore Blog CI



man-pages

11th chunk of `ld.man`
cf787679a7724a87515a00dabdbaebfa2cc96880985b31070000000100000fb1
  Write  a  dependency file to depfile.  This file contains a rule suitable for "make" describing the output file and all the input files that were read to produce it.  The output is similar to the compiler’s output
           with -M -MP.  Note that there is no option like the compiler’s -MM, to exclude "system files" (which is not a well‐specified concept in the linker, unlike "system headers" in the compiler).   So  the  output  from
           --dependency-file is always specific to the exact state of the installation where it was produced, and should not be copied into distributed makefiles without careful editing.

       -O level
           If  level  is  a  numeric values greater than zero ld optimizes the output.  This might take significantly longer and therefore probably should only be enabled for the final binary.  At the moment this option only
           affects ELF shared library generation.  Future releases of the linker may make more use of this option.  Also currently there is no difference in the linker’s  behaviour  for  different  non‐zero  values  of  this
           option.  Again this may change with future releases.

       -plugin name
           Involve a plugin in the linking process.  The name parameter is the absolute filename of the plugin.  Usually this parameter is automatically added by the complier, when using link time optimization, but users can
           also add their own plugins if they so wish.

           Note  that  the  location  of the compiler originated plugins is different from the place where the ar, nm and ranlib programs search for their plugins.  In order for those commands to make use of a compiler based
           plugin it must first be copied into the ${libdir}/bfd-plugins directory.  All gcc based linker plugins are backward compatible, so it is sufficient to just copy in the newest one.

       --push-state
           The --push-state allows one to preserve the current state of the flags which govern the input file handling so that they can all be restored with one corresponding --pop-state option.

           The option which are covered are: -Bdynamic, -Bstatic, -dn, -dy, -call_shared, -non_shared, -static, -N, -n, --whole-archive, --no-whole-archive,  -r,  -Ur,  --copy-dt-needed-entries,  --no-copy-dt-needed-entries,
           --as-needed, --no-as-needed, and -a.

           One  target  for  this  option  are  specifications  for  pkg‐config.   When used with the --libs option all possibly needed libraries are listed and then possibly linked with all the time.  It is better to return
           something as follows:

                   -Wl,--push-state,--as-needed -libone -libtwo -Wl,--pop-state

       --pop-state
           Undoes the effect of --push-state, restores the previous values of the flags governing input file handling.

       -q
       --emit-relocs
           Leave relocation sections and contents in fully linked executables.  Post link analysis and optimization tools may need this information in order to perform correct modifications of executables.  This  results  in
           larger executables.

           This option is currently only supported on ELF platforms.

       --force-dynamic
           Force the output file to have dynamic sections.  This option is specific to VxWorks targets.

       -r
       --relocatable
           Generate  relocatable  output---i.e.,  generate  an  output  file  that  can in turn serve as input to ld.  This is often called partial linking.  As a side effect, in environments that support standard Unix magic
           numbers, this option also sets the output file’s magic number to "OMAGIC".  If this option is not specified, an absolute file is produced.  When linking C++ programs, this option will  not  resolve  references  to
           constructors; to do that, use -Ur.

           When  an input file does not have the same format as the output file, partial linking is only supported if that input file does not

Title: LD (GNU Linker) - Optimization, Plugins, State Management, and Relocatable Output Options
Summary
This section describes several `ld` options including: `-O` for output optimization (currently primarily for ELF shared libraries), `-plugin` to involve plugins in the linking process, `--push-state` and `--pop-state` for preserving and restoring the state of input file handling flags, `-q` for emitting relocation sections in executables, `--force-dynamic` for forcing dynamic sections (VxWorks targets), and `-r` for generating relocatable output files for partial linking.