Skip to content

Implicit link paths - #7153

Merged
tgamblin merged 1 commit into
spack:developfrom
mathstuf:implicit-link-paths
Aug 24, 2019
Merged

tgamblin merged 1 commit into
spack:developfrom
mathstuf:implicit-link-paths

Conversation

@mathstuf

@mathstuf mathstuf commented Jan 31, 2018 •

Copy link
Copy Markdown
Contributor

Resolves #7115.

Currently Spack assumes that compilers add RPATHs for any non-standard runtime directories they use. For example, versions of g++ and the Intel compiler that support newer versions of C++ need an updated libstdc++.so, so they link against a libstdc++.so in $gcc_prefix/lib64. We call $gcc_prefix/lib64 here an "implicit link path" because the compiler implicitly links against libaries there that were not included on the command line.

While Spack-built compilers add RPATHs for these directories, compilers installed at many sites do not. This leads to the following type of error when you run binaries built with these compilers:

/tmp/spack00t/spack-stage/cmake-3.15.1-ywecvmgyzvulocevd5dmilq55zsz5jlp/spack-src/Bootstrap.cmk/cmake: /lib64/libstdc++.s
o.6: version `GLIBCXX_3.4.20' not found (required by /tmp/spack00t/spack-stage/cmake-3.15.1-ywecvmgyzvulocevd5dmilq55zsz5
jlp/spack-src/Bootstrap.cmk/cmake)

The solution so far has been to manually add extra_rpaths to compilers.yaml, which forces Spack to add the RPATHs, or to tell users to load the compiler's module when running with binaries it generated. Neither of these is ideal.

This PR eliminates those requirements by doing a few things:

  • Spack now auto-detects implicit link paths when it detects compilers, by querying compilers for what their implicit link paths are. This is borrowed from what CMake does to detect implicit link paths.

  • Spack adds these paths to compilers.yaml in a new implicit_rpaths field:

    compilers:
    - compiler:
        spec:[email protected]
        paths:
          cc: /opt/intel-19.0.1/bin/icc
          cxx: /opt/intel-19.0.1/bin/icpc
          f77: /opt/intel-19.0.1/bin/ifort
          fc: /opt/intel-19.0.1/bin/ifort
        environment: {}
        # spack now detects these implicit paths automatically and sets them here
        implicit_rpaths:
        - /opt/intel-19.0.1/compilers_and_libraries_2019.4.243/linux/compiler/lib/intel64_lin
        - /opt/gcc-4.9.3/lib64            
        # you can still edit extra_rpaths but likely do not need to
        extra_rpaths: []
        flags: {}
        modules: []
        operating_system: rhel7
        target: x86_64
  • Spack's compiler wrappers now automatically inject implicit RPATHs into binaries they build.

So, in summary, you likely no longer need to fiddle with extra_rpaths. If you do have to, file an issue, and we'll see if we need to add more detection for it.

@mathstuf
mathstuf requested a review from tgamblin January 31, 2018 22:06
@mathstuf
mathstuf force-pushed the implicit-link-paths branch 3 times, most recently from a7dea12 to 09cd996 Compare February 5, 2018 16:56
@mathstuf mathstuf changed the title WIP: Implicit link paths Implicit link paths Feb 5, 2018
@mathstuf
mathstuf force-pushed the implicit-link-paths branch from 09cd996 to 3f2eaaa Compare February 5, 2018 19:48
Comment thread lib/spack/spack/compiler.py Resolved
@aharrison24

Copy link
Copy Markdown
Contributor

This will be really useful!

With this branch checked out on an ubuntu 16.04 VM, I installed llvm inside a spack instance and did this:

$ spack load llvm
$ spack compiler find

The clang compiler was picked up correctly, and the implicit link paths were deduced as:

    implicit_link_paths:
    - /opt/spack_llvm_bootstrap/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/llvm-5.0.1-a7juikjjoqn3fvldllpyohi44tumybrn/lib
    - /usr/lib/x86_64-linux-gnu
    - /usr/lib/gcc/x86_64-linux-gnu/5.4.0
    - /usr/lib
    - /lib64
    - /lib
    - /lib/x86_64-linux-gnu

Is it correct/expected that it would be picking up those library paths related to the system's gcc compiler?

@mathstuf

mathstuf commented Feb 7, 2018

Copy link
Copy Markdown
Contributor Author

Is it correct/expected that it would be picking up those library paths related to the system's gcc compiler?

That depends on the build. It may have compiled those in during its build.

@aharrison24

Copy link
Copy Markdown
Contributor

OK. So this could be an issue with the llvm package in spack?

For what it's worth, here is the output of a verbose build using the clang++ compiler from the llvm package.
https://gist.github.com/aharrison24/d4448432d06c2fdc74a54a74a686e40b
In the ld line at the bottom, all of those system library paths are listed before the spack llvm library paths.

So it does seem like the PR is doing the right thing in this case and the behaviour I'm seeing is caused by issues elsewhere.

Will there be a separate PR to have spack act upon the information in the implicit_link_paths field of compilers.yaml? Can't find any reference to that anywhere.

@mathstuf

mathstuf commented Feb 7, 2018

Copy link
Copy Markdown
Contributor Author

Will there be a separate PR to have spack act upon the information in the implicit_link_paths field of compilers.yaml? Can't find any reference to that anywhere.

Yes, that is the rest of #7115 and #7120.

@mathstuf
mathstuf force-pushed the implicit-link-paths branch from 3f2eaaa to 8ad3608 Compare February 13, 2018 17:09

@tgamblin tgamblin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good! Thanks. I added some comments. Also, this needs a few unit tests with output from different compilers. Can you add unit tests?

If you need access to the compilers, we have them on our clusters. You can module load them.

Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
@mathstuf
mathstuf force-pushed the implicit-link-paths branch from 8ad3608 to fe7506d Compare February 21, 2018 16:01
@mathstuf

Copy link
Copy Markdown
Contributor Author

Updated for the requested changes. Unit tests are still missing. Though, I'm not sure what to expect in those tests.

@tgamblin

tgamblin commented Feb 21, 2018 •

Copy link
Copy Markdown
Member

@mathstuf: can you just make the tests simple scripts or test cases to exercise the parsing logic? Basically I would just run each compiler with the verbose_flag, and make sure that for the output, the expected implicit paths are generated.

@mathstuf

Copy link
Copy Markdown
Contributor Author

expected implicit paths are generated.

This is what I don't know to write in the tests. A compiler loaded from /opt/intel-16.10 is going to differ from one in /opt/intel-17.10. Should I just expect a non-empty list?

@tgamblin

Copy link
Copy Markdown
Member

This is what I don't know to write in the tests. A compiler loaded from /opt/intel-16.10 is going to differ from one in /opt/intel-17.10. Should I just expect a non-empty list?

Maybe I was vague. I mean you could run a compiler on the cluster and take its output and put that in the test suite to exercise things. So the test suite shouldn't actually interact with a compiler -- just some saved output, for which you'd know what to expect.

@mathstuf

Copy link
Copy Markdown
Contributor Author

Well, that'd make the test pass (or not-skipped) on that one machine and fail (or skip) on everything else. I doubt the efficacy of such a test.

@tgamblin

Copy link
Copy Markdown
Member

It's not supposed to be a machine-specific test, just a spot test to prevent regression in the parser. Let's get the output of several different compilers (on several machines if you want), and make sure _determine_implicit_link_paths() works on it. The test would be something like:

lib/spack/spack/test/data/
    implicit_link_paths/
        icc-16.0.1.out
        icc-17.2.3.out
        xl-10.1.out
        clang-3.9.0.out

And the test would read those in and validate that implicit_link_paths() works on at least some inputs we know about. If we add code changes, we can avoid some regressions.

Agreed that it's not going to validate every machine, but it's better than nothing.

@mathstuf

Copy link
Copy Markdown
Contributor Author

That still doesn't help. My clang-3.9.0 is in /usr. On Apple, it's under some Homebrew directory. Someone else might have it as a module under /opt/clang/3.9.0. There's no general answer to "oh, you have this compiler, I know the paths you're supposed to be using". It's like trying to test os.path.expanduser('~') with /home/boeckb as the expected value; it doesn't work as a unit test.

Comment thread lib/spack/spack/compiler.py Resolved
@tgamblin

Copy link
Copy Markdown
Member

That still doesn't help. My clang-3.9.0 is in /usr. On Apple, it's under some Homebrew directory. Someone else might have it as a module under /opt/clang/3.9.0. There's no general answer to "oh, you have this compiler, I know the paths you're supposed to be using". It's like trying to test os.path.expanduser('~') with /home/boeckb as the expected value; it doesn't work as a unit test.

I added two simple tests to show what I'm talking about. Again, it's not a system test, it's a parser regression test. All I had to do was factor out the parsing part. Can you add some more for other compilers?

There's another question in here which is where we should filter system paths. We're going to RPATH these things, so system paths shouldn't be added to the RPATH. There is spack.util.environment.filter_system_paths() that we'll probably need in here.

@mathstuf

Copy link
Copy Markdown
Contributor Author

Ah, I see now. Sorry, I missed that you wanted a refactor to separate out the inner logic. This makes more sense now.

I updated it to also check that we don't extract incorrect paths from the compilers.

There's another question in here which is where we should filter system paths. We're going to RPATH these things, so system paths shouldn't be added to the RPATH. There is spack.util.environment.filter_system_paths() that we'll probably need in here.

I think it should be filtered where RPATHs are handled. The implicit link paths are used no matter what. Spack should filter where it adds rpaths, not in the storage of the implicit link paths.

@scheibelp

Copy link
Copy Markdown
Member

@tgamblin: this is an update on the current state of the PR. I'm currently considering a few ways to achieve the appropriate balance in filtering paths.

Originally this was failing because the following implicit link directories are detected for gcc 4.8 (i.e. this is from ~/.spack/linux/compilers.yaml):

implicit_rpaths:
- /usr/lib/gcc/x86_64-linux-gnu/4.8
- /usr/lib/x86_64-linux-gnu
- /lib/x86_64-linux-gnu

In particular, /usr/lib/x86_64-linux-gnu contains libpython2.7.so; when installing python, the make target instructions point LD_LIBRARY_PATH to the libpython2.7.so created for that python installation, but this is overridden by the RPATH (which takes precedence).

Currently this is addressed by following up after spack.util.environment.filter_system_paths by additionally removing paths which contain /usr/ or /usr/lib/ as a prefix whereas filter_system_paths only removes paths if they exactly match.

filter_system_paths should keep its original behavior because it includes /usr/local/ and AFAIK that could be managed using per-package prefixes (which would not be auto-included by ld). Arguably this also means that the current compiler link path filtering is too aggressive.

I can think of three ways to proceed with this:

  • check candidate directories for the presence of compiler libraries (e.g. libgcc.a) - this isn't necessarily foolproof since they could appear in a shared prefix
  • check whether the path explicitly mentions a compiler: this is an even looser heuristic but would work here
  • The most-aggressive but safest option I can think of is to specifically look for a spack metadata directory relative to the listed binaries. One of the main goals is to avoid RPATH errors with spack-built compilers and this would address that directly without above problems with including too much.

@tgamblin tgamblin self-assigned this Jul 21, 2018
@becker33
becker33 force-pushed the implicit-link-paths branch 3 times, most recently from e02efdd to 063cb07 Compare August 23, 2019 14:35
Comment thread lib/spack/env/cc Resolved
Comment thread lib/spack/spack/build_environment.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread lib/spack/spack/compiler.py Resolved
Comment thread share/spack/qa/run-build-tests Resolved

@tgamblin tgamblin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last request: _parse_implicit_rpaths should be fully covered. The other stuff (like verbose_flag) seems unnecessary, but there are parts of that method that are not yet covered by the tests.

@adamjstewart

Copy link
Copy Markdown
Member

This looks great! The only question I had seems to have already been asked: why are we creating an extra field called implicit_rpaths instead of auto-populating extra_rpaths? I'll assume most compilers have been thoroughly tested. Let me know if you need/want any additional compilers or old versions to be tested.

@becker33

Copy link
Copy Markdown
Member

why are we creating an extra field called implicit_rpaths instead of auto-populating extra_rpaths

@adamjstewart because the extra_rpaths field could still be useful to add libraries into the build. I'm not 100% sure, but I think we could use it to swap openmp runtimes, for example.

Libraries in extra_rpaths have -L and -Wl,-rpath flags generated. The libraries in implicit_rpaths have implied -L flags, so we only need to generate the -Wl,-rpath flags.

@tgamblin
tgamblin force-pushed the implicit-link-paths branch 2 times, most recently from a025bc9 to 222b586 Compare August 23, 2019 18:42
Uses code from CMake to detect implicit link paths from compilers
System paths are filtered out of implicit link paths
Implicit link paths added to compiler config and object under `implicit_rpaths`
Implicit link paths added as rpaths to compile line through env/cc wrapper

Authored by: "Ben Boeckel <[email protected]>"
Co-authored by: "Peter Scheibel <[email protected]>"
Co-authored by: "Gregory Becker <[email protected]>"
@tgamblin
tgamblin force-pushed the implicit-link-paths branch from 222b586 to bb4827c Compare August 23, 2019 18:45
@tgamblin

tgamblin commented Aug 23, 2019 •

Copy link
Copy Markdown
Member

The other main gist of it is that extra_rpaths is for people and implicit_rpaths is for Spack. If we had one field, Spack could clobber something someone wrote. We wanted to avoid that and allow both to coexist.

@tgamblin
tgamblin merged commit c22a145 into spack:develop Aug 24, 2019
@adamjstewart

Copy link
Copy Markdown
Member

I'm seeing some odd behavior with this PR. When I run spack compiler find, it pulls in a lot of implicit RPATHs that don't seem to be related to the compilers themselves:

compilers:
- compiler:
    environment: {}
    extra_rpaths: []
    flags: {}
    implicit_rpaths:
    - /opt/cray/cce/8.4.6/CC/x86-64/lib/x86-64
    - /opt/gcc/4.8.1/snos/lib64
    - /opt/cray/dmapp/default/lib64
    - /opt/cray/mpt/7.5.0/gni/mpich-cray/8.4/lib
    - /opt/cray/libsci/16.11.1/CRAY/8.3/x86_64/lib
    - /sw/xe/darshan/3.1.3/darshan-3.1.3/lib
    - /opt/cray/rca/1.0.0-2.0502.60530.1.63.gem/lib64
    - /opt/cray/alps/5.2.4-2.0502.9774.31.12.gem/lib64
    - /opt/cray/xpmem/0.1-2.0502.64982.5.3.gem/lib64
    - /opt/cray/dmapp/7.0.1-1.0502.11080.8.74.gem/lib64
    - /opt/cray/pmi/5.0.10-1.0000.11050.179.3.gem/lib64
    - /opt/cray/ugni/6.0-1.0502.10863.8.28.gem/lib64
    - /opt/cray/udreg/2.3.2-1.0502.10518.2.17.gem/lib64
    - /opt/cray/atp/2.0.4/libApp
    - /opt/cray/cce/8.4.6/craylibs/x86-64
    - /opt/cray/wlm_detect/1.0-1.0502.64649.2.2.gem/lib64
    - /opt/gcc/4.8.1/snos/lib/gcc/x86_64-suse-linux/4.8.1
    - /opt/cray/cce/8.4.6/cray-binutils/x86_64-unknown-linux-gnu/lib
    modules: []
    operating_system: suse_linux11
    paths:
      cc: /opt/cray/craype/2.5.8/bin/cc
      cxx: /opt/cray/craype/2.5.8/bin/CC
      f77: /opt/cray/craype/2.5.8/bin/ftn
      fc: /opt/cray/craype/2.5.8/bin/ftn
    spec: [email protected]
    target: x86_64
- compiler:
    environment: {}
    extra_rpaths: []
    flags: {}
    implicit_rpaths:
    - /usr/lib64/gcc/x86_64-suse-linux/4.3
    - /sw/EasyBuild/software/cURL/7.59.0/lib
    - /sw/EasyBuild/software/OpenSSL/1.0.2m/lib
    - /usr/x86_64-suse-linux/lib
    modules: []
    operating_system: suse_linux11
    paths:
      cc: /usr/bin/X11/gcc-4.3
      cxx: /usr/bin/X11/g++-4.3
      f77: null
      fc: null
    spec: [email protected]
    target: x86_64
- compiler:
    environment: {}
    extra_rpaths: []
    flags: {}
    implicit_rpaths:
    - /usr/lib64/gcc/x86_64-suse-linux/4.3
    - /sw/EasyBuild/software/cURL/7.59.0/lib
    - /sw/EasyBuild/software/OpenSSL/1.0.2m/lib
    - /usr/x86_64-suse-linux/lib
    modules: []
    operating_system: suse_linux11
    paths:
      cc: null
      cxx: null
      f77: /usr/bin/X11/gfortran-4.3
      fc: /usr/bin/X11/gfortran-4.3
    spec: [email protected]
    target: x86_64
- compiler:
    environment: {}
    extra_rpaths: []
    flags: {}
    implicit_rpaths:
    - /usr/lib64/gcc/x86_64-suse-linux/4.7
    - /sw/EasyBuild/software/cURL/7.59.0/lib
    - /sw/EasyBuild/software/OpenSSL/1.0.2m/lib
    - /usr/x86_64-suse-linux/lib
    modules: []
    operating_system: suse_linux11
    paths:
      cc: /usr/bin/X11/gcc-4.7
      cxx: /usr/bin/X11/g++-4.7
      f77: null
      fc: null
    spec: [email protected]
    target: x86_64

A user on Slack reported the same issue:

    implicit_rpaths:
    - /cm/shared/apps/slurm/14.03.0/lib64
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-4.4.7/gcc-5.5.0-2jzzwnbvmmzblo26gkspqky6hxw7pk27/lib64
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-4.4.7/gcc-9.2.0-hp2yw3l6kykego2cgj3diofr27ovo35d/lib/gcc/x86_64-pc-linux-gnu/9.2.0
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-4.4.7/gcc-9.2.0-hp2yw3l6kykego2cgj3diofr27ovo35d/lib64
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-5.5.0/ncurses-6.1-73q5txyg6am43d4kzs34eeea6edwagcp/lib
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-4.4.7/gcc-5.5.0-2jzzwnbvmmzblo26gkspqky6hxw7pk27/lib
    - /md1200-1/home/CMAP/ruben.di-battista/.opt/linux-scientific6-x86_64/gcc-4.4.7/gcc-9.2.0-hp2yw3l6kykego2cgj3diofr27ovo35d/lib

This user encountered build errors with numpy, and had to remove these implicit_rpaths in order to build numpy.

@adamjstewart

Copy link
Copy Markdown
Member

@becker33 getting more reports of erroneous implicit RPATHs causing build failures: #12709 (comment)

@scheibelp scheibelp mentioned this pull request Sep 11, 2019
3 of 5 tasks
jrmadsen pushed a commit to jrmadsen/spack that referenced this pull request Oct 30, 2019
Uses code from CMake to detect implicit link paths from compilers
System paths are filtered out of implicit link paths
Implicit link paths added to compiler config and object under `implicit_rpaths`
Implicit link paths added as rpaths to compile line through env/cc wrapper

Authored by: "Ben Boeckel <[email protected]>"
Co-authored by: "Peter Scheibel <[email protected]>"
Co-authored by: "Gregory Becker <[email protected]>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Spack's detection of compiler run paths

6 participants