Repository: spack/spack

Issue:
Installation issue: binutils
### Steps to reproduce the issue

```console
$ spack spec -I binutils
Input spec
--------------------------------
 -   binutils

Concretized
--------------------------------
 -   binutils@2.40%apple-clang@13.1.6~gprofng~headers~interwork~ld~libiberty~lto~nls~pgo+plugins build_system=autotools libs=shared,static arch=darwin-ventura-skylake
[+]      ^diffutils@3.8%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]          ^libiconv@1.17%apple-clang@13.1.6 build_system=autotools libs=shared,static arch=darwin-ventura-skylake
[+]      ^texinfo@7.0%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]          ^gettext@0.21.1%apple-clang@13.1.6+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=darwin-ventura-skylake
[+]              ^bzip2@1.0.8%apple-clang@13.1.6~debug~pic+shared build_system=generic arch=darwin-ventura-skylake
[+]              ^libxml2@2.10.3%apple-clang@13.1.6~python build_system=autotools arch=darwin-ventura-skylake
[+]              ^tar@1.34%apple-clang@13.1.6 build_system=autotools zip=pigz arch=darwin-ventura-skylake
[+]                  ^pigz@2.7%apple-clang@13.1.6 build_system=makefile arch=darwin-ventura-skylake
[+]                  ^zstd@1.5.2%apple-clang@13.1.6+programs build_system=makefile compression=none libs=shared,static arch=darwin-ventura-skylake
[+]              ^xz@5.4.1%apple-clang@13.1.6~pic build_system=autotools libs=shared,static arch=darwin-ventura-skylake
[+]          ^ncurses@6.4%apple-clang@13.1.6~symlinks+termlib abi=none build_system=autotools arch=darwin-ventura-skylake
[+]              ^pkgconf@1.8.0%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]          ^perl@5.36.0%apple-clang@13.1.6+cpanm+open+shared+threads build_system=generic arch=darwin-ventura-skylake
[+]              ^berkeley-db@18.1.40%apple-clang@13.1.6+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=darwin-ventura-skylake
[+]              ^gdbm@1.23%apple-clang@13.1.6 build_system=autotools arch=darwin-ventura-skylake
[+]                  ^readline@8.2%apple-clang@13.1.6 build_system=autotools patches=bbf97f1 arch=darwin-ventura-skylake
[+]      ^zlib@1.2.13%apple-clang@13.1.6+optimize+pic+shared build_system=makefile arch=darwin-ventura-skylake
```


### Error message

<details><summary>Error message</summary>

<pre>$ spack install --jobs 1 binutils
[...]
==> binutils: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j1' 'V=1'
 
