Skip to content

Commit

Permalink
RISCV64: add buildroot toolchain support
Browse files Browse the repository at this point in the history
This is work in a progress, still got build issues
defined by mlx_riscv64_defconfig

Signed-off-by: Noam Camus <noamca@mellanox.com>
  • Loading branch information
Noam Camus committed Jun 13, 2017
1 parent 5fa9693 commit d22f226
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 1 deletion.
8 changes: 8 additions & 0 deletions arch/Config.in.riscv
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ config BR2_ENDIAN

config BR2_READELF_ARCH_NAME
default "RISC-V"

config BR2_GCC_TARGET_ARCH
default "rv32g" if BR2_riscv32
default "rv64g" if BR2_riscv64

config BR2_GCC_TARGET_ABI
default "lp32d" if BR2_riscv32
default "lp64d" if BR2_riscv64
11 changes: 11 additions & 0 deletions configs/mlx_riscv64_defconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BR2_riscv64=y
BR2_GLIBC_VERSION_2_23=y
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_GIT=y
BR2_LINUX_KERNEL_CUSTOM_REPO_URL="https://github.com/riscv/riscv-linux.git"
BR2_LINUX_KERNEL_CUSTOM_REPO_VERSION="riscv-next"
BR2_LINUX_KERNEL_PATCH="$(TOPDIR)/linux/riscv.patch"
BR2_LINUX_KERNEL_DEFCONFIG="riscv64_spike"
BR2_TARGET_ROOTFS_INITRAMFS=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_MKE2IMG=y
10 changes: 10 additions & 0 deletions linux/riscv.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff -urN linux-headers.orig/arch/riscv/include/uapi/asm/setup.h linux-headers/arch/riscv/include/uapi/asm/setup.h
--- linux-headers.orig/arch/riscv/include/uapi/asm/setup.h 1970-01-01 02:00:00.000000000 +0200
+++ linux-headers/arch/riscv/include/uapi/asm/setup.h 2017-06-13 08:46:15.567800383 +0300
@@ -0,0 +1,6 @@
+/*
+ * setup.h is part of userspace header ABI so UAPI scripts have to generate it
+ * even if there's nothing to export - causing empty <uapi/asm/setup.h>
+ * However to prevent "patch" from discarding it we add this placeholder
+ * comment
+ */
6 changes: 6 additions & 0 deletions package/binutils/binutils.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ BINUTILS_SITE = $(call github,foss-for-synopsys-dwc-arc-processors,binutils-gdb,
BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz
BINUTILS_FROM_GIT = y
endif
ifeq ($(BR2_riscv64),y)
BINUTILS_VERSION = riscv-next
BINUTILS_SITE = https://github.com/riscv/riscv-binutils-gdb.git
BINUTILS_SITE_METHOD = git
BINUTILS_SOURCE = binutils-$(BINUTILS_VERSION).tar.gz
endif
BINUTILS_SITE ?= $(BR2_GNU_MIRROR)/binutils
BINUTILS_SOURCE ?= binutils-$(BINUTILS_VERSION).tar.bz2
BINUTILS_EXTRA_CONFIG_OPTIONS = $(call qstrip,$(BR2_BINUTILS_EXTRA_CONFIG_OPTIONS))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
diff -urN binutils.orig/bfd/bfd-in2.h binutils/bfd/bfd-in2.h
--- binutils.orig/bfd/bfd-in2.h 2017-05-20 01:49:31.000000000 +0300
+++ binutils/bfd/bfd-in2.h 2017-06-13 15:52:19.961649468 +0300
@@ -4769,6 +4769,7 @@
BFD_RELOC_RISCV_SET8,
BFD_RELOC_RISCV_SET16,
BFD_RELOC_RISCV_SET32,
+ BFD_RELOC_RISCV_64_PCREL,

/* Renesas RL78 Relocations. */
BFD_RELOC_RL78_NEG8,
diff -urN binutils.orig/bfd/elfnn-riscv.c binutils/bfd/elfnn-riscv.c
--- binutils.orig/bfd/elfnn-riscv.c 2017-05-20 01:49:31.000000000 +0300
+++ binutils/bfd/elfnn-riscv.c 2017-06-13 15:53:06.036956405 +0300
@@ -1566,6 +1566,7 @@
case R_RISCV_SET8:
case R_RISCV_SET16:
case R_RISCV_SET32:
+ case R_RISCV_64_PCREL:
case R_RISCV_TLS_DTPREL32:
case R_RISCV_TLS_DTPREL64:
break;
@@ -1853,6 +1854,7 @@
case R_RISCV_SET16:
case R_RISCV_SET32:
case R_RISCV_DELETE:
+ case R_RISCV_64_PCREL:
/* These require no special handling beyond perform_relocation. */
break;

diff -urN binutils.orig/bfd/elfxx-riscv.c binutils/bfd/elfxx-riscv.c
--- binutils.orig/bfd/elfxx-riscv.c 2017-05-20 01:49:31.000000000 +0300
+++ binutils/bfd/elfxx-riscv.c 2017-06-13 15:53:51.780243045 +0300
@@ -849,6 +849,22 @@
0, /* src_mask */
MINUS_ONE, /* dst_mask */
FALSE), /* pcrel_offset */
+
+ /* Deletes bytes after this address. The addend specifies the number of
+ * bytes to delete, just like R_RISCV_ALIGN. */
+ HOWTO (R_RISCV_64_PCREL, /* type */
+ 0, /* rightshift */
+ 4, /* size */
+ 64, /* bitsize */
+ TRUE, /* pc_relative */
+ 0, /* bitpos */
+ complain_overflow_dont, /* complain_on_overflow */
+ bfd_elf_generic_reloc, /* special_function */
+ "R_RISCV_64_PCREL", /* name */
+ FALSE, /* partial_inplace */
+ 0, /* src_mask */
+ MINUS_ONE, /* dst_mask */
+ FALSE), /* pcrel_offset */
};

/* A mapping from BFD reloc types to RISC-V ELF reloc types. */
@@ -910,6 +926,7 @@
{ BFD_RELOC_RISCV_SET8, R_RISCV_SET8 },
{ BFD_RELOC_RISCV_SET16, R_RISCV_SET16 },
{ BFD_RELOC_RISCV_SET32, R_RISCV_SET32 },
+ { BFD_RELOC_RISCV_64_PCREL, R_RISCV_64_PCREL },
};

/* Given a BFD reloc type, return a howto structure. */
diff -urN binutils.orig/bfd/libbfd.h binutils/bfd/libbfd.h
--- binutils.orig/bfd/libbfd.h 2017-05-20 01:49:31.000000000 +0300
+++ binutils/bfd/libbfd.h 2017-06-13 15:54:06.212014046 +0300
@@ -2212,6 +2212,7 @@
"BFD_RELOC_RISCV_SET8",
"BFD_RELOC_RISCV_SET16",
"BFD_RELOC_RISCV_SET32",
+ "BFD_RELOC_RISCV_64_PCREL",
"BFD_RELOC_RL78_NEG8",
"BFD_RELOC_RL78_NEG16",
"BFD_RELOC_RL78_NEG24",
diff -urN binutils.orig/bfd/reloc.c binutils/bfd/reloc.c
--- binutils.orig/bfd/reloc.c 2017-05-20 01:49:31.000000000 +0300
+++ binutils/bfd/reloc.c 2017-06-13 15:54:19.819796701 +0300
@@ -5155,6 +5155,8 @@
BFD_RELOC_RISCV_SET16
ENUMX
BFD_RELOC_RISCV_SET32
+ENUMX
+ BFD_RELOC_RISCV_64_PCREL
ENUMDOC
RISC-V relocations.

diff -urN binutils.orig/gas/config/tc-riscv.c binutils/gas/config/tc-riscv.c
--- binutils.orig/gas/config/tc-riscv.c 2017-05-20 01:49:31.000000000 +0300
+++ binutils/gas/config/tc-riscv.c 2017-06-13 15:55:11.218965592 +0300
@@ -1871,6 +1871,7 @@
bfd_byte *buf = (bfd_byte *) (fixP->fx_frag->fr_literal + fixP->fx_where);
bfd_boolean relaxable = FALSE;
offsetT loc;
+ segT sub_segment;

/* Remember value for tc_gen_reloc. */
fixP->fx_addnumber = *valP;
@@ -1919,6 +1920,23 @@
break;

case BFD_RELOC_64:
+ /* Use pc-relative relocation for FDE initial location.
+ The symbol address in .eh_frame may be adjusted in
+ _bfd_elf_discard_section_eh_frame, and the content of
+ .eh_frame will be adjusted in _bfd_elf_write_section_eh_frame.
+ Therefore, we cannot insert a relocation whose addend symbol is
+ in .eh_frame. Othrewise, the value may be adjusted twice.*/
+ if (fixP->fx_addsy && fixP->fx_subsy
+ && (sub_segment = S_GET_SEGMENT (fixP->fx_subsy))
+ && strcmp (sub_segment->name, ".eh_frame") == 0
+ && S_GET_VALUE (fixP->fx_subsy)
+ == fixP->fx_frag->fr_address + fixP->fx_where)
+ {
+ fixP->fx_r_type = BFD_RELOC_RISCV_64_PCREL;
+ fixP->fx_subsy = NULL;
+ break;
+ }
+ /* Fall through. */
case BFD_RELOC_32:
case BFD_RELOC_16:
case BFD_RELOC_8:
diff -urN binutils.orig/include/elf/riscv.h binutils/include/elf/riscv.h
--- binutils.orig/include/elf/riscv.h 2017-05-20 01:49:31.000000000 +0300
+++ binutils/include/elf/riscv.h 2017-06-13 15:55:36.962544552 +0300
@@ -87,6 +87,7 @@
RELOC_NUMBER (R_RISCV_SET8, 54)
RELOC_NUMBER (R_RISCV_SET16, 55)
RELOC_NUMBER (R_RISCV_SET32, 56)
+ RELOC_NUMBER (R_RISCV_64_PCREL, 57)
END_RELOC_NUMBERS (R_RISCV_max)

/* Processor specific flags for the ELF header e_flags field. */
6 changes: 6 additions & 0 deletions package/gcc/gcc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
else ifeq ($(BR2_or1k),y)
GCC_SITE = $(call github,openrisc,or1k-gcc,$(GCC_VERSION))
GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
else ifeq ($(BR2_riscv64),y)
GCC_VERSION = riscv-next
GCC_SITE = https://github.com/riscv/riscv-gcc.git
HOST_GCC_INITIAL_SITE_METHOD = git
GCC_SOURCE = gcc-$(GCC_VERSION).tar.gz
BR_NO_CHECK_HASH_FOR += $(GCC_SOURCE)
else
GCC_SITE = $(BR2_GNU_MIRROR:/=)/gcc/gcc-$(GCC_VERSION)
GCC_SOURCE = gcc-$(GCC_VERSION).tar.bz2
Expand Down
12 changes: 12 additions & 0 deletions package/gcc/riscv-next/0001-remove-failed-s-selftest-target.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff -urN gcc.orig/gcc/Makefile.in gcc/gcc/Makefile.in
--- gcc.orig/gcc/Makefile.in 2017-05-30 05:47:35.000000000 +0300
+++ gcc/gcc/Makefile.in 2017-06-12 17:43:22.140479147 +0300
@@ -1908,7 +1908,7 @@
# Use "s-selftest" to ensure that we only run the selftests if the
# driver, cc1, or selftest data change.
.PHONY: selftest
-selftest: s-selftest
+selftest: # s-selftest
s-selftest: $(GCC_PASSES) cc1$(exeext) stmp-int-hdrs \
$(srcdir)/testsuite/selftests
$(GCC_FOR_TARGET) $(SELFTEST_FLAGS)
8 changes: 8 additions & 0 deletions package/glibc/glibc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ GLIBC_SITE = $(BR2_GNU_MIRROR)/libc
GLIBC_SOURCE = glibc-$(GLIBC_VERSION).tar.xz
GLIBC_SRC_SUBDIR = .

ifeq ($(BR2_riscv64),y)
GLIBC_VERSION = riscv-next
GLIBC_SITE = https://github.com/riscv/riscv-glibc.git
GLIBC_SITE_METHOD = git
GLIBC_SOURCE = glibc-$(GLIBC_VERSION).tar.gz
endif

GLIBC_LICENSE = GPL-2.0+ (programs), LGPL-2.1+, BSD-3-Clause, MIT (library)
GLIBC_LICENSE_FILES = $(addprefix $(GLIBC_SRC_SUBDIR)/,COPYING COPYING.LIB LICENSES)

Expand Down Expand Up @@ -84,6 +91,7 @@ define GLIBC_CONFIGURE_CMDS
--enable-shared \
$(if $(BR2_SOFT_FLOAT),--without-fp,--with-fp) \
$(if $(BR2_x86_64),--enable-lock-elision) \
$(if $(BR2_riscv64),--disable-werror) \
--with-pkgversion="Buildroot" \
--without-cvs \
--disable-profile \
Expand Down
4 changes: 4 additions & 0 deletions package/linux-headers/Config.in.host
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ choice
This is used to hide/show some packages that have strict
requirements on the version of kernel headers.

config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_12
bool "4.12.x"
select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12

config BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_4_11
bool "4.11.x"
select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11
Expand Down
2 changes: 1 addition & 1 deletion toolchain/toolchain-buildroot/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ config BR2_TOOLCHAIN_BUILDROOT_GLIBC
BR2_mipsel || BR2_mips64 || BR2_mips64el|| \
BR2_powerpc || BR2_powerpc64 || BR2_powerpc64le || \
BR2_sh || BR2_sparc64 || BR2_x86_64 || \
BR2_microblaze || BR2_nios2
BR2_microblaze || BR2_nios2 || BR2_riscv64
depends on BR2_USE_MMU
depends on !BR2_STATIC_LIBS
depends on !BR2_powerpc_SPE
Expand Down
5 changes: 5 additions & 0 deletions toolchain/toolchain-common.in
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,15 @@ config BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11
bool
select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_10

config BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12
bool
select BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11

# This order guarantees that the highest version is set, as kconfig
# stops affecting a value on the first matching default.
config BR2_TOOLCHAIN_HEADERS_AT_LEAST
string
default "4.12" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_12
default "4.11" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_11
default "4.10" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_10
default "4.9" if BR2_TOOLCHAIN_HEADERS_AT_LEAST_4_9
Expand Down

0 comments on commit d22f226

Please sign in to comment.