'Learn LLVM 12' reading note: Part 1 Building LLVM and standalone LLVM project

Building LLVM

Install prerequisites, like git, ninja-build, cmake, ...
Download LLVM from github
Config the build using cmake:

   cmake -G Ninja -DLLVM_ENABLE_PROJECTS=clang -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=`pwd`/llvm-install ../llvm-project/llvm

Then build it:

  ninja install

LLVM structure

LLVM contents: LLVM core libs (in llvm/, has llc, llvm-objdump, llvm-dwarfdump, etc); compilers and tools (clang, lld, lldb, clang-format, clang-tidy, etc); runtime libs (compiler-rt, libunwind, libcxxabi, libcxx, libc, libclc).

LLVM project layout: structured as a bunch of libraries depending on each other. Each project has libs, tools, utils (internal tools), unittests, docs, tests, includes.

Building standalone LLVM projects

It's more flexible to create standalone LLVM project, which can be built outside llvm.
Use CMake configuration, pass LLVM_DIR to cmake to find llvm installation dir. Explanation is in https://llvm.org/docs/CMake.html#id19

A standalone project can use LLVM libs and header files.

Then the book mentioned about targetting a different CPU architecture. It needs both clang and GNU tools (for libc and headers). But there are no details how to do that manually.

Comments

Popular posts from this blog

'Feynman's study method' reading note: Part 1 The essence of learning

‘Wheeled Autonomous Mobile Robot Programming in Practice’ reading note: Part 1 Wheeled Robot Basics

'Prompt Engineering for ChatGPT' course note: Part 2 What are Prompts