6 errors found in build log:
     2498    /bin/sh ./libtool  --tag=CC   --mode=link /Users/pnanda/src/spack-vanilla/lib/spack/env/clang/clang -std=gnu99 -Wall -W -Wall -Wno-narrowing -Wwrite-strings -Wmissing-format-attribute -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -pedantic -Wno-long-long   -g -O2     -version-info 0:0:0  -export-symbols-regex ctf_.*  -o libctf-nobfd.la -rpath /Users/pnanda/src/spack-vanilla/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/binutils-2.40-uxdvmda6dkfokfbe4dwahfc62kdnfw3c/lib libctf_nobfd_la-ctf-archive.lo libctf_nobfd_la-ctf-dump.lo libctf_nobfd_la-ctf-create.lo libctf_nobfd_la-ctf-decl.lo libctf_nobfd_la-ctf-error.lo libctf_nobfd_la-ctf-hash.lo libctf_nobfd_la-ctf-labels.lo libctf_nobfd_la-ctf-dedup.lo libctf_nobfd_la-ctf-link.lo libctf_nobfd_la-ctf-lookup.lo libctf_nobfd_la-ctf-open.lo libctf_nobfd_la-ctf-serialize.lo libctf_nobfd_la-ctf-sha1.lo libctf_nobfd_la-ctf-string.lo libctf_nobfd_la-ctf-subr.lo libctf_nobfd_la-ctf-types.lo libctf_nobfd_la-ctf-util.lo  -L/private/var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-binutils-2.40-uxdvmda6dkfokfbe4dwahfc62kdnfw3c/spack-src/libctf/../libiberty/pic -liberty  -lz
     2499    libtool: link: /opt/local/bin/nm -B  .libs/libctf_nobfd_la-ctf-archive.o .libs/libctf_nobfd_la-ctf-dump.o .libs/libctf_nobfd_la-ctf-create.o .libs/libctf_nobfd_la-ctf-decl.o .libs/libctf_nobfd_la-ctf-error.o .libs/libctf_nobfd_la-ctf-hash.o .libs/libctf_nobfd_la-ctf-labels.o .libs/libctf_nobfd_la-ctf-dedup.o .libs/libctf_nobfd_la-ctf-link.o .libs/libctf_nobfd_la-ctf-lookup.o .libs/libctf_nobfd_la-ctf-open.o .libs/libctf_nobfd_la-ctf-serialize.o .libs/libctf_nobfd_la-ctf-sha1.o .libs/libctf_nobfd_la-ctf-string.o .libs/libctf_nobfd_la-ctf-subr.o .libs/libctf_nobfd_la-ctf-types.o .libs/libctf_nobfd_la-ctf-util.o   | sed -n -e 's/^.*[	 ]\([ABCDGIRSTW][ABCDGIRSTW]*\)[	 ][	 ]*_\([_A-Za-z][_A-Za-z0-9]*\)$/\1 _\2 \2/p' | /usr/bin/sed 's/.* //' | sort | uniq > .libs/libctf-nobfd.exp
     2500    libtool: link: /usr/bin/grep -E -e "ctf_.*" ".libs/libctf-nobfd.exp" > ".libs/libctf-nobfd.expT"
     2501    libtool: link: mv -f ".libs/libctf-nobfd.expT" ".libs/libctf-nobfd.exp"
     2502    libtool: link: sed 's,^,_,' < .libs/libctf-nobfd.exp > .libs/libctf-nobfd-symbols.expsym
     2503    libtool: link: /Users/pnanda/src/spack-vanilla/lib/spack/env/clang/clang -dynamiclib  -o .libs/libctf-nobfd.0.dylib  .libs/libctf_nobfd_la-ctf-archive.o .libs/libctf_nobfd_la-ctf-dump.o .libs/libctf_nobfd_la-ctf-create.o .libs/libctf_nobfd_la-ctf-decl.o .libs/libctf_nobfd_la-ctf-error.o .libs/libctf_nobfd_la-ctf-hash.o .libs/libctf_nobfd_la-ctf-labels.o .libs/libctf_nobfd_la-ctf-dedup.o .libs/libctf_nobfd_la-ctf-link.o .libs/libctf_nobfd_la-ctf-lookup.o .libs/libctf_nobfd_la-ctf-open.o .libs/libctf_nobfd_la-ctf-serialize.o .libs/libctf_nobfd_la-ctf-sha1.o .libs/libctf_nobfd_la-ctf-string.o .libs/libctf_nobfd_la-ctf-subr.o .libs/libctf_nobfd_la-ctf-types.o .libs/libctf_nobfd_la-ctf-util.o   -L/private/var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-binutils-2.40-uxdvmda6dkfokfbe4dwahfc62kdnfw3c/spack-src/libctf/../libiberty/pic -liberty -lz    -install_name  /Users/pnanda/src/spack-vanilla/opt/spack/darwin-ventura-skylake/apple-clang-13.1.6/binutils-2.40-uxdvmda6dkfokfbe4dwahfc62kdnfw3c/lib/libctf-nobfd.0.dylib -compatibility_version 1 -current_version 1.0 -Wl,-single_module -Wl,-exported_symbols_list,.libs/libctf-nobfd-symbols.expsym
  >> 2504    Undefined symbols for architecture x86_64:
     2505      "_ctf_open", referenced from:
     2506          _ctf_link_add_ctf in libctf_nobfd_la-ctf-link.o
     2507          _ctf_link_deduplicating_count_inputs in libctf_nobfd_la-ctf-link.o
     2508    ld: symbol(s) not found for architecture x86_64
  >> 2509    clang: error: linker command failed with exit code 1 (use -v to see invocation)
  >> 2510    make[3]: *** [libctf-nobfd.la] Error 1
  >> 2511    make[2]: *** [all] Error 2
  >> 2512    make[1]: *** [all-libctf] Error 2
  >> 2513    make: *** [all] Error 2
 
See build log for details:
  /var/folders/sb/82r7skjn6yd9b8hsjz63npvr0000gs/T/pnanda/spack-stage/spack-stage-binutils-2.40-uxdvmda6dkfokfbe4dwahfc62kdnfw3c/spack-build-out.txt
</pre></details>


### Information on your system

* **Spack:** 0.20.0.dev0 (c0f48b30cf0cedb542f7b209a119bdfafb9a31d3)
* **Python:** 3.8.9
* **Platform:** darwin-ventura-skylake
* **Concretizer:** clingo

### Additional information

