Repository: spack/spack

Issue:
Cannot install gcc: C compiler cannot create executables
When trying to install gcc using spack I get an error when compiling the actual gcc source code. I get the same error for multiple machines (our cluster and my own private laptop) and for at least versions 6.1.0 and 5.4.0.

The error is `C compiler cannot create executables` but I don't know how to fix it as in [issue 1038](https://github.com/LLNL/spack/issues/1038).

The file `spack-build.out` gives:

```
==> '/home/toon/testspack/var/spack/stage/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/gcc-6.1.0/configure' '--prefix=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6' '--libdir=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/lib64' '--disable-multilib' '--enable-languages=c,java,c++,fortran,objc,go' '--with-mpc=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpc-1.0.3-u3edu7j3u22injou273z4hizip6vhjjt' '--with-mpfr=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpfr-3.1.4-zktmbe3mgwuw3t4c3l7gb7ulnxgzd2tb' '--with-gmp=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gmp-6.1.1-36t7wx6655klu7waooeymnz46rxynaug' '--enable-lto' '--with-quad' '--with-sysroot=/' '--with-stage1-ldflags=-Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/lib64 -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gmp-6.1.1-36t7wx6655klu7waooeymnz46rxynaug/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/isl-0.14-b7nimaueyc7lzqpmdkttmecgm7srhc75/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpc-1.0.3-u3edu7j3u22injou273z4hizip6vhjjt/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpfr-3.1.4-zktmbe3mgwuw3t4c3l7gb7ulnxgzd2tb/lib -static-libstdc++ -static-libgcc' '--with-boot-ldflags=-Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gcc-6.1.0-ch6rh6557ua3p7fnrauyqswcpxqn4bt6/lib64 -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/gmp-6.1.1-36t7wx6655klu7waooeymnz46rxynaug/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/isl-0.14-b7nimaueyc7lzqpmdkttmecgm7srhc75/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpc-1.0.3-u3edu7j3u22injou273z4hizip6vhjjt/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/lib -Wl,-rpath,/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/mpfr-3.1.4-zktmbe3mgwuw3t4c3l7gb7ulnxgzd2tb/lib -static-libstdc++ -static-libgcc' '--with-gnu-ld' '--with-ld=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/bin/ld' '--with-gnu-as' '--with-as=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/bin/as' '--with-isl=/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/isl-0.14-b7nimaueyc7lzqpmdkttmecgm7srhc75'
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln works... yes
checking whether ln -s works... yes
checking for a sed that does not truncate output... /bin/sed
checking for gawk... gawk
checking for libatomic support... yes
checking for libcilkrts support... yes
checking for libitm support... yes
checking for libsanitizer support... yes
checking for libvtv support... yes
checking for libmpx support... yes
checking for gcc... /home/toon/testspack/lib/spack/env/gcc/gcc
checking for C compiler default output file name... 
configure: error: in `/tmp/toon/spack-stage/spack-stage-d1WhBG/spack-build':
configure: error: C compiler cannot create executables
See `config.log' for more details.
```

