Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 22 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ configure_host
target_cxxflags
target_cflags
cmodel
endian
gcc_checking
musl_multilib_names
newlib_multilib_names
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down Expand Up @@ -4138,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"
Expand Down
4 changes: 4 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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])],
Expand Down
4 changes: 4 additions & 0 deletions linux-headers/include/asm/byteorder.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#ifndef _ASM_RISCV_BYTEORDER_H
#define _ASM_RISCV_BYTEORDER_H

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All linux headers are copied without modification as we don't want downstream changes here.
If we add such non-upstream changes, then there is a risk of breaking the BE build each time we update the linux headers.

#include <linux/byteorder/little_endian.h>
#else
#include <linux/byteorder/big_endian.h>
#endif

#endif /* _ASM_RISCV_BYTEORDER_H */