* [spack-build-out.txt](https://github.com/spack/spack/files/10886904/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/10886905/spack-build-env.txt)

@alalazo is the maintainer of binutils

Versions 2.37:2.40 of binutils fail on darwin with the above error.

Versions :2.36.1 don't suffer from this error but still fail because of missing -lintl:
```console
$ spack install binutils@2.36.1
[...]
     2182    ld: library not found for -lintl
  >> 2183    clang: error: linker command failed with exit code 1 (use -v to see invocation)
  >> 2184    make[4]: *** [libbfd.la] Error 1
  >> 2185    make[3]: *** [all-recursive] Error 1
  >> 2186    make[2]: *** [all] Error 2
  >> 2187    make[1]: *** [all-bfd] Error 2
  >> 2188    make: *** [all] Error 2
```
... and therefore need the `nls` variant enabled, which should default be enabled on "darwin" because it's not provided by libc like it is on GNU/Linux.  Alternatively the `nls` variant can be removed entirely so that the dependency on `gettext` should be forced on like `texinfo` (#34312).  PR for the former case incoming.

But I've run out of ideas about what to do next toward fixing the original _ctf_open error 🤷 so any advice appreciated.

### 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:
Correction: binutils 2.35.2 and below don't have the _ctf_open error. 2.36:2.40 are affected.
I just hit this issue too. Any ideas @alalazo?

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
@@ -33,15 +33,51 @@ class Binutils(AutotoolsPackage, GNUMirrorPackage):
     version("2.32", sha256="de38b15c902eb2725eac6af21183a5f34ea4634cb0bcef19612b50e5ed31072d")
     version("2.31.1", sha256="ffcc382695bf947da6135e7436b8ed52d991cf270db897190f19d6f9838564d0")
     version("2.30", sha256="efeade848067e9a03f1918b1da0d37aaffa0b0127a06b5e9236229851d9d0c09")
-    version("2.29.1", sha256="1509dff41369fb70aed23682351b663b56db894034773e6dbf7d5d6071fc55cc")
-    version("2.28", sha256="6297433ee120b11b4b0a1c8f3512d7d73501753142ab9e2daa13c5a3edd32a72")
-    version("2.27", sha256="369737ce51587f92466041a97ab7d2358c6d9e1b6490b3940eb09fb0a9a6ac88")
-    version("2.26", sha256="c2ace41809542f5237afc7e3b8f32bb92bc7bc53c6232a84463c423b0714ecd9")
-    version("2.25.1", sha256="b5b14added7d78a8d1ca70b5cb75fef57ce2197264f4f5835326b0df22ac9f22")
-    version("2.25", sha256="22defc65cfa3ef2a3395faaea75d6331c6e62ea5dfacfed3e2ec17b08c882923")
-    version("2.24", sha256="e5e8c5be9664e7f7f96e0d09919110ab5ad597794f5b1809871177a0f0f14137")
-    version("2.23.2", sha256="fe914e56fed7a9ec2eb45274b1f2e14b0d8b4f41906a5194eac6883cfe5c1097")
-    version("2.20.1", sha256="71d37c96451333c5c0b84b170169fdcb138bbb27397dc06281905d9717c8ed64")
+    version(
+        "2.29.1",
+        sha256="1509dff41369fb70aed23682351b663b56db894034773e6dbf7d5d6071fc55cc",
+        deprecated=True,
+    )
+    version(
+        "2.28",
+        sha256="6297433ee120b11b4b0a1c8f3512d7d73501753142ab9e2daa13c5a3edd32a72",
+        deprecated=True,
+    )
+    version(
+        "2.27",
+        sha256="369737ce51587f92466041a97ab7d2358c6d9e1b6490b3940eb09fb0a9a6ac88",
+        deprecated=True,
+    )
+    version(
+        "2.26",
+        sha256="c2ace41809542f5237afc7e3b8f32bb92bc7bc53c6232a84463c423b0714ecd9",
+        deprecated=True,
+    )
+    version(
+        "2.25.1",
+        sha256="b5b14added7d78a8d1ca70b5cb75fef57ce2197264f4f5835326b0df22ac9f22",
+        deprecated=True,
+    )
+    version(
+        "2.25",
+        sha256="22defc65cfa3ef2a3395faaea75d6331c6e62ea5dfacfed3e2ec17b08c882923",
+        deprecated=True,
+    )
+    version(
+        "2.24",
+        sha256="e5e8c5be9664e7f7f96e0d09919110ab5ad597794f5b1809871177a0f0f14137",
+        deprecated=True,
+    )
+    version(
+        "2.23.2",
+        sha256="fe914e56fed7a9ec2eb45274b1f2e14b0d8b4f41906a5194eac6883cfe5c1097",
+        deprecated=True,
+    )
+    version(
+        "2.20.1",
+        sha256="71d37c96451333c5c0b84b170169fdcb138bbb27397dc06281905d9717c8ed64",
+        deprecated=True,
+    )
 
     variant("plugins", default=True, description="enable plugins, needed for gold linker")
     # When you build ld.gold you automatically get ld, even when you add the
@@ -107,7 +143,12 @@ class Binutils(AutotoolsPackage, GNUMirrorPackage):
     # gprofng requires bison
     depends_on("bison@3.0.4:", type="build", when="+gprofng")
 
-    conflicts("+gold", when="platform=darwin", msg="Binutils cannot build linkers on macOS")
+    with when("platform=darwin"):
+        conflicts("+gold", msg="Binutils cannot build linkers on macOS")
+        conflicts(
+            "libs=shared", when="@2.37:2.40", msg="https://github.com/spack/spack/issues/35817"
+        )
+
     conflicts(
         "~lto", when="+pgo", msg="Profile-guided optimization enables link-time optimization"
     )


Test patch: