Repository: spack/spack

Issue:
Installation issue: Mesa, LLVM, and ParaView linking problems with intel 19
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

@chuckatkins I am including the three errors in one issue, because they can be solved with the same `-shared-intel` linker flag. I'm guessing there's a more general solution, but the solution that seems to work is adding that flag in each individual package.

### Steps to reproduce the issue

paraview@5.8.1 error:
```console
$ spack install paravew@5.8.1%intel@19.0.4 +osmesa+python3+kits+plugins
...
       11199    ld: ../../../bin/vtkpython: hidden symbol `__intel_cpu_feature_indicator_x' in /usr/projects/hpcsoft/toss3/common/intel-clusterstudio/2019.4.070/compilers_and_libraries_2019/linux/lib/intel
                    64/libirc.a(cpu_feature_disp.o) is referenced by DSO
  >> 11200    ld: final link failed: Bad value
```

llvm@7.1.0 error:
```console
$ spack install llvm@7.1.0%intel@19.0.4 +link_dylib~clang~compiler-rt~gold~internal_unwind~libcxx~lld~lldb~polly
...
     59879     ld: ../../bin/llvm-mt: hidden symbol `__intel_cpu_feature_indica
               tor_x' in /yellow/usr/projects/hpcsoft/toss3/common/x86_64/intel
               -clusterstudio/2019.4.070/compilers_and_libraries_2019.4.243/lin
               ux/compiler/lib/intel64_lin/libirc.a(cpu_feature_disp.o) is refe
               renced by DSO
               ld: final link failed: bad value
```

mesa@18.3.6 error:
```console
$ spack install mesa@18.3.6%intel@19.0.4 +llvm
...
  >> 46    configure: error: in `/tmp/stam/spack-stage/spack-stage-mesa-18.3.6-pw5vkllu7xkt4jgavsj4askarqiw6scv/spack-src':
  >> 47    configure: error: C compiler cannot create executables
```

### Information on your system

<!-- Please include the output of `spack debug report` -->

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->
packages.yaml:
```yaml
packages:
  cmake:
    version: ['3.15.3']
  freetype:
    version: ['2.7.1']
  hdf5:
    version: ['1.10.2']
    variants: ['+mpi', '+hl']
  llvm:
    version: ['7.1.0']
    variants: ['+link_dylib', '~clang', '~compiler-rt', '~gold', '~internal_unwind', '~libcxx', '~lld', '~lldb', '~polly']
  mesa:
    version: ['18.3.6']
    variants: ['+llvm']
  ncurses:
    version: ['6.1']
    variants: ['+termlib']
  openblas:
    version: ['0.3.6']
  openmpi:
    version: ['2.1.2']
    externals:
    - spec: openmpi@2.1.2
      modules:
      - openmpi/2.1.2
    buildable: False
  openssl:
    version: ['1.0.2o']
  paraview:
    variants: ['+osmesa', '+opengl2', '+python3', '+plugins']
  python:
    version: ['3.6.8']
  py-matplotlib:
    version: ['3.1.1']
  py-numpy:
    version: ['1.17.3']
```

compilers.yaml:
```yaml
compilers:
  - compiler:
      spec: intel@19.0.4
      paths:
        cc: /usr/projects/hpcsoft/toss3/common/x86_64/intel-clusterstudio/2019.4.070/compilers_and_libraries_2019/linux/bin/intel64/icc
        cxx: /usr/projects/hpcsoft/toss3/common/x86_64/intel-clusterstudio/2019.4.070/compilers_and_libraries_2019/linux/bin/intel64/icpc
        f77: /usr/projects/hpcsoft/toss3/common/x86_64/intel-clusterstudio/2019.4.070/compilers_and_libraries_2019/linux/bin/intel64/ifort
        fc: /usr/projects/hpcsoft/toss3/common/x86_64/intel-clusterstudio/2019.4.070/compilers_and_libraries_2019/linux/bin/intel64/ifort
      flags: {}
      operating_system: rhel7
      target: x86_64
      modules:
        - intel/19.0.4
      environment: {}
      extra_rpaths: []
```

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

<!-- ### General information

These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue.
- [ ] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [ ] I have run `spack maintainers <name-of-the-package>` and @mentioned any maintainers
- [ ] I have uploaded the build log and environment files
- [ ] I have searched the issues of this repo and believe this is not a duplicate -->



Discussion:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/llvm/package.py b/var/spack/repos/builtin/packages/llvm/package.py
--- a/var/spack/repos/builtin/packages/llvm/package.py
+++ b/var/spack/repos/builtin/packages/llvm/package.py
@@ -359,8 +359,14 @@ def codesign_check(self):
                         'create this identity.'
                     )
 
-    def setup_build_environment(self, env):
-        env.append_flags("CXXFLAGS", self.compiler.cxx11_flag)
+    def flag_handler(self, name, flags):
+        if name == 'cxxflags':
+            flags.append(self.compiler.cxx11_flag)
+            return(None, flags, None)
+        elif name == 'ldflags' and self.spec.satisfies('%intel'):
+            flags.append('-shared-intel')
+            return(None, flags, None)
+        return(flags, None, None)
 
     def setup_run_environment(self, env):
         if "+clang" in self.spec:
diff --git a/var/spack/repos/builtin/packages/paraview/package.py b/var/spack/repos/builtin/packages/paraview/package.py
--- a/var/spack/repos/builtin/packages/paraview/package.py
+++ b/var/spack/repos/builtin/packages/paraview/package.py
@@ -181,6 +181,12 @@ def setup_dependent_build_environment(self, env, dependent_spec):
             env.set('PARAVIEW_VTK_DIR',
                     join_path(lib_dir, 'cmake', self.paraview_subdir, 'vtk'))
 
+    def flag_handler(self, name, flags):
+        if name == 'ldflags' and self.spec.satisfies('%intel'):
+            flags.append('-shared-intel')
+            return(None, flags, None)
+        return(flags, None, None)
+
     def setup_run_environment(self, env):
         # paraview 5.5 and later
         # - cmake under lib/cmake/paraview-5.5


Test patch: