summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/elfutils/files
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/elfutils/files')
-rw-r--r--meta/recipes-devtools/elfutils/files/0001-dso-link-change.patch50
-rw-r--r--meta/recipes-devtools/elfutils/files/0001-libasm-may-link-with-libbz2-if-found.patch36
-rw-r--r--meta/recipes-devtools/elfutils/files/0001-libelf-elf_end.c-check-data_list.data.d.d_buf-before.patch44
-rw-r--r--meta/recipes-devtools/elfutils/files/0001-ppc_initreg.c-Incliude-asm-ptrace.h-for-pt_regs-defi.patch32
-rw-r--r--meta/recipes-devtools/elfutils/files/0001-skip-the-test-when-gcc-not-deployed.patch73
-rw-r--r--meta/recipes-devtools/elfutils/files/0002-Fix-elf_cvt_gunhash-if-dest-and-src-are-same.patch40
-rw-r--r--meta/recipes-devtools/elfutils/files/0003-fixheadercheck.patch38
-rw-r--r--meta/recipes-devtools/elfutils/files/0004-Disable-the-test-to-convert-euc-jp.patch42
-rw-r--r--meta/recipes-devtools/elfutils/files/0006-Fix-build-on-aarch64-musl.patch59
-rw-r--r--meta/recipes-devtools/elfutils/files/0007-Fix-control-path-where-we-have-str-as-uninitialized-.patch42
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/0001-Ignore-differences-between-mips-machine-identifiers.patch34
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/0001-fix-compile-failure-with-debian-patches.patch48
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/0002-Add-support-for-mips64-abis-in-mips_retval.c.patch171
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/0003-Add-mips-n64-relocation-format-hack.patch229
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/arm_backend.diff624
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/disable_werror.patch20
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/hppa_backend.diff831
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/hurd_path.patch17
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/ignore_strmerge.diff14
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/kfreebsd_path.patch20
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/mips_backend.diff717
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/mips_cfi.patch131
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/mips_readelf_w.patch31
-rw-r--r--meta/recipes-devtools/elfutils/files/debian/testsuite-ignore-elflint.diff52
-rw-r--r--meta/recipes-devtools/elfutils/files/musl-libs.patch144
-rw-r--r--meta/recipes-devtools/elfutils/files/musl-obstack-fts.patch128
-rw-r--r--meta/recipes-devtools/elfutils/files/musl-tests.patch29
-rw-r--r--meta/recipes-devtools/elfutils/files/musl-utils.patch165
-rw-r--r--meta/recipes-devtools/elfutils/files/ptest.patch76
-rw-r--r--meta/recipes-devtools/elfutils/files/run-ptest6
30 files changed, 3943 insertions, 0 deletions
diff --git a/meta/recipes-devtools/elfutils/files/0001-dso-link-change.patch b/meta/recipes-devtools/elfutils/files/0001-dso-link-change.patch
new file mode 100644
index 0000000000..af79ef496d
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0001-dso-link-change.patch
@@ -0,0 +1,50 @@
+From b99aa12cf879ce200e03d75e543c7ab2dfa5503b Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Tue, 15 Aug 2017 17:10:57 +0800
+Subject: [PATCH] dso link change
+
+Upstream-Status: Pending
+
+This patch makes the link to the dependencies of libdw explicit, as
+recent ld no longer implicitly links them. See
+http://lists.fedoraproject.org/pipermail/devel/2010-March/133601.html
+as a similar example of the error message you can encounter without this
+patch, and https://fedoraproject.org/wiki/UnderstandingDSOLinkChange and
+https://fedoraproject.org/wiki/Features/ChangeInImplicitDSOLinking for
+more details.
+
+Rebase to 0.170
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ src/Makefile.am | 2 +-
+ tests/Makefile.am | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 2b1c0dc..9305b84 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -44,7 +44,7 @@ libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.a -lz
+ else
+ libasm = ../libasm/libasm.so
+-libdw = ../libdw/libdw.so
++libdw = ../libdw/libdw.so $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.so
+ endif
+ libebl = ../libebl/libebl.a
+diff --git a/tests/Makefile.am b/tests/Makefile.am
+index 1b0c7d3..bced19b 100644
+--- a/tests/Makefile.am
++++ b/tests/Makefile.am
+@@ -476,7 +476,7 @@ libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.a -lz
+ libasm = ../libasm/libasm.a
+ else
+-libdw = ../libdw/libdw.so
++libdw = ../libdw/libdw.so $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.so
+ libasm = ../libasm/libasm.so
+ endif
diff --git a/meta/recipes-devtools/elfutils/files/0001-libasm-may-link-with-libbz2-if-found.patch b/meta/recipes-devtools/elfutils/files/0001-libasm-may-link-with-libbz2-if-found.patch
new file mode 100644
index 0000000000..0d533c8f10
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0001-libasm-may-link-with-libbz2-if-found.patch
@@ -0,0 +1,36 @@
+From d7be687c35fa42954874034c82ca9059d28196fe Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Wed, 4 Oct 2017 22:30:46 -0700
+Subject: [PATCH] libasm may link with libbz2 if found
+
+This can fail to link binaries like objdump
+where indirect libraries may be not found by linker
+
+| /mnt/a/oe/build/tmp/work/riscv64-bec-linux/elfutils/0.170-r0/recipe-sysroot/usr/lib/libbz2.so.1: error adding symbols: DSO missing from command line
+| collect2: error: ld returned 1 exit status
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+
+---
+ src/Makefile.am | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/src/Makefile.am b/src/Makefile.am
+index 9305b84..9b7e853 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -39,11 +39,11 @@ EXTRA_DIST += make-debug-archive.in
+ CLEANFILES += make-debug-archive
+
+ if BUILD_STATIC
+-libasm = ../libasm/libasm.a
++libasm = ../libasm/libasm.a $(zip_LIBS)
+ libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.a -lz
+ else
+-libasm = ../libasm/libasm.so
++libasm = ../libasm/libasm.so $(zip_LIBS)
+ libdw = ../libdw/libdw.so $(zip_LIBS) $(libelf) $(libebl) -ldl
+ libelf = ../libelf/libelf.so
+ endif
diff --git a/meta/recipes-devtools/elfutils/files/0001-libelf-elf_end.c-check-data_list.data.d.d_buf-before.patch b/meta/recipes-devtools/elfutils/files/0001-libelf-elf_end.c-check-data_list.data.d.d_buf-before.patch
new file mode 100644
index 0000000000..b26ed99f65
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0001-libelf-elf_end.c-check-data_list.data.d.d_buf-before.patch
@@ -0,0 +1,44 @@
+From e571cbd0c20085ec71969971f19280b5de95cfb7 Mon Sep 17 00:00:00 2001
+From: Robert Yang <liezhi.yang@windriver.com>
+Date: Thu, 16 Aug 2018 09:58:26 +0800
+Subject: [PATCH] libelf/elf_end.c: check data_list.data.d.d_buf before free it
+
+The one which actually saves the data is data_list.data.d.d_buf, so check it
+before free rawdata_base.
+
+This can fix a segmentation fault when prelink libqb_1.0.3:
+prelink: /usr/lib/libqb.so.0.18.2: Symbol section index outside of section numbers
+
+The segmentation fault happens when prelink call elf_end().
+
+Upstream-Status: Submitted [https://sourceware.org/ml/elfutils-devel/2018-q3/msg00085.html]
+
+Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
+
+---
+ libelf/elf_end.c | 6 ++++--
+ 1 file changed, 4 insertions(+), 2 deletions(-)
+
+diff --git a/libelf/elf_end.c b/libelf/elf_end.c
+index 160f0b8..5280a70 100644
+--- a/libelf/elf_end.c
++++ b/libelf/elf_end.c
+@@ -160,14 +160,16 @@ elf_end (Elf *elf)
+ architecture doesn't require overly stringent
+ alignment the raw data buffer is the same as the
+ one used for presenting to the caller. */
+- if (scn->data_base != scn->rawdata_base)
++ if ((scn->data_base != scn->rawdata_base)
++ && (scn->data_list.data.d.d_buf != NULL))
+ free (scn->data_base);
+
+ /* The section data is allocated if we couldn't mmap
+ the file. Or if we had to decompress. */
+- if (elf->map_address == NULL
++ if ((elf->map_address == NULL
+ || scn->rawdata_base == scn->zdata_base
+ || (scn->flags & ELF_F_MALLOCED) != 0)
++ && (scn->data_list.data.d.d_buf != NULL))
+ free (scn->rawdata_base);
+
+ /* Free the list of data buffers for the section.
diff --git a/meta/recipes-devtools/elfutils/files/0001-ppc_initreg.c-Incliude-asm-ptrace.h-for-pt_regs-defi.patch b/meta/recipes-devtools/elfutils/files/0001-ppc_initreg.c-Incliude-asm-ptrace.h-for-pt_regs-defi.patch
new file mode 100644
index 0000000000..3303333c45
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0001-ppc_initreg.c-Incliude-asm-ptrace.h-for-pt_regs-defi.patch
@@ -0,0 +1,32 @@
+From 2e2232d0935bf8ef6e66ebffba3be68a73b5b3e5 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 8 Sep 2019 15:57:59 -0700
+Subject: [PATCH] ppc_initreg.c: Incliude asm/ptrace.h for pt_regs definition
+
+Fixes
+| ../../elfutils-0.176/backends/ppc_initreg.c:79:22: error: field 'r' has incomplete type
+| struct pt_regs r;
+| ^
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ backends/ppc_initreg.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/backends/ppc_initreg.c b/backends/ppc_initreg.c
+index 0e0d359..e5cca7e 100644
+--- a/backends/ppc_initreg.c
++++ b/backends/ppc_initreg.c
+@@ -33,6 +33,7 @@
+ #include <stdlib.h>
+ #if defined(__powerpc__) && defined(__linux__)
+ # include <sys/ptrace.h>
++# include <asm/ptrace.h>
+ # include <sys/user.h>
+ #endif
+
+--
+2.23.0
+
diff --git a/meta/recipes-devtools/elfutils/files/0001-skip-the-test-when-gcc-not-deployed.patch b/meta/recipes-devtools/elfutils/files/0001-skip-the-test-when-gcc-not-deployed.patch
new file mode 100644
index 0000000000..de8c05f11e
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0001-skip-the-test-when-gcc-not-deployed.patch
@@ -0,0 +1,73 @@
+From e82a055f85e398cb03a4eaf5faf351a3a1f19344 Mon Sep 17 00:00:00 2001
+From: Mingli Yu <Mingli.Yu@windriver.com>
+Date: Tue, 21 May 2019 15:20:34 +0800
+Subject: [PATCH v2] skip the test when gcc not deployed
+
+Skip the tests which depend on gcc when
+gcc not deployed.
+
+Upstream-Status: Submitted[https://sourceware.org/ml/elfutils-devel/2019-q2/msg00091.html]
+
+Signed-off-by: Mingli Yu <Mingli.Yu@windriver.com>
+---
+ tests/run-disasm-x86-64.sh | 2 ++
+ tests/run-disasm-x86.sh | 2 ++
+ tests/run-strip-g.sh | 2 ++
+ tests/run-strip-nothing.sh | 2 ++
+ 4 files changed, 8 insertions(+)
+
+diff --git a/tests/run-disasm-x86-64.sh b/tests/run-disasm-x86-64.sh
+index a6be62b..c3ef238 100755
+--- a/tests/run-disasm-x86-64.sh
++++ b/tests/run-disasm-x86-64.sh
+@@ -22,6 +22,8 @@ case "`uname -m`" in
+ x86_64)
+ tempfiles testfile45.o
+ testfiles testfile45.S testfile45.expect
++ # skip the case if no gcc deployed
++ which gcc || exit 77
+ gcc -m64 -c -o testfile45.o testfile45.S
+ testrun_compare ${abs_top_builddir}/src/objdump -d testfile45.o < testfile45.expect
+ ;;
+diff --git a/tests/run-disasm-x86.sh b/tests/run-disasm-x86.sh
+index 28a3df7..544fc28 100755
+--- a/tests/run-disasm-x86.sh
++++ b/tests/run-disasm-x86.sh
+@@ -22,6 +22,8 @@ case "`uname -m`" in
+ x86_64 | i?86 )
+ tempfiles testfile44.o
+ testfiles testfile44.S testfile44.expect
++ # skip the case if no gcc deployed
++ which gcc || exit 77
+ gcc -m32 -c -o testfile44.o testfile44.S
+ testrun_compare ${abs_top_builddir}/src/objdump -d testfile44.o < testfile44.expect
+ ;;
+diff --git a/tests/run-strip-g.sh b/tests/run-strip-g.sh
+index 1303819..a943dec 100755
+--- a/tests/run-strip-g.sh
++++ b/tests/run-strip-g.sh
+@@ -24,6 +24,8 @@
+
+ tempfiles a.out strip.out debug.out readelf.out
+
++# skip the test if gcc deployed
++which gcc || exit 77
+ echo Create debug a.out.
+ echo "int main() { return 1; }" | gcc -g -xc -
+
+diff --git a/tests/run-strip-nothing.sh b/tests/run-strip-nothing.sh
+index 914fdfb..d03f734 100755
+--- a/tests/run-strip-nothing.sh
++++ b/tests/run-strip-nothing.sh
+@@ -22,6 +22,8 @@
+
+ tempfiles a.out strip.out debug.out
+
++# skip the case if no gcc deployed
++which gcc || exit 77
+ # Create no-debug a.out.
+ echo "int main() { return 1; }" | gcc -s -xc -
+
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/0002-Fix-elf_cvt_gunhash-if-dest-and-src-are-same.patch b/meta/recipes-devtools/elfutils/files/0002-Fix-elf_cvt_gunhash-if-dest-and-src-are-same.patch
new file mode 100644
index 0000000000..96c2565e3e
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0002-Fix-elf_cvt_gunhash-if-dest-and-src-are-same.patch
@@ -0,0 +1,40 @@
+From f8e4118b60a9b54950437006a82b4047f38f5347 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Tue, 15 Aug 2017 17:13:59 +0800
+Subject: [PATCH] Fix elf_cvt_gunhash if dest and src are same.
+
+Upstream-Status: Pending
+
+The 'dest' and 'src' can be same, we need to save the value of src32[2]
+before swaping it.
+
+Signed-off-by: Baoshan Pang <BaoShan.Pang@windriver.com>
+
+Rebase to 0.170
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ libelf/gnuhash_xlate.h | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/libelf/gnuhash_xlate.h b/libelf/gnuhash_xlate.h
+index 6faf113..04d9ca1 100644
+--- a/libelf/gnuhash_xlate.h
++++ b/libelf/gnuhash_xlate.h
+@@ -40,6 +40,7 @@ elf_cvt_gnuhash (void *dest, const void *src, size_t len, int encode)
+ words. We must detangle them here. */
+ Elf32_Word *dest32 = dest;
+ const Elf32_Word *src32 = src;
++ Elf32_Word save_src32_2 = src32[2]; // dest could be equal to src
+
+ /* First four control words, 32 bits. */
+ for (unsigned int cnt = 0; cnt < 4; ++cnt)
+@@ -50,7 +51,7 @@ elf_cvt_gnuhash (void *dest, const void *src, size_t len, int encode)
+ len -= 4;
+ }
+
+- Elf32_Word bitmask_words = encode ? src32[2] : dest32[2];
++ Elf32_Word bitmask_words = encode ? save_src32_2 : dest32[2];
+
+ /* Now the 64 bit words. */
+ Elf64_Xword *dest64 = (Elf64_Xword *) &dest32[4];
diff --git a/meta/recipes-devtools/elfutils/files/0003-fixheadercheck.patch b/meta/recipes-devtools/elfutils/files/0003-fixheadercheck.patch
new file mode 100644
index 0000000000..e36d3f44dd
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0003-fixheadercheck.patch
@@ -0,0 +1,38 @@
+From dd7c8c730457def5f62ebd43022b2f06df8c6ed9 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Tue, 15 Aug 2017 17:17:20 +0800
+Subject: [PATCH] fixheadercheck
+
+For some binaries we can get a invalid section alignment, for example if
+sh_align = 1 and sh_addralign is 0. In the case of a zero size section
+like
+".note.GNU-stack", this is irrelavent as far as I can tell and we
+shouldn't
+error in this case.
+
+RP 2014/6/11
+
+Upstream-Status: Pending
+
+Rebase to 0.170
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ libelf/elf32_updatenull.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/libelf/elf32_updatenull.c b/libelf/elf32_updatenull.c
+index 3e9ef61..5351518 100644
+--- a/libelf/elf32_updatenull.c
++++ b/libelf/elf32_updatenull.c
+@@ -339,8 +339,8 @@ __elfw2(LIBELFBITS,updatenull_wrlock) (Elf *elf, int *change_bop, size_t shnum)
+ we test for the alignment of the section being large
+ enough for the largest alignment required by a data
+ block. */
+- if (unlikely (! powerof2 (shdr->sh_addralign))
+- || unlikely ((shdr->sh_addralign ?: 1) < sh_align))
++ if (shdr->sh_size && (unlikely (! powerof2 (shdr->sh_addralign))
++ || unlikely ((shdr->sh_addralign ?: 1) < sh_align)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ALIGN);
+ return -1;
diff --git a/meta/recipes-devtools/elfutils/files/0004-Disable-the-test-to-convert-euc-jp.patch b/meta/recipes-devtools/elfutils/files/0004-Disable-the-test-to-convert-euc-jp.patch
new file mode 100644
index 0000000000..5dee61210a
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0004-Disable-the-test-to-convert-euc-jp.patch
@@ -0,0 +1,42 @@
+From e4ede22e28eaa38d81667ddcb19541ece1a83cf8 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Tue, 15 Aug 2017 17:24:06 +0800
+Subject: [PATCH] Disable the test to convert euc-jp
+
+Remove the test "Test against HP-UX 11.11 bug:
+No converter from EUC-JP to UTF-8 is provided"
+since we don't support HP-UX and if the euc-jp is not
+installed on the host, the dependence will be built without
+iconv support and will cause guild-native building fail.
+
+Upstream-Status: Inappropriate [OE specific]
+
+Signed-off-by: Roy Li <rongqing.li@windriver.com>
+
+Rebase to 0.170
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ m4/iconv.m4 | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/m4/iconv.m4 b/m4/iconv.m4
+index a503646..299f1eb 100644
+--- a/m4/iconv.m4
++++ b/m4/iconv.m4
+@@ -159,6 +159,7 @@ int main ()
+ }
+ }
+ #endif
++#if 0
+ /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
+ provided. */
+ if (/* Try standardized names. */
+@@ -170,6 +171,7 @@ int main ()
+ /* Try HP-UX names. */
+ && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
+ result |= 16;
++#endif
+ return result;
+ }]])],
+ [am_cv_func_iconv_works=yes],
diff --git a/meta/recipes-devtools/elfutils/files/0006-Fix-build-on-aarch64-musl.patch b/meta/recipes-devtools/elfutils/files/0006-Fix-build-on-aarch64-musl.patch
new file mode 100644
index 0000000000..6f7956c5ae
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0006-Fix-build-on-aarch64-musl.patch
@@ -0,0 +1,59 @@
+From 578f370c7e7a9f056aefa062b34590b0aa13bce5 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Tue, 15 Aug 2017 17:27:30 +0800
+Subject: [PATCH] Fix build on aarch64/musl
+
+Errors
+
+invalid operands to binary & (have 'long double' and 'unsigned int')
+
+error: redefinition
+ of 'struct iovec'
+ struct iovec { void *iov_base; size_t iov_len; };
+ ^
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+
+Rebase to 0.170
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ backends/aarch64_initreg.c | 4 ++--
+ backends/arm_initreg.c | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/backends/aarch64_initreg.c b/backends/aarch64_initreg.c
+index daf6f37..6445276 100644
+--- a/backends/aarch64_initreg.c
++++ b/backends/aarch64_initreg.c
+@@ -33,7 +33,7 @@
+ #include "system.h"
+ #include <assert.h>
+ #if defined(__aarch64__) && defined(__linux__)
+-# include <linux/uio.h>
++# include <sys/uio.h>
+ # include <sys/user.h>
+ # include <sys/ptrace.h>
+ /* Deal with old glibc defining user_pt_regs instead of user_regs_struct. */
+@@ -82,7 +82,7 @@ aarch64_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
+
+ Dwarf_Word dwarf_fregs[32];
+ for (int r = 0; r < 32; r++)
+- dwarf_fregs[r] = fregs.vregs[r] & 0xFFFFFFFF;
++ dwarf_fregs[r] = (unsigned int)fregs.vregs[r] & 0xFFFFFFFF;
+
+ if (! setfunc (64, 32, dwarf_fregs, arg))
+ return false;
+diff --git a/backends/arm_initreg.c b/backends/arm_initreg.c
+index efcabaf..062bb9e 100644
+--- a/backends/arm_initreg.c
++++ b/backends/arm_initreg.c
+@@ -38,7 +38,7 @@
+ #endif
+
+ #ifdef __aarch64__
+-# include <linux/uio.h>
++# include <sys/uio.h>
+ # include <sys/user.h>
+ # include <sys/ptrace.h>
+ /* Deal with old glibc defining user_pt_regs instead of user_regs_struct. */
diff --git a/meta/recipes-devtools/elfutils/files/0007-Fix-control-path-where-we-have-str-as-uninitialized-.patch b/meta/recipes-devtools/elfutils/files/0007-Fix-control-path-where-we-have-str-as-uninitialized-.patch
new file mode 100644
index 0000000000..611a24c0f5
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/0007-Fix-control-path-where-we-have-str-as-uninitialized-.patch
@@ -0,0 +1,42 @@
+From 112d1645bab7922c7796fe32ddea8fa6e1bbded1 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 29 Jun 2018 15:14:28 +0800
+Subject: [PATCH] Fix control path where we have str as uninitialized string
+
+|
+/home/ubuntu/work/oe/openembedded-core/build/tmp-musl/work/i586-oe-linux-musl/elfutils/0.164-r0/elfutils-0.164/libcpu/i386_disasm.c:
+In function 'i386_disasm':
+|
+/home/ubuntu/work/oe/openembedded-core/build/tmp-musl/work/i586-oe-linux-musl/elfutils/0.164-r0/elfutils-0.164/libcpu/i386_disasm.c:310:5:
+error: 'str' may be used uninitialized in this function
+[-Werror=maybe-uninitialized]
+| memcpy (buf + bufcnt, _str, _len); \
+| ^
+|
+/home/ubuntu/work/oe/openembedded-core/build/tmp-musl/work/i586-oe-linux-musl/elfutils/0.164-r0/elfutils-0.164/libcpu/i386_disasm.c:709:17:
+note: 'str' was declared here
+| const char *str;
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Upstream-Status: Pending
+
+Rebase to 0.172
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+---
+ libcpu/i386_disasm.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/libcpu/i386_disasm.c b/libcpu/i386_disasm.c
+index a7e03f9..837a3a8 100644
+--- a/libcpu/i386_disasm.c
++++ b/libcpu/i386_disasm.c
+@@ -821,6 +821,7 @@ i386_disasm (Ebl *ebl __attribute__((unused)),
+ }
+ FALLTHROUGH;
+ default:
++ str = "";
+ assert (! "INVALID not handled");
+ }
+ }
diff --git a/meta/recipes-devtools/elfutils/files/debian/0001-Ignore-differences-between-mips-machine-identifiers.patch b/meta/recipes-devtools/elfutils/files/debian/0001-Ignore-differences-between-mips-machine-identifiers.patch
new file mode 100644
index 0000000000..a2983c5770
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/0001-Ignore-differences-between-mips-machine-identifiers.patch
@@ -0,0 +1,34 @@
+From 77cb4a53c270d5854d3af24f19547bc3de825233 Mon Sep 17 00:00:00 2001
+From: James Cowgill <james410@cowgill.org.uk>
+Date: Mon, 5 Jan 2015 15:16:58 +0000
+Subject: [PATCH 1/3] Ignore differences between mips machine identifiers
+
+Little endian binaries actually use EM_MIPS so you can't tell the endianness
+from the elf machine id. Also, the EM_MIPS_RS3_LE machine is dead anyway (the
+kernel will not load binaries containing it).
+
+Signed-off-by: James Cowgill <james410@cowgill.org.uk>
+
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/mips_init.c | 6 +-----
+ 1 file changed, 1 insertion(+), 5 deletions(-)
+
+Index: b/backends/mips_init.c
+===================================================================
+--- a/backends/mips_init.c
++++ b/backends/mips_init.c
+@@ -45,11 +45,7 @@ mips_init (Elf *elf __attribute__ ((unus
+ return NULL;
+
+ /* We handle it. */
+- if (machine == EM_MIPS)
+- eh->name = "MIPS R3000 big-endian";
+- else if (machine == EM_MIPS_RS3_LE)
+- eh->name = "MIPS R3000 little-endian";
+-
++ eh->name = "MIPS";
+ mips_init_reloc (eh);
+ HOOK (eh, reloc_simple_type);
+ HOOK (eh, return_value_location);
diff --git a/meta/recipes-devtools/elfutils/files/debian/0001-fix-compile-failure-with-debian-patches.patch b/meta/recipes-devtools/elfutils/files/debian/0001-fix-compile-failure-with-debian-patches.patch
new file mode 100644
index 0000000000..19a2015062
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/0001-fix-compile-failure-with-debian-patches.patch
@@ -0,0 +1,48 @@
+From 3f3e7b16934ec58ab47d2bdc9982f54a55b07534 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 16:25:33 +0800
+Subject: [PATCH] fix compile failure with debian patches
+
+While applying debian patches, there is a compile failure
+...
+elfutils-0.177/backends/mips_init.c:48:5: error: 'Ebl' {aka 'struct ebl'} has no member named 'name'
+...
+
+Since upstream applied commit [b323391 libdwelf: Add dwelf_elf_e_machine_string
+and use it in readelf], it remove 'name' from 'struct ebl'
+
+Upstream-Status: Pending
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/mips_init.c | 1 -
+ backends/parisc_init.c | 1 -
+ 2 files changed, 2 deletions(-)
+
+diff --git a/backends/mips_init.c b/backends/mips_init.c
+index bce5abe..e1c65c8 100644
+--- a/backends/mips_init.c
++++ b/backends/mips_init.c
+@@ -45,7 +45,6 @@ mips_init (Elf *elf __attribute__ ((unused)),
+ return NULL;
+
+ /* We handle it. */
+- eh->name = "MIPS";
+ mips_init_reloc (eh);
+ HOOK (eh, reloc_simple_type);
+ HOOK (eh, return_value_location);
+diff --git a/backends/parisc_init.c b/backends/parisc_init.c
+index f1e401c..97b4a8c 100644
+--- a/backends/parisc_init.c
++++ b/backends/parisc_init.c
+@@ -56,7 +56,6 @@ parisc_init (Elf *elf __attribute__ ((unused)),
+ pa64 = 1;
+ }
+ /* We handle it. */
+- eh->name = "PA-RISC";
+ parisc_init_reloc (eh);
+ HOOK (eh, reloc_simple_type);
+ HOOK (eh, machine_flag_check);
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/0002-Add-support-for-mips64-abis-in-mips_retval.c.patch b/meta/recipes-devtools/elfutils/files/debian/0002-Add-support-for-mips64-abis-in-mips_retval.c.patch
new file mode 100644
index 0000000000..aee00cba14
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/0002-Add-support-for-mips64-abis-in-mips_retval.c.patch
@@ -0,0 +1,171 @@
+From fdaab18a65ed2529656baa64cb6169f34d7e507b Mon Sep 17 00:00:00 2001
+From: James Cowgill <james410@cowgill.org.uk>
+Date: Mon, 5 Jan 2015 15:17:01 +0000
+Subject: [PATCH 2/3] Add support for mips64 abis in mips_retval.c
+
+Signed-off-by: James Cowgill <james410@cowgill.org.uk>
+
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/mips_retval.c | 104 ++++++++++++++++++++++++++++++++++++++++++++-----
+ 1 file changed, 94 insertions(+), 10 deletions(-)
+
+diff --git a/backends/mips_retval.c b/backends/mips_retval.c
+index 33f12a7..d5c6ef0 100644
+--- a/backends/mips_retval.c
++++ b/backends/mips_retval.c
+@@ -91,6 +91,8 @@ enum mips_abi find_mips_abi(Elf *elf)
+ default:
+ if ((elf_flags & EF_MIPS_ABI2))
+ return MIPS_ABI_N32;
++ else if ((ehdr->e_ident[EI_CLASS] == ELFCLASS64))
++ return MIPS_ABI_N64;
+ }
+
+ /* GCC creates a pseudo-section whose name describes the ABI. */
+@@ -195,6 +197,57 @@ static const Dwarf_Op loc_aggregate[] =
+ };
+ #define nloc_aggregate 1
+
++/* Test if a struct member is a float */
++static int is_float_child(Dwarf_Die *childdie)
++{
++ /* Test if this is actually a struct member */
++ if (dwarf_tag(childdie) != DW_TAG_member)
++ return 0;
++
++ /* Get type of member */
++ Dwarf_Attribute attr_mem;
++ Dwarf_Die child_type_mem;
++ Dwarf_Die *child_typedie =
++ dwarf_formref_die(dwarf_attr_integrate(childdie,
++ DW_AT_type,
++ &attr_mem), &child_type_mem);
++
++ if (dwarf_tag(child_typedie) != DW_TAG_base_type)
++ return 0;
++
++ /* Get base subtype */
++ Dwarf_Word encoding;
++ if (dwarf_formudata (dwarf_attr_integrate (child_typedie,
++ DW_AT_encoding,
++ &attr_mem), &encoding) != 0)
++ return 0;
++
++ return encoding == DW_ATE_float;
++}
++
++/* Returns the number of fpregs which can be returned in the given struct */
++static int get_struct_fpregs(Dwarf_Die *structtypedie)
++{
++ Dwarf_Die child_mem;
++ int fpregs = 0;
++
++ /* Get first structure member */
++ if (dwarf_child(structtypedie, &child_mem) != 0)
++ return 0;
++
++ do
++ {
++ /* Ensure this register is a float */
++ if (!is_float_child(&child_mem))
++ return 0;
++
++ fpregs++;
++ }
++ while (dwarf_siblingof (&child_mem, &child_mem) == 0);
++
++ return fpregs;
++}
++
+ int
+ mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ {
+@@ -240,6 +293,7 @@ mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ tag = dwarf_tag (typedie);
+ }
+
++ Dwarf_Word size;
+ switch (tag)
+ {
+ case -1:
+@@ -258,8 +312,6 @@ mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ case DW_TAG_enumeration_type:
+ case DW_TAG_pointer_type:
+ case DW_TAG_ptr_to_member_type:
+- {
+- Dwarf_Word size;
+ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
+ &attr_mem), &size) != 0)
+ {
+@@ -289,7 +341,7 @@ mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ if (size <= 4*regsize && abi == MIPS_ABI_O32)
+ return nloc_fpregquad;
+
+- goto aggregate;
++ goto large;
+ }
+ }
+ *locp = ABI_LOC(loc_intreg, regsize);
+@@ -298,18 +350,50 @@ mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ if (size <= 2*regsize)
+ return nloc_intregpair;
+
+- /* Else fall through. Shouldn't happen though (at least with gcc) */
+- }
++ /* Else pass in memory. Shouldn't happen though (at least with gcc) */
++ goto large;
+
+ case DW_TAG_structure_type:
+ case DW_TAG_class_type:
+ case DW_TAG_union_type:
+- case DW_TAG_array_type:
+- aggregate:
+- /* XXX TODO: Can't handle structure return with other ABI's yet :-/ */
+- if ((abi != MIPS_ABI_O32) && (abi != MIPS_ABI_O64))
+- return -2;
++ /* Handle special cases for structures <= 128 bytes in newer ABIs */
++ if (abi == MIPS_ABI_EABI32 || abi == MIPS_ABI_EABI64 ||
++ abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
++ {
++ if (dwarf_aggregate_size (typedie, &size) == 0 && size <= 16)
++ {
++ /*
++ * Special case in N64 / N32 -
++ * structures containing only floats are returned in fp regs.
++ * Everything else is returned in integer regs.
++ */
++ if (tag != DW_TAG_union_type &&
++ (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64))
++ {
++ int num_fpregs = get_struct_fpregs(typedie);
++ if (num_fpregs == 1 || num_fpregs == 2)
++ {
++ *locp = loc_fpreg;
++ if (num_fpregs == 1)
++ return nloc_fpreg;
++ else
++ return nloc_fpregpair;
++ }
++ }
++
++ *locp = loc_intreg;
++ if (size <= 8)
++ return nloc_intreg;
++ else
++ return nloc_intregpair;
++ }
++ }
++
++ /* Fallthrough to handle large types */
+
++ case DW_TAG_array_type:
++ large:
++ /* Return large structures in memory */
+ *locp = loc_aggregate;
+ return nloc_aggregate;
+ }
+--
+2.1.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/0003-Add-mips-n64-relocation-format-hack.patch b/meta/recipes-devtools/elfutils/files/debian/0003-Add-mips-n64-relocation-format-hack.patch
new file mode 100644
index 0000000000..c949e96533
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/0003-Add-mips-n64-relocation-format-hack.patch
@@ -0,0 +1,229 @@
+From 59d4b8c48e5040af7e02b34eb26ea602ec82a38e Mon Sep 17 00:00:00 2001
+From: James Cowgill <james410@cowgill.org.uk>
+Date: Mon, 5 Jan 2015 15:17:02 +0000
+Subject: [PATCH 3/3] Add mips n64 relocation format hack
+
+MIPSEL N64 ELF files use a slightly different format for storing relocation
+entries which is incompatible with the normal R_SYM / R_INFO macros.
+To workaround this, we rearrange the bytes in the relocation's r_info field
+when reading and writing the relocations.
+
+This patch also ensures that strip.c sets the correct value of e_machine
+before manipulating relocations so that these changes take effect.
+
+Signed-off-by: James Cowgill <james410@cowgill.org.uk>
+
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ libelf/gelf_getrel.c | 25 +++++++++++++++++++++++--
+ libelf/gelf_getrela.c | 25 +++++++++++++++++++++++--
+ libelf/gelf_update_rel.c | 20 +++++++++++++++++++-
+ libelf/gelf_update_rela.c | 20 +++++++++++++++++++-
+ src/strip.c | 17 +++++++++++++++++
+ 5 files changed, 101 insertions(+), 6 deletions(-)
+
+Index: elfutils-0.175/libelf/gelf_getrel.c
+===================================================================
+--- elfutils-0.175.orig/libelf/gelf_getrel.c
++++ elfutils-0.175/libelf/gelf_getrel.c
+@@ -36,6 +36,7 @@
+
+ #include "libelfP.h"
+
++#define EF_MIPS_ABI 0x0000F000
+
+ GElf_Rel *
+ gelf_getrel (Elf_Data *data, int ndx, GElf_Rel *dst)
+@@ -89,8 +90,28 @@ gelf_getrel (Elf_Data *data, int ndx, GE
+ result = NULL;
+ }
+ else
+- result = memcpy (dst, &((Elf64_Rel *) data_scn->d.d_buf)[ndx],
+- sizeof (Elf64_Rel));
++ {
++ GElf_Ehdr hdr;
++ result = memcpy (dst, &((Elf64_Rel *) data_scn->d.d_buf)[ndx],
++ sizeof (Elf64_Rel));
++
++ if (gelf_getehdr(scn->elf, &hdr) != NULL &&
++ hdr.e_ident[EI_DATA] == ELFDATA2LSB &&
++ hdr.e_machine == EM_MIPS &&
++ (hdr.e_flags & EF_MIPS_ABI) == 0)
++ {
++ /*
++ * The relocation format is mangled on MIPSEL N64
++ * We'll adjust it so at least R_SYM will work on it
++ */
++ GElf_Xword r_info = dst->r_info;
++ dst->r_info = (r_info << 32) |
++ ((r_info >> 8) & 0xFF000000) |
++ ((r_info >> 24) & 0x00FF0000) |
++ ((r_info >> 40) & 0x0000FF00) |
++ ((r_info >> 56) & 0x000000FF);
++ }
++ }
+ }
+
+ rwlock_unlock (scn->elf->lock);
+Index: elfutils-0.175/libelf/gelf_getrela.c
+===================================================================
+--- elfutils-0.175.orig/libelf/gelf_getrela.c
++++ elfutils-0.175/libelf/gelf_getrela.c
+@@ -36,6 +36,7 @@
+
+ #include "libelfP.h"
+
++#define EF_MIPS_ABI 0x0000F000
+
+ GElf_Rela *
+ gelf_getrela (Elf_Data *data, int ndx, GElf_Rela *dst)
+@@ -90,8 +91,28 @@ gelf_getrela (Elf_Data *data, int ndx, G
+ result = NULL;
+ }
+ else
+- result = memcpy (dst, &((Elf64_Rela *) data_scn->d.d_buf)[ndx],
+- sizeof (Elf64_Rela));
++ {
++ GElf_Ehdr hdr;
++ result = memcpy (dst, &((Elf64_Rela *) data_scn->d.d_buf)[ndx],
++ sizeof (Elf64_Rela));
++
++ if (gelf_getehdr(scn->elf, &hdr) != NULL &&
++ hdr.e_ident[EI_DATA] == ELFDATA2LSB &&
++ hdr.e_machine == EM_MIPS &&
++ (hdr.e_flags & EF_MIPS_ABI) == 0)
++ {
++ /*
++ * The relocation format is mangled on MIPSEL N64
++ * We'll adjust it so at least R_SYM will work on it
++ */
++ GElf_Xword r_info = dst->r_info;
++ dst->r_info = (r_info << 32) |
++ ((r_info >> 8) & 0xFF000000) |
++ ((r_info >> 24) & 0x00FF0000) |
++ ((r_info >> 40) & 0x0000FF00) |
++ ((r_info >> 56) & 0x000000FF);
++ }
++ }
+ }
+
+ rwlock_unlock (scn->elf->lock);
+Index: elfutils-0.175/libelf/gelf_update_rel.c
+===================================================================
+--- elfutils-0.175.orig/libelf/gelf_update_rel.c
++++ elfutils-0.175/libelf/gelf_update_rel.c
+@@ -36,6 +36,7 @@
+
+ #include "libelfP.h"
+
++#define EF_MIPS_ABI 0x0000F000
+
+ int
+ gelf_update_rel (Elf_Data *dst, int ndx, GElf_Rel *src)
+@@ -86,6 +87,9 @@ gelf_update_rel (Elf_Data *dst, int ndx,
+ }
+ else
+ {
++ GElf_Ehdr hdr;
++ GElf_Rel value = *src;
++
+ /* Check whether we have to resize the data buffer. */
+ if (INVALID_NDX (ndx, Elf64_Rel, &data_scn->d))
+ {
+@@ -93,7 +97,21 @@ gelf_update_rel (Elf_Data *dst, int ndx,
+ goto out;
+ }
+
+- ((Elf64_Rel *) data_scn->d.d_buf)[ndx] = *src;
++ if (gelf_getehdr(scn->elf, &hdr) != NULL &&
++ hdr.e_ident[EI_DATA] == ELFDATA2LSB &&
++ hdr.e_machine == EM_MIPS &&
++ (hdr.e_flags & EF_MIPS_ABI) == 0)
++ {
++ /* Undo the MIPSEL N64 hack from gelf_getrel */
++ GElf_Xword r_info = value.r_info;
++ value.r_info = (r_info >> 32) |
++ ((r_info << 8) & 0x000000FF00000000) |
++ ((r_info << 24) & 0x0000FF0000000000) |
++ ((r_info << 40) & 0x00FF000000000000) |
++ ((r_info << 56) & 0xFF00000000000000);
++ }
++
++ ((Elf64_Rel *) data_scn->d.d_buf)[ndx] = value;
+ }
+
+ result = 1;
+Index: elfutils-0.175/libelf/gelf_update_rela.c
+===================================================================
+--- elfutils-0.175.orig/libelf/gelf_update_rela.c
++++ elfutils-0.175/libelf/gelf_update_rela.c
+@@ -36,6 +36,7 @@
+
+ #include "libelfP.h"
+
++#define EF_MIPS_ABI 0x0000F000
+
+ int
+ gelf_update_rela (Elf_Data *dst, int ndx, GElf_Rela *src)
+@@ -89,6 +90,9 @@ gelf_update_rela (Elf_Data *dst, int ndx
+ }
+ else
+ {
++ GElf_Ehdr hdr;
++ GElf_Rela value = *src;
++
+ /* Check whether we have to resize the data buffer. */
+ if (INVALID_NDX (ndx, Elf64_Rela, &data_scn->d))
+ {
+@@ -96,7 +100,21 @@ gelf_update_rela (Elf_Data *dst, int ndx
+ goto out;
+ }
+
+- ((Elf64_Rela *) data_scn->d.d_buf)[ndx] = *src;
++ if (gelf_getehdr(scn->elf, &hdr) != NULL &&
++ hdr.e_ident[EI_DATA] == ELFDATA2LSB &&
++ hdr.e_machine == EM_MIPS &&
++ (hdr.e_flags & EF_MIPS_ABI) == 0)
++ {
++ /* Undo the MIPSEL N64 hack from gelf_getrel */
++ GElf_Xword r_info = value.r_info;
++ value.r_info = (r_info >> 32) |
++ ((r_info << 8) & 0x000000FF00000000) |
++ ((r_info << 24) & 0x0000FF0000000000) |
++ ((r_info << 40) & 0x00FF000000000000) |
++ ((r_info << 56) & 0xFF00000000000000);
++ }
++
++ ((Elf64_Rela *) data_scn->d.d_buf)[ndx] = value;
+ }
+
+ result = 1;
+Index: elfutils-0.175/src/strip.c
+===================================================================
+--- elfutils-0.175.orig/src/strip.c
++++ elfutils-0.175/src/strip.c
+@@ -1062,6 +1062,23 @@ handle_elf (int fd, Elf *elf, const char
+ goto fail;
+ }
+
++ /* Copy identity part of the ELF header now */
++ newehdr = gelf_getehdr (newelf, &newehdr_mem);
++ if (newehdr == NULL)
++ INTERNAL_ERROR (fname);
++
++ memcpy (newehdr->e_ident, ehdr->e_ident, EI_NIDENT);
++ newehdr->e_type = ehdr->e_type;
++ newehdr->e_machine = ehdr->e_machine;
++ newehdr->e_version = ehdr->e_version;
++
++ if (gelf_update_ehdr (newelf, newehdr) == 0)
++ {
++ error (0, 0, gettext ("%s: error while creating ELF header: %s"),
++ fname, elf_errmsg (-1));
++ return 1;
++ }
++
+ /* Copy over the old program header if needed. */
+ if (phnum > 0)
+ {
diff --git a/meta/recipes-devtools/elfutils/files/debian/arm_backend.diff b/meta/recipes-devtools/elfutils/files/debian/arm_backend.diff
new file mode 100644
index 0000000000..ba0ce33bd4
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/arm_backend.diff
@@ -0,0 +1,624 @@
+From 4e6fededb3d8c90694c44214c862ac216a69ecae Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 16:50:33 +0800
+Subject: [PATCH] arm_backend
+
+Upstream-Status: Pending [from debian]
+Rebase to 0.177
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/arm_init.c | 18 ++++-
+ backends/arm_regs.c | 132 ++++++++++++++++++++++++++++++++++++
+ backends/arm_retval.c | 43 +++++++++++-
+ backends/libebl_arm.h | 9 +++
+ libelf/elf.h | 11 +++
+ tests/run-addrcfi.sh | 93 ++++++++++++++++++++++++-
+ tests/run-allregs.sh | 95 +++++++++++++++++++++++++-
+ tests/run-readelf-mixed-corenote.sh | 11 ++-
+ 8 files changed, 400 insertions(+), 12 deletions(-)
+ create mode 100644 backends/libebl_arm.h
+
+diff --git a/backends/arm_init.c b/backends/arm_init.c
+index af023f0..ea2bcb7 100644
+--- a/backends/arm_init.c
++++ b/backends/arm_init.c
+@@ -35,20 +35,31 @@
+ #define RELOC_PREFIX R_ARM_
+ #include "libebl_CPU.h"
+
++#include "libebl_arm.h"
++
+ /* This defines the common reloc hooks based on arm_reloc.def. */
+ #include "common-reloc.c"
+
+
+ const char *
+-arm_init (Elf *elf __attribute__ ((unused)),
++arm_init (Elf *elf,
+ GElf_Half machine __attribute__ ((unused)),
+ Ebl *eh,
+ size_t ehlen)
+ {
++ int soft_float = 0;
++
+ /* Check whether the Elf_BH object has a sufficent size. */
+ if (ehlen < sizeof (Ebl))
+ return NULL;
+
++ if (elf) {
++ GElf_Ehdr ehdr_mem;
++ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
++ if (ehdr && (ehdr->e_flags & EF_ARM_SOFT_FLOAT))
++ soft_float = 1;
++ }
++
+ /* We handle it. */
+ arm_init_reloc (eh);
+ HOOK (eh, segment_type_name);
+@@ -59,7 +70,10 @@ arm_init (Elf *elf __attribute__ ((unused)),
+ HOOK (eh, core_note);
+ HOOK (eh, auxv_info);
+ HOOK (eh, check_object_attribute);
+- HOOK (eh, return_value_location);
++ if (soft_float)
++ eh->return_value_location = arm_return_value_location_soft;
++ else
++ eh->return_value_location = arm_return_value_location_hard;
+ HOOK (eh, abi_cfi);
+ HOOK (eh, check_reloc_target_type);
+ HOOK (eh, symbol_type_name);
+diff --git a/backends/arm_regs.c b/backends/arm_regs.c
+index a46a4c9..418c931 100644
+--- a/backends/arm_regs.c
++++ b/backends/arm_regs.c
+@@ -31,6 +31,7 @@
+ #endif
+
+ #include <string.h>
++#include <stdio.h>
+ #include <dwarf.h>
+
+ #define BACKEND arm_
+@@ -76,6 +77,9 @@ arm_register_info (Ebl *ebl __attribute__ ((unused)),
+ break;
+
+ case 16 + 0 ... 16 + 7:
++ /* AADWARF says that there are no registers in that range,
++ * but gcc maps FPA registers here
++ */
+ regno += 96 - 16;
+ FALLTHROUGH;
+ case 96 + 0 ... 96 + 7:
+@@ -87,11 +91,139 @@ arm_register_info (Ebl *ebl __attribute__ ((unused)),
+ namelen = 2;
+ break;
+
++ case 64 + 0 ... 64 + 9:
++ *setname = "VFP";
++ *bits = 32;
++ *type = DW_ATE_float;
++ name[0] = 's';
++ name[1] = regno - 64 + '0';
++ namelen = 2;
++ break;
++
++ case 64 + 10 ... 64 + 31:
++ *setname = "VFP";
++ *bits = 32;
++ *type = DW_ATE_float;
++ name[0] = 's';
++ name[1] = (regno - 64) / 10 + '0';
++ name[2] = (regno - 64) % 10 + '0';
++ namelen = 3;
++ break;
++
++ case 104 + 0 ... 104 + 7:
++ /* XXX TODO:
++ * This can be either intel wireless MMX general purpose/control
++ * registers or xscale accumulator, which have different usage.
++ * We only have the intel wireless MMX here now.
++ * The name needs to be changed for the xscale accumulator too. */
++ *setname = "MMX";
++ *type = DW_ATE_unsigned;
++ *bits = 32;
++ memcpy(name, "wcgr", 4);
++ name[4] = regno - 104 + '0';
++ namelen = 5;
++ break;
++
++ case 112 + 0 ... 112 + 9:
++ *setname = "MMX";
++ *type = DW_ATE_unsigned;
++ *bits = 64;
++ name[0] = 'w';
++ name[1] = 'r';
++ name[2] = regno - 112 + '0';
++ namelen = 3;
++ break;
++
++ case 112 + 10 ... 112 + 15:
++ *setname = "MMX";
++ *type = DW_ATE_unsigned;
++ *bits = 64;
++ name[0] = 'w';
++ name[1] = 'r';
++ name[2] = '1';
++ name[3] = regno - 112 - 10 + '0';
++ namelen = 4;
++ break;
++
+ case 128:
++ *setname = "state";
+ *type = DW_ATE_unsigned;
+ return stpcpy (name, "spsr") + 1 - name;
+
++ case 129:
++ *setname = "state";
++ *type = DW_ATE_unsigned;
++ return stpcpy(name, "spsr_fiq") + 1 - name;
++
++ case 130:
++ *setname = "state";
++ *type = DW_ATE_unsigned;
++ return stpcpy(name, "spsr_irq") + 1 - name;
++
++ case 131:
++ *setname = "state";
++ *type = DW_ATE_unsigned;
++ return stpcpy(name, "spsr_abt") + 1 - name;
++
++ case 132:
++ *setname = "state";
++ *type = DW_ATE_unsigned;
++ return stpcpy(name, "spsr_und") + 1 - name;
++
++ case 133:
++ *setname = "state";
++ *type = DW_ATE_unsigned;
++ return stpcpy(name, "spsr_svc") + 1 - name;
++
++ case 144 ... 150:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_usr", regno - 144 + 8) + 1;
++
++ case 151 ... 157:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_fiq", regno - 151 + 8) + 1;
++
++ case 158 ... 159:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_irq", regno - 158 + 13) + 1;
++
++ case 160 ... 161:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_abt", regno - 160 + 13) + 1;
++
++ case 162 ... 163:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_und", regno - 162 + 13) + 1;
++
++ case 164 ... 165:
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ return sprintf(name, "r%d_svc", regno - 164 + 13) + 1;
++
++ case 192 ... 199:
++ *setname = "MMX";
++ *bits = 32;
++ *type = DW_ATE_unsigned;
++ name[0] = 'w';
++ name[1] = 'c';
++ name[2] = regno - 192 + '0';
++ namelen = 3;
++ break;
++
+ case 256 + 0 ... 256 + 9:
++ /* XXX TODO: Neon also uses those registers and can contain
++ * both float and integers */
+ *setname = "VFP";
+ *type = DW_ATE_float;
+ *bits = 64;
+diff --git a/backends/arm_retval.c b/backends/arm_retval.c
+index 1c28f01..313e4eb 100644
+--- a/backends/arm_retval.c
++++ b/backends/arm_retval.c
+@@ -48,6 +48,13 @@ static const Dwarf_Op loc_intreg[] =
+ #define nloc_intreg 1
+ #define nloc_intregs(n) (2 * (n))
+
++/* f1 */ /* XXX TODO: f0 can also have number 96 if program was compiled with -mabi=aapcs */
++static const Dwarf_Op loc_fpreg[] =
++ {
++ { .atom = DW_OP_reg16 },
++ };
++#define nloc_fpreg 1
++
+ /* The return value is a structure and is actually stored in stack space
+ passed in a hidden argument by the caller. But, the compiler
+ helpfully returns the address of that space in r0. */
+@@ -58,8 +65,9 @@ static const Dwarf_Op loc_aggregate[] =
+ #define nloc_aggregate 1
+
+
+-int
+-arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++static int
++arm_return_value_location_ (Dwarf_Die *functypedie, const Dwarf_Op **locp,
++ int soft_float)
+ {
+ /* Start with the function's type, and get the DW_AT_type attribute,
+ which is the type of the return value. */
+@@ -98,6 +106,21 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ else
+ return -1;
+ }
++ if (tag == DW_TAG_base_type)
++ {
++ Dwarf_Word encoding;
++ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
++ &attr_mem), &encoding) != 0)
++ return -1;
++
++ if ((encoding == DW_ATE_float) && !soft_float)
++ {
++ *locp = loc_fpreg;
++ if (size <= 8)
++ return nloc_fpreg;
++ goto aggregate;
++ }
++ }
+ if (size <= 16)
+ {
+ intreg:
+@@ -106,6 +129,7 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ }
+
+ aggregate:
++ /* XXX TODO sometimes aggregates are returned in r0 (-mabi=aapcs) */
+ *locp = loc_aggregate;
+ return nloc_aggregate;
+ }
+@@ -125,3 +149,18 @@ arm_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
+ DWARF and might be valid. */
+ return -2;
+ }
++
++/* return location for -mabi=apcs-gnu -msoft-float */
++int
++arm_return_value_location_soft (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++{
++ return arm_return_value_location_ (functypedie, locp, 1);
++}
++
++/* return location for -mabi=apcs-gnu -mhard-float (current default) */
++int
++arm_return_value_location_hard (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++{
++ return arm_return_value_location_ (functypedie, locp, 0);
++}
++
+diff --git a/backends/libebl_arm.h b/backends/libebl_arm.h
+new file mode 100644
+index 0000000..c00770c
+--- /dev/null
++++ b/backends/libebl_arm.h
+@@ -0,0 +1,9 @@
++#ifndef _LIBEBL_ARM_H
++#define _LIBEBL_ARM_H 1
++
++#include <libdw.h>
++
++extern int arm_return_value_location_soft(Dwarf_Die *, const Dwarf_Op **locp);
++extern int arm_return_value_location_hard(Dwarf_Die *, const Dwarf_Op **locp);
++
++#endif
+diff --git a/libelf/elf.h b/libelf/elf.h
+index 01648bd..05b7e7e 100644
+--- a/libelf/elf.h
++++ b/libelf/elf.h
+@@ -2690,6 +2690,9 @@ enum
+ #define EF_ARM_EABI_VER4 0x04000000
+ #define EF_ARM_EABI_VER5 0x05000000
+
++/* EI_OSABI values */
++#define ELFOSABI_ARM_AEABI 64 /* Contains symbol versioning. */
++
+ /* Additional symbol types for Thumb. */
+ #define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */
+ #define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */
+@@ -2707,12 +2710,19 @@ enum
+
+ /* Processor specific values for the Phdr p_type field. */
+ #define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */
++#define PT_ARM_UNWIND PT_ARM_EXIDX
+
+ /* Processor specific values for the Shdr sh_type field. */
+ #define SHT_ARM_EXIDX (SHT_LOPROC + 1) /* ARM unwind section. */
+ #define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2) /* Preemption details. */
+ #define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3) /* ARM attributes section. */
+
++/* Processor specific values for the Dyn d_tag field. */
++#define DT_ARM_RESERVED1 (DT_LOPROC + 0)
++#define DT_ARM_SYMTABSZ (DT_LOPROC + 1)
++#define DT_ARM_PREEMTMAB (DT_LOPROC + 2)
++#define DT_ARM_RESERVED2 (DT_LOPROC + 3)
++#define DT_ARM_NUM 4
+
+ /* AArch64 relocs. */
+
+@@ -3005,6 +3015,7 @@ enum
+ TLS block (LDR, STR). */
+ #define R_ARM_TLS_IE12GP 111 /* 12 bit GOT entry relative
+ to GOT origin (LDR). */
++/* 112 - 127 private range */
+ #define R_ARM_ME_TOO 128 /* Obsolete. */
+ #define R_ARM_THM_TLS_DESCSEQ 129
+ #define R_ARM_THM_TLS_DESCSEQ16 129
+diff --git a/tests/run-addrcfi.sh b/tests/run-addrcfi.sh
+index 64fa24d..1c2aa4d 100755
+--- a/tests/run-addrcfi.sh
++++ b/tests/run-addrcfi.sh
+@@ -3554,6 +3554,38 @@ dwarf_cfi_addrframe (.eh_frame): no matching address range
+ FPA reg21 (f5): undefined
+ FPA reg22 (f6): undefined
+ FPA reg23 (f7): undefined
++ VFP reg64 (s0): undefined
++ VFP reg65 (s1): undefined
++ VFP reg66 (s2): undefined
++ VFP reg67 (s3): undefined
++ VFP reg68 (s4): undefined
++ VFP reg69 (s5): undefined
++ VFP reg70 (s6): undefined
++ VFP reg71 (s7): undefined
++ VFP reg72 (s8): undefined
++ VFP reg73 (s9): undefined
++ VFP reg74 (s10): undefined
++ VFP reg75 (s11): undefined
++ VFP reg76 (s12): undefined
++ VFP reg77 (s13): undefined
++ VFP reg78 (s14): undefined
++ VFP reg79 (s15): undefined
++ VFP reg80 (s16): undefined
++ VFP reg81 (s17): undefined
++ VFP reg82 (s18): undefined
++ VFP reg83 (s19): undefined
++ VFP reg84 (s20): undefined
++ VFP reg85 (s21): undefined
++ VFP reg86 (s22): undefined
++ VFP reg87 (s23): undefined
++ VFP reg88 (s24): undefined
++ VFP reg89 (s25): undefined
++ VFP reg90 (s26): undefined
++ VFP reg91 (s27): undefined
++ VFP reg92 (s28): undefined
++ VFP reg93 (s29): undefined
++ VFP reg94 (s30): undefined
++ VFP reg95 (s31): undefined
+ FPA reg96 (f0): undefined
+ FPA reg97 (f1): undefined
+ FPA reg98 (f2): undefined
+@@ -3562,7 +3594,66 @@ dwarf_cfi_addrframe (.eh_frame): no matching address range
+ FPA reg101 (f5): undefined
+ FPA reg102 (f6): undefined
+ FPA reg103 (f7): undefined
+- integer reg128 (spsr): undefined
++ MMX reg104 (wcgr0): undefined
++ MMX reg105 (wcgr1): undefined
++ MMX reg106 (wcgr2): undefined
++ MMX reg107 (wcgr3): undefined
++ MMX reg108 (wcgr4): undefined
++ MMX reg109 (wcgr5): undefined
++ MMX reg110 (wcgr6): undefined
++ MMX reg111 (wcgr7): undefined
++ MMX reg112 (wr0): undefined
++ MMX reg113 (wr1): undefined
++ MMX reg114 (wr2): undefined
++ MMX reg115 (wr3): undefined
++ MMX reg116 (wr4): undefined
++ MMX reg117 (wr5): undefined
++ MMX reg118 (wr6): undefined
++ MMX reg119 (wr7): undefined
++ MMX reg120 (wr8): undefined
++ MMX reg121 (wr9): undefined
++ MMX reg122 (wr10): undefined
++ MMX reg123 (wr11): undefined
++ MMX reg124 (wr12): undefined
++ MMX reg125 (wr13): undefined
++ MMX reg126 (wr14): undefined
++ MMX reg127 (wr15): undefined
++ state reg128 (spsr): undefined
++ state reg129 (spsr_fiq): undefined
++ state reg130 (spsr_irq): undefined
++ state reg131 (spsr_abt): undefined
++ state reg132 (spsr_und): undefined
++ state reg133 (spsr_svc): undefined
++ integer reg144 (r8_usr): undefined
++ integer reg145 (r9_usr): undefined
++ integer reg146 (r10_usr): undefined
++ integer reg147 (r11_usr): undefined
++ integer reg148 (r12_usr): undefined
++ integer reg149 (r13_usr): undefined
++ integer reg150 (r14_usr): undefined
++ integer reg151 (r8_fiq): undefined
++ integer reg152 (r9_fiq): undefined
++ integer reg153 (r10_fiq): undefined
++ integer reg154 (r11_fiq): undefined
++ integer reg155 (r12_fiq): undefined
++ integer reg156 (r13_fiq): undefined
++ integer reg157 (r14_fiq): undefined
++ integer reg158 (r13_irq): undefined
++ integer reg159 (r14_irq): undefined
++ integer reg160 (r13_abt): undefined
++ integer reg161 (r14_abt): undefined
++ integer reg162 (r13_und): undefined
++ integer reg163 (r14_und): undefined
++ integer reg164 (r13_svc): undefined
++ integer reg165 (r14_svc): undefined
++ MMX reg192 (wc0): undefined
++ MMX reg193 (wc1): undefined
++ MMX reg194 (wc2): undefined
++ MMX reg195 (wc3): undefined
++ MMX reg196 (wc4): undefined
++ MMX reg197 (wc5): undefined
++ MMX reg198 (wc6): undefined
++ MMX reg199 (wc7): undefined
+ VFP reg256 (d0): undefined
+ VFP reg257 (d1): undefined
+ VFP reg258 (d2): undefined
+diff --git a/tests/run-allregs.sh b/tests/run-allregs.sh
+index 1422bd6..dc0fc99 100755
+--- a/tests/run-allregs.sh
++++ b/tests/run-allregs.sh
+@@ -2672,7 +2672,28 @@ integer registers:
+ 13: sp (sp), address 32 bits
+ 14: lr (lr), address 32 bits
+ 15: pc (pc), address 32 bits
+- 128: spsr (spsr), unsigned 32 bits
++ 144: r8_usr (r8_usr), signed 32 bits
++ 145: r9_usr (r9_usr), signed 32 bits
++ 146: r10_usr (r10_usr), signed 32 bits
++ 147: r11_usr (r11_usr), signed 32 bits
++ 148: r12_usr (r12_usr), signed 32 bits
++ 149: r13_usr (r13_usr), signed 32 bits
++ 150: r14_usr (r14_usr), signed 32 bits
++ 151: r8_fiq (r8_fiq), signed 32 bits
++ 152: r9_fiq (r9_fiq), signed 32 bits
++ 153: r10_fiq (r10_fiq), signed 32 bits
++ 154: r11_fiq (r11_fiq), signed 32 bits
++ 155: r12_fiq (r12_fiq), signed 32 bits
++ 156: r13_fiq (r13_fiq), signed 32 bits
++ 157: r14_fiq (r14_fiq), signed 32 bits
++ 158: r13_irq (r13_irq), signed 32 bits
++ 159: r14_irq (r14_irq), signed 32 bits
++ 160: r13_abt (r13_abt), signed 32 bits
++ 161: r14_abt (r14_abt), signed 32 bits
++ 162: r13_und (r13_und), signed 32 bits
++ 163: r14_und (r14_und), signed 32 bits
++ 164: r13_svc (r13_svc), signed 32 bits
++ 165: r14_svc (r14_svc), signed 32 bits
+ FPA registers:
+ 16: f0 (f0), float 96 bits
+ 17: f1 (f1), float 96 bits
+@@ -2690,7 +2711,72 @@ FPA registers:
+ 101: f5 (f5), float 96 bits
+ 102: f6 (f6), float 96 bits
+ 103: f7 (f7), float 96 bits
++MMX registers:
++ 104: wcgr0 (wcgr0), unsigned 32 bits
++ 105: wcgr1 (wcgr1), unsigned 32 bits
++ 106: wcgr2 (wcgr2), unsigned 32 bits
++ 107: wcgr3 (wcgr3), unsigned 32 bits
++ 108: wcgr4 (wcgr4), unsigned 32 bits
++ 109: wcgr5 (wcgr5), unsigned 32 bits
++ 110: wcgr6 (wcgr6), unsigned 32 bits
++ 111: wcgr7 (wcgr7), unsigned 32 bits
++ 112: wr0 (wr0), unsigned 64 bits
++ 113: wr1 (wr1), unsigned 64 bits
++ 114: wr2 (wr2), unsigned 64 bits
++ 115: wr3 (wr3), unsigned 64 bits
++ 116: wr4 (wr4), unsigned 64 bits
++ 117: wr5 (wr5), unsigned 64 bits
++ 118: wr6 (wr6), unsigned 64 bits
++ 119: wr7 (wr7), unsigned 64 bits
++ 120: wr8 (wr8), unsigned 64 bits
++ 121: wr9 (wr9), unsigned 64 bits
++ 122: wr10 (wr10), unsigned 64 bits
++ 123: wr11 (wr11), unsigned 64 bits
++ 124: wr12 (wr12), unsigned 64 bits
++ 125: wr13 (wr13), unsigned 64 bits
++ 126: wr14 (wr14), unsigned 64 bits
++ 127: wr15 (wr15), unsigned 64 bits
++ 192: wc0 (wc0), unsigned 32 bits
++ 193: wc1 (wc1), unsigned 32 bits
++ 194: wc2 (wc2), unsigned 32 bits
++ 195: wc3 (wc3), unsigned 32 bits
++ 196: wc4 (wc4), unsigned 32 bits
++ 197: wc5 (wc5), unsigned 32 bits
++ 198: wc6 (wc6), unsigned 32 bits
++ 199: wc7 (wc7), unsigned 32 bits
+ VFP registers:
++ 64: s0 (s0), float 32 bits
++ 65: s1 (s1), float 32 bits
++ 66: s2 (s2), float 32 bits
++ 67: s3 (s3), float 32 bits
++ 68: s4 (s4), float 32 bits
++ 69: s5 (s5), float 32 bits
++ 70: s6 (s6), float 32 bits
++ 71: s7 (s7), float 32 bits
++ 72: s8 (s8), float 32 bits
++ 73: s9 (s9), float 32 bits
++ 74: s10 (s10), float 32 bits
++ 75: s11 (s11), float 32 bits
++ 76: s12 (s12), float 32 bits
++ 77: s13 (s13), float 32 bits
++ 78: s14 (s14), float 32 bits
++ 79: s15 (s15), float 32 bits
++ 80: s16 (s16), float 32 bits
++ 81: s17 (s17), float 32 bits
++ 82: s18 (s18), float 32 bits
++ 83: s19 (s19), float 32 bits
++ 84: s20 (s20), float 32 bits
++ 85: s21 (s21), float 32 bits
++ 86: s22 (s22), float 32 bits
++ 87: s23 (s23), float 32 bits
++ 88: s24 (s24), float 32 bits
++ 89: s25 (s25), float 32 bits
++ 90: s26 (s26), float 32 bits
++ 91: s27 (s27), float 32 bits
++ 92: s28 (s28), float 32 bits
++ 93: s29 (s29), float 32 bits
++ 94: s30 (s30), float 32 bits
++ 95: s31 (s31), float 32 bits
+ 256: d0 (d0), float 64 bits
+ 257: d1 (d1), float 64 bits
+ 258: d2 (d2), float 64 bits
+@@ -2723,6 +2809,13 @@ VFP registers:
+ 285: d29 (d29), float 64 bits
+ 286: d30 (d30), float 64 bits
+ 287: d31 (d31), float 64 bits
++state registers:
++ 128: spsr (spsr), unsigned 32 bits
++ 129: spsr_fiq (spsr_fiq), unsigned 32 bits
++ 130: spsr_irq (spsr_irq), unsigned 32 bits
++ 131: spsr_abt (spsr_abt), unsigned 32 bits
++ 132: spsr_und (spsr_und), unsigned 32 bits
++ 133: spsr_svc (spsr_svc), unsigned 32 bits
+ EOF
+
+ # See run-readelf-mixed-corenote.sh for instructions to regenerate
+diff --git a/tests/run-readelf-mixed-corenote.sh b/tests/run-readelf-mixed-corenote.sh
+index c960f1d..e4bf074 100755
+--- a/tests/run-readelf-mixed-corenote.sh
++++ b/tests/run-readelf-mixed-corenote.sh
+@@ -31,12 +31,11 @@ Note segment of 892 bytes at offset 0x274:
+ pid: 11087, ppid: 11063, pgrp: 11087, sid: 11063
+ utime: 0.000000, stime: 0.010000, cutime: 0.000000, cstime: 0.000000
+ orig_r0: -1, fpvalid: 1
+- r0: 1 r1: -1091672508 r2: -1091672500
+- r3: 0 r4: 0 r5: 0
+- r6: 33728 r7: 0 r8: 0
+- r9: 0 r10: -1225703496 r11: -1091672844
+- r12: 0 sp: 0xbeee64f4 lr: 0xb6dc3f48
+- pc: 0x00008500 spsr: 0x60000010
++ r0: 1 r1: -1091672508 r2: -1091672500 r3: 0
++ r4: 0 r5: 0 r6: 33728 r7: 0
++ r8: 0 r9: 0 r10: -1225703496 r11: -1091672844
++ r12: 0 sp: 0xbeee64f4 lr: 0xb6dc3f48 pc: 0x00008500
++ spsr: 0x60000010
+ CORE 124 PRPSINFO
+ state: 0, sname: R, zomb: 0, nice: 0, flag: 0x00400500
+ uid: 0, gid: 0, pid: 11087, ppid: 11063, pgrp: 11087, sid: 11063
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/disable_werror.patch b/meta/recipes-devtools/elfutils/files/debian/disable_werror.patch
new file mode 100644
index 0000000000..bd98dae4b2
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/disable_werror.patch
@@ -0,0 +1,20 @@
+From: Helmut Grohne <helmut@subdivi.de>
+Subject: disable -Werror as it tends to break with new gcc versions
+Bug-Debian: https://bugs.debian.org/886004
+Last-Update: 2018-01-01
+
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+Index: elfutils-0.176/config/eu.am
+===================================================================
+--- elfutils-0.176.orig/config/eu.am
++++ elfutils-0.176/config/eu.am
+@@ -73,7 +73,6 @@ AM_CFLAGS = -std=gnu99 -Wall -Wshadow -W
+ -Wold-style-definition -Wstrict-prototypes -Wtrampolines \
+ $(LOGICAL_OP_WARNING) $(DUPLICATED_COND_WARNING) \
+ $(NULL_DEREFERENCE_WARNING) $(IMPLICIT_FALLTHROUGH_WARNING) \
+- $(if $($(*F)_no_Werror),,-Werror) \
+ $(if $($(*F)_no_Wunused),,-Wunused -Wextra) \
+ $(if $($(*F)_no_Wstack_usage),,$(STACK_USAGE_WARNING)) \
+ $(if $($(*F)_no_Wpacked_not_aligned),-Wno-packed-not-aligned,) \
diff --git a/meta/recipes-devtools/elfutils/files/debian/hppa_backend.diff b/meta/recipes-devtools/elfutils/files/debian/hppa_backend.diff
new file mode 100644
index 0000000000..4460d582c7
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/hppa_backend.diff
@@ -0,0 +1,831 @@
+From 8efad9105b38985bea373416ae8fcacf21d1d129 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 15:44:18 +0800
+Subject: [PATCH] hppa backend
+
+Rebase to 0.177
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/Makefile.am | 7 +-
+ backends/libebl_parisc.h | 9 ++
+ backends/parisc_init.c | 73 ++++++++++++++++
+ backends/parisc_regs.c | 159 ++++++++++++++++++++++++++++++++++
+ backends/parisc_reloc.def | 128 ++++++++++++++++++++++++++++
+ backends/parisc_retval.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++
+ backends/parisc_symbol.c | 113 ++++++++++++++++++++++++
+ libelf/elf.h | 11 +++
+ 8 files changed, 711 insertions(+), 2 deletions(-)
+ create mode 100644 backends/libebl_parisc.h
+ create mode 100644 backends/parisc_init.c
+ create mode 100644 backends/parisc_regs.c
+ create mode 100644 backends/parisc_reloc.def
+ create mode 100644 backends/parisc_retval.c
+ create mode 100644 backends/parisc_symbol.c
+
+diff --git a/backends/Makefile.am b/backends/Makefile.am
+index 175468f..91a38e2 100644
+--- a/backends/Makefile.am
++++ b/backends/Makefile.am
+@@ -33,16 +33,19 @@ AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
+
+
+ modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
+- tilegx m68k bpf riscv csky
++ tilegx m68k bpf riscv csky parisc
+ libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \
+ libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \
+ libebl_aarch64_pic.a libebl_sparc_pic.a libebl_ppc_pic.a \
+ libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \
+ libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a \
+- libebl_csky_pic.a
++ libebl_csky_pic.a libebl_parisc_pic.a
+ noinst_LIBRARIES = $(libebl_pic)
+ noinst_DATA = $(libebl_pic:_pic.a=.so)
+
++parisc_SRCS = parisc_init.c parisc_symbol.c parisc_regs.c parisc_retval.c
++libebl_parisc_pic_a_SOURCES = $(parisc_SRCS)
++am_libebl_parisc_pic_a_OBJECTS = $(parisc_SRCS:.c=.os)
+
+ libelf = ../libelf/libelf.so
+ libdw = ../libdw/libdw.so
+diff --git a/backends/libebl_parisc.h b/backends/libebl_parisc.h
+new file mode 100644
+index 0000000..f473b79
+--- /dev/null
++++ b/backends/libebl_parisc.h
+@@ -0,0 +1,9 @@
++#ifndef _LIBEBL_HPPA_H
++#define _LIBEBL_HPPA_H 1
++
++#include <libdw.h>
++
++extern int parisc_return_value_location_32(Dwarf_Die *, const Dwarf_Op **locp);
++extern int parisc_return_value_location_64(Dwarf_Die *, const Dwarf_Op **locp);
++
++#endif
+diff --git a/backends/parisc_init.c b/backends/parisc_init.c
+new file mode 100644
+index 0000000..f1e401c
+--- /dev/null
++++ b/backends/parisc_init.c
+@@ -0,0 +1,73 @@
++/* Initialization of PA-RISC specific backend library.
++ Copyright (C) 2002, 2005, 2006 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#define BACKEND parisc_
++#define RELOC_PREFIX R_PARISC_
++#include "libebl_CPU.h"
++#include "libebl_parisc.h"
++
++/* This defines the common reloc hooks based on parisc_reloc.def. */
++#include "common-reloc.c"
++
++
++const char *
++parisc_init (Elf *elf __attribute__ ((unused)),
++ GElf_Half machine __attribute__ ((unused)),
++ Ebl *eh,
++ size_t ehlen)
++{
++ int pa64 = 0;
++
++ /* Check whether the Elf_BH object has a sufficent size. */
++ if (ehlen < sizeof (Ebl))
++ return NULL;
++
++ if (elf) {
++ GElf_Ehdr ehdr_mem;
++ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
++ if (ehdr && (ehdr->e_flags & EF_PARISC_WIDE))
++ pa64 = 1;
++ }
++ /* We handle it. */
++ eh->name = "PA-RISC";
++ parisc_init_reloc (eh);
++ HOOK (eh, reloc_simple_type);
++ HOOK (eh, machine_flag_check);
++ HOOK (eh, symbol_type_name);
++ HOOK (eh, segment_type_name);
++ HOOK (eh, section_type_name);
++ HOOK (eh, register_info);
++ if (pa64)
++ eh->return_value_location = parisc_return_value_location_64;
++ else
++ eh->return_value_location = parisc_return_value_location_32;
++
++ return MODVERSION;
++}
+diff --git a/backends/parisc_regs.c b/backends/parisc_regs.c
+new file mode 100644
+index 0000000..3895f8e
+--- /dev/null
++++ b/backends/parisc_regs.c
+@@ -0,0 +1,159 @@
++/* Register names and numbers for PA-RISC DWARF.
++ Copyright (C) 2005, 2006 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <string.h>
++#include <dwarf.h>
++
++#define BACKEND parisc_
++#include "libebl_CPU.h"
++
++ssize_t
++parisc_register_info (Ebl *ebl, int regno, char *name, size_t namelen,
++ const char **prefix, const char **setname,
++ int *bits, int *type)
++{
++ int pa64 = 0;
++
++ if (ebl->elf) {
++ GElf_Ehdr ehdr_mem;
++ GElf_Ehdr *ehdr = gelf_getehdr (ebl->elf, &ehdr_mem);
++ if (ehdr->e_flags & EF_PARISC_WIDE)
++ pa64 = 1;
++ }
++
++ int nregs = pa64 ? 127 : 128;
++
++ if (name == NULL)
++ return nregs;
++
++ if (regno < 0 || regno >= nregs || namelen < 6)
++ return -1;
++
++ *prefix = "%";
++
++ if (regno < 32)
++ {
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ if (pa64)
++ {
++ *bits = 64;
++ }
++ else
++ {
++ *bits = 32;
++ }
++ }
++ else if (regno == 32)
++ {
++ *setname = "special";
++ if (pa64)
++ {
++ *bits = 6;
++ }
++ else
++ {
++ *bits = 5;
++ }
++ *type = DW_ATE_unsigned;
++ }
++ else
++ {
++ *setname = "FPU";
++ *type = DW_ATE_float;
++ if (pa64)
++ {
++ *bits = 64;
++ }
++ else
++ {
++ *bits = 32;
++ }
++ }
++
++ if (regno < 33) {
++ switch (regno)
++ {
++ case 0 ... 9:
++ name[0] = 'r';
++ name[1] = regno + '0';
++ namelen = 2;
++ break;
++ case 10 ... 31:
++ name[0] = 'r';
++ name[1] = regno / 10 + '0';
++ name[2] = regno % 10 + '0';
++ namelen = 3;
++ break;
++ case 32:
++ *prefix = NULL;
++ name[0] = 'S';
++ name[1] = 'A';
++ name[2] = 'R';
++ namelen = 3;
++ break;
++ }
++ }
++ else {
++ if (pa64 && ((regno - 72) % 2)) {
++ *setname = NULL;
++ return 0;
++ }
++
++ switch (regno)
++ {
++ case 72 + 0 ... 72 + 11:
++ name[0] = 'f';
++ name[1] = 'r';
++ name[2] = (regno + 8 - 72) / 2 + '0';
++ namelen = 3;
++ if ((regno + 8 - 72) % 2) {
++ name[3] = 'R';
++ namelen++;
++ }
++ break;
++ case 72 + 12 ... 72 + 55:
++ name[0] = 'f';
++ name[1] = 'r';
++ name[2] = (regno + 8 - 72) / 2 / 10 + '0';
++ name[3] = (regno + 8 - 72) / 2 % 10 + '0';
++ namelen = 4;
++ if ((regno + 8 - 72) % 2) {
++ name[4] = 'R';
++ namelen++;
++ }
++ break;
++ default:
++ *setname = NULL;
++ return 0;
++ }
++ }
++ name[namelen++] = '\0';
++ return namelen;
++}
+diff --git a/backends/parisc_reloc.def b/backends/parisc_reloc.def
+new file mode 100644
+index 0000000..1f875ba
+--- /dev/null
++++ b/backends/parisc_reloc.def
+@@ -0,0 +1,128 @@
++/* List the relocation types for PA-RISC. -*- C -*-
++ Copyright (C) 2005 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++/* NAME, REL|EXEC|DYN */
++
++RELOC_TYPE (NONE, EXEC|DYN)
++RELOC_TYPE (DIR32, REL|EXEC|DYN)
++RELOC_TYPE (DIR21L, REL|EXEC|DYN)
++RELOC_TYPE (DIR17R, REL)
++RELOC_TYPE (DIR17F, REL)
++RELOC_TYPE (DIR14R, REL|DYN)
++RELOC_TYPE (PCREL32, REL)
++RELOC_TYPE (PCREL21L, REL)
++RELOC_TYPE (PCREL17R, REL)
++RELOC_TYPE (PCREL17F, REL)
++RELOC_TYPE (PCREL14R, REL|EXEC)
++RELOC_TYPE (DPREL21L, REL)
++RELOC_TYPE (DPREL14WR, REL)
++RELOC_TYPE (DPREL14DR, REL)
++RELOC_TYPE (DPREL14R, REL)
++RELOC_TYPE (GPREL21L, 0)
++RELOC_TYPE (GPREL14R, 0)
++RELOC_TYPE (LTOFF21L, REL)
++RELOC_TYPE (LTOFF14R, REL)
++RELOC_TYPE (DLTIND14F, 0)
++RELOC_TYPE (SETBASE, 0)
++RELOC_TYPE (SECREL32, REL)
++RELOC_TYPE (BASEREL21L, 0)
++RELOC_TYPE (BASEREL17R, 0)
++RELOC_TYPE (BASEREL14R, 0)
++RELOC_TYPE (SEGBASE, 0)
++RELOC_TYPE (SEGREL32, REL)
++RELOC_TYPE (PLTOFF21L, 0)
++RELOC_TYPE (PLTOFF14R, 0)
++RELOC_TYPE (PLTOFF14F, 0)
++RELOC_TYPE (LTOFF_FPTR32, 0)
++RELOC_TYPE (LTOFF_FPTR21L, 0)
++RELOC_TYPE (LTOFF_FPTR14R, 0)
++RELOC_TYPE (FPTR64, 0)
++RELOC_TYPE (PLABEL32, REL|DYN)
++RELOC_TYPE (PCREL64, 0)
++RELOC_TYPE (PCREL22C, 0)
++RELOC_TYPE (PCREL22F, 0)
++RELOC_TYPE (PCREL14WR, 0)
++RELOC_TYPE (PCREL14DR, 0)
++RELOC_TYPE (PCREL16F, 0)
++RELOC_TYPE (PCREL16WF, 0)
++RELOC_TYPE (PCREL16DF, 0)
++RELOC_TYPE (DIR64, REL|DYN)
++RELOC_TYPE (DIR14WR, REL)
++RELOC_TYPE (DIR14DR, REL)
++RELOC_TYPE (DIR16F, REL)
++RELOC_TYPE (DIR16WF, REL)
++RELOC_TYPE (DIR16DF, REL)
++RELOC_TYPE (GPREL64, 0)
++RELOC_TYPE (GPREL14WR, 0)
++RELOC_TYPE (GPREL14DR, 0)
++RELOC_TYPE (GPREL16F, 0)
++RELOC_TYPE (GPREL16WF, 0)
++RELOC_TYPE (GPREL16DF, 0)
++RELOC_TYPE (LTOFF64, 0)
++RELOC_TYPE (LTOFF14WR, 0)
++RELOC_TYPE (LTOFF14DR, 0)
++RELOC_TYPE (LTOFF16F, 0)
++RELOC_TYPE (LTOFF16WF, 0)
++RELOC_TYPE (LTOFF16DF, 0)
++RELOC_TYPE (SECREL64, 0)
++RELOC_TYPE (BASEREL14WR, 0)
++RELOC_TYPE (BASEREL14DR, 0)
++RELOC_TYPE (SEGREL64, 0)
++RELOC_TYPE (PLTOFF14WR, 0)
++RELOC_TYPE (PLTOFF14DR, 0)
++RELOC_TYPE (PLTOFF16F, 0)
++RELOC_TYPE (PLTOFF16WF, 0)
++RELOC_TYPE (PLTOFF16DF, 0)
++RELOC_TYPE (LTOFF_FPTR64, 0)
++RELOC_TYPE (LTOFF_FPTR14WR, 0)
++RELOC_TYPE (LTOFF_FPTR14DR, 0)
++RELOC_TYPE (LTOFF_FPTR16F, 0)
++RELOC_TYPE (LTOFF_FPTR16WF, 0)
++RELOC_TYPE (LTOFF_FPTR16DF, 0)
++RELOC_TYPE (COPY, EXEC)
++RELOC_TYPE (IPLT, EXEC|DYN)
++RELOC_TYPE (EPLT, 0)
++RELOC_TYPE (TPREL32, DYN)
++RELOC_TYPE (TPREL21L, 0)
++RELOC_TYPE (TPREL14R, 0)
++RELOC_TYPE (LTOFF_TP21L, 0)
++RELOC_TYPE (LTOFF_TP14R, 0)
++RELOC_TYPE (LTOFF_TP14F, 0)
++RELOC_TYPE (TPREL64, 0)
++RELOC_TYPE (TPREL14WR, 0)
++RELOC_TYPE (TPREL14DR, 0)
++RELOC_TYPE (TPREL16F, 0)
++RELOC_TYPE (TPREL16WF, 0)
++RELOC_TYPE (TPREL16DF, 0)
++RELOC_TYPE (LTOFF_TP64, 0)
++RELOC_TYPE (LTOFF_TP14WR, 0)
++RELOC_TYPE (LTOFF_TP14DR, 0)
++RELOC_TYPE (LTOFF_TP16F, 0)
++RELOC_TYPE (LTOFF_TP16WF, 0)
++RELOC_TYPE (LTOFF_TP16DF, 0)
++RELOC_TYPE (TLS_DTPMOD32, DYN)
++RELOC_TYPE (TLS_DTPMOD64, DYN)
++
++#define NO_RELATIVE_RELOC 1
+diff --git a/backends/parisc_retval.c b/backends/parisc_retval.c
+new file mode 100644
+index 0000000..df7ec3a
+--- /dev/null
++++ b/backends/parisc_retval.c
+@@ -0,0 +1,213 @@
++/* Function return value location for Linux/PA-RISC ABI.
++ Copyright (C) 2005 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <assert.h>
++#include <dwarf.h>
++
++#define BACKEND parisc_
++#include "libebl_CPU.h"
++#include "libebl_parisc.h"
++
++/* %r28, or pair %r28, %r29. */
++static const Dwarf_Op loc_intreg32[] =
++ {
++ { .atom = DW_OP_reg28 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_reg29 }, { .atom = DW_OP_piece, .number = 4 },
++ };
++
++static const Dwarf_Op loc_intreg[] =
++ {
++ { .atom = DW_OP_reg28 }, { .atom = DW_OP_piece, .number = 8 },
++ { .atom = DW_OP_reg29 }, { .atom = DW_OP_piece, .number = 8 },
++ };
++#define nloc_intreg 1
++#define nloc_intregpair 4
++
++/* %fr4L, or pair %fr4L, %fr4R on pa-32 */
++static const Dwarf_Op loc_fpreg32[] =
++ {
++ { .atom = DW_OP_regx, .number = 72 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_regx, .number = 73 }, { .atom = DW_OP_piece, .number = 4 },
++ };
++#define nloc_fpreg32 2
++#define nloc_fpregpair32 4
++
++/* $fr4 */
++static const Dwarf_Op loc_fpreg[] =
++ {
++ { .atom = DW_OP_regx, .number = 72 },
++ };
++#define nloc_fpreg 1
++
++#if 0
++/* The return value is a structure and is actually stored in stack space
++ passed in a hidden argument by the caller. Address of the location is stored
++ in %r28 before function call, but it may be changed by function. */
++static const Dwarf_Op loc_aggregate[] =
++ {
++ { .atom = DW_OP_breg28 },
++ };
++#define nloc_aggregate 1
++#endif
++
++static int
++parisc_return_value_location_ (Dwarf_Die *functypedie, const Dwarf_Op **locp, int pa64)
++{
++ Dwarf_Word regsize = pa64 ? 8 : 4;
++
++ /* Start with the function's type, and get the DW_AT_type attribute,
++ which is the type of the return value. */
++
++ Dwarf_Attribute attr_mem;
++ Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem);
++ if (attr == NULL)
++ /* The function has no return value, like a `void' function in C. */
++ return 0;
++
++ Dwarf_Die die_mem;
++ Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
++ int tag = dwarf_tag (typedie);
++
++ /* Follow typedefs and qualifiers to get to the actual type. */
++ while (tag == DW_TAG_typedef
++ || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
++ || tag == DW_TAG_restrict_type)
++ {
++ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
++ typedie = dwarf_formref_die (attr, &die_mem);
++ tag = dwarf_tag (typedie);
++ }
++
++ switch (tag)
++ {
++ case -1:
++ return -1;
++
++ case DW_TAG_subrange_type:
++ if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
++ {
++ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
++ typedie = dwarf_formref_die (attr, &die_mem);
++ tag = dwarf_tag (typedie);
++ }
++ /* Fall through. */
++
++ case DW_TAG_base_type:
++ case DW_TAG_enumeration_type:
++ case DW_TAG_pointer_type:
++ case DW_TAG_ptr_to_member_type:
++ {
++ Dwarf_Word size;
++ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
++ &attr_mem), &size) != 0)
++ {
++ if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
++ size = 4;
++ else
++ return -1;
++ }
++ if (tag == DW_TAG_base_type)
++ {
++ Dwarf_Word encoding;
++ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
++ &attr_mem), &encoding) != 0)
++ return -1;
++
++ if (encoding == DW_ATE_float)
++ {
++ if (pa64) {
++ *locp = loc_fpreg;
++ if (size <= 8)
++ return nloc_fpreg;
++ }
++ else {
++ *locp = loc_fpreg32;
++ if (size <= 4)
++ return nloc_fpreg32;
++ else if (size <= 8)
++ return nloc_fpregpair32;
++ }
++ goto aggregate;
++ }
++ }
++ if (pa64)
++ *locp = loc_intreg;
++ else
++ *locp = loc_intreg32;
++ if (size <= regsize)
++ return nloc_intreg;
++ if (size <= 2 * regsize)
++ return nloc_intregpair;
++
++ /* Else fall through. */
++ }
++
++ case DW_TAG_structure_type:
++ case DW_TAG_class_type:
++ case DW_TAG_union_type:
++ case DW_TAG_array_type:
++ aggregate: {
++ Dwarf_Word size;
++ if (dwarf_aggregate_size (typedie, &size) != 0)
++ return -1;
++ if (pa64)
++ *locp = loc_intreg;
++ else
++ *locp = loc_intreg32;
++ if (size <= regsize)
++ return nloc_intreg;
++ if (size <= 2 * regsize)
++ return nloc_intregpair;
++#if 0
++ /* there should be some way to know this location... But I do not see it. */
++ *locp = loc_aggregate;
++ return nloc_aggregate;
++#endif
++ /* fall through. */
++ }
++ }
++
++ /* XXX We don't have a good way to return specific errors from ebl calls.
++ This value means we do not understand the type, but it is well-formed
++ DWARF and might be valid. */
++ return -2;
++}
++
++int
++parisc_return_value_location_32 (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++{
++ return parisc_return_value_location_ (functypedie, locp, 0);
++}
++
++int
++parisc_return_value_location_64 (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++{
++ return parisc_return_value_location_ (functypedie, locp, 1);
++}
++
+diff --git a/backends/parisc_symbol.c b/backends/parisc_symbol.c
+new file mode 100644
+index 0000000..5754bd8
+--- /dev/null
++++ b/backends/parisc_symbol.c
+@@ -0,0 +1,113 @@
++/* PA-RISC specific symbolic name handling.
++ Copyright (C) 2002, 2005 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++ Written by Ulrich Drepper <drepper@redhat.com>, 2002.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <elf.h>
++#include <stddef.h>
++
++#define BACKEND parisc_
++#include "libebl_CPU.h"
++
++const char *
++parisc_segment_type_name (int segment, char *buf __attribute__ ((unused)),
++ size_t len __attribute__ ((unused)))
++{
++ switch (segment)
++ {
++ case PT_PARISC_ARCHEXT:
++ return "PARISC_ARCHEXT";
++ case PT_PARISC_UNWIND:
++ return "PARISC_UNWIND";
++ default:
++ break;
++ }
++ return NULL;
++}
++
++/* Return symbolic representation of symbol type. */
++const char *
++parisc_symbol_type_name(int symbol, char *buf __attribute__ ((unused)),
++ size_t len __attribute__ ((unused)))
++{
++ if (symbol == STT_PARISC_MILLICODE)
++ return "PARISC_MILLI";
++ return NULL;
++}
++
++/* Return symbolic representation of section type. */
++const char *
++parisc_section_type_name (int type,
++ char *buf __attribute__ ((unused)),
++ size_t len __attribute__ ((unused)))
++{
++ switch (type)
++ {
++ case SHT_PARISC_EXT:
++ return "PARISC_EXT";
++ case SHT_PARISC_UNWIND:
++ return "PARISC_UNWIND";
++ case SHT_PARISC_DOC:
++ return "PARISC_DOC";
++ }
++
++ return NULL;
++}
++
++/* Check whether machine flags are valid. */
++bool
++parisc_machine_flag_check (GElf_Word flags)
++{
++ if (flags &~ (EF_PARISC_TRAPNIL | EF_PARISC_EXT | EF_PARISC_LSB |
++ EF_PARISC_WIDE | EF_PARISC_NO_KABP |
++ EF_PARISC_LAZYSWAP | EF_PARISC_ARCH))
++ return 0;
++
++ GElf_Word arch = flags & EF_PARISC_ARCH;
++
++ return ((arch == EFA_PARISC_1_0) || (arch == EFA_PARISC_1_1) ||
++ (arch == EFA_PARISC_2_0));
++}
++
++/* Check for the simple reloc types. */
++Elf_Type
++parisc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
++ int *addsub __attribute__ ((unused)))
++{
++ switch (type)
++ {
++ case R_PARISC_DIR64:
++ case R_PARISC_SECREL64:
++ return ELF_T_XWORD;
++ case R_PARISC_DIR32:
++ case R_PARISC_SECREL32:
++ return ELF_T_WORD;
++ default:
++ return ELF_T_NUM;
++ }
++}
+diff --git a/libelf/elf.h b/libelf/elf.h
+index 01648bd..218ceb2 100644
+--- a/libelf/elf.h
++++ b/libelf/elf.h
+@@ -2162,16 +2162,24 @@ enum
+ #define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */
+ #define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */
+ #define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */
++#define R_PARISC_DPREL14WR 19
++#define R_PARISC_DPREL14DR 20
+ #define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */
+ #define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */
+ #define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */
+ #define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */
+ #define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */
++#define R_PARISC_DLTIND14F 39
++#define R_PARISC_SETBASE 40
+ #define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */
++#define R_PARISC_BASEREL21L 42
++#define R_PARISC_BASEREL17R 43
++#define R_PARISC_BASEREL14R 46
+ #define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */
+ #define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */
+ #define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */
+ #define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */
++#define R_PARISC_PLTOFF14F 55
+ #define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */
+ #define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */
+ #define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */
+@@ -2180,6 +2188,7 @@ enum
+ #define R_PARISC_PLABEL21L 66 /* Left 21 bits of fdesc address. */
+ #define R_PARISC_PLABEL14R 70 /* Right 14 bits of fdesc address. */
+ #define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */
++#define R_PARISC_PCREL22C 73
+ #define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */
+ #define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */
+ #define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */
+@@ -2205,6 +2214,8 @@ enum
+ #define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */
+ #define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */
+ #define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */
++#define R_PARISC_BASEREL14WR 107
++#define R_PARISC_BASEREL14DR 108
+ #define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */
+ #define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */
+ #define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/hurd_path.patch b/meta/recipes-devtools/elfutils/files/debian/hurd_path.patch
new file mode 100644
index 0000000000..62a960f3a8
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/hurd_path.patch
@@ -0,0 +1,17 @@
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+Index: elfutils-0.165/tests/run-native-test.sh
+===================================================================
+--- elfutils-0.165.orig/tests/run-native-test.sh
++++ elfutils-0.165/tests/run-native-test.sh
+@@ -83,6 +83,9 @@ native_test()
+ # "cannot attach to process: Function not implemented".
+ [ "$(uname)" = "GNU/kFreeBSD" ] && exit 77
+
++# hurd's /proc/$PID/maps does not give paths yet.
++[ "$(uname)" = "GNU" ] && exit 77
++
+ native_test ${abs_builddir}/allregs
+ native_test ${abs_builddir}/funcretval
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/ignore_strmerge.diff b/meta/recipes-devtools/elfutils/files/debian/ignore_strmerge.diff
new file mode 100644
index 0000000000..55513eeddc
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/ignore_strmerge.diff
@@ -0,0 +1,14 @@
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+--- elfutils-0.165.orig/tests/run-strip-strmerge.sh
++++ elfutils-0.165/tests/run-strip-strmerge.sh
+@@ -30,7 +30,7 @@ remerged=remerged.elf
+ tempfiles $merged $stripped $debugfile $remerged
+
+ echo elflint $input
+-testrun ${abs_top_builddir}/src/elflint --gnu $input
++testrun_on_self_skip ${abs_top_builddir}/src/elflint --gnu $input
+ echo elfstrmerge
+ testrun ${abs_top_builddir}/tests/elfstrmerge -o $merged $input
+ echo elflint $merged
diff --git a/meta/recipes-devtools/elfutils/files/debian/kfreebsd_path.patch b/meta/recipes-devtools/elfutils/files/debian/kfreebsd_path.patch
new file mode 100644
index 0000000000..e85a2fed9d
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/kfreebsd_path.patch
@@ -0,0 +1,20 @@
+Upstream-Status: Pending [from debian]
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+
+Index: b/tests/run-native-test.sh
+===================================================================
+--- a/tests/run-native-test.sh
++++ b/tests/run-native-test.sh
+@@ -77,6 +77,12 @@ native_test()
+ test $native -eq 0 || testrun "$@" -p $native > /dev/null
+ }
+
++# On the Debian buildds, GNU/kFreeBSD linprocfs /proc/$PID/maps does
++# not give absolute paths due to sbuild's bind mounts (bug #570805)
++# therefore the next two test programs are expected to fail with
++# "cannot attach to process: Function not implemented".
++[ "$(uname)" = "GNU/kFreeBSD" ] && exit 77
++
+ native_test ${abs_builddir}/allregs
+ native_test ${abs_builddir}/funcretval
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/mips_backend.diff b/meta/recipes-devtools/elfutils/files/debian/mips_backend.diff
new file mode 100644
index 0000000000..1097b0ec6f
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/mips_backend.diff
@@ -0,0 +1,717 @@
+From 68b497668cde5171880d073a7ea50d11c3bddbfc Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 15:49:52 +0800
+Subject: [PATCH] mips backend
+
+Rebase to 0.177
+Upstream-Status: Pending [from debian]
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/Makefile.am | 8 +-
+ backends/mips_init.c | 59 +++++++++
+ backends/mips_regs.c | 104 ++++++++++++++++
+ backends/mips_reloc.def | 79 ++++++++++++
+ backends/mips_retval.c | 321 ++++++++++++++++++++++++++++++++++++++++++++++++
+ backends/mips_symbol.c | 53 ++++++++
+ libebl/eblopenbackend.c | 2 +
+ 7 files changed, 624 insertions(+), 2 deletions(-)
+ create mode 100644 backends/mips_init.c
+ create mode 100644 backends/mips_regs.c
+ create mode 100644 backends/mips_reloc.def
+ create mode 100644 backends/mips_retval.c
+ create mode 100644 backends/mips_symbol.c
+
+diff --git a/backends/Makefile.am b/backends/Makefile.am
+index 91a38e2..aba8a4a 100644
+--- a/backends/Makefile.am
++++ b/backends/Makefile.am
+@@ -33,13 +33,13 @@ AM_CPPFLAGS += -I$(top_srcdir)/libebl -I$(top_srcdir)/libasm \
+
+
+ modules = i386 sh x86_64 ia64 alpha arm aarch64 sparc ppc ppc64 s390 \
+- tilegx m68k bpf riscv csky parisc
++ tilegx m68k bpf riscv csky parisc mips
+ libebl_pic = libebl_i386_pic.a libebl_sh_pic.a libebl_x86_64_pic.a \
+ libebl_ia64_pic.a libebl_alpha_pic.a libebl_arm_pic.a \
+ libebl_aarch64_pic.a libebl_sparc_pic.a libebl_ppc_pic.a \
+ libebl_ppc64_pic.a libebl_s390_pic.a libebl_tilegx_pic.a \
+ libebl_m68k_pic.a libebl_bpf_pic.a libebl_riscv_pic.a \
+- libebl_csky_pic.a libebl_parisc_pic.a
++ libebl_csky_pic.a libebl_parisc_pic.a libebl_mips_pic.a
+ noinst_LIBRARIES = $(libebl_pic)
+ noinst_DATA = $(libebl_pic:_pic.a=.so)
+
+@@ -145,6 +145,10 @@ csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \
+ libebl_csky_pic_a_SOURCES = $(csky_SRCS)
+ am_libebl_csky_pic_a_OBJECTS = $(csky_SRCS:.c=.os)
+
++mips_SRCS = mips_init.c mips_symbol.c mips_regs.c mips_retval.c
++libebl_mips_pic_a_SOURCES = $(mips_SRCS)
++am_libebl_mips_pic_a_OBJECTS = $(mips_SRCS:.c=.os)
++
+ libebl_%.so libebl_%.map: libebl_%_pic.a $(libelf) $(libdw) $(libeu)
+ @rm -f $(@:.so=.map)
+ $(AM_V_at)echo 'ELFUTILS_$(PACKAGE_VERSION) { global: $*_init; local: *; };' \
+diff --git a/backends/mips_init.c b/backends/mips_init.c
+new file mode 100644
+index 0000000..975c04e
+--- /dev/null
++++ b/backends/mips_init.c
+@@ -0,0 +1,59 @@
++/* Initialization of mips specific backend library.
++ Copyright (C) 2006 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#define BACKEND mips_
++#define RELOC_PREFIX R_MIPS_
++#include "libebl_CPU.h"
++
++/* This defines the common reloc hooks based on mips_reloc.def. */
++#include "common-reloc.c"
++
++const char *
++mips_init (Elf *elf __attribute__ ((unused)),
++ GElf_Half machine __attribute__ ((unused)),
++ Ebl *eh,
++ size_t ehlen)
++{
++ /* Check whether the Elf_BH object has a sufficent size. */
++ if (ehlen < sizeof (Ebl))
++ return NULL;
++
++ /* We handle it. */
++ if (machine == EM_MIPS)
++ eh->name = "MIPS R3000 big-endian";
++ else if (machine == EM_MIPS_RS3_LE)
++ eh->name = "MIPS R3000 little-endian";
++
++ mips_init_reloc (eh);
++ HOOK (eh, reloc_simple_type);
++ HOOK (eh, return_value_location);
++ HOOK (eh, register_info);
++
++ return MODVERSION;
++}
+diff --git a/backends/mips_regs.c b/backends/mips_regs.c
+new file mode 100644
+index 0000000..44f86cb
+--- /dev/null
++++ b/backends/mips_regs.c
+@@ -0,0 +1,104 @@
++/* Register names and numbers for MIPS DWARF.
++ Copyright (C) 2006 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <string.h>
++#include <dwarf.h>
++
++#define BACKEND mips_
++#include "libebl_CPU.h"
++
++ssize_t
++mips_register_info (Ebl *ebl __attribute__((unused)),
++ int regno, char *name, size_t namelen,
++ const char **prefix, const char **setname,
++ int *bits, int *type)
++{
++ if (name == NULL)
++ return 66;
++
++ if (regno < 0 || regno > 65 || namelen < 4)
++ return -1;
++
++ *prefix = "$";
++
++ if (regno < 32)
++ {
++ *setname = "integer";
++ *type = DW_ATE_signed;
++ *bits = 32;
++ if (regno < 32 + 10)
++ {
++ name[0] = regno + '0';
++ namelen = 1;
++ }
++ else
++ {
++ name[0] = (regno / 10) + '0';
++ name[1] = (regno % 10) + '0';
++ namelen = 2;
++ }
++ }
++ else if (regno < 64)
++ {
++ *setname = "FPU";
++ *type = DW_ATE_float;
++ *bits = 32;
++ name[0] = 'f';
++ if (regno < 32 + 10)
++ {
++ name[1] = (regno - 32) + '0';
++ namelen = 2;
++ }
++ else
++ {
++ name[1] = (regno - 32) / 10 + '0';
++ name[2] = (regno - 32) % 10 + '0';
++ namelen = 3;
++ }
++ }
++ else if (regno == 64)
++ {
++ *type = DW_ATE_signed;
++ *bits = 32;
++ name[0] = 'h';
++ name[1] = 'i';
++ namelen = 2;
++ }
++ else
++ {
++ *type = DW_ATE_signed;
++ *bits = 32;
++ name[0] = 'l';
++ name[1] = 'o';
++ namelen = 2;
++ }
++
++ name[namelen++] = '\0';
++ return namelen;
++}
+diff --git a/backends/mips_reloc.def b/backends/mips_reloc.def
+new file mode 100644
+index 0000000..4579970
+--- /dev/null
++++ b/backends/mips_reloc.def
+@@ -0,0 +1,79 @@
++/* List the relocation types for mips. -*- C -*-
++ Copyright (C) 2006 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++/* NAME, REL|EXEC|DYN */
++
++RELOC_TYPE (NONE, 0)
++RELOC_TYPE (16, 0)
++RELOC_TYPE (32, 0)
++RELOC_TYPE (REL32, 0)
++RELOC_TYPE (26, 0)
++RELOC_TYPE (HI16, 0)
++RELOC_TYPE (LO16, 0)
++RELOC_TYPE (GPREL16, 0)
++RELOC_TYPE (LITERAL, 0)
++RELOC_TYPE (GOT16, 0)
++RELOC_TYPE (PC16, 0)
++RELOC_TYPE (CALL16, 0)
++RELOC_TYPE (GPREL32, 0)
++
++RELOC_TYPE (SHIFT5, 0)
++RELOC_TYPE (SHIFT6, 0)
++RELOC_TYPE (64, 0)
++RELOC_TYPE (GOT_DISP, 0)
++RELOC_TYPE (GOT_PAGE, 0)
++RELOC_TYPE (GOT_OFST, 0)
++RELOC_TYPE (GOT_HI16, 0)
++RELOC_TYPE (GOT_LO16, 0)
++RELOC_TYPE (SUB, 0)
++RELOC_TYPE (INSERT_A, 0)
++RELOC_TYPE (INSERT_B, 0)
++RELOC_TYPE (DELETE, 0)
++RELOC_TYPE (HIGHER, 0)
++RELOC_TYPE (HIGHEST, 0)
++RELOC_TYPE (CALL_HI16, 0)
++RELOC_TYPE (CALL_LO16, 0)
++RELOC_TYPE (SCN_DISP, 0)
++RELOC_TYPE (REL16, 0)
++RELOC_TYPE (ADD_IMMEDIATE, 0)
++RELOC_TYPE (PJUMP, 0)
++RELOC_TYPE (RELGOT, 0)
++RELOC_TYPE (JALR, 0)
++RELOC_TYPE (TLS_DTPMOD32, 0)
++RELOC_TYPE (TLS_DTPREL32, 0)
++RELOC_TYPE (TLS_DTPMOD64, 0)
++RELOC_TYPE (TLS_DTPREL64, 0)
++RELOC_TYPE (TLS_GD, 0)
++RELOC_TYPE (TLS_LDM, 0)
++RELOC_TYPE (TLS_DTPREL_HI16, 0)
++RELOC_TYPE (TLS_DTPREL_LO16, 0)
++RELOC_TYPE (TLS_GOTTPREL, 0)
++RELOC_TYPE (TLS_TPREL32, 0)
++RELOC_TYPE (TLS_TPREL64, 0)
++RELOC_TYPE (TLS_TPREL_HI16, 0)
++RELOC_TYPE (TLS_TPREL_LO16, 0)
++
++#define NO_COPY_RELOC 1
++#define NO_RELATIVE_RELOC 1
+diff --git a/backends/mips_retval.c b/backends/mips_retval.c
+new file mode 100644
+index 0000000..656cd1f
+--- /dev/null
++++ b/backends/mips_retval.c
+@@ -0,0 +1,321 @@
++/* Function return value location for Linux/mips ABI.
++ Copyright (C) 2005 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <string.h>
++#include <assert.h>
++#include <dwarf.h>
++#include <elf.h>
++
++#include "../libebl/libeblP.h"
++#include "../libdw/libdwP.h"
++
++#define BACKEND mips_
++#include "libebl_CPU.h"
++
++/* The ABI of the file. Also see EF_MIPS_ABI2 above. */
++#define EF_MIPS_ABI 0x0000F000
++
++/* The original o32 abi. */
++#define E_MIPS_ABI_O32 0x00001000
++
++/* O32 extended to work on 64 bit architectures */
++#define E_MIPS_ABI_O64 0x00002000
++
++/* EABI in 32 bit mode */
++#define E_MIPS_ABI_EABI32 0x00003000
++
++/* EABI in 64 bit mode */
++#define E_MIPS_ABI_EABI64 0x00004000
++
++/* All the possible MIPS ABIs. */
++enum mips_abi
++ {
++ MIPS_ABI_UNKNOWN = 0,
++ MIPS_ABI_N32,
++ MIPS_ABI_O32,
++ MIPS_ABI_N64,
++ MIPS_ABI_O64,
++ MIPS_ABI_EABI32,
++ MIPS_ABI_EABI64,
++ MIPS_ABI_LAST
++ };
++
++/* Find the mips ABI of the current file */
++enum mips_abi find_mips_abi(Elf *elf)
++{
++ GElf_Ehdr ehdr_mem;
++ GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
++
++ if (ehdr == NULL)
++ return MIPS_ABI_LAST;
++
++ GElf_Word elf_flags = ehdr->e_flags;
++
++ /* Check elf_flags to see if it specifies the ABI being used. */
++ switch ((elf_flags & EF_MIPS_ABI))
++ {
++ case E_MIPS_ABI_O32:
++ return MIPS_ABI_O32;
++ case E_MIPS_ABI_O64:
++ return MIPS_ABI_O64;
++ case E_MIPS_ABI_EABI32:
++ return MIPS_ABI_EABI32;
++ case E_MIPS_ABI_EABI64:
++ return MIPS_ABI_EABI64;
++ default:
++ if ((elf_flags & EF_MIPS_ABI2))
++ return MIPS_ABI_N32;
++ }
++
++ /* GCC creates a pseudo-section whose name describes the ABI. */
++ size_t shstrndx;
++ if (elf_getshdrstrndx (elf, &shstrndx) < 0)
++ return MIPS_ABI_LAST;
++
++ const char *name;
++ Elf_Scn *scn = NULL;
++ while ((scn = elf_nextscn (elf, scn)) != NULL)
++ {
++ GElf_Shdr shdr_mem;
++ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
++ if (shdr == NULL)
++ return MIPS_ABI_LAST;
++
++ name = elf_strptr (elf, shstrndx, shdr->sh_name) ?: "";
++ if (strncmp (name, ".mdebug.", 8) != 0)
++ continue;
++
++ if (strcmp (name, ".mdebug.abi32") == 0)
++ return MIPS_ABI_O32;
++ else if (strcmp (name, ".mdebug.abiN32") == 0)
++ return MIPS_ABI_N32;
++ else if (strcmp (name, ".mdebug.abi64") == 0)
++ return MIPS_ABI_N64;
++ else if (strcmp (name, ".mdebug.abiO64") == 0)
++ return MIPS_ABI_O64;
++ else if (strcmp (name, ".mdebug.eabi32") == 0)
++ return MIPS_ABI_EABI32;
++ else if (strcmp (name, ".mdebug.eabi64") == 0)
++ return MIPS_ABI_EABI64;
++ else
++ return MIPS_ABI_UNKNOWN;
++ }
++
++ return MIPS_ABI_UNKNOWN;
++}
++
++unsigned int
++mips_abi_regsize (enum mips_abi abi)
++{
++ switch (abi)
++ {
++ case MIPS_ABI_EABI32:
++ case MIPS_ABI_O32:
++ return 4;
++ case MIPS_ABI_N32:
++ case MIPS_ABI_N64:
++ case MIPS_ABI_O64:
++ case MIPS_ABI_EABI64:
++ return 8;
++ case MIPS_ABI_UNKNOWN:
++ case MIPS_ABI_LAST:
++ default:
++ return 0;
++ }
++}
++
++
++/* $v0 or pair $v0, $v1 */
++static const Dwarf_Op loc_intreg_o32[] =
++ {
++ { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 4 },
++ };
++
++static const Dwarf_Op loc_intreg[] =
++ {
++ { .atom = DW_OP_reg2 }, { .atom = DW_OP_piece, .number = 8 },
++ { .atom = DW_OP_reg3 }, { .atom = DW_OP_piece, .number = 8 },
++ };
++#define nloc_intreg 1
++#define nloc_intregpair 4
++
++/* $f0 (float), or pair $f0, $f1 (double).
++ * f2/f3 are used for COMPLEX (= 2 doubles) returns in Fortran */
++static const Dwarf_Op loc_fpreg_o32[] =
++ {
++ { .atom = DW_OP_regx, .number = 32 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_regx, .number = 33 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 4 },
++ { .atom = DW_OP_regx, .number = 35 }, { .atom = DW_OP_piece, .number = 4 },
++ };
++
++/* $f0, or pair $f0, $f2. */
++static const Dwarf_Op loc_fpreg[] =
++ {
++ { .atom = DW_OP_regx, .number = 32 }, { .atom = DW_OP_piece, .number = 8 },
++ { .atom = DW_OP_regx, .number = 34 }, { .atom = DW_OP_piece, .number = 8 },
++ };
++#define nloc_fpreg 1
++#define nloc_fpregpair 4
++#define nloc_fpregquad 8
++
++/* The return value is a structure and is actually stored in stack space
++ passed in a hidden argument by the caller. But, the compiler
++ helpfully returns the address of that space in $v0. */
++static const Dwarf_Op loc_aggregate[] =
++ {
++ { .atom = DW_OP_breg2, .number = 0 }
++ };
++#define nloc_aggregate 1
++
++int
++mips_return_value_location (Dwarf_Die *functypedie, const Dwarf_Op **locp)
++{
++ /* First find the ABI used by the elf object */
++ enum mips_abi abi = find_mips_abi(functypedie->cu->dbg->elf);
++
++ /* Something went seriously wrong while trying to figure out the ABI */
++ if (abi == MIPS_ABI_LAST)
++ return -1;
++
++ /* We couldn't identify the ABI, but the file seems valid */
++ if (abi == MIPS_ABI_UNKNOWN)
++ return -2;
++
++ /* Can't handle EABI variants */
++ if ((abi == MIPS_ABI_EABI32) || (abi == MIPS_ABI_EABI64))
++ return -2;
++
++ unsigned int regsize = mips_abi_regsize (abi);
++ if (!regsize)
++ return -2;
++
++ /* Start with the function's type, and get the DW_AT_type attribute,
++ which is the type of the return value. */
++
++ Dwarf_Attribute attr_mem;
++ Dwarf_Attribute *attr = dwarf_attr_integrate (functypedie, DW_AT_type, &attr_mem);
++ if (attr == NULL)
++ /* The function has no return value, like a `void' function in C. */
++ return 0;
++
++ Dwarf_Die die_mem;
++ Dwarf_Die *typedie = dwarf_formref_die (attr, &die_mem);
++ int tag = dwarf_tag (typedie);
++
++ /* Follow typedefs and qualifiers to get to the actual type. */
++ while (tag == DW_TAG_typedef
++ || tag == DW_TAG_const_type || tag == DW_TAG_volatile_type
++ || tag == DW_TAG_restrict_type)
++ {
++ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
++ typedie = dwarf_formref_die (attr, &die_mem);
++ tag = dwarf_tag (typedie);
++ }
++
++ switch (tag)
++ {
++ case -1:
++ return -1;
++
++ case DW_TAG_subrange_type:
++ if (! dwarf_hasattr_integrate (typedie, DW_AT_byte_size))
++ {
++ attr = dwarf_attr_integrate (typedie, DW_AT_type, &attr_mem);
++ typedie = dwarf_formref_die (attr, &die_mem);
++ tag = dwarf_tag (typedie);
++ }
++ /* Fall through. */
++
++ case DW_TAG_base_type:
++ case DW_TAG_enumeration_type:
++ case DW_TAG_pointer_type:
++ case DW_TAG_ptr_to_member_type:
++ {
++ Dwarf_Word size;
++ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_byte_size,
++ &attr_mem), &size) != 0)
++ {
++ if (tag == DW_TAG_pointer_type || tag == DW_TAG_ptr_to_member_type)
++ size = regsize;
++ else
++ return -1;
++ }
++ if (tag == DW_TAG_base_type)
++ {
++ Dwarf_Word encoding;
++ if (dwarf_formudata (dwarf_attr_integrate (typedie, DW_AT_encoding,
++ &attr_mem), &encoding) != 0)
++ return -1;
++
++#define ABI_LOC(loc, regsize) ((regsize) == 4 ? (loc ## _o32) : (loc))
++
++ if (encoding == DW_ATE_float)
++ {
++ *locp = ABI_LOC(loc_fpreg, regsize);
++ if (size <= regsize)
++ return nloc_fpreg;
++
++ if (size <= 2*regsize)
++ return nloc_fpregpair;
++
++ if (size <= 4*regsize && abi == MIPS_ABI_O32)
++ return nloc_fpregquad;
++
++ goto aggregate;
++ }
++ }
++ *locp = ABI_LOC(loc_intreg, regsize);
++ if (size <= regsize)
++ return nloc_intreg;
++ if (size <= 2*regsize)
++ return nloc_intregpair;
++
++ /* Else fall through. Shouldn't happen though (at least with gcc) */
++ }
++
++ case DW_TAG_structure_type:
++ case DW_TAG_class_type:
++ case DW_TAG_union_type:
++ case DW_TAG_array_type:
++ aggregate:
++ /* XXX TODO: Can't handle structure return with other ABI's yet :-/ */
++ if ((abi != MIPS_ABI_O32) && (abi != MIPS_ABI_O64))
++ return -2;
++
++ *locp = loc_aggregate;
++ return nloc_aggregate;
++ }
++
++ /* XXX We don't have a good way to return specific errors from ebl calls.
++ This value means we do not understand the type, but it is well-formed
++ DWARF and might be valid. */
++ return -2;
++}
+diff --git a/backends/mips_symbol.c b/backends/mips_symbol.c
+new file mode 100644
+index 0000000..261b05d
+--- /dev/null
++++ b/backends/mips_symbol.c
+@@ -0,0 +1,53 @@
++/* MIPS specific symbolic name handling.
++ Copyright (C) 2002, 2003, 2005 Red Hat, Inc.
++ This file is part of Red Hat elfutils.
++ Written by Jakub Jelinek <jakub@redhat.com>, 2002.
++
++ Red Hat elfutils 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; version 2 of the License.
++
++ Red Hat elfutils 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 Red Hat elfutils; if not, write to the Free Software Foundation,
++ Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA.
++
++ Red Hat elfutils is an included package of the Open Invention Network.
++ An included package of the Open Invention Network is a package for which
++ Open Invention Network licensees cross-license their patents. No patent
++ license is granted, either expressly or impliedly, by designation as an
++ included package. Should you wish to participate in the Open Invention
++ Network licensing program, please visit www.openinventionnetwork.com
++ <http://www.openinventionnetwork.com>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <elf.h>
++#include <stddef.h>
++
++#define BACKEND mips_
++#include "libebl_CPU.h"
++
++/* Check for the simple reloc types. */
++Elf_Type
++mips_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
++ int *addsub __attribute__ ((unused)))
++{
++ switch (type)
++ {
++ case R_MIPS_16:
++ return ELF_T_HALF;
++ case R_MIPS_32:
++ return ELF_T_WORD;
++ case R_MIPS_64:
++ return ELF_T_XWORD;
++ default:
++ return ELF_T_NUM;
++ }
++}
+diff --git a/libebl/eblopenbackend.c b/libebl/eblopenbackend.c
+index 01711f5..d0c3589 100644
+--- a/libebl/eblopenbackend.c
++++ b/libebl/eblopenbackend.c
+@@ -71,6 +71,8 @@ static const struct
+ { "sparc", "elf_sparc", "sparc", 5, EM_SPARC, 0, 0 },
+ { "sparc", "elf_sparcv8plus", "sparc", 5, EM_SPARC32PLUS, 0, 0 },
+ { "s390", "ebl_s390", "s390", 4, EM_S390, 0, 0 },
++ { "mips", "elf_mips", "mips", 4, EM_MIPS, 0, 0 },
++ { "mips", "elf_mipsel", "mipsel", 4, EM_MIPS_RS3_LE, 0, 0 },
+
+ { "m32", "elf_m32", "m32", 3, EM_M32, 0, 0 },
+ { "m68k", "elf_m68k", "m68k", 4, EM_68K, ELFCLASS32, ELFDATA2MSB },
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/mips_cfi.patch b/meta/recipes-devtools/elfutils/files/debian/mips_cfi.patch
new file mode 100644
index 0000000000..fda4f68059
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/mips_cfi.patch
@@ -0,0 +1,131 @@
+From 96e38289f2887ddb8e6d2fb91ea04bdbdf034ab5 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 17:00:30 +0800
+Subject: [PATCH 2/2] mips_cfi
+
+Upstream-Status: Pending [from debian]
+
+Rebase to 0.177
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ backends/Makefile.am | 2 +-
+ backends/mips_cfi.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++
+ backends/mips_init.c | 1 +
+ 3 files changed, 82 insertions(+), 1 deletion(-)
+ create mode 100644 backends/mips_cfi.c
+
+diff --git a/backends/Makefile.am b/backends/Makefile.am
+index aba8a4a..6ac0eec 100644
+--- a/backends/Makefile.am
++++ b/backends/Makefile.am
+@@ -145,7 +145,7 @@ csky_SRCS = csky_attrs.c csky_init.c csky_symbol.c csky_cfi.c \
+ libebl_csky_pic_a_SOURCES = $(csky_SRCS)
+ am_libebl_csky_pic_a_OBJECTS = $(csky_SRCS:.c=.os)
+
+-mips_SRCS = mips_init.c mips_symbol.c mips_regs.c mips_retval.c
++mips_SRCS = mips_init.c mips_symbol.c mips_regs.c mips_retval.c mips_cfi.c
+ libebl_mips_pic_a_SOURCES = $(mips_SRCS)
+ am_libebl_mips_pic_a_OBJECTS = $(mips_SRCS:.c=.os)
+
+diff --git a/backends/mips_cfi.c b/backends/mips_cfi.c
+new file mode 100644
+index 0000000..9ffdab5
+--- /dev/null
++++ b/backends/mips_cfi.c
+@@ -0,0 +1,80 @@
++/* MIPS ABI-specified defaults for DWARF CFI.
++ Copyright (C) 2018 Kurt Roeckx, Inc.
++ This file is part of elfutils.
++
++ This file is free software; you can redistribute it and/or modify
++ it under the terms of either
++
++ * the GNU Lesser General Public License as published by the Free
++ Software Foundation; either version 3 of the License, or (at
++ your option) any later version
++
++ or
++
++ * the GNU General Public License as published by the Free
++ Software Foundation; either version 2 of the License, or (at
++ your option) any later version
++
++ or both in parallel, as here.
++
++ elfutils 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 copies of the GNU General Public License and
++ the GNU Lesser General Public License along with this program. If
++ not, see <http://www.gnu.org/licenses/>. */
++
++#ifdef HAVE_CONFIG_H
++# include <config.h>
++#endif
++
++#include <dwarf.h>
++
++#define BACKEND mips_
++#include "libebl_CPU.h"
++
++int
++mips_abi_cfi (Ebl *ebl __attribute__ ((unused)), Dwarf_CIE *abi_info)
++{
++ static const uint8_t abi_cfi[] =
++ {
++ /* Call-saved regs. */
++ DW_CFA_same_value, ULEB128_7 (16), /* $16 */
++ DW_CFA_same_value, ULEB128_7 (17), /* $17 */
++ DW_CFA_same_value, ULEB128_7 (18), /* $18 */
++ DW_CFA_same_value, ULEB128_7 (19), /* $19 */
++ DW_CFA_same_value, ULEB128_7 (20), /* $20 */
++ DW_CFA_same_value, ULEB128_7 (21), /* $21 */
++ DW_CFA_same_value, ULEB128_7 (22), /* $22 */
++ DW_CFA_same_value, ULEB128_7 (23), /* $23 */
++ DW_CFA_same_value, ULEB128_7 (28), /* $28 */
++ DW_CFA_same_value, ULEB128_7 (29), /* $29 */
++ DW_CFA_same_value, ULEB128_7 (30), /* $30 */
++
++ DW_CFA_same_value, ULEB128_7 (52), /* $f20 */
++ DW_CFA_same_value, ULEB128_7 (53), /* $f21 */
++ DW_CFA_same_value, ULEB128_7 (54), /* $f22 */
++ DW_CFA_same_value, ULEB128_7 (55), /* $f23 */
++ DW_CFA_same_value, ULEB128_7 (56), /* $f24 */
++ DW_CFA_same_value, ULEB128_7 (57), /* $f25 */
++ DW_CFA_same_value, ULEB128_7 (58), /* $f26 */
++ DW_CFA_same_value, ULEB128_7 (59), /* $f27 */
++ DW_CFA_same_value, ULEB128_7 (60), /* $f28 */
++ DW_CFA_same_value, ULEB128_7 (61), /* $f29 */
++ DW_CFA_same_value, ULEB128_7 (62), /* $f30 */
++ DW_CFA_same_value, ULEB128_7 (63), /* $f31 */
++
++ /* The CFA is the SP. */
++ DW_CFA_def_cfa, ULEB128_7 (29), ULEB128_7 (0),
++ };
++
++ abi_info->initial_instructions = abi_cfi;
++ abi_info->initial_instructions_end = &abi_cfi[sizeof abi_cfi];
++ abi_info->data_alignment_factor = 4;
++
++ abi_info->return_address_register = 31; /* $31 */
++
++ return 0;
++}
+diff --git a/backends/mips_init.c b/backends/mips_init.c
+index 8482e7f..bce5abe 100644
+--- a/backends/mips_init.c
++++ b/backends/mips_init.c
+@@ -50,6 +50,7 @@ mips_init (Elf *elf __attribute__ ((unused)),
+ HOOK (eh, reloc_simple_type);
+ HOOK (eh, return_value_location);
+ HOOK (eh, register_info);
++ HOOK (eh, abi_cfi);
+
+ return MODVERSION;
+ }
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/mips_readelf_w.patch b/meta/recipes-devtools/elfutils/files/debian/mips_readelf_w.patch
new file mode 100644
index 0000000000..c6d42e163a
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/mips_readelf_w.patch
@@ -0,0 +1,31 @@
+From 7bdc83296865cf2b2a5615dbdb7ac0d441fb1849 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 16:55:01 +0800
+Subject: [PATCH] mips_readelf_w
+
+Upstream-Status: Pending [from debian]
+
+Rebase to 0.177
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ src/readelf.c | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/readelf.c b/src/readelf.c
+index 2084fb1..5c02a9b 100644
+--- a/src/readelf.c
++++ b/src/readelf.c
+@@ -11256,7 +11256,8 @@ print_debug (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr)
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+
+- if (shdr != NULL && shdr->sh_type == SHT_PROGBITS)
++ if (shdr != NULL && (
++ (shdr->sh_type == SHT_PROGBITS) || (shdr->sh_type == SHT_MIPS_DWARF)))
+ {
+ static const struct
+ {
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/debian/testsuite-ignore-elflint.diff b/meta/recipes-devtools/elfutils/files/debian/testsuite-ignore-elflint.diff
new file mode 100644
index 0000000000..e6d7948c67
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/debian/testsuite-ignore-elflint.diff
@@ -0,0 +1,52 @@
+From 6393b0e57872b3ffedf0dbd6784cd29694010878 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Wed, 21 Aug 2019 16:59:01 +0800
+Subject: [PATCH 1/2] testsuite-ignore-elflint
+
+Upstream-Status: Pending [from debian]
+
+Rebase to 0.177
+
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ tests/run-elflint-self.sh | 2 +-
+ tests/test-subr.sh | 15 +++++++++++++++
+ 2 files changed, 16 insertions(+), 1 deletion(-)
+
+diff --git a/tests/run-elflint-self.sh b/tests/run-elflint-self.sh
+index 58fa7d0..85d21a5 100755
+--- a/tests/run-elflint-self.sh
++++ b/tests/run-elflint-self.sh
+@@ -18,5 +18,5 @@
+
+ . $srcdir/test-subr.sh
+
+-testrun_on_self ${abs_top_builddir}/src/elflint --quiet --gnu-ld
++testrun_on_self_skip ${abs_top_builddir}/src/elflint --quiet --gnu-ld
+ testrun_on_self_compressed ${abs_top_builddir}/src/elflint --quiet --gnu-ld
+diff --git a/tests/test-subr.sh b/tests/test-subr.sh
+index 09f428d..26f61f1 100644
+--- a/tests/test-subr.sh
++++ b/tests/test-subr.sh
+@@ -201,3 +201,18 @@ testrun_on_self_quiet()
+ # Only exit if something failed
+ if test $exit_status != 0; then exit $exit_status; fi
+ }
++
++# Same as testrun_on_self(), but skip on failure.
++testrun_on_self_skip()
++{
++ exit_status=0
++
++ for file in $self_test_files; do
++ testrun $* $file \
++ || { echo "*** failure in $* $file"; exit_status=77; }
++ done
++
++ # Only exit if something failed
++ if test $exit_status != 0; then exit $exit_status; fi
++}
++
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/musl-libs.patch b/meta/recipes-devtools/elfutils/files/musl-libs.patch
new file mode 100644
index 0000000000..b9b9f120df
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/musl-libs.patch
@@ -0,0 +1,144 @@
+From d5a1651df9884fcf57ed320bc2f866538af2f420 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 23 Aug 2019 10:18:47 +0800
+Subject: [PATCH 2/3] musl-libs
+
+Collection of fixes needed to compile libelf and other libraries
+provided by elfutils for musl targets
+
+error is glibc specific API, so this patch will mostly not accepted
+upstream given that elfutils has been closely tied to glibc
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Upstream-Status: Inappropriate [workaround for musl]
+
+Rebase to 0.177
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ lib/error.h | 27 +++++++++++++++++++++++++++
+ lib/fixedsizehash.h | 1 -
+ lib/libeu.h | 1 +
+ libdwfl/dwfl_error.c | 9 +++++++++
+ libdwfl/linux-kernel-modules.c | 1 +
+ libelf/elf.h | 9 ++++++---
+ 6 files changed, 44 insertions(+), 4 deletions(-)
+ create mode 100644 lib/error.h
+
+diff --git a/lib/error.h b/lib/error.h
+new file mode 100644
+index 0000000..ef06827
+--- /dev/null
++++ b/lib/error.h
+@@ -0,0 +1,27 @@
++#ifndef _ERROR_H_
++#define _ERROR_H_
++
++#include <stdarg.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <errno.h>
++
++static unsigned int error_message_count = 0;
++
++static inline void error(int status, int errnum, const char* format, ...)
++{
++ va_list ap;
++ fprintf(stderr, "%s: ", program_invocation_name);
++ va_start(ap, format);
++ vfprintf(stderr, format, ap);
++ va_end(ap);
++ if (errnum)
++ fprintf(stderr, ": %s", strerror(errnum));
++ fprintf(stderr, "\n");
++ error_message_count++;
++ if (status)
++ exit(status);
++}
++
++#endif /* _ERROR_H_ */
+diff --git a/lib/fixedsizehash.h b/lib/fixedsizehash.h
+index dac2a5f..43016fc 100644
+--- a/lib/fixedsizehash.h
++++ b/lib/fixedsizehash.h
+@@ -30,7 +30,6 @@
+ #include <errno.h>
+ #include <stdlib.h>
+ #include <string.h>
+-#include <sys/cdefs.h>
+
+ #include <system.h>
+
+diff --git a/lib/libeu.h b/lib/libeu.h
+index ecb4d01..edc85e3 100644
+--- a/lib/libeu.h
++++ b/lib/libeu.h
+@@ -29,6 +29,7 @@
+ #ifndef LIBEU_H
+ #define LIBEU_H
+
++#include "system.h"
+ #include <stddef.h>
+ #include <stdint.h>
+
+diff --git a/libdwfl/dwfl_error.c b/libdwfl/dwfl_error.c
+index 7bcf61c..11dcc8b 100644
+--- a/libdwfl/dwfl_error.c
++++ b/libdwfl/dwfl_error.c
+@@ -154,7 +154,16 @@ dwfl_errmsg (int error)
+ switch (error &~ 0xffff)
+ {
+ case OTHER_ERROR (ERRNO):
++#if defined(__GLIBC__)
+ return strerror_r (error & 0xffff, "bad", 0);
++#else
++ {
++ static __thread char buf[128] = "";
++ if (strerror_r (error & 0xffff, buf, sizeof(buf)) == 0)
++ return buf;
++ }
++ return "strerror_r() failed";
++#endif
+ case OTHER_ERROR (LIBELF):
+ return elf_errmsg (error & 0xffff);
+ case OTHER_ERROR (LIBDW):
+diff --git a/libdwfl/linux-kernel-modules.c b/libdwfl/linux-kernel-modules.c
+index d46ab5a..1c3faee 100644
+--- a/libdwfl/linux-kernel-modules.c
++++ b/libdwfl/linux-kernel-modules.c
+@@ -50,6 +50,7 @@
+ #include <sys/utsname.h>
+ #include <fcntl.h>
+ #include <unistd.h>
++#include "system.h"
+
+ /* If fts.h is included before config.h, its indirect inclusions may not
+ give us the right LFS aliases of these functions, so map them manually. */
+diff --git a/libelf/elf.h b/libelf/elf.h
+index bed273d..be228e6 100644
+--- a/libelf/elf.h
++++ b/libelf/elf.h
+@@ -21,7 +21,9 @@
+
+ #include <features.h>
+
+-__BEGIN_DECLS
++#ifdef __cplusplus
++extern "C" {
++#endif
+
+ /* Standard ELF types. */
+
+@@ -4029,6 +4031,7 @@ enum
+ #define R_NDS32_TLS_TPOFF 102
+ #define R_NDS32_TLS_DESC 119
+
+-__END_DECLS
+-
++#ifdef __cplusplus
++}
++#endif
+ #endif /* elf.h */
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/musl-obstack-fts.patch b/meta/recipes-devtools/elfutils/files/musl-obstack-fts.patch
new file mode 100644
index 0000000000..40f2b69cf4
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/musl-obstack-fts.patch
@@ -0,0 +1,128 @@
+From 77b89dbc9f9f965ad0ef2e341d7d46bce5f07549 Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 23 Aug 2019 10:17:25 +0800
+Subject: [PATCH 1/3] musl-obstack-fts
+
+Look for libfts and libobstack during configure, these
+libraries are external to libc when using musl, whereas
+on glibc these libraries are provided in libc itself.
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Upstream-Status: Inappropriate [workaround for musl]
+
+Rebase to 0.177
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ configure.ac | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ libdw/Makefile.am | 2 +-
+ src/Makefile.am | 8 ++++----
+ 3 files changed, 59 insertions(+), 5 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index f93964c..b87b762 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -494,6 +494,60 @@ else
+ fi
+ AC_SUBST([argp_LDADD])
+
++dnl Check if we have fts available from our libc
++AC_LINK_IFELSE(
++ [AC_LANG_PROGRAM(
++ [#if !defined(__x86_64__)
++ #undef _FILE_OFFSET_BITS
++ #define _FILE_OFFSET_BITS 32
++ #endif
++ #include <fts.h>],
++ [FTS* fts = 0; return fts_close(fts); return 0;]
++ )],
++ [libc_has_fts="true"],
++ [libc_has_fts="false"]
++)
++
++dnl If our libc doesn't provide fts, then test for libfts
++if test "$libc_has_fts" = "false" ; then
++ AC_MSG_WARN("libc does not have fts")
++ AC_CHECK_LIB([fts], [fts_close], [have_fts="true"], [have_fts="false"])
++
++ if test "$have_fts" = "false"; then
++ AC_MSG_ERROR("no libfts found")
++ else
++ fts_LDADD="-lfts"
++ fi
++else
++ fts_LDADD=""
++fi
++AC_SUBST([fts_LDADD])
++
++dnl Check if we have obstack available from our libc
++AC_LINK_IFELSE(
++ [AC_LANG_PROGRAM(
++ [#include <obstack.h>],
++ [_obstack_begin(0, 0, 0, NULL, NULL); return 0;]
++ )],
++ [libc_has_obstack="true"],
++ [libc_has_obstack="false"]
++)
++
++dnl If our libc doesn't provide obstack, then test for libobstack
++if test "$libc_has_obstack" = "false" ; then
++ AC_MSG_WARN("libc does not have obstack")
++ AC_CHECK_LIB([obstack], [_obstack_begin], [have_obstack="true"], [have_obstack="false"])
++
++ if test "$have_obstack" = "false"; then
++ AC_MSG_ERROR("no libobstack found")
++ else
++ obstack_LDADD="-lobstack"
++ fi
++else
++ obstack_LDADD=""
++fi
++AC_SUBST([obstack_LDADD])
++
+ dnl The directories with content.
+
+ dnl Documentation.
+diff --git a/libdw/Makefile.am b/libdw/Makefile.am
+index 7a3d532..a541fa3 100644
+--- a/libdw/Makefile.am
++++ b/libdw/Makefile.am
+@@ -108,7 +108,7 @@ am_libdw_pic_a_OBJECTS = $(libdw_a_SOURCES:.c=.os)
+ libdw_so_LIBS = libdw_pic.a ../libdwelf/libdwelf_pic.a \
+ ../libdwfl/libdwfl_pic.a ../libebl/libebl.a
+ libdw_so_DEPS = ../lib/libeu.a ../libelf/libelf.so
+-libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(zip_LIBS)
++libdw_so_LDLIBS = $(libdw_so_DEPS) -ldl -lz $(argp_LDADD) $(fts_LDADD) $(zip_LIBS)
+ libdw_so_SOURCES =
+ libdw.so$(EXEEXT): $(srcdir)/libdw.map $(libdw_so_LIBS) $(libdw_so_DEPS)
+ # The rpath is necessary for libebl because its $ORIGIN use will
+diff --git a/src/Makefile.am b/src/Makefile.am
+index b72f853..2f3dfce 100644
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -69,8 +69,8 @@ ar_no_Wstack_usage = yes
+ unstrip_no_Wstack_usage = yes
+
+ readelf_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+-nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl \
+- $(demanglelib)
++nm_LDADD = $(libdw) $(libebl) $(libelf) $(libeu) $(argp_LDADD) \
++ $(obstack_LDADD) -ldl $(demanglelib)
+ size_LDADD = $(libelf) $(libeu) $(argp_LDADD)
+ strip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl
+ elflint_LDADD = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+@@ -78,9 +78,9 @@ findtextrel_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD)
+ addr2line_LDADD = $(libdw) $(libelf) $(libeu) $(argp_LDADD) $(demanglelib)
+ elfcmp_LDADD = $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+ objdump_LDADD = $(libasm) $(libebl) $(libelf) $(libeu) $(argp_LDADD) -ldl
+-ranlib_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
++ranlib_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LDADD)
+ strings_LDADD = $(libelf) $(libeu) $(argp_LDADD)
+-ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD)
++ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LDADD)
+ unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl
+ stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) -ldl $(demanglelib)
+ elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/musl-tests.patch b/meta/recipes-devtools/elfutils/files/musl-tests.patch
new file mode 100644
index 0000000000..be35791b1a
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/musl-tests.patch
@@ -0,0 +1,29 @@
+Fix error on musl:
+
+| ../../elfutils-0.176/tests/elfstrmerge.c: In function 'main':
+| ../../elfutils-0.176/tests/elfstrmerge.c:370:60: error: 'ALLPERMS' undeclared (first use in this function); did you mean 'EPERM'?
+| fdnew = open (fnew, O_WRONLY | O_CREAT, st.st_mode & ALLPERMS);
+| ^~~~~~~~
+| EPERM
+| ../../elfutils-0.176/tests/elfstrmerge.c:370:60: note: each undeclared identifier is reported only once for each function it appears in
+
+Upstream-Status: Inappropriate [workaround in musl]
+
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+Index: elfutils-0.176/tests/elfstrmerge.c
+===================================================================
+--- elfutils-0.176.orig/tests/elfstrmerge.c
++++ elfutils-0.176/tests/elfstrmerge.c
+@@ -33,6 +33,11 @@
+ #include ELFUTILS_HEADER(dwelf)
+ #include "elf-knowledge.h"
+
++/* for musl */
++#ifndef ALLPERMS
++# define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO)/* 07777 */
++#endif
++
+ /* The original ELF file. */
+ static int fd = -1;
+ static Elf *elf = NULL;
diff --git a/meta/recipes-devtools/elfutils/files/musl-utils.patch b/meta/recipes-devtools/elfutils/files/musl-utils.patch
new file mode 100644
index 0000000000..a8ad931236
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/musl-utils.patch
@@ -0,0 +1,165 @@
+From 7f5e2fd86d54e0a4d195ec65afb9b411829dff9f Mon Sep 17 00:00:00 2001
+From: Hongxu Jia <hongxu.jia@windriver.com>
+Date: Fri, 23 Aug 2019 10:19:48 +0800
+Subject: [PATCH 3/3] musl-utils
+
+Provide missing defines which otherwise are available on glibc system headers
+
+Alter the error API to match posix version
+use qsort instead of qsort_r which is glibc specific API
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+Upstream-Status: Inappropriate [workaround for musl]
+
+Rebase to 0.177
+Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
+---
+ src/arlib.h | 6 ++++++
+ src/elfcompress.c | 7 +++++++
+ src/readelf.c | 20 ++++++++++++--------
+ src/strip.c | 7 +++++++
+ src/unstrip.c | 9 +++++++++
+ 5 files changed, 41 insertions(+), 8 deletions(-)
+
+diff --git a/src/arlib.h b/src/arlib.h
+index e117166..8326f6c 100644
+--- a/src/arlib.h
++++ b/src/arlib.h
+@@ -29,6 +29,12 @@
+ #include <stdint.h>
+ #include <sys/types.h>
+
++#if !defined(ALLPERMS)
++# define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
++#endif
++#if !defined(DEFFILEMODE)
++# define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666*/
++#endif
+
+ /* State of -D/-U flags. */
+ extern bool arlib_deterministic_output;
+diff --git a/src/elfcompress.c b/src/elfcompress.c
+index 6ba6af4..0c7674b 100644
+--- a/src/elfcompress.c
++++ b/src/elfcompress.c
+@@ -37,6 +37,13 @@
+ #include "libeu.h"
+ #include "printversion.h"
+
++#if !defined(ALLPERMS)
++# define ALLPERMS (S_ISUID|S_ISGID|S_ISVTX|S_IRWXU|S_IRWXG|S_IRWXO) /* 07777 */
++#endif
++#if !defined(FNM_EXTMATCH)
++# define FNM_EXTMATCH (0)
++#endif
++
+ /* Name and version of program. */
+ ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
+
+diff --git a/src/readelf.c b/src/readelf.c
+index 5c02a9b..817562d 100644
+--- a/src/readelf.c
++++ b/src/readelf.c
+@@ -4813,10 +4813,11 @@ listptr_base (struct listptr *p)
+ return cudie_base (&cu);
+ }
+
++static const char *listptr_name;
++
+ static int
+-compare_listptr (const void *a, const void *b, void *arg)
++compare_listptr (const void *a, const void *b)
+ {
+- const char *name = arg;
+ struct listptr *p1 = (void *) a;
+ struct listptr *p2 = (void *) b;
+
+@@ -4832,21 +4833,21 @@ compare_listptr (const void *a, const void *b, void *arg)
+ p1->warned = p2->warned = true;
+ error (0, 0,
+ gettext ("%s %#" PRIx64 " used with different address sizes"),
+- name, (uint64_t) p1->offset);
++ listptr_name, (uint64_t) p1->offset);
+ }
+ if (p1->dwarf64 != p2->dwarf64)
+ {
+ p1->warned = p2->warned = true;
+ error (0, 0,
+ gettext ("%s %#" PRIx64 " used with different offset sizes"),
+- name, (uint64_t) p1->offset);
++ listptr_name, (uint64_t) p1->offset);
+ }
+ if (listptr_base (p1) != listptr_base (p2))
+ {
+ p1->warned = p2->warned = true;
+ error (0, 0,
+ gettext ("%s %#" PRIx64 " used with different base addresses"),
+- name, (uint64_t) p1->offset);
++ listptr_name, (uint64_t) p1->offset);
+ }
+ if (p1->attr != p2 ->attr)
+ {
+@@ -4854,7 +4855,7 @@ compare_listptr (const void *a, const void *b, void *arg)
+ error (0, 0,
+ gettext ("%s %#" PRIx64
+ " used with different attribute %s and %s"),
+- name, (uint64_t) p1->offset, dwarf_attr_name (p2->attr),
++ listptr_name, (uint64_t) p1->offset, dwarf_attr_name (p2->attr),
+ dwarf_attr_name (p2->attr));
+ }
+ }
+@@ -4926,8 +4927,11 @@ static void
+ sort_listptr (struct listptr_table *table, const char *name)
+ {
+ if (table->n > 0)
+- qsort_r (table->table, table->n, sizeof table->table[0],
+- &compare_listptr, (void *) name);
++ {
++ listptr_name = name;
++ qsort (table->table, table->n, sizeof table->table[0],
++ &compare_listptr);
++ }
+ }
+
+ static bool
+diff --git a/src/strip.c b/src/strip.c
+index 4054c2a..d2d2176 100644
+--- a/src/strip.c
++++ b/src/strip.c
+@@ -46,6 +46,13 @@
+ #include <system.h>
+ #include <printversion.h>
+
++#if !defined(ACCESSPERMS)
++# define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 0777 */
++#endif
++#if !defined(FNM_EXTMATCH)
++# define FNM_EXTMATCH (0)
++#endif
++
+ typedef uint8_t GElf_Byte;
+
+ /* Name and version of program. */
+diff --git a/src/unstrip.c b/src/unstrip.c
+index fc87832..21ea6b3 100644
+--- a/src/unstrip.c
++++ b/src/unstrip.c
+@@ -56,6 +56,15 @@
+ # define _(str) gettext (str)
+ #endif
+
++#ifndef strndupa
++#define strndupa(s, n) \
++ ({const char *__in = (s); \
++ size_t __len = strnlen (__in, (n)) + 1; \
++ char *__out = (char *) alloca (__len); \
++ __out[__len-1] = '\0'; \
++ (char *) memcpy (__out, __in, __len-1);})
++#endif
++
+ /* Name and version of program. */
+ ARGP_PROGRAM_VERSION_HOOK_DEF = print_version;
+
+--
+2.7.4
+
diff --git a/meta/recipes-devtools/elfutils/files/ptest.patch b/meta/recipes-devtools/elfutils/files/ptest.patch
new file mode 100644
index 0000000000..35b23f43b3
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/ptest.patch
@@ -0,0 +1,76 @@
+Changes to allow ptest to run standalone on target:
+
+a) Run the tests serially
+b) Use the standalone test mode which allows the tests to be run in their
+ 'installled' locations on target (but not any of the standalone build pieces)
+c) We want to use the binaries from their installed locations so the run-subr
+ script needs tweaking to run them like that. The rpath conditional isn't
+ enough since we want the second entry in the case statement.
+d) Add an oecheck make target which we can use to build the test binaries we need
+
+Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
+
+Upstream-Status: Inappropriate [oe specific]
+
+Index: elfutils-0.176/configure.ac
+===================================================================
+--- elfutils-0.176.orig/configure.ac
++++ elfutils-0.176/configure.ac
+@@ -45,7 +45,7 @@ AC_COPYRIGHT([Copyright (C) 1996-2018 Th
+ AC_PREREQ(2.63) dnl Minimum Autoconf version required.
+
+ dnl We use GNU make extensions; automake 1.10 defaults to -Wportability.
+-AM_INIT_AUTOMAKE([gnits 1.11 -Wno-portability dist-bzip2 no-dist-gzip parallel-tests])
++AM_INIT_AUTOMAKE([gnits 1.11 -Wno-portability dist-bzip2 no-dist-gzip serial-tests])
+ AM_MAINTAINER_MODE
+
+ AM_SILENT_RULES([yes])
+Index: elfutils-0.176/tests/Makefile.am
+===================================================================
+--- elfutils-0.176.orig/tests/Makefile.am
++++ elfutils-0.176/tests/Makefile.am
+@@ -445,10 +445,10 @@ installed_TESTS_ENVIRONMENT = libdir=$(D
+ installed_LOG_COMPILER = $(abs_srcdir)/test-wrapper.sh \
+ installed $(tests_rpath) \
+ '$(program_transform_name)'
+-if STANDALONE
++if !STANDALONE
+ TESTS_ENVIRONMENT = $(installed_TESTS_ENVIRONMENT)
+ LOG_COMPILER = $(installed_LOG_COMPILER)
+-else !STANDALONE
++else STANDALONE
+ TESTS_ENVIRONMENT = LC_ALL=C; LANG=C; VALGRIND_CMD=$(valgrind_cmd); \
+ abs_srcdir=$(abs_srcdir); abs_builddir=$(abs_builddir); \
+ abs_top_builddir=$(abs_top_builddir); \
+@@ -463,7 +463,7 @@ installcheck-local:
+ $(MAKE) $(AM_MAKEFLAGS) \
+ TESTS_ENVIRONMENT="$(installed_TESTS_ENVIRONMENT)" \
+ LOG_COMPILER="$(installed_LOG_COMPILER)" check-TESTS
+-endif !STANDALONE
++endif STANDALONE
+
+ if STANDALONE
+ libdw = -ldw
+@@ -612,3 +612,5 @@ check: check-am coverage
+ coverage:
+ -$(srcdir)/coverage.sh
+ endif
++oecheck:
++ $(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
+Index: elfutils-0.176/tests/test-subr.sh
+===================================================================
+--- elfutils-0.176.orig/tests/test-subr.sh
++++ elfutils-0.176/tests/test-subr.sh
+@@ -91,12 +91,6 @@ installed_testrun()
+ program="$1"
+ shift
+ case "$program" in
+- ${abs_builddir}/*)
+- if [ "x$elfutils_tests_rpath" != xno ]; then
+- echo >&2 installcheck not possible with --enable-tests-rpath
+- exit 77
+- fi
+- ;;
+ ${abs_top_builddir}/src/*)
+ program=${bindir}/`program_transform ${program##*/}`
+ ;;
diff --git a/meta/recipes-devtools/elfutils/files/run-ptest b/meta/recipes-devtools/elfutils/files/run-ptest
new file mode 100644
index 0000000000..81b81f2f5d
--- /dev/null
+++ b/meta/recipes-devtools/elfutils/files/run-ptest
@@ -0,0 +1,6 @@
+#!/bin/sh
+#
+#This script is used to run elfutils test suites
+cd tests
+
+make -k runtest-TESTS abs_srcdir=$PWD abs_builddir=$PWD srcdir=$PWD top_srcdir=$PWD/../ abs_top_builddir=$PWD/../ elfutils_testrun=installed elfutils_tests_rpath=no program_transform_name=s,^,eu-,