Repository: spack/spack

Issue:
Installation issue: intel-tbb %nvhpc build issues
When attempting to build intel-tbb with %nvhpc, I am running into a several issues:
1) a number of compiler flags are not recognized by the nvc compilers
2) in several places, the commands to link the code into shared libs is using ld version scripts and complaining about syntax errors in such.

The first issue is common when building with %nvhpc (and truth be told, I "cheat" and have spack pass --noswitcherror to all of the compilers, preprocessor, and linker to avoid these errors, but since I was writing a patch for the second issue, I figured would bring this up as well).

The second issue appears to be due to how the Makefiles are generating the version scripts, and some differences between the g++ and nvc++ commands when running as a preprocessor (with -E flag).  Indeed, the nvc++ version appears to be automagically including a couple of header files (_cplus_macros.h, _cplus_preinclude.h), as can be seen in the tbb.def file
attached in the "Additional information" section.

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install intel-tbb@2018.3%nvhpc@21.5 cxxstd=default +shared +tm arch=linux-rhel8-x86_64
...
/software/spack/git.2021.04.28/lib/spack/env/nvhpc/nvc++ -E -x c++ ../../src/tbb/lin64-tbb-export.def -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm  -fPIC -flifetime-dse=1 -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor  -I../../src -I../../src/rml/include -I../../include > tbb.def
nvc++-Warning-Unknown switch: -flifetime-dse=1
nvc++-Warning-Unknown switch: -Wno-parentheses
nvc++-Warning-Unknown switch: -Wno-non-virtual-dtor
/software/spack/git.2021.04.28/lib/spack/env/nvhpc/nvc++ -fPIC -o libtbb_debug.so.2 concurrent_hash_map.o concurrent_queue.o concurrent_vector.o dynamic_link.o itt_notify.o cache_aligned_allocator.o pipeline.o queuing_mutex.o queuing_rw_mutex.o reader_writer_lock.o spin_rw_mutex.o x86_rtm_rw_mutex.o spin_mutex.o critical_section.o mutex.o recursive_mutex.o condition_variable.o tbb_thread.o concurrent_monitor.o semaphore.o private_server.o rml_tbb.o tbb_misc.o tbb_misc_ex.o task.o task_group_context.o governor.o market.o arena.o scheduler.o observer_proxy.o tbb_statistics.o tbb_main.o concurrent_vector_v2.o concurrent_queue_v2.o spin_rw_mutex_v2.o task_v2.o   -ldl -lpthread -lrt -shared -Wl,-soname=libtbb_debug.so.2 -m64  -Wl,--version-script,tbb.def
/bin/ld:tbb.def:12: syntax error in VERSION script
make[1]: *** [../../build/Makefile.tbb:107: libtbb_debug.so.2] Error 2
make[1]: Leaving directory '/tmp/spackswinst/spack-stage/spack-stage-intel-tbb-2018.3-24wu2fazsj5qgxocxoixqcphnrdieogl/spack-src/build/linux_intel64_gcc_cc8.4.0_libc2.28_kernel4.18.0_debug'
make: *** [Makefile:32: tbb] Error 2
```

### Information on your system

```console
$spack debug report
* **Spack:** 0.16.1-2429-f5e6c32495
* **Python:** 3.6.8
* **Platform:** linux-rhel8-x86_64
* **Concretizer:** original
```

I have nvhpc@21.5 set up as an external package in spack, and as compilers.yaml has --noswitcherror set for cppflags (and 
everything else), the unknown compiler flags are only warnings, not errors.


### Additional information


* [spack-build-out.txt](https://github.com/spack/spack/files/6864996/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/6864997/spack-build-env.txt)
* [tbb.def.txt](https://github.com/spack/spack/files/6864995/tbb.def.txt) This is one of the problematic version scripts (originally named tbb.def, renamed to tbb.def.txt to allow attaching)

No maintainers for intel-tbb found.

### 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

Installation issue: intel-tbb %nvhpc build issues
When attempting to build intel-tbb with %nvhpc, I am running into a several issues:
1) a number of compiler flags are not recognized by the nvc compilers
2) in several places, the commands to link the code into shared libs is using ld version scripts and complaining about syntax errors in such.

The first issue is common when building with %nvhpc (and truth be told, I "cheat" and have spack pass --noswitcherror to all of the compilers, preprocessor, and linker to avoid these errors, but since I was writing a patch for the second issue, I figured would bring this up as well).

The second issue appears to be due to how the Makefiles are generating the version scripts, and some differences between the g++ and nvc++ commands when running as a preprocessor (with -E flag).  Indeed, the nvc++ version appears to be automagically including a couple of header files (_cplus_macros.h, _cplus_preinclude.h), as can be seen in the tbb.def file
attached in the "Additional information" section.

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack install intel-tbb@2018.3%nvhpc@21.5 cxxstd=default +shared +tm arch=linux-rhel8-x86_64
...
/software/spack/git.2021.04.28/lib/spack/env/nvhpc/nvc++ -E -x c++ ../../src/tbb/lin64-tbb-export.def -DTBB_USE_DEBUG -DDO_ITT_NOTIFY -g -O0 -DUSE_PTHREAD -m64 -mrtm  -fPIC -flifetime-dse=1 -D__TBB_BUILD=1 -Wall -Wno-parentheses -Wno-non-virtual-dtor  -I../../src -I../../src/rml/include -I../../include > tbb.def
nvc++-Warning-Unknown switch: -flifetime-dse=1
nvc++-Warning-Unknown switch: -Wno-parentheses
nvc++-Warning-Unknown switch: -Wno-non-virtual-dtor
/software/spack/git.2021.04.28/lib/spack/env/nvhpc/nvc++ -fPIC -o libtbb_debug.so.2 concurrent_hash_map.o concurrent_queue.o concurrent_vector.o dynamic_link.o itt_notify.o cache_aligned_allocator.o pipeline.o queuing_mutex.o queuing_rw_mutex.o reader_writer_lock.o spin_rw_mutex.o x86_rtm_rw_mutex.o spin_mutex.o critical_section.o mutex.o recursive_mutex.o condition_variable.o tbb_thread.o concurrent_monitor.o semaphore.o private_server.o rml_tbb.o tbb_misc.o tbb_misc_ex.o task.o task_group_context.o governor.o market.o arena.o scheduler.o observer_proxy.o tbb_statistics.o tbb_main.o concurrent_vector_v2.o concurrent_queue_v2.o spin_rw_mutex_v2.o task_v2.o   -ldl -lpthread -lrt -shared -Wl,-soname=libtbb_debug.so.2 -m64  -Wl,--version-script,tbb.def
/bin/ld:tbb.def:12: syntax error in VERSION script
make[1]: *** [../../build/Makefile.tbb:107: libtbb_debug.so.2] Error 2
make[1]: Leaving directory '/tmp/spackswinst/spack-stage/spack-stage-intel-tbb-2018.3-24wu2fazsj5qgxocxoixqcphnrdieogl/spack-src/build/linux_intel64_gcc_cc8.4.0_libc2.28_kernel4.18.0_debug'
make: *** [Makefile:32: tbb] Error 2
```

### Information on your system

```console
$spack debug report
* **Spack:** 0.16.1-2429-f5e6c32495
* **Python:** 3.6.8
* **Platform:** linux-rhel8-x86_64
* **Concretizer:** original
```

I have nvhpc@21.5 set up as an external package in spack, and as compilers.yaml has --noswitcherror set for cppflags (and 
everything else), the unknown compiler flags are only warnings, not errors.


### Additional information


* [spack-build-out.txt](https://github.com/spack/spack/files/6864996/spack-build-out.txt)
* [spack-build-env.txt](https://github.com/spack/spack/files/6864997/spack-build-env.txt)
* [tbb.def.txt](https://github.com/spack/spack/files/6864995/tbb.def.txt) This is one of the problematic version scripts (originally named tbb.def, renamed to tbb.def.txt to allow attaching)

No maintainers for intel-tbb found.

### 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:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/intel-tbb/package.py b/var/spack/repos/builtin/packages/intel-tbb/package.py
--- a/var/spack/repos/builtin/packages/intel-tbb/package.py
+++ b/var/spack/repos/builtin/packages/intel-tbb/package.py
@@ -120,6 +120,27 @@ class IntelTbb(Package):
     # https://github.com/oneapi-src/oneTBB/commit/86f6dcdc17a8f5ef2382faaef860cfa5243984fe.patch?full_index=1
     patch("macos-arm64.patch", when="@:2021.0")
 
+    # Support for building with %nvhpc
+    # 1) remove flags nvhpc compilers do not recognize
+    patch("intel-tbb.nvhpc-remove-flags.2017.patch",
+          when="@2017:2018.9 %nvhpc")
+    patch("intel-tbb.nvhpc-remove-flags.2019.patch",
+          when="@2019:2019.0 %nvhpc")
+    patch("intel-tbb.nvhpc-remove-flags.2019.1.patch",
+          when="@2019.1:2019.6 %nvhpc")
+    patch("intel-tbb.nvhpc-remove-flags.2019.7.patch",
+          when="@2019.7:2019.8 %nvhpc")
+    # The 2019.9 patch below was tested successfully
+    # on @2019.9, @2020.0, and @2020.3
+    patch("intel-tbb.nvhpc-remove-flags.2019.9.patch",
+          when="@2019.9: %nvhpc")
+    # 2) Fix generation of version script tbb.def for ld (nvc++ -E
+    # appears to produce more output than g++ -E which was causing problems)
+    # The 2017 patch below was tested on @2017, @2017.8, @2018,
+    # @2018.3, @2018.6, 2019, @2019.[1-9], and @2020.[0-3]
+    patch("intel-tbb.nvhpc-version-script-fix.2017.patch",
+          when="@2017 %nvhpc")
+
     # Version and tar file names:
     #  2020.0 --> v2020.0.tar.gz  starting with 2020
     #  2017.1 --> 2017_U1.tar.gz  starting with 2017


Test patch: