From 9a85a7a5aa9ce28d744fc5718470bc4e17dc7216 Mon Sep 17 00:00:00 2001 From: Patrick Gartung Date: Fri, 3 May 2019 16:41:57 -0500 Subject: Binary caches on MacOS - allow expanded RPATHs (#11345) Fixes #11335 Update the Spack compiler wrappers to add the headerpad_max_install_names linker flag on MacOS. This allows the install_name_tool to rewrite the RPATH entry of the binary to be longer if needed. This is primarily useful for creating and distributing binary caches of packages (i.e. using the "spack buildcache" command); binary caches created on MacOS before this commit may not successfully relocate (if the target root path is larger). --- lib/spack/env/cc | 11 +++++++++++ lib/spack/spack/test/cc.py | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lib/spack/env/cc b/lib/spack/env/cc index 199ce1d7e6..738a7e37af 100755 --- a/lib/spack/env/cc +++ b/lib/spack/env/cc @@ -382,6 +382,17 @@ case "$mode" in flags=("${flags[@]}" "${SPACK_LDFLAGS[@]}") ;; esac +# On macOS insert headerpad_max_install_names linker flag +if [[ ($mode == ld || $mode == ccld) && "$SPACK_SHORT_SPEC" =~ "darwin" ]]; +then + case "$mode" in + ld) + flags=("${flags[@]}" -headerpad_max_install_names) ;; + ccld) + flags=("${flags[@]}" -Wl,-headerpad_max_install_names) ;; + esac +fi + # Prepend include directories IFS=':' read -ra include_dirs <<< "$SPACK_INCLUDE_DIRS" if [[ $mode == cpp || $mode == cc || $mode == as || $mode == ccld ]]; then diff --git a/lib/spack/spack/test/cc.py b/lib/spack/spack/test/cc.py index 2a4d7ec3a8..3e8d5d8c70 100644 --- a/lib/spack/spack/test/cc.py +++ b/lib/spack/spack/test/cc.py @@ -79,6 +79,9 @@ spack_fflags = ['-w'] spack_ldflags = ['-L', 'foo'] spack_ldlibs = ['-lfoo'] +lheaderpad = ['-Wl,-headerpad_max_install_names'] +headerpad = ['-headerpad_max_install_names'] + @pytest.fixture(scope='session') def wrapper_environment(): @@ -451,6 +454,7 @@ def test_ld_deps_partial(): check_args( ld, ['-r'] + test_args, ['ld'] + + headerpad + test_include_paths + test_library_paths + ['-Lxlib'] + @@ -461,6 +465,7 @@ def test_ld_deps_partial(): def test_ccache_prepend_for_cc(): with set_env(SPACK_CCACHE_BINARY='ccache'): + os.environ['SPACK_SHORT_SPEC'] = "foo@1.2=linux-x86_64" check_args( cc, test_args, ['ccache'] + # ccache prepended in cc mode @@ -469,13 +474,34 @@ def test_ccache_prepend_for_cc(): test_library_paths + test_wl_rpaths + test_args_without_paths) + os.environ['SPACK_SHORT_SPEC'] = "foo@1.2=darwin-x86_64" + check_args( + cc, test_args, + ['ccache'] + # ccache prepended in cc mode + [real_cc] + + lheaderpad + + test_include_paths + + test_library_paths + + test_wl_rpaths + + test_args_without_paths) def test_no_ccache_prepend_for_fc(): + os.environ['SPACK_SHORT_SPEC'] = "foo@1.2=linux-x86_64" + check_args( + fc, test_args, + # no ccache for Fortran + [real_cc] + + test_include_paths + + test_library_paths + + test_wl_rpaths + + test_args_without_paths) + os.environ['SPACK_SHORT_SPEC'] = "foo@1.2=darwin-x86_64" check_args( fc, test_args, # no ccache for Fortran [real_cc] + + lheaderpad + test_include_paths + test_library_paths + test_wl_rpaths + -- cgit v1.2.3-70-g09d2