Repository: spack/spack

Issue:
Installation issue: Julia
### Steps to reproduce the issue

```console
$ spack spec -I julia@1.7.2^libgit2@1.1.1
julia@1.7.2^libgit2@1.1.1
Input spec
--------------------------------
 -   julia@1.7.2
 -       ^libgit2@1.1.1

Concretized
--------------------------------
[+]  julia@1.7.2%gcc@8.4.0+openlibm+precompile patches=8b993a2 arch=linux-centos7-skylake_avx512
[+]      ^curl@7.78.0%gcc@8.4.0~gssapi~ldap~libidn2~librtmp~libssh+libssh2+nghttp2 tls=mbedtls,openssl arch=linux-centos7-skylake_avx512
[+]          ^libssh2@1.10.0%gcc@8.4.0~ipo+shared build_type=RelWithDebInfo crypto=mbedtls arch=linux-centos7-skylake_avx512
[+]              ^cmake@3.22.3%gcc@8.4.0~doc+ncurses+openssl+ownlibs~qt build_type=Release arch=linux-centos7-skylake_avx512
[+]                  ^ncurses@6.2%gcc@8.4.0~symlinks+termlib abi=none arch=linux-centos7-skylake_avx512
[+]                      ^pkgconf@1.8.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^openssl@1.1.1n%gcc@8.4.0~docs~shared certs=system arch=linux-centos7-skylake_avx512
[+]                      ^perl@5.34.0%gcc@8.4.0+cpanm+shared+threads arch=linux-centos7-skylake_avx512
[+]                          ^berkeley-db@18.1.40%gcc@8.4.0+cxx~docs+stl patches=b231fcc arch=linux-centos7-skylake_avx512
[+]                          ^bzip2@1.0.8%gcc@8.4.0~debug~pic+shared arch=linux-centos7-skylake_avx512
[+]                              ^diffutils@3.8%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                                  ^libiconv@1.16%gcc@8.4.0 libs=shared,static arch=linux-centos7-skylake_avx512
[+]                          ^gdbm@1.19%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                              ^readline@8.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                          ^zlib@1.2.11%gcc@8.4.0+optimize+pic+shared arch=linux-centos7-skylake_avx512
[+]              ^mbedtls@2.24.0%gcc@8.4.0+pic build_type=Release libs=shared,static patches=ab3db2c arch=linux-centos7-skylake_avx512
[+]              ^xz@5.2.5%gcc@8.4.0~pic libs=shared,static arch=linux-centos7-skylake_avx512
[+]          ^nghttp2@1.44.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^dsfmt@2.2.5%gcc@8.4.0 patches=b79624c arch=linux-centos7-skylake_avx512
[+]      ^gmp@6.2.1%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^autoconf@2.69%gcc@8.4.0 patches=35c4492,7793209,a49dd5b arch=linux-centos7-skylake_avx512
[+]              ^m4@1.4.19%gcc@8.4.0+sigsegv patches=9dc5fbd,bfdffa7 arch=linux-centos7-skylake_avx512
[+]                  ^libsigsegv@2.13%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^automake@1.16.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^libtool@2.4.6%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^libblastrampoline@3.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^libgit2@1.1.1%gcc@8.4.0~curl~ipo+mmap+ssh build_type=RelWithDebInfo https=system arch=linux-centos7-skylake_avx512
[+]      ^libunwind@1.5.0%gcc@8.4.0~block_signals~conservative_checks~cxx_exceptions~debug~debug_frame+docs~pic+tests+weak_backtrace~xz~zlib components=none libs=shared,static arch=linux-centos7-skylake_avx512
[+]      ^libuv@1.42.0%gcc@8.4.0 patches=d9252fb arch=linux-centos7-skylake_avx512
[+]      ^libwhich@1.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^llvm@12.0.1%gcc@8.4.0+clang~code_signing+compiler-rt~cuda~flang+gold~internal_unwind~ipo+libcxx+link_llvm_dylib+lld+lldb+llvm_dylib~mlir+omp_as_runtime~omp_debug~omp_tsan+polly~python~shared_libs~split_dwarf~z3 build_type=Release patches=10cb42f,88ae104 targets=amdgpu,bpf,nvptx,webassembly version_suffix=jl arch=linux-centos7-skylake_avx512
[+]          ^binutils@2.38%gcc@8.4.0~gas+gold~headers~interwork+ld~libiberty~lto+nls+plugins libs=shared,static arch=linux-centos7-skylake_avx512
[+]              ^gettext@0.21%gcc@8.4.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=linux-centos7-skylake_avx512
[+]                  ^libxml2@2.9.12%gcc@8.4.0~python arch=linux-centos7-skylake_avx512
[+]                  ^tar@1.34%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^hwloc@2.7.0%gcc@8.4.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-centos7-skylake_avx512
[+]              ^libpciaccess@0.16%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^util-macros@1.19.3%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^libedit@3.1-20210216%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^ninja@1.10.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]              ^python@3.9.10%gcc@8.4.0+bz2+ctypes+dbm~debug+ensurepip+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,4c24573,f2fd060 arch=linux-centos7-skylake_avx512
[+]                  ^expat@2.4.6%gcc@8.4.0+libbsd arch=linux-centos7-skylake_avx512
[+]                      ^libbsd@0.11.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                          ^libmd@1.0.4%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^libffi@3.4.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]                  ^sqlite@3.37.2%gcc@8.4.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=linux-centos7-skylake_avx512
[+]                  ^util-linux-uuid@2.37.4%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^perl-data-dumper@2.173%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^swig@4.0.2%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]              ^pcre@8.45%gcc@8.4.0~jit+multibyte+utf arch=linux-centos7-skylake_avx512
[+]      ^mpfr@4.1.0%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^autoconf-archive@2019.01.06%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]          ^texinfo@6.5%gcc@8.4.0 patches=12f6edb,1732115 arch=linux-centos7-skylake_avx512
[+]      ^openblas@0.3.20%gcc@8.4.0~bignuma~consistent_fpcsr+ilp64+locking+pic+shared symbol_suffix=64_ threads=none arch=linux-centos7-skylake_avx512
[+]      ^openlibm@0.7.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^p7zip@16.02%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^patchelf@0.14.5%gcc@8.4.0 arch=linux-centos7-skylake_avx512
[+]      ^pcre2@10.39%gcc@8.4.0~jit+multibyte arch=linux-centos7-skylake_avx512
[+]      ^suite-sparse@5.10.1%gcc@8.4.0~cuda~graphblas~openmp+pic~tbb arch=linux-centos7-skylake_avx512
[+]          ^metis@5.1.0%gcc@8.4.0~gdb~int64~real64+shared build_type=Release patches=4991da9,b1225da arch=linux-centos7-skylake_avx512
[+]      ^utf8proc@2.6.1%gcc@8.4.0~ipo build_type=RelWithDebInfo arch=linux-centos7-skylake_avx512
```


### Error message

The build completes without any errors. However, when trying to launch Julia I get the following error
<details><summary>Error message</summary><pre>
spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/julia-1.7.2-mnwxn4vfgsi2vrw4xn5pmlgujz6rhd3z/bin/julia 
ERROR: Unable to load dependent library /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/julia-1.7.2-mnwxn4vfgsi2vrw4xn5pmlgujz6rhd3z/bin/../lib/julia/libjulia-internal.so.1
Message:libtinfo.so.6: cannot open shared object file: No such file or directory
</pre></details>

Using the command `ldd /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/julia-1.7.2-mnwxn4vfgsi2vrw4xn5pmlgujz6rhd3z/bin/../lib/julia/libjulia-internal.so.1` produces the output
```console
	linux-vdso.so.1 =>  (0x00007fff083e4000)
	/nopt/xalt/xalt/lib64/libxalt_init.so (0x00007ff2eb68b000)
	libjulia.so.1 => /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/julia-1.7.2-mnwxn4vfgsi2vrw4xn5pmlgujz6rhd3z/lib/libjulia.so.1 (0x00007ff2eb46a000)
	libuv.so.2 => /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/libuv-1.42.0-wx3m7efefdnihopw6v3qeoe6ya55pdw6/lib/libuv.so.2 (0x00007ff2eb23d000)
	libunwind.so.8 => /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/libunwind-1.5.0-xgj5txk6vebl7ffpo2futuqdts65waez/lib/libunwind.so.8 (0x00007ff2eb025000)
	libLLVM-12jl.so => /home/jmaack/spack/opt/spack/linux-centos7-skylake_avx512/gcc-8.4.0/llvm-12.0.1-lpfeoh3oshwxrjqwgqg6vyn6csn4ankd/lib/libLLVM-12jl.so (0x00007ff2e66d2000)
	libdl.so.2 => /lib64/libdl.so.2 (0x00007ff2e64ce000)
	librt.so.1 => /lib64/librt.so.1 (0x00007ff2e62c6000)
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007ff2e60aa000)
	libatomic.so.1 => /nopt/nrel/apps/base/2020-05-12/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/gcc-8.4.0-xrmnckz436rnkcwooooi2r7n35pojkov/lib64/libatomic.so.1 (0x00007ff2e5ea1000)
	libstdc++.so.6 => /nopt/nrel/apps/base/2020-05-12/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/gcc-8.4.0-xrmnckz436rnkcwooooi2r7n35pojkov/lib64/libstdc++.so.6 (0x00007ff2e5b1d000)
	libm.so.6 => /lib64/libm.so.6 (0x00007ff2e581b000)
	libgcc_s.so.1 => /nopt/nrel/apps/base/2020-05-12/spack/opt/spack/linux-centos7-x86_64/gcc-4.8.5/gcc-8.4.0-xrmnckz436rnkcwooooi2r7n35pojkov/lib64/libgcc_s.so.1 (0x00007ff2e5603000)
	libc.so.6 => /lib64/libc.so.6 (0x00007ff2e5235000)
	/lib64/ld-linux-x86-64.so.2 (0x00007ff2ec0bb000)
	libedit.so.0 => /lib64/libedit.so.0 (0x00007ff2e4ff8000)
	libz.so.1 => /lib64/libz.so.1 (0x00007ff2e4de2000)
	libtinfo.so.6 => not found
	libxml2.so.2 => /lib64/libxml2.so.2 (0x00007ff2e4a78000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007ff2e484e000)
	liblzma.so.5 => /lib64/liblzma.so.5 (0x00007ff2e4628000)
```

In addition to being unable to find the ncurses library libtinfo.so.6 there are a large number of system libraries here.  I would expect most of these to be libraries built by spack as the only system provided thing I have setup spack to use is GCC v8.4.0.

### Information on your system

* **Spack:** 0.18.0.dev0 (048a0de35bd791f233d0a6f676d841d85e75aae7)
* **Python:** 3.6.8
* **Platform:** linux-centos7-skylake_avx512
* **Concretizer:** clingo

### Additional information

@glennpj 
@haampie 
@vchuravy

[spack-build-env-mods.txt](https://github.com/spack/spack/files/8354014/spack-build-env-mods.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/8354015/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/8354016/spack-build-out.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:
Can you run https://github.com/haampie/libtree instead of ldd? I think this is coming from LLVM's "system libraries", but it's difficult to say.

It's also possible that `llvm-config` in Julia's build script somehow adds those libs to julia itself, which would be annoying.
My suspicion is that Julia modifies the rpath of libLLVM... from the build logs the rpaths of LLVM look fine. Have to verify this.
Yup, that's the case :weary: 
```
121-# Set rpath for LLVM.so which is `RIGIN/../lib` moving from `../lib` to `../lib/julia`.  We only need to do this for Linux/FreeBSD
122:patchelf --set-rpath '$ORIGIN:$ORIGIN/..' /home/harmen/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-11.2.0/julia-1.7.2-7xre62gf3wq2jlnjwkgdxqbxfjhvzphs/lib/julia/libLLVM.so
```

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/julia/package.py b/var/spack/repos/builtin/packages/julia/package.py
--- a/var/spack/repos/builtin/packages/julia/package.py
+++ b/var/spack/repos/builtin/packages/julia/package.py
@@ -121,6 +121,10 @@ class Julia(MakefilePackage):
     # Fix gfortran abi detection https://github.com/JuliaLang/julia/pull/44026
     patch('fix-gfortran.patch', when='@1.7.0:1.7.2')
 
+    # Don't make julia run patchelf --set-rpath on llvm (presumably this should've
+    # only applied to libllvm when it's vendored by julia).
+    patch('revert-fix-rpath-of-libllvm.patch', when='@1.7.0:1.7')
+
     def patch(self):
         # The system-libwhich-libblastrampoline.patch causes a rebuild of docs as it
         # touches the main Makefile, so we reset the a/m-time to doc/_build's.


Test patch: