Merge tag 'elfutils-0.190' into main

elfutils 0.190 release

* tag 'elfutils-0.190':
  Prepare for 0.190
  The default branch is now 'main'
  libelf/elf_newscn.c: fix build failure against gcc-14 (-Walloc-size)
  tests: Optionally dump all units in dwarf-getmacros
  tests: Handle DW_MACRO_{define,undef}_{strx,sup} in dwarf-getmacros
  readelf: Support .gdb_index version 9
  libdw, libdwfl: Save original path of ELF file
  debuginfod-client.c: Don't print empty line in header_callback
  dwfl_offline_section_address: replace asserts with early return
  libdw: Recognize .debug_[ct]u_index sections in dwarf_elf_begin
  libdw: ignore really large discriminator
  CONTRIBUTING: Update ChangeLog policy, mention patchwork and try bots
  PR 30000: debuginfod-find should have a source-list verb
  CONTRIBUTING: Switch from real name policy to know identity policy
  libelf: Make elf32_getchdr and elf64_getchdr thread-safe
  libelf: Fix elf_end deadlock
  libelf: Make elf_version thread-safe
  lib: Add new once_define and once macros to eu-config.h
  libelf: Sync elf.h from glibc
  PR30962: debuginfod: full paths for X-DEBUGINFOD-FILE/ARCHIVE response headers
  libdw: Skip zero entries in aranges
  strip: Clean up a bit more after errors
  libdw: Handle split DWARF in dwarf_macro_getsrcfiles
  libdw: Fix dwarf_macro_getsrcfiles for DWARF 5
  libdw: Handle other string forms in dwarf_macro_param2
  libdw: Handle DW_AT_ranges in split DWARF 5 skeleton in dwarf_ranges
  libdw: Handle split DWARF in dwarf_entrypc
  libdw: Make try_split_file static
  PR30879: intermittent debuginfod crash with unhandled exception
  libelf: tdelete dummy key if anything goes wrong setting up rawchunk
  libelf: fix typos in comment
  tests: Fix system_elf_gelf_test build without system libelf.h
  PR30809: improve debuginfod client progress-callback parameters
  backends: Update list of LoongArch relocations
  libelf: Sync elf.h from Glibc
  libelf, readelf, elflint: Add RELR support
  libelf: Remove elf_scncnt from libelf.map
  libelf: Free and clear rawdata_base and zdata_base consistently
  tests: run-lfs-symbols.sh needs gawk
  SECURITY: new file
  libelf: Replace list of elf_getdata_rawchunk results with a tree
  backends: Update list of RISC-V relocations
  libelf: Sync elf.h from glibc
  debuginfod: Fix formatting in debuginfod_config_cache
  tests: Use -N for run-readelf-self.sh.
  tests: Split up run-strip-reloc.sh test in three subtests
  tests: Really split run-copymany-sections.sh into separate tests
  tests: Split run-copymany-sections.sh into separate tests
  tests: Use readelf -N -w in run-strip-reloc.sh
  tests: Add a bit less and slightly smaller sections for addsections
  debuginfod: PR29696: enlarge run-debuginfod-federation-metrics.sh workload again
  debuginfod: PR29696: Removed secondary fd close in cache config causing a race condition
  report_r_debug: handle `-z separate-code' and find more modules
  PR30316: debuginfod wal checkpointing
  debuginfod: PR30378: better compression for _files table
  backends: Add set_initial_registers_tid callback for LoongArch
  backends: Add core_note callback for LoongArch
  backends: Add frame pointer unwinding for LoongArch
  backends: Add initial return value location support for LoongArch
  backends: Add abi_cfi and register_info callbacks for LoongArch
  elfcompress: Don't compress if section already compressed unless forced
  libdwfl: Fix memory leak in unzip()
  PR30377: fix debuginfod -r -X combination
  testsuite: Avoid C99 compatibility issues in run-native-test.sh
  readelf: display dynamic symtab without section headers
  tests: Limit the number of concurrent requests in debuginfod-federation
  readelf: Handle NULL shdr in section_name
  backends: Check results for NULL early in dwarf_peeled_die_type
  PR30348: debuginfod: retry partial archive scans
  backends: add checks for _GLOBAL_OFFSET_TABLE_ on loongarch
  backends: Add new relocation type handling for LoongArch
  libelf: Sync elf.h from glibc.
  debuginfod: When retrieving files from cache, update atime manually
  debuginfod: Don't touch access time of new files
  debuginfod-client.c: Avoid sscanf on mixed-case component of string
  nuke a top-level ChangeLog blurb that duplicated the debuginfod/ChangeLog
  debuginfod: Replace futimes with futimens
  debuginfod-client.c: Fix download size not correctly fallbacks to x-debuginfod-size header
  LoongArch: implemented a basic machine flag check
  debuginfod-client.c: Skip empty file creation for cancelled queries
  tests: skip '(null)' symname frames in backtrace tests
  configure.ac contains Bashisms
  Fix static build when zstd is enabled for libelf

Change-Id: Ic46cacc727d5f6f26023419995cc5b4fb9102001
Signed-off-by: Matthias Maennich <maennich@google.com>
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..848df07
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,204 @@
+// Copyright (C) 2013 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE
+//     CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
+//     DEPENDING ON IT IN YOUR PROJECT. ***
+package {
+    default_applicable_licenses: ["external_elfutils_license"],
+}
+
+// http://go/android-license-faq
+license {
+    name: "external_elfutils_license",
+    visibility: [":__subpackages__"],
+    license_kinds: [
+        "SPDX-license-identifier-Apache-2.0",
+        "SPDX-license-identifier-BSD",
+        "SPDX-license-identifier-GFDL", // by exception only
+        "SPDX-license-identifier-GPL-2.0-or-later",
+        "SPDX-license-identifier-GPL-3.0-or-later",
+        "SPDX-license-identifier-LGPL-3.0-or-later",
+    ],
+    license_text: [
+        "COPYING",
+        "COPYING-GPLV2",
+        "COPYING-LGPLV3",
+        "NOTICE",
+    ],
+}
+
+// Properties to apply to all static libraries that use elfutils.
+// Soong doesn't have propagation for static library dependencies,
+// and this have to be included explicitly by elfutils users.
+cc_defaults {
+    name: "elfutils_transitive_defaults",
+    static_libs: [
+        "libz",
+        "libzstd",
+    ],
+}
+
+cc_defaults {
+    name: "elfutils_defaults",
+    defaults: ["elfutils_transitive_defaults"],
+    cflags: [
+        "-DHAVE_CONFIG_H",
+        "-D_GNU_SOURCE",
+        // upper bound for the number of lines of the resulting mnemonic files
+        "-DNMNES=1000",
+        "-std=gnu99",
+        "-Werror",
+        // to suppress the "pointer of type ‘void *’ used in arithmetic" warning
+        "-Wno-pointer-arith",
+        "-Wno-typedef-redefinition",
+    ],
+    header_libs: [
+         "elfutils_headers",
+    ],
+    export_header_lib_headers: ["elfutils_headers"],
+
+    visibility: [
+        "//external/dwarves:__subpackages__",
+        "//external/elfutils:__subpackages__",
+        "//external/libabigail:__subpackages__",
+        "//external/libbpf:__subpackages__",
+        "//external/stg:__subpackages__",
+    ],
+}
+
+cc_library {
+    name: "libelf",
+    host_supported: true,
+    native_bridge_supported: true,
+    vendor_available: true,
+    defaults: ["elfutils_defaults"],
+
+    srcs:  ["libelf/*.c",],
+
+    export_include_dirs: ["libelf"],
+
+    target: {
+        darwin: {
+            enabled: false,
+        },
+        android: {
+            cflags: [
+                "-D_FILE_OFFSET_BITS=64",
+                "-include AndroidFixup.h",
+            ],
+            shared: {
+                enabled: false,
+            },
+        },
+        musl: {
+            cflags: [
+                "-include AndroidFixup.h",
+            ],
+        },
+    },
+
+    visibility: [
+        "//device/google/contexthub/util/nanoapp_postprocess",
+        "//external/bcc/libbpf-tools",
+        "//external/bpftool",
+        "//external/igt-gpu-tools",
+        "//external/mesa3d",
+    ],
+}
+
+cc_library_headers {
+    name: "elfutils_headers",
+    host_supported: true,
+    native_bridge_supported: true,
+    vendor_available: true,
+    export_include_dirs: [
+        ".",
+        "include",
+        "lib",
+    ],
+    target: {
+        android: {
+            export_include_dirs: ["bionic-fixup"],
+        },
+        musl: {
+            export_include_dirs: ["bionic-fixup"],
+        },
+    },
+    visibility: [":__subpackages__"],
+}
+
+cc_library_host_static {
+    name: "libdw",
+    defaults: ["elfutils_defaults"],
+    target: {
+        darwin: {
+            enabled: false,
+        },
+        musl: {
+            static_libs: [
+                "libfts",
+            ],
+        },
+    },
+    srcs: [
+        "backends/*.c",
+        "libcpu/*_disasm.c",
+        "libdw/*.c",
+        "libdwelf/*.c",
+        "libdwfl/*.c",
+        "libebl/*.c",
+    ],
+    generated_headers: [
+        "i386_dis",
+        "i386_mnemonics",
+        "x86_64_dis",
+        "x86_64_mnemonics",
+    ],
+    exclude_srcs: [
+        // Do not enabled compression support
+        "libdwfl/bzip2.c",
+        "libdwfl/lzma.c",
+        // Those headers are incompatible with clang due to nested function
+        // definitions.
+        "libdwfl/dwfl_segment_report_module.c",
+        "libdwfl/debuginfod-client.c",
+        "libdwfl/elf-from-memory.c",
+        "libdwfl/link_map.c",
+        // These depend on argp which doesn't exist in musl
+        "libdwfl/argp-std.c",
+        // Those are common source files actually used as headers and not
+        // compiled standalone.
+        "backends/common-reloc.c",
+        "backends/linux-core-note.c",
+        "backends/x86_corenote.c",
+    ],
+    local_include_dirs: [
+        "libcpu",
+        "libasm",
+        "libdwelf",
+        "libdwfl",
+        "libebl",
+    ],
+    export_include_dirs: [
+        "libdw",
+    ],
+    static_libs: [
+        "libelf"
+    ],
+    whole_static_libs: [
+        "libeu",
+    ],
+    compile_multilib: "64",
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 0000000..7fd2f2d
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,23 @@
+# *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS.  PLEASE
+#     CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE
+#     DEPENDING ON IT IN YOUR PROJECT. ***
+name: "elfutils"
+description: "elfutils is a collection of utilities and libraries to read, create and modify ELF binary files, find and handle DWARF debug data, symbols, thread state and stacktraces for processes and core files on GNU/Linux."
+third_party {
+  url {
+    type: HOMEPAGE
+    value: "https://sourceware.org/elfutils/"
+  }
+  url {
+    type: GIT
+    value: "git://sourceware.org/git/elfutils.git"
+  }
+  version: "elfutils-0.190"
+  license_type: BY_EXCEPTION_ONLY
+  license_note: "Would be RESTRICTED save for doc/COPYING-GFDL"
+  last_upgrade_date {
+    year: 2024
+    month: 01
+    day: 24
+  }
+}
diff --git a/MODULE_LICENSE_GPL b/MODULE_LICENSE_GPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_GPL
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..60549be
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,340 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) 19yy  <name of author>
+
+    This program 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; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program 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 this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) 19yy name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..80b7325
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1 @@
+maennich@google.com
diff --git a/bionic-fixup/AndroidFixup.h b/bionic-fixup/AndroidFixup.h
new file mode 100644
index 0000000..83d2952
--- /dev/null
+++ b/bionic-fixup/AndroidFixup.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_FIXUP_H
+#define ANDROID_FIXUP_H
+
+static inline void *rawmemchr(const void *s, int c)
+{
+    const unsigned char *ptr = s;
+    while (1) {
+        if (*ptr == c) return (void *) ptr;
+        ptr++;
+    }
+}
+
+/* workaround for canonicalize_file_name */
+#define canonicalize_file_name(path) realpath(path, NULL)
+
+#endif /* ANDROID_FIXUP_H */
diff --git a/bionic-fixup/argp.h b/bionic-fixup/argp.h
new file mode 100644
index 0000000..fe53b6d
--- /dev/null
+++ b/bionic-fixup/argp.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ELFUTILS_ARGP_H
+#define ELFUTILS_ARGP_H
+
+// We don't have an implementation, but elfutils unconditionally includes this,
+// and relies on its transitive includes in places.
+
+#include <errno.h>
+
+#endif /* ELFUTILS_ARGP_H */
diff --git a/bionic-fixup/libintl.h b/bionic-fixup/libintl.h
new file mode 100644
index 0000000..c35a06d
--- /dev/null
+++ b/bionic-fixup/libintl.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2013, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ELFUTILS_LIBINTL_H
+#define ELFUTILS_LIBINTL_H
+
+/* no internalization */
+#define gettext(x)      (x)
+#define dgettext(x,y)   (y)
+
+#endif /* ELFUTILS_LIBINTL_H */
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..364ce05
--- /dev/null
+++ b/config.h
@@ -0,0 +1,213 @@
+/* config.h.  Generated from config.h.in by configure.  */
+/* config.h.in.  Generated from configure.ac by autoheader.  */
+
+/* Building with -fsanitize=undefined or not */
+#define CHECK_UNDEFINED 0
+
+/* Should ar and ranlib use -D behavior by default? */
+#define DEFAULT_AR_DETERMINISTIC false
+
+/* Build dummy libdebuginfod */
+/* #undef DUMMY_LIBDEBUGINFOD */
+
+/* Build debuginfod */
+/* #undef ENABLE_DEBUGINFOD */
+
+/* Enable libdebuginfod */
+/* #undef ENABLE_LIBDEBUGINFOD */
+
+/* Define to 1 if translation of program messages to the user's native
+   language is requested. */
+#define ENABLE_NLS 1
+
+/* Define to 1 if you have the Mac OS X function
+   CFLocaleCopyPreferredLanguages in the CoreFoundation framework. */
+/* #undef HAVE_CFLOCALECOPYPREFERREDLANGUAGES */
+
+/* Define to 1 if you have the Mac OS X function CFPreferencesCopyAppValue in
+   the CoreFoundation framework. */
+/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
+
+/* define if the compiler supports basic C++11 syntax */
+#define HAVE_CXX11 1
+
+/* Define if the GNU dcgettext() function is already present or preinstalled.
+   */
+#define HAVE_DCGETTEXT 1
+
+/* Define to 1 if you have the declaration of `mempcpy', and to 0 if you
+   don't. */
+#define HAVE_DECL_MEMPCPY 1
+
+/* Define to 1 if you have the declaration of `memrchr', and to 0 if you
+   don't. */
+#define HAVE_DECL_MEMRCHR 1
+
+/* Define to 1 if you have the declaration of `powerof2', and to 0 if you
+   don't. */
+#define HAVE_DECL_POWEROF2 1
+
+/* Define to 1 if you have the declaration of `rawmemchr', and to 0 if you
+   don't. */
+#define HAVE_DECL_RAWMEMCHR 1
+
+/* Define to 1 if you have the declaration of `reallocarray', and to 0 if you
+   don't. */
+#define HAVE_DECL_REALLOCARRAY 1
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+   don't. */
+#define HAVE_DECL_STRERROR_R 1
+
+/* Define to 1 if you have the <error.h> header file. */
+#if defined(__BIONIC__) || defined(__GLIBC__)
+#define HAVE_ERROR_H 1
+#endif
+
+/* Define to 1 if you have the <err.h> header file. */
+#define HAVE_ERR_H 1
+
+/* Define to 1 if you have the <execinfo.h> header file. */
+#define HAVE_EXECINFO_H 1
+
+/* Defined if __attribute__((fallthrough)) is supported */
+#define HAVE_FALLTHROUGH 1
+
+/* Defined if __attribute__((gcc_struct)) is supported */
+/* #undef HAVE_GCC_STRUCT */
+
+/* Define to 1 if you have the `getrlimit' function. */
+#define HAVE_GETRLIMIT 1
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+#define HAVE_GETTEXT 1
+
+/* Define if you have the iconv() function and it works. */
+/* #undef HAVE_ICONV */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the `mremap' function. */
+#define HAVE_MREMAP 1
+
+/* Define to 1 if you have the `process_vm_readv' function. */
+#define HAVE_PROCESS_VM_READV 1
+
+/* Enable pthread_setname_np */
+#define HAVE_PTHREAD_SETNAME_NP 1
+
+/* Define to 1 if you have the `sched_getaffinity' function. */
+#define HAVE_SCHED_GETAFFINITY 1
+
+/* Define to 1 if you have the <sched.h> header file. */
+#define HAVE_SCHED_H 1
+
+/* Define to 1 if `stdatomic.h` is provided by the system, 0 otherwise. */
+#define HAVE_STDATOMIC_H 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdio.h> header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define if you have `strerror_r'. */
+#define HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the <sys/resource.h> header file. */
+#define HAVE_SYS_RESOURCE_H 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if <sys/user.h> defines struct user_regs_struct */
+#define HAVE_SYS_USER_REGS 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Defined if __attribute__((visibility())) is supported */
+#define HAVE_VISIBILITY 1
+
+/* Name of package */
+#define PACKAGE "elfutils"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "https://sourceware.org/bugzilla"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "elfutils"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "elfutils 0.190"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "elfutils"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "http://elfutils.org/"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "0.190"
+
+/* The size of `long', as computed by sizeof. */
+#define SIZEOF_LONG 8
+
+/* Define to 1 if all of the C90 standard headers exist (not just the ones
+   required in a freestanding environment). This macro is provided for
+   backward compatibility; new code need not use it. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if strerror_r returns char *. */
+#if defined(__GLIBC__) || defined(__BIONIC__)
+#define STRERROR_R_CHAR_P 1
+#endif
+
+/* Support bzip2 decompression via -lbz2. */
+/* #undef USE_BZLIB */
+
+/* Defined if demangling is enabled */
+#define USE_DEMANGLE 1
+
+/* Defined if libraries should be thread-safe. */
+/* #undef USE_LOCKS */
+
+/* Support LZMA (xz) decompression via -llzma. */
+/* #undef USE_LZMA */
+
+/* Support gzip decompression via -lz. */
+#define USE_ZLIB 1
+
+/* Support ZSTD (zst) decompression via -lzstd. */
+#define USE_ZSTD 1
+
+/* zstd compression support */
+#define USE_ZSTD_COMPRESS 1
+
+/* Version number of package */
+#define VERSION "0.190"
+
+/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a
+   `char[]'. */
+#define YYTEXT_POINTER 1
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
+
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
+
+#include <eu-config.h>
diff --git a/doc/man3 b/doc/man3
deleted file mode 120000
index 945c9b4..0000000
--- a/doc/man3
+++ /dev/null
@@ -1 +0,0 @@
-.
\ No newline at end of file
diff --git a/doc/man7 b/doc/man7
deleted file mode 120000
index 945c9b4..0000000
--- a/doc/man7
+++ /dev/null
@@ -1 +0,0 @@
-.
\ No newline at end of file
diff --git a/include/elfutils/libdw.h b/include/elfutils/libdw.h
new file mode 120000
index 0000000..b7328a2
--- /dev/null
+++ b/include/elfutils/libdw.h
@@ -0,0 +1 @@
+../../libdw/libdw.h
\ No newline at end of file
diff --git a/include/elfutils/libdwfl.h b/include/elfutils/libdwfl.h
new file mode 120000
index 0000000..240eb56
--- /dev/null
+++ b/include/elfutils/libdwfl.h
@@ -0,0 +1 @@
+../../libdwfl/libdwfl.h
\ No newline at end of file
diff --git a/include/elfutils/version.h b/include/elfutils/version.h
new file mode 120000
index 0000000..ea58c60
--- /dev/null
+++ b/include/elfutils/version.h
@@ -0,0 +1 @@
+../../version.h
\ No newline at end of file
diff --git a/lib/Android.bp b/lib/Android.bp
new file mode 100644
index 0000000..9016e29
--- /dev/null
+++ b/lib/Android.bp
@@ -0,0 +1,14 @@
+package {
+    default_applicable_licenses: ["external_elfutils_license"],
+}
+
+cc_library_host_static {
+    name: "libeu",
+    defaults: ["elfutils_defaults"],
+    srcs: ["*.c"],
+    exclude_srcs: [
+        "color.c", // uses argp
+        "dynamicsizehash*.c",
+        "printversion.c", // uses argp
+    ],
+}
diff --git a/libcpu/Android.bp b/libcpu/Android.bp
new file mode 100644
index 0000000..13b7255
--- /dev/null
+++ b/libcpu/Android.bp
@@ -0,0 +1,86 @@
+package {
+    default_applicable_licenses: ["external_elfutils_license"],
+}
+
+genrule {
+    name: "i386_mnemonics",
+    srcs: [
+        "defs/i386",
+    ],
+    out: ["i386.mnemonics"],
+    cmd: "M4=$(location m4) $(location android_mnemonic_preprocess.sh) i386 $(in) $(out)",
+    tool_files: [
+        "android_mnemonic_preprocess.sh",
+    ],
+    tools : [
+        "m4",
+    ]
+}
+
+genrule {
+    name: "x86_64_mnemonics",
+    srcs : [
+        "defs/i386",
+    ],
+    out : ["x86_64.mnemonics"],
+    cmd : "M4=$(location m4) $(location android_mnemonic_preprocess.sh) x86_64 $(in) $(out)",
+    tool_files : [
+        "android_mnemonic_preprocess.sh",
+    ],
+    tools : [
+        "m4",
+    ]
+}
+
+cc_binary_host {
+    name: "i386_gendis",
+    defaults: ["elfutils_defaults"],
+    srcs: [
+        "i386_parse.y",
+        "i386_lex.l",
+        "i386_gendis.c",
+    ],
+    generated_headers: [
+        "i386_mnemonics",
+    ],
+    yacc: {
+        flags: ["-pi386_",]
+    },
+    lex: {
+        flags: ["-Pi386_",]
+    },
+    static_libs: [
+        "libeu",
+    ],
+    target: {
+        musl: {
+            static_libs: ["libobstack"],
+        },
+    },
+}
+
+genrule {
+    name: "i386_dis",
+    srcs: [
+        "defs/i386",
+    ],
+    out: ["i386_dis.h"],
+    cmd: "$(location m4) -Di386 -DDISASSEMBLER $(in) > $(genDir)/i386_defs && $(location i386_gendis) $(genDir)/i386_defs > $(out)",
+    tools: [
+        "i386_gendis",
+        "m4",
+    ],
+}
+
+genrule {
+    name: "x86_64_dis",
+    srcs: [
+        "defs/i386",
+    ],
+    out: ["x86_64_dis.h"],
+    cmd: "$(location m4) -Dx86_64 -DDISASSEMBLER $(in) > $(genDir)/x86_64_defs && $(location i386_gendis) $(genDir)/x86_64_defs > $(out)",
+    tools: [
+        "i386_gendis",
+        "m4",
+    ],
+}
diff --git a/libcpu/android_mnemonic_preprocess.sh b/libcpu/android_mnemonic_preprocess.sh
new file mode 100755
index 0000000..2b05249
--- /dev/null
+++ b/libcpu/android_mnemonic_preprocess.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+arch="$1"
+defs="$2"
+out="$3"
+
+$M4 "-D${arch}" -DDISASSEMBLER "$defs" \
+	| sed "1,/^%%/d;/^#/d;/^[[:space:]]*$/d;s/[^:]*:\([^[:space:]]*\).*/MNE(\\1)/;s/{[^}]*}//g;/INVALID/d" \
+	| sort -u \
+> "$out"
diff --git a/libdw/dwarf_formstring.c b/libdw/dwarf_formstring.c
index 0ee4241..65f03a5 100644
--- a/libdw/dwarf_formstring.c
+++ b/libdw/dwarf_formstring.c
@@ -173,11 +173,11 @@
 	off = read_4ubyte_unaligned (dbg, datap);
       else
 	off = read_8ubyte_unaligned (dbg, datap);
-
-      if (off >= data_size)
-	goto invalid_offset;
     }
 
+  if (off >= data_size)
+    goto invalid_offset;
+
   return (const char *) data->d_buf + off;
 }
 INTDEF(dwarf_formstring)
diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c
index 581f407..a76d368 100644
--- a/libdwfl/dwfl_report_elf.c
+++ b/libdwfl/dwfl_report_elf.c
@@ -276,10 +276,11 @@
 	}
       else
 	{
-	  elf_end (elf);
 	  if (m->main_bias != bias
 	      || m->main.vaddr != vaddr || m->main.address_sync != address_sync)
 	    goto overlap;
+	  elf_end (m->main.elf);
+	  m->main.elf = elf;
 	}
     }
   return m;
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index c7283c6..0ad6a32 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -422,7 +422,7 @@
     }
 
   size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in);
-  if (ZSTD_isError (ret))
+  if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out))
     {
       free (buf_out);
       __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
diff --git a/patches/config.h.patch b/patches/config.h.patch
new file mode 100644
index 0000000..901b8f0
--- /dev/null
+++ b/patches/config.h.patch
@@ -0,0 +1,33 @@
+diff --git a/config.h b/config.h
+index af199565..873627e0 100644
+--- a/config.h
++++ b/config.h
+@@ -60,7 +60,9 @@
+ #define HAVE_DECL_STRERROR_R 1
+ 
+ /* Define to 1 if you have the <error.h> header file. */
++#if defined(__BIONIC__) || defined(__GLIBC__)
+ #define HAVE_ERROR_H 1
++#endif
+ 
+ /* Define to 1 if you have the <err.h> header file. */
+ #define HAVE_ERR_H 1
+@@ -69,7 +71,7 @@
+ #define HAVE_FALLTHROUGH 1
+ 
+ /* Defined if __attribute__((gcc_struct)) is supported */
+-#define HAVE_GCC_STRUCT 1
++/* #undef HAVE_GCC_STRUCT */
+ 
+ /* Define to 1 if you have the `getrlimit' function. */
+ #define HAVE_GETRLIMIT 1
+@@ -167,7 +169,9 @@
+ #define STDC_HEADERS 1
+ 
+ /* Define to 1 if strerror_r returns char *. */
++#if defined(__GLIBC__) || defined(__BIONIC__)
+ #define STRERROR_R_CHAR_P 1
++#endif
+ 
+ /* Support bzip2 decompression via -lbz2. */
+ /* #undef USE_BZLIB */
diff --git a/patches/libdw-check-offset-dwarf_formstring-in-all-cases.patch b/patches/libdw-check-offset-dwarf_formstring-in-all-cases.patch
new file mode 100644
index 0000000..7e30d2a
--- /dev/null
+++ b/patches/libdw-check-offset-dwarf_formstring-in-all-cases.patch
@@ -0,0 +1,36 @@
+From 1bd9deb9aa19ac2e2fa9665009e0d5924adcf4d3 Mon Sep 17 00:00:00 2001
+From: Aleksei Vetrov <vvvvvv@google.com>
+Date: Thu, 16 Nov 2023 21:29:22 +0000
+Subject: [PATCH] libdw: check offset dwarf_formstring in all cases
+
+This check was initially added to test if offset overflows the safe
+prefix where any string will be null-terminated. However the check
+was placed in a wrong place and didn't cover all `attrp->form` cases.
+
+    * libdw/dwarf_formstring.c (dwarf_formstring): Move offset check
+      right before returning the result.
+
+Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
+
+diff --git a/libdw/dwarf_formstring.c b/libdw/dwarf_formstring.c
+index 0ee42411..65f03a5e 100644
+--- a/libdw/dwarf_formstring.c
++++ b/libdw/dwarf_formstring.c
+@@ -173,11 +173,11 @@ dwarf_formstring (Dwarf_Attribute *attrp)
+ 	off = read_4ubyte_unaligned (dbg, datap);
+       else
+ 	off = read_8ubyte_unaligned (dbg, datap);
+-
+-      if (off >= data_size)
+-	goto invalid_offset;
+     }
+ 
++  if (off >= data_size)
++    goto invalid_offset;
++
+   return (const char *) data->d_buf + off;
+ }
+ INTDEF(dwarf_formstring)
+-- 
+2.43.0.rc1.413.gea7ed67945-goog
+
diff --git a/patches/libdwfl-handle-duplicate-ELFs-when-reporting-archive.patch b/patches/libdwfl-handle-duplicate-ELFs-when-reporting-archive.patch
new file mode 100644
index 0000000..021ecdc
--- /dev/null
+++ b/patches/libdwfl-handle-duplicate-ELFs-when-reporting-archive.patch
@@ -0,0 +1,56 @@
+From 0ab5a3eb4122f36cbaff259e7a0a3f9d014cb6f7 Mon Sep 17 00:00:00 2001
+From: Aleksei Vetrov <vvvvvv@google.com>
+Date: Mon, 20 Nov 2023 17:44:47 +0000
+Subject: [PATCH] libdwfl: handle duplicate ELFs when reporting archives
+
+When archive is processed in process_archive (libdwfl/offline.c), it
+creates an Elf object for each archive member. Then in
+process_archive_member it calls process_file to create a Dwfl_Module
+through __libdwfl_report_elf.
+
+The ownership of the Elf object is expected to be:
+
+* either transfered to the Dwfl_Module, if __libdwfl_report_elf returns
+  not NULL;
+
+* or handled at the end of process_archive_member by calling elf_end.
+
+Moreover, Elf object is expected to be alive, if __libdwfl_report_elf
+returns not NULL, because at the end of process_archive_member it
+advances to the next member through the elf_next call.
+
+The problem happens when __libdwfl_report_elf encounters Elf with the
+same name and content as it seen before. In that case dwfl_report_module
+will reuse existing Dwfl_Module object. This leads to a codepath that
+calls elf_end on the Elf object, while returning not NULL, breaking the
+elf_next call to the next member.
+
+The fix is to destroy m->main.elf instead and put the new Elf object in
+the already existing Dwfl_Module.
+
+    * libdwfl/dwfl_report_elf.c (__libdwfl_report_elf): Replace Elf in
+      the Dwfl_Module in case of duplicate modules to prolong its
+      lifetime for subsequent processing.
+
+Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
+
+diff --git a/libdwfl/dwfl_report_elf.c b/libdwfl/dwfl_report_elf.c
+index 581f4079..a76d3681 100644
+--- a/libdwfl/dwfl_report_elf.c
++++ b/libdwfl/dwfl_report_elf.c
+@@ -276,10 +276,11 @@ __libdwfl_report_elf (Dwfl *dwfl, const char *name, const char *file_name,
+ 	}
+       else
+ 	{
+-	  elf_end (elf);
+ 	  if (m->main_bias != bias
+ 	      || m->main.vaddr != vaddr || m->main.address_sync != address_sync)
+ 	    goto overlap;
++	  elf_end (m->main.elf);
++	  m->main.elf = elf;
+ 	}
+     }
+   return m;
+-- 
+2.43.0.rc1.413.gea7ed67945-goog
+
diff --git a/patches/libelf-check-decompressed-ZSTD-size.patch b/patches/libelf-check-decompressed-ZSTD-size.patch
new file mode 100644
index 0000000..6c76fac
--- /dev/null
+++ b/patches/libelf-check-decompressed-ZSTD-size.patch
@@ -0,0 +1,33 @@
+From 03c171947cc538b04957ac2222ce86e7c0170bd1 Mon Sep 17 00:00:00 2001
+From: Aleksei Vetrov <vvvvvv@google.com>
+Date: Thu, 23 Nov 2023 15:31:47 +0000
+Subject: [PATCH] libelf: check decompressed ZSTD size
+
+Decompression functions like __libelf_decompress_zlib check that
+decompressed data has the same size as it was declared in the header
+(size_out argument). The same check is now added to
+__libelf_decompress_zstd to make sure that the whole allocated buffer is
+initialized.
+
+    * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value
+      of ZSTD_decompress to check that decompressed data size is the
+      same as size_out of the buffer that was allocated.
+
+Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
+
+diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
+index c7283c6a..0ad6a32a 100644
+--- a/libelf/elf_compress.c
++++ b/libelf/elf_compress.c
+@@ -422,7 +422,7 @@ __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out)
+     }
+ 
+   size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in);
+-  if (ZSTD_isError (ret))
++  if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out))
+     {
+       free (buf_out);
+       __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
+-- 
+2.43.0.rc1.413.gea7ed67945-goog
+
diff --git a/post_update.sh b/post_update.sh
new file mode 100755
index 0000000..9079e37
--- /dev/null
+++ b/post_update.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# $1 Path to the new version.
+# $2 Path to the old version.
+
+set -x
+set -e
+
+# if called from the external_updater, change to the new dir first
+if [ "$1" != "" ]; then
+    cd $1
+fi
+
+autoreconf -i && ./configure --enable-maintainer-mode --disable-debuginfod --disable-libdebuginfod --without-lzma --without-bzlib
+
+# if called from the external_updater, do not apply any patches as it will do
+# that for us
+if [ "$2" == "" ]; then
+    git apply patches/*
+fi
diff --git a/version.h b/version.h
new file mode 100644
index 0000000..f3e0b00
--- /dev/null
+++ b/version.h
@@ -0,0 +1,38 @@
+/* Version information about elfutils development libraries.
+   Copyright (C) 2008 Red Hat, 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/>.  */
+
+#ifndef _ELFUTILS_VERSION_H
+#define _ELFUTILS_VERSION_H	1
+
+#define _ELFUTILS_VERSION	190
+
+#define _ELFUTILS_PREREQ(major, minor) \
+  (_ELFUTILS_VERSION >= ((major) * 1000 + (minor)))
+
+#endif	/* elfutils/version.h */