and [config.log](https://github.com/LLNL/spack/files/410994/config.log.txt) is attached. It looks like the error occurs here:

```
configure:4436: /home/toon/testspack/lib/spack/env/gcc/gcc    conftest.c  >&5
/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o: unrecognized relocation (0x2a) in section `.init'
/home/toon/testspack/opt/spack/linux-Ubuntu16-x86_64/gcc-5.4.0/binutils-2.25-e34u7ath72ak6d6sicerzub37dvhubf5/bin/ld: final link failed: Bad value
```

Do you have any idea how to solve this? Thank in advance.



Discussion:
Could this be related to your problem?

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808205

Here's more info:

https://bbs.archlinux.org/viewtopic.php?id=210340

> I reached out to Allan and he pointed out that the older glibc and gcc have relocations only recognised by newer binutils. At his suggestion, what I did was make a VM that used Arch Linux Archive to restore glibc and gcc to a state before the relocation changes. Then I was able to compile newer version of binutils using the above linked `git bisect run` script.
> Long story short. Problem is solved. Thank you for the suggestions.

You probably have an ancient `binutils` on your system, what OS and version are you running?  I would try:
1. Get Spack to install you a new `binutils`: `spack install binutils`
2. Get Spack to use the `binutils` you just installed.  Probably `spack load` it in your environment (or equivalent, use `spack module` to find the right module to load, then load it with `module load`.  This will be faster in your `.bashrc`).

Hi and thanks for the help.

We were using a (very small) ubuntu server, with binutils `GNU ld (GNU Binutils) 2.25`. But in any case, spack seems to like the version of binutils that it compiled itself, which is 2.5 as well.

Anyway, I used the module, but it gives the same error.

Do you think I have to tamper with the versions of the libraries?

Which version of Ubuntu are you running?

Can you see what happens if you add `depends_on('binutils')` to
`gcc/package.py`?

-- Elizabeth

On Mon, Aug 22, 2016 at 7:25 AM, Astran notifications@github.com wrote:

> Hi and thanks for the help.
> 
> We were using a (very small) ubuntu server, with binutils GNU ld (GNU
> Binutils) 2.25. But in any case, spack seems to like the version of
> binutils that it compiled itself, which is 2.5 as well.
> 
> Anyway, I used the module, but it gives the same error.
> 
> Do you think I have to tamper with the versions of the libraries?
> 
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> https://github.com/LLNL/spack/issues/1487#issuecomment-241384917, or mute
> the thread
> https://github.com/notifications/unsubscribe-auth/AB1cd-vOfb_ye894fdCPZHaao4YZ0plSks5qiYcNgaJpZM4JhFc1
> .

GCC already conditionally depends on binutils. @Astran just try installing `gcc+binutils`. If that works, we may just want to always build GCC with binutils.

@citibeth `gcc/package.py` contains the following lines:

```
variant('binutils',
        default=sys.platform != 'darwin',
        description="Build via binutils")
variant('gold',
        default=sys.platform != 'darwin',
        description="Build the gold linker plugin for ld-based LTO")

depends_on("mpfr")
depends_on("gmp")
depends_on("mpc", when='@4.5:')
depends_on("isl", when='@5.0:')
depends_on("binutils~libiberty", when='+binutils ~gold')
depends_on("binutils~libiberty+gold", when='+binutils +gold')
```

So I can certainly add `depends_on("binutils")` here. Would it make a difference? How do I continue after doing this?

@adamjstewart Thanks but this changes nothing, as it already conditionally depends on binutils...

Starting from a minimal Ubuntu 16.04, I first install
`apt install curl git lbzip2 python xz-utils gcc g++ make zip` (this is probably the minimal set)
and then build
`spack install gcc ~binutils`

This works fine. I don't recall why I say `~binutils`; likely there's a build error without this option.

The only package ubuntu did not have yet was `lbzip2` and I installed it. But even then, `spack install gcc ~binutils` gives the same error.

I also noticed that just changing the file `gcc/package.py` (adding the line that @citibeth suggested) indeed persists when I build it with spack. 

But sadly no solution either. Still the same error.

I have tried the mechanism I suggested earlier today. I start from a bare-bones Ubuntu 16.04 image, run `apt update` and `apt install`, download Spack, and install `gcc ~binutils`. This is on an x86-64 system. I'm using Docker to automate this. See https://github.com/eschnett/spack-test. I'm surprised that you get an error.

I assume you have additional packages installed that I didn't install, and Spack picks these up, leading to the problems you observe. Can you post the set of packages that you installed manually, on top of the base Ubuntu system?

Astran,

Hmm... looks like my suggestion led to nothing.

Which exact version of Ubuntu are you running?

Also, do you have any weird stuff "polluting" your environment when you run
Spack?  That can cause mysterious problems.  Best to start from a clean
environment; for example, the default when you create a new user on your
system.

-- Elizabeth

On Mon, Aug 22, 2016 at 9:25 AM, Astran notifications@github.com wrote:

> The only package ubuntu did not have yet was lbzip2 and I installed it.
> But even then, spack install gcc ~binutils gives the same error.
> 
> I also noticed that just changing the file gcc/package.py (adding the
> line that @citibeth https://github.com/citibeth suggested) indeed
> persists when I build it with spack.
> 
> But sadly no solution either. Still the same error.
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> https://github.com/LLNL/spack/issues/1487#issuecomment-241411250, or mute
> the thread
> https://github.com/notifications/unsubscribe-auth/AB1cd74CHDfmEar1Xx_tlIAXG-1mn79oks5qiaM2gaJpZM4JhFc1
> .

Hi, I ran some of the commands of @eschnett 's script and got it to compile gcc correctly in a test folder.

Then I checked why it wouldn't do the same in my own case, and it looks like there was a difference in the output from the `spack spec gcc ~binutils %"$systemcc"` command:

The output I got using @eschnett 's script was:

```
Input spec
------------------------------
  gcc%gcc@5.4.0~binutils

Normalized
------------------------------
  gcc%gcc@5.4.0~binutils
      ^gmp
          ^m4
      ^mpfr

Concretized
------------------------------
  gcc@6.2.0%gcc@5.4.0~binutils+gold arch=linux-Ubuntu16-x86_64
      ^gmp@6.1.1%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
          ^m4@1.4.17%gcc@5.4.0+sigsegv arch=linux-Ubuntu16-x86_64
              ^libsigsegv@2.10%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
      ^isl@0.14%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
      ^mpc@1.0.3%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
          ^mpfr@3.1.4%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
```

Then I checked the output from my own version:

```
Input spec
------------------------------
  gcc%gcc@5.4.0~binutils

Normalized
------------------------------
  gcc%gcc@5.4.0~binutils
      ^binutils
          ^bison
              ^m4
          ^flex
      ^gmp
      ^mpfr

Concretized
------------------------------
  gcc@6.1.0%gcc@5.4.0~binutils+gold arch=linux-Ubuntu16-x86_64
      ^binutils@2.25%gcc@5.4.0+gold~krellpatch~libiberty arch=linux-Ubuntu16-x86_64
          ^bison@3.0.4%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
              ^m4@1.4.17%gcc@5.4.0+sigsegv arch=linux-Ubuntu16-x86_64
                  ^libsigsegv@2.10%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
          ^flex@2.6.0%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
      ^gmp@6.1.1%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
      ^isl@0.14%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
      ^mpc@1.0.3%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
          ^mpfr@3.1.4%gcc@5.4.0 arch=linux-Ubuntu16-x86_64
```

So you can see that for some reason binutils is present there, while it is not for the test case. Do you know what the difference is?

Any way, pulling the latest commit fixed the entire problem.

Thanks again,

Cheers,
Toon

The issue seems to be solved. Would it be fine to close it ?

@alalazo It would be fine and indeed it is.


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py
--- a/var/spack/repos/builtin/packages/gcc/package.py
+++ b/var/spack/repos/builtin/packages/gcc/package.py
@@ -69,7 +69,7 @@ class Gcc(AutotoolsPackage):
             multi=True,
             description='Compilers and runtime libraries to build')
     variant('binutils',
-            default=sys.platform != 'darwin',
+            default=False,
             description='Build via binutils')
     variant('piclibs',
             default=False,


Test patch: