[cfe-users] Need a GCC-free LLVM/Clang on Linux.

Chris Green via cfe-users cfe-users at lists.llvm.org
Tue Mar 10 07:53:14 PDT 2020


Hi,

On 2/19/20 4:02 PM, Richard Smith wrote:
> I have a two-stage setup that builds a GCC-free Clang except for 
> libgcc_s (I've not looked at what's pulling that in yet, but I expect 
> that's resolvable).
>
> My stage1 cmake setup has: -DCLANG_DEFAULT_CXX_STDLIB=libc++ 
> -DCLANG_DEFAULT_RTLIB=compiler-rt
> My stage2 cmake setup additionally 
> has: -DLIBCXXABI_USE_LLVM_UNWINDER=ON -DLIBCXXABI_USE_COMPILER_RT=ON 
> -DLIBCXX_USE_COMPILER_RT=ON
> (and points CMAKE_C_COMPILER and CMAKE_CXX_COMPILER at the stage1 clang).

Many thanks for this. I got further (I think) but I'm still hitting a 
snag (see below).

I'm attempting to use the cache method per the guide (latest caches 
attached), and I'm invoking them with:

+ env CC=clang CXX=clang++ cmake -GNinja -C /home/greenc/work/cet-is/test-products/clang/v9_0_1/patch/FNAL.cmake -DCMAKE_INSTALL_PREFIX=/home/greenc/work/cet-is/test-products/clang/v9_0_1/Linux64bit+3.10-2.17 -DBOOTSTRAP_LLVM_CXX_STD=c++17 -S ../../src/clang-9.0.1/llvm -B /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17

and

+ cmake --build /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17 -j 25 --target stage2 --

where which clang returns:

/home/greenc/work/cet-is/test-products/clang/v7_0_0/Linux64bit+3.10-2.17/bin/clang

and the default C++ standard library for this compiler is libc++.

I'm also attempting to build with C++17 (see command line) to allow for 
a later build of flang against the installed new compiler. Eventually I 
hope to get all the right components listed to be able to do a 
distribution installation such that the installed distribution is 
relocatable and able to operate as an SDK against which to compile other 
tools such as flang, castxml and include-what-you-use.

I appear to be getting through the compilation of the compiler, 
builtins, linker and basic tools (llvm-ar, llvm-nm, /etc./), but I'm 
experiencing a failure with the next compilation stage (full log 
attached, bzipped to 28K). During the runtimes configuration step I'm 
getting a worrying message about ranlib:

/home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/bin/llvm-ar: warning: creating t.a
/home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/bin/llvm-ranlib: error: Exactly one archive should be specified.

There are a couple of CMake policy warnings (CMP0077), and then when we 
try to perform the configure step for "stage2", we get:

-- Check for working CXX compiler: /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/./bin/clang++
-- Check for working CXX compiler: /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/./bin/clang++ -- broken
CMake Error at /home/greenc/work/cet-is/test-products/cmake/v3_14_3/Linux64bit+3.10-2.17/share/cmake-3.14/Modules/CMakeTestCXXCompiler.cmake:53 (message):
   The C++ compiler

     "/home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/./bin/clang++"

   is not able to compile a simple test program.

   It fails with the following output:

     Change Dir: /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/tools/clang/stage2-bins/CMakeFiles/CMakeTmp
     
     Run Build Command(s):/home/greenc/work/cet-is/test-products/ninja/v1_10_0/Linux64bit+3.10-2.17/bin/ninja cmTC_f1b67
     [1/2] Building CXX object CMakeFiles/cmTC_f1b67.dir/testCXXCompiler.cxx.o
     [2/2] Linking CXX executable cmTC_f1b67
     FAILED: cmTC_f1b67
     : && /home/greenc/work/cet-is/test-products/clang/v9_0_1/build/Linux64bit+3.10-2.17/./bin/clang++  -fno-stack-protector -fno-common -Wno-profile-instr-unprofiled   CMakeFiles/cmTC_f1b67.dir/testCXXCompiler.cxx.o  -o cmTC_f1b67   && :
     /usr/bin/ld: cannot find -lc++

Indeed, libc++ has not been built.

I'm obviously doing something silly, but I'm not able to ascertain from 
the documentation what it might be. I'll try again with a modern GCC 
(I'm on Scientific Linux 7, so the native GCC 4.8.5 is insufficient) 
just in case the Clang compiler is not recent enough to handle this, but 
I'm not optimistic. Any pointers you can give me would be very much 
appreciated.

Thanks for any help,

Chris.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200310/9507dea5/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: build-clang.log.bz2
Type: application/x-bzip2
Size: 28628 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200310/9507dea5/attachment-0001.bin>
-------------- next part --------------
# A full-featured bootstrapped build of LLVM, Clang and friends for FNAL.

set(PACKAGE_VENDOR FNAL CACHE STRING "")

set(LLVM_ENABLE_PROJECTS
  "clang;clang-tools-extra;libclc;lld;lldb;llgo;openmp;polly"
  CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "all" CACHE STRING "")

set(LLVM_TARGETS_TO_BUILD "X86;ARM;AArch64;AMDGPU;NVPTX;BPF;PowerPC"
  CACHE STRING "")

set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG"
  CACHE STRING "")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -gline-tables-only -DNDEBUG"
  CACHE STRING "")

# setup toolchain
set(LLVM_INSTALL_TOOLCHAIN_ONLY ON CACHE BOOL "")
set(LLVM_TOOLCHAIN_TOOLS
  dsymutil
  llvm-cov
  llvm-cxxfilt
  llvm-dwarfdump
  llvm-profdata
  llvm-objdump
  llvm-nm
  llvm-size
  CACHE STRING "")

if (APPLE)
  set(COMPILER_RT_ENABLE_IOS ON CACHE BOOL "Build iOS Compiler-RT libraries")
  set(LLVM_CREATE_XCODE_TOOLCHAIN ON CACHE BOOL
    "Generate targets to create and install an Xcode compatible toolchain")
  set(LLVM_EXTERNALIZE_DEBUGINFO OFF CACHE BOOL "External debuginfo files")
endif()

set(CMAKE_C_FLAGS
  "-fno-stack-protector -fno-common -Wno-profile-instr-unprofiled"
  CACHE STRING "")
set(CMAKE_CXX_FLAGS
  "-fno-stack-protector -fno-common -Wno-profile-instr-unprofiled"
  CACHE STRING "")

# These options should be OK.
set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LINK_POLLY_INTO_TOOLS ON CACHE BOOL "")
set(LLVM_BUILD_LLVM_DYLIB ON CACHE BOOL "")
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
set(LLVM_ENABLE_FFI ON CACHE BOOL "")
set(LLVM_ENABLE_LTO Full CACHE STRING "")
set(LLVM_ENABLE_MODULES ON CACHE BOOL "")
set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
# set(LLVM_LINK_LLVM_DYLIB ON CACHE BOOL "")
set(WITH_POLLY ON CACHE BOOL "")

# Possibly-problematic options.
set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
set(CLANG_DEFAULT_UNWINDLIB libunwind CACHE STRING "")
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")

# Recommended options.
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
-------------- next part --------------
# This file sets up a CMakeCache for a simple distribution bootstrap build.

#Enable LLVM projects and runtimes
set(LLVM_ENABLE_PROJECTS "clang;lld" CACHE STRING "")
set(LLVM_ENABLE_RUNTIMES "all" CACHE STRING "")

# Optimize the stage1 compiler, but don't LTO it because that wastes time.
set(CMAKE_BUILD_TYPE Release CACHE STRING "")

# Setup vendor-specific settings.
set(PACKAGE_VENDOR FNAL CACHE STRING "")

# Setting up the stage2 LTO option needs to be done on the stage1 build so that
# the proper LTO library dependencies can be connected.
set(BOOTSTRAP_LLVM_ENABLE_LTO ON CACHE BOOL "")

if (APPLE)
  set(LLVM_TARGETS_TO_BUILD X86 CACHE STRING "")
  # Disabling embedded darwin compiler-rt on stage1 builds is required because we
  # don't build stage1 to support arm code generation.
  set(COMPILER_RT_ENABLE_IOS OFF CACHE BOOL "")
  set(COMPILER_RT_ENABLE_WATCHOS OFF CACHE BOOL "")
  set(COMPILER_RT_ENABLE_TVOS OFF CACHE BOOL "")
else()
  set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")
  # Since LLVM_ENABLE_LTO is ON we need a LTO capable linker
  set(BOOTSTRAP_LLVM_ENABLE_LLD ON CACHE BOOL "")
endif()

# These options should be OK.
set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
set(CLANG_PLUGIN_SUPPORT OFF CACHE BOOL "")
set(COMPILER_RT_BUILD_SANITIZERS OFF CACHE BOOL "")
set(COMPILER_RT_INCLUDE_TESTS OFF CACHE BOOL "")
set(LLVM_ENABLE_BACKTRACES OFF CACHE BOOL "")
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "")

# Possibly-problematic options.
set(LIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS ON CACHE BOOL "")
set(LIBCXX_ENABLE_NEW_DELETE_DEFINITIONS OFF CACHE BOOL "")
set(LIBCXXABI_INCLUDE_TESTS OFF CACHE BOOL "")
set(LIBCXXABI_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBCXXABI_USE_LLVM_UNWINDER ON CACHE BOOL "")
#set(LIBCXX_CXX_ABI libcxxabi CACHE STRING "")
set(LIBCXX_INCLUDE_TESTS OFF CACHE BOOL "")
set(LIBCXX_USE_COMPILER_RT ON CACHE BOOL "")
set(LIBUNWIND_USE_COMPILER_RT ON CACHE BOOL "")

# Recommended options.
set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
set(CLANG_DEFAULT_RTLIB compiler-rt CACHE STRING "")

# Expose stage2 targets through the stage1 build configuration.
set(CLANG_BOOTSTRAP_TARGETS
  check-all
  check-llvm
  check-clang
  llvm-config
  test-suite
  test-depends
  llvm-test-depends
  clang-test-depends
  clang
  distribution
  install-distribution
  CACHE STRING "")

if (APPLE)
  set(CLANG_BOOTSTRAP_TARGETS
    ${CLANG_BOOTSTRAP_TARGETS}
    install-xcode-toolchain
    install-distribution-toolchain
    CACHE STRING "")
endif()

# Setup the bootstrap build.
set(CLANG_ENABLE_BOOTSTRAP ON CACHE BOOL "")
set(CLANG_BOOTSTRAP_PASSTHROUGH "CMAKE_INSTALL_PREFIX;CMAKE_VERBOSE_MAKEFILE" CACHE STRING "")

if(STAGE2_CACHE_FILE)
  set(CLANG_BOOTSTRAP_CMAKE_ARGS
    -C ${STAGE2_CACHE_FILE}
    CACHE STRING "")
else()
  set(CLANG_BOOTSTRAP_CMAKE_ARGS
    -C ${CMAKE_CURRENT_LIST_DIR}/FNAL-stage2.cmake
    CACHE STRING "")
endif()


More information about the cfe-users mailing list