(no commit message)
[libreriscv.git] / llvm_on_riscv.mdwn
1 # Compiling LLVM on RISC-V
2
3 By simply copying & pasting the following, absolutely verbatim with no
4 changes, you can get a working clang from the head of the official llvm
5 master branch. I've tested it on a completely virgin install of Ubuntu
6 16.04 LTS server. It should work on other versions of Ubuntu and on
7 other Debian-based distros. (If it doesn't then please let me know)
8
9 Note that you currently must use a soft float version of the rv32 compiler
10 and libraries.
11
12 You can skip the gnu toolchain and/or qemu parts if you already have
13 those.
14
15 # about 17 GB of disk space is needed
16 # entire process takes (not including apt-get, which is about 90 seconds on AWS):
17 # 87m10s on i7-8650U Intel NUC with 32 GB RAM (on 30 Mbps VDSL internet in NZ)
18 # 20m40s on server with Xeon E5-2667v4 @3.20GHz (16 cores)
19 # 17m30s on an AWS m5.12xlarge with fresh Ubuntu 16.04 AMI (ami-4e79ed36)
20
21 #harmless if things are already installed. Obviously you can't do it if
22 #you're not an admin
23 sudo apt-get update
24 sudo apt-get -y dist-upgrade
25 sudo apt-get -y install \
26 binutils build-essential libtool texinfo \
27 gzip zip unzip patchutils curl git \
28 make cmake ninja-build automake bison flex gperf \
29 grep sed gawk python bc \
30 zlib1g-dev libexpat1-dev libmpc-dev \
31 libglib2.0-dev libfdt-dev libpixman-1-dev
32
33 mkdir riscv
34 cd riscv
35 mkdir _install
36 export PATH=`pwd`/_install/bin:$PATH
37
38 git clone --recursive https://github.com/riscv/riscv-gnu-toolchain
39 pushd riscv-gnu-toolchain
40 ./configure --prefix=`pwd`/../_install --with-arch=rv32gc --with-abi=ilp32
41 make -j`nproc`
42 popd
43
44 git clone https://github.com/riscv/riscv-qemu
45 pushd riscv-qemu
46 ./configure --prefix=`pwd`/../_install --target-list=riscv32-linux-user
47 make -j`nproc` install
48 popd
49
50 git clone https://github.com/llvm-project/llvm-project-20170507 llvm
51 pushd llvm
52 (cd llvm/tools; ln -s ../../clang .)
53 mkdir _build
54 cd _build
55 cmake -G Ninja -DCMAKE_BUILD_TYPE="Release" \
56 -DBUILD_SHARED_LIBS=True -DLLVM_USE_SPLIT_DWARF=True \
57 -DLLVM_OPTIMIZED_TABLEGEN=True -DLLVM_BUILD_TESTS=False \
58 -DDEFAULT_SYSROOT="../../_install/riscv32-unknown-elf" \
59 -DGCC_INSTALL_PREFIX="../../_install" \
60 -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" \
61 -DLLVM_TARGETS_TO_BUILD="" \
62 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="RISCV" \
63 ../llvm
64 cmake --build .
65 alias clang-rv32="`pwd`/bin/clang -Xclang -iwithsysroot -Xclang /include \
66 -ccc-gcc-name riscv32-unknown-elf-gcc \
67 -target riscv32 -march=rv32imc"
68 popd
69
70 cat >hello.c <<END
71 #include <stdio.h>
72
73 int main(){
74 printf("Hello RISCV!\n");
75 return 0;
76 }
77 END
78
79 clang-rv32 -O1 hello.c -o hello
80 qemu-riscv32 hello
81