--- rpmbuild/SPECS/gcc.spec	2018-03-24 08:43:19.000000000 +0000
+++ gcc.spec	2018-03-26 12:38:08.876000000 +0000
@@ -1,10 +1,10 @@
-%global DATE 20180324
-%global SVNREV 258832
+%global DATE 20180317
+%global SVNREV 258622
 %global gcc_version 8.0.1
 %global gcc_major 8
 # Note, gcc_release must be integer, if you want to add suffixes to
 # %%{release}, append them after %%{gcc_release} on Release: line.
-%global gcc_release 0.20
+%global gcc_release 0.19
 %global nvptx_tools_gitrev c28050f60193b3b95a18866a96f03334e874e78f
 %global nvptx_newlib_gitrev aadc8eb0ec43b7cd0dd2dfb484bae63c8b05ef24
 %global _unpackaged_files_terminate_build 0
@@ -21,7 +21,7 @@
 %else
 %global build_ada 0
 %endif
-%ifarch %{ix86} x86_64 ppc ppc64 ppc64le ppc64p7 s390 s390x %{arm} aarch64 %{mips}
+%ifarch %{ix86} x86_64 ppc ppc64 ppc64le ppc64p7 s390 s390x %{arm} aarch64 %{mips} riscv64
 %global build_go 1
 %else
 %global build_go 0
@@ -51,7 +51,7 @@
 %else
 %global build_libubsan 0
 %endif
-%ifarch %{ix86} x86_64 ppc ppc64 ppc64le ppc64p7 s390 s390x %{arm} aarch64 %{mips}
+%ifarch %{ix86} x86_64 ppc ppc64 ppc64le ppc64p7 s390 s390x %{arm} aarch64 %{mips} riscv64
 %global build_libatomic 1
 %else
 %global build_libatomic 0
@@ -67,7 +67,7 @@
 %global build_libmpx 0
 %endif
 %global build_isl 1
-%global build_libstdcxx_docs 1
+%global build_libstdcxx_docs 0
 %ifarch %{ix86} x86_64 ppc ppc64 ppc64le ppc64p7 s390 s390x %{arm} aarch64 %{mips}
 %global attr_ifunc 1
 %else
@@ -93,7 +93,7 @@
 Summary: Various compilers (C, C++, Objective-C, ...)
 Name: gcc
 Version: %{gcc_version}
-Release: %{gcc_release}%{?dist}
+Release: %{gcc_release}.0.riscv64%{?dist}
 # libgcc, libgfortran, libgomp, libstdc++ and crtstuff have
 # GCC Runtime Exception.
 License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
@@ -149,7 +149,10 @@
 BuildRequires: hostname, procps
 %endif
 # For VTA guality testing
+# riscv64 does not have GDB port at this point
+%ifnarch riscv64
 BuildRequires: gdb
+%endif
 # Make sure pthread.h doesn't contain __thread tokens
 # Make sure glibc supports stack protector
 # Make sure glibc supports DT_GNU_HASH
@@ -245,6 +248,13 @@
 Patch10: gcc8-foffload-default.patch
 Patch11: gcc8-Wno-format-security.patch
 Patch12: gcc8-rh1512529-aarch64.patch
+# TODO: Remove after --with-multilib-list=list support for riscv64 is added
+# See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84797
+Patch13: gcc8-riscv64-multilib.patch
+# See: https://github.com/libffi/libffi/pull/281
+Patch14: gcc8-libffi-add-riscv64.patch                                                                                                                                                                                                                           
+Patch15: gcc8-libffi-regen.patch
+Patch16: gcc8-libffi-riscv64-def-FFI_ALIGN.patch
 
 Patch1000: nvptx-tools-no-ptxas.patch
 Patch1001: nvptx-tools-build.patch
@@ -804,6 +814,10 @@
 %patch10 -p0 -b .foffload-default~
 %patch11 -p0 -b .Wno-format-security~
 %patch12 -p0 -b .rh1512529-aarch64~
+%patch13 -p1 -b .riscv64-multilib~
+%patch14 -p1 -b .libffi-add-riscv64~
+%patch15 -p1 -b .libffi-regen~
+%patch16 -p1 -b .libffi-ffi_align~
 
 cd nvptx-tools-%{nvptx_tools_gitrev}
 %patch1000 -p1 -b .nvptx-tools-no-ptxas~
@@ -921,7 +935,7 @@
 %ifarch ppc64le
 	--enable-targets=powerpcle-linux \
 %endif
-%ifarch ppc64le %{mips} riscv64
+%ifarch ppc64le %{mips}
 	--disable-multilib \
 %else
 	--enable-multilib \
@@ -1003,19 +1017,14 @@
 %endif
 %ifarch s390 s390x
 %if 0%{?rhel} >= 7
-%if 0%{?rhel} >= 8
-	--with-arch=zEC12 --with-tune=z13 \
-%else
-	--with-arch=z196 --with-tune=zEC12 \
-%endif
+	--with-arch=z196 --with-tune=zEC12 --enable-decimal-float \
 %else
 %if 0%{?fedora} >= 26
-	--with-arch=zEC12 --with-tune=z13 \
+	--with-arch=zEC12 --with-tune=z13 --enable-decimal-float \
 %else
-	--with-arch=z9-109 --with-tune=z10 \
+	--with-arch=z9-109 --with-tune=z10 --enable-decimal-float \
 %endif
 %endif
-	--enable-decimal-float \
 %endif
 %ifarch armv7hl
 	--with-tune=generic-armv7-a --with-arch=armv7-a \
@@ -1040,7 +1049,7 @@
 	--enable-languages=c,c++,objc,obj-c++,fortran${enablelada}${enablelgo},lto \
 	$CONFIGURE_OPTS
 
-%ifarch sparc sparcv9 sparc64
+%ifarch sparc sparcv9 sparc64 riscv64
 make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" bootstrap
 %else
 make %{?_smp_mflags} BOOT_CFLAGS="$OPT_FLAGS" profiledbootstrap
@@ -1130,6 +1139,17 @@
 
 %install
 rm -rf %{buildroot}
+mkdir -p %{buildroot}
+
+%ifarch riscv64
+# RISC-V ABI wants to install everything in /lib64/lp64d or /usr/lib64/lp64d.
+# Make these be symlinks to /lib64 or /usr/lib64 respectively.  See:
+# https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/DRHT5YTPK4WWVGL3GIN5BF2IKX2ODHZ3/
+for d in %{buildroot}%{_libdir} %{buildroot}/%{_lib} %{buildroot}%{_datadir}/gdb/auto-load/%{_prefix}/%{_lib} %{buildroot}%{_prefix}/include/c++/%{gcc_major}/%{gcc_target_platform}/%{_lib}; do
+  mkdir -p $d
+  (cd $d && ln -sf . lp64d)
+done
+%endif
 
 %if %{build_offload_nvptx}
 cd nvptx-tools-%{nvptx_tools_gitrev}
@@ -1183,6 +1203,13 @@
 ln -sf gcc %{buildroot}%{_prefix}/bin/gnatgcc
 mkdir -p %{buildroot}%{_fmoddir}
 
+%ifarch riscv64
+# libcc1.so is ELF 64-bit binary thus we move it to _libdir
+# It's only used by GDB for on-demand compilation and code injection support
+# GDB will use dlopen() to load libcc1.so
+mv %{buildroot}%{_prefix}/lib/libcc1.so* %{buildroot}%{_libdir}
+%endif
+
 %if %{build_go}
 mv %{buildroot}%{_prefix}/bin/go{,.gcc}
 mv %{buildroot}%{_prefix}/bin/gofmt{,.gcc}
@@ -2484,6 +2511,10 @@
 %dir %{_datadir}/gdb/auto-load
 %dir %{_datadir}/gdb/auto-load/%{_prefix}
 %dir %{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/
+%ifarch riscv64
+# Package symlink to keep compatibility
+%{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/lp64d
+%endif
 %{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/libstdc*gdb.py*
 %{_datadir}/gdb/auto-load/%{_prefix}/%{_lib}/__pycache__
 %dir %{_prefix}/share/gcc-%{gcc_major}
@@ -3069,32 +3100,6 @@
 %endif
 
 %changelog
-* Sat Mar 24 2018 Jakub Jelinek <jakub@redhat.com> 8.0.1-0.20
-- update from the trunk
-  - PRs ada/85007, ada/85036, bootstrap/84856, c++/71251, c++/71638,
-	c++/71834, c++/71965, c++/78489, c++/81311, c++/84610, c++/84642,
-	c++/84729, c++/84789, c++/84804, c++/84812, c++/84835, c++/84836,
-	c++/84850, c++/84854, c++/84892, c++/84925, c++/84927, c++/84937,
-	c++/84942, c++/84961, c++/84962, c++/84970, c++/84972, c++/84978,
-	c++/84994, c++/85008, c++/85015, c++/85033, c++/85045, c/80778,
-	c/84953, c/84999, debug/84875, debug/85020, fortran/65453,
-	fortran/77414, fortran/79929, fortran/84615, fortran/84922,
-	fortran/84931, fortran/84957, fortran/85001, inline-asm/84941,
-	inline-asm/85022, inline-asm/85030, inline-asm/85034, ipa/84825,
-	ipa/84963, libstdc++/77691, libstdc++/84998, rtl-optimization/84635,
-	rtl-optimization/84643, rtl-optimization/84989, sanitizer/78651,
-	sanitizer/84761, sanitizer/85018, sanitizer/85029, target/81647,
-	target/82518, target/82989, target/83789, target/84760, target/84826,
-	target/84838, target/84845, target/84945, target/84952, target/84954,
-	target/84986, target/84988, target/84990, target/85025, target/85026,
-	tree-optimization/83126, tree-optimization/84811,
-	tree-optimization/84859, tree-optimization/84913,
-	tree-optimization/84929, tree-optimization/84933,
-	tree-optimization/84946, tree-optimization/84956,
-	tree-optimization/84960, tree-optimization/84969,
-	tree-optimization/84982
-  - fix std::less etc. (#1559171, PR libstdc++/85040)
-
 * Sat Mar 17 2018 Jakub Jelinek <jakub@redhat.com> 8.0.1-0.19
 - update from the trunk
   - PRs ada/82813, c++/79085, c++/79937, c++/80227, c++/81236, c++/82336,
@@ -3102,7 +3107,7 @@
 	c++/84720, c++/84798, c++/84801, c++/84820, c++/84839, c++/84843,
 	c++/84874, c++/84906, c/46921, c/84852, c/84853, c/84873, c/84909,
 	c/84910, fortran/61775, fortran/69395, fortran/78741, ipa/84658,
-	ipa/84722, ipa/84805, ipa/84833, libgfortran/84880, libstdc++/78420,
+	ipa/84722, ipa/8480, ipa/84833, libgfortran/84880, libstdc++/78420,
 	libstdc++/83662, libstdc++/84773, lto/84805, middle-end/84831,
 	middle-end/84834, sanitizer/83392, target/68256, target/78090,
 	target/83451, target/84574, target/84711, target/84743, target/84827,
