Building Clang with openSUSE Tumbleweed + Virtual Box 6.0

很久沒有編譯怪物級的專案來折磨 CPU 和硬碟了。

基本上照著 Clang 文件 https://clang.llvm.org/get_started.html 就不會在 compilation 上運到奇怪問題,只有幾個細節需要調校一下:
  1. Virtual Box 的 storage controller 要開啟 Host I/O Cache ,不然很容易在大量 I/O 時遇到 Virtual Box 沒有反應,然後出現 Disk I/O 讀取錯誤:
    00:39:53.953457 Console: VM runtime error: fatal=false, errorID=BLKCACHE_IOERR message="The I/O cache encountered an error while updating data in medium "ahci-0-0" (rc=VERR_IO_NOT_READY). Make sure there is enough free space on the disk and that the disk is working properly. Operation can be resumed afterwards"
    image
  2. 不要編譯 libcxx ,Clang 教學文件雖然提到這是 optional ,但實際跑時會在 linker 階段炸出很多 undefined reference  (乍看下感覺是 linker 只使用了 C runtime 而漏了 C++ runtime)
    image
  3. 使用 gold 作為 linker 而不是 gnu ld ,因為 ld 在工作階段會耗用過多 memory ,以我的實驗為例:即使已經設定了 8GB Ram 和 8GB swap 空間,仍然會遇到 ld 耗盡 memory 的問題。
    [ 63%] Linking CXX shared library ../../lib/libLTO.so
    /usr/bin/ld: failed to set dynamic section sizes: Memory exhausted

Let's Build

  1. 先 checkout llvm
    1. svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
    2. cd llvm/tools
  2. 再來是 checkout clang
    1. svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
    2. cd ../..
  3. extra Clang tools(optional)
    1. cd llvm/tools/clang/tools
    2. svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
  4. Compiler RT(optional)
    1. cd ../../../..
    2. cd llvm/projects
    3. svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
  5. 除了 libcxx 之外的代碼都已經準備好了~
    1. cd ../..
    2. mkdir llvm_build
    3. cd llvm_build
    4. cmake -DLLVM_USE_LINKER=gold -G "Unix Makefiles" ../llvm
      帶上 LLVM_USE_LINKER=gold 來使用 gold linker ,避免記憶體不足問題。

後話

不過 llvm 遷移至 git 的工作也差不多要完成了[3],看來很快又要更新內容了。

Reference

  1. Getting Started: Building and Running Clang
  2. Building LLVM with CMake
  3. LLVM Is Nearly Finalized On Its Repository Conversion To Git

留言

這個網誌中的熱門文章

Missing Process Argument

Syntax Hightlight