Skip to content

Commit 3d8e780

Browse files
committed
picolibc: Add support of building Picolibc based toolchains
Use this option to use Picolibc for building a baremetal toolchain: --enable-picolibc Here is a sample command line for configuring and building a Picolibc toolchain for ARC-V: ./configure \ --prefix=<path> \ --with-arch=rv32imafc \ --with-tune=rocket \ --with-abi=ilp32f \ --with-cmodel=medlow \ --with-triplet-xlen=64 \ --with-sim=qemu \ --enable-picolibc \ --enable-gdb \ --enable-multilib \ --enable-qemu-system \ --with-vendor=snps \ --with-vendor-alias=unknown \ --with-multilib-generator="" \ --enable-debug-info \ --with-host-cflags="-O2" \ --with-host-cxxflags="-O2" make make aliases Note that building Picolibc requires Meson and Ninja on a host system. Two versions of Picolibc, libgcc and libstdc++ are built: 1. -O3 optimized libraries for default linking. 2. -Os optimized libraries in a separate picolibc-nano directory. Use -specs=nano.specs to link a program with size optimized libraries. Also, stamps/check-libc-picolibc target builds Picolibc for running tests and runs them. Only QEMU is supported so far. Signed-off-by: Yuriy Kolerov <[email protected]>
1 parent 3c50de7 commit 3d8e780

File tree

7 files changed

+554
-3
lines changed

7 files changed

+554
-3
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@
5050
path = uclibc-ng
5151
url = https://github.com/wbx-github/uclibc-ng.git
5252
shallow = true
53+
[submodule "picolibc"]
54+
path = picolibc
55+
url = https://github.com/foss-for-synopsys-dwc-arc-processors/picolibc
56+
branch = arc-2025.06

Makefile.in

Lines changed: 316 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ INSTALL_DIR := @prefix@
55
GCC_SRCDIR := @with_gcc_src@
66
BINUTILS_SRCDIR := @with_binutils_src@
77
NEWLIB_SRCDIR := @with_newlib_src@
8+
PICOLIBC_SRCDIR := @with_picolibc_src@
89
GLIBC_SRCDIR := @with_glibc_src@
910
MUSL_SRCDIR := @with_musl_src@
1011
UCLIBC_SRCDIR := @with_uclibc_src@
@@ -163,11 +164,13 @@ PATH := $(builddir)/install-host-gcc/bin:$(PATH)
163164
GCC_CHECKING_FLAGS := $(GCC_CHECKING_FLAGS) --enable-werror-always
164165
endif
165166
newlib: stamps/build-gcc-newlib-stage2
167+
picolibc: stamps/build-gcc-picolibc-stage2-nano
166168
linux: stamps/build-gcc-linux-stage2
167169
musl: stamps/build-gcc-musl-stage2
168170
uclibc: stamps/build-gcc-uclibc-stage2
169171
ifeq (@enable_gdb@,--enable-gdb)
170172
newlib: stamps/build-gdb-newlib
173+
picolibc: stamps/build-gdb-picolibc
171174
linux: stamps/build-gdb-linux
172175
musl: stamps/build-gdb-musl
173176
endif
@@ -210,6 +213,9 @@ check-gcc-newlib-nano: stamps/check-gcc-newlib-nano
210213
.PHONY: check-libc-newlib check-libc-newlib-nano
211214
check-libc-newlib: stamps/check-libc-newlib
212215
check-libc-newlib-nano: stamps/check-libc-newlib-nano
216+
.PHONY: check-libc-picolibc-perf check-libc-picolibc-nano
217+
check-libc-picolibc-perf: stamps/check-libc-picolibc-perf
218+
check-libc-picolibc-nano: stamps/check-libc-picolibc-nano
213219
.PHONY: check-glibc-linux
214220
check-glibc-linux: $(addprefix stamps/check-glibc-linux-,$(GLIBC_MULTILIB_NAMES))
215221
.PHONY: check-dhrystone check-dhrystone-linux check-dhrystone-newlib
@@ -341,6 +347,12 @@ else
341347
NEWLIB_SRC_GIT :=
342348
endif
343349

