summaryrefslogtreecommitdiff
path: root/patches/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'patches/gcc')
-rw-r--r--patches/gcc/4.8.5/111-alpha-bad-eh_frame.patch13
-rw-r--r--patches/gcc/4.8.5/874-gcc-xtensa-fix-fprintf-format-specifiers.patch73
-rw-r--r--patches/gcc/4.9.4/1100-msp430-string-literals.patch27
-rw-r--r--patches/gcc/4.9.4/111-alpha-bad-eh_frame.patch13
-rw-r--r--patches/gcc/4.9.4/875-gcc-xtensa-fix-fprintf-format-specifiers.patch73
-rw-r--r--patches/gcc/5.4.0/1100-msp430-string-literals.patch81
-rw-r--r--patches/gcc/5.4.0/111-alpha-bad-eh_frame.patch13
-rw-r--r--patches/gcc/5.4.0/879-gcc-xtensa-fix-fprintf-format-specifiers.patch74
-rw-r--r--patches/gcc/6.3.0/1100-ubsan-fix-check-empty-string.patch28
-rw-r--r--patches/gcc/6.3.0/111-alpha-bad-eh_frame.patch13
-rw-r--r--patches/gcc/6.3.0/873-gcc-xtensa-fix-fprintf-format-specifiers.patch74
-rw-r--r--patches/gcc/6.3.0/951-bionic-ndk.patch58
-rw-r--r--patches/gcc/6.3.0/952-bionic-errno.patch19
-rw-r--r--patches/gcc/6.3.0/970-crystax.patch551
-rw-r--r--patches/gcc/6.3.0/971-crystax.patch25
-rw-r--r--patches/gcc/6.3.0/972-crystax.patch302
-rw-r--r--patches/gcc/6.3.0/973-crystax.patch20
-rw-r--r--patches/gcc/6.3.0/974-crystax.patch24
-rw-r--r--patches/gcc/6.3.0/975-crystax.patch31
-rw-r--r--patches/gcc/6.3.0/976-crystax.patch21
-rw-r--r--patches/gcc/6.3.0/977-crystax.patch33
-rw-r--r--patches/gcc/7.1.0/100-uclibc-conf.patch (renamed from patches/gcc/linaro-6.3-2017.02/100-uclibc-conf.patch)0
-rw-r--r--patches/gcc/7.1.0/1000-libtool-leave-framework-alone.patch (renamed from patches/gcc/linaro-6.3-2017.02/1000-libtool-leave-framework-alone.patch)0
-rw-r--r--patches/gcc/7.1.0/111-alpha-bad-eh_frame.patch13
-rw-r--r--patches/gcc/7.1.0/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch (renamed from patches/gcc/linaro-6.3-2017.02/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch)0
-rw-r--r--patches/gcc/7.1.0/380-gcc-plugin-POSIX-include-sys-select-h.patch (renamed from patches/gcc/linaro-6.3-2017.02/380-gcc-plugin-POSIX-include-sys-select-h.patch)0
-rw-r--r--patches/gcc/7.1.0/810-arm-softfloat-libgcc.patch (renamed from patches/gcc/linaro-6.3-2017.02/810-arm-softfloat-libgcc.patch)0
-rw-r--r--patches/gcc/7.1.0/860-cilk-wchar.patch (renamed from patches/gcc/linaro-6.3-2017.02/860-cilk-wchar.patch)0
-rw-r--r--patches/gcc/7.1.0/870-gcc-xtensa-fix-fprintf-format-specifiers.patch74
-rw-r--r--patches/gcc/7.1.0/891-fix-m68k-uclinux.patch (renamed from patches/gcc/linaro-6.3-2017.02/891-fix-m68k-uclinux.patch)0
-rw-r--r--patches/gcc/7.1.0/900-libgfortran-missing-include.patch (renamed from patches/gcc/linaro-6.3-2017.02/900-libgfortran-missing-include.patch)0
-rw-r--r--patches/gcc/7.1.0/910-nios2-bad-multilib-default.patch (renamed from patches/gcc/linaro-6.3-2017.02/910-nios2-bad-multilib-default.patch)0
-rw-r--r--patches/gcc/7.1.0/930-libgcc-disable-split-stack-nothreads.patch (renamed from patches/gcc/linaro-6.3-2017.02/930-libgcc-disable-split-stack-nothreads.patch)0
-rw-r--r--patches/gcc/7.1.0/951-bionic-ndk.patch58
-rw-r--r--patches/gcc/7.1.0/952-bionic-errno.patch19
-rw-r--r--patches/gcc/7.1.0/970-crystax.patch553
-rw-r--r--patches/gcc/7.1.0/971-crystax.patch25
-rw-r--r--patches/gcc/7.1.0/972-crystax.patch302
-rw-r--r--patches/gcc/7.1.0/973-crystax.patch20
-rw-r--r--patches/gcc/7.1.0/974-crystax.patch24
-rw-r--r--patches/gcc/7.1.0/975-crystax.patch31
-rw-r--r--patches/gcc/7.1.0/976-crystax.patch21
-rw-r--r--patches/gcc/7.1.0/977-crystax.patch33
-rw-r--r--patches/gcc/linaro-4.8-2015.06/874-gcc-xtensa-fix-fprintf-format-specifiers.patch73
-rw-r--r--patches/gcc/linaro-4.9-2017.01/1100-msp430-string-literals.patch27
-rw-r--r--patches/gcc/linaro-4.9-2017.01/875-gcc-xtensa-fix-fprintf-format-specifiers.patch73
-rw-r--r--patches/gcc/linaro-5.4-2017.05/100-uclibc-conf.patch (renamed from patches/gcc/linaro-5.4-2017.01/100-uclibc-conf.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/1000-libtool-leave-framework-alone.patch (renamed from patches/gcc/linaro-5.4-2017.01/1000-libtool-leave-framework-alone.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/110-xtensa-implement-trap-pattern.patch (renamed from patches/gcc/linaro-5.4-2017.01/110-xtensa-implement-trap-pattern.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/1100-msp430-string-literals.patch81
-rw-r--r--patches/gcc/linaro-5.4-2017.05/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch (renamed from patches/gcc/linaro-5.4-2017.01/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/301-missing-execinfo_h.patch (renamed from patches/gcc/linaro-6.3-2017.02/301-missing-execinfo_h.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch (renamed from patches/gcc/linaro-5.4-2017.01/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch (renamed from patches/gcc/linaro-5.4-2017.01/380-gcc-plugin-POSIX-include-sys-select-h.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/810-arm-softfloat-libgcc.patch (renamed from patches/gcc/linaro-5.4-2017.01/810-arm-softfloat-libgcc.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/830-arm_unbreak_armv4t.patch (renamed from patches/gcc/linaro-6.3-2017.02/830-arm_unbreak_armv4t.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/840-microblaze-enable-dwarf-eh-support.patch (renamed from patches/gcc/linaro-5.4-2017.01/840-microblaze-enable-dwarf-eh-support.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/850-libstdcxx-uclibc-c99.patch (renamed from patches/gcc/linaro-5.4-2017.01/850-libstdcxx-uclibc-c99.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/860-cilk-wchar.patch (renamed from patches/gcc/linaro-5.4-2017.01/860-cilk-wchar.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/870-xtensa-add-mauto-litpools-option.patch (renamed from patches/gcc/linaro-5.4-2017.01/870-xtensa-add-mauto-litpools-option.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/871-xtensa-reimplement-register-spilling.patch (renamed from patches/gcc/linaro-5.4-2017.01/871-xtensa-reimplement-register-spilling.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch (renamed from patches/gcc/linaro-5.4-2017.01/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/873-xtensa-fix-_Unwind_GetCFA.patch (renamed from patches/gcc/linaro-5.4-2017.01/873-xtensa-fix-_Unwind_GetCFA.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/874-xtensa-add-uclinux-support.patch (renamed from patches/gcc/linaro-5.4-2017.01/874-xtensa-add-uclinux-support.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch (renamed from patches/gcc/linaro-5.4-2017.01/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/876-xtensa-fix-libgcc-build-with-text-section-literals.patch (renamed from patches/gcc/linaro-5.4-2017.01/876-xtensa-fix-libgcc-build-with-text-section-literals.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch (renamed from patches/gcc/linaro-5.4-2017.01/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/878-xtensa-Fix-PR-target-78603.patch (renamed from patches/gcc/linaro-5.4-2017.01/878-xtensa-Fix-PR-target-78603.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/879-gcc-xtensa-fix-fprintf-format-specifiers.patch74
-rw-r--r--patches/gcc/linaro-5.4-2017.05/890-fix-m68k-compile.patch (renamed from patches/gcc/linaro-6.3-2017.02/890-fix-m68k-compile.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/891-fix-m68k-uclinux.patch (renamed from patches/gcc/linaro-5.4-2017.01/891-fix-m68k-uclinux.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/892-microblaze-uclibc.patch (renamed from patches/gcc/linaro-5.4-2017.01/892-microblaze-uclibc.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/902-unwind-fix-for-musl.patch (renamed from patches/gcc/linaro-5.4-2017.01/902-unwind-fix-for-musl.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/910-nios2-bad-multilib-default.patch (renamed from patches/gcc/linaro-5.4-2017.01/910-nios2-bad-multilib-default.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/930-libgcc-disable-split-stack-nothreads.patch (renamed from patches/gcc/linaro-5.4-2017.01/930-libgcc-disable-split-stack-nothreads.patch)0
-rw-r--r--patches/gcc/linaro-5.4-2017.05/940-uclinux-enable-threads.patch (renamed from patches/gcc/linaro-6.3-2017.02/940-uclinux-enable-threads.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/100-uclibc-conf.patch15
-rw-r--r--patches/gcc/linaro-6.3-2017.05/1000-libtool-leave-framework-alone.patch14
-rw-r--r--patches/gcc/linaro-6.3-2017.05/301-missing-execinfo_h.patch (renamed from patches/gcc/linaro-5.4-2017.01/301-missing-execinfo_h.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch160
-rw-r--r--patches/gcc/linaro-6.3-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch11
-rw-r--r--patches/gcc/linaro-6.3-2017.05/810-arm-softfloat-libgcc.patch30
-rw-r--r--patches/gcc/linaro-6.3-2017.05/830-arm_unbreak_armv4t.patch (renamed from patches/gcc/linaro-5.4-2017.01/830-arm_unbreak_armv4t.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/860-cilk-wchar.patch56
-rw-r--r--patches/gcc/linaro-6.3-2017.05/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch (renamed from patches/gcc/linaro-6.3-2017.02/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/871-xtensa-Fix-PR-target-78118.patch (renamed from patches/gcc/linaro-6.3-2017.02/871-xtensa-Fix-PR-target-78118.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/872-xtensa-Fix-PR-target-78603.patch (renamed from patches/gcc/linaro-6.3-2017.02/872-xtensa-Fix-PR-target-78603.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/873-gcc-xtensa-fix-fprintf-format-specifiers.patch74
-rw-r--r--patches/gcc/linaro-6.3-2017.05/890-fix-m68k-compile.patch (renamed from patches/gcc/linaro-5.4-2017.01/890-fix-m68k-compile.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/891-fix-m68k-uclinux.patch18
-rw-r--r--patches/gcc/linaro-6.3-2017.05/892-libgcc-mkmap-symver-support-skip_underscore.patch (renamed from patches/gcc/linaro-6.3-2017.02/892-libgcc-mkmap-symver-support-skip_underscore.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch (renamed from patches/gcc/linaro-6.3-2017.02/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch (renamed from patches/gcc/linaro-6.3-2017.02/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/895-bfin-define-REENTRANT.patch (renamed from patches/gcc/linaro-6.3-2017.02/895-bfin-define-REENTRANT.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/900-libgfortran-missing-include.patch10
-rw-r--r--patches/gcc/linaro-6.3-2017.05/910-nios2-bad-multilib-default.patch28
-rw-r--r--patches/gcc/linaro-6.3-2017.05/930-libgcc-disable-split-stack-nothreads.patch14
-rw-r--r--patches/gcc/linaro-6.3-2017.05/940-uclinux-enable-threads.patch (renamed from patches/gcc/linaro-5.4-2017.01/940-uclinux-enable-threads.patch)0
-rw-r--r--patches/gcc/linaro-6.3-2017.05/951-bionic-ndk.patch58
-rw-r--r--patches/gcc/linaro-6.3-2017.05/952-bionic-errno.patch19
-rw-r--r--patches/gcc/linaro-6.3-2017.05/970-crystax.patch551
-rw-r--r--patches/gcc/linaro-6.3-2017.05/971-crystax.patch25
-rw-r--r--patches/gcc/linaro-6.3-2017.05/972-crystax.patch302
-rw-r--r--patches/gcc/linaro-6.3-2017.05/973-crystax.patch20
-rw-r--r--patches/gcc/linaro-6.3-2017.05/974-crystax.patch24
-rw-r--r--patches/gcc/linaro-6.3-2017.05/975-crystax.patch31
-rw-r--r--patches/gcc/linaro-6.3-2017.05/976-crystax.patch21
-rw-r--r--patches/gcc/linaro-6.3-2017.05/977-crystax.patch33
108 files changed, 4581 insertions, 0 deletions
diff --git a/patches/gcc/4.8.5/111-alpha-bad-eh_frame.patch b/patches/gcc/4.8.5/111-alpha-bad-eh_frame.patch
new file mode 100644
index 0000000..93f6e94
--- /dev/null
+++ b/patches/gcc/4.8.5/111-alpha-bad-eh_frame.patch
@@ -0,0 +1,13 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80037
+
+diff --git a/libgcc/config/alpha/t-alpha b/libgcc/config/alpha/t-alpha
+index 0b6ffb1..0c2f840 100644
+--- a/libgcc/config/alpha/t-alpha
++++ b/libgcc/config/alpha/t-alpha
+@@ -1,2 +1,6 @@
+ # This is a support routine for longlong.h, used by libgcc2.c.
+ LIB2ADD += $(srcdir)/config/alpha/qrnnd.S
++
++# When GAS-generated unwind tables are created, they get created
++# after the __FRAME_END__ terminator, which causes an ld error.
++CRTSTUFF_T_CFLAGS = -fno-unwind-tables
diff --git a/patches/gcc/4.8.5/874-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/4.8.5/874-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..6013fef
--- /dev/null
+++ b/patches/gcc/4.8.5/874-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,73 @@
+From 0343a584d6b5128908eabf1db43c70bed7114989 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index dbc5bd3..466adb5 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1772,7 +1772,7 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call8\t0x%lx", INTVAL (tgt));
++ sprintf (result, "call8\t" HOST_WIDE_INT_PRINT_HEX, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx8\t%%%d", callop);
+ else
+@@ -2347,14 +2347,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2368,7 +2368,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2437,7 +2437,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/4.9.4/1100-msp430-string-literals.patch b/patches/gcc/4.9.4/1100-msp430-string-literals.patch
new file mode 100644
index 0000000..346842e
--- /dev/null
+++ b/patches/gcc/4.9.4/1100-msp430-string-literals.patch
@@ -0,0 +1,27 @@
+commit 9d247a3d78b97c004e7ca5e7d6cc9964dba870c7
+Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Wed May 13 01:11:13 2015 +0000
+
+ gcc/
+ * config/mmix/mmix.c, config/msp430/msp430.c: Add space between
+ string literal and macro name.
+ gcc/ada/
+ * sigtramp-vxworks.c: Add space between string literal and macro
+ name.
+
+ git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223106 138bc75d-0d04-0410-961f-82ee72b054a4
+
+[4.9 change: remove non-applicable parts of the patch]
+diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
+index bec168ca2ae..58d0efea1de 100644
+--- a/gcc/config/msp430/msp430.c
++++ b/gcc/config/msp430/msp430.c
+@@ -2248,7 +2248,7 @@ static struct
+ }
+ const_shift_helpers[] =
+ {
+-#define CSH(N,C,X,G) { "__mspabi_"N, C, X, gen_##G }
++#define CSH(N,C,X,G) { "__mspabi_" N, C, X, gen_##G }
+
+ CSH ("slli", 1, 1, slli_1),
+ CSH ("slll", 1, 1, slll_1),
diff --git a/patches/gcc/4.9.4/111-alpha-bad-eh_frame.patch b/patches/gcc/4.9.4/111-alpha-bad-eh_frame.patch
new file mode 100644
index 0000000..93f6e94
--- /dev/null
+++ b/patches/gcc/4.9.4/111-alpha-bad-eh_frame.patch
@@ -0,0 +1,13 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80037
+
+diff --git a/libgcc/config/alpha/t-alpha b/libgcc/config/alpha/t-alpha
+index 0b6ffb1..0c2f840 100644
+--- a/libgcc/config/alpha/t-alpha
++++ b/libgcc/config/alpha/t-alpha
+@@ -1,2 +1,6 @@
+ # This is a support routine for longlong.h, used by libgcc2.c.
+ LIB2ADD += $(srcdir)/config/alpha/qrnnd.S
++
++# When GAS-generated unwind tables are created, they get created
++# after the __FRAME_END__ terminator, which causes an ld error.
++CRTSTUFF_T_CFLAGS = -fno-unwind-tables
diff --git a/patches/gcc/4.9.4/875-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/4.9.4/875-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..052ffc3
--- /dev/null
+++ b/patches/gcc/4.9.4/875-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,73 @@
+From 0f32ae7bc51725cd500e2877b571fd914d77852e Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index d8c8298..3c00961 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1785,7 +1785,7 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call8\t0x%lx", INTVAL (tgt));
++ sprintf (result, "call8\t" HOST_WIDE_INT_PRINT_HEX, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx8\t%%%d", callop);
+ else
+@@ -2360,14 +2360,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2381,7 +2381,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2450,7 +2450,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/5.4.0/1100-msp430-string-literals.patch b/patches/gcc/5.4.0/1100-msp430-string-literals.patch
new file mode 100644
index 0000000..819d6d2
--- /dev/null
+++ b/patches/gcc/5.4.0/1100-msp430-string-literals.patch
@@ -0,0 +1,81 @@
+commit 9d247a3d78b97c004e7ca5e7d6cc9964dba870c7
+Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Wed May 13 01:11:13 2015 +0000
+
+ gcc/
+ * config/mmix/mmix.c, config/msp430/msp430.c: Add space between
+ string literal and macro name.
+ gcc/ada/
+ * sigtramp-vxworks.c: Add space between string literal and macro
+ name.
+
+ git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223106 138bc75d-0d04-0410-961f-82ee72b054a4
+
+diff --git a/gcc/ada/sigtramp-vxworks.c b/gcc/ada/sigtramp-vxworks.c
+index 2119296dc1d..c697626a03e 100644
+--- a/gcc/ada/sigtramp-vxworks.c
++++ b/gcc/ada/sigtramp-vxworks.c
+@@ -342,16 +342,16 @@ CR("") \
+ TCR("# Allocate frame and save the non-volatile") \
+ TCR("# registers we're going to modify") \
+ TCR("mov ip, sp") \
+-TCR("stmfd sp!, {r"S(CFA_REG)", fp, ip, lr, pc}") \
++TCR("stmfd sp!, {r" S(CFA_REG)", fp, ip, lr, pc}") \
+ TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
+-TCR("ldr r"S(CFA_REG)", [ip]") \
++TCR("ldr r" S(CFA_REG)", [ip]") \
+ TCR("") \
+ TCR("# Call the real handler. The signo, siginfo and sigcontext") \
+ TCR("# arguments are the same as those we received in r0, r1 and r2") \
+ TCR("sub fp, ip, #4") \
+ TCR("blx r3") \
+ TCR("# Restore our callee-saved items, release our frame and return") \
+-TCR("ldmfd sp, {r"S(CFA_REG)", fp, sp, pc}")
++TCR("ldmfd sp, {r" S(CFA_REG)", fp, sp, pc}")
+
+ #else
+ Not_implemented;
+diff --git a/gcc/config/mmix/mmix.c b/gcc/config/mmix/mmix.c
+index 6e991207dbc..e0699854e25 100644
+--- a/gcc/config/mmix/mmix.c
++++ b/gcc/config/mmix/mmix.c
+@@ -2520,7 +2520,7 @@ mmix_output_shiftvalue_op_from_str (FILE *stream,
+ if (! mmix_shiftable_wyde_value (value))
+ {
+ char s[sizeof ("0xffffffffffffffff")];
+- sprintf (s, "%#"PRIx64, value);
++ sprintf (s, "%#" PRIx64, value);
+ internal_error ("MMIX Internal: %s is not a shiftable int", s);
+ }
+
+@@ -2562,7 +2562,7 @@ mmix_output_octa (FILE *stream, int64_t value, int do_begin_end)
+ fprintf (stream, "#" HOST_WIDE_INT_PRINT_HEX_PURE,
+ (HOST_WIDE_INT) value);
+ else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
+- fprintf (stream, "%"PRIu64, value);
++ fprintf (stream, "%" PRIu64, value);
+
+ if (do_begin_end)
+ fprintf (stream, "\n");
+@@ -2579,7 +2579,7 @@ mmix_output_shifted_value (FILE *stream, int64_t value)
+ if (! mmix_shiftable_wyde_value (value))
+ {
+ char s[16+2+1];
+- sprintf (s, "%#"PRIx64, value);
++ sprintf (s, "%#" PRIx64, value);
+ internal_error ("MMIX Internal: %s is not a shiftable int", s);
+ }
+
+diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
+index bec168ca2ae..58d0efea1de 100644
+--- a/gcc/config/msp430/msp430.c
++++ b/gcc/config/msp430/msp430.c
+@@ -2248,7 +2248,7 @@ static struct
+ }
+ const_shift_helpers[] =
+ {
+-#define CSH(N,C,X,G) { "__mspabi_"N, C, X, gen_##G }
++#define CSH(N,C,X,G) { "__mspabi_" N, C, X, gen_##G }
+
+ CSH ("slli", 1, 1, slli_1),
+ CSH ("slll", 1, 1, slll_1),
diff --git a/patches/gcc/5.4.0/111-alpha-bad-eh_frame.patch b/patches/gcc/5.4.0/111-alpha-bad-eh_frame.patch
new file mode 100644
index 0000000..93f6e94
--- /dev/null
+++ b/patches/gcc/5.4.0/111-alpha-bad-eh_frame.patch
@@ -0,0 +1,13 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80037
+
+diff --git a/libgcc/config/alpha/t-alpha b/libgcc/config/alpha/t-alpha
+index 0b6ffb1..0c2f840 100644
+--- a/libgcc/config/alpha/t-alpha
++++ b/libgcc/config/alpha/t-alpha
+@@ -1,2 +1,6 @@
+ # This is a support routine for longlong.h, used by libgcc2.c.
+ LIB2ADD += $(srcdir)/config/alpha/qrnnd.S
++
++# When GAS-generated unwind tables are created, they get created
++# after the __FRAME_END__ terminator, which causes an ld error.
++CRTSTUFF_T_CFLAGS = -fno-unwind-tables
diff --git a/patches/gcc/5.4.0/879-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/5.4.0/879-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..e75e258
--- /dev/null
+++ b/patches/gcc/5.4.0/879-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,74 @@
+From 1117c8be9e712f778739d751aa61038794437d7d Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 36ab1e3..8e62d63 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1811,7 +1811,8 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call%d\t0x%lx", WINDOW_SIZE, INTVAL (tgt));
++ sprintf (result, "call%d\t" HOST_WIDE_INT_PRINT_HEX,
++ WINDOW_SIZE, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx%d\t%%%d", WINDOW_SIZE, callop);
+ else
+@@ -2382,14 +2383,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2403,7 +2404,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2472,7 +2473,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/6.3.0/1100-ubsan-fix-check-empty-string.patch b/patches/gcc/6.3.0/1100-ubsan-fix-check-empty-string.patch
new file mode 100644
index 0000000..c012719
--- /dev/null
+++ b/patches/gcc/6.3.0/1100-ubsan-fix-check-empty-string.patch
@@ -0,0 +1,28 @@
+From 8db2cf6353c13f2a84cbe49b689654897906c499 Mon Sep 17 00:00:00 2001
+From: kyukhin <kyukhin@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Sat, 3 Sep 2016 10:57:05 +0000
+Subject: [PATCH] gcc/ * ubsan.c (ubsan_use_new_style_p): Fix check for empty
+ string.
+
+git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239971 138bc75d-0d04-0410-961f-82ee72b054a4
+
+Upstream-Status: Backport
+Signed-off-by: Joshua Lock <joshua.g.lock@intel.com>
+
+---
+ gcc/ubsan.c | 2 +-
+ 2 files changed, 5 insertions(+), 1 deletion(-)
+
+Index: gcc-6.3.0/gcc/ubsan.c
+===================================================================
+--- gcc-6.3.0.orig/gcc/ubsan.c
++++ gcc-6.3.0/gcc/ubsan.c
+@@ -1471,7 +1471,7 @@ ubsan_use_new_style_p (location_t loc)
+
+ expanded_location xloc = expand_location (loc);
+ if (xloc.file == NULL || strncmp (xloc.file, "\1", 2) == 0
+- || xloc.file == '\0' || xloc.file[0] == '\xff'
++ || xloc.file[0] == '\0' || xloc.file[0] == '\xff'
+ || xloc.file[1] == '\xff')
+ return false;
+
diff --git a/patches/gcc/6.3.0/111-alpha-bad-eh_frame.patch b/patches/gcc/6.3.0/111-alpha-bad-eh_frame.patch
new file mode 100644
index 0000000..93f6e94
--- /dev/null
+++ b/patches/gcc/6.3.0/111-alpha-bad-eh_frame.patch
@@ -0,0 +1,13 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80037
+
+diff --git a/libgcc/config/alpha/t-alpha b/libgcc/config/alpha/t-alpha
+index 0b6ffb1..0c2f840 100644
+--- a/libgcc/config/alpha/t-alpha
++++ b/libgcc/config/alpha/t-alpha
+@@ -1,2 +1,6 @@
+ # This is a support routine for longlong.h, used by libgcc2.c.
+ LIB2ADD += $(srcdir)/config/alpha/qrnnd.S
++
++# When GAS-generated unwind tables are created, they get created
++# after the __FRAME_END__ terminator, which causes an ld error.
++CRTSTUFF_T_CFLAGS = -fno-unwind-tables
diff --git a/patches/gcc/6.3.0/873-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/6.3.0/873-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..a5b0624
--- /dev/null
+++ b/patches/gcc/6.3.0/873-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,74 @@
+From a3d07c8a2a9564b57ebcae8463c1541a37c97c34 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 70f698a..2bdf5cc 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1776,7 +1776,8 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call%d\t0x%lx", WINDOW_SIZE, INTVAL (tgt));
++ sprintf (result, "call%d\t" HOST_WIDE_INT_PRINT_HEX,
++ WINDOW_SIZE, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx%d\t%%%d", WINDOW_SIZE, callop);
+ else
+@@ -2347,14 +2348,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2368,7 +2369,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2433,7 +2434,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (GET_MODE (x), XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/6.3.0/951-bionic-ndk.patch b/patches/gcc/6.3.0/951-bionic-ndk.patch
new file mode 100644
index 0000000..59c50a8
--- /dev/null
+++ b/patches/gcc/6.3.0/951-bionic-ndk.patch
@@ -0,0 +1,58 @@
+commit d38d37bdfe24b7ce1bdcb55642fb6b904718e68f
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 19:02:18 2017 -0700
+
+ Fix ctype for newer NDK headers
+
+diff --git a/libstdc++-v3/config/os/bionic/ctype_base.h b/libstdc++-v3/config/os/bionic/ctype_base.h
+index 33978f3..c36e63c 100644
+--- a/libstdc++-v3/config/os/bionic/ctype_base.h
++++ b/libstdc++-v3/config/os/bionic/ctype_base.h
+@@ -28,6 +28,18 @@
+
+ // Information as gleaned from /usr/include/ctype.h
+
++// _CTYPE prefix was added in NDK r14 unified headers
++#ifndef _CTYPE_U
++#define _CTYPE_U _U
++#define _CTYPE_L _L
++#define _CTYPE_D _N
++#define _CTYPE_S _S
++#define _CTYPE_P _P
++#define _CTYPE_C _C
++#define _CTYPE_X _X
++#define _CTYPE_B _B
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -41,17 +53,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ // NB: Offsets into ctype<char>::_M_table force a particular size
+ // on the mask type. Because of this, we don't use an enum.
+ typedef char mask;
+- static const mask upper = _U;
+- static const mask lower = _L;
+- static const mask alpha = _U | _L;
+- static const mask digit = _N;
+- static const mask xdigit = _X | _N;
+- static const mask space = _S;
+- static const mask print = _P | _U | _L | _N | _B;
+- static const mask graph = _P | _U | _L | _N;
+- static const mask cntrl = _C;
+- static const mask punct = _P;
+- static const mask alnum = _U | _L | _N;
++ static const mask upper = _CTYPE_U;
++ static const mask lower = _CTYPE_L;
++ static const mask alpha = _CTYPE_U | _CTYPE_L;
++ static const mask digit = _CTYPE_D;
++ static const mask xdigit = _CTYPE_X | _CTYPE_D;
++ static const mask space = _CTYPE_S;
++ static const mask print = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D | _CTYPE_B;
++ static const mask graph = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D;
++ static const mask cntrl = _CTYPE_C;
++ static const mask punct = _CTYPE_P;
++ static const mask alnum = _CTYPE_U | _CTYPE_L | _CTYPE_D;
+ #if __cplusplus >= 201103L
+ static const mask blank = space;
+ #endif
diff --git a/patches/gcc/6.3.0/952-bionic-errno.patch b/patches/gcc/6.3.0/952-bionic-errno.patch
new file mode 100644
index 0000000..91f6ca3
--- /dev/null
+++ b/patches/gcc/6.3.0/952-bionic-errno.patch
@@ -0,0 +1,19 @@
+commit 6cd4ad106ef87a3c58b0c3478e78409b47000de0
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 20:17:03 2017 -0700
+
+ Fix, errno is volatile int
+
+diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
+index 6ff12d0..5bbd664 100644
+--- a/libstdc++-v3/src/filesystem/dir.cc
++++ b/libstdc++-v3/src/filesystem/dir.cc
+@@ -147,7 +147,7 @@ fs::_Dir::advance(error_code* ec, directory_options options)
+
+ int err = std::exchange(errno, 0);
+ const auto entp = readdir(dirp);
+- std::swap(errno, err);
++ std::swap((int&)errno, err);
+
+ if (entp)
+ {
diff --git a/patches/gcc/6.3.0/970-crystax.patch b/patches/gcc/6.3.0/970-crystax.patch
new file mode 100644
index 0000000..e3109cc
--- /dev/null
+++ b/patches/gcc/6.3.0/970-crystax.patch
@@ -0,0 +1,551 @@
+commit 080803512c8f6f87c2f1f711170d54033144d628
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Wed Jul 29 11:28:29 2015 +0300
+
+ [android] Apply Android-related modifications
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+[Edited: keep libstdc++, drop libcrystax-related modifications]
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index f66e48cd1..1c253496b 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -942,13 +942,17 @@ aarch64*-*-elf | aarch64*-*-rtems*)
+ TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
+ ;;
+ aarch64*-*-linux*)
+- tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
++ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h"
+ tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-linux.h"
++ extra_options="${extra_options} linux-android.opt"
+ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-linux"
+ case $target in
+ aarch64_be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
++ aarch64*-*-linux-android*)
++ tm_file="${tm_file} aarch64/aarch64-linux-android.h"
++ ;;
+ esac
+ aarch64_multilibs="${with_multilib_list}"
+ if test "$aarch64_multilibs" = "default"; then
+@@ -2055,6 +2059,17 @@ mips*-*-linux*) # Linux MIPS, either endian.
+ tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h mips/linux-common.h"
+ extra_options="${extra_options} linux-android.opt"
+ case ${target} in
++ mips64*android*)
++ default_mips_arch=mips64r6
++ default_mips_abi=64
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="${tmake_file} mips/t-linux-android64"
++ ;;
++ mips*android*)
++ default_mips_arch=mips32
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="$tmake_file mips/t-linux-android"
++ ;;
+ mipsisa32r6*)
+ default_mips_arch=mips32r6
+ ;;
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+new file mode 100644
+index 000000000..db1288fd0
+--- /dev/null
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -0,0 +1,59 @@
++/* Machine description for AArch64 architecture.
++ Copyright (C) 2014 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/>. */
++
++#ifndef GCC_AARCH64_LINUX_ANDROID_H
++#define GCC_AARCH64_LINUX_ANDROID_H
++
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS() \
++ do \
++ { \
++ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
++ } \
++ while (0)
++
++#undef LINK_SPEC
++#define LINK_SPEC \
++ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \
++ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
++
++#undef CC1_SPEC
++#define CC1_SPEC \
++ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
++
++#undef LIB_SPEC
++#define LIB_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
++ GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC " " ANDROID_LIB_SPEC)
++
++#undef STARTFILE_SPEC
++#define STARTFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
++
++#undef ENDFILE_SPEC
++#define ENDFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
++
++#endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
+index 5fcaa59a3..6864195ee 100644
+--- a/gcc/config/aarch64/aarch64-linux.h
++++ b/gcc/config/aarch64/aarch64-linux.h
+@@ -21,7 +21,14 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+
+-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifndef RUNTIME_ROOT_PREFIX
++#define RUNTIME_ROOT_PREFIX ""
++#endif
++#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifdef BIONIC_DYNAMIC_LINKER
++#undef BIONIC_DYNAMIC_LINKER
++#endif
++#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker64"
+
+ #undef MUSL_DYNAMIC_LINKER
+ #define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
+index ad123dde9..97b059de6 100644
+--- a/gcc/config/arm/arm.h
++++ b/gcc/config/arm/arm.h
+@@ -1888,10 +1888,11 @@ enum arm_auto_incmodes
+
+ #define CASE_VECTOR_PC_RELATIVE (TARGET_THUMB2 \
+ || (TARGET_THUMB1 \
++ && !inline_thumb1_jump_table \
+ && (optimize_size || flag_pic)))
+
+ #define CASE_VECTOR_SHORTEN_MODE(min, max, body) \
+- (TARGET_THUMB1 \
++ (TARGET_THUMB1 && !inline_thumb1_jump_table \
+ ? (min >= 0 && max < 512 \
+ ? (ADDR_DIFF_VEC_FLAGS (body).offset_unsigned = 1, QImode) \
+ : min >= -256 && max < 256 \
+diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
+index 47171b996..eb22d1181 100644
+--- a/gcc/config/arm/arm.md
++++ b/gcc/config/arm/arm.md
+@@ -8179,7 +8179,7 @@
+ (match_operand:SI 2 "const_int_operand" "") ; total range
+ (match_operand:SI 3 "" "") ; table label
+ (match_operand:SI 4 "" "")] ; Out of range label
+- "TARGET_32BIT || optimize_size || flag_pic"
++ "TARGET_32BIT || ((optimize_size || flag_pic) && !inline_thumb1_jump_table)"
+ "
+ {
+ enum insn_code code;
+diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt
+index 0ebe01743..772453889 100644
+--- a/gcc/config/arm/arm.opt
++++ b/gcc/config/arm/arm.opt
+@@ -193,6 +193,10 @@ mthumb-interwork
+ Target Report Mask(INTERWORK)
+ Support calls between Thumb and ARM instruction sets.
+
++minline-thumb1-jumptable
++Target Report Var(inline_thumb1_jump_table)
++Inline Thumb1 Jump table code
++
+ mtls-dialect=
+ Target RejectNegative Joined Enum(tls_type) Var(target_tls_dialect) Init(TLS_GNU)
+ Specify thread local storage scheme.
+diff --git a/gcc/config/arm/elf.h b/gcc/config/arm/elf.h
+index 77f30554d..32158ed65 100644
+--- a/gcc/config/arm/elf.h
++++ b/gcc/config/arm/elf.h
+@@ -56,8 +56,7 @@
+ #undef SUBSUBTARGET_EXTRA_SPECS
+ #define SUBSUBTARGET_EXTRA_SPECS
+
+-#ifndef ASM_SPEC
+-#define ASM_SPEC "\
++#define DEFAULT_ASM_SPEC "\
+ %{mbig-endian:-EB} \
+ %{mlittle-endian:-EL} \
+ %(asm_cpu_spec) \
+@@ -66,6 +65,9 @@
+ %{mthumb-interwork:-mthumb-interwork} \
+ %{mfloat-abi=*} %{mfpu=*} \
+ %(subtarget_extra_asm_spec)"
++
++#ifndef ASM_SPEC
++#define ASM_SPEC DEFAULT_ASM_SPEC
+ #endif
+
+ /* The ARM uses @ are a comment character so we need to redefine
+@@ -104,7 +106,8 @@
+ the code more efficient, but for Thumb-1 it's better to put them out of
+ band unless we are generating compressed tables. */
+ #define JUMP_TABLES_IN_TEXT_SECTION \
+- (TARGET_32BIT || (TARGET_THUMB && (optimize_size || flag_pic)))
++ (TARGET_32BIT || (TARGET_THUMB && !inline_thumb1_jump_table \
++ && (optimize_size || flag_pic)))
+
+ #ifndef LINK_SPEC
+ #define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL} -X"
+diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
+index ace84816e..8c8fa6553 100644
+--- a/gcc/config/arm/linux-eabi.h
++++ b/gcc/config/arm/linux-eabi.h
+@@ -108,11 +108,16 @@
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC, \
+ GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \
+- ANDROID_CC1_SPEC)
++ ANDROID_CC1_SPEC("-fpic"))
+
+ #define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
++#undef ASM_SPEC
++#define ASM_SPEC \
++ LINUX_OR_ANDROID_CC (DEFAULT_ASM_SPEC, \
++ DEFAULT_ASM_SPEC " " ANDROID_ASM_SPEC)
++
+ #undef LIB_SPEC
+ #define LIB_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
+index fee33a3ef..22fb2ced9 100644
+--- a/gcc/config/i386/gnu-user.h
++++ b/gcc/config/i386/gnu-user.h
+@@ -65,9 +65,14 @@ along with GCC; see the file COPYING3. If not see
+ When the -shared link option is used a final link is not being
+ done. */
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ " -mssse3 -fno-short-enums " \
++
+ #undef ASM_SPEC
+ #define ASM_SPEC \
+- "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
++ "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ #undef SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
+index 7a02a7eb4..cac4179bc 100644
+--- a/gcc/config/i386/gnu-user64.h
++++ b/gcc/config/i386/gnu-user64.h
+@@ -46,6 +46,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define SPEC_X32 "mx32"
+ #endif
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ "%{m32:-mssse3 -fno-short-enums}" \
++ "%{!m32:-msse4.2 -mpopcnt}"
++
+ #undef ASM_SPEC
+ #define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
+index 4b9910fa9..3b11ed086 100644
+--- a/gcc/config/i386/linux-common.h
++++ b/gcc/config/i386/linux-common.h
+@@ -30,7 +30,13 @@ along with GCC; see the file COPYING3. If not see
+ #undef CC1_SPEC
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC \
++ ANDROID_TARGET_CC1_SPEC \
++ " " \
++ ANDROID_CC1_SPEC("-fPIC"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
+ #undef LINK_SPEC
+ #define LINK_SPEC \
+diff --git a/gcc/config/linux-android.h b/gcc/config/linux-android.h
+index 301a41ccd..9623c88d0 100644
+--- a/gcc/config/linux-android.h
++++ b/gcc/config/linux-android.h
+@@ -38,15 +39,18 @@
+ "%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}"
+
+ #define ANDROID_LINK_SPEC \
+- "%{shared: -Bsymbolic}"
++ "%{shared: -Bsymbolic} -z noexecstack -z relro -z now"
+
+-#define ANDROID_CC1_SPEC \
++#define ANDROID_CC1_SPEC(ANDROID_PIC_DEFAULT) \
+ "%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \
+- "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
++ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: " ANDROID_PIC_DEFAULT "}}}}"
+
+ #define ANDROID_CC1PLUS_SPEC \
+- "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \
+- "%{!frtti:%{!fno-rtti: -fno-rtti}}"
++ "%{!fexceptions:%{!fno-exceptions: -fexceptions}} " \
++ "%{!frtti:%{!fno-rtti: -frtti}}"
++
++#define ANDROID_ASM_SPEC \
++ "--noexecstack"
+
+ #define ANDROID_LIB_SPEC \
+ "%{!static: -ldl}"
+diff --git a/gcc/config/mips/android.h b/gcc/config/mips/android.h
+new file mode 100644
+index 000000000..32c539c8d
+--- /dev/null
++++ b/gcc/config/mips/android.h
+@@ -0,0 +1,49 @@
++/* Target macros for mips*-*android* targets.
++ Copyright (C) 2014 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 DRIVER_SELF_SPECS
++#define DRIVER_SELF_SPECS \
++ /* Make sure a -mips option is present. This helps us to pick \
++ the right multilib, and also makes the later specs easier \
++ to write. */ \
++ MIPS_ISA_LEVEL_SPEC, \
++ \
++ /* Infer the default float setting from -march. */ \
++ MIPS_ARCH_FLOAT_SPEC, \
++ \
++ /* Infer the -msynci setting from -march if not explicitly set. */ \
++ MIPS_ISA_SYNCI_SPEC, \
++ \
++ /* If no ABI option is specified, infer one from the ISA level \
++ or -mgp setting. */ \
++ "%{!mabi=*: %{" MIPS_32BIT_OPTION_SPEC ": -mabi=32;: -mabi=64}}", \
++ \
++ /* If no FP ABI option is specified, infer one from the \
++ ABI/ISA level unless there is a conflicting option. */ \
++ "%{!msoft-float: %{!msingle-float: %{!mfp*: %{!mmsa: %{mabi=32: %{" \
++ MIPS_FPXX_OPTION_SPEC ": -mfpxx}}}}}}", \
++ \
++ /* If no odd-spreg option is specified, infer one from the ISA. */ \
++ "%{!modd-spreg: %{mabi=32: %{mips32r6: -mno-odd-spreg}}}", \
++ \
++ /* Base SPECs. */ \
++ BASE_DRIVER_SELF_SPECS, \
++ \
++ /* Use the standard linux specs for everything else. */ \
++ LINUX_DRIVER_SELF_SPECS
+diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
+index 15b549c08..4a2816014 100644
+--- a/gcc/config/mips/gnu-user.h
++++ b/gcc/config/mips/gnu-user.h
+@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
+ /* The GNU C++ standard library requires this. */ \
+ if (c_dialect_cxx ()) \
+ builtin_define ("_GNU_SOURCE"); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
+ } while (0)
+
+ #undef SUBTARGET_CPP_SPEC
+@@ -71,7 +72,8 @@ along with GCC; see the file COPYING3. If not see
+
+ #undef SUBTARGET_ASM_SPEC
+ #define SUBTARGET_ASM_SPEC \
+- "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}}"
++ "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ /* The MIPS assembler has different syntax for .set. We set it to
+ .dummy to trap any errors. */
+@@ -120,7 +122,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #endif
+
+ #define LINUX_DRIVER_SELF_SPECS \
+- NO_SHARED_SPECS \
++ LINUX_OR_ANDROID_CC(NO_SHARED_SPECS, "") \
+ MARCH_MTUNE_NATIVE_SPECS, \
+ /* -mplt has no effect without -mno-shared. Simplify later \
+ specs handling by removing a redundant option. */ \
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8429a7ca2..8bfacf994 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see
+ #undef SUBTARGET_CC1_SPEC
+ #define SUBTARGET_CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
+
+ #undef CC1PLUS_SPEC
+ #define CC1PLUS_SPEC \
+diff --git a/gcc/config/mips/t-linux-android b/gcc/config/mips/t-linux-android
+new file mode 100644
+index 000000000..39f512c81
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android
+@@ -0,0 +1,3 @@
++MULTILIB_OPTIONS = mips32r2/mips32r6
++MULTILIB_DIRNAMES = mips-r2 mips-r6
++MULTILIB_OSDIRNAMES = ../libr2 ../libr6
+diff --git a/gcc/config/mips/t-linux-android64 b/gcc/config/mips/t-linux-android64
+new file mode 100644
+index 000000000..55cab7d62
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android64
+@@ -0,0 +1,4 @@
++MULTILIB_OPTIONS = mabi=32 mips32/mips32r2/mips32r6/mips64r2/mips64r6
++MULTILIB_DIRNAMES = 32 mips-r1 mips-r2 mips-r6 mips64-r2 mips64-r6
++MULTILIB_OSDIRNAMES = ../lib ../lib ../libr2 ../libr6 ../lib64r2 ../lib64
++MULTILIB_REQUIRED = mabi=32/mips32 mabi=32/mips32r2 mabi=32/mips32r6 mips64r2 mips64r6
+diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
+index 555c0fe24..47c8655f9 100644
+--- a/libgcc/gthr-posix.h
++++ b/libgcc/gthr-posix.h
+@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define __GTHREADS 1
+ #define __GTHREADS_CXX0X 1
+
++/* The following should normally be in a different header file,
++ * but I couldn't find the right location. The point of the macro
++ * definition below is to prevent libsupc++ and libstdc++ to reference
++ * weak symbols in their static C++ constructors. Such code crashes
++ * when a shared object linked statically to these libraries is
++ * loaded on Android 2.1 (Eclair) and older platform releases, due
++ * to a dynamic linker bug.
++ */
++#ifdef __ANDROID__
++#undef GTHREAD_USE_WEAK
++#define GTHREAD_USE_WEAK 0
++#endif
++
+ #include <pthread.h>
+
+ #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
+diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
+index 41797a971..f746e8353 100755
+--- a/libstdc++-v3/configure
++++ b/libstdc++-v3/configure
+@@ -78319,6 +78341,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+@@ -78377,6 +78405,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h
+index e3e206b7d..e85dc2c76 100644
+--- a/libstdc++-v3/include/bits/locale_facets.h
++++ b/libstdc++-v3/include/bits/locale_facets.h
+@@ -47,6 +47,20 @@
+ #include <ext/numeric_traits.h>
+ #include <bits/streambuf_iterator.h>
+
++#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ == 9 && __i386__
++// CrystaX: for some reason, x86 gcc-4.9 makes ctype<char>::do_widen() and
++// ctype<char>::_M_widen_init() methods working wrong if optimization enabled.
++// For ctype<char>::do_widen(), values of passed arguments (__lo, __hi and __to)
++// are completely messed up and don't correspond to passed values. In case if
++// we disable optimization for those methods, things become correct so we apply
++// this workaround here for a time.
++// TODO: figure out what exactly wrong here - is it bug in GCC optimization
++// algorithm or smth else?
++#define __CRYSTAX_X86_DONT_OPTIMIZE __attribute__((optimize(0)))
++#else
++#define __CRYSTAX_X86_DONT_OPTIMIZE
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -1102,7 +1116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ * @return @a __hi.
+ */
+ virtual const char*
+- do_widen(const char* __lo, const char* __hi, char_type* __to) const
++ do_widen(const char* __lo, const char* __hi, char_type* __to) const __CRYSTAX_X86_DONT_OPTIMIZE
+ {
+ __builtin_memcpy(__to, __lo, __hi - __lo);
+ return __hi;
+@@ -1163,7 +1177,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ private:
+ void _M_narrow_init() const;
+- void _M_widen_init() const;
++ void _M_widen_init() const __CRYSTAX_X86_DONT_OPTIMIZE;
+ };
+
+ #ifdef _GLIBCXX_USE_WCHAR_T
+diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc
+index 9b617998f..c149169bb 100644
+--- a/libstdc++-v3/libsupc++/guard.cc
++++ b/libstdc++-v3/libsupc++/guard.cc
+@@ -33,7 +33,12 @@
+ #if defined(__GTHREADS) && defined(__GTHREAD_HAS_COND) \
+ && (ATOMIC_INT_LOCK_FREE > 1) && defined(_GLIBCXX_HAVE_LINUX_FUTEX)
+ # include <climits>
++#if defined(__ANDROID__)
++# include <sys/syscall.h>
++# define SYS_futex __NR_futex
++#else
+ # include <syscall.h>
++#endif
+ # include <unistd.h>
+ # define _GLIBCXX_USE_FUTEX
+ # define _GLIBCXX_FUTEX_WAIT 0
diff --git a/patches/gcc/6.3.0/971-crystax.patch b/patches/gcc/6.3.0/971-crystax.patch
new file mode 100644
index 0000000..748a381
--- /dev/null
+++ b/patches/gcc/6.3.0/971-crystax.patch
@@ -0,0 +1,25 @@
+commit 9f057b62caafe08c968103d39b5df82486a175c2
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 13 16:11:54 2015 +0300
+
+ [android] Add additional multilib option: mfloat-abi=hard
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/t-linux-androideabi b/gcc/config/arm/t-linux-androideabi
+index 8f1307c55..cbbec5bd2 100644
+--- a/gcc/config/arm/t-linux-androideabi
++++ b/gcc/config/arm/t-linux-androideabi
+@@ -1,8 +1,9 @@
+-MULTILIB_OPTIONS = march=armv7-a mthumb
+-MULTILIB_DIRNAMES = armv7-a thumb
+-MULTILIB_EXCEPTIONS =
++MULTILIB_OPTIONS = march=armv7-a mthumb mfloat-abi=hard
++MULTILIB_DIRNAMES = armv7-a thumb hard
++MULTILIB_EXCEPTIONS = mfloat-abi=hard* mthumb/mfloat-abi=hard*
+ MULTILIB_MATCHES =
+ MULTILIB_OSDIRNAMES =
++MULTILIB_EXTRA_OPTS = Wl,--no-warn-mismatch
+
+ # The "special" multilib can be used to build native applications for Android,
+ # as opposed to native shared libraries that are then called via JNI.
diff --git a/patches/gcc/6.3.0/972-crystax.patch b/patches/gcc/6.3.0/972-crystax.patch
new file mode 100644
index 0000000..b9077be
--- /dev/null
+++ b/patches/gcc/6.3.0/972-crystax.patch
@@ -0,0 +1,302 @@
+commit 44a81ebb7698dac41ffa7acd5e0cc1578e5ab1fd
+Author: H.J. Lu <hongjiu.lu@intel.com>
+Date: Mon Apr 14 15:59:47 2014 -0700
+
+ [android] Always enable --eh-frame-hdr for static executable
+
+ See 5e6cdf76af295c9a39b695ca228cff675e8ff4ae and
+ 23e3137ee2897464b051599b85a09f130d3ad05d
+
+ Change-Id: Ibda473188e5a10f2a0592f2494ad00ad1f91e04b
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config.in b/gcc/config.in
+index 115cb6163..933916833 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -2119,6 +2119,12 @@
+ #endif
+
+
++/* Define if your system supports PT_GNU_EH_FRAME for static executable. */
++#ifndef USED_FOR_TARGET
++#undef USE_EH_FRAME_HDR_FOR_STATIC
++#endif
++
++
+ /* Define to 1 if the 'long long' type is wider than 'long' but still
+ efficiently supported by the host hardware. */
+ #ifndef USED_FOR_TARGET
+diff --git a/gcc/config/alpha/elf.h b/gcc/config/alpha/elf.h
+index 093c38bba..54b3e0c91 100644
+--- a/gcc/config/alpha/elf.h
++++ b/gcc/config/alpha/elf.h
+@@ -168,5 +168,9 @@ extern int alpha_this_gpdisp_sequence_number;
+ I imagine that other systems will catch up. In the meantime, it
+ doesn't harm to make sure that the data exists to be used later. */
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+diff --git a/gcc/config/freebsd.h b/gcc/config/freebsd.h
+index 5ded869d2..5f51ac81d 100644
+--- a/gcc/config/freebsd.h
++++ b/gcc/config/freebsd.h
+@@ -45,8 +45,12 @@ along with GCC; see the file COPYING3. If not see
+ #define LIB_SPEC FBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #ifdef TARGET_LIBC_PROVIDES_SSP
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
+index b0bf40a95..d1874bc29 100644
+--- a/gcc/config/gnu-user.h
++++ b/gcc/config/gnu-user.h
+@@ -118,8 +118,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LINK_GCC_C_SEQUENCE_SPEC
+ #define LINK_GCC_C_SEQUENCE_SPEC \
+diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h
+index 37ecfc43f..a5f1b9955 100644
+--- a/gcc/config/openbsd.h
++++ b/gcc/config/openbsd.h
+@@ -136,8 +136,12 @@ while (0)
+ #define LIB_SPEC OBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LIB_SPEC
+ #define LIB_SPEC OBSD_LIB_SPEC
+diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
+index cbf909722..eb2217fad 100644
+--- a/gcc/config/rs6000/sysv4.h
++++ b/gcc/config/rs6000/sysv4.h
+@@ -789,7 +789,11 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
+-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# ifdef USE_EH_FRAME_HDR_FOR_STATIC
++# define LINK_EH_SPEC "--eh-frame-hdr "
++# else
++# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# endif
+ #endif
+
+ #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
+diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
+index 5160e1fda..7632a5081 100644
+--- a/gcc/config/sol2.h
++++ b/gcc/config/sol2.h
+@@ -347,7 +347,11 @@ along with GCC; see the file COPYING3. If not see
+ /* Solaris 11 build 135+ implements dl_iterate_phdr. GNU ld needs
+ --eh-frame-hdr to create the required .eh_frame_hdr sections. */
+ #if defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++#endif
+ #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
+ #endif
+
+diff --git a/gcc/configure b/gcc/configure
+index 1c6e3407c..28ad05004 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -934,6 +934,7 @@ enable_fix_cortex_a53_835769
+ enable_fix_cortex_a53_843419
+ with_glibc_version
+ enable_gnu_unique_object
++enable_eh_frame_hdr_for_static
+ enable_linker_build_id
+ enable_default_ssp
+ with_long_double_128
+@@ -1670,6 +1671,9 @@ Optional Features:
+ --enable-gnu-unique-object
+ enable the use of the @gnu_unique_object ELF
+ extension on glibc systems
++ --enable-eh-frame-hdr-for-static
++ enable linker PT_GNU_EH_FRAME support for static
++ executable
+ --enable-linker-build-id
+ compiler will always pass --build-id to linker
+ --enable-default-ssp enable Stack Smashing Protection as default
+@@ -27703,6 +27707,38 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+
+ $as_echo "#define HAVE_LD_EH_FRAME_HDR 1" >>confdefs.h
+
++ # Check whether --enable-eh-frame-hdr-for-static was given.
++if test "${enable_eh_frame_hdr_for_static+set}" = set; then :
++ enableval=$enable_eh_frame_hdr_for_static; case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) as_fn_error "'$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
++ esac
++else
++ # Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi
++fi
++
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++
++$as_echo "#define USE_EH_FRAME_HDR_FOR_STATIC 1" >>confdefs.h
++
++ fi
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_eh_frame_hdr" >&5
+ $as_echo "$gcc_cv_ld_eh_frame_hdr" >&6; }
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 6c1dcd9ae..0cf7419e7 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -4828,6 +4828,35 @@ GCC_TARGET_TEMPLATE([HAVE_LD_EH_FRAME_HDR])
+ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+ AC_DEFINE(HAVE_LD_EH_FRAME_HDR, 1,
+ [Define if your linker supports .eh_frame_hdr.])
++ AC_ARG_ENABLE(eh-frame-hdr-for-static,
++ [AS_HELP_STRING([--enable-eh-frame-hdr-for-static],
++ [enable linker PT_GNU_EH_FRAME support for static executable])],
++ [case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) AC_MSG_ERROR(['$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'.]) ;;
++ esac],
++# Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ [[if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi]])
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++ AC_DEFINE(USE_EH_FRAME_HDR_FOR_STATIC, 1,
++[Define if your system supports PT_GNU_EH_FRAME for static executable.])
++ fi
+ fi
+ AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr)
+
+diff --git a/gcc/testsuite/g++.dg/eh/spec3-static.C b/gcc/testsuite/g++.dg/eh/spec3-static.C
+new file mode 100644
+index 000000000..15408effa
+--- /dev/null
++++ b/gcc/testsuite/g++.dg/eh/spec3-static.C
+@@ -0,0 +1,25 @@
++// PR c++/4381
++// Test that exception-specs work properly for classes with virtual bases.
++
++// { dg-do run }
++// { dg-options "-static" }
++
++class Base {};
++
++struct A : virtual public Base
++{
++ A() {}
++};
++
++struct B {};
++
++void func() throw (B,A)
++{
++ throw A();
++}
++
++int main(void)
++{
++ try { func(); }
++ catch (A& a) { }
++}
+diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
+index f3343fc4f..d42647779 100644
+--- a/libgcc/crtstuff.c
++++ b/libgcc/crtstuff.c
+@@ -88,7 +88,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -97,7 +98,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__sun__) && defined(__svr4__)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -106,7 +108,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__GLIBC__) && __GLIBC__ >= 2
+ #include <link.h>
+ /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
+@@ -121,7 +124,7 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(CRTSTUFFT_O) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(inhibit_libc) \
+ && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
+ /* On systems using glibc, an inhibit_libc build of libgcc is only
diff --git a/patches/gcc/6.3.0/973-crystax.patch b/patches/gcc/6.3.0/973-crystax.patch
new file mode 100644
index 0000000..b96ece3
--- /dev/null
+++ b/patches/gcc/6.3.0/973-crystax.patch
@@ -0,0 +1,20 @@
+commit 778a9ef107f51544d583f110e92b75f4d9d79117
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 20 19:11:07 2015 +0300
+
+ [android] Don't use PIE copyrelocs for x86/x86_64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
+index 3d044e8bd..5c89fcab0 100644
+--- a/gcc/config/i386/i386.c
++++ b/gcc/config/i386/i386.c
+@@ -14631,6 +14631,7 @@ legitimate_pic_address_disp_p (rtx disp)
+ else if (!SYMBOL_REF_FAR_ADDR_P (op0)
+ && (SYMBOL_REF_LOCAL_P (op0)
+ || (HAVE_LD_PIE_COPYRELOC
++ && !TARGET_HAS_BIONIC
+ && flag_pie
+ && !SYMBOL_REF_WEAK (op0)
+ && !SYMBOL_REF_FUNCTION_P (op0)))
diff --git a/patches/gcc/6.3.0/974-crystax.patch b/patches/gcc/6.3.0/974-crystax.patch
new file mode 100644
index 0000000..9db4f54
--- /dev/null
+++ b/patches/gcc/6.3.0/974-crystax.patch
@@ -0,0 +1,24 @@
+commit dbeae1190cabad83999f2540523f045acc1bb4ec
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Fri Aug 21 17:41:59 2015 +0300
+
+ [android] Always use gthr-posix.h instead of gthr-default.h
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/libgcc/gthr.h b/libgcc/gthr.h
+index 47a7d061a..67a680f90 100644
+--- a/libgcc/gthr.h
++++ b/libgcc/gthr.h
+@@ -145,7 +145,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define GTHREAD_USE_WEAK 1
+ #endif
+ #endif
++#if __ANDROID__
++#include "gthr-posix.h"
++#else
+ #include "gthr-default.h"
++#endif
+
+ #ifndef HIDE_EXPORTS
+ #pragma GCC visibility pop
diff --git a/patches/gcc/6.3.0/975-crystax.patch b/patches/gcc/6.3.0/975-crystax.patch
new file mode 100644
index 0000000..9efc2a4
--- /dev/null
+++ b/patches/gcc/6.3.0/975-crystax.patch
@@ -0,0 +1,31 @@
+commit 8a66d422721ae5999737d7825701ff22097d287b
+Author: Andrew Hsieh <andrewhsieh@google.com>
+Date: Mon Apr 14 21:05:51 2014 -0700
+
+ [android] Fix ARM generates insufficient alignment for NEON vst/vld
+
+ See d909af3e2469aad87d5c3e79b93c778fd26c03a9
+
+ Change-Id: Ie1de9f946f397196bb6f1623f5add86933739484
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
+index 5974c65d3..71b2c7aa9 100644
+--- a/gcc/config/arm/arm.c
++++ b/gcc/config/arm/arm.c
+@@ -22403,9 +22403,13 @@ arm_print_operand (FILE *stream, rtx x, int code)
+ memsize = MEM_SIZE (x);
+
+ /* Only certain alignment specifiers are supported by the hardware. */
+- if (memsize == 32 && (align % 32) == 0)
++ /* Note that ARM EABI only guarentees 8-byte stack alignment. While GCC
++ honors stricter alignment of composite type in user code, it doesn't
++ observe the alignment of memory passed as an extra argument for function
++ returning large composite type. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57271 */
++ if (memsize == 32 && (align % 32) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 256;
+- else if ((memsize == 16 || memsize == 32) && (align % 16) == 0)
++ else if ((memsize == 16 || memsize == 32) && (align % 16) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 128;
+ else if (memsize >= 8 && (align % 8) == 0)
+ align_bits = 64;
diff --git a/patches/gcc/6.3.0/976-crystax.patch b/patches/gcc/6.3.0/976-crystax.patch
new file mode 100644
index 0000000..790d4a9
--- /dev/null
+++ b/patches/gcc/6.3.0/976-crystax.patch
@@ -0,0 +1,21 @@
+commit 89d27bc45ee7325dcfff6748da0f8b9c1dc1f234
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Sat Aug 22 09:55:55 2015 +0300
+
+ [android][i386] Remove throw() declaration from posix_memalign() proto
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
+index a1f98d3d1..3725799be 100644
+--- a/gcc/config/i386/pmm_malloc.h
++++ b/gcc/config/i386/pmm_malloc.h
+@@ -31,7 +31,7 @@
+ #ifndef __cplusplus
+ extern int posix_memalign (void **, size_t, size_t);
+ #else
+-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
++extern "C" int posix_memalign (void **, size_t, size_t);
+ #endif
+
+ static __inline void *
diff --git a/patches/gcc/6.3.0/977-crystax.patch b/patches/gcc/6.3.0/977-crystax.patch
new file mode 100644
index 0000000..0211d72
--- /dev/null
+++ b/patches/gcc/6.3.0/977-crystax.patch
@@ -0,0 +1,33 @@
+commit 9ae82f7cfc1073820092dd9f957559667e77db0d
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Tue Aug 25 09:36:42 2015 +0300
+
+ [android] Explicitly make _Unwind_Resume visible for arm64/mips64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+index db1288fd0..38bc64d61 100644
+--- a/gcc/config/aarch64/aarch64-linux-android.h
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -57,4 +57,8 @@
+ #define ENDFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
+
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif
++
+ #endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8bfacf994..262a9a341 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -63,3 +63,7 @@ along with GCC; see the file COPYING3. If not see
+
+ /* The default value isn't sufficient in 64-bit mode. */
+ #define STACK_CHECK_PROTECT (TARGET_64BIT ? 16 * 1024 : 12 * 1024)
++
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif
diff --git a/patches/gcc/linaro-6.3-2017.02/100-uclibc-conf.patch b/patches/gcc/7.1.0/100-uclibc-conf.patch
index 73d1f0d..73d1f0d 100644
--- a/patches/gcc/linaro-6.3-2017.02/100-uclibc-conf.patch
+++ b/patches/gcc/7.1.0/100-uclibc-conf.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/1000-libtool-leave-framework-alone.patch b/patches/gcc/7.1.0/1000-libtool-leave-framework-alone.patch
index bce09eb..bce09eb 100644
--- a/patches/gcc/linaro-6.3-2017.02/1000-libtool-leave-framework-alone.patch
+++ b/patches/gcc/7.1.0/1000-libtool-leave-framework-alone.patch
diff --git a/patches/gcc/7.1.0/111-alpha-bad-eh_frame.patch b/patches/gcc/7.1.0/111-alpha-bad-eh_frame.patch
new file mode 100644
index 0000000..93f6e94
--- /dev/null
+++ b/patches/gcc/7.1.0/111-alpha-bad-eh_frame.patch
@@ -0,0 +1,13 @@
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80037
+
+diff --git a/libgcc/config/alpha/t-alpha b/libgcc/config/alpha/t-alpha
+index 0b6ffb1..0c2f840 100644
+--- a/libgcc/config/alpha/t-alpha
++++ b/libgcc/config/alpha/t-alpha
+@@ -1,2 +1,6 @@
+ # This is a support routine for longlong.h, used by libgcc2.c.
+ LIB2ADD += $(srcdir)/config/alpha/qrnnd.S
++
++# When GAS-generated unwind tables are created, they get created
++# after the __FRAME_END__ terminator, which causes an ld error.
++CRTSTUFF_T_CFLAGS = -fno-unwind-tables
diff --git a/patches/gcc/linaro-6.3-2017.02/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch b/patches/gcc/7.1.0/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
index d8986d5..d8986d5 100644
--- a/patches/gcc/linaro-6.3-2017.02/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
+++ b/patches/gcc/7.1.0/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/380-gcc-plugin-POSIX-include-sys-select-h.patch b/patches/gcc/7.1.0/380-gcc-plugin-POSIX-include-sys-select-h.patch
index 12ef48e..12ef48e 100644
--- a/patches/gcc/linaro-6.3-2017.02/380-gcc-plugin-POSIX-include-sys-select-h.patch
+++ b/patches/gcc/7.1.0/380-gcc-plugin-POSIX-include-sys-select-h.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/810-arm-softfloat-libgcc.patch b/patches/gcc/7.1.0/810-arm-softfloat-libgcc.patch
index 5efa7fd..5efa7fd 100644
--- a/patches/gcc/linaro-6.3-2017.02/810-arm-softfloat-libgcc.patch
+++ b/patches/gcc/7.1.0/810-arm-softfloat-libgcc.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/860-cilk-wchar.patch b/patches/gcc/7.1.0/860-cilk-wchar.patch
index 1d9916f..1d9916f 100644
--- a/patches/gcc/linaro-6.3-2017.02/860-cilk-wchar.patch
+++ b/patches/gcc/7.1.0/860-cilk-wchar.patch
diff --git a/patches/gcc/7.1.0/870-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/7.1.0/870-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..cf21584
--- /dev/null
+++ b/patches/gcc/7.1.0/870-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,74 @@
+From 06689e5973647f5c65d1984b164f2531f5418d7a Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 0181dde..25e4a28 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1780,7 +1780,8 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call%d\t0x%lx", WINDOW_SIZE, INTVAL (tgt));
++ sprintf (result, "call%d\t" HOST_WIDE_INT_PRINT_HEX,
++ WINDOW_SIZE, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx%d\t%%%d", WINDOW_SIZE, callop);
+ else
+@@ -2351,14 +2352,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2372,7 +2373,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2437,7 +2438,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (GET_MODE (x), XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/linaro-6.3-2017.02/891-fix-m68k-uclinux.patch b/patches/gcc/7.1.0/891-fix-m68k-uclinux.patch
index 4e186bd..4e186bd 100644
--- a/patches/gcc/linaro-6.3-2017.02/891-fix-m68k-uclinux.patch
+++ b/patches/gcc/7.1.0/891-fix-m68k-uclinux.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/900-libgfortran-missing-include.patch b/patches/gcc/7.1.0/900-libgfortran-missing-include.patch
index 1f47469..1f47469 100644
--- a/patches/gcc/linaro-6.3-2017.02/900-libgfortran-missing-include.patch
+++ b/patches/gcc/7.1.0/900-libgfortran-missing-include.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/910-nios2-bad-multilib-default.patch b/patches/gcc/7.1.0/910-nios2-bad-multilib-default.patch
index 61989e5..61989e5 100644
--- a/patches/gcc/linaro-6.3-2017.02/910-nios2-bad-multilib-default.patch
+++ b/patches/gcc/7.1.0/910-nios2-bad-multilib-default.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/930-libgcc-disable-split-stack-nothreads.patch b/patches/gcc/7.1.0/930-libgcc-disable-split-stack-nothreads.patch
index 07f9a73..07f9a73 100644
--- a/patches/gcc/linaro-6.3-2017.02/930-libgcc-disable-split-stack-nothreads.patch
+++ b/patches/gcc/7.1.0/930-libgcc-disable-split-stack-nothreads.patch
diff --git a/patches/gcc/7.1.0/951-bionic-ndk.patch b/patches/gcc/7.1.0/951-bionic-ndk.patch
new file mode 100644
index 0000000..59c50a8
--- /dev/null
+++ b/patches/gcc/7.1.0/951-bionic-ndk.patch
@@ -0,0 +1,58 @@
+commit d38d37bdfe24b7ce1bdcb55642fb6b904718e68f
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 19:02:18 2017 -0700
+
+ Fix ctype for newer NDK headers
+
+diff --git a/libstdc++-v3/config/os/bionic/ctype_base.h b/libstdc++-v3/config/os/bionic/ctype_base.h
+index 33978f3..c36e63c 100644
+--- a/libstdc++-v3/config/os/bionic/ctype_base.h
++++ b/libstdc++-v3/config/os/bionic/ctype_base.h
+@@ -28,6 +28,18 @@
+
+ // Information as gleaned from /usr/include/ctype.h
+
++// _CTYPE prefix was added in NDK r14 unified headers
++#ifndef _CTYPE_U
++#define _CTYPE_U _U
++#define _CTYPE_L _L
++#define _CTYPE_D _N
++#define _CTYPE_S _S
++#define _CTYPE_P _P
++#define _CTYPE_C _C
++#define _CTYPE_X _X
++#define _CTYPE_B _B
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -41,17 +53,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ // NB: Offsets into ctype<char>::_M_table force a particular size
+ // on the mask type. Because of this, we don't use an enum.
+ typedef char mask;
+- static const mask upper = _U;
+- static const mask lower = _L;
+- static const mask alpha = _U | _L;
+- static const mask digit = _N;
+- static const mask xdigit = _X | _N;
+- static const mask space = _S;
+- static const mask print = _P | _U | _L | _N | _B;
+- static const mask graph = _P | _U | _L | _N;
+- static const mask cntrl = _C;
+- static const mask punct = _P;
+- static const mask alnum = _U | _L | _N;
++ static const mask upper = _CTYPE_U;
++ static const mask lower = _CTYPE_L;
++ static const mask alpha = _CTYPE_U | _CTYPE_L;
++ static const mask digit = _CTYPE_D;
++ static const mask xdigit = _CTYPE_X | _CTYPE_D;
++ static const mask space = _CTYPE_S;
++ static const mask print = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D | _CTYPE_B;
++ static const mask graph = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D;
++ static const mask cntrl = _CTYPE_C;
++ static const mask punct = _CTYPE_P;
++ static const mask alnum = _CTYPE_U | _CTYPE_L | _CTYPE_D;
+ #if __cplusplus >= 201103L
+ static const mask blank = space;
+ #endif
diff --git a/patches/gcc/7.1.0/952-bionic-errno.patch b/patches/gcc/7.1.0/952-bionic-errno.patch
new file mode 100644
index 0000000..91f6ca3
--- /dev/null
+++ b/patches/gcc/7.1.0/952-bionic-errno.patch
@@ -0,0 +1,19 @@
+commit 6cd4ad106ef87a3c58b0c3478e78409b47000de0
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 20:17:03 2017 -0700
+
+ Fix, errno is volatile int
+
+diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
+index 6ff12d0..5bbd664 100644
+--- a/libstdc++-v3/src/filesystem/dir.cc
++++ b/libstdc++-v3/src/filesystem/dir.cc
+@@ -147,7 +147,7 @@ fs::_Dir::advance(error_code* ec, directory_options options)
+
+ int err = std::exchange(errno, 0);
+ const auto entp = readdir(dirp);
+- std::swap(errno, err);
++ std::swap((int&)errno, err);
+
+ if (entp)
+ {
diff --git a/patches/gcc/7.1.0/970-crystax.patch b/patches/gcc/7.1.0/970-crystax.patch
new file mode 100644
index 0000000..7324d7f
--- /dev/null
+++ b/patches/gcc/7.1.0/970-crystax.patch
@@ -0,0 +1,553 @@
+commit 080803512c8f6f87c2f1f711170d54033144d628
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Wed Jul 29 11:28:29 2015 +0300
+
+ [android] Apply Android-related modifications
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+[Edited: keep libstdc++, drop libcrystax-related modifications]
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index f66e48cd1..1c253496b 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -942,13 +942,17 @@ aarch64*-*-elf | aarch64*-*-rtems*)
+ TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
+ ;;
+ aarch64*-*-linux*)
+- tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
++ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h"
+ tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-linux.h"
++ extra_options="${extra_options} linux-android.opt"
+ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-linux"
+ case $target in
+ aarch64_be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
++ aarch64*-*-linux-android*)
++ tm_file="${tm_file} aarch64/aarch64-linux-android.h"
++ ;;
+ esac
+ aarch64_multilibs="${with_multilib_list}"
+ if test "$aarch64_multilibs" = "default"; then
+@@ -2055,6 +2059,17 @@ mips*-*-linux*) # Linux MIPS, either endian.
+ tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h mips/linux-common.h"
+ extra_options="${extra_options} linux-android.opt"
+ case ${target} in
++ mips64*android*)
++ default_mips_arch=mips64r6
++ default_mips_abi=64
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="${tmake_file} mips/t-linux-android64"
++ ;;
++ mips*android*)
++ default_mips_arch=mips32
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="$tmake_file mips/t-linux-android"
++ ;;
+ mipsisa32r6*)
+ default_mips_arch=mips32r6
+ ;;
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+new file mode 100644
+index 000000000..db1288fd0
+--- /dev/null
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -0,0 +1,59 @@
++/* Machine description for AArch64 architecture.
++ Copyright (C) 2014 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/>. */
++
++#ifndef GCC_AARCH64_LINUX_ANDROID_H
++#define GCC_AARCH64_LINUX_ANDROID_H
++
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS() \
++ do \
++ { \
++ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
++ } \
++ while (0)
++
++#undef LINK_SPEC
++#define LINK_SPEC \
++ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \
++ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
++
++#undef CC1_SPEC
++#define CC1_SPEC \
++ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
++
++#undef LIB_SPEC
++#define LIB_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
++ GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC " " ANDROID_LIB_SPEC)
++
++#undef STARTFILE_SPEC
++#define STARTFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
++
++#undef ENDFILE_SPEC
++#define ENDFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
++
++#endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
+index 5fcaa59a3..6864195ee 100644
+--- a/gcc/config/aarch64/aarch64-linux.h
++++ b/gcc/config/aarch64/aarch64-linux.h
+@@ -21,7 +21,14 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+
+-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifndef RUNTIME_ROOT_PREFIX
++#define RUNTIME_ROOT_PREFIX ""
++#endif
++#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifdef BIONIC_DYNAMIC_LINKER
++#undef BIONIC_DYNAMIC_LINKER
++#endif
++#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker64"
+
+ #undef MUSL_DYNAMIC_LINKER
+ #define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
+index ad123dde9..97b059de6 100644
+--- a/gcc/config/arm/arm.h
++++ b/gcc/config/arm/arm.h
+@@ -1888,10 +1888,11 @@ enum arm_auto_incmodes
+
+ #define CASE_VECTOR_PC_RELATIVE (TARGET_THUMB2 \
+ || (TARGET_THUMB1 \
++ && !inline_thumb1_jump_table \
+ && (optimize_size || flag_pic)))
+
+ #define CASE_VECTOR_SHORTEN_MODE(min, max, body) \
+- (TARGET_THUMB1 \
++ (TARGET_THUMB1 && !inline_thumb1_jump_table \
+ ? (min >= 0 && max < 512 \
+ ? (ADDR_DIFF_VEC_FLAGS (body).offset_unsigned = 1, QImode) \
+ : min >= -256 && max < 256 \
+diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
+index 47171b996..eb22d1181 100644
+--- a/gcc/config/arm/arm.md
++++ b/gcc/config/arm/arm.md
+@@ -8179,7 +8179,7 @@
+ (match_operand:SI 2 "const_int_operand" "") ; total range
+ (match_operand:SI 3 "" "") ; table label
+ (match_operand:SI 4 "" "")] ; Out of range label
+- "(TARGET_32BIT || optimize_size || flag_pic) && !target_pure_code"
++ "(TARGET_32BIT || ((optimize_size || flag_pic) && !inline_thumb1_jump_table)) && !target_pure_code"
+ "
+ {
+ enum insn_code code;
+diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt
+index 0ebe01743..772453889 100644
+--- a/gcc/config/arm/arm.opt
++++ b/gcc/config/arm/arm.opt
+@@ -193,6 +193,10 @@ mthumb-interwork
+ Target Report Mask(INTERWORK)
+ Support calls between Thumb and ARM instruction sets.
+
++minline-thumb1-jumptable
++Target Report Var(inline_thumb1_jump_table)
++Inline Thumb1 Jump table code
++
+ mtls-dialect=
+ Target RejectNegative Joined Enum(tls_type) Var(target_tls_dialect) Init(TLS_GNU)
+ Specify thread local storage scheme.
+diff --git a/gcc/config/arm/elf.h b/gcc/config/arm/elf.h
+index 77f30554d..32158ed65 100644
+--- a/gcc/config/arm/elf.h
++++ b/gcc/config/arm/elf.h
+@@ -56,8 +56,7 @@
+ #undef SUBSUBTARGET_EXTRA_SPECS
+ #define SUBSUBTARGET_EXTRA_SPECS
+
+-#ifndef ASM_SPEC
+-#define ASM_SPEC "\
++#define DEFAULT_ASM_SPEC "\
+ %{mbig-endian:-EB} \
+ %{mlittle-endian:-EL} \
+ %(asm_cpu_spec) \
+@@ -66,6 +65,9 @@
+ %{mthumb-interwork:-mthumb-interwork} \
+ %{mfloat-abi=*} %{mfpu=*} \
+ %(subtarget_extra_asm_spec)"
++
++#ifndef ASM_SPEC
++#define ASM_SPEC DEFAULT_ASM_SPEC
+ #endif
+
+ /* The ARM uses @ are a comment character so we need to redefine
+@@ -104,8 +106,9 @@
+ the code more efficient, but for Thumb-1 it's better to put them out of
+ band unless we are generating compressed tables. */
+ #define JUMP_TABLES_IN_TEXT_SECTION \
+- ((TARGET_32BIT || (TARGET_THUMB && (optimize_size || flag_pic))) \
+- && !target_pure_code)
++ ((TARGET_32BIT || (TARGET_THUMB && !inline_thumb1_jump_table \
++ && (optimize_size || flag_pic))) \
++ && !target_pure_code)
+
+ #ifndef LINK_SPEC
+ #define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL} -X"
+diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
+index ace84816e..8c8fa6553 100644
+--- a/gcc/config/arm/linux-eabi.h
++++ b/gcc/config/arm/linux-eabi.h
+@@ -108,11 +108,16 @@
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC, \
+ GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \
+- ANDROID_CC1_SPEC)
++ ANDROID_CC1_SPEC("-fpic"))
+
+ #define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
++#undef ASM_SPEC
++#define ASM_SPEC \
++ LINUX_OR_ANDROID_CC (DEFAULT_ASM_SPEC, \
++ DEFAULT_ASM_SPEC " " ANDROID_ASM_SPEC)
++
+ #undef LIB_SPEC
+ #define LIB_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
+index fee33a3ef..22fb2ced9 100644
+--- a/gcc/config/i386/gnu-user.h
++++ b/gcc/config/i386/gnu-user.h
+@@ -65,9 +65,14 @@ along with GCC; see the file COPYING3. If not see
+ When the -shared link option is used a final link is not being
+ done. */
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ " -mssse3 -fno-short-enums " \
++
+ #undef ASM_SPEC
+ #define ASM_SPEC \
+- "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
++ "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ #undef SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
+index 7a02a7eb4..cac4179bc 100644
+--- a/gcc/config/i386/gnu-user64.h
++++ b/gcc/config/i386/gnu-user64.h
+@@ -46,6 +46,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define SPEC_X32 "mx32"
+ #endif
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ "%{m32:-mssse3 -fno-short-enums}" \
++ "%{!m32:-msse4.2 -mpopcnt}"
++
+ #undef ASM_SPEC
+ #define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
+index 4b9910fa9..3b11ed086 100644
+--- a/gcc/config/i386/linux-common.h
++++ b/gcc/config/i386/linux-common.h
+@@ -30,7 +30,13 @@ along with GCC; see the file COPYING3. If not see
+ #undef CC1_SPEC
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC \
++ ANDROID_TARGET_CC1_SPEC \
++ " " \
++ ANDROID_CC1_SPEC("-fPIC"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
+ #undef LINK_SPEC
+ #define LINK_SPEC \
+diff --git a/gcc/config/linux-android.h b/gcc/config/linux-android.h
+index 301a41ccd..9623c88d0 100644
+--- a/gcc/config/linux-android.h
++++ b/gcc/config/linux-android.h
+@@ -38,15 +39,18 @@
+ "%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}"
+
+ #define ANDROID_LINK_SPEC \
+- "%{shared: -Bsymbolic}"
++ "%{shared: -Bsymbolic} -z noexecstack -z relro -z now"
+
+-#define ANDROID_CC1_SPEC \
++#define ANDROID_CC1_SPEC(ANDROID_PIC_DEFAULT) \
+ "%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \
+- "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
++ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: " ANDROID_PIC_DEFAULT "}}}}"
+
+ #define ANDROID_CC1PLUS_SPEC \
+- "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \
+- "%{!frtti:%{!fno-rtti: -fno-rtti}}"
++ "%{!fexceptions:%{!fno-exceptions: -fexceptions}} " \
++ "%{!frtti:%{!fno-rtti: -frtti}}"
++
++#define ANDROID_ASM_SPEC \
++ "--noexecstack"
+
+ #define ANDROID_LIB_SPEC \
+ "%{!static: -ldl}"
+diff --git a/gcc/config/mips/android.h b/gcc/config/mips/android.h
+new file mode 100644
+index 000000000..32c539c8d
+--- /dev/null
++++ b/gcc/config/mips/android.h
+@@ -0,0 +1,49 @@
++/* Target macros for mips*-*android* targets.
++ Copyright (C) 2014 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 DRIVER_SELF_SPECS
++#define DRIVER_SELF_SPECS \
++ /* Make sure a -mips option is present. This helps us to pick \
++ the right multilib, and also makes the later specs easier \
++ to write. */ \
++ MIPS_ISA_LEVEL_SPEC, \
++ \
++ /* Infer the default float setting from -march. */ \
++ MIPS_ARCH_FLOAT_SPEC, \
++ \
++ /* Infer the -msynci setting from -march if not explicitly set. */ \
++ MIPS_ISA_SYNCI_SPEC, \
++ \
++ /* If no ABI option is specified, infer one from the ISA level \
++ or -mgp setting. */ \
++ "%{!mabi=*: %{" MIPS_32BIT_OPTION_SPEC ": -mabi=32;: -mabi=64}}", \
++ \
++ /* If no FP ABI option is specified, infer one from the \
++ ABI/ISA level unless there is a conflicting option. */ \
++ "%{!msoft-float: %{!msingle-float: %{!mfp*: %{!mmsa: %{mabi=32: %{" \
++ MIPS_FPXX_OPTION_SPEC ": -mfpxx}}}}}}", \
++ \
++ /* If no odd-spreg option is specified, infer one from the ISA. */ \
++ "%{!modd-spreg: %{mabi=32: %{mips32r6: -mno-odd-spreg}}}", \
++ \
++ /* Base SPECs. */ \
++ BASE_DRIVER_SELF_SPECS, \
++ \
++ /* Use the standard linux specs for everything else. */ \
++ LINUX_DRIVER_SELF_SPECS
+diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
+index 15b549c08..4a2816014 100644
+--- a/gcc/config/mips/gnu-user.h
++++ b/gcc/config/mips/gnu-user.h
+@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
+ /* The GNU C++ standard library requires this. */ \
+ if (c_dialect_cxx ()) \
+ builtin_define ("_GNU_SOURCE"); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
+ } while (0)
+
+ #undef SUBTARGET_CPP_SPEC
+@@ -71,7 +72,8 @@ along with GCC; see the file COPYING3. If not see
+
+ #undef SUBTARGET_ASM_SPEC
+ #define SUBTARGET_ASM_SPEC \
+- "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}}"
++ "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ /* The MIPS assembler has different syntax for .set. We set it to
+ .dummy to trap any errors. */
+@@ -120,7 +122,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #endif
+
+ #define LINUX_DRIVER_SELF_SPECS \
+- NO_SHARED_SPECS \
++ LINUX_OR_ANDROID_CC(NO_SHARED_SPECS, "") \
+ MARCH_MTUNE_NATIVE_SPECS, \
+ /* -mplt has no effect without -mno-shared. Simplify later \
+ specs handling by removing a redundant option. */ \
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8429a7ca2..8bfacf994 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see
+ #undef SUBTARGET_CC1_SPEC
+ #define SUBTARGET_CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
+
+ #undef CC1PLUS_SPEC
+ #define CC1PLUS_SPEC \
+diff --git a/gcc/config/mips/t-linux-android b/gcc/config/mips/t-linux-android
+new file mode 100644
+index 000000000..39f512c81
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android
+@@ -0,0 +1,3 @@
++MULTILIB_OPTIONS = mips32r2/mips32r6
++MULTILIB_DIRNAMES = mips-r2 mips-r6
++MULTILIB_OSDIRNAMES = ../libr2 ../libr6
+diff --git a/gcc/config/mips/t-linux-android64 b/gcc/config/mips/t-linux-android64
+new file mode 100644
+index 000000000..55cab7d62
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android64
+@@ -0,0 +1,4 @@
++MULTILIB_OPTIONS = mabi=32 mips32/mips32r2/mips32r6/mips64r2/mips64r6
++MULTILIB_DIRNAMES = 32 mips-r1 mips-r2 mips-r6 mips64-r2 mips64-r6
++MULTILIB_OSDIRNAMES = ../lib ../lib ../libr2 ../libr6 ../lib64r2 ../lib64
++MULTILIB_REQUIRED = mabi=32/mips32 mabi=32/mips32r2 mabi=32/mips32r6 mips64r2 mips64r6
+diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
+index 555c0fe24..47c8655f9 100644
+--- a/libgcc/gthr-posix.h
++++ b/libgcc/gthr-posix.h
+@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define __GTHREADS 1
+ #define __GTHREADS_CXX0X 1
+
++/* The following should normally be in a different header file,
++ * but I couldn't find the right location. The point of the macro
++ * definition below is to prevent libsupc++ and libstdc++ to reference
++ * weak symbols in their static C++ constructors. Such code crashes
++ * when a shared object linked statically to these libraries is
++ * loaded on Android 2.1 (Eclair) and older platform releases, due
++ * to a dynamic linker bug.
++ */
++#ifdef __ANDROID__
++#undef GTHREAD_USE_WEAK
++#define GTHREAD_USE_WEAK 0
++#endif
++
+ #include <pthread.h>
+
+ #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
+diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
+index 41797a971..f746e8353 100755
+--- a/libstdc++-v3/configure
++++ b/libstdc++-v3/configure
+@@ -78319,6 +78341,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+@@ -78377,6 +78405,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h
+index e3e206b7d..e85dc2c76 100644
+--- a/libstdc++-v3/include/bits/locale_facets.h
++++ b/libstdc++-v3/include/bits/locale_facets.h
+@@ -47,6 +47,20 @@
+ #include <ext/numeric_traits.h>
+ #include <bits/streambuf_iterator.h>
+
++#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ == 9 && __i386__
++// CrystaX: for some reason, x86 gcc-4.9 makes ctype<char>::do_widen() and
++// ctype<char>::_M_widen_init() methods working wrong if optimization enabled.
++// For ctype<char>::do_widen(), values of passed arguments (__lo, __hi and __to)
++// are completely messed up and don't correspond to passed values. In case if
++// we disable optimization for those methods, things become correct so we apply
++// this workaround here for a time.
++// TODO: figure out what exactly wrong here - is it bug in GCC optimization
++// algorithm or smth else?
++#define __CRYSTAX_X86_DONT_OPTIMIZE __attribute__((optimize(0)))
++#else
++#define __CRYSTAX_X86_DONT_OPTIMIZE
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -1102,7 +1116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ * @return @a __hi.
+ */
+ virtual const char*
+- do_widen(const char* __lo, const char* __hi, char_type* __to) const
++ do_widen(const char* __lo, const char* __hi, char_type* __to) const __CRYSTAX_X86_DONT_OPTIMIZE
+ {
+ __builtin_memcpy(__to, __lo, __hi - __lo);
+ return __hi;
+@@ -1163,7 +1177,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ private:
+ void _M_narrow_init() const;
+- void _M_widen_init() const;
++ void _M_widen_init() const __CRYSTAX_X86_DONT_OPTIMIZE;
+ };
+
+ #ifdef _GLIBCXX_USE_WCHAR_T
+diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc
+index 9b617998f..c149169bb 100644
+--- a/libstdc++-v3/libsupc++/guard.cc
++++ b/libstdc++-v3/libsupc++/guard.cc
+@@ -33,7 +33,12 @@
+ #if defined(__GTHREADS) && defined(__GTHREAD_HAS_COND) \
+ && (ATOMIC_INT_LOCK_FREE > 1) && defined(_GLIBCXX_HAVE_LINUX_FUTEX)
+ # include <climits>
++#if defined(__ANDROID__)
++# include <sys/syscall.h>
++# define SYS_futex __NR_futex
++#else
+ # include <syscall.h>
++#endif
+ # include <unistd.h>
+ # define _GLIBCXX_USE_FUTEX
+ # define _GLIBCXX_FUTEX_WAIT 0
diff --git a/patches/gcc/7.1.0/971-crystax.patch b/patches/gcc/7.1.0/971-crystax.patch
new file mode 100644
index 0000000..748a381
--- /dev/null
+++ b/patches/gcc/7.1.0/971-crystax.patch
@@ -0,0 +1,25 @@
+commit 9f057b62caafe08c968103d39b5df82486a175c2
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 13 16:11:54 2015 +0300
+
+ [android] Add additional multilib option: mfloat-abi=hard
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/t-linux-androideabi b/gcc/config/arm/t-linux-androideabi
+index 8f1307c55..cbbec5bd2 100644
+--- a/gcc/config/arm/t-linux-androideabi
++++ b/gcc/config/arm/t-linux-androideabi
+@@ -1,8 +1,9 @@
+-MULTILIB_OPTIONS = march=armv7-a mthumb
+-MULTILIB_DIRNAMES = armv7-a thumb
+-MULTILIB_EXCEPTIONS =
++MULTILIB_OPTIONS = march=armv7-a mthumb mfloat-abi=hard
++MULTILIB_DIRNAMES = armv7-a thumb hard
++MULTILIB_EXCEPTIONS = mfloat-abi=hard* mthumb/mfloat-abi=hard*
+ MULTILIB_MATCHES =
+ MULTILIB_OSDIRNAMES =
++MULTILIB_EXTRA_OPTS = Wl,--no-warn-mismatch
+
+ # The "special" multilib can be used to build native applications for Android,
+ # as opposed to native shared libraries that are then called via JNI.
diff --git a/patches/gcc/7.1.0/972-crystax.patch b/patches/gcc/7.1.0/972-crystax.patch
new file mode 100644
index 0000000..b9077be
--- /dev/null
+++ b/patches/gcc/7.1.0/972-crystax.patch
@@ -0,0 +1,302 @@
+commit 44a81ebb7698dac41ffa7acd5e0cc1578e5ab1fd
+Author: H.J. Lu <hongjiu.lu@intel.com>
+Date: Mon Apr 14 15:59:47 2014 -0700
+
+ [android] Always enable --eh-frame-hdr for static executable
+
+ See 5e6cdf76af295c9a39b695ca228cff675e8ff4ae and
+ 23e3137ee2897464b051599b85a09f130d3ad05d
+
+ Change-Id: Ibda473188e5a10f2a0592f2494ad00ad1f91e04b
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config.in b/gcc/config.in
+index 115cb6163..933916833 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -2119,6 +2119,12 @@
+ #endif
+
+
++/* Define if your system supports PT_GNU_EH_FRAME for static executable. */
++#ifndef USED_FOR_TARGET
++#undef USE_EH_FRAME_HDR_FOR_STATIC
++#endif
++
++
+ /* Define to 1 if the 'long long' type is wider than 'long' but still
+ efficiently supported by the host hardware. */
+ #ifndef USED_FOR_TARGET
+diff --git a/gcc/config/alpha/elf.h b/gcc/config/alpha/elf.h
+index 093c38bba..54b3e0c91 100644
+--- a/gcc/config/alpha/elf.h
++++ b/gcc/config/alpha/elf.h
+@@ -168,5 +168,9 @@ extern int alpha_this_gpdisp_sequence_number;
+ I imagine that other systems will catch up. In the meantime, it
+ doesn't harm to make sure that the data exists to be used later. */
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+diff --git a/gcc/config/freebsd.h b/gcc/config/freebsd.h
+index 5ded869d2..5f51ac81d 100644
+--- a/gcc/config/freebsd.h
++++ b/gcc/config/freebsd.h
+@@ -45,8 +45,12 @@ along with GCC; see the file COPYING3. If not see
+ #define LIB_SPEC FBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #ifdef TARGET_LIBC_PROVIDES_SSP
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
+index b0bf40a95..d1874bc29 100644
+--- a/gcc/config/gnu-user.h
++++ b/gcc/config/gnu-user.h
+@@ -118,8 +118,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LINK_GCC_C_SEQUENCE_SPEC
+ #define LINK_GCC_C_SEQUENCE_SPEC \
+diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h
+index 37ecfc43f..a5f1b9955 100644
+--- a/gcc/config/openbsd.h
++++ b/gcc/config/openbsd.h
+@@ -136,8 +136,12 @@ while (0)
+ #define LIB_SPEC OBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LIB_SPEC
+ #define LIB_SPEC OBSD_LIB_SPEC
+diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
+index cbf909722..eb2217fad 100644
+--- a/gcc/config/rs6000/sysv4.h
++++ b/gcc/config/rs6000/sysv4.h
+@@ -789,7 +789,11 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
+-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# ifdef USE_EH_FRAME_HDR_FOR_STATIC
++# define LINK_EH_SPEC "--eh-frame-hdr "
++# else
++# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# endif
+ #endif
+
+ #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
+diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
+index 5160e1fda..7632a5081 100644
+--- a/gcc/config/sol2.h
++++ b/gcc/config/sol2.h
+@@ -347,7 +347,11 @@ along with GCC; see the file COPYING3. If not see
+ /* Solaris 11 build 135+ implements dl_iterate_phdr. GNU ld needs
+ --eh-frame-hdr to create the required .eh_frame_hdr sections. */
+ #if defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++#endif
+ #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
+ #endif
+
+diff --git a/gcc/configure b/gcc/configure
+index 1c6e3407c..28ad05004 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -934,6 +934,7 @@ enable_fix_cortex_a53_835769
+ enable_fix_cortex_a53_843419
+ with_glibc_version
+ enable_gnu_unique_object
++enable_eh_frame_hdr_for_static
+ enable_linker_build_id
+ enable_default_ssp
+ with_long_double_128
+@@ -1670,6 +1671,9 @@ Optional Features:
+ --enable-gnu-unique-object
+ enable the use of the @gnu_unique_object ELF
+ extension on glibc systems
++ --enable-eh-frame-hdr-for-static
++ enable linker PT_GNU_EH_FRAME support for static
++ executable
+ --enable-linker-build-id
+ compiler will always pass --build-id to linker
+ --enable-default-ssp enable Stack Smashing Protection as default
+@@ -27703,6 +27707,38 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+
+ $as_echo "#define HAVE_LD_EH_FRAME_HDR 1" >>confdefs.h
+
++ # Check whether --enable-eh-frame-hdr-for-static was given.
++if test "${enable_eh_frame_hdr_for_static+set}" = set; then :
++ enableval=$enable_eh_frame_hdr_for_static; case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) as_fn_error "'$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
++ esac
++else
++ # Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi
++fi
++
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++
++$as_echo "#define USE_EH_FRAME_HDR_FOR_STATIC 1" >>confdefs.h
++
++ fi
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_eh_frame_hdr" >&5
+ $as_echo "$gcc_cv_ld_eh_frame_hdr" >&6; }
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 6c1dcd9ae..0cf7419e7 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -4828,6 +4828,35 @@ GCC_TARGET_TEMPLATE([HAVE_LD_EH_FRAME_HDR])
+ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+ AC_DEFINE(HAVE_LD_EH_FRAME_HDR, 1,
+ [Define if your linker supports .eh_frame_hdr.])
++ AC_ARG_ENABLE(eh-frame-hdr-for-static,
++ [AS_HELP_STRING([--enable-eh-frame-hdr-for-static],
++ [enable linker PT_GNU_EH_FRAME support for static executable])],
++ [case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) AC_MSG_ERROR(['$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'.]) ;;
++ esac],
++# Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ [[if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi]])
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++ AC_DEFINE(USE_EH_FRAME_HDR_FOR_STATIC, 1,
++[Define if your system supports PT_GNU_EH_FRAME for static executable.])
++ fi
+ fi
+ AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr)
+
+diff --git a/gcc/testsuite/g++.dg/eh/spec3-static.C b/gcc/testsuite/g++.dg/eh/spec3-static.C
+new file mode 100644
+index 000000000..15408effa
+--- /dev/null
++++ b/gcc/testsuite/g++.dg/eh/spec3-static.C
+@@ -0,0 +1,25 @@
++// PR c++/4381
++// Test that exception-specs work properly for classes with virtual bases.
++
++// { dg-do run }
++// { dg-options "-static" }
++
++class Base {};
++
++struct A : virtual public Base
++{
++ A() {}
++};
++
++struct B {};
++
++void func() throw (B,A)
++{
++ throw A();
++}
++
++int main(void)
++{
++ try { func(); }
++ catch (A& a) { }
++}
+diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
+index f3343fc4f..d42647779 100644
+--- a/libgcc/crtstuff.c
++++ b/libgcc/crtstuff.c
+@@ -88,7 +88,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -97,7 +98,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__sun__) && defined(__svr4__)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -106,7 +108,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__GLIBC__) && __GLIBC__ >= 2
+ #include <link.h>
+ /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
+@@ -121,7 +124,7 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(CRTSTUFFT_O) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(inhibit_libc) \
+ && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
+ /* On systems using glibc, an inhibit_libc build of libgcc is only
diff --git a/patches/gcc/7.1.0/973-crystax.patch b/patches/gcc/7.1.0/973-crystax.patch
new file mode 100644
index 0000000..b96ece3
--- /dev/null
+++ b/patches/gcc/7.1.0/973-crystax.patch
@@ -0,0 +1,20 @@
+commit 778a9ef107f51544d583f110e92b75f4d9d79117
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 20 19:11:07 2015 +0300
+
+ [android] Don't use PIE copyrelocs for x86/x86_64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
+index 3d044e8bd..5c89fcab0 100644
+--- a/gcc/config/i386/i386.c
++++ b/gcc/config/i386/i386.c
+@@ -14631,6 +14631,7 @@ legitimate_pic_address_disp_p (rtx disp)
+ else if (!SYMBOL_REF_FAR_ADDR_P (op0)
+ && (SYMBOL_REF_LOCAL_P (op0)
+ || (HAVE_LD_PIE_COPYRELOC
++ && !TARGET_HAS_BIONIC
+ && flag_pie
+ && !SYMBOL_REF_WEAK (op0)
+ && !SYMBOL_REF_FUNCTION_P (op0)))
diff --git a/patches/gcc/7.1.0/974-crystax.patch b/patches/gcc/7.1.0/974-crystax.patch
new file mode 100644
index 0000000..9db4f54
--- /dev/null
+++ b/patches/gcc/7.1.0/974-crystax.patch
@@ -0,0 +1,24 @@
+commit dbeae1190cabad83999f2540523f045acc1bb4ec
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Fri Aug 21 17:41:59 2015 +0300
+
+ [android] Always use gthr-posix.h instead of gthr-default.h
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/libgcc/gthr.h b/libgcc/gthr.h
+index 47a7d061a..67a680f90 100644
+--- a/libgcc/gthr.h
++++ b/libgcc/gthr.h
+@@ -145,7 +145,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define GTHREAD_USE_WEAK 1
+ #endif
+ #endif
++#if __ANDROID__
++#include "gthr-posix.h"
++#else
+ #include "gthr-default.h"
++#endif
+
+ #ifndef HIDE_EXPORTS
+ #pragma GCC visibility pop
diff --git a/patches/gcc/7.1.0/975-crystax.patch b/patches/gcc/7.1.0/975-crystax.patch
new file mode 100644
index 0000000..9efc2a4
--- /dev/null
+++ b/patches/gcc/7.1.0/975-crystax.patch
@@ -0,0 +1,31 @@
+commit 8a66d422721ae5999737d7825701ff22097d287b
+Author: Andrew Hsieh <andrewhsieh@google.com>
+Date: Mon Apr 14 21:05:51 2014 -0700
+
+ [android] Fix ARM generates insufficient alignment for NEON vst/vld
+
+ See d909af3e2469aad87d5c3e79b93c778fd26c03a9
+
+ Change-Id: Ie1de9f946f397196bb6f1623f5add86933739484
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
+index 5974c65d3..71b2c7aa9 100644
+--- a/gcc/config/arm/arm.c
++++ b/gcc/config/arm/arm.c
+@@ -22403,9 +22403,13 @@ arm_print_operand (FILE *stream, rtx x, int code)
+ memsize = MEM_SIZE (x);
+
+ /* Only certain alignment specifiers are supported by the hardware. */
+- if (memsize == 32 && (align % 32) == 0)
++ /* Note that ARM EABI only guarentees 8-byte stack alignment. While GCC
++ honors stricter alignment of composite type in user code, it doesn't
++ observe the alignment of memory passed as an extra argument for function
++ returning large composite type. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57271 */
++ if (memsize == 32 && (align % 32) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 256;
+- else if ((memsize == 16 || memsize == 32) && (align % 16) == 0)
++ else if ((memsize == 16 || memsize == 32) && (align % 16) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 128;
+ else if (memsize >= 8 && (align % 8) == 0)
+ align_bits = 64;
diff --git a/patches/gcc/7.1.0/976-crystax.patch b/patches/gcc/7.1.0/976-crystax.patch
new file mode 100644
index 0000000..790d4a9
--- /dev/null
+++ b/patches/gcc/7.1.0/976-crystax.patch
@@ -0,0 +1,21 @@
+commit 89d27bc45ee7325dcfff6748da0f8b9c1dc1f234
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Sat Aug 22 09:55:55 2015 +0300
+
+ [android][i386] Remove throw() declaration from posix_memalign() proto
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
+index a1f98d3d1..3725799be 100644
+--- a/gcc/config/i386/pmm_malloc.h
++++ b/gcc/config/i386/pmm_malloc.h
+@@ -31,7 +31,7 @@
+ #ifndef __cplusplus
+ extern int posix_memalign (void **, size_t, size_t);
+ #else
+-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
++extern "C" int posix_memalign (void **, size_t, size_t);
+ #endif
+
+ static __inline void *
diff --git a/patches/gcc/7.1.0/977-crystax.patch b/patches/gcc/7.1.0/977-crystax.patch
new file mode 100644
index 0000000..0211d72
--- /dev/null
+++ b/patches/gcc/7.1.0/977-crystax.patch
@@ -0,0 +1,33 @@
+commit 9ae82f7cfc1073820092dd9f957559667e77db0d
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Tue Aug 25 09:36:42 2015 +0300
+
+ [android] Explicitly make _Unwind_Resume visible for arm64/mips64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+index db1288fd0..38bc64d61 100644
+--- a/gcc/config/aarch64/aarch64-linux-android.h
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -57,4 +57,8 @@
+ #define ENDFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
+
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif
++
+ #endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8bfacf994..262a9a341 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -63,3 +63,7 @@ along with GCC; see the file COPYING3. If not see
+
+ /* The default value isn't sufficient in 64-bit mode. */
+ #define STACK_CHECK_PROTECT (TARGET_64BIT ? 16 * 1024 : 12 * 1024)
++
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif
diff --git a/patches/gcc/linaro-4.8-2015.06/874-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/linaro-4.8-2015.06/874-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..6013fef
--- /dev/null
+++ b/patches/gcc/linaro-4.8-2015.06/874-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,73 @@
+From 0343a584d6b5128908eabf1db43c70bed7114989 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index dbc5bd3..466adb5 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1772,7 +1772,7 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call8\t0x%lx", INTVAL (tgt));
++ sprintf (result, "call8\t" HOST_WIDE_INT_PRINT_HEX, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx8\t%%%d", callop);
+ else
+@@ -2347,14 +2347,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2368,7 +2368,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2437,7 +2437,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/linaro-4.9-2017.01/1100-msp430-string-literals.patch b/patches/gcc/linaro-4.9-2017.01/1100-msp430-string-literals.patch
new file mode 100644
index 0000000..346842e
--- /dev/null
+++ b/patches/gcc/linaro-4.9-2017.01/1100-msp430-string-literals.patch
@@ -0,0 +1,27 @@
+commit 9d247a3d78b97c004e7ca5e7d6cc9964dba870c7
+Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Wed May 13 01:11:13 2015 +0000
+
+ gcc/
+ * config/mmix/mmix.c, config/msp430/msp430.c: Add space between
+ string literal and macro name.
+ gcc/ada/
+ * sigtramp-vxworks.c: Add space between string literal and macro
+ name.
+
+ git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223106 138bc75d-0d04-0410-961f-82ee72b054a4
+
+[4.9 change: remove non-applicable parts of the patch]
+diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
+index bec168ca2ae..58d0efea1de 100644
+--- a/gcc/config/msp430/msp430.c
++++ b/gcc/config/msp430/msp430.c
+@@ -2248,7 +2248,7 @@ static struct
+ }
+ const_shift_helpers[] =
+ {
+-#define CSH(N,C,X,G) { "__mspabi_"N, C, X, gen_##G }
++#define CSH(N,C,X,G) { "__mspabi_" N, C, X, gen_##G }
+
+ CSH ("slli", 1, 1, slli_1),
+ CSH ("slll", 1, 1, slll_1),
diff --git a/patches/gcc/linaro-4.9-2017.01/875-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/linaro-4.9-2017.01/875-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..052ffc3
--- /dev/null
+++ b/patches/gcc/linaro-4.9-2017.01/875-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,73 @@
+From 0f32ae7bc51725cd500e2877b571fd914d77852e Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 10 +++++-----
+ 1 file changed, 5 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index d8c8298..3c00961 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1785,7 +1785,7 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call8\t0x%lx", INTVAL (tgt));
++ sprintf (result, "call8\t" HOST_WIDE_INT_PRINT_HEX, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx8\t%%%d", callop);
+ else
+@@ -2360,14 +2360,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2381,7 +2381,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2450,7 +2450,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/linaro-5.4-2017.01/100-uclibc-conf.patch b/patches/gcc/linaro-5.4-2017.05/100-uclibc-conf.patch
index 73d1f0d..73d1f0d 100644
--- a/patches/gcc/linaro-5.4-2017.01/100-uclibc-conf.patch
+++ b/patches/gcc/linaro-5.4-2017.05/100-uclibc-conf.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/1000-libtool-leave-framework-alone.patch b/patches/gcc/linaro-5.4-2017.05/1000-libtool-leave-framework-alone.patch
index 0f4912a..0f4912a 100644
--- a/patches/gcc/linaro-5.4-2017.01/1000-libtool-leave-framework-alone.patch
+++ b/patches/gcc/linaro-5.4-2017.05/1000-libtool-leave-framework-alone.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/110-xtensa-implement-trap-pattern.patch b/patches/gcc/linaro-5.4-2017.05/110-xtensa-implement-trap-pattern.patch
index 3304532..3304532 100644
--- a/patches/gcc/linaro-5.4-2017.01/110-xtensa-implement-trap-pattern.patch
+++ b/patches/gcc/linaro-5.4-2017.05/110-xtensa-implement-trap-pattern.patch
diff --git a/patches/gcc/linaro-5.4-2017.05/1100-msp430-string-literals.patch b/patches/gcc/linaro-5.4-2017.05/1100-msp430-string-literals.patch
new file mode 100644
index 0000000..819d6d2
--- /dev/null
+++ b/patches/gcc/linaro-5.4-2017.05/1100-msp430-string-literals.patch
@@ -0,0 +1,81 @@
+commit 9d247a3d78b97c004e7ca5e7d6cc9964dba870c7
+Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
+Date: Wed May 13 01:11:13 2015 +0000
+
+ gcc/
+ * config/mmix/mmix.c, config/msp430/msp430.c: Add space between
+ string literal and macro name.
+ gcc/ada/
+ * sigtramp-vxworks.c: Add space between string literal and macro
+ name.
+
+ git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@223106 138bc75d-0d04-0410-961f-82ee72b054a4
+
+diff --git a/gcc/ada/sigtramp-vxworks.c b/gcc/ada/sigtramp-vxworks.c
+index 2119296dc1d..c697626a03e 100644
+--- a/gcc/ada/sigtramp-vxworks.c
++++ b/gcc/ada/sigtramp-vxworks.c
+@@ -342,16 +342,16 @@ CR("") \
+ TCR("# Allocate frame and save the non-volatile") \
+ TCR("# registers we're going to modify") \
+ TCR("mov ip, sp") \
+-TCR("stmfd sp!, {r"S(CFA_REG)", fp, ip, lr, pc}") \
++TCR("stmfd sp!, {r" S(CFA_REG)", fp, ip, lr, pc}") \
+ TCR("# Setup CFA_REG = context, which we'll retrieve as our CFA value") \
+-TCR("ldr r"S(CFA_REG)", [ip]") \
++TCR("ldr r" S(CFA_REG)", [ip]") \
+ TCR("") \
+ TCR("# Call the real handler. The signo, siginfo and sigcontext") \
+ TCR("# arguments are the same as those we received in r0, r1 and r2") \
+ TCR("sub fp, ip, #4") \
+ TCR("blx r3") \
+ TCR("# Restore our callee-saved items, release our frame and return") \
+-TCR("ldmfd sp, {r"S(CFA_REG)", fp, sp, pc}")
++TCR("ldmfd sp, {r" S(CFA_REG)", fp, sp, pc}")
+
+ #else
+ Not_implemented;
+diff --git a/gcc/config/mmix/mmix.c b/gcc/config/mmix/mmix.c
+index 6e991207dbc..e0699854e25 100644
+--- a/gcc/config/mmix/mmix.c
++++ b/gcc/config/mmix/mmix.c
+@@ -2520,7 +2520,7 @@ mmix_output_shiftvalue_op_from_str (FILE *stream,
+ if (! mmix_shiftable_wyde_value (value))
+ {
+ char s[sizeof ("0xffffffffffffffff")];
+- sprintf (s, "%#"PRIx64, value);
++ sprintf (s, "%#" PRIx64, value);
+ internal_error ("MMIX Internal: %s is not a shiftable int", s);
+ }
+
+@@ -2562,7 +2562,7 @@ mmix_output_octa (FILE *stream, int64_t value, int do_begin_end)
+ fprintf (stream, "#" HOST_WIDE_INT_PRINT_HEX_PURE,
+ (HOST_WIDE_INT) value);
+ else /* Need to avoid the hex output; there's no ...WIDEST...HEX_PURE. */
+- fprintf (stream, "%"PRIu64, value);
++ fprintf (stream, "%" PRIu64, value);
+
+ if (do_begin_end)
+ fprintf (stream, "\n");
+@@ -2579,7 +2579,7 @@ mmix_output_shifted_value (FILE *stream, int64_t value)
+ if (! mmix_shiftable_wyde_value (value))
+ {
+ char s[16+2+1];
+- sprintf (s, "%#"PRIx64, value);
++ sprintf (s, "%#" PRIx64, value);
+ internal_error ("MMIX Internal: %s is not a shiftable int", s);
+ }
+
+diff --git a/gcc/config/msp430/msp430.c b/gcc/config/msp430/msp430.c
+index bec168ca2ae..58d0efea1de 100644
+--- a/gcc/config/msp430/msp430.c
++++ b/gcc/config/msp430/msp430.c
+@@ -2248,7 +2248,7 @@ static struct
+ }
+ const_shift_helpers[] =
+ {
+-#define CSH(N,C,X,G) { "__mspabi_"N, C, X, gen_##G }
++#define CSH(N,C,X,G) { "__mspabi_" N, C, X, gen_##G }
+
+ CSH ("slli", 1, 1, slli_1),
+ CSH ("slll", 1, 1, slll_1),
diff --git a/patches/gcc/linaro-5.4-2017.01/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch b/patches/gcc/linaro-5.4-2017.05/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch
index c11ad35..c11ad35 100644
--- a/patches/gcc/linaro-5.4-2017.01/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch
+++ b/patches/gcc/linaro-5.4-2017.05/120-gcc-config.gcc-fix-typo-for-powerpc-e6500-cpu_is_64b.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/301-missing-execinfo_h.patch b/patches/gcc/linaro-5.4-2017.05/301-missing-execinfo_h.patch
index 2d0e7ba..2d0e7ba 100644
--- a/patches/gcc/linaro-6.3-2017.02/301-missing-execinfo_h.patch
+++ b/patches/gcc/linaro-5.4-2017.05/301-missing-execinfo_h.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch b/patches/gcc/linaro-5.4-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
index d8986d5..d8986d5 100644
--- a/patches/gcc/linaro-5.4-2017.01/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
+++ b/patches/gcc/linaro-5.4-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/380-gcc-plugin-POSIX-include-sys-select-h.patch b/patches/gcc/linaro-5.4-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch
index 12ef48e..12ef48e 100644
--- a/patches/gcc/linaro-5.4-2017.01/380-gcc-plugin-POSIX-include-sys-select-h.patch
+++ b/patches/gcc/linaro-5.4-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/810-arm-softfloat-libgcc.patch b/patches/gcc/linaro-5.4-2017.05/810-arm-softfloat-libgcc.patch
index 5efa7fd..5efa7fd 100644
--- a/patches/gcc/linaro-5.4-2017.01/810-arm-softfloat-libgcc.patch
+++ b/patches/gcc/linaro-5.4-2017.05/810-arm-softfloat-libgcc.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/830-arm_unbreak_armv4t.patch b/patches/gcc/linaro-5.4-2017.05/830-arm_unbreak_armv4t.patch
index b730059..b730059 100644
--- a/patches/gcc/linaro-6.3-2017.02/830-arm_unbreak_armv4t.patch
+++ b/patches/gcc/linaro-5.4-2017.05/830-arm_unbreak_armv4t.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/840-microblaze-enable-dwarf-eh-support.patch b/patches/gcc/linaro-5.4-2017.05/840-microblaze-enable-dwarf-eh-support.patch
index 9d29090..9d29090 100644
--- a/patches/gcc/linaro-5.4-2017.01/840-microblaze-enable-dwarf-eh-support.patch
+++ b/patches/gcc/linaro-5.4-2017.05/840-microblaze-enable-dwarf-eh-support.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/850-libstdcxx-uclibc-c99.patch b/patches/gcc/linaro-5.4-2017.05/850-libstdcxx-uclibc-c99.patch
index 9e97d94..9e97d94 100644
--- a/patches/gcc/linaro-5.4-2017.01/850-libstdcxx-uclibc-c99.patch
+++ b/patches/gcc/linaro-5.4-2017.05/850-libstdcxx-uclibc-c99.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/860-cilk-wchar.patch b/patches/gcc/linaro-5.4-2017.05/860-cilk-wchar.patch
index 1d9916f..1d9916f 100644
--- a/patches/gcc/linaro-5.4-2017.01/860-cilk-wchar.patch
+++ b/patches/gcc/linaro-5.4-2017.05/860-cilk-wchar.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/870-xtensa-add-mauto-litpools-option.patch b/patches/gcc/linaro-5.4-2017.05/870-xtensa-add-mauto-litpools-option.patch
index aa1376c..aa1376c 100644
--- a/patches/gcc/linaro-5.4-2017.01/870-xtensa-add-mauto-litpools-option.patch
+++ b/patches/gcc/linaro-5.4-2017.05/870-xtensa-add-mauto-litpools-option.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/871-xtensa-reimplement-register-spilling.patch b/patches/gcc/linaro-5.4-2017.05/871-xtensa-reimplement-register-spilling.patch
index 4056f8b..4056f8b 100644
--- a/patches/gcc/linaro-5.4-2017.01/871-xtensa-reimplement-register-spilling.patch
+++ b/patches/gcc/linaro-5.4-2017.05/871-xtensa-reimplement-register-spilling.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch b/patches/gcc/linaro-5.4-2017.05/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch
index 9707f68..9707f68 100644
--- a/patches/gcc/linaro-5.4-2017.01/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch
+++ b/patches/gcc/linaro-5.4-2017.05/872-xtensa-use-unwind-dw2-fde-dip-instead-of-unwind-dw2-.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/873-xtensa-fix-_Unwind_GetCFA.patch b/patches/gcc/linaro-5.4-2017.05/873-xtensa-fix-_Unwind_GetCFA.patch
index 2d8eb7c..2d8eb7c 100644
--- a/patches/gcc/linaro-5.4-2017.01/873-xtensa-fix-_Unwind_GetCFA.patch
+++ b/patches/gcc/linaro-5.4-2017.05/873-xtensa-fix-_Unwind_GetCFA.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/874-xtensa-add-uclinux-support.patch b/patches/gcc/linaro-5.4-2017.05/874-xtensa-add-uclinux-support.patch
index 23db3d8..23db3d8 100644
--- a/patches/gcc/linaro-5.4-2017.01/874-xtensa-add-uclinux-support.patch
+++ b/patches/gcc/linaro-5.4-2017.05/874-xtensa-add-uclinux-support.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch b/patches/gcc/linaro-5.4-2017.05/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch
index d128596..d128596 100644
--- a/patches/gcc/linaro-5.4-2017.01/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch
+++ b/patches/gcc/linaro-5.4-2017.05/875-xtensa-fix-xtensa_fallback_frame_state-for-call0-ABI.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/876-xtensa-fix-libgcc-build-with-text-section-literals.patch b/patches/gcc/linaro-5.4-2017.05/876-xtensa-fix-libgcc-build-with-text-section-literals.patch
index 4b2334a..4b2334a 100644
--- a/patches/gcc/linaro-5.4-2017.01/876-xtensa-fix-libgcc-build-with-text-section-literals.patch
+++ b/patches/gcc/linaro-5.4-2017.05/876-xtensa-fix-libgcc-build-with-text-section-literals.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch b/patches/gcc/linaro-5.4-2017.05/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
index 6e0ce6e..6e0ce6e 100644
--- a/patches/gcc/linaro-5.4-2017.01/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
+++ b/patches/gcc/linaro-5.4-2017.05/877-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/878-xtensa-Fix-PR-target-78603.patch b/patches/gcc/linaro-5.4-2017.05/878-xtensa-Fix-PR-target-78603.patch
index 4646d3c..4646d3c 100644
--- a/patches/gcc/linaro-5.4-2017.01/878-xtensa-Fix-PR-target-78603.patch
+++ b/patches/gcc/linaro-5.4-2017.05/878-xtensa-Fix-PR-target-78603.patch
diff --git a/patches/gcc/linaro-5.4-2017.05/879-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/linaro-5.4-2017.05/879-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..e75e258
--- /dev/null
+++ b/patches/gcc/linaro-5.4-2017.05/879-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,74 @@
+From 1117c8be9e712f778739d751aa61038794437d7d Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 36ab1e3..8e62d63 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1811,7 +1811,8 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call%d\t0x%lx", WINDOW_SIZE, INTVAL (tgt));
++ sprintf (result, "call%d\t" HOST_WIDE_INT_PRINT_HEX,
++ WINDOW_SIZE, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx%d\t%%%d", WINDOW_SIZE, callop);
+ else
+@@ -2382,14 +2383,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2403,7 +2404,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2472,7 +2473,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/linaro-6.3-2017.02/890-fix-m68k-compile.patch b/patches/gcc/linaro-5.4-2017.05/890-fix-m68k-compile.patch
index 6e63de0..6e63de0 100644
--- a/patches/gcc/linaro-6.3-2017.02/890-fix-m68k-compile.patch
+++ b/patches/gcc/linaro-5.4-2017.05/890-fix-m68k-compile.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/891-fix-m68k-uclinux.patch b/patches/gcc/linaro-5.4-2017.05/891-fix-m68k-uclinux.patch
index 4e186bd..4e186bd 100644
--- a/patches/gcc/linaro-5.4-2017.01/891-fix-m68k-uclinux.patch
+++ b/patches/gcc/linaro-5.4-2017.05/891-fix-m68k-uclinux.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/892-microblaze-uclibc.patch b/patches/gcc/linaro-5.4-2017.05/892-microblaze-uclibc.patch
index a8eb5a6..a8eb5a6 100644
--- a/patches/gcc/linaro-5.4-2017.01/892-microblaze-uclibc.patch
+++ b/patches/gcc/linaro-5.4-2017.05/892-microblaze-uclibc.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/902-unwind-fix-for-musl.patch b/patches/gcc/linaro-5.4-2017.05/902-unwind-fix-for-musl.patch
index ef47054..ef47054 100644
--- a/patches/gcc/linaro-5.4-2017.01/902-unwind-fix-for-musl.patch
+++ b/patches/gcc/linaro-5.4-2017.05/902-unwind-fix-for-musl.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/910-nios2-bad-multilib-default.patch b/patches/gcc/linaro-5.4-2017.05/910-nios2-bad-multilib-default.patch
index d94697f..d94697f 100644
--- a/patches/gcc/linaro-5.4-2017.01/910-nios2-bad-multilib-default.patch
+++ b/patches/gcc/linaro-5.4-2017.05/910-nios2-bad-multilib-default.patch
diff --git a/patches/gcc/linaro-5.4-2017.01/930-libgcc-disable-split-stack-nothreads.patch b/patches/gcc/linaro-5.4-2017.05/930-libgcc-disable-split-stack-nothreads.patch
index 07f9a73..07f9a73 100644
--- a/patches/gcc/linaro-5.4-2017.01/930-libgcc-disable-split-stack-nothreads.patch
+++ b/patches/gcc/linaro-5.4-2017.05/930-libgcc-disable-split-stack-nothreads.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/940-uclinux-enable-threads.patch b/patches/gcc/linaro-5.4-2017.05/940-uclinux-enable-threads.patch
index 490a55b..490a55b 100644
--- a/patches/gcc/linaro-6.3-2017.02/940-uclinux-enable-threads.patch
+++ b/patches/gcc/linaro-5.4-2017.05/940-uclinux-enable-threads.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/100-uclibc-conf.patch b/patches/gcc/linaro-6.3-2017.05/100-uclibc-conf.patch
new file mode 100644
index 0000000..73d1f0d
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/100-uclibc-conf.patch
@@ -0,0 +1,15 @@
+Index: b/contrib/regression/objs-gcc.sh
+===================================================================
+--- a/contrib/regression/objs-gcc.sh
++++ b/contrib/regression/objs-gcc.sh
+@@ -106,6 +106,10 @@
+ then
+ make all-gdb all-dejagnu all-ld || exit 1
+ make install-gdb install-dejagnu install-ld || exit 1
++elif [ $H_REAL_TARGET = $H_REAL_HOST -a $H_REAL_TARGET = i686-pc-linux-uclibc ]
++ then
++ make all-gdb all-dejagnu all-ld || exit 1
++ make install-gdb install-dejagnu install-ld || exit 1
+ elif [ $H_REAL_TARGET = $H_REAL_HOST ] ; then
+ make bootstrap || exit 1
+ make install || exit 1
diff --git a/patches/gcc/linaro-6.3-2017.05/1000-libtool-leave-framework-alone.patch b/patches/gcc/linaro-6.3-2017.05/1000-libtool-leave-framework-alone.patch
new file mode 100644
index 0000000..bce09eb
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/1000-libtool-leave-framework-alone.patch
@@ -0,0 +1,14 @@
+--- gcc-6.2.0/libtool-ldflags 2016-12-20 11:13:12.669668125 -0800
++++ gcc-6.2.0/libtool-ldflags 2016-12-20 11:28:34.894826286 -0800
+@@ -36,6 +36,11 @@
+ for arg
+ do
+ case $arg in
++ -framework)
++ # libtool handles this option. It should not be prefixed with
++ # -Xcompiler, as that would split it from the argument that
++ # follows.
++ ;;
+ -f*|--*|-static-lib*|-shared-lib*|-B*)
+ # Libtool does not ascribe any special meaning options
+ # that begin with -f or with a double-dash. So, it will
diff --git a/patches/gcc/linaro-5.4-2017.01/301-missing-execinfo_h.patch b/patches/gcc/linaro-6.3-2017.05/301-missing-execinfo_h.patch
index 2d0e7ba..2d0e7ba 100644
--- a/patches/gcc/linaro-5.4-2017.01/301-missing-execinfo_h.patch
+++ b/patches/gcc/linaro-6.3-2017.05/301-missing-execinfo_h.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch b/patches/gcc/linaro-6.3-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
new file mode 100644
index 0000000..d8986d5
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/370-gcc-plugin-Win-Dont-need-undefined-extern-var-refs-nor-fpic.patch
@@ -0,0 +1,160 @@
+diff -urN gcc-5.3.0.orig/config/gcc-plugin.m4 gcc-5.3.0/config/gcc-plugin.m4
+--- gcc-5.3.0.orig/config/gcc-plugin.m4 2015-12-19 14:39:04.120734900 +0000
++++ gcc-5.3.0/config/gcc-plugin.m4 2015-12-20 01:28:45.381965300 +0000
+@@ -20,6 +20,9 @@
+
+ pluginlibs=
+
++ PICFLAG="-fPIC"
++ UNDEFINEDPREAMBLE="extern int X;"
++ UNDEFINEDCODE="return X == 0;"
+ case "${host}" in
+ *-*-darwin*)
+ if test x$build = x$host; then
+@@ -30,6 +33,11 @@
+ export_sym_check=
+ fi
+ ;;
++ *-*-mingw*|*-*-cygwin*|*-*-msys*)
++ PICFLAG=""
++ UNDEFINEDPREAMBLE=""
++ UNDEFINEDCODE=""
++ ;;
+ *)
+ if test x$build = x$host; then
+ export_sym_check="objdump${exeext} -T"
+@@ -81,17 +89,17 @@
+ case "${host}" in
+ *-*-darwin*)
+ CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
+- CFLAGS="$CFLAGS -fPIC"
++ CFLAGS="$CFLAGS ${PICFLAG}"
+ LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
+ ;;
+ *)
+- CFLAGS="$CFLAGS -fPIC"
+- LDFLAGS="$LDFLAGS -fPIC -shared"
++ CFLAGS="$CFLAGS ${PICFLAG}"
++ LDFLAGS="$LDFLAGS ${PICFLAG} -shared"
+ ;;
+ esac
+- AC_MSG_CHECKING([for -fPIC -shared])
++ AC_MSG_CHECKING([for ${PICFLAG} -shared])
+ AC_TRY_LINK(
+- [extern int X;],[return X == 0;],
++ [${UNDEFINEDPREAMBLE}],[${UNDEFINEDCODE}],
+ [AC_MSG_RESULT([yes]); have_pic_shared=yes],
+ [AC_MSG_RESULT([no]); have_pic_shared=no])
+ if test x"$have_pic_shared" != x"yes" -o x"$ac_cv_search_dlopen" = x"no"; then
+diff -urN gcc-5.3.0.orig/gcc/configure gcc-5.3.0/gcc/configure
+--- gcc-5.3.0.orig/gcc/configure 2015-12-19 14:40:16.893975900 +0000
++++ gcc-5.3.0/gcc/configure 2015-12-20 01:28:45.472476700 +0000
+@@ -28386,6 +28386,9 @@
+
+ pluginlibs=
+
++ PICFLAG="-fPIC"
++ UNDEFINEDPREAMBLE="extern int X;"
++ UNDEFINEDCODE="return X == 0;"
+ case "${host}" in
+ *-*-darwin*)
+ if test x$build = x$host; then
+@@ -28396,6 +28399,11 @@
+ export_sym_check=
+ fi
+ ;;
++ *-*-mingw*|*-*-cygwin*|*-*-msys*)
++ PICFLAG=""
++ UNDEFINEDPREAMBLE=""
++ UNDEFINEDCODE=""
++ ;;
+ *)
+ if test x$build = x$host; then
+ export_sym_check="objdump${exeext} -T"
+@@ -28508,23 +28516,23 @@
+ case "${host}" in
+ *-*-darwin*)
+ CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
+- CFLAGS="$CFLAGS -fPIC"
++ CFLAGS="$CFLAGS ${PICFLAG}"
+ LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
+ ;;
+ *)
+- CFLAGS="$CFLAGS -fPIC"
+- LDFLAGS="$LDFLAGS -fPIC -shared"
++ CFLAGS="$CFLAGS ${PICFLAG}"
++ LDFLAGS="$LDFLAGS ${PICFLAG} -shared"
+ ;;
+ esac
+- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fPIC -shared" >&5
+-$as_echo_n "checking for -fPIC -shared... " >&6; }
++ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${PICFLAG} -shared" >&5
++$as_echo_n "checking for ${PICFLAG} -shared... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+-extern int X;
++${UNDEFINEDPREAMBLE}
+ int
+ main ()
+ {
+-return X == 0;
++${UNDEFINEDCODE}
+ ;
+ return 0;
+ }
+diff -urN gcc-5.3.0.orig/libcc1/configure gcc-5.3.0/libcc1/configure
+--- gcc-5.3.0.orig/libcc1/configure 2015-12-19 14:40:20.855979000 +0000
++++ gcc-5.3.0/libcc1/configure 2015-12-20 01:28:45.504980900 +0000
+@@ -14500,6 +14500,9 @@
+
+ pluginlibs=
+
++ PICFLAG="-fPIC"
++ UNDEFINEDPREAMBLE="extern int X;"
++ UNDEFINEDCODE="return X == 0;"
+ case "${host}" in
+ *-*-darwin*)
+ if test x$build = x$host; then
+@@ -14510,6 +14513,11 @@
+ export_sym_check=
+ fi
+ ;;
++ *-*-mingw*|*-*-cygwin*|*-*-msys*)
++ PICFLAG=""
++ UNDEFINEDPREAMBLE=""
++ UNDEFINEDCODE=""
++ ;;
+ *)
+ if test x$build = x$host; then
+ export_sym_check="objdump${exeext} -T"
+@@ -14622,23 +14630,23 @@
+ case "${host}" in
+ *-*-darwin*)
+ CFLAGS=`echo $CFLAGS | sed s/-mdynamic-no-pic//g`
+- CFLAGS="$CFLAGS -fPIC"
++ CFLAGS="$CFLAGS ${PICFLAG}"
+ LDFLAGS="$LDFLAGS -shared -undefined dynamic_lookup"
+ ;;
+ *)
+- CFLAGS="$CFLAGS -fPIC"
+- LDFLAGS="$LDFLAGS -fPIC -shared"
++ CFLAGS="$CFLAGS ${PICFLAG}"
++ LDFLAGS="$LDFLAGS ${PICFLAG} -shared"
+ ;;
+ esac
+- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fPIC -shared" >&5
+-$as_echo_n "checking for -fPIC -shared... " >&6; }
++ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${PICFLAG} -shared" >&5
++$as_echo_n "checking for ${PICFLAG} -shared... " >&6; }
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+-extern int X;
++${UNDEFINEDPREAMBLE}
+ int
+ main ()
+ {
+-return X == 0;
++${UNDEFINEDCODE}
+ ;
+ return 0;
+ }
diff --git a/patches/gcc/linaro-6.3-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch b/patches/gcc/linaro-6.3-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch
new file mode 100644
index 0000000..12ef48e
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/380-gcc-plugin-POSIX-include-sys-select-h.patch
@@ -0,0 +1,11 @@
+diff -urN gcc-5.3.0.orig/libcc1/connection.cc gcc-5.3.0/libcc1/connection.cc
+--- gcc-5.3.0.orig/libcc1/connection.cc 2015-12-19 14:40:20.860479600 +0000
++++ gcc-5.3.0/libcc1/connection.cc 2015-12-20 01:31:04.346611500 +0000
+@@ -21,6 +21,7 @@
+ #include <string>
+ #include <unistd.h>
+ #include <sys/types.h>
++#include <sys/select.h>
+ #include <string.h>
+ #include <errno.h>
+ #include "marshall.hh"
diff --git a/patches/gcc/linaro-6.3-2017.05/810-arm-softfloat-libgcc.patch b/patches/gcc/linaro-6.3-2017.05/810-arm-softfloat-libgcc.patch
new file mode 100644
index 0000000..5efa7fd
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/810-arm-softfloat-libgcc.patch
@@ -0,0 +1,30 @@
+Index: b/gcc/config/arm/linux-elf.h
+===================================================================
+--- a/gcc/config/arm/linux-elf.h
++++ b/gcc/config/arm/linux-elf.h
+@@ -60,7 +60,7 @@
+ %{shared:-lc} \
+ %{!shared:%{profile:-lc_p}%{!profile:-lc}}"
+
+-#define LIBGCC_SPEC "%{mfloat-abi=soft*:-lfloat} -lgcc"
++#define LIBGCC_SPEC "-lgcc"
+
+ #define GLIBC_DYNAMIC_LINKER "/lib/ld-linux.so.2"
+
+Index: b/libgcc/config/arm/t-linux
+===================================================================
+--- a/libgcc/config/arm/t-linux
++++ b/libgcc/config/arm/t-linux
+@@ -1,6 +1,11 @@
+ LIB1ASMSRC = arm/lib1funcs.S
+ LIB1ASMFUNCS = _udivsi3 _divsi3 _umodsi3 _modsi3 _dvmd_lnx _clzsi2 _clzdi2 \
+- _ctzsi2 _arm_addsubdf3 _arm_addsubsf3
++ _ctzsi2 _arm_addsubdf3 _arm_addsubsf3 \
++ _arm_addsubdf3 _arm_addsubsf3 \
++ _arm_negdf2 _arm_muldivdf3 _arm_cmpdf2 _arm_unorddf2 \
++ _arm_fixdfsi _arm_fixunsdfsi _arm_truncdfsf2 \
++ _arm_negsf2 _arm_muldivsf3 _arm_cmpsf2 _arm_unordsf2 \
++ _arm_fixsfsi _arm_fixunssfsi
+
+ # Just for these, we omit the frame pointer since it makes such a big
+ # difference.
diff --git a/patches/gcc/linaro-5.4-2017.01/830-arm_unbreak_armv4t.patch b/patches/gcc/linaro-6.3-2017.05/830-arm_unbreak_armv4t.patch
index b730059..b730059 100644
--- a/patches/gcc/linaro-5.4-2017.01/830-arm_unbreak_armv4t.patch
+++ b/patches/gcc/linaro-6.3-2017.05/830-arm_unbreak_armv4t.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/860-cilk-wchar.patch b/patches/gcc/linaro-6.3-2017.05/860-cilk-wchar.patch
new file mode 100644
index 0000000..1d9916f
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/860-cilk-wchar.patch
@@ -0,0 +1,56 @@
+[PATCH] cilk: fix build without wchar
+
+When building against uClibc with wchar support disabled, WCHAR_MIN and
+WCHAR_MAX are not defined leading to compilation errors.
+
+Fix it by only including the wchar code if available.
+
+Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
+---
+ libcilkrts/include/cilk/reducer_min_max.h | 8 ++++++++
+ 1 file changed, 8 insertions(+)
+
+Index: b/libcilkrts/include/cilk/reducer_min_max.h
+===================================================================
+--- a/libcilkrts/include/cilk/reducer_min_max.h
++++ b/libcilkrts/include/cilk/reducer_min_max.h
+@@ -3154,7 +3154,9 @@
+ CILK_C_REDUCER_MAX_INSTANCE(char, char, CHAR_MIN)
+ CILK_C_REDUCER_MAX_INSTANCE(unsigned char, uchar, 0)
+ CILK_C_REDUCER_MAX_INSTANCE(signed char, schar, SCHAR_MIN)
++#ifdef WCHAR_MIN
+ CILK_C_REDUCER_MAX_INSTANCE(wchar_t, wchar_t, WCHAR_MIN)
++#endif
+ CILK_C_REDUCER_MAX_INSTANCE(short, short, SHRT_MIN)
+ CILK_C_REDUCER_MAX_INSTANCE(unsigned short, ushort, 0)
+ CILK_C_REDUCER_MAX_INSTANCE(int, int, INT_MIN)
+@@ -3306,7 +3308,9 @@
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(char, char, CHAR_MIN)
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(unsigned char, uchar, 0)
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(signed char, schar, SCHAR_MIN)
++#ifdef WCHAR_MIN
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(wchar_t, wchar_t, WCHAR_MIN)
++#endif
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(short, short, SHRT_MIN)
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(unsigned short, ushort, 0)
+ CILK_C_REDUCER_MAX_INDEX_INSTANCE(int, int, INT_MIN)
+@@ -3432,7 +3436,9 @@
+ CILK_C_REDUCER_MIN_INSTANCE(char, char, CHAR_MAX)
+ CILK_C_REDUCER_MIN_INSTANCE(unsigned char, uchar, CHAR_MAX)
+ CILK_C_REDUCER_MIN_INSTANCE(signed char, schar, SCHAR_MAX)
++#ifdef WCHAR_MAX
+ CILK_C_REDUCER_MIN_INSTANCE(wchar_t, wchar_t, WCHAR_MAX)
++#endif
+ CILK_C_REDUCER_MIN_INSTANCE(short, short, SHRT_MAX)
+ CILK_C_REDUCER_MIN_INSTANCE(unsigned short, ushort, USHRT_MAX)
+ CILK_C_REDUCER_MIN_INSTANCE(int, int, INT_MAX)
+@@ -3584,7 +3590,9 @@
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(char, char, CHAR_MAX)
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(unsigned char, uchar, CHAR_MAX)
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(signed char, schar, SCHAR_MAX)
++#ifdef WCHAR_MAX
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(wchar_t, wchar_t, WCHAR_MAX)
++#endif
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(short, short, SHRT_MAX)
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(unsigned short, ushort, USHRT_MAX)
+ CILK_C_REDUCER_MIN_INDEX_INSTANCE(int, int, INT_MAX)
diff --git a/patches/gcc/linaro-6.3-2017.02/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch b/patches/gcc/linaro-6.3-2017.05/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
index 6e0ce6e..6e0ce6e 100644
--- a/patches/gcc/linaro-6.3-2017.02/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
+++ b/patches/gcc/linaro-6.3-2017.05/870-xtensa-don-t-use-unwind-dw2-fde-dip-with-elf-targets.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/871-xtensa-Fix-PR-target-78118.patch b/patches/gcc/linaro-6.3-2017.05/871-xtensa-Fix-PR-target-78118.patch
index c6ae103..c6ae103 100644
--- a/patches/gcc/linaro-6.3-2017.02/871-xtensa-Fix-PR-target-78118.patch
+++ b/patches/gcc/linaro-6.3-2017.05/871-xtensa-Fix-PR-target-78118.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/872-xtensa-Fix-PR-target-78603.patch b/patches/gcc/linaro-6.3-2017.05/872-xtensa-Fix-PR-target-78603.patch
index 669097c..669097c 100644
--- a/patches/gcc/linaro-6.3-2017.02/872-xtensa-Fix-PR-target-78603.patch
+++ b/patches/gcc/linaro-6.3-2017.05/872-xtensa-Fix-PR-target-78603.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/873-gcc-xtensa-fix-fprintf-format-specifiers.patch b/patches/gcc/linaro-6.3-2017.05/873-gcc-xtensa-fix-fprintf-format-specifiers.patch
new file mode 100644
index 0000000..a5b0624
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/873-gcc-xtensa-fix-fprintf-format-specifiers.patch
@@ -0,0 +1,74 @@
+From a3d07c8a2a9564b57ebcae8463c1541a37c97c34 Mon Sep 17 00:00:00 2001
+From: Max Filippov <jcmvbkbc@gmail.com>
+Date: Sun, 28 May 2017 19:56:56 -0700
+Subject: [PATCH] gcc: xtensa: fix fprintf format specifiers
+
+HOST_WIDE_INT may not be long as assumed in print_operand and
+xtensa_emit_call. Use HOST_WIDE_INT_PRINT_DEC/HOST_WIDE_INT_PRINT_HEX
+format strings instead of %ld/0x%lx. This fixes incorrect assembly code
+generation by the compiler running on armhf host.
+
+2017-05-28 Max Filippov <jcmvbkbc@gmail.com>
+gcc/
+ * config/xtensa/xtensa.c (xtensa_emit_call): Use
+ HOST_WIDE_INT_PRINT_HEX instead of 0x%lx format string.
+ (print_operand): Use HOST_WIDE_INT_PRINT_DEC instead of %ld
+ format string.
+
+Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
+---
+ gcc/config/xtensa/xtensa.c | 11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+diff --git a/gcc/config/xtensa/xtensa.c b/gcc/config/xtensa/xtensa.c
+index 70f698a..2bdf5cc 100644
+--- a/gcc/config/xtensa/xtensa.c
++++ b/gcc/config/xtensa/xtensa.c
+@@ -1776,7 +1776,8 @@ xtensa_emit_call (int callop, rtx *operands)
+ rtx tgt = operands[callop];
+
+ if (GET_CODE (tgt) == CONST_INT)
+- sprintf (result, "call%d\t0x%lx", WINDOW_SIZE, INTVAL (tgt));
++ sprintf (result, "call%d\t" HOST_WIDE_INT_PRINT_HEX,
++ WINDOW_SIZE, INTVAL (tgt));
+ else if (register_operand (tgt, VOIDmode))
+ sprintf (result, "callx%d\t%%%d", WINDOW_SIZE, callop);
+ else
+@@ -2347,14 +2348,14 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'L':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", (32 - INTVAL (x)) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, (32 - INTVAL (x)) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%L value");
+ break;
+
+ case 'R':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x) & 0x1f);
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x) & 0x1f);
+ else
+ output_operand_lossage ("invalid %%R value");
+ break;
+@@ -2368,7 +2369,7 @@ print_operand (FILE *file, rtx x, int letter)
+
+ case 'd':
+ if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_operand_lossage ("invalid %%d value");
+ break;
+@@ -2433,7 +2434,7 @@ print_operand (FILE *file, rtx x, int letter)
+ else if (GET_CODE (x) == MEM)
+ output_address (GET_MODE (x), XEXP (x, 0));
+ else if (GET_CODE (x) == CONST_INT)
+- fprintf (file, "%ld", INTVAL (x));
++ fprintf (file, HOST_WIDE_INT_PRINT_DEC, INTVAL (x));
+ else
+ output_addr_const (file, x);
+ }
+--
+2.1.4
+
diff --git a/patches/gcc/linaro-5.4-2017.01/890-fix-m68k-compile.patch b/patches/gcc/linaro-6.3-2017.05/890-fix-m68k-compile.patch
index 6e63de0..6e63de0 100644
--- a/patches/gcc/linaro-5.4-2017.01/890-fix-m68k-compile.patch
+++ b/patches/gcc/linaro-6.3-2017.05/890-fix-m68k-compile.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/891-fix-m68k-uclinux.patch b/patches/gcc/linaro-6.3-2017.05/891-fix-m68k-uclinux.patch
new file mode 100644
index 0000000..4e186bd
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/891-fix-m68k-uclinux.patch
@@ -0,0 +1,18 @@
+avoids internal compiler error while compiling linux-atomic.c
+See here:
+https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53833
+
+Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
+
+diff -Nur gcc-5.3.0.orig/libgcc/config.host gcc-5.3.0/libgcc/config.host
+--- gcc-5.3.0.orig/libgcc/config.host 2015-10-01 14:01:18.000000000 +0200
++++ gcc-5.3.0/libgcc/config.host 2016-04-26 21:30:25.353691745 +0200
+@@ -794,7 +794,7 @@
+ m68k*-*-openbsd*)
+ ;;
+ m68k-*-uclinux*) # Motorola m68k/ColdFire running uClinux with uClibc
+- tmake_file="$tmake_file m68k/t-floatlib m68k/t-linux"
++ tmake_file="$tmake_file m68k/t-floatlib"
+ md_unwind_header=m68k/linux-unwind.h
+ ;;
+ m68k-*-linux*) # Motorola m68k's running GNU/Linux
diff --git a/patches/gcc/linaro-6.3-2017.02/892-libgcc-mkmap-symver-support-skip_underscore.patch b/patches/gcc/linaro-6.3-2017.05/892-libgcc-mkmap-symver-support-skip_underscore.patch
index 73ee6c5..73ee6c5 100644
--- a/patches/gcc/linaro-6.3-2017.02/892-libgcc-mkmap-symver-support-skip_underscore.patch
+++ b/patches/gcc/linaro-6.3-2017.05/892-libgcc-mkmap-symver-support-skip_underscore.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch b/patches/gcc/linaro-6.3-2017.05/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch
index 454295d..454295d 100644
--- a/patches/gcc/linaro-6.3-2017.02/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch
+++ b/patches/gcc/linaro-6.3-2017.05/893-libgcc-config-bfin-use-the-generic-linker-version-in.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch b/patches/gcc/linaro-6.3-2017.05/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch
index ce49de7..ce49de7 100644
--- a/patches/gcc/linaro-6.3-2017.02/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch
+++ b/patches/gcc/linaro-6.3-2017.05/894-libgcc-fix-DWARF-compilation-with-FDPIC-targets.patch
diff --git a/patches/gcc/linaro-6.3-2017.02/895-bfin-define-REENTRANT.patch b/patches/gcc/linaro-6.3-2017.05/895-bfin-define-REENTRANT.patch
index e2828a5..e2828a5 100644
--- a/patches/gcc/linaro-6.3-2017.02/895-bfin-define-REENTRANT.patch
+++ b/patches/gcc/linaro-6.3-2017.05/895-bfin-define-REENTRANT.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/900-libgfortran-missing-include.patch b/patches/gcc/linaro-6.3-2017.05/900-libgfortran-missing-include.patch
new file mode 100644
index 0000000..1f47469
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/900-libgfortran-missing-include.patch
@@ -0,0 +1,10 @@
+--- gcc-6.3.0/libgfortran/io/close.c.org 2017-01-17 09:43:48.395850000 +0100
++++ gcc-6.3.0/libgfortran/io/close.c 2017-01-17 09:21:05.000000000 +0100
+@@ -25,6 +25,7 @@
+ #include "io.h"
+ #include "unix.h"
+ #include <limits.h>
++#include <stdlib.h>
+
+ typedef enum
+ { CLOSE_DELETE, CLOSE_KEEP, CLOSE_UNSPECIFIED }
diff --git a/patches/gcc/linaro-6.3-2017.05/910-nios2-bad-multilib-default.patch b/patches/gcc/linaro-6.3-2017.05/910-nios2-bad-multilib-default.patch
new file mode 100644
index 0000000..61989e5
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/910-nios2-bad-multilib-default.patch
@@ -0,0 +1,28 @@
+diff -ur gcc-6.2.0.orig/gcc/config/nios2/nios2.h gcc-6.2.0/gcc/config/nios2/nios2.h
+--- gcc-6.2.0.orig/gcc/config/nios2/nios2.h 2016-11-29 10:27:50.364479625 -0800
++++ gcc-6.2.0/gcc/config/nios2/nios2.h 2016-11-29 10:29:55.069624746 -0800
+@@ -63,11 +63,11 @@
+ #if TARGET_ENDIAN_DEFAULT == 0
+ # define ASM_SPEC "%{!meb:-EL} %{meb:-EB} %{march=*:-march=%*}"
+ # define LINK_SPEC_ENDIAN "%{!meb:-EL} %{meb:-EB}"
+-# define MULTILIB_DEFAULTS { "EL" }
++# define MULTILIB_DEFAULTS { "mel" }
+ #else
+ # define ASM_SPEC "%{!mel:-EB} %{mel:-EL} %{march=*:-march=%*}"
+ # define LINK_SPEC_ENDIAN "%{!mel:-EB} %{mel:-EL}"
+-# define MULTILIB_DEFAULTS { "EB" }
++# define MULTILIB_DEFAULTS { "meb" }
+ #endif
+
+ #define LINK_SPEC LINK_SPEC_ENDIAN \
+diff -ur gcc-6.2.0.orig/gcc/config/nios2/t-nios2 gcc-6.2.0/gcc/config/nios2/t-nios2
+--- gcc-6.2.0.orig/gcc/config/nios2/t-nios2 2016-11-29 10:27:50.364479625 -0800
++++ gcc-6.2.0/gcc/config/nios2/t-nios2 2016-11-29 10:29:03.517151014 -0800
+@@ -22,6 +22,5 @@
+ # MULTILIB_DIRNAMES = nomul mulx fpu-60-1 fpu-60-2
+ # MULTILIB_EXCEPTIONS =
+
+-# MULTILIB_OPTIONS += EL/EB
++# MULTILIB_OPTIONS += mel/meb
+ # MULTILIB_DIRNAMES += le be
+-# MULTILIB_MATCHES += EL=mel EB=meb
diff --git a/patches/gcc/linaro-6.3-2017.05/930-libgcc-disable-split-stack-nothreads.patch b/patches/gcc/linaro-6.3-2017.05/930-libgcc-disable-split-stack-nothreads.patch
new file mode 100644
index 0000000..07f9a73
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/930-libgcc-disable-split-stack-nothreads.patch
@@ -0,0 +1,14 @@
+disable split-stack for non-thread builds
+
+Signed-off-by: Waldemar Brodkorb <wbx@openadk.org>
+
+diff -Nur gcc-5.3.0.orig/libgcc/config/t-stack gcc-5.3.0/libgcc/config/t-stack
+--- gcc-5.3.0.orig/libgcc/config/t-stack 2010-10-01 21:31:49.000000000 +0200
++++ gcc-5.3.0/libgcc/config/t-stack 2016-03-07 03:25:32.000000000 +0100
+@@ -1,4 +1,6 @@
+ # Makefile fragment to provide generic support for -fsplit-stack.
+ # This should be used in config.host for any host which supports
+ # -fsplit-stack.
++ifeq ($(enable_threads),yes)
+ LIB2ADD_ST += $(srcdir)/generic-morestack.c $(srcdir)/generic-morestack-thread.c
++endif
diff --git a/patches/gcc/linaro-5.4-2017.01/940-uclinux-enable-threads.patch b/patches/gcc/linaro-6.3-2017.05/940-uclinux-enable-threads.patch
index 490a55b..490a55b 100644
--- a/patches/gcc/linaro-5.4-2017.01/940-uclinux-enable-threads.patch
+++ b/patches/gcc/linaro-6.3-2017.05/940-uclinux-enable-threads.patch
diff --git a/patches/gcc/linaro-6.3-2017.05/951-bionic-ndk.patch b/patches/gcc/linaro-6.3-2017.05/951-bionic-ndk.patch
new file mode 100644
index 0000000..59c50a8
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/951-bionic-ndk.patch
@@ -0,0 +1,58 @@
+commit d38d37bdfe24b7ce1bdcb55642fb6b904718e68f
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 19:02:18 2017 -0700
+
+ Fix ctype for newer NDK headers
+
+diff --git a/libstdc++-v3/config/os/bionic/ctype_base.h b/libstdc++-v3/config/os/bionic/ctype_base.h
+index 33978f3..c36e63c 100644
+--- a/libstdc++-v3/config/os/bionic/ctype_base.h
++++ b/libstdc++-v3/config/os/bionic/ctype_base.h
+@@ -28,6 +28,18 @@
+
+ // Information as gleaned from /usr/include/ctype.h
+
++// _CTYPE prefix was added in NDK r14 unified headers
++#ifndef _CTYPE_U
++#define _CTYPE_U _U
++#define _CTYPE_L _L
++#define _CTYPE_D _N
++#define _CTYPE_S _S
++#define _CTYPE_P _P
++#define _CTYPE_C _C
++#define _CTYPE_X _X
++#define _CTYPE_B _B
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -41,17 +53,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ // NB: Offsets into ctype<char>::_M_table force a particular size
+ // on the mask type. Because of this, we don't use an enum.
+ typedef char mask;
+- static const mask upper = _U;
+- static const mask lower = _L;
+- static const mask alpha = _U | _L;
+- static const mask digit = _N;
+- static const mask xdigit = _X | _N;
+- static const mask space = _S;
+- static const mask print = _P | _U | _L | _N | _B;
+- static const mask graph = _P | _U | _L | _N;
+- static const mask cntrl = _C;
+- static const mask punct = _P;
+- static const mask alnum = _U | _L | _N;
++ static const mask upper = _CTYPE_U;
++ static const mask lower = _CTYPE_L;
++ static const mask alpha = _CTYPE_U | _CTYPE_L;
++ static const mask digit = _CTYPE_D;
++ static const mask xdigit = _CTYPE_X | _CTYPE_D;
++ static const mask space = _CTYPE_S;
++ static const mask print = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D | _CTYPE_B;
++ static const mask graph = _CTYPE_P | _CTYPE_U | _CTYPE_L | _CTYPE_D;
++ static const mask cntrl = _CTYPE_C;
++ static const mask punct = _CTYPE_P;
++ static const mask alnum = _CTYPE_U | _CTYPE_L | _CTYPE_D;
+ #if __cplusplus >= 201103L
+ static const mask blank = space;
+ #endif
diff --git a/patches/gcc/linaro-6.3-2017.05/952-bionic-errno.patch b/patches/gcc/linaro-6.3-2017.05/952-bionic-errno.patch
new file mode 100644
index 0000000..91f6ca3
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/952-bionic-errno.patch
@@ -0,0 +1,19 @@
+commit 6cd4ad106ef87a3c58b0c3478e78409b47000de0
+Author: Howard Chu <hyc@symas.com>
+Date: Tue Apr 25 20:17:03 2017 -0700
+
+ Fix, errno is volatile int
+
+diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc
+index 6ff12d0..5bbd664 100644
+--- a/libstdc++-v3/src/filesystem/dir.cc
++++ b/libstdc++-v3/src/filesystem/dir.cc
+@@ -147,7 +147,7 @@ fs::_Dir::advance(error_code* ec, directory_options options)
+
+ int err = std::exchange(errno, 0);
+ const auto entp = readdir(dirp);
+- std::swap(errno, err);
++ std::swap((int&)errno, err);
+
+ if (entp)
+ {
diff --git a/patches/gcc/linaro-6.3-2017.05/970-crystax.patch b/patches/gcc/linaro-6.3-2017.05/970-crystax.patch
new file mode 100644
index 0000000..e3109cc
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/970-crystax.patch
@@ -0,0 +1,551 @@
+commit 080803512c8f6f87c2f1f711170d54033144d628
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Wed Jul 29 11:28:29 2015 +0300
+
+ [android] Apply Android-related modifications
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+[Edited: keep libstdc++, drop libcrystax-related modifications]
+diff --git a/gcc/config.gcc b/gcc/config.gcc
+index f66e48cd1..1c253496b 100644
+--- a/gcc/config.gcc
++++ b/gcc/config.gcc
+@@ -942,13 +942,17 @@ aarch64*-*-elf | aarch64*-*-rtems*)
+ TM_MULTILIB_CONFIG=`echo $TM_MULTILIB_CONFIG | sed 's/^,//'`
+ ;;
+ aarch64*-*-linux*)
+- tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h glibc-stdint.h"
++ tm_file="${tm_file} dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h"
+ tm_file="${tm_file} aarch64/aarch64-elf.h aarch64/aarch64-linux.h"
++ extra_options="${extra_options} linux-android.opt"
+ tmake_file="${tmake_file} aarch64/t-aarch64 aarch64/t-aarch64-linux"
+ case $target in
+ aarch64_be-*)
+ tm_defines="${tm_defines} TARGET_BIG_ENDIAN_DEFAULT=1"
+ ;;
++ aarch64*-*-linux-android*)
++ tm_file="${tm_file} aarch64/aarch64-linux-android.h"
++ ;;
+ esac
+ aarch64_multilibs="${with_multilib_list}"
+ if test "$aarch64_multilibs" = "default"; then
+@@ -2055,6 +2059,17 @@ mips*-*-linux*) # Linux MIPS, either endian.
+ tm_file="dbxelf.h elfos.h gnu-user.h linux.h linux-android.h glibc-stdint.h ${tm_file} mips/gnu-user.h mips/linux.h mips/linux-common.h"
+ extra_options="${extra_options} linux-android.opt"
+ case ${target} in
++ mips64*android*)
++ default_mips_arch=mips64r6
++ default_mips_abi=64
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="${tmake_file} mips/t-linux-android64"
++ ;;
++ mips*android*)
++ default_mips_arch=mips32
++ tm_file="${tm_file} mips/android.h"
++ tmake_file="$tmake_file mips/t-linux-android"
++ ;;
+ mipsisa32r6*)
+ default_mips_arch=mips32r6
+ ;;
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+new file mode 100644
+index 000000000..db1288fd0
+--- /dev/null
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -0,0 +1,59 @@
++/* Machine description for AArch64 architecture.
++ Copyright (C) 2014 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/>. */
++
++#ifndef GCC_AARCH64_LINUX_ANDROID_H
++#define GCC_AARCH64_LINUX_ANDROID_H
++
++
++#undef TARGET_OS_CPP_BUILTINS
++#define TARGET_OS_CPP_BUILTINS() \
++ do \
++ { \
++ GNU_USER_TARGET_OS_CPP_BUILTINS(); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
++ } \
++ while (0)
++
++#undef LINK_SPEC
++#define LINK_SPEC \
++ LINUX_OR_ANDROID_LD (LINUX_TARGET_LINK_SPEC, \
++ LINUX_TARGET_LINK_SPEC " " ANDROID_LINK_SPEC)
++
++#undef CC1_SPEC
++#define CC1_SPEC \
++ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
++
++#undef LIB_SPEC
++#define LIB_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
++ GNU_USER_TARGET_NO_PTHREADS_LIB_SPEC " " ANDROID_LIB_SPEC)
++
++#undef STARTFILE_SPEC
++#define STARTFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_STARTFILE_SPEC, ANDROID_STARTFILE_SPEC)
++
++#undef ENDFILE_SPEC
++#define ENDFILE_SPEC \
++ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
++
++#endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/aarch64/aarch64-linux.h b/gcc/config/aarch64/aarch64-linux.h
+index 5fcaa59a3..6864195ee 100644
+--- a/gcc/config/aarch64/aarch64-linux.h
++++ b/gcc/config/aarch64/aarch64-linux.h
+@@ -21,7 +21,14 @@
+ #ifndef GCC_AARCH64_LINUX_H
+ #define GCC_AARCH64_LINUX_H
+
+-#define GLIBC_DYNAMIC_LINKER "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifndef RUNTIME_ROOT_PREFIX
++#define RUNTIME_ROOT_PREFIX ""
++#endif
++#define GLIBC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/lib/ld-linux-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
++#ifdef BIONIC_DYNAMIC_LINKER
++#undef BIONIC_DYNAMIC_LINKER
++#endif
++#define BIONIC_DYNAMIC_LINKER RUNTIME_ROOT_PREFIX "/system/bin/linker64"
+
+ #undef MUSL_DYNAMIC_LINKER
+ #define MUSL_DYNAMIC_LINKER "/lib/ld-musl-aarch64%{mbig-endian:_be}%{mabi=ilp32:_ilp32}.so.1"
+diff --git a/gcc/config/arm/arm.h b/gcc/config/arm/arm.h
+index ad123dde9..97b059de6 100644
+--- a/gcc/config/arm/arm.h
++++ b/gcc/config/arm/arm.h
+@@ -1888,10 +1888,11 @@ enum arm_auto_incmodes
+
+ #define CASE_VECTOR_PC_RELATIVE (TARGET_THUMB2 \
+ || (TARGET_THUMB1 \
++ && !inline_thumb1_jump_table \
+ && (optimize_size || flag_pic)))
+
+ #define CASE_VECTOR_SHORTEN_MODE(min, max, body) \
+- (TARGET_THUMB1 \
++ (TARGET_THUMB1 && !inline_thumb1_jump_table \
+ ? (min >= 0 && max < 512 \
+ ? (ADDR_DIFF_VEC_FLAGS (body).offset_unsigned = 1, QImode) \
+ : min >= -256 && max < 256 \
+diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
+index 47171b996..eb22d1181 100644
+--- a/gcc/config/arm/arm.md
++++ b/gcc/config/arm/arm.md
+@@ -8179,7 +8179,7 @@
+ (match_operand:SI 2 "const_int_operand" "") ; total range
+ (match_operand:SI 3 "" "") ; table label
+ (match_operand:SI 4 "" "")] ; Out of range label
+- "TARGET_32BIT || optimize_size || flag_pic"
++ "TARGET_32BIT || ((optimize_size || flag_pic) && !inline_thumb1_jump_table)"
+ "
+ {
+ enum insn_code code;
+diff --git a/gcc/config/arm/arm.opt b/gcc/config/arm/arm.opt
+index 0ebe01743..772453889 100644
+--- a/gcc/config/arm/arm.opt
++++ b/gcc/config/arm/arm.opt
+@@ -193,6 +193,10 @@ mthumb-interwork
+ Target Report Mask(INTERWORK)
+ Support calls between Thumb and ARM instruction sets.
+
++minline-thumb1-jumptable
++Target Report Var(inline_thumb1_jump_table)
++Inline Thumb1 Jump table code
++
+ mtls-dialect=
+ Target RejectNegative Joined Enum(tls_type) Var(target_tls_dialect) Init(TLS_GNU)
+ Specify thread local storage scheme.
+diff --git a/gcc/config/arm/elf.h b/gcc/config/arm/elf.h
+index 77f30554d..32158ed65 100644
+--- a/gcc/config/arm/elf.h
++++ b/gcc/config/arm/elf.h
+@@ -56,8 +56,7 @@
+ #undef SUBSUBTARGET_EXTRA_SPECS
+ #define SUBSUBTARGET_EXTRA_SPECS
+
+-#ifndef ASM_SPEC
+-#define ASM_SPEC "\
++#define DEFAULT_ASM_SPEC "\
+ %{mbig-endian:-EB} \
+ %{mlittle-endian:-EL} \
+ %(asm_cpu_spec) \
+@@ -66,6 +65,9 @@
+ %{mthumb-interwork:-mthumb-interwork} \
+ %{mfloat-abi=*} %{mfpu=*} \
+ %(subtarget_extra_asm_spec)"
++
++#ifndef ASM_SPEC
++#define ASM_SPEC DEFAULT_ASM_SPEC
+ #endif
+
+ /* The ARM uses @ are a comment character so we need to redefine
+@@ -104,7 +106,8 @@
+ the code more efficient, but for Thumb-1 it's better to put them out of
+ band unless we are generating compressed tables. */
+ #define JUMP_TABLES_IN_TEXT_SECTION \
+- (TARGET_32BIT || (TARGET_THUMB && (optimize_size || flag_pic)))
++ (TARGET_32BIT || (TARGET_THUMB && !inline_thumb1_jump_table \
++ && (optimize_size || flag_pic)))
+
+ #ifndef LINK_SPEC
+ #define LINK_SPEC "%{mbig-endian:-EB} %{mlittle-endian:-EL} -X"
+diff --git a/gcc/config/arm/linux-eabi.h b/gcc/config/arm/linux-eabi.h
+index ace84816e..8c8fa6553 100644
+--- a/gcc/config/arm/linux-eabi.h
++++ b/gcc/config/arm/linux-eabi.h
+@@ -108,11 +108,16 @@
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC, \
+ GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " " \
+- ANDROID_CC1_SPEC)
++ ANDROID_CC1_SPEC("-fpic"))
+
+ #define CC1PLUS_SPEC \
+ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
++#undef ASM_SPEC
++#define ASM_SPEC \
++ LINUX_OR_ANDROID_CC (DEFAULT_ASM_SPEC, \
++ DEFAULT_ASM_SPEC " " ANDROID_ASM_SPEC)
++
+ #undef LIB_SPEC
+ #define LIB_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_LIB_SPEC, \
+diff --git a/gcc/config/i386/gnu-user.h b/gcc/config/i386/gnu-user.h
+index fee33a3ef..22fb2ced9 100644
+--- a/gcc/config/i386/gnu-user.h
++++ b/gcc/config/i386/gnu-user.h
+@@ -65,9 +65,14 @@ along with GCC; see the file COPYING3. If not see
+ When the -shared link option is used a final link is not being
+ done. */
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ " -mssse3 -fno-short-enums " \
++
+ #undef ASM_SPEC
+ #define ASM_SPEC \
+- "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}}"
++ "--32 %{!mno-sse2avx:%{mavx:-msse2avx}} %{msse2avx:%{!mavx:-msse2avx}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ #undef SUBTARGET_EXTRA_SPECS
+ #define SUBTARGET_EXTRA_SPECS \
+diff --git a/gcc/config/i386/gnu-user64.h b/gcc/config/i386/gnu-user64.h
+index 7a02a7eb4..cac4179bc 100644
+--- a/gcc/config/i386/gnu-user64.h
++++ b/gcc/config/i386/gnu-user64.h
+@@ -46,6 +46,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define SPEC_X32 "mx32"
+ #endif
+
++#undef ANDROID_TARGET_CC1_SPEC
++#define ANDROID_TARGET_CC1_SPEC \
++ "%{m32:-mssse3 -fno-short-enums}" \
++ "%{!m32:-msse4.2 -mpopcnt}"
++
+ #undef ASM_SPEC
+ #define ASM_SPEC "%{" SPEC_32 ":--32} \
+ %{" SPEC_64 ":--64} \
+diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
+index 4b9910fa9..3b11ed086 100644
+--- a/gcc/config/i386/linux-common.h
++++ b/gcc/config/i386/linux-common.h
+@@ -30,7 +30,13 @@ along with GCC; see the file COPYING3. If not see
+ #undef CC1_SPEC
+ #define CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC \
++ ANDROID_TARGET_CC1_SPEC \
++ " " \
++ ANDROID_CC1_SPEC("-fPIC"))
++
++#define CC1PLUS_SPEC \
++ LINUX_OR_ANDROID_CC ("", ANDROID_CC1PLUS_SPEC)
+
+ #undef LINK_SPEC
+ #define LINK_SPEC \
+diff --git a/gcc/config/linux-android.h b/gcc/config/linux-android.h
+index 301a41ccd..9623c88d0 100644
+--- a/gcc/config/linux-android.h
++++ b/gcc/config/linux-android.h
+@@ -38,15 +39,18 @@
+ "%{" NOANDROID "|tno-android-ld:" LINUX_SPEC ";:" ANDROID_SPEC "}"
+
+ #define ANDROID_LINK_SPEC \
+- "%{shared: -Bsymbolic}"
++ "%{shared: -Bsymbolic} -z noexecstack -z relro -z now"
+
+-#define ANDROID_CC1_SPEC \
++#define ANDROID_CC1_SPEC(ANDROID_PIC_DEFAULT) \
+ "%{!mglibc:%{!muclibc:%{!mbionic: -mbionic}}} " \
+- "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}"
++ "%{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: " ANDROID_PIC_DEFAULT "}}}}"
+
+ #define ANDROID_CC1PLUS_SPEC \
+- "%{!fexceptions:%{!fno-exceptions: -fno-exceptions}} " \
+- "%{!frtti:%{!fno-rtti: -fno-rtti}}"
++ "%{!fexceptions:%{!fno-exceptions: -fexceptions}} " \
++ "%{!frtti:%{!fno-rtti: -frtti}}"
++
++#define ANDROID_ASM_SPEC \
++ "--noexecstack"
+
+ #define ANDROID_LIB_SPEC \
+ "%{!static: -ldl}"
+diff --git a/gcc/config/mips/android.h b/gcc/config/mips/android.h
+new file mode 100644
+index 000000000..32c539c8d
+--- /dev/null
++++ b/gcc/config/mips/android.h
+@@ -0,0 +1,49 @@
++/* Target macros for mips*-*android* targets.
++ Copyright (C) 2014 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 DRIVER_SELF_SPECS
++#define DRIVER_SELF_SPECS \
++ /* Make sure a -mips option is present. This helps us to pick \
++ the right multilib, and also makes the later specs easier \
++ to write. */ \
++ MIPS_ISA_LEVEL_SPEC, \
++ \
++ /* Infer the default float setting from -march. */ \
++ MIPS_ARCH_FLOAT_SPEC, \
++ \
++ /* Infer the -msynci setting from -march if not explicitly set. */ \
++ MIPS_ISA_SYNCI_SPEC, \
++ \
++ /* If no ABI option is specified, infer one from the ISA level \
++ or -mgp setting. */ \
++ "%{!mabi=*: %{" MIPS_32BIT_OPTION_SPEC ": -mabi=32;: -mabi=64}}", \
++ \
++ /* If no FP ABI option is specified, infer one from the \
++ ABI/ISA level unless there is a conflicting option. */ \
++ "%{!msoft-float: %{!msingle-float: %{!mfp*: %{!mmsa: %{mabi=32: %{" \
++ MIPS_FPXX_OPTION_SPEC ": -mfpxx}}}}}}", \
++ \
++ /* If no odd-spreg option is specified, infer one from the ISA. */ \
++ "%{!modd-spreg: %{mabi=32: %{mips32r6: -mno-odd-spreg}}}", \
++ \
++ /* Base SPECs. */ \
++ BASE_DRIVER_SELF_SPECS, \
++ \
++ /* Use the standard linux specs for everything else. */ \
++ LINUX_DRIVER_SELF_SPECS
+diff --git a/gcc/config/mips/gnu-user.h b/gcc/config/mips/gnu-user.h
+index 15b549c08..4a2816014 100644
+--- a/gcc/config/mips/gnu-user.h
++++ b/gcc/config/mips/gnu-user.h
+@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
+ /* The GNU C++ standard library requires this. */ \
+ if (c_dialect_cxx ()) \
+ builtin_define ("_GNU_SOURCE"); \
++ ANDROID_TARGET_OS_CPP_BUILTINS(); \
+ } while (0)
+
+ #undef SUBTARGET_CPP_SPEC
+@@ -71,7 +72,8 @@ along with GCC; see the file COPYING3. If not see
+
+ #undef SUBTARGET_ASM_SPEC
+ #define SUBTARGET_ASM_SPEC \
+- "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}}"
++ "%{!mno-abicalls:%{mplt:-call_nonpic;:-KPIC}} " \
++ LINUX_OR_ANDROID_CC ("", ANDROID_ASM_SPEC)
+
+ /* The MIPS assembler has different syntax for .set. We set it to
+ .dummy to trap any errors. */
+@@ -120,7 +122,7 @@ extern const char *host_detect_local_cpu (int argc, const char **argv);
+ #endif
+
+ #define LINUX_DRIVER_SELF_SPECS \
+- NO_SHARED_SPECS \
++ LINUX_OR_ANDROID_CC(NO_SHARED_SPECS, "") \
+ MARCH_MTUNE_NATIVE_SPECS, \
+ /* -mplt has no effect without -mno-shared. Simplify later \
+ specs handling by removing a redundant option. */ \
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8429a7ca2..8bfacf994 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see
+ #undef SUBTARGET_CC1_SPEC
+ #define SUBTARGET_CC1_SPEC \
+ LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC, \
+- GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC)
++ GNU_USER_TARGET_CC1_SPEC " " ANDROID_CC1_SPEC("-fpic"))
+
+ #undef CC1PLUS_SPEC
+ #define CC1PLUS_SPEC \
+diff --git a/gcc/config/mips/t-linux-android b/gcc/config/mips/t-linux-android
+new file mode 100644
+index 000000000..39f512c81
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android
+@@ -0,0 +1,3 @@
++MULTILIB_OPTIONS = mips32r2/mips32r6
++MULTILIB_DIRNAMES = mips-r2 mips-r6
++MULTILIB_OSDIRNAMES = ../libr2 ../libr6
+diff --git a/gcc/config/mips/t-linux-android64 b/gcc/config/mips/t-linux-android64
+new file mode 100644
+index 000000000..55cab7d62
+--- /dev/null
++++ b/gcc/config/mips/t-linux-android64
+@@ -0,0 +1,4 @@
++MULTILIB_OPTIONS = mabi=32 mips32/mips32r2/mips32r6/mips64r2/mips64r6
++MULTILIB_DIRNAMES = 32 mips-r1 mips-r2 mips-r6 mips64-r2 mips64-r6
++MULTILIB_OSDIRNAMES = ../lib ../lib ../libr2 ../libr6 ../lib64r2 ../lib64
++MULTILIB_REQUIRED = mabi=32/mips32 mabi=32/mips32r2 mabi=32/mips32r6 mips64r2 mips64r6
+diff --git a/libgcc/gthr-posix.h b/libgcc/gthr-posix.h
+index 555c0fe24..47c8655f9 100644
+--- a/libgcc/gthr-posix.h
++++ b/libgcc/gthr-posix.h
+@@ -32,6 +32,19 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define __GTHREADS 1
+ #define __GTHREADS_CXX0X 1
+
++/* The following should normally be in a different header file,
++ * but I couldn't find the right location. The point of the macro
++ * definition below is to prevent libsupc++ and libstdc++ to reference
++ * weak symbols in their static C++ constructors. Such code crashes
++ * when a shared object linked statically to these libraries is
++ * loaded on Android 2.1 (Eclair) and older platform releases, due
++ * to a dynamic linker bug.
++ */
++#ifdef __ANDROID__
++#undef GTHREAD_USE_WEAK
++#define GTHREAD_USE_WEAK 0
++#endif
++
+ #include <pthread.h>
+
+ #if ((defined(_LIBOBJC) || defined(_LIBOBJC_WEAK)) \
+diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure
+index 41797a971..f746e8353 100755
+--- a/libstdc++-v3/configure
++++ b/libstdc++-v3/configure
+@@ -78319,6 +78341,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+@@ -78377,6 +78405,12 @@ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+ /* end confdefs.h. */
+ #include <sys/syscall.h>
+ int lk;
++#if !defined(SYS_gettid)
++#define SYS_gettid __NR_gettid
++#endif
++#if !defined(SYS_futex)
++#define SYS_futex __NR_futex
++#endif
+ int
+ main ()
+ {
+diff --git a/libstdc++-v3/include/bits/locale_facets.h b/libstdc++-v3/include/bits/locale_facets.h
+index e3e206b7d..e85dc2c76 100644
+--- a/libstdc++-v3/include/bits/locale_facets.h
++++ b/libstdc++-v3/include/bits/locale_facets.h
+@@ -47,6 +47,20 @@
+ #include <ext/numeric_traits.h>
+ #include <bits/streambuf_iterator.h>
+
++#if !__clang__ && __GNUC__ == 4 && __GNUC_MINOR__ == 9 && __i386__
++// CrystaX: for some reason, x86 gcc-4.9 makes ctype<char>::do_widen() and
++// ctype<char>::_M_widen_init() methods working wrong if optimization enabled.
++// For ctype<char>::do_widen(), values of passed arguments (__lo, __hi and __to)
++// are completely messed up and don't correspond to passed values. In case if
++// we disable optimization for those methods, things become correct so we apply
++// this workaround here for a time.
++// TODO: figure out what exactly wrong here - is it bug in GCC optimization
++// algorithm or smth else?
++#define __CRYSTAX_X86_DONT_OPTIMIZE __attribute__((optimize(0)))
++#else
++#define __CRYSTAX_X86_DONT_OPTIMIZE
++#endif
++
+ namespace std _GLIBCXX_VISIBILITY(default)
+ {
+ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+@@ -1102,7 +1116,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+ * @return @a __hi.
+ */
+ virtual const char*
+- do_widen(const char* __lo, const char* __hi, char_type* __to) const
++ do_widen(const char* __lo, const char* __hi, char_type* __to) const __CRYSTAX_X86_DONT_OPTIMIZE
+ {
+ __builtin_memcpy(__to, __lo, __hi - __lo);
+ return __hi;
+@@ -1163,7 +1177,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ private:
+ void _M_narrow_init() const;
+- void _M_widen_init() const;
++ void _M_widen_init() const __CRYSTAX_X86_DONT_OPTIMIZE;
+ };
+
+ #ifdef _GLIBCXX_USE_WCHAR_T
+diff --git a/libstdc++-v3/libsupc++/guard.cc b/libstdc++-v3/libsupc++/guard.cc
+index 9b617998f..c149169bb 100644
+--- a/libstdc++-v3/libsupc++/guard.cc
++++ b/libstdc++-v3/libsupc++/guard.cc
+@@ -33,7 +33,12 @@
+ #if defined(__GTHREADS) && defined(__GTHREAD_HAS_COND) \
+ && (ATOMIC_INT_LOCK_FREE > 1) && defined(_GLIBCXX_HAVE_LINUX_FUTEX)
+ # include <climits>
++#if defined(__ANDROID__)
++# include <sys/syscall.h>
++# define SYS_futex __NR_futex
++#else
+ # include <syscall.h>
++#endif
+ # include <unistd.h>
+ # define _GLIBCXX_USE_FUTEX
+ # define _GLIBCXX_FUTEX_WAIT 0
diff --git a/patches/gcc/linaro-6.3-2017.05/971-crystax.patch b/patches/gcc/linaro-6.3-2017.05/971-crystax.patch
new file mode 100644
index 0000000..748a381
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/971-crystax.patch
@@ -0,0 +1,25 @@
+commit 9f057b62caafe08c968103d39b5df82486a175c2
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 13 16:11:54 2015 +0300
+
+ [android] Add additional multilib option: mfloat-abi=hard
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/t-linux-androideabi b/gcc/config/arm/t-linux-androideabi
+index 8f1307c55..cbbec5bd2 100644
+--- a/gcc/config/arm/t-linux-androideabi
++++ b/gcc/config/arm/t-linux-androideabi
+@@ -1,8 +1,9 @@
+-MULTILIB_OPTIONS = march=armv7-a mthumb
+-MULTILIB_DIRNAMES = armv7-a thumb
+-MULTILIB_EXCEPTIONS =
++MULTILIB_OPTIONS = march=armv7-a mthumb mfloat-abi=hard
++MULTILIB_DIRNAMES = armv7-a thumb hard
++MULTILIB_EXCEPTIONS = mfloat-abi=hard* mthumb/mfloat-abi=hard*
+ MULTILIB_MATCHES =
+ MULTILIB_OSDIRNAMES =
++MULTILIB_EXTRA_OPTS = Wl,--no-warn-mismatch
+
+ # The "special" multilib can be used to build native applications for Android,
+ # as opposed to native shared libraries that are then called via JNI.
diff --git a/patches/gcc/linaro-6.3-2017.05/972-crystax.patch b/patches/gcc/linaro-6.3-2017.05/972-crystax.patch
new file mode 100644
index 0000000..b9077be
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/972-crystax.patch
@@ -0,0 +1,302 @@
+commit 44a81ebb7698dac41ffa7acd5e0cc1578e5ab1fd
+Author: H.J. Lu <hongjiu.lu@intel.com>
+Date: Mon Apr 14 15:59:47 2014 -0700
+
+ [android] Always enable --eh-frame-hdr for static executable
+
+ See 5e6cdf76af295c9a39b695ca228cff675e8ff4ae and
+ 23e3137ee2897464b051599b85a09f130d3ad05d
+
+ Change-Id: Ibda473188e5a10f2a0592f2494ad00ad1f91e04b
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config.in b/gcc/config.in
+index 115cb6163..933916833 100644
+--- a/gcc/config.in
++++ b/gcc/config.in
+@@ -2119,6 +2119,12 @@
+ #endif
+
+
++/* Define if your system supports PT_GNU_EH_FRAME for static executable. */
++#ifndef USED_FOR_TARGET
++#undef USE_EH_FRAME_HDR_FOR_STATIC
++#endif
++
++
+ /* Define to 1 if the 'long long' type is wider than 'long' but still
+ efficiently supported by the host hardware. */
+ #ifndef USED_FOR_TARGET
+diff --git a/gcc/config/alpha/elf.h b/gcc/config/alpha/elf.h
+index 093c38bba..54b3e0c91 100644
+--- a/gcc/config/alpha/elf.h
++++ b/gcc/config/alpha/elf.h
+@@ -168,5 +168,9 @@ extern int alpha_this_gpdisp_sequence_number;
+ I imagine that other systems will catch up. In the meantime, it
+ doesn't harm to make sure that the data exists to be used later. */
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+diff --git a/gcc/config/freebsd.h b/gcc/config/freebsd.h
+index 5ded869d2..5f51ac81d 100644
+--- a/gcc/config/freebsd.h
++++ b/gcc/config/freebsd.h
+@@ -45,8 +45,12 @@ along with GCC; see the file COPYING3. If not see
+ #define LIB_SPEC FBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #ifdef TARGET_LIBC_PROVIDES_SSP
+ #define LINK_SSP_SPEC "%{fstack-protector|fstack-protector-all" \
+diff --git a/gcc/config/gnu-user.h b/gcc/config/gnu-user.h
+index b0bf40a95..d1874bc29 100644
+--- a/gcc/config/gnu-user.h
++++ b/gcc/config/gnu-user.h
+@@ -118,8 +118,12 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define LIB_SPEC GNU_USER_TARGET_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LINK_GCC_C_SEQUENCE_SPEC
+ #define LINK_GCC_C_SEQUENCE_SPEC \
+diff --git a/gcc/config/openbsd.h b/gcc/config/openbsd.h
+index 37ecfc43f..a5f1b9955 100644
+--- a/gcc/config/openbsd.h
++++ b/gcc/config/openbsd.h
+@@ -136,8 +136,12 @@ while (0)
+ #define LIB_SPEC OBSD_LIB_SPEC
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
+ #endif
++#endif
+
+ #undef LIB_SPEC
+ #define LIB_SPEC OBSD_LIB_SPEC
+diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h
+index cbf909722..eb2217fad 100644
+--- a/gcc/config/rs6000/sysv4.h
++++ b/gcc/config/rs6000/sysv4.h
+@@ -789,7 +789,11 @@ ENDIAN_SELECT(" -mbig", " -mlittle", DEFAULT_ASM_ENDIAN)
+ -dynamic-linker " GNU_USER_DYNAMIC_LINKER "}}"
+
+ #if defined(HAVE_LD_EH_FRAME_HDR)
+-# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# ifdef USE_EH_FRAME_HDR_FOR_STATIC
++# define LINK_EH_SPEC "--eh-frame-hdr "
++# else
++# define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++# endif
+ #endif
+
+ #define CPP_OS_LINUX_SPEC "-D__unix__ -D__gnu_linux__ -D__linux__ \
+diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
+index 5160e1fda..7632a5081 100644
+--- a/gcc/config/sol2.h
++++ b/gcc/config/sol2.h
+@@ -347,7 +347,11 @@ along with GCC; see the file COPYING3. If not see
+ /* Solaris 11 build 135+ implements dl_iterate_phdr. GNU ld needs
+ --eh-frame-hdr to create the required .eh_frame_hdr sections. */
+ #if defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR)
++#ifdef USE_EH_FRAME_HDR_FOR_STATIC
++#define LINK_EH_SPEC "--eh-frame-hdr "
++#else
+ #define LINK_EH_SPEC "%{!static:--eh-frame-hdr} "
++#endif
+ #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
+ #endif
+
+diff --git a/gcc/configure b/gcc/configure
+index 1c6e3407c..28ad05004 100755
+--- a/gcc/configure
++++ b/gcc/configure
+@@ -934,6 +934,7 @@ enable_fix_cortex_a53_835769
+ enable_fix_cortex_a53_843419
+ with_glibc_version
+ enable_gnu_unique_object
++enable_eh_frame_hdr_for_static
+ enable_linker_build_id
+ enable_default_ssp
+ with_long_double_128
+@@ -1670,6 +1671,9 @@ Optional Features:
+ --enable-gnu-unique-object
+ enable the use of the @gnu_unique_object ELF
+ extension on glibc systems
++ --enable-eh-frame-hdr-for-static
++ enable linker PT_GNU_EH_FRAME support for static
++ executable
+ --enable-linker-build-id
+ compiler will always pass --build-id to linker
+ --enable-default-ssp enable Stack Smashing Protection as default
+@@ -27703,6 +27707,38 @@ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+
+ $as_echo "#define HAVE_LD_EH_FRAME_HDR 1" >>confdefs.h
+
++ # Check whether --enable-eh-frame-hdr-for-static was given.
++if test "${enable_eh_frame_hdr_for_static+set}" = set; then :
++ enableval=$enable_eh_frame_hdr_for_static; case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) as_fn_error "'$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'." "$LINENO" 5 ;;
++ esac
++else
++ # Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi
++fi
++
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++
++$as_echo "#define USE_EH_FRAME_HDR_FOR_STATIC 1" >>confdefs.h
++
++ fi
+ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_ld_eh_frame_hdr" >&5
+ $as_echo "$gcc_cv_ld_eh_frame_hdr" >&6; }
+diff --git a/gcc/configure.ac b/gcc/configure.ac
+index 6c1dcd9ae..0cf7419e7 100644
+--- a/gcc/configure.ac
++++ b/gcc/configure.ac
+@@ -4828,6 +4828,35 @@ GCC_TARGET_TEMPLATE([HAVE_LD_EH_FRAME_HDR])
+ if test x"$gcc_cv_ld_eh_frame_hdr" = xyes; then
+ AC_DEFINE(HAVE_LD_EH_FRAME_HDR, 1,
+ [Define if your linker supports .eh_frame_hdr.])
++ AC_ARG_ENABLE(eh-frame-hdr-for-static,
++ [AS_HELP_STRING([--enable-eh-frame-hdr-for-static],
++ [enable linker PT_GNU_EH_FRAME support for static executable])],
++ [case $enable_eh_frame_hdr_for_static in
++ yes | no) ;;
++ *) AC_MSG_ERROR(['$enable_eh_frame_hdr_for_static' is an invalid
++value for --enable-eh-frame-hdr-for-static.
++Valid choices are 'yes' and 'no'.]) ;;
++ esac],
++# Only support for glibc 2.3.0 or higher with AT_PHDR/AT_PHNUM from
++# Linux kernel.
++ [[if test x$host = x$build -a x$host = x$target &&
++ ldd --version 2>&1 >/dev/null &&
++ glibcver=`ldd --version 2>/dev/null | sed 's/.* //;q'`; then
++ glibcmajor=`expr "$glibcver" : "\([0-9]*\)"`
++ glibcminor=`expr "$glibcver" : "[2-9]*\.\([0-9]*\)"`
++ glibcnum=`expr $glibcmajor \* 1000 + $glibcminor`
++ if test "$glibcnum" -ge 2003 ; then
++ auvx=`LD_SHOW_AUXV=1 ldd 2>/dev/null`
++ if echo "$auvx" | grep AT_PHDR > /dev/null &&
++ echo "$auvx" | grep AT_PHNUM > /dev/null; then
++ enable_eh_frame_hdr_for_static=yes
++ fi
++ fi
++ fi]])
++ if test x$enable_eh_frame_hdr_for_static = xyes; then
++ AC_DEFINE(USE_EH_FRAME_HDR_FOR_STATIC, 1,
++[Define if your system supports PT_GNU_EH_FRAME for static executable.])
++ fi
+ fi
+ AC_MSG_RESULT($gcc_cv_ld_eh_frame_hdr)
+
+diff --git a/gcc/testsuite/g++.dg/eh/spec3-static.C b/gcc/testsuite/g++.dg/eh/spec3-static.C
+new file mode 100644
+index 000000000..15408effa
+--- /dev/null
++++ b/gcc/testsuite/g++.dg/eh/spec3-static.C
+@@ -0,0 +1,25 @@
++// PR c++/4381
++// Test that exception-specs work properly for classes with virtual bases.
++
++// { dg-do run }
++// { dg-options "-static" }
++
++class Base {};
++
++struct A : virtual public Base
++{
++ A() {}
++};
++
++struct B {};
++
++void func() throw (B,A)
++{
++ throw A();
++}
++
++int main(void)
++{
++ try { func(); }
++ catch (A& a) { }
++}
+diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c
+index f3343fc4f..d42647779 100644
+--- a/libgcc/crtstuff.c
++++ b/libgcc/crtstuff.c
+@@ -88,7 +88,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(BSD_DL_ITERATE_PHDR_AVAILABLE)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -97,7 +98,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) && defined(TARGET_DL_ITERATE_PHDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__sun__) && defined(__svr4__)
+ #include <link.h>
+ # define USE_PT_GNU_EH_FRAME
+@@ -106,7 +108,8 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(inhibit_libc) && !defined(CRTSTUFFT_O) \
++ && !defined(inhibit_libc) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(__GLIBC__) && __GLIBC__ >= 2
+ #include <link.h>
+ /* uClibc pretends to be glibc 2.2 and DT_CONFIG is defined in its link.h.
+@@ -121,7 +124,7 @@ call_ ## FUNC (void) \
+ #if defined(OBJECT_FORMAT_ELF) \
+ && !defined(OBJECT_FORMAT_FLAT) \
+ && defined(HAVE_LD_EH_FRAME_HDR) \
+- && !defined(CRTSTUFFT_O) \
++ && (defined(USE_EH_FRAME_HDR_FOR_STATIC) || !defined(CRTSTUFFT_O)) \
+ && defined(inhibit_libc) \
+ && (defined(__GLIBC__) || defined(__gnu_linux__) || defined(__GNU__))
+ /* On systems using glibc, an inhibit_libc build of libgcc is only
diff --git a/patches/gcc/linaro-6.3-2017.05/973-crystax.patch b/patches/gcc/linaro-6.3-2017.05/973-crystax.patch
new file mode 100644
index 0000000..b96ece3
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/973-crystax.patch
@@ -0,0 +1,20 @@
+commit 778a9ef107f51544d583f110e92b75f4d9d79117
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Thu Aug 20 19:11:07 2015 +0300
+
+ [android] Don't use PIE copyrelocs for x86/x86_64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
+index 3d044e8bd..5c89fcab0 100644
+--- a/gcc/config/i386/i386.c
++++ b/gcc/config/i386/i386.c
+@@ -14631,6 +14631,7 @@ legitimate_pic_address_disp_p (rtx disp)
+ else if (!SYMBOL_REF_FAR_ADDR_P (op0)
+ && (SYMBOL_REF_LOCAL_P (op0)
+ || (HAVE_LD_PIE_COPYRELOC
++ && !TARGET_HAS_BIONIC
+ && flag_pie
+ && !SYMBOL_REF_WEAK (op0)
+ && !SYMBOL_REF_FUNCTION_P (op0)))
diff --git a/patches/gcc/linaro-6.3-2017.05/974-crystax.patch b/patches/gcc/linaro-6.3-2017.05/974-crystax.patch
new file mode 100644
index 0000000..9db4f54
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/974-crystax.patch
@@ -0,0 +1,24 @@
+commit dbeae1190cabad83999f2540523f045acc1bb4ec
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Fri Aug 21 17:41:59 2015 +0300
+
+ [android] Always use gthr-posix.h instead of gthr-default.h
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/libgcc/gthr.h b/libgcc/gthr.h
+index 47a7d061a..67a680f90 100644
+--- a/libgcc/gthr.h
++++ b/libgcc/gthr.h
+@@ -145,7 +145,11 @@ see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+ #define GTHREAD_USE_WEAK 1
+ #endif
+ #endif
++#if __ANDROID__
++#include "gthr-posix.h"
++#else
+ #include "gthr-default.h"
++#endif
+
+ #ifndef HIDE_EXPORTS
+ #pragma GCC visibility pop
diff --git a/patches/gcc/linaro-6.3-2017.05/975-crystax.patch b/patches/gcc/linaro-6.3-2017.05/975-crystax.patch
new file mode 100644
index 0000000..9efc2a4
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/975-crystax.patch
@@ -0,0 +1,31 @@
+commit 8a66d422721ae5999737d7825701ff22097d287b
+Author: Andrew Hsieh <andrewhsieh@google.com>
+Date: Mon Apr 14 21:05:51 2014 -0700
+
+ [android] Fix ARM generates insufficient alignment for NEON vst/vld
+
+ See d909af3e2469aad87d5c3e79b93c778fd26c03a9
+
+ Change-Id: Ie1de9f946f397196bb6f1623f5add86933739484
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
+index 5974c65d3..71b2c7aa9 100644
+--- a/gcc/config/arm/arm.c
++++ b/gcc/config/arm/arm.c
+@@ -22403,9 +22403,13 @@ arm_print_operand (FILE *stream, rtx x, int code)
+ memsize = MEM_SIZE (x);
+
+ /* Only certain alignment specifiers are supported by the hardware. */
+- if (memsize == 32 && (align % 32) == 0)
++ /* Note that ARM EABI only guarentees 8-byte stack alignment. While GCC
++ honors stricter alignment of composite type in user code, it doesn't
++ observe the alignment of memory passed as an extra argument for function
++ returning large composite type. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57271 */
++ if (memsize == 32 && (align % 32) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 256;
+- else if ((memsize == 16 || memsize == 32) && (align % 16) == 0)
++ else if ((memsize == 16 || memsize == 32) && (align % 16) == 0 && !TARGET_AAPCS_BASED)
+ align_bits = 128;
+ else if (memsize >= 8 && (align % 8) == 0)
+ align_bits = 64;
diff --git a/patches/gcc/linaro-6.3-2017.05/976-crystax.patch b/patches/gcc/linaro-6.3-2017.05/976-crystax.patch
new file mode 100644
index 0000000..790d4a9
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/976-crystax.patch
@@ -0,0 +1,21 @@
+commit 89d27bc45ee7325dcfff6748da0f8b9c1dc1f234
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Sat Aug 22 09:55:55 2015 +0300
+
+ [android][i386] Remove throw() declaration from posix_memalign() proto
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/i386/pmm_malloc.h b/gcc/config/i386/pmm_malloc.h
+index a1f98d3d1..3725799be 100644
+--- a/gcc/config/i386/pmm_malloc.h
++++ b/gcc/config/i386/pmm_malloc.h
+@@ -31,7 +31,7 @@
+ #ifndef __cplusplus
+ extern int posix_memalign (void **, size_t, size_t);
+ #else
+-extern "C" int posix_memalign (void **, size_t, size_t) throw ();
++extern "C" int posix_memalign (void **, size_t, size_t);
+ #endif
+
+ static __inline void *
diff --git a/patches/gcc/linaro-6.3-2017.05/977-crystax.patch b/patches/gcc/linaro-6.3-2017.05/977-crystax.patch
new file mode 100644
index 0000000..0211d72
--- /dev/null
+++ b/patches/gcc/linaro-6.3-2017.05/977-crystax.patch
@@ -0,0 +1,33 @@
+commit 9ae82f7cfc1073820092dd9f957559667e77db0d
+Author: Dmitry Moskalchuk <dm@crystax.net>
+Date: Tue Aug 25 09:36:42 2015 +0300
+
+ [android] Explicitly make _Unwind_Resume visible for arm64/mips64
+
+ Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
+
+diff --git a/gcc/config/aarch64/aarch64-linux-android.h b/gcc/config/aarch64/aarch64-linux-android.h
+index db1288fd0..38bc64d61 100644
+--- a/gcc/config/aarch64/aarch64-linux-android.h
++++ b/gcc/config/aarch64/aarch64-linux-android.h
+@@ -57,4 +57,8 @@
+ #define ENDFILE_SPEC \
+ LINUX_OR_ANDROID_LD (GNU_USER_TARGET_ENDFILE_SPEC, ANDROID_ENDFILE_SPEC)
+
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif
++
+ #endif /* GCC_AARCH64_LINUX_ANDROID_H */
+diff --git a/gcc/config/mips/linux-common.h b/gcc/config/mips/linux-common.h
+index 8bfacf994..262a9a341 100644
+--- a/gcc/config/mips/linux-common.h
++++ b/gcc/config/mips/linux-common.h
+@@ -63,3 +63,7 @@ along with GCC; see the file COPYING3. If not see
+
+ /* The default value isn't sufficient in 64-bit mode. */
+ #define STACK_CHECK_PROTECT (TARGET_64BIT ? 16 * 1024 : 12 * 1024)
++
++#ifdef IN_LIBGCC2
++#define LIBGCC2_UNWIND_ATTRIBUTE __attribute__((visibility("default")))
++#endif