Skip to content

Make gcc embed rpath automatically#645

Closed
certik wants to merge 2 commits intomasterfrom
gcc
Closed

Make gcc embed rpath automatically#645
certik wants to merge 2 commits intomasterfrom
gcc

Conversation

@certik
Copy link
Copy Markdown
Member

@certik certik commented Feb 18, 2015

It embeds RPATH to $ARTIFACT/lib, that way the proper libstdc++ and libgcc will
be used.

Here is "proof" that it works:

certik@redhawk:/tmp$ cat a.c
int main()
{
    return 0;
}
certik@redhawk:/tmp$ which g++
/home/certik/repos/hashstack/default/bin/g++
certik@redhawk:/tmp$ g++ a.c
certik@redhawk:/tmp$ ldd a.out 
    linux-vdso.so.1 =>  (0x00007fff12b92000)
    libstdc++.so.6 => /local/certik/bld/gcc/tonmpmygwfax/lib/libstdc++.so.6 (0x00007fee15d67000)
    libm.so.6 => /lib64/libm.so.6 (0x00007fee15ac7000)
    libgcc_s.so.1 => /local/certik/bld/gcc/tonmpmygwfax/lib/libgcc_s.so.1 (0x00007fee158b1000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fee1551d000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fee1607a000)
certik@redhawk:/tmp$ ./a.out 
certik@redhawk:/tmp$ 

It embeds RPATH to $ARTIFACT/lib, that way the proper libstdc++ and libgcc will
be used.
@ahmadia
Copy link
Copy Markdown
Contributor

ahmadia commented Feb 18, 2015

Useful. I don't see a reason not to merge this in.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

I've moved the line to a better location in the file and added a comment.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

Don't merge this yet, it doesn't seem to be working for building hashstack.

[pcre] libtool: link: unsupported hardcode properties
[pcre] libtool: link: See the libtool documentation for more information.
[pcre] libtool: link: Fatal configuration error.

I am investigating.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

So any package that uses libtool and C++ fails, it looks like the shared library is not created, but I haven't figured it out yet. CMake packages build just fine, also if I build things by hand, it works as well. Boost builds too.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

libtool and C++, curious can you send me some logs privately (or on the list) to dissect? I have several gcc that are patched as discussed (instead of this) and I have never had that problem.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

After lots of debugging of the gmp package, I found out the problem:

certik@redhawk:/local/certik/tmp/gmp-raasuuf2hgmg-2((a6538ff...))$ /bin/sh ./libtool --tag=CXX   --mode=link g++  -m64 -O2 -march=corei7-avx -mtune=corei7-avx -Wl,-z,noexecstack  -version-info 8:0 :4 -L/local/certik/bld/autoconf/t7wgqipufbc6/lib -Wl,-rpath=/local/certik/bld/autoconf/t7wgqipufbc6/lib -L/local/certik/bld/automake/elwjizcnljke/lib -Wl,-rpath=/local/certik/bld/automake/elwjizcnljke/lib -L/local/certik/bld/libtool/u5k4q6tyeujn/lib -Wl,-rpath=/local/certik/bld/libtool/u5k4q6tyeujn/lib -L/local/certik/bld/m4/v33ckvkruuwa/lib -Wl,-rpath=/local/certik/bld/m4/v33ckvkruuwa/lib -L/local/certik/bld/patchelf/qqzlbpi7rek7/lib -Wl,-rpath=/local/certik/bld/patchelf/qqzlbpi7rek7/lib -o libmpirxx.la -rpath /local/certik/bld/gmp/raasuuf2hgmg/lib dummy.lo cxx/isfuns.lo cxx/ismpf.lo cxx/ismpq.lo cxx/ismpz.lo cxx/ismpznw.lo cxx/osdoprnti.lo cxx/osfuns.lo cxx/osmpf.lo cxx/osmpq.lo cxx/osmpz.lo libmpir.la 
libtool: link: unsupported hardcode properties
libtool: link: See the libtool documentation for more information.
libtool: link: Fatal configuration error.
certik@redhawk:/local/certik/tmp/gmp-raasuuf2hgmg-2((a6538ff...))$ vim libtool certik@redhawk:/local/certik/tmp/gmp-raasuuf2hgmg-2((a6538ff...))$ /bin/sh ./libtool --tag=CXX   --mode=link g++  -m64 -O2 -march=corei7-avx -mtune=corei7-avx -Wl,-z,noexecstack  -version-info 8:0 :4 -L/local/certik/bld/autoconf/t7wgqipufbc6/lib -Wl,-rpath=/local/certik/bld/autoconf/t7wgqipufbc6/lib -L/local/certik/bld/automake/elwjizcnljke/lib -Wl,-rpath=/local/certik/bld/automake/elwjizcnljke/lib -L/local/certik/bld/libtool/u5k4q6tyeujn/lib -Wl,-rpath=/local/certik/bld/libtool/u5k4q6tyeujn/lib -L/local/certik/bld/m4/v33ckvkruuwa/lib -Wl,-rpath=/local/certik/bld/m4/v33ckvkruuwa/lib -L/local/certik/bld/patchelf/qqzlbpi7rek7/lib -Wl,-rpath=/local/certik/bld/patchelf/qqzlbpi7rek7/lib -o libmpirxx.la -rpath /local/certik/bld/gmp/raasuuf2hgmg/lib dummy.lo cxx/isfuns.lo cxx/ismpf.lo cxx/ismpq.lo cxx/ismpz.lo cxx/ismpznw.lo cxx/osdoprnti.lo cxx/osfuns.lo cxx/osmpf.lo cxx/osmpq.lo cxx/osmpz.lo libmpir.la 
libtool: link: (cd ".libs" && rm -f "libmpirxx.so.8" && ln -s "libmpirxx.so.8.0.0" "libmpirxx.so.8")
libtool: link: (cd ".libs" && rm -f "libmpirxx.so" && ln -s "libmpirxx.so.8.0.0" "libmpirxx.so")
libtool: link: ar cq .libs/libmpirxx.a  dummy.o cxx/isfuns.o cxx/ismpf.o cxx/ismpq.o cxx/ismpz.o cxx/ismpznw.o cxx/osdoprnti.o cxx/osfuns.o cxx/osmpf.o cxx/osmpq.o cxx/osmpz.o
libtool: link: ranlib .libs/libmpirxx.a
libtool: link: ( cd ".libs" && rm -f "libmpirxx.la" && ln -s "../libmpirxx.la" "libmpirxx.la" )

First it fails, then I change at the bottom of the (generated) libtool file

hardcode_action=

to

hardcode_action=immediate

Note that the hardcode_action is assigned twice in that file. First for C, then for CXX. It works for C, but fails for CXX.

Then it works.

So now the next step is to figure out how to make sure hardcode_action is set to immediate using the configure script. The configure script has two parts, hardcode_action for C and hardcode_action_CXX for C++. It seems the hardcode_action_CXX part is not run (because it doesn't print "checking how to hardcode library paths into programs" twice, only once for C), so the variable is empty and that's how it ends up empty in libtool.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

I have verified that with a working configuration (no PROLOGUE in the profile), the hardcode check is there twice in configure:

2015/02/18 14:39:48 - INFO: [package:run_job] checking how to hardcode library paths into programs... immediate
...
2015/02/18 14:39:48 - INFO: [package:run_job] checking how to hardcode library paths into programs... immediate

Which causes the CXX part in libtool to be moved up and the hardcode_action=immediate is assigned there twice for both C and CXX. So now we just need to figure out why the configure is behaving differently in the two cases.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

I think the C++ tests were skipped due to these lines in ./configure:

# No sense in running all these tests if we already determined that
# the CXX compiler isn't working.  Some variables (like enable_shared)
# are currently assumed to apply to all compilers on this platform,
# and will be corrupted by setting them based on a non-working compiler.
if test "$_lt_caught_CXX_error" != yes; then
...

Somehow _lt_caught_CXX_error is yes.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

You have naked "-rpath" in those libtool lines. i.e. they are not preceded by "-Wl,", they are supposed to be passed directly to ld, they wouldn't work for gcc or g++ (or gfortran for that matter). I would need to check the configure script. You say it is gmp, is it actually mpir?

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

Hadn´t seen your comment about _lt_caught_CXX_error weĺl have to go through the whole config.log to chase that.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

Ok, I think I found the problem. In the ./configure file, the following lines:

      if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
    (test "X$CXX" != "Xg++"))) ; then

test that the g++ -v works, and if so, run the C++ tests (see above). However, somehow our g++ -v compiled with this PR returns non-zero exit code, compare this:

certik@redhawk:~$ /usr/bin/g++ --version
g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

certik@redhawk:~$ /usr/bin/g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 

to this:

certik@redhawk:~$ g++ --version
g++ (GCC) 4.9.2
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

certik@redhawk:~$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/local/certik/bld/gcc/hc3bnbyc3hsf/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/local/certik/bld/gcc/hc3bnbyc3hsf --enable-checking=release --enable-languages=fortran,c,c++ --with-local-prefix=/local/certik/bld/gcc/hc3bnbyc3hsf --with-specs='%{shared:-Wl,-rpath -Wl,/local/certik/bld/gcc/hc3bnbyc3hsf/lib}%{!shared:-Wl,-rpath -Wl,/local/certik/bld/gcc/hc3bnbyc3hsf/lib}' --with-gmp=/local/certik/bld/gmp/vadkrj43wtyr --with-mpc=/local/certik/bld/mpc/sushaq7ufe2f --with-mpfr=/local/certik/bld/mpfr/vxwmnxjsshse --with-cloog=/local/certik/bld/cloog/f5p5vql5p36v --with-isl=/local/certik/bld/isl/qr4j7jaetze7 --enable-clocale=gnu --enable-__cxa_atexit --enable-shared --enable-threads=posix --disable-multilib --libdir=/local/certik/bld/gcc/hc3bnbyc3hsf/lib --with-stage1-ldflags='-L/local/certik/bld/cloog/f5p5vql5p36v/lib -Wl,-rpath=/local/certik/bld/cloog/f5p5vql5p36v/lib -L/local/certik/bld/gmp/vadkrj43wtyr/lib -Wl,-rpath=/local/certik/bld/gmp/vadkrj43wtyr/lib -L/local/certik/bld/isl/qr4j7jaetze7/lib -Wl,-rpath=/local/certik/bld/isl/qr4j7jaetze7/lib -L/local/certik/bld/mpc/sushaq7ufe2f/lib -Wl,-rpath=/local/certik/bld/mpc/sushaq7ufe2f/lib -L/local/certik/bld/mpfr/vxwmnxjsshse/lib -Wl,-rpath=/local/certik/bld/mpfr/vxwmnxjsshse/lib -L/local/certik/bld/patchelf/k3rloj265ogt/lib -Wl,-rpath=/local/certik/bld/patchelf/k3rloj265ogt/lib -L/local/certik/bld/zlib/3el5ccejre7b/lib -Wl,-rpath=/local/certik/bld/zlib/3el5ccejre7b/lib' --with-boot-ldflags='-L/local/certik/bld/cloog/f5p5vql5p36v/lib -Wl,-rpath=/local/certik/bld/cloog/f5p5vql5p36v/lib -L/local/certik/bld/gmp/vadkrj43wtyr/lib -Wl,-rpath=/local/certik/bld/gmp/vadkrj43wtyr/lib -L/local/certik/bld/isl/qr4j7jaetze7/lib -Wl,-rpath=/local/certik/bld/isl/qr4j7jaetze7/lib -L/local/certik/bld/mpc/sushaq7ufe2f/lib -Wl,-rpath=/local/certik/bld/mpc/sushaq7ufe2f/lib -L/local/certik/bld/mpfr/vxwmnxjsshse/lib -Wl,-rpath=/local/certik/bld/mpfr/vxwmnxjsshse/lib -L/local/certik/bld/patchelf/k3rloj265ogt/lib -Wl,-rpath=/local/certik/bld/patchelf/k3rloj265ogt/lib -L/local/certik/bld/zlib/3el5ccejre7b/lib -Wl,-rpath=/local/certik/bld/zlib/3el5ccejre7b/lib'
Thread model: posix
gcc version 4.9.2 (GCC) 
COMPILER_PATH=/local/certik/bld/gcc/hc3bnbyc3hsf/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/local/certik/bld/gcc/hc3bnbyc3hsf/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/:/local/certik/bld/gcc/hc3bnbyc3hsf/libexec/gcc/x86_64-unknown-linux-gnu/:/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/:/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/local/certik/intel_base/composer_xe_2015.1.133/compiler/lib/intel64/:/local/certik/intel_base/composer_xe_2015.1.133/ipp/../compiler/lib/intel64/:/local/certik/intel_base/composer_xe_2015.1.133/ipp/lib/intel64/:/local/certik/intel_base/composer_xe_2015.1.133/compiler/lib/intel64/:/local/certik/intel_base/composer_xe_2015.1.133/mkl/lib/intel64/:/local/certik/intel_base/composer_xe_2015.1.133/tbb/lib/intel64/gcc4.4/:/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /local/certik/bld/gcc/hc3bnbyc3hsf/libexec/gcc/x86_64-unknown-linux-gnu/4.9.2/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/crtbegin.o -L/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2 -L/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/local/certik/intel_base/composer_xe_2015.1.133/compiler/lib/intel64 -L/local/certik/intel_base/composer_xe_2015.1.133/ipp/../compiler/lib/intel64 -L/local/certik/intel_base/composer_xe_2015.1.133/ipp/lib/intel64 -L/local/certik/intel_base/composer_xe_2015.1.133/compiler/lib/intel64 -L/local/certik/intel_base/composer_xe_2015.1.133/mkl/lib/intel64 -L/local/certik/intel_base/composer_xe_2015.1.133/tbb/lib/intel64/gcc4.4 -L/local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/../../.. -rpath /local/certik/bld/gcc/hc3bnbyc3hsf/lib -lgcc_s -lgcc -lc -lgcc_s -lgcc /local/certik/bld/gcc/hc3bnbyc3hsf/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/crtend.o /usr/lib/../lib64/crtn.o
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

