Repository: spack/spack

Issue:
Installation issue: openssh %nvhpc
### Steps to reproduce the issue

$ spack maintainers openssh
@bernhardkaindl

$ spack install openssh %nvhpc@22.1 ^openssl %gcc
```
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/pkgconf-1.8.0-a3kn22sdo3dikakyqkux3xsr4gcmnu5n
[+] /usr (external perl-5.30.0-gmkstxoj5w7t5eemib4yd365zw3nqayk)
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.3.0/zlib-1.2.11-whj3n7mok67wqtm5dofead56i6krevxc
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/ncurses-6.2-7yglxp6sw2ajhjpdgaxfs63hu3i2dok7
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.3.0/openssl-1.1.1m-23imk2rsftvme5mwrkr6wdvhoecqq2rk
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/libedit-3.1-20210216-c5mkfnd4gab6cuceloxorgpypr565b5u
==> Installing openssh-8.8p1-m6zc5n3ra3rfeg4senjydunhcsq6ub56
==> No binary for openssh-8.8p1-m6zc5n3ra3rfeg4senjydunhcsq6ub56 found: installing from source
==> Using cached archive: /home2/cessenat/Softs/spack/var/spack/cache/_source-cache/archive/45/4590890ea9bb9ace4f71ae331785a3a5823232435161960ed5fc86588f331fe9.tar.gz
==> No patches needed for openssh
==> openssh: Executing phase: 'autoreconf'
==> openssh: Executing phase: 'configure'
==> openssh: Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j6' 'V=1'

2 errors found in build log:
     6092    a - sshbuf-io.o
     6093    ranlib libssh.a
     6094    /home2/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc -o ssh ssh.o readconf.o clientloop.o sshtty.o sshconnect.o sshconnect2.o mux.o ssh-sk-c
             lient.o -L. -Lopenbsd-compat/  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie  -lssh -lopenbsd-compat -lcrypto -l
             util -lz  -lcrypt -lresolv
     6095    nvc-Warning-Unknown switch: -fstack-protector-strong
     6096    /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when ma
             king a PIE object
     6097    /home2/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc -o sshd sshd.o auth-rhosts.o auth-passwd.o audit.o audit-bsm.o audit-linux.o platform.o
              sshpty.o sshlogin.o servconf.o serverloop.o auth.o auth2.o auth-options.o session.o auth2-chall.o groupaccess.o auth-bsdauth.o auth2-hostb
             ased.o auth2-kbdint.o auth2-none.o auth2-passwd.o auth2-pubkey.o monitor.o monitor_wrap.o auth-krb5.o auth2-gss.o gss-serv.o gss-serv-krb5.
             o loginrec.o auth-pam.o auth-shadow.o auth-sia.o md5crypt.o srclimit.o sftp-server.o sftp-common.o sandbox-null.o sandbox-rlimit.o sandbox-
             systrace.o sandbox-darwin.o sandbox-seccomp-filter.o sandbox-capsicum.o sandbox-pledge.o sandbox-solaris.o uidswap.o ssh-sk-client.o -L. -L
             openbsd-compat/  -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie  -lssh -lopenbsd-compat  -lcrypto -lutil -lz  -lc
             rypt -lresolv
  >> 6098    make: *** [Makefile:210: ssh] Error 2
     6099    make: *** Waiting for unfinished jobs....
     6100    nvc-Warning-Unknown switch: -fstack-protector-strong
     6101    /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when ma
             king a PIE object
  >> 6102    make: *** [Makefile:213: sshd] Error 2

See build log for details:
  /tmp/cessenat/spack-stage/spack-stage-openssh-8.8p1-m6zc5n3ra3rfeg4senjydunhcsq6ub56/spack-build-out.txt

```

### Information on your system

$ spack debug report
* **Spack:** 0.17.0-856-e0f044561e
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-zen2
* **Concretizer:** clingo


### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/7883866/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/7883867/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:
did you figure this out?

I can make it build by adding `--without-pie` to configure_args. But curiously it's not required for gcc. Unclear what the difference is.
I am puzzled that `/home2/cessenat/Softs/spack/lib/spack/env/nvhpc/nvc` was used for compilation even tho %gcc was selected by @cessenat (likely in an attempt to workaround the issue): `spack install openssh %nvhpc@22.1 ^openssl %gcc`

Of course the error is: `/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object`

This error is the result of attempting to link non-PIC code into an output file which shall be relocatable:

https://stackoverflow.com/questions/19364969/compilation-fails-with-relocation-r-x86-64-32-against-rodata-str1-8-can-not

The build enabled `-pie` for linking, but code which shall used for linking was compiled (by nvc) non-PIC code.

`__TMC_END__` appears to be used for transactional memory by gcc:
https://stackoverflow.com/questions/17605794/what-are-linker-symbols-tmc-end-and-tmc-list-for?noredirect=1&lq=1
https://sourceware.org/bugzilla/show_bug.cgi?id=13621 :
> gcc 4.7 (not yet released) introduces a new __TMC_END__ global hidden symbol to mark the end of a .tm_clone_table section. > When linking a program that doesn't use any tm_clone_table entries the __TMC_END__ symbol is left in .symtab pointing outside any section. For example just compiling an empty program int main(int argc, char **argv) { return 0; } produces on x86_64 with gcc (GCC) 4.7.0 20120119
> (Red Hat 4.7.0-0.8) and binutils-2.22-4.fc17.x86_64  a __TMC_END__ symbol in .symtab that looks as follows:
>   66: 0000000000600850      0 OBJECT  GLOBAL HIDDEN        24 __TMC_END__
> Section 24 is:
> [24] .data                PROGBITS     0000000000600848 00000848 00000004  0 WA     0   0  4
> So the address of __TMC_END__ is outside that section.

This might be a bug in the build system not passing -fPIC or nvc, still producing non-PIC code, or something equally obscure.

I think we should add `--without-pie` when the cc used isn't really gcc to workaround such issues:
```diff
--- a/var/spack/repos/builtin/packages/openssh/package.py
+++ b/var/spack/repos/builtin/packages/openssh/package.py
@@ -66,6 +66,8 @@ def configure_args(self):
         # least newer versions want to create the directory during the
         # install step and fail if they cannot do so.
         args = ['--with-privsep-path={0}'.format(self.prefix.var.empty)]
+        if not self.spec.satisfies('%gcc'):
+            args.append('--without-pie')
         return args
 `` 
Thanks very much @bernhardkaindl , I added --without-pie and got further. It has nothing to do with the initial problem, prabably :

```
$ spack install openssh %nvhpc@22.1 ^openssl %gcc
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/pkgconf-1.8.0-a3kn22sdo3dikakyqkux3xsr4gcmnu5n
[+] /usr (external perl-5.30.0-gmkstxoj5w7t5eemib4yd365zw3nqayk)
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.3.0/zlib-1.2.11-whj3n7mok67wqtm5dofead56i6krevxc
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/ncurses-6.2-7yglxp6sw2ajhjpdgaxfs63hu3i2dok7
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/gcc-9.3.0/openssl-1.1.1n-4dnvw3ptsh4bvdspnnviju4kwobpcc3u
[+] /home2/cessenat/Softs/spack/opt/spack/linux-ubuntu20.04-zen2/nvhpc-22.1/libedit-3.1-20210216-c5mkfnd4gab6cuceloxorgpypr565b5u
==> Installing openssh-8.9p1-7lhnpnffzj6bvyujinys35uvjf3pzfm2
==> No binary for openssh-8.9p1-7lhnpnffzj6bvyujinys35uvjf3pzfm2 found: installing from source
==> Using cached archive: /home2/cessenat/Softs/spack/var/spack/cache/_source-cache/archive/fd/fd497654b7ab1686dac672fb83dfb4ba4096e8b5ffcdaccd262380ae58bec5e7.tar.gz
==> No patches needed for openssh
==> openssh: Executing phase: 'autoreconf'
==> openssh: Executing phase: 'configure'
==> openssh: Executing phase: 'build'
==> openssh: Executing phase: 'install'
==> Error: InvalidPermissionsError: Attempting to set suid with group writable

/home2/cessenat/Softs/spack/lib/spack/spack/build_environment.py:1065, in _setup_pkg_and_run:
       1062        tb_string = traceback.format_exc()
       1063
       1064        # build up some context from the offending package so we can
  >>   1065        # show that, too.
       1066        package_context = get_package_context(tb)
       1067
       1068        logfile = None

See build log for details:
  /tmp/cessenat/spack-stage/spack-stage-openssh-8.9p1-7lhnpnffzj6bvyujinys35uvjf3pzfm2/spack-build-out.txt

```
$ spack debug report
* **Spack:** 0.18.0.dev0 (f41c3a0fe96df09e3d6887dbeda6cb822e32e7f5)
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-zen2
* **Concretizer:** clingo


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/openssh/package.py b/var/spack/repos/builtin/packages/openssh/package.py
--- a/var/spack/repos/builtin/packages/openssh/package.py
+++ b/var/spack/repos/builtin/packages/openssh/package.py
@@ -66,6 +66,10 @@ def configure_args(self):
         # least newer versions want to create the directory during the
         # install step and fail if they cannot do so.
         args = ['--with-privsep-path={0}'.format(self.prefix.var.empty)]
+
+        # Somehow creating pie executables fails with nvhpc, not with gcc.
+        if '%nvhpc' in self.spec:
+            args.append('--without-pie')
         return args
 
     def install(self, spec, prefix):


Test patch: