From 417f276e41f635811c87f353bf67d16661cf0da4 Mon Sep 17 00:00:00 2001 From: Dale Rahn Date: Wed, 5 May 2021 04:52:40 +0000 Subject: riscv64 binutils 'support' Enable just enough of binutils to be a functional compilation system with llvm doing the heavy lifting. With corrections suggested by reviewers. ok jsg@ kettenis@ --- gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper | 11 ++-- gnu/usr.bin/binutils-2.17/bfd/Makefile.am | 5 ++ gnu/usr.bin/binutils-2.17/bfd/Makefile.in | 5 ++ gnu/usr.bin/binutils-2.17/bfd/archures.c | 3 ++ gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h | 1 + gnu/usr.bin/binutils-2.17/bfd/config.bfd | 4 ++ gnu/usr.bin/binutils-2.17/bfd/configure | 1 + gnu/usr.bin/binutils-2.17/bfd/cpu-riscv64.c | 40 +++++++++++++++ gnu/usr.bin/binutils-2.17/bfd/elf64-riscv.c | 69 ++++++++++++++++++++++++++ gnu/usr.bin/binutils-2.17/bfd/targets.c | 1 + gnu/usr.bin/binutils-2.17/configure | 6 +++ gnu/usr.bin/binutils-2.17/configure.in | 3 ++ gnu/usr.bin/binutils-2.17/gas/bfin-lex.c | 2 +- gnu/usr.bin/binutils-2.17/opcodes/configure | 1 + gnu/usr.bin/binutils-2.17/opcodes/configure.in | 1 + 15 files changed, 147 insertions(+), 6 deletions(-) create mode 100644 gnu/usr.bin/binutils-2.17/bfd/cpu-riscv64.c create mode 100644 gnu/usr.bin/binutils-2.17/bfd/elf64-riscv.c (limited to 'gnu') diff --git a/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper b/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper index 41ca6e57a19..f7c2af02fda 100644 --- a/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper +++ b/gnu/usr.bin/binutils-2.17/Makefile.bsd-wrapper @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.bsd-wrapper,v 1.21 2020/05/30 19:22:00 drahn Exp $ +# $OpenBSD: Makefile.bsd-wrapper,v 1.22 2021/05/05 04:52:39 drahn Exp $ .include @@ -32,10 +32,11 @@ INST_SUBDIRS+= binutils MAN+= binutils/doc/ar.1 binutils/doc/ranlib.1 \ binutils/doc/strings.1 binutils/doc/strip.1 -.if (${TARGET_ARCH} != "aarch64" && ${TARGET_ARCH} != "powerpc64") -SUBDIRS+= ld gas -CONF_SUBDIRS+= ld gas -INST_SUBDIRS+= ld gas +.if (${TARGET_ARCH} != "aarch64" && ${TARGET_ARCH} != "powerpc64" && \ + ${TARGET_ARCH} != "riscv64") +SUBDIRS+= ld gas +CONF_SUBDIRS+= ld gas +INST_SUBDIRS+= ld gas MAN+= gas/doc/as.1 ld/ld.bfd.1 .if ${LINKER_VERSION:L} == "bfd" maninstall: diff --git a/gnu/usr.bin/binutils-2.17/bfd/Makefile.am b/gnu/usr.bin/binutils-2.17/bfd/Makefile.am index bddd324b2c4..0a603c708ac 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/Makefile.am +++ b/gnu/usr.bin/binutils-2.17/bfd/Makefile.am @@ -550,6 +550,7 @@ BFD64_BACKENDS = \ elf64-mmix.lo \ elf64-sh64.lo \ elf64-ppc.lo \ + elf64-riscv.lo \ elf64-s390.lo \ elf64-sparc.lo \ elf64.lo \ @@ -574,6 +575,7 @@ BFD64_BACKENDS_CFILES = \ elf64-mips.c \ elf64-mmix.c \ elf64-ppc.c \ + elf64-riscv.c \ elf64-s390.c \ elf64-sh64.c \ elf64-sparc.c \ @@ -1782,6 +1784,9 @@ elf64-ppc.lo: elf64-ppc.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \ $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/elf/ppc64.h \ $(INCDIR)/elf/reloc-macros.h elf64-ppc.h elf64-target.h +elf64-riscv.lo: elf64-riscv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ + elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \ + $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h elf64-target.h elf64-s390.lo: elf64-s390.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \ $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/elf/s390.h \ diff --git a/gnu/usr.bin/binutils-2.17/bfd/Makefile.in b/gnu/usr.bin/binutils-2.17/bfd/Makefile.in index 3c04ce18994..c005fd7bdf2 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/Makefile.in +++ b/gnu/usr.bin/binutils-2.17/bfd/Makefile.in @@ -791,6 +791,7 @@ BFD64_BACKENDS = \ elf64-mmix.lo \ elf64-sh64.lo \ elf64-ppc.lo \ + elf64-riscv.lo \ elf64-s390.lo \ elf64-sparc.lo \ elf64.lo \ @@ -816,6 +817,7 @@ BFD64_BACKENDS_CFILES = \ elf64-mips.c \ elf64-mmix.c \ elf64-ppc.c \ + elf64-riscv.c \ elf64-s390.c \ elf64-sh64.c \ elf64-sparc.c \ @@ -2358,6 +2360,9 @@ elf64-ppc.lo: elf64-ppc.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \ $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/elf/ppc64.h \ $(INCDIR)/elf/reloc-macros.h elf64-ppc.h elf64-target.h +elf64-riscv.lo: elf64-riscv.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h \ + elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \ + $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h elf64-target.h elf64-s390.lo: elf64-s390.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \ $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \ $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/elf/s390.h \ diff --git a/gnu/usr.bin/binutils-2.17/bfd/archures.c b/gnu/usr.bin/binutils-2.17/bfd/archures.c index 64f60ff9a1d..ab2d868231e 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/archures.c +++ b/gnu/usr.bin/binutils-2.17/bfd/archures.c @@ -383,6 +383,7 @@ DESCRIPTION .#define bfd_mach_z80full 7 {* All undocumented instructions. *} .#define bfd_mach_r800 11 {* R800: successor with multiplication. *} . bfd_arch_aarch64, +. bfd_arch_riscv64, . bfd_arch_last . }; */ @@ -467,6 +468,7 @@ extern const bfd_arch_info_type bfd_pj_arch; extern const bfd_arch_info_type bfd_powerpc_archs[]; #define bfd_powerpc_arch bfd_powerpc_archs[0] extern const bfd_arch_info_type bfd_rs6000_arch; +extern const bfd_arch_info_type bfd_riscv64_arch; extern const bfd_arch_info_type bfd_s390_arch; extern const bfd_arch_info_type bfd_sh_arch; extern const bfd_arch_info_type bfd_sparc_arch; @@ -531,6 +533,7 @@ static const bfd_arch_info_type * const bfd_archures_list[] = &bfd_or32_arch, &bfd_pdp11_arch, &bfd_powerpc_arch, + &bfd_riscv_arch, &bfd_rs6000_arch, &bfd_s390_arch, &bfd_sh_arch, diff --git a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h index d36a8a9cbec..e17a29d4086 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h +++ b/gnu/usr.bin/binutils-2.17/bfd/bfd-in2.h @@ -1987,6 +1987,7 @@ enum bfd_architecture #define bfd_mach_z80full 7 /* All undocumented instructions. */ #define bfd_mach_r800 11 /* R800: successor with multiplication. */ bfd_arch_aarch64, + bfd_arch_riscv64, bfd_arch_last }; diff --git a/gnu/usr.bin/binutils-2.17/bfd/config.bfd b/gnu/usr.bin/binutils-2.17/bfd/config.bfd index 40e4c3e1ff9..fbf223e839e 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/config.bfd +++ b/gnu/usr.bin/binutils-2.17/bfd/config.bfd @@ -92,6 +92,7 @@ or32*) targ_archs=bfd_or32_arch ;; pdp11*) targ_archs=bfd_pdp11_arch ;; pj*) targ_archs="bfd_pj_arch bfd_i386_arch";; powerpc*) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;; +riscv64) targ_archs=bfd_riscv64_arch ;; rs6000) targ_archs="bfd_rs6000_arch bfd_powerpc_arch" ;; s390*) targ_archs=bfd_s390_arch ;; sh*) targ_archs=bfd_sh_arch ;; @@ -178,6 +179,9 @@ case "${targ}" in targ_defvec=bfd_elf32_ia64_hpux_big_vec targ_selvecs="bfd_elf64_ia64_hpux_big_vec" ;; + riscv64-*-openbsd*) + targ_defvec=bfd_elf64_riscv_vec + ;; sparc64-*-freebsd* | sparc64-*-netbsd* | sparc64-*-openbsd* | sparc64-*-kfreebsd*-gnu) targ_defvec=bfd_elf64_sparc_vec targ_selvecs="bfd_elf32_sparc_vec sunos_big_vec" diff --git a/gnu/usr.bin/binutils-2.17/bfd/configure b/gnu/usr.bin/binutils-2.17/bfd/configure index ab6f6cd91c4..ea423d3725c 100755 --- a/gnu/usr.bin/binutils-2.17/bfd/configure +++ b/gnu/usr.bin/binutils-2.17/bfd/configure @@ -13192,6 +13192,7 @@ do bfd_elf64_mmix_vec) tb="$tb elf64-mmix.lo elf64.lo $elf" target_size=64 ;; bfd_elf64_powerpc_vec) tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf"; target_size=64 ;; bfd_elf64_powerpcle_vec) tb="$tb elf64-ppc.lo elf64-gen.lo elf64.lo $elf" target_size=64 ;; + bfd_elf64_riscv_vec) tb="$tb elf64-riscv.lo"; target_size=64 ;; bfd_elf64_s390_vec) tb="$tb elf64-s390.lo elf64.lo $elf"; target_size=64 ;; bfd_elf64_sh64_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;; bfd_elf64_sh64l_vec) tb="$tb elf64-sh64.lo elf64.lo $elf" target_size=64 ;; diff --git a/gnu/usr.bin/binutils-2.17/bfd/cpu-riscv64.c b/gnu/usr.bin/binutils-2.17/bfd/cpu-riscv64.c new file mode 100644 index 00000000000..558f9a9a85e --- /dev/null +++ b/gnu/usr.bin/binutils-2.17/bfd/cpu-riscv64.c @@ -0,0 +1,40 @@ +/* BFD Support for RISCV + + Copyright 2005 Free Software Foundation, Inc. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, + USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" + +const bfd_arch_info_type bfd_riscv64_arch = + { + 64, /* Bits in a word. */ + 64, /* Bits in an address. */ + 8, /* Bits in a byte. */ + bfd_arch_riscv64, + 0, /* Only one machine. */ + "riscv", /* Arch name. */ + "riscv:rv64", /* Arch printable name. */ + 4, /* Section align power. */ + TRUE, /* The one and only. */ + bfd_default_compatible, + bfd_default_scan , + 0, + }; diff --git a/gnu/usr.bin/binutils-2.17/bfd/elf64-riscv.c b/gnu/usr.bin/binutils-2.17/bfd/elf64-riscv.c new file mode 100644 index 00000000000..66fb793108f --- /dev/null +++ b/gnu/usr.bin/binutils-2.17/bfd/elf64-riscv.c @@ -0,0 +1,69 @@ +/* Generic support for 64-bit ELF + Copyright 1993, 1995, 1998, 1999, 2001, 2002, 2004, 2005 + Free Software Foundation, Inc. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include "bfd.h" +#include "sysdep.h" +#include "libbfd.h" +#include "elf-bfd.h" + +/* This does not include any relocation information, but should be + good enough for GDB or objdump to read the file. */ + +static reloc_howto_type dummy = + HOWTO (0, /* type */ + 0, /* rightshift */ + 0, /* size (0 = byte, 1 = short, 2 = long) */ + 0, /* bitsize */ + FALSE, /* pc_relative */ + 0, /* bitpos */ + complain_overflow_dont, /* complain_on_overflow */ + NULL, /* special_function */ + "UNKNOWN", /* name */ + FALSE, /* partial_inplace */ + 0, /* src_mask */ + 0, /* dst_mask */ + FALSE); /* pcrel_offset */ + +static void +elf_generic_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, + arelent *bfd_reloc, + Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) +{ + bfd_reloc->howto = &dummy; +} + +static void +elf_generic_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, + arelent *bfd_reloc, + Elf_Internal_Rela *elf_reloc ATTRIBUTE_UNUSED) +{ + bfd_reloc->howto = &dummy; +} + +#define TARGET_LITTLE_SYM bfd_elf64_riscv_vec +#define TARGET_LITTLE_NAME "elf64-riscv" +#define ELF_ARCH bfd_arch_riscv64 +#define ELF_MACHINE_CODE EM_RISCV +#define ELF_MAXPAGESIZE 0x1000 +#define bfd_elf64_bfd_reloc_type_lookup bfd_default_reloc_type_lookup +#define elf_info_to_howto elf_generic_info_to_howto +#define elf_info_to_howto_rel elf_generic_info_to_howto_rel + +#include "elf64-target.h" diff --git a/gnu/usr.bin/binutils-2.17/bfd/targets.c b/gnu/usr.bin/binutils-2.17/bfd/targets.c index f81449099f1..7c23d4157c3 100644 --- a/gnu/usr.bin/binutils-2.17/bfd/targets.c +++ b/gnu/usr.bin/binutils-2.17/bfd/targets.c @@ -663,6 +663,7 @@ extern const bfd_target bfd_elf64_littlemips_vec; extern const bfd_target bfd_elf64_mmix_vec; extern const bfd_target bfd_elf64_powerpc_vec; extern const bfd_target bfd_elf64_powerpcle_vec; +extern const bfd_target bfd_elf64_riscv_vec; extern const bfd_target bfd_elf64_s390_vec; extern const bfd_target bfd_elf64_sh64_vec; extern const bfd_target bfd_elf64_sh64l_vec; diff --git a/gnu/usr.bin/binutils-2.17/configure b/gnu/usr.bin/binutils-2.17/configure index ba999a3d80a..999d8c26c69 100755 --- a/gnu/usr.bin/binutils-2.17/configure +++ b/gnu/usr.bin/binutils-2.17/configure @@ -1237,6 +1237,9 @@ case "${target}" in ;; esac ;; + riscv*-*-openbsd*) + noconfigdirs="ld gas" + ;; *-*-netware*) noconfigdirs="$noconfigdirs target-newlib target-libiberty target-libgloss ${libgcj} target-libmudflap" ;; @@ -1585,6 +1588,9 @@ case "${target}" in mips*-*-*) noconfigdirs="$noconfigdirs gprof ${libgcj}" ;; + riscv*-*-openbsd*) + noconfigdirs="ld gas" + ;; romp-*-*) noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}" ;; diff --git a/gnu/usr.bin/binutils-2.17/configure.in b/gnu/usr.bin/binutils-2.17/configure.in index 3cf10f0aa54..4e71d4917cd 100644 --- a/gnu/usr.bin/binutils-2.17/configure.in +++ b/gnu/usr.bin/binutils-2.17/configure.in @@ -777,6 +777,9 @@ case "${target}" in mips*-*-*) noconfigdirs="$noconfigdirs gprof ${libgcj}" ;; + riscv*-*-openbsd*) + noconfigdirs="$noconfigdirs gas ld" + ;; romp-*-*) noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}" ;; diff --git a/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c b/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c index c8a443dd65c..ad60ea20608 100644 --- a/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c +++ b/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c @@ -1,7 +1,7 @@ /* A lexical scanner generated by flex */ /* Scanner skeleton version: - * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c,v 1.1 2011/04/24 20:14:44 miod Exp $ + * $Header: /cvs/OpenBSD/src/gnu/usr.bin/binutils-2.17/gas/bfin-lex.c,v 1.2 2021/05/05 04:52:39 drahn Exp $ */ #define FLEX_SCANNER diff --git a/gnu/usr.bin/binutils-2.17/opcodes/configure b/gnu/usr.bin/binutils-2.17/opcodes/configure index 7849ffee738..1a4e412bb19 100755 --- a/gnu/usr.bin/binutils-2.17/opcodes/configure +++ b/gnu/usr.bin/binutils-2.17/opcodes/configure @@ -8846,6 +8846,7 @@ if test x${all_targets} = xfalse ; then bfd_powerpc_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_powerpc_64_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_pyramid_arch) ;; + bfd_riscv64_arch) ;; bfd_romp_arch) ;; bfd_rs6000_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_s390_arch) ta="$ta s390-dis.lo s390-opc.lo" ;; diff --git a/gnu/usr.bin/binutils-2.17/opcodes/configure.in b/gnu/usr.bin/binutils-2.17/opcodes/configure.in index c98802c9ac9..7d4617ddf66 100644 --- a/gnu/usr.bin/binutils-2.17/opcodes/configure.in +++ b/gnu/usr.bin/binutils-2.17/opcodes/configure.in @@ -198,6 +198,7 @@ if test x${all_targets} = xfalse ; then bfd_powerpc_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_powerpc_64_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_pyramid_arch) ;; + bfd_riscv64_arch) ;; bfd_romp_arch) ;; bfd_rs6000_arch) ta="$ta ppc-dis.lo ppc-opc.lo" ;; bfd_s390_arch) ta="$ta s390-dis.lo s390-opc.lo" ;; -- cgit v1.2.3