diff --git a/etc/patches/gcc-4.8.5-with-gcc-7 b/etc/patches/gcc-4.8.5-with-gcc-7
new file mode 100644
index 0000000000000000000000000000000000000000..fbbf3ce5ee57fb2e2e4eabb8943a201d0137273e
--- /dev/null
+++ b/etc/patches/gcc-4.8.5-with-gcc-7
@@ -0,0 +1,155 @@
+#
+# Patch for building older gcc versions with gcc-7
+#
+--- gcc-4.8.5/gcc/cp/cfns.gperf.orig	2013-01-10 21:38:27.000000000 +0100
++++ gcc-4.8.5/gcc/cp/cfns.gperf	2016-02-25 16:36:41.000000000 +0100
+@@ -1,5 +1,7 @@
++%language=C++
++%define class-name libc_name
+ %{
+-/* Copyright (C) 2000-2013 Free Software Foundation, Inc.
++/* Copyright (C) 2000-2014 Free Software Foundation, Inc.
+ 
+ This file is part of GCC.
+ 
+@@ -16,14 +18,6 @@
+ 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/>.  */
+-#ifdef __GNUC__
+-__inline
+-#endif
+-static unsigned int hash (const char *, unsigned int);
+-#ifdef __GNUC__
+-__inline
+-#endif
+-const char * libc_name_p (const char *, unsigned int);
+ %}
+ %%
+ # The standard C library functions, for feeding to gperf; the result is used
+--- gcc-4.8.5/gcc/cp/cfns.h.orig	2013-01-10 21:38:27.000000000 +0100
++++ gcc-4.8.5/gcc/cp/cfns.h	2016-02-25 16:36:41.000000000 +0100
+@@ -1,5 +1,5 @@
+-/* ANSI-C code produced by gperf version 3.0.3 */
+-/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L ANSI-C cfns.gperf  */
++/* C++ code produced by gperf version 3.0.4 */
++/* Command-line: gperf -o -C -E -k '1-6,$' -j1 -D -N libc_name_p -L C++ --output-file cfns.h cfns.gperf  */
+ 
+ #if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
+       && ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
+@@ -28,9 +28,9 @@
+ #error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gnu-gperf@gnu.org>."
+ #endif
+ 
+-#line 1 "cfns.gperf"
++#line 3 "cfns.gperf"
+ 
+-/* Copyright (C) 2000-2013 Free Software Foundation, Inc.
++/* Copyright (C) 2000-2014 Free Software Foundation, Inc.
+ 
+ This file is part of GCC.
+ 
+@@ -47,25 +47,18 @@
+ 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/>.  */
+-#ifdef __GNUC__
+-__inline
+-#endif
+-static unsigned int hash (const char *, unsigned int);
+-#ifdef __GNUC__
+-__inline
+-#endif
+-const char * libc_name_p (const char *, unsigned int);
+ /* maximum key range = 391, duplicates = 0 */
+ 
+-#ifdef __GNUC__
+-__inline
+-#else
+-#ifdef __cplusplus
+-inline
+-#endif
+-#endif
+-static unsigned int
+-hash (register const char *str, register unsigned int len)
++class libc_name
++{
++private:
++  static inline unsigned int hash (const char *str, unsigned int len);
++public:
++  static const char *libc_name_p (const char *str, unsigned int len);
++};
++
++inline unsigned int
++libc_name::hash (register const char *str, register unsigned int len)
+ {
+   static const unsigned short asso_values[] =
+     {
+@@ -122,14 +115,8 @@
+   return hval + asso_values[(unsigned char)str[len - 1]];
+ }
+ 
+-#ifdef __GNUC__
+-__inline
+-#ifdef __GNUC_STDC_INLINE__
+-__attribute__ ((__gnu_inline__))
+-#endif
+-#endif
+ const char *
+-libc_name_p (register const char *str, register unsigned int len)
++libc_name::libc_name_p (register const char *str, register unsigned int len)
+ {
+   enum
+     {
+--- gcc-4.8.5/gcc/cp/except.c.orig	2013-10-25 15:49:48.000000000 +0200
++++ gcc-4.8.5/gcc/cp/except.c	2018-07-27 13:11:11.825369497 +0200
+@@ -1025,7 +1025,7 @@
+      unless the system headers are playing rename tricks, and if
+      they are, we don't want to be confused by them.  */
+   id = DECL_NAME (fn);
+-  return !!libc_name_p (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
++  return !!libc_name::libc_name_p (IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
+ }
+ 
+ /* Returns nonzero if an exception of type FROM will be caught by a
+--- gcc-4.8.5/libgcc/config/i386/linux-unwind.h.orig	2013-02-04 20:06:20.000000000 +0100
++++ gcc-4.8.5/libgcc/config/i386/linux-unwind.h	2018-07-27 12:51:18.305390871 +0200
+@@ -58,7 +58,7 @@
+   if (*(unsigned char *)(pc+0) == 0x48
+       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context->cfa;
++      ucontext_t *uc_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@
+ 	siginfo_t *pinfo;
+ 	void *puc;
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+--- gcc-4.8.5/libsanitizer/asan/asan_linux.cc.orig	2013-01-23 12:41:33.000000000 +0100
++++ gcc-4.8.5/libsanitizer/asan/asan_linux.cc	2018-07-27 12:51:45.641390381 +0200
+@@ -25,6 +25,7 @@
+ #include <sys/types.h>
+ #include <fcntl.h>
+ #include <pthread.h>
++#include <signal.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <unwind.h>
+--- gcc-4.8.5/libsanitizer/tsan/tsan_platform_linux.cc.orig	2013-02-21 11:57:10.000000000 +0100
++++ gcc-4.8.5/libsanitizer/tsan/tsan_platform_linux.cc	2018-07-27 13:17:32.417362682 +0200
+@@ -292,7 +292,7 @@
+ #ifndef TSAN_GO
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
diff --git a/etc/patches/gcc-4.9.4-with-gcc-7 b/etc/patches/gcc-4.9.4-with-gcc-7
new file mode 100644
index 0000000000000000000000000000000000000000..a93f217be4f9c3904f6dea724baca45e640397d7
--- /dev/null
+++ b/etc/patches/gcc-4.9.4-with-gcc-7
@@ -0,0 +1,87 @@
+#
+# Patch for building older gcc versions with gcc-7
+#
+--- gcc-4.9.4/libgcc/config/i386/linux-unwind.h.orig	2014-01-02 23:25:22.000000000 +0100
++++ gcc-4.9.4/libgcc/config/i386/linux-unwind.h	2018-07-27 10:43:46.021527909 +0200
+@@ -58,7 +58,7 @@
+   if (*(unsigned char *)(pc+0) == 0x48
+       && *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context->cfa;
++      ucontext_t *uc_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@
+ 	siginfo_t *pinfo;
+ 	void *puc;
+ 	siginfo_t info;
+-	struct ucontext uc;
++	ucontext_t uc;
+       } *rt_ = context->cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+--- gcc-4.9.4/libsanitizer/asan/asan_linux.cc.orig	2013-12-05 10:18:38.000000000 +0100
++++ gcc-4.9.4/libsanitizer/asan/asan_linux.cc	2018-07-27 11:11:52.085497715 +0200
+@@ -26,6 +26,7 @@
+ #include <sys/types.h>
+ #include <fcntl.h>
+ #include <pthread.h>
++#include <signal.h>
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <unwind.h>
+--- gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_linux.cc.orig	2013-12-05 10:18:38.000000000 +0100
++++ gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_linux.cc	2018-07-27 10:43:02.405528690 +0200
+@@ -599,8 +599,7 @@
+   return internal_syscall(__NR_prctl, option, arg2, arg3, arg4, arg5);
+ }
+ 
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(__NR_sigaltstack, (uptr)ss, (uptr)oss);
+ }
+ 
+--- gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_linux.h.orig	2013-12-05 10:18:38.000000000 +0100
++++ gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_linux.h	2018-07-27 10:42:29.845529273 +0200
+@@ -18,7 +18,6 @@
+ #include "sanitizer_platform_limits_posix.h"
+ 
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+ 
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -28,8 +27,7 @@
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigaction(int signum, const __sanitizer_kernel_sigaction_t *act,
+     __sanitizer_kernel_sigaction_t *oldact);
+ uptr internal_sigprocmask(int how, __sanitizer_kernel_sigset_t *set,
+--- gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc.orig	2013-12-05 11:28:59.000000000 +0100
++++ gcc-4.9.4/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc	2018-07-27 10:41:32.053530308 +0200
+@@ -238,7 +238,7 @@
+ 
+   // Alternate stack for signal handling.
+   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+--- gcc-4.9.4/libsanitizer/tsan/tsan_platform_linux.cc.orig	2013-12-05 10:18:38.000000000 +0100
++++ gcc-4.9.4/libsanitizer/tsan/tsan_platform_linux.cc	2018-07-27 10:40:13.781531710 +0200
+@@ -351,7 +351,7 @@
+ // closes within glibc. The code is a pure hack.
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
diff --git a/etc/patches/gcc-6.3.0-with-gcc-7 b/etc/patches/gcc-6.3.0-with-gcc-7
new file mode 100644
index 0000000000000000000000000000000000000000..9ee055992c29b0ffbd8bb40790b7f09c5a64b617
--- /dev/null
+++ b/etc/patches/gcc-6.3.0-with-gcc-7
@@ -0,0 +1,82 @@
+#
+# Patch for building older gcc versions with gcc-7
+#
+diff -u gcc-6.3.0/libgcc/config/i386/linux-unwind.h.orig gcc-6.3.0/libgcc/config/i386/linux-unwind.h
+--- gcc-6.3.0/libgcc/config/i386/linux-unwind.h.orig 2016-01-04 23:30:50.000000000 +0900
++++ gcc-6.3.0/libgcc/config/i386/linux-unwind.h 2017-10-29 23:01:21.717240052 +0900
+@@ -58,7 +58,7 @@
+   if (*(unsigned char *)(pc+0) == 0x48
+       &amp;&amp; *(unsigned long long *)(pc+1) == RT_SIGRETURN_SYSCALL)
+     {
+-      struct ucontext *uc_ = context-&gt;cfa;
++      ucontext_t *uc_ = context-&gt;cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+          because it does not alias anything.  */
+@@ -138,7 +138,7 @@
+  siginfo_t *pinfo;
+  void *puc;
+  siginfo_t info;
+- struct ucontext uc;
++ ucontext_t uc;
+       } *rt_ = context-&gt;cfa;
+       /* The void * cast is necessary to avoid an aliasing warning.
+          The aliasing warning is correct, but should not be a problem
+diff -u gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc.orig gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc
+--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc.orig 2015-11-23 18:07:18.000000000 +0900
++++ gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cc 2017-10-29 23:09:00.490577558 +0900
+@@ -546,8 +546,7 @@
+ }
+ #endif
+
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
+ }
+
+diff -u gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h.orig gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h
+--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h.orig 2015-10-21 16:32:45.000000000 +0900
++++ gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_linux.h 2017-10-29 23:09:43.907244619 +0900
+@@ -19,7 +19,6 @@
+ #include "sanitizer_platform_limits_posix.h"
+
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -28,8 +27,7 @@
+
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset);
+ void internal_sigfillset(__sanitizer_sigset_t *set);
+diff -u gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc.orig gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+--- gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc.orig 2015-10-21 16:32:45.000000000 +0900
++++ gcc-6.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc 2017-10-29 23:08:07.260577074 +0900
+@@ -267,7 +267,7 @@
+
+   // Alternate stack for signal handling.
+   InternalScopedBuffer&lt;char&gt; handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&amp;handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+diff -u gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc.orig gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc
+--- gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc.orig 2016-08-12 17:53:46.000000000 +0900
++++ gcc-6.3.0/libsanitizer/tsan/tsan_platform_linux.cc 2017-10-29 23:10:38.817245120 +0900
+@@ -291,7 +291,7 @@
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+ #if SANITIZER_LINUX
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i &lt; MAXNS &amp;&amp; cnt &lt; nfd; i++) {
+     if (statp-&gt;_u._ext.nsaddrs[i] &amp;&amp; statp-&gt;_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp-&gt;_u._ext.nssocks[i];