Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile OpenSSL with relative rpath

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

$ORIGIN/../lib64

Everytime I readelf -d apps/openssl, I am getting results like the following depending on what escaping variation I tried:

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

I want to setup my rpath without using external tools like chrpath. Is it at all possible? I will basically accept anything that does not involve using external tools like chrpath (though I would already be done with that).

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

I don't mind editing the generated Makefile, which is what I have been trying last. If only I could get it to print a stupid dollar sign!!! I tried modifying LIBRPATH under the BUILDENV= block with no luck. My best results so far:

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

I have read various rpath related questions and tried various escaping and quoting tricks but nothing worked so far!

like image 210
Philippe A. Avatar asked Feb 22 '12 17:02

Philippe A.


3 Answers

In your makefile try:

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

I am assuming that the ORIGIN is a shell variable.

EDIT

I have just found an answer to your question (better late then never): You need to prevent make from interpolating variables, to do that you need to use $$ (double dolar sign):

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

I know that it works because I have tested it with my own application, enjoy :)

like image 110
sirgeorge Avatar answered Nov 11 '22 06:11

sirgeorge


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

It is quite complicated to counter shell expansion of `$$ORIGIN`` in openssl. Sooner or later, it gets expanded because of the dollar sign. If you really want to go this way, you can do it. I have found the following to work with openssl 1.0.1g on Linux. In Makefile.shared, look for this line:

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

Replace it with the following. This quoting-fu neutralize the expansion of $. The double $$ is the way to get a single dollar sign in makefiles.

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

After compiling:

readelf -d apps/openssl | grep RPATH
 0x000000000000000f (RPATH)              Library rpath: ['$ORIGIN/../lib64']
like image 2
Philippe A. Avatar answered Nov 11 '22 05:11

Philippe A.


OK I spent several hours fighting with this same issue and trying all manner of crazy escaping, at one point I was up to eight $ signs, at which point I decided that there must be another way.

In fact, it appears that there is, at least with GNU ld.

Instead of -Wl,-rpath,\\$$$\$\$\$$$\$\\\\$ or some other elder god invoking monstrosity, just do this:

echo '-rpath=$ORIGIN/../lib64' > rpathorigin
./config -Wl,@$(pwd)/rpathorigin ...

I don't see that ld.gold documents the @ flag, and I have no idea about, say, lld. But if you are using GCC and it is invoking BFD ld, the above may just work for you.

Of course, the actual path used with origin should be customized as needed, and I have no opinion on ./config vs ./Configure. But using the response file trick seems to entirely sidestep the shell/make escaping nightmare.

like image 1
acm Avatar answered Nov 11 '22 05:11

acm