--- /dev/null
+From ff45000fcb56b5b0f1a14a865d3541746d838a0a Mon Sep 17 00:00:00 2001
+From: Nicholas Piggin <npiggin@gmail.com>
+Date: Mon, 28 Nov 2016 12:42:26 +1100
+Subject: powerpc/boot: Request no dynamic linker for boot wrapper
+
+From: Nicholas Piggin <npiggin@gmail.com>
+
+commit ff45000fcb56b5b0f1a14a865d3541746d838a0a upstream.
+
+The boot wrapper performs its own relocations and does not require
+PT_INTERP segment. However currently we don't tell the linker that.
+
+Prior to binutils 2.28 that works OK. But since binutils commit
+1a9ccd70f9a7 ("Fix the linker so that it will not silently generate ELF
+binaries with invalid program headers. Fix readelf to report such
+invalid binaries.") binutils tries to create a program header segment
+due to PT_INTERP, and the link fails because there is no space for it:
+
+ ld: arch/powerpc/boot/zImage.pseries: Not enough room for program headers, try linking with -N
+ ld: final link failed: Bad value
+
+So tell the linker not to do that, by passing --no-dynamic-linker.
+
+Cc: stable@vger.kernel.org
+Reported-by: Anton Blanchard <anton@samba.org>
+Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
+[mpe: Drop dependency on ld-version.sh and massage change log]
+Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
+[ajd: backport to v4.4 (resolve conflict with a comment line)]
+Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/powerpc/boot/wrapper | 24 +++++++++++++++++++++++-
+ 1 file changed, 23 insertions(+), 1 deletion(-)
+
+--- a/arch/powerpc/boot/wrapper
++++ b/arch/powerpc/boot/wrapper
+@@ -161,6 +161,28 @@ case "$elfformat" in
+ elf32-powerpc) format=elf32ppc ;;
+ esac
+
++ld_version()
++{
++ # Poached from scripts/ld-version.sh, but we don't want to call that because
++ # this script (wrapper) is distributed separately from the kernel source.
++ # Extract linker version number from stdin and turn into single number.
++ awk '{
++ gsub(".*\\)", "");
++ gsub(".*version ", "");
++ gsub("-.*", "");
++ split($1,a, ".");
++ print a[1]*100000000 + a[2]*1000000 + a[3]*10000;
++ exit
++ }'
++}
++
++# Do not include PT_INTERP segment when linking pie. Non-pie linking
++# just ignores this option.
++LD_VERSION=$(${CROSS}ld --version | ld_version)
++LD_NO_DL_MIN_VERSION=$(echo 2.26 | ld_version)
++if [ "$LD_VERSION" -ge "$LD_NO_DL_MIN_VERSION" ] ; then
++ nodl="--no-dynamic-linker"
++fi
+
+ platformo=$object/"$platform".o
+ lds=$object/zImage.lds
+@@ -412,7 +434,7 @@ if [ "$platform" != "miboot" ]; then
+ if [ -n "$link_address" ] ; then
+ text_start="-Ttext $link_address"
+ fi
+- ${CROSS}ld -m $format -T $lds $text_start $pie -o "$ofile" \
++ ${CROSS}ld -m $format -T $lds $text_start $pie $nodl -o "$ofile" \
+ $platformo $tmp $object/wrapper.a
+ rm $tmp
+ fi
--- /dev/null
+From 4dc831aa88132f835cefe876aa0206977c4d7710 Mon Sep 17 00:00:00 2001
+From: Nicholas Piggin <npiggin@gmail.com>
+Date: Sun, 27 Nov 2016 13:46:20 +1100
+Subject: powerpc: Fix compiling a BE kernel with a powerpc64le toolchain
+
+From: Nicholas Piggin <npiggin@gmail.com>
+
+commit 4dc831aa88132f835cefe876aa0206977c4d7710 upstream.
+
+GCC can compile with either endian, but the default ABI version is set
+based on the default endianness of the toolchain. Alan Modra says:
+
+ you need both -mbig and -mabi=elfv1 to make a powerpc64le gcc
+ generate powerpc64 code
+
+The opposite is true for powerpc64 when generating -mlittle it
+requires -mabi=elfv2 to generate v2 ABI, which we were already doing.
+
+This change adds ABI annotations together with endianness for all cases,
+LE and BE. This fixes the case of building a BE kernel with a toolchain
+that is LE by default.
+
+Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
+Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
+Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
+Cc: Andrew Donnellan <ajd@linux.ibm.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/powerpc/Makefile | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+--- a/arch/powerpc/Makefile
++++ b/arch/powerpc/Makefile
+@@ -79,8 +79,15 @@ GNUTARGET := powerpc
+ MULTIPLEWORD := -mmultiple
+ endif
+
+-cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
++ifdef CONFIG_PPC64
++cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mabi=elfv1)
++cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mcall-aixdesc)
++aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mabi=elfv1)
++aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mabi=elfv2
++endif
++
+ cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
++cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
+ ifneq ($(cc-name),clang)
+ cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
+ endif
+@@ -120,7 +127,9 @@ ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
+ CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2,$(call cc-option,-mcall-aixdesc))
+ AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv2)
+ else
++CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
+ CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcall-aixdesc)
++AFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mabi=elfv1)
+ endif
+ CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mcmodel=medium,$(call cc-option,-mminimal-toc))
+ CFLAGS-$(CONFIG_PPC64) += $(call cc-option,-mno-pointers-to-nested-functions)
--- /dev/null
+From 164af597ce945751e2dcd53d0a86e84203a6d117 Mon Sep 17 00:00:00 2001
+From: Michael Ellerman <mpe@ellerman.id.au>
+Date: Tue, 9 Aug 2016 22:43:46 +1000
+Subject: powerpc/Makefile: Use cflags-y/aflags-y for setting endian options
+
+From: Michael Ellerman <mpe@ellerman.id.au>
+
+commit 164af597ce945751e2dcd53d0a86e84203a6d117 upstream.
+
+When we introduced the little endian support, we added the endian flags
+to CC directly using override. I don't know the history of why we did
+that, I suspect no one does.
+
+Although this mostly works, it has one bug, which is that CROSS32CC
+doesn't get -mbig-endian. That means when the compiler is little endian
+by default and the user is building big endian, vdso32 is incorrectly
+compiled as little endian and the kernel fails to build.
+
+Instead we can add the endian flags to cflags-y/aflags-y, and then
+append those to KBUILD_CFLAGS/KBUILD_AFLAGS.
+
+This has the advantage of being 1) less ugly, 2) the documented way of
+adding flags in the arch Makefile and 3) it fixes building vdso32 with a
+LE toolchain.
+
+Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
+Cc: Andrew Donnellan <ajd@linux.ibm.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ arch/powerpc/Makefile | 22 ++++++++++++----------
+ 1 file changed, 12 insertions(+), 10 deletions(-)
+
+--- a/arch/powerpc/Makefile
++++ b/arch/powerpc/Makefile
+@@ -66,29 +66,28 @@ endif
+ UTS_MACHINE := $(OLDARCH)
+
+ ifeq ($(CONFIG_CPU_LITTLE_ENDIAN),y)
+-override CC += -mlittle-endian
+-ifneq ($(cc-name),clang)
+-override CC += -mno-strict-align
+-endif
+-override AS += -mlittle-endian
+ override LD += -EL
+-override CROSS32CC += -mlittle-endian
+ override CROSS32AS += -mlittle-endian
+ LDEMULATION := lppc
+ GNUTARGET := powerpcle
+ MULTIPLEWORD := -mno-multiple
+ KBUILD_CFLAGS_MODULE += $(call cc-option,-mno-save-toc-indirect)
+ else
+-ifeq ($(call cc-option-yn,-mbig-endian),y)
+-override CC += -mbig-endian
+-override AS += -mbig-endian
+-endif
+ override LD += -EB
+ LDEMULATION := ppc
+ GNUTARGET := powerpc
+ MULTIPLEWORD := -mmultiple
+ endif
+
++cflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
++cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
++ifneq ($(cc-name),clang)
++ cflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mno-strict-align
++endif
++
++aflags-$(CONFIG_CPU_BIG_ENDIAN) += $(call cc-option,-mbig-endian)
++aflags-$(CONFIG_CPU_LITTLE_ENDIAN) += -mlittle-endian
++
+ ifeq ($(HAS_BIARCH),y)
+ override AS += -a$(CONFIG_WORD_SIZE)
+ override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION)
+@@ -212,6 +211,9 @@ cpu-as-$(CONFIG_E200) += -Wa,-me200
+ KBUILD_AFLAGS += $(cpu-as-y)
+ KBUILD_CFLAGS += $(cpu-as-y)
+
++KBUILD_AFLAGS += $(aflags-y)
++KBUILD_CFLAGS += $(cflags-y)
++
+ head-y := arch/powerpc/kernel/head_$(CONFIG_WORD_SIZE).o
+ head-$(CONFIG_8xx) := arch/powerpc/kernel/head_8xx.o
+ head-$(CONFIG_40x) := arch/powerpc/kernel/head_40x.o
kvm-mmu-don-t-read-pdptes-when-paging-is-not-enabled.patch
mips-bcm63xx-fix-switch-core-reset-on-bcm6368.patch
+powerpc-makefile-use-cflags-y-aflags-y-for-setting-endian-options.patch
+powerpc-fix-compiling-a-be-kernel-with-a-powerpc64le-toolchain.patch
+powerpc-boot-request-no-dynamic-linker-for-boot-wrapper.patch