Repository: spack/spack

Issue:
"linker was not configured to use sysroots"
I want to install `gcc` on Ubuntu 14.04. `gcc`'s dependencies installed fine, but `gcc` itself doesn't build. I see this error message that I don't understand. Have you seen it before, or can you give me a pointer?

The system has gcc 4.9.2 installed; I am trying to install gcc 5.2 via Spack. This looks as if it was using Spack's `binutils` package.

Google didn't find any good answers. Apart from "don't mess with your system", there is one message suggesting to build `ld` with the `--with-sysroot` option. However, `--with-sysroot` expects a path as argument, and it's unclear to me what argument that could be. I also don't understand what Spack is trying to achieve by using the `--sysroot` argument.

```
configure:4370: checking for C compiler default output file name
configure:4392: /xfs1/eschnetter/src/spack/lib/spack/env/cc    conftest.c  >&5 /xfs1/eschnetter/src/spack/opt/spack/linux-x86_64/gcc-4.9.2/binutils-2.25-gqbrzkvzz2q236u5tkyo7uxn2u5i5b4q/bin/ld: this linker was not configured to use sysroots
collect2: error: ld returned 1 exit status
```



Discussion:
@tgamblin , @mplegendre : I think the issue stems from the configuration of system `gcc` in Ubuntu, which has `--with-sysroot=/`

```
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.9.3-8ubuntu2~14.04' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.9.3 (Ubuntu 4.9.3-8ubuntu2~14.04) 
```

I'll try to see if I can find a way to employ the default linker for whatever compiler we are using in stage 1. Does it seem reasonable to you?

I was able to reproduce this via travis: https://travis-ci.org/tgamblin/spack/builds/95503933, even after @mplegendre's #203 (not surprising but I thought I'd try).  

I need to get an Ubuntu VM set up on my machine to really try it out.  Ubuntu seems to fail in weird ways that RHEL does not.

@alalazo: I'm not sure this has to do with the system linker, but I could be wrong.  Because `gcc` depends on `binutils`, `ld` from `binutils` in in the `PATH` when the build happens, and it seems to me that the error could be coming from something wrong with the `binutils` build.  If you want to take a stab at this while I'm getting set up, be my guest.

@tgamblin: I am quite sure it's the `binutils` build. In fact, it seems that having a system compiler configured with `--with-sysroot=/` creates an incompatibility when using a `binutils` that was not configured the same.


Resolving patch:
diff --git a/var/spack/packages/binutils/package.py b/var/spack/packages/binutils/package.py
--- a/var/spack/packages/binutils/package.py
+++ b/var/spack/packages/binutils/package.py
@@ -20,7 +20,8 @@ def install(self, spec, prefix):
             '--enable-multilib',
             '--enable-shared',
             '--enable-64-bit-bfd',
-            '--enable-targets=all']
+            '--enable-targets=all',
+            '--with-sysroot=/']
 
         if '+libiberty' in spec:
             configure_args.append('--enable-install-libiberty')
diff --git a/var/spack/packages/gcc/package.py b/var/spack/packages/gcc/package.py
--- a/var/spack/packages/gcc/package.py
+++ b/var/spack/packages/gcc/package.py
@@ -38,6 +38,7 @@ class Gcc(Package):
 
     DEPENDS_ON_ISL_PREDICATE = '@5.0:'
 
+    version('5.3.0', 'c9616fd448f980259c31de613e575719')
     version('5.2.0', 'a51bcfeb3da7dd4c623e27207ed43467')
     version('4.9.3', '6f831b4d251872736e8e9cc09746f327')
     version('4.9.2', '4df8ee253b7f3863ad0b86359cd39c43')
@@ -80,7 +81,8 @@ def install(self, spec, prefix):
                    "--with-quad"]
         # Binutils
         static_bootstrap_flags = "-static-libstdc++ -static-libgcc"
-        binutils_options = ["--with-stage1-ldflags=%s %s" % (self.rpath_args, static_bootstrap_flags),
+        binutils_options = ["--with-sysroot=/",
+                            "--with-stage1-ldflags=%s %s" % (self.rpath_args, static_bootstrap_flags),
                             "--with-boot-ldflags=%s %s"   % (self.rpath_args, static_bootstrap_flags),
                             "--with-ld=%s/bin/ld" % spec['binutils'].prefix,
                             "--with-as=%s/bin/as" % spec['binutils'].prefix]
@@ -90,9 +92,10 @@ def install(self, spec, prefix):
             isl_options = ["--with-isl=%s" % spec['isl'].prefix]
             options.extend(isl_options)
 
-        with working_dir('spack-build', create=True):
+        build_dir = join_path(self.stage.path, 'spack-build')
+        configure = Executable( join_path(self.stage.source_path, 'configure') )
+        with working_dir(build_dir, create=True):
             # Rest of install is straightforward.
-            configure = Executable('../configure')
             configure(*options)
             make()
             make("install")


Test patch: