ASR_BASE
Change-Id: Icf3719cc0afe3eeb3edc7fa80a2eb5199ca9dda1
diff --git a/tools/elfutils/patches/100-portability.patch b/tools/elfutils/patches/100-portability.patch
new file mode 100644
index 0000000..2cc8a4c
--- /dev/null
+++ b/tools/elfutils/patches/100-portability.patch
@@ -0,0 +1,300 @@
+--- a/configure.ac
++++ b/configure.ac
+@@ -44,6 +44,7 @@ fi
+
+ AC_CONFIG_AUX_DIR([config])
+ AC_CONFIG_FILES([config/Makefile])
++AC_CONFIG_FILES([libgnu/Makefile])
+
+ AC_COPYRIGHT([Copyright (C) 1996-2024 The elfutils developers.])
+ AC_PREREQ(2.63) dnl Minimum Autoconf version required.
+@@ -88,11 +89,14 @@ AS_IF([test "$use_locks" = yes],
+
+ AH_TEMPLATE([USE_LOCKS], [Defined if libraries should be thread-safe.])
+
++AC_USE_SYSTEM_EXTENSIONS()
++
+ m4_version_prereq([2.70], [AC_PROG_CC], [AC_PROG_CC_C99])
+ AC_PROG_CXX
+ AC_PROG_RANLIB
+ AC_PROG_YACC
+ AC_PROG_LEX([noyywrap])
++gl_EARLY
+ # Only available since automake 1.12
+ m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+ AC_CHECK_TOOL([READELF], [readelf])
+@@ -635,6 +639,8 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+ CFLAGS="$old_CFLAGS"])
+ AS_IF([test "x$ac_cv_fno_addrsig" = "xyes"], CFLAGS="$CFLAGS -fno-addrsig")
+
++gl_INIT
++
+ saved_LIBS="$LIBS"
+ AC_SEARCH_LIBS([argp_parse], [argp])
+ LIBS="$saved_LIBS"
+--- a/lib/eu-config.h
++++ b/lib/eu-config.h
+@@ -59,14 +59,19 @@
+ # define once(once_control, init_routine) init_routine()
+ #endif /* USE_LOCKS */
+
+-#include <libintl.h>
++#include <gettext.h>
+ /* gettext helper macros. */
+ #define N_(Str) Str
+ #define _(Str) dgettext ("elfutils", Str)
+
+ /* Compiler-specific definitions. */
++#define __PRAGMA(str) _Pragma (#str)
++#ifdef __APPLE__
++#define strong_alias(name, aliasname) __PRAGMA(weak aliasname = name)
++#else
+ #define strong_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
++#endif
+
+ #ifdef __i386__
+ # define internal_function __attribute__ ((regparm (3), stdcall))
+@@ -77,7 +82,7 @@
+ #define internal_strong_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function;
+
+-#ifdef HAVE_VISIBILITY
++#if defined(HAVE_VISIBILITY) && !defined(__APPLE__)
+ #define attribute_hidden \
+ __attribute__ ((visibility ("hidden")))
+ #else
+@@ -166,7 +171,7 @@ asm (".section predict_data, \"aw\"; .pr
+ #endif
+
+ /* Avoid PLT entries. */
+-#ifdef PIC
++#if defined(PIC) && !defined(__APPLE__)
+ # define INTUSE(name) _INTUSE(name)
+ # define _INTUSE(name) __##name##_internal
+ # define INTDEF(name) _INTDEF(name)
+--- a/backends/i386_auxv.c
++++ b/backends/i386_auxv.c
+@@ -48,5 +48,4 @@ EBLHOOK(auxv_info) (GElf_Xword a_type, c
+ return 1;
+ }
+
+-__typeof (i386_auxv_info) x86_64_auxv_info
+- __attribute__ ((alias ("i386_auxv_info")));
++auxv_info_alias(x86_64)
+--- a/backends/ppc_regs.c
++++ b/backends/ppc_regs.c
+@@ -204,5 +204,11 @@ ppc_register_info (Ebl *ebl __attribute_
+ return namelen;
+ }
+
+-__typeof (ppc_register_info)
+- ppc64_register_info __attribute__ ((alias ("ppc_register_info")));
++ssize_t
++ppc64_register_info (Ebl *ebl,
++ int regno, char *name, size_t namelen,
++ const char **prefix, const char **setname,
++ int *bits, int *type)
++{
++ return ppc_register_info(ebl, regno, name, namelen, prefix, setname, bits, type);
++}
+--- a/backends/libebl_CPU.h
++++ b/backends/libebl_CPU.h
+@@ -97,4 +97,10 @@ dwarf_is_pointer (int tag)
+ case DW_TAG_reference_type: \
+ case DW_TAG_rvalue_reference_type
+
++#define auxv_info_alias(arch) \
++ int EBLHOOK_1(arch ## _, auxv_info) (GElf_Xword a_type, const char **name, const char **format) \
++ { \
++ return EBLHOOK(auxv_info)(a_type, name, format); \
++ }
++
+ #endif /* libebl_CPU.h */
+--- a/backends/ppc_auxv.c
++++ b/backends/ppc_auxv.c
+@@ -51,5 +51,4 @@ EBLHOOK(auxv_info) (GElf_Xword a_type, c
+ return 1;
+ }
+
+-__typeof (ppc_auxv_info) ppc64_auxv_info
+- __attribute__ ((alias ("ppc_auxv_info")));
++auxv_info_alias(ppc64)
+--- a/backends/ppc_cfi.c
++++ b/backends/ppc_cfi.c
+@@ -72,6 +72,7 @@ ppc_abi_cfi (Ebl *ebl __attribute__ ((un
+ return 0;
+ }
+
+-__typeof (ppc_abi_cfi)
+- ppc64_abi_cfi
+- __attribute__ ((alias ("ppc_abi_cfi")));
++int ppc64_abi_cfi(Ebl *ebl, Dwarf_CIE *abi_info)
++{
++ return ppc_abi_cfi(ebl, abi_info);
++}
+--- a/backends/ppc_initreg.c
++++ b/backends/ppc_initreg.c
+@@ -68,9 +68,10 @@ ppc_dwarf_to_regno (Ebl *ebl __attribute
+ abort ();
+ }
+
+-__typeof (ppc_dwarf_to_regno)
+- ppc64_dwarf_to_regno
+- __attribute__ ((alias ("ppc_dwarf_to_regno")));
++bool ppc64_dwarf_to_regno (Ebl *ebl, unsigned *regno)
++{
++ return ppc_dwarf_to_regno(ebl, regno);
++}
+
+ bool
+ ppc_set_initial_registers_tid (pid_t tid __attribute__ ((unused)),
+@@ -127,6 +128,7 @@ ppc_set_initial_registers_tid (pid_t tid
+ #endif /* __powerpc__ */
+ }
+
+-__typeof (ppc_set_initial_registers_tid)
+- ppc64_set_initial_registers_tid
+- __attribute__ ((alias ("ppc_set_initial_registers_tid")));
++bool ppc64_set_initial_registers_tid(pid_t tid, ebl_tid_registers_t *setfunc, void *arg)
++{
++ return ppc_set_initial_registers_tid(tid, setfunc, arg);
++}
+--- a/backends/ppc_attrs.c
++++ b/backends/ppc_attrs.c
+@@ -81,6 +81,9 @@ ppc_check_object_attribute (Ebl *ebl __a
+ return false;
+ }
+
+-__typeof (ppc_check_object_attribute)
+- ppc64_check_object_attribute
+- __attribute__ ((alias ("ppc_check_object_attribute")));
++bool ppc64_check_object_attribute(Ebl *ebl,
++ const char *vendor, int tag, uint64_t value,
++ const char **tag_name, const char **value_name)
++{
++ return ppc_check_object_attribute(ebl, vendor, tag, value, tag_name, value_name);
++}
+--- a/libdwfl/libdwflP.h
++++ b/libdwfl/libdwflP.h
+@@ -31,6 +31,7 @@
+
+ #include <libdwfl.h>
+ #include <libebl.h>
++#include <libeu.h>
+ #include <assert.h>
+ #include <dirent.h>
+ #include <errno.h>
+--- /dev/null
++++ b/lib/stdio_ext.h
+@@ -0,0 +1,6 @@
++#include <stdio.h>
++#ifndef __APPLE__
++#include_next <stdio_ext.h>
++#else
++#define __fsetlocking(...) 0
++#endif
+--- a/libdw/libdwP.h
++++ b/libdw/libdwP.h
+@@ -32,6 +32,7 @@
+ #include <stdbool.h>
+ #include <pthread.h>
+
++#include <libeu.h>
+ #include <libdw.h>
+ #include <dwarf.h>
+
+--- a/config/libdebuginfod.pc.in
++++ b/config/libdebuginfod.pc.in
+@@ -8,5 +8,5 @@ Description: elfutils library to query d
+ Version: @VERSION@
+ URL: http://elfutils.org/
+
+-Libs: -L${libdir} -ldebuginfod
++Libs: -L${libdir} -ldebuginfod -lpthread
+ Cflags: -I${includedir}
+--- a/config/libdw.pc.in
++++ b/config/libdw.pc.in
+@@ -8,7 +8,7 @@ Description: elfutils library for DWARF
+ Version: @VERSION@
+ URL: http://elfutils.org/
+
+-Libs: -L${libdir} -ldw
++Libs: -L${libdir} -ldw -lz -lelf -lz -ldl -lpthread
+ Cflags: -I${includedir}
+
+ # We need the exact matching elfutils libelf version since internal data
+--- a/config/libelf.pc.in
++++ b/config/libelf.pc.in
+@@ -8,7 +8,7 @@ Description: elfutils libelf library to
+ Version: @VERSION@
+ URL: http://elfutils.org/
+
+-Libs: -L${libdir} -lelf
++Libs: -L${libdir} -lelf -lz
+ Cflags: -I${includedir}
+
+ Requires.private: zlib @LIBZSTD@
+--- a/lib/next_prime.c
++++ b/lib/next_prime.c
+@@ -27,6 +27,7 @@
+ the GNU Lesser General Public License along with this program. If
+ not, see <http://www.gnu.org/licenses/>. */
+
++#include <config.h>
+ #include <stddef.h>
+
+
+--- a/libebl/eblopenbackend.c
++++ b/libebl/eblopenbackend.c
+@@ -200,8 +200,6 @@ static bool default_object_note (const c
+ uint32_t descsz, const char *desc);
+ static bool default_debugscn_p (const char *name);
+ static bool default_copy_reloc_p (int reloc);
+-static bool default_none_reloc_p (int reloc);
+-static bool default_relative_reloc_p (int reloc);
+ static bool default_check_special_symbol (Elf *elf,
+ const GElf_Sym *sym,
+ const char *name,
+@@ -253,8 +251,8 @@ fill_defaults (Ebl *result)
+ result->object_note = default_object_note;
+ result->debugscn_p = default_debugscn_p;
+ result->copy_reloc_p = default_copy_reloc_p;
+- result->none_reloc_p = default_none_reloc_p;
+- result->relative_reloc_p = default_relative_reloc_p;
++ result->none_reloc_p = default_copy_reloc_p;
++ result->relative_reloc_p = default_copy_reloc_p;
+ result->check_special_symbol = default_check_special_symbol;
+ result->data_marker_symbol = default_data_marker_symbol;
+ result->check_st_other_bits = default_check_st_other_bits;
+@@ -636,8 +634,6 @@ default_copy_reloc_p (int reloc __attrib
+ {
+ return false;
+ }
+-strong_alias (default_copy_reloc_p, default_none_reloc_p)
+-strong_alias (default_copy_reloc_p, default_relative_reloc_p)
+
+ static bool
+ default_check_special_symbol (Elf *elf __attribute__ ((unused)),
+--- a/src/srcfiles.cxx
++++ b/src/srcfiles.cxx
+@@ -78,7 +78,9 @@ ARGP_PROGRAM_VERSION_HOOK_DEF = print_ve
+ /* Bug report address. */
+ ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
+
++#ifdef HAVE_LIBARCHIVE
+ constexpr size_t BUFFER_SIZE = 8192;
++#endif
+
+ /* Definitions of arguments for argp functions. */
+ static const struct argp_option options[] =
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -92,6 +92,7 @@ strings_LDADD = $(libelf) $(libeu) $(arg
+ ar_LDADD = libar.a $(libelf) $(libeu) $(argp_LDADD) $(obstack_LIBS)
+ unstrip_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+ stack_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD) $(demanglelib)
++EXTRA_stack_DEPENDENCIES = $(if $(findstring srcfiles,$(bin_PROGRAMS)),$(srcfiles_OBJECTS))
+ elfcompress_LDADD = $(libebl) $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+ elfclassify_LDADD = $(libelf) $(libdw) $(libeu) $(argp_LDADD)
+ srcfiles_SOURCES = srcfiles.cxx