Blame NOTES.UNIX

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