Skip to content

Latest commit

 

History

History
94 lines (79 loc) · 2.52 KB

riscv-llvm.org

File metadata and controls

94 lines (79 loc) · 2.52 KB

Compiling LLVM/Clang to Target RISC-V

These notes are adapted from SiFive’s original LLVM/Clang build.

Global Environment Variables

export RISCV_INSTALL_DIR="path/to/tool/install/dir"

Build GCC

Prerequisites

sudo apt-get -y install \
  binutils build-essential libtool texinfo \
  gzip zip unzip patchutils curl git \
  make automake bison flex gperf \
  grep sed gawk python bc \
  zlib1g-dev libexpat1-dev libmpc-dev \
  libglib2.0-dev libfdt-dev libpixman-1-dev

Fetch Sources

git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
RISCV_GNU_SRC="path/to/riscv-gnu-toolchain"

Configure Build

mkdir _build-riscv-gnu-toolchain
pushd _build-riscv-gnu-toolchain
RISCV_GNU_BUILD=`pwd`
$RISCV_GNU_SRC/configure --prefix="$RISCV_INSTALL_DIR" --enable-multilib
# Multilib here means that RV32 & RV64 will be built

Build & Install

make -j`nproc`
popd

You should end up in the directory above the $RISCV_GNU_BUILD directory. This directory should hold at least $RISCV_GNU_SRC and $RISCV_GNU_BUILD.

Build LLVM

Prerequisites

sudo apt-get -y install \
  binutils build-essential cmake ninja-build grep sed gawk

Fetch Sources

git clone https://github.com/llvm/llvm-project.git riscv-llvm
RISCV_LLVM_SRC="path/to/riscv-llvm"

Configure Build

pushd riscv-llvm
ln -s ../../clang llvm/tools || true

mkdir _build-riscv-llvm
cd _build-riscv-llvm
RISCV_LLVM_BUILD=`pwd`

cmake -G Ninja -DCMAKE_BUILD_TYPE="Release" \
      -DBUILD_SHARED_LIBS=True \
      -DLLVM_USE_SPLIT_DWARF=True \
      -DCMAKE_INSTALL_PREFIX="$RISCV_INSTALL_DIR" \
      -DLLVM_OPTIMIZED_TABLEGEN=True \
      -DLLVM_BUILD_TESTS=False \
      -DDEFAULT_SYSROOT="$RISCV_INSTALL_DIR/riscv64-unknown-elf" \
      -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-elf" \
      -DLLVM_TARGETS_TO_BUILD="RISCV" \
      $RISCV_LLVM_SRC/llvm

Build & Install

cmake --build . --parallel 8 --target install
popd

You should end up in the directory above $RISCV_LLVM_BUILD. This directory should hold at least $RISCV_LLVM_SRC and $RISCV_LLVM_BUILD.

Making RISC-V Tools Available

To make the newly compiled GNU, GCC, LLVM, and Clang tools available to the shell, you need to re-export $PATH.

export PATH=$PATH:"$RISCV_INSTALL_DIR/bin"