Hi all:

This patch is version 2 of FreeBSD supporting for RISC-V, Ruslan
(RISC-V FreeBSD maintainer) and me has been tested on FreeBSD 12
for building kernel and whole user space programs/libraries again :)


Hi Jim:

Ruslan and me just decide upstream GCC part only this time since
binutils need more work (mostly for ELF header info), but it's not
affect the correctness.

Changes since v1[1]:
- Remove dbxelf.h.
- Correct the copyright year info.
- Fix libgcc/config.host for riscv*-*-freebsd*.

Copyright part, Ruslan has sent to fsf-reco...@gnu.org but no echo,
I've forward that to ass...@gnu.org again.


gcc/ChangeLog

2018-01-29  Ruslan Bukin  <b...@bsdpad.com>
                    Kito Cheng  <kito.ch...@gmail.com>

        * config.gcc (riscv*-*-freebsd*): New.
        * config/riscv/freebsd.h: New.

libgcc/ChangeLog

2018-01-29  Ruslan Bukin  <b...@bsdpad.com>

        * libgcc/config.host: Support RISC-V FreeBSD.

[1] V1 patch: https://gcc.gnu.org/ml/gcc-patches/2018-01/msg02235.html
From 13781768c4f71eb83505f0d579de37d5f861ac7c Mon Sep 17 00:00:00 2001
From: Ruslan Bukin <b...@bsdpad.com>
Date: Wed, 3 Jan 2018 15:59:04 +0000
Subject: [PATCH] RISC-V: Add support for FreeBSD

gcc/ChangeLog

2018-02-18  Ruslan Bukin  <b...@bsdpad.com>
	    Kito Cheng  <kito.ch...@gmail.com>

	* config.gcc (riscv*-*-freebsd*): New.
	* config/riscv/freebsd.h: New.

libgcc/ChangeLog

2018-02-18  Ruslan Bukin  <b...@bsdpad.com>

	* libgcc/config.host: Support RISC-V FreeBSD.
---
 gcc/config.gcc             |  9 ++++++++
 gcc/config/riscv/freebsd.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++
 libgcc/config.host         |  4 ++++
 3 files changed, 67 insertions(+)
 create mode 100644 gcc/config/riscv/freebsd.h

diff --git a/gcc/config.gcc b/gcc/config.gcc
index c52fecf..01b5a92 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2086,6 +2086,15 @@ riscv*-*-elf* | riscv*-*-rtems*)
 	  ;;
 	esac
 	;;
+riscv*-*-freebsd*)
+	tm_file="${tm_file} elfos.h ${fbsd_tm_file} riscv/freebsd.h"
+	tmake_file="${tmake_file} riscv/t-riscv"
+	gnu_ld=yes
+	gas=yes
+	# Force .init_array support.  The configure script cannot always
+	# automatically detect that GAS supports it, yet we require it.
+	gcc_cv_initfini_array=yes
+	;;
 mips*-*-netbsd*)			# NetBSD/mips, either endian.
 	target_cpu_default="MASK_ABICALLS"
 	tm_file="elfos.h ${tm_file} mips/elf.h ${nbsd_tm_file} mips/netbsd.h"
diff --git a/gcc/config/riscv/freebsd.h b/gcc/config/riscv/freebsd.h
new file mode 100644
index 0000000..019b22f
--- /dev/null
+++ b/gcc/config/riscv/freebsd.h
@@ -0,0 +1,54 @@
+/* Definitions for RISC-V FreeBSD systems with ELF format.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC 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 3, or (at your option)
+any later version.
+
+GCC 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 GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+#undef WCHAR_TYPE
+#define WCHAR_TYPE "int"
+
+#undef WCHAR_TYPE_SIZE
+#define WCHAR_TYPE_SIZE 32
+
+#undef  SUBTARGET_EXTRA_SPECS
+#define SUBTARGET_EXTRA_SPECS \
+  { "fbsd_dynamic_linker", FBSD_DYNAMIC_LINKER }
+
+#undef CC1_SPEC
+#define CC1_SPEC "%(cc1_cpu) %{profile:-p}"
+
+/* Provide a LINK_SPEC appropriate for FreeBSD.  Here we provide support
+   for the special GCC options -static and -shared, which allow us to
+   link things in one of these three modes by applying the appropriate
+   combinations of options at link-time.
+
+   When the -shared link option is used a final link is not being
+   done.  */
+
+#undef LINK_SPEC
+#define LINK_SPEC "						\
+  -melf" XLEN_SPEC "lriscv					\
+  %{p:%nconsider using `-pg' instead of `-p' with gprof (1) }	\
+  %{v:-V}							\
+  %{assert*} %{R*} %{rpath*} %{defsym*}				\
+  %{shared:-Bshareable %{h*} %{soname*}}			\
+  %{symbolic:-Bsymbolic}					\
+  %{static:-Bstatic}						\
+  %{!shared:							\
+      %{!static:						\
+        %{rdynamic:-export-dynamic}				\
+        -dynamic-linker " FBSD_DYNAMIC_LINKER "}		\
+        %{static:-static}}"
diff --git a/libgcc/config.host b/libgcc/config.host
index 96d55a4..11b4aca 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -1128,6 +1128,10 @@ riscv*-*-linux*)
 	extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o"
 	md_unwind_header=riscv/linux-unwind.h
 	;;
+riscv*-*-freebsd*)
+	tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}"
+	extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o crtendS.o crtbeginT.o"
+	;;
 riscv*-*-*)
 	tmake_file="${tmake_file} riscv/t-softfp${host_address} t-softfp riscv/t-elf riscv/t-elf${host_address}"
 	extra_parts="$extra_parts crtbegin.o crtend.o crti.o crtn.o"
-- 
2.7.4

Reply via email to