350+
ifeq ($(findstring $(srcdir),$(PICOLIBC_SRCDIR)),$(srcdir))
351+
PICOLIBC_SRC_GIT := $(PICOLIBC_SRCDIR)/.git
352+
else
353+
PICOLIBC_SRC_GIT :=
354+
endif
355+
344356
ifeq ($(findstring $(srcdir),$(GLIBC_SRCDIR)),$(srcdir))
345357
GLIBC_SRC_GIT := $(GLIBC_SRCDIR)/.git
346358
else
@@ -390,7 +402,7 @@ else
390402
GCCPKGVER :=
391403
endif
392404

393-
TARGET_DIRS := binutils gdb gcc newlib dejagnu
405+
TARGET_DIRS := binutils gdb gcc newlib dejagnu picolibc
394406
$(srcdir)/%/.git:
395407
cd $(srcdir) && \
396408
flock `git rev-parse --git-dir`/config git submodule init $(dir $@) && \
@@ -847,6 +859,309 @@ stamps/build-gcc-newlib-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-newlib
847859
$(MAKE) -C $(notdir $@) install
848860
mkdir -p $(dir $@) && touch $@
849861

862+
#
863+
# Picolibc
864+
#
865+
866+
stamps/build-binutils-picolibc: $(BINUTILS_SRCDIR) $(BINUTILS_SRC_GIT) $(PREPARATION_STAMP)
867+
rm -rf $@ $(notdir $@)
868+
mkdir $(notdir $@)
869+
# CC_FOR_TARGET is required for the ld testsuite.
870+
cd $(notdir $@) && CC_FOR_TARGET=$(NEWLIB_CC_FOR_TARGET) $</configure \
871+
--target=$(NEWLIB_TUPLE) \
872+
$(CONFIGURE_HOST) \
873+
--prefix=$(INSTALL_DIR) \
874+
--enable-plugins \
875+
@with_guile@ \
876+
--disable-werror \
877+
$(BINUTILS_TARGET_FLAGS) \
878+
--disable-gdb \
879+
--disable-sim \
880+
--disable-libdecnumber \
881+
--disable-readline \
882+
$(WITH_ISA_SPEC) \
883+
CFLAGS="$(CFLAGS_FOR_HOST)" \
884+
CXXFLAGS="$(CXXFLAGS_FOR_HOST)"
885+
$(MAKE) -C $(notdir $@)
886+
$(MAKE) -C $(notdir $@) install
887+
mkdir -p $(dir $@) && touch $@
888+
889+
stamps/build-gdb-picolibc: $(GDB_SRCDIR) $(GDB_SRC_GIT) $(PREPARATION_STAMP)
890+
rm -rf $@ $(notdir $@)
891+
mkdir $(notdir $@)
892+
# CC_FOR_TARGET is required for the ld testsuite.
893+
cd $(notdir $@) && CC_FOR_TARGET=$(NEWLIB_CC_FOR_TARGET) $</configure \
894+
--target=$(NEWLIB_TUPLE) \
895+
$(CONFIGURE_HOST) \
896+
--prefix=$(INSTALL_DIR) \
897+
@with_guile@ \
898+
--disable-werror \
899+
$(GDB_TARGET_FLAGS) \
900+
--enable-gdb \
901+
--disable-gas \
902+
--disable-binutils \
903+
--disable-ld \
904+
--disable-gold \
905+
--disable-gprof \
906+
CFLAGS="$(CFLAGS_FOR_HOST)" \
907+
CXXFLAGS="$(CXXFLAGS_FOR_HOST)"
908+
$(MAKE) -C $(notdir $@)
909+
$(MAKE) -C $(notdir $@) install
910+
mkdir -p $(dir $@) && touch $@
911+
912+
stamps/build-gcc-picolibc-stage1: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-binutils-picolibc
913+
if test -f $</contrib/download_prerequisites && test "@NEED_GCC_EXTERNAL_LIBRARIES@" = "true"; then cd $< && ./contrib/download_prerequisites; fi
914+
rm -rf $@ $(notdir $@)
915+
mkdir $(notdir $@)
916+
cd $(notdir $@) && $</configure \
917+
--target=$(NEWLIB_TUPLE) \
918+
$(CONFIGURE_HOST) \
919+
--prefix=$(INSTALL_DIR) \
920+
--disable-shared \
921+
--disable-threads \
922+
--enable-tls \
923+
--enable-languages=c,c++ \
924+
@with_system_zlib@ \
925+
--with-newlib \
926+
--without-headers \
927+
--disable-libmudflap \
928+
--disable-libssp \
929+
--disable-libquadmath \
930+
--disable-libgomp \
931+
--disable-nls \
932+
--disable-tm-clone-registry \
933+
--src=$(gccsrcdir) \
934+
$(GCC_CHECKING_FLAGS) \
935+
$(GCC_MULTILIB_FLAGS) \
936+
$(WITH_ABI) \
937+
$(WITH_ARCH) \
938+
$(WITH_TUNE) \
939+
$(WITH_ISA_SPEC) \
940+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
941+
CFLAGS="$(CFLAGS_FOR_HOST)" \
942+
CXXFLAGS="$(CXXFLAGS_FOR_HOST)" \
943+
CFLAGS_FOR_TARGET="-Os $(CFLAGS_FOR_TARGET)" \
944+
CXXFLAGS_FOR_TARGET="-Os $(CXXFLAGS_FOR_TARGET)"
945+
$(MAKE) -C $(notdir $@) all-gcc
946+
$(MAKE) -C $(notdir $@) install-gcc
947+
mkdir -p $(dir $@) && touch $@
948+
949+
PICOLIBC_COMMON_CONFIGURE_OPTIONS := \
950+
--cross-file cross-$(NEWLIB_TUPLE).txt \
951+
-Dincludedir=include \
952+
-Dsystem-libc=true \
953+
-Dposix-console=true \
954+
-Dlite-exit=true \
955+
-Dnewlib-obsolete-math=false \
956+
-Dwant-math-errno=true \
957+
-Datomic-signal=false \
958+
-Dassert-verbose=true \
959+
-Ddebug=true \
960+
-Dwerror=true
961+
962+
PICOLIBC_PERF_CONFIGURE_OPTIONS := \
963+
-Doptimization=3 \
964+
-Dio-c99-formats=true \
965+
-Dio-long-long=true \
966+
-Dio-long-double=true \
967+
-Dio-percent-b=true \
968+
-Dprintf-percent-n=true \
969+
-Dfast-bufio=true \
970+
-Dmb-capable=true \
971+
-Dio-wchar=true \
972+
$(PICOLIBC_COMMON_CONFIGURE_OPTIONS)
973+
974+
PICOLIBC_NANO_CONFIGURE_OPTIONS := \
975+
-Doptimization=s \
976+
-Dio-c99-formats=true \
977+
-Dio-long-long=false \
978+
-Dio-long-double=false \
979+
-Dio-percent-b=false \
980+
-Dprintf-percent-n=false \
981+
-Dfast-bufio=false \
982+
-Dmb-capable=false \
983+
-Dio-wchar=false \
984+
$(PICOLIBC_COMMON_CONFIGURE_OPTIONS)
985+
986+
define PICOLIBC_OBSOLETE_MATH_BLOCK
987+
#if (__riscv_flen < 64) && !defined(__riscv_zdinx)
988+
#undef __OBSOLETE_MATH
989+
#undef __OBSOLETE_MATH_FLOAT
990+
#undef __OBSOLETE_MATH_DOUBLE
991+
#define __OBSOLETE_MATH 1
992+
#endif
993+
endef
994+
export PICOLIBC_OBSOLETE_MATH_BLOCK
995+
996+
stamps/configure-picolibc-perf: $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT) stamps/build-gcc-picolibc-stage1
997+
rm -rf $@ stamps/build-picolibc-perf build-picolibc-perf
998+
mkdir build-picolibc-perf
999+
cd build-picolibc-perf && $(srcdir)/scripts/generate_picolibc_cross_file \
1000+
--triplet $(NEWLIB_TUPLE) \
1001+
--cflags "$(CFLAGS_FOR_TARGET)" \
1002+
> cross-$(NEWLIB_TUPLE).txt
1003+
cd build-picolibc-perf && meson setup . $(PICOLIBC_SRCDIR) \
1004+
-Dprefix=$(INSTALL_DIR)/$(NEWLIB_TUPLE) \
1005+
-Dlibdir=$(INSTALL_DIR)/$(NEWLIB_TUPLE)/lib \
1006+
-Dspecsdir=$(INSTALL_DIR)/$(NEWLIB_TUPLE)/lib \
1007+
$(PICOLIBC_PERF_CONFIGURE_OPTIONS)
1008+
cd build-picolibc-perf && echo "$$PICOLIBC_OBSOLETE_MATH_BLOCK" >> picolibc.h
1009+
mkdir -p $(dir $@) && touch $@
1010+
1011+
stamps/build-picolibc-perf: $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT) stamps/configure-picolibc-perf
1012+
ninja -C $(notdir $@)
1013+
ninja -C $(notdir $@) install
1014+
mkdir -p $(dir $@) && touch $@
1015+
1016+
stamps/build-gcc-picolibc-stage2: ENABLED_LANGUAGES?="c,c++"
1017+
stamps/build-gcc-picolibc-stage2: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-picolibc-perf
1018+
rm -rf $@ $(notdir $@)
1019+
mkdir $(notdir $@)
1020+
cd $(notdir $@) && $</configure \
1021+
--target=$(NEWLIB_TUPLE) \
1022+
$(CONFIGURE_HOST) \
1023+
--prefix=$(INSTALL_DIR) \
1024+
--disable-shared \
1025+
--disable-threads \
1026+
--enable-languages=$(ENABLED_LANGUAGES) \
1027+
--with-pkgversion="$(GCCPKGVER)" \
1028+
@with_system_zlib@ \
1029+
--enable-tls \
1030+
--with-newlib \
1031+
--with-headers=$(INSTALL_DIR)/$(NEWLIB_TUPLE)/include \
1032+
--disable-libmudflap \
1033+
--disable-libssp \
1034+
--disable-libquadmath \
1035+
--disable-libgomp \
1036+
--disable-nls \
1037+
--disable-tm-clone-registry \
1038+
--src=$(gccsrcdir) \
1039+
$(GCC_CHECKING_FLAGS) \
1040+
$(GCC_MULTILIB_FLAGS) \
1041+
$(WITH_ABI) \
1042+
$(WITH_ARCH) \
1043+
$(WITH_TUNE) \
1044+
$(WITH_ISA_SPEC) \
1045+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
1046+
CFLAGS="$(CFLAGS_FOR_HOST)" \
1047+
CXXFLAGS="$(CXXFLAGS_FOR_HOST)" \
1048+
CFLAGS_FOR_TARGET="-O3 -g $(CFLAGS_FOR_TARGET)" \
1049+
CXXFLAGS_FOR_TARGET="-O3 -g $(CXXFLAGS_FOR_TARGET)"
1050+
$(MAKE) -C $(notdir $@)
1051+
$(MAKE) -C $(notdir $@) install
1052+
mkdir -p $(dir $@) && touch $@
1053+
1054+
stamps/configure-picolibc-nano: $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT) stamps/build-gcc-picolibc-stage2
1055+
rm -rf $@ stamps/build-picolibc-nano build-picolibc-nano
1056+
mkdir build-picolibc-nano
1057+
cd build-picolibc-nano && $(srcdir)/scripts/generate_picolibc_cross_file \
1058+
--triplet $(NEWLIB_TUPLE) \
1059+
--cflags "$(CFLAGS_FOR_TARGET) -msave-restore" \
1060+
> cross-$(NEWLIB_TUPLE).txt
1061+
cd build-picolibc-nano && meson setup . $(PICOLIBC_SRCDIR) \
1062+
-Dprefix=$(INSTALL_DIR)/picolibc-nano/$(NEWLIB_TUPLE) \
1063+
-Dlibdir=$(INSTALL_DIR)/picolibc-nano/$(NEWLIB_TUPLE)/lib \
1064+
-Dspecsdir=none \
1065+
$(PICOLIBC_NANO_CONFIGURE_OPTIONS)
1066+
cd build-picolibc-nano && echo "$$PICOLIBC_OBSOLETE_MATH_BLOCK" >> picolibc.h
1067+
mkdir -p $(dir $@) && touch $@
1068+
1069+
stamps/build-picolibc-nano: $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT) stamps/configure-picolibc-nano
1070+
ninja -C $(notdir $@)
1071+
ninja -C $(notdir $@) install
1072+
$(srcdir)/scripts/generate_picolibc_nano_specs \
1073+
--triplet $(NEWLIB_TUPLE) \
1074+
--nano-dir-name picolibc-nano \
1075+
> $(INSTALL_DIR)/$(NEWLIB_TUPLE)/lib/nano.specs
1076+
mkdir -p $(dir $@) && touch $@
1077+
1078+
stamps/build-gcc-picolibc-stage2-nano: ENABLED_LANGUAGES?="c,c++"
1079+
stamps/build-gcc-picolibc-stage2-nano: $(GCC_SRCDIR) $(GCC_SRC_GIT) stamps/build-picolibc-nano
1080+
rm -rf $@ $(notdir $@)
1081+
mkdir $(notdir $@)
1082+
cd $(notdir $@) && $</configure \
1083+
--target=$(NEWLIB_TUPLE) \
1084+
$(CONFIGURE_HOST) \
1085+
--prefix=$(INSTALL_DIR)/picolibc-nano \
1086+
--disable-shared \
1087+
--disable-threads \
1088+
--enable-languages=$(ENABLED_LANGUAGES) \
1089+
--with-pkgversion="$(GCCPKGVER)" \
1090+
@with_system_zlib@ \
1091+
--enable-tls \
1092+
--with-newlib \
1093+
--with-headers=$(INSTALL_DIR)/picolibc-nano/$(NEWLIB_TUPLE)/include \
1094+
--disable-libmudflap \
1095+
--disable-libssp \
1096+
--disable-libquadmath \
1097+
--disable-libgomp \
1098+
--disable-nls \
1099+
--disable-tm-clone-registry \
1100+
--src=$(gccsrcdir) \
1101+
--enable-target-optspace \
1102+
$(GCC_CHECKING_FLAGS) \
1103+
$(GCC_MULTILIB_FLAGS) \
1104+
$(WITH_ABI) \
1105+
$(WITH_ARCH) \
1106+
$(WITH_TUNE) \
1107+
$(WITH_ISA_SPEC) \
1108+
$(GCC_EXTRA_CONFIGURE_FLAGS) \
1109+
CFLAGS_FOR_TARGET="-g $(CFLAGS_FOR_TARGET)" \
1110+
CXXFLAGS_FOR_TARGET="-g $(CXXFLAGS_FOR_TARGET)"
1111+
$(MAKE) -C $(notdir $@) all-target-libgcc all-target-libstdc++-v3
1112+
$(MAKE) -C $(notdir $@) install-target-libgcc install-target-libstdc++-v3
1113+
mkdir -p $(dir $@) && touch $@
1114+
1115+
stamps/configure-picolibc-perf-test: stamps/build-gcc-picolibc-stage2 $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT)
1116+
rm -rf $@ stamps/build-picolibc-perf-test build-picolibc-perf-test
1117+
mkdir build-picolibc-perf-test
1118+
cd build-picolibc-perf-test && $(srcdir)/scripts/generate_picolibc_cross_file \
1119+
--triplet $(NEWLIB_TUPLE) \
1120+
--cflags "$(CFLAGS_FOR_TARGET)" \
1121+
--simulator "$(SIM)" \
1122+
> cross-$(NEWLIB_TUPLE).txt
1123+
cd build-picolibc-perf-test && meson setup . $(PICOLIBC_SRCDIR) \
1124+
-Dprefix=$(INSTALL_DIR)/$(NEWLIB_TUPLE) \
1125+
-Dlibdir=$(INSTALL_DIR)/$(NEWLIB_TUPLE)/lib \
1126+
-Dspecsdir=$(INSTALL_DIR)/$(NEWLIB_TUPLE)/lib \
1127+
-Dtests=true \
1128+
$(PICOLIBC_PERF_CONFIGURE_OPTIONS)
1129+
cd build-picolibc-perf-test && echo "$$PICOLIBC_OBSOLETE_MATH_BLOCK" >> picolibc.h
1130+
mkdir -p $(dir $@) && touch $@
1131+
1132+
stamps/build-picolibc-perf-test: stamps/configure-picolibc-perf-test
1133+
ninja -C $(notdir $@)
1134+
mkdir -p $(dir $@) && touch $@
1135+
1136+
stamps/check-libc-picolibc-perf: stamps/build-picolibc-perf-test $(SIM_STAMP)
1137+
ninja -C build-picolibc-perf-test test
1138+
date > $@
1139+
1140+
stamps/configure-picolibc-nano-test: stamps/build-gcc-picolibc-stage2 $(PICOLIBC_SRCDIR) $(PICOLIBC_SRC_GIT)
1141+
rm -rf $@ stamps/build-picolibc-nano-test build-picolibc-nano-test
1142+
mkdir build-picolibc-nano-test
1143+
cd build-picolibc-nano-test && $(srcdir)/scripts/generate_picolibc_cross_file \
1144+
--triplet $(NEWLIB_TUPLE) \
1145+
--cflags "$(CFLAGS_FOR_TARGET)" \
1146+
--simulator "$(SIM)" \
1147+
> cross-$(NEWLIB_TUPLE).txt
1148+
cd build-picolibc-nano-test && meson setup . $(PICOLIBC_SRCDIR) \
1149+
-Dprefix=$(INSTALL_DIR)/picolibc-nano/$(NEWLIB_TUPLE) \
1150+
-Dlibdir=$(INSTALL_DIR)/picolibc-nano/$(NEWLIB_TUPLE)/lib \
1151+
-Dspecsdir=none \
1152+
-Dtests=true \
1153+
$(PICOLIBC_NANO_CONFIGURE_OPTIONS)
1154+
cd build-picolibc-nano-test && echo "$$PICOLIBC_OBSOLETE_MATH_BLOCK" >> picolibc.h
1155+
mkdir -p $(dir $@) && touch $@
1156+
1157+
stamps/build-picolibc-nano-test: stamps/configure-picolibc-nano-test
1158+
ninja -C $(notdir $@)
1159+
mkdir -p $(dir $@) && touch $@
1160+
1161+
stamps/check-libc-picolibc-nano: stamps/build-picolibc-nano-test $(SIM_STAMP)
1162+
ninja -C build-picolibc-nano-test test
1163+
date > $@
1164+
8501165
#
8511166
# MUSL
8521167
#

0 commit comments

Comments
 (0)