From 11df93a1dd1bc281e07f2315565f2f3236911bd0 Mon Sep 17 00:00:00 2001 From: Djordje Todorovic Date: Wed, 14 Aug 2024 13:54:06 +0200 Subject: [PATCH 1/4] configure: Add --with-endian option --- Makefile.in | 6 +++++- configure | 16 ++++++++++++++++ configure.ac | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index e6fc8ec8224..2bfbf698f37 100644 --- a/Makefile.in +++ b/Makefile.in @@ -84,7 +84,11 @@ ifneq ($(XLEN),32) XLEN := 64 endif -make_tuple = riscv$(1)-unknown-$(2) +ifeq (@endian@,big) +ENDIAN_POSTFIX := be +endif + +make_tuple = riscv$(1)$(ENDIAN_POSTFIX)-unknown-$(2) LINUX_TUPLE ?= $(call make_tuple,$(XLEN),linux-gnu) NEWLIB_TUPLE ?= $(call make_tuple,$(XLEN),elf) MUSL_TUPLE ?= $(call make_tuple,$(XLEN),linux-musl) diff --git a/configure b/configure index 2fc589e7db6..ecc38fe896b 100755 --- a/configure +++ b/configure @@ -641,6 +641,7 @@ configure_host target_cxxflags target_cflags cmodel +endian gcc_checking musl_multilib_names newlib_multilib_names @@ -730,6 +731,7 @@ with_multilib_generator with_extra_multilib_test enable_gcc_checking with_cmodel +with_endian with_target_cflags with_target_cxxflags with_host @@ -1426,6 +1428,7 @@ Optional Packages: --with-extra-multilib-test="rv64gcv-lp64;rv64gcv_zba-lp64" --with-cmodel Select the code model to use when building libc and libgcc [--with-cmodel=medlow] + --with-endian Select the target endianess [--with-endian=little] --with-target-cflags Add extra target flags for C for library code --with-target-cxxflags Add extra target flags for C++ for library code --with-host=x86_64-w64-mingw32 @@ -4080,6 +4083,19 @@ WITH_SIM=$with_sim WITH_LANGUAGES=$with_languages +# Check whether --with-endian was given. +if test "${with_endian+set}" = set; then : + withval=$with_endian; +fi + +if test "x$with_endian" != x; then : + endian=$with_endian + +else + endian=little + +fi + # Check whether --enable-multilib was given. if test ${enable_multilib+y} then : diff --git a/configure.ac b/configure.ac index 80ca038bbe0..bae4c57ffae 100644 --- a/configure.ac +++ b/configure.ac @@ -188,6 +188,10 @@ AS_IF([test "x$with_cmodel" != xno], [AC_SUBST(cmodel, -mcmodel=$with_cmodel)], [AC_SUBST(cmodel, -mcmodel=medlow)]) +AS_IF([test "x$with_endian" != x], + [AC_SUBST(endian, endian=$with_endian)], + [AC_SUBST(endian, endian=little)]) + AC_ARG_WITH(target_cflags, [AS_HELP_STRING([--with-target-cflags], [Add extra target flags for C for library code])], From c9d6ddce5118cf12f2343a3b68a4ad098207e7ee Mon Sep 17 00:00:00 2001 From: Djordje Todorovic Date: Wed, 14 Aug 2024 13:56:48 +0200 Subject: [PATCH 2/4] linux-headers: Ensure proper endianess --- linux-headers/include/asm/byteorder.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/linux-headers/include/asm/byteorder.h b/linux-headers/include/asm/byteorder.h index 03ac550720f..44552373908 100644 --- a/linux-headers/include/asm/byteorder.h +++ b/linux-headers/include/asm/byteorder.h @@ -7,6 +7,10 @@ #ifndef _ASM_RISCV_BYTEORDER_H #define _ASM_RISCV_BYTEORDER_H +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #include +#else +#include +#endif #endif /* _ASM_RISCV_BYTEORDER_H */ From 6355cfd32766c4f7790b241bff650e675a322ea9 Mon Sep 17 00:00:00 2001 From: Djordje Todorovic Date: Wed, 14 Aug 2024 13:57:44 +0200 Subject: [PATCH 3/4] README: Add BE instructions --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 8dc1910937a..125f2aa2bc6 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,15 @@ This option only takes effect for the GNU toolchain. The toolchain has an option `--enable-strip` to control strip of host binaries, strip is disabled by default. +### Big Endian configuration + +To build either cross-compiler with support for big endian targets, run the following command: + +``` +./configure --prefix=/opt/riscv --with-endian=big +make (target) +``` + ### Troubleshooting Build Problems Builds work best if installing into an empty directory. If you build a From e01382e9b0f3f3004c89ac1fce62db327eb90901 Mon Sep 17 00:00:00 2001 From: Aleksa Paunovic Date: Thu, 4 Dec 2025 16:01:12 +0100 Subject: [PATCH 4/4] configure: Fix glibc multilib build on BE platforms --- configure | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/configure b/configure index ecc38fe896b..b76b701a629 100755 --- a/configure +++ b/configure @@ -4154,7 +4154,12 @@ fi if test "x$enable_multilib" = xyes then : - glibc_multilib_names="rv32imac-ilp32 rv32gc-ilp32d rv64imac-lp64 rv64gc-lp64d rv64gcv-lp64d" + glibc_multilib_names="rv32imac-ilp32 rv32gc-ilp32d rv64imac-lp64 rv64gc-lp64d" + # Vector extension is currently not supported on Big-endian systems. + if test "x$endian" = xlittle + then : + glibc_multilib_names+=" rv64gcv-lp64d" + fi else $as_nop glibc_multilib_names="$with_arch-$with_abi"