Skip to content

Commit bb74af5

Browse files
jysh1214kito-cheng
andcommitted
Enable riscv llvm & qemu build flow
Update readme about llvm & qemu examples Co-authored-by: Kito Cheng <[email protected]>
1 parent ea26fd6 commit bb74af5

File tree

13 files changed

+294
-58
lines changed

13 files changed

+294
-58
lines changed

.github/setup-apt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ dpkg --add-architecture i386
55
apt update
66
apt install -y autoconf automake autotools-dev curl python3 libmpc-dev libmpfr-dev \
77
libgmp-dev gawk build-essential bison flex texinfo gperf libtool \
8-
patchutils bc zlib1g-dev libexpat-dev git
8+
patchutils bc zlib1g-dev libexpat-dev git ninja-build cmake ibglib2.0-dev expect

.github/workflows/build.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ jobs:
3636
./configure --prefix=/opt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]}
3737
sudo make -j $(nproc) ${{ matrix.mode }}
3838
39+
- name: make report
40+
if: |
41+
matrix.os == 'ubuntu-20.04'
42+
&& (matrix.mode == 'linux' || matrix.mode == 'newlib')
43+
run: |
44+
sudo make report-${{ matrix.mode }} -j $(nproc)
45+
3946
- name: tarball build
4047
run: tar czvf riscv.tar.gz -C /opt/ riscv/
4148

@@ -57,3 +64,54 @@ jobs:
5764
with:
5865
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
5966
path: riscv.tar.gz
67+
68+
build-multilib:
69+
if: ${{ false }} # Disable until multilib errors are triaged
70+
runs-on: ${{ matrix.os }}
71+
strategy:
72+
matrix:
73+
os: [ubuntu-20.04]
74+
mode: [newlib, linux]
75+
target: [rv64gc-lp64d]
76+
steps:
77+
- uses: actions/checkout@v2
78+
79+
- name: initialize submodules
80+
run: |
81+
git submodule init
82+
git submodule update --recursive --progress --recommend-shallow
83+
84+
- name: install dependencies
85+
run: sudo ./.github/setup-apt.sh
86+
87+
- name: build toolchain
88+
run: |
89+
TARGET_TUPLE=($(echo ${{ matrix.target }} | tr "-" "\n"))
90+
./configure --prefix=/opt/riscv --with-arch=${TARGET_TUPLE[0]} --with-abi=${TARGET_TUPLE[1]} --enable-multilib
91+
sudo make -j $(nproc) ${{ matrix.mode }}
92+
93+
- name: make report
94+
run: |
95+
sudo make report-${{ matrix.mode }} -j $(nproc)
96+
97+
- name: tarball build
98+
run: tar czvf riscv.tar.gz -C /opt/ riscv/
99+
100+
- name: generate prebuilt toolchain name
101+
id: toolchain-name-generator
102+
run: |
103+
if [[ "${{ matrix.target }}" == *"32"* ]]; then BITS=32; else BITS=64; fi
104+
case "${{ matrix.mode }}" in
105+
"linux")
106+
MODE="glibc";;
107+
"musl")
108+
MODE="musl";;
109+
*)
110+
MODE="elf";;
111+
esac
112+
echo ::set-output name=TOOLCHAIN_NAME::riscv$BITS-$MODE-${{ matrix.os }}-multilib-nightly
113+
114+
- uses: actions/upload-artifact@v2
115+
with:
116+
name: ${{ steps.toolchain-name-generator.outputs.TOOLCHAIN_NAME }}
117+
path: riscv.tar.gz

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[submodule "binutils"]
22
path = binutils
33
url = https://sourceware.org/git/binutils-gdb.git
4-
branch = binutils-2_39-branch
4+
branch = binutils-2_40-branch
55
[submodule "gcc"]
66
path = gcc
77
url = https://gcc.gnu.org/git/gcc.git

Makefile.in

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ QEMU_SRCDIR := @with_qemu_src@
1313
SPIKE_SRCDIR := @with_spike_src@
1414
PK_SRCDIR := @with_pk_src@
1515
LLVM_SRCDIR := @with_llvm_src@
16+
DEJAGNU_SRCDIR := @with_dejagnu_src@
17+
DEBUG_INFO := @debug_info@
18+
DEJAGNU_SRCDIR := @with_dejagnu_src@
1619

1720
SIM ?= @WITH_SIM@
1821

19-
ifeq ($(srcdir)/riscv-gcc,$(GCC_SRCDIR))
22+
ifeq ($(srcdir)/gcc,$(GCC_SRCDIR))
2023
# We need a relative source dir for the gcc configure, to make msys2 mingw64
2124
# builds work. Mayberelsrcdir is relative if a relative path was used to run
2225
# configure, otherwise absolute, so we have to check.
2326
mayberelsrcdir := @top_srcdir@
2427
gccsrcdir := $(shell case $(mayberelsrcdir) in \
25-
([\\/]* | ?:[\\/]*) echo $(mayberelsrcdir)/riscv-gcc ;; \
26-
(*) echo ../$(mayberelsrcdir)/riscv-gcc ;; \
28+
([\\/]* | ?:[\\/]*) echo $(mayberelsrcdir)/gcc ;; \
29+
(*) echo ../$(mayberelsrcdir)/gcc ;; \
2730
esac)
2831
else
2932
gccsrcdir := $(abspath $(GCC_SRCDIR))
@@ -76,9 +79,9 @@ LINUX_TUPLE ?= $(call make_tuple,$(XLEN),linux-gnu)
7679
NEWLIB_TUPLE ?= $(call make_tuple,$(XLEN),elf)
7780
MUSL_TUPLE ?= $(call make_tuple,$(XLEN),linux-musl)
7881

79-
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) @target_cflags@ @cmodel@
80-
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) @target_cxxflags@ @cmodel@
81-
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) @cmodel@
82+
CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) @target_cflags@ @cmodel@
83+
CXXFLAGS_FOR_TARGET := $(CXXFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) @target_cxxflags@ @cmodel@
84+
ASFLAGS_FOR_TARGET := $(ASFLAGS_FOR_TARGET_EXTRA) $(DEBUG_INFO) @cmodel@
8285
# --with-expat is required to enable XML support used by OpenOCD.
8386
BINUTILS_TARGET_FLAGS := --with-expat=yes $(BINUTILS_TARGET_FLAGS_EXTRA)
8487
BINUTILS_NATIVE_FLAGS := $(BINUTILS_NATIVE_FLAGS_EXTRA)
@@ -94,6 +97,7 @@ NEWLIB_CC_FOR_TARGET ?= $(NEWLIB_TUPLE)-gcc
9497
NEWLIB_CXX_FOR_TARGET ?= $(NEWLIB_TUPLE)-g++
9598
NEWLIB_TARGET_BOARDS ?= $(shell echo "$(NEWLIB_MULTILIB_NAMES)" | sed 's!\([_a-z0-9]*\)-\([_a-z0-9]*\)!riscv-sim/-march=\1/-mabi=\2/@cmodel@!g')
9699
NEWLIB_NANO_TARGET_BOARDS ?= $(shell echo "$(NEWLIB_MULTILIB_NAMES)" | sed 's!\([_a-z0-9]*\)-\([_a-z0-9]*\)!riscv-sim-nano/-march=\1/-mabi=\2/@cmodel@!g')
100+
NEWLIB_CC_FOR_MULTILIB_INFO := $(NEWLIB_CC_FOR_TARGET)
97101

98102
MUSL_TARGET_FLAGS := $(MUSL_TARGET_FLAGS_EXTRA)
99103
MUSL_CC_FOR_TARGET ?= $(MUSL_TUPLE)-gcc
@@ -183,10 +187,9 @@ report-gdb: report-gdb-@default_target@
183187

184188
.PHONY: build-sim
185189
ifeq ($(SIM),qemu)
186-
QEMU_CPU=$(shell $(srcdir)/scripts/march-to-cpu-opt $(WITH_ARCH))
187-
SIM_PATH:=$(srcdir)/scripts/wrapper/qemu
188-
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" RISC_V_SYSROOT="$(SYSROOT)" QEMU_CPU="$(QEMU_CPU)"
189-
SIM_STAMP:= stamps/build-qemu
190+
SIM_PATH:=$(srcdir)/scripts/wrapper/qemu:$(srcdir)/scripts
191+
SIM_PREPARE:=PATH="$(SIM_PATH):$(INSTALL_DIR)/bin:$(PATH)" RISC_V_SYSROOT="$(SYSROOT)"
192+
SIM_STAMP:= stamps/build-qemu stamps/install-python-package
190193
else
191194
ifeq ($(SIM),spike)
192195
# Using spike simulator.
@@ -278,6 +281,7 @@ endif
278281

