-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make macOS installed libraries more relocatable #26608
Conversation
Multiple times on my mac, trying to install in parallel led to failures from multiple tasks trying to simultaneously create `$PREFIX/lib`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as is passes spack unit-test -k bindist
I am OK with the changes.
c886c85
to
9094be5
Compare
@gartung @alalazo Please take a look at this when you have a minute. With this change, making build caches on macOS should be much easier and it should be easier for external tools to relocate spack libraries: in both cases, the only change to be made to shared libraries will be to update their rpaths. I've tested this out on my macOS and it correctly patches my entire toolchain so far (including perl, pcre, gcc, zstd, zlib, glib, etc.), but I'll update when I can confirm that our downstream tools (and CMake's |
packages) that do not install relocatable libraries by default. | ||
""" | ||
if 'platform=darwin' not in self.spec: | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it would be a good idea to add a config
option to control the automatic behavior? That way we could turn it off by default if we're worried about side effects or longer build+install times.
@@ -82,7 +84,7 @@ def _patchelf(): | |||
Return None on Darwin or if patchelf cannot be found. | |||
""" | |||
# Check if patchelf is already in the PATH | |||
patchelf = spack.util.executable.which('patchelf') | |||
patchelf = executable.which('patchelf') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alalazo Was this working before?
Found one issue due to this change: the relocatable code change the absolute path of libgfortran to an rpath, but this exposes a bug related to my other lovely walk through RPATH hell, #26582 !! Without the library fixup, code compiled/linked with Linking against libgfortran with the fixup exposes this, since for some reason the RPATH entries for So I will update #26590 to use the correct rpath command on macOS, which should be merged before this PR. |
I'm going to examine this a bit more. It has consequences when using spack GCC Fortran as part of a mixed toolchain on macOS. |
This restores the hardcoded library path for GCC.
OK, this should be much more reliable. I'm testing this (as well as #26590) on my mac now. |
After spack#26608 I got a report about missing rpaths when building a downstream package independently using a spack-installed toolchain (@tmdelellis). This occurred because the spack-installed libraries were being linked into the downstream app, but the rpaths were not being manually added. Prior to spack#26608 autotools-installed libs would retain their hard-coded path and would thus propagate their link information into the downstream library on mac. We could solve this problem *if* the mac linker (ld) respected `LD_RUN_PATH` like it does on GNU systems, i.e. adding `rpath` entries to each item in the environment variable. However on mac we would have to manually add rpaths either using spack's compiler wrapper scripts or manually (e.g. using `CMAKE_BUILD_RPATH` and pointing to the libraries of all the autotools-installed spack libraries). The easier and safer thing to do for now is to simply stop changing the dylib IDs.
…27139) After #26608 I got a report about missing rpaths when building a downstream package independently using a spack-installed toolchain (@tmdelellis). This occurred because the spack-installed libraries were being linked into the downstream app, but the rpaths were not being manually added. Prior to #26608 autotools-installed libs would retain their hard-coded path and would thus propagate their link information into the downstream library on mac. We could solve this problem *if* the mac linker (ld) respected `LD_RUN_PATH` like it does on GNU systems, i.e. adding `rpath` entries to each item in the environment variable. However on mac we would have to manually add rpaths either using spack's compiler wrapper scripts or manually (e.g. using `CMAKE_BUILD_RPATH` and pointing to the libraries of all the autotools-installed spack libraries). The easier and safer thing to do for now is to simply stop changing the dylib IDs.
Fixes #26544 and #26552 by adding a post-install step on macOS for autotools-based and package-based packages. The fixup will:
$prefix/foo.dylib
paths with@rpath/foo.dylib
if and only if$prefix
is in the library's list of rpaths$spack_root/$other/bar.dylib
with@rpath/bar.dylib
and add$spack_root/$other
to the rpath listI used the following script to successfully fix up a number of affected (already installed) libraries:
Of course, libraries that link against the previously broken ones are unaffected since they may still contain hard-coded library IDs. But newly installed binaries from here out will not.