Repository: spack/spack

Issue:
Cannot use `config:shared_linking:bind:true` anymore
### Steps to reproduce the issue
Turn this non-default option on:
```console
$ spack config add config:shared_linking:bind:true
```
Then try to install anything:
```console
$ spack spec -I <spec>
Input spec
--------------------------------
 -   gcc-runtime

Concretized
--------------------------------
[+]  gcc-runtime@11.4.1%gcc@11.4.1 build_system=generic arch=linux-almalinux9-x86_64_v3
[e]      ^glibc@2.34%gcc@11.4.1 build_system=autotools arch=linux-almalinux9-x86_64_v3

$ spack install gcc-runtime # Or any package compiled with gcc
[+] /usr (external glibc-2.34-xvxngcqmc33coucpn3qpxr2by2ruwxgi)
==> Installing gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3 [2/2]
==> No binary for gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3 found: installing from source
==> No patches needed for gcc-runtime
==> gcc-runtime: Executing phase: 'install'
==> Error: TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'Executable'
See build log for details:
  /tmp/root/spack-stage/spack-stage-gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/spack-build-out.txt

$ vim /cluster/spack/app/lib/spack/spack/hooks/absolutify_elf_sonames.py
Add .path to line 152 resulting in `patchelf_path = spack.relocate._patchelf().path`

$ spack install gcc-runtime
[+] /usr (external glibc-2.34-xvxngcqmc33coucpn3qpxr2by2ruwxgi)
==> Installing gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3 [2/2]
==> No binary for gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3 found: installing from source
==> No patches needed for gcc-runtime
==> gcc-runtime: Executing phase: 'install'
==> gcc-runtime: Patched 6 sonames: lib/libatomic.so.1, lib/libgcc_s.so.1, lib/libgfortran.so.5, lib/libgomp.so.1, ..., lib/libstdc++.so.6
==> gcc-runtime: Successfully installed gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3
  Stage: 0.00s.  Install: 0.04s.  Post-install: 0.24s.  Total: 0.29s
[+] /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3

$ cat /etc/os-release
NAME="AlmaLinux"
VERSION="9.4 (Seafoam Ocelot)"
ID="almalinux"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.4"
PLATFORM_ID="platform:el9"
PRETTY_NAME="AlmaLinux 9.4 (Seafoam Ocelot)"
ANSI_COLOR="0;34"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:almalinux:almalinux:9::baseos"
HOME_URL="https://almalinux.org/"
DOCUMENTATION_URL="https://wiki.almalinux.org/"
BUG_REPORT_URL="https://bugs.almalinux.org/"

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-9"
ALMALINUX_MANTISBT_PROJECT_VERSION="9.4"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.4"
SUPPORT_END=2032-06-01
```


### Error message

<details><summary>Error message</summary>

<pre>
==> [2024-05-23-12:45:05.723837] Adding env modifications for patchelf
==> [2024-05-23-12:45:05.741491] Error: TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'Executable'
See build log for details:
  /tmp/root/spack-stage/spack-stage-gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/spack-build-out.txt

Traceback (most recent call last):
  File "/cluster/spack/app/lib/spack/spack/build_environment.py", line 1151, in _setup_pkg_and_run
    return_value = function(pkg, kwargs)
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/cluster/spack/app/lib/spack/spack/installer.py", line 2482, in build_process
    return installer.run()
           ^^^^^^^^^^^^^^^
  File "/cluster/spack/app/lib/spack/spack/installer.py", line 2359, in run
    spack.hooks.post_install(self.pkg.spec, self.explicit)
  File "/cluster/spack/app/lib/spack/spack/hooks/__init__.py", line 67, in __call__
    hook(*args, **kwargs)
  File "/cluster/spack/app/lib/spack/spack/hooks/absolutify_elf_sonames.py", line 155, in post_install
    patchelf = Executable(patchelf_path)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/cluster/spack/app/lib/spack/spack/util/executable.py", line 23, in __init__
    file_path = str(Path(name))
                    ^^^^^^^^^^
  File "/usr/lib64/python3.12/pathlib.py", line 1162, in __init__
    super().__init__(*args)
  File "/usr/lib64/python3.12/pathlib.py", line 373, in __init__
    raise TypeError(
TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'Executable'
==> [2024-05-23-12:45:05.741797] Flagging gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3 as failed: TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'Executable'
==> [2024-05-23-12:45:05.744836] ChildError: TypeError: argument should be a str or an os.PathLike object where __fspath__ returns a str, not 'Executable'
</pre></details>


### Information on your system

* **Spack:** 0.22.0 (5fe93fee1eec46a0750bd340198bffcb92ff9eec)
* **Python:** 3.12.1
* **Platform:** linux-almalinux9-zen2
* **Concretizer:** clingo

### Additional information

<ul><li><details>
<summary>spack-build-out.txt</summary>
<pre>
==> [2024-05-23-12:57:00.064859] gcc-runtime: Executing phase: 'install'
==> [2024-05-23-12:57:00.067187] '/usr/bin/gcc' '-print-file-name=libasan.so'
==> [2024-05-23-12:57:00.068601] '/usr/bin/gcc' '-print-file-name=libasan.so.6'
==> [2024-05-23-12:57:00.069981] '/usr/bin/gcc' '-print-file-name=libatomic.so'
==> [2024-05-23-12:57:00.071220] '/usr/bin/gcc' '-print-file-name=libatomic.so.1'
==> [2024-05-23-12:57:00.072481] '/usr/bin/gcc' '-print-file-name=libgcc_s.so'
==> [2024-05-23-12:57:00.073671] '/usr/bin/gcc' '-print-file-name=libgcc_s.so.1'
==> [2024-05-23-12:57:00.074738] '/usr/bin/gcc' '-print-file-name=libgfortran.so'
==> [2024-05-23-12:57:00.076059] '/usr/bin/gcc' '-print-file-name=libgfortran.so.5'
==> [2024-05-23-12:57:00.077192] '/usr/bin/gcc' '-print-file-name=libgomp.so'
==> [2024-05-23-12:57:00.078491] '/usr/bin/gcc' '-print-file-name=libgomp.so.1'
==> [2024-05-23-12:57:00.079691] '/usr/bin/gcc' '-print-file-name=libhwasan.so'
==> [2024-05-23-12:57:00.080934] '/usr/bin/gcc' '-print-file-name=libitm.so'
==> [2024-05-23-12:57:00.082071] '/usr/bin/gcc' '-print-file-name=liblsan.so'
==> [2024-05-23-12:57:00.083229] '/usr/bin/gcc' '-print-file-name=liblsan.so.0'
==> [2024-05-23-12:57:00.084413] '/usr/bin/gcc' '-print-file-name=libquadmath.so'
==> [2024-05-23-12:57:00.085461] '/usr/bin/gcc' '-print-file-name=libquadmath.so.0'
==> [2024-05-23-12:57:00.086466] '/usr/bin/gcc' '-print-file-name=libssp.so'
==> [2024-05-23-12:57:00.087560] '/usr/bin/gcc' '-print-file-name=libstdc++.so'
==> [2024-05-23-12:57:00.088925] '/usr/bin/gcc' '-print-file-name=libstdc++.so.6'
==> [2024-05-23-12:57:00.090141] '/usr/bin/gcc' '-print-file-name=libtsan.so'
==> [2024-05-23-12:57:00.091325] '/usr/bin/gcc' '-print-file-name=libtsan.so.0'
==> [2024-05-23-12:57:00.092551] '/usr/bin/gcc' '-print-file-name=libubsan.so'
==> [2024-05-23-12:57:00.093711] '/usr/bin/gcc' '-print-file-name=libubsan.so.1'
==> [2024-05-23-12:57:00.094870] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libatomic.so.1 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libatomic.so.1
==> [2024-05-23-12:57:00.095279] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libgcc_s.so.1 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libgcc_s.so.1
==> [2024-05-23-12:57:00.095697] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libgfortran.so.5 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libgfortran.so.5
==> [2024-05-23-12:57:00.098545] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libgomp.so.1 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libgomp.so.1
==> [2024-05-23-12:57:00.098989] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libquadmath.so.0 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libquadmath.so.0
==> [2024-05-23-12:57:00.099439] Installing /usr/lib/gcc/x86_64-redhat-linux/11/../../../../lib64/libstdc++.so.6 to /cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib/libstdc++.so.6
</pre></details></li>
<li><details>
<summary>spack-build-env.txt</summary>
<pre>
function BASH_FUNC__spack_shell_wrapper%%() {  for var in DYLD_LIBRARY_PATH DYLD_FALLBACK_LIBRARY_PATH;
 do
 eval "if [ -n \"\${${var}-}\" ]; then export SPACK_$var=\${${var}}; fi";
 done;
 if [ -n "${ZSH_VERSION:-}" ]; then
 emulate -L sh;
 fi;
 _sp_flags="";
 while [ ! -z ${1+x} ] && [ "${1#-}" != "${1}" ]; do
 _sp_flags="$_sp_flags $1";
 shift;
 done;
 if [ -n "$_sp_flags" ] && [ "${_sp_flags#*h}" != "${_sp_flags}" ] || [ "${_sp_flags#*V}" != "${_sp_flags}" ]; then
 command spack $_sp_flags "$@";
 return;
 fi;
 _sp_subcommand="";
 if [ ! -z ${1+x} ]; then
 _sp_subcommand="$1";
 shift;
 fi;
 case $_sp_subcommand in
 "cd")
 _sp_arg="";
 if [ -n "$1" ]; then
 _sp_arg="$1";
 shift;
 fi;
 if [ "$_sp_arg" = "-h" ] || [ "$_sp_arg" = "--help" ]; then
 command spack cd -h;
 else
 LOC="$(SPACK_COLOR="${SPACK_COLOR:-always}" spack location $_sp_arg "$@")";
 if [ -d "$LOC" ]; then
 cd "$LOC";
 else
 return 1;
 fi;
 fi;
 return
 ;;
 "env")
 _sp_arg="";
 if [ -n "$1" ]; then
 _sp_arg="$1";
 shift;
 fi;
 if [ "$_sp_arg" = "-h" ] || [ "$_sp_arg" = "--help" ]; then
 command spack env -h;
 else
 case $_sp_arg in
 activate)
 _a=" $@";
 if [ "${_a#* --sh}" != "$_a" ] || [ "${_a#* --csh}" != "$_a" ] || [ "${_a#* -h}" != "$_a" ] || [ "${_a#* --help}" != "$_a" ]; then
 command spack env activate "$@";
 else
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags env activate --sh "$@")" || return;
 eval "$stdout";
 fi
 ;;
 deactivate)
 _a=" $@";
 if [ "${_a#* --sh}" != "$_a" ] || [ "${_a#* --csh}" != "$_a" ]; then
 command spack env deactivate "$@";
 else
 if [ -n "$*" ]; then
 command spack env deactivate -h;
 else
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags env deactivate --sh)" || return;
 eval "$stdout";
 fi;
 fi
 ;;
 *)
 command spack env $_sp_arg "$@"
 ;;
 esac;
 fi;
 return
 ;;
 "load" | "unload")
 _a=" $@";
 if [ "${_a#* --sh}" != "$_a" ] || [ "${_a#* --csh}" != "$_a" ] || [ "${_a#* -h}" != "$_a" ] || [ "${_a#* --list}" != "$_a" ] || [ "${_a#* --help}" != "$_a" ]; then
 command spack $_sp_flags $_sp_subcommand "$@";
 else
 stdout="$(SPACK_COLOR="${SPACK_COLOR:-always}" command spack $_sp_flags $_sp_subcommand --sh "$@")" || return;
 eval "$stdout";
 fi
 ;;
 *)
 command spack $_sp_flags $_sp_subcommand "$@"
 ;;
 esac
}; export -f BASH_FUNC__spack_shell_wrapper%%
function BASH_FUNC_spack%%() {  : this is a shell function from: /cluster/spack/app/share/spack/setup-env.sh;
 : the real spack script is here: /cluster/spack/app/bin/spack;
 _spack_shell_wrapper "$@";
 return $?
}; export -f BASH_FUNC_spack%%
function BASH_FUNC_which%%() {  ( alias;
 eval ${which_declare} ) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
}; export -f BASH_FUNC_which%%
CC=/cluster/spack/app/lib/spack/env/gcc/gcc; export CC
CXX=/cluster/spack/app/lib/spack/env/gcc/g++; export CXX
DEBUGINFOD_URLS="https://debuginfod.centos.org/ "; export DEBUGINFOD_URLS
F77=/cluster/spack/app/lib/spack/env/gcc/gfortran; export F77
FC=/cluster/spack/app/lib/spack/env/gcc/gfortran; export FC
HISTCONTROL=ignoredups; export HISTCONTROL
HISTSIZE=1000; export HISTSIZE
HOME=/root; export HOME
HOSTNAME=dungeonkeeper; export HOSTNAME
LANG=de_DE.UTF-8; export LANG
LC_ALL=C; export LC_ALL
LESSOPEN="||/usr/bin/lesspipe.sh %s"; export LESSOPEN
LOGNAME=root; export LOGNAME
LS_COLORS=""; export LS_COLORS
MAIL=/var/spool/mail/root; export MAIL
PATH=/cluster/spack/app/lib/spack/env/gcc:/cluster/spack/app/lib/spack/env/case-insensitive:/cluster/spack/app/lib/spack/env:/root/.local/bin:/root/bin:/cluster/spack/app/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin; export PATH
#PWD=/root; export PWD
SHELL=/bin/bash; export SHELL
SHLVL=1; export SHLVL
SPACK_CC=/usr/bin/gcc; export SPACK_CC
SPACK_CC_RPATH_ARG=-Wl,-rpath,; export SPACK_CC_RPATH_ARG
SPACK_COMPILER_FLAGS_KEEP=""; export SPACK_COMPILER_FLAGS_KEEP
SPACK_COMPILER_FLAGS_REPLACE="-Werror-|-Wno-error= -Werror|-Wno-error"; export SPACK_COMPILER_FLAGS_REPLACE
SPACK_COMPILER_SPEC=gcc@=11.4.1; export SPACK_COMPILER_SPEC
SPACK_CXX=/usr/bin/g++; export SPACK_CXX
SPACK_CXX_RPATH_ARG=-Wl,-rpath,; export SPACK_CXX_RPATH_ARG
SPACK_DEBUG=TRUE; export SPACK_DEBUG
SPACK_DEBUG_LOG_DIR=/root; export SPACK_DEBUG_LOG_DIR
SPACK_DEBUG_LOG_ID=gcc-runtime-w3a63xa; export SPACK_DEBUG_LOG_ID
SPACK_DTAGS_TO_ADD=--disable-new-dtags; export SPACK_DTAGS_TO_ADD
SPACK_DTAGS_TO_STRIP=--enable-new-dtags; export SPACK_DTAGS_TO_STRIP
SPACK_ENV_PATH=/cluster/spack/app/lib/spack/env:/cluster/spack/app/lib/spack/env/case-insensitive:/cluster/spack/app/lib/spack/env/gcc; export SPACK_ENV_PATH
SPACK_F77=/usr/bin/gfortran; export SPACK_F77
SPACK_F77_RPATH_ARG=-Wl,-rpath,; export SPACK_F77_RPATH_ARG
SPACK_FC=/usr/bin/gfortran; export SPACK_FC
SPACK_FC_RPATH_ARG=-Wl,-rpath,; export SPACK_FC_RPATH_ARG
SPACK_INCLUDE_DIRS=""; export SPACK_INCLUDE_DIRS
SPACK_LINKER_ARG=-Wl,; export SPACK_LINKER_ARG
SPACK_LINK_DIRS=""; export SPACK_LINK_DIRS
SPACK_MANAGED_DIRS="\"/cluster/spack/packages/\"*|\"/tmp/root/spack-stage/\"*"; export SPACK_MANAGED_DIRS
SPACK_PYTHON=/usr/bin/python3.12; export SPACK_PYTHON
SPACK_ROOT=/cluster/spack/app; export SPACK_ROOT
SPACK_RPATH_DIRS=""; export SPACK_RPATH_DIRS
SPACK_SHORT_SPEC="gcc-runtime@11.4.1%gcc@11.4.1 build_system=generic arch=linux-almalinux9-x86_64_v3/w3a63xa"; export SPACK_SHORT_SPEC
SPACK_SKIP_MODULES=1; export SPACK_SKIP_MODULES
SPACK_STORE_INCLUDE_DIRS=""; export SPACK_STORE_INCLUDE_DIRS
SPACK_STORE_LINK_DIRS=""; export SPACK_STORE_LINK_DIRS
SPACK_STORE_RPATH_DIRS=/cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib:/cluster/spack/packages/linux-almalinux9-x86_64_v3/gcc-11.4.1/gcc-runtime-11.4.1-w3a63xayu37ralwmc6jxy2cb6mmmwgu3/lib64; export SPACK_STORE_RPATH_DIRS
SPACK_SYSTEM_DIRS="\"/\"|\"//\"|\"/bin\"|\"/bin/\"|\"/bin64\"|\"/bin64/\"|\"/include\"|\"/include/\"|\"/lib\"|\"/lib/\"|\"/lib64\"|\"/lib64/\"|\"/usr\"|\"/usr/\"|\"/usr/bin\"|\"/usr/bin/\"|\"/usr/bin64\"|\"/usr/bin64/\"|\"/usr/include\"|\"/usr/include/\"|\"/usr/lib\"|\"/usr/lib/\"|\"/usr/lib64\"|\"/usr/lib64/\"|\"/usr/local\"|\"/usr/local/\"|\"/usr/local/bin\"|\"/usr/local/bin/\"|\"/usr/local/bin64\"|\"/usr/local/bin64/\"|\"/usr/local/include\"|\"/usr/local/include/\"|\"/usr/local/lib\"|\"/usr/local/lib/\"|\"/usr/local/lib64\"|\"/usr/local/lib64/\""; export SPACK_SYSTEM_DIRS
SPACK_TARGET_ARGS="-march=x86-64-v3 -mtune=generic"; export SPACK_TARGET_ARGS
SUDO_COMMAND=/bin/bash; export SUDO_COMMAND
SUDO_GID=2000; export SUDO_GID
SUDO_UID=2000; export SUDO_UID
SUDO_USER=mavieth; export SUDO_USER
TERM=alacritty; export TERM
USER=root; export USER
XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share; export XDG_DATA_DIRS
which_declare="declare -f"; export which_declare
</pre></details></li></ul>

> 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.

@haampie

## Note:

I'm able to fix the problem by adding `.path` to line 152 in `lib/spack/spack/hooks/absolutify_elf_sonames.py`. But I'm not sure, if this could break other setups.

### 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:
Possibly broken by #42318

Resolving patch:
diff --git a/lib/spack/spack/hooks/absolutify_elf_sonames.py b/lib/spack/spack/hooks/absolutify_elf_sonames.py
--- a/lib/spack/spack/hooks/absolutify_elf_sonames.py
+++ b/lib/spack/spack/hooks/absolutify_elf_sonames.py
@@ -13,7 +13,6 @@
 import spack.config
 import spack.relocate
 from spack.util.elf import ElfParsingError, parse_elf
-from spack.util.executable import Executable
 
 
 def is_shared_library_elf(filepath):
@@ -149,10 +148,9 @@ def post_install(spec, explicit=None):
         return
 
     # Should failing to locate patchelf be a hard error?
-    patchelf_path = spack.relocate._patchelf()
-    if not patchelf_path:
+    patchelf = spack.relocate._patchelf()
+    if not patchelf:
         return
-    patchelf = Executable(patchelf_path)
 
     fixes = find_and_patch_sonames(spec.prefix, spec.package.non_bindable_shared_objects, patchelf)
 


Test patch: