How to compile openssl with relative rpath

I am trying to compile openssl 1.0.0g with the following rpath:

$ORIGIN/../lib64 

Every time I readelf -d apps/openssl , I get results similar to the following, depending on which option I avoided:

 \RIGIN/../lib64 RIGIN/../lib64 ORIGIN/../lib64 

I want to configure my rpath without using external tools like chrpath. Is it possible? I basically agree that it is not related to using external tools like chrpath (although I would already do with that).

Ideally, I would like to do this by passing parameters on the command line (any form -Wl,-rpath,$ORIGIN/../lib64 ).

I am not against editing the created Makefile, and this is what I have tried in the past. If I could get him to print a silly dollar sign! I tried modifying LIBRPATH in the BUILDENV = block with no luck. My top scores:

 LIBRPATH=$$'ORIGIN/../lib64 # result: /../lib64 LIBRPATH=$$$$'ORIGIN/../lib64 # result: 12345<pid>/../lib64 

I read various rpath related questions and tried various elusive and quoting tricks, but nothing has worked so far!

+6
source share
3 answers

In your makefile, try:

 -Wl,-rpath,${ORIGIN}/../lib64 

I assume ORIGIN is a shell variable.

EDIT

I just found the answer to your question (better late, then never): You need to prevent make from interpolating variables, for this you need to use $$ (double-dolera sign):

 -Wl,-rpath,'$$ORIGIN/../lib64' 

I know this works because I tested it with my application, enjoy :)

+7
source

I went the way. http://enchildfone.wordpress.com/2010/03/23/a-description-of-rpath-origin-ld_library_path-and-portable-linux-binaries/

It is difficult to counteract the expansion of the `$$ ORIGIN`` shell in openssl. Sooner or later, it expands due to the dollar sign. If you really want to go this route, you can do it. I found the following for working with openssl 1.0.1g on Linux. In Makefile.shared, find this line:

 DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,$(LIBRPATH)" 

Replace it with the following. This quoting-fu will neutralize the $ decomposition. Double $$ is a way to get one dollar sign in makefiles.

 DO_GNU_APP=LDFLAGS="$(CFLAGS) -Wl,-rpath,'"'$$'"ORIGIN/../lib64'" 

After compilation:

 readelf -d apps/openssl | grep RPATH 0x000000000000000f (RPATH) Library rpath: ['$ORIGIN/../lib64'] 
+2
source

I am not against editing the generated Makefile, which I am trying to make last ...

I'm not sure if you can set it using a shell variable and a relative path. I don't think ldd extends $ORIGIN to $ORIGIN/../lib64 . In this case, I think you need to use ldconfig to add $ORIGIN/../lib64 in the library search path. For more information, see finding the ldd search path in the Server Error section.

Since I'm not sure, I will give instructions anyway. You do not need to change the Makefile. Actually, I was unlucky in the past because things are overwritten and other things like CFLAGS and LDFLAGS are ignored.

Also see Build OpenSSL with RPATH? Your question and the question quoted is another question that converges on similar answers (there are no duplicates between them). But it does provide an OpenSSL dev position on RPATH. It was a personal email, so I shared the relevant data, not the whole message.

If you manage to insert $ORIGIN/../lib64 into the ELF partition and it works, please report it. Below I use /usr/local/ssl/lib for my RPATH. You should replace $ORIGIN/../lib64 with /usr/local/ssl/lib .


OpenSSL supports RPATH out of the box for BSD purposes (but not for others). From Configure:

 # Unlike other OSes (like Solaris, Linux, Tru64, IRIX) BSD run-time # linkers (tested OpenBSD, NetBSD and FreeBSD) "demand" RPATH set on # .so objects. Apparently application RPATH is not global and does # not apply to .so linked with other .so. Problem manifests itself # when libssl.so fails to load libcrypto.so. One can argue that we # should engrave this into Makefile.shared rules or into BSD-* config # lines above. Meanwhile let try to be cautious and pass -rpath to # linker only when --prefix is not /usr. if ($target =~ /^BSD\-/) { $shared_ldflag.=" -Wl,-rpath,\$(LIBRPATH)" if ($prefix !~ m|^/usr[/]*$|); } 

The easiest way to do this for OpenSSL 1.0.2 is to add it to the linker flags during configuration

 ./config -Wl,-rpath=/usr/local/ssl/lib 

You can also edit the string setting and RPATH . For example, I am working on Debian x86_64. So I opened the Configure file in the editor, copied linux-x86_64 , named it linux-x86_64-rpath and made the following change to add the -rpath parameter:

 "linux-x86_64-rpath", "gcc:-m64 -DL_ENDIAN -O3 -Wall -Wl,-rpath=/usr/local/ssl/lib:: -D_REENTRANT::-Wl,-rpath=/usr/local/ssl/lib -ldl:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL: ${x86_64_asm}:elf:dlfcn:linux-shared:-fPIC:-m64:.so.\$(SHLIB_MAJOR).\$(SHLIB_MINOR):::64", 

Above, fields 2 and 6 have been changed. They correspond to $cflag and $ldflag in the OpenSSL build system.

Then configure the new configuration:

 $ ./Configure linux-x86_64-rpath shared no-ssl2 no-ssl3 no-comp \ --openssldir=/usr/local/ssl enable-ec_nistp_64_gcc_128 

Finally, after make check the settings:

 $ readelf -d ./libssl.so | grep -i rpath 0x000000000000000f (RPATH) Library rpath: [/usr/local/ssl/lib] $ readelf -d ./libcrypto.so | grep -i rpath 0x000000000000000f (RPATH) Library rpath: [/usr/local/ssl/lib] $ readelf -d ./apps/openssl | grep -i rpath 0x000000000000000f (RPATH) Library rpath: [/usr/local/ssl/lib] 

After doing make install , then ldd will produce the expected results:

 $ ldd /usr/local/ssl/lib/libssl.so linux-vdso.so.1 => (0x00007ffceff6c000) libcrypto.so.1.0.0 => /usr/local/ssl/lib/libcrypto.so.1.0.0 (0x00007ff5eff96000) ... $ ldd /usr/local/ssl/bin/openssl linux-vdso.so.1 => (0x00007ffc30d3a000) libssl.so.1.0.0 => /usr/local/ssl/lib/libssl.so.1.0.0 (0x00007f9e8372e000) libcrypto.so.1.0.0 => /usr/local/ssl/lib/libcrypto.so.1.0.0 (0x00007f9e832c0000) ... 
0
source

Source: https://habr.com/ru/post/909107/


All Articles