elfutils: upgraded package to upstream

Upgraded dev-libs/elfutils to version 0.185 on amd64, arm, arm64

We also backported two patches from elfutils mainline to allow
builds with Clang. Created a Gentoo PR to add those patches
upstream as well: https://github.com/gentoo/gentoo/pull/22173

BUG=b:186803608
TEST=Local builds on amd64, arm64, arm; CQ

Change-Id: If8e6e4d0af66bc6cde1a6af702ae9ee629ccaf60
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/overlays/portage-stable/+/3140200
Reviewed-by: Manoj Gupta <manojgupta@chromium.org>
Tested-by: Manoj Gupta <manojgupta@chromium.org>
Commit-Queue: Manoj Gupta <manojgupta@chromium.org>
diff --git a/dev-libs/elfutils/Manifest b/dev-libs/elfutils/Manifest
index a17eef8..346d253 100644
--- a/dev-libs/elfutils/Manifest
+++ b/dev-libs/elfutils/Manifest
@@ -1 +1 @@
-DIST elfutils-0.182.tar.bz2 9096742 BLAKE2B 59efd76c921a90a5ac18a62a00845080b574f167ae633d32b14acce554523736d0ccfdf539ba61e8ec1511b3294b486e0fa512887582a2e5cc34e71954e87e73 SHA512 8ab0735bbe11b4383169341bf674ace360038b6ae5239f1d5a991c46260cd4bce545e078735b7de3b8fab132bb5da41f60689ff1b1d7ebccfada117a954a2c81
+DIST elfutils-0.185.tar.bz2 9187627 BLAKE2B 57cfa7e4060975c4bf6170dbd354687a19a92f7069c060db1ac2fa4da5a9d34e8bddd07c7ce376b5c28b5670ad5b8c1df795164cbcfb600a44cf1db60c20c4af SHA512 34de0de1355b11740e036e0fc64f2fc063587c8eb121b19216ee5548d3f0f268d8fc3995176c47190466b9d881007cfa11a9d01e9a50e38af6119492bf8bb47f
diff --git a/dev-libs/elfutils/elfutils-0.182.ebuild b/dev-libs/elfutils/elfutils-0.185.ebuild
similarity index 88%
rename from dev-libs/elfutils/elfutils-0.182.ebuild
rename to dev-libs/elfutils/elfutils-0.185.ebuild
index e9e78b1..8974965 100644
--- a/dev-libs/elfutils/elfutils-0.182.ebuild
+++ b/dev-libs/elfutils/elfutils-0.185.ebuild
@@ -1,9 +1,9 @@
-# Copyright 2003-2020 Gentoo Authors
+# Copyright 2003-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=7
 
-inherit flag-o-matic multilib-minimal toolchain-funcs
+inherit flag-o-matic multilib-minimal
 
 DESCRIPTION="Libraries/utilities to handle ELF objects (drop in replacement for libelf)"
 HOMEPAGE="http://elfutils.org/"
@@ -33,8 +33,9 @@
 	"${FILESDIR}"/${PN}-0.175-disable-biarch-test-PR24158.patch
 	"${FILESDIR}"/${PN}-0.177-disable-large.patch
 	"${FILESDIR}"/${PN}-0.180-PaX-support.patch
-	"${FILESDIR}"/${PN}-0.179-CC-in-tests.patch
-	"${FILESDIR}"/${PN}-0.181-CC-in-tests-p2.patch
+	"${FILESDIR}"/${PN}-0.185-static-inline.patch
+	"${FILESDIR}"/${PN}-0.185-pull-advance_pc-in-file-scope.patch
+	"${FILESDIR}"/${PN}-0.185-configure.ac-rework-gnu99-ext-check-to-allow-clang.patch
 )
 
 src_prepare() {
@@ -72,10 +73,8 @@
 }
 
 multilib_src_test() {
-	# CC is a workaround for tests using ${CC-gcc}
 	env	LD_LIBRARY_PATH="${BUILD_DIR}/libelf:${BUILD_DIR}/libebl:${BUILD_DIR}/libdw:${BUILD_DIR}/libasm" \
 		LC_ALL="C" \
-		CC="$(tc-getCC)" \
 		emake check VERBOSE=1
 }
 
diff --git a/dev-libs/elfutils/files/elfutils-0.179-CC-in-tests.patch b/dev-libs/elfutils/files/elfutils-0.179-CC-in-tests.patch
deleted file mode 100644
index aa58862..0000000
--- a/dev-libs/elfutils/files/elfutils-0.179-CC-in-tests.patch
+++ /dev/null
@@ -1,45 +0,0 @@
-https://bugs.gentoo.org/718872
---- a/tests/run-disasm-x86-64.sh
-+++ b/tests/run-disasm-x86-64.sh
-@@ -22,7 +22,7 @@ case "`uname -m`" in
-   x86_64)
-     tempfiles testfile45.o
-     testfiles testfile45.S testfile45.expect
--    gcc -m64 -c -o testfile45.o testfile45.S
-+    ${CC-gcc} -m64 -c -o testfile45.o testfile45.S
-     testrun_compare ${abs_top_builddir}/src/objdump -d testfile45.o < testfile45.expect
-     ;;
- esac
---- a/tests/run-disasm-x86.sh
-+++ b/tests/run-disasm-x86.sh
-@@ -22,7 +22,7 @@ case "`uname -m`" in
-   x86_64 | i?86 )
-     tempfiles testfile44.o
-     testfiles testfile44.S testfile44.expect
--    gcc -m32 -c -o testfile44.o testfile44.S
-+    ${CC-gcc} -m32 -c -o testfile44.o testfile44.S
-     testrun_compare ${abs_top_builddir}/src/objdump -d testfile44.o < testfile44.expect
-     ;;
- esac
---- a/tests/run-strip-g.sh
-+++ b/tests/run-strip-g.sh
-@@ -25,7 +25,7 @@
- tempfiles a.out strip.out debug.out readelf.out
- 
- echo Create debug a.out.
--echo "int main() { return 1; }" | gcc -g -xc -
-+echo "int main() { return 1; }" | ${CC-gcc} -g -xc -
- 
- echo strip -g to file with debug file
- testrun ${abs_top_builddir}/src/strip -g -o strip.out -f debug.out ||
---- a/tests/run-strip-nothing.sh
-+++ b/tests/run-strip-nothing.sh
-@@ -23,7 +23,7 @@
- tempfiles a.out strip.out debug.out
- 
- # Create no-debug a.out.
--echo "int main() { return 1; }" | gcc -s -xc -
-+echo "int main() { return 1; }" | ${CC-gcc} -s -xc -
- 
- # strip to file
- testrun ${abs_top_builddir}/src/strip -g -o strip.out ||
diff --git a/dev-libs/elfutils/files/elfutils-0.181-CC-in-tests-p2.patch b/dev-libs/elfutils/files/elfutils-0.181-CC-in-tests-p2.patch
deleted file mode 100644
index 63c0ed0..0000000
--- a/dev-libs/elfutils/files/elfutils-0.181-CC-in-tests-p2.patch
+++ /dev/null
@@ -1,34 +0,0 @@
---- a/tests/run-test-includes.sh
-+++ b/tests/run-test-includes.sh
-@@ -3,24 +3,24 @@
- . $srcdir/test-subr.sh
- 
- echo '#include "libelf.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf -xc -
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf -xc -
- echo '#include "gelf.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf -xc -
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf -xc -
- 
- echo '#include "dwarf.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf \
-         -I ${abs_srcdir}/../libdw -xc -
- echo '#include "libdw.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf \
-         -I ${abs_srcdir}/../libdw -xc -
- 
- echo '#include "libdwfl.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf \
-     -I ${abs_srcdir}/../libdw -I ${abs_srcdir}/../libdwfl -xc -
- echo '#include "libdwelf.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf \
-     -I ${abs_srcdir}/../libdw -I ${abs_srcdir}/../libdwelf -xc -
- 
- echo '#include "libasm.h"' \
--  | gcc -c -o /dev/null -I ${abs_srcdir}/../libelf \
-+  | ${CC-gcc} -c -o /dev/null -I ${abs_srcdir}/../libelf \
-     -I ${abs_srcdir}/../libasm -xc -
diff --git a/dev-libs/elfutils/files/elfutils-0.185-configure.ac-rework-gnu99-ext-check-to-allow-clang.patch b/dev-libs/elfutils/files/elfutils-0.185-configure.ac-rework-gnu99-ext-check-to-allow-clang.patch
new file mode 100644
index 0000000..fe0b111
--- /dev/null
+++ b/dev-libs/elfutils/files/elfutils-0.185-configure.ac-rework-gnu99-ext-check-to-allow-clang.patch
@@ -0,0 +1,146 @@
+From c9ff5c53c319f963cac34a41c86cd43edf902459 Mon Sep 17 00:00:00 2001
+From: Adrian Ratiu <adrian.ratiu@collabora.com>
+Date: Mon, 30 Aug 2021 18:43:13 +0300
+Subject: [PATCH] configure.ac: rework gnu99 ext check to allow clang
+
+It is true that Clang does not support all gnu99 extensions [1],
+but not all of them are used in the codebase and over time there
+have been code cleanup efforts to improve Clang support.
+
+For example after commit 779c57ea ("readelf: Pull advance_pc()
+in file scope") there are no more nested function declarations
+and elfutils now builds fine with Clang.
+
+So in the interest of enabling Clang builds we remove the only
+remaining blocker: the configure checks for nested functions and
+variable length arrays which are also unused.
+
+Considering mixed decls and code is also part of c99 standard,
+the entire check becomes redundant and we can just replace
+AC_PROG_CC -> AC_PROG_CC_C99.
+
+Upstream-Status: Backport [master commit 6eb991a9]
+
+[1] https://sourceware.org/bugzilla/show_bug.cgi?id=24964
+[Adrian: backported to v0.185]
+Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
+---
+ configure    | 48 ------------------------------------------------
+ configure.ac | 35 +----------------------------------
+ 2 files changed, 1 insertion(+), 82 deletions(-)
+
+diff --git a/configure b/configure
+index 4ea75ee..22bda6c 100755
+--- a/configure
++++ b/configure
+@@ -5162,54 +5162,6 @@ else
+ fi
+ 
+ 
+-# We use -std=gnu99 but have explicit checks for some language constructs
+-# and GNU extensions since some compilers claim GNU99 support, but don't
+-# really support all language extensions. In particular we need
+-# Mixed Declarations and Code
+-# https://gcc.gnu.org/onlinedocs/gcc/Mixed-Declarations.html
+-# Nested Functions
+-# https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
+-# Arrays of Variable Length
+-# https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for gcc with GNU99 support" >&5
+-$as_echo_n "checking for gcc with GNU99 support... " >&6; }
+-if ${ac_cv_c99+:} false; then :
+-  $as_echo_n "(cached) " >&6
+-else
+-  old_CFLAGS="$CFLAGS"
+-CFLAGS="$CFLAGS -std=gnu99"
+-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+-/* end confdefs.h.  */
+-int foo (int a)
+-{
+-  for (int i = 0; i < a; ++i) if (i % 4) break; int s = a; return s;
+-}
+-
+-double bar (double a, double b)
+-{
+-  double square (double z) { return z * z; }
+-  return square (a) + square (b);
+-}
+-
+-void baz (int n)
+-{
+-  struct S { int x[n]; };
+-}
+-_ACEOF
+-if ac_fn_c_try_compile "$LINENO"; then :
+-  ac_cv_c99=yes
+-else
+-  ac_cv_c99=no
+-fi
+-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+-CFLAGS="$old_CFLAGS"
+-fi
+-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c99" >&5
+-$as_echo "$ac_cv_c99" >&6; }
+-if test "x$ac_cv_c99" != xyes; then :
+-  as_fn_error $? "gcc with GNU99 support required" "$LINENO" 5
+-fi
+-
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether gcc supports __attribute__((visibility()))" >&5
+ $as_echo_n "checking whether gcc supports __attribute__((visibility()))... " >&6; }
+ if ${ac_cv_visibility+:} false; then :
+diff --git a/configure.ac b/configure.ac
+index b348a71..6298547 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -87,7 +87,7 @@ AS_IF([test "$use_locks" = yes],
+ 
+ AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.])
+ 
+-AC_PROG_CC
++AC_PROG_CC_C99
+ AC_PROG_RANLIB
+ AC_PROG_YACC
+ AM_PROG_LEX
+@@ -96,39 +96,6 @@ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+ AC_CHECK_TOOL([READELF], [readelf])
+ AC_CHECK_TOOL([NM], [nm])
+ 
+-# We use -std=gnu99 but have explicit checks for some language constructs
+-# and GNU extensions since some compilers claim GNU99 support, but don't
+-# really support all language extensions. In particular we need
+-# Mixed Declarations and Code
+-# https://gcc.gnu.org/onlinedocs/gcc/Mixed-Declarations.html
+-# Nested Functions
+-# https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html
+-# Arrays of Variable Length
+-# https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html
+-AC_CACHE_CHECK([for gcc with GNU99 support], ac_cv_c99, [dnl
+-old_CFLAGS="$CFLAGS"
+-CFLAGS="$CFLAGS -std=gnu99"
+-AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+-int foo (int a)
+-{
+-  for (int i = 0; i < a; ++i) if (i % 4) break; int s = a; return s;
+-}
+-
+-double bar (double a, double b)
+-{
+-  double square (double z) { return z * z; }
+-  return square (a) + square (b);
+-}
+-
+-void baz (int n)
+-{
+-  struct S { int x[[n]]; };
+-}])],
+-		  ac_cv_c99=yes, ac_cv_c99=no)
+-CFLAGS="$old_CFLAGS"])
+-AS_IF([test "x$ac_cv_c99" != xyes],
+-      AC_MSG_ERROR([gcc with GNU99 support required]))
+-
+ AC_CACHE_CHECK([whether gcc supports __attribute__((visibility()))],
+ 	ac_cv_visibility, [dnl
+ save_CFLAGS="$CFLAGS"
+-- 
+2.33.0
+
diff --git a/dev-libs/elfutils/files/elfutils-0.185-pull-advance_pc-in-file-scope.patch b/dev-libs/elfutils/files/elfutils-0.185-pull-advance_pc-in-file-scope.patch
new file mode 100644
index 0000000..e0678c9
--- /dev/null
+++ b/dev-libs/elfutils/files/elfutils-0.185-pull-advance_pc-in-file-scope.patch
@@ -0,0 +1,70 @@
+From 779c57ea864d104bad88455535df9b26336349fd Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder@redhat.com>
+Date: Thu, 18 Mar 2021 10:25:24 +0100
+Subject: [PATCH] readelf: Pull advance_pc() in file scope
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Make advance_pc() a static function so we can get rid of another nested
+function. Rename it to run_advance_pc() and use a local advance_pc()
+macro to pass all the local variables. This is similar to what the
+equivalent code in libdw/dwarf_getsrclines.c is doing.
+
+Upstream-Status: Backport [master commit 779c57ea]
+
+Signed-off-by: Timm Bäder <tbaeder@redhat.com>
+[Adrian: backported to v0.185]
+Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
+---
+ src/ChangeLog |  7 +++++++
+ src/readelf.c | 26 +++++++++++++++++++-------
+ 2 files changed, 26 insertions(+), 7 deletions(-)
+
+diff --git a/src/readelf.c b/src/readelf.c
+index 161d7e65..8191bde2 100644
+--- a/src/readelf.c
++++ b/src/readelf.c
+@@ -8373,6 +8373,23 @@ print_form_data (Dwarf *dbg, int form, const unsigned char *readp,
+   return readp;
+ }
+ 
++/* Only used via run_advance_pc() macro */
++static inline void
++run_advance_pc (unsigned int op_advance,
++                unsigned int minimum_instr_len,
++                unsigned int max_ops_per_instr,
++                unsigned int *op_addr_advance,
++                Dwarf_Word *address,
++                unsigned int *op_index)
++{
++  const unsigned int advanced_op_index = (*op_index) + op_advance;
++
++  *op_addr_advance = minimum_instr_len * (advanced_op_index
++                                         / max_ops_per_instr);
++  *address = *address + *op_addr_advance;
++  *op_index = advanced_op_index % max_ops_per_instr;
++}
++
+ static void
+ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
+ 			  Elf_Scn *scn, GElf_Shdr *shdr, Dwarf *dbg)
+@@ -8763,13 +8780,8 @@ print_debug_line_section (Dwfl_Module *dwflmod, Ebl *ebl, GElf_Ehdr *ehdr,
+       /* Apply the "operation advance" from a special opcode
+ 	 or DW_LNS_advance_pc (as per DWARF4 6.2.5.1).  */
+       unsigned int op_addr_advance;
+-      inline void advance_pc (unsigned int op_advance)
+-      {
+-	op_addr_advance = minimum_instr_len * ((op_index + op_advance)
+-					       / max_ops_per_instr);
+-	address += op_addr_advance;
+-	op_index = (op_index + op_advance) % max_ops_per_instr;
+-      }
++#define advance_pc(op_advance) run_advance_pc(op_advance, minimum_instr_len, \
++                      max_ops_per_instr, &op_addr_advance, &address, &op_index)
+ 
+       if (max_ops_per_instr == 0)
+ 	{
+-- 
+2.32.0
+
diff --git a/dev-libs/elfutils/files/elfutils-0.185-static-inline.patch b/dev-libs/elfutils/files/elfutils-0.185-static-inline.patch
new file mode 100644
index 0000000..ec1aaf4
--- /dev/null
+++ b/dev-libs/elfutils/files/elfutils-0.185-static-inline.patch
@@ -0,0 +1,12 @@
+https://bugs.gentoo.org/794601
+--- a/src/elflint.c
++++ b/src/elflint.c
+@@ -3434,7 +3434,7 @@ buffer_pos (Elf_Data *data, const unsigned char *p)
+   return p - (const unsigned char *) data->d_buf;
+ }
+ 
+-inline size_t
++static inline size_t
+ buffer_left (Elf_Data *data, const unsigned char *p)
+ {
+   return (const unsigned char *) data->d_buf + data->d_size - p;
diff --git a/metadata/md5-cache/dev-libs/elfutils-0.182 b/metadata/md5-cache/dev-libs/elfutils-0.185
similarity index 96%
rename from metadata/md5-cache/dev-libs/elfutils-0.182
rename to metadata/md5-cache/dev-libs/elfutils-0.185
index 2139ee6..3d3bc2e 100644
--- a/metadata/md5-cache/dev-libs/elfutils-0.182
+++ b/metadata/md5-cache/dev-libs/elfutils-0.185
@@ -10,6 +10,6 @@
 RDEPEND=>=sys-libs/zlib-1.2.8-r1[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] bzip2? ( >=app-arch/bzip2-1.0.6-r4[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) lzma? ( >=app-arch/xz-utils-5.0.5-r1[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) zstd? ( app-arch/zstd:=[static-libs?,abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?,abi_arm_32(-)?,abi_arm_64(-)?] ) !dev-libs/libelf
 RESTRICT=!test? ( test )
 SLOT=0
-SRC_URI=https://sourceware.org/elfutils/ftp/0.182/elfutils-0.182.tar.bz2
+SRC_URI=https://sourceware.org/elfutils/ftp/0.185/elfutils-0.185.tar.bz2
 _eclasses_=eutils	fcb2aa98e1948b835b5ae66ca52868c5	flag-o-matic	5d5921a298e95441da2f85be419894c0	multibuild	40fe59465edacd730c644ec2bc197809	multilib	2477ebe553d3e4d2c606191fe6c33602	multilib-build	1979aa0ff4d356d32507ca4650d9f37d	multilib-minimal	8bddda43703ba94d8341f4e247f97566	toolchain-funcs	605c126bed8d87e4378d5ff1645330cb
-_md5_=a13325cbe8b902df764bbf27f0f9b132
+_md5_=412a6d207598d7258afe90d022c7c13b