--- /dev/null
+From f43edca7ed08fc02279f2a62015da5cb6aa0ad61 Mon Sep 17 00:00:00 2001
+From: Ralf Baechle <ralf@linux-mips.org>
+Date: Mon, 23 May 2016 16:22:26 -0700
+Subject: ELF/MIPS build fix
+
+From: Ralf Baechle <ralf@linux-mips.org>
+
+commit f43edca7ed08fc02279f2a62015da5cb6aa0ad61 upstream.
+
+CONFIG_MIPS32_N32=y but CONFIG_BINFMT_ELF disabled results in the
+following linker errors:
+
+ arch/mips/built-in.o: In function `elf_core_dump':
+ binfmt_elfn32.c:(.text+0x23dbc): undefined reference to `elf_core_extra_phdrs'
+ binfmt_elfn32.c:(.text+0x246e4): undefined reference to `elf_core_extra_data_size'
+ binfmt_elfn32.c:(.text+0x248d0): undefined reference to `elf_core_write_extra_phdrs'
+ binfmt_elfn32.c:(.text+0x24ac4): undefined reference to `elf_core_write_extra_data'
+
+CONFIG_MIPS32_O32=y but CONFIG_BINFMT_ELF disabled results in the following
+linker errors:
+
+ arch/mips/built-in.o: In function `elf_core_dump':
+ binfmt_elfo32.c:(.text+0x28a04): undefined reference to `elf_core_extra_phdrs'
+ binfmt_elfo32.c:(.text+0x29330): undefined reference to `elf_core_extra_data_size'
+ binfmt_elfo32.c:(.text+0x2951c): undefined reference to `elf_core_write_extra_phdrs'
+ binfmt_elfo32.c:(.text+0x29710): undefined reference to `elf_core_write_extra_data'
+
+This is because binfmt_elfn32 and binfmt_elfo32 are using symbols from
+elfcore but for these configurations elfcore will not be built.
+
+Fixed by making elfcore selectable by a separate config symbol which
+unlike the current mechanism can also be used from other directories
+than kernel/, then having each flavor of ELF that relies on elfcore.o,
+select it in Kconfig, including CONFIG_MIPS32_N32 and CONFIG_MIPS32_O32
+which fixes this issue.
+
+Link: http://lkml.kernel.org/r/20160520141705.GA1913@linux-mips.org
+Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
+Reviewed-by: James Hogan <james.hogan@imgtec.com>
+Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ arch/mips/Kconfig | 1 +
+ fs/Kconfig.binfmt | 8 ++++++++
+ kernel/Makefile | 4 +---
+ 3 files changed, 10 insertions(+), 3 deletions(-)
+
+--- a/arch/mips/Kconfig
++++ b/arch/mips/Kconfig
+@@ -2990,6 +2990,7 @@ config MIPS32_N32
+ config BINFMT_ELF32
+ bool
+ default y if MIPS32_O32 || MIPS32_N32
++ select ELFCORE
+
+ endmenu
+
+--- a/fs/Kconfig.binfmt
++++ b/fs/Kconfig.binfmt
+@@ -1,6 +1,7 @@
+ config BINFMT_ELF
+ bool "Kernel support for ELF binaries"
+ depends on MMU && (BROKEN || !FRV)
++ select ELFCORE
+ default y
+ ---help---
+ ELF (Executable and Linkable Format) is a format for libraries and
+@@ -26,6 +27,7 @@ config BINFMT_ELF
+ config COMPAT_BINFMT_ELF
+ bool
+ depends on COMPAT && BINFMT_ELF
++ select ELFCORE
+
+ config ARCH_BINFMT_ELF_STATE
+ bool
+@@ -34,6 +36,7 @@ config BINFMT_ELF_FDPIC
+ bool "Kernel support for FDPIC ELF binaries"
+ default y
+ depends on (FRV || BLACKFIN || (SUPERH32 && !MMU) || C6X)
++ select ELFCORE
+ help
+ ELF FDPIC binaries are based on ELF, but allow the individual load
+ segments of a binary to be located in memory independently of each
+@@ -43,6 +46,11 @@ config BINFMT_ELF_FDPIC
+
+ It is also possible to run FDPIC ELF binaries on MMU linux also.
+
++config ELFCORE
++ bool
++ help
++ This option enables kernel/elfcore.o.
++
+ config CORE_DUMP_DEFAULT_ELF_HEADERS
+ bool "Write ELF core dumps with partial segments"
+ default y
+--- a/kernel/Makefile
++++ b/kernel/Makefile
+@@ -77,9 +77,7 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayac
+ obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
+ obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
+ obj-$(CONFIG_LATENCYTOP) += latencytop.o
+-obj-$(CONFIG_BINFMT_ELF) += elfcore.o
+-obj-$(CONFIG_COMPAT_BINFMT_ELF) += elfcore.o
+-obj-$(CONFIG_BINFMT_ELF_FDPIC) += elfcore.o
++obj-$(CONFIG_ELFCORE) += elfcore.o
+ obj-$(CONFIG_FUNCTION_TRACER) += trace/
+ obj-$(CONFIG_TRACING) += trace/
+ obj-$(CONFIG_TRACE_CLOCK) += trace/
--- /dev/null
+From 6e7b64b9dd6d96537d816ea07ec26b7dedd397b9 Mon Sep 17 00:00:00 2001
+From: Arnd Bergmann <arnd@arndb.de>
+Date: Fri, 11 Dec 2020 13:36:46 -0800
+Subject: elfcore: fix building with clang
+
+From: Arnd Bergmann <arnd@arndb.de>
+
+commit 6e7b64b9dd6d96537d816ea07ec26b7dedd397b9 upstream.
+
+kernel/elfcore.c only contains weak symbols, which triggers a bug with
+clang in combination with recordmcount:
+
+ Cannot find symbol for section 2: .text.
+ kernel/elfcore.o: failed
+
+Move the empty stubs into linux/elfcore.h as inline functions. As only
+two architectures use these, just use the architecture specific Kconfig
+symbols to key off the declaration.
+
+Link: https://lkml.kernel.org/r/20201204165742.3815221-2-arnd@kernel.org
+Signed-off-by: Arnd Bergmann <arnd@arndb.de>
+Cc: Nathan Chancellor <natechancellor@gmail.com>
+Cc: Nick Desaulniers <ndesaulniers@google.com>
+Cc: Barret Rhoden <brho@google.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/elfcore.h | 22 ++++++++++++++++++++++
+ kernel/Makefile | 1 -
+ kernel/elfcore.c | 25 -------------------------
+ 3 files changed, 22 insertions(+), 26 deletions(-)
+ delete mode 100644 kernel/elfcore.c
+
+--- a/include/linux/elfcore.h
++++ b/include/linux/elfcore.h
+@@ -55,6 +55,7 @@ static inline int elf_core_copy_task_xfp
+ }
+ #endif
+
++#if defined(CONFIG_UM) || defined(CONFIG_IA64)
+ /*
+ * These functions parameterize elf_core_dump in fs/binfmt_elf.c to write out
+ * extra segments containing the gate DSO contents. Dumping its
+@@ -69,5 +70,26 @@ elf_core_write_extra_phdrs(struct coredu
+ extern int
+ elf_core_write_extra_data(struct coredump_params *cprm);
+ extern size_t elf_core_extra_data_size(void);
++#else
++static inline Elf_Half elf_core_extra_phdrs(void)
++{
++ return 0;
++}
++
++static inline int elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
++{
++ return 1;
++}
++
++static inline int elf_core_write_extra_data(struct coredump_params *cprm)
++{
++ return 1;
++}
++
++static inline size_t elf_core_extra_data_size(void)
++{
++ return 0;
++}
++#endif
+
+ #endif /* _LINUX_ELFCORE_H */
+--- a/kernel/Makefile
++++ b/kernel/Makefile
+@@ -77,7 +77,6 @@ obj-$(CONFIG_TASK_DELAY_ACCT) += delayac
+ obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o
+ obj-$(CONFIG_TRACEPOINTS) += tracepoint.o
+ obj-$(CONFIG_LATENCYTOP) += latencytop.o
+-obj-$(CONFIG_ELFCORE) += elfcore.o
+ obj-$(CONFIG_FUNCTION_TRACER) += trace/
+ obj-$(CONFIG_TRACING) += trace/
+ obj-$(CONFIG_TRACE_CLOCK) += trace/
+--- a/kernel/elfcore.c
++++ /dev/null
+@@ -1,25 +0,0 @@
+-#include <linux/elf.h>
+-#include <linux/fs.h>
+-#include <linux/mm.h>
+-#include <linux/binfmts.h>
+-#include <linux/elfcore.h>
+-
+-Elf_Half __weak elf_core_extra_phdrs(void)
+-{
+- return 0;
+-}
+-
+-int __weak elf_core_write_extra_phdrs(struct coredump_params *cprm, loff_t offset)
+-{
+- return 1;
+-}
+-
+-int __weak elf_core_write_extra_data(struct coredump_params *cprm)
+-{
+- return 1;
+-}
+-
+-size_t __weak elf_core_extra_data_size(void)
+-{
+- return 0;
+-}