Repository: spack/spack

Issue:
Installation issue: llvm, gcc was broken during cmake stage
### Steps to reproduce the issue
run: 
```
spack install llvm
```

```console
$ spack spec -I llvm
Input spec
--------------------------------
 -   llvm

Concretized
--------------------------------
 -   llvm@16.0.0%gcc@9.5.0~clang~cuda+gold~ipo~link_llvm_dylib+lld+llvm_dylib~mlir~omp_debug~omp_tsan+polly~python~split_dwarf build_system=cmake build_type=Release generator=ninja shlib_symbol_version=none targets=none version_suffix=none arch=linux-centos7-cascadelake
[+]      ^binutils@2.40%gcc@9.5.0~gas+gold~gprofng~headers~interwork+ld~libiberty~lto~nls~pgo+plugins build_system=autotools libs=shared,static arch=linux-centos7-cascadelake
[+]          ^diffutils@3.9%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]              ^libiconv@1.17%gcc@9.5.0 build_system=autotools libs=shared,static arch=linux-centos7-cascadelake
[+]          ^texinfo@7.0%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]      ^cmake@3.26.1%gcc@9.5.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-centos7-cascadelake
[+]          ^ncurses@6.4%gcc@9.5.0~symlinks+termlib abi=none build_system=autotools arch=linux-centos7-cascadelake
[+]          ^openssl@1.1.1t%gcc@9.5.0~docs~shared build_system=generic certs=mozilla arch=linux-centos7-cascadelake
[+]              ^ca-certificates-mozilla@2023-01-10%gcc@9.5.0 build_system=generic arch=linux-centos7-cascadelake
[+]      ^hwloc@2.9.0%gcc@9.5.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-centos7-cascadelake
[+]          ^libpciaccess@0.17%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]              ^libtool@2.4.7%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]                  ^m4@1.4.19%gcc@9.5.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-centos7-cascadelake
[+]                      ^libsigsegv@2.14%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]              ^util-macros@1.19.3%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]          ^libxml2@2.10.3%gcc@9.5.0~python build_system=autotools arch=linux-centos7-cascadelake
[+]      ^ninja@1.11.1%gcc@9.5.0+re2c build_system=generic arch=linux-centos7-cascadelake
[+]          ^re2c@2.2%gcc@9.5.0 build_system=generic arch=linux-centos7-cascadelake
[+]      ^perl-data-dumper@2.173%gcc@9.5.0 build_system=perl arch=linux-centos7-cascadelake
[+]          ^perl@5.36.0%gcc@9.5.0+cpanm+open+shared+threads build_system=generic arch=linux-centos7-cascadelake
[+]              ^berkeley-db@18.1.40%gcc@9.5.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-centos7-cascadelake
[+]      ^pkgconf@1.8.0%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]      ^python@3.10.10%gcc@9.5.0+bz2+crypt+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tkinter+uuid+zlib build_system=generic patches=0d98e93,7d40923,f2fd060 arch=linux-centos7-cascadelake
[+]          ^bzip2@1.0.8%gcc@9.5.0~debug~pic+shared build_system=generic arch=linux-centos7-cascadelake
[+]          ^expat@2.5.0%gcc@9.5.0+libbsd build_system=autotools arch=linux-centos7-cascadelake
[+]              ^libbsd@0.11.7%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]                  ^libmd@1.0.4%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]          ^gdbm@1.23%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]          ^gettext@0.21.1%gcc@9.5.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-centos7-cascadelake
[+]              ^tar@1.34%gcc@9.5.0 build_system=autotools zip=pigz arch=linux-centos7-cascadelake
[+]                  ^pigz@2.7%gcc@9.5.0 build_system=makefile arch=linux-centos7-cascadelake
[+]                  ^zstd@1.5.4%gcc@9.5.0~ipo+programs build_system=cmake build_type=RelWithDebInfo compression=none generator=make libs=shared,static arch=linux-centos7-cascadelake
[+]                      ^gmake@4.4.1%gcc@9.5.0~guile build_system=autotools arch=linux-centos7-cascadelake
[+]          ^libffi@3.4.4%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]          ^libxcrypt@4.4.33%gcc@9.5.0~obsolete_api build_system=autotools arch=linux-centos7-cascadelake
[+]          ^readline@8.2%gcc@9.5.0 build_system=autotools patches=bbf97f1 arch=linux-centos7-cascadelake
[+]          ^sqlite@3.40.1%gcc@9.5.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-centos7-cascadelake
[+]          ^util-linux-uuid@2.38.1%gcc@9.5.0 build_system=autotools arch=linux-centos7-cascadelake
[+]          ^xz@5.4.1%gcc@9.5.0~pic build_system=autotools libs=shared,static arch=linux-centos7-cascadelake
[+]      ^zlib@1.2.13%gcc@9.5.0+optimize+pic+shared build_system=makefile arch=linux-centos7-cascadelake

```


### Error message

<details><summary>Error message</summary><pre>
4 errors found in build log:
     6     -- The ASM compiler identification is GNU
     7     -- Found assembler: /share/home/duyiming/spack/lib/spack/env/gcc/gcc
     8     -- Detecting C compiler ABI info
     9     -- Detecting C compiler ABI info - failed
     10    -- Check for working C compiler: /share/home/duyiming/spack/lib/spack/env/gcc/gcc
     11    -- Check for working C compiler: /share/home/duyiming/spack/lib/spack/env/gcc/gcc - broken
  >> 12    CMake Error at /share/home/duyiming/spack/opt/spack/linux-centos7-cascadelake/gcc-9.5.0/cmake-3.26.1-z6jwygy6dxsw6aylduylezonwutfjsry/s
           hare/cmake-3.26/Modules/CMakeTestCCompiler.cmake:67 (message):
     13      The C compiler
     14    
     15        "/share/home/duyiming/spack/lib/spack/env/gcc/gcc"
     16    
     17      is not able to compile a simple test program.
     18    
     19      It fails with the following output:
     20    
     21        Change Dir: /tmp/duyiming/spack-stage/spack-stage-llvm-16.0.0-cfxo5mw3zhl3a65lb33qahozai46fs3z/spack-build-cfxo5mw/CMakeFiles/CMake
           Scratch/TryCompile-oueISC
     22    
     23        Run Build Command(s):/share/home/duyiming/spack/opt/spack/linux-centos7-cascadelake/gcc-9.5.0/ninja-1.11.1-sk2s5lqsumspp5v7xfqkjgdi
           kr3uc7i3/bin/ninja-build -v cmTC_58f89 && [1/2] /share/home/duyiming/spack/lib/spack/env/gcc/gcc    -o CMakeFiles/cmTC_58f89.dir/testCC
           ompiler.c.o -c /tmp/duyiming/spack-stage/spack-stage-llvm-16.0.0-cfxo5mw3zhl3a65lb33qahozai46fs3z/spack-build-cfxo5mw/CMakeFiles/CMakeS
           cratch/TryCompile-oueISC/testCCompiler.c
     24        [2/2] : && /share/home/duyiming/spack/lib/spack/env/gcc/gcc   CMakeFiles/cmTC_58f89.dir/testCCompiler.c.o -o cmTC_58f89   && :
  >> 25    FAILED: cmTC_58f89
     26        : && /share/home/duyiming/spack/lib/spack/env/gcc/gcc   CMakeFiles/cmTC_58f89.dir/testCCompiler.c.o -o cmTC_58f89   && :
  >> 27        /share/home/duyiming/spack/opt/spack/linux-centos7-cascadelake/gcc-9.5.0/binutils-2.40-2tekwniai7zszayquggcb7ppajh4tldg/bin/ld: err
           or while loading shared libraries: libzstd.so.1: cannot open shared object file: No such file or directory
  >> 28        collect2: error: ld returned 127 exit status
     29        ninja: build stopped: subcommand failed.
</pre></details>


### Information on your system

* **Spack:** 0.20.0.dev0 (4242989f2217e13209c0634e6747e52808ac7c9d)
* **Python:** 3.6.8
* **Platform:** linux-centos7-cascadelake
* **Concretizer:** clingo

### Additional information

@haampie @trw

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
Try without binutils (I think it's llvm~gold).

Looks like for some reason your binutils build is broken. Edit: it's because binutils@2.40 added a dependency on zstd which is missing in Spack.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/binutils/package.py b/var/spack/repos/builtin/packages/binutils/package.py
--- a/var/spack/repos/builtin/packages/binutils/package.py
+++ b/var/spack/repos/builtin/packages/binutils/package.py
@@ -82,7 +82,12 @@ class Binutils(AutotoolsPackage, GNUMirrorPackage):
     # https://sourceware.org/bugzilla/show_bug.cgi?id=27482
     patch("parallel-build-2.36.patch", when="@2.36")
 
+    # compression libs for debug symbols.
+    # pkg-config is used to find zstd in gas/configure
+    depends_on("pkgconfig", type="build")
+    depends_on("zstd@1.4.0:", when="@2.40:")
     depends_on("zlib")
+
     depends_on("diffutils", type="build")
     depends_on("gettext", when="+nls")
 


Test patch: