1*b077aed3SPierre ProncheryNotes for UNIX-like platforms 2*b077aed3SPierre Pronchery============================= 3*b077aed3SPierre Pronchery 4*b077aed3SPierre Pronchery For Unix/POSIX runtime systems on Windows, 5*b077aed3SPierre Pronchery please see the [Notes for Windows platforms](NOTES-WINDOWS.md). 6*b077aed3SPierre Pronchery 7*b077aed3SPierre Pronchery OpenSSL uses the compiler to link programs and shared libraries 8*b077aed3SPierre Pronchery --------------------------------------------------------------- 9*b077aed3SPierre Pronchery 10*b077aed3SPierre Pronchery OpenSSL's generated Makefile uses the C compiler command line to 11*b077aed3SPierre Pronchery link programs, shared libraries and dynamically loadable shared 12*b077aed3SPierre Pronchery objects. Because of this, any linking option that's given to the 13*b077aed3SPierre Pronchery configuration scripts MUST be in a form that the compiler can accept. 14*b077aed3SPierre Pronchery This varies between systems, where some have compilers that accept 15*b077aed3SPierre Pronchery linker flags directly, while others take them in `-Wl,` form. You need 16*b077aed3SPierre Pronchery to read your compiler documentation to figure out what is acceptable, 17*b077aed3SPierre Pronchery and `ld(1)` to figure out what linker options are available. 18*b077aed3SPierre Pronchery 19*b077aed3SPierre Pronchery Shared libraries and installation in non-default locations 20*b077aed3SPierre Pronchery ---------------------------------------------------------- 21*b077aed3SPierre Pronchery 22*b077aed3SPierre Pronchery Every Unix system has its own set of default locations for shared 23*b077aed3SPierre Pronchery libraries, such as `/lib`, `/usr/lib` or possibly `/usr/local/lib`. If 24*b077aed3SPierre Pronchery libraries are installed in non-default locations, dynamically linked 25*b077aed3SPierre Pronchery binaries will not find them and therefore fail to run, unless they get 26*b077aed3SPierre Pronchery a bit of help from a defined runtime shared library search path. 27*b077aed3SPierre Pronchery 28*b077aed3SPierre Pronchery For OpenSSL's application (the `openssl` command), our configuration 29*b077aed3SPierre Pronchery scripts do NOT generally set the runtime shared library search path for 30*b077aed3SPierre Pronchery you. It's therefore advisable to set it explicitly when configuring, 31*b077aed3SPierre Pronchery unless the libraries are to be installed in directories that you know 32*b077aed3SPierre Pronchery to be in the default list. 33*b077aed3SPierre Pronchery 34*b077aed3SPierre Pronchery Runtime shared library search paths are specified with different 35*b077aed3SPierre Pronchery linking options depending on operating system and versions thereof, and 36*b077aed3SPierre Pronchery are talked about differently in their respective documentation; 37*b077aed3SPierre Pronchery variations of RPATH are the most usual (note: ELF systems have two such 38*b077aed3SPierre Pronchery tags, more on that below). 39*b077aed3SPierre Pronchery 40*b077aed3SPierre Pronchery Possible options to set the runtime shared library search path include 41*b077aed3SPierre Pronchery the following: 42*b077aed3SPierre Pronchery 43*b077aed3SPierre Pronchery -Wl,-rpath,/whatever/path # Linux, *BSD, etc. 44*b077aed3SPierre Pronchery -R /whatever/path # Solaris 45*b077aed3SPierre Pronchery -Wl,-R,/whatever/path # AIX (-bsvr4 is passed internally) 46*b077aed3SPierre Pronchery -Wl,+b,/whatever/path # HP-UX 47*b077aed3SPierre Pronchery -rpath /whatever/path # Tru64, IRIX 48*b077aed3SPierre Pronchery 49*b077aed3SPierre Pronchery OpenSSL's configuration scripts recognise all these options and pass 50*b077aed3SPierre Pronchery them to the Makefile that they build. (In fact, all arguments starting 51*b077aed3SPierre Pronchery with `-Wl,` are recognised as linker options.) 52*b077aed3SPierre Pronchery Please note that 'l' in '-Wl' is lowercase L and not 1. 53*b077aed3SPierre Pronchery 54*b077aed3SPierre Pronchery Please do not use verbatim directories in your runtime shared library 55*b077aed3SPierre Pronchery search path! Some OpenSSL config targets add an extra directory level 56*b077aed3SPierre Pronchery for multilib installations. To help with that, the produced Makefile 57*b077aed3SPierre Pronchery includes the variable LIBRPATH, which is a convenience variable to be 58*b077aed3SPierre Pronchery used with the runtime shared library search path options, as shown in 59*b077aed3SPierre Pronchery this example: 60*b077aed3SPierre Pronchery 61*b077aed3SPierre Pronchery $ ./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl \ 62*b077aed3SPierre Pronchery '-Wl,-rpath,$(LIBRPATH)' 63*b077aed3SPierre Pronchery 64*b077aed3SPierre Pronchery On modern ELF based systems, there are two runtime search paths tags to 65*b077aed3SPierre Pronchery consider, `DT_RPATH` and `DT_RUNPATH`. Shared objects are searched for in 66*b077aed3SPierre Pronchery this order: 67*b077aed3SPierre Pronchery 68*b077aed3SPierre Pronchery 1. Using directories specified in DT_RPATH, unless DT_RUNPATH is also set. 69*b077aed3SPierre Pronchery 2. Using the environment variable LD_LIBRARY_PATH 70*b077aed3SPierre Pronchery 3. Using directories specified in DT_RUNPATH. 71*b077aed3SPierre Pronchery 4. Using system shared object caches and default directories. 72*b077aed3SPierre Pronchery 73*b077aed3SPierre Pronchery This means that the values in the environment variable `LD_LIBRARY_PATH` 74*b077aed3SPierre Pronchery won't matter if the library is found in the paths given by `DT_RPATH` 75*b077aed3SPierre Pronchery (and `DT_RUNPATH` isn't set). 76*b077aed3SPierre Pronchery 77*b077aed3SPierre Pronchery Exactly which of `DT_RPATH` or `DT_RUNPATH` is set by default appears to 78*b077aed3SPierre Pronchery depend on the system. For example, according to documentation, 79*b077aed3SPierre Pronchery `DT_RPATH` appears to be deprecated on Solaris in favor of `DT_RUNPATH`, 80*b077aed3SPierre Pronchery while on Debian GNU/Linux, either can be set, and `DT_RPATH` is the 81*b077aed3SPierre Pronchery default at the time of writing. 82*b077aed3SPierre Pronchery 83*b077aed3SPierre Pronchery How to choose which runtime search path tag is to be set depends on 84*b077aed3SPierre Pronchery your system, please refer to ld(1) for the exact information on your 85*b077aed3SPierre Pronchery system. As an example, the way to ensure the `DT_RUNPATH` is set on 86*b077aed3SPierre Pronchery Debian GNU/Linux systems rather than DT_RPATH is to tell the linker to 87*b077aed3SPierre Pronchery set new dtags, like this: 88*b077aed3SPierre Pronchery 89*b077aed3SPierre Pronchery $ ./Configure --prefix=/usr/local/ssl --openssldir=/usr/local/ssl \ 90*b077aed3SPierre Pronchery '-Wl,--enable-new-dtags,-rpath,$(LIBRPATH)' 91*b077aed3SPierre Pronchery 92*b077aed3SPierre Pronchery It might be worth noting that some/most ELF systems implement support 93*b077aed3SPierre Pronchery for runtime search path relative to the directory containing current 94*b077aed3SPierre Pronchery executable, by interpreting `$ORIGIN` along with some other internal 95*b077aed3SPierre Pronchery variables. Consult your system documentation. 96*b077aed3SPierre Pronchery 97*b077aed3SPierre Pronchery Linking your application 98*b077aed3SPierre Pronchery ------------------------ 99*b077aed3SPierre Pronchery 100*b077aed3SPierre Pronchery Third-party applications dynamically linked with OpenSSL (or any other) 101*b077aed3SPierre Pronchery shared library face exactly the same problem with non-default locations. 102*b077aed3SPierre Pronchery The OpenSSL config options mentioned above might or might not have bearing 103*b077aed3SPierre Pronchery on linking of the target application. "Might" means that under some 104*b077aed3SPierre Pronchery circumstances it would be sufficient to link with OpenSSL shared library 105*b077aed3SPierre Pronchery "naturally", i.e. with `-L/whatever/path -lssl -lcrypto`. But there are 106*b077aed3SPierre Pronchery also cases when you'd have to explicitly specify runtime search path 107*b077aed3SPierre Pronchery when linking your application. Consult your system documentation and use 108*b077aed3SPierre Pronchery above section as inspiration... 109*b077aed3SPierre Pronchery 110*b077aed3SPierre Pronchery Shared OpenSSL builds also install static libraries. Linking with the 111*b077aed3SPierre Pronchery latter is likely to require special care, because linkers usually look 112*b077aed3SPierre Pronchery for shared libraries first and tend to remain "blind" to static OpenSSL 113*b077aed3SPierre Pronchery libraries. Referring to system documentation would suffice, if not for 114*b077aed3SPierre Pronchery a corner case. On AIX static libraries (in shared build) are named 115*b077aed3SPierre Pronchery differently, add `_a` suffix to link with them, e.g. `-lcrypto_a`. 116