This is an archive of the discontinued LLVM Phabricator instance.

Make LIBOMP_CONFIGURED_LIBFLAGS a list instead of string
ClosedPublic

Authored by msimberg on May 11 2022, 3:40 AM.

Details

Summary

When configuring llvm with the openmp subproject, the build for the omp target
fails if LIBOMP_CONFIGURED_LIBFLAGS contains more than one item.
LIBOMP_CONFIGURED_LIBFLAGS should be a semicolon-separated list instead of a
string with items separated by spaces for this call to target_link_libraries:
https://reviews.llvm.org/source/llvm-github/browse/main/openmp/runtime/src/CMakeLists.txt$148.

I can reproduce the failure with both the "Unix Makefiles" and "Ninja"
generators on Linux and from what I understand CMake does really expect a
semicolon-separated list and not a space-separated string (indirectly based on
the help text under "A generator expression" here:
https://cmake.org/cmake/help/latest/command/target_link_libraries.html?highlight=target_link_libraries#overview).

I'm assuming this can be reproduced quite easily in many setups but I can for
example reproduce it with a nix environment with the following shell.nix:

{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {

buildInputs = with pkgs; [ hwloc ];

}

and then entering the shell with nix-shell shell.nix and configuring llvm e.g. as follows:

cmake -DLLVM_ENABLE_PROJECTS="clang;openmp" -DLIBOMP_USE_HWLOC=ON -DCMAKE_BUILD_TYPE=Release ../llvm

Configuration passes but compilation fails. With Ninja:

$ ninja omp
ninja: error: '/nix/store/8d3mc9m48w8bg118aw4dpvifn9zm59r9-hwloc-2.7.1-lib/lib/libhwloc.so -lm', needed by 'lib/libomp.so', missing and no known rule to make it

and with make:

$ make omp
Built target libomp-needed-headers
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_alloc.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_atomic.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_csupport.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_debug.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_itt.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_environment.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_error.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_global.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_i18n.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_io.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_runtime.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_settings.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_str.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_tasking.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_threadprivate.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_utility.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_barrier.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_wait_release.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_affinity.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_dispatch.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_lock.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_sched.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/thirdparty/ittnotify/ittnotify_static.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_taskdeps.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_cancel.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_version.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/ompt-general.cpp.o
Building CXX object projects/openmp/runtime/src/CMakeFiles/omp.dir/ompd-specific.cpp.o
Building C object projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o
make[3]: * No rule to make target '/nix/store/8d3mc9m48w8bg118aw4dpvifn9zm59r9-hwloc-2.7.1-lib/lib/libhwloc.so -lm', needed by 'lib/libomp.so'. Stop.
make[2]:
* [CMakeFiles/Makefile2:30563: projects/openmp/runtime/src/CMakeFiles/omp.dir/all] Error 2
make[1]: * [CMakeFiles/Makefile2:30570: projects/openmp/runtime/src/CMakeFiles/omp.dir/rule] Error 2
make:
* [Makefile:7638: omp] Error 2

In my understanding not all flags need to (or can) be lists, so I've only made a
local change in libomp_get_libflags and not made the change in e.g.
libomp_setup_flags
(https://reviews.llvm.org/source/llvm-github/browse/main/openmp/runtime/cmake/LibompHandleFlags.cmake$14)
which would apply to all libomp_get_*flags functions.

If in a particular configuration LIBOMP_CONFIGURED_LIBFLAGS ends up having only
one or zero items all is fine, e.g. if hwloc is not used.

I have not made any attempts to look for other places where this may need
fixing as I'm not otherwise familiar with the codebase.

This is also my first contribution so apologies in advance if I've missed
something.

Diff Detail

Event Timeline

msimberg created this revision.May 11 2022, 3:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 3:40 AM
Herald added a subscriber: mgorny. · View Herald Transcript
msimberg requested review of this revision.May 11 2022, 3:40 AM
Herald added a project: Restricted Project. · View Herald Transcript
haampie accepted this revision.May 11 2022, 3:45 AM
This revision is now accepted and ready to land.May 11 2022, 3:45 AM

Ping, any comments on this?

Appreciate the fix! It looks fine to me. Do you need someone to push it for you?

jlpeyton accepted this revision.Jun 1 2022, 8:44 AM

Do you need someone to push it for you?

I assume so, yes! That is to say I wouldn't even know where to push this, let alone do I think I have rights to push this to the right place.

This revision was landed with ongoing or failed builds.Jun 2 2022, 8:51 AM
This revision was automatically updated to reflect the committed changes.