diff --git a/main/gcc/APKBUILD b/main/gcc/APKBUILD
index 6323f1bcc65c558188073da34cc6d05bf7e46fce..f90cd60be5e760c2f5ef765834996350301b51aa 100644
--- a/main/gcc/APKBUILD
+++ b/main/gcc/APKBUILD
@@ -192,6 +192,8 @@ source="ftp://gcc.gnu.org/pub/gcc/releases/gcc-${_pkgbase:-$pkgver}/gcc-${_pkgba
 	ada-musl.patch
 
 	300-main-gcc-add-musl-s390x-dynamic-linker.patch
+
+	fix-rs6000-pie.patch
 	"
 
 # we build out-of-tree
@@ -646,7 +648,8 @@ e17bbb0fe802974e20645b4182b4c410  fix-gcj-iconv-musl.patch
 d00d7e4b0c00cb7448576af9cd7fcea8  ada-fixes.patch
 20e2731c02ce50739ebdead2795f9c41  ada-shared.patch
 bd2f71f7559e0aa38745ee62e5799601  ada-musl.patch
-29d7ce72d73cb920c6d1f276a2286f40  300-main-gcc-add-musl-s390x-dynamic-linker.patch"
+29d7ce72d73cb920c6d1f276a2286f40  300-main-gcc-add-musl-s390x-dynamic-linker.patch
+75a8966bf9396dc67a423258e4dcf617  fix-rs6000-pie.patch"
 sha256sums="f06ae7f3f790fbf0f018f6d40e844451e6bc3b7bc96e128e63b09825c1f8b29f  gcc-6.3.0.tar.bz2
 9506e75b862f782213df61af67338eb7a23c35ff425d328affc65585477d34cd  ecj-4.9.jar
 deb22792f37e107d0afff5f4ea6b2a9fc9de4f48e1c7133bf658b6e0d057b1d6  001_all_default-ssp-strong.patch
@@ -681,7 +684,8 @@ a395ba4cf047c48cac56985726fddf0948f4425c9f1a0c9ddba1812b2b3d8300  fix-cxxflags-p
 d2a67a7ae0304cd10532883df19923b98dbc9b7a24957b619d4a6e04f19c5507  ada-fixes.patch
 d6c7fc1820a4fa285297c299c255fe2f19ce1695486f20edd098252a97545e6a  ada-shared.patch
 f7f5aa37d27644292a90ab31afdf4be93b116507bfc39f4d9f6af047311b7d87  ada-musl.patch
-66b1d3c5880e0651c46f32f3a44171cc80d216d6514e75b8d7bd8fdbc565424c  300-main-gcc-add-musl-s390x-dynamic-linker.patch"
+66b1d3c5880e0651c46f32f3a44171cc80d216d6514e75b8d7bd8fdbc565424c  300-main-gcc-add-musl-s390x-dynamic-linker.patch
+337b90a6350ae1170634b1bc0f910b39a5d346f50bf8ca7addeb404ed145a609  fix-rs6000-pie.patch"
 sha512sums="234dd9b1bdc9a9c6e352216a7ef4ccadc6c07f156006a59759c5e0e6a69f0abcdc14630eff11e3826dd6ba5933a8faa43043f3d1d62df6bd5ab1e82862f9bf78  gcc-6.3.0.tar.bz2
 28f8c6fdbcb19e950b1d0bafb3bcc7a8cba87bc673aa6027cece116599cdee80f0cf5e95a1440544890239f5c754e8a93ab46d9daedd937faef445d7ea33b226  ecj-4.9.jar
 a1335adc2fbee98e36c4437ff2587771b98ed4180726779020f65039498235626a411cdb0100dbd20cd19d12f0d94f9a21af179ff624676c28cead9d60598b5d  001_all_default-ssp-strong.patch
@@ -716,4 +720,5 @@ abe9aaf9aa956058d0386a4396a511d176a46bb3906b90e952383646cdc158cbeb0a5dc616a1ccb1
 9016b257abd8fa981de44a49512e35db814d1cbb47c1a87cd31c12d4ae20b13e9e149fe41691a7ec3c95bbcfde8a79194a8d2eaf547ceade3a246fad67c47dd8  ada-fixes.patch
 3f5bc334d9f73d06f5f7c876738d02356acdd08958bea0e4d2095ebf15c2c2ec4e411abdae0297505ae9a1699ca01b17338e853184e84663203b192b0d35fc19  ada-shared.patch
 631d4bdef6d8bde34df7978bb53ec28c3c909cf1f87139e5f148138d0f09adc58b41ecf0148bbf50fb4bc916c411e9bf8a2b6c046c75c0e77d754d8c35bcd4d7  ada-musl.patch
-4b4a0ff306a8ef34ff6e3284fbfca869012164a47ba7cb099085c1dd03e6ca0cdd462f82710e08c9a02895adc7484e4c5eef17b5aa264cf5d978fe8ad78eea93  300-main-gcc-add-musl-s390x-dynamic-linker.patch"
+4b4a0ff306a8ef34ff6e3284fbfca869012164a47ba7cb099085c1dd03e6ca0cdd462f82710e08c9a02895adc7484e4c5eef17b5aa264cf5d978fe8ad78eea93  300-main-gcc-add-musl-s390x-dynamic-linker.patch
+01c71cd5881fc07ea3b9b980697e89b3ca0fe98502958ceafc3fca18b2604c844e2f457feab711baf8e03f00a5383b0e38aac7eb954034e306f43d4a37f165ed  fix-rs6000-pie.patch"
diff --git a/main/gcc/fix-rs6000-pie.patch b/main/gcc/fix-rs6000-pie.patch
new file mode 100644
index 0000000000000000000000000000000000000000..1fbc31a56a32b5c4b81b0243156e60c8b8bcd0b0
--- /dev/null
+++ b/main/gcc/fix-rs6000-pie.patch
@@ -0,0 +1,59 @@
+--- gcc-6.3.0.orig/gcc/config/rs6000/sysv4.h
++++ gcc-6.3.0/gcc/config/rs6000/sysv4.h
+@@ -753,23 +753,42 @@
+ #endif
+ 
+ #ifdef HAVE_LD_PIE
+-#define	STARTFILE_LINUX_SPEC "\
+-%{!shared: %{pg|p|profile:gcrt1.o%s;pie:Scrt1.o%s;:crt1.o%s}} \
+-%{mnewlib:ecrti.o%s;:crti.o%s} \
+-%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
+-" CRTOFFLOADBEGIN
++#define STARTFILE_LINUX_SPEC \
++  "%{!shared: %{pg|p|profile:gcrt1.o%s;: \
++    %{" PIE_SPEC ":%{static:rcrt1.o%s;:Scrt1.o%s}} %{" NO_PIE_SPEC ":crt1.o%s}}} \
++   crti.o%s %{shared:crtbeginS.o%s;: \
++              %{" PIE_SPEC ":crtbeginS.o%s} \
++              %{" NO_PIE_SPEC ":%{static:crtbeginT.o%s;:crtbegin.o%s}}} \
++   %{fvtable-verify=none:%s; \
++     fvtable-verify=preinit:vtv_start_preinit.o%s; \
++     fvtable-verify=std:vtv_start.o%s} \
++   " CRTOFFLOADBEGIN
+ #else
+-#define	STARTFILE_LINUX_SPEC "\
+-%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
+-%{mnewlib:ecrti.o%s;:crti.o%s} \
+-%{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
+-" CRTOFFLOADBEGIN
++#define STARTFILE_LINUX_SPEC \
++  "%{!shared: %{pg|p|profile:gcrt1.o%s;:crt1.o%s}} \
++   crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s} \
++   %{fvtable-verify=none:%s; \
++     fvtable-verify=preinit:vtv_start_preinit.o%s; \
++     fvtable-verify=std:vtv_start.o%s} \
++   " CRTOFFLOADBEGIN
+ #endif
+ 
+-#define	ENDFILE_LINUX_SPEC "\
+-%{shared|pie:crtendS.o%s;:crtend.o%s} \
+-%{mnewlib:ecrtn.o%s;:crtn.o%s} \
+-" CRTOFFLOADEND
++#ifdef HAVE_LD_PIE
++#define ENDFILE_LINUX_SPEC \
++  "%{fvtable-verify=none:%s; \
++     fvtable-verify=preinit:vtv_end_preinit.o%s; \
++     fvtable-verify=std:vtv_end.o%s} \
++   %{shared:crtendS.o%s;: %{" PIE_SPEC ":crtendS.o%s} \
++   %{" NO_PIE_SPEC ":crtend.o%s}} crtn.o%s \
++   " CRTOFFLOADEND
++#else
++#define ENDFILE_LINUX_SPEC \
++  "%{fvtable-verify=none:%s; \
++     fvtable-verify=preinit:vtv_end_preinit.o%s; \
++     fvtable-verify=std:vtv_end.o%s} \
++   %{shared|pie:crtendS.o%s;:crtend.o%s} crtn.o%s \
++   " CRTOFFLOADEND
++#endif
+ 
+ #define LINK_START_LINUX_SPEC ""
+