diff --git a/.gitignore b/.gitignore index 5a1eeb513f5..c833cfa4c09 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build config.log config.status Makefile +picolibc-cross.txt .DS_Store !/regression/Makefile /build-*/ diff --git a/Makefile.in b/Makefile.in index a67c4b911bb..a414d6b57e3 100644 --- a/Makefile.in +++ b/Makefile.in @@ -5,6 +5,7 @@ INSTALL_DIR := @prefix@ GCC_SRCDIR := @with_gcc_src@ BINUTILS_SRCDIR := @with_binutils_src@ NEWLIB_SRCDIR := @with_newlib_src@ +PICOLIBC_SRCDIR := @with_picolibc_src@ GLIBC_SRCDIR := @with_glibc_src@ MUSL_SRCDIR := @with_musl_src@ LINUX_HEADERS_SRCDIR := @with_linux_headers_src@ @@ -57,9 +58,11 @@ MULTILIB_FLAGS := @multilib_flags@ MULTILIB_GEN := @multilib_gen@ ifeq ($(MULTILIB_GEN),) NEWLIB_MULTILIB_NAMES := @newlib_multilib_names@ +PICOLIBC_MULTILIB_NAMES := @picolibc_multilib_names@ GCC_MULTILIB_FLAGS := $(MULTILIB_FLAGS) else NEWLIB_MULTILIB_NAMES := $(shell echo "$(MULTILIB_GEN)" | $(SED) 's/;/\n/g'| $(AWK) '{split($$0,a,"-"); printf "%s-%s ", a[1],a[2]}') +PICOLIBC_MULTILIB_NAMES := $(shell echo "$(MULTILIB_GEN)" | $(SED) 's/;/\n/g'| $(AWK) '{split($$0,a,"-"); printf "%s-%s ", a[1],a[2]}') GCC_MULTILIB_FLAGS := $(MULTILIB_FLAGS) --with-multilib-generator="$(MULTILIB_GEN)" endif GLIBC_MULTILIB_NAMES := @glibc_multilib_names@ @@ -73,6 +76,7 @@ endif make_tuple = riscv$(1)-unknown-$(2) LINUX_TUPLE ?= $(call make_tuple,$(XLEN),linux-gnu) NEWLIB_TUPLE ?= $(call make_tuple,$(XLEN),elf) +PICOLIBC_TUPLE ?= $(call make_tuple,$(XLEN),elf) MUSL_TUPLE ?= $(call make_tuple,$(XLEN),linux-musl) CFLAGS_FOR_TARGET := $(CFLAGS_FOR_TARGET_EXTRA) @target_cflags@ @cmodel@ @@ -94,6 +98,10 @@ NEWLIB_CXX_FOR_TARGET ?= $(NEWLIB_TUPLE)-g++ NEWLIB_TARGET_BOARDS ?= $(shell echo "$(NEWLIB_MULTILIB_NAMES)" | sed 's!\([_a-z0-9]*\)-\([_a-z0-9]*\)!riscv-sim/-march=\1/-mabi=\2/@cmodel@!g') 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') +PICOLIBC_CC_FOR_TARGET ?= $(PICOLIBC_TUPLE)-gcc +PICOLIBC_CXX_FOR_TARGET ?= $(PICOLIBC_TUPLE)-g++ +PICOLIBC_TARGET_BOARDS ?= $(shell echo "$(PICOLIBC_MULTILIB_NAMES)" | sed 's!\([_a-z0-9]*\)-\([_a-z0-9]*\)!riscv-sim/-march=\1/-mabi=\2/@cmodel@!g') + MUSL_TARGET_FLAGS := $(MUSL_TARGET_FLAGS_EXTRA) MUSL_CC_FOR_TARGET ?= $(MUSL_TUPLE)-gcc MUSL_CXX_FOR_TARGET ?= $(MUSL_TUPLE)-g++ @@ -102,6 +110,7 @@ CONFIGURE_HOST = @configure_host@ all: @default_target@ newlib: stamps/build-gcc-newlib-stage2 +picolibc: stamps/build-gcc-picolibc-stage2 linux: stamps/build-gcc-linux-stage2 ifneq (,$(findstring riscv32,$(MUSL_TUPLE))) .PHONY: musl @@ -112,6 +121,7 @@ musl: stamps/build-gcc-musl-stage2 endif ifeq (@enable_gdb@,--enable-gdb) newlib: stamps/build-gdb-newlib +picolibc: stamps/build-gdb-picolibc linux: stamps/build-gdb-linux endif linux-native: stamps/build-gcc-linux-native @@ -123,43 +133,52 @@ build-gcc%: stamps/build-gcc-@default_target@-stage% ifeq (@default_target@,linux) build-libc: $(addprefix stamps/build-glibc-linux-,$(GLIBC_MULTILIB_NAMES)) else +ifeq (@default_target@,picolibc) +build-libc: stamps/build-picolibc +else build-libc: stamps/build-newlib stamps/build-newlib-nano \ stamps/merge-newlib-nano endif +endif build-qemu: stamps/build-qemu REGRESSION_TEST_LIST = gcc .PHONY: check check: check-@default_target@ -.PHONY: check-linux check-newlib +.PHONY: check-linux check-newlib check-picolibc check-linux: $(patsubst %,check-%-linux,$(REGRESSION_TEST_LIST)) check-newlib: $(patsubst %,check-%-newlib,$(REGRESSION_TEST_LIST)) check-newlib-nano: $(patsubst %,check-%-newlib-nano,$(REGRESSION_TEST_LIST)) -.PHONY: check-gcc check-gcc-linux check-gcc-newlib check-gcc-newlib-nano +check-picolibc: $(patsubst %,check-%-picolibc,$(REGRESSION_TEST_LIST)) +.PHONY: check-gcc check-gcc-linux check-gcc-newlib check-gcc-newlib-nano check-gcc-picolibc check-gcc: check-gcc-@default_target@ check-gcc-linux: stamps/check-gcc-linux check-gcc-newlib: stamps/check-gcc-newlib check-gcc-newlib-nano: stamps/check-gcc-newlib-nano -.PHONY: check-dhrystone check-dhrystone-linux check-dhrystone-newlib +check-gcc-picolibc: stamps/check-gcc-picolibc +.PHONY: check-dhrystone check-dhrystone-linux check-dhrystone-newlib check-dhrystone-picolibc check-dhrystone: check-dhrystone-@default_target@ -.PHONY: check-binutils check-binutils-linux check-binutils-newlib +.PHONY: check-binutils check-binutils-linux check-binutils-newlib check-binutils-picolibc check-binutils: check-binutils-@default_target@ check-binutils-linux: stamps/check-binutils-linux check-binutils-newlib: stamps/check-binutils-newlib check-binutils-newlib-nano: stamps/check-binutils-newlib-nano -.PHONY: check-gdb check-gdb-linux check-gdb-newlib +check-binutils-picolibc: stamps/check-binutils-picolibc +.PHONY: check-gdb check-gdb-linux check-gdb-newlib check-gdb-picolibc check-gdb: check-gdb-@default_target@ check-gdb-linux: stamps/check-gdb-linux check-gdb-newlib: stamps/check-gdb-newlib check-gdb-newlib-nano: stamps/check-gdb-newlib-nano +check-gdb-picolibc: stamps/check-gdb-picolibc .PHONY: report report: report-@default_target@ -.PHONY: report-linux report-newlib report-newlib-nano +.PHONY: report-linux report-newlib report-newlib-nano report-picolibc report-linux: $(patsubst %,report-%-linux,$(REGRESSION_TEST_LIST)) report-newlib: $(patsubst %,report-%-newlib,$(REGRESSION_TEST_LIST)) report-newlib-nano: $(patsubst %,report-%-newlib-nano,$(REGRESSION_TEST_LIST)) +report-picolibc: $(patsubst %,report-%-picolibc,$(REGRESSION_TEST_LIST)) .PHONY: report-gcc report-gcc: report-gcc-@default_target@ .PHONY: report-dhrystone @@ -678,6 +697,141 @@ stamps/build-gcc-newlib-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-newlib $(MAKE) -C $(notdir $@) install mkdir -p $(dir $@) && touch $@ +# +# PICOLIBC +# + +stamps/build-binutils-picolibc: $(BINUTILS_SRCDIR) $(BINUTILS_SRC_GIT) stamps/check-write-permission + rm -rf $@ $(notdir $@) + mkdir $(notdir $@) +# CC_FOR_TARGET is required for the ld testsuite. + cd $(notdir $@) && CC_FOR_TARGET=$(PICOLIBC_CC_FOR_TARGET) $ $@ + +stamps/build-gcc-picolibc-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-picolibc + rm -rf $@ $(notdir $@) + mkdir $(notdir $@) + cd $(notdir $@) && $ $@ +stamps/check-gcc-picolibc: stamps/build-gcc-picolibc-stage2 $(SIM_STAMP) stamps/build-dejagnu + $(SIM_PREPARE) $(MAKE) -C build-gcc-picolibc-stage2 check-gcc "RUNTESTFLAGS=--target_board='$(PICOLIBC_TARGET_BOARDS)'" + mkdir -p $(dir $@) + date > $@ + stamps/check-gcc-linux: stamps/build-gcc-linux-stage2 $(SIM_STAMP) stamps/build-dejagnu $(SIM_PREPARE) $(MAKE) -C build-gcc-linux-stage2 check-gcc "RUNTESTFLAGS=--target_board='$(GLIBC_TARGET_BOARDS)'" mkdir -p $(dir $@) @@ -903,6 +1062,17 @@ stamps/check-dhrystone-newlib-nano-%: \ $(eval $@_XLEN := $(patsubst rv32%,32,$(patsubst rv64%,64,$($@_ARCH)))) $(SIM_PREPARE) $(srcdir)/test/benchmarks/dhrystone/check -march=$($@_ARCH) -mabi=$($@_ABI) -specs=nano.specs -cc=riscv$(XLEN)-unknown-elf-gcc -objdump=riscv$(XLEN)-unknown-elf-objdump -sim=riscv$($@_XLEN)-unknown-elf-run -out=$@ $(filter %.c,$^) || true +.PHONY: check-dhrystone-picolibc +check-dhrystone-picolibc: $(patsubst %,stamps/check-dhrystone-picolibc-%,$(PICOLIBC_MULTILIB_NAMES)) +stamps/check-dhrystone-picolibc-%: \ + stamps/build-gcc-picolibc-stage2 \ + $(SIM_STAMP) \ + $(wildcard $(srcdir)/test/benchmarks/dhrystone/*) + $(eval $@_ARCH := $(word 4,$(subst -, ,$@))) + $(eval $@_ABI := $(word 5,$(subst -, ,$@))) + $(eval $@_XLEN := $(patsubst rv32%,32,$(patsubst rv64%,64,$($@_ARCH)))) + $(SIM_PREPARE) $(srcdir)/test/benchmarks/dhrystone/check -march=$($@_ARCH) -mabi=$($@_ABI) -cc=riscv$(XLEN)-unknown-elf-gcc -objdump=riscv$(XLEN)-unknown-elf-objdump -sim=riscv$($@_XLEN)-unknown-elf-run -out=$@ $(filter %.c,$^) || true + .PHONY: check-dhrystone-linux check-dhrystone-linux: $(patsubst %,stamps/check-dhrystone-linux-%,$(GLIBC_MULTILIB_NAMES)) @@ -923,6 +1093,10 @@ stamps/check-binutils-newlib-nano: stamps/build-gcc-newlib-stage2 $(SIM_STAMP) s $(SIM_PREPARE) $(MAKE) -C build-binutils-newlib check-binutils check-gas check-ld -k "RUNTESTFLAGS=--target_board='$(NEWLIB_NANO_TARGET_BOARDS)'" || true date > $@ +stamps/check-binutils-picolibc: stamps/build-gcc-picolibc-stage2 $(SIM_STAMP) stamps/build-dejagnu + $(SIM_PREPARE) $(MAKE) -C build-binutils-picolibc check-binutils check-gas check-ld -k "RUNTESTFLAGS=--target_board='$(PICOLIBC_TARGET_BOARDS)'" || true + date > $@ + stamps/check-binutils-linux: stamps/build-gcc-linux-stage2 $(SIM_STAMP) stamps/build-dejagnu $(SIM_PREPARE) $(MAKE) -C build-binutils-linux check-binutils check-gas check-ld -k "RUNTESTFLAGS=--target_board='$(GLIBC_TARGET_BOARDS)'" || true date > $@ @@ -935,6 +1109,10 @@ stamps/check-gdb-newlib-nano: stamps/build-gcc-newlib-stage2 stamps/build-gdb-ne $(SIM_PREPARE) $(MAKE) -C build-gdb-newlib check-gdb -k "RUNTESTFLAGS=--target_board='$(NEWLIB_NANO_TARGET_BOARDS)'" || true date > $@ +stamps/check-gdb-picolibc: stamps/build-gcc-picolibc-stage2 stamps/build-gdb-picolibc $(SIM_STAMP) stamps/build-dejagnu + $(SIM_PREPARE) $(MAKE) -C build-gdb-picolibc check-gdb -k "RUNTESTFLAGS=--target_board='$(PICOLIBC_TARGET_BOARDS)'" || true + date > $@ + stamps/check-gdb-linux: stamps/build-gcc-linux-stage2 stamps/build-gdb-linux $(SIM_STAMP) stamps/build-dejagnu $(SIM_PREPARE) $(MAKE) -C build-gdb-linux check-gdb -k "RUNTESTFLAGS=--target_board='$(GLIBC_TARGET_BOARDS)'" || true date > $@ @@ -946,6 +1124,10 @@ report-gcc-newlib: stamps/check-gcc-newlib report-gcc-newlib-nano: stamps/check-gcc-newlib-nano $(srcdir)/scripts/testsuite-filter gcc newlib-nano $(srcdir)/test/allowlist `find build-gcc-newlib-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -` +.PHONY: report-gcc-picolibc +report-gcc-picolibc: stamps/check-gcc-picolibc + $(srcdir)/scripts/testsuite-filter gcc picolibc $(srcdir)/test/allowlist `find build-gcc-picolibc-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -` + .PHONY: report-gcc-linux report-gcc-linux: stamps/check-gcc-linux $(srcdir)/scripts/testsuite-filter gcc glibc $(srcdir)/test/allowlist `find build-gcc-linux-stage2/gcc/testsuite/ -name *.sum |paste -sd "," -` @@ -956,6 +1138,10 @@ report-dhrystone-newlib: $(patsubst %,stamps/check-dhrystone-newlib-%,$(NEWLIB_M report-dhrystone-newlib-nano: $(patsubst %,stamps/check-dhrystone-newlib-nano-%,$(NEWLIB_MULTILIB_NAMES)) if cat $^ | grep -v '^PASS'; then false; else true; fi +.PHONY: report-dhrystone-picolibc +report-dhrystone-picolibc: $(patsubst %,stamps/check-dhrystone-picolibc-%,$(PICOLIBC_MULTILIB_NAMES)) + if cat $^ | grep -v '^PASS'; then false; else true; fi + .PHONY: report-dhrystone-linux report-dhrystone-linux: $(patsubst %,stamps/check-dhrystone-linux-%,$(GLIBC_MULTILIB_NAMES)) if cat $^ | grep -v '^PASS'; then false; else true; fi @@ -971,6 +1157,12 @@ report-binutils-newlib-nano: stamps/check-binutils-newlib-nano $(srcdir)/test/allowlist \ `find build-binutils-newlib/ -name *.sum |paste -sd "," -` +.PHONY: report-binutils-picolibc +report-binutils-picolibc: stamps/check-binutils-picolibc + $(srcdir)/scripts/testsuite-filter binutils picolibc \ + $(srcdir)/test/allowlist \ + `find build-binutils-picolibc/ -name *.sum |paste -sd "," -` + .PHONY: report-binutils-linux report-binutils-linux: stamps/check-binutils-linux $(srcdir)/scripts/testsuite-filter binutils glibc \ @@ -978,7 +1170,7 @@ report-binutils-linux: stamps/check-binutils-linux `find build-binutils-linux/ -name *.sum |paste -sd "," -` clean: - rm -rf build-* stamps install-newlib-nano + rm -rf build-* stamps install-newlib-nano picolibc-cross.txt .PHONY: report-gdb-newlib report-gdb-newlib-nano report-gdb-newlib: stamps/check-gdb-newlib @@ -993,6 +1185,13 @@ report-gdb-newlib-nano: stamps/check-gdb-newlib-nano if grep '^$$' $(patsubst %,$(srcdir)/test/gdb-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then exit 1; fi if find build-gdb-newlib -iname '*.sum' | xargs grep ^FAIL | sort | grep -F -v $(patsubst %,--file=$(srcdir)/test/gdb-newlib/%.log,$(NEWLIB_MULTILIB_NAMES)); then false; else true; fi +.PHONY: report-gdb-picolibc +report-gdb-picolibc: stamps/check-gdb-picolibc + stat $(patsubst %,$(srcdir)/test/gdb-picolibc/%.log,$(PICOLIBC_MULTILIB_NAMES)) || exit 1 +# Fail if there are blank lines in the log file used as input for grep below. + if grep '^$$' $(patsubst %,$(srcdir)/test/gdb-picolibc/%.log,$(PICOLIBC_MULTILIB_NAMES)); then exit 1; fi + if find build-gdb-picolibc -iname '*.sum' | xargs grep ^FAIL | sort | grep -F -v $(patsubst %,--file=$(srcdir)/test/gdb-picolibc/%.log,$(PICOLIBC_MULTILIB_NAMES)); then false; else true; fi + .PHONY: report-gdb-linux report-gdb-linux: stamps/check-gdb-linux stat $(patsubst %,$(srcdir)/test/gdb-linux/%.log,$(GLIBC_MULTILIB_NAMES)) || exit 1 diff --git a/configure b/configure index e148a8fde59..eac9b02a370 100755 --- a/configure +++ b/configure @@ -593,6 +593,7 @@ with_qemu_src with_gdb_src with_musl_src with_glibc_src +with_picolibc_src with_newlib_src with_binutils_src with_gcc_src @@ -605,6 +606,7 @@ target_cflags cmodel gcc_checking musl_multilib_names +picolibc_multilib_names newlib_multilib_names glibc_multilib_names multilib_flags @@ -675,6 +677,7 @@ ac_subst_files='' ac_user_opts=' enable_option_checking enable_linux +enable_picolibc with_arch with_abi with_tune @@ -693,6 +696,7 @@ enable_gdb with_gcc_src with_binutils_src with_newlib_src +with_picolibc_src with_glibc_src with_musl_src with_gdb_src @@ -1333,6 +1337,7 @@ Optional Features: --enable-FEATURE[=ARG] include FEATURE [ARG=yes] --enable-linux set linux as the default make target [--disable-linux] + --enable-picolibc set picolibc as the default make target --enable-multilib build both RV32 and RV64 runtime libraries (only RV64 for musl libc) [--disable-multilib] --enable-gcc-checking Enable gcc internal checking, it will make gcc very @@ -1369,6 +1374,8 @@ Optional Packages: default --with-newlib-src Set newlib source path, use builtin source by default + --with-picolibc-src Set picolibc source path, use builtin source by + default --with-glibc-src Set glibc source path, use builtin source by default --with-musl-src Set musl source path, use builtin source by default --with-gdb-src Set gdb source path, use builtin source by default @@ -3283,12 +3290,27 @@ else fi +# Check whether --enable-picolibc was given. +if test "${enable_picolibc+set}" = set; then : + enableval=$enable_picolibc; enable_picolibc=yes +else + enable_picolibc=no + +fi + + if test "x$enable_linux" != xno; then : default_target=linux +else + if test "x$enable_picolibc" != xno; then : + default_target=picolibc + else default_target=newlib + +fi fi @@ -3426,6 +3448,14 @@ else fi +if test "x$enable_multilib" != xno; then : + picolibc_multilib_names="rv32i-ilp32 rv32iac-ilp32 rv32im-ilp32 rv32imac-ilp32 rv32imafc-ilp32f rv64imac-lp64 rv64imafdc-lp64d" + +else + picolibc_multilib_names="$with_arch-$with_abi" + +fi + if test "x$enable_multilib" != xno; then : musl_multilib_names="rv64imac-lp64 rv64imafdc-lp64d" @@ -3617,6 +3647,25 @@ fi } { +# Check whether --with-picolibc-src was given. +if test "${with_picolibc_src+set}" = set; then : + withval=$with_picolibc_src; +else + with_picolibc_src=default + +fi + + if test "x$with_picolibc_src" != xdefault; then : + with_picolibc_src=$with_picolibc_src + +else + with_picolibc_src="\$(srcdir)/picolibc" + +fi + + } +{ + # Check whether --with-glibc-src was given. if test "${with_glibc_src+set}" = set; then : withval=$with_glibc_src; diff --git a/configure.ac b/configure.ac index f2464d1b1c9..423fd1ded3c 100644 --- a/configure.ac +++ b/configure.ac @@ -46,9 +46,19 @@ AC_ARG_ENABLE(linux, [enable_linux=no] ) +AC_ARG_ENABLE(picolibc, + [AS_HELP_STRING([--enable-picolibc], + [set picolibc as the default make target])], + [enable_picolibc=yes], + [enable_picolibc=no] + ) + AS_IF([test "x$enable_linux" != xno], [AC_SUBST(default_target, linux)], - [AC_SUBST(default_target, newlib)]) + [AS_IF([test "x$enable_picolibc" != xno], + [AC_SUBST(default_target, picolibc)], + [AC_SUBST(default_target, newlib)] + )]) AC_ARG_WITH(arch, [AS_HELP_STRING([--with-arch=rv64imafdc], @@ -134,6 +144,10 @@ AS_IF([test "x$enable_multilib" != xno], [AC_SUBST(newlib_multilib_names,"rv32i-ilp32 rv32iac-ilp32 rv32im-ilp32 rv32imac-ilp32 rv32imafc-ilp32f rv64imac-lp64 rv64imafdc-lp64d")], [AC_SUBST(newlib_multilib_names,"$with_arch-$with_abi")]) +AS_IF([test "x$enable_multilib" != xno], + [AC_SUBST(picolibc_multilib_names,"rv32i-ilp32 rv32iac-ilp32 rv32im-ilp32 rv32imac-ilp32 rv32imafc-ilp32f rv64imac-lp64 rv64imafdc-lp64d")], + [AC_SUBST(picolibc_multilib_names,"$with_arch-$with_abi")]) + AS_IF([test "x$enable_multilib" != xno], [AC_SUBST(musl_multilib_names,"rv64imac-lp64 rv64imafdc-lp64d")], [AC_SUBST(musl_multilib_names,"$with_arch-$with_abi")]) @@ -238,6 +252,7 @@ AC_DEFUN([AX_ARG_WITH_SRC], AX_ARG_WITH_SRC(gcc, gcc) AX_ARG_WITH_SRC(binutils, binutils) AX_ARG_WITH_SRC(newlib, newlib) +AX_ARG_WITH_SRC(picolibc, picolibc) AX_ARG_WITH_SRC(glibc, glibc) AX_ARG_WITH_SRC(musl, musl) AX_ARG_WITH_SRC(gdb, riscv-gdb) diff --git a/make-picolibc-cross b/make-picolibc-cross new file mode 100644 index 00000000000..6140cf58600 --- /dev/null +++ b/make-picolibc-cross @@ -0,0 +1,25 @@ +#!/bin/sh +tuple="$1" +shift +args="" +for cf in "$@"; do + args="$args '$cf'," +done +cat << EOF +[binaries] +c = '${tuple}-gcc' +ar = '${tuple}-ar' +as = '${tuple}-as' +strip = '${tuple}-strip' + +[host_machine] +system = 'riscv' +cpu_family = 'riscv' +cpu = 'riscv' +endian = 'little' + +[properties] +c_args = [ '-Os',${args} '-nostdlib', '-fno-common', '-ftls-model=local-exec' ] +needs_exe_wrapper = true +skip_sanity_check = true +EOF