Home Explore Blog CI



man-pages

30th chunk of `ld.man`
91fec059ccad68e1b3182d000ef43fa45e4ce832918fb63f0000000100000fb2
 specified by -rpath options.  The difference between -rpath and -rpath-link is that directories specified by -rpath options are included in the executable  and  used  at  runtime,  whereas  the
               -rpath-link option is only effective at link time. Searching -rpath in this way is only supported by native linkers and cross linkers which have been configured with the --with-sysroot option.

           3.  On an ELF system, for native linkers, if the -rpath and -rpath-link options were not used, search the contents of the environment variable "LD_RUN_PATH".

           4.  On SunOS, if the -rpath option was not used, search any directories specified using -L options.

           5.  For a native linker, search the contents of the environment variable "LD_LIBRARY_PATH".

           6.  For a native ELF linker, the directories in "DT_RUNPATH" or "DT_RPATH" of a shared library are searched for shared libraries needed by it. The "DT_RPATH" entries are ignored if "DT_RUNPATH" entries exist.

           7.  For  a linker for a Linux system, if the file /etc/ld.so.conf exists, the list of directories found in that file.  Note: the path to this file is prefixed with the "sysroot" value, if that is defined, and then
               any "prefix" string if the linker was configured with the --prefix=<path> option.

           8.  For a native linker on a FreeBSD system, any directories specified by the "_PATH_ELF_HINTS" macro defined in the elf-hints.h header file.

           9.  Any directories specified by a "SEARCH_DIR" command in a linker script given on the command line, including scripts specified by -T (but not -dT).

           10. The default directories, normally /lib and /usr/lib.

           11. Any directories specified by a plugin LDPT_SET_EXTRA_LIBRARY_PATH.

           12. Any directories specified by a "SEARCH_DIR" command in a default linker script.

           Note however on Linux based systems there is an additional caveat:  If the --as-needed option is active and a shared library is located which would normally satisfy the  search  and  this  library  does  not  have
           DT_NEEDED  tag  for  libc.so  and  there  is a shared library later on in the set of search directories which also satisfies the search and this second shared library does have a DT_NEEDED tag for libc.so then the
           second library will be selected instead of the first.

           If the required shared library is not found, the linker will issue a warning and continue with the link.

       -shared
       -Bshareable
           Create a shared library.  This is currently only supported on ELF, XCOFF and SunOS platforms.  On SunOS, the linker will automatically create a shared library if the -e option is not used and there  are  undefined
           symbols in the link.

       --sort-common
       --sort-common=ascending
       --sort-common=descending
           This  option  tells ld to sort the common symbols by alignment in ascending or descending order when it places them in the appropriate output sections.  The symbol alignments considered are sixteen‐byte or larger,
           eight‐byte, four‐byte, two‐byte, and one‐byte. This is to prevent gaps between symbols due to alignment constraints.  If no sorting order is specified, then descending order is assumed.

       --sort-section=name
           This option will apply "SORT_BY_NAME" to all wildcard section patterns in the linker script.

       --sort-section=alignment
           This option will apply "SORT_BY_ALIGNMENT" to all wildcard section patterns in the linker script.

       --spare-dynamic-tags=count
           This option specifies the number of empty slots to leave in the .dynamic section of ELF shared objects.  Empty slots may be needed by post processing tools, such as the prelinker.  The default is 5.

       --split-by-file[=size]
           Similar to --split-by-reloc but creates a new output section for each input file when size is reached.  size defaults

Title: LD (GNU Linker) Shared Library Search Paths and Options
Summary
This section details the complete search paths used by the GNU linker to locate required shared libraries. It encompasses environment variables (LD_RUN_PATH, LD_LIBRARY_PATH), system files (/etc/ld.so.conf), linker scripts, default directories (/lib, /usr/lib), and plugin-specified directories. It also describes caveats on Linux systems regarding the --as-needed option and DT_NEEDED tags. The section further explains the -shared option for creating shared libraries and options for sorting common symbols and sections, as well as managing dynamic tags in ELF shared objects.