Dogfood part3: native libc++

In part 2, I created a cut down compiler-rt (libclang_rt.builtins.a)
Which allows me to build a native libc++ library. In <arch>-<vendor>-linux-gnu the code assumes the GNU Compiler Collection libraries at every stage, so I have to explicitly thread the llvm-libraries together using a ‘runtime only’ build.

linker_flags = '-nostdlib -rtlib=compiler-rt -fuse-ld=lld'
subprocess.run (
    [
        'cmake',
        '-G',
        'Ninja',
        '-S',
        'runtimes',
        '-B',
        build,
        '--trace-expand',
        '--trace-redirect=' + build +'/cmake.log',
        '-DCMAKE_BUILD_TYPE=Release',
        '-DCMAKE_C_COMPILER=' + STAGING + '/bin/clang',
        '-DCMAKE_CXX_COMPILER=' + STAGING + '/bin/clang++',
        '-DCMAKE_EXE_LINKER_FLAGS_INIT=' + linker_flags,
        '-DCMAKE_INSTALL_PREFIX=' + STAGING,
        '-DCMAKE_MODULE_LINKER_FLAGS_INIT=' + linker_flags,
        '-DCMAKE_SHARED_LINKER_FLAGS_INIT=' + linker_flags,
        '-DLIBCXX_CXX_ABI=libcxxabi',
        '-DLIBCXX_USE_COMPILER_RT=ON',
        '-DLIBCXXABI_USE_COMPILER_RT=ON',
        '-DLIBCXXABI_USE_LLVM_UNWINDER=ON',
        '-DLIBUNWIND_USE_COMPILER_RT=ON',
        '-DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON',
        '-DLLVM_ENABLE_RUNTIMES=libunwind;libcxxabi;libcxx',
        '-DLLVM_TARGETS_TO_BUILD=Native'
    ],
    check=True
)
subprocess.run (
    [
        'ninja',
        '-C',
        build,
        'cxx',
        'cxxabi',
        'unwind',
    ],
    check=True
)
subprocess.run (
    [
        'ninja',
        '-C',
        build,
        'install-cxx',
        'install-cxxabi',
        'install-unwind',
    ],
    check=True
)

Where:

  • linker_flags unlike on the last build, I can express exactly what I need. No Standard C++ Library, because I am building that, and use the compiler-rt I built in part2 and the linker built in part 1.
  • The variable build is now set to ‘build-native-libcxx’
  • The constant STAGING is still set to ‘/staging’
  • LIBUNWIND_USE_COMPILER_RT asks libunwind to use compiler-rt
  • LIBCXXABI_USE_LLVM_UNWINDER asks libc++abi to use libunwind
  • LIBCXXABI_USE_COMPILER_RT asks libc++abi to also use compiler-rt
  • LIBCXX_CXX_ABI=libcxxabi asks libc++ to use libc++abi
  • LIBCXX_USE_COMPILER_RT asks libc++ to use compiler-rt

There does not seem to be anything to ask libc++ to use libunwind so is that the default?

Once again, this build does not work.

In … /libcxx/cmake/config-ix.cmake (about line: 128) the code looks for the GNU compiler collection’s libatomic even though I am trying to use llvm’s compiler-rt
I fixed this by making the check dependent on LIBCXX_USE_COMPILER_RT like line: 25

There does not seem to be anything to ask libc++ to use libunwind so is that the default?

libc++ has an option with the slightly confusing name LIBCXXABI_USE_LLVM_UNWINDER, which I think does what you want.

In … /libcxx/cmake/config-ix.cmake (about line: 128) the code looks for the GNU compiler collection’s libatomic even though I am trying to use llvm’s compiler-rt

In the past, compiler-rt didn’t have a replacement for libatomic.so. (You could mess with COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN, but that doesn’t work correctly for building shared libraries because it’s statically linked.)

It looks like the CMake flag COMPILER_RT_BUILD_STANDALONE_LIBATOMIC was added recently in ⚙ D102155 [AIX][compiler-rt] Build and install standalone libatomic, but I have no idea if it works correctly on targets other than AIX.

1 Like

Thanks, It works (of a fashion) at the moment, but I will read up about those flags.
I think the patch in ‘Dogfood Summary’ will make sense to you.
July 8