diff --git a/0034-Loongarch-add-clobber-for-csr-builtin.patch b/0034-Loongarch-add-clobber-for-csr-builtin.patch
new file mode 100644
index 0000000000000000000000000000000000000000..4fb70ea45ed0b69994a0d1c5845b33b452895d74
--- /dev/null
+++ b/0034-Loongarch-add-clobber-for-csr-builtin.patch
@@ -0,0 +1,109 @@
+diff -uNr gcc-10.3.0.org/gcc/config/loongarch/loongarch-builtins.c gcc-10.3.0/gcc/config/loongarch/loongarch-builtins.c
+--- gcc-10.3.0.org/gcc/config/loongarch/loongarch-builtins.c 2022-04-06 16:26:45.084375233 +0800
++++ gcc-10.3.0/gcc/config/loongarch/loongarch-builtins.c 2022-04-06 16:37:45.574942820 +0800
+@@ -442,41 +442,7 @@
+ loongarch_expand_builtin_insn (enum insn_code icode, unsigned int nops,
+ struct expand_operand *ops, bool has_target_p)
+ {
+- int error_opno = 0, rangelo = 0, rangehi =0 ;
+-
+- switch(icode){
+- case CODE_FOR_csrrd:
+- case CODE_FOR_dcsrrd:
+- case CODE_FOR_csrwr:
+- case CODE_FOR_dcsrwr:
+- case CODE_FOR_csrxchg:
+- case CODE_FOR_dcsrxchg:
+- case CODE_FOR_iocsrrd_b:
+- case CODE_FOR_iocsrrd_h:
+- case CODE_FOR_iocsrrd_w:
+- case CODE_FOR_iocsrrd_d:
+- case CODE_FOR_iocsrwr_b:
+- case CODE_FOR_iocsrwr_h:
+- case CODE_FOR_iocsrwr_w:
+- case CODE_FOR_iocsrwr_d:
+- if (!maybe_expand_insn (icode, nops, ops))
+- {
+- error ("invalid argument to built-in function");
+- return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx;
+- }
+- emit_barrier();
+- break;
+- default:
+- break;
+- }
+-
+- if (error_opno != 0)
+- {
+- error ("argument %d to the built-in must be a constant"
+- " in range %d to %d", error_opno, rangelo, rangehi);
+- return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx;
+- }
+- else if (!maybe_expand_insn (icode, nops, ops))
++ if (!maybe_expand_insn (icode, nops, ops))
+ {
+ error ("invalid argument to built-in function");
+ return has_target_p ? gen_reg_rtx (ops[0].mode) : const0_rtx;
+diff -uNr gcc-10.3.0.org/gcc/config/loongarch/loongarch.md gcc-10.3.0/gcc/config/loongarch/loongarch.md
+--- gcc-10.3.0.org/gcc/config/loongarch/loongarch.md 2022-04-06 16:26:45.091375154 +0800
++++ gcc-10.3.0/gcc/config/loongarch/loongarch.md 2022-04-06 16:37:45.575942809 +0800
+@@ -2599,7 +2599,8 @@
+ "ibar\t%0")
+
+ (define_insn "dbar"
+- [(unspec_volatile:SI [(match_operand 0 "const_uimm15_operand")] UNSPEC_DBAR)]
++ [(unspec_volatile:SI [(match_operand 0 "const_uimm15_operand")] UNSPEC_DBAR)
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "dbar\t%0")
+
+@@ -2637,7 +2638,8 @@
+ (define_insn "
csrrd"
+ [(set (match_operand:GPR 0 "register_operand" "=d")
+ (unspec_volatile:GPR [(match_operand 1 "const_uimm14_operand")]
+- UNSPEC_CSRRD))]
++ UNSPEC_CSRRD))
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "csrrd\t%0,%1"
+ [(set_attr "type" "load")
+@@ -2648,7 +2650,8 @@
+ (unspec_volatile:GPR
+ [(match_operand:GPR 1 "register_operand" "0")
+ (match_operand 2 "const_uimm14_operand")]
+- UNSPEC_CSRWR))]
++ UNSPEC_CSRWR))
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "csrwr\t%0,%2"
+ [(set_attr "type" "store")
+@@ -2660,7 +2663,8 @@
+ [(match_operand:GPR 1 "register_operand" "0")
+ (match_operand:GPR 2 "register_operand" "q")
+ (match_operand 3 "const_uimm14_operand")]
+- UNSPEC_CSRXCHG))]
++ UNSPEC_CSRXCHG))
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "csrxchg\t%0,%2,%3"
+ [(set_attr "type" "load")
+@@ -2669,7 +2673,8 @@
+ (define_insn "iocsrrd_"
+ [(set (match_operand:QHWD 0 "register_operand" "=d")
+ (unspec_volatile:QHWD [(match_operand:SI 1 "register_operand" "d")]
+- UNSPEC_IOCSRRD))]
++ UNSPEC_IOCSRRD))
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "iocsrrd.\t%0,%1"
+ [(set_attr "type" "load")
+@@ -2678,7 +2683,8 @@
+ (define_insn "iocsrwr_"
+ [(unspec_volatile:QHWD [(match_operand:QHWD 0 "register_operand" "d")
+ (match_operand:SI 1 "register_operand" "d")]
+- UNSPEC_IOCSRWR)]
++ UNSPEC_IOCSRWR)
++ (clobber (mem:BLK (scratch)))]
+ ""
+ "iocsrwr.\t%0,%1"
+ [(set_attr "type" "load")
diff --git a/0035-Fixup-missing-file-error.patch b/0035-Fixup-missing-file-error.patch
new file mode 100644
index 0000000000000000000000000000000000000000..ac3196e671e236b11479e198ea79f1a4d699b677
--- /dev/null
+++ b/0035-Fixup-missing-file-error.patch
@@ -0,0 +1,29 @@
+diff -uNr gcc-10.3.0.org/libgcc/config/loongarch/lib2funcs.c gcc-10.3.0/libgcc/config/loongarch/lib2funcs.c
+--- gcc-10.3.0.org/libgcc/config/loongarch/lib2funcs.c 1970-01-01 08:00:00.000000000 +0800
++++ gcc-10.3.0/libgcc/config/loongarch/lib2funcs.c 2022-04-06 17:09:49.899785626 +0800
+@@ -0,0 +1,25 @@
++/* libgcc routines for LOONGARCH
++ Copyright (C) 2013-2020 Free Software Foundation, Inc.
++ DMULT/DDIV replacement support by Juergen Urban, JuergenUrban@gmx.de.
++
++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.
++
++Under Section 7 of GPL version 3, you are granted additional
++permissions described in the GCC Runtime Library Exception, version
++3.1, as published by the Free Software Foundation.
++
++You should have received a copy of the GNU General Public License and
++a copy of the GCC Runtime Library Exception along with this program;
++see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
++. */
++
diff --git a/gcc.spec b/gcc.spec
index e9b52f63fef615910f6adc4179db0485bdc38b57..97c3e996c3f05f5fcfaa269709a4922b9b618acb 100644
--- a/gcc.spec
+++ b/gcc.spec
@@ -61,7 +61,7 @@
Summary: Various compilers (C, C++, Objective-C, ...)
Name: gcc
Version: %{gcc_version}
-Release: 10
+Release: 12
License: GPLv3+ and GPLv3+ with exceptions and GPLv2+ with exceptions and LGPLv2+ and BSD
URL: https://gcc.gnu.org
@@ -149,6 +149,8 @@ Patch30: 0030-AutoBOLT-Add-bolt-linker-plugin-2-3.patch
Patch31: 0031-AutoBOLT-Enable-BOLT-linker-plugin-on-aarch64-3-3.patch
Patch32: 0032-Autoprefetch-Prune-invaild-loops-containing-edges-wh.patch
Patch33: 0033-Add-Loongarch-backend-support.patch
+Patch34: 0034-Loongarch-add-clobber-for-csr-builtin.patch
+Patch35: 0035-Fixup-missing-file-error.patch
%global gcc_target_platform %{_arch}-linux-gnu
@@ -623,6 +625,8 @@ not stable, so plugins must be rebuilt any time GCC is updated.
%patch31 -p1
%patch32 -p1
%patch33 -p1
+%patch34 -p1
+%patch35 -p1
%build
@@ -707,7 +711,7 @@ CC="$CC" CFLAGS="$OPT_FLAGS" \
%endif
%ifarch loongarch64
--with-arch=loongarch64 --with-abi=lp64 \
- --disable-libquadmath --disable-multilib
+ --disable-libquadmath --disable-multilib --enable-tls
%endif
%ifarch sparc sparcv9 sparc64
@@ -2592,6 +2596,18 @@ end
%doc rpm.doc/changelogs/libcc1/ChangeLog*
%changelog
+* Mon Apr 06 2022 lixing - 10.3.1-12
+- Type:requirements
+- ID:NA
+- SUG:NA
+- DESC:Fixup Loongarch missing file error
+
+* Mon Apr 06 2022 lixing - 10.3.1-11
+- Type:requirements
+- ID:NA
+- SUG:NA
+- DESC:Fixup Loongarch csr access error
+
* Mon Mar 28 2022 lixing - 10.3.1-10
- Type:requirements
- ID:NA