Cling + LLVM 13 from monorepo fails to compile with libc++

Overview

To start with, I have Cling + LLVM 13 building and working fine using the monorepo using libstdc++. However, when I try to build with libc++, I run into compilation errors in LLVM. Is anyone using this? If so, any tips to get it working?

Secondary question, any idea why I always see “Cannot determine location of C++ headers for runtime.” in that compilation log. To me, this seems related to this issue: Libc++ issue on Linux - #10 by Axel

Setup

I’m on Arch, using system Clang 15 to build.

cling_url="https://github.com/root-project/cling.git"
cling_branch="master" # commit acb2334131c19ef506767d6d9051b24755a8566b
llvm_url="https://github.com/root-project/llvm-project.git"
llvm_branch="cling-llvm13"

LLVM configuration

  cmake -DCMAKE_BUILD_TYPE=Release \
        -DCMAKE_CXX_STANDARD=20 \
        -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \
        -DLLVM_BUILD_LLVM_DYLIB=OFF \
        -DLLVM_ENABLE_RTTI=ON \
        -DLLVM_ENABLE_FFI=ON \
        -DLLVM_BUILD_DOCS=OFF \
        -DLLVM_ENABLE_SPHINX=OFF \
        -DLLVM_ENABLE_DOXYGEN=OFF \
        -DLLVM_ENABLE_LIBCXX=ON \
        -DLLVM_ENABLE_WERROR=OFF \
        -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" \
        -DLLVM_EXTERNAL_PROJECTS=cling \
        -DLLVM_EXTERNAL_CLING_SOURCE_DIR="${srcdir}/cling" \
        -DFFI_INCLUDE_DIR="${ffi_include_dir}" \
        -DCLING_CXX_HEADERS=ON \
        "${srcdir}/llvm/llvm"

Compilation output

~/projects/jank/build on main [M] at 23:31:40
❯ ../bin/build-cling
Using 32 cores to build
-- clang project is enabled
-- clang-tools-extra project is enabled
-- compiler-rt project is disabled
-- cross-project-tests project is disabled
-- libc project is disabled
-- libclc project is disabled
-- libcxx project is disabled
-- libcxxabi project is disabled
-- libunwind project is disabled
-- lld project is disabled
-- lldb project is disabled
-- mlir project is disabled
-- openmp project is disabled
-- parallel-libs project is disabled
-- polly project is disabled
-- pstl project is disabled
-- flang project is disabled
-- cling project is enabled
-- Native target architecture is X86
-- Threads enabled.
-- Doxygen disabled.
-- Go bindings enabled.
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH)
-- Could NOT find OCaml (missing: OCAMLFIND OCAML_VERSION OCAML_STDLIB_PATH)
-- OCaml bindings disabled.
-- LLVM host triple: x86_64-unknown-linux-gnu
-- LLVM default target triple: x86_64-unknown-linux-gnu
-- Building with -fPIC
-- Targeting NVPTX
-- Targeting X86
-- Clang version: 13.0.0
-- Not building amdgpu-arch: hsa-runtime64 not found
-- Cling version (from VERSION file): 1.0~dev
CMake Warning at /home/jeaye/projects/jank/build/cling/lib/Interpreter/CMakeLists.txt:281 (MESSAGE):
  Cannot determine location of C++ headers for runtime.


-- Cling will look for C++ headers in '' at runtime.
-- And then fallback to: 'clang-15'
CMake Warning (dev) at /usr/share/cmake/Modules/ExternalProject.cmake:2271 (message):
  Policy CMP0114 is not set: ExternalProject step targets fully adopt their
  steps.  Run "cmake --help-policy CMP0114" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  ExternalProject target 'builtins' would depend on the targets for step(s)
  'clean' under policy CMP0114, but this is being left out for compatibility
  since the policy is not set.
Call Stack (most recent call first):
  cmake/modules/LLVMExternalProjectUtils.cmake:333 (ExternalProject_Add_StepTargets)
  runtimes/CMakeLists.txt:81 (llvm_ExternalProject_Add)
  runtimes/CMakeLists.txt:134 (builtin_default_target)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at /usr/share/cmake/Modules/ExternalProject.cmake:2271 (message):
  Policy CMP0114 is not set: ExternalProject step targets fully adopt their
  steps.  Run "cmake --help-policy CMP0114" for policy details.  Use the
  cmake_policy command to set the policy and suppress this warning.

  ExternalProject target 'runtimes' would depend on the targets for step(s)
  'clean' under policy CMP0114, but this is being left out for compatibility
  since the policy is not set.
Call Stack (most recent call first):
  cmake/modules/LLVMExternalProjectUtils.cmake:333 (ExternalProject_Add_StepTargets)
  runtimes/CMakeLists.txt:226 (llvm_ExternalProject_Add)
  runtimes/CMakeLists.txt:363 (runtime_default_target)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Registering Bye as a pass plugin (static build: OFF)
-- LLVM FileCheck Found: /usr/bin/FileCheck
-- Version: 0.0.0
-- Performing Test HAVE_THREAD_SAFETY_ATTRIBUTES -- failed to compile
-- Performing Test HAVE_GNU_POSIX_REGEX -- failed to compile
-- Performing Test HAVE_POSIX_REGEX -- success
-- Performing Test HAVE_STEADY_CLOCK -- success
-- Configuring done (4.2s)
-- Generating done (2.3s)
-- Build files have been written to: /home/jeaye/projects/jank/build/cling-build
make: Entering directory '/home/jeaye/projects/jank/build-monorepo/cling-build/tools/clang'
[  0%] Built target CheckerDependencyHandlingAnalyzerPlugin_exports
[  0%] Built target scan-view
[  0%] Built target CheckerOptionHandlingAnalyzerPlugin_exports
[  0%] Built target llvm_vcsrevision_h
[  0%] Built target SampleAnalyzerPlugin_exports
[  0%] Built target scan-build-py
[  0%] Built target scan-build
[  0%] Built target hmaptool
[  0%] Built target LLVMDemangle
[  1%] Built target obj.clang-tblgen
[  3%] Built target obj.llvm-tblgen
[  3%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/StringSaver.cpp.o
[  5%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.o
[  5%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/StringExtras.cpp.o
[  5%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/SpecialCaseList.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Statistic.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/StringMap.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/StringRef.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ToolOutputFile.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Timer.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/SuffixTree.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Triple.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TarWriter.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TargetParser.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/SystemUtils.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/SymbolRemappingReader.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ThreadPool.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TimeProfiler.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/VersionTuple.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TrigramIndex.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Unicode.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Twine.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TypeSize.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/UnicodeCaseFold.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/VirtualFileSystem.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/WithColor.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/X86TargetParser.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/YAMLParser.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/raw_os_ostream.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/raw_ostream.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/YAMLTraits.cpp.o
[  7%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regcomp.c.o
[  7%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regerror.c.o
[  7%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regexec.c.o
[  7%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regfree.c.o
[  7%] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/regstrlcpy.c.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/xxhash.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Z3Solver.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Atomic.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/DynamicLibrary.cpp.o
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/StringSaver.cpp:9:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/StringSaver.h:12:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseSet.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/SuffixTree.cpp:13:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/SuffixTree.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Errno.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Host.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Memory.cpp.o
1 warning generated.
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Path.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Process.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Program.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/RWMutex.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/TargetRegistry.cpp.o
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/TimeProfiler.cpp:17:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/JSON.h:49:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/ThreadLocal.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Threading.cpp.o
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Valgrind.cpp.o
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/CodeGenCoverage.cpp:24:30: error: declaration requires a global destructor [-Werror,-Wglobal-constructors]
static sys::SmartMutex<true> OutputMutex;
                             ^
[  7%] Building CXX object lib/Support/CMakeFiles/LLVMSupport.dir/Watchdog.cpp.o
1 warning generated.
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/VirtualFileSystem.cpp:15:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
1 error generated.
make[2]: *** [lib/Support/CMakeFiles/LLVMSupport.dir/build.make:412: lib/Support/CMakeFiles/LLVMSupport.dir/CodeGenCoverage.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/DynamicLibrary.cpp:15:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseSet.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
1 warning generated.
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/TargetRegistry.cpp:9:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/TargetRegistry.h:26:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/MC/MCObjectFileInfo.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
1 warning generated.
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:32:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/StringSaver.h:12:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseSet.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Program.cpp:103:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Program.inc:27:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/Support/StringSaver.h:12:
In file included from /home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseSet.h:16:
/home/jeaye/projects/jank/build/llvm/llvm/include/llvm/ADT/DenseMap.h:128:16: warning: variable 'NumEntries' set but not used [-Wunused-but-set-variable]
      unsigned NumEntries = getNumEntries();
               ^
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:86:26: error: declaration requires a global constructor [-Werror,-Wglobal-constructors]
static CallbackAndCookie CallBacksToRun[MaxSignalHandlerCallbacks];
                         ^~~~~~~~~~~~~~
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:88:5: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
    ATOMIC_VAR_INIT(nullptr);
    ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:90:5: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
    ATOMIC_VAR_INIT(nullptr);
    ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:93:5: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
    ATOMIC_VAR_INIT(nullptr);
    ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:101:34: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
  std::atomic<char *> Filename = ATOMIC_VAR_INIT(nullptr);
                                 ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:102:42: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
  std::atomic<FileToRemoveList *> Next = ATOMIC_VAR_INIT(nullptr);
                                         ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:191:56: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
static std::atomic<FileToRemoveList *> FilesToRemove = ATOMIC_VAR_INIT(nullptr);
                                                       ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
In file included from /home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Signals.cpp:251:
/home/jeaye/projects/jank/build/llvm/llvm/lib/Support/Unix/Signals.inc:246:53: warning: macro 'ATOMIC_VAR_INIT' has been marked as deprecated [-Wdeprecated-pragma]
static std::atomic<unsigned> NumRegisteredSignals = ATOMIC_VAR_INIT(0);
                                                    ^
/usr/bin/../include/c++/v1/atomic:2671:43: note: macro marked 'deprecated' here
#  pragma clang deprecated(ATOMIC_VAR_INIT)
                                          ^
1 warning generated.
8 warnings and 1 error generated.
make[2]: *** [lib/Support/CMakeFiles/LLVMSupport.dir/build.make:1924: lib/Support/CMakeFiles/LLVMSupport.dir/Signals.cpp.o] Error 1
1 warning generated.
1 warning generated.
make[1]: *** [CMakeFiles/Makefile2:12233: lib/Support/CMakeFiles/LLVMSupport.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
make: Leaving directory '/home/jeaye/projects/jank/build-monorepo/cling-build/tools/clang'

May be @Axel or @vvassilev can help.

Does this commit help? If so we’ll try to backport it.

Ah, good find. Looks like it’s the same exact problem as that commit, but another piece of data. This time it’s the static sys::SmartMutex<true> OutputMutex; which would need to be wrapped in a function.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.