Browse Source

Add newlib toolchain with llvm build flow

Update readme about newlib toolchain flow

Co-authored-by: Yun Hsiang <yun.hsiang@sifive.com>
pull/1273/head
alexsifivetw 3 years ago
parent
commit
9027b5a78d
  1. 22
      Makefile.in
  2. 20
      README.md

22
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 $@)

20
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

Loading…
Cancel
Save