My goodness it is trying to compile instead of just giving you g++ info. What about gcc -v?

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

I see, it's the extra options being passed to the linker that are causing this, e.g. using the systemwide compiler:

certik@redhawk:~$ /usr/bin/g++ -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
certik@redhawk:~$ /usr/bin/g++ -v -Wl,-rpath -Wl,/local/certik/bld/gcc/hc3bnbyc3hsf/lib
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
COMPILER_PATH=/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/:/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/:/usr/libexec/gcc/x86_64-redhat-linux/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-shared-libgcc' '-mtune=generic'
 /usr/libexec/gcc/x86_64-redhat-linux/4.4.7/collect2 --eh-frame-hdr --build-id -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../.. -rpath /local/certik/bld/gcc/hc3bnbyc3hsf/lib -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.4.7/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crtn.o
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status

Looks like the extra configure option causes g++ to go via a different route, which then confuses the configure script.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

I don't have this problem at all with the patched version

frb15@p2n14-c /hpc/home/frb15 :module purge
frb15@p2n14-c /hpc/home/frb15 :module load gcc/4.9
frb15@p2n14-c /hpc/home/frb15 :g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/hpc/home/projects/packages/local.linux.ppc/pkg/gcc/4.9.1_at2/bin/../libexec/gcc/powerpc64-linux/4.9.1/lto-wrapper
Target: powerpc64-linux
Configured with: ../configure --build=powerpc64-linux --host=powerpc64-linux --target=powerpc64-linux --with-cpu=default64 --prefix=/usr/local/pkg/gcc/4.9.1_at2 --with-long-double-128 --enable-secureplt --enable-threads=posix --enable-languages=c,c++,fortran --enable-__cxa_atexit --enable-shared --enable-checking=release --enable-lto --enable-gnu-indirect-function --with-gmp=/usr/local/pkg/gcc/supportlibs --with-mpfr=/usr/local/pkg/gcc/supportlibs --with-mpc=/usr/local/pkg/gcc/supportlibs --with-isl=/usr/local/pkg/gcc/supportlibs --with-cloog=/usr/local/pkg/gcc/supportlibs --without-libelf --with-cpu=power7 --with-tune=power7 --with-build-time-tools=/opt/at7.0/powerpc64-linux/bin --disable-libsanitizer
Thread model: posix
gcc version 4.9.1 (GCC) 

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

I will be honest and call this a gcc bug. But did you read the rest of the thread where we turned more to wrapping the system ld as a safer route?

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

The following patch to gmp fixes the issue:

--- a/configure
+++ b/configure
@@ -18755,7 +18755,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 CC="$lt_save_CC"

       if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
-    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
+    ( (test "X$CXX" = "Xg++" && `g++ --version >/dev/null 2>&1` ) ||
     (test "X$CXX" != "Xg++"))) ; then
   ac_ext=cpp
 ac_cpp='$CXXCPP $CPPFLAGS'

So that shows where the problem is. Essentially g++ -v is reserved to return 0 exit code, unlike g++ or g++ -Wl,-rpath -Wl,/local/certik/bld/gcc/hc3bnbyc3hsf/lib, both of which return non-zero exit code. The same issue is with gcc.

Since otherwise things work, we should figure out how to patch g++ to return 0 exit code for g++ -v (and our rpath patch).

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

Similar difference is for gfortran:

certik@redhawk:~/repos/hfsolver(func_deriv)$ gfortran 
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
certik@redhawk:~/repos/hfsolver(func_deriv)$ /usr/bin/gfortran
gfortran: no input files

@ahmadia
Copy link
Copy Markdown
Contributor

ahmadia commented Feb 18, 2015

On Wed, Feb 18, 2015 at 5:33 PM, Ondřej Čertík notifications@github.com
wrote:

So that shows where the problem is. Essentially g++ -v is reserved to
return 0 exit code, unlike g++ or g++ -Wl,-rpath
-Wl,/local/certik/bld/gcc/hc3bnbyc3hsf/lib, both of which return non-zero
exit code. The same issue is with gcc.

Since otherwise things work, we should figure out how to patch g++ to
return 0 exit code for g++ -v (and our rpath patch).

I'm hoping there's a cleaner solution than this.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

@kiwifb --- I also think it's a bug in gcc. I noticed that the -rpath became naked in COLLECT_GCC_OPTIONS, but all those options look like they are for the linker, aren't they? It works otherwise. Yes, gcc -v as well as gfortran -v have the same problem.

If we go the patching route, it would be patched in the set_collect_gcc_options() function in gcc/gcc.c, essentially if the verbose_flag is on (a global variable) and no other flags are on the command line, we remove -rpath (though I don't know if -rpath goes through this function in this case).

I think it's hackish though, and since the spec modification doesn't have this problem, I would go that route. @kiwifb do you think you could send me a patch how you think it should be modified? You don't need to test it, I'll test it myself. I am a little at loss of which variables should be modified. Essentially the spec that needs to got there is just %{shared:-Wl,-rpath -Wl,${ARTIFACT}/lib}%{!shared:-Wl,-rpath -Wl,${ARTIFACT}/lib}, which seems to work per this PR, but I am not sure where exactly to put it in gcc/config/rs6000/linux64.h.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

rs6000 is ppc specific you want to spray all the subfolder of gcc/config containing linux.h/linux64.h/sysv4.h files. LFS style: http://www.linuxfromscratch.org/lfs/view/stable/chapter05/gcc-pass1.html

for file in \
 $(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
....

I don't suggest you follow what LFS does as it wouldn't work in your case.

Before I go further writing a sed line I need to know if gcc is built multilib and if not if you put everything under lib or lib64.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 18, 2015

It appears you are not multilib and you put things into "lib" I'll get to that after lunch.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 18, 2015

@kiwifb correct, no multilib, and I put (link) everything into lib. Thank you, that would be awesome.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

Hum.... I actually learned something new today. The structure is not strictly the same across architectures, a generic sed won't do. I guess if it had been as simple as I was thinking it would have been refactored already. Not impossible it will all be streamlined and refactored in the future. There is a lot of common things across several archs here but it is coded slightly differently in each one.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

I will target linux x86(_64) first what archs are we targeting?

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 19, 2015

Yes, just send a patch for x86(_64). After we test it and it works, we can add support for 32 bits, that should cover most Linux + Mac machines, wouldn't it @ahmadia? We can implement support for more later.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

No darwin won't be covered, I don't know where to poke for darwin, I have been looking on and off for sometimes, I'll try to follow a new lead now.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 19, 2015

Ok. Let's concentrate on x86_64 for now, as that I can test and use daily. We can add the rest later.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

diff -Naur i386.orig/gnu-user.h i386/gnu-user.h
--- i386.orig/gnu-user.h        2015-02-19 14:00:02.412911378 +1300
+++ i386/gnu-user.h     2015-02-19 14:01:11.623027677 +1300
@@ -79,6 +79,7 @@
     %{!static: \
       %{rdynamic:-export-dynamic} \
       -dynamic-linker %(dynamic_linker)} \
+      -rpath @@ARTIFACT@@/lib \
       %{static:-static}}"

 #undef LINK_SPEC
diff -Naur i386.orig/gnu-user64.h i386/gnu-user64.h
--- i386.orig/gnu-user64.h      2015-02-19 14:00:02.412911378 +1300
+++ i386/gnu-user64.h   2015-02-19 14:01:01.393010491 +1300
@@ -63,6 +63,7 @@
       %{" SPEC_32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER32 "} \
       %{" SPEC_64 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKER64 "} \
       %{" SPEC_X32 ":-dynamic-linker " GNU_USER_DYNAMIC_LINKERX32 "}} \
+      -rpath @@ARTIFACT@@/lib \
     %{static:-static}}"

 #undef LINK_SPEC

where @@ARTIFACT@@ has to be replaced with the right value. I haven't actually tried it myself yet but that's what I am expecting to work. The only thing I think could be wrong is the line actually needing to be moved one line down.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

I think I now have a clue for darwin - I know which file needs patching (gcc/config/darwin.h). Where to put the line is the hard bit because it looks very different from linux.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

--- darwin.h.orig       2015-02-19 14:26:30.425580680 +1300
+++ darwin.h    2015-02-19 14:27:13.495653133 +1300
@@ -256,6 +256,7 @@
      %{Zinstall_name*:-dylib_install_name %*} \
      %{keep_private_externs:%e-keep_private_externs not allowed with -dynamiclib} \
      %{private_bundle:%e-private_bundle not allowed with -dynamiclib} \
+     -rpath @@ARTIFACT@@/lib \
     } \
    %{Zall_load:-all_load} \
    %{Zallowable_client*:-allowable_client %*} \

This is gcc/config/darwin.h as before @@artifact@@ would have to be filled with the right value. This is also to be tested.

@kiwifb
Copy link
Copy Markdown

kiwifb commented Feb 19, 2015

Ate my own dog food on x86_64 with the kind of configuration used by hashdist and my patch

readelf -d a.out 

Dynamic section at offset 0xe18 contains 25 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [/home/fbissey/sandbox/local/lib]

I'll have a look at OS X later.

@ahmadia
Copy link
Copy Markdown
Contributor

ahmadia commented Feb 19, 2015

On Wed, Feb 18, 2015 at 9:49 PM, François Bissey notifications@github.com
wrote:

Ate my own dog food on x86_64 with the kind of configuration used by
hashdist and my patch

Sweet!

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 19, 2015

@kiwifb thanks! I am testing your patch at #646.

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 19, 2015

It works!!!

@certik
Copy link
Copy Markdown
Member Author

certik commented Feb 19, 2015

I am closing this in favor of #646.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants