Repository: spack/spack

Issue:
Installation issue: Gnuplot will not build with apple-clang
### Steps to reproduce the issue

```console
$ spack spec -I gnuplot
Input spec
--------------------------------
 -   gnuplot

Concretized
--------------------------------
 -   gnuplot@5.4.3%apple-clang@14.0.0~X+cairo+gd+libcerf~pbm~qt~wx patches=ad89f23 arch=darwin-monterey-cannonlake
[+]      ^cairo@1.16.0%apple-clang@14.0.0~X+fc+ft+gobject+pdf~png~svg patches=7c4da77 arch=darwin-monterey-cannonlake
[+]          ^autoconf@2.69%apple-clang@14.0.0 patches=35c4492,7793209,a49dd5b arch=darwin-monterey-cannonlake
[+]              ^m4@1.4.19%apple-clang@14.0.0+sigsegv patches=9dc5fbd,bfdffa7 arch=darwin-monterey-cannonlake
[+]                  ^diffutils@3.8%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                      ^libiconv@1.16%apple-clang@14.0.0 libs=shared,static arch=darwin-monterey-cannonlake
[+]                  ^libsigsegv@2.13%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^perl@5.34.1%apple-clang@14.0.0+cpanm+shared+threads arch=darwin-monterey-cannonlake
[+]                  ^berkeley-db@18.1.40%apple-clang@14.0.0+cxx~docs+stl patches=26090f4,b231fcc arch=darwin-monterey-cannonlake
[+]                  ^bzip2@1.0.8%apple-clang@14.0.0~debug~pic+shared arch=darwin-monterey-cannonlake
[+]                  ^gdbm@1.19%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                      ^readline@8.1.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^ncurses@6.3%apple-clang@14.0.0~symlinks+termlib abi=none arch=darwin-monterey-cannonlake
[+]                              ^pkgconf@1.8.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^zlib@1.2.12%apple-clang@14.0.0+optimize+pic+shared patches=0d38234 arch=darwin-monterey-cannonlake
[+]          ^automake@1.16.5%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^fontconfig@2.13.94%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^apple-libuuid@1353.100.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^font-util@1.3.2%apple-clang@14.0.0 fonts=encodings,font-adobe-100dpi,font-adobe-75dpi,font-adobe-utopia-100dpi,font-adobe-utopia-75dpi,font-adobe-utopia-type1,font-alias,font-arabic-misc,font-bh-100dpi,font-bh-75dpi,font-bh-lucidatypewriter-100dpi,font-bh-lucidatypewriter-75dpi,font-bh-type1,font-bitstream-100dpi,font-bitstream-75dpi,font-bitstream-speedo,font-bitstream-type1,font-cronyx-cyrillic,font-cursor-misc,font-daewoo-misc,font-dec-misc,font-ibm-type1,font-isas-misc,font-jis-misc,font-micro-misc,font-misc-cyrillic,font-misc-ethiopic,font-misc-meltho,font-misc-misc,font-mutt-misc,font-schumacher-misc,font-screen-cyrillic,font-sun-misc,font-winitzki-cyrillic,font-xfree86-type1 arch=darwin-monterey-cannonlake
[+]                  ^bdftopcf@1.0.5%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                      ^fontsproto@2.1.3%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^util-macros@1.19.3%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                      ^libxfont@1.5.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^freetype@2.11.1%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                              ^libpng@1.6.37%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^libfontenc@1.1.3%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                              ^xproto@7.0.31%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^xtrans@1.3.5%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^mkfontdir@1.0.7%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                      ^mkfontscale@1.1.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^gperf@3.1%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^libxml2@2.10.1%apple-clang@14.0.0~python arch=darwin-monterey-cannonlake
[+]                  ^xz@5.2.5%apple-clang@14.0.0~pic libs=shared,static arch=darwin-monterey-cannonlake
[+]              ^python@3.9.13%apple-clang@14.0.0+bz2+ctypes+dbm~debug+libxml2+lzma~nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=0d98e93,4c24573,f2fd060 arch=darwin-monterey-cannonlake
[+]                  ^expat@2.4.8%apple-clang@14.0.0~libbsd arch=darwin-monterey-cannonlake
[+]                  ^gettext@0.21%apple-clang@14.0.0+bzip2+curses+git~libunistring+libxml2+tar+xz arch=darwin-monterey-cannonlake
[+]                      ^tar@1.34%apple-clang@14.0.0 zip=pigz arch=darwin-monterey-cannonlake
[+]                          ^pigz@2.7%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                          ^zstd@1.5.2%apple-clang@14.0.0+programs compression=none libs=shared,static arch=darwin-monterey-cannonlake
[+]                  ^libffi@3.4.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^openssl@1.1.1q%apple-clang@14.0.0~docs~shared certs=mozilla patches=3fdcf2d arch=darwin-monterey-cannonlake
[+]                      ^ca-certificates-mozilla@2022-07-19%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^sqlite@3.39.2%apple-clang@14.0.0+column_metadata+dynamic_extensions+fts~functions+rtree arch=darwin-monterey-cannonlake
[+]          ^glib@2.72.3%apple-clang@14.0.0~libmount patches=b3fd450 tracing=none arch=darwin-monterey-cannonlake
[+]              ^meson@0.63.2%apple-clang@14.0.0 patches=9c87472,aa6c50d arch=darwin-monterey-cannonlake
[+]                  ^ninja@1.11.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^py-pip@22.1.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^py-setuptools@65.0.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^py-wheel@0.37.1%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^pcre@8.45%apple-clang@14.0.0~jit+multibyte+utf arch=darwin-monterey-cannonlake
[+]          ^libtool@2.4.7%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^pixman@0.40.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]      ^libcerf@1.3%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]      ^libgd@2.2.4%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^libjpeg-turbo@2.1.3%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^cmake@3.24.2%apple-clang@14.0.0~doc+ncurses+ownlibs~qt build_type=Release arch=darwin-monterey-cannonlake
[+]              ^nasm@2.15.05%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^libtiff@4.4.0%apple-clang@14.0.0~jbig~jpeg~jpeg12~lerc~libdeflate~lzma~old-jpeg~pixarlog~webp~zlib~zstd arch=darwin-monterey-cannonlake
[+]      ^libxpm@3.5.12%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^libx11@1.7.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^inputproto@2.3.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^kbproto@1.0.7%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^libxcb@1.14%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^libpthread-stubs@0.4%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^libxau@1.0.8%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^libxdmcp@1.1.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]                  ^xcb-proto@1.14.1%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^xextproto@7.3.0%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]      ^pango@1.50.7%apple-clang@14.0.0~X~strip buildtype=debugoptimized default_library=shared arch=darwin-monterey-cannonlake
[+]          ^fribidi@1.0.12%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^gobject-introspection@1.72.0%apple-clang@14.0.0~strip buildtype=debugoptimized default_library=shared arch=darwin-monterey-cannonlake
[+]              ^bison@3.8.2%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]              ^flex@2.6.3%apple-clang@14.0.0+lex~nls arch=darwin-monterey-cannonlake
[+]                  ^findutils@4.9.0%apple-clang@14.0.0 patches=440b954 arch=darwin-monterey-cannonlake
[+]              ^sed@4.8%apple-clang@14.0.0 arch=darwin-monterey-cannonlake
[+]          ^harfbuzz@5.1.0%apple-clang@14.0.0+coretext~graphite2~strip buildtype=debugoptimized default_library=shared arch=darwin-monterey-cannonlake
[+]              ^icu4c@67.1%apple-clang@14.0.0 cxxstd=11 arch=darwin-monterey-cannonlake
[+]          ^json-glib@1.6.6%apple-clang@14.0.0~strip buildtype=debugoptimized default_library=shared arch=darwin-monterey-cannonlake
```


### Error message

<details><summary>Error message</summary><pre>
==> gnuplot: Executing phase: 'autoreconf'
==> gnuplot: Executing phase: 'configure'
==> Error: ProcessError: Command exited with status 77:
    '/var/folders/k2/c2vvwrxs4_z7523r3nqqnzbm000lts/T/jcverle/spack-stage/spack-stage-gnuplot-5.4.3-2ayftoulcwjfwkwm2lazq65uxjm2sxh3/spack-src/configure' '--prefix=/Users/jcverle/repos/spack/opt/spack/darwin-monterey-cannonlake/apple-clang-14.0.0/gnuplot-5.4.3-2ayftoulcwjfwkwm2lazq65uxjm2sxh3' '--disable-dependency-tracking' '--disable-silent-rules' '--without-tutorial' '--with-readline=/Users/jcverle/repos/spack/opt/spack/darwin-monterey-cannonlake/apple-clang-14.0.0/readline-8.1.2-45ws4yjcq253chukjkvhuu2jzyc54ggc' '--without-bitmap-terminals' '--without-x' '--with-qt=no' '--disable-wxwidgets' '--with-gd=/Users/jcverle/repos/spack/opt/spack/darwin-monterey-cannonlake/apple-clang-14.0.0/libgd-2.2.4-2fm5mo53kzxpnkxrwmxm725xwuru7oeb' '--with-cairo' '--with-libcerf' '--without-pdf' '--without-lua' '--without-latex' '--without-aquaterm'

2 errors found in build log:
     12    checking whether make sets $(MAKE)... yes
     13    checking whether make supports nested variables... yes
     14    checking whether to enable maintainer-specific portions of Makefiles... no
     15    checking whether make supports the include directive... yes (GNU style)
     16    checking for gcc... /Users/jcverle/repos/spack/lib/spack/env/clang/clang
     17    checking whether the C compiler works... no
  >> 18    configure: error: in `/private/var/folders/k2/c2vvwrxs4_z7523r3nqqnzbm000lts/T/jcverle/spack-stage/spack-stage-gnuplot-5.4.3-2ayftoulcwjfw
           kwm2lazq65uxjm2sxh3/spack-src':
  >> 19    configure: error: C compiler cannot create executables
     20    See `config.log' for more details
</pre></details>
[config.log](https://github.com/spack/spack/files/9660121/config.log)


### Information on your system

* **Spack:** 0.19.0.dev0 (87b014ed13051f24a62aa41eb716ec82d7a26886)
* **Python:** 3.9.6
* **Platform:** darwin-monterey-cannonlake
* **Concretizer:** clingo

### Additional information

[spack-build-out.txt](https://github.com/spack/spack/files/9660113/spack-build-out.txt)
[spack-build-env.txt](https://github.com/spack/spack/files/9660115/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 wonder if this is at all related to https://github.com/iains/gcc-12-branch/issues/6.

TL;DR: the linker that comes with Xcode 14.0 is known to have bugs, they may be fixed in Xcode 14.1 (in beta)
That is possible. A while after reporting this issue, I ran into the linker issue you noted. I'm willing/able to wait until Apple resolves their issue, and then I can try this again.
I did some more digging. The problem is the following line at the very end of the "package.py" file:
```
os.environ["LDFLAGS"] = "-Wl,--copy-dt-needed-entries"
```
The `copy-dt-needed-entries` flag is not supported by clang. The flag was introduced in commit 89cc16a9cd back in April.
@haralmha can you take a look at this? Maybe we can limit this flag to only certain compilers, or use a different flag for clang.
@adamjstewart I am not working with this anymore and I do not have the Spack setup available. But I suggest keeping the workaround for gcc11 only and potentially extend the version range condition (and/or add other compilers as well) later if users experience that the DSO is not found.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/gnuplot/package.py b/var/spack/repos/builtin/packages/gnuplot/package.py
--- a/var/spack/repos/builtin/packages/gnuplot/package.py
+++ b/var/spack/repos/builtin/packages/gnuplot/package.py
@@ -158,5 +158,7 @@ def configure_args(self):
         # TODO: --with-aquaterm  depends_on('aquaterm')
         options.append("--without-aquaterm")
 
-        os.environ["LDFLAGS"] = "-Wl,--copy-dt-needed-entries"
+        if spec.satisfies("%gcc@11:"):
+            os.environ["LDFLAGS"] = "-Wl,--copy-dt-needed-entries"
+
         return options


Test patch: