Building the CRT

Folks,

I'm at a loss trying to add Compiler-RT to an LLVM build, even after checking out the instructions at http://compiler-rt.llvm.org, so I'd appreciate your help.

I've tried adding the CMake options LLVM_ENABLE_PROJECTS, LLVM_BUILD_EXTERNAL_COMPILER_RT, LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR, CLANG_DEFAULT_RTLIB. All to no avail.

FWIW, I'm building for the targets AArch64, ARM and X86.

Feeling like a newbie makes me want to cry... :-}

Thank you,

Folks,

I'm at a loss trying to add Compiler-RT to an LLVM build, even after
checking out the instructions at http://compiler-rt.llvm.org, so I'd
appreciate your help.

I've tried adding the CMake options LLVM_ENABLE_PROJECTS,
LLVM_BUILD_EXTERNAL_COMPILER_RT, LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR,
CLANG_DEFAULT_RTLIB. All to no avail.

You'll need to give a lot more details on what you tried, and how it failed. Without that information, nobody can really help you.

Jon

Shot in the dark: double-check that your checkout is under llvm/projects or llvm/runtimes, and wipe your cmake cache before attempting a rebuild.

vedant

OK, what else can I say?

I checked out the projects side by side, as I usually do:

    ~/src/llvm.tip $ ls
    clang compiler-rt klee libcxx lld llvm
    clang-tools-extra dragonegg libclc libcxxabi lldb polly

So I expected that setting LLVM_ENABLE_PROJECTS="clang;compiler-rt" would be enough to get Compiler-RT added to a functional build tree, since setting it to just "clang" does result in Clang being built. I tired the other variables above for good measure, alas unsuccessfully.

In the end, everything gets built as before, except for Compiler-RT, which I expect to be any built-in and sanitizer libraries.

Thank you,

Folks,

I'm at a loss trying to add Compiler-RT to an LLVM build, even after
checking out the instructions at http://compiler-rt.llvm.org, so I'd
appreciate your help.

I've tried adding the CMake options LLVM_ENABLE_PROJECTS,
LLVM_BUILD_EXTERNAL_COMPILER_RT, LLVM_EXTERNAL_COMPILER_RT_SOURCE_DIR,
CLANG_DEFAULT_RTLIB. All to no avail.

You'll need to give a lot more details on what you tried, and how it
failed. Without that information, nobody can really help you.

OK, what else can I say?

I checked out the projects side by side, as I usually do:

   ~/src/llvm.tip $ ls
   clang compiler-rt klee libcxx lld llvm
   clang-tools-extra dragonegg libclc libcxxabi lldb polly

The instructions on http://compiler-rt.llvm.org are for building compiler-rt separately from llvm, which is not how most people build it. If you're just getting started with it, I'd recommend doing it the other way, and that is to do a combined-tree build. For that you'll want:

     * symlinks in llvm/runtimes to each of libcxx, libcxxabi, compiler-rt respectively
     * symlinks in llvm/tools to clang, lld, and lldb respectively
     * symlink from llvm/tools/clang/tools/extra to clang-tools-extra

Dragonegg is dead, and you probably don't want klee / polly unless you know what you're doing.

So I expected that setting LLVM_ENABLE_PROJECTS="clang;compiler-rt"
would be enough to get Compiler-RT added to a functional build tree,
since setting it to just "clang" does result in Clang being built.

Interesting. Didn't know the build would do that (assuming you didn't already have the symlink in place for clang).

Jon

For this option, you need to follow: http://llvm.org/docs/GettingStarted.html#for-developers-to-work-with-a-git-monorepo

You can’t add this to an existing build directory, you need to wipe it and re-run cmake (at least for me that’s the only way I found).

Yes, I have a monorepo, that's why I have projects that I don't care about cloned (e.g., draggonegg). But, as I said, this configuration has worked fine, until I decided to do some work in CRT.

And, yes, I tried starting a build from a clean directory. Yet...

Thank you,

Can you give the exact command you’re trying and the effect you’re observing (or the missing effects you’re not observing but expecting?).

For ARM/AArch64, are you trying to do cross compiling?

If so, you need GCC tools for ARM/AArch64 in your PATH so CMake can linking a simple testing code. If not in the PATH, you might need --sysroot/ ---gcc-toolchain in CFLAGS.

Below is my CMake command for arm:

GCCTC= path_to_gcc

TRIPLE=arm-linux-gnueabi
SRC_DIR=<llvm_source_root>
INSTALL_DIR=<llvm_install_dir>

cmake -G Ninja -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR/lib/clang/5.0.0 -DCMAKE_C_COMPILER=$INSTALL_DIR/bin/clang -DCMAKE_CXX_COMPILER=$INSTALL_DIR/bin/clang++ -DCMAKE_PREFIX_PATH=$INSTALL_DIR -DCMAKE_C_FLAGS=" -target ${TRIPLE} " -DCMAKE_CXX_FLAGS=" -target ${TRIPLE} " -DCMAKE_SYSTEM_NAME=Linux -DCOMPILER_RT_DEFAULT_TARGET_ARCH=arm -DCOMPILER_RT_TEST_COMPILER_CFLAGS=" -target ${TRIPLE} " -DCOMPILER_RT_TEST_COMPILER=${INSTALL_DIR}/bin/clang $SRC_DIR/llvm/projects/compiler-rt

compiler-rt needs clang to be able to generate the code for the intended targets. The suggestion above finally worked, but got stopped at the lack of a multiarch linker and archiver. And the build files of compiler-rt don't seem to provide a way to specify either for specific targets. Building compiler-rt separately from clang might allow one to specify ancillary tools used just for its build.

Thank you,