Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Build LLVM with the Repo Compiler

MaggieYingYi edited this page Apr 8, 2019 · 11 revisions

This page shows how to build the llvm-project-prepo project from source then use the resulting compiler to re-build LLVM on Linux.

Building the initial repo compiler

  1. Clone llvm-project-prepo repository.

     $ cd  $REPO_DIR
     $ git clone https://github.com/SNSystems/llvm-project-prepo.git
    
  2. (Temporary step) Checkout the branch named 'build_llvm_project_repo_using_built_repo_compiler'.

     $ cd $REPO_DIR/llvm-project-prepo
     $ git checkout build_llvm_project_repo_using_built_repo_compiler
    
  3. Clone pstore.

     $ cd $REPO_DIR/llvm-project-prepo
     $ git clone https://github.com/SNSystems/pstore.git
    
  4. Build LLVM enabling the clang and pstore subprojects.

     $ cd $REPO_DIR/llvm-project-prepo
     $ mkdir build && cd build
     $ cmake -G "Ninja"  -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;pstore" -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF ../llvm
     $ ninja
    

Using the initial repo compiler to build LLVM

  • Compile the llvm-project-prepo project targeting the program repository using the initial repo compiler.
  • Convert the Repo ticket files to ELF object files using repo2obj.
  • Link the ELF object files to generate an executable ELF file.
  • Repeat the above steps once to verity database (i.e. all fragments are in the database).
  1. Copy the repo.json to any parent directory of $REPO_DIR/llvm-project-prepo/build.

     $ cd llvm-project-prepo
     $ cp ./llvm/utils/repo/repo.json .		
     $ less repo.json
     {
     	"ar": "/usr/bin/ar",
     	"link": "/usr/bin/clang++",
     	"repo2obj": "/point/to/the/repo2obj/tool/in/llvm-pstore/build/directory"
     }
    
  2. Continue to use your default ar and clang++ for the archiving and linking because the repo toolchain currently only supports the compilation. Modify the repo2obj option to point to the repo2obj tool in your build directory. Note: it must be an absolute path. e.g.

     "repo2obj": "/home/username/llvm-project-prepo/build/bin/repo2obj"
    
  3. Generate a release build using the repo.cmake toolchain file.

     $ cd llvm-project-prepo
     $ mkdir build_repo_release && cd build_repo_release
     $ cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DLLVM_ENABLE_PROJECTS="clang;pstore"  -DLLVM_TOOL_CLANG_TOOLS_EXTRA_BUILD=OFF  -DPSTORE_ENABLE_BROKER=OFF -DLLVM_DISABLE_DYNAMIC_LIBRARY_UNITTEST=ON -DCMAKE_TOOLCHAIN_FILE=/home/username/github/llvm-project-prepo/llvm/utils/repo/repo.cmake -DCMAKE_CXX_COMPILER=/home/username/github/llvm-project-prepo/build/bin/clang++ -DCMAKE_C_COMPILER=/home/username/github/llvm-project-prepo/build/bin/clang -Dutils_dir=/home/username/github/llvm-project-prepo/llvm/utils/repo ../llvm
    
     You must specify for cmake:
         1. -DPSTORE_ENABLE_BROKER=OFF
             Disable the pstore broker projects since the repo compiler currently does not support exception handling
         2. -DLLVM_DISABLE_DYNAMIC_LIBRARY_UNITTEST=ON
             Disable the dynamic library unittests [issue12](https://github.com/SNSystems/llvm-project-prepo/issues/12)
         3. -DCMAKE_TOOLCHAIN_FILE=/home/username/github/llvm-project-prepo/llvm/utils/repo/repo.cmake
         4. -DCMAKE_CXX_COMPILER=/home/username/github/llvm-project-prepo/build/bin/clang++
         5. -DCMAKE_C_COMPILER=/home/username/github/llvm-project-prepo/build/bin/clang 
             Both CMAKE_CXX_COMPILER and DCMAKE_C_COMPILER are pointing to the initial repo compiler.
         6. -Dutils_dir=/home/username/github/llvm-project-prepo/llvm/utils/repo
             Specify the repo utilities directory, which contains additional scripts requied for the build.
    
     $ ninja
    
  4. To rebuild, you can clean/delete all ticket files. All code fragments will be retained within the database (clang.db).

     $ ninja clean
     $ ninja
    

Running unit and regression tests

Currently, for a debug build, there are 30552 tests passed out of 30567 tests (99.95%) and for the release build, there are 30583 tests passed out of 30717 tests (99.56%). The issues found by the failing tests are being worked on.

	$ ninja check-all

Current build status

The llvm-project-prepo has been built and run with the tests twice in debug and release configurations.

Debug build with compiler switches: -O0 -fno-exceptions -fno-rtti.

Release build with compiler switches: -O3 -fno-exceptions -fno-rtti.

Configuration 1st build 1st run test 2nd build 2nd run test
Debug 99.95% tests passed 99.95% tests passed
Release 99.56% tests passed 99.56% tests passed

Clone this wiki locally