Blame NOTES.UNIX

Packit c4476c
Packit c4476c
 NOTES FOR UNIX LIKE PLATFORMS
Packit c4476c
 =============================
Packit c4476c
Packit c4476c
 For Unix/POSIX runtime systems on Windows, please see NOTES.WIN.
Packit c4476c
Packit c4476c
Packit c4476c
 OpenSSL uses the compiler to link programs and shared libraries
Packit c4476c
 ---------------------------------------------------------------
Packit c4476c
Packit c4476c
 OpenSSL's generated Makefile uses the C compiler command line to
Packit c4476c
 link programs, shared libraries and dynamically loadable shared
Packit c4476c
 objects.  Because of this, any linking option that's given to the
Packit c4476c
 configuration scripts MUST be in a form that the compiler can accept.
Packit c4476c
 This varies between systems, where some have compilers that accept
Packit c4476c
 linker flags directly, while others take them in '-Wl,' form.  You need
Packit c4476c
 to read your compiler documentation to figure out what is acceptable,
Packit c4476c
 and ld(1) to figure out what linker options are available.
Packit c4476c
Packit c4476c
Packit c4476c
 Shared libraries and installation in non-default locations
Packit c4476c
 ----------------------------------------------------------
Packit c4476c
Packit c4476c
 Every Unix system has its own set of default locations for shared
Packit c4476c
 libraries, such as /lib, /usr/lib or possibly /usr/local/lib.  If
Packit c4476c
 libraries are installed in non-default locations, dynamically linked
Packit c4476c
 binaries will not find them and therefore fail to run, unless they get
Packit c4476c
 a bit of help from a defined runtime shared library search path.
Packit c4476c
Packit c4476c
 For OpenSSL's application (the 'openssl' command), our configuration
Packit c4476c
 scripts do NOT generally set the runtime shared library search path for
Packit c4476c
 you.  It's therefore advisable to set it explicitly when configuring,
Packit c4476c
 unless the libraries are to be installed in directories that you know
Packit c4476c
 to be in the default list.
Packit c4476c
Packit c4476c
 Runtime shared library search paths are specified with different
Packit c4476c
 linking options depending on operating system and versions thereof, and
Packit c4476c
 are talked about differently in their respective documentation;
Packit c4476c
 variations of RPATH are the most usual (note: ELF systems have two such
Packit c4476c
 tags, more on that below).
Packit c4476c
Packit c4476c
 Possible options to set the runtime shared library search path include
Packit c4476c
 the following:
Packit c4476c
Packit c4476c
    -Wl,-rpath,/whatever/path	# Linux, *BSD, etc.
Packit c4476c
    -R /whatever/path		# Solaris
Packit c4476c
    -Wl,-R,/whatever/path	# AIX (-bsvr4 is passed internally)
Packit c4476c
    -Wl,+b,/whatever/path	# HP-UX
Packit c4476c
    -rpath /whatever/path	# Tru64, IRIX
Packit c4476c
Packit c4476c
 OpenSSL's configuration scripts recognise all these options and pass
Packit c4476c
 them to the Makefile that they build. (In fact, all arguments starting
Packit c4476c
 with '-Wl,' are recognised as linker options.)
Packit c4476c
Packit c4476c
 Please do not use verbatim directories in your runtime shared library
Packit c4476c
 search path!  Some OpenSSL config targets add an extra directory level
Packit c4476c
 for multilib installations.  To help with that, the produced Makefile
Packit c4476c
 includes the variable LIBRPATH, which is a convenience variable to be
Packit c4476c
 used with the runtime shared library search path options, as shown in
Packit c4476c
 this example:
Packit c4476c
Packit c4476c
    $ ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl \
Packit c4476c
        '-Wl,-rpath,$(LIBRPATH)'
Packit c4476c
Packit c4476c
 On modern ELF based systems, there are two runtime search paths tags to
Packit c4476c
 consider, DT_RPATH and DT_RUNPATH.  Shared objects are searched for in
Packit c4476c
 this order:
Packit c4476c
Packit c4476c
    1. Using directories specified in DT_RPATH, unless DT_RUNPATH is
Packit c4476c
       also set.
Packit c4476c
    2. Using the environment variable LD_LIBRARY_PATH
Packit c4476c
    3. Using directories specified in DT_RUNPATH.
Packit c4476c
    4. Using system shared object caches and default directories.
Packit c4476c
Packit c4476c
 This means that the values in the environment variable LD_LIBRARY_PATH
Packit c4476c
 won't matter if the library is found in the paths given by DT_RPATH
Packit c4476c
 (and DT_RUNPATH isn't set).
Packit c4476c
Packit c4476c
 Exactly which of DT_RPATH or DT_RUNPATH is set by default appears to
Packit c4476c
 depend on the system.  For example, according to documentation,
Packit c4476c
 DT_RPATH appears to be deprecated on Solaris in favor of DT_RUNPATH,
Packit c4476c
 while on Debian GNU/Linux, either can be set, and DT_RPATH is the
Packit c4476c
 default at the time of writing.
Packit c4476c
Packit c4476c
 How to choose which runtime search path tag is to be set depends on
Packit c4476c
 your system, please refer to ld(1) for the exact information on your
Packit c4476c
 system.  As an example, the way to ensure the DT_RUNPATH is set on
Packit c4476c
 Debian GNU/Linux systems rather than DT_RPATH is to tell the linker to
Packit c4476c
 set new dtags, like this:
Packit c4476c
Packit c4476c
    $ ./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl \
Packit c4476c
        '-Wl,--enable-new-dtags,-rpath,$(LIBRPATH)'
Packit c4476c
Packit c4476c
 It might be worth noting that some/most ELF systems implement support
Packit c4476c
 for runtime search path relative to the directory containing current
Packit c4476c
 executable, by interpreting $ORIGIN along with some other internal
Packit c4476c
 variables. Consult your system documentation.
Packit c4476c
Packit c4476c
 Linking your application
Packit c4476c
 ------------------------
Packit c4476c
Packit c4476c
 Third-party applications dynamically linked with OpenSSL (or any other)
Packit c4476c
 shared library face exactly the same problem with non-default locations.
Packit c4476c
 The OpenSSL config options mentioned above might or might not have bearing
Packit c4476c
 on linking of the target application. "Might" means that under some
Packit c4476c
 circumstances it would be sufficient to link with OpenSSL shared library
Packit c4476c
 "naturally", i.e. with -L/whatever/path -lssl -lcrypto. But there are
Packit c4476c
 also cases when you'd have to explicitly specify runtime search path
Packit c4476c
 when linking your application. Consult your system documentation and use
Packit c4476c
 above section as inspiration...
Packit c4476c
Packit c4476c
 Shared OpenSSL builds also install static libraries. Linking with the
Packit c4476c
 latter is likely to require special care, because linkers usually look
Packit c4476c
 for shared libraries first and tend to remain "blind" to static OpenSSL
Packit c4476c
 libraries. Referring to system documentation would suffice, if not for
Packit c4476c
 a corner case. On AIX static libraries (in shared build) are named
Packit c4476c
 differently, add _a suffix to link with them, e.g. -lcrypto_a.