279282
ifeq ($(findstring $(srcdir),$(SPIKE_SRCDIR)),$(srcdir))
280283
SPIKE_SRC_GIT := $(SPIKE_SRCDIR)/.git
284+
PK_SRC_GIT := $(PK_SRCDIR)/.git
281285
else
282286
SPIKE_SRC_GIT :=
283287
endif
@@ -288,6 +292,12 @@ else
288292
LLVM_SRC_GIT :=
289293
endif
290294

295+
ifeq ($(findstring $(srcdir),$(DEJAGNU_SRCDIR)),$(srcdir))
296+
DEJAGNU_SRC_GIT := $(DEJAGNU_SRCDIR)/.git
297+
else
298+
DEJAGNU_SRC_GIT :=
299+
endif
300+
291301
ifneq ("$(wildcard $(GCC_SRCDIR)/.git)","")
292302
GCCPKGVER := g$(shell git -C $(GCC_SRCDIR) describe --always --dirty --exclude '*')
293303
else
@@ -380,8 +390,8 @@ endif
380390
cd $(notdir $@) && \
381391
CC="$(GLIBC_CC_FOR_TARGET) $($@_CFLAGS)" \
382392
CXX="this-is-not-the-compiler-youre-looking-for" \
383-
CFLAGS="$(CFLAGS_FOR_TARGET) -g -O2 $($@_CFLAGS)" \
384-
CXXFLAGS="$(CXXFLAGS_FOR_TARGET) -g -O2 $($@_CFLAGS)" \
393+
CFLAGS="$(CFLAGS_FOR_TARGET) -O2 $($@_CFLAGS)" \
394+
CXXFLAGS="$(CXXFLAGS_FOR_TARGET) -O2 $($@_CFLAGS)" \
385395
ASFLAGS="$(ASFLAGS_FOR_TARGET) $($@_CFLAGS)" \
386396
$</configure \
387397
--host=$(call make_tuple,$($@_XLEN),linux-gnu) \
@@ -429,6 +439,7 @@ stamps/build-gcc-linux-stage1: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-binutil
429439
$(WITH_ARCH) \
430440
$(WITH_TUNE) \
431441
$(WITH_ISA_SPEC) \
442+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
432443
CFLAGS_FOR_TARGET="-O2 $(CFLAGS_FOR_TARGET)" \
433444
CXXFLAGS_FOR_TARGET="-O2 $(CXXFLAGS_FOR_TARGET)"
434445
$(MAKE) -C $(notdir $@) inhibit-libc=true all-gcc
@@ -464,6 +475,7 @@ stamps/build-gcc-linux-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) $(addprefix stamps/b
464475
$(WITH_ARCH) \
465476
$(WITH_TUNE) \
466477
$(WITH_ISA_SPEC) \
478+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
467479
CFLAGS_FOR_TARGET="-O2 $(CFLAGS_FOR_TARGET)" \
468480
CXXFLAGS_FOR_TARGET="-O2 $(CXXFLAGS_FOR_TARGET)"
469481
$(MAKE) -C $(notdir $@)
@@ -518,6 +530,7 @@ stamps/build-gcc-linux-native: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-gcc-lin
518530
$(WITH_ARCH) \
519531
$(WITH_TUNE) \
520532
$(WITH_ISA_SPEC) \
533+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
521534
$(MAKE) -C $(notdir $@)
522535
$(MAKE) -C $(notdir $@) install
523536
cp -a $(INSTALL_DIR)/$(LINUX_TUPLE)/lib* $(SYSROOT)
@@ -596,6 +609,7 @@ stamps/build-gcc-newlib-stage1: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-binuti
596609
$(WITH_ARCH) \
597610
$(WITH_TUNE) \
598611
$(WITH_ISA_SPEC) \
612+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
599613
CFLAGS_FOR_TARGET="-Os $(CFLAGS_FOR_TARGET)" \
600614
CXXFLAGS_FOR_TARGET="-Os $(CXXFLAGS_FOR_TARGET)"
601615
$(MAKE) -C $(notdir $@) all-gcc
@@ -645,8 +659,13 @@ stamps/build-newlib-nano: $(NEWLIB_SRCDIR) $(NEWLIB_SRC_GIT) stamps/build-gcc-ne
645659

646660
stamps/merge-newlib-nano: stamps/build-newlib-nano stamps/build-newlib
647661
# Copy nano library files into newlib install dir.
662+
if [ -f $(INSTALL_DIR)/bin/$(NEWLIB_TUPLE)-gcc ] ; then \
663+
export NEWLIB_CC_FOR_MULTILIB_INFO="$(INSTALL_DIR)/bin/$(NEWLIB_TUPLE)-gcc"; \
664+
else \
665+
export NEWLIB_CC_FOR_MULTILIB_INFO="$(NEWLIB_CC_FOR_TARGET)"; \
666+
fi
648667
set -e; \
649-
for ml in `$(INSTALL_DIR)/bin/$(NEWLIB_TUPLE)-gcc --print-multi-lib`; \
668+
for ml in `${NEWLIB_CC_FOR_MULTILIB_INFO} --print-multi-lib`; \
650669
do \
651670
mld=`echo $${ml} | sed -e 's/;.*$$//'`; \
652671
cp $(builddir)/install-newlib-nano/$(NEWLIB_TUPLE)/lib/$${mld}/libc.a \
@@ -696,6 +715,7 @@ stamps/build-gcc-newlib-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-newlib
696715
$(WITH_ARCH) \
697716
$(WITH_TUNE) \
698717
$(WITH_ISA_SPEC) \
718+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
699719
CFLAGS_FOR_TARGET="-Os $(CFLAGS_FOR_TARGET)" \
700720
CXXFLAGS_FOR_TARGET="-Os $(CXXFLAGS_FOR_TARGET)"
701721
$(MAKE) -C $(notdir $@)
@@ -758,6 +778,7 @@ stamps/build-gcc-musl-stage1: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-binutils
758778
$(WITH_ARCH) \
759779
$(WITH_TUNE) \
760780
$(WITH_ISA_SPEC) \
781+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
761782
CFLAGS_FOR_TARGET="-O2 $(CFLAGS_FOR_TARGET)" \
762783
CXXFLAGS_FOR_TARGET="-O2 $(CXXFLAGS_FOR_TARGET)"
763784
$(MAKE) -C $(notdir $@) inhibit-libc=true all-gcc
@@ -785,8 +806,8 @@ stamps/build-musl-linux: $(MUSL_SRCDIR) $(MUSL_SRC_GIT) stamps/build-gcc-musl-st
785806
cd $(notdir $@) && \
786807
CC="$(MUSL_CC_FOR_TARGET) $($@_CFLAGS)" \
787808
CXX="$(MUSL_CXX_FOR_TARGET) $($@_CFLAGS)" \
788-
CFLAGS="$(CFLAGS_FOR_TARGET) -g -O2 $($@_CFLAGS)" \
789-
CXXFLAGS="$(CXXFLAGS_FOR_TARGET) -g -O2 $($@_CFLAGS)" \
809+
CFLAGS="$(CFLAGS_FOR_TARGET) -O2 $($@_CFLAGS)" \
810+
CXXFLAGS="$(CXXFLAGS_FOR_TARGET) -O2 $($@_CFLAGS)" \
790811
ASFLAGS="$(ASFLAGS_FOR_TARGET) $($@_CFLAGS)" \
791812
$</configure \
792813
--host=$(MUSL_TUPLE) \
@@ -826,6 +847,7 @@ stamps/build-gcc-musl-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-musl-lin
826847
$(WITH_ARCH) \
827848
$(WITH_TUNE) \
828849
$(WITH_ISA_SPEC) \
850+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
829851
CFLAGS_FOR_TARGET="-O2 $(CFLAGS_FOR_TARGET)" \
830852
CXXFLAGS_FOR_TARGET="-O2 $(CXXFLAGS_FOR_TARGET)"
831853
$(MAKE) -C $(notdir $@)
@@ -843,7 +865,7 @@ stamps/build-spike: $(SPIKE_SRCDIR) $(SPIKE_SRC_GIT)
843865
mkdir -p $(dir $@)
844866
date > $@
845867

846-
stamps/build-pk32: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
868+
stamps/build-pk32: $(PK_SRCDIR) $(PK_SRC_GIT) stamps/build-gcc-newlib-stage2
847869
rm -rf $@ $(notdir $@)
848870
mkdir $(notdir $@)
849871
cd $(notdir $@) && $</configure \
@@ -856,7 +878,7 @@ stamps/build-pk32: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
856878
mkdir -p $(dir $@)
857879
date > $@
858880

859-
stamps/build-pk64: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
881+
stamps/build-pk64: $(PK_SRCDIR) $(PK_SRC_GIT) stamps/build-gcc-newlib-stage2
860882
rm -rf $@ $(notdir $@)
861883
mkdir $(notdir $@)
862884
cd $(notdir $@) && $</configure \
@@ -868,6 +890,10 @@ stamps/build-pk64: $(PK_SRCDIR) stamps/build-gcc-newlib-stage2
868890
mkdir -p $(dir $@)
869891
date > $@
870892

893+
stamps/install-python-package:
894+
python3 -m pip install --user pyelftools
895+
date > $@
896+
871897
stamps/build-qemu: $(QEMU_SRCDIR) $(QEMU_SRC_GIT)
872898
rm -rf $@ $(notdir $@)
873899
mkdir $(notdir $@)
@@ -893,9 +919,10 @@ stamps/build-llvm-linux: $(LLVM_SRCDIR) $(LLVM_SRC_GIT) \
893919
# Without a proper GCC install directory libgcc won't be found.
894920
# As a workaround we have to merge both paths:
895921
mkdir -p $(SYSROOT)/lib/
896-
ln -s $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc
922+
ln -s -f $(INSTALL_DIR)/lib/gcc $(SYSROOT)/lib/gcc
897923
rm -rf $@ $(notdir $@)
898924
mkdir $(notdir $@)
925+
cd $(notdir $@) && ln -f -s $(SYSROOT) sysroot
899926
cd $(notdir $@) && \
900927
cmake $(LLVM_SRCDIR)/llvm \
901928
-DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) \
@@ -904,20 +931,21 @@ stamps/build-llvm-linux: $(LLVM_SRCDIR) $(LLVM_SRC_GIT) \
904931
-DLLVM_ENABLE_PROJECTS="clang;lld" \
905932
-DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind" \
906933
-DLLVM_DEFAULT_TARGET_TRIPLE="$(LINUX_TUPLE)" \
907-
-DDEFAULT_SYSROOT="$(INSTALL_DIR)/sysroot" \
934+
-DDEFAULT_SYSROOT="../sysroot" \
908935
-DLLVM_RUNTIME_TARGETS=$(call make_tuple,$(XLEN),linux-gnu) \
909936
-DLLVM_INSTALL_TOOLCHAIN_ONLY=On \
910937
-DLLVM_PARALLEL_LINK_JOBS=4
911938
$(MAKE) -C $(notdir $@)
912939
$(MAKE) -C $(notdir $@) install
940+
cp $(notdir $@)/lib/riscv64-unknown-linux-gnu/libc++* $(SYSROOT)/lib
913941
cd $(INSTALL_DIR)/bin && ln -s clang $(LINUX_TUPLE)-clang
914942
mkdir -p $(dir $@) && touch $@
915943

916944
stamps/build-llvm-newlib:
917945
echo "Building LLVM is only supported in combination with a Linux toolchain."
918946
exit 1
919947

920-
stamps/build-dejagnu: $(srcdir)/dejagnu $(srcdir)/dejagnu/.git
948+
stamps/build-dejagnu: $(DEJAGNU_SRCDIR) $(DEJAGNU_SRC_GIT)
921949
rm -rf $@ $(notdir $@)
922950
mkdir $(notdir $@)
923951
cd $(notdir $@) && $</configure \

0 commit comments

Comments
 (0)