From 0653eb8afde0c258c401e0b0ade565bb23919713 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Wed, 17 Jul 2019 16:26:56 +0200
Subject: [PATCH 1/9] musl: update to 1.1.23.

---
 srcpkgs/musl/patches/mo_lookup.patch          | 19 --------
 srcpkgs/musl/patches/powerpc-wchar-t.patch    | 19 --------
 .../patches/ppc64-vrregset-t-fix-layout.patch | 45 -------------------
 .../patches/ppc64-vrregset-t-vrregs-fix.patch | 29 ------------
 srcpkgs/musl/template                         |  6 +--
 5 files changed, 3 insertions(+), 115 deletions(-)
 delete mode 100644 srcpkgs/musl/patches/mo_lookup.patch
 delete mode 100644 srcpkgs/musl/patches/powerpc-wchar-t.patch
 delete mode 100644 srcpkgs/musl/patches/ppc64-vrregset-t-fix-layout.patch
 delete mode 100644 srcpkgs/musl/patches/ppc64-vrregset-t-vrregs-fix.patch

diff --git a/srcpkgs/musl/patches/mo_lookup.patch b/srcpkgs/musl/patches/mo_lookup.patch
deleted file mode 100644
index c23eaf33bc3..00000000000
--- a/srcpkgs/musl/patches/mo_lookup.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-Do not crash with a NULL pointer dereference when dcngettext()
-is called with NULL msgid[12] arguments.
-
-Fix for https://github.com/void-linux/void-packages/issues/12042
-and probably others.
-
-	--xtraeme
-
---- src/locale/__mo_lookup.c.orig	2019-06-26 09:55:36.843012674 +0200
-+++ src/locale/__mo_lookup.c	2019-06-26 09:56:11.529443955 +0200
-@@ -13,7 +13,7 @@ const char *__mo_lookup(const void *p, s
- 	uint32_t b = 0, n = swapc(mo[2], sw);
- 	uint32_t o = swapc(mo[3], sw);
- 	uint32_t t = swapc(mo[4], sw);
--	if (n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4))
-+	if (!s || n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4))
- 		return 0;
- 	o/=4;
- 	t/=4;
diff --git a/srcpkgs/musl/patches/powerpc-wchar-t.patch b/srcpkgs/musl/patches/powerpc-wchar-t.patch
deleted file mode 100644
index fb45d26f029..00000000000
--- a/srcpkgs/musl/patches/powerpc-wchar-t.patch
+++ /dev/null
@@ -1,19 +0,0 @@
-Clang defines wchar_t as int, gcc as long on the target. They have the same
-size, but are different types. i386 already has this same change, do it for
-powerpc as well.
-
---- arch/powerpc/bits/alltypes.h.in
-+++ arch/powerpc/bits/alltypes.h.in
-@@ -6,8 +6,12 @@ TYPEDEF __builtin_va_list va_list;
- TYPEDEF __builtin_va_list __isoc_va_list;
- 
- #ifndef __cplusplus
-+#ifdef __WCHAR_TYPE__
-+TYPEDEF __WCHAR_TYPE__ wchar_t;
-+#else
- TYPEDEF long wchar_t;
- #endif
-+#endif
- 
- TYPEDEF float float_t;
- TYPEDEF double double_t;
diff --git a/srcpkgs/musl/patches/ppc64-vrregset-t-fix-layout.patch b/srcpkgs/musl/patches/ppc64-vrregset-t-fix-layout.patch
deleted file mode 100644
index 5ca68a35aaf..00000000000
--- a/srcpkgs/musl/patches/ppc64-vrregset-t-fix-layout.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-commit 3c59a868956636bc8adafb1b168d090897692532
-Author: Rich Felker <dalias@aerifal.cx>
-Date:   Wed May 22 15:17:12 2019 -0400
-
-    fix vrregset_t layout and member naming on powerpc64
-    
-    the mistaken layout seems to have been adapted from 32-bit powerpc,
-    where vscr and vrsave are packed into the same 128-bit slot in a way
-    that looks like it relies on non-overlapping-ness of the value bits in
-    big endian.
-    
-    the powerpc64 port accounted for the fact that the 64-bit ABI puts
-    each in its own 128-bit slot, but ordered them incorrectly (matching
-    the bit order used on the 32-bit ABI), and failed to account for vscr
-    being padded according to endianness so that it can be accessed via
-    vector moves.
-    
-    in addition to ABI layout, our definition used different logical
-    member layout/naming from glibc, where vscr is a structure to
-    facilitate access as a 32-bit word or a 128-bit vector. the
-    inconsistency here was unintentional, so fix it.
-
-diff --git a/arch/powerpc64/bits/signal.h b/arch/powerpc64/bits/signal.h
-index 34693a68..94c7a327 100644
---- arch/powerpc64/bits/signal.h
-+++ arch/powerpc64/bits/signal.h
-@@ -17,10 +17,14 @@ typedef struct {
- 
- typedef struct {
- 	unsigned __int128 vrregs[32];
--	unsigned _pad[3];
--	unsigned vrsave;
--	unsigned vscr;
--	unsigned _pad2[3];
-+	struct {
-+#if __BIG_ENDIAN__
-+		unsigned _pad[3], vscr_word;
-+#else
-+		unsigned vscr_word, _pad[3];
-+#endif
-+	} vscr;
-+	unsigned vrsave, _pad[3];
- } vrregset_t;
- 
- typedef struct sigcontext {
diff --git a/srcpkgs/musl/patches/ppc64-vrregset-t-vrregs-fix.patch b/srcpkgs/musl/patches/ppc64-vrregset-t-vrregs-fix.patch
deleted file mode 100644
index 0d2664e6c97..00000000000
--- a/srcpkgs/musl/patches/ppc64-vrregset-t-vrregs-fix.patch
+++ /dev/null
@@ -1,29 +0,0 @@
-commit ac304227bb3ea1787d581f17d76a5f5f3abff51f
-Author: Rich Felker <dalias@aerifal.cx>
-Date:   Wed May 22 18:28:32 2019 -0400
-
-    make powerpc64 vrregset_t logical layout match expected API
-    
-    between v2 and v3 of the powerpc64 port patch, the change was made
-    from a 32x4 array of 32-bit unsigned ints for vrregs[] to a 32-element
-    array of __int128. this mismatches the API applications working with
-    mcontext_t expect from glibc, and seems to have been motivated by a
-    misinterpretation of a comment on how aarch64 did things as a
-    suggestion to do the same on powerpc64.
-
-diff --git a/arch/powerpc64/bits/signal.h b/arch/powerpc64/bits/signal.h
-index 94c7a327..2cc0604c 100644
---- arch/powerpc64/bits/signal.h
-+++ arch/powerpc64/bits/signal.h
-@@ -16,7 +16,10 @@ typedef struct {
- } fpregset_t;
- 
- typedef struct {
--	unsigned __int128 vrregs[32];
-+#ifdef __GNUC__
-+	__attribute__((__aligned__(16)))
-+#endif
-+	unsigned vrregs[32][4];
- 	struct {
- #if __BIG_ENDIAN__
- 		unsigned _pad[3], vscr_word;
diff --git a/srcpkgs/musl/template b/srcpkgs/musl/template
index 4a312725d60..5a267c59ff0 100644
--- a/srcpkgs/musl/template
+++ b/srcpkgs/musl/template
@@ -1,7 +1,7 @@
 # Template file for 'musl'.
 pkgname=musl
-version=1.1.22
-revision=4
+version=1.1.23
+revision=1
 archs="*-musl"
 build_style=gnu-configure
 configure_args="--prefix=/usr --disable-gcc-wrapper"
@@ -12,7 +12,7 @@ maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="MIT"
 homepage="http://www.musl-libc.org/"
 distfiles="http://www.musl-libc.org/releases/musl-${version}.tar.gz"
-checksum=8b0941a48d2f980fd7036cfbd24aa1d414f03d9a0652ecbd5ec5c7ff1bee29e3
+checksum=8a0feb41cef26c97dde382c014e68b9bb335c094bbc1356f6edaaf6b79bd14aa
 
 nostrip_files="libc.so"
 shlib_provides="libc.so"

From 9f42412e937e92e5ec29411194a28e18ff3179f7 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Wed, 17 Jul 2019 16:54:58 +0200
Subject: [PATCH 2/9] New package: cross-riscv64-linux-musl-0.31

---
 srcpkgs/cross-riscv64-linux-musl-libc         |   1 +
 .../files/fix-cxxflags-passing.patch          |   1 +
 .../files/invalid_tls_model.patch             |   1 +
 .../files/libgnarl-musl.patch                 |   1 +
 .../files/musl-ada.patch                      |   1 +
 .../files/non-nullness.patch                  |   1 +
 srcpkgs/cross-riscv64-linux-musl/template     | 283 ++++++++++++++++++
 7 files changed, 289 insertions(+)
 create mode 120000 srcpkgs/cross-riscv64-linux-musl-libc
 create mode 120000 srcpkgs/cross-riscv64-linux-musl/files/fix-cxxflags-passing.patch
 create mode 120000 srcpkgs/cross-riscv64-linux-musl/files/invalid_tls_model.patch
 create mode 120000 srcpkgs/cross-riscv64-linux-musl/files/libgnarl-musl.patch
 create mode 120000 srcpkgs/cross-riscv64-linux-musl/files/musl-ada.patch
 create mode 120000 srcpkgs/cross-riscv64-linux-musl/files/non-nullness.patch
 create mode 100644 srcpkgs/cross-riscv64-linux-musl/template

diff --git a/srcpkgs/cross-riscv64-linux-musl-libc b/srcpkgs/cross-riscv64-linux-musl-libc
new file mode 120000
index 00000000000..29a94c9a743
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl-libc
@@ -0,0 +1 @@
+cross-riscv64-linux-musl
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/files/fix-cxxflags-passing.patch b/srcpkgs/cross-riscv64-linux-musl/files/fix-cxxflags-passing.patch
new file mode 120000
index 00000000000..4a8c831e615
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/files/fix-cxxflags-passing.patch
@@ -0,0 +1 @@
+../../gcc/patches/fix-cxxflags-passing.patch
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/files/invalid_tls_model.patch b/srcpkgs/cross-riscv64-linux-musl/files/invalid_tls_model.patch
new file mode 120000
index 00000000000..8f276dc0538
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/files/invalid_tls_model.patch
@@ -0,0 +1 @@
+../../gcc/patches/invalid_tls_model.patch
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/files/libgnarl-musl.patch b/srcpkgs/cross-riscv64-linux-musl/files/libgnarl-musl.patch
new file mode 120000
index 00000000000..33ccc9789f9
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/files/libgnarl-musl.patch
@@ -0,0 +1 @@
+../../gcc/files/libgnarl-musl.patch
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/files/musl-ada.patch b/srcpkgs/cross-riscv64-linux-musl/files/musl-ada.patch
new file mode 120000
index 00000000000..64906d48ecb
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/files/musl-ada.patch
@@ -0,0 +1 @@
+../../gcc/patches/musl-ada.patch
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/files/non-nullness.patch b/srcpkgs/cross-riscv64-linux-musl/files/non-nullness.patch
new file mode 120000
index 00000000000..c8b653748fe
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/files/non-nullness.patch
@@ -0,0 +1 @@
+../../gcc/patches/non-nullness.patch
\ No newline at end of file
diff --git a/srcpkgs/cross-riscv64-linux-musl/template b/srcpkgs/cross-riscv64-linux-musl/template
new file mode 100644
index 00000000000..98b1d1b2956
--- /dev/null
+++ b/srcpkgs/cross-riscv64-linux-musl/template
@@ -0,0 +1,283 @@
+# Template build file for 'cross-riscv64-linux-musl'
+#
+_binutils_version=2.32
+_gcc_version=9.1.0
+_musl_version=1.1.23
+_linux_version=4.19
+
+_triplet=riscv64-linux-musl
+_sysroot="/usr/${_triplet}"
+
+pkgname=cross-${_triplet}
+version=0.31
+revision=2
+short_desc="Cross toolchain for ARM64 LE target (musl)"
+maintainer="Juan RP <xtraeme@voidlinux.org>"
+homepage="https://www.voidlinux.org/"
+license="GPL-2.0-or-later, GPL-3.0-or-later, MIT"
+distfiles="
+ ${GNU_SITE}/binutils/binutils-${_binutils_version}.tar.xz
+ ${GNU_SITE}/gcc/gcc-${_gcc_version}/gcc-${_gcc_version}.tar.xz
+ http://www.musl-libc.org/releases/musl-${_musl_version}.tar.gz
+ ${KERNEL_SITE}/kernel/v4.x/linux-${_linux_version}.tar.xz"
+checksum="0ab6c55dd86a92ed561972ba15b9b70a8b9f75557f896446c82e8b36e473ee04
+ 79a66834e96a6050d8fe78db2c3b32fb285b230b855d0a66288235bc04b327a0
+ 8a0feb41cef26c97dde382c014e68b9bb335c094bbc1356f6edaaf6b79bd14aa
+ 0c68f5655528aed4f99dae71a5b259edc93239fa899e2df79c055275c21749a1"
+
+lib32disabled=yes
+nocross=yes
+nopie=yes
+nodebug=yes
+create_wrksrc=yes
+
+archs="x86_64* ppc64le"
+hostmakedepends="flex perl python3"
+makedepends="zlib-devel gmp-devel mpfr-devel libmpc-devel isl15-devel"
+nostrip_files="libcaf_single.a libgcc.a libgcov.a libgcc_eh.a
+ libgnarl_pic.a libgnarl.a libgnat_pic.a libgnat.a"
+depends="${pkgname}-libc-${version}_${revision}"
+
+_apply_patch() {
+	local args="$1" pname="$(basename $2)"
+
+	if [ ! -f ".${pname}_done" ]; then
+		patch -N $args -i $2
+		touch .${pname}_done
+	fi
+}
+
+_binutils_build() {
+	local _args
+
+	[ -f ${wrksrc}/.binutils_build_done ] && return 0
+
+	cd ${wrksrc}
+	msg_normal "Building cross binutils bootstrap\n"
+
+	[ ! -d binutils-build ] && mkdir binutils-build
+	cd binutils-build
+	_args="--prefix=/usr"
+	_args+=" --target=${_triplet}"
+	_args+=" --with-sysroot=${_sysroot}"
+	_args+=" --disable-nls"
+	_args+=" --disable-multilib"
+	_args+=" --disable-werror"
+	_args+=" --disable-shared"
+	_args+=" --with-system-zlib"
+
+	../binutils-${_binutils_version}/configure ${_args}
+
+	make configure-host && make ${makejobs}
+	make install
+
+	touch ${wrksrc}/.binutils_build_done
+}
+
+_gcc_bootstrap() {
+	local _args
+	[ -f ${wrksrc}/.gcc_bootstrap_done ] && return 0
+
+	cd ${wrksrc}/gcc-${_gcc_version}
+	_apply_patch -p0 ${FILESDIR}/fix-cxxflags-passing.patch
+	_apply_patch -p0 ${FILESDIR}/non-nullness.patch
+	_apply_patch -p0 ${FILESDIR}/musl-ada.patch
+	_apply_patch -p1 ${FILESDIR}/libgnarl-musl.patch
+	_apply_patch -p0 ${FILESDIR}/invalid_tls_model.patch
+
+	msg_normal "Building cross gcc bootstrap\n"
+
+	[ ! -d ../gcc-bootstrap ] && mkdir ../gcc-bootstrap
+	cd ../gcc-bootstrap
+
+	_args="--prefix=/usr"
+	_args+=" --target=${_triplet}"
+	_args+=" --with-sysroot=${_sysroot}"
+	_args+=" --with-newlib"
+	_args+=" --enable-languages=c"
+	_args+=" --with-newlib"
+	_args+=" --disable-libssp"
+	_args+=" --disable-nls"
+	_args+=" --disable-libquadmath"
+	_args+=" --disable-threads"
+	_args+=" --disable-decimal-float"
+	_args+=" --disable-shared"
+	_args+=" --disable-libmudflap"
+	_args+=" --disable-libgomp"
+	_args+=" --disable-libatomic"
+	_args+=" --disable-symvers"
+	_args+=" libat_cv_have_ifunc=no"
+
+	CFLAGS="-O0 -g0" CXXFLAGS="-O0 -g0" \
+		../gcc-${_gcc_version}/configure ${_args}
+
+	make ${makejobs}
+	make install
+
+	touch ${wrksrc}/.gcc_bootstrap_done
+}
+
+_linux_headers() {
+	[ -f ${wrksrc}/.linux_build_done ] && return 0
+
+	cd ${wrksrc}
+	msg_normal "Building Linux API headers\n"
+
+	cd linux-${_linux_version}
+
+	for f in ${XBPS_SRCPKGDIR}/kernel-libc-headers/patches/*.patch; do
+		_apply_patch -p0 $f
+	done
+
+	make ARCH=arm64 headers_check
+	make ARCH=arm64 INSTALL_HDR_PATH=${_sysroot}/usr headers_install
+
+	touch ${wrksrc}/.linux_build_done
+}
+
+_musl_build() {
+	[ -f ${wrksrc}/.musl_build_done ] && return 0
+
+	cd ${wrksrc}/musl-${_musl_version}
+	msg_normal "Building cross musl libc\n"
+
+	CC="${_triplet}-gcc" LD="${_triplet}-ld" AR="${_triplet}-ar" \
+		AS="${_triplet}-as" RANLIB="${_triplet}-ranlib" \
+		CFLAGS="-Os -pipe ${_archflags}" \
+		./configure --prefix=/usr
+
+	make ${makejobs}
+	make DESTDIR=${_sysroot} install
+
+	touch ${wrksrc}/.musl_build_done
+}
+
+_gcc_build() {
+	local _args
+
+	[ -f ${wrksrc}/.gcc_build_done ] && return 0
+
+	cd ${wrksrc}
+	msg_normal "Building cross gcc final\n"
+
+	[ ! -d gcc-build ] && mkdir gcc-build
+	cd gcc-build
+
+	_args="--prefix=/usr"
+	_args+=" --libexecdir=/usr/lib"
+	_args+=" --target=${_triplet}"
+	_args+=" --with-sysroot=${_sysroot}"
+	_args+=" --enable-languages=c,ada,c++,fortran,lto"
+	_args+=" --enable-libada"
+	_args+=" --enable-lto"
+	_args+=" --enable-default-pie"
+	_args+=" --enable-default-ssp"
+	_args+=" --disable-libsanitizer"
+	_args+=" --disable-multilib"
+	_args+=" --disable-nls"
+	_args+=" --disable-libquadmath"
+	_args+=" --disable-libmudflap"
+	_args+=" --enable-shared"
+	_args+=" --disable-symvers"
+	_args+=" libat_cv_have_ifunc=no"
+
+	../gcc-${_gcc_version}/configure ${_args}
+
+	make ${makejobs}
+
+	touch ${wrksrc}/.gcc_build_done
+}
+
+do_build() {
+	# Ensure we use sane environment
+	unset CC CXX CPP LD AS AR RANLIB OBJDUMP READELF NM
+	unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
+	export CFLAGS="-Os -pipe" CXXFLAGS="-Os -pipe"
+
+	for f in include lib libexec bin sbin; do
+		if [ ! -d ${_sysroot}/usr/${f} ]; then
+			mkdir -p ${_sysroot}/usr/${f}
+		fi
+		if [ ! -h ${_sysroot}/${f} ]; then
+			ln -sfr ${_sysroot}/usr/${f} ${_sysroot}/${f}
+		fi
+	done
+
+	_binutils_build
+	_gcc_bootstrap
+	_linux_headers
+	_musl_build
+	_gcc_build
+}
+
+do_install() {
+	for f in include libexec bin sbin; do
+		if [ ! -d ${DESTDIR}/${_sysroot}/usr/${f} ]; then
+			mkdir -p ${DESTDIR}/${_sysroot}/usr/${f}
+		fi
+		if [ ! -h ${DESTDIR}/${_sysroot}/${f} ]; then
+			ln -sfr ${DESTDIR}/${_sysroot}/usr/${f} \
+				${DESTDIR}/${_sysroot}/${f}
+		fi
+	done
+	mkdir -p ${DESTDIR}/${_sysroot}/usr/lib
+	ln -sf lib ${DESTDIR}/${_sysroot}/usr/lib64
+	ln -sf usr/lib ${DESTDIR}/${_sysroot}/lib64
+	ln -sf usr/lib ${DESTDIR}/${_sysroot}/lib
+
+	# install linux API headers
+	cd ${wrksrc}/linux-${_linux_version}
+	make ARCH=arm64 INSTALL_HDR_PATH=${DESTDIR}/${_sysroot}/usr headers_install
+	rm -f $(find ${DESTDIR}/${_sysroot}/usr/include -name .install -or -name ..install.cmd)
+	rm -rf ${DESTDIR}/${_sysroot}/usr/include/drm
+
+	# install cross binutils
+	cd ${wrksrc}/binutils-build
+	make DESTDIR=${DESTDIR} install
+
+	# install cross gcc
+	cd ${wrksrc}/gcc-build
+	make DESTDIR=${DESTDIR} install
+
+	# move libcc1.so* to the sysroot
+	mv ${DESTDIR}/usr/lib/libcc1.so* ${DESTDIR}/${_sysroot}/usr/lib
+
+	# install musl libc for target
+	cd ${wrksrc}/musl-${_musl_version}
+	make DESTDIR=${DESTDIR}/${_sysroot} install
+
+	# Remove useless headers.
+	rm -rf ${DESTDIR}/usr/lib/gcc/${_triplet}/*/include-fixed/ \
+		${DESTDIR}/usr/lib/gcc/${_triplet}/*/include/stddef.h
+
+	# Make ld-musl.so symlinks relative.
+	ln -sf libc.so ${DESTDIR}/${_sysroot}/usr/lib/ld-musl-riscv64.so.1
+
+	# symlinks for gnarl and gnat shared libraries
+	_majorver=${_gcc_version%.*.*}
+	_adalib=usr/lib/gcc/${_triplet}/${_gcc_version}/adalib
+	mv -v ${DESTDIR}/${_adalib}/libgnarl-${_majorver}.so ${DESTDIR}/${_sysroot}/usr/lib
+	mv -v ${DESTDIR}/${_adalib}/libgnat-${_majorver}.so ${DESTDIR}/${_sysroot}/usr/lib
+	ln -svf libgnarl-${_majorver}.so libgnarl.so
+	ln -svf libgnat-${_majorver}.so libgnat.so
+	rm -vf ${DESTDIR}/${_adalib}/libgna{rl,t}.so
+
+	# Remove unnecessary stuff
+	rm -f ${DESTDIR}/usr/lib*/libiberty.a
+	rm -rf ${DESTDIR}/usr/share
+	rm -rf ${DESTDIR}/${_sysroot}/{etc,var}
+	rm -rf ${DESTDIR}/${_sysroot}/usr/{sbin,share,libexec}
+	rm -f ${DESTDIR}/${_sysroot}/libexec
+	rm -f ${DESTDIR}/${_sysroot}/lib/*.py
+	rm -f ${DESTDIR}/${_sysroot}/sbin
+}
+
+cross-riscv64-linux-musl-libc_package() {
+	short_desc+=" - libc files"
+	nostrip=yes
+	noshlibprovides=yes
+	noverifyrdeps=yes
+	pkg_install() {
+		vmove ${_sysroot}
+	}
+}

From cc1e54709625a7c628c85035b524cb72ea383c98 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Wed, 17 Jul 2019 16:55:24 +0200
Subject: [PATCH 3/9] add riscv64 profiles

---
 common/build-profiles/riscv64-musl.sh |  5 +++++
 common/cross-profiles/riscv64-musl.sh | 10 ++++++++++
 2 files changed, 15 insertions(+)
 create mode 100644 common/build-profiles/riscv64-musl.sh
 create mode 100644 common/cross-profiles/riscv64-musl.sh

diff --git a/common/build-profiles/riscv64-musl.sh b/common/build-profiles/riscv64-musl.sh
new file mode 100644
index 00000000000..6810f63f353
--- /dev/null
+++ b/common/build-profiles/riscv64-musl.sh
@@ -0,0 +1,5 @@
+XBPS_TARGET_CFLAGS="-march=rv64imafdc"
+XBPS_TARGET_CXXFLAGS="$XBPS_TARGET_CFLAGS"
+XBPS_TARGET_FFLAGS=""
+XBPS_TRIPLET="riscv64-unknown-linux-musl"
+XBPS_RUST_TARGET="$XBPS_TRIPLET"
diff --git a/common/cross-profiles/riscv64-musl.sh b/common/cross-profiles/riscv64-musl.sh
new file mode 100644
index 00000000000..9b9d8934bdd
--- /dev/null
+++ b/common/cross-profiles/riscv64-musl.sh
@@ -0,0 +1,10 @@
+# Cross build profile for riscv64 and Musl libc.
+
+XBPS_TARGET_MACHINE="riscv64-musl"
+XBPS_TARGET_QEMU_MACHINE="riscv64"
+XBPS_CROSS_TRIPLET="riscv64-linux-musl"
+XBPS_CROSS_CFLAGS="-march=rv64imafdc"
+XBPS_CROSS_CXXFLAGS="$XBPS_CROSS_CFLAGS"
+XBPS_CROSS_FFLAGS=""
+XBPS_CROSS_RUSTFLAGS="--sysroot=${XBPS_CROSS_BASE}/usr"
+XBPS_CROSS_RUST_TARGET="riscv64-unknown-linux-musl"

From 61675567ac8c0dad0fc84c15aca65a3b830b8bf1 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Thu, 18 Jul 2019 11:07:04 +0200
Subject: [PATCH 4/9] [WIP] add configure/autoconf_cache/riscv64-linux

---
 common/environment/configure/autoconf_cache/riscv64-linux | 5 +++++
 common/environment/configure/gnu-configure-args.sh        | 5 +++++
 2 files changed, 10 insertions(+)
 create mode 100644 common/environment/configure/autoconf_cache/riscv64-linux

diff --git a/common/environment/configure/autoconf_cache/riscv64-linux b/common/environment/configure/autoconf_cache/riscv64-linux
new file mode 100644
index 00000000000..2b45e5aaa81
--- /dev/null
+++ b/common/environment/configure/autoconf_cache/riscv64-linux
@@ -0,0 +1,5 @@
+# XXX all just guesswork!
+
+glib_cv_stack_grows=${glib_cv_stack_grows=no}
+glib_cv_uscore=${glib_cv_uscore=no}
+
diff --git a/common/environment/configure/gnu-configure-args.sh b/common/environment/configure/gnu-configure-args.sh
index ea82c1cc17e..e5ca2a45b74 100644
--- a/common/environment/configure/gnu-configure-args.sh
+++ b/common/environment/configure/gnu-configure-args.sh
@@ -109,6 +109,11 @@ case "$XBPS_TARGET_MACHINE" in
 		. ${_AUTOCONFCACHEDIR}/powerpc64-linux
 		;;
 
+	riscv*)
+		. ${_AUTOCONFCACHEDIR}/endian-little
+		. ${_AUTOCONFCACHEDIR}/riscv64-linux
+		;;
+
 	*) ;;
 esac
 

From c662f32118f5888def8c25a112a35be7cbca2aa6 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Thu, 18 Jul 2019 11:30:56 +0200
Subject: [PATCH 5/9] gcc: add riscv.

---
 srcpkgs/gcc/template | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/srcpkgs/gcc/template b/srcpkgs/gcc/template
index bebcba9ac3d..0c81a33d820 100644
--- a/srcpkgs/gcc/template
+++ b/srcpkgs/gcc/template
@@ -106,6 +106,7 @@ case "$XBPS_TARGET_MACHINE" in
 	mipshf-musl) _triplet="mips-linux-muslhf";;
 	mipsel-musl) _triplet="mipsel-linux-musl";;
 	mipselhf-musl) _triplet="mipsel-linux-muslhf";;
+	riscv64-musl) _triplet="riscv64-linux-musl";;
 esac
 case "$XBPS_TARGET_MACHINE" in
 	*-musl)	 depends+=" musl-devel";;
@@ -124,6 +125,7 @@ case "$XBPS_TARGET_MACHINE" in
 esac
 case "$XBPS_TARGET_MACHINE" in
 	mips*) ;;
+	riscv*) ;;
 	x86_64*|i686) subpackages+=" libitm libitm-devel";;
 	*) subpackages+=" libitm libitm-devel";;
 esac

From 29ee92afd2492794920606367b00360ddb470c3c Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Thu, 18 Jul 2019 12:23:44 +0200
Subject: [PATCH 6/9] kernel-libc-headers: add riscv.

---
 srcpkgs/kernel-libc-headers/template | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/kernel-libc-headers/template b/srcpkgs/kernel-libc-headers/template
index 2cae8e99e30..cca823f53c4 100644
--- a/srcpkgs/kernel-libc-headers/template
+++ b/srcpkgs/kernel-libc-headers/template
@@ -1,7 +1,7 @@
 # Template file for 'kernel-libc-headers'
 pkgname=kernel-libc-headers
 version=4.19.0
-revision=2
+revision=3
 bootstrap=yes
 nostrip=yes
 noverifyrdeps=yes
@@ -23,6 +23,7 @@ case "$XBPS_TARGET_MACHINE" in
 	aarch64*) _arch="arm64";;
 	mips*) _arch="mips";;
 	ppc*) _arch="powerpc";;
+	riscv*) _arch="riscv";;
 	*) msg_error "$pkgname: unknown architecture.\n";;
 esac
 

From f6fbac99b7f818bf0e57032c0503b00b035d628a Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Wed, 17 Jul 2019 17:06:00 +0200
Subject: [PATCH 7/9] pcre: disable JIT on riscv

---
 srcpkgs/pcre/template | 1 +
 1 file changed, 1 insertion(+)

diff --git a/srcpkgs/pcre/template b/srcpkgs/pcre/template
index 4991f0a6df6..867f8cc41b4 100644
--- a/srcpkgs/pcre/template
+++ b/srcpkgs/pcre/template
@@ -16,6 +16,7 @@ checksum=91e762520003013834ac1adb4a938d53b22a216341c061b0cf05603b290faf6b
 
 case "$XBPS_TARGET_MACHINE" in
 	mips*) ;; # Without stack for recursion the mips builds fail
+	riscv*) configure_args+=" --disable-jit" ;;
 	*) configure_args+=" --disable-stack-for-recursion" ;;
 esac
 

From 00c6d1adf1a49c7f8c4339989653fb9b08ed7389 Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Thu, 18 Jul 2019 10:22:24 +0200
Subject: [PATCH 8/9] [WIP] libffi: update to 3.3.

Using rc0.
---
 common/shlibs                                 |  2 +-
 srcpkgs/libffi/patches/fix-aarch64.patch      | 15 ----
 .../libffi/patches/fix_includedir_path.diff   | 20 -----
 .../patches/libffi-fix-define-for-musl.patch  | 13 ---
 srcpkgs/libffi/patches/libffi-pr401.patch     | 33 --------
 .../patches/libffi-race-condition.patch       | 38 ---------
 srcpkgs/libffi/patches/mips.sgidefs_h.patch   | 11 ---
 srcpkgs/libffi/patches/mips.softfloat.patch   | 83 -------------------
 srcpkgs/libffi/patches/mipsen-r6.diff         | 17 ----
 srcpkgs/libffi/template                       |  9 +-
 10 files changed, 6 insertions(+), 235 deletions(-)
 delete mode 100644 srcpkgs/libffi/patches/fix-aarch64.patch
 delete mode 100644 srcpkgs/libffi/patches/fix_includedir_path.diff
 delete mode 100644 srcpkgs/libffi/patches/libffi-fix-define-for-musl.patch
 delete mode 100644 srcpkgs/libffi/patches/libffi-pr401.patch
 delete mode 100644 srcpkgs/libffi/patches/libffi-race-condition.patch
 delete mode 100644 srcpkgs/libffi/patches/mips.sgidefs_h.patch
 delete mode 100644 srcpkgs/libffi/patches/mips.softfloat.patch
 delete mode 100644 srcpkgs/libffi/patches/mipsen-r6.diff

diff --git a/common/shlibs b/common/shlibs
index 2f146bbfa9d..e965cab56e6 100644
--- a/common/shlibs
+++ b/common/shlibs
@@ -195,7 +195,7 @@ libtextstyle.so.0 gettext-libs-0.20.1_1
 libattr.so.1 attr-2.4.43_1
 libacl.so.1 acl-2.2.47_1
 libpython2.7.so.1.0 python-2.7_1
-libffi.so.6 libffi-3.1_1
+libffi.so.7 libffi-3.3_1
 libffcall.so.0 ffcall-2.1_1
 libavcall.so.1 ffcall-2.1_1
 libtrampoline.so.1 ffcall-2.1_1
diff --git a/srcpkgs/libffi/patches/fix-aarch64.patch b/srcpkgs/libffi/patches/fix-aarch64.patch
deleted file mode 100644
index a0668a4a0f9..00000000000
--- a/srcpkgs/libffi/patches/fix-aarch64.patch
+++ /dev/null
@@ -1,15 +0,0 @@
-Description: fixes issue with aarch64
-Author: Debian packagers
-Origin: libffi_3.2.1-9.debian.tar.xz
-
---- src/aarch64/ffi.c
-+++ src/aarch64/ffi.c
-@@ -731,7 +731,7 @@
- 	      state.ngrn = N_X_ARG_REG;
- 
- 	      memcpy (allocate_to_stack (&state, stack, ty->alignment,
--					 ty->size), ecif->avalue + i, ty->size);
-+					 ty->size), ecif->avalue[i], ty->size);
- 	    }
- 	  break;
- 
diff --git a/srcpkgs/libffi/patches/fix_includedir_path.diff b/srcpkgs/libffi/patches/fix_includedir_path.diff
deleted file mode 100644
index 598edef9066..00000000000
--- a/srcpkgs/libffi/patches/fix_includedir_path.diff
+++ /dev/null
@@ -1,20 +0,0 @@
---- include/Makefile.in.orig	2010-05-11 19:03:20.645903854 +0200
-+++ include/Makefile.in	2010-05-11 19:04:02.930565181 +0200
-@@ -44,7 +44,7 @@ am__aclocal_m4_deps = $(top_srcdir)/acin
- am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
- 	$(ACLOCAL_M4)
- mkinstalldirs = $(install_sh) -d
--CONFIG_HEADER = $(top_builddir)/fficonfig.h
-+CONFIG_HEADER = $(builddir)/fficonfig.h
- CONFIG_CLEAN_FILES = ffi.h ffitarget.h
- CONFIG_CLEAN_VPATH_FILES =
- SOURCES =
-@@ -203,7 +203,7 @@ top_srcdir = @top_srcdir@
- AUTOMAKE_OPTIONS = foreign
- DISTCLEANFILES = ffitarget.h
- EXTRA_DIST = ffi.h.in ffi_common.h
--includesdir = $(libdir)/@PACKAGE_NAME@-@PACKAGE_VERSION@/include
-+includesdir = @prefix@/include
- nodist_includes_HEADERS = ffi.h ffitarget.h
- all: all-am
- 
diff --git a/srcpkgs/libffi/patches/libffi-fix-define-for-musl.patch b/srcpkgs/libffi/patches/libffi-fix-define-for-musl.patch
deleted file mode 100644
index ab8f9486cdf..00000000000
--- a/srcpkgs/libffi/patches/libffi-fix-define-for-musl.patch
+++ /dev/null
@@ -1,13 +0,0 @@
-http://bugs.alpinelinux.org/issues/4275
-
---- src/closures.c.orig
-+++ src/closures.c
-@@ -34,7 +34,7 @@
- #include <ffi_common.h>
-
- #if !FFI_MMAP_EXEC_WRIT && !FFI_EXEC_TRAMPOLINE_TABLE
--# if __gnu_linux__ && !defined(__ANDROID__)
-+# if __linux__ && !defined(__ANDROID__)
- /* This macro indicates it may be forbidden to map anonymous memory
-    with both write and execute permission.  Code compiled when this
-    option is defined will attempt to map such pages once, but if it
diff --git a/srcpkgs/libffi/patches/libffi-pr401.patch b/srcpkgs/libffi/patches/libffi-pr401.patch
deleted file mode 100644
index 18baa2ca39c..00000000000
--- a/srcpkgs/libffi/patches/libffi-pr401.patch
+++ /dev/null
@@ -1,33 +0,0 @@
-Description: fixes issue with aarch64
-Author: Anthony Green <green@moxielogic.com>
-Origin: libffi_3.2.1-9.debian.tar.xz
-
-https://github.com/libffi/libffi/pull/401
-
---- src/mips/ffi.c
-+++ src/mips/ffi.c
-@@ -715,7 +715,11 @@ ffi_prep_closure_loc (ffi_closure *closure,
-   /* lui  $12,high(codeloc) */
-   tramp[2] = 0x3c0c0000 | ((unsigned)codeloc >> 16);
-   /* jr   $25          */
-+#if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
-   tramp[3] = 0x03200008;
-+#else
-+  tramp[3] = 0x03200009;
-+#endif
-   /* ori  $12,low(codeloc)  */
-   tramp[4] = 0x358c0000 | ((unsigned)codeloc & 0xffff);
- #else
-@@ -743,7 +747,11 @@ ffi_prep_closure_loc (ffi_closure *closure,
-   /* ori  $25,low(fn)  */
-   tramp[10] = 0x37390000 | ((unsigned long)fn  & 0xffff);
-   /* jr   $25          */
-+#if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
-   tramp[11] = 0x03200008;
-+#else
-+  tramp[11] = 0x03200009;
-+#endif
-   /* ori  $12,low(codeloc)  */
-   tramp[12] = 0x358c0000 | ((unsigned long)codeloc & 0xffff);
- 
-
diff --git a/srcpkgs/libffi/patches/libffi-race-condition.patch b/srcpkgs/libffi/patches/libffi-race-condition.patch
deleted file mode 100644
index 4d401ebcffa..00000000000
--- a/srcpkgs/libffi/patches/libffi-race-condition.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-Description: fixes race condition
-Author: Stefan Bühler <buehler@cert.uni-stuttgart.de>
-Origin: libffi_3.2.1-9.debian.tar.xz
-
-From 48d2e46528fb6e621d95a7fa194069fd136b712d Mon Sep 17 00:00:00 2001
-From: =?UTF-8?q?Stefan=20B=C3=BChler?= <buehler@cert.uni-stuttgart.de>
-Date: Wed, 7 Sep 2016 15:49:48 +0200
-Subject: [PATCH 1/2] dlmmap_locked always needs locking as it always modifies
- execsize
-
----
- src/closures.c | 13 ++++---------
- 1 file changed, 4 insertions(+), 9 deletions(-)
-
---- src/closures.c
-+++ src/closures.c
-@@ -568,16 +568,11 @@
- 	 MREMAP_DUP and prot at this point.  */
-     }
- 
--  if (execsize == 0 || execfd == -1)
--    {
--      pthread_mutex_lock (&open_temp_exec_file_mutex);
--      ptr = dlmmap_locked (start, length, prot, flags, offset);
--      pthread_mutex_unlock (&open_temp_exec_file_mutex);
-+  pthread_mutex_lock (&open_temp_exec_file_mutex);
-+  ptr = dlmmap_locked (start, length, prot, flags, offset);
-+  pthread_mutex_unlock (&open_temp_exec_file_mutex);
- 
--      return ptr;
--    }
--
--  return dlmmap_locked (start, length, prot, flags, offset);
-+  return ptr;
- }
- 
- /* Release memory at the given address, as well as the corresponding
-
diff --git a/srcpkgs/libffi/patches/mips.sgidefs_h.patch b/srcpkgs/libffi/patches/mips.sgidefs_h.patch
deleted file mode 100644
index b6324c86658..00000000000
--- a/srcpkgs/libffi/patches/mips.sgidefs_h.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- src/mips/ffitarget.h	2014-11-08 13:47:24.000000000 +0100
-+++ src/mips/ffitarget.h	2017-11-09 16:51:11.866848444 +0100
-@@ -42,7 +42,7 @@
- #define _MIPS_SIM_NABI32	2
- #define _MIPS_SIM_ABI64		3
- #elif !defined(__OpenBSD__)
--# include <sgidefs.h>
-+# include <asm/sgidefs.h>
- #endif
- 
- #  ifndef _ABIN32
diff --git a/srcpkgs/libffi/patches/mips.softfloat.patch b/srcpkgs/libffi/patches/mips.softfloat.patch
deleted file mode 100644
index e06fbbd0cc4..00000000000
--- a/srcpkgs/libffi/patches/mips.softfloat.patch
+++ /dev/null
@@ -1,83 +0,0 @@
-Taken from the Optware fork Optware-ng:
-alllexx88 libffi: mips: fix build for soft-float
-https://raw.githubusercontent.com/Optware/Optware-ng/master/sources/libffi/mips.softfloat.patch
-
---- src/mips/o32.S.orig	2014-11-08 14:47:24.000000000 +0200
-+++ src/mips/o32.S	2015-04-16 12:03:11.302116104 +0300
-@@ -82,13 +82,16 @@
- 		
- 	ADDU	$sp, 4 * FFI_SIZEOF_ARG		# adjust $sp to new args
- 
-+#ifndef __mips_soft_float
- 	bnez	t0, pass_d			# make it quick for int
-+#endif
- 	REG_L	a0, 0*FFI_SIZEOF_ARG($sp)	# just go ahead and load the
- 	REG_L	a1, 1*FFI_SIZEOF_ARG($sp)	# four regs.
- 	REG_L	a2, 2*FFI_SIZEOF_ARG($sp)
- 	REG_L	a3, 3*FFI_SIZEOF_ARG($sp)
- 	b	call_it
- 
-+#ifndef __mips_soft_float
- pass_d:
- 	bne	t0, FFI_ARGS_D, pass_f
- 	l.d	$f12, 0*FFI_SIZEOF_ARG($sp)	# load $fp regs from args
-@@ -130,6 +133,7 @@
-  #	bne	t0, FFI_ARGS_F_D, call_it
- 	l.s	$f12, 0*FFI_SIZEOF_ARG($sp)	# load $fp regs from args
- 	l.d	$f14, 2*FFI_SIZEOF_ARG($sp)	# passing double and float
-+#endif
- 
- call_it:	
- 	# Load the function pointer
-@@ -158,14 +162,23 @@
- 	bne     t2, FFI_TYPE_FLOAT, retdouble
- 	jalr	t9
- 	REG_L	t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
-+#ifndef __mips_soft_float
- 	s.s	$f0, 0(t0)
-+#else
-+	REG_S	v0, 0(t0)
-+#endif
- 	b	epilogue
- 
- retdouble:	
- 	bne	t2, FFI_TYPE_DOUBLE, noretval
- 	jalr	t9
- 	REG_L	t0, SIZEOF_FRAME + 4*FFI_SIZEOF_ARG($fp)
-+#ifndef __mips_soft_float
- 	s.d	$f0, 0(t0)
-+#else
-+	REG_S	v1, 4(t0)
-+	REG_S	v0, 0(t0)
-+#endif
- 	b	epilogue
- 	
- noretval:	
-@@ -261,9 +274,11 @@
- 	li	$13, 1		# FFI_O32
- 	bne	$16, $13, 1f	# Skip fp save if FFI_O32_SOFT_FLOAT
- 	
-+#ifndef __mips_soft_float
- 	# Store all possible float/double registers.
- 	s.d	$f12, FA_0_0_OFF2($fp)
- 	s.d	$f14, FA_1_0_OFF2($fp)
-+#endif
- 1:	
- 	# Call ffi_closure_mips_inner_O32 to do the work.
- 	la	t9, ffi_closure_mips_inner_O32
-@@ -281,6 +296,7 @@
- 	li	$13, 1		# FFI_O32
- 	bne	$16, $13, 1f	# Skip fp restore if FFI_O32_SOFT_FLOAT
- 
-+#ifndef __mips_soft_float
- 	li	$9, FFI_TYPE_FLOAT
- 	l.s	$f0, V0_OFF2($fp)
- 	beq	$8, $9, closure_done
-@@ -288,6 +304,7 @@
- 	li	$9, FFI_TYPE_DOUBLE
- 	l.d	$f0, V0_OFF2($fp)
- 	beq	$8, $9, closure_done
-+#endif
- 1:	
- 	REG_L	$3, V1_OFF2($fp)
- 	REG_L	$2, V0_OFF2($fp)
diff --git a/srcpkgs/libffi/patches/mipsen-r6.diff b/srcpkgs/libffi/patches/mipsen-r6.diff
deleted file mode 100644
index 3dc4620bad0..00000000000
--- a/srcpkgs/libffi/patches/mipsen-r6.diff
+++ /dev/null
@@ -1,17 +0,0 @@
-Description: fixes issue with aarch64
-Author: Debian packagers
-Origin: libffi_3.2.1-9.debian.tar.xz
-
---- src/mips/n32.S
-+++ src/mips/n32.S
-@@ -47,7 +47,9 @@
- #ifdef __GNUC__
- 	.abicalls
- #endif
-+#if !defined(__mips_isa_rev) || (__mips_isa_rev<6)
- 	.set mips4
-+#endif
- 	.text
- 	.align	2
- 	.globl	ffi_call_N32
-
diff --git a/srcpkgs/libffi/template b/srcpkgs/libffi/template
index 9b3e04e8f42..b0dde3fbc13 100644
--- a/srcpkgs/libffi/template
+++ b/srcpkgs/libffi/template
@@ -1,7 +1,7 @@
 # Template file for 'libffi'
 pkgname=libffi
-version=3.2.1
-revision=6
+version=3.3
+revision=1
 build_style=gnu-configure
 configure_args="--includedir=/usr/include --with-pic"
 checkdepends="dejagnu"
@@ -9,8 +9,9 @@ short_desc="Library supporting Foreign Function Interfaces"
 maintainer="Juan RP <xtraeme@voidlinux.org>"
 license="MIT"
 homepage="http://sourceware.org/libffi"
-distfiles="ftp://sourceware.org/pub/$pkgname/$pkgname-$version.tar.gz"
-checksum=d06ebb8e1d9a22d19e38d63fdb83954253f39bedc5d46232a05645685722ca37
+distfiles="https://github.com/libffi/libffi/releases/download/v3.3-rc0/libffi-3.3-rc0.tar.gz"
+wrksrc="libffi-3.3-rc0"
+checksum=403d67aabf1c05157855ea2b1d9950263fb6316536c8c333f5b9ab1eb2f20ecf
 
 pre_install() {
 	vmkdir usr/lib

From ce4dd41755721a2fef1c46a1cd75ae6f44cb87ec Mon Sep 17 00:00:00 2001
From: Leah Neukirchen <leah@vuxu.org>
Date: Thu, 18 Jul 2019 11:30:41 +0200
Subject: [PATCH 9/9] gdb: disable gdbserver on riscv (nyi)

---
 srcpkgs/gdb/template | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/srcpkgs/gdb/template b/srcpkgs/gdb/template
index eb0e76dbcb4..0364a6ba6c6 100644
--- a/srcpkgs/gdb/template
+++ b/srcpkgs/gdb/template
@@ -27,7 +27,10 @@ fi
 build_options="gdbserver static python"
 desc_option_gdbserver="Enable support for building GDB server"
 # Enable gdbserver if !static.
-build_options_default="gdbserver python"
+case "$XBPS_TARGET_MACHINE" in
+	riscv*) build_options_default="python";;
+	*) build_options_default="gdbserver python";;
+esac
 # Both options cannot be enabled at the same time
 vopt_conflict gdbserver static
 
