aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexsifivetw <alex.chiang@sifive.com>2023-06-12 01:38:24 -0700
committeralexsifivetw <alex.chiang@sifive.com>2023-06-13 03:08:30 -0700
commit9027b5a78ddf9c9279618674f67186c1bb636825 (patch)
tree9a32eeed2ca66dd46c4ba9bf5329babe8819a35a
parent89f3238e9dfd9630741b543cf608a8dd5a8cea16 (diff)
downloadriscv-gnu-toolchain-9027b5a78ddf9c9279618674f67186c1bb636825.zip
riscv-gnu-toolchain-9027b5a78ddf9c9279618674f67186c1bb636825.tar.gz
riscv-gnu-toolchain-9027b5a78ddf9c9279618674f67186c1bb636825.tar.bz2
Add newlib toolchain with llvm build flow
Update readme about newlib toolchain flow Co-authored-by: Yun Hsiang <yun.hsiang@sifive.com>
-rw-r--r--Makefile.in22
-rw-r--r--README.md20
2 files changed, 34 insertions, 8 deletions
diff --git a/Makefile.in b/Makefile.in
index 47d66e8..578e511 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -938,12 +938,26 @@ stamps/build-llvm-linux: $(LLVM_SRCDIR) $(LLVM_SRC_GIT) \
$(MAKE) -C $(notdir $@)
$(MAKE) -C $(notdir $@) install
cp $(notdir $@)/lib/riscv$(XLEN)-unknown-linux-gnu/libc++* $(SYSROOT)/lib
- cd $(INSTALL_DIR)/bin && ln -s -f clang $(LINUX_TUPLE)-clang
+ cd $(INSTALL_DIR)/bin && ln -s -f clang $(LINUX_TUPLE)-clang && ln -s -f clang++ $(LINUX_TUPLE)-clang++
mkdir -p $(dir $@) && touch $@
-stamps/build-llvm-newlib:
- echo "Building LLVM is only supported in combination with a Linux toolchain."
- exit 1
+stamps/build-llvm-newlib: $(LLVM_SRCDIR) $(LLVM_SRC_GIT) stamps/build-gcc-newlib-stage2
+ rm -rf $@ $(notdir $@)
+ mkdir $(notdir $@)
+ cd $(notdir $@) && \
+ cmake $(LLVM_SRCDIR)/llvm \
+ -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DLLVM_TARGETS_TO_BUILD="RISCV" \
+ -DLLVM_ENABLE_PROJECTS="clang;lld" \
+ -DLLVM_DEFAULT_TARGET_TRIPLE="$(NEWLIB_TUPLE)" \
+ -DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
+ -DLLVM_PARALLEL_LINK_JOBS=4
+ $(MAKE) -C $(notdir $@)
+ $(MAKE) -C $(notdir $@) install
+ cd $(INSTALL_DIR)/bin && ln -s -f clang $(NEWLIB_TUPLE)-clang && \
+ ln -s -f clang++ $(NEWLIB_TUPLE)-clang++
+ mkdir -p $(dir $@) && touch $@
stamps/build-dejagnu: $(DEJAGNU_SRCDIR) $(DEJAGNU_SRC_GIT)
rm -rf $@ $(notdir $@)
diff --git a/README.md b/README.md
index f6e93b8..5ac8921 100644
--- a/README.md
+++ b/README.md
@@ -260,12 +260,12 @@ can be used:
Note, that a combination of `--enable-llvm` and multilib configuration flags
is not supported.
-Also note, that building LLVM is only supported in combination with building
-a Linux toolchain.
-Below is an example how to build a rv64gc Linux toolchain with LLVM support,
+Below are examples how to build a rv64gc Linux/newlib toolchain with LLVM support,
how to use it to build a C and a C++ application using clang, and how to
-execute the generated binaries using QEMU:
+execute the generated binaries using QEMU.
+
+Build Linux toolchain and run examples:
# Build rv64gc toolchain with LLVM
./configure --prefix=$RISCV --enable-llvm --enable-linux --with-arch=rv64gc --with-abi=lp64d
@@ -277,6 +277,18 @@ execute the generated binaries using QEMU:
$RISCV/bin/clang++ -march=rv64imafdc -stdlib=libc++ -o hello_world_cpp hello_world_cpp.cxx
$RISCV/bin/qemu-riscv64 -L $RISCV/sysroot ./hello_world_cpp
+Build newlib toolchain and run examples (don't work with `--with-multilib-generator=`):
+
+ # Build rv64gc bare-metal toolchain with LLVM
+ ./configure --prefix=$RISCV --enable-llvm --disable-linux --with-arch=rv64gc --with-abi=lp64d
+ make -j$(nproc) all build-sim SIM=qemu
+ # Build C application with clang
+ $RISCV/bin/clang -march=rv64imafdc -o hello_world hello_world.c
+ $RISCV/bin/qemu-riscv64 -L $RISCV/sysroot ./hello_world
+ # Build C++ application with clang using static link
+ $RISCV/bin/clang++ -march=rv64imafdc -static -o hello_world_cpp hello_world_cpp.cxx
+ $RISCV/bin/qemu-riscv64 -L $RISCV/sysroot ./hello_world_cpp
+
### Development
This section is only for developer or advanced user, or you want to build