Repository: spack/spack

Issue:
Installation issue: elfutils
### Steps to reproduce the issue

```console
$ spack spec -I spack spec -I elfutils@0.189%gcc@11.2.0~bzip2+debuginfod+nls~xz~zstd build_system=autotools arch=linux-centos7-x86_64
Input spec
--------------------------------
 -   elfutils@0.189%gcc@11.2.0~bzip2+debuginfod+nls~xz~zstd build_system=autotools arch=linux-centos7-x86_64

Concretized
--------------------------------
 -   elfutils@0.189%gcc@11.2.0~bzip2+debuginfod+nls~xz~zstd build_system=autotools arch=linux-centos7-x86_64
[+]      ^curl@7.88.1%gcc@11.2.0~gssapi~ldap+libidn2~librtmp~libssh~libssh2~nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-centos7-x86_64
[+]          ^libidn2@2.3.4%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]              ^libunistring@1.1%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]          ^openssl@1.1.1t%gcc@11.2.0~docs~shared build_system=generic certs=mozilla arch=linux-centos7-x86_64
[+]              ^ca-certificates-mozilla@2023-01-10%gcc@11.2.0 build_system=generic arch=linux-centos7-x86_64
[+]              ^perl@5.36.0%gcc@11.2.0+cpanm+open+shared+threads build_system=generic arch=linux-centos7-x86_64
[+]                  ^berkeley-db@18.1.40%gcc@11.2.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-centos7-x86_64
[+]                  ^gdbm@1.23%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]          ^pkgconf@1.8.0%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]      ^gettext@0.21.1%gcc@11.2.0+bzip2+curses+git~libunistring+libxml2+tar+xz build_system=autotools arch=linux-centos7-x86_64
[+]          ^bzip2@1.0.8%gcc@11.2.0~debug~pic+shared build_system=generic arch=linux-centos7-x86_64
[+]          ^libiconv@1.17%gcc@11.2.0 build_system=autotools libs=shared,static arch=linux-centos7-x86_64
[+]          ^libxml2@2.10.3%gcc@11.2.0~python build_system=autotools arch=linux-centos7-x86_64
[+]          ^ncurses@6.4%gcc@11.2.0~symlinks+termlib abi=none build_system=autotools arch=linux-centos7-x86_64
[+]          ^tar@1.34%gcc@11.2.0 build_system=autotools zip=pigz arch=linux-centos7-x86_64
[+]              ^pigz@2.7%gcc@11.2.0 build_system=makefile arch=linux-centos7-x86_64
[+]          ^xz@5.4.1%gcc@11.2.0~pic build_system=autotools libs=shared,static arch=linux-centos7-x86_64
[+]      ^libarchive@3.6.2%gcc@11.2.0+iconv build_system=autotools compression=bz2lib,lz4,lzma,lzo2,zlib,zstd crypto=mbedtls libs=shared,static programs=none xar=libxml2 arch=linux-centos7-x86_64
[+]          ^lz4@1.9.4%gcc@11.2.0 build_system=makefile libs=shared,static arch=linux-centos7-x86_64
[+]          ^lzo@2.10%gcc@11.2.0 build_system=autotools libs=shared,static arch=linux-centos7-x86_64
[+]          ^mbedtls@2.28.2%gcc@11.2.0+pic build_system=makefile build_type=Release libs=static arch=linux-centos7-x86_64
[+]          ^zstd@1.5.4%gcc@11.2.0+programs build_system=makefile compression=none libs=shared,static arch=linux-centos7-x86_64
[+]      ^libmicrohttpd@0.9.70%gcc@11.2.0~https build_system=autotools arch=linux-centos7-x86_64
[+]      ^m4@1.4.19%gcc@11.2.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-centos7-x86_64
[+]          ^diffutils@3.8%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]          ^libsigsegv@2.13%gcc@11.2.0 build_system=autotools arch=linux-centos7-x86_64
[+]      ^sqlite@3.40.1%gcc@11.2.0+column_metadata+dynamic_extensions+fts~functions+rtree build_system=autotools arch=linux-centos7-x86_64
[+]          ^readline@8.2%gcc@11.2.0 build_system=autotools patches=bbf97f1 arch=linux-centos7-x86_64
[+]      ^zlib@1.2.13%gcc@11.2.0+optimize+pic+shared build_system=makefile arch=linux-centos7-x86_64
```


### Error message

<details><summary>Error message</summary><pre>

```
==> Installing elfutils-0.189-rflm2fga7fem45hsysiex7jmzs54wjoj
==> No binary for elfutils-0.189-rflm2fga7fem45hsysiex7jmzs54wjoj found: installing from source
==> Using cached archive: /home/gitlab-runner/Build/release/spack/var/spack/cache/_source-cache/archive/39/39bd8f1a338e2b7cd4abc3ff11a0eddc6e690f69578a57478d8179b4148708c8.tar.bz2
==> Ran patch() for elfutils
==> elfutils: Executing phase: 'autoreconf'
==> elfutils: Executing phase: 'configure'
==> Error: ProcessError: Command exited with status 1:
    '/tmp/gitlab-runner/spack-stage/spack-stage-elfutils-0.189-rflm2fga7fem45hsysiex7jmzs54wjoj/spack-src/configure' '--prefix=/cvmfs/sw.hsf.org/spackages7/elfutils/0.189/x86_64-centos7-gcc11.2.0-opt/rflm2' '--without-bzlib' '--without-lzma' '--without-zstd' '--with-zlib=/cvmfs/sw.hsf.org/spackages7/zlib/1.2.13/x86_64-centos7-gcc11.2.0-opt/2wmsk' 'LDFLAGS=-Wl,--no-as-needed -L/cvmfs/sw.hsf.org/spackages7/gettext/0.21.1/x86_64-centos7-gcc11.2.0-opt/4mu7e/lib -lintl' '--enable-debuginfod' '--enable-libdebuginfod'

1 error found in build log:
     133    checking for pkg-config... (cached) /bin/pkg-config
     134    checking pkg-config is at least version 0.9.0... yes
     135    checking for libmicrohttpd... yes
     136    checking for oldlibmicrohttpd... no
     137    checking for sqlite3... yes
     138    checking for libarchive... no
  >> 139    configure: error: dependencies not found, use --disable-debuginfod to disable.

```

</pre></details>
### Information on your system

```
* **Spack:** 0.20.0.dev0
* **Python:** 3.6.8
* **Platform:** linux-centos7-cascadelake
* **Concretizer:** clingo
```

### Additional information

@mwkrentel 

[spack-build-out.txt](https://github.com/spack/spack/files/11182937/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/11182936/spack-build-env.txt)

### 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:
I've also encountered this.  It is caused by the +debuginfod option requiring libarchive, but the configure script for elfutils fails to find libarchive because when using pkgconfig, it complains that libarchive requires iconv.  Here is the relevant config.log:

```
configure:13983: checking for libarchive
configure:13990: $PKG_CONFIG --exists --print-errors "libarchive >= 3.1.2"
Package iconv was not found in the pkg-config search path.
Perhaps you should add the directory containing `iconv.pc'
to the PKG_CONFIG_PATH environment variable
Package 'iconv', required by 'libarchive', not found
```
This problem prevents gdb from building.
I tried a few old revs, including 0.179 when `+debuginfod` was first added.
They all failed the same way.

@hainest   IIRC, you added `+debuginfod`.  Did this ever work?

I'm not that familiar with `pkgconfig`.
Should I blame `libarchive`, `pkgconfig` or `elfutils` or what?
Elfutils configure.ac just says this, it never mentions `iconv`.

```
PKG_CHECK_MODULES([libarchive],[libarchive >= 3.1.2],[],[enable_debuginfod=no])
```

Running into the same thing. Apart from `libarchive` there is in principle another configuration error:

```console
configure:13770: checking for libmicrohttpd
configure:13777: $PKG_CONFIG --exists --print-errors "libmicrohttpd >= 0.9.33"
configure:13780: $? = 0
configure:13794: $PKG_CONFIG --exists --print-errors "libmicrohttpd >= 0.9.33"
configure:13797: $? = 0
configure:13811: result: no
Package 'gnutls', required by 'libmicrohttpd', not found
configure:13841: checking for oldlibmicrohttpd
configure:13848: $PKG_CONFIG --exists --print-errors "libmicrohttpd < 0.9.51"
Package dependency requirement 'libmicrohttpd < 0.9.51' could not be satisfied.
Package 'libmicrohttpd' has version '0.9.70', required version is '< 0.9.51'
configure:13851: $? = 1
configure:13865: $PKG_CONFIG --exists --print-errors "libmicrohttpd < 0.9.51"
Package dependency requirement 'libmicrohttpd < 0.9.51' could not be satisfied.
Package 'libmicrohttpd' has version '0.9.70', required version is '< 0.9.51'
configure:13868: $? = 1
configure:13882: result: no
Package dependency requirement 'libmicrohttpd < 0.9.51' could not be satisfied.
Package 'libmicrohttpd' has version '0.9.70', required version is '< 0.9.51'
```
So also this would need fixing (+adding versions of `libmicrohttp` that make it possible to satisfy this constraint).
https://github.com/spack/spack/blob/cb9ae0fa77c245ca999a5478b8a37b6a1c325987/var/spack/repos/builtin/packages/elfutils/package.py#L79
Adding a suitable version for `libmicrohttpd` solves that issue. Unfortunately the `libarchive` issue is a bit more involved, and it seems to be a collection of several smaller issues:

- `libarchive` has `iconv` as `Requires.private` in its `.pc` file. This can be fixed by defining a suitable `setup_dependent_build_environment` for `libarchive` to add `iconv` to `PATH`.
- `elfutils` uses the `--static` flag when invoking `pkg-config` which apparently makes it search for a `.pc` file for `iconv` (which doesn't provide one as far as I can tell). The `pkg-config` call works without `--static` if `iconv` is on `PATH`.

I am no autotools expert, so I am really not sure if this is an issue in `libarchive` "exporting" a private dependency, or whether it is an `elfutils` issue of requiring `--static` when invoking `pkg-config`.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/elfutils/package.py b/var/spack/repos/builtin/packages/elfutils/package.py
--- a/var/spack/repos/builtin/packages/elfutils/package.py
+++ b/var/spack/repos/builtin/packages/elfutils/package.py
@@ -73,10 +73,11 @@ class Elfutils(AutotoolsPackage, SourcewarePackage):
     depends_on("zlib", type="link")
     depends_on("gettext", when="+nls")
     depends_on("m4", type="build")
+    depends_on("pkgconfig@0.9.0:", type=("build", "link"))
 
     # debuginfod has extra dependencies
-    # NB: Waiting on an elfutils patch before we can use libmicrohttpd@0.9.71
-    depends_on("libmicrohttpd@0.9.33:0.9.70", type="link", when="+debuginfod")
+    # NB: Waiting on an elfutils patch before we can use libmicrohttpd@0.9.51
+    depends_on("libmicrohttpd@0.9.33:0.9.50", type="link", when="+debuginfod")
     depends_on("libarchive@3.1.2:", type="link", when="+debuginfod")
     depends_on("sqlite@3.7.17:", type="link", when="+debuginfod")
     depends_on("curl@7.29.0:", type="link", when="+debuginfod")
@@ -85,6 +86,11 @@ class Elfutils(AutotoolsPackage, SourcewarePackage):
 
     provides("elf@1")
 
+    # libarchive with iconv doesn't configure.
+    # see https://github.com/spack/spack/issues/36710
+    # and https://github.com/libarchive/libarchive/issues/1819
+    conflicts("^libarchive@3.6.2 +iconv", when="+debuginfod")
+
     # Elfutils uses nested functions in C code, which is implemented
     # in gcc, but not in clang. C code compiled with gcc is
     # binary-compatible with clang, so it should be possible to build
diff --git a/var/spack/repos/builtin/packages/libmicrohttpd/package.py b/var/spack/repos/builtin/packages/libmicrohttpd/package.py
--- a/var/spack/repos/builtin/packages/libmicrohttpd/package.py
+++ b/var/spack/repos/builtin/packages/libmicrohttpd/package.py
@@ -16,8 +16,14 @@ class Libmicrohttpd(AutotoolsPackage):
 
     maintainers("hainest")
 
+    version("0.9.76", sha256="f0b1547b5a42a6c0f724e8e1c1cb5ce9c4c35fb495e7d780b9930d35011ceb4c")
+    version("0.9.75", sha256="9278907a6f571b391aab9644fd646a5108ed97311ec66f6359cebbedb0a4e3bb")
+    version("0.9.74", sha256="42035d0261373324bfb434018f4ab892514b10253d1af232e41b4cc2c11e650b")
+    version("0.9.73", sha256="a37b2f1b88fd1bfe74109586be463a434d34e773530fc2a74364cfcf734c032e")
+    version("0.9.72", sha256="0ae825f8e0d7f41201fd44a0df1cf454c1cb0bc50fe9d59c26552260264c2ff8")
     version("0.9.71", sha256="e8f445e85faf727b89e9f9590daea4473ae00ead38b237cf1eda55172b89b182")
     version("0.9.70", sha256="90d0a3d396f96f9bc41eb0f7e8187796049285fabef82604acd4879590977307")
+    version("0.9.50", sha256="d1b6385068abded29b6470e383287aa7705de05ae3c08ad0bf5747ac4dc6ebd7")
 
     variant("https", default=False, description="HTTPS support with GnuTLS")
 


Test patch: