Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set rpath on gcc binaries during bootstrap?

Tags:

c++

linux

gcc

I am trying to build gcc 4.7.2 using a custom prefix $PREFIX

I have built and installed all the prerequisites into my prefix location, and then successfully configured, built and installed gcc.

The problem that I now have is that $PREFIX is not in the library search path, and therefore the shared libraries cannot be found.

$PREFIX/bin $ ./g++ ~/main.cpp 
$PREFIX/libexec/gcc/x86_64-suse-linux/4.7.2/cc1plus: \
    error while loading shared libraries: \
        libcloog-isl.so.1: \
           cannot open shared object file: No such file or directory

What works, but isn't ideal

If I export LD_LIBRARY_PATH=$PREFIX/lib then it works, but I'm looking for something which works without having to set environment variables.

If I use patchelf to set the RPATH on all the gcc binaries then it also works; however this involves searching out all elf binaries and iterating over them calling patchelf, I would rather have something more permanent.

What I think would be ideal for my purposes

So I'm hoping there is a way to have -Wl,-rpath,$PREFIX/lib passed to make during the build process.

Since I know the paths won't need to be changed this seems like the most robust solution, and can be also be used for when we build the next gcc version.

Is configuring the build process to hard code the RPATH possible?

What I have tried, but doesn't work

Setting LDFLAGS_FOR_TARGET prior to calling configure:

All of these fail:

export LDFLAGS_FOR_TARGET="-L$PREFIX/lib -R$PREFIX/lib" 
export LDFLAGS_FOR_TARGET="-L$PREFIX/lib" 
export LDFLAGS_FOR_TARGET="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib" 

Setting LDFLAGS prior to calling configure:

export LDFLAGS="-L$PREFIX/lib -Wl,-rpath,$PREFIX/lib" 

In any event I worry that these will override any of the LDFLAGS gcc would have had, so I'm not sure these are a viable option even if they could be made to work?

My configure line

For completeness here is the line I pass to configure:

./configure \
    --prefix=$PREFIX \
    --build=x86_64-suse-linux \
    --with-pkgversion='SIG build 12/10/2012' \
    --disable-multilib \
    --enable-cloog-backend=isl \
    --with-mpc=$PREFIX \
    --with-mpfr=$PREFIX \
    --with-gmp=$PREFIX \
    --with-cloog=$PREFIX \
    --with-ppl=$PREFIX \
    --with-gxx-include-dir=$PREFIX/include/c++/4.7.2
like image 417
Steve Lorimer Avatar asked Dec 11 '12 04:12

Steve Lorimer


People also ask

What is Rpath in GCC?

In computing, rpath designates the run-time search path hard-coded in an executable file or library. Dynamic linking loaders use the rpath to find required libraries. Specifically, it encodes a path to shared libraries into the header of an executable (or another shared library).

How do I specify an Rpath?

To create an RPATH entry, you simply tell it to the linker (not the compiler!), so for instance you could add to your ./configure call the string LDFLAGS=-Wl,-rpath,/my/software/base/my/lib/. libs to build and run against a specific version of your library.

How do you make a Libgcc?

How to build libgcc. You need to invoke the all-target-libgcc and install-target-libgcc make targets while building your GCC Cross-Compiler to build and install libgcc along with your cross-compiler. A static library called libgcc. a is installed into your compiler prefix along with the other compiler-specific files.


1 Answers

I've found that copying the source directories for gmp, mpfr, mpc, isl, cloog, etc. into the top level gcc source directory (or using symbolic links with the same name) works everywhere. This is in fact the preferred way.

You need to copy (or link) to those source directory names without the version numbers for this to work.

The compilers do not need LD_LIBRARY_PATH (although running applications built with the compilers will need an LD_LIBRARY_PATH to the $PREFIX/lib64 or something like that - but that's different)

Start in a source directory where you'll keep all your sources. In this source directory you have your gcc directory either by unpacking a tarball or svn... I use subversion.

Also in this top level directory you have, say, the following source tarballs:

gmp-5.1.0.tar.bz2
mpfr-3.1.1.tar.bz2
mpc-1.0.1.tar.gz
isl-0.11.1.tar.bz2
cloog-0.18.0.tar.gz

I just download these and update to the latest tarballs periodically.

In script form:

# Either:
svn checkout svn://gcc.gnu.org/svn/gcc/trunk gcc_work
# Or:
bunzip -c gcc-4.8.0.tar.bz2 | tar -xvf -
mv gcc-4.8.0 gcc_work

#  Uncompress sources..  (This will produce version numbered directories).
bunzip -c gmp-5.1.0.tar.bz2 | tar -xvf -
bunzip -c mpfr-3.1.1.tar.bz2 | tar -xvf -
gunzip -c mpc-1.0.1.tar.gz | tar -xvf -
bunzip -c isl-0.11.1.tar.bz2 | tar -xvf -
gunzip -c cloog-0.18.0.tar.gz | tar -xvf -

# Link outside source directories into the top level gcc directory.
cd gcc_work
ln -s ../gmp-5.1.0 gmp
ln -s ../mpfr-3.1.1 mpfr
ln -s ../mpc-1.0.1 mpc
ln -s ../isl-0.11.1 isl
ln -s ../cloog-0.18.0 cloog

# Get out of the gcc working directory and create a build directory.  I call mine obj_work.
# I configure the gcc binary and other outputs to be bin_work in the top level directory.  Your choice.  But I have this:
# home/ed/projects
# home/ed/projects/gcc_work
# home/ed/projects/obj_work
# home/ed/projects/bin_work
# home/ed/projects/gmp-5.1.0
# home/ed/projects/mpfr-3.1.1
# home/ed/projects/mpc-1.0.1
# home/ed/projects/isl-0.11.1
# home/ed/projects/cloog-0.18.0

mkdir obj_work
cd obj_work
../gcc_work/configure --prefix=../bin_work <other options>

# Your <other options> shouldn't need to involve anything about gmp, mpfr, mpc, isl, cloog.
# The gcc build system will find the directories you linked,
# then configure and compile the needed libraries with the necessary flags and such.
# Good luck.
like image 86
emsr Avatar answered Sep 25 '22 01:09

emsr