diff --git a/Makefile b/Makefile
index 0445293..a5ea0d7 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
#CXX=clang++
CXXFLAGS = -std=c++11 -Wall -Wno-reorder -fPIC -pie -march=native \
- -DVERSION=$(shell cat VERSION)
+ -DVERSION=$(shell cat VERSION) -Wl,-rpath=/usr/share/e9tool/lib/
E9PATCH_OBJS=\
src/e9patch/e9CFR.o \
@@ -33,10 +33,21 @@ E9TOOL_OBJS=\
src/e9tool/e9tool.o \
src/e9tool/e9types.o \
src/e9tool/e9x86_64.o
+E9TOOL_LIBS=\
+ contrib/zydis/libZydis.a \
+ contrib/libdw/libdw.a
+E9TOOL_CXXFLAGS=\
+ -I src/e9tool/ -Wno-unused-function \
+ -I contrib/libdw/ \
+ -I contrib/zydis/include/ \
+ -I contrib/zydis/dependencies/zycore/include/
+E9TOOL_LDFLAGS=\
+ -Wl,--dynamic-list=src/e9tool/e9tool.syms \
+ -lpthread -ldl -lz
release: CXXFLAGS += -O2 -D NDEBUG
release: $(E9PATCH_OBJS)
- $(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch $(LDFLAGS)
+ $(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
strip e9patch
debug: CXXFLAGS += -O0 -g
@@ -47,25 +58,21 @@ sanitize: CXXFLAGS += -O0 -g -fsanitize=address
sanitize: $(E9PATCH_OBJS)
$(CXX) $(CXXFLAGS) $(E9PATCH_OBJS) -o e9patch
-tool: CXXFLAGS += -O2 -I src/e9tool/ -I zydis/include/ \
- -I zydis/dependencies/zycore/include/ -Wno-unused-function
-tool: $(E9TOOL_OBJS)
- $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) -o e9tool libZydis.a \
- -Wl,--dynamic-list=src/e9tool/e9tool.syms -ldl $(LDFLAGS)
+tool: CXXFLAGS += -O2 $(E9TOOL_CXXFLAGS)
+tool: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
+ $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
+ $(E9TOOL_LDFLAGS) -Wl,-Map=output.map
strip e9tool
-tool.debug: CXXFLAGS += -O0 -g -I src/e9tool/ -I zydis/include/ \
- -I zydis/dependencies/zycore/include/ -Wno-unused-function
-tool.debug: $(E9TOOL_OBJS)
- $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) -o e9tool libZydis.a \
- -Wl,--dynamic-list=src/e9tool/e9tool.syms -ldl
+tool.debug: CXXFLAGS += -O0 -g $(E9TOOL_CXXFLAGS)
+tool.debug: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
+ $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
+ $(E9TOOL_LDFLAGS)
-tool.sanitize: CXXFLAGS += -O0 -g -I src/e9tool/ -I zydis/include/ \
- -I zydis/dependencies/zycore/include/ -Wno-unused-function \
- -fsanitize=address
-tool.sanitize: $(E9TOOL_OBJS)
- $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) -o e9tool libZydis.a \
- -Wl,--dynamic-list=src/e9tool/e9tool.syms -ldl
+tool.sanitize: CXXFLAGS += -O0 -g -fsanitize=address $(E9TOOL_CXXFLAGS)
+tool.sanitize: $(E9TOOL_OBJS) $(E9TOOL_LIBS)
+ $(CXX) $(CXXFLAGS) $(E9TOOL_OBJS) $(E9TOOL_LIBS) -o e9tool \
+ $(E9TOOL_LDFLAGS)
tool.clean:
rm -rf $(E9TOOL_OBJS) e9tool
@@ -86,6 +93,12 @@ loader_pe:
src/e9patch/e9elf.o: loader_elf
src/e9patch/e9pe.o: loader_pe
+contrib/zydis/libZydis.a:
+ (cd contrib/zydis/; make)
+
+contrib/libdw/libdw.a:
+ (cd contrib/libdw/; make)
+
clean:
rm -rf $(E9PATCH_OBJS) e9patch \
src/e9patch/e9loader.c e9loader.out e9loader.o e9loader.bin
diff --git a/build.sh b/build.sh
index 7113cd2..17a04c4 100755
--- a/build.sh
+++ b/build.sh
@@ -36,56 +36,6 @@ do
shift
done
-TARGET=`readlink zydis`
-if [ ! -d zydis ]
-then
- ZYDIS_VERSION=3f5a3ad8e16658c62d7033e9373232d19480d3cc
- ZYCORE_VERSION=5c341bf141fe9274c9037c542274ead19fb645d8
-
- echo -e "${GREEN}$0${OFF}: downloading zydis-$ZYDIS_VERSION.zip..."
- wget -O zydis-$ZYDIS_VERSION.zip https://github.com/zyantific/zydis/archive/$ZYDIS_VERSION.zip
-
- echo -e "${GREEN}$0${OFF}: downloading zycore-$ZYCORE_VERSION.zip..."
- wget -O zycore-$ZYCORE_VERSION.zip https://github.com/zyantific/zycore-c/archive/$ZYCORE_VERSION.zip
-
- echo -e "${GREEN}$0${OFF}: extracting zydis-$ZYDIS_VERSION.zip..."
- unzip zydis-$ZYDIS_VERSION.zip
- rm -f zydis-$ZYDIS_VERSION.zip
-
- echo -e "${GREEN}$0${OFF}: extracting zycore-$ZYCORE_VERSION.zip..."
- unzip zycore-$ZYCORE_VERSION.zip
- rm -f zycore-$ZYCORE_VERSION.zip
-
- echo -e "${GREEN}$0${OFF}: building Zydis..."
- mv zydis-$ZYDIS_VERSION zydis/
- rm -rf zydis/dependencies/zycore/
- mv zycore-c-$ZYCORE_VERSION zydis/dependencies/zycore/
- rm -rf zycore-c-$ZYCORE_VERSION
- cat << EOF > zydis/include/ZydisExportConfig.h
-#ifndef ZYDIS_EXPORT_H
-#define ZYDIS_EXPORT_H
-#define ZYDIS_EXPORT
-#define ZYDIS_NO_EXPORT
-#define ZYDIS_DEPRECATED __attribute__ ((__deprecated__))
-#define ZYDIS_DEPRECATED_EXPORT ZYDIS_EXPORT ZYDIS_DEPRECATED
-#define ZYDIS_DEPRECATED_NO_EXPORT ZYDIS_NO_EXPORT ZYDIS_DEPRECATED
-#define ZYDIS_NO_DEPRECATED
-#endif
-EOF
- cat << EOF > zydis/include/ZycoreExportConfig.h
-#ifndef ZYCORE_EXPORT_H
-#define ZYCORE_EXPORT_H
-#define ZYCORE_EXPORT
-#define ZYCORE_NO_EXPORT
-#define ZYCORE_DEPRECATED __attribute__ ((__deprecated__))
-#define ZYCORE_DEPRECATED_EXPORT ZYCORE_EXPORT ZYCORE_DEPRECATED
-#define ZYCORE_DEPRECATED_NO_EXPORT ZYCORE_NO_EXPORT ZYCORE_DEPRECATED
-#define ZYCORE_NO_DEPRECATED
-#endif
-EOF
- make -f Makefile.zydis -j `nproc`
-fi
-
echo -e "${GREEN}$0${OFF}: building e9patch and e9tool..."
make tool.clean clean
make -j `nproc` tool release
diff --git a/contrib/libdw/AUTHORS b/contrib/libdw/AUTHORS
new file mode 100644
index 0000000..45cb1f8
--- /dev/null
+++ b/contrib/libdw/AUTHORS
@@ -0,0 +1,104 @@
+Aaron Merey
+Adam Markey
+Adrian Ratiu
+Ahelenia Ziemiańska
+Akihiko Odaki
+Alexander Cherepanov
+Alexander Kanavin
+Alexander Miller
+Alice Zhang
+Andreas Krebbel
+Andreas Schwab
+Andrei Homescu
+Anthony G. Basile
+Ben Woodard
+Chih-Hung Hsieh
+Claudio Rodrigo Pereyra Diaz
+Colin Cross
+Cornelius Neckenig
+Daniel Cabrera
+David Abdurachmanov
+Di Chen
+Dima Kogan
+Dimitris Glezos
+Dmitry V. Levin
+Dodji Seketeli
+Domingo Becker
+Eduardo Santiago
+Eli Schwartz
+Érico Nogueira
+Érico Rolim
+Filipe Brandenburger
+Florian Weimer
+Francesco Tombolini
+Frank Ch. Eigler
+Geert Warrink
+Gladys Guerrero
+Gustavo Romero
+Hayatsu Shunsuke
+H.J. Lu
+Hyu_gabaru Ryu_ichi
+Jakub Jelinek
+Jan Kratochvil
+Jan Pokorný
+Jason P. Leasure
+Jean Pihet
+Jeff Kenton
+Jim Wilson
+John M Mellor-Crummey
+John Ogness
+Jonathan Lebon
+Jonathon Anderson
+Jose E. Marchesi
+Josh Stone
+Joshua Watt
+Kevin Cernekee
+kiyoto hashida
+Konrad Kleine
+Kurt Roeckx
+Kyle McMartin
+Lei Zhang
+Lubomir Rintel
+Luca Boccassi
+Luiz Angelo Daros de Luca
+Mao Han
+Marek Polacek
+Mark Wielaard
+Martin Liska
+Masatake YAMATO
+Matt Fleming
+Matthias Klose
+Matthias Maennich
+Max Filippov
+Michael Forney
+Michael Münch
+Mike Frysinger
+Milian Wolff
+Namhyung Kim
+Noah Sanci
+Noriko Mizumoto
+Omar Sandoval
+Petr Machata
+Pino Toscano
+Piotr Drąg
+Ravi Bangoria
+Richard Henderson
+Roland McGrath
+Rosen Penev
+Ross Burton
+Saleem Abdulrasool
+Sergei Trofimovich
+Srđan Milaković
+Steven Chamberlain
+Thomas Canniot
+Thomas Spura
+Timm Bäder
+Tom Tromey
+Ulf Hermann
+Ulrich Drepper
+Wei Liu
+William Cohen
+Yonghong Song
+Yulia Poyarkova
+Yunlian Jiang
+Yuri Chornoivan
diff --git a/contrib/libdw/COPYING b/contrib/libdw/COPYING
new file mode 100644
index 0000000..94a9ed0
--- /dev/null
+++ b/contrib/libdw/COPYING
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. 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
+them 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 prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. 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.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey 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;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If 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 convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU 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 that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ 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.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+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.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ 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
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+
+ Copyright (C)
+
+ 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 3 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, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program 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, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU 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 Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/contrib/libdw/COPYING-LGPLV3 b/contrib/libdw/COPYING-LGPLV3
new file mode 100644
index 0000000..65c5ca8
--- /dev/null
+++ b/contrib/libdw/COPYING-LGPLV3
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser 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
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/contrib/libdw/Makefile b/contrib/libdw/Makefile
new file mode 100644
index 0000000..c743ad3
--- /dev/null
+++ b/contrib/libdw/Makefile
@@ -0,0 +1,12 @@
+CC=gcc
+CFLAGS = -fPIC -Os -I. -Iinclude/ -D HAVE_CONFIG_H
+
+SRCS = $(wildcard *.c)
+OBJS = $(SRCS:.c=.o)
+
+libdw.a: $(OBJS)
+ ar rvs libdw.a $(OBJS)
+
+clean:
+ rm -rf $(OBJS) libdw.a
+
diff --git a/contrib/libdw/abstract.h b/contrib/libdw/abstract.h
new file mode 100644
index 0000000..d4515f2
--- /dev/null
+++ b/contrib/libdw/abstract.h
@@ -0,0 +1,330 @@
+/* Abstract description of component ELF types.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004, 2007, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+/* ELF header. */
+#define Ehdr(Bits, Ext) \
+START (Bits, Ehdr, Ext##Ehdr) \
+ TYPE_EXTRA (unsigned char e_ident[EI_NIDENT];) \
+ TYPE_XLATE (memmove (tdest->e_ident, tsrc->e_ident, EI_NIDENT);) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_type) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_machine) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), e_version) \
+ TYPE_NAME (ElfW2(Bits, Ext##Addr), e_entry) \
+ TYPE_NAME (ElfW2(Bits, Ext##Off), e_phoff) \
+ TYPE_NAME (ElfW2(Bits, Ext##Off), e_shoff) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), e_flags) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_ehsize) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_phentsize) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_phnum) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_shentsize) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_shnum) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), e_shstrndx) \
+END (Bits, Ext##Ehdr)
+
+#define Ehdr32(Ext) \
+ Ehdr(32, Ext)
+#define Ehdr64(Ext) \
+ Ehdr(64, Ext)
+
+
+/* Program header. */
+#define Phdr32(Ext) \
+START (32, Phdr, Ext##Phdr) \
+ TYPE_NAME (ElfW2(32, Ext##Word), p_type) \
+ TYPE_NAME (ElfW2(32, Ext##Off), p_offset) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), p_vaddr) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), p_paddr) \
+ TYPE_NAME (ElfW2(32, Ext##Word), p_filesz) \
+ TYPE_NAME (ElfW2(32, Ext##Word), p_memsz) \
+ TYPE_NAME (ElfW2(32, Ext##Word), p_flags) \
+ TYPE_NAME (ElfW2(32, Ext##Word), p_align) \
+END (32, Ext##Phdr)
+#define Phdr64(Ext) \
+START (64, Phdr, Ext##Phdr) \
+ TYPE_NAME (ElfW2(64, Ext##Word), p_type) \
+ TYPE_NAME (ElfW2(64, Ext##Word), p_flags) \
+ TYPE_NAME (ElfW2(64, Ext##Off), p_offset) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), p_vaddr) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), p_paddr) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), p_filesz) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), p_memsz) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), p_align) \
+END (64, Ext##Phdr)
+
+
+/* Section header. */
+#define Shdr32(Ext) \
+START (32, Shdr, Ext##Shdr) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_name) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_type) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_flags) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), sh_addr) \
+ TYPE_NAME (ElfW2(32, Ext##Off), sh_offset) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_size) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_link) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_info) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_addralign) \
+ TYPE_NAME (ElfW2(32, Ext##Word), sh_entsize) \
+END (32, Ext##Shdr)
+#define Shdr64(Ext) \
+START (64, Shdr, Ext##Shdr) \
+ TYPE_NAME (ElfW2(64, Ext##Word), sh_name) \
+ TYPE_NAME (ElfW2(64, Ext##Word), sh_type) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), sh_flags) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), sh_addr) \
+ TYPE_NAME (ElfW2(64, Ext##Off), sh_offset) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), sh_size) \
+ TYPE_NAME (ElfW2(64, Ext##Word), sh_link) \
+ TYPE_NAME (ElfW2(64, Ext##Word), sh_info) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), sh_addralign) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), sh_entsize) \
+END (64, Ext##Shdr)
+
+
+/* Symbol table. */
+#define Sym32(Ext) \
+START (32, Sym, Ext##Sym) \
+ TYPE_NAME (ElfW2(32, Ext##Word), st_name) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), st_value) \
+ TYPE_NAME (ElfW2(32, Ext##Word), st_size) \
+ TYPE_EXTRA (unsigned char st_info;) \
+ TYPE_XLATE (tdest->st_info = tsrc->st_info;) \
+ TYPE_EXTRA (unsigned char st_other;) \
+ TYPE_XLATE (tdest->st_other = tsrc->st_other;) \
+ TYPE_NAME (ElfW2(32, Ext##Half), st_shndx) \
+END (32, Ext##Sym)
+#define Sym64(Ext) \
+START (64, Sym, Ext##Sym) \
+ TYPE_NAME (ElfW2(64, Ext##Word), st_name) \
+ TYPE_EXTRA (unsigned char st_info;) \
+ TYPE_XLATE (tdest->st_info = tsrc->st_info;) \
+ TYPE_EXTRA (unsigned char st_other;) \
+ TYPE_XLATE (tdest->st_other = tsrc->st_other;) \
+ TYPE_NAME (ElfW2(64, Ext##Half), st_shndx) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), st_value) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), st_size) \
+END (64, Ext##Sym)
+
+
+/* Relocation. */
+#define Rel32(Ext) \
+START (32, Rel, Ext##Rel) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), r_offset) \
+ TYPE_NAME (ElfW2(32, Ext##Word), r_info) \
+END (32, Ext##Rel)
+#define Rel64(Ext) \
+START (64, Rel, Ext##Rel) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), r_offset) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), r_info) \
+END (64, Ext##Rel)
+
+#define Rela32(Ext) \
+START (32, Rela, Ext##Rela) \
+ TYPE_NAME (ElfW2(32, Ext##Addr), r_offset) \
+ TYPE_NAME (ElfW2(32, Ext##Word), r_info) \
+ TYPE_NAME (ElfW2(32, Ext##Sword), r_addend) \
+END (32, Ext##Rela)
+#define Rela64(Ext) \
+START (64, Rela, Ext##Rela) \
+ TYPE_NAME (ElfW2(64, Ext##Addr), r_offset) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), r_info) \
+ TYPE_NAME (ElfW2(64, Ext##Sxword), r_addend) \
+END (64, Ext##Rela)
+
+
+/* Note entry header. */
+#define Note(Bits, Ext) \
+START (Bits, Nhdr, Ext##Nhdr) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), n_namesz) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), n_descsz) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), n_type) \
+END (Bits, Ext##Nhdr)
+
+#define Note32(Ext) \
+ Note (32, Ext)
+#define Note64(Ext) \
+ Note (64, Ext)
+
+
+/* Dynamic section data. */
+#define Dyn32(Ext) \
+START (32, Dyn, Ext##Dyn) \
+ TYPE_NAME (ElfW2(32, Ext##Sword), d_tag) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(32, Ext##Word) d_val;) \
+ TYPE_EXTRA (ElfW2(32, Ext##Addr) d_ptr;) \
+ TYPE_XLATE (Elf32_cvt_Addr1 (&tdest->d_un.d_val, &tsrc->d_un.d_val);) \
+ TYPE_EXTRA (ElfW2(32, Ext##Off) d_off;) \
+ TYPE_EXTRA (} d_un;) \
+END (32, Ext##Dyn)
+#define Dyn64(Ext) \
+START (64, Dyn, Ext##Dyn) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), d_tag) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(64, Ext##Xword) d_val;) \
+ TYPE_EXTRA (ElfW2(64, Ext##Addr) d_ptr;) \
+ TYPE_XLATE (Elf64_cvt_Addr1 (&tdest->d_un.d_val, &tsrc->d_un.d_val);) \
+ TYPE_EXTRA (} d_un;) \
+END (64, Ext##Dyn)
+
+
+#ifndef GENERATE_CONVERSION
+/* Version definitions. */
+# define Verdef(Bits, Ext) \
+START (Bits, Verdef, Ext##Verdef) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vd_version) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vd_flags) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vd_ndx) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vd_cnt) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vd_hash) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vd_aux) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vd_next) \
+END (Bits, Ext##Verdef)
+
+# define Verdef32(Ext) \
+ Verdef (32, Ext)
+# define Verdef64(Ext) \
+ Verdef (64, Ext)
+
+# define Verdaux(Bits, Ext) \
+START (Bits, Verdaux, Ext##Verdaux) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vda_name) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vda_next) \
+END (Bits, Ext##Verdaux)
+
+# define Verdaux32(Ext) \
+ Verdaux (32, Ext)
+# define Verdaux64(Ext) \
+ Verdaux (64, Ext)
+
+/* Required versions. */
+# define Verneed(Bits, Ext) \
+START (Bits, Verneed, Ext##Verneed) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vn_version) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vn_cnt) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vn_file) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vn_aux) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vn_next) \
+END (Bits, Ext##Verneed)
+
+# define Verneed32(Ext) \
+ Verneed (32, Ext)
+# define Verneed64(Ext) \
+ Verneed (64, Ext)
+
+# define Vernaux(Bits, Ext) \
+START (Bits, Vernaux, Ext##Vernaux) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vna_hash) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vna_flags) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), vna_other) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vna_name) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), vna_next) \
+END (Bits, Ext##Vernaux)
+
+# define Vernaux32(Ext) \
+ Vernaux (32, Ext)
+# define Vernaux64(Ext) \
+ Vernaux (64, Ext)
+#endif
+
+/* Symbol information. */
+#define Syminfo(Bits, Ext) \
+START (Bits, Syminfo, Ext##Syminfo) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), si_boundto) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), si_flags) \
+END (Bits, Ext##Syminfo)
+
+#define Syminfo32(Ext) \
+ Syminfo (32, Ext)
+#define Syminfo64(Ext) \
+ Syminfo (64, Ext)
+
+/* Move information. */
+#define Move(Bits, Ext) \
+START (Bits, Move, Ext##Move) \
+ TYPE_NAME (ElfW2(Bits, Ext##Xword), m_value) \
+ TYPE_NAME (ElfW2(Bits, Ext##Xword), m_info) \
+ TYPE_NAME (ElfW2(Bits, Ext##Xword), m_poffset) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), m_repeat) \
+ TYPE_NAME (ElfW2(Bits, Ext##Half), m_stride) \
+END (Bits, Ext##Move)
+
+#define Move32(Ext) \
+ Move (32, Ext)
+#define Move64(Ext) \
+ Move (64, Ext)
+
+#define Lib(Bits, Ext) \
+START (Bits, Lib, Ext##Lib) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), l_name) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), l_time_stamp) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), l_checksum) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), l_version) \
+ TYPE_NAME (ElfW2(Bits, Ext##Word), l_flags) \
+END (Bits, Ext##Lib)
+
+#define Lib32(Ext) \
+ Lib (32, Ext)
+#define Lib64(Ext) \
+ Lib (64, Ext)
+
+#define auxv_t32(Ext) \
+START (32, auxv_t, Ext##auxv_t) \
+ TYPE_NAME (ElfW2(32, Ext##Word), a_type) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(32, Ext##Word) a_val;) \
+ TYPE_XLATE (Elf32_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);) \
+ TYPE_EXTRA (} a_un;) \
+END (32, Ext##auxv_t)
+#define auxv_t64(Ext) \
+START (64, auxv_t, Ext##auxv_t) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), a_type) \
+ TYPE_EXTRA (union {) \
+ TYPE_EXTRA (ElfW2(64, Ext##Xword) a_val;) \
+ TYPE_XLATE (Elf64_cvt_Addr1 (&tdest->a_un.a_val, &tsrc->a_un.a_val);) \
+ TYPE_EXTRA (} a_un;) \
+END (64, Ext##auxv_t)
+
+/* Note that there is actual compression data right after the Chdr.
+ So we also have a separate conversion function for the whole
+ section. */
+#define Chdr32(Ext) \
+START (32, Chdr, Ext##Chdr) \
+ TYPE_NAME (ElfW2(32, Ext##Word), ch_type) \
+ TYPE_NAME (ElfW2(32, Ext##Word), ch_size) \
+ TYPE_NAME (ElfW2(32, Ext##Word), ch_addralign) \
+END (32, Ext##Chdr)
+
+#define Chdr64(Ext) \
+START (64, Chdr, Ext##Chdr) \
+ TYPE_NAME (ElfW2(64, Ext##Word), ch_type) \
+ TYPE_NAME (ElfW2(64, Ext##Word), ch_reserved) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), ch_size) \
+ TYPE_NAME (ElfW2(64, Ext##Xword), ch_addralign) \
+END (64, Ext##Chdr)
diff --git a/contrib/libdw/atomics.h b/contrib/libdw/atomics.h
new file mode 100644
index 0000000..ffd12f8
--- /dev/null
+++ b/contrib/libdw/atomics.h
@@ -0,0 +1,37 @@
+/* Conditional wrapper header for C11-style atomics.
+ Copyright (C) 2019-2019 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 . */
+
+#include "config.h"
+
+#if HAVE_STDATOMIC_H
+/* If possible, use the compiler's preferred atomics. */
+# include
+#else
+/* Otherwise, try to use the builtins provided by this compiler. */
+# include "stdatomic-fbsd.h"
+#endif /* HAVE_STDATOMIC_H */
diff --git a/contrib/libdw/cfi.h b/contrib/libdw/cfi.h
new file mode 100644
index 0000000..1b0d712
--- /dev/null
+++ b/contrib/libdw/cfi.h
@@ -0,0 +1,238 @@
+/* Internal definitions for libdw CFI interpreter.
+ Copyright (C) 2009-2010, 2013, 2015 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 . */
+
+#ifndef _UNWINDP_H
+#define _UNWINDP_H 1
+
+#include "libdwP.h"
+#include "libelfP.h"
+struct ebl;
+
+/* Cached CIE representation. */
+struct dwarf_cie
+{
+ Dwarf_Off offset; /* Our position, as seen in FDEs' CIE_pointer. */
+
+ Dwarf_Word code_alignment_factor;
+ Dwarf_Sword data_alignment_factor;
+ Dwarf_Word return_address_register;
+
+ size_t fde_augmentation_data_size;
+
+ // play out to initial state
+ const uint8_t *initial_instructions;
+ const uint8_t *initial_instructions_end;
+
+ const Dwarf_Frame *initial_state;
+
+ uint8_t fde_encoding; /* DW_EH_PE_* for addresses in FDEs. */
+ uint8_t lsda_encoding; /* DW_EH_PE_* for LSDA in FDE augmentation. */
+
+ bool sized_augmentation_data; /* Saw 'z': FDEs have self-sized data. */
+ bool signal_frame; /* Saw 'S': FDE is for a signal frame. */
+};
+
+/* Cached FDE representation. */
+struct dwarf_fde
+{
+ struct dwarf_cie *cie;
+
+ /* This FDE describes PC values in [start, end). */
+ Dwarf_Addr start;
+ Dwarf_Addr end;
+
+ const uint8_t *instructions;
+ const uint8_t *instructions_end;
+};
+
+/* This holds everything we cache about the CFI from each ELF file's
+ .debug_frame or .eh_frame section. */
+struct Dwarf_CFI_s
+{
+ /* Dwarf handle we came from. If null, this is .eh_frame data. */
+ Dwarf *dbg;
+#define CFI_IS_EH(cfi) ((cfi)->dbg == NULL)
+
+ /* Data of the .debug_frame or .eh_frame section. */
+ Elf_Data_Scn *data;
+ const unsigned char *e_ident; /* For EI_DATA and EI_CLASS. */
+
+ Dwarf_Addr frame_vaddr; /* DW_EH_PE_pcrel, address of frame section. */
+ Dwarf_Addr textrel; /* DW_EH_PE_textrel base address. */
+ Dwarf_Addr datarel; /* DW_EH_PE_datarel base address. */
+
+ /* Location of next unread entry in the section. */
+ Dwarf_Off next_offset;
+
+ /* Search tree for the CIEs, indexed by CIE_pointer (section offset). */
+ void *cie_tree;
+
+ /* Search tree for the FDEs, indexed by PC address. */
+ void *fde_tree;
+
+ /* Search tree for parsed DWARF expressions, indexed by raw pointer. */
+ void *expr_tree;
+
+ /* Backend hook. */
+ struct ebl *ebl;
+
+ /* Binary search table in .eh_frame_hdr section. */
+ const uint8_t *search_table;
+ size_t search_table_len;
+ Dwarf_Addr search_table_vaddr;
+ size_t search_table_entries;
+ uint8_t search_table_encoding;
+
+ uint16_t e_machine;
+
+ /* True if the file has a byte order different from the host. */
+ bool other_byte_order;
+
+ /* Default rule for registers not previously mentioned
+ is same_value, not undefined. */
+ bool default_same_value;
+};
+
+
+enum dwarf_frame_rule
+ {
+ reg_unspecified, /* Uninitialized state. */
+ reg_undefined, /* DW_CFA_undefined */
+ reg_same_value, /* DW_CFA_same_value */
+ reg_offset, /* DW_CFA_offset_extended et al */
+ reg_val_offset, /* DW_CFA_val_offset et al */
+ reg_register, /* DW_CFA_register */
+ reg_expression, /* DW_CFA_expression */
+ reg_val_expression, /* DW_CFA_val_expression */
+ };
+
+/* This describes what we know about an individual register. */
+struct dwarf_frame_register
+{
+ enum dwarf_frame_rule rule:3;
+
+ /* The meaning of the value bits depends on the rule:
+
+ Rule Value
+ ---- -----
+ undefined unused
+ same_value unused
+ offset(N) N (register saved at CFA + value)
+ val_offset(N) N (register = CFA + value)
+ register(R) R (register = register #value)
+ expression(E) section offset of DW_FORM_block containing E
+ (register saved at address E computes)
+ val_expression(E) section offset of DW_FORM_block containing E
+ (register = value E computes)
+ */
+ Dwarf_Sword value:(sizeof (Dwarf_Sword) * 8 - 3);
+};
+
+/* This holds instructions for unwinding frame at a particular PC location
+ described by an FDE. */
+struct Dwarf_Frame_s
+{
+ /* This frame description covers PC values in [start, end). */
+ Dwarf_Addr start;
+ Dwarf_Addr end;
+
+ Dwarf_CFI *cache;
+
+ /* Previous state saved by DW_CFA_remember_state, or .cie->initial_state,
+ or NULL in an initial_state pseudo-frame. */
+ Dwarf_Frame *prev;
+
+ /* The FDE that generated this frame state. This points to its CIE,
+ which has the return_address_register and signal_frame flag. */
+ struct dwarf_fde *fde;
+
+ /* The CFA is unknown, is R+N, or is computed by a DWARF expression.
+ A bogon in the CFI can indicate an invalid/incalculable rule.
+ We store that as cfa_invalid rather than barfing when processing it,
+ so callers can ignore the bogon unless they really need that CFA. */
+ enum { cfa_undefined, cfa_offset, cfa_expr, cfa_invalid } cfa_rule;
+ union
+ {
+ Dwarf_Op offset;
+ Dwarf_Block expr;
+ } cfa_data;
+ /* We store an offset rule as a DW_OP_bregx operation. */
+#define cfa_val_reg cfa_data.offset.number
+#define cfa_val_offset cfa_data.offset.number2
+
+ size_t nregs;
+ struct dwarf_frame_register regs[];
+};
+
+
+/* Clean up the data structure and all it points to. */
+extern void __libdw_destroy_frame_cache (Dwarf_CFI *cache)
+ __nonnull_attribute__ (1) internal_function;
+
+/* Enter a CIE encountered while reading through for FDEs. */
+extern void __libdw_intern_cie (Dwarf_CFI *cache, Dwarf_Off offset,
+ const Dwarf_CIE *info)
+ __nonnull_attribute__ (1, 3) internal_function;
+
+/* Look up a CIE_pointer for random access. */
+extern struct dwarf_cie *__libdw_find_cie (Dwarf_CFI *cache, Dwarf_Off offset)
+ __nonnull_attribute__ (1) internal_function;
+
+
+/* Look for an FDE covering the given PC address. */
+extern struct dwarf_fde *__libdw_find_fde (Dwarf_CFI *cache,
+ Dwarf_Addr address)
+ __nonnull_attribute__ (1) internal_function;
+
+/* Look for an FDE by its offset in the section. */
+extern struct dwarf_fde *__libdw_fde_by_offset (Dwarf_CFI *cache,
+ Dwarf_Off offset)
+ __nonnull_attribute__ (1) internal_function;
+
+/* Process the FDE that contains the given PC address,
+ to yield the frame state when stopped there.
+ The return value is a DWARF_E_* error code. */
+extern int __libdw_frame_at_address (Dwarf_CFI *cache, struct dwarf_fde *fde,
+ Dwarf_Addr address, Dwarf_Frame **frame)
+ __nonnull_attribute__ (1, 2, 4) internal_function;
+
+
+/* Dummy struct for memory-access.h macros. */
+#define BYTE_ORDER_DUMMY(var, e_ident) \
+ const struct { bool other_byte_order; } var = \
+ { ((BYTE_ORDER == LITTLE_ENDIAN && e_ident[EI_DATA] == ELFDATA2MSB) \
+ || (BYTE_ORDER == BIG_ENDIAN && e_ident[EI_DATA] == ELFDATA2LSB)) }
+
+
+INTDECL (dwarf_next_cfi)
+INTDECL (dwarf_getcfi)
+INTDECL (dwarf_getcfi_elf)
+INTDECL (dwarf_cfi_end)
+INTDECL (dwarf_cfi_addrframe)
+
+#endif /* unwindP.h */
diff --git a/contrib/libdw/chdr_xlate.h b/contrib/libdw/chdr_xlate.h
new file mode 100644
index 0000000..70782b4
--- /dev/null
+++ b/contrib/libdw/chdr_xlate.h
@@ -0,0 +1,33 @@
+#include "common.h"
+
+/* These functions convert a while section, one Chdr plus compression data. */
+
+static void
+Elf32_cvt_chdr (void *dest, const void *src, size_t len, int encode)
+{
+ if (len == 0)
+ return;
+
+ /* Move everything over, if necessary, we only need to xlate the
+ header, not the compressed data following it. */
+ if (dest != src)
+ memmove (dest, src, len);
+
+ if (len >= sizeof (Elf32_Chdr))
+ Elf32_cvt_Chdr (dest, src, sizeof (Elf32_Chdr), encode);
+}
+
+static void
+Elf64_cvt_chdr (void *dest, const void *src, size_t len, int encode)
+{
+ if (len == 0)
+ return;
+
+ /* Move everything over, if necessary, we only need to xlate the
+ header, not the compressed data following it. */
+ if (dest != src)
+ memmove (dest, src, len);
+
+ if (len >= sizeof (Elf64_Chdr))
+ Elf64_cvt_Chdr (dest, src, sizeof (Elf64_Chdr), encode);
+}
diff --git a/contrib/libdw/common.h b/contrib/libdw/common.h
new file mode 100644
index 0000000..9b2a856
--- /dev/null
+++ b/contrib/libdw/common.h
@@ -0,0 +1,160 @@
+/* Common definitions for handling files in memory or only on disk.
+ Copyright (C) 1998, 1999, 2000, 2002, 2005, 2008 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifndef _COMMON_H
+#define _COMMON_H 1
+
+#include
+#include
+
+#include "libelfP.h"
+
+static inline Elf_Kind
+__attribute__ ((unused))
+determine_kind (void *buf, size_t len)
+{
+ /* First test for an archive. */
+ if (len >= SARMAG && memcmp (buf, ARMAG, SARMAG) == 0)
+ return ELF_K_AR;
+
+ /* Next try ELF files. */
+ if (len >= EI_NIDENT && memcmp (buf, ELFMAG, SELFMAG) == 0)
+ {
+ /* Could be an ELF file. */
+ int eclass = (int) ((unsigned char *) buf)[EI_CLASS];
+ int data = (int) ((unsigned char *) buf)[EI_DATA];
+ int version = (int) ((unsigned char *) buf)[EI_VERSION];
+
+ if (eclass > ELFCLASSNONE && eclass < ELFCLASSNUM
+ && data > ELFDATANONE && data < ELFDATANUM
+ && version == EV_CURRENT)
+ return ELF_K_ELF;
+ }
+
+ /* We do not know this file type. */
+ return ELF_K_NONE;
+}
+
+
+/* Allocate an Elf descriptor and fill in the generic information. */
+static inline Elf *
+__attribute__ ((unused))
+allocate_elf (int fildes, void *map_address, int64_t offset, size_t maxsize,
+ Elf_Cmd cmd, Elf *parent, Elf_Kind kind, size_t extra)
+{
+ Elf *result = calloc (1, sizeof (Elf) + extra);
+ if (result == NULL)
+ __libelf_seterrno (ELF_E_NOMEM);
+ else
+ {
+ result->kind = kind;
+ result->ref_count = 1;
+ result->cmd = cmd;
+ result->fildes = fildes;
+ result->start_offset = offset;
+ result->maximum_size = maxsize;
+ result->map_address = map_address;
+ result->parent = parent;
+
+ rwlock_init (result->lock);
+ }
+
+ return result;
+}
+
+
+/* Acquire lock for the descriptor and all children. */
+static void
+__attribute__ ((unused))
+libelf_acquire_all (Elf *elf)
+{
+ rwlock_wrlock (elf->lock);
+
+ if (elf->kind == ELF_K_AR)
+ {
+ Elf *child = elf->state.ar.children;
+
+ while (child != NULL)
+ {
+ if (child->ref_count != 0)
+ libelf_acquire_all (child);
+ child = child->next;
+ }
+ }
+}
+
+/* Release own lock and those of the children. */
+static void
+__attribute__ ((unused))
+libelf_release_all (Elf *elf)
+{
+ if (elf->kind == ELF_K_AR)
+ {
+ Elf *child = elf->state.ar.children;
+
+ while (child != NULL)
+ {
+ if (child->ref_count != 0)
+ libelf_release_all (child);
+ child = child->next;
+ }
+ }
+
+ rwlock_unlock (elf->lock);
+}
+
+
+/* Macro to convert endianness in place. It determines the function it
+ has to use itself. */
+#define CONVERT(Var) \
+ (Var) = (sizeof (Var) == 1 \
+ ? (unsigned char) (Var) \
+ : (sizeof (Var) == 2 \
+ ? bswap_16 (Var) \
+ : (sizeof (Var) == 4 \
+ ? bswap_32 (Var) \
+ : bswap_64 (Var))))
+
+#define CONVERT_TO(Dst, Var) \
+ (Dst) = (sizeof (Var) == 1 \
+ ? (unsigned char) (Var) \
+ : (sizeof (Var) == 2 \
+ ? bswap_16 (Var) \
+ : (sizeof (Var) == 4 \
+ ? bswap_32 (Var) \
+ : bswap_64 (Var))))
+
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define MY_ELFDATA ELFDATA2LSB
+#else
+# define MY_ELFDATA ELFDATA2MSB
+#endif
+
+#endif /* common.h */
diff --git a/contrib/libdw/config.h b/contrib/libdw/config.h
new file mode 100644
index 0000000..ccfebb9
--- /dev/null
+++ b/contrib/libdw/config.h
@@ -0,0 +1,266 @@
+/* Configuration definitions.
+ Copyright (C) 2008, 2009 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 . */
+
+#ifndef CONFIG_H
+#define CONFIG_H 1
+
+#define _GNU_SOURCE
+
+#define PIC 1
+#define HAVE_ERROR_H 1
+#define USE_LOCKS 1
+
+#ifdef USE_LOCKS
+# include
+# include
+# define rwlock_define(class,name) class pthread_rwlock_t name
+# define once_define(class,name) class pthread_once_t name = PTHREAD_ONCE_INIT
+# define RWLOCK_CALL(call) \
+ ({ int _err = pthread_rwlock_ ## call; assert_perror (_err); })
+# define ONCE_CALL(call) \
+ ({ int _err = pthread_ ## call; assert_perror (_err); })
+# define rwlock_init(lock) RWLOCK_CALL (init (&lock, NULL))
+# define rwlock_fini(lock) RWLOCK_CALL (destroy (&lock))
+# define rwlock_rdlock(lock) RWLOCK_CALL (rdlock (&lock))
+# define rwlock_wrlock(lock) RWLOCK_CALL (wrlock (&lock))
+# define rwlock_unlock(lock) RWLOCK_CALL (unlock (&lock))
+# define once(once_control, init_routine) \
+ ONCE_CALL (once (&once_control, init_routine))
+#else
+/* Eventually we will allow multi-threaded applications to use the
+ libraries. Therefore we will add the necessary locking although
+ the macros used expand to nothing for now. */
+# define rwlock_define(class,name) class int name
+# define rwlock_init(lock) ((void) (lock))
+# define rwlock_fini(lock) ((void) (lock))
+# define rwlock_rdlock(lock) ((void) (lock))
+# define rwlock_wrlock(lock) ((void) (lock))
+# define rwlock_unlock(lock) ((void) (lock))
+# define once_define(class,name)
+# define once(once_control, init_routine) init_routine()
+#endif /* USE_LOCKS */
+
+#include
+/* gettext helper macros. */
+#define N_(Str) Str
+#define _(Str) dgettext ("elfutils", Str)
+
+/* Compiler-specific definitions. */
+#define strong_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name)));
+
+#ifdef __i386__
+# define internal_function __attribute__ ((regparm (3), stdcall))
+#else
+# define internal_function /* nothing */
+#endif
+
+#define internal_strong_alias(name, aliasname) \
+ extern __typeof (name) aliasname __attribute__ ((alias (#name))) internal_function;
+
+#define HAVE_VISIBILITY 1
+#ifdef HAVE_VISIBILITY
+#define attribute_hidden \
+ __attribute__ ((visibility ("hidden")))
+#else
+#define attribute_hidden /* empty */
+#endif
+
+#ifdef HAVE_GCC_STRUCT
+#define attribute_packed \
+ __attribute__ ((packed, gcc_struct))
+#else
+#define attribute_packed \
+ __attribute__ ((packed))
+#endif
+
+/* Define ALLOW_UNALIGNED if the architecture allows operations on
+ unaligned memory locations. */
+#define SANITIZE_UNDEFINED 1
+#if (defined __i386__ || defined __x86_64__) && ! CHECK_UNDEFINED
+# define ALLOW_UNALIGNED 1
+#else
+# define ALLOW_UNALIGNED 0
+#endif
+
+#if DEBUGPRED
+# ifdef __x86_64__
+asm (".section predict_data, \"aw\"; .previous\n"
+ ".section predict_line, \"a\"; .previous\n"
+ ".section predict_file, \"a\"; .previous");
+# ifndef PIC
+# define debugpred__(e, E) \
+ ({ long int _e = !!(e); \
+ asm volatile (".pushsection predict_data; ..predictcnt%=: .quad 0; .quad 0\n" \
+ ".section predict_line; .quad %c1\n" \
+ ".section predict_file; .quad %c2; .popsection\n" \
+ "addq $1,..predictcnt%=(,%0,8)" \
+ : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
+ __builtin_expect (_e, E); \
+ })
+# endif
+# elif defined __i386__
+asm (".section predict_data, \"aw\"; .previous\n"
+ ".section predict_line, \"a\"; .previous\n"
+ ".section predict_file, \"a\"; .previous");
+# ifndef PIC
+# define debugpred__(e, E) \
+ ({ long int _e = !!(e); \
+ asm volatile (".pushsection predict_data; ..predictcnt%=: .long 0; .long 0\n" \
+ ".section predict_line; .long %c1\n" \
+ ".section predict_file; .long %c2; .popsection\n" \
+ "incl ..predictcnt%=(,%0,8)" \
+ : : "r" (_e == E), "i" (__LINE__), "i" (__FILE__)); \
+ __builtin_expect (_e, E); \
+ })
+# endif
+# endif
+# ifdef debugpred__
+# define unlikely(e) debugpred__ (e,0)
+# define likely(e) debugpred__ (e,1)
+# endif
+#endif
+#ifndef likely
+# define unlikely(expr) __builtin_expect (!!(expr), 0)
+# define likely(expr) __builtin_expect (!!(expr), 1)
+#endif
+
+#define obstack_calloc(ob, size) \
+ ({ size_t _s = (size); memset (obstack_alloc (ob, _s), '\0', _s); })
+#define obstack_strdup(ob, str) \
+ ({ const char *_s = (str); obstack_copy0 (ob, _s, strlen (_s)); })
+#define obstack_strndup(ob, str, n) \
+ ({ const char *_s = (str); obstack_copy0 (ob, _s, strnlen (_s, n)); })
+
+#if __STDC_VERSION__ >= 199901L
+# define flexarr_size /* empty */
+#else
+# define flexarr_size 0
+#endif
+
+/* Calling conventions. */
+#ifdef __i386__
+# define CALLING_CONVENTION regparm (3), stdcall
+# define AND_CALLING_CONVENTION , regparm (3), stdcall
+#else
+# define CALLING_CONVENTION
+# define AND_CALLING_CONVENTION
+#endif
+
+/* Avoid PLT entries. */
+#ifdef PIC
+# define INTUSE(name) _INTUSE(name)
+# define _INTUSE(name) __##name##_internal
+# define INTDEF(name) _INTDEF(name)
+# define _INTDEF(name) \
+ extern __typeof__ (name) __##name##_internal __attribute__ ((alias (#name)));
+# define INTDECL(name) _INTDECL(name)
+# define _INTDECL(name) \
+ extern __typeof__ (name) __##name##_internal attribute_hidden;
+#else
+# define INTUSE(name) name
+# define INTDEF(name) /* empty */
+# define INTDECL(name) /* empty */
+#endif
+
+/* This macro is used by the tests conditionalize for standalone building. */
+#define ELFUTILS_HEADER(name)
+
+/* Don't reorder with global asm blocks or optimize away. (Doesn't reliably
+ keep it in the same LTO partition, though; -flto-partition=none may be
+ still needed for some gcc versions < 10.) */
+#ifdef __has_attribute
+# if __has_attribute(no_reorder)
+# define used_in_asm __attribute__ ((externally_visible, no_reorder))
+# endif
+#endif
+#ifndef used_in_asm
+# define used_in_asm /* empty */
+#endif
+
+#ifdef SYMBOL_VERSIONING
+# define NEW_INTDEF(name) __typeof (name) INTUSE(name) \
+ __attribute__ ((alias ("_new." #name))) attribute_hidden;
+# ifdef __has_attribute
+# if __has_attribute(symver)
+# define NEW_VERSION(name, version) \
+ __typeof (name) name __asm__ ("_new." #name) \
+ __attribute__ ((symver (#name "@@" #version)));
+# define OLD_VERSION(name, version) _OLD_VERSION1(name, __COUNTER__, version)
+# define _OLD_VERSION1(name, num, version) _OLD_VERSION2(name, num, version)
+# define _OLD_VERSION2(name, num, version) \
+ __typeof (name) _compat_old##num##_##name \
+ __asm__ ("_compat." #version "." #name) \
+ __attribute__ ((alias ("_new." #name), symver (#name "@" #version)));
+# define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
+ __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \
+ __asm__ ("_compat." #version "." #name) \
+ __attribute__ ((symver (#name "@" #version)));
+# define COMPAT_VERSION(name, version, prefix) \
+ asm (".symver _compat." #version "." #name "," #name "@" #version); \
+ __typeof (name) _compat_##prefix##_##name \
+ __asm__ ("_compat." #version "." #name) \
+ __attribute__ ((symver (#name "@" #version)));
+# endif
+# endif
+# ifndef NEW_VERSION
+# define OLD_VERSION(name, version) \
+ asm (".globl _compat." #version "." #name "\n\t" \
+ "_compat." #version "." #name " = _new." #name "\n\t" \
+ ".symver _compat." #version "." #name "," #name "@" #version);
+# define NEW_VERSION(name, version) \
+ __typeof (name) name __asm__ ("_new." #name) used_in_asm; \
+ asm (".symver _new." #name ", " #name "@@" #version);
+# define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
+ __typeof (_compat_##prefix##_##name) _compat_##prefix##_##name \
+ __asm__ ("_compat." #version "." #name) used_in_asm; \
+ asm (".symver _compat." #version "." #name ", " #name "@" #version);
+# define COMPAT_VERSION(name, version, prefix) \
+ __typeof (name) _compat_##prefix##_##name \
+ __asm__ ("_compat." #version "." #name) used_in_asm; \
+ asm (".symver _compat." #version "." #name ", " #name "@" #version);
+# endif
+#else
+# define NEW_INTDEF(name) INTDEF(name)
+# define OLD_VERSION(name, version) /* Nothing for static linking. */
+# define NEW_VERSION(name, version) /* Nothing for static linking. */
+# define COMPAT_VERSION_NEWPROTO(name, version, prefix) \
+ error "should use #ifdef SYMBOL_VERSIONING"
+# define COMPAT_VERSION(name, version, prefix) \
+ error "should use #ifdef SYMBOL_VERSIONING"
+#endif
+
+#ifndef FALLTHROUGH
+# ifdef HAVE_FALLTHROUGH
+# define FALLTHROUGH __attribute__ ((fallthrough))
+# else
+# define FALLTHROUGH ((void) 0)
+# endif
+#endif
+
+#endif /* config.h */
diff --git a/contrib/libdw/dwarf.h b/contrib/libdw/dwarf.h
new file mode 100644
index 0000000..4be32de
--- /dev/null
+++ b/contrib/libdw/dwarf.h
@@ -0,0 +1,1050 @@
+/* This file defines standard DWARF types, structures, and macros.
+ Copyright (C) 2000-2011, 2014, 2016, 2017, 2018 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 . */
+
+#ifndef _DWARF_H
+#define _DWARF_H 1
+
+/* DWARF Unit Header Types. */
+enum
+ {
+ DW_UT_compile = 0x01,
+ DW_UT_type = 0x02,
+ DW_UT_partial = 0x03,
+ DW_UT_skeleton = 0x04,
+ DW_UT_split_compile = 0x05,
+ DW_UT_split_type = 0x06,
+
+ DW_UT_lo_user = 0x80,
+ DW_UT_hi_user = 0xff
+ };
+
+/* DWARF tags. */
+enum
+ {
+ DW_TAG_array_type = 0x01,
+ DW_TAG_class_type = 0x02,
+ DW_TAG_entry_point = 0x03,
+ DW_TAG_enumeration_type = 0x04,
+ DW_TAG_formal_parameter = 0x05,
+ /* 0x06 reserved. */
+ /* 0x07 reserved. */
+ DW_TAG_imported_declaration = 0x08,
+ /* 0x09 reserved. */
+ DW_TAG_label = 0x0a,
+ DW_TAG_lexical_block = 0x0b,
+ /* 0x0c reserved. */
+ DW_TAG_member = 0x0d,
+ /* 0x0e reserved. */
+ DW_TAG_pointer_type = 0x0f,
+ DW_TAG_reference_type = 0x10,
+ DW_TAG_compile_unit = 0x11,
+ DW_TAG_string_type = 0x12,
+ DW_TAG_structure_type = 0x13,
+ /* 0x14 reserved. */
+ DW_TAG_subroutine_type = 0x15,
+ DW_TAG_typedef = 0x16,
+ DW_TAG_union_type = 0x17,
+ DW_TAG_unspecified_parameters = 0x18,
+ DW_TAG_variant = 0x19,
+ DW_TAG_common_block = 0x1a,
+ DW_TAG_common_inclusion = 0x1b,
+ DW_TAG_inheritance = 0x1c,
+ DW_TAG_inlined_subroutine = 0x1d,
+ DW_TAG_module = 0x1e,
+ DW_TAG_ptr_to_member_type = 0x1f,
+ DW_TAG_set_type = 0x20,
+ DW_TAG_subrange_type = 0x21,
+ DW_TAG_with_stmt = 0x22,
+ DW_TAG_access_declaration = 0x23,
+ DW_TAG_base_type = 0x24,
+ DW_TAG_catch_block = 0x25,
+ DW_TAG_const_type = 0x26,
+ DW_TAG_constant = 0x27,
+ DW_TAG_enumerator = 0x28,
+ DW_TAG_file_type = 0x29,
+ DW_TAG_friend = 0x2a,
+ DW_TAG_namelist = 0x2b,
+ DW_TAG_namelist_item = 0x2c,
+ DW_TAG_packed_type = 0x2d,
+ DW_TAG_subprogram = 0x2e,
+ DW_TAG_template_type_parameter = 0x2f,
+ DW_TAG_template_value_parameter = 0x30,
+ DW_TAG_thrown_type = 0x31,
+ DW_TAG_try_block = 0x32,
+ DW_TAG_variant_part = 0x33,
+ DW_TAG_variable = 0x34,
+ DW_TAG_volatile_type = 0x35,
+ DW_TAG_dwarf_procedure = 0x36,
+ DW_TAG_restrict_type = 0x37,
+ DW_TAG_interface_type = 0x38,
+ DW_TAG_namespace = 0x39,
+ DW_TAG_imported_module = 0x3a,
+ DW_TAG_unspecified_type = 0x3b,
+ DW_TAG_partial_unit = 0x3c,
+ DW_TAG_imported_unit = 0x3d,
+ /* 0x3e reserved. Was DW_TAG_mutable_type. */
+ DW_TAG_condition = 0x3f,
+ DW_TAG_shared_type = 0x40,
+ DW_TAG_type_unit = 0x41,
+ DW_TAG_rvalue_reference_type = 0x42,
+ DW_TAG_template_alias = 0x43,
+ DW_TAG_coarray_type = 0x44,
+ DW_TAG_generic_subrange = 0x45,
+ DW_TAG_dynamic_type = 0x46,
+ DW_TAG_atomic_type = 0x47,
+ DW_TAG_call_site = 0x48,
+ DW_TAG_call_site_parameter = 0x49,
+ DW_TAG_skeleton_unit = 0x4a,
+ DW_TAG_immutable_type = 0x4b,
+
+ DW_TAG_lo_user = 0x4080,
+
+ DW_TAG_MIPS_loop = 0x4081,
+ DW_TAG_format_label = 0x4101,
+ DW_TAG_function_template = 0x4102,
+ DW_TAG_class_template = 0x4103,
+
+ DW_TAG_GNU_BINCL = 0x4104,
+ DW_TAG_GNU_EINCL = 0x4105,
+
+ DW_TAG_GNU_template_template_param = 0x4106,
+ DW_TAG_GNU_template_parameter_pack = 0x4107,
+ DW_TAG_GNU_formal_parameter_pack = 0x4108,
+ DW_TAG_GNU_call_site = 0x4109,
+ DW_TAG_GNU_call_site_parameter = 0x410a,
+
+ DW_TAG_hi_user = 0xffff
+ };
+
+
+/* Children determination encodings. */
+enum
+ {
+ DW_CHILDREN_no = 0,
+ DW_CHILDREN_yes = 1
+ };
+
+
+/* DWARF attributes encodings. */
+enum
+ {
+ DW_AT_sibling = 0x01,
+ DW_AT_location = 0x02,
+ DW_AT_name = 0x03,
+ /* 0x04 reserved. */
+ /* 0x05 reserved. */
+ /* 0x06 reserved. */
+ /* 0x07 reserved. */
+ /* 0x08 reserved. */
+ DW_AT_ordering = 0x09,
+ /* 0x0a reserved. */
+ DW_AT_byte_size = 0x0b,
+ DW_AT_bit_offset = 0x0c, /* Deprecated in DWARF4. */
+ DW_AT_bit_size = 0x0d,
+ /* 0x0e reserved. */
+ /* 0x0f reserved. */
+ DW_AT_stmt_list = 0x10,
+ DW_AT_low_pc = 0x11,
+ DW_AT_high_pc = 0x12,
+ DW_AT_language = 0x13,
+ /* 0x14 reserved. */
+ DW_AT_discr = 0x15,
+ DW_AT_discr_value = 0x16,
+ DW_AT_visibility = 0x17,
+ DW_AT_import = 0x18,
+ DW_AT_string_length = 0x19,
+ DW_AT_common_reference = 0x1a,
+ DW_AT_comp_dir = 0x1b,
+ DW_AT_const_value = 0x1c,
+ DW_AT_containing_type = 0x1d,
+ DW_AT_default_value = 0x1e,
+ /* 0x1f reserved. */
+ DW_AT_inline = 0x20,
+ DW_AT_is_optional = 0x21,
+ DW_AT_lower_bound = 0x22,
+ /* 0x23 reserved. */
+ /* 0x24 reserved. */
+ DW_AT_producer = 0x25,
+ /* 0x26 reserved. */
+ DW_AT_prototyped = 0x27,
+ /* 0x28 reserved. */
+ /* 0x29 reserved. */
+ DW_AT_return_addr = 0x2a,
+ /* 0x2b reserved. */
+ DW_AT_start_scope = 0x2c,
+ /* 0x2d reserved. */
+ DW_AT_bit_stride = 0x2e,
+ DW_AT_upper_bound = 0x2f,
+ /* 0x30 reserved. */
+ DW_AT_abstract_origin = 0x31,
+ DW_AT_accessibility = 0x32,
+ DW_AT_address_class = 0x33,
+ DW_AT_artificial = 0x34,
+ DW_AT_base_types = 0x35,
+ DW_AT_calling_convention = 0x36,
+ DW_AT_count = 0x37,
+ DW_AT_data_member_location = 0x38,
+ DW_AT_decl_column = 0x39,
+ DW_AT_decl_file = 0x3a,
+ DW_AT_decl_line = 0x3b,
+ DW_AT_declaration = 0x3c,
+ DW_AT_discr_list = 0x3d,
+ DW_AT_encoding = 0x3e,
+ DW_AT_external = 0x3f,
+ DW_AT_frame_base = 0x40,
+ DW_AT_friend = 0x41,
+ DW_AT_identifier_case = 0x42,
+ DW_AT_macro_info = 0x43, /* Deprecated in DWARF5. */
+ DW_AT_namelist_item = 0x44,
+ DW_AT_priority = 0x45,
+ DW_AT_segment = 0x46,
+ DW_AT_specification = 0x47,
+ DW_AT_static_link = 0x48,
+ DW_AT_type = 0x49,
+ DW_AT_use_location = 0x4a,
+ DW_AT_variable_parameter = 0x4b,
+ DW_AT_virtuality = 0x4c,
+ DW_AT_vtable_elem_location = 0x4d,
+ DW_AT_allocated = 0x4e,
+ DW_AT_associated = 0x4f,
+ DW_AT_data_location = 0x50,
+ DW_AT_byte_stride = 0x51,
+ DW_AT_entry_pc = 0x52,
+ DW_AT_use_UTF8 = 0x53,
+ DW_AT_extension = 0x54,
+ DW_AT_ranges = 0x55,
+ DW_AT_trampoline = 0x56,
+ DW_AT_call_column = 0x57,
+ DW_AT_call_file = 0x58,
+ DW_AT_call_line = 0x59,
+ DW_AT_description = 0x5a,
+ DW_AT_binary_scale = 0x5b,
+ DW_AT_decimal_scale = 0x5c,
+ DW_AT_small = 0x5d,
+ DW_AT_decimal_sign = 0x5e,
+ DW_AT_digit_count = 0x5f,
+ DW_AT_picture_string = 0x60,
+ DW_AT_mutable = 0x61,
+ DW_AT_threads_scaled = 0x62,
+ DW_AT_explicit = 0x63,
+ DW_AT_object_pointer = 0x64,
+ DW_AT_endianity = 0x65,
+ DW_AT_elemental = 0x66,
+ DW_AT_pure = 0x67,
+ DW_AT_recursive = 0x68,
+ DW_AT_signature = 0x69,
+ DW_AT_main_subprogram = 0x6a,
+ DW_AT_data_bit_offset = 0x6b,
+ DW_AT_const_expr = 0x6c,
+ DW_AT_enum_class = 0x6d,
+ DW_AT_linkage_name = 0x6e,
+ DW_AT_string_length_bit_size = 0x6f,
+ DW_AT_string_length_byte_size = 0x70,
+ DW_AT_rank = 0x71,
+ DW_AT_str_offsets_base = 0x72,
+ DW_AT_addr_base = 0x73,
+ DW_AT_rnglists_base = 0x74,
+ /* 0x75 reserved. */
+ DW_AT_dwo_name = 0x76,
+ DW_AT_reference = 0x77,
+ DW_AT_rvalue_reference = 0x78,
+ DW_AT_macros = 0x79,
+ DW_AT_call_all_calls = 0x7a,
+ DW_AT_call_all_source_calls = 0x7b,
+ DW_AT_call_all_tail_calls = 0x7c,
+ DW_AT_call_return_pc = 0x7d,
+ DW_AT_call_value = 0x7e,
+ DW_AT_call_origin = 0x7f,
+ DW_AT_call_parameter = 0x80,
+ DW_AT_call_pc = 0x81,
+ DW_AT_call_tail_call = 0x82,
+ DW_AT_call_target = 0x83,
+ DW_AT_call_target_clobbered = 0x84,
+ DW_AT_call_data_location = 0x85,
+ DW_AT_call_data_value = 0x86,
+ DW_AT_noreturn = 0x87,
+ DW_AT_alignment = 0x88,
+ DW_AT_export_symbols = 0x89,
+ DW_AT_deleted = 0x8a,
+ DW_AT_defaulted = 0x8b,
+ DW_AT_loclists_base = 0x8c,
+
+ DW_AT_lo_user = 0x2000,
+
+ DW_AT_MIPS_fde = 0x2001,
+ DW_AT_MIPS_loop_begin = 0x2002,
+ DW_AT_MIPS_tail_loop_begin = 0x2003,
+ DW_AT_MIPS_epilog_begin = 0x2004,
+ DW_AT_MIPS_loop_unroll_factor = 0x2005,
+ DW_AT_MIPS_software_pipeline_depth = 0x2006,
+ DW_AT_MIPS_linkage_name = 0x2007,
+ DW_AT_MIPS_stride = 0x2008,
+ DW_AT_MIPS_abstract_name = 0x2009,
+ DW_AT_MIPS_clone_origin = 0x200a,
+ DW_AT_MIPS_has_inlines = 0x200b,
+ DW_AT_MIPS_stride_byte = 0x200c,
+ DW_AT_MIPS_stride_elem = 0x200d,
+ DW_AT_MIPS_ptr_dopetype = 0x200e,
+ DW_AT_MIPS_allocatable_dopetype = 0x200f,
+ DW_AT_MIPS_assumed_shape_dopetype = 0x2010,
+ DW_AT_MIPS_assumed_size = 0x2011,
+
+ /* GNU extensions. */
+ DW_AT_sf_names = 0x2101,
+ DW_AT_src_info = 0x2102,
+ DW_AT_mac_info = 0x2103,
+ DW_AT_src_coords = 0x2104,
+ DW_AT_body_begin = 0x2105,
+ DW_AT_body_end = 0x2106,
+ DW_AT_GNU_vector = 0x2107,
+ DW_AT_GNU_guarded_by = 0x2108,
+ DW_AT_GNU_pt_guarded_by = 0x2109,
+ DW_AT_GNU_guarded = 0x210a,
+ DW_AT_GNU_pt_guarded = 0x210b,
+ DW_AT_GNU_locks_excluded = 0x210c,
+ DW_AT_GNU_exclusive_locks_required = 0x210d,
+ DW_AT_GNU_shared_locks_required = 0x210e,
+ DW_AT_GNU_odr_signature = 0x210f,
+ DW_AT_GNU_template_name = 0x2110,
+ DW_AT_GNU_call_site_value = 0x2111,
+ DW_AT_GNU_call_site_data_value = 0x2112,
+ DW_AT_GNU_call_site_target = 0x2113,
+ DW_AT_GNU_call_site_target_clobbered = 0x2114,
+ DW_AT_GNU_tail_call = 0x2115,
+ DW_AT_GNU_all_tail_call_sites = 0x2116,
+ DW_AT_GNU_all_call_sites = 0x2117,
+ DW_AT_GNU_all_source_call_sites = 0x2118,
+ DW_AT_GNU_locviews = 0x2137,
+ DW_AT_GNU_entry_view = 0x2138,
+ DW_AT_GNU_macros = 0x2119,
+ DW_AT_GNU_deleted = 0x211a,
+ /* GNU Debug Fission extensions. */
+ DW_AT_GNU_dwo_name = 0x2130,
+ DW_AT_GNU_dwo_id = 0x2131,
+ DW_AT_GNU_ranges_base = 0x2132,
+ DW_AT_GNU_addr_base = 0x2133,
+ DW_AT_GNU_pubnames = 0x2134,
+ DW_AT_GNU_pubtypes = 0x2135,
+
+ /* https://gcc.gnu.org/wiki/DW_AT_GNU_numerator_denominator */
+ DW_AT_GNU_numerator = 0x2303,
+ DW_AT_GNU_denominator = 0x2304,
+ /* https://gcc.gnu.org/wiki/DW_AT_GNU_bias */
+ DW_AT_GNU_bias = 0x2305,
+
+ DW_AT_hi_user = 0x3fff
+ };
+
+/* Old unofficially attribute names. Should not be used.
+ Will not appear in known-dwarf.h */
+
+/* DWARF1 array subscripts and element data types. */
+#define DW_AT_subscr_data 0x0a
+/* DWARF1 enumeration literals. */
+#define DW_AT_element_list 0x0f
+/* DWARF1 reference for variable to member structure, class or union. */
+#define DW_AT_member 0x14
+
+/* DWARF form encodings. */
+enum
+ {
+ DW_FORM_addr = 0x01,
+ DW_FORM_block2 = 0x03,
+ DW_FORM_block4 = 0x04,
+ DW_FORM_data2 = 0x05,
+ DW_FORM_data4 = 0x06,
+ DW_FORM_data8 = 0x07,
+ DW_FORM_string = 0x08,
+ DW_FORM_block = 0x09,
+ DW_FORM_block1 = 0x0a,
+ DW_FORM_data1 = 0x0b,
+ DW_FORM_flag = 0x0c,
+ DW_FORM_sdata = 0x0d,
+ DW_FORM_strp = 0x0e,
+ DW_FORM_udata = 0x0f,
+ DW_FORM_ref_addr = 0x10,
+ DW_FORM_ref1 = 0x11,
+ DW_FORM_ref2 = 0x12,
+ DW_FORM_ref4 = 0x13,
+ DW_FORM_ref8 = 0x14,
+ DW_FORM_ref_udata = 0x15,
+ DW_FORM_indirect = 0x16,
+ DW_FORM_sec_offset = 0x17,
+ DW_FORM_exprloc = 0x18,
+ DW_FORM_flag_present = 0x19,
+ DW_FORM_strx = 0x1a,
+ DW_FORM_addrx = 0x1b,
+ DW_FORM_ref_sup4 = 0x1c,
+ DW_FORM_strp_sup = 0x1d,
+ DW_FORM_data16 = 0x1e,
+ DW_FORM_line_strp = 0x1f,
+ DW_FORM_ref_sig8 = 0x20,
+ DW_FORM_implicit_const = 0x21,
+ DW_FORM_loclistx = 0x22,
+ DW_FORM_rnglistx = 0x23,
+ DW_FORM_ref_sup8 = 0x24,
+ DW_FORM_strx1 = 0x25,
+ DW_FORM_strx2 = 0x26,
+ DW_FORM_strx3 = 0x27,
+ DW_FORM_strx4 = 0x28,
+ DW_FORM_addrx1 = 0x29,
+ DW_FORM_addrx2 = 0x2a,
+ DW_FORM_addrx3 = 0x2b,
+ DW_FORM_addrx4 = 0x2c,
+
+ /* GNU Debug Fission extensions. */
+ DW_FORM_GNU_addr_index = 0x1f01,
+ DW_FORM_GNU_str_index = 0x1f02,
+
+ DW_FORM_GNU_ref_alt = 0x1f20, /* offset in alternate .debuginfo. */
+ DW_FORM_GNU_strp_alt = 0x1f21 /* offset in alternate .debug_str. */
+ };
+
+
+/* DWARF location operation encodings. */
+enum
+ {
+ DW_OP_addr = 0x03, /* Constant address. */
+ DW_OP_deref = 0x06,
+ DW_OP_const1u = 0x08, /* Unsigned 1-byte constant. */
+ DW_OP_const1s = 0x09, /* Signed 1-byte constant. */
+ DW_OP_const2u = 0x0a, /* Unsigned 2-byte constant. */
+ DW_OP_const2s = 0x0b, /* Signed 2-byte constant. */
+ DW_OP_const4u = 0x0c, /* Unsigned 4-byte constant. */
+ DW_OP_const4s = 0x0d, /* Signed 4-byte constant. */
+ DW_OP_const8u = 0x0e, /* Unsigned 8-byte constant. */
+ DW_OP_const8s = 0x0f, /* Signed 8-byte constant. */
+ DW_OP_constu = 0x10, /* Unsigned LEB128 constant. */
+ DW_OP_consts = 0x11, /* Signed LEB128 constant. */
+ DW_OP_dup = 0x12,
+ DW_OP_drop = 0x13,
+ DW_OP_over = 0x14,
+ DW_OP_pick = 0x15, /* 1-byte stack index. */
+ DW_OP_swap = 0x16,
+ DW_OP_rot = 0x17,
+ DW_OP_xderef = 0x18,
+ DW_OP_abs = 0x19,
+ DW_OP_and = 0x1a,
+ DW_OP_div = 0x1b,
+ DW_OP_minus = 0x1c,
+ DW_OP_mod = 0x1d,
+ DW_OP_mul = 0x1e,
+ DW_OP_neg = 0x1f,
+ DW_OP_not = 0x20,
+ DW_OP_or = 0x21,
+ DW_OP_plus = 0x22,
+ DW_OP_plus_uconst = 0x23, /* Unsigned LEB128 addend. */
+ DW_OP_shl = 0x24,
+ DW_OP_shr = 0x25,
+ DW_OP_shra = 0x26,
+ DW_OP_xor = 0x27,
+ DW_OP_bra = 0x28, /* Signed 2-byte constant. */
+ DW_OP_eq = 0x29,
+ DW_OP_ge = 0x2a,
+ DW_OP_gt = 0x2b,
+ DW_OP_le = 0x2c,
+ DW_OP_lt = 0x2d,
+ DW_OP_ne = 0x2e,
+ DW_OP_skip = 0x2f, /* Signed 2-byte constant. */
+ DW_OP_lit0 = 0x30, /* Literal 0. */
+ DW_OP_lit1 = 0x31, /* Literal 1. */
+ DW_OP_lit2 = 0x32, /* Literal 2. */
+ DW_OP_lit3 = 0x33, /* Literal 3. */
+ DW_OP_lit4 = 0x34, /* Literal 4. */
+ DW_OP_lit5 = 0x35, /* Literal 5. */
+ DW_OP_lit6 = 0x36, /* Literal 6. */
+ DW_OP_lit7 = 0x37, /* Literal 7. */
+ DW_OP_lit8 = 0x38, /* Literal 8. */
+ DW_OP_lit9 = 0x39, /* Literal 9. */
+ DW_OP_lit10 = 0x3a, /* Literal 10. */
+ DW_OP_lit11 = 0x3b, /* Literal 11. */
+ DW_OP_lit12 = 0x3c, /* Literal 12. */
+ DW_OP_lit13 = 0x3d, /* Literal 13. */
+ DW_OP_lit14 = 0x3e, /* Literal 14. */
+ DW_OP_lit15 = 0x3f, /* Literal 15. */
+ DW_OP_lit16 = 0x40, /* Literal 16. */
+ DW_OP_lit17 = 0x41, /* Literal 17. */
+ DW_OP_lit18 = 0x42, /* Literal 18. */
+ DW_OP_lit19 = 0x43, /* Literal 19. */
+ DW_OP_lit20 = 0x44, /* Literal 20. */
+ DW_OP_lit21 = 0x45, /* Literal 21. */
+ DW_OP_lit22 = 0x46, /* Literal 22. */
+ DW_OP_lit23 = 0x47, /* Literal 23. */
+ DW_OP_lit24 = 0x48, /* Literal 24. */
+ DW_OP_lit25 = 0x49, /* Literal 25. */
+ DW_OP_lit26 = 0x4a, /* Literal 26. */
+ DW_OP_lit27 = 0x4b, /* Literal 27. */
+ DW_OP_lit28 = 0x4c, /* Literal 28. */
+ DW_OP_lit29 = 0x4d, /* Literal 29. */
+ DW_OP_lit30 = 0x4e, /* Literal 30. */
+ DW_OP_lit31 = 0x4f, /* Literal 31. */
+ DW_OP_reg0 = 0x50, /* Register 0. */
+ DW_OP_reg1 = 0x51, /* Register 1. */
+ DW_OP_reg2 = 0x52, /* Register 2. */
+ DW_OP_reg3 = 0x53, /* Register 3. */
+ DW_OP_reg4 = 0x54, /* Register 4. */
+ DW_OP_reg5 = 0x55, /* Register 5. */
+ DW_OP_reg6 = 0x56, /* Register 6. */
+ DW_OP_reg7 = 0x57, /* Register 7. */
+ DW_OP_reg8 = 0x58, /* Register 8. */
+ DW_OP_reg9 = 0x59, /* Register 9. */
+ DW_OP_reg10 = 0x5a, /* Register 10. */
+ DW_OP_reg11 = 0x5b, /* Register 11. */
+ DW_OP_reg12 = 0x5c, /* Register 12. */
+ DW_OP_reg13 = 0x5d, /* Register 13. */
+ DW_OP_reg14 = 0x5e, /* Register 14. */
+ DW_OP_reg15 = 0x5f, /* Register 15. */
+ DW_OP_reg16 = 0x60, /* Register 16. */
+ DW_OP_reg17 = 0x61, /* Register 17. */
+ DW_OP_reg18 = 0x62, /* Register 18. */
+ DW_OP_reg19 = 0x63, /* Register 19. */
+ DW_OP_reg20 = 0x64, /* Register 20. */
+ DW_OP_reg21 = 0x65, /* Register 21. */
+ DW_OP_reg22 = 0x66, /* Register 22. */
+ DW_OP_reg23 = 0x67, /* Register 24. */
+ DW_OP_reg24 = 0x68, /* Register 24. */
+ DW_OP_reg25 = 0x69, /* Register 25. */
+ DW_OP_reg26 = 0x6a, /* Register 26. */
+ DW_OP_reg27 = 0x6b, /* Register 27. */
+ DW_OP_reg28 = 0x6c, /* Register 28. */
+ DW_OP_reg29 = 0x6d, /* Register 29. */
+ DW_OP_reg30 = 0x6e, /* Register 30. */
+ DW_OP_reg31 = 0x6f, /* Register 31. */
+ DW_OP_breg0 = 0x70, /* Base register 0. */
+ DW_OP_breg1 = 0x71, /* Base register 1. */
+ DW_OP_breg2 = 0x72, /* Base register 2. */
+ DW_OP_breg3 = 0x73, /* Base register 3. */
+ DW_OP_breg4 = 0x74, /* Base register 4. */
+ DW_OP_breg5 = 0x75, /* Base register 5. */
+ DW_OP_breg6 = 0x76, /* Base register 6. */
+ DW_OP_breg7 = 0x77, /* Base register 7. */
+ DW_OP_breg8 = 0x78, /* Base register 8. */
+ DW_OP_breg9 = 0x79, /* Base register 9. */
+ DW_OP_breg10 = 0x7a, /* Base register 10. */
+ DW_OP_breg11 = 0x7b, /* Base register 11. */
+ DW_OP_breg12 = 0x7c, /* Base register 12. */
+ DW_OP_breg13 = 0x7d, /* Base register 13. */
+ DW_OP_breg14 = 0x7e, /* Base register 14. */
+ DW_OP_breg15 = 0x7f, /* Base register 15. */
+ DW_OP_breg16 = 0x80, /* Base register 16. */
+ DW_OP_breg17 = 0x81, /* Base register 17. */
+ DW_OP_breg18 = 0x82, /* Base register 18. */
+ DW_OP_breg19 = 0x83, /* Base register 19. */
+ DW_OP_breg20 = 0x84, /* Base register 20. */
+ DW_OP_breg21 = 0x85, /* Base register 21. */
+ DW_OP_breg22 = 0x86, /* Base register 22. */
+ DW_OP_breg23 = 0x87, /* Base register 23. */
+ DW_OP_breg24 = 0x88, /* Base register 24. */
+ DW_OP_breg25 = 0x89, /* Base register 25. */
+ DW_OP_breg26 = 0x8a, /* Base register 26. */
+ DW_OP_breg27 = 0x8b, /* Base register 27. */
+ DW_OP_breg28 = 0x8c, /* Base register 28. */
+ DW_OP_breg29 = 0x8d, /* Base register 29. */
+ DW_OP_breg30 = 0x8e, /* Base register 30. */
+ DW_OP_breg31 = 0x8f, /* Base register 31. */
+ DW_OP_regx = 0x90, /* Unsigned LEB128 register. */
+ DW_OP_fbreg = 0x91, /* Signed LEB128 offset. */
+ DW_OP_bregx = 0x92, /* ULEB128 register followed by SLEB128 off. */
+ DW_OP_piece = 0x93, /* ULEB128 size of piece addressed. */
+ DW_OP_deref_size = 0x94, /* 1-byte size of data retrieved. */
+ DW_OP_xderef_size = 0x95, /* 1-byte size of data retrieved. */
+ DW_OP_nop = 0x96,
+ DW_OP_push_object_address = 0x97,
+ DW_OP_call2 = 0x98,
+ DW_OP_call4 = 0x99,
+ DW_OP_call_ref = 0x9a,
+ DW_OP_form_tls_address = 0x9b,/* TLS offset to address in current thread */
+ DW_OP_call_frame_cfa = 0x9c,/* CFA as determined by CFI. */
+ DW_OP_bit_piece = 0x9d, /* ULEB128 size and ULEB128 offset in bits. */
+ DW_OP_implicit_value = 0x9e, /* DW_FORM_block follows opcode. */
+ DW_OP_stack_value = 0x9f, /* No operands, special like DW_OP_piece. */
+
+ DW_OP_implicit_pointer = 0xa0,
+ DW_OP_addrx = 0xa1,
+ DW_OP_constx = 0xa2,
+ DW_OP_entry_value = 0xa3,
+ DW_OP_const_type = 0xa4,
+ DW_OP_regval_type = 0xa5,
+ DW_OP_deref_type = 0xa6,
+ DW_OP_xderef_type = 0xa7,
+ DW_OP_convert = 0xa8,
+ DW_OP_reinterpret = 0xa9,
+
+ /* GNU extensions. */
+ DW_OP_GNU_push_tls_address = 0xe0,
+ DW_OP_GNU_uninit = 0xf0,
+ DW_OP_GNU_encoded_addr = 0xf1,
+ DW_OP_GNU_implicit_pointer = 0xf2,
+ DW_OP_GNU_entry_value = 0xf3,
+ DW_OP_GNU_const_type = 0xf4,
+ DW_OP_GNU_regval_type = 0xf5,
+ DW_OP_GNU_deref_type = 0xf6,
+ DW_OP_GNU_convert = 0xf7,
+ DW_OP_GNU_reinterpret = 0xf9,
+ DW_OP_GNU_parameter_ref = 0xfa,
+
+ /* GNU Debug Fission extensions. */
+ DW_OP_GNU_addr_index = 0xfb,
+ DW_OP_GNU_const_index = 0xfc,
+
+ DW_OP_GNU_variable_value = 0xfd,
+
+ DW_OP_lo_user = 0xe0, /* Implementation-defined range start. */
+ DW_OP_hi_user = 0xff /* Implementation-defined range end. */
+ };
+
+
+/* DWARF base type encodings. */
+enum
+ {
+ DW_ATE_void = 0x0,
+ DW_ATE_address = 0x1,
+ DW_ATE_boolean = 0x2,
+ DW_ATE_complex_float = 0x3,
+ DW_ATE_float = 0x4,
+ DW_ATE_signed = 0x5,
+ DW_ATE_signed_char = 0x6,
+ DW_ATE_unsigned = 0x7,
+ DW_ATE_unsigned_char = 0x8,
+ DW_ATE_imaginary_float = 0x9,
+ DW_ATE_packed_decimal = 0xa,
+ DW_ATE_numeric_string = 0xb,
+ DW_ATE_edited = 0xc,
+ DW_ATE_signed_fixed = 0xd,
+ DW_ATE_unsigned_fixed = 0xe,
+ DW_ATE_decimal_float = 0xf,
+ DW_ATE_UTF = 0x10,
+ DW_ATE_UCS = 0x11,
+ DW_ATE_ASCII = 0x12,
+
+ DW_ATE_lo_user = 0x80,
+ DW_ATE_hi_user = 0xff
+ };
+
+
+/* DWARF decimal sign encodings. */
+enum
+ {
+ DW_DS_unsigned = 1,
+ DW_DS_leading_overpunch = 2,
+ DW_DS_trailing_overpunch = 3,
+ DW_DS_leading_separate = 4,
+ DW_DS_trailing_separate = 5,
+ };
+
+
+/* DWARF endianity encodings. */
+enum
+ {
+ DW_END_default = 0,
+ DW_END_big = 1,
+ DW_END_little = 2,
+
+ DW_END_lo_user = 0x40,
+ DW_END_hi_user = 0xff
+ };
+
+
+/* DWARF accessibility encodings. */
+enum
+ {
+ DW_ACCESS_public = 1,
+ DW_ACCESS_protected = 2,
+ DW_ACCESS_private = 3
+ };
+
+
+/* DWARF visibility encodings. */
+enum
+ {
+ DW_VIS_local = 1,
+ DW_VIS_exported = 2,
+ DW_VIS_qualified = 3
+ };
+
+
+/* DWARF virtuality encodings. */
+enum
+ {
+ DW_VIRTUALITY_none = 0,
+ DW_VIRTUALITY_virtual = 1,
+ DW_VIRTUALITY_pure_virtual = 2
+ };
+
+
+/* DWARF language encodings. */
+enum
+ {
+ DW_LANG_C89 = 0x0001, /* ISO C:1989 */
+ DW_LANG_C = 0x0002, /* C */
+ DW_LANG_Ada83 = 0x0003, /* ISO Ada:1983 */
+ DW_LANG_C_plus_plus = 0x0004, /* ISO C++:1998 */
+ DW_LANG_Cobol74 = 0x0005, /* ISO Cobol:1974 */
+ DW_LANG_Cobol85 = 0x0006, /* ISO Cobol:1985 */
+ DW_LANG_Fortran77 = 0x0007, /* ISO FORTRAN 77 */
+ DW_LANG_Fortran90 = 0x0008, /* ISO Fortran 90 */
+ DW_LANG_Pascal83 = 0x0009, /* ISO Pascal:1983 */
+ DW_LANG_Modula2 = 0x000a, /* ISO Modula-2:1996 */
+ DW_LANG_Java = 0x000b, /* Java */
+ DW_LANG_C99 = 0x000c, /* ISO C:1999 */
+ DW_LANG_Ada95 = 0x000d, /* ISO Ada:1995 */
+ DW_LANG_Fortran95 = 0x000e, /* ISO Fortran 95 */
+ DW_LANG_PLI = 0x000f, /* ISO PL/1:1976 */
+ DW_LANG_ObjC = 0x0010, /* Objective-C */
+ DW_LANG_ObjC_plus_plus = 0x0011, /* Objective-C++ */
+ DW_LANG_UPC = 0x0012, /* Unified Parallel C */
+ DW_LANG_D = 0x0013, /* D */
+ DW_LANG_Python = 0x0014, /* Python */
+ DW_LANG_OpenCL = 0x0015, /* OpenCL */
+ DW_LANG_Go = 0x0016, /* Go */
+ DW_LANG_Modula3 = 0x0017, /* Modula-3 */
+ DW_LANG_Haskell = 0x0018, /* Haskell */
+ DW_LANG_C_plus_plus_03 = 0x0019, /* ISO C++:2003 */
+ DW_LANG_C_plus_plus_11 = 0x001a, /* ISO C++:2011 */
+ DW_LANG_OCaml = 0x001b, /* OCaml */
+ DW_LANG_Rust = 0x001c, /* Rust */
+ DW_LANG_C11 = 0x001d, /* ISO C:2011 */
+ DW_LANG_Swift = 0x001e, /* Swift */
+ DW_LANG_Julia = 0x001f, /* Julia */
+ DW_LANG_Dylan = 0x0020, /* Dylan */
+ DW_LANG_C_plus_plus_14 = 0x0021, /* ISO C++:2014 */
+ DW_LANG_Fortran03 = 0x0022, /* ISO/IEC 1539-1:2004 */
+ DW_LANG_Fortran08 = 0x0023, /* ISO/IEC 1539-1:2010 */
+ DW_LANG_RenderScript = 0x0024, /* RenderScript Kernal Language */
+ DW_LANG_BLISS = 0x0025, /* BLISS */
+
+ DW_LANG_lo_user = 0x8000,
+ DW_LANG_Mips_Assembler = 0x8001, /* Assembler */
+ DW_LANG_hi_user = 0xffff
+ };
+
+/* Old (typo) '1' != 'I'. */
+#define DW_LANG_PL1 DW_LANG_PLI
+
+/* DWARF identifier case encodings. */
+enum
+ {
+ DW_ID_case_sensitive = 0,
+ DW_ID_up_case = 1,
+ DW_ID_down_case = 2,
+ DW_ID_case_insensitive = 3
+ };
+
+
+/* DWARF calling conventions encodings.
+ Used as values of DW_AT_calling_convention for subroutines
+ (normal, program or nocall) or structures, unions and class types
+ (normal, reference or value). */
+enum
+ {
+ DW_CC_normal = 0x1,
+ DW_CC_program = 0x2,
+ DW_CC_nocall = 0x3,
+ DW_CC_pass_by_reference = 0x4,
+ DW_CC_pass_by_value = 0x5,
+ DW_CC_lo_user = 0x40,
+ DW_CC_hi_user = 0xff
+ };
+
+
+/* DWARF inline encodings. */
+enum
+ {
+ DW_INL_not_inlined = 0,
+ DW_INL_inlined = 1,
+ DW_INL_declared_not_inlined = 2,
+ DW_INL_declared_inlined = 3
+ };
+
+
+/* DWARF ordering encodings. */
+enum
+ {
+ DW_ORD_row_major = 0,
+ DW_ORD_col_major = 1
+ };
+
+
+/* DWARF discriminant descriptor encodings. */
+enum
+ {
+ DW_DSC_label = 0,
+ DW_DSC_range = 1
+ };
+
+/* DWARF defaulted member function encodings. */
+enum
+ {
+ DW_DEFAULTED_no = 0,
+ DW_DEFAULTED_in_class = 1,
+ DW_DEFAULTED_out_of_class = 2
+ };
+
+/* DWARF line content descriptions. */
+enum
+ {
+ DW_LNCT_path = 0x1,
+ DW_LNCT_directory_index = 0x2,
+ DW_LNCT_timestamp = 0x3,
+ DW_LNCT_size = 0x4,
+ DW_LNCT_MD5 = 0x5,
+ DW_LNCT_lo_user = 0x2000,
+ DW_LNCT_hi_user = 0x3fff
+ };
+
+/* DWARF standard opcode encodings. */
+enum
+ {
+ DW_LNS_copy = 1,
+ DW_LNS_advance_pc = 2,
+ DW_LNS_advance_line = 3,
+ DW_LNS_set_file = 4,
+ DW_LNS_set_column = 5,
+ DW_LNS_negate_stmt = 6,
+ DW_LNS_set_basic_block = 7,
+ DW_LNS_const_add_pc = 8,
+ DW_LNS_fixed_advance_pc = 9,
+ DW_LNS_set_prologue_end = 10,
+ DW_LNS_set_epilogue_begin = 11,
+ DW_LNS_set_isa = 12
+ };
+
+
+/* DWARF extended opcode encodings. */
+enum
+ {
+ DW_LNE_end_sequence = 1,
+ DW_LNE_set_address = 2,
+ DW_LNE_define_file = 3,
+ DW_LNE_set_discriminator = 4,
+
+ DW_LNE_lo_user = 128,
+
+ DW_LNE_NVIDIA_inlined_call = 144,
+ DW_LNE_NVIDIA_set_function_name = 145,
+
+ DW_LNE_hi_user = 255
+ };
+
+
+/* DWARF macinfo type encodings. */
+enum
+ {
+ DW_MACINFO_define = 1,
+ DW_MACINFO_undef = 2,
+ DW_MACINFO_start_file = 3,
+ DW_MACINFO_end_file = 4,
+ DW_MACINFO_vendor_ext = 255
+ };
+
+
+/* DWARF debug_macro type encodings. */
+enum
+ {
+ DW_MACRO_define = 0x01,
+ DW_MACRO_undef = 0x02,
+ DW_MACRO_start_file = 0x03,
+ DW_MACRO_end_file = 0x04,
+ DW_MACRO_define_strp = 0x05,
+ DW_MACRO_undef_strp = 0x06,
+ DW_MACRO_import = 0x07,
+ DW_MACRO_define_sup = 0x08,
+ DW_MACRO_undef_sup = 0x09,
+ DW_MACRO_import_sup = 0x0a,
+ DW_MACRO_define_strx = 0x0b,
+ DW_MACRO_undef_strx = 0x0c,
+ DW_MACRO_lo_user = 0xe0,
+ DW_MACRO_hi_user = 0xff
+ };
+
+/* Old GNU extension names for DWARF5 debug_macro type encodings.
+ There are no equivalents for the supplementary object file (sup)
+ and indirect string references (strx). */
+#define DW_MACRO_GNU_define DW_MACRO_define
+#define DW_MACRO_GNU_undef DW_MACRO_undef
+#define DW_MACRO_GNU_start_file DW_MACRO_start_file
+#define DW_MACRO_GNU_end_file DW_MACRO_end_file
+#define DW_MACRO_GNU_define_indirect DW_MACRO_define_strp
+#define DW_MACRO_GNU_undef_indirect DW_MACRO_undef_strp
+#define DW_MACRO_GNU_transparent_include DW_MACRO_import
+#define DW_MACRO_GNU_lo_user DW_MACRO_lo_user
+#define DW_MACRO_GNU_hi_user DW_MACRO_hi_user
+
+
+/* Range list entry encoding. */
+enum
+ {
+ DW_RLE_end_of_list = 0x0,
+ DW_RLE_base_addressx = 0x1,
+ DW_RLE_startx_endx = 0x2,
+ DW_RLE_startx_length = 0x3,
+ DW_RLE_offset_pair = 0x4,
+ DW_RLE_base_address = 0x5,
+ DW_RLE_start_end = 0x6,
+ DW_RLE_start_length = 0x7
+ };
+
+
+/* Location list entry encoding. */
+enum
+ {
+ DW_LLE_end_of_list = 0x0,
+ DW_LLE_base_addressx = 0x1,
+ DW_LLE_startx_endx = 0x2,
+ DW_LLE_startx_length = 0x3,
+ DW_LLE_offset_pair = 0x4,
+ DW_LLE_default_location = 0x5,
+ DW_LLE_base_address = 0x6,
+ DW_LLE_start_end = 0x7,
+ DW_LLE_start_length = 0x8
+ };
+
+
+/* GNU DebugFission list entry encodings (.debug_loc.dwo). */
+enum
+ {
+ DW_LLE_GNU_end_of_list_entry = 0x0,
+ DW_LLE_GNU_base_address_selection_entry = 0x1,
+ DW_LLE_GNU_start_end_entry = 0x2,
+ DW_LLE_GNU_start_length_entry = 0x3,
+
+ // http://www.fsfla.org/~lxoliva/papers/sfn/dwarf6-sfn-lvu.txt
+ // https://dwarfstd.org/ShowIssue.php?issue=170427.1
+ DW_LLE_GNU_view_pair = 0x9
+ };
+
+/* DWARF5 package file section identifiers. */
+enum
+ {
+ DW_SECT_INFO = 1,
+ DW_SECT_TYPES = 2, /* Only DWARF4 GNU DebugFission. Reserved in DWARF5. */
+ DW_SECT_ABBREV = 3,
+ DW_SECT_LINE = 4,
+ DW_SECT_LOCLISTS = 5,
+ DW_SECT_STR_OFFSETS = 6,
+ DW_SECT_MACRO = 7,
+ DW_SECT_RNGLISTS = 8,
+ };
+
+
+/* DWARF call frame instruction encodings. */
+enum
+ {
+ DW_CFA_advance_loc = 0x40,
+ DW_CFA_offset = 0x80,
+ DW_CFA_restore = 0xc0,
+ DW_CFA_extended = 0,
+
+ DW_CFA_nop = 0x00,
+ DW_CFA_set_loc = 0x01,
+ DW_CFA_advance_loc1 = 0x02,
+ DW_CFA_advance_loc2 = 0x03,
+ DW_CFA_advance_loc4 = 0x04,
+ DW_CFA_offset_extended = 0x05,
+ DW_CFA_restore_extended = 0x06,
+ DW_CFA_undefined = 0x07,
+ DW_CFA_same_value = 0x08,
+ DW_CFA_register = 0x09,
+ DW_CFA_remember_state = 0x0a,
+ DW_CFA_restore_state = 0x0b,
+ DW_CFA_def_cfa = 0x0c,
+ DW_CFA_def_cfa_register = 0x0d,
+ DW_CFA_def_cfa_offset = 0x0e,
+ DW_CFA_def_cfa_expression = 0x0f,
+ DW_CFA_expression = 0x10,
+ DW_CFA_offset_extended_sf = 0x11,
+ DW_CFA_def_cfa_sf = 0x12,
+ DW_CFA_def_cfa_offset_sf = 0x13,
+ DW_CFA_val_offset = 0x14,
+ DW_CFA_val_offset_sf = 0x15,
+ DW_CFA_val_expression = 0x16,
+
+ DW_CFA_low_user = 0x1c,
+ DW_CFA_MIPS_advance_loc8 = 0x1d,
+ DW_CFA_GNU_window_save = 0x2d,
+ DW_CFA_AARCH64_negate_ra_state = 0x2d,
+ DW_CFA_GNU_args_size = 0x2e,
+ DW_CFA_GNU_negative_offset_extended = 0x2f,
+ DW_CFA_high_user = 0x3f
+ };
+
+/* ID indicating CIE as opposed to FDE in .debug_frame. */
+enum
+ {
+ DW_CIE_ID_32 = 0xffffffffU, /* In 32-bit format CIE header. */
+ DW_CIE_ID_64 = 0xffffffffffffffffULL /* In 64-bit format CIE header. */
+ };
+
+
+/* Information for GNU unwind information. */
+enum
+ {
+ DW_EH_PE_absptr = 0x00,
+ DW_EH_PE_omit = 0xff,
+
+ /* FDE data encoding. */
+ DW_EH_PE_uleb128 = 0x01,
+ DW_EH_PE_udata2 = 0x02,
+ DW_EH_PE_udata4 = 0x03,
+ DW_EH_PE_udata8 = 0x04,
+ DW_EH_PE_sleb128 = 0x09,
+ DW_EH_PE_sdata2 = 0x0a,
+ DW_EH_PE_sdata4 = 0x0b,
+ DW_EH_PE_sdata8 = 0x0c,
+ DW_EH_PE_signed = 0x08,
+
+ /* FDE flags. */
+ DW_EH_PE_pcrel = 0x10,
+ DW_EH_PE_textrel = 0x20,
+ DW_EH_PE_datarel = 0x30,
+ DW_EH_PE_funcrel = 0x40,
+ DW_EH_PE_aligned = 0x50,
+
+ DW_EH_PE_indirect = 0x80
+ };
+
+
+/* DWARF XXX. */
+#define DW_ADDR_none 0
+
+/* Section 7.2.2 of the DWARF3 specification defines a range of escape
+ codes that can appear in the length field of certain DWARF structures.
+
+ These defines enumerate the minimum and maximum values of this range.
+ Currently only the maximum value is used (to indicate that 64-bit
+ values are going to be used in the dwarf data that accompanies the
+ structure). The other values are reserved.
+
+ Note: There is a typo in DWARF3 spec (published Dec 20, 2005). In
+ sections 7.4, 7.5.1, 7.19, 7.20 the minimum escape code is referred to
+ as 0xffffff00 whereas in fact it should be 0xfffffff0. */
+#define DWARF3_LENGTH_MIN_ESCAPE_CODE 0xfffffff0u
+#define DWARF3_LENGTH_MAX_ESCAPE_CODE 0xffffffffu
+#define DWARF3_LENGTH_64_BIT DWARF3_LENGTH_MAX_ESCAPE_CODE
+
+#endif /* dwarf.h */
diff --git a/contrib/libdw/dwarf_abbrev_hash.c b/contrib/libdw/dwarf_abbrev_hash.c
new file mode 100644
index 0000000..d65e804
--- /dev/null
+++ b/contrib/libdw/dwarf_abbrev_hash.c
@@ -0,0 +1,45 @@
+/* Implementation of hash table for DWARF .debug_abbrev section content.
+ Copyright (C) 2000-2010 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2000.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "dwarf_sig8_hash.h"
+#define NO_UNDEF
+#include "libdwP.h"
+
+#define next_prime __libdwarf_next_prime
+extern size_t next_prime (size_t) attribute_hidden;
+
+#include
+
+#undef next_prime
+#define next_prime attribute_hidden __libdwarf_next_prime
+#include "include/next_prime.c"
diff --git a/contrib/libdw/dwarf_abbrev_hash.h b/contrib/libdw/dwarf_abbrev_hash.h
new file mode 100644
index 0000000..a368c59
--- /dev/null
+++ b/contrib/libdw/dwarf_abbrev_hash.h
@@ -0,0 +1,38 @@
+/* Hash table for DWARF .debug_abbrev section content.
+ Copyright (C) 2000, 2001, 2002 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2000.
+
+ 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 . */
+
+#ifndef _DWARF_ABBREV_HASH_H
+#define _DWARF_ABBREV_HASH_H 1
+
+#define NAME Dwarf_Abbrev_Hash
+#define TYPE Dwarf_Abbrev *
+
+#include
+
+#endif /* dwarf_abbrev_hash.h */
diff --git a/contrib/libdw/dwarf_attr.c b/contrib/libdw/dwarf_attr.c
new file mode 100644
index 0000000..db8acfe
--- /dev/null
+++ b/contrib/libdw/dwarf_attr.c
@@ -0,0 +1,52 @@
+/* Return specific DWARF attribute of a DIE.
+ Copyright (C) 2003, 2005, 2014 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+
+Dwarf_Attribute *
+dwarf_attr (Dwarf_Die *die, unsigned int search_name, Dwarf_Attribute *result)
+{
+ if (die == NULL)
+ return NULL;
+
+ /* Search for the attribute with the given name. */
+ result->valp = __libdw_find_attr (die, search_name, &result->code,
+ &result->form);
+ /* Always fill in the CU information. */
+ result->cu = die->cu;
+
+ return result->valp != NULL && result->code == search_name ? result : NULL;
+}
+INTDEF(dwarf_attr)
diff --git a/contrib/libdw/dwarf_begin.c b/contrib/libdw/dwarf_begin.c
new file mode 100644
index 0000000..19d16e5
--- /dev/null
+++ b/contrib/libdw/dwarf_begin.c
@@ -0,0 +1,99 @@
+/* Create descriptor from file descriptor for processing file.
+ Copyright (C) 2002, 2003, 2004, 2005 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include
+
+
+Dwarf *
+dwarf_begin (int fd, Dwarf_Cmd cmd)
+{
+ Elf *elf;
+ Elf_Cmd elfcmd;
+ Dwarf *result = NULL;
+
+ switch (cmd)
+ {
+ case DWARF_C_READ:
+ elfcmd = ELF_C_READ_MMAP;
+ break;
+ case DWARF_C_WRITE:
+ elfcmd = ELF_C_WRITE;
+ break;
+ case DWARF_C_RDWR:
+ elfcmd = ELF_C_RDWR;
+ break;
+ default:
+ /* No valid mode. */
+ __libdw_seterrno (DWARF_E_INVALID_CMD);
+ return NULL;
+ }
+
+ /* We have to call `elf_version' here since the user might have not
+ done it or initialized libelf with a different version. This
+ would break libdwarf since we are using the ELF data structures
+ in a certain way. */
+ elf_version (EV_CURRENT);
+
+ /* Get an ELF descriptor. */
+ elf = elf_begin (fd, elfcmd, NULL);
+ if (elf == NULL)
+ {
+ /* Test why the `elf_begin" call failed. */
+ struct stat st;
+
+ if (fstat (fd, &st) == 0 && ! S_ISREG (st.st_mode))
+ __libdw_seterrno (DWARF_E_NO_REGFILE);
+ else if (errno == EBADF)
+ __libdw_seterrno (DWARF_E_INVALID_FILE);
+ else
+ __libdw_seterrno (DWARF_E_IO_ERROR);
+ }
+ else
+ {
+ /* Do the real work now that we have an ELF descriptor. */
+ result = INTUSE(dwarf_begin_elf) (elf, cmd, NULL);
+
+ /* If this failed, free the resources. */
+ if (result == NULL)
+ elf_end (elf);
+ else
+ result->free_elf = true;
+ }
+
+ return result;
+}
+INTDEF(dwarf_begin)
diff --git a/contrib/libdw/dwarf_begin_elf.c b/contrib/libdw/dwarf_begin_elf.c
new file mode 100644
index 0000000..ca2b7e2
--- /dev/null
+++ b/contrib/libdw/dwarf_begin_elf.c
@@ -0,0 +1,621 @@
+/* Create descriptor from ELF descriptor for processing file.
+ Copyright (C) 2002-2011, 2014, 2015, 2017, 2018 Red Hat, Inc.
+ Copyright (C) 2023, Mark J. Wielaard
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+#include "libdwP.h"
+
+
+/* Section names. (Note .debug_str_offsets is the largest 19 chars.) */
+static const char dwarf_scnnames[IDX_last][19] =
+{
+ [IDX_debug_info] = ".debug_info",
+ [IDX_debug_types] = ".debug_types",
+ [IDX_debug_abbrev] = ".debug_abbrev",
+ [IDX_debug_addr] = ".debug_addr",
+ [IDX_debug_aranges] = ".debug_aranges",
+ [IDX_debug_line] = ".debug_line",
+ [IDX_debug_line_str] = ".debug_line_str",
+ [IDX_debug_frame] = ".debug_frame",
+ [IDX_debug_loc] = ".debug_loc",
+ [IDX_debug_loclists] = ".debug_loclists",
+ [IDX_debug_pubnames] = ".debug_pubnames",
+ [IDX_debug_str] = ".debug_str",
+ [IDX_debug_str_offsets] = ".debug_str_offsets",
+ [IDX_debug_macinfo] = ".debug_macinfo",
+ [IDX_debug_macro] = ".debug_macro",
+ [IDX_debug_ranges] = ".debug_ranges",
+ [IDX_debug_rnglists] = ".debug_rnglists",
+ [IDX_debug_cu_index] = ".debug_cu_index",
+ [IDX_debug_tu_index] = ".debug_tu_index",
+ [IDX_gnu_debugaltlink] = ".gnu_debugaltlink"
+};
+#define ndwarf_scnnames (sizeof (dwarf_scnnames) / sizeof (dwarf_scnnames[0]))
+
+/* Map from section index to string section index.
+ Non-string sections should have STR_SCN_IDX_last. */
+static const enum string_section_index scn_to_string_section_idx[IDX_last] =
+{
+ [IDX_debug_info] = STR_SCN_IDX_last,
+ [IDX_debug_types] = STR_SCN_IDX_last,
+ [IDX_debug_abbrev] = STR_SCN_IDX_last,
+ [IDX_debug_addr] = STR_SCN_IDX_last,
+ [IDX_debug_aranges] = STR_SCN_IDX_last,
+ [IDX_debug_line] = STR_SCN_IDX_last,
+ [IDX_debug_line_str] = STR_SCN_IDX_debug_line_str,
+ [IDX_debug_frame] = STR_SCN_IDX_last,
+ [IDX_debug_loc] = STR_SCN_IDX_last,
+ [IDX_debug_loclists] = STR_SCN_IDX_last,
+ [IDX_debug_pubnames] = STR_SCN_IDX_last,
+ [IDX_debug_str] = STR_SCN_IDX_debug_str,
+ [IDX_debug_str_offsets] = STR_SCN_IDX_last,
+ [IDX_debug_macinfo] = STR_SCN_IDX_last,
+ [IDX_debug_macro] = STR_SCN_IDX_last,
+ [IDX_debug_ranges] = STR_SCN_IDX_last,
+ [IDX_debug_rnglists] = STR_SCN_IDX_last,
+ [IDX_debug_cu_index] = STR_SCN_IDX_last,
+ [IDX_debug_tu_index] = STR_SCN_IDX_last,
+ [IDX_gnu_debugaltlink] = STR_SCN_IDX_last
+};
+
+static enum dwarf_type
+scn_dwarf_type (Dwarf *result, size_t shstrndx, Elf_Scn *scn)
+{
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ return TYPE_UNKNOWN;
+
+ const char *scnname = elf_strptr (result->elf, shstrndx,
+ shdr->sh_name);
+ if (scnname != NULL)
+ {
+ if (startswith (scnname, ".gnu.debuglto_.debug"))
+ return TYPE_GNU_LTO;
+ else if (strcmp (scnname, ".debug_cu_index") == 0
+ || strcmp (scnname, ".debug_tu_index") == 0
+ || strcmp (scnname, ".zdebug_cu_index") == 0
+ || strcmp (scnname, ".zdebug_tu_index") == 0)
+ return TYPE_DWO;
+ else if (startswith (scnname, ".debug_") || startswith (scnname, ".zdebug_"))
+ {
+ size_t len = strlen (scnname);
+ if (strcmp (scnname + len - 4, ".dwo") == 0)
+ return TYPE_DWO;
+ else
+ return TYPE_PLAIN;
+ }
+ }
+ return TYPE_UNKNOWN;
+}
+static Dwarf *
+check_section (Dwarf *result, size_t shstrndx, Elf_Scn *scn, bool inscngrp)
+{
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr;
+
+ /* Get the section header data. */
+ shdr = gelf_getshdr (scn, &shdr_mem);
+ if (shdr == NULL)
+ /* We may read /proc/PID/mem with only program headers mapped and section
+ headers out of the mapped pages. */
+ goto err;
+
+ /* Ignore any SHT_NOBITS sections. Debugging sections should not
+ have been stripped, but in case of a corrupt file we won't try
+ to look at the missing data. */
+ if (unlikely (shdr->sh_type == SHT_NOBITS))
+ return result;
+
+ /* Make sure the section is part of a section group only iff we
+ really need it. If we are looking for the global (= non-section
+ group debug info) we have to ignore all the info in section
+ groups. If we are looking into a section group we cannot look at
+ a section which isn't part of the section group. */
+ if (! inscngrp && (shdr->sh_flags & SHF_GROUP) != 0)
+ /* Ignore the section. */
+ return result;
+
+
+ /* We recognize the DWARF section by their names. This is not very
+ safe and stable but the best we can do. */
+ const char *scnname = elf_strptr (result->elf, shstrndx,
+ shdr->sh_name);
+ if (scnname == NULL)
+ {
+ /* The section name must be valid. Otherwise is the ELF file
+ invalid. */
+ err:
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ return NULL;
+ }
+
+ /* Recognize the various sections. Most names start with .debug_.
+ They might be compressed (and start with .z). Or end with .dwo
+ for split dwarf sections. Or start with .gnu.debuglto_ for
+ LTO debug sections. We should only use one consistent set at
+ a time. We prefer PLAIN over DWO over LTO. */
+ size_t cnt;
+ bool gnu_compressed = false;
+ for (cnt = 0; cnt < ndwarf_scnnames; ++cnt)
+ {
+ /* .debug_cu_index and .debug_tu_index don't have a .dwo suffix,
+ but they are for DWO. */
+ if (result->type != TYPE_DWO
+ && (cnt == IDX_debug_cu_index || cnt == IDX_debug_tu_index))
+ continue;
+ bool need_dot_dwo =
+ (result->type == TYPE_DWO
+ && cnt != IDX_debug_cu_index
+ && cnt != IDX_debug_tu_index);
+ size_t dbglen = strlen (dwarf_scnnames[cnt]);
+ size_t scnlen = strlen (scnname);
+ if (strncmp (scnname, dwarf_scnnames[cnt], dbglen) == 0
+ && ((!need_dot_dwo && dbglen == scnlen)
+ || (need_dot_dwo
+ && scnlen == dbglen + 4
+ && strstr (scnname, ".dwo") == scnname + dbglen)))
+ break;
+ else if (scnname[0] == '.' && scnname[1] == 'z'
+ && (strncmp (&scnname[2], &dwarf_scnnames[cnt][1],
+ dbglen - 1) == 0
+ && ((!need_dot_dwo && scnlen == dbglen + 1)
+ || (need_dot_dwo
+ && scnlen == dbglen + 5
+ && strstr (scnname,
+ ".dwo") == scnname + dbglen + 1))))
+ {
+ gnu_compressed = true;
+ break;
+ }
+ else if (scnlen > 14 /* .gnu.debuglto_ prefix. */
+ && startswith (scnname, ".gnu.debuglto_")
+ && strcmp (&scnname[14], dwarf_scnnames[cnt]) == 0)
+ {
+ if (result->type == TYPE_GNU_LTO)
+ break;
+ }
+ }
+
+ if (cnt >= ndwarf_scnnames)
+ /* Not a debug section; ignore it. */
+ return result;
+
+ if (unlikely (result->sectiondata[cnt] != NULL))
+ /* A section appears twice. That's bad. We ignore the section. */
+ return result;
+
+ /* We cannot know whether or not a GNU compressed section has already
+ been uncompressed or not, so ignore any errors. */
+ if (gnu_compressed)
+ elf_compress_gnu (scn, 0, 0);
+
+ if ((shdr->sh_flags & SHF_COMPRESSED) != 0)
+ {
+ if (elf_compress (scn, 0, 0) < 0)
+ {
+ /* It would be nice if we could fail with a specific error.
+ But we don't know if this was an essential section or not.
+ So just continue for now. See also valid_p(). */
+ return result;
+ }
+ }
+
+ /* Get the section data. Should be raw bytes, no conversion needed. */
+ Elf_Data *data = elf_rawdata (scn, NULL);
+ if (data == NULL)
+ goto err;
+
+ if (data->d_buf == NULL || data->d_size == 0)
+ /* No data actually available, ignore it. */
+ return result;
+
+ /* We can now read the section data into results. */
+ result->sectiondata[cnt] = data;
+
+ /* If the section contains string data, we want to know a size of a prefix
+ where any string will be null-terminated. */
+ enum string_section_index string_section_idx = scn_to_string_section_idx[cnt];
+ if (string_section_idx < STR_SCN_IDX_last)
+ {
+ size_t size = data->d_size;
+ /* Reduce the size by the number of non-zero bytes at the end of the
+ section. */
+ while (size > 0 && *((const char *) data->d_buf + size - 1) != '\0')
+ --size;
+ result->string_section_size[string_section_idx] = size;
+ }
+
+ return result;
+}
+
+char *
+__libdw_elfpath (int fd)
+{
+ /* strlen ("/proc/self/fd/") = 14 + strlen () = 10 + 1 = 25. */
+ char devfdpath[25];
+ sprintf (devfdpath, "/proc/self/fd/%u", fd);
+ return realpath (devfdpath, NULL);
+}
+
+
+void
+__libdw_set_debugdir (Dwarf *dbg)
+{
+ if (dbg->elfpath == NULL || dbg->elfpath[0] != '/')
+ return;
+ size_t dirlen = strrchr (dbg->elfpath, '/') - dbg->elfpath + 1;
+ dbg->debugdir = malloc (dirlen + 1);
+ if (dbg->debugdir == NULL)
+ return;
+ memcpy (dbg->debugdir, dbg->elfpath, dirlen);
+ dbg->debugdir[dirlen] = '\0';
+}
+
+
+/* Check whether all the necessary DWARF information is available. */
+static Dwarf *
+valid_p (Dwarf *result)
+{
+ /* We looked at all the sections. Now determine whether all the
+ sections with debugging information we need are there.
+
+ Require at least one section that can be read "standalone". */
+ if (likely (result != NULL)
+ && unlikely (result->sectiondata[IDX_debug_info] == NULL
+ && result->sectiondata[IDX_debug_line] == NULL
+ && result->sectiondata[IDX_debug_frame] == NULL))
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_NO_DWARF);
+ free (result);
+ result = NULL;
+ }
+
+ /* We are setting up some "fake" CUs, which need an address size.
+ Check the ELF class to come up with something reasonable. */
+ int elf_addr_size = 8;
+ if (result != NULL)
+ {
+ GElf_Ehdr ehdr;
+ if (gelf_getehdr (result->elf, &ehdr) == NULL)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ result = NULL;
+ }
+ else if (ehdr.e_ident[EI_CLASS] == ELFCLASS32)
+ elf_addr_size = 4;
+ }
+
+ /* For dwarf_location_attr () we need a "fake" CU to indicate
+ where the "fake" attribute data comes from. This is a block
+ inside the .debug_loc or .debug_loclists section. */
+ if (result != NULL && result->sectiondata[IDX_debug_loc] != NULL)
+ {
+ result->fake_loc_cu = malloc (sizeof (Dwarf_CU));
+ if (unlikely (result->fake_loc_cu == NULL))
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ free (result);
+ result = NULL;
+ }
+ else
+ {
+ result->fake_loc_cu->sec_idx = IDX_debug_loc;
+ result->fake_loc_cu->dbg = result;
+ result->fake_loc_cu->startp
+ = result->sectiondata[IDX_debug_loc]->d_buf;
+ result->fake_loc_cu->endp
+ = (result->sectiondata[IDX_debug_loc]->d_buf
+ + result->sectiondata[IDX_debug_loc]->d_size);
+ result->fake_loc_cu->locs = NULL;
+ result->fake_loc_cu->address_size = elf_addr_size;
+ result->fake_loc_cu->offset_size = 4;
+ result->fake_loc_cu->version = 4;
+ result->fake_loc_cu->split = NULL;
+ }
+ }
+
+ if (result != NULL && result->sectiondata[IDX_debug_loclists] != NULL)
+ {
+ result->fake_loclists_cu = malloc (sizeof (Dwarf_CU));
+ if (unlikely (result->fake_loclists_cu == NULL))
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ free (result->fake_loc_cu);
+ free (result);
+ result = NULL;
+ }
+ else
+ {
+ result->fake_loclists_cu->sec_idx = IDX_debug_loclists;
+ result->fake_loclists_cu->dbg = result;
+ result->fake_loclists_cu->startp
+ = result->sectiondata[IDX_debug_loclists]->d_buf;
+ result->fake_loclists_cu->endp
+ = (result->sectiondata[IDX_debug_loclists]->d_buf
+ + result->sectiondata[IDX_debug_loclists]->d_size);
+ result->fake_loclists_cu->locs = NULL;
+ result->fake_loclists_cu->address_size = elf_addr_size;
+ result->fake_loclists_cu->offset_size = 4;
+ result->fake_loclists_cu->version = 5;
+ result->fake_loclists_cu->split = NULL;
+ }
+ }
+
+ /* For DW_OP_constx/GNU_const_index and DW_OP_addrx/GNU_addr_index
+ the dwarf_location_attr () will need a "fake" address CU to
+ indicate where the attribute data comes from. This is a just
+ inside the .debug_addr section, if it exists. */
+ if (result != NULL && result->sectiondata[IDX_debug_addr] != NULL)
+ {
+ result->fake_addr_cu = malloc (sizeof (Dwarf_CU));
+ if (unlikely (result->fake_addr_cu == NULL))
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ free (result->fake_loc_cu);
+ free (result->fake_loclists_cu);
+ free (result);
+ result = NULL;
+ }
+ else
+ {
+ result->fake_addr_cu->sec_idx = IDX_debug_addr;
+ result->fake_addr_cu->dbg = result;
+ result->fake_addr_cu->startp
+ = result->sectiondata[IDX_debug_addr]->d_buf;
+ result->fake_addr_cu->endp
+ = (result->sectiondata[IDX_debug_addr]->d_buf
+ + result->sectiondata[IDX_debug_addr]->d_size);
+ result->fake_addr_cu->locs = NULL;
+ result->fake_addr_cu->address_size = elf_addr_size;
+ result->fake_addr_cu->offset_size = 4;
+ result->fake_addr_cu->version = 5;
+ result->fake_addr_cu->split = NULL;
+ }
+ }
+
+ if (result != NULL)
+ {
+ result->elfpath = __libdw_elfpath (result->elf->fildes);
+ __libdw_set_debugdir(result);
+ }
+
+ return result;
+}
+
+
+static Dwarf *
+global_read (Dwarf *result, Elf *elf, size_t shstrndx)
+{
+ Elf_Scn *scn = NULL;
+
+ /* First check the type (PLAIN, DWO, LTO) we are looking for. We
+ prefer PLAIN if available over DWO, over LTO. */
+ while ((scn = elf_nextscn (elf, scn)) != NULL && result->type != TYPE_PLAIN)
+ {
+ enum dwarf_type type = scn_dwarf_type (result, shstrndx, scn);
+ if (type > result->type)
+ result->type = type;
+ }
+
+ scn = NULL;
+ while (result != NULL && (scn = elf_nextscn (elf, scn)) != NULL)
+ result = check_section (result, shstrndx, scn, false);
+
+ return valid_p (result);
+}
+
+
+static Dwarf *
+scngrp_read (Dwarf *result, Elf *elf, size_t shstrndx, Elf_Scn *scngrp)
+{
+ GElf_Shdr shdr_mem;
+ GElf_Shdr *shdr = gelf_getshdr (scngrp, &shdr_mem);
+ if (shdr == NULL)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ return NULL;
+ }
+
+ if ((shdr->sh_flags & SHF_COMPRESSED) != 0
+ && elf_compress (scngrp, 0, 0) < 0)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_COMPRESSED_ERROR);
+ free (result);
+ return NULL;
+ }
+
+ /* SCNGRP is the section descriptor for a section group which might
+ contain debug sections. */
+ Elf_Data *data = elf_getdata (scngrp, NULL);
+ if (data == NULL)
+ {
+ /* We cannot read the section content. Fail! */
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ free (result);
+ return NULL;
+ }
+
+ /* The content of the section is a number of 32-bit words which
+ represent section indices. The first word is a flag word. */
+ Elf32_Word *scnidx = (Elf32_Word *) data->d_buf;
+ size_t cnt;
+
+ /* First check the type (PLAIN, DWO, LTO) we are looking for. We
+ prefer PLAIN if available over DWO, over LTO. */
+ for (cnt = 1; cnt * sizeof (Elf32_Word) <= data->d_size; ++cnt)
+ {
+ Elf_Scn *scn = elf_getscn (elf, scnidx[cnt]);
+ if (scn == NULL)
+ {
+ /* A section group refers to a non-existing section. Should
+ never happen. */
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ return NULL;
+ }
+
+ enum dwarf_type type = scn_dwarf_type (result, shstrndx, scn);
+ if (type > result->type)
+ result->type = type;
+ }
+
+ for (cnt = 1; cnt * sizeof (Elf32_Word) <= data->d_size && result != NULL; ++cnt)
+ {
+ Elf_Scn *scn = elf_getscn (elf, scnidx[cnt]);
+ assert (scn != NULL); // checked above
+ result = check_section (result, shstrndx, scn, true);
+ if (result == NULL)
+ break;
+ }
+
+ return valid_p (result);
+}
+
+
+Dwarf *
+dwarf_begin_elf (Elf *elf, Dwarf_Cmd cmd, Elf_Scn *scngrp)
+{
+ GElf_Ehdr *ehdr;
+ GElf_Ehdr ehdr_mem;
+
+ /* Get the ELF header of the file. We need various pieces of
+ information from it. */
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
+ if (ehdr == NULL)
+ {
+ if (elf_kind (elf) != ELF_K_ELF)
+ __libdw_seterrno (DWARF_E_NOELF);
+ else
+ __libdw_seterrno (DWARF_E_GETEHDR_ERROR);
+
+ return NULL;
+ }
+
+
+ /* Default memory allocation size. */
+ size_t mem_default_size = sysconf (_SC_PAGESIZE) - 4 * sizeof (void *);
+ assert (sizeof (struct Dwarf) < mem_default_size);
+
+ /* Allocate the data structure. */
+ Dwarf *result = calloc (1, sizeof (Dwarf));
+ if (unlikely (result == NULL)
+ || unlikely (Dwarf_Sig8_Hash_init (&result->sig8_hash, 11) < 0))
+ {
+ free (result);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return NULL;
+ }
+
+ /* Fill in some values. */
+ if ((BYTE_ORDER == LITTLE_ENDIAN && ehdr->e_ident[EI_DATA] == ELFDATA2MSB)
+ || (BYTE_ORDER == BIG_ENDIAN && ehdr->e_ident[EI_DATA] == ELFDATA2LSB))
+ result->other_byte_order = true;
+
+ result->elf = elf;
+ result->alt_fd = -1;
+ result->dwp_fd = -1;
+
+ /* Initialize the memory handling. Initial blocks are allocated on first
+ actual allocation. */
+ result->mem_default_size = mem_default_size;
+ result->oom_handler = __libdw_oom;
+ if (pthread_rwlock_init(&result->mem_rwl, NULL) != 0)
+ {
+ free (result);
+ __libdw_seterrno (DWARF_E_NOMEM); /* no memory. */
+ return NULL;
+ }
+ result->mem_stacks = 0;
+ result->mem_tails = NULL;
+
+ if (cmd == DWARF_C_READ || cmd == DWARF_C_RDWR)
+ {
+ /* All sections are recognized by name, so pass the section header
+ string index along to easily get the section names. */
+ size_t shstrndx;
+ if (elf_getshdrstrndx (elf, &shstrndx) != 0)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ free (result);
+ return NULL;
+ }
+
+ /* If the caller provides a section group we get the DWARF
+ sections only from this section group. Otherwise we search
+ for the first section with the required name. Further
+ sections with the name are ignored. The DWARF specification
+ does not really say this is allowed. */
+ if (scngrp == NULL)
+ return global_read (result, elf, shstrndx);
+ else
+ return scngrp_read (result, elf, shstrndx, scngrp);
+ }
+ else if (cmd == DWARF_C_WRITE)
+ {
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_UNIMPL);
+ free (result);
+ return NULL;
+ }
+
+ Dwarf_Sig8_Hash_free (&result->sig8_hash);
+ __libdw_seterrno (DWARF_E_INVALID_CMD);
+ free (result);
+ return NULL;
+}
+INTDEF(dwarf_begin_elf)
diff --git a/contrib/libdw/dwarf_child.c b/contrib/libdw/dwarf_child.c
new file mode 100644
index 0000000..96a0d60
--- /dev/null
+++ b/contrib/libdw/dwarf_child.c
@@ -0,0 +1,193 @@
+/* Return child of current DIE.
+ Copyright (C) 2003-2011, 2014, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+#include
+
+/* Some arbitrary value not conflicting with any existing code. */
+#define INVALID 0xffffe444
+
+
+unsigned char *
+internal_function
+__libdw_find_attr (Dwarf_Die *die, unsigned int search_name,
+ unsigned int *codep, unsigned int *formp)
+{
+ const unsigned char *readp = NULL;
+
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, &readp);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ const unsigned char *endp = die->cu->endp;
+
+ /* Search the name attribute. Attribute has been checked when
+ Dwarf_Abbrev was created, we can read unchecked. */
+ const unsigned char *attrp = abbrevp->attrp;
+ while (1)
+ {
+ /* Get attribute name and form. */
+ unsigned int attr_name;
+ get_uleb128_unchecked (attr_name, attrp);
+
+ unsigned int attr_form;
+ get_uleb128_unchecked (attr_form, attrp);
+
+ /* We can stop if we found the attribute with value zero. */
+ if (attr_name == 0 && attr_form == 0)
+ break;
+
+ if (attr_form == DW_FORM_indirect)
+ {
+ if (readp >= endp)
+ goto invalid;
+ get_uleb128 (attr_form, readp, endp);
+ if (attr_form == DW_FORM_indirect ||
+ attr_form == DW_FORM_implicit_const)
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+ }
+
+ /* Is this the name attribute? */
+ if (attr_name == search_name && search_name != INVALID)
+ {
+ if (codep != NULL)
+ *codep = attr_name;
+ if (formp != NULL)
+ *formp = attr_form;
+
+ /* Normally the attribute data comes from the DIE/info,
+ except for implicit_form, where it comes from the abbrev. */
+ if (attr_form == DW_FORM_implicit_const)
+ return (unsigned char *) attrp;
+ else
+ return (unsigned char *) readp;
+ }
+
+ /* Skip over the rest of this attribute (if there is any). */
+ if (attr_form != 0)
+ {
+ size_t len = __libdw_form_val_len (die->cu, attr_form, readp);
+ if (unlikely (len == (size_t) -1l))
+ {
+ readp = NULL;
+ break;
+ }
+
+ // __libdw_form_val_len will have done a bounds check.
+ readp += len;
+
+ // If the value is in the abbrev data, skip it.
+ if (attr_form == DW_FORM_implicit_const)
+ {
+ int64_t attr_value __attribute__((__unused__));
+ get_sleb128_unchecked (attr_value, attrp);
+ }
+ }
+ }
+
+ // XXX Do we need other values?
+ if (codep != NULL)
+ *codep = INVALID;
+ if (formp != NULL)
+ *formp = INVALID;
+
+ return (unsigned char *) readp;
+}
+
+
+int
+dwarf_child (Dwarf_Die *die, Dwarf_Die *result)
+{
+ /* Ignore previous errors. */
+ if (die == NULL)
+ return -1;
+
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
+ /* If there are no children, do not search. */
+ if (! abbrevp->has_children)
+ return 1;
+
+ /* Skip past the last attribute. */
+ void *addr = __libdw_find_attr (die, INVALID, NULL, NULL);
+
+ if (addr == NULL)
+ return -1;
+
+ /* RESULT can be the same as DIE. So preserve what we need. */
+ struct Dwarf_CU *cu = die->cu;
+
+ /* It's kosher (just suboptimal) to have a null entry first thing (7.5.3).
+ So if this starts with ULEB128 of 0 (even with silly encoding of 0),
+ it is a kosher null entry and we do not really have any children. */
+ const unsigned char *code = addr;
+ const unsigned char *endp = cu->endp;
+ while (1)
+ {
+ if (unlikely (code >= endp)) /* Truncated section. */
+ return 1;
+ if (unlikely (*code == 0x80))
+ ++code;
+ else
+ break;
+ }
+ if (unlikely (*code == '\0'))
+ return 1;
+
+ /* Clear the entire DIE structure. This signals we have not yet
+ determined any of the information. */
+ memset (result, '\0', sizeof (Dwarf_Die));
+
+ /* We have the address. */
+ result->addr = addr;
+
+ /* Same CU as the parent. */
+ result->cu = cu;
+
+ return 0;
+}
+INTDEF(dwarf_child)
diff --git a/contrib/libdw/dwarf_cu_dwp_section_info.c b/contrib/libdw/dwarf_cu_dwp_section_info.c
new file mode 100644
index 0000000..5a081f5
--- /dev/null
+++ b/contrib/libdw/dwarf_cu_dwp_section_info.c
@@ -0,0 +1,532 @@
+/* Read DWARF package file index sections.
+ Copyright (c) 2023 Meta Platforms, Inc. and affiliates.
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+
+#include "libdwP.h"
+
+static Dwarf_Package_Index *
+__libdw_read_package_index (Dwarf *dbg, bool tu)
+{
+ Elf_Data *data;
+ if (tu)
+ data = dbg->sectiondata[IDX_debug_tu_index];
+ else
+ data = dbg->sectiondata[IDX_debug_cu_index];
+
+ /* We need at least 16 bytes for the header. */
+ if (data == NULL || data->d_size < 16)
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ const unsigned char *datap = data->d_buf;
+ const unsigned char *endp = datap + data->d_size;
+ uint16_t version;
+ /* In GNU DebugFission for DWARF 4, the version is 2 as a uword. In the
+ standardized DWARF 5 format, it is a uhalf followed by a padding uhalf.
+ Check for both. */
+ if (read_4ubyte_unaligned (dbg, datap) == 2)
+ version = 2;
+ else
+ {
+ version = read_2ubyte_unaligned (dbg, datap);
+ if (version != 5)
+ {
+ __libdw_seterrno (DWARF_E_VERSION);
+ return NULL;
+ }
+ }
+ datap += 4;
+ uint32_t section_count = read_4ubyte_unaligned_inc (dbg, datap);
+ uint32_t unit_count = read_4ubyte_unaligned_inc (dbg, datap);
+ uint32_t slot_count = read_4ubyte_unaligned_inc (dbg, datap);
+
+ /* The specification has a stricter requirement that
+ slot_count > 3 * unit_count / 2, but this is enough for us. */
+ if (slot_count < unit_count)
+ goto invalid;
+
+ /* After the header, the section must contain:
+
+ 8 byte signature per hash table slot
+ + 4 byte index per hash table slot
+ + Section offset table with 1 header row, 1 row per unit, 1 column per
+ section, 4 bytes per field
+ + Section size table with 1 row per unit, 1 column per section, 4 bytes
+ per field
+
+ We have to be careful about overflow when checking this. */
+ const unsigned char *hash_table = datap;
+ if ((size_t) (endp - hash_table) < (uint64_t) slot_count * 12)
+ goto invalid;
+ const unsigned char *indices = hash_table + (size_t) slot_count * 8;
+ const unsigned char *sections = indices + (size_t) slot_count * 4;
+ if ((size_t) (endp - sections) < (uint64_t) section_count * 4)
+ goto invalid;
+ const unsigned char *section_offsets = sections + (size_t) section_count * 4;
+ if ((uint64_t) unit_count * section_count > UINT64_MAX / 8
+ || ((size_t) (endp - section_offsets)
+ < (uint64_t) unit_count * section_count * 8))
+ goto invalid;
+ const unsigned char *section_sizes
+ = section_offsets + (uint64_t) unit_count * section_count * 4;
+
+ Dwarf_Package_Index *index = malloc (sizeof (*index));
+ if (index == NULL)
+ {
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return NULL;
+ }
+
+ index->dbg = dbg;
+ /* Set absent sections to UINT32_MAX. */
+ for (size_t i = 0;
+ i < sizeof (index->sections) / sizeof (index->sections[0]); i++)
+ index->sections[i] = UINT32_MAX;
+ for (size_t i = 0; i < section_count; i++)
+ {
+ uint32_t section = read_4ubyte_unaligned (dbg, sections + i * 4);
+ /* 2 is DW_SECT_TYPES in version 2 and reserved in version 5. We ignore
+ it for version 5.
+ 5 is DW_SECT_LOC in version 2 and DW_SECT_LOCLISTS in version 5. We
+ use the same index for both.
+ 7 is DW_SECT_MACINFO in version 2 and DW_SECT_MACRO in version 5. We
+ use the same index for both.
+ 8 is DW_SECT_MACRO in version 2 and DW_SECT_RNGLISTS in version 5. We
+ use the same index for version 2's DW_SECT_MACRO as version 2's
+ DW_SECT_MACINFO/version 5's DW_SECT_MACRO.
+ We ignore unknown sections. */
+ if (section == 0)
+ continue;
+ if (version == 2)
+ {
+ if (section > 8)
+ continue;
+ else if (section == 8)
+ section = DW_SECT_MACRO;
+ }
+ else if (section == 2
+ || (section
+ > sizeof (index->sections) / sizeof (index->sections[0])))
+ continue;
+ index->sections[section - 1] = i;
+ }
+
+ /* DW_SECT_INFO (or DW_SECT_TYPES for DWARF 4 type units) and DW_SECT_ABBREV
+ are required. */
+ if (((!tu || dbg->sectiondata[IDX_debug_types] == NULL)
+ && index->sections[DW_SECT_INFO - 1] == UINT32_MAX)
+ || (tu && dbg->sectiondata[IDX_debug_types] != NULL
+ && index->sections[DW_SECT_TYPES - 1] == UINT32_MAX)
+ || index->sections[DW_SECT_ABBREV - 1] == UINT32_MAX)
+ {
+ free (index);
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ index->section_count = section_count;
+ index->unit_count = unit_count;
+ index->slot_count = slot_count;
+ index->last_unit_found = 0;
+ index->hash_table = hash_table;
+ index->indices = indices;
+ index->section_offsets = section_offsets;
+ index->section_sizes = section_sizes;
+ index->debug_info_offsets = NULL;
+
+ return index;
+}
+
+static Dwarf_Package_Index *
+__libdw_package_index (Dwarf *dbg, bool tu)
+{
+ if (tu && dbg->tu_index != NULL)
+ return dbg->tu_index;
+ else if (!tu && dbg->cu_index != NULL)
+ return dbg->cu_index;
+
+ Dwarf_Package_Index *index = __libdw_read_package_index (dbg, tu);
+ if (index == NULL)
+ return NULL;
+
+ /* Offsets in the section offset table are 32-bit unsigned integers. In
+ practice, the .debug_info.dwo section for very large executables can be
+ larger than 4GB. GNU dwp as of binutils 2.41 and llvm-dwp before LLVM 15
+ both accidentally truncate offsets larger than 4GB.
+
+ LLVM 15 detects the overflow and errors out instead; see LLVM commit
+ f8df8114715b ("[DWP][DWARF] Detect and error on debug info offset
+ overflow"). However, lldb in LLVM 16 supports using dwp files with
+ truncated offsets by recovering them directly from the unit headers in the
+ .debug_info.dwo section; see LLVM commit c0db06227721 ("[DWARFLibrary] Add
+ support to re-construct cu-index"). Since LLVM 17, the overflow error can
+ be turned into a warning instead; see LLVM commit 53a483cee801 ("[DWP] add
+ overflow check for llvm-dwp tools if offset overflow").
+
+ LLVM's support for > 4GB offsets is effectively an extension to the DWARF
+ package file format, which we implement here. The strategy is to walk the
+ unit headers in .debug_info.dwo in lockstep with the DW_SECT_INFO columns
+ in the section offset tables. As long as they are in the same order
+ (which they are in practice for both GNU dwp and llvm-dwp), we can
+ correlate the truncated offset and produce a corrected array of offsets.
+
+ Note that this will be fixed properly in DWARF 6:
+ https://dwarfstd.org/issues/220708.2.html. */
+ if (index->sections[DW_SECT_INFO - 1] != UINT32_MAX
+ && dbg->sectiondata[IDX_debug_info]->d_size > UINT32_MAX)
+ {
+ Dwarf_Package_Index *cu_index, *tu_index = NULL;
+ if (tu)
+ {
+ tu_index = index;
+ assert (dbg->cu_index == NULL);
+ cu_index = __libdw_read_package_index (dbg, false);
+ if (cu_index == NULL)
+ {
+ free(index);
+ return NULL;
+ }
+ }
+ else
+ {
+ cu_index = index;
+ if (dbg->sectiondata[IDX_debug_tu_index] != NULL
+ && dbg->sectiondata[IDX_debug_types] == NULL)
+ {
+ assert (dbg->tu_index == NULL);
+ tu_index = __libdw_read_package_index (dbg, true);
+ if (tu_index == NULL)
+ {
+ free(index);
+ return NULL;
+ }
+ }
+ }
+
+ cu_index->debug_info_offsets = malloc (cu_index->unit_count
+ * sizeof (Dwarf_Off));
+ if (cu_index->debug_info_offsets == NULL)
+ {
+ free (tu_index);
+ free (cu_index);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return NULL;
+ }
+ if (tu_index != NULL)
+ {
+ tu_index->debug_info_offsets = malloc (tu_index->unit_count
+ * sizeof (Dwarf_Off));
+ if (tu_index->debug_info_offsets == NULL)
+ {
+ free (tu_index);
+ free (cu_index->debug_info_offsets);
+ free (cu_index);
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return NULL;
+ }
+ }
+
+ Dwarf_Off off = 0;
+ uint32_t cui = 0, tui = 0;
+ uint32_t cu_count = cu_index->unit_count;
+ const unsigned char *cu_offset
+ = cu_index->section_offsets + cu_index->sections[DW_SECT_INFO - 1] * 4;
+ uint32_t tu_count = 0;
+ const unsigned char *tu_offset = NULL;
+ if (tu_index != NULL)
+ {
+ tu_count = tu_index->unit_count;
+ tu_offset = tu_index->section_offsets
+ + tu_index->sections[DW_SECT_INFO - 1] * 4;
+ }
+ while (cui < cu_count || tui < tu_count)
+ {
+ Dwarf_Off next_off;
+ uint8_t unit_type;
+ if (__libdw_next_unit (dbg, false, off, &next_off, NULL, NULL,
+ &unit_type, NULL, NULL, NULL, NULL, NULL)
+ != 0)
+ {
+ not_sorted:
+ free (cu_index->debug_info_offsets);
+ cu_index->debug_info_offsets = NULL;
+ if (tu_index != NULL)
+ {
+ free (tu_index->debug_info_offsets);
+ tu_index->debug_info_offsets = NULL;
+ }
+ break;
+ }
+ if (unit_type != DW_UT_split_type && cui < cu_count)
+ {
+ if ((off & UINT32_MAX) != read_4ubyte_unaligned (dbg, cu_offset))
+ goto not_sorted;
+ cu_index->debug_info_offsets[cui++] = off;
+ cu_offset += cu_index->section_count * 4;
+ }
+ else if (unit_type == DW_UT_split_type && tu_index != NULL
+ && tui < tu_count)
+ {
+ if ((off & UINT32_MAX) != read_4ubyte_unaligned (dbg, tu_offset))
+ goto not_sorted;
+ tu_index->debug_info_offsets[tui++] = off;
+ tu_offset += tu_index->section_count * 4;
+ }
+ off = next_off;
+ }
+
+ if (tu)
+ dbg->cu_index = cu_index;
+ else if (tu_index != NULL)
+ dbg->tu_index = tu_index;
+ }
+
+ if (tu)
+ dbg->tu_index = index;
+ else
+ dbg->cu_index = index;
+ return index;
+}
+
+static int
+__libdw_dwp_unit_row (Dwarf_Package_Index *index, uint64_t unit_id,
+ uint32_t *unit_rowp)
+{
+ if (index == NULL)
+ return -1;
+
+ uint32_t hash = unit_id;
+ uint32_t hash2 = (unit_id >> 32) | 1;
+ /* Only check each slot once. */
+ for (uint32_t n = index->slot_count; n-- > 0; )
+ {
+ size_t slot = hash & (index->slot_count - 1);
+ uint64_t sig = read_8ubyte_unaligned (index->dbg,
+ index->hash_table + slot * 8);
+ if (sig == unit_id)
+ {
+ uint32_t row = read_4ubyte_unaligned (index->dbg,
+ index->indices + slot * 4);
+ if (row > index->unit_count)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+ *unit_rowp = row;
+ return 0;
+ }
+ else if (sig == 0
+ && read_4ubyte_unaligned (index->dbg,
+ index->indices + slot * 4) == 0)
+ break;
+ hash += hash2;
+ }
+ *unit_rowp = 0;
+ return 0;
+}
+
+static int
+__libdw_dwp_section_info (Dwarf_Package_Index *index, uint32_t unit_row,
+ unsigned int section, Dwarf_Off *offsetp,
+ Dwarf_Off *sizep)
+{
+ if (index == NULL)
+ return -1;
+ if (unit_row == 0)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+ if (index->sections[section - 1] == UINT32_MAX)
+ {
+ if (offsetp != NULL)
+ *offsetp = 0;
+ if (sizep != NULL)
+ *sizep = 0;
+ return 0;
+ }
+ size_t i = (size_t)(unit_row - 1) * index->section_count
+ + index->sections[section - 1];
+ if (offsetp != NULL)
+ {
+ if (section == DW_SECT_INFO && index->debug_info_offsets != NULL)
+ *offsetp = index->debug_info_offsets[unit_row - 1];
+ else
+ *offsetp = read_4ubyte_unaligned (index->dbg,
+ index->section_offsets + i * 4);
+ }
+ if (sizep != NULL)
+ *sizep = read_4ubyte_unaligned (index->dbg,
+ index->section_sizes + i * 4);
+ return 0;
+}
+
+int
+internal_function
+__libdw_dwp_find_unit (Dwarf *dbg, bool debug_types, Dwarf_Off off,
+ uint16_t version, uint8_t unit_type, uint64_t unit_id8,
+ uint32_t *unit_rowp, Dwarf_Off *abbrev_offsetp)
+{
+ if (version >= 5
+ && unit_type != DW_UT_split_compile && unit_type != DW_UT_split_type)
+ {
+ not_dwp:
+ *unit_rowp = 0;
+ *abbrev_offsetp = 0;
+ return 0;
+ }
+ bool tu = unit_type == DW_UT_split_type || debug_types;
+ if (dbg->sectiondata[tu ? IDX_debug_tu_index : IDX_debug_cu_index] == NULL)
+ goto not_dwp;
+ Dwarf_Package_Index *index = __libdw_package_index (dbg, tu);
+ if (index == NULL)
+ return -1;
+
+ /* This is always called for ascending offsets. The most obvious way for a
+ producer to generate the section offset table is sorted by offset; both
+ GNU dwp and llvm-dwp do this. In this common case, we can avoid the full
+ lookup. */
+ if (index->last_unit_found < index->unit_count)
+ {
+ Dwarf_Off offset, size;
+ if (__libdw_dwp_section_info (index, index->last_unit_found + 1,
+ debug_types ? DW_SECT_TYPES : DW_SECT_INFO,
+ &offset, &size) != 0)
+ return -1;
+ if (offset <= off && off - offset < size)
+ {
+ *unit_rowp = ++index->last_unit_found;
+ goto done;
+ }
+ else
+ /* The units are not sorted. Don't try again. */
+ index->last_unit_found = index->unit_count;
+ }
+
+ if (version >= 5 || debug_types)
+ {
+ /* In DWARF 5 and in type units, the unit signature is available in the
+ unit header. */
+ if (__libdw_dwp_unit_row (index, unit_id8, unit_rowp) != 0)
+ return -1;
+ }
+ else
+ {
+ /* In DWARF 4 compilation units, the unit signature is an attribute. We
+ can't parse attributes in the split unit until we get the abbreviation
+ table offset from the package index, which is a chicken-and-egg
+ problem. We could get the signature from the skeleton unit, but that
+ may not be available.
+
+ Instead, we resort to a linear scan through the section offset table.
+ Finding all units is therefore quadratic in the number of units.
+ However, this will likely never be needed in practice because of the
+ sorted fast path above. If this ceases to be the case, we can try to
+ plumb through the skeleton unit's signature when it is available, or
+ build a sorted lookup table for binary search. */
+ if (index->sections[DW_SECT_INFO - 1] == UINT32_MAX)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+ for (uint32_t i = 0; i < index->unit_count; i++)
+ {
+ Dwarf_Off offset, size;
+ __libdw_dwp_section_info (index, i + 1, DW_SECT_INFO, &offset,
+ &size);
+ if (offset <= off && off - offset < size)
+ {
+ *unit_rowp = i + 1;
+ goto done;
+ }
+ }
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
+ done:
+ return __libdw_dwp_section_info (index, *unit_rowp, DW_SECT_ABBREV,
+ abbrev_offsetp, NULL);
+}
+
+Dwarf_CU *
+internal_function
+__libdw_dwp_findcu_id (Dwarf *dbg, uint64_t unit_id8)
+{
+ Dwarf_Package_Index *index = __libdw_package_index (dbg, false);
+ uint32_t unit_row;
+ Dwarf_Off offset;
+ Dwarf_CU *cu;
+ if (__libdw_dwp_unit_row (index, unit_id8, &unit_row) == 0
+ && __libdw_dwp_section_info (index, unit_row, DW_SECT_INFO, &offset,
+ NULL) == 0
+ && (cu = __libdw_findcu (dbg, offset, false)) != NULL
+ && cu->unit_type == DW_UT_split_compile
+ && cu->unit_id8 == unit_id8)
+ return cu;
+ else
+ return NULL;
+}
+
+int
+dwarf_cu_dwp_section_info (Dwarf_CU *cu, unsigned int section,
+ Dwarf_Off *offsetp, Dwarf_Off *sizep)
+{
+ if (cu == NULL)
+ return -1;
+ if (section < DW_SECT_INFO || section > DW_SECT_RNGLISTS)
+ {
+ __libdw_seterrno (DWARF_E_UNKNOWN_SECTION);
+ return -1;
+ }
+ if (cu->dwp_row == 0)
+ {
+ if (offsetp != NULL)
+ *offsetp = 0;
+ if (sizep != NULL)
+ *sizep = 0;
+ return 0;
+ }
+ else
+ {
+ Dwarf_Package_Index *index
+ = cu->unit_type == DW_UT_split_compile
+ ? cu->dbg->cu_index : cu->dbg->tu_index;
+ return __libdw_dwp_section_info (index, cu->dwp_row, section, offsetp,
+ sizep);
+ }
+}
+INTDEF(dwarf_cu_dwp_section_info)
diff --git a/contrib/libdw/dwarf_end.c b/contrib/libdw/dwarf_end.c
new file mode 100644
index 0000000..ed8d27b
--- /dev/null
+++ b/contrib/libdw/dwarf_end.c
@@ -0,0 +1,179 @@
+/* Release debugging handling context.
+ Copyright (C) 2002-2011, 2014, 2018 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "libdwP.h"
+#include "cfi.h"
+
+
+static void
+dwarf_package_index_free (Dwarf_Package_Index *index)
+{
+ if (index != NULL)
+ {
+ free (index->debug_info_offsets);
+ free (index);
+ }
+}
+
+
+static void
+noop_free (void *arg __attribute__ ((unused)))
+{
+}
+
+
+static void
+cu_free (void *arg)
+{
+ struct Dwarf_CU *p = (struct Dwarf_CU *) arg;
+
+ tdestroy (p->locs, noop_free);
+
+ /* Only free the CU internals if its not a fake CU. */
+ if(p != p->dbg->fake_loc_cu && p != p->dbg->fake_loclists_cu
+ && p != p->dbg->fake_addr_cu)
+ {
+ Dwarf_Abbrev_Hash_free (&p->abbrev_hash);
+
+ /* Free split dwarf one way (from skeleton to split). */
+ if (p->unit_type == DW_UT_skeleton
+ && p->split != NULL && p->split != (void *)-1)
+ {
+ /* The fake_addr_cu might be shared, only release one. */
+ if (p->dbg->fake_addr_cu == p->split->dbg->fake_addr_cu)
+ p->split->dbg->fake_addr_cu = NULL;
+ /* There is only one DWP file. We free it later. */
+ if (p->split->dbg != p->dbg->dwp_dwarf)
+ INTUSE(dwarf_end) (p->split->dbg);
+ }
+ }
+}
+
+
+int
+dwarf_end (Dwarf *dwarf)
+{
+ if (dwarf != NULL)
+ {
+ dwarf_package_index_free (dwarf->tu_index);
+ dwarf_package_index_free (dwarf->cu_index);
+
+ if (dwarf->cfi != NULL)
+ /* Clean up the CFI cache. */
+ __libdw_destroy_frame_cache (dwarf->cfi);
+
+ Dwarf_Sig8_Hash_free (&dwarf->sig8_hash);
+
+ /* The search tree for the CUs. NB: the CU data itself is
+ allocated separately, but the abbreviation hash tables need
+ to be handled. */
+ tdestroy (dwarf->cu_tree, cu_free);
+ tdestroy (dwarf->tu_tree, cu_free);
+
+ /* Search tree for macro opcode tables. */
+ tdestroy (dwarf->macro_ops, noop_free);
+
+ /* Search tree for decoded .debug_lines units. */
+ tdestroy (dwarf->files_lines, noop_free);
+
+ /* And the split Dwarf. */
+ tdestroy (dwarf->split_tree, noop_free);
+
+ /* Free the internally allocated memory. */
+ for (size_t i = 0; i < dwarf->mem_stacks; i++)
+ {
+ struct libdw_memblock *memp = dwarf->mem_tails[i];
+ while (memp != NULL)
+ {
+ struct libdw_memblock *prevp = memp->prev;
+ free (memp);
+ memp = prevp;
+ }
+ }
+ if (dwarf->mem_tails != NULL)
+ free (dwarf->mem_tails);
+ pthread_rwlock_destroy (&dwarf->mem_rwl);
+
+ /* Free the pubnames helper structure. */
+ free (dwarf->pubnames_sets);
+
+ /* Free the ELF descriptor if necessary. */
+ if (dwarf->free_elf)
+ elf_end (dwarf->elf);
+
+ /* Free the fake location list CU. */
+ if (dwarf->fake_loc_cu != NULL)
+ {
+ cu_free (dwarf->fake_loc_cu);
+ free (dwarf->fake_loc_cu);
+ }
+ if (dwarf->fake_loclists_cu != NULL)
+ {
+ cu_free (dwarf->fake_loclists_cu);
+ free (dwarf->fake_loclists_cu);
+ }
+ if (dwarf->fake_addr_cu != NULL)
+ {
+ cu_free (dwarf->fake_addr_cu);
+ free (dwarf->fake_addr_cu);
+ }
+
+ /* Did we find and allocate the alt Dwarf ourselves? */
+ if (dwarf->alt_fd != -1)
+ {
+ INTUSE(dwarf_end) (dwarf->alt_dwarf);
+ close (dwarf->alt_fd);
+ }
+
+ if (dwarf->dwp_fd != -1)
+ {
+ INTUSE(dwarf_end) (dwarf->dwp_dwarf);
+ close (dwarf->dwp_fd);
+ }
+
+ /* The cached path and dir we found the Dwarf ELF file in. */
+ free (dwarf->elfpath);
+ free (dwarf->debugdir);
+
+ /* Free the context descriptor. */
+ free (dwarf);
+ }
+
+ return 0;
+}
+INTDEF(dwarf_end)
diff --git a/contrib/libdw/dwarf_error.c b/contrib/libdw/dwarf_error.c
new file mode 100644
index 0000000..0123cfa
--- /dev/null
+++ b/contrib/libdw/dwarf_error.c
@@ -0,0 +1,131 @@
+/* Retrieve ELF descriptor used for DWARF access.
+ Copyright (C) 2002-2005, 2009, 2014, 2015, 2017, 2018 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libdwP.h"
+
+
+/* The error number. */
+static __thread int global_error;
+
+
+int
+dwarf_errno (void)
+{
+ int result = global_error;
+ global_error = DWARF_E_NOERROR;
+ return result;
+}
+INTDEF(dwarf_errno)
+
+
+/* XXX For now we use string pointers. Once the table stablelizes
+ make it more DSO-friendly. */
+static const char *errmsgs[] =
+ {
+ [DWARF_E_NOERROR] = N_("no error"),
+ [DWARF_E_UNKNOWN_ERROR] = N_("unknown error"),
+ [DWARF_E_INVALID_ACCESS] = N_("invalid access"),
+ [DWARF_E_NO_REGFILE] = N_("no regular file"),
+ [DWARF_E_IO_ERROR] = N_("I/O error"),
+ [DWARF_E_INVALID_ELF] = N_("invalid ELF file"),
+ [DWARF_E_NO_DWARF] = N_("no DWARF information"),
+ [DWARF_E_COMPRESSED_ERROR] = N_("cannot decompress DWARF"),
+ [DWARF_E_NOELF] = N_("no ELF file"),
+ [DWARF_E_GETEHDR_ERROR] = N_("cannot get ELF header"),
+ [DWARF_E_NOMEM] = N_("out of memory"),
+ [DWARF_E_UNIMPL] = N_("not implemented"),
+ [DWARF_E_INVALID_CMD] = N_("invalid command"),
+ [DWARF_E_INVALID_VERSION] = N_("invalid version"),
+ [DWARF_E_INVALID_FILE] = N_("invalid file"),
+ [DWARF_E_NO_ENTRY] = N_("no entries found"),
+ [DWARF_E_INVALID_DWARF] = N_("invalid DWARF"),
+ [DWARF_E_NO_STRING] = N_("no string data"),
+ [DWARF_E_NO_DEBUG_STR] = N_(".debug_str section missing"),
+ [DWARF_E_NO_DEBUG_LINE_STR] = N_(".debug_line_str section missing"),
+ [DWARF_E_NO_STR_OFFSETS] = N_(".debug_str_offsets section missing"),
+ [DWARF_E_NO_ADDR] = N_("no address value"),
+ [DWARF_E_NO_CONSTANT] = N_("no constant value"),
+ [DWARF_E_NO_REFERENCE] = N_("no reference value"),
+ [DWARF_E_INVALID_REFERENCE] = N_("invalid reference value"),
+ [DWARF_E_NO_DEBUG_LINE] = N_(".debug_line section missing"),
+ [DWARF_E_INVALID_DEBUG_LINE] = N_("invalid .debug_line section"),
+ [DWARF_E_TOO_BIG] = N_("debug information too big"),
+ [DWARF_E_VERSION] = N_("invalid DWARF version"),
+ [DWARF_E_INVALID_DIR_IDX] = N_("invalid directory index"),
+ [DWARF_E_ADDR_OUTOFRANGE] = N_("address out of range"),
+ [DWARF_E_NO_DEBUG_LOC] = N_(".debug_loc section missing"),
+ [DWARF_E_NO_DEBUG_LOCLISTS] = N_(".debug_loclists section missing"),
+ [DWARF_E_NO_LOC_VALUE] = N_("not a location list value"),
+ [DWARF_E_NO_BLOCK] = N_("no block data"),
+ [DWARF_E_INVALID_LINE_IDX] = N_("invalid line index"),
+ [DWARF_E_INVALID_ARANGE_IDX] = N_("invalid address range index"),
+ [DWARF_E_NO_MATCH] = N_("no matching address range"),
+ [DWARF_E_NO_FLAG] = N_("no flag value"),
+ [DWARF_E_INVALID_OFFSET] = N_("invalid offset"),
+ [DWARF_E_NO_DEBUG_RANGES] = N_(".debug_ranges section missing"),
+ [DWARF_E_NO_DEBUG_RNGLISTS] = N_(".debug_rnglists section missing"),
+ [DWARF_E_INVALID_CFI] = N_("invalid CFI section"),
+ [DWARF_E_NO_ALT_DEBUGLINK] = N_("no alternative debug link found"),
+ [DWARF_E_INVALID_OPCODE] = N_("invalid opcode"),
+ [DWARF_E_NOT_CUDIE] = N_("not a CU (unit) DIE"),
+ [DWARF_E_UNKNOWN_LANGUAGE] = N_("unknown language code"),
+ [DWARF_E_NO_DEBUG_ADDR] = N_(".debug_addr section missing"),
+ [DWARF_E_UNKNOWN_SECTION] = N_("unknown section"),
+ };
+#define nerrmsgs (sizeof (errmsgs) / sizeof (errmsgs[0]))
+
+
+void
+internal_function
+__libdw_seterrno (int value)
+{
+ global_error = (value >= 0 && value < (int) nerrmsgs
+ ? value : DWARF_E_UNKNOWN_ERROR);
+}
+
+
+const char *
+dwarf_errmsg (int error)
+{
+ int last_error = global_error;
+
+ if (error == 0)
+ return last_error != 0 ? _(errmsgs[last_error]) : NULL;
+ else if (error < -1 || error >= (int) nerrmsgs)
+ return _(errmsgs[DWARF_E_UNKNOWN_ERROR]);
+
+ return _(errmsgs[error == -1 ? last_error : error]);
+}
+INTDEF(dwarf_errmsg)
diff --git a/contrib/libdw/dwarf_formstring.c b/contrib/libdw/dwarf_formstring.c
new file mode 100644
index 0000000..65f03a5
--- /dev/null
+++ b/contrib/libdw/dwarf_formstring.c
@@ -0,0 +1,183 @@
+/* Return string associated with given attribute.
+ Copyright (C) 2003-2010, 2013, 2017, 2018 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+
+const char *
+dwarf_formstring (Dwarf_Attribute *attrp)
+{
+ /* Ignore earlier errors. */
+ if (attrp == NULL)
+ return NULL;
+
+ /* We found it. Now determine where the string is stored. */
+ if (attrp->form == DW_FORM_string)
+ /* A simple inlined string. */
+ return (const char *) attrp->valp;
+
+ Dwarf_CU *cu = attrp->cu;
+ Dwarf *dbg = cu->dbg;
+ Dwarf *dbg_ret = ((attrp->form == DW_FORM_GNU_strp_alt
+ || attrp->form == DW_FORM_strp_sup)
+ ? INTUSE(dwarf_getalt) (dbg) : dbg);
+
+ if (unlikely (dbg_ret == NULL))
+ {
+ __libdw_seterrno (DWARF_E_NO_ALT_DEBUGLINK);
+ return NULL;
+ }
+
+ Elf_Data *data = ((attrp->form == DW_FORM_line_strp)
+ ? dbg_ret->sectiondata[IDX_debug_line_str]
+ : dbg_ret->sectiondata[IDX_debug_str]);
+ size_t data_size = ((attrp->form == DW_FORM_line_strp)
+ ? dbg_ret->string_section_size[STR_SCN_IDX_debug_line_str]
+ : dbg_ret->string_section_size[STR_SCN_IDX_debug_str]);
+ if (data == NULL)
+ {
+ __libdw_seterrno ((attrp->form == DW_FORM_line_strp)
+ ? DWARF_E_NO_DEBUG_LINE_STR
+ : DWARF_E_NO_DEBUG_STR);
+ return NULL;
+ }
+
+ uint64_t off;
+ if (attrp->form == DW_FORM_strp
+ || attrp->form == DW_FORM_GNU_strp_alt
+ || attrp->form == DW_FORM_strp_sup)
+ {
+ if (__libdw_read_offset (dbg, dbg_ret, cu_sec_idx (cu),
+ attrp->valp, cu->offset_size, &off,
+ IDX_debug_str, 1))
+ return NULL;
+ }
+ else if (attrp->form == DW_FORM_line_strp)
+ {
+ if (__libdw_read_offset (dbg, dbg_ret, cu_sec_idx (cu),
+ attrp->valp, cu->offset_size, &off,
+ IDX_debug_line_str, 1))
+ return NULL;
+ }
+ else
+ {
+ Dwarf_Word idx;
+ const unsigned char *datap = attrp->valp;
+ const unsigned char *endp = cu->endp;
+ switch (attrp->form)
+ {
+ case DW_FORM_strx:
+ case DW_FORM_GNU_str_index:
+ if (datap >= endp)
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+ get_uleb128 (idx, datap, endp);
+ break;
+
+ case DW_FORM_strx1:
+ if (datap >= endp - 1)
+ goto invalid;
+ idx = *datap;
+ break;
+
+ case DW_FORM_strx2:
+ if (datap >= endp - 2)
+ goto invalid;
+ idx = read_2ubyte_unaligned (dbg, datap);
+ break;
+
+ case DW_FORM_strx3:
+ if (datap >= endp - 3)
+ goto invalid;
+ idx = read_3ubyte_unaligned (dbg, datap);
+ break;
+
+ case DW_FORM_strx4:
+ if (datap >= endp - 4)
+ goto invalid;
+ idx = read_4ubyte_unaligned (dbg, datap);
+ break;
+
+ default:
+ __libdw_seterrno (DWARF_E_NO_STRING);
+ return NULL;
+ }
+
+ /* So we got an index in the .debug_str_offsets. Lets see if it
+ is valid and we can get the actual .debug_str offset. */
+ Dwarf_Off str_off = __libdw_cu_str_off_base (cu);
+ if (str_off == (Dwarf_Off) -1)
+ return NULL;
+
+ if (dbg->sectiondata[IDX_debug_str_offsets] == NULL)
+ {
+ __libdw_seterrno (DWARF_E_NO_STR_OFFSETS);
+ return NULL;
+ }
+
+ /* The section should at least contain room for one offset. */
+ int offset_size = cu->offset_size;
+ if (cu->offset_size > dbg->sectiondata[IDX_debug_str_offsets]->d_size)
+ {
+ invalid_offset:
+ __libdw_seterrno (DWARF_E_INVALID_OFFSET);
+ return NULL;
+ }
+
+ /* And the base offset should be at least inside the section. */
+ if (str_off > (dbg->sectiondata[IDX_debug_str_offsets]->d_size
+ - offset_size))
+ goto invalid_offset;
+
+ size_t max_idx = (dbg->sectiondata[IDX_debug_str_offsets]->d_size
+ - offset_size - str_off) / offset_size;
+ if (idx > max_idx)
+ goto invalid_offset;
+
+ datap = (dbg->sectiondata[IDX_debug_str_offsets]->d_buf
+ + str_off + (idx * offset_size));
+ if (offset_size == 4)
+ off = read_4ubyte_unaligned (dbg, datap);
+ else
+ off = read_8ubyte_unaligned (dbg, datap);
+ }
+
+ if (off >= data_size)
+ goto invalid_offset;
+
+ return (const char *) data->d_buf + off;
+}
+INTDEF(dwarf_formstring)
diff --git a/contrib/libdw/dwarf_formudata.c b/contrib/libdw/dwarf_formudata.c
new file mode 100644
index 0000000..26f86f1
--- /dev/null
+++ b/contrib/libdw/dwarf_formudata.c
@@ -0,0 +1,357 @@
+/* Return unsigned constant represented by attribute.
+ Copyright (C) 2003-2012, 2014, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+internal_function const unsigned char *
+__libdw_formptr (Dwarf_Attribute *attr, int sec_index,
+ int err_nodata, const unsigned char **endpp,
+ Dwarf_Off *offsetp)
+{
+ if (attr == NULL)
+ return NULL;
+
+ const Elf_Data *d = attr->cu->dbg->sectiondata[sec_index];
+ Dwarf_CU *skel = NULL; /* See below, needed for GNU DebugFission. */
+ if (unlikely (d == NULL
+ && sec_index == IDX_debug_ranges
+ && attr->cu->version < 5
+ && attr->cu->unit_type == DW_UT_split_compile))
+ {
+ skel = __libdw_find_split_unit (attr->cu);
+ if (skel != NULL)
+ d = skel->dbg->sectiondata[IDX_debug_ranges];
+ }
+
+ if (unlikely (d == NULL))
+ {
+ __libdw_seterrno (err_nodata);
+ return NULL;
+ }
+
+ Dwarf_Word offset;
+ if (attr->form == DW_FORM_sec_offset)
+ {
+ /* GNU DebugFission is slightly odd. It uses DW_FORM_sec_offset
+ in split units, but they are really (unrelocated) offsets
+ from the skeleton DW_AT_GNU_ranges_base (which is only used
+ for the split unit, not the skeleton ranges itself, see also
+ DW_AT_rnglists_base, which is used in DWARF5 for both, but
+ points to the offsets index). So it isn't really a formptr,
+ but an offset + base calculation. */
+ if (unlikely (skel != NULL))
+ {
+ Elf_Data *data = attr->cu->dbg->sectiondata[cu_sec_idx (attr->cu)];
+ const unsigned char *datap = attr->valp;
+ size_t size = attr->cu->offset_size;
+ if (unlikely (data == NULL
+ || datap < (const unsigned char *) data->d_buf
+ || data->d_size < size
+ || ((size_t) (datap
+ - (const unsigned char *) data->d_buf)
+ > data->d_size - size)))
+ goto invalid;
+
+ if (size == 4)
+ offset = read_4ubyte_unaligned (attr->cu->dbg, datap);
+ else
+ offset = read_8ubyte_unaligned (attr->cu->dbg, datap);
+
+ offset += __libdw_cu_ranges_base (skel);
+ }
+ else
+ {
+ if (__libdw_read_offset (attr->cu->dbg, attr->cu->dbg,
+ cu_sec_idx (attr->cu), attr->valp,
+ attr->cu->offset_size, &offset,
+ sec_index, 0))
+ return NULL;
+ }
+ }
+ else if (attr->cu->version > 3)
+ goto invalid;
+ else
+ switch (attr->form)
+ {
+ case DW_FORM_data4:
+ case DW_FORM_data8:
+ if (__libdw_read_offset (attr->cu->dbg, attr->cu->dbg,
+ cu_sec_idx (attr->cu),
+ attr->valp,
+ attr->form == DW_FORM_data4 ? 4 : 8,
+ &offset, sec_index, 0))
+ return NULL;
+ break;
+
+ default:
+ if (INTUSE(dwarf_formudata) (attr, &offset))
+ return NULL;
+ };
+
+ unsigned char *readp = d->d_buf + offset;
+ unsigned char *endp = d->d_buf + d->d_size;
+ if (unlikely (readp >= endp))
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ if (endpp != NULL)
+ *endpp = endp;
+ if (offsetp != NULL)
+ *offsetp = offset;
+ return readp;
+}
+
+int
+dwarf_formudata (Dwarf_Attribute *attr, Dwarf_Word *return_uval)
+{
+ if (attr == NULL)
+ return -1;
+
+ const unsigned char *datap = attr->valp;
+ const unsigned char *endp = attr->cu->endp;
+
+ switch (attr->form)
+ {
+ case DW_FORM_data1:
+ if (datap + 1 > endp)
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+ *return_uval = *attr->valp;
+ break;
+
+ case DW_FORM_data2:
+ if (datap + 2 > endp)
+ goto invalid;
+ *return_uval = read_2ubyte_unaligned (attr->cu->dbg, attr->valp);
+ break;
+
+ case DW_FORM_data4:
+ case DW_FORM_data8:
+ case DW_FORM_sec_offset:
+ /* Before DWARF4 data4 and data8 are pure constants unless the
+ attribute also allows offsets (*ptr classes), since DWARF4
+ they are always just constants (start_scope is special though,
+ since it only could express a rangelist since DWARF4). */
+ if (attr->form == DW_FORM_sec_offset
+ || (attr->cu->version < 4 && attr->code != DW_AT_start_scope))
+ {
+ switch (attr->code)
+ {
+ case DW_AT_data_member_location:
+ case DW_AT_frame_base:
+ case DW_AT_location:
+ case DW_AT_return_addr:
+ case DW_AT_segment:
+ case DW_AT_static_link:
+ case DW_AT_string_length:
+ case DW_AT_use_location:
+ case DW_AT_vtable_elem_location:
+ case DW_AT_GNU_locviews:
+ case DW_AT_loclists_base:
+ if (attr->cu->version < 5)
+ {
+ /* loclistptr */
+ if (__libdw_formptr (attr, IDX_debug_loc,
+ DWARF_E_NO_DEBUG_LOC, NULL,
+ return_uval) == NULL)
+ return -1;
+ }
+ else
+ {
+ /* loclist, loclistsptr */
+ if (__libdw_formptr (attr, IDX_debug_loclists,
+ DWARF_E_NO_DEBUG_LOCLISTS, NULL,
+ return_uval) == NULL)
+ return -1;
+ }
+ break;
+
+ case DW_AT_macro_info:
+ /* macptr into .debug_macinfo */
+ if (__libdw_formptr (attr, IDX_debug_macinfo,
+ DWARF_E_NO_ENTRY, NULL,
+ return_uval) == NULL)
+ return -1;
+ break;
+
+ case DW_AT_GNU_macros:
+ case DW_AT_macros:
+ /* macptr into .debug_macro */
+ if (__libdw_formptr (attr, IDX_debug_macro,
+ DWARF_E_NO_ENTRY, NULL,
+ return_uval) == NULL)
+ return -1;
+ break;
+
+ case DW_AT_ranges:
+ case DW_AT_start_scope:
+ case DW_AT_GNU_ranges_base:
+ case DW_AT_rnglists_base:
+ if (attr->cu->version < 5)
+ {
+ /* rangelistptr */
+ if (__libdw_formptr (attr, IDX_debug_ranges,
+ DWARF_E_NO_DEBUG_RANGES, NULL,
+ return_uval) == NULL)
+ return -1;
+ }
+ else
+ {
+ /* rnglistsptr */
+ if (__libdw_formptr (attr, IDX_debug_rnglists,
+ DWARF_E_NO_DEBUG_RNGLISTS, NULL,
+ return_uval) == NULL)
+ return -1;
+ }
+ break;
+
+ case DW_AT_stmt_list:
+ /* lineptr */
+ if (__libdw_formptr (attr, IDX_debug_line,
+ DWARF_E_NO_DEBUG_LINE, NULL,
+ return_uval) == NULL)
+ return -1;
+ break;
+
+ case DW_AT_addr_base:
+ case DW_AT_GNU_addr_base:
+ /* addrptr */
+ if (__libdw_formptr (attr, IDX_debug_addr,
+ DWARF_E_NO_DEBUG_ADDR, NULL,
+ return_uval) == NULL)
+ return -1;
+ break;
+
+ case DW_AT_str_offsets_base:
+ /* stroffsetsptr */
+ if (__libdw_formptr (attr, IDX_debug_str_offsets,
+ DWARF_E_NO_STR_OFFSETS, NULL,
+ return_uval) == NULL)
+ return -1;
+ break;
+
+ default:
+ /* sec_offset can only be used by one of the above attrs. */
+ if (attr->form == DW_FORM_sec_offset)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
+ /* Not one of the special attributes, just a constant. */
+ if (__libdw_read_address (attr->cu->dbg, cu_sec_idx (attr->cu),
+ attr->valp,
+ attr->form == DW_FORM_data4 ? 4 : 8,
+ return_uval))
+ return -1;
+ break;
+ }
+ }
+ else
+ {
+ /* We are dealing with a constant data4 or data8. */
+ if (__libdw_read_address (attr->cu->dbg, cu_sec_idx (attr->cu),
+ attr->valp,
+ attr->form == DW_FORM_data4 ? 4 : 8,
+ return_uval))
+ return -1;
+ }
+ break;
+
+ case DW_FORM_sdata:
+ if (datap + 1 > endp)
+ goto invalid;
+ get_sleb128 (*return_uval, datap, endp);
+ break;
+
+ case DW_FORM_udata:
+ case DW_FORM_rnglistx:
+ case DW_FORM_loclistx:
+ if (datap + 1 > endp)
+ goto invalid;
+ get_uleb128 (*return_uval, datap, endp);
+ break;
+
+ case DW_FORM_implicit_const:
+ // The data comes from the abbrev, which has been bounds checked.
+ get_sleb128_unchecked (*return_uval, datap);
+ break;
+
+ /* These are indexes into the .debug_addr section, normally resolved
+ with dwarf_formaddr. Here treat as constants. */
+ case DW_FORM_GNU_addr_index:
+ case DW_FORM_addrx:
+ if (datap >= endp)
+ goto invalid;
+ get_uleb128 (*return_uval, datap, endp);
+ break;
+
+ case DW_FORM_addrx1:
+ if (datap >= endp - 1)
+ goto invalid;
+ *return_uval = *datap;
+ break;
+
+ case DW_FORM_addrx2:
+ if (datap >= endp - 2)
+ goto invalid;
+ *return_uval = read_2ubyte_unaligned (attr->cu->dbg, datap);
+ break;
+
+ case DW_FORM_addrx3:
+ if (datap >= endp - 3)
+ goto invalid;
+ *return_uval = read_3ubyte_unaligned (attr->cu->dbg, datap);
+ break;
+
+ case DW_FORM_addrx4:
+ if (datap >= endp - 4)
+ goto invalid;
+ *return_uval = read_4ubyte_unaligned (attr->cu->dbg, datap);
+ break;
+
+ default:
+ __libdw_seterrno (DWARF_E_NO_CONSTANT);
+ return -1;
+ }
+
+ return 0;
+}
+INTDEF(dwarf_formudata)
diff --git a/contrib/libdw/dwarf_get_units.c b/contrib/libdw/dwarf_get_units.c
new file mode 100644
index 0000000..407ed2b
--- /dev/null
+++ b/contrib/libdw/dwarf_get_units.c
@@ -0,0 +1,132 @@
+/* Iterate through the CU units for a given Dwarf.
+ Copyright (C) 2016, 2017 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 . */
+
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+
+#include "libdwP.h"
+
+int
+dwarf_get_units (Dwarf *dwarf, Dwarf_CU *cu, Dwarf_CU **next_cu,
+ Dwarf_Half *version, uint8_t *unit_type,
+ Dwarf_Die *cudie, Dwarf_Die *subdie)
+{
+ /* Handle existing error. */
+ if (dwarf == NULL)
+ return -1;
+
+ Dwarf_Off off;
+ bool v4type;
+ if (cu == NULL)
+ {
+ off = 0;
+ v4type = false;
+ }
+ else
+ {
+ off = cu->end;
+ v4type = cu->sec_idx != IDX_debug_info;
+
+ /* Make sure we got a real (not fake) CU. */
+ if (cu->sec_idx != IDX_debug_info && cu->sec_idx != IDX_debug_types)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_OFFSET);
+ return -1;
+ }
+
+ /* Do we have to switch to the other section, or are we at the end? */
+ if (! v4type)
+ {
+ if (off >= cu->dbg->sectiondata[IDX_debug_info]->d_size)
+ {
+ if (cu->dbg->sectiondata[IDX_debug_types] == NULL)
+ return 1;
+
+ off = 0;
+ v4type = true;
+ }
+ }
+ else
+ if (off >= cu->dbg->sectiondata[IDX_debug_types]->d_size)
+ return 1;
+ }
+
+ *next_cu = __libdw_findcu (dwarf, off, v4type);
+ if (*next_cu == NULL)
+ return -1;
+
+ Dwarf_CU *next = (*next_cu);
+
+ if (version != NULL)
+ *version = next->version;
+
+ if (unit_type != NULL)
+ *unit_type = next->unit_type;
+
+ if (cudie != NULL)
+ {
+ if (next->version >= 2 && next->version <= 5
+ && next->unit_type >= DW_UT_compile
+ && next->unit_type <= DW_UT_split_type)
+ *cudie = CUDIE (next);
+ else
+ memset (cudie, '\0', sizeof (Dwarf_Die));
+ }
+
+ if (subdie != NULL)
+ {
+ if (next->version >= 2 && next->version <= 5)
+ {
+ /* For types, return the actual type DIE. For skeletons,
+ find the associated split compile unit and return its
+ DIE. */
+ if (next->unit_type == DW_UT_type
+ || next->unit_type == DW_UT_split_type)
+ *subdie = SUBDIE(next);
+ else if (next->unit_type == DW_UT_skeleton)
+ {
+ Dwarf_CU *split_cu = __libdw_find_split_unit (next);
+ if (split_cu != NULL)
+ *subdie = CUDIE(split_cu);
+ else
+ memset (subdie, '\0', sizeof (Dwarf_Die));
+ }
+ else
+ memset (subdie, '\0', sizeof (Dwarf_Die));
+ }
+ else
+ memset (subdie, '\0', sizeof (Dwarf_Die));
+ }
+
+ return 0;
+}
+INTDEF(dwarf_get_units)
diff --git a/contrib/libdw/dwarf_getabbrev.c b/contrib/libdw/dwarf_getabbrev.c
new file mode 100644
index 0000000..5b02333
--- /dev/null
+++ b/contrib/libdw/dwarf_getabbrev.c
@@ -0,0 +1,187 @@
+/* Get abbreviation at given offset.
+ Copyright (C) 2003, 2004, 2005, 2006, 2014, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+
+Dwarf_Abbrev *
+internal_function
+__libdw_getabbrev (Dwarf *dbg, struct Dwarf_CU *cu, Dwarf_Off offset,
+ size_t *lengthp, Dwarf_Abbrev *result)
+{
+ /* Don't fail if there is not .debug_abbrev section. */
+ if (dbg->sectiondata[IDX_debug_abbrev] == NULL)
+ return NULL;
+
+ if (offset >= dbg->sectiondata[IDX_debug_abbrev]->d_size)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_OFFSET);
+ return NULL;
+ }
+
+ const unsigned char *abbrevp
+ = (unsigned char *) dbg->sectiondata[IDX_debug_abbrev]->d_buf + offset;
+
+ if (*abbrevp == '\0')
+ /* We are past the last entry. */
+ return DWARF_END_ABBREV;
+
+ /* 7.5.3 Abbreviations Tables
+
+ [...] Each declaration begins with an unsigned LEB128 number
+ representing the abbreviation code itself. [...] The
+ abbreviation code is followed by another unsigned LEB128
+ number that encodes the entry's tag. [...]
+
+ [...] Following the tag encoding is a 1-byte value that
+ determines whether a debugging information entry using this
+ abbreviation has child entries or not. [...]
+
+ [...] Finally, the child encoding is followed by a series of
+ attribute specifications. Each attribute specification
+ consists of two parts. The first part is an unsigned LEB128
+ number representing the attribute's name. The second part is
+ an unsigned LEB128 number representing the attribute's form. */
+ const unsigned char *end = (dbg->sectiondata[IDX_debug_abbrev]->d_buf
+ + dbg->sectiondata[IDX_debug_abbrev]->d_size);
+ const unsigned char *start_abbrevp = abbrevp;
+ unsigned int code;
+ // We start off with abbrevp at offset, which is checked above.
+ get_uleb128 (code, abbrevp, end);
+
+ /* Check whether this code is already in the hash table. */
+ bool foundit = false;
+ Dwarf_Abbrev *abb = NULL;
+ if (cu == NULL
+ || (abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code)) == NULL)
+ {
+ if (result == NULL)
+ abb = libdw_typed_alloc (dbg, Dwarf_Abbrev);
+ else
+ abb = result;
+ }
+ else
+ {
+ foundit = true;
+
+ if (unlikely (abb->offset != offset))
+ {
+ /* A duplicate abbrev code at a different offset,
+ that should never happen. */
+ invalid:
+ if (! foundit)
+ libdw_typed_unalloc (dbg, Dwarf_Abbrev);
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ /* If the caller doesn't need the length we are done. */
+ if (lengthp == NULL)
+ goto out;
+ }
+
+ /* If there is already a value in the hash table we are going to
+ overwrite its content. This must not be a problem, since the
+ content better be the same. */
+ abb->code = code;
+ if (abbrevp >= end)
+ goto invalid;
+ get_uleb128 (abb->tag, abbrevp, end);
+ if (abbrevp + 1 >= end)
+ goto invalid;
+ abb->has_children = *abbrevp++ == DW_CHILDREN_yes;
+ abb->attrp = (unsigned char *) abbrevp;
+ abb->offset = offset;
+
+ /* Skip over all the attributes and check rest of the abbrev is valid. */
+ unsigned int attrname;
+ unsigned int attrform;
+ do
+ {
+ if (abbrevp >= end)
+ goto invalid;
+ get_uleb128 (attrname, abbrevp, end);
+ if (abbrevp >= end)
+ goto invalid;
+ get_uleb128 (attrform, abbrevp, end);
+ if (attrform == DW_FORM_implicit_const)
+ {
+ int64_t formval __attribute__((__unused__));
+ if (abbrevp >= end)
+ goto invalid;
+ get_sleb128 (formval, abbrevp, end);
+ }
+ }
+ while (attrname != 0 || attrform != 0);
+
+ /* Return the length to the caller if she asked for it. */
+ if (lengthp != NULL)
+ *lengthp = abbrevp - start_abbrevp;
+
+ /* Add the entry to the hash table. */
+ if (cu != NULL && ! foundit)
+ if (Dwarf_Abbrev_Hash_insert (&cu->abbrev_hash, abb->code, abb) == -1)
+ {
+ /* The entry was already in the table, remove the one we just
+ created and get the one already inserted. */
+ libdw_typed_unalloc (dbg, Dwarf_Abbrev);
+ abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code);
+ }
+
+ out:
+ return abb;
+}
+
+
+Dwarf_Abbrev *
+dwarf_getabbrev (Dwarf_Die *die, Dwarf_Off offset, size_t *lengthp)
+{
+ if (die == NULL || die->cu == NULL)
+ return NULL;
+
+ Dwarf_CU *cu = die->cu;
+ Dwarf *dbg = cu->dbg;
+ Dwarf_Off abbrev_offset = cu->orig_abbrev_offset;
+ Elf_Data *data = dbg->sectiondata[IDX_debug_abbrev];
+ if (data == NULL)
+ return NULL;
+
+ if (offset >= data->d_size - abbrev_offset)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_OFFSET);
+ return NULL;
+ }
+
+ return __libdw_getabbrev (dbg, cu, abbrev_offset + offset, lengthp, NULL);
+}
diff --git a/contrib/libdw/dwarf_getalt.c b/contrib/libdw/dwarf_getalt.c
new file mode 100644
index 0000000..0a12dfa
--- /dev/null
+++ b/contrib/libdw/dwarf_getalt.c
@@ -0,0 +1,184 @@
+/* Retrieves the DWARF descriptor for debugaltlink data.
+ Copyright (C) 2014, 2018 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+#include "libelfP.h"
+#include "libdwelfP.h"
+#include "system.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+
+char *
+internal_function
+__libdw_filepath (const char *debugdir, const char *dir, const char *file)
+{
+ if (file == NULL)
+ return NULL;
+
+ if (file[0] == '/')
+ return strdup (file);
+
+ if (dir != NULL && dir[0] == '/')
+ {
+ size_t dirlen = strlen (dir);
+ size_t filelen = strlen (file);
+ size_t len = dirlen + 1 + filelen + 1;
+ char *path = malloc (len);
+ if (path != NULL)
+ {
+ char *c = mempcpy (path, dir, dirlen);
+ if (dir[dirlen - 1] != '/')
+ *c++ = '/';
+ mempcpy (c, file, filelen + 1);
+ }
+ return path;
+ }
+
+ if (debugdir != NULL)
+ {
+ size_t debugdirlen = strlen (debugdir);
+ size_t dirlen = dir != NULL ? strlen (dir) : 0;
+ size_t filelen = strlen (file);
+ size_t len = debugdirlen + 1 + dirlen + 1 + filelen + 1;
+ char *path = malloc (len);
+ if (path != NULL)
+ {
+ char *c = mempcpy (path, debugdir, debugdirlen);
+ if (dirlen > 0)
+ {
+ c = mempcpy (c, dir, dirlen);
+ if (dir[dirlen - 1] != '/')
+ *c++ = '/';
+ }
+ mempcpy (c, file, filelen + 1);
+ return path;
+ }
+ }
+
+ return NULL;
+}
+
+static void
+find_debug_altlink (Dwarf *dbg)
+{
+ const char *altname;
+ const void *build_id;
+ ssize_t build_id_len = INTUSE(dwelf_dwarf_gnu_debugaltlink) (dbg,
+ &altname,
+ &build_id);
+
+ /* Couldn't even get the debugaltlink. It probably doesn't exist. */
+ if (build_id_len <= 0)
+ return;
+
+ const uint8_t *id = (const uint8_t *) build_id;
+ size_t id_len = build_id_len;
+ int fd = -1;
+
+ /* We only look in the standard path. And relative to the dbg file. */
+#define DEBUGINFO_PATH "/usr/lib/debug"
+
+ /* We don't handle very short or really large build-ids. We need at
+ at least 3 and allow for up to 64 (normally ids are 20 long). */
+#define MIN_BUILD_ID_BYTES 3
+#define MAX_BUILD_ID_BYTES 64
+ if (id_len >= MIN_BUILD_ID_BYTES && id_len <= MAX_BUILD_ID_BYTES)
+ {
+ /* Note sizeof a string literal includes the trailing zero. */
+ char id_path[sizeof DEBUGINFO_PATH - 1 + sizeof "/.build-id/" - 1
+ + 2 + 1 + (MAX_BUILD_ID_BYTES - 1) * 2 + sizeof ".debug"];
+ sprintf (&id_path[0], "%s%s", DEBUGINFO_PATH, "/.build-id/");
+ sprintf (&id_path[sizeof DEBUGINFO_PATH - 1 + sizeof "/.build-id/" - 1],
+ "%02" PRIx8 "/", (uint8_t) id[0]);
+ for (size_t i = 1; i < id_len; ++i)
+ sprintf (&id_path[sizeof DEBUGINFO_PATH - 1 + sizeof "/.build-id/" - 1
+ + 3 + (i - 1) * 2], "%02" PRIx8, (uint8_t) id[i]);
+ strcpy (&id_path[sizeof DEBUGINFO_PATH - 1 + sizeof "/.build-id/" - 1
+ + 3 + (id_len - 1) * 2], ".debug");
+
+ fd = TEMP_FAILURE_RETRY (open (id_path, O_RDONLY));
+ }
+
+ /* Fall back on (possible relative) alt file path. */
+ if (fd < 0)
+ {
+ char *altpath = __libdw_filepath (dbg->debugdir, NULL, altname);
+ if (altpath != NULL)
+ {
+ fd = TEMP_FAILURE_RETRY (open (altpath, O_RDONLY));
+ free (altpath);
+ }
+ }
+
+ if (fd >= 0)
+ {
+ Dwarf *alt = dwarf_begin (fd, O_RDONLY);
+ if (alt != NULL)
+ {
+ dbg->alt_dwarf = alt;
+ dbg->alt_fd = fd;
+ }
+ else
+ close (fd);
+ }
+}
+
+Dwarf *
+dwarf_getalt (Dwarf *main)
+{
+ /* Only try once. */
+ if (main == NULL || main->alt_dwarf == (void *) -1)
+ return NULL;
+
+ if (main->alt_dwarf != NULL)
+ return main->alt_dwarf;
+
+ find_debug_altlink (main);
+
+ /* If we found nothing, make sure we don't try again. */
+ if (main->alt_dwarf == NULL)
+ {
+ main->alt_dwarf = (void *) -1;
+ return NULL;
+ }
+
+ return main->alt_dwarf;
+}
+INTDEF (dwarf_getalt)
diff --git a/contrib/libdw/dwarf_getsrcdirs.c b/contrib/libdw/dwarf_getsrcdirs.c
new file mode 100644
index 0000000..8160ed3
--- /dev/null
+++ b/contrib/libdw/dwarf_getsrcdirs.c
@@ -0,0 +1,45 @@
+/* Find include directories in source file information.
+ Copyright (C) 2007 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+int
+dwarf_getsrcdirs (Dwarf_Files *files, const char *const **result, size_t *ndirs)
+{
+ if (files == NULL)
+ return -1;
+
+ *result = (void *) &files->info[files->nfiles];
+ *ndirs = files->ndirs;
+ return 0;
+}
diff --git a/contrib/libdw/dwarf_getsrcfiles.c b/contrib/libdw/dwarf_getsrcfiles.c
new file mode 100644
index 0000000..cd2e5b5
--- /dev/null
+++ b/contrib/libdw/dwarf_getsrcfiles.c
@@ -0,0 +1,116 @@
+/* Return source file information of CU.
+ Copyright (C) 2004, 2005, 2013, 2015, 2018 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include "libdwP.h"
+
+
+int
+dwarf_getsrcfiles (Dwarf_Die *cudie, Dwarf_Files **files, size_t *nfiles)
+{
+ if (cudie == NULL)
+ return -1;
+ if (! is_cudie (cudie))
+ {
+ __libdw_seterrno (DWARF_E_NOT_CUDIE);
+ return -1;
+ }
+
+ int res = -1;
+
+ /* Get the information if it is not already known. */
+ struct Dwarf_CU *const cu = cudie->cu;
+ if (cu->files == NULL)
+ {
+ /* For split units there might be a simple file table (without lines).
+ If not, use the one from the skeleton. */
+ if (cu->unit_type == DW_UT_split_compile
+ || cu->unit_type == DW_UT_split_type)
+ {
+ /* We tried, assume we fail... */
+ cu->files = (void *) -1;
+
+ /* See if there is a .debug_line section, for split CUs
+ the table is at offset zero. */
+ if (cu->dbg->sectiondata[IDX_debug_line] != NULL)
+ {
+ Dwarf_Off dwp_off;
+ if (INTUSE(dwarf_cu_dwp_section_info) (cu, DW_SECT_LINE,
+ &dwp_off, NULL) == 0)
+ {
+ /* We are only interested in the files, the lines will
+ always come from the skeleton. */
+ res = __libdw_getsrclines (cu->dbg, dwp_off,
+ __libdw_getcompdir (cudie),
+ cu->address_size, NULL,
+ &cu->files);
+ }
+ }
+ else
+ {
+ Dwarf_CU *skel = __libdw_find_split_unit (cu);
+ if (skel != NULL)
+ {
+ Dwarf_Die skeldie = CUDIE (skel);
+ res = INTUSE(dwarf_getsrcfiles) (&skeldie, files, nfiles);
+ cu->files = skel->files;
+ }
+ }
+ }
+ else
+ {
+ Dwarf_Lines *lines;
+ size_t nlines;
+
+ /* Let the more generic function do the work. It'll create more
+ data but that will be needed in an real program anyway. */
+ res = INTUSE(dwarf_getsrclines) (cudie, &lines, &nlines);
+ }
+ }
+ else if (cu->files != (void *) -1l)
+ /* We already have the information. */
+ res = 0;
+
+ if (likely (res == 0))
+ {
+ assert (cu->files != NULL && cu->files != (void *) -1l);
+ *files = cu->files;
+ if (nfiles != NULL)
+ *nfiles = cu->files->nfiles;
+ }
+
+ // XXX Eventually: unlocking here.
+
+ return res;
+}
+INTDEF (dwarf_getsrcfiles)
diff --git a/contrib/libdw/dwarf_getsrclines.c b/contrib/libdw/dwarf_getsrclines.c
new file mode 100644
index 0000000..69e10c7
--- /dev/null
+++ b/contrib/libdw/dwarf_getsrclines.c
@@ -0,0 +1,1268 @@
+/* Return line number information of CU.
+ Copyright (C) 2004-2010, 2013, 2014, 2015, 2016, 2018 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "dwarf.h"
+#include "libdwP.h"
+
+
+struct filelist
+{
+ Dwarf_Fileinfo info;
+ struct filelist *next;
+};
+
+struct linelist
+{
+ Dwarf_Line line;
+ struct linelist *next;
+ size_t sequence;
+};
+
+
+/* Compare by Dwarf_Line.addr, given pointers into an array of pointers. */
+static int
+compare_lines (const void *a, const void *b)
+{
+ struct linelist *const *p1 = a;
+ struct linelist *const *p2 = b;
+ struct linelist *list1 = *p1;
+ struct linelist *list2 = *p2;
+ Dwarf_Line *line1 = &list1->line;
+ Dwarf_Line *line2 = &list2->line;
+
+ if (line1->addr != line2->addr)
+ return (line1->addr < line2->addr) ? -1 : 1;
+
+ /* An end_sequence marker precedes a normal record at the same address. */
+ if (line1->end_sequence != line2->end_sequence)
+ return line2->end_sequence - line1->end_sequence;
+
+ /* Otherwise, the linelist sequence maintains a stable sort. */
+ return (list1->sequence < list2->sequence) ? -1
+ : (list1->sequence > list2->sequence) ? 1
+ : 0;
+}
+
+struct line_state
+{
+ Dwarf_Word addr;
+ unsigned int op_index;
+ unsigned int file;
+ int64_t line;
+ unsigned int column;
+ uint_fast8_t is_stmt;
+ bool basic_block;
+ bool prologue_end;
+ bool epilogue_begin;
+ unsigned int isa;
+ unsigned int discriminator;
+ struct linelist *linelist;
+ size_t nlinelist;
+ unsigned int end_sequence;
+ unsigned int context;
+ unsigned int function_name;
+};
+
+static inline void
+run_advance_pc (struct line_state *state, unsigned int op_advance,
+ uint_fast8_t minimum_instr_len, uint_fast8_t max_ops_per_instr)
+{
+ state->addr += minimum_instr_len * ((state->op_index + op_advance)
+ / max_ops_per_instr);
+ state->op_index = (state->op_index + op_advance) % max_ops_per_instr;
+}
+
+static inline bool
+add_new_line (struct line_state *state, struct linelist *new_line)
+{
+ /* Set the line information. For some fields we use bitfields,
+ so we would lose information if the encoded values are too large.
+ Check just for paranoia, and call the data "invalid" if it
+ violates our assumptions on reasonable limits for the values. */
+ new_line->next = state->linelist;
+ new_line->sequence = state->nlinelist;
+ state->linelist = new_line;
+ ++(state->nlinelist);
+
+ /* Set the line information. For some fields we use bitfields,
+ so we would lose information if the encoded values are too large.
+ Check just for paranoia, and call the data "invalid" if it
+ violates our assumptions on reasonable limits for the values. */
+#define SET(field) \
+ do { \
+ new_line->line.field = state->field; \
+ if (unlikely (new_line->line.field != state->field)) \
+ return true; \
+ } while (0)
+
+ /* Same as above, but don't flag as "invalid" just use truncated
+ value. Used for discriminator for which llvm might use a value
+ that won't fit 24 bits. */
+#define SETX(field) \
+ new_line->line.field = state->field; \
+
+ SET (addr);
+ SET (op_index);
+ SET (file);
+ SET (line);
+ SET (column);
+ SET (is_stmt);
+ SET (basic_block);
+ SET (end_sequence);
+ SET (prologue_end);
+ SET (epilogue_begin);
+ SET (isa);
+ SETX (discriminator);
+ SET (context);
+ SET (function_name);
+
+#undef SET
+
+ return false;
+}
+
+static int
+read_srclines (Dwarf *dbg,
+ const unsigned char *linep, const unsigned char *lineendp,
+ const char *comp_dir, unsigned address_size,
+ Dwarf_Lines **linesp, Dwarf_Files **filesp)
+{
+ int res = -1;
+
+ struct filelist *filelist = NULL;
+ size_t nfilelist = 0;
+ size_t ndirlist = 0;
+
+ /* If there are a large number of lines, files or dirs don't blow up
+ the stack. Stack allocate some entries, only dynamically malloc
+ when more than MAX. */
+#define MAX_STACK_ALLOC 4096
+#define MAX_STACK_LINES (MAX_STACK_ALLOC / 2)
+#define MAX_STACK_FILES (MAX_STACK_ALLOC / 4)
+#define MAX_STACK_DIRS (MAX_STACK_ALLOC / 16)
+
+ /* Initial statement program state (except for stmt_list, see below). */
+ struct line_state state =
+ {
+ .linelist = NULL,
+ .nlinelist = 0,
+ .addr = 0,
+ .op_index = 0,
+ .file = 1,
+ /* We only store int but want to check for overflow (see SET above). */
+ .line = 1,
+ .column = 0,
+ .basic_block = false,
+ .prologue_end = false,
+ .epilogue_begin = false,
+ .isa = 0,
+ .discriminator = 0,
+ .context = 0,
+ .function_name = 0
+ };
+
+ /* The dirs normally go on the stack, but if there are too many
+ we alloc them all. Set up stack storage early, so we can check on
+ error if we need to free them or not. */
+ struct dirlist
+ {
+ const char *dir;
+ size_t len;
+ };
+ struct dirlist dirstack[MAX_STACK_DIRS];
+ struct dirlist *dirarray = dirstack;
+
+ if (unlikely (linep + 4 > lineendp))
+ {
+ invalid_data:
+ __libdw_seterrno (DWARF_E_INVALID_DEBUG_LINE);
+ goto out;
+ }
+
+ Dwarf_Word unit_length = read_4ubyte_unaligned_inc (dbg, linep);
+ unsigned int length = 4;
+ if (unlikely (unit_length == DWARF3_LENGTH_64_BIT))
+ {
+ if (unlikely (linep + 8 > lineendp))
+ goto invalid_data;
+ unit_length = read_8ubyte_unaligned_inc (dbg, linep);
+ length = 8;
+ }
+
+ /* Check whether we have enough room in the section. */
+ if (unlikely (unit_length > (size_t) (lineendp - linep)))
+ goto invalid_data;
+ lineendp = linep + unit_length;
+
+ /* The next element of the header is the version identifier. */
+ if ((size_t) (lineendp - linep) < 2)
+ goto invalid_data;
+ uint_fast16_t version = read_2ubyte_unaligned_inc (dbg, linep);
+ if (unlikely (version < 2) || unlikely (version > 5))
+ {
+ __libdw_seterrno (DWARF_E_VERSION);
+ goto out;
+ }
+
+ /* DWARF5 explicitly lists address and segment_selector sizes. */
+ if (version >= 5)
+ {
+ if ((size_t) (lineendp - linep) < 2)
+ goto invalid_data;
+ size_t line_address_size = *linep++;
+ size_t segment_selector_size = *linep++;
+ if (line_address_size != address_size || segment_selector_size != 0)
+ goto invalid_data;
+ }
+
+ /* Next comes the header length. */
+ Dwarf_Word header_length;
+ if (length == 4)
+ {
+ if ((size_t) (lineendp - linep) < 4)
+ goto invalid_data;
+ header_length = read_4ubyte_unaligned_inc (dbg, linep);
+ }
+ else
+ {
+ if ((size_t) (lineendp - linep) < 8)
+ goto invalid_data;
+ header_length = read_8ubyte_unaligned_inc (dbg, linep);
+ }
+ const unsigned char *header_start = linep;
+
+ /* Next the minimum instruction length. */
+ uint_fast8_t minimum_instr_len = *linep++;
+
+ /* Next the maximum operations per instruction, in version 4 format. */
+ uint_fast8_t max_ops_per_instr = 1;
+ if (version >= 4)
+ {
+ if (unlikely ((size_t) (lineendp - linep) < 1))
+ goto invalid_data;
+ max_ops_per_instr = *linep++;
+ if (unlikely (max_ops_per_instr == 0))
+ goto invalid_data;
+ }
+
+ /* 4 more bytes, is_stmt, line_base, line_range and opcode_base. */
+ if ((size_t) (lineendp - linep) < 4)
+ goto invalid_data;
+
+ /* Then the flag determining the default value of the is_stmt
+ register. */
+ uint_fast8_t default_is_stmt = *linep++;
+
+ /* Now the line base. */
+ int_fast8_t line_base = (int8_t) *linep++;
+
+ /* And the line range. */
+ uint_fast8_t line_range = *linep++;
+
+ /* The opcode base. */
+ uint_fast8_t opcode_base = *linep++;
+
+ /* Remember array with the standard opcode length (-1 to account for
+ the opcode with value zero not being mentioned). */
+ const uint8_t *standard_opcode_lengths = linep - 1;
+ if (unlikely (lineendp - linep < opcode_base - 1))
+ goto invalid_data;
+ linep += opcode_base - 1;
+
+ /* To read DWARF5 dir and file lists we need to know the forms. For
+ now we skip everything, except the DW_LNCT_path and
+ DW_LNCT_directory_index. */
+ uint16_t forms[256];
+ unsigned char nforms = 0;
+ unsigned char form_path = -1; /* Which forms is DW_LNCT_path. */
+ unsigned char form_idx = -1; /* And which is DW_LNCT_directory_index. */
+
+ /* To read/skip form data. */
+ Dwarf_CU fake_cu = {
+ .dbg = dbg,
+ .sec_idx = IDX_debug_line,
+ .version = 5,
+ .offset_size = length,
+ .address_size = address_size,
+ .startp = (void *) linep,
+ .endp = (void *) lineendp,
+ };
+
+ /* First count the entries. */
+ size_t ndirs = 0;
+ if (version < 5)
+ {
+ const unsigned char *dirp = linep;
+ while (dirp < lineendp && *dirp != 0)
+ {
+ uint8_t *endp = memchr (dirp, '\0', lineendp - dirp);
+ if (endp == NULL)
+ goto invalid_data;
+ ++ndirs;
+ dirp = endp + 1;
+ }
+ if (dirp >= lineendp || *dirp != '\0')
+ goto invalid_data;
+ ndirs = ndirs + 1; /* There is always the "unknown" dir. */
+ }
+ else
+ {
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ nforms = *linep++;
+ for (int i = 0; i < nforms; i++)
+ {
+ uint16_t desc, form;
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (desc, linep, lineendp);
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (form, linep, lineendp);
+
+ if (! libdw_valid_user_form (form))
+ goto invalid_data;
+
+ forms[i] = form;
+ if (desc == DW_LNCT_path)
+ form_path = i;
+ }
+
+ if (nforms > 0 && form_path == (unsigned char) -1)
+ goto invalid_data;
+
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (ndirs, linep, lineendp);
+
+ if (nforms == 0 && ndirs != 0)
+ goto invalid_data;
+
+ /* Assume there is at least 1 byte needed per form to describe
+ the directory. Filters out insanely large ndirs. */
+ if (nforms != 0 && ndirs > (size_t) (lineendp - linep) / nforms)
+ goto invalid_data;
+ }
+
+ /* Arrange the list in array form. */
+ ndirlist = ndirs;
+ if (ndirlist >= MAX_STACK_DIRS)
+ {
+ if (ndirlist > SIZE_MAX / sizeof (*dirarray))
+ goto no_mem;
+ dirarray = malloc (ndirlist * sizeof (*dirarray));
+ if (unlikely (dirarray == NULL))
+ {
+ no_mem:
+ __libdw_seterrno (DWARF_E_NOMEM);
+ goto out;
+ }
+ }
+
+ /* Entry zero is implicit for older versions, but explicit for 5+. */
+ struct dirlist comp_dir_elem;
+ if (version < 5)
+ {
+ /* First comes the list of directories. Add the compilation
+ directory first since the index zero is used for it. */
+ comp_dir_elem.dir = comp_dir;
+ comp_dir_elem.len = comp_dir ? strlen (comp_dir) : 0,
+ dirarray[0] = comp_dir_elem;
+ for (unsigned int n = 1; n < ndirlist; n++)
+ {
+ dirarray[n].dir = (char *) linep;
+ uint8_t *endp = memchr (linep, '\0', lineendp - linep);
+ assert (endp != NULL); // Checked above when calculating ndirlist.
+ dirarray[n].len = endp - linep;
+ linep = endp + 1;
+ }
+ /* Skip the final NUL byte. */
+ assert (*linep == '\0'); // Checked above when calculating ndirlist.
+ ++linep;
+ }
+ else
+ {
+ Dwarf_Attribute attr;
+ attr.code = DW_AT_name;
+ attr.cu = &fake_cu;
+ for (unsigned int n = 0; n < ndirlist; n++)
+ {
+ const char *dir = NULL;
+ for (unsigned char m = 0; m < nforms; m++)
+ {
+ if (m == form_path)
+ {
+ attr.form = forms[m];
+ attr.valp = (void *) linep;
+ dir = dwarf_formstring (&attr);
+ }
+
+ size_t len = __libdw_form_val_len (&fake_cu, forms[m], linep);
+ if ((size_t) (lineendp - linep) < len)
+ goto invalid_data;
+
+ linep += len;
+ }
+
+ if (dir == NULL)
+ goto invalid_data;
+
+ dirarray[n].dir = dir;
+ dirarray[n].len = strlen (dir);
+ }
+ }
+
+ /* File index zero doesn't exist for DWARF < 5. Files are indexed
+ starting from 1. But for DWARF5 they are indexed starting from
+ zero, but the default index is still 1. In both cases the
+ "first" file is special and refers to the main compile unit file,
+ equal to the DW_AT_name of the DW_TAG_compile_unit. */
+ struct filelist null_file =
+ {
+ .info =
+ {
+ .name = "???",
+ .mtime = 0,
+ .length = 0
+ },
+ .next = NULL
+ };
+ filelist = &null_file;
+ nfilelist = 1;
+
+ /* Allocate memory for a new file. For the first MAX_STACK_FILES
+ entries just return a slot in the preallocated stack array.
+ This is slightly complicated because in DWARF < 5 new files could
+ be defined with DW_LNE_define_file after the normal file list was
+ read. */
+ struct filelist flstack[MAX_STACK_FILES];
+#define NEW_FILE() ({ \
+ struct filelist *fl = (nfilelist < MAX_STACK_FILES \
+ ? &flstack[nfilelist] \
+ : malloc (sizeof (struct filelist))); \
+ if (unlikely (fl == NULL)) \
+ goto no_mem; \
+ ++nfilelist; \
+ fl->next = filelist; \
+ filelist = fl; \
+ fl; })
+
+ /* Now read the files. */
+ if (version < 5)
+ {
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ while (linep < lineendp && *linep != '\0')
+ {
+ struct filelist *new_file = NEW_FILE ();
+
+ /* First comes the file name. */
+ char *fname = (char *) linep;
+ uint8_t *endp = memchr (fname, '\0', lineendp - linep);
+ if (endp == NULL)
+ goto invalid_data;
+ size_t fnamelen = endp - (uint8_t *) fname;
+ linep = endp + 1;
+
+ /* Then the index. */
+ Dwarf_Word diridx;
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (diridx, linep, lineendp);
+ if (unlikely (diridx >= ndirlist))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DIR_IDX);
+ goto out;
+ }
+
+ if (*fname == '/')
+ /* It's an absolute path. */
+ new_file->info.name = fname;
+ else
+ {
+ new_file->info.name = libdw_alloc (dbg, char, 1,
+ dirarray[diridx].len + 1
+ + fnamelen + 1);
+ char *cp = new_file->info.name;
+
+ if (dirarray[diridx].dir != NULL)
+ {
+ /* This value could be NULL in case the DW_AT_comp_dir
+ was not present. We cannot do much in this case.
+ Just keep the file relative. */
+ cp = stpcpy (cp, dirarray[diridx].dir);
+ *cp++ = '/';
+ }
+ strcpy (cp, fname);
+ assert (strlen (new_file->info.name)
+ < dirarray[diridx].len + 1 + fnamelen + 1);
+ }
+
+ /* Next comes the modification time. */
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (new_file->info.mtime, linep, lineendp);
+
+ /* Finally the length of the file. */
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (new_file->info.length, linep, lineendp);
+ }
+ if (linep >= lineendp || *linep != '\0')
+ goto invalid_data;
+ /* Skip the final NUL byte. */
+ ++linep;
+ }
+ else
+ {
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ nforms = *linep++;
+ form_path = form_idx = -1;
+ for (int i = 0; i < nforms; i++)
+ {
+ uint16_t desc, form;
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (desc, linep, lineendp);
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (form, linep, lineendp);
+
+ if (! libdw_valid_user_form (form))
+ goto invalid_data;
+
+ forms[i] = form;
+ if (desc == DW_LNCT_path)
+ form_path = i;
+ else if (desc == DW_LNCT_directory_index)
+ form_idx = i;
+ }
+
+ if (nforms > 0 && (form_path == (unsigned char) -1
+ || form_idx == (unsigned char) -1))
+ goto invalid_data;
+
+ size_t nfiles;
+ if ((size_t) (lineendp - linep) < 1)
+ goto invalid_data;
+ get_uleb128 (nfiles, linep, lineendp);
+
+ if (nforms == 0 && nfiles != 0)
+ goto invalid_data;
+
+ /* Assume there is at least 1 byte needed per form to describe
+ the file. Filters out insanely large nfiles. */
+ if (nforms != 0 && nfiles > (size_t) (lineendp - linep) / nforms)
+ goto invalid_data;
+
+ Dwarf_Attribute attr;
+ attr.cu = &fake_cu;
+ for (unsigned int n = 0; n < nfiles; n++)
+ {
+ const char *fname = NULL;
+ Dwarf_Word diridx = (Dwarf_Word) -1;
+ for (unsigned char m = 0; m < nforms; m++)
+ {
+ if (m == form_path)
+ {
+ attr.code = DW_AT_name;
+ attr.form = forms[m];
+ attr.valp = (void *) linep;
+ fname = dwarf_formstring (&attr);
+ }
+ else if (m == form_idx)
+ {
+ attr.code = DW_AT_decl_file; /* Close enough. */
+ attr.form = forms[m];
+ attr.valp = (void *) linep;
+ if (dwarf_formudata (&attr, &diridx) != 0)
+ diridx = (Dwarf_Word) -1;
+ }
+
+ size_t len = __libdw_form_val_len (&fake_cu, forms[m], linep);
+ if ((size_t) (lineendp - linep) < len)
+ goto invalid_data;
+
+ linep += len;
+ }
+
+ if (fname == NULL || diridx == (Dwarf_Word) -1)
+ goto invalid_data;
+
+ size_t fnamelen = strlen (fname);
+
+ if (unlikely (diridx >= ndirlist))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DIR_IDX);
+ goto out;
+ }
+
+ /* Yes, weird. Looks like an off-by-one in the spec. */
+ struct filelist *new_file = n == 0 ? &null_file : NEW_FILE ();
+
+ /* We follow the same rules as above for DWARF < 5, even
+ though the standard doesn't explicitly mention absolute
+ paths and ignoring the dir index. */
+ if (*fname == '/')
+ /* It's an absolute path. */
+ new_file->info.name = (char *) fname;
+ else
+ {
+ new_file->info.name = libdw_alloc (dbg, char, 1,
+ dirarray[diridx].len + 1
+ + fnamelen + 1);
+ char *cp = new_file->info.name;
+
+ /* In the DWARF >= 5 case, dir can never be NULL. */
+ cp = stpcpy (cp, dirarray[diridx].dir);
+ *cp++ = '/';
+ strcpy (cp, fname);
+ assert (strlen (new_file->info.name)
+ < dirarray[diridx].len + 1 + fnamelen + 1);
+ }
+
+ /* For now we just ignore the modification time and file length. */
+ new_file->info.mtime = 0;
+ new_file->info.length = 0;
+ }
+ }
+
+ unsigned int debug_str_offset = 0;
+ if (unlikely (linep == header_start + header_length - 4))
+ {
+ /* CUBINs contain an unsigned 4-byte offset */
+ debug_str_offset = read_4ubyte_unaligned_inc (dbg, linep);
+ }
+
+ /* Consistency check. */
+ if (unlikely (linep != header_start + header_length))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ goto out;
+ }
+
+ /* We are about to process the statement program. Most state machine
+ registers have already been initialize above. Just add the is_stmt
+ default. See 6.2.2 in the v2.1 specification. */
+ state.is_stmt = default_is_stmt;
+
+ /* Apply the "operation advance" from a special opcode or
+ DW_LNS_advance_pc (as per DWARF4 6.2.5.1). */
+#define advance_pc(op_advance) \
+ run_advance_pc (&state, op_advance, minimum_instr_len, max_ops_per_instr)
+
+ /* Process the instructions. */
+
+ /* Adds a new line to the matrix. For the first MAX_STACK_LINES
+ entries just return a slot in the preallocated stack array. */
+ struct linelist llstack[MAX_STACK_LINES];
+#define NEW_LINE(end_seq) \
+ do { \
+ struct linelist *ll = (state.nlinelist < MAX_STACK_LINES \
+ ? &llstack[state.nlinelist] \
+ : malloc (sizeof (struct linelist))); \
+ if (unlikely (ll == NULL)) \
+ goto no_mem; \
+ state.end_sequence = end_seq; \
+ if (unlikely (add_new_line (&state, ll))) \
+ goto invalid_data; \
+ } while (0)
+
+ while (linep < lineendp)
+ {
+ unsigned int opcode;
+ unsigned int u128;
+ int s128;
+
+ /* Read the opcode. */
+ opcode = *linep++;
+
+ /* Is this a special opcode? */
+ if (likely (opcode >= opcode_base))
+ {
+ if (unlikely (line_range == 0))
+ goto invalid_data;
+
+ /* Yes. Handling this is quite easy since the opcode value
+ is computed with
+
+ opcode = (desired line increment - line_base)
+ + (line_range * address advance) + opcode_base
+ */
+ int line_increment = (line_base
+ + (opcode - opcode_base) % line_range);
+
+ /* Perform the increments. */
+ state.line += line_increment;
+ advance_pc ((opcode - opcode_base) / line_range);
+
+ /* Add a new line with the current state machine values. */
+ NEW_LINE (0);
+
+ /* Reset the flags. */
+ state.basic_block = false;
+ state.prologue_end = false;
+ state.epilogue_begin = false;
+ state.discriminator = 0;
+ }
+ else if (opcode == 0)
+ {
+ /* This an extended opcode. */
+ if (unlikely (lineendp - linep < 2))
+ goto invalid_data;
+
+ /* The length. */
+ uint_fast8_t len = *linep++;
+
+ if (unlikely ((size_t) (lineendp - linep) < len))
+ goto invalid_data;
+
+ /* The sub-opcode. */
+ opcode = *linep++;
+
+ switch (opcode)
+ {
+ case DW_LNE_end_sequence:
+ /* Add a new line with the current state machine values.
+ The is the end of the sequence. */
+ NEW_LINE (1);
+
+ /* Reset the registers. */
+ state.addr = 0;
+ state.op_index = 0;
+ state.file = 1;
+ state.line = 1;
+ state.column = 0;
+ state.is_stmt = default_is_stmt;
+ state.basic_block = false;
+ state.prologue_end = false;
+ state.epilogue_begin = false;
+ state.isa = 0;
+ state.discriminator = 0;
+ state.context = 0;
+ state.function_name = 0;
+ break;
+
+ case DW_LNE_set_address:
+ /* The value is an address. The size is defined as
+ appropriate for the target machine. We use the
+ address size field from the CU header. */
+ state.op_index = 0;
+ if (unlikely (lineendp - linep < (uint8_t) address_size))
+ goto invalid_data;
+ if (__libdw_read_address_inc (dbg, IDX_debug_line, &linep,
+ address_size, &state.addr))
+ goto out;
+ break;
+
+ case DW_LNE_define_file:
+ {
+ char *fname = (char *) linep;
+ uint8_t *endp = memchr (linep, '\0', lineendp - linep);
+ if (endp == NULL)
+ goto invalid_data;
+ size_t fnamelen = endp - linep;
+ linep = endp + 1;
+
+ unsigned int diridx;
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (diridx, linep, lineendp);
+ if (unlikely (diridx >= ndirlist))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DIR_IDX);
+ goto invalid_data;
+ }
+ Dwarf_Word mtime;
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (mtime, linep, lineendp);
+ Dwarf_Word filelength;
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (filelength, linep, lineendp);
+
+ struct filelist *new_file = NEW_FILE ();
+ if (fname[0] == '/')
+ new_file->info.name = fname;
+ else
+ {
+ new_file->info.name =
+ libdw_alloc (dbg, char, 1, (dirarray[diridx].len + 1
+ + fnamelen + 1));
+ char *cp = new_file->info.name;
+
+ if (dirarray[diridx].dir != NULL)
+ /* This value could be NULL in case the
+ DW_AT_comp_dir was not present. We
+ cannot do much in this case. Just
+ keep the file relative. */
+ {
+ cp = stpcpy (cp, dirarray[diridx].dir);
+ *cp++ = '/';
+ }
+ strcpy (cp, fname);
+ }
+
+ new_file->info.mtime = mtime;
+ new_file->info.length = filelength;
+ }
+ break;
+
+ case DW_LNE_set_discriminator:
+ /* Takes one ULEB128 parameter, the discriminator. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (state.discriminator, linep, lineendp);
+ break;
+
+ case DW_LNE_NVIDIA_inlined_call:
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (state.context, linep, lineendp);
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (state.function_name, linep, lineendp);
+ state.function_name += debug_str_offset;
+ break;
+
+ case DW_LNE_NVIDIA_set_function_name:
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (state.function_name, linep, lineendp);
+ state.function_name += debug_str_offset;
+ break;
+
+ default:
+ /* Unknown, ignore it. */
+ if (unlikely ((size_t) (lineendp - (linep - 1)) < len))
+ goto invalid_data;
+ linep += len - 1;
+ break;
+ }
+ }
+ else if (opcode <= DW_LNS_set_isa)
+ {
+ /* This is a known standard opcode. */
+ switch (opcode)
+ {
+ case DW_LNS_copy:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ /* Add a new line with the current state machine values. */
+ NEW_LINE (0);
+
+ /* Reset the flags. */
+ state.basic_block = false;
+ state.prologue_end = false;
+ state.epilogue_begin = false;
+ state.discriminator = 0;
+ break;
+
+ case DW_LNS_advance_pc:
+ /* Takes one uleb128 parameter which is added to the
+ address. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (u128, linep, lineendp);
+ advance_pc (u128);
+ break;
+
+ case DW_LNS_advance_line:
+ /* Takes one sleb128 parameter which is added to the
+ line. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_sleb128 (s128, linep, lineendp);
+ state.line += s128;
+ break;
+
+ case DW_LNS_set_file:
+ /* Takes one uleb128 parameter which is stored in file. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (u128, linep, lineendp);
+ state.file = u128;
+ break;
+
+ case DW_LNS_set_column:
+ /* Takes one uleb128 parameter which is stored in column. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (u128, linep, lineendp);
+ state.column = u128;
+ break;
+
+ case DW_LNS_negate_stmt:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ state.is_stmt = 1 - state.is_stmt;
+ break;
+
+ case DW_LNS_set_basic_block:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ state.basic_block = true;
+ break;
+
+ case DW_LNS_const_add_pc:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ if (unlikely (line_range == 0))
+ goto invalid_data;
+
+ advance_pc ((255 - opcode_base) / line_range);
+ break;
+
+ case DW_LNS_fixed_advance_pc:
+ /* Takes one 16 bit parameter which is added to the
+ address. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1)
+ || unlikely (lineendp - linep < 2))
+ goto invalid_data;
+
+ state.addr += read_2ubyte_unaligned_inc (dbg, linep);
+ state.op_index = 0;
+ break;
+
+ case DW_LNS_set_prologue_end:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ state.prologue_end = true;
+ break;
+
+ case DW_LNS_set_epilogue_begin:
+ /* Takes no argument. */
+ if (unlikely (standard_opcode_lengths[opcode] != 0))
+ goto invalid_data;
+
+ state.epilogue_begin = true;
+ break;
+
+ case DW_LNS_set_isa:
+ /* Takes one uleb128 parameter which is stored in isa. */
+ if (unlikely (standard_opcode_lengths[opcode] != 1))
+ goto invalid_data;
+
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (state.isa, linep, lineendp);
+ break;
+ }
+ }
+ else
+ {
+ /* This is a new opcode the generator but not we know about.
+ Read the parameters associated with it but then discard
+ everything. Read all the parameters for this opcode. */
+ for (int n = standard_opcode_lengths[opcode]; n > 0; --n)
+ {
+ if (unlikely (linep >= lineendp))
+ goto invalid_data;
+ get_uleb128 (u128, linep, lineendp);
+ }
+
+ /* Next round, ignore this opcode. */
+ continue;
+ }
+ }
+
+ /* Put all the files in an array. */
+ Dwarf_Files *files = libdw_alloc (dbg, Dwarf_Files,
+ sizeof (Dwarf_Files)
+ + nfilelist * sizeof (Dwarf_Fileinfo)
+ + (ndirlist + 1) * sizeof (char *),
+ 1);
+ const char **dirs = (void *) &files->info[nfilelist];
+
+ struct filelist *fileslist = filelist;
+ files->nfiles = nfilelist;
+ for (size_t n = nfilelist; n > 0; n--)
+ {
+ files->info[n - 1] = fileslist->info;
+ fileslist = fileslist->next;
+ }
+ assert (fileslist == NULL);
+
+ /* Put all the directory strings in an array. */
+ files->ndirs = ndirlist;
+ for (unsigned int i = 0; i < ndirlist; ++i)
+ dirs[i] = dirarray[i].dir;
+ dirs[ndirlist] = NULL;
+
+ /* Pass the file data structure to the caller. */
+ if (filesp != NULL)
+ *filesp = files;
+
+ size_t buf_size = (sizeof (Dwarf_Lines)
+ + (sizeof (Dwarf_Line) * state.nlinelist));
+ void *buf = libdw_alloc (dbg, Dwarf_Lines, buf_size, 1);
+
+ /* First use the buffer for the pointers, and sort the entries.
+ We'll write the pointers in the end of the buffer, and then
+ copy into the buffer from the beginning so the overlap works. */
+ assert (sizeof (Dwarf_Line) >= sizeof (struct linelist *));
+ struct linelist **sortlines = (buf + buf_size
+ - sizeof (struct linelist **) * state.nlinelist);
+
+ /* The list is in LIFO order and usually they come in clumps with
+ ascending addresses. So fill from the back to probably start with
+ runs already in order before we sort. */
+ struct linelist *lineslist = state.linelist;
+ for (size_t i = state.nlinelist; i-- > 0; )
+ {
+ sortlines[i] = lineslist;
+ lineslist = lineslist->next;
+ }
+ assert (lineslist == NULL);
+
+ /* Sort by ascending address. */
+ qsort (sortlines, state.nlinelist, sizeof sortlines[0], &compare_lines);
+
+ /* Now that they are sorted, put them in the final array.
+ The buffers overlap, so we've clobbered the early elements
+ of SORTLINES by the time we're reading the later ones. */
+ Dwarf_Lines *lines = buf;
+ lines->nlines = state.nlinelist;
+ for (size_t i = 0; i < state.nlinelist; ++i)
+ {
+ lines->info[i] = sortlines[i]->line;
+ lines->info[i].files = files;
+ }
+
+ /* Make sure the highest address for the CU is marked as end_sequence.
+ This is required by the DWARF spec, but some compilers forget and
+ dwfl_module_getsrc depends on it. */
+ if (state.nlinelist > 0)
+ lines->info[state.nlinelist - 1].end_sequence = 1;
+
+ /* Pass the line structure back to the caller. */
+ if (linesp != NULL)
+ *linesp = lines;
+
+ /* Success. */
+ res = 0;
+
+ out:
+ /* Free malloced line records, if any. */
+ for (size_t i = MAX_STACK_LINES; i < state.nlinelist; i++)
+ {
+ struct linelist *ll = state.linelist->next;
+ free (state.linelist);
+ state.linelist = ll;
+ }
+ if (dirarray != dirstack)
+ free (dirarray);
+ for (size_t i = MAX_STACK_FILES; i < nfilelist; i++)
+ {
+ struct filelist *fl = filelist->next;
+ free (filelist);
+ filelist = fl;
+ }
+
+ return res;
+}
+
+static int
+files_lines_compare (const void *p1, const void *p2)
+{
+ const struct files_lines_s *t1 = p1;
+ const struct files_lines_s *t2 = p2;
+
+ if (t1->debug_line_offset < t2->debug_line_offset)
+ return -1;
+ if (t1->debug_line_offset > t2->debug_line_offset)
+ return 1;
+
+ return 0;
+}
+
+int
+internal_function
+__libdw_getsrclines (Dwarf *dbg, Dwarf_Off debug_line_offset,
+ const char *comp_dir, unsigned address_size,
+ Dwarf_Lines **linesp, Dwarf_Files **filesp)
+{
+ struct files_lines_s fake = { .debug_line_offset = debug_line_offset };
+ struct files_lines_s **found = tfind (&fake, &dbg->files_lines,
+ files_lines_compare);
+ if (found == NULL)
+ {
+ Elf_Data *data = __libdw_checked_get_data (dbg, IDX_debug_line);
+ if (data == NULL
+ || __libdw_offset_in_section (dbg, IDX_debug_line,
+ debug_line_offset, 1) != 0)
+ return -1;
+
+ const unsigned char *linep = data->d_buf + debug_line_offset;
+ const unsigned char *lineendp = data->d_buf + data->d_size;
+
+ struct files_lines_s *node = libdw_alloc (dbg, struct files_lines_s,
+ sizeof *node, 1);
+
+ if (read_srclines (dbg, linep, lineendp, comp_dir, address_size,
+ &node->lines, &node->files) != 0)
+ return -1;
+
+ node->debug_line_offset = debug_line_offset;
+
+ found = tsearch (node, &dbg->files_lines, files_lines_compare);
+ if (found == NULL)
+ {
+ __libdw_seterrno (DWARF_E_NOMEM);
+ return -1;
+ }
+ }
+
+ if (linesp != NULL)
+ *linesp = (*found)->lines;
+
+ if (filesp != NULL)
+ *filesp = (*found)->files;
+
+ return 0;
+}
+
+/* Get the compilation directory, if any is set. */
+const char *
+__libdw_getcompdir (Dwarf_Die *cudie)
+{
+ Dwarf_Attribute compdir_attr_mem;
+ Dwarf_Attribute *compdir_attr = INTUSE(dwarf_attr) (cudie,
+ DW_AT_comp_dir,
+ &compdir_attr_mem);
+ return INTUSE(dwarf_formstring) (compdir_attr);
+}
+
+int
+dwarf_getsrclines (Dwarf_Die *cudie, Dwarf_Lines **lines, size_t *nlines)
+{
+ if (cudie == NULL)
+ return -1;
+ if (! is_cudie (cudie))
+ {
+ __libdw_seterrno (DWARF_E_NOT_CUDIE);
+ return -1;
+ }
+
+ /* Get the information if it is not already known. */
+ struct Dwarf_CU *const cu = cudie->cu;
+ if (cu->lines == NULL)
+ {
+ /* For split units always pick the lines from the skeleton. */
+ if (cu->unit_type == DW_UT_split_compile
+ || cu->unit_type == DW_UT_split_type)
+ {
+ /* We tries, assume we fail... */
+ cu->lines = (void *) -1l;
+
+ Dwarf_CU *skel = __libdw_find_split_unit (cu);
+ if (skel != NULL)
+ {
+ Dwarf_Die skeldie = CUDIE (skel);
+ int res = INTUSE(dwarf_getsrclines) (&skeldie, lines, nlines);
+ if (res == 0)
+ {
+ cu->lines = skel->lines;
+ *lines = cu->lines;
+ *nlines = cu->lines->nlines;
+ }
+ return res;
+ }
+
+ __libdw_seterrno (DWARF_E_NO_DEBUG_LINE);
+ return -1;
+ }
+
+ /* Failsafe mode: no data found. */
+ cu->lines = (void *) -1l;
+ cu->files = (void *) -1l;
+
+ /* The die must have a statement list associated. */
+ Dwarf_Attribute stmt_list_mem;
+ Dwarf_Attribute *stmt_list = INTUSE(dwarf_attr) (cudie, DW_AT_stmt_list,
+ &stmt_list_mem);
+
+ /* Get the offset into the .debug_line section. NB: this call
+ also checks whether the previous dwarf_attr call failed. */
+ Dwarf_Off debug_line_offset;
+ if (__libdw_formptr (stmt_list, IDX_debug_line, DWARF_E_NO_DEBUG_LINE,
+ NULL, &debug_line_offset) == NULL)
+ return -1;
+
+ if (__libdw_getsrclines (cu->dbg, debug_line_offset,
+ __libdw_getcompdir (cudie),
+ cu->address_size, &cu->lines, &cu->files) < 0)
+ return -1;
+ }
+ else if (cu->lines == (void *) -1l)
+ return -1;
+
+ *lines = cu->lines;
+ *nlines = cu->lines->nlines;
+
+ // XXX Eventually: unlocking here.
+
+ return 0;
+}
+INTDEF(dwarf_getsrclines)
diff --git a/contrib/libdw/dwarf_hasattr.c b/contrib/libdw/dwarf_hasattr.c
new file mode 100644
index 0000000..eca0839
--- /dev/null
+++ b/contrib/libdw/dwarf_hasattr.c
@@ -0,0 +1,77 @@
+/* Check whether given DIE has specific attribute.
+ Copyright (C) 2003, 2005, 2014, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+
+int
+dwarf_hasattr (Dwarf_Die *die, unsigned int search_name)
+{
+ if (die == NULL)
+ return 0;
+
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return 0;
+ }
+
+ /* Search the name attribute. Dwarf_Abbrev was checked when created,
+ so we can read unchecked here. */
+ const unsigned char *attrp = abbrevp->attrp;
+ while (1)
+ {
+ /* Get attribute name and form. */
+ unsigned int attr_name;
+ get_uleb128_unchecked (attr_name, attrp);
+ unsigned int attr_form;
+ get_uleb128_unchecked (attr_form, attrp);
+
+ /* We can stop if we found the end of the attribute list. */
+ if (attr_name == 0 && attr_form == 0)
+ return 0;
+
+ if (attr_name == search_name)
+ return 1;
+
+ if (attr_form == DW_FORM_implicit_const)
+ {
+ int64_t attr_value __attribute__ ((unused));
+ get_sleb128_unchecked (attr_value, attrp);
+ }
+ }
+}
+INTDEF (dwarf_hasattr)
diff --git a/contrib/libdw/dwarf_haschildren.c b/contrib/libdw/dwarf_haschildren.c
new file mode 100644
index 0000000..03a8173
--- /dev/null
+++ b/contrib/libdw/dwarf_haschildren.c
@@ -0,0 +1,51 @@
+/* Return string associated with given attribute.
+ Copyright (C) 2003, 2005, 2008, 2014 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+#include
+
+
+int
+dwarf_haschildren (Dwarf_Die *die)
+{
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
+ return abbrevp->has_children;
+}
+INTDEF (dwarf_haschildren)
diff --git a/contrib/libdw/dwarf_lineaddr.c b/contrib/libdw/dwarf_lineaddr.c
new file mode 100644
index 0000000..4e1952d
--- /dev/null
+++ b/contrib/libdw/dwarf_lineaddr.c
@@ -0,0 +1,46 @@
+/* Return line address.
+ Copyright (C) 2004 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2004.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+int
+dwarf_lineaddr (Dwarf_Line *line, Dwarf_Addr *addrp)
+{
+ if (line == NULL)
+ return -1;
+
+ *addrp = line->addr;
+
+ return 0;
+}
diff --git a/contrib/libdw/dwarf_lineno.c b/contrib/libdw/dwarf_lineno.c
new file mode 100644
index 0000000..009999c
--- /dev/null
+++ b/contrib/libdw/dwarf_lineno.c
@@ -0,0 +1,46 @@
+/* Return line number.
+ Copyright (C) 2004 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2004.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+int
+dwarf_lineno (Dwarf_Line *line, int *linep)
+{
+ if (line == NULL)
+ return -1;
+
+ *linep = line->line;
+
+ return 0;
+}
diff --git a/contrib/libdw/dwarf_linesrc.c b/contrib/libdw/dwarf_linesrc.c
new file mode 100644
index 0000000..27b5990
--- /dev/null
+++ b/contrib/libdw/dwarf_linesrc.c
@@ -0,0 +1,56 @@
+/* Find line information for address.
+ Copyright (C) 2004 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2004.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+const char *
+dwarf_linesrc (Dwarf_Line *line, Dwarf_Word *mtime, Dwarf_Word *length)
+{
+ if (line == NULL)
+ return NULL;
+
+ if (line->file >= line->files->nfiles)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ if (mtime != NULL)
+ *mtime = line->files->info[line->file].mtime;
+
+ if (length != NULL)
+ *length = line->files->info[line->file].length;
+
+ return line->files->info[line->file].name;
+}
diff --git a/contrib/libdw/dwarf_nextcu.c b/contrib/libdw/dwarf_nextcu.c
new file mode 100644
index 0000000..67cec44
--- /dev/null
+++ b/contrib/libdw/dwarf_nextcu.c
@@ -0,0 +1,309 @@
+/* Advance to next CU header.
+ Copyright (C) 2002-2010, 2016, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+
+int
+dwarf_next_unit (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
+ size_t *header_sizep, Dwarf_Half *versionp,
+ Dwarf_Off *abbrev_offsetp, uint8_t *address_sizep,
+ uint8_t *offset_sizep, uint64_t *v4_type_signaturep,
+ Dwarf_Off *v4_type_offsetp)
+{
+ const bool v4_debug_types = v4_type_signaturep != NULL;
+ return __libdw_next_unit (dwarf, v4_debug_types, off, next_off,
+ header_sizep, versionp, NULL,
+ abbrev_offsetp, address_sizep, offset_sizep,
+ v4_type_signaturep, v4_type_offsetp);
+}
+INTDEF(dwarf_next_unit)
+
+int
+internal_function
+__libdw_next_unit (Dwarf *dwarf, bool v4_debug_types, Dwarf_Off off,
+ Dwarf_Off *next_off, size_t *header_sizep,
+ Dwarf_Half *versionp, uint8_t *unit_typep,
+ Dwarf_Off *abbrev_offsetp, uint8_t *address_sizep,
+ uint8_t *offset_sizep, uint64_t *unit_id8p,
+ Dwarf_Off *subdie_offsetp)
+{
+ /* Note that debug_type units come from .debug_types in DWARF < 5 and
+ from .debug_info in DWARF >= 5. If the user requested the
+ v4_type_signature we return from .debug_types always. If no signature
+ is requested we return units (any type) from .debug_info. */
+ const size_t sec_idx = v4_debug_types ? IDX_debug_types : IDX_debug_info;
+
+ /* Maybe there has been an error before. */
+ if (dwarf == NULL)
+ return -1;
+
+ /* If we reached the end before don't do anything. */
+ if (off == (Dwarf_Off) -1l
+ || unlikely (dwarf->sectiondata[sec_idx] == NULL)
+ /* Make sure there is enough space in the .debug_info section
+ for at least the initial word. We cannot test the rest since
+ we don't know yet whether this is a 64-bit object or not. */
+ || unlikely (off + 4 >= dwarf->sectiondata[sec_idx]->d_size))
+ {
+ *next_off = (Dwarf_Off) -1l;
+ return 1;
+ }
+
+ /* This points into the .debug_info or .debug_types section to the
+ beginning of the CU entry. */
+ const unsigned char *data = dwarf->sectiondata[sec_idx]->d_buf;
+ const unsigned char *bytes = data + off;
+ const unsigned char *bytes_end = data + dwarf->sectiondata[sec_idx]->d_size;
+
+ /* The format of the CU header is described in dwarf2p1 7.5.1 and
+ changed in DWARFv5 (to include unit type, switch location of some
+ fields and add some optional fields).
+
+ 1. A 4-byte or 12-byte unsigned integer representing the length
+ of the .debug_info contribution for that compilation unit, not
+ including the length field itself. In the 32-bit DWARF format,
+ this is a 4-byte unsigned integer (which must be less than
+ 0xfffffff0); in the 64-bit DWARF format, this consists of the
+ 4-byte value 0xffffffff followed by an 8-byte unsigned integer
+ that gives the actual length (see Section 7.2.2). This field
+ indicates whether this unit is 32-bit of 64-bit DWARF, which
+ affects all other offset fields in this header.
+
+ 2. A 2-byte unsigned integer representing the version of the
+ DWARF information for that compilation unit. For DWARF Version
+ 2.1, the value in this field is 2 (3 for v3, 4 for v4, 5 for v5).
+ This fields determines the order of the next fields and whether
+ there are any optional fields in this header.
+
+ 3. For DWARF 2, 3 and 4 (including v4 type units):
+ A 4-byte or 8-byte unsigned offset into the .debug_abbrev
+ section. This offset associates the compilation unit with a
+ particular set of debugging information entry abbreviations. In
+ the 32-bit DWARF format, this is a 4-byte unsigned length; in
+ the 64-bit DWARF format, this is an 8-byte unsigned length (see
+ Section 7.4).
+
+ For DWARF 5:
+ A 1-byte unsigned integer representing the unit (header) type.
+ This field determines what the optional fields in the header
+ represent. If this is an unknown unit type then we cannot
+ assume anything about the rest of the unit (header).
+
+ 4. For all DWARF versions (including v4 type units):
+ A 1-byte unsigned integer representing the size in bytes of
+ an address on the target architecture. If the system uses
+ segmented addressing, this value represents the size of the
+ offset portion of an address. This is the last field in the header
+ for DWARF versions 2, 3 and 4 (except for v4 type units).
+
+ 5. For DWARF 5 only (this is field 3 for DWARF 2, 3, 4 and v4 types):
+ A 4-byte or 8-byte unsigned offset into the .debug_abbrev
+ section. This offset associates the compilation unit with a
+ particular set of debugging information entry abbreviations. In
+ the 32-bit DWARF format, this is a 4-byte unsigned length; in
+ the 64-bit DWARF format, this is an 8-byte unsigned length.
+
+ 6. For v4 type units (this is really field 5 for v4 types) and
+ DWARF 5 optional (skeleton, split_compile, type and
+ split_type): An 8 byte (opaque) integer constant value. For
+ v4 and v5 type units this is the type signature. For skeleton
+ and split compile units this is the compilation ID.
+
+ 7. For v4 type units (this is really field 6 for v4 types) and
+ DWARF 5 optional (type and split_type) and v4 type units:
+ A 4-byte or 8-byte unsigned offset. In the 32-bit DWARF format,
+ this is a 4-byte unsigned length; in the 64-bit DWARF format,
+ this is an 8-byte unsigned length. This is the type DIE offset
+ (which is not necessarily the first DIE in the unit).
+ */
+
+ uint64_t length = read_4ubyte_unaligned_inc (dwarf, bytes);
+ size_t offset_size = 4;
+ /* Lengths of 0xfffffff0 - 0xffffffff are escape codes. Oxffffffff is
+ used to indicate that 64-bit dwarf information is being used, the
+ other values are currently reserved. */
+ if (length == DWARF3_LENGTH_64_BIT)
+ offset_size = 8;
+ else if (unlikely (length >= DWARF3_LENGTH_MIN_ESCAPE_CODE
+ && length <= DWARF3_LENGTH_MAX_ESCAPE_CODE))
+ {
+ invalid:
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return -1;
+ }
+
+ if (length == DWARF3_LENGTH_64_BIT)
+ {
+ /* This is a 64-bit DWARF format. */
+ if (bytes_end - bytes < 8)
+ goto invalid;
+ length = read_8ubyte_unaligned_inc (dwarf, bytes);
+ }
+
+ /* Read the version stamp. Always a 16-bit value. */
+ if (bytes_end - bytes < 2)
+ goto invalid;
+ uint_fast16_t version = read_2ubyte_unaligned_inc (dwarf, bytes);
+
+ /* We keep unit_type at zero for older DWARF since we cannot
+ easily guess whether it is a compile or partial unit. */
+ uint8_t unit_type = 0;
+ if (version >= 5)
+ {
+ if (bytes_end - bytes < 1)
+ goto invalid;
+ unit_type = *bytes++;
+ }
+
+ /* All these are optional. */
+ Dwarf_Off subdie_off = 0;
+ uint64_t sig_id = 0;
+ Dwarf_Off abbrev_offset = 0;
+ uint8_t address_size = 0;
+
+ if (version < 2 || version > 5
+ || (version == 5 && ! (unit_type == DW_UT_compile
+ || unit_type == DW_UT_partial
+ || unit_type == DW_UT_skeleton
+ || unit_type == DW_UT_split_compile
+ || unit_type == DW_UT_type
+ || unit_type == DW_UT_split_type)))
+ {
+ /* We cannot really know more about the header. Just report
+ the length of the unit, version and unit type. */
+ goto done;
+ }
+
+ /* We have to guess the unit_type. But we don't have a real CUDIE. */
+ if (version < 5)
+ unit_type = v4_debug_types ? DW_UT_type : DW_UT_compile;
+
+ /* Now we know how large the header is (should be). */
+ if (unlikely (__libdw_first_die_from_cu_start (off, offset_size, version,
+ unit_type)
+ >= dwarf->sectiondata[sec_idx]->d_size))
+ {
+ *next_off = -1;
+ return 1;
+ }
+
+ /* The address size. Always an 8-bit value.
+ Comes after abbrev_offset for version < 5, otherwise unit type
+ and address size (if a known unit type) comes before abbrev_offset. */
+ if (version >= 5)
+ address_size = *bytes++;
+
+ /* Get offset in .debug_abbrev. Note that the size of the entry
+ depends on whether this is a 32-bit or 64-bit DWARF definition. */
+ if (__libdw_read_offset_inc (dwarf, sec_idx, &bytes, offset_size,
+ &abbrev_offset, IDX_debug_abbrev, 0))
+ return -1;
+
+ if (version < 5)
+ address_size = *bytes++;
+
+ /* Extra fields, signature/id and type offset/padding. */
+ if (v4_debug_types
+ || (version >= 5
+ && (unit_type == DW_UT_skeleton || unit_type == DW_UT_split_compile
+ || unit_type == DW_UT_type || unit_type == DW_UT_split_type)))
+ {
+ sig_id = read_8ubyte_unaligned_inc (dwarf, bytes);
+
+ if ((v4_debug_types
+ || unit_type == DW_UT_type || unit_type == DW_UT_split_type))
+ {
+ if (__libdw_read_offset_inc (dwarf, sec_idx, &bytes, offset_size,
+ &subdie_off, sec_idx, 0))
+ return -1;
+
+ /* Validate that the TYPE_OFFSET points past the header. */
+ if (unlikely (subdie_off < (size_t) (bytes - (data + off))))
+ goto invalid;
+ }
+ }
+
+ done:
+ if (unit_id8p != NULL)
+ *unit_id8p = sig_id;
+
+ if (subdie_offsetp != NULL)
+ *subdie_offsetp = subdie_off;
+
+ /* Store the header length. This is really how much we have read
+ from the header. If we didn't recognize the unit type the
+ header might actually be bigger. */
+ if (header_sizep != NULL)
+ *header_sizep = bytes - (data + off);
+
+ if (versionp != NULL)
+ *versionp = version;
+
+ if (unit_typep != NULL)
+ *unit_typep = unit_type;
+
+ if (abbrev_offsetp != NULL)
+ *abbrev_offsetp = abbrev_offset;
+
+ if (address_sizep != NULL)
+ *address_sizep = address_size;
+
+ /* Store the offset size. */
+ if (offset_sizep != NULL)
+ *offset_sizep = offset_size;
+
+ /* The length of the unit doesn't include the length field itself.
+ The length field is either, with offset == 4: 2 * 4 - 4 == 4,
+ or with offset == 8: 2 * 8 - 4 == 12. */
+ *next_off = off + 2 * offset_size - 4 + length;
+
+ /* This means that the length field is bogus, but return the CU anyway.
+ We just won't return anything after this. */
+ if (*next_off <= off)
+ *next_off = (Dwarf_Off) -1;
+
+ return 0;
+}
+
+int
+dwarf_nextcu (Dwarf *dwarf, Dwarf_Off off, Dwarf_Off *next_off,
+ size_t *header_sizep, Dwarf_Off *abbrev_offsetp,
+ uint8_t *address_sizep, uint8_t *offset_sizep)
+{
+ return INTUSE(dwarf_next_unit) (dwarf, off, next_off, header_sizep, NULL,
+ abbrev_offsetp, address_sizep, offset_sizep,
+ NULL, NULL);
+}
+INTDEF(dwarf_nextcu)
diff --git a/contrib/libdw/dwarf_offdie.c b/contrib/libdw/dwarf_offdie.c
new file mode 100644
index 0000000..883720d
--- /dev/null
+++ b/contrib/libdw/dwarf_offdie.c
@@ -0,0 +1,84 @@
+/* Return DIE at given offset.
+ Copyright (C) 2002-2010, 2017 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libdwP.h"
+
+
+Dwarf_Die *
+internal_function
+__libdw_offdie (Dwarf *dbg, Dwarf_Off offset, Dwarf_Die *result,
+ bool debug_types)
+{
+ if (dbg == NULL)
+ return NULL;
+
+ Elf_Data *const data = dbg->sectiondata[debug_types ? IDX_debug_types
+ : IDX_debug_info];
+ if (data == NULL || offset >= data->d_size)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return NULL;
+ }
+
+ /* Clear the entire DIE structure. This signals we have not yet
+ determined any of the information. */
+ memset (result, '\0', sizeof (Dwarf_Die));
+
+ result->addr = (char *) data->d_buf + offset;
+
+ /* Get the CU. */
+ result->cu = __libdw_findcu (dbg, offset, debug_types);
+ if (result->cu == NULL)
+ {
+ /* This should never happen. The input file is malformed. */
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ result = NULL;
+ }
+
+ return result;
+}
+
+
+Dwarf_Die *
+dwarf_offdie (Dwarf *dbg, Dwarf_Off offset, Dwarf_Die *result)
+{
+ return __libdw_offdie (dbg, offset, result, false);
+}
+INTDEF(dwarf_offdie)
+
+Dwarf_Die *
+dwarf_offdie_types (Dwarf *dbg, Dwarf_Off offset, Dwarf_Die *result)
+{
+ return __libdw_offdie (dbg, offset, result, true);
+}
diff --git a/contrib/libdw/dwarf_onesrcline.c b/contrib/libdw/dwarf_onesrcline.c
new file mode 100644
index 0000000..5d3c3de
--- /dev/null
+++ b/contrib/libdw/dwarf_onesrcline.c
@@ -0,0 +1,50 @@
+/* Return one of the sources lines of a CU.
+ Copyright (C) 2004 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2004.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+Dwarf_Line *
+dwarf_onesrcline (Dwarf_Lines *lines, size_t idx)
+{
+ if (lines == NULL)
+ return NULL;
+
+ if (idx >= lines->nlines)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_LINE_IDX);
+ return NULL;
+ }
+
+ return &lines->info[idx];
+}
diff --git a/contrib/libdw/dwarf_sig8_hash.c b/contrib/libdw/dwarf_sig8_hash.c
new file mode 100644
index 0000000..777f9eb
--- /dev/null
+++ b/contrib/libdw/dwarf_sig8_hash.c
@@ -0,0 +1,41 @@
+/* Implementation of hash table for DWARF .debug_types section content.
+ Copyright (C) 2010 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#define NO_UNDEF
+#include "dwarf_sig8_hash.h"
+#undef NO_UNDEF
+
+/* This is defined in dwarf_abbrev_hash.c, we can just use it here. */
+#define next_prime __libdwarf_next_prime
+extern size_t next_prime (size_t) attribute_hidden;
+
+#include
diff --git a/contrib/libdw/dwarf_sig8_hash.h b/contrib/libdw/dwarf_sig8_hash.h
new file mode 100644
index 0000000..c399919
--- /dev/null
+++ b/contrib/libdw/dwarf_sig8_hash.h
@@ -0,0 +1,43 @@
+/* Hash table for DWARF .debug_types section content.
+ Copyright (C) 2010 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 . */
+
+#ifndef _DWARF_SIG8_HASH_H
+#define _DWARF_SIG8_HASH_H 1
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdw.h"
+
+#define NAME Dwarf_Sig8_Hash
+#define TYPE struct Dwarf_CU *
+
+#include
+
+#endif /* dwarf_sig8_hash.h */
diff --git a/contrib/libdw/dwarf_tag.c b/contrib/libdw/dwarf_tag.c
new file mode 100644
index 0000000..d784970
--- /dev/null
+++ b/contrib/libdw/dwarf_tag.c
@@ -0,0 +1,94 @@
+/* Return tag of given DIE.
+ Copyright (C) 2003-2011, 2014 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2003.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwP.h"
+
+
+Dwarf_Abbrev *
+internal_function
+__libdw_findabbrev (struct Dwarf_CU *cu, unsigned int code)
+{
+ Dwarf_Abbrev *abb;
+
+ /* Abbreviation code can never have a value of 0. */
+ if (unlikely (code == 0))
+ return DWARF_END_ABBREV;
+
+ /* See whether the entry is already in the hash table. */
+ abb = Dwarf_Abbrev_Hash_find (&cu->abbrev_hash, code);
+ if (abb == NULL)
+ while (cu->last_abbrev_offset != (size_t) -1l)
+ {
+ size_t length;
+
+ /* Find the next entry. It gets automatically added to the
+ hash table. */
+ abb = __libdw_getabbrev (cu->dbg, cu, cu->last_abbrev_offset, &length,
+ NULL);
+ if (abb == NULL || abb == DWARF_END_ABBREV)
+ {
+ /* Make sure we do not try to search for it again. */
+ cu->last_abbrev_offset = (size_t) -1l;
+ return DWARF_END_ABBREV;
+ }
+
+ cu->last_abbrev_offset += length;
+
+ /* Is this the code we are looking for? */
+ if (abb->code == code)
+ break;
+ }
+
+ /* This is our second (or third, etc.) call to __libdw_findabbrev
+ and the code is invalid. */
+ if (unlikely (abb == NULL))
+ abb = DWARF_END_ABBREV;
+
+ return abb;
+}
+
+
+int
+dwarf_tag (Dwarf_Die *die)
+{
+ /* Find the abbreviation entry. */
+ Dwarf_Abbrev *abbrevp = __libdw_dieabbrev (die, NULL);
+ if (unlikely (abbrevp == DWARF_END_ABBREV))
+ {
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ return DW_TAG_invalid;
+ }
+
+ return abbrevp->tag;
+}
+INTDEF(dwarf_tag)
diff --git a/contrib/libdw/dwelf_dwarf_gnu_debugaltlink.c b/contrib/libdw/dwelf_dwarf_gnu_debugaltlink.c
new file mode 100644
index 0000000..b8285d0
--- /dev/null
+++ b/contrib/libdw/dwelf_dwarf_gnu_debugaltlink.c
@@ -0,0 +1,62 @@
+/* Returns the file name and build ID stored in the .gnu_altdebuglink if found.
+ Copyright (C) 2014 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libdwelfP.h"
+
+ssize_t
+dwelf_dwarf_gnu_debugaltlink (Dwarf *dwarf,
+ const char **name_p,
+ const void **build_idp)
+{
+ Elf_Data *data = dwarf->sectiondata[IDX_gnu_debugaltlink];
+ if (data == NULL)
+ {
+ return 0;
+ }
+
+ const void *ptr = memchr (data->d_buf, '\0', data->d_size);
+ if (ptr == NULL)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ return -1;
+ }
+ size_t build_id_len = data->d_size - (ptr - data->d_buf + 1);
+ if (build_id_len == 0 || (size_t) (ssize_t) build_id_len != build_id_len)
+ {
+ __libdw_seterrno (DWARF_E_INVALID_ELF);
+ return -1;
+ }
+ *name_p = data->d_buf;
+ *build_idp = ptr + 1;
+ return build_id_len;
+}
+INTDEF(dwelf_dwarf_gnu_debugaltlink)
diff --git a/contrib/libdw/dynamicsizehash.h b/contrib/libdw/dynamicsizehash.h
new file mode 100644
index 0000000..ccd41d0
--- /dev/null
+++ b/contrib/libdw/dynamicsizehash.h
@@ -0,0 +1,127 @@
+/* Copyright (C) 2000-2010 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2000.
+
+ 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 . */
+
+#include
+
+/* Before including this file the following macros must be defined:
+
+ NAME name of the hash table structure.
+ TYPE data type of the hash table entries
+
+ The following macros if present select features:
+
+ ITERATE iterating over the table entries is possible
+ HASHTYPE integer type for hash values, default unsigned long int
+ */
+
+
+/* Optionally include an entry pointing to the first used entry. */
+#ifdef ITERATE
+# define FIRST(name) name##_ent *first;
+# define NEXT(name) struct name##_ent *next;
+#else
+# define FIRST(name)
+# define NEXT(name)
+#endif
+
+#ifndef HASHTYPE
+# define HASHTYPE unsigned long int
+#endif
+
+
+/* Defined separately. */
+extern size_t next_prime (size_t seed);
+
+
+/* Table entry type. */
+#define _DYNHASHENTTYPE(name) \
+ typedef struct name##_ent \
+ { \
+ HASHTYPE hashval; \
+ TYPE data; \
+ NEXT (name) \
+ } name##_ent
+#define DYNHASHENTTYPE(name) _DYNHASHENTTYPE (name)
+DYNHASHENTTYPE (NAME);
+
+
+/* Type of the dynamic hash table data structure. */
+#define _DYNHASHTYPE(name) \
+typedef struct \
+{ \
+ size_t size; \
+ size_t filled; \
+ name##_ent *table; \
+ FIRST (name) \
+} name
+#define DYNHASHTYPE(name) _DYNHASHTYPE (name)
+DYNHASHTYPE (NAME);
+
+
+
+#define _FUNCTIONS(name) \
+/* Initialize the hash table. */ \
+extern int name##_init (name *htab, size_t init_size); \
+ \
+/* Free resources allocated for hash table. */ \
+extern int name##_free (name *htab); \
+ \
+/* Insert new entry. */ \
+extern int name##_insert (name *htab, HASHTYPE hval, TYPE data); \
+ \
+/* Insert new entry, possibly overwrite old entry. */ \
+extern int name##_overwrite (name *htab, HASHTYPE hval, TYPE data); \
+ \
+/* Find entry in hash table. */ \
+extern TYPE name##_find (name *htab, HASHTYPE hval, TYPE val);
+#define FUNCTIONS(name) _FUNCTIONS (name)
+FUNCTIONS (NAME)
+
+
+#ifdef ITERATE
+# define _XFUNCTIONS(name) \
+/* Get next element in table. */ \
+extern TYPE name##_iterate (name *htab, void **ptr);
+# define XFUNCTIONS(name) _XFUNCTIONS (name)
+XFUNCTIONS (NAME)
+#endif
+
+#ifndef NO_UNDEF
+# undef DYNHASHENTTYPE
+# undef DYNHASHTYPE
+# undef FUNCTIONS
+# undef _FUNCTIONS
+# undef XFUNCTIONS
+# undef _XFUNCTIONS
+# undef NAME
+# undef TYPE
+# undef ITERATE
+# undef COMPARE
+# undef FIRST
+# undef NEXT
+#endif
diff --git a/contrib/libdw/dynamicsizehash_concurrent.h b/contrib/libdw/dynamicsizehash_concurrent.h
new file mode 100644
index 0000000..73e66e9
--- /dev/null
+++ b/contrib/libdw/dynamicsizehash_concurrent.h
@@ -0,0 +1,118 @@
+/* Copyright (C) 2000-2019 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Srdan Milakovic , 2019.
+ Derived from Ulrich Drepper , 2000.
+
+ 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 . */
+
+#include
+#include
+#include "atomics.h"
+/* Before including this file the following macros must be defined:
+
+ NAME name of the hash table structure.
+ TYPE data type of the hash table entries
+
+ The following macros if present select features:
+
+ ITERATE iterating over the table entries is possible
+ HASHTYPE integer type for hash values, default unsigned long int
+ */
+
+
+
+#ifndef HASHTYPE
+# define HASHTYPE unsigned long int
+#endif
+
+#ifndef RESIZE_BLOCK_SIZE
+# define RESIZE_BLOCK_SIZE 256
+#endif
+
+/* Defined separately. */
+extern size_t next_prime (size_t seed);
+
+
+/* Table entry type. */
+#define _DYNHASHCONENTTYPE(name) \
+ typedef struct name##_ent \
+ { \
+ _Atomic(HASHTYPE) hashval; \
+ atomic_uintptr_t val_ptr; \
+ } name##_ent
+#define DYNHASHENTTYPE(name) _DYNHASHCONENTTYPE (name)
+DYNHASHENTTYPE (NAME);
+
+/* Type of the dynamic hash table data structure. */
+#define _DYNHASHCONTYPE(name) \
+typedef struct \
+{ \
+ size_t size; \
+ size_t old_size; \
+ atomic_size_t filled; \
+ name##_ent *table; \
+ name##_ent *old_table; \
+ atomic_size_t resizing_state; \
+ atomic_size_t next_init_block; \
+ atomic_size_t num_initialized_blocks; \
+ atomic_size_t next_move_block; \
+ atomic_size_t num_moved_blocks; \
+ pthread_rwlock_t resize_rwl; \
+} name
+#define DYNHASHTYPE(name) _DYNHASHCONTYPE (name)
+DYNHASHTYPE (NAME);
+
+
+
+#define _FUNCTIONS(name) \
+/* Initialize the hash table. */ \
+extern int name##_init (name *htab, size_t init_size); \
+ \
+/* Free resources allocated for hash table. */ \
+extern int name##_free (name *htab); \
+ \
+/* Insert new entry. */ \
+extern int name##_insert (name *htab, HASHTYPE hval, TYPE data); \
+ \
+/* Find entry in hash table. */ \
+extern TYPE name##_find (name *htab, HASHTYPE hval);
+#define FUNCTIONS(name) _FUNCTIONS (name)
+FUNCTIONS (NAME)
+
+
+#ifndef NO_UNDEF
+# undef DYNHASHENTTYPE
+# undef DYNHASHTYPE
+# undef FUNCTIONS
+# undef _FUNCTIONS
+# undef XFUNCTIONS
+# undef _XFUNCTIONS
+# undef NAME
+# undef TYPE
+# undef ITERATE
+# undef COMPARE
+# undef FIRST
+# undef NEXT
+#endif
diff --git a/contrib/libdw/elf-knowledge.h b/contrib/libdw/elf-knowledge.h
new file mode 100644
index 0000000..6e005fa
--- /dev/null
+++ b/contrib/libdw/elf-knowledge.h
@@ -0,0 +1,101 @@
+/* Accumulation of various pieces of knowledge about ELF.
+ Copyright (C) 2000-2012, 2014, 2016 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2000.
+
+ 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 . */
+
+#ifndef _ELF_KNOWLEDGE_H
+#define _ELF_KNOWLEDGE_H 1
+
+#include
+
+
+/* Test whether a section can be stripped or not. */
+#define SECTION_STRIP_P(shdr, name, remove_comment) \
+ /* Sections which are allocated are not removed. */ \
+ (((shdr)->sh_flags & SHF_ALLOC) == 0 \
+ /* We never remove .note sections. */ \
+ && (shdr)->sh_type != SHT_NOTE \
+ && (((shdr)->sh_type) != SHT_PROGBITS \
+ /* Never remove .gnu.warning.* sections. */ \
+ || (name != NULL \
+ && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
+ /* We remove .comment sections only if explicitly told to do so. */\
+ && (remove_comment \
+ || strcmp (name, ".comment") != 0))))
+
+
+/* Test whether `sh_info' field in section header contains a section
+ index. There are two kinds of sections doing this:
+
+ - the sections containing relocation information reference in this
+ field the section to which the relocations apply;
+
+ - section with the SHF_INFO_LINK flag set to signal that `sh_info'
+ references a section. This allows correct handling of unknown
+ sections. */
+#define SH_INFO_LINK_P(Shdr) \
+ ((Shdr)->sh_type == SHT_REL || (Shdr)->sh_type == SHT_RELA \
+ || ((Shdr)->sh_flags & SHF_INFO_LINK) != 0)
+
+
+/* Size of an entry in the hash table. The ELF specification says all
+ entries are regardless of platform 32-bits in size. Early 64-bit
+ ports (namely Alpha for Linux) got this wrong. The wording was not
+ clear.
+
+ Several years later the ABI for the 64-bit S390s was developed.
+ Many things were copied from the IA-64 ABI (which uses the correct
+ 32-bit entry size) but it does get the SHT_HASH entry size wrong by
+ using a 64-bit entry size. So now we need this macro to special
+ case both the alpha and s390x ABIs. */
+#define SH_ENTSIZE_HASH(Ehdr) \
+ ((Ehdr)->e_machine == EM_ALPHA \
+ || ((Ehdr)->e_machine == EM_S390 \
+ && (Ehdr)->e_ident[EI_CLASS] == ELFCLASS64) ? 8 : 4)
+
+/* GNU Annobin notes are not fully standardized and abuses the owner name. */
+
+#define ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX "GA"
+
+#define NT_GNU_BUILD_ATTRIBUTE_OPEN 0x100
+#define NT_GNU_BUILD_ATTRIBUTE_FUNC 0x101
+
+#define GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC '*'
+#define GNU_BUILD_ATTRIBUTE_TYPE_STRING '$'
+#define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE '+'
+#define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE '!'
+
+#define GNU_BUILD_ATTRIBUTE_VERSION 1
+#define GNU_BUILD_ATTRIBUTE_STACK_PROT 2
+#define GNU_BUILD_ATTRIBUTE_RELRO 3
+#define GNU_BUILD_ATTRIBUTE_STACK_SIZE 4
+#define GNU_BUILD_ATTRIBUTE_TOOL 5
+#define GNU_BUILD_ATTRIBUTE_ABI 6
+#define GNU_BUILD_ATTRIBUTE_PIC 7
+#define GNU_BUILD_ATTRIBUTE_SHORT_ENUM 8
+
+#endif /* elf-knowledge.h */
diff --git a/contrib/libdw/elf.h b/contrib/libdw/elf.h
new file mode 100644
index 0000000..f2206e5
--- /dev/null
+++ b/contrib/libdw/elf.h
@@ -0,0 +1,4477 @@
+/* This file defines standard ELF types, structures, and macros.
+ Copyright (C) 1995-2024 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ . */
+
+#ifndef _ELF_H
+#define _ELF_H 1
+
+/* Standard ELF types. */
+
+#include
+
+/* Type for a 16-bit quantity. */
+typedef uint16_t Elf32_Half;
+typedef uint16_t Elf64_Half;
+
+/* Types for signed and unsigned 32-bit quantities. */
+typedef uint32_t Elf32_Word;
+typedef int32_t Elf32_Sword;
+typedef uint32_t Elf64_Word;
+typedef int32_t Elf64_Sword;
+
+/* Types for signed and unsigned 64-bit quantities. */
+typedef uint64_t Elf32_Xword;
+typedef int64_t Elf32_Sxword;
+typedef uint64_t Elf64_Xword;
+typedef int64_t Elf64_Sxword;
+
+/* Type of addresses. */
+typedef uint32_t Elf32_Addr;
+typedef uint64_t Elf64_Addr;
+
+/* Type of file offsets. */
+typedef uint32_t Elf32_Off;
+typedef uint64_t Elf64_Off;
+
+/* Type for section indices, which are 16-bit quantities. */
+typedef uint16_t Elf32_Section;
+typedef uint16_t Elf64_Section;
+
+/* Type for version symbol information. */
+typedef Elf32_Half Elf32_Versym;
+typedef Elf64_Half Elf64_Versym;
+
+
+/* The ELF file header. This appears at the start of every ELF file. */
+
+#define EI_NIDENT (16)
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+ Elf32_Half e_type; /* Object file type */
+ Elf32_Half e_machine; /* Architecture */
+ Elf32_Word e_version; /* Object file version */
+ Elf32_Addr e_entry; /* Entry point virtual address */
+ Elf32_Off e_phoff; /* Program header table file offset */
+ Elf32_Off e_shoff; /* Section header table file offset */
+ Elf32_Word e_flags; /* Processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size in bytes */
+ Elf32_Half e_phentsize; /* Program header table entry size */
+ Elf32_Half e_phnum; /* Program header table entry count */
+ Elf32_Half e_shentsize; /* Section header table entry size */
+ Elf32_Half e_shnum; /* Section header table entry count */
+ Elf32_Half e_shstrndx; /* Section header string table index */
+} Elf32_Ehdr;
+
+typedef struct
+{
+ unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */
+ Elf64_Half e_type; /* Object file type */
+ Elf64_Half e_machine; /* Architecture */
+ Elf64_Word e_version; /* Object file version */
+ Elf64_Addr e_entry; /* Entry point virtual address */
+ Elf64_Off e_phoff; /* Program header table file offset */
+ Elf64_Off e_shoff; /* Section header table file offset */
+ Elf64_Word e_flags; /* Processor-specific flags */
+ Elf64_Half e_ehsize; /* ELF header size in bytes */
+ Elf64_Half e_phentsize; /* Program header table entry size */
+ Elf64_Half e_phnum; /* Program header table entry count */
+ Elf64_Half e_shentsize; /* Section header table entry size */
+ Elf64_Half e_shnum; /* Section header table entry count */
+ Elf64_Half e_shstrndx; /* Section header string table index */
+} Elf64_Ehdr;
+
+/* Fields in the e_ident array. The EI_* macros are indices into the
+ array. The macros under each EI_* macro are the values the byte
+ may have. */
+
+#define EI_MAG0 0 /* File identification byte 0 index */
+#define ELFMAG0 0x7f /* Magic number byte 0 */
+
+#define EI_MAG1 1 /* File identification byte 1 index */
+#define ELFMAG1 'E' /* Magic number byte 1 */
+
+#define EI_MAG2 2 /* File identification byte 2 index */
+#define ELFMAG2 'L' /* Magic number byte 2 */
+
+#define EI_MAG3 3 /* File identification byte 3 index */
+#define ELFMAG3 'F' /* Magic number byte 3 */
+
+/* Conglomeration of the identification bytes, for easy testing as a word. */
+#define ELFMAG "\177ELF"
+#define SELFMAG 4
+
+#define EI_CLASS 4 /* File class byte index */
+#define ELFCLASSNONE 0 /* Invalid class */
+#define ELFCLASS32 1 /* 32-bit objects */
+#define ELFCLASS64 2 /* 64-bit objects */
+#define ELFCLASSNUM 3
+
+#define EI_DATA 5 /* Data encoding byte index */
+#define ELFDATANONE 0 /* Invalid data encoding */
+#define ELFDATA2LSB 1 /* 2's complement, little endian */
+#define ELFDATA2MSB 2 /* 2's complement, big endian */
+#define ELFDATANUM 3
+
+#define EI_VERSION 6 /* File version byte index */
+ /* Value must be EV_CURRENT */
+
+#define EI_OSABI 7 /* OS ABI identification */
+#define ELFOSABI_NONE 0 /* UNIX System V ABI */
+#define ELFOSABI_SYSV 0 /* Alias. */
+#define ELFOSABI_HPUX 1 /* HP-UX */
+#define ELFOSABI_NETBSD 2 /* NetBSD. */
+#define ELFOSABI_GNU 3 /* Object uses GNU ELF extensions. */
+#define ELFOSABI_LINUX ELFOSABI_GNU /* Compatibility alias. */
+#define ELFOSABI_SOLARIS 6 /* Sun Solaris. */
+#define ELFOSABI_AIX 7 /* IBM AIX. */
+#define ELFOSABI_IRIX 8 /* SGI Irix. */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD. */
+#define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */
+#define ELFOSABI_MODESTO 11 /* Novell Modesto. */
+#define ELFOSABI_OPENBSD 12 /* OpenBSD. */
+#define ELFOSABI_ARM_AEABI 64 /* ARM EABI */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+#define EI_ABIVERSION 8 /* ABI version */
+
+#define EI_PAD 9 /* Byte index of padding bytes */
+
+/* Legal values for e_type (object file type). */
+
+#define ET_NONE 0 /* No file type */
+#define ET_REL 1 /* Relocatable file */
+#define ET_EXEC 2 /* Executable file */
+#define ET_DYN 3 /* Shared object file */
+#define ET_CORE 4 /* Core file */
+#define ET_NUM 5 /* Number of defined types */
+#define ET_LOOS 0xfe00 /* OS-specific range start */
+#define ET_HIOS 0xfeff /* OS-specific range end */
+#define ET_LOPROC 0xff00 /* Processor-specific range start */
+#define ET_HIPROC 0xffff /* Processor-specific range end */
+
+/* Legal values for e_machine (architecture). */
+
+#define EM_NONE 0 /* No machine */
+#define EM_M32 1 /* AT&T WE 32100 */
+#define EM_SPARC 2 /* SUN SPARC */
+#define EM_386 3 /* Intel 80386 */
+#define EM_68K 4 /* Motorola m68k family */
+#define EM_88K 5 /* Motorola m88k family */
+#define EM_IAMCU 6 /* Intel MCU */
+#define EM_860 7 /* Intel 80860 */
+#define EM_MIPS 8 /* MIPS R3000 big-endian */
+#define EM_S370 9 /* IBM System/370 */
+#define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */
+ /* reserved 11-14 */
+#define EM_PARISC 15 /* HPPA */
+ /* reserved 16 */
+#define EM_VPP500 17 /* Fujitsu VPP500 */
+#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
+#define EM_960 19 /* Intel 80960 */
+#define EM_PPC 20 /* PowerPC */
+#define EM_PPC64 21 /* PowerPC 64-bit */
+#define EM_S390 22 /* IBM S390 */
+#define EM_SPU 23 /* IBM SPU/SPC */
+ /* reserved 24-35 */
+#define EM_V800 36 /* NEC V800 series */
+#define EM_FR20 37 /* Fujitsu FR20 */
+#define EM_RH32 38 /* TRW RH-32 */
+#define EM_RCE 39 /* Motorola RCE */
+#define EM_ARM 40 /* ARM */
+#define EM_FAKE_ALPHA 41 /* Digital Alpha */
+#define EM_SH 42 /* Hitachi SH */
+#define EM_SPARCV9 43 /* SPARC v9 64-bit */
+#define EM_TRICORE 44 /* Siemens Tricore */
+#define EM_ARC 45 /* Argonaut RISC Core */
+#define EM_H8_300 46 /* Hitachi H8/300 */
+#define EM_H8_300H 47 /* Hitachi H8/300H */
+#define EM_H8S 48 /* Hitachi H8S */
+#define EM_H8_500 49 /* Hitachi H8/500 */
+#define EM_IA_64 50 /* Intel Merced */
+#define EM_MIPS_X 51 /* Stanford MIPS-X */
+#define EM_COLDFIRE 52 /* Motorola Coldfire */
+#define EM_68HC12 53 /* Motorola M68HC12 */
+#define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator */
+#define EM_PCP 55 /* Siemens PCP */
+#define EM_NCPU 56 /* Sony nCPU embedded RISC */
+#define EM_NDR1 57 /* Denso NDR1 microprocessor */
+#define EM_STARCORE 58 /* Motorola Start*Core processor */
+#define EM_ME16 59 /* Toyota ME16 processor */
+#define EM_ST100 60 /* STMicroelectronic ST100 processor */
+#define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam */
+#define EM_X86_64 62 /* AMD x86-64 architecture */
+#define EM_PDSP 63 /* Sony DSP Processor */
+#define EM_PDP10 64 /* Digital PDP-10 */
+#define EM_PDP11 65 /* Digital PDP-11 */
+#define EM_FX66 66 /* Siemens FX66 microcontroller */
+#define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */
+#define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */
+#define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */
+#define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */
+#define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */
+#define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */
+#define EM_SVX 73 /* Silicon Graphics SVx */
+#define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */
+#define EM_VAX 75 /* Digital VAX */
+#define EM_CRIS 76 /* Axis Communications 32-bit emb.proc */
+#define EM_JAVELIN 77 /* Infineon Technologies 32-bit emb.proc */
+#define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */
+#define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */
+#define EM_MMIX 80 /* Donald Knuth's educational 64-bit proc */
+#define EM_HUANY 81 /* Harvard University machine-independent object files */
+#define EM_PRISM 82 /* SiTera Prism */
+#define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */
+#define EM_FR30 84 /* Fujitsu FR30 */
+#define EM_D10V 85 /* Mitsubishi D10V */
+#define EM_D30V 86 /* Mitsubishi D30V */
+#define EM_V850 87 /* NEC v850 */
+#define EM_M32R 88 /* Mitsubishi M32R */
+#define EM_MN10300 89 /* Matsushita MN10300 */
+#define EM_MN10200 90 /* Matsushita MN10200 */
+#define EM_PJ 91 /* picoJava */
+#define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */
+#define EM_ARC_COMPACT 93 /* ARC International ARCompact */
+#define EM_XTENSA 94 /* Tensilica Xtensa Architecture */
+#define EM_VIDEOCORE 95 /* Alphamosaic VideoCore */
+#define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Proc */
+#define EM_NS32K 97 /* National Semi. 32000 */
+#define EM_TPC 98 /* Tenor Network TPC */
+#define EM_SNP1K 99 /* Trebia SNP 1000 */
+#define EM_ST200 100 /* STMicroelectronics ST200 */
+#define EM_IP2K 101 /* Ubicom IP2xxx */
+#define EM_MAX 102 /* MAX processor */
+#define EM_CR 103 /* National Semi. CompactRISC */
+#define EM_F2MC16 104 /* Fujitsu F2MC16 */
+#define EM_MSP430 105 /* Texas Instruments msp430 */
+#define EM_BLACKFIN 106 /* Analog Devices Blackfin DSP */
+#define EM_SE_C33 107 /* Seiko Epson S1C33 family */
+#define EM_SEP 108 /* Sharp embedded microprocessor */
+#define EM_ARCA 109 /* Arca RISC */
+#define EM_UNICORE 110 /* PKU-Unity & MPRC Peking Uni. mc series */
+#define EM_EXCESS 111 /* eXcess configurable cpu */
+#define EM_DXP 112 /* Icera Semi. Deep Execution Processor */
+#define EM_ALTERA_NIOS2 113 /* Altera Nios II */
+#define EM_CRX 114 /* National Semi. CompactRISC CRX */
+#define EM_XGATE 115 /* Motorola XGATE */
+#define EM_C166 116 /* Infineon C16x/XC16x */
+#define EM_M16C 117 /* Renesas M16C */
+#define EM_DSPIC30F 118 /* Microchip Technology dsPIC30F */
+#define EM_CE 119 /* Freescale Communication Engine RISC */
+#define EM_M32C 120 /* Renesas M32C */
+ /* reserved 121-130 */
+#define EM_TSK3000 131 /* Altium TSK3000 */
+#define EM_RS08 132 /* Freescale RS08 */
+#define EM_SHARC 133 /* Analog Devices SHARC family */
+#define EM_ECOG2 134 /* Cyan Technology eCOG2 */
+#define EM_SCORE7 135 /* Sunplus S+core7 RISC */
+#define EM_DSP24 136 /* New Japan Radio (NJR) 24-bit DSP */
+#define EM_VIDEOCORE3 137 /* Broadcom VideoCore III */
+#define EM_LATTICEMICO32 138 /* RISC for Lattice FPGA */
+#define EM_SE_C17 139 /* Seiko Epson C17 */
+#define EM_TI_C6000 140 /* Texas Instruments TMS320C6000 DSP */
+#define EM_TI_C2000 141 /* Texas Instruments TMS320C2000 DSP */
+#define EM_TI_C5500 142 /* Texas Instruments TMS320C55x DSP */
+#define EM_TI_ARP32 143 /* Texas Instruments App. Specific RISC */
+#define EM_TI_PRU 144 /* Texas Instruments Prog. Realtime Unit */
+ /* reserved 145-159 */
+#define EM_MMDSP_PLUS 160 /* STMicroelectronics 64bit VLIW DSP */
+#define EM_CYPRESS_M8C 161 /* Cypress M8C */
+#define EM_R32C 162 /* Renesas R32C */
+#define EM_TRIMEDIA 163 /* NXP Semi. TriMedia */
+#define EM_QDSP6 164 /* QUALCOMM DSP6 */
+#define EM_8051 165 /* Intel 8051 and variants */
+#define EM_STXP7X 166 /* STMicroelectronics STxP7x */
+#define EM_NDS32 167 /* Andes Tech. compact code emb. RISC */
+#define EM_ECOG1X 168 /* Cyan Technology eCOG1X */
+#define EM_MAXQ30 169 /* Dallas Semi. MAXQ30 mc */
+#define EM_XIMO16 170 /* New Japan Radio (NJR) 16-bit DSP */
+#define EM_MANIK 171 /* M2000 Reconfigurable RISC */
+#define EM_CRAYNV2 172 /* Cray NV2 vector architecture */
+#define EM_RX 173 /* Renesas RX */
+#define EM_METAG 174 /* Imagination Tech. META */
+#define EM_MCST_ELBRUS 175 /* MCST Elbrus */
+#define EM_ECOG16 176 /* Cyan Technology eCOG16 */
+#define EM_CR16 177 /* National Semi. CompactRISC CR16 */
+#define EM_ETPU 178 /* Freescale Extended Time Processing Unit */
+#define EM_SLE9X 179 /* Infineon Tech. SLE9X */
+#define EM_L10M 180 /* Intel L10M */
+#define EM_K10M 181 /* Intel K10M */
+ /* reserved 182 */
+#define EM_AARCH64 183 /* ARM AARCH64 */
+ /* reserved 184 */
+#define EM_AVR32 185 /* Amtel 32-bit microprocessor */
+#define EM_STM8 186 /* STMicroelectronics STM8 */
+#define EM_TILE64 187 /* Tilera TILE64 */
+#define EM_TILEPRO 188 /* Tilera TILEPro */
+#define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */
+#define EM_CUDA 190 /* NVIDIA CUDA */
+#define EM_TILEGX 191 /* Tilera TILE-Gx */
+#define EM_CLOUDSHIELD 192 /* CloudShield */
+#define EM_COREA_1ST 193 /* KIPO-KAIST Core-A 1st gen. */
+#define EM_COREA_2ND 194 /* KIPO-KAIST Core-A 2nd gen. */
+#define EM_ARCV2 195 /* Synopsys ARCv2 ISA. */
+#define EM_OPEN8 196 /* Open8 RISC */
+#define EM_RL78 197 /* Renesas RL78 */
+#define EM_VIDEOCORE5 198 /* Broadcom VideoCore V */
+#define EM_78KOR 199 /* Renesas 78KOR */
+#define EM_56800EX 200 /* Freescale 56800EX DSC */
+#define EM_BA1 201 /* Beyond BA1 */
+#define EM_BA2 202 /* Beyond BA2 */
+#define EM_XCORE 203 /* XMOS xCORE */
+#define EM_MCHP_PIC 204 /* Microchip 8-bit PIC(r) */
+#define EM_INTELGT 205 /* Intel Graphics Technology */
+ /* reserved 206-209 */
+#define EM_KM32 210 /* KM211 KM32 */
+#define EM_KMX32 211 /* KM211 KMX32 */
+#define EM_EMX16 212 /* KM211 KMX16 */
+#define EM_EMX8 213 /* KM211 KMX8 */
+#define EM_KVARC 214 /* KM211 KVARC */
+#define EM_CDP 215 /* Paneve CDP */
+#define EM_COGE 216 /* Cognitive Smart Memory Processor */
+#define EM_COOL 217 /* Bluechip CoolEngine */
+#define EM_NORC 218 /* Nanoradio Optimized RISC */
+#define EM_CSR_KALIMBA 219 /* CSR Kalimba */
+#define EM_Z80 220 /* Zilog Z80 */
+#define EM_VISIUM 221 /* Controls and Data Services VISIUMcore */
+#define EM_FT32 222 /* FTDI Chip FT32 */
+#define EM_MOXIE 223 /* Moxie processor */
+#define EM_AMDGPU 224 /* AMD GPU */
+ /* reserved 225-242 */
+#define EM_RISCV 243 /* RISC-V */
+
+#define EM_BPF 247 /* Linux BPF -- in-kernel virtual machine */
+#define EM_CSKY 252 /* C-SKY */
+#define EM_LOONGARCH 258 /* LoongArch */
+
+#define EM_NUM 259
+
+/* Old spellings/synonyms. */
+
+#define EM_ARC_A5 EM_ARC_COMPACT
+
+/* If it is necessary to assign new unofficial EM_* values, please
+ pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the
+ chances of collision with official or non-GNU unofficial values. */
+
+#define EM_ALPHA 0x9026
+
+/* Legal values for e_version (version). */
+
+#define EV_NONE 0 /* Invalid ELF version */
+#define EV_CURRENT 1 /* Current version */
+#define EV_NUM 2
+
+/* Section header. */
+
+typedef struct
+{
+ Elf32_Word sh_name; /* Section name (string tbl index) */
+ Elf32_Word sh_type; /* Section type */
+ Elf32_Word sh_flags; /* Section flags */
+ Elf32_Addr sh_addr; /* Section virtual addr at execution */
+ Elf32_Off sh_offset; /* Section file offset */
+ Elf32_Word sh_size; /* Section size in bytes */
+ Elf32_Word sh_link; /* Link to another section */
+ Elf32_Word sh_info; /* Additional section information */
+ Elf32_Word sh_addralign; /* Section alignment */
+ Elf32_Word sh_entsize; /* Entry size if section holds table */
+} Elf32_Shdr;
+
+typedef struct
+{
+ Elf64_Word sh_name; /* Section name (string tbl index) */
+ Elf64_Word sh_type; /* Section type */
+ Elf64_Xword sh_flags; /* Section flags */
+ Elf64_Addr sh_addr; /* Section virtual addr at execution */
+ Elf64_Off sh_offset; /* Section file offset */
+ Elf64_Xword sh_size; /* Section size in bytes */
+ Elf64_Word sh_link; /* Link to another section */
+ Elf64_Word sh_info; /* Additional section information */
+ Elf64_Xword sh_addralign; /* Section alignment */
+ Elf64_Xword sh_entsize; /* Entry size if section holds table */
+} Elf64_Shdr;
+
+/* Special section indices. */
+
+#define SHN_UNDEF 0 /* Undefined section */
+#define SHN_LORESERVE 0xff00 /* Start of reserved indices */
+#define SHN_LOPROC 0xff00 /* Start of processor-specific */
+#define SHN_BEFORE 0xff00 /* Order section before all others
+ (Solaris). */
+#define SHN_AFTER 0xff01 /* Order section after all others
+ (Solaris). */
+#define SHN_HIPROC 0xff1f /* End of processor-specific */
+#define SHN_LOOS 0xff20 /* Start of OS-specific */
+#define SHN_HIOS 0xff3f /* End of OS-specific */
+#define SHN_ABS 0xfff1 /* Associated symbol is absolute */
+#define SHN_COMMON 0xfff2 /* Associated symbol is common */
+#define SHN_XINDEX 0xffff /* Index is in extra table. */
+#define SHN_HIRESERVE 0xffff /* End of reserved indices */
+
+/* Legal values for sh_type (section type). */
+
+#define SHT_NULL 0 /* Section header table entry unused */
+#define SHT_PROGBITS 1 /* Program data */
+#define SHT_SYMTAB 2 /* Symbol table */
+#define SHT_STRTAB 3 /* String table */
+#define SHT_RELA 4 /* Relocation entries with addends */
+#define SHT_HASH 5 /* Symbol hash table */
+#define SHT_DYNAMIC 6 /* Dynamic linking information */
+#define SHT_NOTE 7 /* Notes */
+#define SHT_NOBITS 8 /* Program space with no data (bss) */
+#define SHT_REL 9 /* Relocation entries, no addends */
+#define SHT_SHLIB 10 /* Reserved */
+#define SHT_DYNSYM 11 /* Dynamic linker symbol table */
+#define SHT_INIT_ARRAY 14 /* Array of constructors */
+#define SHT_FINI_ARRAY 15 /* Array of destructors */
+#define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */
+#define SHT_GROUP 17 /* Section group */
+#define SHT_SYMTAB_SHNDX 18 /* Extended section indices */
+#define SHT_RELR 19 /* RELR relative relocations */
+#define SHT_NUM 20 /* Number of defined types. */
+#define SHT_LOOS 0x60000000 /* Start OS-specific. */
+#define SHT_GNU_ATTRIBUTES 0x6ffffff5 /* Object attributes. */
+#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table. */
+#define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */
+#define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */
+#define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */
+#define SHT_SUNW_move 0x6ffffffa
+#define SHT_SUNW_COMDAT 0x6ffffffb
+#define SHT_SUNW_syminfo 0x6ffffffc
+#define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */
+#define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */
+#define SHT_GNU_versym 0x6fffffff /* Version symbol table. */
+#define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */
+#define SHT_HIOS 0x6fffffff /* End OS-specific type */
+#define SHT_LOPROC 0x70000000 /* Start of processor-specific */
+#define SHT_HIPROC 0x7fffffff /* End of processor-specific */
+#define SHT_LOUSER 0x80000000 /* Start of application-specific */
+#define SHT_HIUSER 0x8fffffff /* End of application-specific */
+
+/* Legal values for sh_flags (section flags). */
+
+#define SHF_WRITE (1 << 0) /* Writable */
+#define SHF_ALLOC (1 << 1) /* Occupies memory during execution */
+#define SHF_EXECINSTR (1 << 2) /* Executable */
+#define SHF_MERGE (1 << 4) /* Might be merged */
+#define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */
+#define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */
+#define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */
+#define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling
+ required */
+#define SHF_GROUP (1 << 9) /* Section is member of a group. */
+#define SHF_TLS (1 << 10) /* Section hold thread-local data. */
+#define SHF_COMPRESSED (1 << 11) /* Section with compressed data. */
+#define SHF_MASKOS 0x0ff00000 /* OS-specific. */
+#define SHF_MASKPROC 0xf0000000 /* Processor-specific */
+#define SHF_GNU_RETAIN (1 << 21) /* Not to be GCed by linker. */
+#define SHF_ORDERED (1 << 30) /* Special ordering requirement
+ (Solaris). */
+#define SHF_EXCLUDE (1U << 31) /* Section is excluded unless
+ referenced or allocated (Solaris).*/
+
+/* Section compression header. Used when SHF_COMPRESSED is set. */
+
+typedef struct
+{
+ Elf32_Word ch_type; /* Compression format. */
+ Elf32_Word ch_size; /* Uncompressed data size. */
+ Elf32_Word ch_addralign; /* Uncompressed data alignment. */
+} Elf32_Chdr;
+
+typedef struct
+{
+ Elf64_Word ch_type; /* Compression format. */
+ Elf64_Word ch_reserved;
+ Elf64_Xword ch_size; /* Uncompressed data size. */
+ Elf64_Xword ch_addralign; /* Uncompressed data alignment. */
+} Elf64_Chdr;
+
+/* Legal values for ch_type (compression algorithm). */
+#define ELFCOMPRESS_ZLIB 1 /* ZLIB/DEFLATE algorithm. */
+#define ELFCOMPRESS_ZSTD 2 /* Zstandard algorithm. */
+#define ELFCOMPRESS_LOOS 0x60000000 /* Start of OS-specific. */
+#define ELFCOMPRESS_HIOS 0x6fffffff /* End of OS-specific. */
+#define ELFCOMPRESS_LOPROC 0x70000000 /* Start of processor-specific. */
+#define ELFCOMPRESS_HIPROC 0x7fffffff /* End of processor-specific. */
+
+/* Section group handling. */
+#define GRP_COMDAT 0x1 /* Mark group as COMDAT. */
+
+/* Symbol table entry. */
+
+typedef struct
+{
+ Elf32_Word st_name; /* Symbol name (string tbl index) */
+ Elf32_Addr st_value; /* Symbol value */
+ Elf32_Word st_size; /* Symbol size */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf32_Section st_shndx; /* Section index */
+} Elf32_Sym;
+
+typedef struct
+{
+ Elf64_Word st_name; /* Symbol name (string tbl index) */
+ unsigned char st_info; /* Symbol type and binding */
+ unsigned char st_other; /* Symbol visibility */
+ Elf64_Section st_shndx; /* Section index */
+ Elf64_Addr st_value; /* Symbol value */
+ Elf64_Xword st_size; /* Symbol size */
+} Elf64_Sym;
+
+/* The syminfo section if available contains additional information about
+ every dynamic symbol. */
+
+typedef struct
+{
+ Elf32_Half si_boundto; /* Direct bindings, symbol bound to */
+ Elf32_Half si_flags; /* Per symbol flags */
+} Elf32_Syminfo;
+
+typedef struct
+{
+ Elf64_Half si_boundto; /* Direct bindings, symbol bound to */
+ Elf64_Half si_flags; /* Per symbol flags */
+} Elf64_Syminfo;
+
+/* Possible values for si_boundto. */
+#define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */
+#define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */
+#define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */
+
+/* Possible bitmasks for si_flags. */
+#define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */
+#define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-through symbol for translator */
+#define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */
+#define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy
+ loaded */
+/* Syminfo version values. */
+#define SYMINFO_NONE 0
+#define SYMINFO_CURRENT 1
+#define SYMINFO_NUM 2
+
+
+/* How to extract and insert information held in the st_info field. */
+
+#define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
+#define ELF32_ST_TYPE(val) ((val) & 0xf)
+#define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
+
+/* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */
+#define ELF64_ST_BIND(val) ELF32_ST_BIND (val)
+#define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val)
+#define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type))
+
+/* Legal values for ST_BIND subfield of st_info (symbol binding). */
+
+#define STB_LOCAL 0 /* Local symbol */
+#define STB_GLOBAL 1 /* Global symbol */
+#define STB_WEAK 2 /* Weak symbol */
+#define STB_NUM 3 /* Number of defined types. */
+#define STB_LOOS 10 /* Start of OS-specific */
+#define STB_GNU_UNIQUE 10 /* Unique symbol. */
+#define STB_HIOS 12 /* End of OS-specific */
+#define STB_LOPROC 13 /* Start of processor-specific */
+#define STB_HIPROC 15 /* End of processor-specific */
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_NOTYPE 0 /* Symbol type is unspecified */
+#define STT_OBJECT 1 /* Symbol is a data object */
+#define STT_FUNC 2 /* Symbol is a code object */
+#define STT_SECTION 3 /* Symbol associated with a section */
+#define STT_FILE 4 /* Symbol's name is file name */
+#define STT_COMMON 5 /* Symbol is a common data object */
+#define STT_TLS 6 /* Symbol is thread-local data object*/
+#define STT_NUM 7 /* Number of defined types. */
+#define STT_LOOS 10 /* Start of OS-specific */
+#define STT_GNU_IFUNC 10 /* Symbol is indirect code object */
+#define STT_HIOS 12 /* End of OS-specific */
+#define STT_LOPROC 13 /* Start of processor-specific */
+#define STT_HIPROC 15 /* End of processor-specific */
+
+
+/* Symbol table indices are found in the hash buckets and chain table
+ of a symbol hash table section. This special index value indicates
+ the end of a chain, meaning no further symbols are found in that bucket. */
+
+#define STN_UNDEF 0 /* End of a chain. */
+
+
+/* How to extract and insert information held in the st_other field. */
+
+#define ELF32_ST_VISIBILITY(o) ((o) & 0x03)
+
+/* For ELF64 the definitions are the same. */
+#define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o)
+
+/* Symbol visibility specification encoded in the st_other field. */
+#define STV_DEFAULT 0 /* Default symbol visibility rules */
+#define STV_INTERNAL 1 /* Processor specific hidden class */
+#define STV_HIDDEN 2 /* Sym unavailable in other modules */
+#define STV_PROTECTED 3 /* Not preemptible, not exported */
+
+
+/* Relocation table entry without addend (in section of type SHT_REL). */
+
+typedef struct
+{
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
+} Elf32_Rel;
+
+/* I have seen two different definitions of the Elf64_Rel and
+ Elf64_Rela structures, so we'll leave them out until Novell (or
+ whoever) gets their act together. */
+/* The following, at least, is used on Sparc v9, MIPS, and Alpha. */
+
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+} Elf64_Rel;
+
+/* Relocation table entry with addend (in section of type SHT_RELA). */
+
+typedef struct
+{
+ Elf32_Addr r_offset; /* Address */
+ Elf32_Word r_info; /* Relocation type and symbol index */
+ Elf32_Sword r_addend; /* Addend */
+} Elf32_Rela;
+
+typedef struct
+{
+ Elf64_Addr r_offset; /* Address */
+ Elf64_Xword r_info; /* Relocation type and symbol index */
+ Elf64_Sxword r_addend; /* Addend */
+} Elf64_Rela;
+
+/* RELR relocation table entry */
+
+typedef Elf32_Word Elf32_Relr;
+typedef Elf64_Xword Elf64_Relr;
+
+/* How to extract and insert information held in the r_info field. */
+
+#define ELF32_R_SYM(val) ((val) >> 8)
+#define ELF32_R_TYPE(val) ((val) & 0xff)
+#define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
+
+#define ELF64_R_SYM(i) ((i) >> 32)
+#define ELF64_R_TYPE(i) ((i) & 0xffffffff)
+#define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type))
+
+/* Program segment header. */
+
+typedef struct
+{
+ Elf32_Word p_type; /* Segment type */
+ Elf32_Off p_offset; /* Segment file offset */
+ Elf32_Addr p_vaddr; /* Segment virtual address */
+ Elf32_Addr p_paddr; /* Segment physical address */
+ Elf32_Word p_filesz; /* Segment size in file */
+ Elf32_Word p_memsz; /* Segment size in memory */
+ Elf32_Word p_flags; /* Segment flags */
+ Elf32_Word p_align; /* Segment alignment */
+} Elf32_Phdr;
+
+typedef struct
+{
+ Elf64_Word p_type; /* Segment type */
+ Elf64_Word p_flags; /* Segment flags */
+ Elf64_Off p_offset; /* Segment file offset */
+ Elf64_Addr p_vaddr; /* Segment virtual address */
+ Elf64_Addr p_paddr; /* Segment physical address */
+ Elf64_Xword p_filesz; /* Segment size in file */
+ Elf64_Xword p_memsz; /* Segment size in memory */
+ Elf64_Xword p_align; /* Segment alignment */
+} Elf64_Phdr;
+
+/* Special value for e_phnum. This indicates that the real number of
+ program headers is too large to fit into e_phnum. Instead the real
+ value is in the field sh_info of section 0. */
+
+#define PN_XNUM 0xffff
+
+/* Legal values for p_type (segment type). */
+
+#define PT_NULL 0 /* Program header table entry unused */
+#define PT_LOAD 1 /* Loadable program segment */
+#define PT_DYNAMIC 2 /* Dynamic linking information */
+#define PT_INTERP 3 /* Program interpreter */
+#define PT_NOTE 4 /* Auxiliary information */
+#define PT_SHLIB 5 /* Reserved */
+#define PT_PHDR 6 /* Entry for header table itself */
+#define PT_TLS 7 /* Thread-local storage segment */
+#define PT_NUM 8 /* Number of defined types */
+#define PT_LOOS 0x60000000 /* Start of OS-specific */
+#define PT_GNU_EH_FRAME 0x6474e550 /* GCC .eh_frame_hdr segment */
+#define PT_GNU_STACK 0x6474e551 /* Indicates stack executability */
+#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
+#define PT_GNU_PROPERTY 0x6474e553 /* GNU property */
+#define PT_GNU_SFRAME 0x6474e554 /* SFrame segment. */
+#define PT_LOSUNW 0x6ffffffa
+#define PT_SUNWBSS 0x6ffffffa /* Sun Specific segment */
+#define PT_SUNWSTACK 0x6ffffffb /* Stack segment */
+#define PT_HISUNW 0x6fffffff
+#define PT_HIOS 0x6fffffff /* End of OS-specific */
+#define PT_LOPROC 0x70000000 /* Start of processor-specific */
+#define PT_HIPROC 0x7fffffff /* End of processor-specific */
+
+/* Legal values for p_flags (segment flags). */
+
+#define PF_X (1 << 0) /* Segment is executable */
+#define PF_W (1 << 1) /* Segment is writable */
+#define PF_R (1 << 2) /* Segment is readable */
+#define PF_MASKOS 0x0ff00000 /* OS-specific */
+#define PF_MASKPROC 0xf0000000 /* Processor-specific */
+
+/* Legal values for note segment descriptor types for core files. */
+
+#define NT_PRSTATUS 1 /* Contains copy of prstatus struct */
+#define NT_PRFPREG 2 /* Contains copy of fpregset
+ struct. */
+#define NT_FPREGSET 2 /* Contains copy of fpregset struct */
+#define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
+#define NT_PRXREG 4 /* Contains copy of prxregset struct */
+#define NT_TASKSTRUCT 4 /* Contains copy of task structure */
+#define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */
+#define NT_AUXV 6 /* Contains copy of auxv array */
+#define NT_GWINDOWS 7 /* Contains copy of gwindows struct */
+#define NT_ASRS 8 /* Contains copy of asrset struct */
+#define NT_PSTATUS 10 /* Contains copy of pstatus struct */
+#define NT_PSINFO 13 /* Contains copy of psinfo struct */
+#define NT_PRCRED 14 /* Contains copy of prcred struct */
+#define NT_UTSNAME 15 /* Contains copy of utsname struct */
+#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */
+#define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */
+#define NT_PRFPXREG 20 /* Contains copy of fprxregset struct */
+#define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t,
+ size might increase */
+#define NT_FILE 0x46494c45 /* Contains information about mapped
+ files */
+#define NT_PRXFPREG 0x46e62b7f /* Contains copy of user_fxsr_struct */
+#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
+#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
+#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
+#define NT_PPC_TAR 0x103 /* Target Address Register */
+#define NT_PPC_PPR 0x104 /* Program Priority Register */
+#define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
+#define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
+#define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
+#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
+#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
+#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
+#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
+#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
+#define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address
+ Register */
+#define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority
+ Register */
+#define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control
+ Register */
+#define NT_PPC_PKEY 0x110 /* Memory Protection Keys
+ registers. */
+#define NT_PPC_DEXCR 0x111 /* PowerPC DEXCR registers. */
+#define NT_PPC_HASHKEYR 0x112 /* PowerPC HASHKEYR register. */
+#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
+#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
+#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
+#define NT_X86_SHSTK 0x204 /* x86 SHSTK state */
+#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
+#define NT_S390_TIMER 0x301 /* s390 timer register */
+#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
+#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
+#define NT_S390_CTRS 0x304 /* s390 control registers */
+#define NT_S390_PREFIX 0x305 /* s390 prefix register */
+#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
+#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
+#define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
+#define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15
+ upper half. */
+#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31. */
+#define NT_S390_GS_CB 0x30b /* s390 guarded storage registers. */
+#define NT_S390_GS_BC 0x30c /* s390 guarded storage
+ broadcast control block. */
+#define NT_S390_RI_CB 0x30d /* s390 runtime instrumentation. */
+#define NT_S390_PV_CPU_DATA 0x30e /* s390 protvirt cpu dump data. */
+#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
+#define NT_ARM_TLS 0x401 /* ARM TLS register */
+#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
+#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
+#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
+#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
+ registers */
+#define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication
+ code masks. */
+#define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication
+ address keys. */
+#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication
+ generic key. */
+#define NT_ARM_TAGGED_ADDR_CTRL 0x409 /* AArch64 tagged address
+ control. */
+#define NT_ARM_PAC_ENABLED_KEYS 0x40a /* AArch64 pointer authentication
+ enabled keys. */
+#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
+#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers. */
+#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode. */
+#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers. */
+#define NT_RISCV_CSR 0x900 /* RISC-V Control and Status Registers */
+#define NT_RISCV_VECTOR 0x901 /* RISC-V vector registers */
+#define NT_LOONGARCH_CPUCFG 0xa00 /* LoongArch CPU config registers. */
+#define NT_LOONGARCH_CSR 0xa01 /* LoongArch control and
+ status registers. */
+#define NT_LOONGARCH_LSX 0xa02 /* LoongArch Loongson SIMD
+ Extension registers. */
+#define NT_LOONGARCH_LASX 0xa03 /* LoongArch Loongson Advanced
+ SIMD Extension registers. */
+#define NT_LOONGARCH_LBT 0xa04 /* LoongArch Loongson Binary
+ Translation registers. */
+#define NT_LOONGARCH_HW_BREAK 0xa05 /* LoongArch hardware breakpoint registers */
+#define NT_LOONGARCH_HW_WATCH 0xa06 /* LoongArch hardware watchpoint registers */
+
+/* Legal values for the note segment descriptor types for object files. */
+
+#define NT_VERSION 1 /* Contains a version string. */
+
+
+/* Dynamic section entry. */
+
+typedef struct
+{
+ Elf32_Sword d_tag; /* Dynamic entry type */
+ union
+ {
+ Elf32_Word d_val; /* Integer value */
+ Elf32_Addr d_ptr; /* Address value */
+ } d_un;
+} Elf32_Dyn;
+
+typedef struct
+{
+ Elf64_Sxword d_tag; /* Dynamic entry type */
+ union
+ {
+ Elf64_Xword d_val; /* Integer value */
+ Elf64_Addr d_ptr; /* Address value */
+ } d_un;
+} Elf64_Dyn;
+
+/* Legal values for d_tag (dynamic entry type). */
+
+#define DT_NULL 0 /* Marks end of dynamic section */
+#define DT_NEEDED 1 /* Name of needed library */
+#define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */
+#define DT_PLTGOT 3 /* Processor defined value */
+#define DT_HASH 4 /* Address of symbol hash table */
+#define DT_STRTAB 5 /* Address of string table */
+#define DT_SYMTAB 6 /* Address of symbol table */
+#define DT_RELA 7 /* Address of Rela relocs */
+#define DT_RELASZ 8 /* Total size of Rela relocs */
+#define DT_RELAENT 9 /* Size of one Rela reloc */
+#define DT_STRSZ 10 /* Size of string table */
+#define DT_SYMENT 11 /* Size of one symbol table entry */
+#define DT_INIT 12 /* Address of init function */
+#define DT_FINI 13 /* Address of termination function */
+#define DT_SONAME 14 /* Name of shared object */
+#define DT_RPATH 15 /* Library search path (deprecated) */
+#define DT_SYMBOLIC 16 /* Start symbol search here */
+#define DT_REL 17 /* Address of Rel relocs */
+#define DT_RELSZ 18 /* Total size of Rel relocs */
+#define DT_RELENT 19 /* Size of one Rel reloc */
+#define DT_PLTREL 20 /* Type of reloc in PLT */
+#define DT_DEBUG 21 /* For debugging; unspecified */
+#define DT_TEXTREL 22 /* Reloc might modify .text */
+#define DT_JMPREL 23 /* Address of PLT relocs */
+#define DT_BIND_NOW 24 /* Process relocations of object */
+#define DT_INIT_ARRAY 25 /* Array with addresses of init fct */
+#define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */
+#define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */
+#define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */
+#define DT_RUNPATH 29 /* Library search path */
+#define DT_FLAGS 30 /* Flags for the object being loaded */
+#define DT_ENCODING 32 /* Start of encoded range */
+#define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/
+#define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */
+#define DT_SYMTAB_SHNDX 34 /* Address of SYMTAB_SHNDX section */
+#define DT_RELRSZ 35 /* Total size of RELR relative relocations */
+#define DT_RELR 36 /* Address of RELR relative relocations */
+#define DT_RELRENT 37 /* Size of one RELR relative relocaction */
+#define DT_NUM 38 /* Number used */
+#define DT_LOOS 0x6000000d /* Start of OS-specific */
+#define DT_HIOS 0x6ffff000 /* End of OS-specific */
+#define DT_LOPROC 0x70000000 /* Start of processor-specific */
+#define DT_HIPROC 0x7fffffff /* End of processor-specific */
+#define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */
+
+/* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the
+ Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's
+ approach. */
+#define DT_VALRNGLO 0x6ffffd00
+#define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */
+#define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */
+#define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */
+#define DT_CHECKSUM 0x6ffffdf8
+#define DT_PLTPADSZ 0x6ffffdf9
+#define DT_MOVEENT 0x6ffffdfa
+#define DT_MOVESZ 0x6ffffdfb
+#define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */
+#define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting
+ the following DT_* entry. */
+#define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */
+#define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */
+#define DT_VALRNGHI 0x6ffffdff
+#define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */
+#define DT_VALNUM 12
+
+/* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the
+ Dyn.d_un.d_ptr field of the Elf*_Dyn structure.
+
+ If any adjustment is made to the ELF object after it has been
+ built these entries will need to be adjusted. */
+#define DT_ADDRRNGLO 0x6ffffe00
+#define DT_GNU_HASH 0x6ffffef5 /* GNU-style hash table. */
+#define DT_TLSDESC_PLT 0x6ffffef6
+#define DT_TLSDESC_GOT 0x6ffffef7
+#define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */
+#define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */
+#define DT_CONFIG 0x6ffffefa /* Configuration information. */
+#define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */
+#define DT_AUDIT 0x6ffffefc /* Object auditing. */
+#define DT_PLTPAD 0x6ffffefd /* PLT padding. */
+#define DT_MOVETAB 0x6ffffefe /* Move table. */
+#define DT_SYMINFO 0x6ffffeff /* Syminfo table. */
+#define DT_ADDRRNGHI 0x6ffffeff
+#define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */
+#define DT_ADDRNUM 11
+
+/* The versioning entry types. The next are defined as part of the
+ GNU extension. */
+#define DT_VERSYM 0x6ffffff0
+
+#define DT_RELACOUNT 0x6ffffff9
+#define DT_RELCOUNT 0x6ffffffa
+
+/* These were chosen by Sun. */
+#define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */
+#define DT_VERDEF 0x6ffffffc /* Address of version definition
+ table */
+#define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */
+#define DT_VERNEED 0x6ffffffe /* Address of table with needed
+ versions */
+#define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */
+#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
+#define DT_VERSIONTAGNUM 16
+
+/* Sun added these machine-independent extensions in the "processor-specific"
+ range. Be compatible. */
+#define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */
+#define DT_FILTER 0x7fffffff /* Shared object to get values from */
+#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
+#define DT_EXTRANUM 3
+
+/* Values of `d_un.d_val' in the DT_FLAGS entry. */
+#define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */
+#define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */
+#define DF_TEXTREL 0x00000004 /* Object contains text relocations */
+#define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */
+#define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */
+
+/* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1
+ entry in the dynamic section. */
+#define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */
+#define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */
+#define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */
+#define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/
+#define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/
+#define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/
+#define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */
+#define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */
+#define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */
+#define DF_1_TRANS 0x00000200
+#define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */
+#define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */
+#define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */
+#define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/
+#define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */
+#define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */
+#define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */
+#define DF_1_NODIRECT 0x00020000 /* Object has no-direct binding. */
+#define DF_1_IGNMULDEF 0x00040000
+#define DF_1_NOKSYMS 0x00080000
+#define DF_1_NOHDR 0x00100000
+#define DF_1_EDITED 0x00200000 /* Object is modified after built. */
+#define DF_1_NORELOC 0x00400000
+#define DF_1_SYMINTPOSE 0x00800000 /* Object has individual interposers. */
+#define DF_1_GLOBAUDIT 0x01000000 /* Global auditing required. */
+#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */
+#define DF_1_STUB 0x04000000
+#define DF_1_PIE 0x08000000
+#define DF_1_KMOD 0x10000000
+#define DF_1_WEAKFILTER 0x20000000
+#define DF_1_NOCOMMON 0x40000000
+
+/* Flags for the feature selection in DT_FEATURE_1. */
+#define DTF_1_PARINIT 0x00000001
+#define DTF_1_CONFEXP 0x00000002
+
+/* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */
+#define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */
+#define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not
+ generally available. */
+
+/* Version definition sections. */
+
+typedef struct
+{
+ Elf32_Half vd_version; /* Version revision */
+ Elf32_Half vd_flags; /* Version information */
+ Elf32_Half vd_ndx; /* Version Index */
+ Elf32_Half vd_cnt; /* Number of associated aux entries */
+ Elf32_Word vd_hash; /* Version name hash value */
+ Elf32_Word vd_aux; /* Offset in bytes to verdaux array */
+ Elf32_Word vd_next; /* Offset in bytes to next verdef
+ entry */
+} Elf32_Verdef;
+
+typedef struct
+{
+ Elf64_Half vd_version; /* Version revision */
+ Elf64_Half vd_flags; /* Version information */
+ Elf64_Half vd_ndx; /* Version Index */
+ Elf64_Half vd_cnt; /* Number of associated aux entries */
+ Elf64_Word vd_hash; /* Version name hash value */
+ Elf64_Word vd_aux; /* Offset in bytes to verdaux array */
+ Elf64_Word vd_next; /* Offset in bytes to next verdef
+ entry */
+} Elf64_Verdef;
+
+
+/* Legal values for vd_version (version revision). */
+#define VER_DEF_NONE 0 /* No version */
+#define VER_DEF_CURRENT 1 /* Current version */
+#define VER_DEF_NUM 2 /* Given version number */
+
+/* Legal values for vd_flags (version information flags). */
+#define VER_FLG_BASE 0x1 /* Version definition of file itself */
+#define VER_FLG_WEAK 0x2 /* Weak version identifier. Also
+ used by vna_flags below. */
+
+/* Versym symbol index values. */
+#define VER_NDX_LOCAL 0 /* Symbol is local. */
+#define VER_NDX_GLOBAL 1 /* Symbol is global. */
+#define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */
+#define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */
+
+/* Auxiliary version information. */
+
+typedef struct
+{
+ Elf32_Word vda_name; /* Version or dependency names */
+ Elf32_Word vda_next; /* Offset in bytes to next verdaux
+ entry */
+} Elf32_Verdaux;
+
+typedef struct
+{
+ Elf64_Word vda_name; /* Version or dependency names */
+ Elf64_Word vda_next; /* Offset in bytes to next verdaux
+ entry */
+} Elf64_Verdaux;
+
+
+/* Version dependency section. */
+
+typedef struct
+{
+ Elf32_Half vn_version; /* Version of structure */
+ Elf32_Half vn_cnt; /* Number of associated aux entries */
+ Elf32_Word vn_file; /* Offset of filename for this
+ dependency */
+ Elf32_Word vn_aux; /* Offset in bytes to vernaux array */
+ Elf32_Word vn_next; /* Offset in bytes to next verneed
+ entry */
+} Elf32_Verneed;
+
+typedef struct
+{
+ Elf64_Half vn_version; /* Version of structure */
+ Elf64_Half vn_cnt; /* Number of associated aux entries */
+ Elf64_Word vn_file; /* Offset of filename for this
+ dependency */
+ Elf64_Word vn_aux; /* Offset in bytes to vernaux array */
+ Elf64_Word vn_next; /* Offset in bytes to next verneed
+ entry */
+} Elf64_Verneed;
+
+
+/* Legal values for vn_version (version revision). */
+#define VER_NEED_NONE 0 /* No version */
+#define VER_NEED_CURRENT 1 /* Current version */
+#define VER_NEED_NUM 2 /* Given version number */
+
+/* Auxiliary needed version information. */
+
+typedef struct
+{
+ Elf32_Word vna_hash; /* Hash value of dependency name */
+ Elf32_Half vna_flags; /* Dependency specific information */
+ Elf32_Half vna_other; /* Unused */
+ Elf32_Word vna_name; /* Dependency name string offset */
+ Elf32_Word vna_next; /* Offset in bytes to next vernaux
+ entry */
+} Elf32_Vernaux;
+
+typedef struct
+{
+ Elf64_Word vna_hash; /* Hash value of dependency name */
+ Elf64_Half vna_flags; /* Dependency specific information */
+ Elf64_Half vna_other; /* Unused */
+ Elf64_Word vna_name; /* Dependency name string offset */
+ Elf64_Word vna_next; /* Offset in bytes to next vernaux
+ entry */
+} Elf64_Vernaux;
+
+
+/* Auxiliary vector. */
+
+/* This vector is normally only used by the program interpreter. The
+ usual definition in an ABI supplement uses the name auxv_t. The
+ vector is not usually defined in a standard file, but it
+ can't hurt. We rename it to avoid conflicts. The sizes of these
+ types are an arrangement between the exec server and the program
+ interpreter, so we don't fully specify them here. */
+
+typedef struct
+{
+ uint32_t a_type; /* Entry type */
+ union
+ {
+ uint32_t a_val; /* Integer value */
+ /* We use to have pointer elements added here. We cannot do that,
+ though, since it does not work when using 32-bit definitions
+ on 64-bit platforms and vice versa. */
+ } a_un;
+} Elf32_auxv_t;
+
+typedef struct
+{
+ uint64_t a_type; /* Entry type */
+ union
+ {
+ uint64_t a_val; /* Integer value */
+ /* We use to have pointer elements added here. We cannot do that,
+ though, since it does not work when using 32-bit definitions
+ on 64-bit platforms and vice versa. */
+ } a_un;
+} Elf64_auxv_t;
+
+/* Legal values for a_type (entry type). */
+
+#define AT_NULL 0 /* End of vector */
+#define AT_IGNORE 1 /* Entry should be ignored */
+#define AT_EXECFD 2 /* File descriptor of program */
+#define AT_PHDR 3 /* Program headers for program */
+#define AT_PHENT 4 /* Size of program header entry */
+#define AT_PHNUM 5 /* Number of program headers */
+#define AT_PAGESZ 6 /* System page size */
+#define AT_BASE 7 /* Base address of interpreter */
+#define AT_FLAGS 8 /* Flags */
+#define AT_ENTRY 9 /* Entry point of program */
+#define AT_NOTELF 10 /* Program is not ELF */
+#define AT_UID 11 /* Real uid */
+#define AT_EUID 12 /* Effective uid */
+#define AT_GID 13 /* Real gid */
+#define AT_EGID 14 /* Effective gid */
+#define AT_CLKTCK 17 /* Frequency of times() */
+
+/* Some more special a_type values describing the hardware. */
+#define AT_PLATFORM 15 /* String identifying platform. */
+#define AT_HWCAP 16 /* Machine-dependent hints about
+ processor capabilities. */
+
+/* This entry gives some information about the FPU initialization
+ performed by the kernel. */
+#define AT_FPUCW 18 /* Used FPU control word. */
+
+/* Cache block sizes. */
+#define AT_DCACHEBSIZE 19 /* Data cache block size. */
+#define AT_ICACHEBSIZE 20 /* Instruction cache block size. */
+#define AT_UCACHEBSIZE 21 /* Unified cache block size. */
+
+/* A special ignored value for PPC, used by the kernel to control the
+ interpretation of the AUXV. Must be > 16. */
+#define AT_IGNOREPPC 22 /* Entry should be ignored. */
+
+#define AT_SECURE 23 /* Boolean, was exec setuid-like? */
+
+#define AT_BASE_PLATFORM 24 /* String identifying real platforms.*/
+
+#define AT_RANDOM 25 /* Address of 16 random bytes. */
+
+#define AT_HWCAP2 26 /* More machine-dependent hints about
+ processor capabilities. */
+
+#define AT_RSEQ_FEATURE_SIZE 27 /* rseq supported feature size. */
+#define AT_RSEQ_ALIGN 28 /* rseq allocation alignment. */
+
+#define AT_EXECFN 31 /* Filename of executable. */
+
+/* Pointer to the global system page used for system calls and other
+ nice things. */
+#define AT_SYSINFO 32
+#define AT_SYSINFO_EHDR 33
+
+/* Shapes of the caches. Bits 0-3 contains associativity; bits 4-7 contains
+ log2 of line size; mask those to get cache size. */
+#define AT_L1I_CACHESHAPE 34
+#define AT_L1D_CACHESHAPE 35
+#define AT_L2_CACHESHAPE 36
+#define AT_L3_CACHESHAPE 37
+
+/* Shapes of the caches, with more room to describe them.
+ *GEOMETRY are comprised of cache line size in bytes in the bottom 16 bits
+ and the cache associativity in the next 16 bits. */
+#define AT_L1I_CACHESIZE 40
+#define AT_L1I_CACHEGEOMETRY 41
+#define AT_L1D_CACHESIZE 42
+#define AT_L1D_CACHEGEOMETRY 43
+#define AT_L2_CACHESIZE 44
+#define AT_L2_CACHEGEOMETRY 45
+#define AT_L3_CACHESIZE 46
+#define AT_L3_CACHEGEOMETRY 47
+
+#define AT_MINSIGSTKSZ 51 /* Stack needed for signal delivery */
+
+/* Note section contents. Each entry in the note section begins with
+ a header of a fixed form. */
+
+typedef struct
+{
+ Elf32_Word n_namesz; /* Length of the note's name. */
+ Elf32_Word n_descsz; /* Length of the note's descriptor. */
+ Elf32_Word n_type; /* Type of the note. */
+} Elf32_Nhdr;
+
+typedef struct
+{
+ Elf64_Word n_namesz; /* Length of the note's name. */
+ Elf64_Word n_descsz; /* Length of the note's descriptor. */
+ Elf64_Word n_type; /* Type of the note. */
+} Elf64_Nhdr;
+
+/* Known names of notes. */
+
+/* Solaris entries in the note section have this name. */
+#define ELF_NOTE_SOLARIS "SUNW Solaris"
+
+/* Note entries for GNU systems have this name. */
+#define ELF_NOTE_GNU "GNU"
+
+/* Note entries for freedesktop.org have this name. */
+#define ELF_NOTE_FDO "FDO"
+
+/* Defined types of notes for Solaris. */
+
+/* Value of descriptor (one word) is desired pagesize for the binary. */
+#define ELF_NOTE_PAGESIZE_HINT 1
+
+
+/* Defined note types for GNU systems. */
+
+/* ABI information. The descriptor consists of words:
+ word 0: OS descriptor
+ word 1: major version of the ABI
+ word 2: minor version of the ABI
+ word 3: subminor version of the ABI
+*/
+#define NT_GNU_ABI_TAG 1
+#define ELF_NOTE_ABI NT_GNU_ABI_TAG /* Old name. */
+
+/* Known OSes. These values can appear in word 0 of an
+ NT_GNU_ABI_TAG note section entry. */
+#define ELF_NOTE_OS_LINUX 0
+#define ELF_NOTE_OS_GNU 1
+#define ELF_NOTE_OS_SOLARIS2 2
+#define ELF_NOTE_OS_FREEBSD 3
+
+/* Synthetic hwcap information. The descriptor begins with two words:
+ word 0: number of entries
+ word 1: bitmask of enabled entries
+ Then follow variable-length entries, one byte followed by a
+ '\0'-terminated hwcap name string. The byte gives the bit
+ number to test if enabled, (1U << bit) & bitmask. */
+#define NT_GNU_HWCAP 2
+
+/* Build ID bits as generated by ld --build-id.
+ The descriptor consists of any nonzero number of bytes. */
+#define NT_GNU_BUILD_ID 3
+
+/* Version note generated by GNU gold containing a version string. */
+#define NT_GNU_GOLD_VERSION 4
+
+/* Program property. */
+#define NT_GNU_PROPERTY_TYPE_0 5
+
+/* Packaging metadata as defined on
+ https://systemd.io/COREDUMP_PACKAGE_METADATA/ */
+#define NT_FDO_PACKAGING_METADATA 0xcafe1a7e
+
+/* Note section name of program property. */
+#define NOTE_GNU_PROPERTY_SECTION_NAME ".note.gnu.property"
+
+/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */
+
+/* Stack size. */
+#define GNU_PROPERTY_STACK_SIZE 1
+/* No copy relocation on protected data symbol. */
+#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2
+
+/* A 4-byte unsigned integer property: A bit is set if it is set in all
+ relocatable inputs. */
+#define GNU_PROPERTY_UINT32_AND_LO 0xb0000000
+#define GNU_PROPERTY_UINT32_AND_HI 0xb0007fff
+
+/* A 4-byte unsigned integer property: A bit is set if it is set in any
+ relocatable inputs. */
+#define GNU_PROPERTY_UINT32_OR_LO 0xb0008000
+#define GNU_PROPERTY_UINT32_OR_HI 0xb000ffff
+
+/* The needed properties by the object file. */
+#define GNU_PROPERTY_1_NEEDED GNU_PROPERTY_UINT32_OR_LO
+
+/* Set if the object file requires canonical function pointers and
+ cannot be used with copy relocation. */
+#define GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS (1U << 0)
+
+/* Processor-specific semantics, lo */
+#define GNU_PROPERTY_LOPROC 0xc0000000
+/* Processor-specific semantics, hi */
+#define GNU_PROPERTY_HIPROC 0xdfffffff
+/* Application-specific semantics, lo */
+#define GNU_PROPERTY_LOUSER 0xe0000000
+/* Application-specific semantics, hi */
+#define GNU_PROPERTY_HIUSER 0xffffffff
+
+/* AArch64 specific GNU properties. */
+#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000
+
+#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1U << 0)
+#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1U << 1)
+
+/* The x86 instruction sets indicated by the corresponding bits are
+ used in program. Their support in the hardware is optional. */
+#define GNU_PROPERTY_X86_ISA_1_USED 0xc0010002
+/* The x86 instruction sets indicated by the corresponding bits are
+ used in program and they must be supported by the hardware. */
+#define GNU_PROPERTY_X86_ISA_1_NEEDED 0xc0008002
+/* X86 processor-specific features used in program. */
+#define GNU_PROPERTY_X86_FEATURE_1_AND 0xc0000002
+
+/* GNU_PROPERTY_X86_ISA_1_BASELINE: CMOV, CX8 (cmpxchg8b), FPU (fld),
+ MMX, OSFXSR (fxsave), SCE (syscall), SSE and SSE2. */
+#define GNU_PROPERTY_X86_ISA_1_BASELINE (1U << 0)
+/* GNU_PROPERTY_X86_ISA_1_V2: GNU_PROPERTY_X86_ISA_1_BASELINE,
+ CMPXCHG16B (cmpxchg16b), LAHF-SAHF (lahf), POPCNT (popcnt), SSE3,
+ SSSE3, SSE4.1 and SSE4.2. */
+#define GNU_PROPERTY_X86_ISA_1_V2 (1U << 1)
+/* GNU_PROPERTY_X86_ISA_1_V3: GNU_PROPERTY_X86_ISA_1_V2, AVX, AVX2, BMI1,
+ BMI2, F16C, FMA, LZCNT, MOVBE, XSAVE. */
+#define GNU_PROPERTY_X86_ISA_1_V3 (1U << 2)
+/* GNU_PROPERTY_X86_ISA_1_V4: GNU_PROPERTY_X86_ISA_1_V3, AVX512F,
+ AVX512BW, AVX512CD, AVX512DQ and AVX512VL. */
+#define GNU_PROPERTY_X86_ISA_1_V4 (1U << 3)
+
+/* This indicates that all executable sections are compatible with
+ IBT. */
+#define GNU_PROPERTY_X86_FEATURE_1_IBT (1U << 0)
+/* This indicates that all executable sections are compatible with
+ SHSTK. */
+#define GNU_PROPERTY_X86_FEATURE_1_SHSTK (1U << 1)
+
+/* Move records. */
+typedef struct
+{
+ Elf32_Xword m_value; /* Symbol value. */
+ Elf32_Word m_info; /* Size and index. */
+ Elf32_Word m_poffset; /* Symbol offset. */
+ Elf32_Half m_repeat; /* Repeat count. */
+ Elf32_Half m_stride; /* Stride info. */
+} Elf32_Move;
+
+typedef struct
+{
+ Elf64_Xword m_value; /* Symbol value. */
+ Elf64_Xword m_info; /* Size and index. */
+ Elf64_Xword m_poffset; /* Symbol offset. */
+ Elf64_Half m_repeat; /* Repeat count. */
+ Elf64_Half m_stride; /* Stride info. */
+} Elf64_Move;
+
+/* Macro to construct move records. */
+#define ELF32_M_SYM(info) ((info) >> 8)
+#define ELF32_M_SIZE(info) ((unsigned char) (info))
+#define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size))
+
+#define ELF64_M_SYM(info) ELF32_M_SYM (info)
+#define ELF64_M_SIZE(info) ELF32_M_SIZE (info)
+#define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size)
+
+
+/* Motorola 68k specific definitions. */
+
+/* Values for Elf32_Ehdr.e_flags. */
+#define EF_CPU32 0x00810000
+
+/* m68k relocs. */
+
+#define R_68K_NONE 0 /* No reloc */
+#define R_68K_32 1 /* Direct 32 bit */
+#define R_68K_16 2 /* Direct 16 bit */
+#define R_68K_8 3 /* Direct 8 bit */
+#define R_68K_PC32 4 /* PC relative 32 bit */
+#define R_68K_PC16 5 /* PC relative 16 bit */
+#define R_68K_PC8 6 /* PC relative 8 bit */
+#define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */
+#define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */
+#define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */
+#define R_68K_GOT32O 10 /* 32 bit GOT offset */
+#define R_68K_GOT16O 11 /* 16 bit GOT offset */
+#define R_68K_GOT8O 12 /* 8 bit GOT offset */
+#define R_68K_PLT32 13 /* 32 bit PC relative PLT address */
+#define R_68K_PLT16 14 /* 16 bit PC relative PLT address */
+#define R_68K_PLT8 15 /* 8 bit PC relative PLT address */
+#define R_68K_PLT32O 16 /* 32 bit PLT offset */
+#define R_68K_PLT16O 17 /* 16 bit PLT offset */
+#define R_68K_PLT8O 18 /* 8 bit PLT offset */
+#define R_68K_COPY 19 /* Copy symbol at runtime */
+#define R_68K_GLOB_DAT 20 /* Create GOT entry */
+#define R_68K_JMP_SLOT 21 /* Create PLT entry */
+#define R_68K_RELATIVE 22 /* Adjust by program base */
+#define R_68K_TLS_GD32 25 /* 32 bit GOT offset for GD */
+#define R_68K_TLS_GD16 26 /* 16 bit GOT offset for GD */
+#define R_68K_TLS_GD8 27 /* 8 bit GOT offset for GD */
+#define R_68K_TLS_LDM32 28 /* 32 bit GOT offset for LDM */
+#define R_68K_TLS_LDM16 29 /* 16 bit GOT offset for LDM */
+#define R_68K_TLS_LDM8 30 /* 8 bit GOT offset for LDM */
+#define R_68K_TLS_LDO32 31 /* 32 bit module-relative offset */
+#define R_68K_TLS_LDO16 32 /* 16 bit module-relative offset */
+#define R_68K_TLS_LDO8 33 /* 8 bit module-relative offset */
+#define R_68K_TLS_IE32 34 /* 32 bit GOT offset for IE */
+#define R_68K_TLS_IE16 35 /* 16 bit GOT offset for IE */
+#define R_68K_TLS_IE8 36 /* 8 bit GOT offset for IE */
+#define R_68K_TLS_LE32 37 /* 32 bit offset relative to
+ static TLS block */
+#define R_68K_TLS_LE16 38 /* 16 bit offset relative to
+ static TLS block */
+#define R_68K_TLS_LE8 39 /* 8 bit offset relative to
+ static TLS block */
+#define R_68K_TLS_DTPMOD32 40 /* 32 bit module number */
+#define R_68K_TLS_DTPREL32 41 /* 32 bit module-relative offset */
+#define R_68K_TLS_TPREL32 42 /* 32 bit TP-relative offset */
+/* Keep this the last entry. */
+#define R_68K_NUM 43
+
+/* Intel 80386 specific definitions. */
+
+/* i386 relocs. */
+
+#define R_386_NONE 0 /* No reloc */
+#define R_386_32 1 /* Direct 32 bit */
+#define R_386_PC32 2 /* PC relative 32 bit */
+#define R_386_GOT32 3 /* 32 bit GOT entry */
+#define R_386_PLT32 4 /* 32 bit PLT address */
+#define R_386_COPY 5 /* Copy symbol at runtime */
+#define R_386_GLOB_DAT 6 /* Create GOT entry */
+#define R_386_JMP_SLOT 7 /* Create PLT entry */
+#define R_386_RELATIVE 8 /* Adjust by program base */
+#define R_386_GOTOFF 9 /* 32 bit offset to GOT */
+#define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */
+#define R_386_32PLT 11
+#define R_386_TLS_TPOFF 14 /* Offset in static TLS block */
+#define R_386_TLS_IE 15 /* Address of GOT entry for static TLS
+ block offset */
+#define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block
+ offset */
+#define R_386_TLS_LE 17 /* Offset relative to static TLS
+ block */
+#define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of
+ general dynamic thread local data */
+#define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of
+ local dynamic thread local data
+ in LE code */
+#define R_386_16 20
+#define R_386_PC16 21
+#define R_386_8 22
+#define R_386_PC8 23
+#define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic
+ thread local data */
+#define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */
+#define R_386_TLS_GD_CALL 26 /* Relocation for call to
+ __tls_get_addr() */
+#define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */
+#define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic
+ thread local data in LE code */
+#define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */
+#define R_386_TLS_LDM_CALL 30 /* Relocation for call to
+ __tls_get_addr() in LDM code */
+#define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */
+#define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */
+#define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS
+ block offset */
+#define R_386_TLS_LE_32 34 /* Negated offset relative to static
+ TLS block */
+#define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */
+#define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */
+#define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */
+#define R_386_SIZE32 38 /* 32-bit symbol size */
+#define R_386_TLS_GOTDESC 39 /* GOT offset for TLS descriptor. */
+#define R_386_TLS_DESC_CALL 40 /* Marker of call through TLS
+ descriptor for
+ relaxation. */
+#define R_386_TLS_DESC 41 /* TLS descriptor containing
+ pointer to code and to
+ argument, returning the TLS
+ offset for the symbol. */
+#define R_386_IRELATIVE 42 /* Adjust indirectly by program base */
+#define R_386_GOT32X 43 /* Load from 32 bit GOT entry,
+ relaxable. */
+/* Keep this the last entry. */
+#define R_386_NUM 44
+
+/* SUN SPARC specific definitions. */
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_SPARC_REGISTER 13 /* Global register reserved to app. */
+
+/* Values for Elf64_Ehdr.e_flags. */
+
+#define EF_SPARCV9_MM 3
+#define EF_SPARCV9_TSO 0
+#define EF_SPARCV9_PSO 1
+#define EF_SPARCV9_RMO 2
+#define EF_SPARC_LEDATA 0x800000 /* little endian data */
+#define EF_SPARC_EXT_MASK 0xFFFF00
+#define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */
+#define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */
+#define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */
+#define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */
+
+/* SPARC relocs. */
+
+#define R_SPARC_NONE 0 /* No reloc */
+#define R_SPARC_8 1 /* Direct 8 bit */
+#define R_SPARC_16 2 /* Direct 16 bit */
+#define R_SPARC_32 3 /* Direct 32 bit */
+#define R_SPARC_DISP8 4 /* PC relative 8 bit */
+#define R_SPARC_DISP16 5 /* PC relative 16 bit */
+#define R_SPARC_DISP32 6 /* PC relative 32 bit */
+#define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */
+#define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */
+#define R_SPARC_HI22 9 /* High 22 bit */
+#define R_SPARC_22 10 /* Direct 22 bit */
+#define R_SPARC_13 11 /* Direct 13 bit */
+#define R_SPARC_LO10 12 /* Truncated 10 bit */
+#define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */
+#define R_SPARC_GOT13 14 /* 13 bit GOT entry */
+#define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */
+#define R_SPARC_PC10 16 /* PC relative 10 bit truncated */
+#define R_SPARC_PC22 17 /* PC relative 22 bit shifted */
+#define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */
+#define R_SPARC_COPY 19 /* Copy symbol at runtime */
+#define R_SPARC_GLOB_DAT 20 /* Create GOT entry */
+#define R_SPARC_JMP_SLOT 21 /* Create PLT entry */
+#define R_SPARC_RELATIVE 22 /* Adjust by program base */
+#define R_SPARC_UA32 23 /* Direct 32 bit unaligned */
+
+/* Additional Sparc64 relocs. */
+
+#define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */
+#define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */
+#define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */
+#define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */
+#define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */
+#define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */
+#define R_SPARC_10 30 /* Direct 10 bit */
+#define R_SPARC_11 31 /* Direct 11 bit */
+#define R_SPARC_64 32 /* Direct 64 bit */
+#define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */
+#define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */
+#define R_SPARC_HM10 35 /* High middle 10 bits of ... */
+#define R_SPARC_LM22 36 /* Low middle 22 bits of ... */
+#define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */
+#define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */
+#define R_SPARC_PC_LM22 39 /* Low miggle 22 bits of ... */
+#define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */
+#define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */
+#define R_SPARC_GLOB_JMP 42 /* was part of v9 ABI but was removed */
+#define R_SPARC_7 43 /* Direct 7 bit */
+#define R_SPARC_5 44 /* Direct 5 bit */
+#define R_SPARC_6 45 /* Direct 6 bit */
+#define R_SPARC_DISP64 46 /* PC relative 64 bit */
+#define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */
+#define R_SPARC_HIX22 48 /* High 22 bit complemented */
+#define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */
+#define R_SPARC_H44 50 /* Direct high 12 of 44 bit */
+#define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */
+#define R_SPARC_L44 52 /* Direct low 10 of 44 bit */
+#define R_SPARC_REGISTER 53 /* Global register usage */
+#define R_SPARC_UA64 54 /* Direct 64 bit unaligned */
+#define R_SPARC_UA16 55 /* Direct 16 bit unaligned */
+#define R_SPARC_TLS_GD_HI22 56
+#define R_SPARC_TLS_GD_LO10 57
+#define R_SPARC_TLS_GD_ADD 58
+#define R_SPARC_TLS_GD_CALL 59
+#define R_SPARC_TLS_LDM_HI22 60
+#define R_SPARC_TLS_LDM_LO10 61
+#define R_SPARC_TLS_LDM_ADD 62
+#define R_SPARC_TLS_LDM_CALL 63
+#define R_SPARC_TLS_LDO_HIX22 64
+#define R_SPARC_TLS_LDO_LOX10 65
+#define R_SPARC_TLS_LDO_ADD 66
+#define R_SPARC_TLS_IE_HI22 67
+#define R_SPARC_TLS_IE_LO10 68
+#define R_SPARC_TLS_IE_LD 69
+#define R_SPARC_TLS_IE_LDX 70
+#define R_SPARC_TLS_IE_ADD 71
+#define R_SPARC_TLS_LE_HIX22 72
+#define R_SPARC_TLS_LE_LOX10 73
+#define R_SPARC_TLS_DTPMOD32 74
+#define R_SPARC_TLS_DTPMOD64 75
+#define R_SPARC_TLS_DTPOFF32 76
+#define R_SPARC_TLS_DTPOFF64 77
+#define R_SPARC_TLS_TPOFF32 78
+#define R_SPARC_TLS_TPOFF64 79
+#define R_SPARC_GOTDATA_HIX22 80
+#define R_SPARC_GOTDATA_LOX10 81
+#define R_SPARC_GOTDATA_OP_HIX22 82
+#define R_SPARC_GOTDATA_OP_LOX10 83
+#define R_SPARC_GOTDATA_OP 84
+#define R_SPARC_H34 85
+#define R_SPARC_SIZE32 86
+#define R_SPARC_SIZE64 87
+#define R_SPARC_WDISP10 88
+#define R_SPARC_JMP_IREL 248
+#define R_SPARC_IRELATIVE 249
+#define R_SPARC_GNU_VTINHERIT 250
+#define R_SPARC_GNU_VTENTRY 251
+#define R_SPARC_REV32 252
+/* Keep this the last entry. */
+#define R_SPARC_NUM 253
+
+/* For Sparc64, legal values for d_tag of Elf64_Dyn. */
+
+#define DT_SPARC_REGISTER 0x70000001
+#define DT_SPARC_NUM 2
+
+/* MIPS R3000 specific definitions. */
+
+/* Legal values for e_flags field of Elf32_Ehdr. */
+
+#define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used. */
+#define EF_MIPS_PIC 2 /* Contains PIC code. */
+#define EF_MIPS_CPIC 4 /* Uses PIC calling sequence. */
+#define EF_MIPS_XGOT 8
+#define EF_MIPS_UCODE 16
+#define EF_MIPS_ABI2 32
+#define EF_MIPS_ABI_ON32 64
+#define EF_MIPS_OPTIONS_FIRST 0x00000080 /* Process the .MIPS.options
+ section first by ld. */
+#define EF_MIPS_32BITMODE 0x00000100 /* Indicates code compiled for
+ a 64-bit machine in 32-bit
+ mode (regs are 32-bits
+ wide). */
+#define EF_MIPS_FP64 512 /* Uses FP64 (12 callee-saved). */
+#define EF_MIPS_NAN2008 1024 /* Uses IEEE 754-2008 NaN encoding. */
+#define EF_MIPS_ARCH_ASE 0x0f000000 /* Architectural Extensions
+ used by this file. */
+#define EF_MIPS_ARCH_ASE_MDMX 0x08000000 /* Use MDMX multimedia
+ extensions. */
+#define EF_MIPS_ARCH_ASE_M16 0x04000000 /* Use MIPS-16 ISA
+ extensions. */
+#define EF_MIPS_ARCH_ASE_MICROMIPS 0x02000000 /* Use MICROMIPS ISA
+ extensions. */
+#define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level. */
+
+/* Legal values for MIPS architecture level. */
+
+#define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */
+#define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */
+#define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */
+#define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */
+#define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */
+#define EF_MIPS_ARCH_32 0x50000000 /* MIPS32 code. */
+#define EF_MIPS_ARCH_64 0x60000000 /* MIPS64 code. */
+#define EF_MIPS_ARCH_32R2 0x70000000 /* MIPS32r2 code. */
+#define EF_MIPS_ARCH_64R2 0x80000000 /* MIPS64r2 code. */
+#define EF_MIPS_ARCH_32R6 0x90000000 /* MIPS32r6 code. */
+#define EF_MIPS_ARCH_64R6 0xa0000000 /* MIPS64r6 code. */
+#define EF_MIPS_ABI 0x0000F000 /* The ABI of the file. Also
+ see EF_MIPS_ABI2 above. */
+#define EF_MIPS_ABI_O32 0x00001000 /* The original o32 abi. */
+#define EF_MIPS_ABI_O64 0x00002000 /* O32 extended to work on
+ 64 bit architectures. */
+#define EF_MIPS_ABI_EABI32 0x00003000 /* EABI in 32 bit mode. */
+#define EF_MIPS_ABI_EABI64 0x00004000 /* EABI in 64 bit mode. */
+#define EF_MIPS_MACH 0x00FF0000
+#define EF_MIPS_MACH_3900 0x00810000
+#define EF_MIPS_MACH_4010 0x00820000
+#define EF_MIPS_MACH_4100 0x00830000
+#define EF_MIPS_MACH_ALLEGREX 0x00840000
+#define EF_MIPS_MACH_4650 0x00850000
+#define EF_MIPS_MACH_4120 0x00870000
+#define EF_MIPS_MACH_4111 0x00880000
+#define EF_MIPS_MACH_SB1 0x008a0000
+#define EF_MIPS_MACH_OCTEON 0x008b0000
+#define EF_MIPS_MACH_XLR 0x008c0000
+#define EF_MIPS_MACH_OCTEON2 0x008d0000
+#define EF_MIPS_MACH_OCTEON3 0x008e0000
+#define EF_MIPS_MACH_5400 0x00910000
+#define EF_MIPS_MACH_5900 0x00920000
+#define EF_MIPS_MACH_IAMR2 0x00930000
+#define EF_MIPS_MACH_5500 0x00980000
+#define EF_MIPS_MACH_9000 0x00990000
+#define EF_MIPS_MACH_LS2E 0x00A00000
+#define EF_MIPS_MACH_LS2F 0x00A10000
+#define EF_MIPS_MACH_GS464 0x00A20000
+#define EF_MIPS_MACH_GS464E 0x00A30000
+#define EF_MIPS_MACH_GS264E 0x00A40000
+
+/* The following are unofficial names and should not be used. */
+
+#define E_MIPS_ARCH_1 EF_MIPS_ARCH_1
+#define E_MIPS_ARCH_2 EF_MIPS_ARCH_2
+#define E_MIPS_ARCH_3 EF_MIPS_ARCH_3
+#define E_MIPS_ARCH_4 EF_MIPS_ARCH_4
+#define E_MIPS_ARCH_5 EF_MIPS_ARCH_5
+#define E_MIPS_ARCH_32 EF_MIPS_ARCH_32
+#define E_MIPS_ARCH_64 EF_MIPS_ARCH_64
+
+/* Special section indices. */
+
+#define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols. */
+#define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */
+#define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */
+#define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols. */
+#define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols. */
+
+/* Legal values for sh_type field of Elf32_Shdr. */
+
+#define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link. */
+#define SHT_MIPS_MSYM 0x70000001
+#define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols. */
+#define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes. */
+#define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */
+#define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging info. */
+#define SHT_MIPS_REGINFO 0x70000006 /* Register usage information. */
+#define SHT_MIPS_PACKAGE 0x70000007
+#define SHT_MIPS_PACKSYM 0x70000008
+#define SHT_MIPS_RELD 0x70000009
+#define SHT_MIPS_IFACE 0x7000000b
+#define SHT_MIPS_CONTENT 0x7000000c
+#define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */
+#define SHT_MIPS_SHDR 0x70000010
+#define SHT_MIPS_FDESC 0x70000011
+#define SHT_MIPS_EXTSYM 0x70000012
+#define SHT_MIPS_DENSE 0x70000013
+#define SHT_MIPS_PDESC 0x70000014
+#define SHT_MIPS_LOCSYM 0x70000015
+#define SHT_MIPS_AUXSYM 0x70000016
+#define SHT_MIPS_OPTSYM 0x70000017
+#define SHT_MIPS_LOCSTR 0x70000018
+#define SHT_MIPS_LINE 0x70000019
+#define SHT_MIPS_RFDESC 0x7000001a
+#define SHT_MIPS_DELTASYM 0x7000001b
+#define SHT_MIPS_DELTAINST 0x7000001c
+#define SHT_MIPS_DELTACLASS 0x7000001d
+#define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */
+#define SHT_MIPS_DELTADECL 0x7000001f
+#define SHT_MIPS_SYMBOL_LIB 0x70000020
+#define SHT_MIPS_EVENTS 0x70000021 /* Event section. */
+#define SHT_MIPS_TRANSLATE 0x70000022
+#define SHT_MIPS_PIXIE 0x70000023
+#define SHT_MIPS_XLATE 0x70000024
+#define SHT_MIPS_XLATE_DEBUG 0x70000025
+#define SHT_MIPS_WHIRL 0x70000026
+#define SHT_MIPS_EH_REGION 0x70000027
+#define SHT_MIPS_XLATE_OLD 0x70000028
+#define SHT_MIPS_PDR_EXCEPTION 0x70000029
+#define SHT_MIPS_ABIFLAGS 0x7000002a
+#define SHT_MIPS_XHASH 0x7000002b
+
+/* Legal values for sh_flags field of Elf32_Shdr. */
+
+#define SHF_MIPS_GPREL 0x10000000 /* Must be in global data area. */
+#define SHF_MIPS_MERGE 0x20000000
+#define SHF_MIPS_ADDR 0x40000000
+#define SHF_MIPS_STRINGS 0x80000000
+#define SHF_MIPS_NOSTRIP 0x08000000
+#define SHF_MIPS_LOCAL 0x04000000
+#define SHF_MIPS_NAMES 0x02000000
+#define SHF_MIPS_NODUPE 0x01000000
+
+
+/* Symbol tables. */
+
+/* MIPS specific values for `st_other'. */
+#define STO_MIPS_DEFAULT 0x0
+#define STO_MIPS_INTERNAL 0x1
+#define STO_MIPS_HIDDEN 0x2
+#define STO_MIPS_PROTECTED 0x3
+#define STO_MIPS_PLT 0x8
+#define STO_MIPS_SC_ALIGN_UNUSED 0xff
+
+/* MIPS specific values for `st_info'. */
+#define STB_MIPS_SPLIT_COMMON 13
+
+/* Entries found in sections of type SHT_MIPS_GPTAB. */
+
+typedef union
+{
+ struct
+ {
+ Elf32_Word gt_current_g_value; /* -G value used for compilation. */
+ Elf32_Word gt_unused; /* Not used. */
+ } gt_header; /* First entry in section. */
+ struct
+ {
+ Elf32_Word gt_g_value; /* If this value were used for -G. */
+ Elf32_Word gt_bytes; /* This many bytes would be used. */
+ } gt_entry; /* Subsequent entries in section. */
+} Elf32_gptab;
+
+/* Entry found in sections of type SHT_MIPS_REGINFO. */
+
+typedef struct
+{
+ Elf32_Word ri_gprmask; /* General registers used. */
+ Elf32_Word ri_cprmask[4]; /* Coprocessor registers used. */
+ Elf32_Sword ri_gp_value; /* $gp register value. */
+} Elf32_RegInfo;
+
+/* Entries found in sections of type SHT_MIPS_OPTIONS. */
+
+typedef struct
+{
+ unsigned char kind; /* Determines interpretation of the
+ variable part of descriptor. */
+ unsigned char size; /* Size of descriptor, including header. */
+ Elf32_Section section; /* Section header index of section affected,
+ 0 for global options. */
+ Elf32_Word info; /* Kind-specific information. */
+} Elf_Options;
+
+/* Values for `kind' field in Elf_Options. */
+
+#define ODK_NULL 0 /* Undefined. */
+#define ODK_REGINFO 1 /* Register usage information. */
+#define ODK_EXCEPTIONS 2 /* Exception processing options. */
+#define ODK_PAD 3 /* Section padding options. */
+#define ODK_HWPATCH 4 /* Hardware workarounds performed */
+#define ODK_FILL 5 /* record the fill value used by the linker. */
+#define ODK_TAGS 6 /* reserve space for desktop tools to write. */
+#define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */
+#define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */
+
+/* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */
+
+#define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */
+#define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */
+#define OEX_PAGE0 0x10000 /* page zero must be mapped. */
+#define OEX_SMM 0x20000 /* Force sequential memory mode? */
+#define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */
+#define OEX_PRECISEFP OEX_FPDBUG
+#define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */
+
+#define OEX_FPU_INVAL 0x10
+#define OEX_FPU_DIV0 0x08
+#define OEX_FPU_OFLO 0x04
+#define OEX_FPU_UFLO 0x02
+#define OEX_FPU_INEX 0x01
+
+/* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */
+
+#define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */
+#define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */
+#define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */
+#define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */
+
+#define OPAD_PREFIX 0x1
+#define OPAD_POSTFIX 0x2
+#define OPAD_SYMBOL 0x4
+
+/* Entry found in `.options' section. */
+
+typedef struct
+{
+ Elf32_Word hwp_flags1; /* Extra flags. */
+ Elf32_Word hwp_flags2; /* Extra flags. */
+} Elf_Options_Hw;
+
+/* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */
+
+#define OHWA0_R4KEOP_CHECKED 0x00000001
+#define OHWA1_R4KEOP_CLEAN 0x00000002
+
+/* MIPS relocs. */
+
+#define R_MIPS_NONE 0 /* No reloc */
+#define R_MIPS_16 1 /* Direct 16 bit */
+#define R_MIPS_32 2 /* Direct 32 bit */
+#define R_MIPS_REL32 3 /* PC relative 32 bit */
+#define R_MIPS_26 4 /* Direct 26 bit shifted */
+#define R_MIPS_HI16 5 /* High 16 bit */
+#define R_MIPS_LO16 6 /* Low 16 bit */
+#define R_MIPS_GPREL16 7 /* GP relative 16 bit */
+#define R_MIPS_LITERAL 8 /* 16 bit literal entry */
+#define R_MIPS_GOT16 9 /* 16 bit GOT entry */
+#define R_MIPS_PC16 10 /* PC relative 16 bit */
+#define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */
+#define R_MIPS_GPREL32 12 /* GP relative 32 bit */
+
+#define R_MIPS_SHIFT5 16
+#define R_MIPS_SHIFT6 17
+#define R_MIPS_64 18
+#define R_MIPS_GOT_DISP 19
+#define R_MIPS_GOT_PAGE 20
+#define R_MIPS_GOT_OFST 21
+#define R_MIPS_GOT_HI16 22
+#define R_MIPS_GOT_LO16 23
+#define R_MIPS_SUB 24
+#define R_MIPS_INSERT_A 25
+#define R_MIPS_INSERT_B 26
+#define R_MIPS_DELETE 27
+#define R_MIPS_HIGHER 28
+#define R_MIPS_HIGHEST 29
+#define R_MIPS_CALL_HI16 30
+#define R_MIPS_CALL_LO16 31
+#define R_MIPS_SCN_DISP 32
+#define R_MIPS_REL16 33
+#define R_MIPS_ADD_IMMEDIATE 34
+#define R_MIPS_PJUMP 35
+#define R_MIPS_RELGOT 36
+#define R_MIPS_JALR 37
+#define R_MIPS_TLS_DTPMOD32 38 /* Module number 32 bit */
+#define R_MIPS_TLS_DTPREL32 39 /* Module-relative offset 32 bit */
+#define R_MIPS_TLS_DTPMOD64 40 /* Module number 64 bit */
+#define R_MIPS_TLS_DTPREL64 41 /* Module-relative offset 64 bit */
+#define R_MIPS_TLS_GD 42 /* 16 bit GOT offset for GD */
+#define R_MIPS_TLS_LDM 43 /* 16 bit GOT offset for LDM */
+#define R_MIPS_TLS_DTPREL_HI16 44 /* Module-relative offset, high 16 bits */
+#define R_MIPS_TLS_DTPREL_LO16 45 /* Module-relative offset, low 16 bits */
+#define R_MIPS_TLS_GOTTPREL 46 /* 16 bit GOT offset for IE */
+#define R_MIPS_TLS_TPREL32 47 /* TP-relative offset, 32 bit */
+#define R_MIPS_TLS_TPREL64 48 /* TP-relative offset, 64 bit */
+#define R_MIPS_TLS_TPREL_HI16 49 /* TP-relative offset, high 16 bits */
+#define R_MIPS_TLS_TPREL_LO16 50 /* TP-relative offset, low 16 bits */
+#define R_MIPS_GLOB_DAT 51
+#define R_MIPS_PC21_S2 60
+#define R_MIPS_PC26_S2 61
+#define R_MIPS_PC18_S3 62
+#define R_MIPS_PC19_S2 63
+#define R_MIPS_PCHI16 64
+#define R_MIPS_PCLO16 65
+#define R_MIPS16_26 100
+#define R_MIPS16_GPREL 101
+#define R_MIPS16_GOT16 102
+#define R_MIPS16_CALL16 103
+#define R_MIPS16_HI16 104
+#define R_MIPS16_LO16 105
+#define R_MIPS16_TLS_GD 106
+#define R_MIPS16_TLS_LDM 107
+#define R_MIPS16_TLS_DTPREL_HI16 108
+#define R_MIPS16_TLS_DTPREL_LO16 109
+#define R_MIPS16_TLS_GOTTPREL 110
+#define R_MIPS16_TLS_TPREL_HI16 111
+#define R_MIPS16_TLS_TPREL_LO16 112
+#define R_MIPS16_PC16_S1 113
+#define R_MIPS_COPY 126
+#define R_MIPS_JUMP_SLOT 127
+#define R_MIPS_RELATIVE 128
+#define R_MICROMIPS_26_S1 133
+#define R_MICROMIPS_HI16 134
+#define R_MICROMIPS_LO16 135
+#define R_MICROMIPS_GPREL16 136
+#define R_MICROMIPS_LITERAL 137
+#define R_MICROMIPS_GOT16 138
+#define R_MICROMIPS_PC7_S1 139
+#define R_MICROMIPS_PC10_S1 140
+#define R_MICROMIPS_PC16_S1 141
+#define R_MICROMIPS_CALL16 142
+#define R_MICROMIPS_GOT_DISP 145
+#define R_MICROMIPS_GOT_PAGE 146
+#define R_MICROMIPS_GOT_OFST 147
+#define R_MICROMIPS_GOT_HI16 148
+#define R_MICROMIPS_GOT_LO16 149
+#define R_MICROMIPS_SUB 150
+#define R_MICROMIPS_HIGHER 151
+#define R_MICROMIPS_HIGHEST 152
+#define R_MICROMIPS_CALL_HI16 153
+#define R_MICROMIPS_CALL_LO16 154
+#define R_MICROMIPS_SCN_DISP 155
+#define R_MICROMIPS_JALR 156
+#define R_MICROMIPS_HI0_LO16 157
+#define R_MICROMIPS_TLS_GD 162
+#define R_MICROMIPS_TLS_LDM 163
+#define R_MICROMIPS_TLS_DTPREL_HI16 164
+#define R_MICROMIPS_TLS_DTPREL_LO16 165
+#define R_MICROMIPS_TLS_GOTTPREL 166
+#define R_MICROMIPS_TLS_TPREL_HI16 169
+#define R_MICROMIPS_TLS_TPREL_LO16 170
+#define R_MICROMIPS_GPREL7_S2 172
+#define R_MICROMIPS_PC23_S2 173
+#define R_MIPS_PC32 248
+#define R_MIPS_EH 249
+#define R_MIPS_GNU_REL16_S2 250
+#define R_MIPS_GNU_VTINHERIT 253
+#define R_MIPS_GNU_VTENTRY 254
+/* Keep this the last entry. */
+#define R_MIPS_NUM 255
+
+/* Legal values for p_type field of Elf32_Phdr. */
+
+#define PT_MIPS_REGINFO 0x70000000 /* Register usage information. */
+#define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */
+#define PT_MIPS_OPTIONS 0x70000002
+#define PT_MIPS_ABIFLAGS 0x70000003 /* FP mode requirement. */
+
+/* Special program header types. */
+
+#define PF_MIPS_LOCAL 0x10000000
+
+/* Legal values for d_tag field of Elf32_Dyn. */
+
+#define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */
+#define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */
+#define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */
+#define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */
+#define DT_MIPS_FLAGS 0x70000005 /* Flags */
+#define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */
+#define DT_MIPS_MSYM 0x70000007
+#define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */
+#define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */
+#define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */
+#define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */
+#define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */
+#define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */
+#define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */
+#define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */
+#define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */
+#define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */
+#define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */
+#define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in
+ DT_MIPS_DELTA_CLASS. */
+#define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */
+#define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in
+ DT_MIPS_DELTA_INSTANCE. */
+#define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */
+#define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in
+ DT_MIPS_DELTA_RELOC. */
+#define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta
+ relocations refer to. */
+#define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in
+ DT_MIPS_DELTA_SYM. */
+#define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the
+ class declaration. */
+#define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in
+ DT_MIPS_DELTA_CLASSSYM. */
+#define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */
+#define DT_MIPS_PIXIE_INIT 0x70000023
+#define DT_MIPS_SYMBOL_LIB 0x70000024
+#define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025
+#define DT_MIPS_LOCAL_GOTIDX 0x70000026
+#define DT_MIPS_HIDDEN_GOTIDX 0x70000027
+#define DT_MIPS_PROTECTED_GOTIDX 0x70000028
+#define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */
+#define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */
+#define DT_MIPS_DYNSTR_ALIGN 0x7000002b
+#define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */
+#define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve
+ function stored in GOT. */
+#define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added
+ by rld on dlopen() calls. */
+#define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */
+#define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */
+#define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */
+/* The address of .got.plt in an executable using the new non-PIC ABI. */
+#define DT_MIPS_PLTGOT 0x70000032
+/* The base of the PLT in an executable using the new non-PIC ABI if that
+ PLT is writable. For a non-writable PLT, this is omitted or has a zero
+ value. */
+#define DT_MIPS_RWPLT 0x70000034
+/* An alternative description of the classic MIPS RLD_MAP that is usable
+ in a PIE as it stores a relative offset from the address of the tag
+ rather than an absolute address. */
+#define DT_MIPS_RLD_MAP_REL 0x70000035
+/* GNU-style hash table with xlat. */
+#define DT_MIPS_XHASH 0x70000036
+#define DT_MIPS_NUM 0x37
+
+/* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */
+
+#define RHF_NONE 0 /* No flags */
+#define RHF_QUICKSTART (1 << 0) /* Use quickstart */
+#define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */
+#define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */
+#define RHF_NO_MOVE (1 << 3)
+#define RHF_SGI_ONLY (1 << 4)
+#define RHF_GUARANTEE_INIT (1 << 5)
+#define RHF_DELTA_C_PLUS_PLUS (1 << 6)
+#define RHF_GUARANTEE_START_INIT (1 << 7)
+#define RHF_PIXIE (1 << 8)
+#define RHF_DEFAULT_DELAY_LOAD (1 << 9)
+#define RHF_REQUICKSTART (1 << 10)
+#define RHF_REQUICKSTARTED (1 << 11)
+#define RHF_CORD (1 << 12)
+#define RHF_NO_UNRES_UNDEF (1 << 13)
+#define RHF_RLD_ORDER_SAFE (1 << 14)
+
+/* Entries found in sections of type SHT_MIPS_LIBLIST. */
+
+typedef struct
+{
+ Elf32_Word l_name; /* Name (string table index) */
+ Elf32_Word l_time_stamp; /* Timestamp */
+ Elf32_Word l_checksum; /* Checksum */
+ Elf32_Word l_version; /* Interface version */
+ Elf32_Word l_flags; /* Flags */
+} Elf32_Lib;
+
+typedef struct
+{
+ Elf64_Word l_name; /* Name (string table index) */
+ Elf64_Word l_time_stamp; /* Timestamp */
+ Elf64_Word l_checksum; /* Checksum */
+ Elf64_Word l_version; /* Interface version */
+ Elf64_Word l_flags; /* Flags */
+} Elf64_Lib;
+
+
+/* Legal values for l_flags. */
+
+#define LL_NONE 0
+#define LL_EXACT_MATCH (1 << 0) /* Require exact match */
+#define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */
+#define LL_REQUIRE_MINOR (1 << 2)
+#define LL_EXPORTS (1 << 3)
+#define LL_DELAY_LOAD (1 << 4)
+#define LL_DELTA (1 << 5)
+
+/* Entries found in sections of type SHT_MIPS_CONFLICT. */
+
+typedef Elf32_Addr Elf32_Conflict;
+
+typedef struct
+{
+ /* Version of flags structure. */
+ Elf32_Half version;
+ /* The level of the ISA: 1-5, 32, 64. */
+ unsigned char isa_level;
+ /* The revision of ISA: 0 for MIPS V and below, 1-n otherwise. */
+ unsigned char isa_rev;
+ /* The size of general purpose registers. */
+ unsigned char gpr_size;
+ /* The size of co-processor 1 registers. */
+ unsigned char cpr1_size;
+ /* The size of co-processor 2 registers. */
+ unsigned char cpr2_size;
+ /* The floating-point ABI. */
+ unsigned char fp_abi;
+ /* Processor-specific extension. */
+ Elf32_Word isa_ext;
+ /* Mask of ASEs used. */
+ Elf32_Word ases;
+ /* Mask of general flags. */
+ Elf32_Word flags1;
+ Elf32_Word flags2;
+} Elf_MIPS_ABIFlags_v0;
+
+/* Values for the register size bytes of an abi flags structure. */
+
+#define MIPS_AFL_REG_NONE 0x00 /* No registers. */
+#define MIPS_AFL_REG_32 0x01 /* 32-bit registers. */
+#define MIPS_AFL_REG_64 0x02 /* 64-bit registers. */
+#define MIPS_AFL_REG_128 0x03 /* 128-bit registers. */
+
+/* Masks for the ases word of an ABI flags structure. */
+
+#define MIPS_AFL_ASE_DSP 0x00000001 /* DSP ASE. */
+#define MIPS_AFL_ASE_DSPR2 0x00000002 /* DSP R2 ASE. */
+#define MIPS_AFL_ASE_EVA 0x00000004 /* Enhanced VA Scheme. */
+#define MIPS_AFL_ASE_MCU 0x00000008 /* MCU (MicroController) ASE. */
+#define MIPS_AFL_ASE_MDMX 0x00000010 /* MDMX ASE. */
+#define MIPS_AFL_ASE_MIPS3D 0x00000020 /* MIPS-3D ASE. */
+#define MIPS_AFL_ASE_MT 0x00000040 /* MT ASE. */
+#define MIPS_AFL_ASE_SMARTMIPS 0x00000080 /* SmartMIPS ASE. */
+#define MIPS_AFL_ASE_VIRT 0x00000100 /* VZ ASE. */
+#define MIPS_AFL_ASE_MSA 0x00000200 /* MSA ASE. */
+#define MIPS_AFL_ASE_MIPS16 0x00000400 /* MIPS16 ASE. */
+#define MIPS_AFL_ASE_MICROMIPS 0x00000800 /* MICROMIPS ASE. */
+#define MIPS_AFL_ASE_XPA 0x00001000 /* XPA ASE. */
+#define MIPS_AFL_ASE_MASK 0x00001fff /* All ASEs. */
+
+/* Values for the isa_ext word of an ABI flags structure. */
+
+#define MIPS_AFL_EXT_XLR 1 /* RMI Xlr instruction. */
+#define MIPS_AFL_EXT_OCTEON2 2 /* Cavium Networks Octeon2. */
+#define MIPS_AFL_EXT_OCTEONP 3 /* Cavium Networks OcteonP. */
+#define MIPS_AFL_EXT_LOONGSON_3A 4 /* Loongson 3A. */
+#define MIPS_AFL_EXT_OCTEON 5 /* Cavium Networks Octeon. */
+#define MIPS_AFL_EXT_5900 6 /* MIPS R5900 instruction. */
+#define MIPS_AFL_EXT_4650 7 /* MIPS R4650 instruction. */
+#define MIPS_AFL_EXT_4010 8 /* LSI R4010 instruction. */
+#define MIPS_AFL_EXT_4100 9 /* NEC VR4100 instruction. */
+#define MIPS_AFL_EXT_3900 10 /* Toshiba R3900 instruction. */
+#define MIPS_AFL_EXT_10000 11 /* MIPS R10000 instruction. */
+#define MIPS_AFL_EXT_SB1 12 /* Broadcom SB-1 instruction. */
+#define MIPS_AFL_EXT_4111 13 /* NEC VR4111/VR4181 instruction. */
+#define MIPS_AFL_EXT_4120 14 /* NEC VR4120 instruction. */
+#define MIPS_AFL_EXT_5400 15 /* NEC VR5400 instruction. */
+#define MIPS_AFL_EXT_5500 16 /* NEC VR5500 instruction. */
+#define MIPS_AFL_EXT_LOONGSON_2E 17 /* ST Microelectronics Loongson 2E. */
+#define MIPS_AFL_EXT_LOONGSON_2F 18 /* ST Microelectronics Loongson 2F. */
+
+/* Masks for the flags1 word of an ABI flags structure. */
+#define MIPS_AFL_FLAGS1_ODDSPREG 1 /* Uses odd single-precision registers. */
+
+/* Object attribute values. */
+enum
+{
+ /* Not tagged or not using any ABIs affected by the differences. */
+ Val_GNU_MIPS_ABI_FP_ANY = 0,
+ /* Using hard-float -mdouble-float. */
+ Val_GNU_MIPS_ABI_FP_DOUBLE = 1,
+ /* Using hard-float -msingle-float. */
+ Val_GNU_MIPS_ABI_FP_SINGLE = 2,
+ /* Using soft-float. */
+ Val_GNU_MIPS_ABI_FP_SOFT = 3,
+ /* Using -mips32r2 -mfp64. */
+ Val_GNU_MIPS_ABI_FP_OLD_64 = 4,
+ /* Using -mfpxx. */
+ Val_GNU_MIPS_ABI_FP_XX = 5,
+ /* Using -mips32r2 -mfp64. */
+ Val_GNU_MIPS_ABI_FP_64 = 6,
+ /* Using -mips32r2 -mfp64 -mno-odd-spreg. */
+ Val_GNU_MIPS_ABI_FP_64A = 7,
+ /* Maximum allocated FP ABI value. */
+ Val_GNU_MIPS_ABI_FP_MAX = 7
+};
+
+/* HPPA specific definitions. */
+
+/* Legal values for e_flags field of Elf32_Ehdr. */
+
+#define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */
+#define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */
+#define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */
+#define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */
+#define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch
+ prediction. */
+#define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */
+#define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */
+
+/* Defined values for `e_flags & EF_PARISC_ARCH' are: */
+
+#define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */
+#define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */
+#define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */
+
+/* Additional section indices. */
+
+#define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tentatively declared
+ symbols in ANSI C. */
+#define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */
+
+/* Legal values for sh_type field of Elf32_Shdr. */
+
+#define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */
+#define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */
+#define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */
+
+/* Legal values for sh_flags field of Elf32_Shdr. */
+
+#define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */
+#define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */
+#define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */
+
+/* Legal values for ST_TYPE subfield of st_info (symbol type). */
+
+#define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */
+
+#define STT_HP_OPAQUE (STT_LOOS + 0x1)
+#define STT_HP_STUB (STT_LOOS + 0x2)
+
+/* HPPA relocs. */
+
+#define R_PARISC_NONE 0 /* No reloc. */
+#define R_PARISC_DIR32 1 /* Direct 32-bit reference. */
+#define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */
+#define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */
+#define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */
+#define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */
+#define R_PARISC_PCREL32 9 /* 32-bit rel. address. */
+#define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */
+#define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */
+#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_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_SECREL32 41 /* 32 bits section rel. address. */
+#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_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. */
+#define R_PARISC_FPTR64 64 /* 64 bits function address. */
+#define R_PARISC_PLABEL32 65 /* 32 bits function address. */
+#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_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. */
+#define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */
+#define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */
+#define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */
+#define R_PARISC_DIR64 80 /* 64 bits of eff. address. */
+#define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */
+#define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */
+#define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */
+#define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */
+#define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */
+#define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */
+#define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */
+#define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */
+#define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */
+#define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */
+#define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */
+#define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */
+#define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */
+#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_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. */
+#define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */
+#define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */
+#define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */
+#define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */
+#define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */
+#define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */
+#define R_PARISC_LORESERVE 128
+#define R_PARISC_COPY 128 /* Copy relocation. */
+#define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */
+#define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */
+#define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */
+#define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */
+#define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */
+#define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */
+#define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */
+#define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */
+#define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */
+#define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */
+#define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */
+#define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/
+#define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */
+#define R_PARISC_GNU_VTENTRY 232
+#define R_PARISC_GNU_VTINHERIT 233
+#define R_PARISC_TLS_GD21L 234 /* GD 21-bit left. */
+#define R_PARISC_TLS_GD14R 235 /* GD 14-bit right. */
+#define R_PARISC_TLS_GDCALL 236 /* GD call to __t_g_a. */
+#define R_PARISC_TLS_LDM21L 237 /* LD module 21-bit left. */
+#define R_PARISC_TLS_LDM14R 238 /* LD module 14-bit right. */
+#define R_PARISC_TLS_LDMCALL 239 /* LD module call to __t_g_a. */
+#define R_PARISC_TLS_LDO21L 240 /* LD offset 21-bit left. */
+#define R_PARISC_TLS_LDO14R 241 /* LD offset 14-bit right. */
+#define R_PARISC_TLS_DTPMOD32 242 /* DTP module 32-bit. */
+#define R_PARISC_TLS_DTPMOD64 243 /* DTP module 64-bit. */
+#define R_PARISC_TLS_DTPOFF32 244 /* DTP offset 32-bit. */
+#define R_PARISC_TLS_DTPOFF64 245 /* DTP offset 32-bit. */
+#define R_PARISC_TLS_LE21L R_PARISC_TPREL21L
+#define R_PARISC_TLS_LE14R R_PARISC_TPREL14R
+#define R_PARISC_TLS_IE21L R_PARISC_LTOFF_TP21L
+#define R_PARISC_TLS_IE14R R_PARISC_LTOFF_TP14R
+#define R_PARISC_TLS_TPREL32 R_PARISC_TPREL32
+#define R_PARISC_TLS_TPREL64 R_PARISC_TPREL64
+#define R_PARISC_HIRESERVE 255
+
+/* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */
+
+#define PT_HP_TLS (PT_LOOS + 0x0)
+#define PT_HP_CORE_NONE (PT_LOOS + 0x1)
+#define PT_HP_CORE_VERSION (PT_LOOS + 0x2)
+#define PT_HP_CORE_KERNEL (PT_LOOS + 0x3)
+#define PT_HP_CORE_COMM (PT_LOOS + 0x4)
+#define PT_HP_CORE_PROC (PT_LOOS + 0x5)
+#define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6)
+#define PT_HP_CORE_STACK (PT_LOOS + 0x7)
+#define PT_HP_CORE_SHM (PT_LOOS + 0x8)
+#define PT_HP_CORE_MMF (PT_LOOS + 0x9)
+#define PT_HP_PARALLEL (PT_LOOS + 0x10)
+#define PT_HP_FASTBIND (PT_LOOS + 0x11)
+#define PT_HP_OPT_ANNOT (PT_LOOS + 0x12)
+#define PT_HP_HSL_ANNOT (PT_LOOS + 0x13)
+#define PT_HP_STACK (PT_LOOS + 0x14)
+
+#define PT_PARISC_ARCHEXT 0x70000000
+#define PT_PARISC_UNWIND 0x70000001
+
+/* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */
+
+#define PF_PARISC_SBP 0x08000000
+
+#define PF_HP_PAGE_SIZE 0x00100000
+#define PF_HP_FAR_SHARED 0x00200000
+#define PF_HP_NEAR_SHARED 0x00400000
+#define PF_HP_CODE 0x01000000
+#define PF_HP_MODIFY 0x02000000
+#define PF_HP_LAZYSWAP 0x04000000
+#define PF_HP_SBP 0x08000000
+
+
+/* Alpha specific definitions. */
+
+/* Legal values for e_flags field of Elf64_Ehdr. */
+
+#define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */
+#define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */
+
+/* Legal values for sh_type field of Elf64_Shdr. */
+
+/* These two are primerily concerned with ECOFF debugging info. */
+#define SHT_ALPHA_DEBUG 0x70000001
+#define SHT_ALPHA_REGINFO 0x70000002
+
+/* Legal values for sh_flags field of Elf64_Shdr. */
+
+#define SHF_ALPHA_GPREL 0x10000000
+
+/* Legal values for st_other field of Elf64_Sym. */
+#define STO_ALPHA_NOPV 0x80 /* No PV required. */
+#define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */
+
+/* Alpha relocs. */
+
+#define R_ALPHA_NONE 0 /* No reloc */
+#define R_ALPHA_REFLONG 1 /* Direct 32 bit */
+#define R_ALPHA_REFQUAD 2 /* Direct 64 bit */
+#define R_ALPHA_GPREL32 3 /* GP relative 32 bit */
+#define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */
+#define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */
+#define R_ALPHA_GPDISP 6 /* Add displacement to GP */
+#define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */
+#define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */
+#define R_ALPHA_SREL16 9 /* PC relative 16 bit */
+#define R_ALPHA_SREL32 10 /* PC relative 32 bit */
+#define R_ALPHA_SREL64 11 /* PC relative 64 bit */
+#define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */
+#define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */
+#define R_ALPHA_GPREL16 19 /* GP relative 16 bit */
+#define R_ALPHA_COPY 24 /* Copy symbol at runtime */
+#define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */
+#define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */
+#define R_ALPHA_RELATIVE 27 /* Adjust by program base */
+#define R_ALPHA_TLS_GD_HI 28
+#define R_ALPHA_TLSGD 29
+#define R_ALPHA_TLS_LDM 30
+#define R_ALPHA_DTPMOD64 31
+#define R_ALPHA_GOTDTPREL 32
+#define R_ALPHA_DTPREL64 33
+#define R_ALPHA_DTPRELHI 34
+#define R_ALPHA_DTPRELLO 35
+#define R_ALPHA_DTPREL16 36
+#define R_ALPHA_GOTTPREL 37
+#define R_ALPHA_TPREL64 38
+#define R_ALPHA_TPRELHI 39
+#define R_ALPHA_TPRELLO 40
+#define R_ALPHA_TPREL16 41
+/* Keep this the last entry. */
+#define R_ALPHA_NUM 46
+
+/* Magic values of the LITUSE relocation addend. */
+#define LITUSE_ALPHA_ADDR 0
+#define LITUSE_ALPHA_BASE 1
+#define LITUSE_ALPHA_BYTOFF 2
+#define LITUSE_ALPHA_JSR 3
+#define LITUSE_ALPHA_TLS_GD 4
+#define LITUSE_ALPHA_TLS_LDM 5
+
+/* Legal values for d_tag of Elf64_Dyn. */
+#define DT_ALPHA_PLTRO (DT_LOPROC + 0)
+#define DT_ALPHA_NUM 1
+
+/* PowerPC specific declarations */
+
+/* Values for Elf32/64_Ehdr.e_flags. */
+#define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */
+
+/* Cygnus local bits below */
+#define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/
+#define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib
+ flag */
+
+/* PowerPC relocations defined by the ABIs */
+#define R_PPC_NONE 0
+#define R_PPC_ADDR32 1 /* 32bit absolute address */
+#define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */
+#define R_PPC_ADDR16 3 /* 16bit absolute address */
+#define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */
+#define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */
+#define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */
+#define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */
+#define R_PPC_ADDR14_BRTAKEN 8
+#define R_PPC_ADDR14_BRNTAKEN 9
+#define R_PPC_REL24 10 /* PC relative 26 bit */
+#define R_PPC_REL14 11 /* PC relative 16 bit */
+#define R_PPC_REL14_BRTAKEN 12
+#define R_PPC_REL14_BRNTAKEN 13
+#define R_PPC_GOT16 14
+#define R_PPC_GOT16_LO 15
+#define R_PPC_GOT16_HI 16
+#define R_PPC_GOT16_HA 17
+#define R_PPC_PLTREL24 18
+#define R_PPC_COPY 19
+#define R_PPC_GLOB_DAT 20
+#define R_PPC_JMP_SLOT 21
+#define R_PPC_RELATIVE 22
+#define R_PPC_LOCAL24PC 23
+#define R_PPC_UADDR32 24
+#define R_PPC_UADDR16 25
+#define R_PPC_REL32 26
+#define R_PPC_PLT32 27
+#define R_PPC_PLTREL32 28
+#define R_PPC_PLT16_LO 29
+#define R_PPC_PLT16_HI 30
+#define R_PPC_PLT16_HA 31
+#define R_PPC_SDAREL16 32
+#define R_PPC_SECTOFF 33
+#define R_PPC_SECTOFF_LO 34
+#define R_PPC_SECTOFF_HI 35
+#define R_PPC_SECTOFF_HA 36
+
+/* PowerPC relocations defined for the TLS access ABI. */
+#define R_PPC_TLS 67 /* none (sym+add)@tls */
+#define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */
+#define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */
+#define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */
+#define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */
+#define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */
+#define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */
+#define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */
+#define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */
+#define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */
+#define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */
+#define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */
+#define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */
+#define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */
+#define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */
+#define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */
+#define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */
+#define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */
+#define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */
+#define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */
+#define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */
+#define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */
+#define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */
+#define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */
+#define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */
+#define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */
+#define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */
+#define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */
+#define R_PPC_TLSGD 95 /* none (sym+add)@tlsgd */
+#define R_PPC_TLSLD 96 /* none (sym+add)@tlsld */
+
+/* The remaining relocs are from the Embedded ELF ABI, and are not
+ in the SVR4 ELF ABI. */
+#define R_PPC_EMB_NADDR32 101
+#define R_PPC_EMB_NADDR16 102
+#define R_PPC_EMB_NADDR16_LO 103
+#define R_PPC_EMB_NADDR16_HI 104
+#define R_PPC_EMB_NADDR16_HA 105
+#define R_PPC_EMB_SDAI16 106
+#define R_PPC_EMB_SDA2I16 107
+#define R_PPC_EMB_SDA2REL 108
+#define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */
+#define R_PPC_EMB_MRKREF 110
+#define R_PPC_EMB_RELSEC16 111
+#define R_PPC_EMB_RELST_LO 112
+#define R_PPC_EMB_RELST_HI 113
+#define R_PPC_EMB_RELST_HA 114
+#define R_PPC_EMB_BIT_FLD 115
+#define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */
+
+/* Diab tool relocations. */
+#define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */
+#define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */
+#define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */
+#define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */
+#define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */
+#define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */
+
+/* GNU extension to support local ifunc. */
+#define R_PPC_IRELATIVE 248
+
+/* GNU relocs used in PIC code sequences. */
+#define R_PPC_REL16 249 /* half16 (sym+add-.) */
+#define R_PPC_REL16_LO 250 /* half16 (sym+add-.)@l */
+#define R_PPC_REL16_HI 251 /* half16 (sym+add-.)@h */
+#define R_PPC_REL16_HA 252 /* half16 (sym+add-.)@ha */
+
+/* This is a phony reloc to handle any old fashioned TOC16 references
+ that may still be in object files. */
+#define R_PPC_TOC16 255
+
+/* PowerPC specific values for the Dyn d_tag field. */
+#define DT_PPC_GOT (DT_LOPROC + 0)
+#define DT_PPC_OPT (DT_LOPROC + 1)
+#define DT_PPC_NUM 2
+
+/* PowerPC specific values for the DT_PPC_OPT Dyn entry. */
+#define PPC_OPT_TLS 1
+
+/* PowerPC64 relocations defined by the ABIs */
+#define R_PPC64_NONE R_PPC_NONE
+#define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */
+#define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */
+#define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */
+#define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */
+#define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */
+#define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */
+#define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */
+#define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN
+#define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN
+#define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */
+#define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */
+#define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN
+#define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN
+#define R_PPC64_GOT16 R_PPC_GOT16
+#define R_PPC64_GOT16_LO R_PPC_GOT16_LO
+#define R_PPC64_GOT16_HI R_PPC_GOT16_HI
+#define R_PPC64_GOT16_HA R_PPC_GOT16_HA
+
+#define R_PPC64_COPY R_PPC_COPY
+#define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT
+#define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT
+#define R_PPC64_RELATIVE R_PPC_RELATIVE
+
+#define R_PPC64_UADDR32 R_PPC_UADDR32
+#define R_PPC64_UADDR16 R_PPC_UADDR16
+#define R_PPC64_REL32 R_PPC_REL32
+#define R_PPC64_PLT32 R_PPC_PLT32
+#define R_PPC64_PLTREL32 R_PPC_PLTREL32
+#define R_PPC64_PLT16_LO R_PPC_PLT16_LO
+#define R_PPC64_PLT16_HI R_PPC_PLT16_HI
+#define R_PPC64_PLT16_HA R_PPC_PLT16_HA
+
+#define R_PPC64_SECTOFF R_PPC_SECTOFF
+#define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO
+#define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI
+#define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA
+#define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */
+#define R_PPC64_ADDR64 38 /* doubleword64 S + A */
+#define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */
+#define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */
+#define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */
+#define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */
+#define R_PPC64_UADDR64 43 /* doubleword64 S + A */
+#define R_PPC64_REL64 44 /* doubleword64 S + A - P */
+#define R_PPC64_PLT64 45 /* doubleword64 L + A */
+#define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */
+#define R_PPC64_TOC16 47 /* half16* S + A - .TOC */
+#define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */
+#define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */
+#define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */
+#define R_PPC64_TOC 51 /* doubleword64 .TOC */
+#define R_PPC64_PLTGOT16 52 /* half16* M + A */
+#define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */
+#define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */
+#define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */
+
+#define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */
+#define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */
+#define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */
+#define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */
+#define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */
+#define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */
+#define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */
+#define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */
+#define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */
+#define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */
+#define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */
+
+/* PowerPC64 relocations defined for the TLS access ABI. */
+#define R_PPC64_TLS 67 /* none (sym+add)@tls */
+#define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */
+#define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */
+#define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */
+#define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */
+#define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */
+#define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */
+#define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */
+#define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */
+#define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */
+#define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */
+#define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */
+#define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */
+#define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */
+#define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */
+#define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */
+#define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */
+#define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */
+#define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */
+#define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */
+#define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */
+#define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */
+#define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */
+#define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */
+#define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */
+#define R_PPC64_GOT_DTPREL16_LO_DS 92 /* half16ds (sym+add)@got@dtprel@l */
+#define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */
+#define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */
+#define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */
+#define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */
+#define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */
+#define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */
+#define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */
+#define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */
+#define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */
+#define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */
+#define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */
+#define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */
+#define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */
+#define R_PPC64_DTPREL16_HIGHESTA 106 /* half16 (sym+add)@dtprel@highesta */
+#define R_PPC64_TLSGD 107 /* none (sym+add)@tlsgd */
+#define R_PPC64_TLSLD 108 /* none (sym+add)@tlsld */
+#define R_PPC64_TOCSAVE 109 /* none */
+
+/* Added when HA and HI relocs were changed to report overflows. */
+#define R_PPC64_ADDR16_HIGH 110
+#define R_PPC64_ADDR16_HIGHA 111
+#define R_PPC64_TPREL16_HIGH 112
+#define R_PPC64_TPREL16_HIGHA 113
+#define R_PPC64_DTPREL16_HIGH 114
+#define R_PPC64_DTPREL16_HIGHA 115
+
+/* GNU extension to support local ifunc. */
+#define R_PPC64_JMP_IREL 247
+#define R_PPC64_IRELATIVE 248
+#define R_PPC64_REL16 249 /* half16 (sym+add-.) */
+#define R_PPC64_REL16_LO 250 /* half16 (sym+add-.)@l */
+#define R_PPC64_REL16_HI 251 /* half16 (sym+add-.)@h */
+#define R_PPC64_REL16_HA 252 /* half16 (sym+add-.)@ha */
+
+/* e_flags bits specifying ABI.
+ 1 for original function descriptor using ABI,
+ 2 for revised ABI without function descriptors,
+ 0 for unspecified or not using any features affected by the differences. */
+#define EF_PPC64_ABI 3
+
+/* PowerPC64 specific values for the Dyn d_tag field. */
+#define DT_PPC64_GLINK (DT_LOPROC + 0)
+#define DT_PPC64_OPD (DT_LOPROC + 1)
+#define DT_PPC64_OPDSZ (DT_LOPROC + 2)
+#define DT_PPC64_OPT (DT_LOPROC + 3)
+#define DT_PPC64_NUM 4
+
+/* PowerPC64 specific bits in the DT_PPC64_OPT Dyn entry. */
+#define PPC64_OPT_TLS 1
+#define PPC64_OPT_MULTI_TOC 2
+#define PPC64_OPT_LOCALENTRY 4
+
+/* PowerPC64 specific values for the Elf64_Sym st_other field. */
+#define STO_PPC64_LOCAL_BIT 5
+#define STO_PPC64_LOCAL_MASK (7 << STO_PPC64_LOCAL_BIT)
+#define PPC64_LOCAL_ENTRY_OFFSET(other) \
+ (((1 << (((other) & STO_PPC64_LOCAL_MASK) >> STO_PPC64_LOCAL_BIT)) >> 2) << 2)
+
+
+/* ARM specific declarations */
+
+/* Processor specific flags for the ELF header e_flags field. */
+#define EF_ARM_RELEXEC 0x01
+#define EF_ARM_HASENTRY 0x02
+#define EF_ARM_INTERWORK 0x04
+#define EF_ARM_APCS_26 0x08
+#define EF_ARM_APCS_FLOAT 0x10
+#define EF_ARM_PIC 0x20
+#define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */
+#define EF_ARM_NEW_ABI 0x80
+#define EF_ARM_OLD_ABI 0x100
+#define EF_ARM_SOFT_FLOAT 0x200
+#define EF_ARM_VFP_FLOAT 0x400
+#define EF_ARM_MAVERICK_FLOAT 0x800
+
+#define EF_ARM_ABI_FLOAT_SOFT 0x200 /* NB conflicts with EF_ARM_SOFT_FLOAT */
+#define EF_ARM_ABI_FLOAT_HARD 0x400 /* NB conflicts with EF_ARM_VFP_FLOAT */
+
+
+/* Other constants defined in the ARM ELF spec. version B-01. */
+/* NB. These conflict with values defined above. */
+#define EF_ARM_SYMSARESORTED 0x04
+#define EF_ARM_DYNSYMSUSESEGIDX 0x08
+#define EF_ARM_MAPSYMSFIRST 0x10
+#define EF_ARM_EABIMASK 0XFF000000
+
+/* Constants defined in AAELF. */
+#define EF_ARM_BE8 0x00800000
+#define EF_ARM_LE8 0x00400000
+
+#define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
+#define EF_ARM_EABI_UNKNOWN 0x00000000
+#define EF_ARM_EABI_VER1 0x01000000
+#define EF_ARM_EABI_VER2 0x02000000
+#define EF_ARM_EABI_VER3 0x03000000
+#define EF_ARM_EABI_VER4 0x04000000
+#define EF_ARM_EABI_VER5 0x05000000
+
+/* Additional symbol types for Thumb. */
+#define STT_ARM_TFUNC STT_LOPROC /* A Thumb function. */
+#define STT_ARM_16BIT STT_HIPROC /* A Thumb label. */
+
+/* ARM-specific values for sh_flags */
+#define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */
+#define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined
+ in the input to a link step. */
+
+/* ARM-specific program header flags */
+#define PF_ARM_SB 0x10000000 /* Segment contains the location
+ addressed by the static base. */
+#define PF_ARM_PI 0x20000000 /* Position-independent segment. */
+#define PF_ARM_ABS 0x40000000 /* Absolute segment. */
+
+/* Processor specific values for the Phdr p_type field. */
+#define PT_ARM_EXIDX (PT_LOPROC + 1) /* ARM unwind segment. */
+
+/* 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. */
+
+
+/* AArch64 relocs. */
+
+#define R_AARCH64_NONE 0 /* No relocation. */
+
+/* ILP32 AArch64 relocs. */
+#define R_AARCH64_P32_ABS32 1 /* Direct 32 bit. */
+#define R_AARCH64_P32_COPY 180 /* Copy symbol at runtime. */
+#define R_AARCH64_P32_GLOB_DAT 181 /* Create GOT entry. */
+#define R_AARCH64_P32_JUMP_SLOT 182 /* Create PLT entry. */
+#define R_AARCH64_P32_RELATIVE 183 /* Adjust by program base. */
+#define R_AARCH64_P32_TLS_DTPMOD 184 /* Module number, 32 bit. */
+#define R_AARCH64_P32_TLS_DTPREL 185 /* Module-relative offset, 32 bit. */
+#define R_AARCH64_P32_TLS_TPREL 186 /* TP-relative offset, 32 bit. */
+#define R_AARCH64_P32_TLSDESC 187 /* TLS Descriptor. */
+#define R_AARCH64_P32_IRELATIVE 188 /* STT_GNU_IFUNC relocation. */
+
+/* LP64 AArch64 relocs. */
+#define R_AARCH64_ABS64 257 /* Direct 64 bit. */
+#define R_AARCH64_ABS32 258 /* Direct 32 bit. */
+#define R_AARCH64_ABS16 259 /* Direct 16-bit. */
+#define R_AARCH64_PREL64 260 /* PC-relative 64-bit. */
+#define R_AARCH64_PREL32 261 /* PC-relative 32-bit. */
+#define R_AARCH64_PREL16 262 /* PC-relative 16-bit. */
+#define R_AARCH64_MOVW_UABS_G0 263 /* Dir. MOVZ imm. from bits 15:0. */
+#define R_AARCH64_MOVW_UABS_G0_NC 264 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_UABS_G1 265 /* Dir. MOVZ imm. from bits 31:16. */
+#define R_AARCH64_MOVW_UABS_G1_NC 266 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_UABS_G2 267 /* Dir. MOVZ imm. from bits 47:32. */
+#define R_AARCH64_MOVW_UABS_G2_NC 268 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_UABS_G3 269 /* Dir. MOV{K,Z} imm. from 63:48. */
+#define R_AARCH64_MOVW_SABS_G0 270 /* Dir. MOV{N,Z} imm. from 15:0. */
+#define R_AARCH64_MOVW_SABS_G1 271 /* Dir. MOV{N,Z} imm. from 31:16. */
+#define R_AARCH64_MOVW_SABS_G2 272 /* Dir. MOV{N,Z} imm. from 47:32. */
+#define R_AARCH64_LD_PREL_LO19 273 /* PC-rel. LD imm. from bits 20:2. */
+#define R_AARCH64_ADR_PREL_LO21 274 /* PC-rel. ADR imm. from bits 20:0. */
+#define R_AARCH64_ADR_PREL_PG_HI21 275 /* Page-rel. ADRP imm. from 32:12. */
+#define R_AARCH64_ADR_PREL_PG_HI21_NC 276 /* Likewise; no overflow check. */
+#define R_AARCH64_ADD_ABS_LO12_NC 277 /* Dir. ADD imm. from bits 11:0. */
+#define R_AARCH64_LDST8_ABS_LO12_NC 278 /* Likewise for LD/ST; no check. */
+#define R_AARCH64_TSTBR14 279 /* PC-rel. TBZ/TBNZ imm. from 15:2. */
+#define R_AARCH64_CONDBR19 280 /* PC-rel. cond. br. imm. from 20:2. */
+#define R_AARCH64_JUMP26 282 /* PC-rel. B imm. from bits 27:2. */
+#define R_AARCH64_CALL26 283 /* Likewise for CALL. */
+#define R_AARCH64_LDST16_ABS_LO12_NC 284 /* Dir. ADD imm. from bits 11:1. */
+#define R_AARCH64_LDST32_ABS_LO12_NC 285 /* Likewise for bits 11:2. */
+#define R_AARCH64_LDST64_ABS_LO12_NC 286 /* Likewise for bits 11:3. */
+#define R_AARCH64_MOVW_PREL_G0 287 /* PC-rel. MOV{N,Z} imm. from 15:0. */
+#define R_AARCH64_MOVW_PREL_G0_NC 288 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_PREL_G1 289 /* PC-rel. MOV{N,Z} imm. from 31:16. */
+#define R_AARCH64_MOVW_PREL_G1_NC 290 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_PREL_G2 291 /* PC-rel. MOV{N,Z} imm. from 47:32. */
+#define R_AARCH64_MOVW_PREL_G2_NC 292 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_PREL_G3 293 /* PC-rel. MOV{N,Z} imm. from 63:48. */
+#define R_AARCH64_LDST128_ABS_LO12_NC 299 /* Dir. ADD imm. from bits 11:4. */
+#define R_AARCH64_MOVW_GOTOFF_G0 300 /* GOT-rel. off. MOV{N,Z} imm. 15:0. */
+#define R_AARCH64_MOVW_GOTOFF_G0_NC 301 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_GOTOFF_G1 302 /* GOT-rel. o. MOV{N,Z} imm. 31:16. */
+#define R_AARCH64_MOVW_GOTOFF_G1_NC 303 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_GOTOFF_G2 304 /* GOT-rel. o. MOV{N,Z} imm. 47:32. */
+#define R_AARCH64_MOVW_GOTOFF_G2_NC 305 /* Likewise for MOVK; no check. */
+#define R_AARCH64_MOVW_GOTOFF_G3 306 /* GOT-rel. o. MOV{N,Z} imm. 63:48. */
+#define R_AARCH64_GOTREL64 307 /* GOT-relative 64-bit. */
+#define R_AARCH64_GOTREL32 308 /* GOT-relative 32-bit. */
+#define R_AARCH64_GOT_LD_PREL19 309 /* PC-rel. GOT off. load imm. 20:2. */
+#define R_AARCH64_LD64_GOTOFF_LO15 310 /* GOT-rel. off. LD/ST imm. 14:3. */
+#define R_AARCH64_ADR_GOT_PAGE 311 /* P-page-rel. GOT off. ADRP 32:12. */
+#define R_AARCH64_LD64_GOT_LO12_NC 312 /* Dir. GOT off. LD/ST imm. 11:3. */
+#define R_AARCH64_LD64_GOTPAGE_LO15 313 /* GOT-page-rel. GOT off. LD/ST 14:3 */
+#define R_AARCH64_TLSGD_ADR_PREL21 512 /* PC-relative ADR imm. 20:0. */
+#define R_AARCH64_TLSGD_ADR_PAGE21 513 /* page-rel. ADRP imm. 32:12. */
+#define R_AARCH64_TLSGD_ADD_LO12_NC 514 /* direct ADD imm. from 11:0. */
+#define R_AARCH64_TLSGD_MOVW_G1 515 /* GOT-rel. MOV{N,Z} 31:16. */
+#define R_AARCH64_TLSGD_MOVW_G0_NC 516 /* GOT-rel. MOVK imm. 15:0. */
+#define R_AARCH64_TLSLD_ADR_PREL21 517 /* Like 512; local dynamic model. */
+#define R_AARCH64_TLSLD_ADR_PAGE21 518 /* Like 513; local dynamic model. */
+#define R_AARCH64_TLSLD_ADD_LO12_NC 519 /* Like 514; local dynamic model. */
+#define R_AARCH64_TLSLD_MOVW_G1 520 /* Like 515; local dynamic model. */
+#define R_AARCH64_TLSLD_MOVW_G0_NC 521 /* Like 516; local dynamic model. */
+#define R_AARCH64_TLSLD_LD_PREL19 522 /* TLS PC-rel. load imm. 20:2. */
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 /* TLS DTP-rel. MOV{N,Z} 47:32. */
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 /* TLS DTP-rel. MOV{N,Z} 31:16. */
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 /* Likewise; MOVK; no check. */
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 /* TLS DTP-rel. MOV{N,Z} 15:0. */
+#define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 /* Likewise; MOVK; no check. */
+#define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 /* DTP-rel. ADD imm. from 23:12. */
+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 /* DTP-rel. ADD imm. from 11:0. */
+#define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 /* Likewise; no ovfl. check. */
+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 /* DTP-rel. LD/ST imm. 11:0. */
+#define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 /* Likewise; no check. */
+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 /* DTP-rel. LD/ST imm. 11:1. */
+#define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 /* Likewise; no check. */
+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 /* DTP-rel. LD/ST imm. 11:2. */
+#define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 /* Likewise; no check. */
+#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 /* DTP-rel. LD/ST imm. 11:3. */
+#define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 /* Likewise; no check. */
+#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 /* GOT-rel. MOV{N,Z} 31:16. */
+#define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 /* GOT-rel. MOVK 15:0. */
+#define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 /* Page-rel. ADRP 32:12. */
+#define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 /* Direct LD off. 11:3. */
+#define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 /* PC-rel. load imm. 20:2. */
+#define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 /* TLS TP-rel. MOV{N,Z} 47:32. */
+#define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 /* TLS TP-rel. MOV{N,Z} 31:16. */
+#define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 /* Likewise; MOVK; no check. */
+#define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 /* TLS TP-rel. MOV{N,Z} 15:0. */
+#define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 /* Likewise; MOVK; no check. */
+#define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 /* TP-rel. ADD imm. 23:12. */
+#define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 /* TP-rel. ADD imm. 11:0. */
+#define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 /* Likewise; no ovfl. check. */
+#define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 /* TP-rel. LD/ST off. 11:0. */
+#define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 /* Likewise; no ovfl. check. */
+#define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 /* TP-rel. LD/ST off. 11:1. */
+#define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 /* Likewise; no check. */
+#define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 /* TP-rel. LD/ST off. 11:2. */
+#define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 /* Likewise; no check. */
+#define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 /* TP-rel. LD/ST off. 11:3. */
+#define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 /* Likewise; no check. */
+#define R_AARCH64_TLSDESC_LD_PREL19 560 /* PC-rel. load immediate 20:2. */
+#define R_AARCH64_TLSDESC_ADR_PREL21 561 /* PC-rel. ADR immediate 20:0. */
+#define R_AARCH64_TLSDESC_ADR_PAGE21 562 /* Page-rel. ADRP imm. 32:12. */
+#define R_AARCH64_TLSDESC_LD64_LO12 563 /* Direct LD off. from 11:3. */
+#define R_AARCH64_TLSDESC_ADD_LO12 564 /* Direct ADD imm. from 11:0. */
+#define R_AARCH64_TLSDESC_OFF_G1 565 /* GOT-rel. MOV{N,Z} imm. 31:16. */
+#define R_AARCH64_TLSDESC_OFF_G0_NC 566 /* GOT-rel. MOVK imm. 15:0; no ck. */
+#define R_AARCH64_TLSDESC_LDR 567 /* Relax LDR. */
+#define R_AARCH64_TLSDESC_ADD 568 /* Relax ADD. */
+#define R_AARCH64_TLSDESC_CALL 569 /* Relax BLR. */
+#define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 /* TP-rel. LD/ST off. 11:4. */
+#define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 /* Likewise; no check. */
+#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 /* DTP-rel. LD/ST imm. 11:4. */
+#define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 /* Likewise; no check. */
+#define R_AARCH64_COPY 1024 /* Copy symbol at runtime. */
+#define R_AARCH64_GLOB_DAT 1025 /* Create GOT entry. */
+#define R_AARCH64_JUMP_SLOT 1026 /* Create PLT entry. */
+#define R_AARCH64_RELATIVE 1027 /* Adjust by program base. */
+#define R_AARCH64_TLS_DTPMOD 1028 /* Module number, 64 bit. */
+#define R_AARCH64_TLS_DTPREL 1029 /* Module-relative offset, 64 bit. */
+#define R_AARCH64_TLS_TPREL 1030 /* TP-relative offset, 64 bit. */
+#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
+#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */
+
+/* MTE memory tag segment type. */
+#define PT_AARCH64_MEMTAG_MTE (PT_LOPROC + 2)
+
+/* AArch64 specific values for the Dyn d_tag field. */
+#define DT_AARCH64_BTI_PLT (DT_LOPROC + 1)
+#define DT_AARCH64_PAC_PLT (DT_LOPROC + 3)
+#define DT_AARCH64_VARIANT_PCS (DT_LOPROC + 5)
+#define DT_AARCH64_NUM 6
+
+/* AArch64 specific values for the st_other field. */
+#define STO_AARCH64_VARIANT_PCS 0x80
+
+/* ARM relocs. */
+
+#define R_ARM_NONE 0 /* No reloc */
+#define R_ARM_PC24 1 /* Deprecated PC relative 26
+ bit branch. */
+#define R_ARM_ABS32 2 /* Direct 32 bit */
+#define R_ARM_REL32 3 /* PC relative 32 bit */
+#define R_ARM_PC13 4
+#define R_ARM_ABS16 5 /* Direct 16 bit */
+#define R_ARM_ABS12 6 /* Direct 12 bit */
+#define R_ARM_THM_ABS5 7 /* Direct & 0x7C (LDR, STR). */
+#define R_ARM_ABS8 8 /* Direct 8 bit */
+#define R_ARM_SBREL32 9
+#define R_ARM_THM_PC22 10 /* PC relative 24 bit (Thumb32 BL). */
+#define R_ARM_THM_PC8 11 /* PC relative & 0x3FC
+ (Thumb16 LDR, ADD, ADR). */
+#define R_ARM_AMP_VCALL9 12
+#define R_ARM_SWI24 13 /* Obsolete static relocation. */
+#define R_ARM_TLS_DESC 13 /* Dynamic relocation. */
+#define R_ARM_THM_SWI8 14 /* Reserved. */
+#define R_ARM_XPC25 15 /* Reserved. */
+#define R_ARM_THM_XPC22 16 /* Reserved. */
+#define R_ARM_TLS_DTPMOD32 17 /* ID of module containing symbol */
+#define R_ARM_TLS_DTPOFF32 18 /* Offset in TLS block */
+#define R_ARM_TLS_TPOFF32 19 /* Offset in static TLS block */
+#define R_ARM_COPY 20 /* Copy symbol at runtime */
+#define R_ARM_GLOB_DAT 21 /* Create GOT entry */
+#define R_ARM_JUMP_SLOT 22 /* Create PLT entry */
+#define R_ARM_RELATIVE 23 /* Adjust by program base */
+#define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */
+#define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */
+#define R_ARM_GOT32 26 /* 32 bit GOT entry */
+#define R_ARM_PLT32 27 /* Deprecated, 32 bit PLT address. */
+#define R_ARM_CALL 28 /* PC relative 24 bit (BL, BLX). */
+#define R_ARM_JUMP24 29 /* PC relative 24 bit
+ (B, BL). */
+#define R_ARM_THM_JUMP24 30 /* PC relative 24 bit (Thumb32 B.W). */
+#define R_ARM_BASE_ABS 31 /* Adjust by program base. */
+#define R_ARM_ALU_PCREL_7_0 32 /* Obsolete. */
+#define R_ARM_ALU_PCREL_15_8 33 /* Obsolete. */
+#define R_ARM_ALU_PCREL_23_15 34 /* Obsolete. */
+#define R_ARM_LDR_SBREL_11_0 35 /* Deprecated, prog. base relative. */
+#define R_ARM_ALU_SBREL_19_12 36 /* Deprecated, prog. base relative. */
+#define R_ARM_ALU_SBREL_27_20 37 /* Deprecated, prog. base relative. */
+#define R_ARM_TARGET1 38
+#define R_ARM_SBREL31 39 /* Program base relative. */
+#define R_ARM_V4BX 40
+#define R_ARM_TARGET2 41
+#define R_ARM_PREL31 42 /* 32 bit PC relative. */
+#define R_ARM_MOVW_ABS_NC 43 /* Direct 16-bit (MOVW). */
+#define R_ARM_MOVT_ABS 44 /* Direct high 16-bit (MOVT). */
+#define R_ARM_MOVW_PREL_NC 45 /* PC relative 16-bit (MOVW). */
+#define R_ARM_MOVT_PREL 46 /* PC relative (MOVT). */
+#define R_ARM_THM_MOVW_ABS_NC 47 /* Direct 16 bit (Thumb32 MOVW). */
+#define R_ARM_THM_MOVT_ABS 48 /* Direct high 16 bit
+ (Thumb32 MOVT). */
+#define R_ARM_THM_MOVW_PREL_NC 49 /* PC relative 16 bit
+ (Thumb32 MOVW). */
+#define R_ARM_THM_MOVT_PREL 50 /* PC relative high 16 bit
+ (Thumb32 MOVT). */
+#define R_ARM_THM_JUMP19 51 /* PC relative 20 bit
+ (Thumb32 B.W). */
+#define R_ARM_THM_JUMP6 52 /* PC relative X & 0x7E
+ (Thumb16 CBZ, CBNZ). */
+#define R_ARM_THM_ALU_PREL_11_0 53 /* PC relative 12 bit
+ (Thumb32 ADR.W). */
+#define R_ARM_THM_PC12 54 /* PC relative 12 bit
+ (Thumb32 LDR{D,SB,H,SH}). */
+#define R_ARM_ABS32_NOI 55 /* Direct 32-bit. */
+#define R_ARM_REL32_NOI 56 /* PC relative 32-bit. */
+#define R_ARM_ALU_PC_G0_NC 57 /* PC relative (ADD, SUB). */
+#define R_ARM_ALU_PC_G0 58 /* PC relative (ADD, SUB). */
+#define R_ARM_ALU_PC_G1_NC 59 /* PC relative (ADD, SUB). */
+#define R_ARM_ALU_PC_G1 60 /* PC relative (ADD, SUB). */
+#define R_ARM_ALU_PC_G2 61 /* PC relative (ADD, SUB). */
+#define R_ARM_LDR_PC_G1 62 /* PC relative (LDR,STR,LDRB,STRB). */
+#define R_ARM_LDR_PC_G2 63 /* PC relative (LDR,STR,LDRB,STRB). */
+#define R_ARM_LDRS_PC_G0 64 /* PC relative (STR{D,H},
+ LDR{D,SB,H,SH}). */
+#define R_ARM_LDRS_PC_G1 65 /* PC relative (STR{D,H},
+ LDR{D,SB,H,SH}). */
+#define R_ARM_LDRS_PC_G2 66 /* PC relative (STR{D,H},
+ LDR{D,SB,H,SH}). */
+#define R_ARM_LDC_PC_G0 67 /* PC relative (LDC, STC). */
+#define R_ARM_LDC_PC_G1 68 /* PC relative (LDC, STC). */
+#define R_ARM_LDC_PC_G2 69 /* PC relative (LDC, STC). */
+#define R_ARM_ALU_SB_G0_NC 70 /* Program base relative (ADD,SUB). */
+#define R_ARM_ALU_SB_G0 71 /* Program base relative (ADD,SUB). */
+#define R_ARM_ALU_SB_G1_NC 72 /* Program base relative (ADD,SUB). */
+#define R_ARM_ALU_SB_G1 73 /* Program base relative (ADD,SUB). */
+#define R_ARM_ALU_SB_G2 74 /* Program base relative (ADD,SUB). */
+#define R_ARM_LDR_SB_G0 75 /* Program base relative (LDR,
+ STR, LDRB, STRB). */
+#define R_ARM_LDR_SB_G1 76 /* Program base relative
+ (LDR, STR, LDRB, STRB). */
+#define R_ARM_LDR_SB_G2 77 /* Program base relative
+ (LDR, STR, LDRB, STRB). */
+#define R_ARM_LDRS_SB_G0 78 /* Program base relative
+ (LDR, STR, LDRB, STRB). */
+#define R_ARM_LDRS_SB_G1 79 /* Program base relative
+ (LDR, STR, LDRB, STRB). */
+#define R_ARM_LDRS_SB_G2 80 /* Program base relative
+ (LDR, STR, LDRB, STRB). */
+#define R_ARM_LDC_SB_G0 81 /* Program base relative (LDC,STC). */
+#define R_ARM_LDC_SB_G1 82 /* Program base relative (LDC,STC). */
+#define R_ARM_LDC_SB_G2 83 /* Program base relative (LDC,STC). */
+#define R_ARM_MOVW_BREL_NC 84 /* Program base relative 16
+ bit (MOVW). */
+#define R_ARM_MOVT_BREL 85 /* Program base relative high
+ 16 bit (MOVT). */
+#define R_ARM_MOVW_BREL 86 /* Program base relative 16
+ bit (MOVW). */
+#define R_ARM_THM_MOVW_BREL_NC 87 /* Program base relative 16
+ bit (Thumb32 MOVW). */
+#define R_ARM_THM_MOVT_BREL 88 /* Program base relative high
+ 16 bit (Thumb32 MOVT). */
+#define R_ARM_THM_MOVW_BREL 89 /* Program base relative 16
+ bit (Thumb32 MOVW). */
+#define R_ARM_TLS_GOTDESC 90
+#define R_ARM_TLS_CALL 91
+#define R_ARM_TLS_DESCSEQ 92 /* TLS relaxation. */
+#define R_ARM_THM_TLS_CALL 93
+#define R_ARM_PLT32_ABS 94
+#define R_ARM_GOT_ABS 95 /* GOT entry. */
+#define R_ARM_GOT_PREL 96 /* PC relative GOT entry. */
+#define R_ARM_GOT_BREL12 97 /* GOT entry relative to GOT
+ origin (LDR). */
+#define R_ARM_GOTOFF12 98 /* 12 bit, GOT entry relative
+ to GOT origin (LDR, STR). */
+#define R_ARM_GOTRELAX 99
+#define R_ARM_GNU_VTENTRY 100
+#define R_ARM_GNU_VTINHERIT 101
+#define R_ARM_THM_PC11 102 /* PC relative & 0xFFE (Thumb16 B). */
+#define R_ARM_THM_PC9 103 /* PC relative & 0x1FE
+ (Thumb16 B/B). */
+#define R_ARM_TLS_GD32 104 /* PC-rel 32 bit for global dynamic
+ thread local data */
+#define R_ARM_TLS_LDM32 105 /* PC-rel 32 bit for local dynamic
+ thread local data */
+#define R_ARM_TLS_LDO32 106 /* 32 bit offset relative to TLS
+ block */
+#define R_ARM_TLS_IE32 107 /* PC-rel 32 bit for GOT entry of
+ static TLS block offset */
+#define R_ARM_TLS_LE32 108 /* 32 bit offset relative to static
+ TLS block */
+#define R_ARM_TLS_LDO12 109 /* 12 bit relative to TLS
+ block (LDR, STR). */
+#define R_ARM_TLS_LE12 110 /* 12 bit relative to static
+ TLS block (LDR, STR). */
+#define R_ARM_TLS_IE12GP 111 /* 12 bit GOT entry relative
+ to GOT origin (LDR). */
+#define R_ARM_ME_TOO 128 /* Obsolete. */
+#define R_ARM_THM_TLS_DESCSEQ 129
+#define R_ARM_THM_TLS_DESCSEQ16 129
+#define R_ARM_THM_TLS_DESCSEQ32 130
+#define R_ARM_THM_GOT_BREL12 131 /* GOT entry relative to GOT
+ origin, 12 bit (Thumb32 LDR). */
+#define R_ARM_IRELATIVE 160
+#define R_ARM_RXPC25 249
+#define R_ARM_RSBREL32 250
+#define R_ARM_THM_RPC22 251
+#define R_ARM_RREL32 252
+#define R_ARM_RABS22 253
+#define R_ARM_RPC24 254
+#define R_ARM_RBASE 255
+/* Keep this the last entry. */
+#define R_ARM_NUM 256
+
+/* C-SKY */
+#define R_CKCORE_NONE 0 /* no reloc */
+#define R_CKCORE_ADDR32 1 /* direct 32 bit (S + A) */
+#define R_CKCORE_PCRELIMM8BY4 2 /* disp ((S + A - P) >> 2) & 0xff */
+#define R_CKCORE_PCRELIMM11BY2 3 /* disp ((S + A - P) >> 1) & 0x7ff */
+#define R_CKCORE_PCREL32 5 /* 32-bit rel (S + A - P) */
+#define R_CKCORE_PCRELJSR_IMM11BY2 6 /* disp ((S + A - P) >>1) & 0x7ff */
+#define R_CKCORE_RELATIVE 9 /* 32 bit adjust program base(B + A)*/
+#define R_CKCORE_COPY 10 /* 32 bit adjust by program base */
+#define R_CKCORE_GLOB_DAT 11 /* off between got and sym (S) */
+#define R_CKCORE_JUMP_SLOT 12 /* PLT entry (S) */
+#define R_CKCORE_GOTOFF 13 /* offset to GOT (S + A - GOT) */
+#define R_CKCORE_GOTPC 14 /* PC offset to GOT (GOT + A - P) */
+#define R_CKCORE_GOT32 15 /* 32 bit GOT entry (G) */
+#define R_CKCORE_PLT32 16 /* 32 bit PLT entry (G) */
+#define R_CKCORE_ADDRGOT 17 /* GOT entry in GLOB_DAT (GOT + G) */
+#define R_CKCORE_ADDRPLT 18 /* PLT entry in GLOB_DAT (GOT + G) */
+#define R_CKCORE_PCREL_IMM26BY2 19 /* ((S + A - P) >> 1) & 0x3ffffff */
+#define R_CKCORE_PCREL_IMM16BY2 20 /* disp ((S + A - P) >> 1) & 0xffff */
+#define R_CKCORE_PCREL_IMM16BY4 21 /* disp ((S + A - P) >> 2) & 0xffff */
+#define R_CKCORE_PCREL_IMM10BY2 22 /* disp ((S + A - P) >> 1) & 0x3ff */
+#define R_CKCORE_PCREL_IMM10BY4 23 /* disp ((S + A - P) >> 2) & 0x3ff */
+#define R_CKCORE_ADDR_HI16 24 /* high & low 16 bit ADDR */
+ /* ((S + A) >> 16) & 0xffff */
+#define R_CKCORE_ADDR_LO16 25 /* (S + A) & 0xffff */
+#define R_CKCORE_GOTPC_HI16 26 /* high & low 16 bit GOTPC */
+ /* ((GOT + A - P) >> 16) & 0xffff */
+#define R_CKCORE_GOTPC_LO16 27 /* (GOT + A - P) & 0xffff */
+#define R_CKCORE_GOTOFF_HI16 28 /* high & low 16 bit GOTOFF */
+ /* ((S + A - GOT) >> 16) & 0xffff */
+#define R_CKCORE_GOTOFF_LO16 29 /* (S + A - GOT) & 0xffff */
+#define R_CKCORE_GOT12 30 /* 12 bit disp GOT entry (G) */
+#define R_CKCORE_GOT_HI16 31 /* high & low 16 bit GOT */
+ /* (G >> 16) & 0xffff */
+#define R_CKCORE_GOT_LO16 32 /* (G & 0xffff) */
+#define R_CKCORE_PLT12 33 /* 12 bit disp PLT entry (G) */
+#define R_CKCORE_PLT_HI16 34 /* high & low 16 bit PLT */
+ /* (G >> 16) & 0xffff */
+#define R_CKCORE_PLT_LO16 35 /* G & 0xffff */
+#define R_CKCORE_ADDRGOT_HI16 36 /* high & low 16 bit ADDRGOT */
+ /* (GOT + G * 4) & 0xffff */
+#define R_CKCORE_ADDRGOT_LO16 37 /* (GOT + G * 4) & 0xffff */
+#define R_CKCORE_ADDRPLT_HI16 38 /* high & low 16 bit ADDRPLT */
+ /* ((GOT + G * 4) >> 16) & 0xFFFF */
+#define R_CKCORE_ADDRPLT_LO16 39 /* (GOT+G*4) & 0xffff */
+#define R_CKCORE_PCREL_JSR_IMM26BY2 40 /* disp ((S+A-P) >>1) & x3ffffff */
+#define R_CKCORE_TOFFSET_LO16 41 /* (S+A-BTEXT) & 0xffff */
+#define R_CKCORE_DOFFSET_LO16 42 /* (S+A-BTEXT) & 0xffff */
+#define R_CKCORE_PCREL_IMM18BY2 43 /* disp ((S+A-P) >>1) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18 44 /* disp (S+A-BDATA) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18BY2 45 /* disp ((S+A-BDATA)>>1) & 0x3ffff */
+#define R_CKCORE_DOFFSET_IMM18BY4 46 /* disp ((S+A-BDATA)>>2) & 0x3ffff */
+#define R_CKCORE_GOT_IMM18BY4 48 /* disp (G >> 2) */
+#define R_CKCORE_PLT_IMM18BY4 49 /* disp (G >> 2) */
+#define R_CKCORE_PCREL_IMM7BY4 50 /* disp ((S+A-P) >>2) & 0x7f */
+#define R_CKCORE_TLS_LE32 51 /* 32 bit offset to TLS block */
+#define R_CKCORE_TLS_IE32 52
+#define R_CKCORE_TLS_GD32 53
+#define R_CKCORE_TLS_LDM32 54
+#define R_CKCORE_TLS_LDO32 55
+#define R_CKCORE_TLS_DTPMOD32 56
+#define R_CKCORE_TLS_DTPOFF32 57
+#define R_CKCORE_TLS_TPOFF32 58
+
+/* C-SKY elf header definition. */
+#define EF_CSKY_ABIMASK 0XF0000000
+#define EF_CSKY_OTHER 0X0FFF0000
+#define EF_CSKY_PROCESSOR 0X0000FFFF
+
+#define EF_CSKY_ABIV1 0X10000000
+#define EF_CSKY_ABIV2 0X20000000
+
+/* C-SKY attributes section. */
+#define SHT_CSKY_ATTRIBUTES (SHT_LOPROC + 1)
+
+/* IA-64 specific declarations. */
+
+/* Processor specific flags for the Ehdr e_flags field. */
+#define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */
+#define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */
+#define EF_IA_64_ARCH 0xff000000 /* arch. version mask */
+
+/* Processor specific values for the Phdr p_type field. */
+#define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */
+#define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */
+#define PT_IA_64_HP_OPT_ANOT (PT_LOOS + 0x12)
+#define PT_IA_64_HP_HSL_ANOT (PT_LOOS + 0x13)
+#define PT_IA_64_HP_STACK (PT_LOOS + 0x14)
+
+/* Processor specific flags for the Phdr p_flags field. */
+#define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */
+
+/* Processor specific values for the Shdr sh_type field. */
+#define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */
+#define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */
+
+/* Processor specific flags for the Shdr sh_flags field. */
+#define SHF_IA_64_SHORT 0x10000000 /* section near gp */
+#define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */
+
+/* Processor specific values for the Dyn d_tag field. */
+#define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0)
+#define DT_IA_64_NUM 1
+
+/* IA-64 relocations. */
+#define R_IA64_NONE 0x00 /* none */
+#define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */
+#define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */
+#define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */
+#define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */
+#define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */
+#define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */
+#define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */
+#define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */
+#define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */
+#define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */
+#define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */
+#define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */
+#define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */
+#define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */
+#define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */
+#define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */
+#define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */
+#define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */
+#define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */
+#define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */
+#define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */
+#define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */
+#define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */
+#define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */
+#define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */
+#define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */
+#define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */
+#define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */
+#define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */
+#define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */
+#define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */
+#define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */
+#define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */
+#define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */
+#define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */
+#define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */
+#define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */
+#define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */
+#define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */
+#define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */
+#define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */
+#define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */
+#define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */
+#define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */
+#define R_IA64_REL32MSB 0x6c /* data 4 + REL */
+#define R_IA64_REL32LSB 0x6d /* data 4 + REL */
+#define R_IA64_REL64MSB 0x6e /* data 8 + REL */
+#define R_IA64_REL64LSB 0x6f /* data 8 + REL */
+#define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */
+#define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */
+#define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */
+#define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */
+#define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */
+#define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */
+#define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */
+#define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */
+#define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */
+#define R_IA64_COPY 0x84 /* copy relocation */
+#define R_IA64_SUB 0x85 /* Addend and symbol difference */
+#define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */
+#define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */
+#define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */
+#define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */
+#define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */
+#define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */
+#define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */
+#define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */
+#define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */
+#define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */
+#define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */
+#define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */
+#define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */
+#define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */
+#define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */
+#define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */
+#define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */
+#define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */
+
+/* SH specific declarations */
+
+/* Processor specific flags for the ELF header e_flags field. */
+#define EF_SH_MACH_MASK 0x1f
+#define EF_SH_UNKNOWN 0x0
+#define EF_SH1 0x1
+#define EF_SH2 0x2
+#define EF_SH3 0x3
+#define EF_SH_DSP 0x4
+#define EF_SH3_DSP 0x5
+#define EF_SH4AL_DSP 0x6
+#define EF_SH3E 0x8
+#define EF_SH4 0x9
+#define EF_SH2E 0xb
+#define EF_SH4A 0xc
+#define EF_SH2A 0xd
+#define EF_SH4_NOFPU 0x10
+#define EF_SH4A_NOFPU 0x11
+#define EF_SH4_NOMMU_NOFPU 0x12
+#define EF_SH2A_NOFPU 0x13
+#define EF_SH3_NOMMU 0x14
+#define EF_SH2A_SH4_NOFPU 0x15
+#define EF_SH2A_SH3_NOFPU 0x16
+#define EF_SH2A_SH4 0x17
+#define EF_SH2A_SH3E 0x18
+
+/* SH relocs. */
+#define R_SH_NONE 0
+#define R_SH_DIR32 1
+#define R_SH_REL32 2
+#define R_SH_DIR8WPN 3
+#define R_SH_IND12W 4
+#define R_SH_DIR8WPL 5
+#define R_SH_DIR8WPZ 6
+#define R_SH_DIR8BP 7
+#define R_SH_DIR8W 8
+#define R_SH_DIR8L 9
+#define R_SH_SWITCH16 25
+#define R_SH_SWITCH32 26
+#define R_SH_USES 27
+#define R_SH_COUNT 28
+#define R_SH_ALIGN 29
+#define R_SH_CODE 30
+#define R_SH_DATA 31
+#define R_SH_LABEL 32
+#define R_SH_SWITCH8 33
+#define R_SH_GNU_VTINHERIT 34
+#define R_SH_GNU_VTENTRY 35
+#define R_SH_TLS_GD_32 144
+#define R_SH_TLS_LD_32 145
+#define R_SH_TLS_LDO_32 146
+#define R_SH_TLS_IE_32 147
+#define R_SH_TLS_LE_32 148
+#define R_SH_TLS_DTPMOD32 149
+#define R_SH_TLS_DTPOFF32 150
+#define R_SH_TLS_TPOFF32 151
+#define R_SH_GOT32 160
+#define R_SH_PLT32 161
+#define R_SH_COPY 162
+#define R_SH_GLOB_DAT 163
+#define R_SH_JMP_SLOT 164
+#define R_SH_RELATIVE 165
+#define R_SH_GOTOFF 166
+#define R_SH_GOTPC 167
+/* Keep this the last entry. */
+#define R_SH_NUM 256
+
+/* S/390 specific definitions. */
+
+/* Valid values for the e_flags field. */
+
+#define EF_S390_HIGH_GPRS 0x00000001 /* High GPRs kernel facility needed. */
+
+/* Additional s390 relocs */
+
+#define R_390_NONE 0 /* No reloc. */
+#define R_390_8 1 /* Direct 8 bit. */
+#define R_390_12 2 /* Direct 12 bit. */
+#define R_390_16 3 /* Direct 16 bit. */
+#define R_390_32 4 /* Direct 32 bit. */
+#define R_390_PC32 5 /* PC relative 32 bit. */
+#define R_390_GOT12 6 /* 12 bit GOT offset. */
+#define R_390_GOT32 7 /* 32 bit GOT offset. */
+#define R_390_PLT32 8 /* 32 bit PC relative PLT address. */
+#define R_390_COPY 9 /* Copy symbol at runtime. */
+#define R_390_GLOB_DAT 10 /* Create GOT entry. */
+#define R_390_JMP_SLOT 11 /* Create PLT entry. */
+#define R_390_RELATIVE 12 /* Adjust by program base. */
+#define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */
+#define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */
+#define R_390_GOT16 15 /* 16 bit GOT offset. */
+#define R_390_PC16 16 /* PC relative 16 bit. */
+#define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */
+#define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */
+#define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */
+#define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */
+#define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */
+#define R_390_64 22 /* Direct 64 bit. */
+#define R_390_PC64 23 /* PC relative 64 bit. */
+#define R_390_GOT64 24 /* 64 bit GOT offset. */
+#define R_390_PLT64 25 /* 64 bit PC relative PLT address. */
+#define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */
+#define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */
+#define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */
+#define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */
+#define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */
+#define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */
+#define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */
+#define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */
+#define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */
+#define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */
+#define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */
+#define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */
+#define R_390_TLS_GDCALL 38 /* Tag for function call in general
+ dynamic TLS code. */
+#define R_390_TLS_LDCALL 39 /* Tag for function call in local
+ dynamic TLS code. */
+#define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic
+ thread local data. */
+#define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic
+ thread local data. */
+#define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS
+ block offset. */
+#define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS
+ block offset. */
+#define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS
+ block offset. */
+#define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic
+ thread local data in LE code. */
+#define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic
+ thread local data in LE code. */
+#define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for
+ negated static TLS block offset. */
+#define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for
+ negated static TLS block offset. */
+#define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for
+ negated static TLS block offset. */
+#define R_390_TLS_LE32 50 /* 32 bit negated offset relative to
+ static TLS block. */
+#define R_390_TLS_LE64 51 /* 64 bit negated offset relative to
+ static TLS block. */
+#define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS
+ block. */
+#define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS
+ block. */
+#define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */
+#define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */
+#define R_390_TLS_TPOFF 56 /* Negated offset in static TLS
+ block. */
+#define R_390_20 57 /* Direct 20 bit. */
+#define R_390_GOT20 58 /* 20 bit GOT offset. */
+#define R_390_GOTPLT20 59 /* 20 bit offset to jump slot. */
+#define R_390_TLS_GOTIE20 60 /* 20 bit GOT offset for static TLS
+ block offset. */
+#define R_390_IRELATIVE 61 /* STT_GNU_IFUNC relocation. */
+/* Keep this the last entry. */
+#define R_390_NUM 62
+
+
+/* CRIS relocations. */
+#define R_CRIS_NONE 0
+#define R_CRIS_8 1
+#define R_CRIS_16 2
+#define R_CRIS_32 3
+#define R_CRIS_8_PCREL 4
+#define R_CRIS_16_PCREL 5
+#define R_CRIS_32_PCREL 6
+#define R_CRIS_GNU_VTINHERIT 7
+#define R_CRIS_GNU_VTENTRY 8
+#define R_CRIS_COPY 9
+#define R_CRIS_GLOB_DAT 10
+#define R_CRIS_JUMP_SLOT 11
+#define R_CRIS_RELATIVE 12
+#define R_CRIS_16_GOT 13
+#define R_CRIS_32_GOT 14
+#define R_CRIS_16_GOTPLT 15
+#define R_CRIS_32_GOTPLT 16
+#define R_CRIS_32_GOTREL 17
+#define R_CRIS_32_PLT_GOTREL 18
+#define R_CRIS_32_PLT_PCREL 19
+
+#define R_CRIS_NUM 20
+
+
+/* AMD x86-64 relocations. */
+#define R_X86_64_NONE 0 /* No reloc */
+#define R_X86_64_64 1 /* Direct 64 bit */
+#define R_X86_64_PC32 2 /* PC relative 32 bit signed */
+#define R_X86_64_GOT32 3 /* 32 bit GOT entry */
+#define R_X86_64_PLT32 4 /* 32 bit PLT address */
+#define R_X86_64_COPY 5 /* Copy symbol at runtime */
+#define R_X86_64_GLOB_DAT 6 /* Create GOT entry */
+#define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */
+#define R_X86_64_RELATIVE 8 /* Adjust by program base */
+#define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative
+ offset to GOT */
+#define R_X86_64_32 10 /* Direct 32 bit zero extended */
+#define R_X86_64_32S 11 /* Direct 32 bit sign extended */
+#define R_X86_64_16 12 /* Direct 16 bit zero extended */
+#define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */
+#define R_X86_64_8 14 /* Direct 8 bit sign extended */
+#define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */
+#define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */
+#define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */
+#define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */
+#define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset
+ to two GOT entries for GD symbol */
+#define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset
+ to two GOT entries for LD symbol */
+#define R_X86_64_DTPOFF32 21 /* Offset in TLS block */
+#define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset
+ to GOT entry for IE symbol */
+#define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */
+#define R_X86_64_PC64 24 /* PC relative 64 bit */
+#define R_X86_64_GOTOFF64 25 /* 64 bit offset to GOT */
+#define R_X86_64_GOTPC32 26 /* 32 bit signed pc relative
+ offset to GOT */
+#define R_X86_64_GOT64 27 /* 64-bit GOT entry offset */
+#define R_X86_64_GOTPCREL64 28 /* 64-bit PC relative offset
+ to GOT entry */
+#define R_X86_64_GOTPC64 29 /* 64-bit PC relative offset to GOT */
+#define R_X86_64_GOTPLT64 30 /* like GOT64, says PLT entry needed */
+#define R_X86_64_PLTOFF64 31 /* 64-bit GOT relative offset
+ to PLT entry */
+#define R_X86_64_SIZE32 32 /* Size of symbol plus 32-bit addend */
+#define R_X86_64_SIZE64 33 /* Size of symbol plus 64-bit addend */
+#define R_X86_64_GOTPC32_TLSDESC 34 /* GOT offset for TLS descriptor. */
+#define R_X86_64_TLSDESC_CALL 35 /* Marker for call through TLS
+ descriptor. */
+#define R_X86_64_TLSDESC 36 /* TLS descriptor. */
+#define R_X86_64_IRELATIVE 37 /* Adjust indirectly by program base */
+#define R_X86_64_RELATIVE64 38 /* 64-bit adjust by program base */
+ /* 39 Reserved was R_X86_64_PC32_BND */
+ /* 40 Reserved was R_X86_64_PLT32_BND */
+#define R_X86_64_GOTPCRELX 41 /* Load from 32 bit signed pc relative
+ offset to GOT entry without REX
+ prefix, relaxable. */
+#define R_X86_64_REX_GOTPCRELX 42 /* Load from 32 bit signed pc relative
+ offset to GOT entry with REX prefix,
+ relaxable. */
+#define R_X86_64_NUM 43
+
+/* x86-64 sh_type values. */
+#define SHT_X86_64_UNWIND 0x70000001 /* Unwind information. */
+
+/* x86-64 d_tag values. */
+#define DT_X86_64_PLT (DT_LOPROC + 0)
+#define DT_X86_64_PLTSZ (DT_LOPROC + 1)
+#define DT_X86_64_PLTENT (DT_LOPROC + 3)
+#define DT_X86_64_NUM 4
+
+/* AM33 relocations. */
+#define R_MN10300_NONE 0 /* No reloc. */
+#define R_MN10300_32 1 /* Direct 32 bit. */
+#define R_MN10300_16 2 /* Direct 16 bit. */
+#define R_MN10300_8 3 /* Direct 8 bit. */
+#define R_MN10300_PCREL32 4 /* PC-relative 32-bit. */
+#define R_MN10300_PCREL16 5 /* PC-relative 16-bit signed. */
+#define R_MN10300_PCREL8 6 /* PC-relative 8-bit signed. */
+#define R_MN10300_GNU_VTINHERIT 7 /* Ancient C++ vtable garbage... */
+#define R_MN10300_GNU_VTENTRY 8 /* ... collection annotation. */
+#define R_MN10300_24 9 /* Direct 24 bit. */
+#define R_MN10300_GOTPC32 10 /* 32-bit PCrel offset to GOT. */
+#define R_MN10300_GOTPC16 11 /* 16-bit PCrel offset to GOT. */
+#define R_MN10300_GOTOFF32 12 /* 32-bit offset from GOT. */
+#define R_MN10300_GOTOFF24 13 /* 24-bit offset from GOT. */
+#define R_MN10300_GOTOFF16 14 /* 16-bit offset from GOT. */
+#define R_MN10300_PLT32 15 /* 32-bit PCrel to PLT entry. */
+#define R_MN10300_PLT16 16 /* 16-bit PCrel to PLT entry. */
+#define R_MN10300_GOT32 17 /* 32-bit offset to GOT entry. */
+#define R_MN10300_GOT24 18 /* 24-bit offset to GOT entry. */
+#define R_MN10300_GOT16 19 /* 16-bit offset to GOT entry. */
+#define R_MN10300_COPY 20 /* Copy symbol at runtime. */
+#define R_MN10300_GLOB_DAT 21 /* Create GOT entry. */
+#define R_MN10300_JMP_SLOT 22 /* Create PLT entry. */
+#define R_MN10300_RELATIVE 23 /* Adjust by program base. */
+#define R_MN10300_TLS_GD 24 /* 32-bit offset for global dynamic. */
+#define R_MN10300_TLS_LD 25 /* 32-bit offset for local dynamic. */
+#define R_MN10300_TLS_LDO 26 /* Module-relative offset. */
+#define R_MN10300_TLS_GOTIE 27 /* GOT offset for static TLS block
+ offset. */
+#define R_MN10300_TLS_IE 28 /* GOT address for static TLS block
+ offset. */
+#define R_MN10300_TLS_LE 29 /* Offset relative to static TLS
+ block. */
+#define R_MN10300_TLS_DTPMOD 30 /* ID of module containing symbol. */
+#define R_MN10300_TLS_DTPOFF 31 /* Offset in module TLS block. */
+#define R_MN10300_TLS_TPOFF 32 /* Offset in static TLS block. */
+#define R_MN10300_SYM_DIFF 33 /* Adjustment for next reloc as needed
+ by linker relaxation. */
+#define R_MN10300_ALIGN 34 /* Alignment requirement for linker
+ relaxation. */
+#define R_MN10300_NUM 35
+
+
+/* M32R relocs. */
+#define R_M32R_NONE 0 /* No reloc. */
+#define R_M32R_16 1 /* Direct 16 bit. */
+#define R_M32R_32 2 /* Direct 32 bit. */
+#define R_M32R_24 3 /* Direct 24 bit. */
+#define R_M32R_10_PCREL 4 /* PC relative 10 bit shifted. */
+#define R_M32R_18_PCREL 5 /* PC relative 18 bit shifted. */
+#define R_M32R_26_PCREL 6 /* PC relative 26 bit shifted. */
+#define R_M32R_HI16_ULO 7 /* High 16 bit with unsigned low. */
+#define R_M32R_HI16_SLO 8 /* High 16 bit with signed low. */
+#define R_M32R_LO16 9 /* Low 16 bit. */
+#define R_M32R_SDA16 10 /* 16 bit offset in SDA. */
+#define R_M32R_GNU_VTINHERIT 11
+#define R_M32R_GNU_VTENTRY 12
+/* M32R relocs use SHT_RELA. */
+#define R_M32R_16_RELA 33 /* Direct 16 bit. */
+#define R_M32R_32_RELA 34 /* Direct 32 bit. */
+#define R_M32R_24_RELA 35 /* Direct 24 bit. */
+#define R_M32R_10_PCREL_RELA 36 /* PC relative 10 bit shifted. */
+#define R_M32R_18_PCREL_RELA 37 /* PC relative 18 bit shifted. */
+#define R_M32R_26_PCREL_RELA 38 /* PC relative 26 bit shifted. */
+#define R_M32R_HI16_ULO_RELA 39 /* High 16 bit with unsigned low */
+#define R_M32R_HI16_SLO_RELA 40 /* High 16 bit with signed low */
+#define R_M32R_LO16_RELA 41 /* Low 16 bit */
+#define R_M32R_SDA16_RELA 42 /* 16 bit offset in SDA */
+#define R_M32R_RELA_GNU_VTINHERIT 43
+#define R_M32R_RELA_GNU_VTENTRY 44
+#define R_M32R_REL32 45 /* PC relative 32 bit. */
+
+#define R_M32R_GOT24 48 /* 24 bit GOT entry */
+#define R_M32R_26_PLTREL 49 /* 26 bit PC relative to PLT shifted */
+#define R_M32R_COPY 50 /* Copy symbol at runtime */
+#define R_M32R_GLOB_DAT 51 /* Create GOT entry */
+#define R_M32R_JMP_SLOT 52 /* Create PLT entry */
+#define R_M32R_RELATIVE 53 /* Adjust by program base */
+#define R_M32R_GOTOFF 54 /* 24 bit offset to GOT */
+#define R_M32R_GOTPC24 55 /* 24 bit PC relative offset to GOT */
+#define R_M32R_GOT16_HI_ULO 56 /* High 16 bit GOT entry with unsigned
+ low */
+#define R_M32R_GOT16_HI_SLO 57 /* High 16 bit GOT entry with signed
+ low */
+#define R_M32R_GOT16_LO 58 /* Low 16 bit GOT entry */
+#define R_M32R_GOTPC_HI_ULO 59 /* High 16 bit PC relative offset to
+ GOT with unsigned low */
+#define R_M32R_GOTPC_HI_SLO 60 /* High 16 bit PC relative offset to
+ GOT with signed low */
+#define R_M32R_GOTPC_LO 61 /* Low 16 bit PC relative offset to
+ GOT */
+#define R_M32R_GOTOFF_HI_ULO 62 /* High 16 bit offset to GOT
+ with unsigned low */
+#define R_M32R_GOTOFF_HI_SLO 63 /* High 16 bit offset to GOT
+ with signed low */
+#define R_M32R_GOTOFF_LO 64 /* Low 16 bit offset to GOT */
+#define R_M32R_NUM 256 /* Keep this the last entry. */
+
+/* MicroBlaze relocations */
+#define R_MICROBLAZE_NONE 0 /* No reloc. */
+#define R_MICROBLAZE_32 1 /* Direct 32 bit. */
+#define R_MICROBLAZE_32_PCREL 2 /* PC relative 32 bit. */
+#define R_MICROBLAZE_64_PCREL 3 /* PC relative 64 bit. */
+#define R_MICROBLAZE_32_PCREL_LO 4 /* Low 16 bits of PCREL32. */
+#define R_MICROBLAZE_64 5 /* Direct 64 bit. */
+#define R_MICROBLAZE_32_LO 6 /* Low 16 bit. */
+#define R_MICROBLAZE_SRO32 7 /* Read-only small data area. */
+#define R_MICROBLAZE_SRW32 8 /* Read-write small data area. */
+#define R_MICROBLAZE_64_NONE 9 /* No reloc. */
+#define R_MICROBLAZE_32_SYM_OP_SYM 10 /* Symbol Op Symbol relocation. */
+#define R_MICROBLAZE_GNU_VTINHERIT 11 /* GNU C++ vtable hierarchy. */
+#define R_MICROBLAZE_GNU_VTENTRY 12 /* GNU C++ vtable member usage. */
+#define R_MICROBLAZE_GOTPC_64 13 /* PC-relative GOT offset. */
+#define R_MICROBLAZE_GOT_64 14 /* GOT entry offset. */
+#define R_MICROBLAZE_PLT_64 15 /* PLT offset (PC-relative). */
+#define R_MICROBLAZE_REL 16 /* Adjust by program base. */
+#define R_MICROBLAZE_JUMP_SLOT 17 /* Create PLT entry. */
+#define R_MICROBLAZE_GLOB_DAT 18 /* Create GOT entry. */
+#define R_MICROBLAZE_GOTOFF_64 19 /* 64 bit offset to GOT. */
+#define R_MICROBLAZE_GOTOFF_32 20 /* 32 bit offset to GOT. */
+#define R_MICROBLAZE_COPY 21 /* Runtime copy. */
+#define R_MICROBLAZE_TLS 22 /* TLS Reloc. */
+#define R_MICROBLAZE_TLSGD 23 /* TLS General Dynamic. */
+#define R_MICROBLAZE_TLSLD 24 /* TLS Local Dynamic. */
+#define R_MICROBLAZE_TLSDTPMOD32 25 /* TLS Module ID. */
+#define R_MICROBLAZE_TLSDTPREL32 26 /* TLS Offset Within TLS Block. */
+#define R_MICROBLAZE_TLSDTPREL64 27 /* TLS Offset Within TLS Block. */
+#define R_MICROBLAZE_TLSGOTTPREL32 28 /* TLS Offset From Thread Pointer. */
+#define R_MICROBLAZE_TLSTPREL32 29 /* TLS Offset From Thread Pointer. */
+
+/* Legal values for d_tag (dynamic entry type). */
+#define DT_NIOS2_GP 0x70000002 /* Address of _gp. */
+
+/* Nios II relocations. */
+#define R_NIOS2_NONE 0 /* No reloc. */
+#define R_NIOS2_S16 1 /* Direct signed 16 bit. */
+#define R_NIOS2_U16 2 /* Direct unsigned 16 bit. */
+#define R_NIOS2_PCREL16 3 /* PC relative 16 bit. */
+#define R_NIOS2_CALL26 4 /* Direct call. */
+#define R_NIOS2_IMM5 5 /* 5 bit constant expression. */
+#define R_NIOS2_CACHE_OPX 6 /* 5 bit expression, shift 22. */
+#define R_NIOS2_IMM6 7 /* 6 bit constant expression. */
+#define R_NIOS2_IMM8 8 /* 8 bit constant expression. */
+#define R_NIOS2_HI16 9 /* High 16 bit. */
+#define R_NIOS2_LO16 10 /* Low 16 bit. */
+#define R_NIOS2_HIADJ16 11 /* High 16 bit, adjusted. */
+#define R_NIOS2_BFD_RELOC_32 12 /* 32 bit symbol value + addend. */
+#define R_NIOS2_BFD_RELOC_16 13 /* 16 bit symbol value + addend. */
+#define R_NIOS2_BFD_RELOC_8 14 /* 8 bit symbol value + addend. */
+#define R_NIOS2_GPREL 15 /* 16 bit GP pointer offset. */
+#define R_NIOS2_GNU_VTINHERIT 16 /* GNU C++ vtable hierarchy. */
+#define R_NIOS2_GNU_VTENTRY 17 /* GNU C++ vtable member usage. */
+#define R_NIOS2_UJMP 18 /* Unconditional branch. */
+#define R_NIOS2_CJMP 19 /* Conditional branch. */
+#define R_NIOS2_CALLR 20 /* Indirect call through register. */
+#define R_NIOS2_ALIGN 21 /* Alignment requirement for
+ linker relaxation. */
+#define R_NIOS2_GOT16 22 /* 16 bit GOT entry. */
+#define R_NIOS2_CALL16 23 /* 16 bit GOT entry for function. */
+#define R_NIOS2_GOTOFF_LO 24 /* %lo of offset to GOT pointer. */
+#define R_NIOS2_GOTOFF_HA 25 /* %hiadj of offset to GOT pointer. */
+#define R_NIOS2_PCREL_LO 26 /* %lo of PC relative offset. */
+#define R_NIOS2_PCREL_HA 27 /* %hiadj of PC relative offset. */
+#define R_NIOS2_TLS_GD16 28 /* 16 bit GOT offset for TLS GD. */
+#define R_NIOS2_TLS_LDM16 29 /* 16 bit GOT offset for TLS LDM. */
+#define R_NIOS2_TLS_LDO16 30 /* 16 bit module relative offset. */
+#define R_NIOS2_TLS_IE16 31 /* 16 bit GOT offset for TLS IE. */
+#define R_NIOS2_TLS_LE16 32 /* 16 bit LE TP-relative offset. */
+#define R_NIOS2_TLS_DTPMOD 33 /* Module number. */
+#define R_NIOS2_TLS_DTPREL 34 /* Module-relative offset. */
+#define R_NIOS2_TLS_TPREL 35 /* TP-relative offset. */
+#define R_NIOS2_COPY 36 /* Copy symbol at runtime. */
+#define R_NIOS2_GLOB_DAT 37 /* Create GOT entry. */
+#define R_NIOS2_JUMP_SLOT 38 /* Create PLT entry. */
+#define R_NIOS2_RELATIVE 39 /* Adjust by program base. */
+#define R_NIOS2_GOTOFF 40 /* 16 bit offset to GOT pointer. */
+#define R_NIOS2_CALL26_NOAT 41 /* Direct call in .noat section. */
+#define R_NIOS2_GOT_LO 42 /* %lo() of GOT entry. */
+#define R_NIOS2_GOT_HA 43 /* %hiadj() of GOT entry. */
+#define R_NIOS2_CALL_LO 44 /* %lo() of function GOT entry. */
+#define R_NIOS2_CALL_HA 45 /* %hiadj() of function GOT entry. */
+
+/* TILEPro relocations. */
+#define R_TILEPRO_NONE 0 /* No reloc */
+#define R_TILEPRO_32 1 /* Direct 32 bit */
+#define R_TILEPRO_16 2 /* Direct 16 bit */
+#define R_TILEPRO_8 3 /* Direct 8 bit */
+#define R_TILEPRO_32_PCREL 4 /* PC relative 32 bit */
+#define R_TILEPRO_16_PCREL 5 /* PC relative 16 bit */
+#define R_TILEPRO_8_PCREL 6 /* PC relative 8 bit */
+#define R_TILEPRO_LO16 7 /* Low 16 bit */
+#define R_TILEPRO_HI16 8 /* High 16 bit */
+#define R_TILEPRO_HA16 9 /* High 16 bit, adjusted */
+#define R_TILEPRO_COPY 10 /* Copy relocation */
+#define R_TILEPRO_GLOB_DAT 11 /* Create GOT entry */
+#define R_TILEPRO_JMP_SLOT 12 /* Create PLT entry */
+#define R_TILEPRO_RELATIVE 13 /* Adjust by program base */
+#define R_TILEPRO_BROFF_X1 14 /* X1 pipe branch offset */
+#define R_TILEPRO_JOFFLONG_X1 15 /* X1 pipe jump offset */
+#define R_TILEPRO_JOFFLONG_X1_PLT 16 /* X1 pipe jump offset to PLT */
+#define R_TILEPRO_IMM8_X0 17 /* X0 pipe 8-bit */
+#define R_TILEPRO_IMM8_Y0 18 /* Y0 pipe 8-bit */
+#define R_TILEPRO_IMM8_X1 19 /* X1 pipe 8-bit */
+#define R_TILEPRO_IMM8_Y1 20 /* Y1 pipe 8-bit */
+#define R_TILEPRO_MT_IMM15_X1 21 /* X1 pipe mtspr */
+#define R_TILEPRO_MF_IMM15_X1 22 /* X1 pipe mfspr */
+#define R_TILEPRO_IMM16_X0 23 /* X0 pipe 16-bit */
+#define R_TILEPRO_IMM16_X1 24 /* X1 pipe 16-bit */
+#define R_TILEPRO_IMM16_X0_LO 25 /* X0 pipe low 16-bit */
+#define R_TILEPRO_IMM16_X1_LO 26 /* X1 pipe low 16-bit */
+#define R_TILEPRO_IMM16_X0_HI 27 /* X0 pipe high 16-bit */
+#define R_TILEPRO_IMM16_X1_HI 28 /* X1 pipe high 16-bit */
+#define R_TILEPRO_IMM16_X0_HA 29 /* X0 pipe high 16-bit, adjusted */
+#define R_TILEPRO_IMM16_X1_HA 30 /* X1 pipe high 16-bit, adjusted */
+#define R_TILEPRO_IMM16_X0_PCREL 31 /* X0 pipe PC relative 16 bit */
+#define R_TILEPRO_IMM16_X1_PCREL 32 /* X1 pipe PC relative 16 bit */
+#define R_TILEPRO_IMM16_X0_LO_PCREL 33 /* X0 pipe PC relative low 16 bit */
+#define R_TILEPRO_IMM16_X1_LO_PCREL 34 /* X1 pipe PC relative low 16 bit */
+#define R_TILEPRO_IMM16_X0_HI_PCREL 35 /* X0 pipe PC relative high 16 bit */
+#define R_TILEPRO_IMM16_X1_HI_PCREL 36 /* X1 pipe PC relative high 16 bit */
+#define R_TILEPRO_IMM16_X0_HA_PCREL 37 /* X0 pipe PC relative ha() 16 bit */
+#define R_TILEPRO_IMM16_X1_HA_PCREL 38 /* X1 pipe PC relative ha() 16 bit */
+#define R_TILEPRO_IMM16_X0_GOT 39 /* X0 pipe 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X1_GOT 40 /* X1 pipe 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X0_GOT_LO 41 /* X0 pipe low 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X1_GOT_LO 42 /* X1 pipe low 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X0_GOT_HI 43 /* X0 pipe high 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X1_GOT_HI 44 /* X1 pipe high 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X0_GOT_HA 45 /* X0 pipe ha() 16-bit GOT offset */
+#define R_TILEPRO_IMM16_X1_GOT_HA 46 /* X1 pipe ha() 16-bit GOT offset */
+#define R_TILEPRO_MMSTART_X0 47 /* X0 pipe mm "start" */
+#define R_TILEPRO_MMEND_X0 48 /* X0 pipe mm "end" */
+#define R_TILEPRO_MMSTART_X1 49 /* X1 pipe mm "start" */
+#define R_TILEPRO_MMEND_X1 50 /* X1 pipe mm "end" */
+#define R_TILEPRO_SHAMT_X0 51 /* X0 pipe shift amount */
+#define R_TILEPRO_SHAMT_X1 52 /* X1 pipe shift amount */
+#define R_TILEPRO_SHAMT_Y0 53 /* Y0 pipe shift amount */
+#define R_TILEPRO_SHAMT_Y1 54 /* Y1 pipe shift amount */
+#define R_TILEPRO_DEST_IMM8_X1 55 /* X1 pipe destination 8-bit */
+/* Relocs 56-59 are currently not defined. */
+#define R_TILEPRO_TLS_GD_CALL 60 /* "jal" for TLS GD */
+#define R_TILEPRO_IMM8_X0_TLS_GD_ADD 61 /* X0 pipe "addi" for TLS GD */
+#define R_TILEPRO_IMM8_X1_TLS_GD_ADD 62 /* X1 pipe "addi" for TLS GD */
+#define R_TILEPRO_IMM8_Y0_TLS_GD_ADD 63 /* Y0 pipe "addi" for TLS GD */
+#define R_TILEPRO_IMM8_Y1_TLS_GD_ADD 64 /* Y1 pipe "addi" for TLS GD */
+#define R_TILEPRO_TLS_IE_LOAD 65 /* "lw_tls" for TLS IE */
+#define R_TILEPRO_IMM16_X0_TLS_GD 66 /* X0 pipe 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X1_TLS_GD 67 /* X1 pipe 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X0_TLS_GD_LO 68 /* X0 pipe low 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X1_TLS_GD_LO 69 /* X1 pipe low 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X0_TLS_GD_HI 70 /* X0 pipe high 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X1_TLS_GD_HI 71 /* X1 pipe high 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X0_TLS_GD_HA 72 /* X0 pipe ha() 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X1_TLS_GD_HA 73 /* X1 pipe ha() 16-bit TLS GD offset */
+#define R_TILEPRO_IMM16_X0_TLS_IE 74 /* X0 pipe 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X1_TLS_IE 75 /* X1 pipe 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X0_TLS_IE_LO 76 /* X0 pipe low 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X1_TLS_IE_LO 77 /* X1 pipe low 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X0_TLS_IE_HI 78 /* X0 pipe high 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X1_TLS_IE_HI 79 /* X1 pipe high 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X0_TLS_IE_HA 80 /* X0 pipe ha() 16-bit TLS IE offset */
+#define R_TILEPRO_IMM16_X1_TLS_IE_HA 81 /* X1 pipe ha() 16-bit TLS IE offset */
+#define R_TILEPRO_TLS_DTPMOD32 82 /* ID of module containing symbol */
+#define R_TILEPRO_TLS_DTPOFF32 83 /* Offset in TLS block */
+#define R_TILEPRO_TLS_TPOFF32 84 /* Offset in static TLS block */
+#define R_TILEPRO_IMM16_X0_TLS_LE 85 /* X0 pipe 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X1_TLS_LE 86 /* X1 pipe 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X0_TLS_LE_LO 87 /* X0 pipe low 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X1_TLS_LE_LO 88 /* X1 pipe low 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X0_TLS_LE_HI 89 /* X0 pipe high 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X1_TLS_LE_HI 90 /* X1 pipe high 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X0_TLS_LE_HA 91 /* X0 pipe ha() 16-bit TLS LE offset */
+#define R_TILEPRO_IMM16_X1_TLS_LE_HA 92 /* X1 pipe ha() 16-bit TLS LE offset */
+
+#define R_TILEPRO_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */
+#define R_TILEPRO_GNU_VTENTRY 129 /* GNU C++ vtable member usage */
+
+#define R_TILEPRO_NUM 130
+
+
+/* TILE-Gx relocations. */
+#define R_TILEGX_NONE 0 /* No reloc */
+#define R_TILEGX_64 1 /* Direct 64 bit */
+#define R_TILEGX_32 2 /* Direct 32 bit */
+#define R_TILEGX_16 3 /* Direct 16 bit */
+#define R_TILEGX_8 4 /* Direct 8 bit */
+#define R_TILEGX_64_PCREL 5 /* PC relative 64 bit */
+#define R_TILEGX_32_PCREL 6 /* PC relative 32 bit */
+#define R_TILEGX_16_PCREL 7 /* PC relative 16 bit */
+#define R_TILEGX_8_PCREL 8 /* PC relative 8 bit */
+#define R_TILEGX_HW0 9 /* hword 0 16-bit */
+#define R_TILEGX_HW1 10 /* hword 1 16-bit */
+#define R_TILEGX_HW2 11 /* hword 2 16-bit */
+#define R_TILEGX_HW3 12 /* hword 3 16-bit */
+#define R_TILEGX_HW0_LAST 13 /* last hword 0 16-bit */
+#define R_TILEGX_HW1_LAST 14 /* last hword 1 16-bit */
+#define R_TILEGX_HW2_LAST 15 /* last hword 2 16-bit */
+#define R_TILEGX_COPY 16 /* Copy relocation */
+#define R_TILEGX_GLOB_DAT 17 /* Create GOT entry */
+#define R_TILEGX_JMP_SLOT 18 /* Create PLT entry */
+#define R_TILEGX_RELATIVE 19 /* Adjust by program base */
+#define R_TILEGX_BROFF_X1 20 /* X1 pipe branch offset */
+#define R_TILEGX_JUMPOFF_X1 21 /* X1 pipe jump offset */
+#define R_TILEGX_JUMPOFF_X1_PLT 22 /* X1 pipe jump offset to PLT */
+#define R_TILEGX_IMM8_X0 23 /* X0 pipe 8-bit */
+#define R_TILEGX_IMM8_Y0 24 /* Y0 pipe 8-bit */
+#define R_TILEGX_IMM8_X1 25 /* X1 pipe 8-bit */
+#define R_TILEGX_IMM8_Y1 26 /* Y1 pipe 8-bit */
+#define R_TILEGX_DEST_IMM8_X1 27 /* X1 pipe destination 8-bit */
+#define R_TILEGX_MT_IMM14_X1 28 /* X1 pipe mtspr */
+#define R_TILEGX_MF_IMM14_X1 29 /* X1 pipe mfspr */
+#define R_TILEGX_MMSTART_X0 30 /* X0 pipe mm "start" */
+#define R_TILEGX_MMEND_X0 31 /* X0 pipe mm "end" */
+#define R_TILEGX_SHAMT_X0 32 /* X0 pipe shift amount */
+#define R_TILEGX_SHAMT_X1 33 /* X1 pipe shift amount */
+#define R_TILEGX_SHAMT_Y0 34 /* Y0 pipe shift amount */
+#define R_TILEGX_SHAMT_Y1 35 /* Y1 pipe shift amount */
+#define R_TILEGX_IMM16_X0_HW0 36 /* X0 pipe hword 0 */
+#define R_TILEGX_IMM16_X1_HW0 37 /* X1 pipe hword 0 */
+#define R_TILEGX_IMM16_X0_HW1 38 /* X0 pipe hword 1 */
+#define R_TILEGX_IMM16_X1_HW1 39 /* X1 pipe hword 1 */
+#define R_TILEGX_IMM16_X0_HW2 40 /* X0 pipe hword 2 */
+#define R_TILEGX_IMM16_X1_HW2 41 /* X1 pipe hword 2 */
+#define R_TILEGX_IMM16_X0_HW3 42 /* X0 pipe hword 3 */
+#define R_TILEGX_IMM16_X1_HW3 43 /* X1 pipe hword 3 */
+#define R_TILEGX_IMM16_X0_HW0_LAST 44 /* X0 pipe last hword 0 */
+#define R_TILEGX_IMM16_X1_HW0_LAST 45 /* X1 pipe last hword 0 */
+#define R_TILEGX_IMM16_X0_HW1_LAST 46 /* X0 pipe last hword 1 */
+#define R_TILEGX_IMM16_X1_HW1_LAST 47 /* X1 pipe last hword 1 */
+#define R_TILEGX_IMM16_X0_HW2_LAST 48 /* X0 pipe last hword 2 */
+#define R_TILEGX_IMM16_X1_HW2_LAST 49 /* X1 pipe last hword 2 */
+#define R_TILEGX_IMM16_X0_HW0_PCREL 50 /* X0 pipe PC relative hword 0 */
+#define R_TILEGX_IMM16_X1_HW0_PCREL 51 /* X1 pipe PC relative hword 0 */
+#define R_TILEGX_IMM16_X0_HW1_PCREL 52 /* X0 pipe PC relative hword 1 */
+#define R_TILEGX_IMM16_X1_HW1_PCREL 53 /* X1 pipe PC relative hword 1 */
+#define R_TILEGX_IMM16_X0_HW2_PCREL 54 /* X0 pipe PC relative hword 2 */
+#define R_TILEGX_IMM16_X1_HW2_PCREL 55 /* X1 pipe PC relative hword 2 */
+#define R_TILEGX_IMM16_X0_HW3_PCREL 56 /* X0 pipe PC relative hword 3 */
+#define R_TILEGX_IMM16_X1_HW3_PCREL 57 /* X1 pipe PC relative hword 3 */
+#define R_TILEGX_IMM16_X0_HW0_LAST_PCREL 58 /* X0 pipe PC-rel last hword 0 */
+#define R_TILEGX_IMM16_X1_HW0_LAST_PCREL 59 /* X1 pipe PC-rel last hword 0 */
+#define R_TILEGX_IMM16_X0_HW1_LAST_PCREL 60 /* X0 pipe PC-rel last hword 1 */
+#define R_TILEGX_IMM16_X1_HW1_LAST_PCREL 61 /* X1 pipe PC-rel last hword 1 */
+#define R_TILEGX_IMM16_X0_HW2_LAST_PCREL 62 /* X0 pipe PC-rel last hword 2 */
+#define R_TILEGX_IMM16_X1_HW2_LAST_PCREL 63 /* X1 pipe PC-rel last hword 2 */
+#define R_TILEGX_IMM16_X0_HW0_GOT 64 /* X0 pipe hword 0 GOT offset */
+#define R_TILEGX_IMM16_X1_HW0_GOT 65 /* X1 pipe hword 0 GOT offset */
+#define R_TILEGX_IMM16_X0_HW0_PLT_PCREL 66 /* X0 pipe PC-rel PLT hword 0 */
+#define R_TILEGX_IMM16_X1_HW0_PLT_PCREL 67 /* X1 pipe PC-rel PLT hword 0 */
+#define R_TILEGX_IMM16_X0_HW1_PLT_PCREL 68 /* X0 pipe PC-rel PLT hword 1 */
+#define R_TILEGX_IMM16_X1_HW1_PLT_PCREL 69 /* X1 pipe PC-rel PLT hword 1 */
+#define R_TILEGX_IMM16_X0_HW2_PLT_PCREL 70 /* X0 pipe PC-rel PLT hword 2 */
+#define R_TILEGX_IMM16_X1_HW2_PLT_PCREL 71 /* X1 pipe PC-rel PLT hword 2 */
+#define R_TILEGX_IMM16_X0_HW0_LAST_GOT 72 /* X0 pipe last hword 0 GOT offset */
+#define R_TILEGX_IMM16_X1_HW0_LAST_GOT 73 /* X1 pipe last hword 0 GOT offset */
+#define R_TILEGX_IMM16_X0_HW1_LAST_GOT 74 /* X0 pipe last hword 1 GOT offset */
+#define R_TILEGX_IMM16_X1_HW1_LAST_GOT 75 /* X1 pipe last hword 1 GOT offset */
+#define R_TILEGX_IMM16_X0_HW3_PLT_PCREL 76 /* X0 pipe PC-rel PLT hword 3 */
+#define R_TILEGX_IMM16_X1_HW3_PLT_PCREL 77 /* X1 pipe PC-rel PLT hword 3 */
+#define R_TILEGX_IMM16_X0_HW0_TLS_GD 78 /* X0 pipe hword 0 TLS GD offset */
+#define R_TILEGX_IMM16_X1_HW0_TLS_GD 79 /* X1 pipe hword 0 TLS GD offset */
+#define R_TILEGX_IMM16_X0_HW0_TLS_LE 80 /* X0 pipe hword 0 TLS LE offset */
+#define R_TILEGX_IMM16_X1_HW0_TLS_LE 81 /* X1 pipe hword 0 TLS LE offset */
+#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_LE 82 /* X0 pipe last hword 0 LE off */
+#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_LE 83 /* X1 pipe last hword 0 LE off */
+#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_LE 84 /* X0 pipe last hword 1 LE off */
+#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_LE 85 /* X1 pipe last hword 1 LE off */
+#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_GD 86 /* X0 pipe last hword 0 GD off */
+#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_GD 87 /* X1 pipe last hword 0 GD off */
+#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_GD 88 /* X0 pipe last hword 1 GD off */
+#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_GD 89 /* X1 pipe last hword 1 GD off */
+/* Relocs 90-91 are currently not defined. */
+#define R_TILEGX_IMM16_X0_HW0_TLS_IE 92 /* X0 pipe hword 0 TLS IE offset */
+#define R_TILEGX_IMM16_X1_HW0_TLS_IE 93 /* X1 pipe hword 0 TLS IE offset */
+#define R_TILEGX_IMM16_X0_HW0_LAST_PLT_PCREL 94 /* X0 pipe PC-rel PLT last hword 0 */
+#define R_TILEGX_IMM16_X1_HW0_LAST_PLT_PCREL 95 /* X1 pipe PC-rel PLT last hword 0 */
+#define R_TILEGX_IMM16_X0_HW1_LAST_PLT_PCREL 96 /* X0 pipe PC-rel PLT last hword 1 */
+#define R_TILEGX_IMM16_X1_HW1_LAST_PLT_PCREL 97 /* X1 pipe PC-rel PLT last hword 1 */
+#define R_TILEGX_IMM16_X0_HW2_LAST_PLT_PCREL 98 /* X0 pipe PC-rel PLT last hword 2 */
+#define R_TILEGX_IMM16_X1_HW2_LAST_PLT_PCREL 99 /* X1 pipe PC-rel PLT last hword 2 */
+#define R_TILEGX_IMM16_X0_HW0_LAST_TLS_IE 100 /* X0 pipe last hword 0 IE off */
+#define R_TILEGX_IMM16_X1_HW0_LAST_TLS_IE 101 /* X1 pipe last hword 0 IE off */
+#define R_TILEGX_IMM16_X0_HW1_LAST_TLS_IE 102 /* X0 pipe last hword 1 IE off */
+#define R_TILEGX_IMM16_X1_HW1_LAST_TLS_IE 103 /* X1 pipe last hword 1 IE off */
+/* Relocs 104-105 are currently not defined. */
+#define R_TILEGX_TLS_DTPMOD64 106 /* 64-bit ID of symbol's module */
+#define R_TILEGX_TLS_DTPOFF64 107 /* 64-bit offset in TLS block */
+#define R_TILEGX_TLS_TPOFF64 108 /* 64-bit offset in static TLS block */
+#define R_TILEGX_TLS_DTPMOD32 109 /* 32-bit ID of symbol's module */
+#define R_TILEGX_TLS_DTPOFF32 110 /* 32-bit offset in TLS block */
+#define R_TILEGX_TLS_TPOFF32 111 /* 32-bit offset in static TLS block */
+#define R_TILEGX_TLS_GD_CALL 112 /* "jal" for TLS GD */
+#define R_TILEGX_IMM8_X0_TLS_GD_ADD 113 /* X0 pipe "addi" for TLS GD */
+#define R_TILEGX_IMM8_X1_TLS_GD_ADD 114 /* X1 pipe "addi" for TLS GD */
+#define R_TILEGX_IMM8_Y0_TLS_GD_ADD 115 /* Y0 pipe "addi" for TLS GD */
+#define R_TILEGX_IMM8_Y1_TLS_GD_ADD 116 /* Y1 pipe "addi" for TLS GD */
+#define R_TILEGX_TLS_IE_LOAD 117 /* "ld_tls" for TLS IE */
+#define R_TILEGX_IMM8_X0_TLS_ADD 118 /* X0 pipe "addi" for TLS GD/IE */
+#define R_TILEGX_IMM8_X1_TLS_ADD 119 /* X1 pipe "addi" for TLS GD/IE */
+#define R_TILEGX_IMM8_Y0_TLS_ADD 120 /* Y0 pipe "addi" for TLS GD/IE */
+#define R_TILEGX_IMM8_Y1_TLS_ADD 121 /* Y1 pipe "addi" for TLS GD/IE */
+
+#define R_TILEGX_GNU_VTINHERIT 128 /* GNU C++ vtable hierarchy */
+#define R_TILEGX_GNU_VTENTRY 129 /* GNU C++ vtable member usage */
+
+#define R_TILEGX_NUM 130
+
+/* RISC-V ELF Flags */
+#define EF_RISCV_RVC 0x0001
+#define EF_RISCV_FLOAT_ABI 0x0006
+#define EF_RISCV_FLOAT_ABI_SOFT 0x0000
+#define EF_RISCV_FLOAT_ABI_SINGLE 0x0002
+#define EF_RISCV_FLOAT_ABI_DOUBLE 0x0004
+#define EF_RISCV_FLOAT_ABI_QUAD 0x0006
+#define EF_RISCV_RVE 0x0008
+#define EF_RISCV_TSO 0x0010
+
+/* RISC-V relocations. */
+#define R_RISCV_NONE 0
+#define R_RISCV_32 1
+#define R_RISCV_64 2
+#define R_RISCV_RELATIVE 3
+#define R_RISCV_COPY 4
+#define R_RISCV_JUMP_SLOT 5
+#define R_RISCV_TLS_DTPMOD32 6
+#define R_RISCV_TLS_DTPMOD64 7
+#define R_RISCV_TLS_DTPREL32 8
+#define R_RISCV_TLS_DTPREL64 9
+#define R_RISCV_TLS_TPREL32 10
+#define R_RISCV_TLS_TPREL64 11
+#define R_RISCV_BRANCH 16
+#define R_RISCV_JAL 17
+#define R_RISCV_CALL 18
+#define R_RISCV_CALL_PLT 19
+#define R_RISCV_GOT_HI20 20
+#define R_RISCV_TLS_GOT_HI20 21
+#define R_RISCV_TLS_GD_HI20 22
+#define R_RISCV_PCREL_HI20 23
+#define R_RISCV_PCREL_LO12_I 24
+#define R_RISCV_PCREL_LO12_S 25
+#define R_RISCV_HI20 26
+#define R_RISCV_LO12_I 27
+#define R_RISCV_LO12_S 28
+#define R_RISCV_TPREL_HI20 29
+#define R_RISCV_TPREL_LO12_I 30
+#define R_RISCV_TPREL_LO12_S 31
+#define R_RISCV_TPREL_ADD 32
+#define R_RISCV_ADD8 33
+#define R_RISCV_ADD16 34
+#define R_RISCV_ADD32 35
+#define R_RISCV_ADD64 36
+#define R_RISCV_SUB8 37
+#define R_RISCV_SUB16 38
+#define R_RISCV_SUB32 39
+#define R_RISCV_SUB64 40
+#define R_RISCV_GNU_VTINHERIT 41
+#define R_RISCV_GNU_VTENTRY 42
+#define R_RISCV_ALIGN 43
+#define R_RISCV_RVC_BRANCH 44
+#define R_RISCV_RVC_JUMP 45
+#define R_RISCV_RVC_LUI 46
+#define R_RISCV_GPREL_I 47
+#define R_RISCV_GPREL_S 48
+#define R_RISCV_TPREL_I 49
+#define R_RISCV_TPREL_S 50
+#define R_RISCV_RELAX 51
+#define R_RISCV_SUB6 52
+#define R_RISCV_SET6 53
+#define R_RISCV_SET8 54
+#define R_RISCV_SET16 55
+#define R_RISCV_SET32 56
+#define R_RISCV_32_PCREL 57
+#define R_RISCV_IRELATIVE 58
+#define R_RISCV_PLT32 59
+#define R_RISCV_SET_ULEB128 60
+#define R_RISCV_SUB_ULEB128 61
+
+#define R_RISCV_NUM 62
+
+/* RISC-V specific values for the st_other field. */
+#define STO_RISCV_VARIANT_CC 0x80 /* Function uses variant calling
+ convention */
+
+/* RISC-V specific values for the sh_type field. */
+#define SHT_RISCV_ATTRIBUTES (SHT_LOPROC + 3)
+
+/* RISC-V specific values for the p_type field. */
+#define PT_RISCV_ATTRIBUTES (PT_LOPROC + 3)
+
+/* RISC-V specific values for the d_tag field. */
+#define DT_RISCV_VARIANT_CC (DT_LOPROC + 1)
+
+/* BPF specific declarations. */
+
+#define R_BPF_NONE 0 /* No reloc */
+#define R_BPF_64_64 1
+#define R_BPF_64_32 10
+
+/* Imagination Meta specific relocations. */
+
+#define R_METAG_HIADDR16 0
+#define R_METAG_LOADDR16 1
+#define R_METAG_ADDR32 2 /* 32bit absolute address */
+#define R_METAG_NONE 3 /* No reloc */
+#define R_METAG_RELBRANCH 4
+#define R_METAG_GETSETOFF 5
+
+/* Backward compatibility */
+#define R_METAG_REG32OP1 6
+#define R_METAG_REG32OP2 7
+#define R_METAG_REG32OP3 8
+#define R_METAG_REG16OP1 9
+#define R_METAG_REG16OP2 10
+#define R_METAG_REG16OP3 11
+#define R_METAG_REG32OP4 12
+
+#define R_METAG_HIOG 13
+#define R_METAG_LOOG 14
+
+#define R_METAG_REL8 15
+#define R_METAG_REL16 16
+
+/* GNU */
+#define R_METAG_GNU_VTINHERIT 30
+#define R_METAG_GNU_VTENTRY 31
+
+/* PIC relocations */
+#define R_METAG_HI16_GOTOFF 32
+#define R_METAG_LO16_GOTOFF 33
+#define R_METAG_GETSET_GOTOFF 34
+#define R_METAG_GETSET_GOT 35
+#define R_METAG_HI16_GOTPC 36
+#define R_METAG_LO16_GOTPC 37
+#define R_METAG_HI16_PLT 38
+#define R_METAG_LO16_PLT 39
+#define R_METAG_RELBRANCH_PLT 40
+#define R_METAG_GOTOFF 41
+#define R_METAG_PLT 42
+#define R_METAG_COPY 43
+#define R_METAG_JMP_SLOT 44
+#define R_METAG_RELATIVE 45
+#define R_METAG_GLOB_DAT 46
+
+/* TLS relocations */
+#define R_METAG_TLS_GD 47
+#define R_METAG_TLS_LDM 48
+#define R_METAG_TLS_LDO_HI16 49
+#define R_METAG_TLS_LDO_LO16 50
+#define R_METAG_TLS_LDO 51
+#define R_METAG_TLS_IE 52
+#define R_METAG_TLS_IENONPIC 53
+#define R_METAG_TLS_IENONPIC_HI16 54
+#define R_METAG_TLS_IENONPIC_LO16 55
+#define R_METAG_TLS_TPOFF 56
+#define R_METAG_TLS_DTPMOD 57
+#define R_METAG_TLS_DTPOFF 58
+#define R_METAG_TLS_LE 59
+#define R_METAG_TLS_LE_HI16 60
+#define R_METAG_TLS_LE_LO16 61
+
+/* NDS32 relocations. */
+#define R_NDS32_NONE 0
+#define R_NDS32_32_RELA 20
+#define R_NDS32_COPY 39
+#define R_NDS32_GLOB_DAT 40
+#define R_NDS32_JMP_SLOT 41
+#define R_NDS32_RELATIVE 42
+#define R_NDS32_TLS_TPOFF 102
+#define R_NDS32_TLS_DESC 119
+
+/* LoongArch ELF Flags */
+#define EF_LARCH_ABI_MODIFIER_MASK 0x07
+#define EF_LARCH_ABI_SOFT_FLOAT 0x01
+#define EF_LARCH_ABI_SINGLE_FLOAT 0x02
+#define EF_LARCH_ABI_DOUBLE_FLOAT 0x03
+#define EF_LARCH_OBJABI_V1 0x40
+
+/* LoongArch specific dynamic relocations */
+#define R_LARCH_NONE 0
+#define R_LARCH_32 1
+#define R_LARCH_64 2
+#define R_LARCH_RELATIVE 3
+#define R_LARCH_COPY 4
+#define R_LARCH_JUMP_SLOT 5
+#define R_LARCH_TLS_DTPMOD32 6
+#define R_LARCH_TLS_DTPMOD64 7
+#define R_LARCH_TLS_DTPREL32 8
+#define R_LARCH_TLS_DTPREL64 9
+#define R_LARCH_TLS_TPREL32 10
+#define R_LARCH_TLS_TPREL64 11
+#define R_LARCH_IRELATIVE 12
+
+/* Reserved for future relocs that the dynamic linker must understand. */
+
+/* used by the static linker for relocating .text. */
+#define R_LARCH_MARK_LA 20
+#define R_LARCH_MARK_PCREL 21
+#define R_LARCH_SOP_PUSH_PCREL 22
+#define R_LARCH_SOP_PUSH_ABSOLUTE 23
+#define R_LARCH_SOP_PUSH_DUP 24
+#define R_LARCH_SOP_PUSH_GPREL 25
+#define R_LARCH_SOP_PUSH_TLS_TPREL 26
+#define R_LARCH_SOP_PUSH_TLS_GOT 27
+#define R_LARCH_SOP_PUSH_TLS_GD 28
+#define R_LARCH_SOP_PUSH_PLT_PCREL 29
+#define R_LARCH_SOP_ASSERT 30
+#define R_LARCH_SOP_NOT 31
+#define R_LARCH_SOP_SUB 32
+#define R_LARCH_SOP_SL 33
+#define R_LARCH_SOP_SR 34
+#define R_LARCH_SOP_ADD 35
+#define R_LARCH_SOP_AND 36
+#define R_LARCH_SOP_IF_ELSE 37
+#define R_LARCH_SOP_POP_32_S_10_5 38
+#define R_LARCH_SOP_POP_32_U_10_12 39
+#define R_LARCH_SOP_POP_32_S_10_12 40
+#define R_LARCH_SOP_POP_32_S_10_16 41
+#define R_LARCH_SOP_POP_32_S_10_16_S2 42
+#define R_LARCH_SOP_POP_32_S_5_20 43
+#define R_LARCH_SOP_POP_32_S_0_5_10_16_S2 44
+#define R_LARCH_SOP_POP_32_S_0_10_10_16_S2 45
+#define R_LARCH_SOP_POP_32_U 46
+
+/* used by the static linker for relocating non .text. */
+#define R_LARCH_ADD8 47
+#define R_LARCH_ADD16 48
+#define R_LARCH_ADD24 49
+#define R_LARCH_ADD32 50
+#define R_LARCH_ADD64 51
+#define R_LARCH_SUB8 52
+#define R_LARCH_SUB16 53
+#define R_LARCH_SUB24 54
+#define R_LARCH_SUB32 55
+#define R_LARCH_SUB64 56
+#define R_LARCH_GNU_VTINHERIT 57
+#define R_LARCH_GNU_VTENTRY 58
+
+/* reserved 59-63 */
+
+#define R_LARCH_B16 64
+#define R_LARCH_B21 65
+#define R_LARCH_B26 66
+#define R_LARCH_ABS_HI20 67
+#define R_LARCH_ABS_LO12 68
+#define R_LARCH_ABS64_LO20 69
+#define R_LARCH_ABS64_HI12 70
+#define R_LARCH_PCALA_HI20 71
+#define R_LARCH_PCALA_LO12 72
+#define R_LARCH_PCALA64_LO20 73
+#define R_LARCH_PCALA64_HI12 74
+#define R_LARCH_GOT_PC_HI20 75
+#define R_LARCH_GOT_PC_LO12 76
+#define R_LARCH_GOT64_PC_LO20 77
+#define R_LARCH_GOT64_PC_HI12 78
+#define R_LARCH_GOT_HI20 79
+#define R_LARCH_GOT_LO12 80
+#define R_LARCH_GOT64_LO20 81
+#define R_LARCH_GOT64_HI12 82
+#define R_LARCH_TLS_LE_HI20 83
+#define R_LARCH_TLS_LE_LO12 84
+#define R_LARCH_TLS_LE64_LO20 85
+#define R_LARCH_TLS_LE64_HI12 86
+#define R_LARCH_TLS_IE_PC_HI20 87
+#define R_LARCH_TLS_IE_PC_LO12 88
+#define R_LARCH_TLS_IE64_PC_LO20 89
+#define R_LARCH_TLS_IE64_PC_HI12 90
+#define R_LARCH_TLS_IE_HI20 91
+#define R_LARCH_TLS_IE_LO12 92
+#define R_LARCH_TLS_IE64_LO20 93
+#define R_LARCH_TLS_IE64_HI12 94
+#define R_LARCH_TLS_LD_PC_HI20 95
+#define R_LARCH_TLS_LD_HI20 96
+#define R_LARCH_TLS_GD_PC_HI20 97
+#define R_LARCH_TLS_GD_HI20 98
+#define R_LARCH_32_PCREL 99
+#define R_LARCH_RELAX 100
+#define R_LARCH_DELETE 101
+#define R_LARCH_ALIGN 102
+#define R_LARCH_PCREL20_S2 103
+#define R_LARCH_CFA 104
+#define R_LARCH_ADD6 105
+#define R_LARCH_SUB6 106
+#define R_LARCH_ADD_ULEB128 107
+#define R_LARCH_SUB_ULEB128 108
+#define R_LARCH_64_PCREL 109
+#define R_LARCH_CALL36 110
+#define R_LARCH_TLS_DESC_PC_HI20 111
+#define R_LARCH_TLS_DESC_PC_LO12 112
+#define R_LARCH_TLS_DESC64_PC_LO20 113
+#define R_LARCH_TLS_DESC64_PC_HI12 114
+#define R_LARCH_TLS_DESC_HI20 115
+#define R_LARCH_TLS_DESC_LO12 116
+#define R_LARCH_TLS_DESC64_LO20 117
+#define R_LARCH_TLS_DESC64_HI12 118
+#define R_LARCH_TLS_DESC_LD 119
+#define R_LARCH_TLS_DESC_CALL 120
+#define R_LARCH_TLS_LE_HI20_R 121
+#define R_LARCH_TLS_LE_ADD_R 122
+#define R_LARCH_TLS_LE_LO12_R 123
+#define R_LARCH_TLS_LD_PCREL20_S2 124
+#define R_LARCH_TLS_GD_PCREL20_S2 125
+#define R_LARCH_TLS_DESC_PCREL20_S2 126
+
+/* ARC specific declarations. */
+
+/* Processor specific flags for the Ehdr e_flags field. */
+#define EF_ARC_MACH_MSK 0x000000ff
+#define EF_ARC_OSABI_MSK 0x00000f00
+#define EF_ARC_ALL_MSK (EF_ARC_MACH_MSK | EF_ARC_OSABI_MSK)
+
+/* Processor specific values for the Shdr sh_type field. */
+#define SHT_ARC_ATTRIBUTES (SHT_LOPROC + 1) /* ARC attributes section. */
+
+/* ARCompact/ARCv2 specific relocs. */
+#define R_ARC_NONE 0x0
+#define R_ARC_8 0x1
+#define R_ARC_16 0x2
+#define R_ARC_24 0x3
+#define R_ARC_32 0x4
+
+#define R_ARC_B22_PCREL 0x6
+#define R_ARC_H30 0x7
+#define R_ARC_N8 0x8
+#define R_ARC_N16 0x9
+#define R_ARC_N24 0xA
+#define R_ARC_N32 0xB
+#define R_ARC_SDA 0xC
+#define R_ARC_SECTOFF 0xD
+#define R_ARC_S21H_PCREL 0xE
+#define R_ARC_S21W_PCREL 0xF
+#define R_ARC_S25H_PCREL 0x10
+#define R_ARC_S25W_PCREL 0x11
+#define R_ARC_SDA32 0x12
+#define R_ARC_SDA_LDST 0x13
+#define R_ARC_SDA_LDST1 0x14
+#define R_ARC_SDA_LDST2 0x15
+#define R_ARC_SDA16_LD 0x16
+#define R_ARC_SDA16_LD1 0x17
+#define R_ARC_SDA16_LD2 0x18
+#define R_ARC_S13_PCREL 0x19
+#define R_ARC_W 0x1A
+#define R_ARC_32_ME 0x1B
+#define R_ARC_N32_ME 0x1C
+#define R_ARC_SECTOFF_ME 0x1D
+#define R_ARC_SDA32_ME 0x1E
+#define R_ARC_W_ME 0x1F
+#define R_ARC_H30_ME 0x20
+#define R_ARC_SECTOFF_U8 0x21
+#define R_ARC_SECTOFF_S9 0x22
+#define R_AC_SECTOFF_U8 0x23
+#define R_AC_SECTOFF_U8_1 0x24
+#define R_AC_SECTOFF_U8_2 0x25
+#define R_AC_SECTOFF_S9 0x26
+#define R_AC_SECTOFF_S9_1 0x27
+#define R_AC_SECTOFF_S9_2 0x28
+#define R_ARC_SECTOFF_ME_1 0x29
+#define R_ARC_SECTOFF_ME_2 0x2A
+#define R_ARC_SECTOFF_1 0x2B
+#define R_ARC_SECTOFF_2 0x2C
+#define R_ARC_SDA_12 0x2D
+#define R_ARC_SDA16_ST2 0x30
+#define R_ARC_32_PCREL 0x31
+#define R_ARC_PC32 0x32
+#define R_ARC_GOTPC32 0x33
+#define R_ARC_PLT32 0x34
+#define R_ARC_COPY 0x35
+#define R_ARC_GLOB_DAT 0x36
+#define R_ARC_JMP_SLOT 0x37
+#define R_ARC_RELATIVE 0x38
+#define R_ARC_GOTOFF 0x39
+#define R_ARC_GOTPC 0x3A
+#define R_ARC_GOT32 0x3B
+#define R_ARC_S21W_PCREL_PLT 0x3C
+#define R_ARC_S25H_PCREL_PLT 0x3D
+
+#define R_ARC_JLI_SECTOFF 0x3F
+
+#define R_ARC_TLS_DTPMOD 0x42
+#define R_ARC_TLS_DTPOFF 0x43
+#define R_ARC_TLS_TPOFF 0x44
+#define R_ARC_TLS_GD_GOT 0x45
+#define R_ARC_TLS_GD_LD 0x46
+#define R_ARC_TLS_GD_CALL 0x47
+#define R_ARC_TLS_IE_GOT 0x48
+#define R_ARC_TLS_DTPOFF_S9 0x49
+#define R_ARC_TLS_LE_S9 0x4A
+#define R_ARC_TLS_LE_32 0x4B
+#define R_ARC_S25W_PCREL_PLT 0x4C
+#define R_ARC_S21H_PCREL_PLT 0x4D
+#define R_ARC_NPS_CMEM16 0x4E
+
+/* OpenRISC 1000 specific relocs. */
+#define R_OR1K_NONE 0
+#define R_OR1K_32 1
+#define R_OR1K_16 2
+#define R_OR1K_8 3
+#define R_OR1K_LO_16_IN_INSN 4
+#define R_OR1K_HI_16_IN_INSN 5
+#define R_OR1K_INSN_REL_26 6
+#define R_OR1K_GNU_VTENTRY 7
+#define R_OR1K_GNU_VTINHERIT 8
+#define R_OR1K_32_PCREL 9
+#define R_OR1K_16_PCREL 10
+#define R_OR1K_8_PCREL 11
+#define R_OR1K_GOTPC_HI16 12
+#define R_OR1K_GOTPC_LO16 13
+#define R_OR1K_GOT16 14
+#define R_OR1K_PLT26 15
+#define R_OR1K_GOTOFF_HI16 16
+#define R_OR1K_GOTOFF_LO16 17
+#define R_OR1K_COPY 18
+#define R_OR1K_GLOB_DAT 19
+#define R_OR1K_JMP_SLOT 20
+#define R_OR1K_RELATIVE 21
+#define R_OR1K_TLS_GD_HI16 22
+#define R_OR1K_TLS_GD_LO16 23
+#define R_OR1K_TLS_LDM_HI16 24
+#define R_OR1K_TLS_LDM_LO16 25
+#define R_OR1K_TLS_LDO_HI16 26
+#define R_OR1K_TLS_LDO_LO16 27
+#define R_OR1K_TLS_IE_HI16 28
+#define R_OR1K_TLS_IE_LO16 29
+#define R_OR1K_TLS_LE_HI16 30
+#define R_OR1K_TLS_LE_LO16 31
+#define R_OR1K_TLS_TPOFF 32
+#define R_OR1K_TLS_DTPOFF 33
+#define R_OR1K_TLS_DTPMOD 34
+
+#endif /* elf.h */
diff --git a/contrib/libdw/elf32_getchdr.c b/contrib/libdw/elf32_getchdr.c
new file mode 100644
index 0000000..4159130
--- /dev/null
+++ b/contrib/libdw/elf32_getchdr.c
@@ -0,0 +1,45 @@
+/* Return section compression header.
+ Copyright (C) 2015 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libelfP.h"
+#include "common.h"
+
+#ifndef LIBELFBITS
+# define LIBELFBITS 32
+#endif
+
+#define ELF_WRLOCK_HELD 1
+#include "elf32_getchdr.h"
+
+#define ELF_WRLOCK_HELD 0
+#include "elf32_getchdr.h"
\ No newline at end of file
diff --git a/contrib/libdw/elf32_getchdr.h b/contrib/libdw/elf32_getchdr.h
new file mode 100644
index 0000000..04d47e7
--- /dev/null
+++ b/contrib/libdw/elf32_getchdr.h
@@ -0,0 +1,61 @@
+#undef ADD_ROUTINE_PREFIX
+#undef ADD_ROUTINE_SUFFIX
+
+#if ELF_WRLOCK_HELD
+#define CONCAT(x,y) x##y
+#define ADD_ROUTINE_PREFIX(y) CONCAT(__,y)
+#define ADD_ROUTINE_SUFFIX(x) x ## _wrlock
+#define INTERNAL internal_function
+#else
+#define ADD_ROUTINE_PREFIX(y) y
+#define ADD_ROUTINE_SUFFIX(x) x
+#define INTERNAL
+#endif
+
+ElfW2(LIBELFBITS,Chdr) *
+INTERNAL
+ADD_ROUTINE_PREFIX(elfw2(LIBELFBITS, ADD_ROUTINE_SUFFIX(getchdr))) (Elf_Scn *scn)
+{
+
+ ElfW2(LIBELFBITS,Shdr) *shdr = ADD_ROUTINE_PREFIX(elfw2(LIBELFBITS, ADD_ROUTINE_SUFFIX(getshdr)))(scn);
+
+ if (shdr == NULL)
+ return NULL;
+
+ /* Must have SHF_COMPRESSED flag set. Allocated or no bits sections
+ can never be compressed. */
+ if ((shdr->sh_flags & SHF_ALLOC) != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
+ return NULL;
+ }
+
+ if (shdr->sh_type == SHT_NULL
+ || shdr->sh_type == SHT_NOBITS)
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
+ return NULL;
+ }
+
+ if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
+ {
+ __libelf_seterrno (ELF_E_NOT_COMPRESSED);
+ return NULL;
+ }
+
+ /* This makes sure the data is in the correct format, so we don't
+ need to swap fields. */
+ Elf_Data *d = ADD_ROUTINE_PREFIX(ADD_ROUTINE_SUFFIX(elf_getdata)) (scn, NULL);
+ if (d == NULL)
+ return NULL;
+
+ if (d->d_size < sizeof (ElfW2(LIBELFBITS,Chdr)) || d->d_buf == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
+ return (ElfW2(LIBELFBITS,Chdr) *) d->d_buf;
+}
+#undef INTERNAL
+#undef ELF_WRLOCK_HELD
\ No newline at end of file
diff --git a/contrib/libdw/elf32_getshdr.c b/contrib/libdw/elf32_getshdr.c
new file mode 100644
index 0000000..fc69630
--- /dev/null
+++ b/contrib/libdw/elf32_getshdr.c
@@ -0,0 +1,297 @@
+/* Return section header.
+ Copyright (C) 1998-2002, 2005, 2007, 2009, 2012, 2014, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+#include "common.h"
+
+#ifndef LIBELFBITS
+# define LIBELFBITS 32
+#endif
+
+
+static ElfW2(LIBELFBITS,Shdr) *
+load_shdr_wrlock (Elf_Scn *scn)
+{
+ ElfW2(LIBELFBITS,Shdr) *result;
+
+ /* Read the section header table. */
+ Elf *elf = scn->elf;
+ ElfW2(LIBELFBITS,Ehdr) *ehdr = elf->state.ELFW(elf,LIBELFBITS).ehdr;
+
+ /* Try again, maybe the data is there now. */
+ result = scn->shdr.ELFW(e,LIBELFBITS);
+ if (result != NULL)
+ goto out;
+
+ size_t shnum;
+ if (__elf_getshdrnum_rdlock (elf, &shnum) != 0
+ || shnum > SIZE_MAX / sizeof (ElfW2(LIBELFBITS,Shdr)))
+ goto out;
+ size_t size = shnum * sizeof (ElfW2(LIBELFBITS,Shdr));
+
+ /* Allocate memory for the section headers. We know the number
+ of entries from the ELF header. */
+ ElfW2(LIBELFBITS,Shdr) *shdr = elf->state.ELFW(elf,LIBELFBITS).shdr =
+ (ElfW2(LIBELFBITS,Shdr) *) malloc (size);
+ if (elf->state.ELFW(elf,LIBELFBITS).shdr == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto out;
+ }
+ elf->state.ELFW(elf,LIBELFBITS).shdr_malloced = 1;
+
+ if (elf->map_address != NULL)
+ {
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
+ if (unlikely (ehdr->e_shoff >= elf->maximum_size)
+ || unlikely (elf->maximum_size - ehdr->e_shoff < size))
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ goto free_and_out;
+ }
+
+ ElfW2(LIBELFBITS,Shdr) *notcvt;
+
+ /* All the data is already mapped. If we could use it
+ directly this would already have happened. Unless
+ we allocated the memory ourselves and the ELF_F_MALLOCED
+ flag is set. */
+ void *file_shdr = ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff);
+
+ assert ((elf->flags & ELF_F_MALLOCED)
+ || ehdr->e_ident[EI_DATA] != MY_ELFDATA
+ || elf->cmd == ELF_C_READ_MMAP
+ || (! ALLOW_UNALIGNED
+ && ((uintptr_t) file_shdr
+ & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1)) != 0));
+
+ /* Now copy the data and at the same time convert the byte order. */
+ if (ehdr->e_ident[EI_DATA] == MY_ELFDATA)
+ {
+ assert ((elf->flags & ELF_F_MALLOCED)
+ || elf->cmd == ELF_C_READ_MMAP
+ || ! ALLOW_UNALIGNED);
+ memcpy (shdr, file_shdr, size);
+ }
+ else
+ {
+ bool copy = ! (ALLOW_UNALIGNED
+ || ((uintptr_t) file_shdr
+ & (__alignof__ (ElfW2(LIBELFBITS,Shdr)) - 1))
+ == 0);
+ if (! copy)
+ notcvt = (ElfW2(LIBELFBITS,Shdr) *)
+ ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff);
+ else
+ {
+ notcvt = (ElfW2(LIBELFBITS,Shdr) *) malloc (size);
+ if (unlikely (notcvt == NULL))
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto out;
+ }
+ memcpy (notcvt, ((char *) elf->map_address
+ + elf->start_offset + ehdr->e_shoff),
+ size);
+ }
+
+ for (size_t cnt = 0; cnt < shnum; ++cnt)
+ {
+ CONVERT_TO (shdr[cnt].sh_name, notcvt[cnt].sh_name);
+ CONVERT_TO (shdr[cnt].sh_type, notcvt[cnt].sh_type);
+ CONVERT_TO (shdr[cnt].sh_flags, notcvt[cnt].sh_flags);
+ CONVERT_TO (shdr[cnt].sh_addr, notcvt[cnt].sh_addr);
+ CONVERT_TO (shdr[cnt].sh_offset, notcvt[cnt].sh_offset);
+ CONVERT_TO (shdr[cnt].sh_size, notcvt[cnt].sh_size);
+ CONVERT_TO (shdr[cnt].sh_link, notcvt[cnt].sh_link);
+ CONVERT_TO (shdr[cnt].sh_info, notcvt[cnt].sh_info);
+ CONVERT_TO (shdr[cnt].sh_addralign,
+ notcvt[cnt].sh_addralign);
+ CONVERT_TO (shdr[cnt].sh_entsize, notcvt[cnt].sh_entsize);
+
+ /* If this is a section with an extended index add a
+ reference in the section which uses the extended
+ index. */
+ if (shdr[cnt].sh_type == SHT_SYMTAB_SHNDX
+ && shdr[cnt].sh_link < shnum)
+ elf->state.ELFW(elf,LIBELFBITS).scns.data[shdr[cnt].sh_link].shndx_index
+ = cnt;
+
+ /* Set the own shndx_index field in case it has not yet
+ been set. */
+ if (elf->state.ELFW(elf,LIBELFBITS).scns.data[cnt].shndx_index == 0)
+ elf->state.ELFW(elf,LIBELFBITS).scns.data[cnt].shndx_index
+ = -1;
+ }
+
+ if (copy)
+ free (notcvt);
+ }
+ }
+ else if (likely (elf->fildes != -1))
+ {
+ /* Read the header. */
+ ssize_t n = pread_retry (elf->fildes,
+ elf->state.ELFW(elf,LIBELFBITS).shdr, size,
+ elf->start_offset + ehdr->e_shoff);
+ if (unlikely ((size_t) n != size))
+ {
+ /* Severe problems. We cannot read the data. */
+ __libelf_seterrno (ELF_E_READ_ERROR);
+ goto free_and_out;
+ }
+
+ /* If the byte order of the file is not the same as the one
+ of the host convert the data now. */
+ if (ehdr->e_ident[EI_DATA] != MY_ELFDATA)
+ for (size_t cnt = 0; cnt < shnum; ++cnt)
+ {
+ CONVERT (shdr[cnt].sh_name);
+ CONVERT (shdr[cnt].sh_type);
+ CONVERT (shdr[cnt].sh_flags);
+ CONVERT (shdr[cnt].sh_addr);
+ CONVERT (shdr[cnt].sh_offset);
+ CONVERT (shdr[cnt].sh_size);
+ CONVERT (shdr[cnt].sh_link);
+ CONVERT (shdr[cnt].sh_info);
+ CONVERT (shdr[cnt].sh_addralign);
+ CONVERT (shdr[cnt].sh_entsize);
+ }
+ }
+ else
+ {
+ /* The file descriptor was already enabled and not all data was
+ read. Undo the allocation. */
+ __libelf_seterrno (ELF_E_FD_DISABLED);
+
+ free_and_out:
+ free (shdr);
+ elf->state.ELFW(elf,LIBELFBITS).shdr = NULL;
+ elf->state.ELFW(elf,LIBELFBITS).shdr_malloced = 0;
+
+ goto out;
+ }
+
+ /* Set the pointers in the `scn's. */
+ for (size_t cnt = 0; cnt < shnum; ++cnt)
+ elf->state.ELFW(elf,LIBELFBITS).scns.data[cnt].shdr.ELFW(e,LIBELFBITS)
+ = &elf->state.ELFW(elf,LIBELFBITS).shdr[cnt];
+
+ result = scn->shdr.ELFW(e,LIBELFBITS);
+ assert (result != NULL);
+
+out:
+ return result;
+}
+
+static bool
+scn_valid (Elf_Scn *scn)
+{
+ if (scn == NULL)
+ return false;
+
+ if (unlikely (scn->elf->state.elf.ehdr == NULL))
+ {
+ __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
+ return false;
+ }
+
+ if (unlikely (scn->elf->class != ELFW(ELFCLASS,LIBELFBITS)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_CLASS);
+ return false;
+ }
+
+ return true;
+}
+
+ElfW2(LIBELFBITS,Shdr) *
+internal_function
+__elfw2(LIBELFBITS,getshdr_rdlock) (Elf_Scn *scn)
+{
+ ElfW2(LIBELFBITS,Shdr) *result;
+
+ if (!scn_valid (scn))
+ return NULL;
+
+ result = scn->shdr.ELFW(e,LIBELFBITS);
+ if (result == NULL)
+ {
+ rwlock_unlock (scn->elf->lock);
+ rwlock_wrlock (scn->elf->lock);
+ result = scn->shdr.ELFW(e,LIBELFBITS);
+ if (result == NULL)
+ result = load_shdr_wrlock (scn);
+ }
+
+ return result;
+}
+
+ElfW2(LIBELFBITS,Shdr) *
+internal_function
+__elfw2(LIBELFBITS,getshdr_wrlock) (Elf_Scn *scn)
+{
+ ElfW2(LIBELFBITS,Shdr) *result;
+
+ if (!scn_valid (scn))
+ return NULL;
+
+ result = scn->shdr.ELFW(e,LIBELFBITS);
+ if (result == NULL)
+ result = load_shdr_wrlock (scn);
+
+ return result;
+}
+
+ElfW2(LIBELFBITS,Shdr) *
+elfw2(LIBELFBITS,getshdr) (Elf_Scn *scn)
+{
+ ElfW2(LIBELFBITS,Shdr) *result;
+
+ if (!scn_valid (scn))
+ return NULL;
+
+ rwlock_rdlock (scn->elf->lock);
+ result = __elfw2(LIBELFBITS,getshdr_rdlock) (scn);
+ rwlock_unlock (scn->elf->lock);
+
+ return result;
+}
diff --git a/contrib/libdw/elf32_xlatetof.c b/contrib/libdw/elf32_xlatetof.c
new file mode 100644
index 0000000..ab85740
--- /dev/null
+++ b/contrib/libdw/elf32_xlatetof.c
@@ -0,0 +1,108 @@
+/* Convert from memory to file representation.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libelfP.h"
+
+#ifndef LIBELFBITS
+# define LIBELFBITS 32
+#endif
+
+
+Elf_Data *
+elfw2(LIBELFBITS, xlatetof) (Elf_Data *dest, const Elf_Data *src,
+ unsigned int encode)
+{
+ /* First test whether the input data is really suitable for this
+ type. This means, whether there is an integer number of records.
+ Note that for this implementation the memory and file size of the
+ data types are identical. */
+ size_t recsize = __libelf_type_sizes[ELFW(ELFCLASS,LIBELFBITS) - 1][src->d_type];
+
+ if (src->d_size % recsize != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
+ /* Next see whether the converted data fits in the output buffer. */
+ if (src->d_size > dest->d_size)
+ {
+ __libelf_seterrno (ELF_E_DEST_SIZE);
+ return NULL;
+ }
+
+ /* Test the encode parameter. */
+ if (encode != ELFDATA2LSB && encode != ELFDATA2MSB)
+ {
+ __libelf_seterrno (ELF_E_INVALID_ENCODING);
+ return NULL;
+ }
+
+ /* Determine the translation function to use.
+
+ At this point we make an assumption which is valid for all
+ existing implementations so far: the memory and file sizes are
+ the same. This has very important consequences:
+ a) The requirement that the source and destination buffer can
+ overlap can easily be fulfilled.
+ b) We need only one function to convert from and memory to file
+ and vice versa since the function only has to copy and/or
+ change the byte order.
+ */
+ if ((BYTE_ORDER == LITTLE_ENDIAN && encode == ELFDATA2LSB)
+ || (BYTE_ORDER == BIG_ENDIAN && encode == ELFDATA2MSB))
+ {
+ /* We simply have to copy since the byte order is the same. */
+ if (src->d_buf != dest->d_buf)
+ memmove (dest->d_buf, src->d_buf, src->d_size);
+ }
+ else
+ {
+ xfct_t fctp;
+ fctp = __elf_xfctstom[ELFW(ELFCLASS, LIBELFBITS) - 1][src->d_type];
+
+ /* Do the real work. */
+ (*fctp) (dest->d_buf, src->d_buf, src->d_size, 1);
+ }
+
+ /* Now set the real destination type and length since the operation was
+ successful. */
+ dest->d_type = src->d_type;
+ dest->d_size = src->d_size;
+
+ return dest;
+}
+INTDEF(elfw2(LIBELFBITS, xlatetof))
diff --git a/contrib/libdw/elf64_getchdr.c b/contrib/libdw/elf64_getchdr.c
new file mode 100644
index 0000000..6588b79
--- /dev/null
+++ b/contrib/libdw/elf64_getchdr.c
@@ -0,0 +1,30 @@
+/* Return section compression header.
+ Copyright (C) 2015 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 . */
+
+#define LIBELFBITS 64
+#include "elf32_getchdr.c"
diff --git a/contrib/libdw/elf64_getshdr.c b/contrib/libdw/elf64_getshdr.c
new file mode 100644
index 0000000..c50cc71
--- /dev/null
+++ b/contrib/libdw/elf64_getshdr.c
@@ -0,0 +1,31 @@
+/* Return section header.
+ Copyright (C) 1998, 1999, 2002 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#define LIBELFBITS 64
+#include "elf32_getshdr.c"
diff --git a/contrib/libdw/elf64_xlatetof.c b/contrib/libdw/elf64_xlatetof.c
new file mode 100644
index 0000000..aacf5b0
--- /dev/null
+++ b/contrib/libdw/elf64_xlatetof.c
@@ -0,0 +1,31 @@
+/* Convert from memory to file representation.
+ Copyright (C) 1998, 2002 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#define LIBELFBITS 64
+#include "elf32_xlatetof.c"
diff --git a/contrib/libdw/elf_begin.c b/contrib/libdw/elf_begin.c
new file mode 100644
index 0000000..8a49f35
--- /dev/null
+++ b/contrib/libdw/elf_begin.c
@@ -0,0 +1,1233 @@
+/* Create descriptor for processing file.
+ Copyright (C) 1998-2010, 2012, 2014, 2015, 2016 Red Hat, Inc.
+ Copyright (C) 2021, 2022 Mark J. Wielaard
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+#include "common.h"
+
+
+/* Create descriptor for archive in memory. */
+static inline Elf *
+file_read_ar (int fildes, void *map_address, off_t offset, size_t maxsize,
+ Elf_Cmd cmd, Elf *parent)
+{
+ Elf *elf;
+
+ /* Create a descriptor. */
+ elf = allocate_elf (fildes, map_address, offset, maxsize, cmd, parent,
+ ELF_K_AR, 0);
+ if (elf != NULL)
+ {
+ /* We don't read all the symbol tables in advance. All this will
+ happen on demand. */
+ elf->state.ar.offset = offset + SARMAG;
+
+ elf->state.ar.elf_ar_hdr.ar_rawname = elf->state.ar.raw_name;
+ }
+
+ return elf;
+}
+
+
+static size_t
+get_shnum (void *map_address, unsigned char *e_ident, int fildes,
+ int64_t offset, size_t maxsize)
+{
+ size_t result;
+ union
+ {
+ Elf32_Ehdr *e32;
+ Elf64_Ehdr *e64;
+ void *p;
+ } ehdr;
+ union
+ {
+ Elf32_Ehdr e32;
+ Elf64_Ehdr e64;
+ } ehdr_mem;
+ bool is32 = e_ident[EI_CLASS] == ELFCLASS32;
+
+ if ((is32 && maxsize < sizeof (Elf32_Ehdr))
+ || (!is32 && maxsize < sizeof (Elf64_Ehdr)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return (size_t) -1l;
+ }
+
+ /* Make the ELF header available. */
+ if (e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (((size_t) e_ident
+ & ((is32 ? __alignof__ (Elf32_Ehdr) : __alignof__ (Elf64_Ehdr))
+ - 1)) == 0)))
+ ehdr.p = e_ident;
+ else
+ {
+ /* We already read the ELF header. We have to copy the header
+ since we possibly modify the data here and the caller
+ expects the memory it passes in to be preserved. */
+ ehdr.p = &ehdr_mem;
+
+ if (is32)
+ {
+ if (ALLOW_UNALIGNED)
+ {
+ ehdr_mem.e32.e_shnum = ((Elf32_Ehdr *) e_ident)->e_shnum;
+ ehdr_mem.e32.e_shoff = ((Elf32_Ehdr *) e_ident)->e_shoff;
+ }
+ else
+ memcpy (&ehdr_mem, e_ident, sizeof (Elf32_Ehdr));
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ {
+ CONVERT (ehdr_mem.e32.e_shnum);
+ CONVERT (ehdr_mem.e32.e_shoff);
+ }
+ }
+ else
+ {
+ if (ALLOW_UNALIGNED)
+ {
+ ehdr_mem.e64.e_shnum = ((Elf64_Ehdr *) e_ident)->e_shnum;
+ ehdr_mem.e64.e_shoff = ((Elf64_Ehdr *) e_ident)->e_shoff;
+ }
+ else
+ memcpy (&ehdr_mem, e_ident, sizeof (Elf64_Ehdr));
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ {
+ CONVERT (ehdr_mem.e64.e_shnum);
+ CONVERT (ehdr_mem.e64.e_shoff);
+ }
+ }
+ }
+
+ if (is32)
+ {
+ /* Get the number of sections from the ELF header. */
+ result = ehdr.e32->e_shnum;
+
+ if (unlikely (result == 0) && ehdr.e32->e_shoff != 0)
+ {
+ if (unlikely (ehdr.e32->e_shoff >= maxsize)
+ || unlikely (maxsize - ehdr.e32->e_shoff < sizeof (Elf32_Shdr)))
+ /* Cannot read the first section header. */
+ return 0;
+
+ if (likely (map_address != NULL) && e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (((size_t) ((char *) (map_address + ehdr.e32->e_shoff
+ + offset)))
+ & (__alignof__ (Elf32_Shdr) - 1)) == 0))
+ /* We can directly access the memory. */
+ result = ((Elf32_Shdr *) ((char *) map_address + ehdr.e32->e_shoff
+ + offset))->sh_size;
+ else
+ {
+ Elf32_Word size;
+ ssize_t r;
+
+ if (likely (map_address != NULL))
+ /* gcc will optimize the memcpy to a simple memory
+ access while taking care of alignment issues. */
+ memcpy (&size, ((char *) map_address
+ + ehdr.e32->e_shoff
+ + offset
+ + offsetof (Elf32_Shdr, sh_size)),
+ sizeof (Elf32_Word));
+ else
+ if (unlikely ((r = pread_retry (fildes, &size,
+ sizeof (Elf32_Word),
+ offset + ehdr.e32->e_shoff
+ + offsetof (Elf32_Shdr,
+ sh_size)))
+ != sizeof (Elf32_Word)))
+ {
+ if (r < 0)
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ else
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return (size_t) -1l;
+ }
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ CONVERT (size);
+
+ result = size;
+ }
+ }
+
+ /* If the section headers were truncated, pretend none were there. */
+ if (ehdr.e32->e_shoff > maxsize
+ || maxsize - ehdr.e32->e_shoff < sizeof (Elf32_Shdr) * result)
+ result = 0;
+ }
+ else
+ {
+ /* Get the number of sections from the ELF header. */
+ result = ehdr.e64->e_shnum;
+
+ if (unlikely (result == 0) && ehdr.e64->e_shoff != 0)
+ {
+ if (unlikely (ehdr.e64->e_shoff >= maxsize)
+ || unlikely (ehdr.e64->e_shoff + sizeof (Elf64_Shdr) > maxsize))
+ /* Cannot read the first section header. */
+ return 0;
+
+ Elf64_Xword size;
+ if (likely (map_address != NULL) && e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (((size_t) ((char *) (map_address + ehdr.e64->e_shoff
+ + offset)))
+ & (__alignof__ (Elf64_Shdr) - 1)) == 0))
+ /* We can directly access the memory. */
+ size = ((Elf64_Shdr *) ((char *) map_address + ehdr.e64->e_shoff
+ + offset))->sh_size;
+ else
+ {
+ ssize_t r;
+ if (likely (map_address != NULL))
+ /* gcc will optimize the memcpy to a simple memory
+ access while taking care of alignment issues. */
+ memcpy (&size, ((char *) map_address
+ + ehdr.e64->e_shoff
+ + offset
+ + offsetof (Elf64_Shdr, sh_size)),
+ sizeof (Elf64_Xword));
+ else
+ if (unlikely ((r = pread_retry (fildes, &size,
+ sizeof (Elf64_Xword),
+ offset + ehdr.e64->e_shoff
+ + offsetof (Elf64_Shdr,
+ sh_size)))
+ != sizeof (Elf64_Xword)))
+ {
+ if (r < 0)
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ else
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return (size_t) -1l;
+ }
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ CONVERT (size);
+ }
+
+ /* Although sh_size is an Elf64_Xword and can contain a 64bit
+ value, we only expect an 32bit value max. GElf_Word is
+ 32bit unsigned. */
+ if (size > ~((GElf_Word) 0))
+ {
+ /* Invalid value, it is too large. */
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return (size_t) -1l;
+ }
+
+ result = size;
+ }
+
+ /* If the section headers were truncated, pretend none were there. */
+ if (ehdr.e64->e_shoff > maxsize
+ || maxsize - ehdr.e64->e_shoff < sizeof (Elf64_Shdr) * result)
+ result = 0;
+ }
+
+ return result;
+}
+
+
+/* Create descriptor for ELF file in memory. */
+static Elf *
+file_read_elf (int fildes, void *map_address, unsigned char *e_ident,
+ int64_t offset, size_t maxsize, Elf_Cmd cmd, Elf *parent)
+{
+ /* Verify the binary is of the class we can handle. */
+ if (unlikely ((e_ident[EI_CLASS] != ELFCLASS32
+ && e_ident[EI_CLASS] != ELFCLASS64)
+ /* We also can only handle two encodings. */
+ || (e_ident[EI_DATA] != ELFDATA2LSB
+ && e_ident[EI_DATA] != ELFDATA2MSB)))
+ {
+ /* Cannot handle this. */
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return NULL;
+ }
+
+ /* Determine the number of sections. Returns -1 and sets libelf errno
+ if the file handle or elf file is invalid. Returns zero if there
+ are no section headers (or they cannot be read). */
+ size_t scncnt = get_shnum (map_address, e_ident, fildes, offset, maxsize);
+ if (scncnt == (size_t) -1l)
+ /* Could not determine the number of sections. */
+ return NULL;
+
+ /* Check for too many sections. */
+ if (e_ident[EI_CLASS] == ELFCLASS32)
+ {
+ if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf32_Shdr)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return NULL;
+ }
+ }
+ else if (scncnt > SIZE_MAX / (sizeof (Elf_Scn) + sizeof (Elf64_Shdr)))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return NULL;
+ }
+
+ /* We can now allocate the memory. Even if there are no section headers,
+ we allocate space for a zeroth section in case we need it later. */
+ const size_t scnmax = (scncnt ?: (cmd == ELF_C_RDWR || cmd == ELF_C_RDWR_MMAP)
+ ? 1 : 0);
+ Elf *elf = allocate_elf (fildes, map_address, offset, maxsize, cmd, parent,
+ ELF_K_ELF, scnmax * sizeof (Elf_Scn));
+ if (elf == NULL)
+ /* Not enough memory. allocate_elf will have set libelf errno. */
+ return NULL;
+
+ assert ((unsigned int) scncnt == scncnt);
+ assert (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns));
+ elf->state.elf32.scns.cnt = scncnt;
+ elf->state.elf32.scns.max = scnmax;
+
+ /* Some more or less arbitrary value. */
+ elf->state.elf.scnincr = 10;
+
+ /* Make the class easily available. */
+ elf->class = e_ident[EI_CLASS];
+
+ if (e_ident[EI_CLASS] == ELFCLASS32)
+ {
+ /* This pointer might not be directly usable if the alignment is
+ not sufficient for the architecture. */
+ uintptr_t ehdr = (uintptr_t) map_address + offset;
+
+ /* This is a 32-bit binary. */
+ if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (ehdr & (__alignof__ (Elf32_Ehdr) - 1)) == 0))
+ {
+ /* We can use the mmapped memory. */
+ elf->state.elf32.ehdr = (Elf32_Ehdr *) ehdr;
+ }
+ else
+ {
+ /* Copy the ELF header. */
+ elf->state.elf32.ehdr = memcpy (&elf->state.elf32.ehdr_mem, e_ident,
+ sizeof (Elf32_Ehdr));
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ {
+ CONVERT (elf->state.elf32.ehdr_mem.e_type);
+ CONVERT (elf->state.elf32.ehdr_mem.e_machine);
+ CONVERT (elf->state.elf32.ehdr_mem.e_version);
+ CONVERT (elf->state.elf32.ehdr_mem.e_entry);
+ CONVERT (elf->state.elf32.ehdr_mem.e_phoff);
+ CONVERT (elf->state.elf32.ehdr_mem.e_shoff);
+ CONVERT (elf->state.elf32.ehdr_mem.e_flags);
+ CONVERT (elf->state.elf32.ehdr_mem.e_ehsize);
+ CONVERT (elf->state.elf32.ehdr_mem.e_phentsize);
+ CONVERT (elf->state.elf32.ehdr_mem.e_phnum);
+ CONVERT (elf->state.elf32.ehdr_mem.e_shentsize);
+ CONVERT (elf->state.elf32.ehdr_mem.e_shnum);
+ CONVERT (elf->state.elf32.ehdr_mem.e_shstrndx);
+ }
+ }
+
+ /* Don't precache the phdr pointer here.
+ elf32_getphdr will validate it against the size when asked. */
+
+ Elf32_Off e_shoff = elf->state.elf32.ehdr->e_shoff;
+ if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
+ && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write. */
+ && (ALLOW_UNALIGNED
+ || (((ehdr + e_shoff) & (__alignof__ (Elf32_Shdr) - 1)) == 0)))
+ {
+ if (unlikely (scncnt > 0 && e_shoff >= maxsize)
+ || unlikely (maxsize - e_shoff
+ < scncnt * sizeof (Elf32_Shdr)))
+ {
+ free_and_out:
+ free (elf);
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ return NULL;
+ }
+
+ if (scncnt > 0)
+ elf->state.elf32.shdr = (Elf32_Shdr *) (ehdr + e_shoff);
+
+ for (size_t cnt = 0; cnt < scncnt; ++cnt)
+ {
+ elf->state.elf32.scns.data[cnt].index = cnt;
+ elf->state.elf32.scns.data[cnt].elf = elf;
+ elf->state.elf32.scns.data[cnt].shdr.e32 =
+ &elf->state.elf32.shdr[cnt];
+ if (likely (elf->state.elf32.shdr[cnt].sh_offset < maxsize)
+ && likely (elf->state.elf32.shdr[cnt].sh_size
+ <= maxsize - elf->state.elf32.shdr[cnt].sh_offset))
+ elf->state.elf32.scns.data[cnt].rawdata_base =
+ elf->state.elf32.scns.data[cnt].data_base =
+ ((char *) map_address + offset
+ + elf->state.elf32.shdr[cnt].sh_offset);
+ elf->state.elf32.scns.data[cnt].list = &elf->state.elf32.scns;
+
+ /* If this is a section with an extended index add a
+ reference in the section which uses the extended
+ index. */
+ if (elf->state.elf32.shdr[cnt].sh_type == SHT_SYMTAB_SHNDX
+ && elf->state.elf32.shdr[cnt].sh_link < scncnt)
+ elf->state.elf32.scns.data[elf->state.elf32.shdr[cnt].sh_link].shndx_index
+ = cnt;
+
+ /* Set the own shndx_index field in case it has not yet
+ been set. */
+ if (elf->state.elf32.scns.data[cnt].shndx_index == 0)
+ elf->state.elf32.scns.data[cnt].shndx_index = -1;
+ }
+ }
+ else
+ {
+ for (size_t cnt = 0; cnt < scncnt; ++cnt)
+ {
+ elf->state.elf32.scns.data[cnt].index = cnt;
+ elf->state.elf32.scns.data[cnt].elf = elf;
+ elf->state.elf32.scns.data[cnt].list = &elf->state.elf32.scns;
+ }
+ }
+
+ /* So far only one block with sections. */
+ elf->state.elf32.scns_last = &elf->state.elf32.scns;
+ }
+ else
+ {
+ /* This pointer might not be directly usable if the alignment is
+ not sufficient for the architecture. */
+ uintptr_t ehdr = (uintptr_t) map_address + offset;
+
+ /* This is a 64-bit binary. */
+ if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (ehdr & (__alignof__ (Elf64_Ehdr) - 1)) == 0))
+ {
+ /* We can use the mmapped memory. */
+ elf->state.elf64.ehdr = (Elf64_Ehdr *) ehdr;
+ }
+ else
+ {
+ /* Copy the ELF header. */
+ elf->state.elf64.ehdr = memcpy (&elf->state.elf64.ehdr_mem, e_ident,
+ sizeof (Elf64_Ehdr));
+
+ if (e_ident[EI_DATA] != MY_ELFDATA)
+ {
+ CONVERT (elf->state.elf64.ehdr_mem.e_type);
+ CONVERT (elf->state.elf64.ehdr_mem.e_machine);
+ CONVERT (elf->state.elf64.ehdr_mem.e_version);
+ CONVERT (elf->state.elf64.ehdr_mem.e_entry);
+ CONVERT (elf->state.elf64.ehdr_mem.e_phoff);
+ CONVERT (elf->state.elf64.ehdr_mem.e_shoff);
+ CONVERT (elf->state.elf64.ehdr_mem.e_flags);
+ CONVERT (elf->state.elf64.ehdr_mem.e_ehsize);
+ CONVERT (elf->state.elf64.ehdr_mem.e_phentsize);
+ CONVERT (elf->state.elf64.ehdr_mem.e_phnum);
+ CONVERT (elf->state.elf64.ehdr_mem.e_shentsize);
+ CONVERT (elf->state.elf64.ehdr_mem.e_shnum);
+ CONVERT (elf->state.elf64.ehdr_mem.e_shstrndx);
+ }
+ }
+
+ /* Don't precache the phdr pointer here.
+ elf64_getphdr will validate it against the size when asked. */
+
+ Elf64_Off e_shoff = elf->state.elf64.ehdr->e_shoff;
+ if (map_address != NULL && e_ident[EI_DATA] == MY_ELFDATA
+ && cmd != ELF_C_READ_MMAP /* We need a copy to be able to write. */
+ && (ALLOW_UNALIGNED
+ || (((ehdr + e_shoff) & (__alignof__ (Elf64_Shdr) - 1)) == 0)))
+ {
+ if (unlikely (scncnt > 0 && e_shoff >= maxsize)
+ || unlikely (maxsize - e_shoff
+ < scncnt * sizeof (Elf64_Shdr)))
+ goto free_and_out;
+
+ if (scncnt > 0)
+ elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + (ptrdiff_t) e_shoff);
+
+ for (size_t cnt = 0; cnt < scncnt; ++cnt)
+ {
+ elf->state.elf64.scns.data[cnt].index = cnt;
+ elf->state.elf64.scns.data[cnt].elf = elf;
+ elf->state.elf64.scns.data[cnt].shdr.e64 =
+ &elf->state.elf64.shdr[cnt];
+ if (likely (elf->state.elf64.shdr[cnt].sh_offset < maxsize)
+ && likely (elf->state.elf64.shdr[cnt].sh_size
+ <= maxsize - elf->state.elf64.shdr[cnt].sh_offset))
+ elf->state.elf64.scns.data[cnt].rawdata_base =
+ elf->state.elf64.scns.data[cnt].data_base =
+ ((char *) map_address + offset
+ + elf->state.elf64.shdr[cnt].sh_offset);
+ elf->state.elf64.scns.data[cnt].list = &elf->state.elf64.scns;
+
+ /* If this is a section with an extended index add a
+ reference in the section which uses the extended
+ index. */
+ if (elf->state.elf64.shdr[cnt].sh_type == SHT_SYMTAB_SHNDX
+ && elf->state.elf64.shdr[cnt].sh_link < scncnt)
+ elf->state.elf64.scns.data[elf->state.elf64.shdr[cnt].sh_link].shndx_index
+ = cnt;
+
+ /* Set the own shndx_index field in case it has not yet
+ been set. */
+ if (elf->state.elf64.scns.data[cnt].shndx_index == 0)
+ elf->state.elf64.scns.data[cnt].shndx_index = -1;
+ }
+ }
+ else
+ {
+ for (size_t cnt = 0; cnt < scncnt; ++cnt)
+ {
+ elf->state.elf64.scns.data[cnt].index = cnt;
+ elf->state.elf64.scns.data[cnt].elf = elf;
+ elf->state.elf64.scns.data[cnt].list = &elf->state.elf64.scns;
+ }
+ }
+
+ /* So far only one block with sections. */
+ elf->state.elf64.scns_last = &elf->state.elf64.scns;
+ }
+
+ return elf;
+}
+
+
+Elf *
+internal_function
+__libelf_read_mmaped_file (int fildes, void *map_address, int64_t offset,
+ size_t maxsize, Elf_Cmd cmd, Elf *parent)
+{
+ /* We have to find out what kind of file this is. We handle ELF
+ files and archives. To find out what we have we must look at the
+ header. The header for an ELF file is EI_NIDENT bytes in size,
+ the header for an archive file SARMAG bytes long. */
+ unsigned char *e_ident = (unsigned char *) map_address + offset;
+
+ /* See what kind of object we have here. */
+ Elf_Kind kind = determine_kind (e_ident, maxsize);
+
+ switch (kind)
+ {
+ case ELF_K_ELF:
+ return file_read_elf (fildes, map_address, e_ident, offset, maxsize,
+ cmd, parent);
+
+ case ELF_K_AR:
+ return file_read_ar (fildes, map_address, offset, maxsize, cmd, parent);
+
+ default:
+ break;
+ }
+
+ /* This case is easy. Since we cannot do anything with this file
+ create a dummy descriptor. */
+ return allocate_elf (fildes, map_address, offset, maxsize, cmd, parent,
+ ELF_K_NONE, 0);
+}
+
+
+static Elf *
+read_unmmaped_file (int fildes, int64_t offset, size_t maxsize, Elf_Cmd cmd,
+ Elf *parent)
+{
+ /* We have to find out what kind of file this is. We handle ELF
+ files and archives. To find out what we have we must read the
+ header. The identification header for an ELF file is EI_NIDENT
+ bytes in size, but we read the whole ELF header since we will
+ need it anyway later. For archives the header in SARMAG bytes
+ long. Read the maximum of these numbers.
+
+ XXX We have to change this for the extended `ar' format some day.
+
+ Use a union to ensure alignment. We might later access the
+ memory as a ElfXX_Ehdr. */
+ union
+ {
+ Elf64_Ehdr ehdr;
+ unsigned char header[MAX (sizeof (Elf64_Ehdr), SARMAG)];
+ } mem;
+
+ /* Read the head of the file. */
+ ssize_t nread = pread_retry (fildes, mem.header,
+ MIN (MAX (sizeof (Elf64_Ehdr), SARMAG),
+ maxsize),
+ offset);
+ if (unlikely (nread == -1))
+ {
+ /* We cannot even read the head of the file. Maybe FILDES is associated
+ with an unseekable device. This is nothing we can handle. */
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ return NULL;
+ }
+
+ /* See what kind of object we have here. */
+ Elf_Kind kind = determine_kind (mem.header, nread);
+
+ switch (kind)
+ {
+ case ELF_K_AR:
+ return file_read_ar (fildes, NULL, offset, maxsize, cmd, parent);
+
+ case ELF_K_ELF:
+ /* Make sure at least the ELF header is contained in the file. */
+ if ((size_t) nread >= (mem.header[EI_CLASS] == ELFCLASS32
+ ? sizeof (Elf32_Ehdr) : sizeof (Elf64_Ehdr)))
+ return file_read_elf (fildes, NULL, mem.header, offset, maxsize, cmd,
+ parent);
+ FALLTHROUGH;
+
+ default:
+ break;
+ }
+
+ /* This case is easy. Since we cannot do anything with this file
+ create a dummy descriptor. */
+ return allocate_elf (fildes, NULL, offset, maxsize, cmd, parent,
+ ELF_K_NONE, 0);
+}
+
+
+/* Open a file for reading. If possible we will try to mmap() the file. */
+static struct Elf *
+read_file (int fildes, int64_t offset, size_t maxsize,
+ Elf_Cmd cmd, Elf *parent)
+{
+ void *map_address = NULL;
+ int use_mmap = (cmd == ELF_C_READ_MMAP || cmd == ELF_C_RDWR_MMAP
+ || cmd == ELF_C_WRITE_MMAP
+ || cmd == ELF_C_READ_MMAP_PRIVATE);
+
+ if (parent == NULL)
+ {
+ if (maxsize == ~((size_t) 0))
+ {
+ /* We don't know in the moment how large the file is.
+ Determine it now. */
+ struct stat st;
+
+ if (fstat (fildes, &st) == 0
+ && (sizeof (size_t) >= sizeof (st.st_size)
+ || st.st_size <= ~((size_t) 0)))
+ maxsize = (size_t) st.st_size;
+ }
+ }
+ else
+ {
+ /* The parent is already loaded. Use it. */
+ assert (maxsize != ~((size_t) 0));
+ }
+
+ if (use_mmap)
+ {
+ if (parent == NULL)
+ {
+ /* We try to map the file ourself. */
+ map_address = mmap (NULL, maxsize, (cmd == ELF_C_READ_MMAP
+ ? PROT_READ
+ : PROT_READ|PROT_WRITE),
+ cmd == ELF_C_READ_MMAP_PRIVATE
+ || cmd == ELF_C_READ_MMAP
+ ? MAP_PRIVATE : MAP_SHARED,
+ fildes, offset);
+
+ if (map_address == MAP_FAILED)
+ map_address = NULL;
+ }
+ else
+ {
+ map_address = parent->map_address;
+ }
+ }
+
+ /* If we have the file in memory optimize the access. */
+ if (map_address != NULL)
+ {
+ assert (map_address != MAP_FAILED);
+
+ struct Elf *result = __libelf_read_mmaped_file (fildes, map_address,
+ offset, maxsize, cmd,
+ parent);
+
+ /* If something went wrong during the initialization unmap the
+ memory if we mmaped here. */
+ if (result == NULL
+ && (parent == NULL
+ || parent->map_address != map_address))
+ munmap (map_address, maxsize);
+ else if (parent == NULL)
+ /* Remember that we mmap()ed the memory. */
+ result->flags |= ELF_F_MMAPPED;
+
+ return result;
+ }
+
+ /* Otherwise we have to do it the hard way. We read as much as necessary
+ from the file whenever we need information which is not available. */
+ return read_unmmaped_file (fildes, offset, maxsize, cmd, parent);
+}
+
+
+/* Find the entry with the long names for the content of this archive. */
+static const char *
+read_long_names (Elf *elf)
+{
+ off_t offset = SARMAG; /* This is the first entry. */
+ struct ar_hdr hdrm;
+ struct ar_hdr *hdr;
+ char *newp;
+ size_t len;
+
+ while (1)
+ {
+ if (elf->map_address != NULL)
+ {
+ if ((size_t) offset > elf->maximum_size
+ || elf->maximum_size - offset < sizeof (struct ar_hdr))
+ return NULL;
+
+ /* The data is mapped. */
+ hdr = (struct ar_hdr *) (elf->map_address + offset);
+ }
+ else
+ {
+ /* Read the header from the file. */
+ if (unlikely (pread_retry (elf->fildes, &hdrm, sizeof (hdrm),
+ elf->start_offset + offset)
+ != sizeof (hdrm)))
+ return NULL;
+
+ hdr = &hdrm;
+ }
+
+ /* The ar_size is given as a fixed size decimal string, right
+ padded with spaces. Make sure we read it properly even if
+ there is no terminating space. */
+ char buf[sizeof (hdr->ar_size) + 1];
+ const char *string = hdr->ar_size;
+ if (hdr->ar_size[sizeof (hdr->ar_size) - 1] != ' ')
+ {
+ *((char *) mempcpy (buf, hdr->ar_size, sizeof (hdr->ar_size))) = '\0';
+ string = buf;
+ }
+
+ /* atol expects to see at least one digit.
+ It also cannot be negative (-). */
+ if (!isdigit(string[0]))
+ return NULL;
+ len = atol (string);
+
+ if (memcmp (hdr->ar_name, "// ", 16) == 0)
+ break;
+
+ offset += sizeof (struct ar_hdr) + ((len + 1) & ~1l);
+ }
+
+ /* Sanity check len early if we can. */
+ if (elf->map_address != NULL)
+ {
+ if (len > elf->maximum_size - offset - sizeof (struct ar_hdr))
+ return NULL;
+ }
+
+ /* Due to the stupid format of the long name table entry (which are not
+ NUL terminted) we have to provide an appropriate representation anyhow.
+ Therefore we always make a copy which has the appropriate form. */
+ newp = malloc (len);
+ if (newp != NULL)
+ {
+ char *runp;
+
+ if (elf->map_address != NULL)
+ {
+ /* Simply copy it over. */
+ elf->state.ar.long_names = (char *) memcpy (newp,
+ elf->map_address + offset
+ + sizeof (struct ar_hdr),
+ len);
+ }
+ else
+ {
+ if (unlikely ((size_t) pread_retry (elf->fildes, newp, len,
+ elf->start_offset + offset
+ + sizeof (struct ar_hdr))
+ != len))
+ {
+ /* We were not able to read all data. */
+ free (newp);
+ elf->state.ar.long_names = NULL;
+ return NULL;
+ }
+ elf->state.ar.long_names = newp;
+ }
+
+ elf->state.ar.long_names_len = len;
+
+ /* Now NUL-terminate the strings. */
+ runp = newp;
+ while (1)
+ {
+ char *startp = runp;
+ runp = (char *) memchr (runp, '/', newp + len - runp);
+ if (runp == NULL)
+ {
+ /* This was the last entry. Clear any left overs. */
+ memset (startp, '\0', newp + len - startp);
+ break;
+ }
+
+ /* NUL-terminate the string. */
+ *runp++ = '\0';
+
+ /* A sanity check. Somebody might have generated invalid
+ archive. */
+ if (runp >= newp + len)
+ break;
+ }
+ }
+
+ return newp;
+}
+
+
+/* Read the next archive header. */
+int
+internal_function
+__libelf_next_arhdr_wrlock (Elf *elf)
+{
+ struct ar_hdr *ar_hdr;
+ Elf_Arhdr *elf_ar_hdr;
+
+ if (elf->map_address != NULL)
+ {
+ /* See whether this entry is in the file. */
+ if (unlikely ((size_t) elf->state.ar.offset
+ > elf->start_offset + elf->maximum_size
+ || (elf->start_offset + elf->maximum_size
+ - elf->state.ar.offset) < sizeof (struct ar_hdr)))
+ {
+ /* This record is not anymore in the file. */
+ __libelf_seterrno (ELF_E_RANGE);
+ return -1;
+ }
+ ar_hdr = (struct ar_hdr *) (elf->map_address + elf->state.ar.offset);
+ }
+ else
+ {
+ ar_hdr = &elf->state.ar.ar_hdr;
+
+ if (unlikely (pread_retry (elf->fildes, ar_hdr, sizeof (struct ar_hdr),
+ elf->state.ar.offset)
+ != sizeof (struct ar_hdr)))
+ {
+ /* Something went wrong while reading the file. */
+ __libelf_seterrno (ELF_E_RANGE);
+ return -1;
+ }
+ }
+
+ /* One little consistency check. */
+ if (unlikely (memcmp (ar_hdr->ar_fmag, ARFMAG, 2) != 0))
+ {
+ /* This is no valid archive. */
+ __libelf_seterrno (ELF_E_ARCHIVE_FMAG);
+ return -1;
+ }
+
+ /* Copy the raw name over to a NUL terminated buffer. */
+ *((char *) mempcpy (elf->state.ar.raw_name, ar_hdr->ar_name, 16)) = '\0';
+
+ elf_ar_hdr = &elf->state.ar.elf_ar_hdr;
+
+ /* Now convert the `struct ar_hdr' into `Elf_Arhdr'.
+ Determine whether this is a special entry. */
+ if (ar_hdr->ar_name[0] == '/')
+ {
+ if (ar_hdr->ar_name[1] == ' '
+ && memcmp (ar_hdr->ar_name, "/ ", 16) == 0)
+ /* This is the index. */
+ elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "/", 2);
+ else if (ar_hdr->ar_name[1] == 'S'
+ && memcmp (ar_hdr->ar_name, "/SYM64/ ", 16) == 0)
+ /* 64-bit index. */
+ elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "/SYM64/", 8);
+ else if (ar_hdr->ar_name[1] == '/'
+ && memcmp (ar_hdr->ar_name, "// ", 16) == 0)
+ /* This is the array with the long names. */
+ elf_ar_hdr->ar_name = memcpy (elf->state.ar.ar_name, "//", 3);
+ else if (likely (isdigit (ar_hdr->ar_name[1])))
+ {
+ size_t offset;
+
+ /* This is a long name. First we have to read the long name
+ table, if this hasn't happened already. */
+ if (unlikely (elf->state.ar.long_names == NULL
+ && read_long_names (elf) == NULL))
+ {
+ /* No long name table although it is reference. The archive is
+ broken. */
+ __libelf_seterrno (ELF_E_INVALID_ARCHIVE);
+ return -1;
+ }
+
+ offset = atol (ar_hdr->ar_name + 1);
+ if (unlikely (offset >= elf->state.ar.long_names_len))
+ {
+ /* The index in the long name table is larger than the table. */
+ __libelf_seterrno (ELF_E_INVALID_ARCHIVE);
+ return -1;
+ }
+ elf_ar_hdr->ar_name = elf->state.ar.long_names + offset;
+ }
+ else
+ {
+ /* This is none of the known special entries. */
+ __libelf_seterrno (ELF_E_INVALID_ARCHIVE);
+ return -1;
+ }
+ }
+ else
+ {
+ char *endp;
+
+ /* It is a normal entry. Copy over the name. */
+ endp = (char *) memccpy (elf->state.ar.ar_name, ar_hdr->ar_name,
+ '/', 16);
+ if (endp != NULL)
+ endp[-1] = '\0';
+ else
+ {
+ /* In the old BSD style of archive, there is no / terminator.
+ Instead, there is space padding at the end of the name. */
+ size_t i = 15;
+ do
+ elf->state.ar.ar_name[i] = '\0';
+ while (i > 0 && elf->state.ar.ar_name[--i] == ' ');
+ }
+
+ elf_ar_hdr->ar_name = elf->state.ar.ar_name;
+ }
+
+ if (unlikely (ar_hdr->ar_size[0] == ' '))
+ /* Something is really wrong. We cannot live without a size for
+ the member since it will not be possible to find the next
+ archive member. */
+ {
+ __libelf_seterrno (ELF_E_INVALID_ARCHIVE);
+ return -1;
+ }
+
+ /* Since there are no specialized functions to convert ASCII to
+ time_t, uid_t, gid_t, mode_t, and off_t we use either atol or
+ atoll depending on the size of the types. We are also prepared
+ for the case where the whole field in the `struct ar_hdr' is
+ filled in which case we cannot simply use atol/l but instead have
+ to create a temporary copy. Note that all fields use decimal
+ encoding, except ar_mode which uses octal. */
+
+#define INT_FIELD(FIELD) \
+ do \
+ { \
+ char buf[sizeof (ar_hdr->FIELD) + 1]; \
+ const char *string = ar_hdr->FIELD; \
+ if (ar_hdr->FIELD[sizeof (ar_hdr->FIELD) - 1] != ' ') \
+ { \
+ *((char *) mempcpy (buf, ar_hdr->FIELD, sizeof (ar_hdr->FIELD))) \
+ = '\0'; \
+ string = buf; \
+ } \
+ if (sizeof (elf_ar_hdr->FIELD) <= sizeof (long int)) \
+ elf_ar_hdr->FIELD = (__typeof (elf_ar_hdr->FIELD)) atol (string); \
+ else \
+ elf_ar_hdr->FIELD = (__typeof (elf_ar_hdr->FIELD)) atoll (string); \
+ } \
+ while (0)
+
+#define OCT_FIELD(FIELD) \
+ do \
+ { \
+ char buf[sizeof (ar_hdr->FIELD) + 1]; \
+ const char *string = ar_hdr->FIELD; \
+ if (ar_hdr->FIELD[sizeof (ar_hdr->FIELD) - 1] != ' ') \
+ { \
+ *((char *) mempcpy (buf, ar_hdr->FIELD, sizeof (ar_hdr->FIELD))) \
+ = '\0'; \
+ string = buf; \
+ } \
+ if (sizeof (elf_ar_hdr->FIELD) <= sizeof (long int)) \
+ elf_ar_hdr->FIELD \
+ = (__typeof (elf_ar_hdr->FIELD)) strtol (string, NULL, 8); \
+ else \
+ elf_ar_hdr->FIELD \
+ = (__typeof (elf_ar_hdr->FIELD)) strtoll (string, NULL, 8); \
+ } \
+ while (0)
+
+ INT_FIELD (ar_date);
+ INT_FIELD (ar_uid);
+ INT_FIELD (ar_gid);
+ OCT_FIELD (ar_mode);
+ INT_FIELD (ar_size);
+
+ if (elf_ar_hdr->ar_size < 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_ARCHIVE);
+ return -1;
+ }
+
+ /* Truncated file? */
+ size_t maxsize;
+ maxsize = (elf->start_offset + elf->maximum_size
+ - elf->state.ar.offset - sizeof (struct ar_hdr));
+ if ((size_t) elf_ar_hdr->ar_size > maxsize)
+ elf_ar_hdr->ar_size = maxsize;
+
+ return 0;
+}
+
+
+/* We were asked to return a clone of an existing descriptor. This
+ function must be called with the lock on the parent descriptor
+ being held. */
+static Elf *
+dup_elf (int fildes, Elf_Cmd cmd, Elf *ref)
+{
+ struct Elf *result;
+
+ if (fildes == -1)
+ /* Allow the user to pass -1 as the file descriptor for the new file. */
+ fildes = ref->fildes;
+ /* The file descriptor better should be the same. If it was disconnected
+ already (using `elf_cntl') we do not test it. */
+ else if (unlikely (ref->fildes != -1 && fildes != ref->fildes))
+ {
+ __libelf_seterrno (ELF_E_FD_MISMATCH);
+ return NULL;
+ }
+
+ /* The mode must allow reading. I.e., a descriptor creating with a
+ command different then ELF_C_READ, ELF_C_WRITE and ELF_C_RDWR is
+ not allowed. */
+ if (unlikely (ref->cmd != ELF_C_READ && ref->cmd != ELF_C_READ_MMAP
+ && ref->cmd != ELF_C_WRITE && ref->cmd != ELF_C_WRITE_MMAP
+ && ref->cmd != ELF_C_RDWR && ref->cmd != ELF_C_RDWR_MMAP
+ && ref->cmd != ELF_C_READ_MMAP_PRIVATE))
+ {
+ __libelf_seterrno (ELF_E_INVALID_OP);
+ return NULL;
+ }
+
+ /* Now it is time to distinguish between reading normal files and
+ archives. Normal files can easily be handled be incrementing the
+ reference counter and return the same descriptor. */
+ if (ref->kind != ELF_K_AR)
+ {
+ ++ref->ref_count;
+ return ref;
+ }
+
+ /* This is an archive. We must create a descriptor for the archive
+ member the internal pointer of the archive file descriptor is
+ pointing to. First read the header of the next member if this
+ has not happened already. */
+ if (ref->state.ar.elf_ar_hdr.ar_name == NULL
+ && __libelf_next_arhdr_wrlock (ref) != 0)
+ /* Something went wrong. Maybe there is no member left. */
+ return NULL;
+
+ /* We have all the information we need about the next archive member.
+ Now create a descriptor for it. */
+ result = read_file (fildes, ref->state.ar.offset + sizeof (struct ar_hdr),
+ ref->state.ar.elf_ar_hdr.ar_size, cmd, ref);
+
+ /* Enlist this new descriptor in the list of children. */
+ if (result != NULL)
+ {
+ result->next = ref->state.ar.children;
+ ref->state.ar.children = result;
+ }
+
+ return result;
+}
+
+
+/* Return descriptor for empty file ready for writing. */
+static struct Elf *
+write_file (int fd, Elf_Cmd cmd)
+{
+ /* We simply create an empty `Elf' structure. */
+#define NSCNSALLOC 10
+ Elf *result = allocate_elf (fd, NULL, 0, 0, cmd, NULL, ELF_K_ELF,
+ NSCNSALLOC * sizeof (Elf_Scn));
+
+ if (result != NULL)
+ {
+ /* We have to write to the file in any case. */
+ result->flags = ELF_F_DIRTY;
+
+ /* Some more or less arbitrary value. */
+ result->state.elf.scnincr = NSCNSALLOC;
+
+ /* We have allocated room for some sections. */
+ assert (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns));
+ result->state.elf.scns_last = &result->state.elf32.scns;
+ result->state.elf32.scns.max = NSCNSALLOC;
+ }
+
+ return result;
+}
+
+/* Lock if necessary before dup an archive. */
+static inline Elf *
+lock_dup_elf (int fildes, Elf_Cmd cmd, Elf *ref)
+{
+ /* We need wrlock to dup an archive. */
+ if (ref->kind == ELF_K_AR)
+ {
+ rwlock_unlock (ref->lock);
+ rwlock_wrlock (ref->lock);
+ }
+ /* Duplicate the descriptor. */
+ return dup_elf (fildes, cmd, ref);
+}
+
+/* Return a descriptor for the file belonging to FILDES. */
+Elf *
+elf_begin (int fildes, Elf_Cmd cmd, Elf *ref)
+{
+ Elf *retval;
+
+ if (unlikely (__libelf_version != EV_CURRENT))
+ {
+ /* Version wasn't set so far. */
+ __libelf_seterrno (ELF_E_NO_VERSION);
+ return NULL;
+ }
+
+ if (ref != NULL)
+ /* Make sure the descriptor is not suddenly going away. */
+ rwlock_rdlock (ref->lock);
+ else if (unlikely (fcntl (fildes, F_GETFD) == -1 && errno == EBADF))
+ {
+ /* We cannot do anything productive without a file descriptor. */
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ return NULL;
+ }
+
+ switch (cmd)
+ {
+ case ELF_C_NULL:
+ /* We simply return a NULL pointer. */
+ retval = NULL;
+ break;
+
+ case ELF_C_READ_MMAP_PRIVATE:
+ /* If we have a reference it must also be opened this way. */
+ if (unlikely (ref != NULL && ref->cmd != ELF_C_READ_MMAP_PRIVATE))
+ {
+ __libelf_seterrno (ELF_E_INVALID_CMD);
+ retval = NULL;
+ break;
+ }
+ FALLTHROUGH;
+
+ case ELF_C_READ:
+ case ELF_C_READ_MMAP:
+ if (ref != NULL)
+ retval = lock_dup_elf (fildes, cmd, ref);
+ else
+ /* Create descriptor for existing file. */
+ retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL);
+ break;
+
+ case ELF_C_RDWR:
+ case ELF_C_RDWR_MMAP:
+ /* If we have a REF object it must also be opened using this
+ command. */
+ if (ref != NULL)
+ {
+ if (unlikely (ref->cmd != ELF_C_RDWR && ref->cmd != ELF_C_RDWR_MMAP
+ && ref->cmd != ELF_C_WRITE
+ && ref->cmd != ELF_C_WRITE_MMAP))
+ {
+ /* This is not ok. REF must also be opened for writing. */
+ __libelf_seterrno (ELF_E_INVALID_CMD);
+ retval = NULL;
+ }
+ else
+ retval = lock_dup_elf (fildes, cmd, ref);
+ }
+ else
+ /* Create descriptor for existing file. */
+ retval = read_file (fildes, 0, ~((size_t) 0), cmd, NULL);
+ break;
+
+ case ELF_C_WRITE:
+ case ELF_C_WRITE_MMAP:
+ /* We ignore REF and prepare a descriptor to write a new file. */
+ retval = write_file (fildes, cmd);
+ break;
+
+ default:
+ __libelf_seterrno (ELF_E_INVALID_CMD);
+ retval = NULL;
+ break;
+ }
+
+ /* Release the lock. */
+ if (ref != NULL)
+ rwlock_unlock (ref->lock);
+
+ return retval;
+}
+INTDEF(elf_begin)
diff --git a/contrib/libdw/elf_cntl.c b/contrib/libdw/elf_cntl.c
new file mode 100644
index 0000000..04aa913
--- /dev/null
+++ b/contrib/libdw/elf_cntl.c
@@ -0,0 +1,79 @@
+/* Control an ELF file desrciptor.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libelfP.h"
+
+
+int
+elf_cntl (Elf *elf, Elf_Cmd cmd)
+{
+ int result = 0;
+
+ if (elf == NULL)
+ return -1;
+
+ if (elf->fildes == -1)
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return -1;
+ }
+
+ rwlock_wrlock (elf->lock);
+
+ switch (cmd)
+ {
+ case ELF_C_FDREAD:
+ /* If not all of the file is in the memory read it now. */
+ if (elf->map_address == NULL && __libelf_readall (elf) == NULL)
+ {
+ /* We were not able to read everything. */
+ result = -1;
+ break;
+ }
+ FALLTHROUGH;
+
+ case ELF_C_FDDONE:
+ /* Mark the file descriptor as not usable. */
+ elf->fildes = -1;
+ break;
+
+ default:
+ __libelf_seterrno (ELF_E_INVALID_CMD);
+ result = -1;
+ break;
+ }
+
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
diff --git a/contrib/libdw/elf_compress.c b/contrib/libdw/elf_compress.c
new file mode 100644
index 0000000..0ad6a32
--- /dev/null
+++ b/contrib/libdw/elf_compress.c
@@ -0,0 +1,749 @@
+/* Compress or decompress a section.
+ Copyright (C) 2015, 2016 Red Hat, Inc.
+ Copyright (C) 2023, Mark J. Wielaard
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libelfP.h"
+#include "common.h"
+
+#include
+#include
+#include
+#include
+
+#ifdef USE_ZSTD
+#include
+#endif
+
+/* Cleanup and return result. Don't leak memory. */
+static void *
+do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
+ Elf_Data *cdatap)
+{
+ deflateEnd (z);
+ free (out_buf);
+ if (cdatap != NULL)
+ free (cdatap->d_buf);
+ return result;
+}
+
+#define deflate_cleanup(result, cdata) \
+ do_deflate_cleanup(result, &z, out_buf, cdata)
+
+static
+void *
+__libelf_compress_zlib (Elf_Scn *scn, size_t hsize, int ei_data,
+ size_t *orig_size, size_t *orig_addralign,
+ size_t *new_size, bool force,
+ Elf_Data *data, Elf_Data *next_data,
+ void *out_buf, size_t out_size, size_t block)
+{
+ /* Caller gets to fill in the header at the start. Just skip it here. */
+ size_t used = hsize;
+
+ z_stream z;
+ z.zalloc = Z_NULL;
+ z.zfree = Z_NULL;
+ z.opaque = Z_NULL;
+ int zrc = deflateInit (&z, Z_BEST_COMPRESSION);
+ if (zrc != Z_OK)
+ {
+ __libelf_seterrno (ELF_E_COMPRESS_ERROR);
+ return deflate_cleanup(NULL, NULL);
+ }
+
+ Elf_Data cdata;
+ cdata.d_buf = NULL;
+
+ /* Loop over data buffers. */
+ int flush = Z_NO_FLUSH;
+ do
+ {
+ /* Convert to raw if different endianness. */
+ cdata = *data;
+ bool convert = ei_data != MY_ELFDATA && data->d_size > 0;
+ if (convert)
+ {
+ /* Don't do this conversion in place, we might want to keep
+ the original data around, caller decides. */
+ cdata.d_buf = malloc (data->d_size);
+ if (cdata.d_buf == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return deflate_cleanup (NULL, NULL);
+ }
+ if (gelf_xlatetof (scn->elf, &cdata, data, ei_data) == NULL)
+ return deflate_cleanup (NULL, &cdata);
+ }
+
+ z.avail_in = cdata.d_size;
+ z.next_in = cdata.d_buf;
+
+ /* Get next buffer to see if this is the last one. */
+ data = next_data;
+ if (data != NULL)
+ {
+ *orig_addralign = MAX (*orig_addralign, data->d_align);
+ *orig_size += data->d_size;
+ next_data = elf_getdata (scn, data);
+ }
+ else
+ flush = Z_FINISH;
+
+ /* Flush one data buffer. */
+ do
+ {
+ z.avail_out = out_size - used;
+ z.next_out = out_buf + used;
+ zrc = deflate (&z, flush);
+ if (zrc == Z_STREAM_ERROR)
+ {
+ __libelf_seterrno (ELF_E_COMPRESS_ERROR);
+ return deflate_cleanup (NULL, convert ? &cdata : NULL);
+ }
+ used += (out_size - used) - z.avail_out;
+
+ /* Bail out if we are sure the user doesn't want the
+ compression forced and we are using more compressed data
+ than original data. */
+ if (!force && flush == Z_FINISH && used >= *orig_size)
+ return deflate_cleanup ((void *) -1, convert ? &cdata : NULL);
+
+ if (z.avail_out == 0)
+ {
+ void *bigger = realloc (out_buf, out_size + block);
+ if (bigger == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return deflate_cleanup (NULL, convert ? &cdata : NULL);
+ }
+ out_buf = bigger;
+ out_size += block;
+ }
+ }
+ while (z.avail_out == 0); /* Need more output buffer. */
+
+ if (convert)
+ {
+ free (cdata.d_buf);
+ cdata.d_buf = NULL;
+ }
+ }
+ while (flush != Z_FINISH); /* More data blocks. */
+
+ if (zrc != Z_STREAM_END)
+ {
+ __libelf_seterrno (ELF_E_COMPRESS_ERROR);
+ return deflate_cleanup (NULL, NULL);
+ }
+
+ deflateEnd (&z);
+ *new_size = used;
+ return out_buf;
+}
+
+#ifdef USE_ZSTD_COMPRESS
+/* Cleanup and return result. Don't leak memory. */
+static void *
+do_zstd_cleanup (void *result, ZSTD_CCtx * const cctx, void *out_buf,
+ Elf_Data *cdatap)
+{
+ ZSTD_freeCCtx (cctx);
+ free (out_buf);
+ if (cdatap != NULL)
+ free (cdatap->d_buf);
+ return result;
+}
+
+#define zstd_cleanup(result, cdata) \
+ do_zstd_cleanup(result, cctx, out_buf, cdata)
+
+static
+void *
+__libelf_compress_zstd (Elf_Scn *scn, size_t hsize, int ei_data,
+ size_t *orig_size, size_t *orig_addralign,
+ size_t *new_size, bool force,
+ Elf_Data *data, Elf_Data *next_data,
+ void *out_buf, size_t out_size, size_t block)
+{
+ /* Caller gets to fill in the header at the start. Just skip it here. */
+ size_t used = hsize;
+
+ ZSTD_CCtx* const cctx = ZSTD_createCCtx();
+ Elf_Data cdata;
+ cdata.d_buf = NULL;
+
+ /* Loop over data buffers. */
+ ZSTD_EndDirective mode = ZSTD_e_continue;
+
+ do
+ {
+ /* Convert to raw if different endianness. */
+ cdata = *data;
+ bool convert = ei_data != MY_ELFDATA && data->d_size > 0;
+ if (convert)
+ {
+ /* Don't do this conversion in place, we might want to keep
+ the original data around, caller decides. */
+ cdata.d_buf = malloc (data->d_size);
+ if (cdata.d_buf == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return zstd_cleanup (NULL, NULL);
+ }
+ if (gelf_xlatetof (scn->elf, &cdata, data, ei_data) == NULL)
+ return zstd_cleanup (NULL, &cdata);
+ }
+
+ ZSTD_inBuffer ib = { cdata.d_buf, cdata.d_size, 0 };
+
+ /* Get next buffer to see if this is the last one. */
+ data = next_data;
+ if (data != NULL)
+ {
+ *orig_addralign = MAX (*orig_addralign, data->d_align);
+ *orig_size += data->d_size;
+ next_data = elf_getdata (scn, data);
+ }
+ else
+ mode = ZSTD_e_end;
+
+ /* Flush one data buffer. */
+ for (;;)
+ {
+ ZSTD_outBuffer ob = { out_buf + used, out_size - used, 0 };
+ size_t ret = ZSTD_compressStream2 (cctx, &ob, &ib, mode);
+ if (ZSTD_isError (ret))
+ {
+ __libelf_seterrno (ELF_E_COMPRESS_ERROR);
+ return zstd_cleanup (NULL, convert ? &cdata : NULL);
+ }
+ used += ob.pos;
+
+ /* Bail out if we are sure the user doesn't want the
+ compression forced and we are using more compressed data
+ than original data. */
+ if (!force && mode == ZSTD_e_end && used >= *orig_size)
+ return zstd_cleanup ((void *) -1, convert ? &cdata : NULL);
+
+ if (ret > 0)
+ {
+ void *bigger = realloc (out_buf, out_size + block);
+ if (bigger == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return zstd_cleanup (NULL, convert ? &cdata : NULL);
+ }
+ out_buf = bigger;
+ out_size += block;
+ }
+ else
+ break;
+ }
+
+ if (convert)
+ {
+ free (cdata.d_buf);
+ cdata.d_buf = NULL;
+ }
+ }
+ while (mode != ZSTD_e_end); /* More data blocks. */
+
+ ZSTD_freeCCtx (cctx);
+ *new_size = used;
+ return out_buf;
+}
+#endif
+
+/* Given a section, uses the (in-memory) Elf_Data to extract the
+ original data size (including the given header size) and data
+ alignment. Returns a buffer that has at least hsize bytes (for the
+ caller to fill in with a header) plus zlib compressed date. Also
+ returns the new buffer size in new_size (hsize + compressed data
+ size). Returns (void *) -1 when FORCE is false and the compressed
+ data would be bigger than the original data. */
+void *
+internal_function
+__libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
+ size_t *orig_size, size_t *orig_addralign,
+ size_t *new_size, bool force, bool use_zstd)
+{
+ /* The compressed data is the on-disk data. We simplify the
+ implementation a bit by asking for the (converted) in-memory
+ data (which might be all there is if the user created it with
+ elf_newdata) and then convert back to raw if needed before
+ compressing. Should be made a bit more clever to directly
+ use raw if that is directly available. */
+ Elf_Data *data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ return NULL;
+
+ /* When not forced and we immediately know we would use more data by
+ compressing, because of the header plus zlib overhead (five bytes
+ per 16 KB block, plus a one-time overhead of six bytes for the
+ entire stream), don't do anything.
+ Size estimation for ZSTD compression would be similar. */
+ Elf_Data *next_data = elf_getdata (scn, data);
+ if (next_data == NULL && !force
+ && data->d_size <= hsize + 5 + 6)
+ return (void *) -1;
+
+ *orig_addralign = data->d_align;
+ *orig_size = data->d_size;
+
+ /* Guess an output block size. 1/8th of the original Elf_Data plus
+ hsize. Make the first chunk twice that size (25%), then increase
+ by a block (12.5%) when necessary. */
+ size_t block = (data->d_size / 8) + hsize;
+ size_t out_size = 2 * block;
+ void *out_buf = malloc (out_size);
+ if (out_buf == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return NULL;
+ }
+
+ if (use_zstd)
+ {
+#ifdef USE_ZSTD_COMPRESS
+ return __libelf_compress_zstd (scn, hsize, ei_data, orig_size,
+ orig_addralign, new_size, force,
+ data, next_data, out_buf, out_size,
+ block);
+#else
+ __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE);
+ return NULL;
+#endif
+ }
+ else
+ return __libelf_compress_zlib (scn, hsize, ei_data, orig_size,
+ orig_addralign, new_size, force,
+ data, next_data, out_buf, out_size,
+ block);
+}
+
+void *
+internal_function
+__libelf_decompress_zlib (void *buf_in, size_t size_in, size_t size_out)
+{
+ /* Catch highly unlikely compression ratios so we don't allocate
+ some giant amount of memory for nothing. The max compression
+ factor 1032:1 comes from http://www.zlib.net/zlib_tech.html */
+ if (unlikely (size_out / 1032 > size_in))
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return NULL;
+ }
+
+ /* Malloc might return NULL when requesting zero size. This is highly
+ unlikely, it would only happen when the compression was forced.
+ But we do need a non-NULL buffer to return and set as result.
+ Just make sure to always allocate at least 1 byte. */
+ void *buf_out = malloc (size_out ?: 1);
+ if (unlikely (buf_out == NULL))
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return NULL;
+ }
+
+ z_stream z =
+ {
+ .next_in = buf_in,
+ .avail_in = size_in,
+ .next_out = buf_out,
+ .avail_out = size_out
+ };
+ int zrc = inflateInit (&z);
+ while (z.avail_in > 0 && likely (zrc == Z_OK))
+ {
+ z.next_out = buf_out + (size_out - z.avail_out);
+ zrc = inflate (&z, Z_FINISH);
+ if (unlikely (zrc != Z_STREAM_END))
+ {
+ zrc = Z_DATA_ERROR;
+ break;
+ }
+ zrc = inflateReset (&z);
+ }
+
+ if (unlikely (zrc != Z_OK) || unlikely (z.avail_out != 0))
+ {
+ free (buf_out);
+ buf_out = NULL;
+ __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
+ }
+
+ inflateEnd(&z);
+ return buf_out;
+}
+
+#ifdef USE_ZSTD
+static void *
+__libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out)
+{
+ /* Malloc might return NULL when requesting zero size. This is highly
+ unlikely, it would only happen when the compression was forced.
+ But we do need a non-NULL buffer to return and set as result.
+ Just make sure to always allocate at least 1 byte. */
+ void *buf_out = malloc (size_out ?: 1);
+ if (unlikely (buf_out == NULL))
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return NULL;
+ }
+
+ size_t ret = ZSTD_decompress (buf_out, size_out, buf_in, size_in);
+ if (unlikely (ZSTD_isError (ret)) || unlikely (ret != size_out))
+ {
+ free (buf_out);
+ __libelf_seterrno (ELF_E_DECOMPRESS_ERROR);
+ return NULL;
+ }
+ else
+ return buf_out;
+}
+#endif
+
+void *
+internal_function
+__libelf_decompress (int chtype, void *buf_in, size_t size_in, size_t size_out)
+{
+ if (chtype == ELFCOMPRESS_ZLIB)
+ return __libelf_decompress_zlib (buf_in, size_in, size_out);
+ else
+ {
+#ifdef USE_ZSTD
+ return __libelf_decompress_zstd (buf_in, size_in, size_out);
+#else
+ __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE);
+ return NULL;
+#endif
+ }
+}
+
+void *
+internal_function
+__libelf_decompress_elf (Elf_Scn *scn, size_t *size_out, size_t *addralign)
+{
+ GElf_Chdr chdr;
+ if (gelf_getchdr (scn, &chdr) == NULL)
+ return NULL;
+
+ bool unknown_compression = false;
+ if (chdr.ch_type != ELFCOMPRESS_ZLIB)
+ {
+ if (chdr.ch_type != ELFCOMPRESS_ZSTD)
+ unknown_compression = true;
+
+#ifndef USE_ZSTD
+ if (chdr.ch_type == ELFCOMPRESS_ZSTD)
+ unknown_compression = true;
+#endif
+ }
+
+ if (unknown_compression)
+ {
+ __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE);
+ return NULL;
+ }
+
+ if (! powerof2 (chdr.ch_addralign))
+ {
+ __libelf_seterrno (ELF_E_INVALID_ALIGN);
+ return NULL;
+ }
+
+ /* Take the in-memory representation, so we can even handle a
+ section that has just been constructed (maybe it was copied
+ over from some other ELF file first with elf_newdata). This
+ is slightly inefficient when the raw data needs to be
+ converted since then we'll be converting the whole buffer and
+ not just Chdr. */
+ Elf_Data *data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ return NULL;
+
+ int elfclass = scn->elf->class;
+ size_t hsize = (elfclass == ELFCLASS32
+ ? sizeof (Elf32_Chdr) : sizeof (Elf64_Chdr));
+ size_t size_in = data->d_size - hsize;
+ void *buf_in = data->d_buf + hsize;
+ void *buf_out
+ = __libelf_decompress (chdr.ch_type, buf_in, size_in, chdr.ch_size);
+
+ *size_out = chdr.ch_size;
+ *addralign = chdr.ch_addralign;
+ return buf_out;
+}
+
+/* Assumes buf is a malloced buffer. */
+void
+internal_function
+__libelf_reset_rawdata (Elf_Scn *scn, void *buf, size_t size, size_t align,
+ Elf_Type type)
+{
+ /* This is the new raw data, replace and possibly free old data. */
+ scn->rawdata.d.d_off = 0;
+ scn->rawdata.d.d_version = EV_CURRENT;
+ scn->rawdata.d.d_buf = buf;
+ scn->rawdata.d.d_size = size;
+ scn->rawdata.d.d_align = align;
+ scn->rawdata.d.d_type = type;
+
+ /* Existing existing data is no longer valid. */
+ scn->data_list_rear = NULL;
+ if (scn->data_base != scn->rawdata_base)
+ free (scn->data_base);
+ scn->data_base = NULL;
+ if (scn->zdata_base != buf
+ && scn->zdata_base != scn->rawdata_base)
+ {
+ free (scn->zdata_base);
+ scn->zdata_base = NULL;
+ }
+ if (scn->elf->map_address == NULL
+ || scn->rawdata_base == scn->zdata_base
+ || (scn->flags & ELF_F_MALLOCED) != 0)
+ {
+ free (scn->rawdata_base);
+ scn->rawdata_base = NULL;
+ scn->zdata_base = NULL;
+ }
+
+ scn->rawdata_base = buf;
+ scn->flags |= ELF_F_MALLOCED;
+
+ /* Pretend we (tried to) read the data from the file and setup the
+ data (might have to convert the Chdr to native format). */
+ scn->data_read = 1;
+ scn->flags |= ELF_F_FILEDATA;
+ __libelf_set_data_list_rdlock (scn, 1);
+}
+
+int
+elf_compress (Elf_Scn *scn, int type, unsigned int flags)
+{
+ if (scn == NULL)
+ return -1;
+
+ if ((flags & ~ELF_CHF_FORCE) != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ return -1;
+ }
+
+ bool force = (flags & ELF_CHF_FORCE) != 0;
+
+ Elf *elf = scn->elf;
+ GElf_Ehdr ehdr;
+ if (gelf_getehdr (elf, &ehdr) == NULL)
+ return -1;
+
+ int elfclass = elf->class;
+ int elfdata = ehdr.e_ident[EI_DATA];
+
+ Elf64_Xword sh_flags;
+ Elf64_Word sh_type;
+ Elf64_Xword sh_addralign;
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ return -1;
+
+ sh_flags = shdr->sh_flags;
+ sh_type = shdr->sh_type;
+ sh_addralign = shdr->sh_addralign;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ if (shdr == NULL)
+ return -1;
+
+ sh_flags = shdr->sh_flags;
+ sh_type = shdr->sh_type;
+ sh_addralign = shdr->sh_addralign;
+ }
+
+ if ((sh_flags & SHF_ALLOC) != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
+ return -1;
+ }
+
+ if (sh_type == SHT_NULL || sh_type == SHT_NOBITS)
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
+ return -1;
+ }
+
+ int compressed = (sh_flags & SHF_COMPRESSED);
+ if (type == ELFCOMPRESS_ZLIB || type == ELFCOMPRESS_ZSTD)
+ {
+ /* Compress/Deflate. */
+ if (compressed == 1)
+ {
+ __libelf_seterrno (ELF_E_ALREADY_COMPRESSED);
+ return -1;
+ }
+
+ size_t hsize = (elfclass == ELFCLASS32
+ ? sizeof (Elf32_Chdr) : sizeof (Elf64_Chdr));
+ size_t orig_size, orig_addralign, new_size;
+ void *out_buf = __libelf_compress (scn, hsize, elfdata,
+ &orig_size, &orig_addralign,
+ &new_size, force,
+ type == ELFCOMPRESS_ZSTD);
+
+ /* Compression would make section larger, don't change anything. */
+ if (out_buf == (void *) -1)
+ return 0;
+
+ /* Compression failed, return error. */
+ if (out_buf == NULL)
+ return -1;
+
+ /* Put the header in front of the data. */
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Chdr chdr;
+ chdr.ch_type = type;
+ chdr.ch_size = orig_size;
+ chdr.ch_addralign = orig_addralign;
+ if (elfdata != MY_ELFDATA)
+ {
+ CONVERT (chdr.ch_type);
+ CONVERT (chdr.ch_size);
+ CONVERT (chdr.ch_addralign);
+ }
+ memcpy (out_buf, &chdr, sizeof (Elf32_Chdr));
+ }
+ else
+ {
+ Elf64_Chdr chdr;
+ chdr.ch_type = type;
+ chdr.ch_reserved = 0;
+ chdr.ch_size = orig_size;
+ chdr.ch_addralign = sh_addralign;
+ if (elfdata != MY_ELFDATA)
+ {
+ CONVERT (chdr.ch_type);
+ CONVERT (chdr.ch_reserved);
+ CONVERT (chdr.ch_size);
+ CONVERT (chdr.ch_addralign);
+ }
+ memcpy (out_buf, &chdr, sizeof (Elf64_Chdr));
+ }
+
+ /* Note we keep the sh_entsize as is, we assume it is setup
+ correctly and ignored when SHF_COMPRESSED is set. */
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ shdr->sh_size = new_size;
+ shdr->sh_addralign = __libelf_type_align (ELFCLASS32, ELF_T_CHDR);
+ shdr->sh_flags |= SHF_COMPRESSED;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ shdr->sh_size = new_size;
+ shdr->sh_addralign = __libelf_type_align (ELFCLASS64, ELF_T_CHDR);
+ shdr->sh_flags |= SHF_COMPRESSED;
+ }
+
+ __libelf_reset_rawdata (scn, out_buf, new_size, 1, ELF_T_CHDR);
+
+ /* The section is now compressed, we could keep the uncompressed
+ data around, but since that might have been multiple Elf_Data
+ buffers let the user uncompress it explicitly again if they
+ want it to simplify bookkeeping. */
+ free (scn->zdata_base);
+ scn->zdata_base = NULL;
+
+ return 1;
+ }
+ else if (type == 0)
+ {
+ /* Decompress/Inflate. */
+ if (compressed == 0)
+ {
+ __libelf_seterrno (ELF_E_NOT_COMPRESSED);
+ return -1;
+ }
+
+ /* If the data is already decompressed (by elf_strptr), then we
+ only need to setup the rawdata and section header. XXX what
+ about elf_newdata? */
+ if (scn->zdata_base == NULL)
+ {
+ size_t size_out, addralign;
+ void *buf_out = __libelf_decompress_elf (scn, &size_out, &addralign);
+ if (buf_out == NULL)
+ return -1;
+
+ scn->zdata_base = buf_out;
+ scn->zdata_size = size_out;
+ scn->zdata_align = addralign;
+ }
+
+ /* Note we keep the sh_entsize as is, we assume it is setup
+ correctly and ignored when SHF_COMPRESSED is set. */
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ shdr->sh_size = scn->zdata_size;
+ shdr->sh_addralign = scn->zdata_align;
+ shdr->sh_flags &= ~SHF_COMPRESSED;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ shdr->sh_size = scn->zdata_size;
+ shdr->sh_addralign = scn->zdata_align;
+ shdr->sh_flags &= ~SHF_COMPRESSED;
+ }
+
+ __libelf_reset_rawdata (scn, scn->zdata_base,
+ scn->zdata_size, scn->zdata_align,
+ __libelf_data_type (&ehdr, sh_type,
+ scn->zdata_align));
+
+ return 1;
+ }
+ else
+ {
+ __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE);
+ return -1;
+ }
+}
diff --git a/contrib/libdw/elf_compress_gnu.c b/contrib/libdw/elf_compress_gnu.c
new file mode 100644
index 0000000..8e20b30
--- /dev/null
+++ b/contrib/libdw/elf_compress_gnu.c
@@ -0,0 +1,213 @@
+/* Compress or decompress a section.
+ Copyright (C) 2015 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include "libelfP.h"
+#include "common.h"
+
+int
+elf_compress_gnu (Elf_Scn *scn, int inflate, unsigned int flags)
+{
+ if (scn == NULL)
+ return -1;
+
+ if ((flags & ~ELF_CHF_FORCE) != 0)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ return -1;
+ }
+
+ bool force = (flags & ELF_CHF_FORCE) != 0;
+
+ Elf *elf = scn->elf;
+ GElf_Ehdr ehdr;
+ if (gelf_getehdr (elf, &ehdr) == NULL)
+ return -1;
+
+ int elfclass = elf->class;
+ int elfdata = ehdr.e_ident[EI_DATA];
+
+ Elf64_Xword sh_flags;
+ Elf64_Word sh_type;
+ Elf64_Xword sh_addralign;
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ if (shdr == NULL)
+ return -1;
+
+ sh_flags = shdr->sh_flags;
+ sh_type = shdr->sh_type;
+ sh_addralign = shdr->sh_addralign;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ if (shdr == NULL)
+ return -1;
+
+ sh_flags = shdr->sh_flags;
+ sh_type = shdr->sh_type;
+ sh_addralign = shdr->sh_addralign;
+ }
+
+ /* Allocated sections, or sections that are already are compressed
+ cannot (also) be GNU compressed. */
+ if ((sh_flags & SHF_ALLOC) != 0 || (sh_flags & SHF_COMPRESSED))
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_FLAGS);
+ return -1;
+ }
+
+ if (sh_type == SHT_NULL || sh_type == SHT_NOBITS)
+ {
+ __libelf_seterrno (ELF_E_INVALID_SECTION_TYPE);
+ return -1;
+ }
+
+ /* For GNU compression we cannot really know whether the section is
+ already compressed or not. Just try and see what happens... */
+ // int compressed = (sh_flags & SHF_COMPRESSED);
+ if (inflate == 1)
+ {
+ size_t hsize = 4 + 8; /* GNU "ZLIB" + 8 byte size. */
+ size_t orig_size, new_size, orig_addralign;
+ void *out_buf = __libelf_compress (scn, hsize, elfdata,
+ &orig_size, &orig_addralign,
+ &new_size, force,
+ /* use_zstd */ false);
+
+ /* Compression would make section larger, don't change anything. */
+ if (out_buf == (void *) -1)
+ return 0;
+
+ /* Compression failed, return error. */
+ if (out_buf == NULL)
+ return -1;
+
+ uint64_t be64_size = htobe64 (orig_size);
+ memmove (out_buf, "ZLIB", 4);
+ memmove (out_buf + 4, &be64_size, sizeof (be64_size));
+
+ /* We don't know anything about sh_entsize, sh_addralign and
+ sh_flags won't have a SHF_COMPRESSED hint in the GNU format.
+ Just adjust the sh_size. */
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ shdr->sh_size = new_size;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ shdr->sh_size = new_size;
+ }
+
+ __libelf_reset_rawdata (scn, out_buf, new_size, 1, ELF_T_BYTE);
+
+ /* The section is now compressed, we could keep the uncompressed
+ data around, but since that might have been multiple Elf_Data
+ buffers let the user uncompress it explicitly again if they
+ want it to simplify bookkeeping. */
+ scn->zdata_base = NULL;
+
+ return 1;
+ }
+ else if (inflate == 0)
+ {
+ /* In theory the user could have constructed a compressed section
+ by hand. And in practice they do. For example when copying
+ a section from one file to another using elf_newdata. So we
+ have to use elf_getdata (not elf_rawdata). */
+ Elf_Data *data = elf_getdata (scn, NULL);
+ if (data == NULL)
+ return -1;
+
+ size_t hsize = 4 + 8; /* GNU "ZLIB" + 8 byte size. */
+ if (data->d_size < hsize || memcmp (data->d_buf, "ZLIB", 4) != 0)
+ {
+ __libelf_seterrno (ELF_E_NOT_COMPRESSED);
+ return -1;
+ }
+
+ /* There is a 12-byte header of "ZLIB" followed by
+ an 8-byte big-endian size. There is only one type and
+ Alignment isn't preserved separately. */
+ uint64_t gsize;
+ memcpy (&gsize, data->d_buf + 4, sizeof gsize);
+ gsize = be64toh (gsize);
+
+ /* One more sanity check, size should be bigger than original
+ data size plus some overhead (4 chars ZLIB + 8 bytes size + 6
+ bytes zlib stream overhead + 5 bytes overhead max for one 16K
+ block) and should fit into a size_t. */
+ if (gsize + 4 + 8 + 6 + 5 < data->d_size || gsize > SIZE_MAX)
+ {
+ __libelf_seterrno (ELF_E_NOT_COMPRESSED);
+ return -1;
+ }
+
+ size_t size = gsize;
+ size_t size_in = data->d_size - hsize;
+ void *buf_in = data->d_buf + hsize;
+ void *buf_out = __libelf_decompress (ELFCOMPRESS_ZLIB, buf_in, size_in, size);
+ if (buf_out == NULL)
+ return -1;
+
+ /* We don't know anything about sh_entsize, sh_addralign and
+ sh_flags won't have a SHF_COMPRESSED hint in the GNU format.
+ Just adjust the sh_size. */
+ if (elfclass == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = elf32_getshdr (scn);
+ shdr->sh_size = size;
+ }
+ else
+ {
+ Elf64_Shdr *shdr = elf64_getshdr (scn);
+ shdr->sh_size = size;
+ }
+
+ __libelf_reset_rawdata (scn, buf_out, size, sh_addralign,
+ __libelf_data_type (&ehdr, sh_type,
+ sh_addralign));
+
+ scn->zdata_base = buf_out;
+
+ return 1;
+ }
+ else
+ {
+ __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE);
+ return -1;
+ }
+}
diff --git a/contrib/libdw/elf_end.c b/contrib/libdw/elf_end.c
new file mode 100644
index 0000000..80f4d13
--- /dev/null
+++ b/contrib/libdw/elf_end.c
@@ -0,0 +1,248 @@
+/* Free resources associated with Elf descriptor.
+ Copyright (C) 1998,1999,2000,2001,2002,2004,2005,2007,2015,2016 Red Hat, Inc.
+ Copyright (C) 2023 Mark J. Wielaard
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+static void
+free_chunk (void *n)
+{
+ Elf_Data_Chunk *rawchunk = (Elf_Data_Chunk *)n;
+ if (rawchunk->dummy_scn.flags & ELF_F_MALLOCED)
+ free (rawchunk->data.d.d_buf);
+ free (rawchunk);
+}
+
+int
+elf_end (Elf *elf)
+{
+ Elf *parent;
+
+ if (elf == NULL)
+ /* This is allowed and is a no-op. */
+ return 0;
+
+ /* Make sure we are alone. */
+ rwlock_wrlock (elf->lock);
+
+ if (elf->ref_count != 0 && --elf->ref_count != 0)
+ {
+ /* Not yet the last activation. */
+ int result = elf->ref_count;
+ rwlock_unlock (elf->lock);
+ return result;
+ }
+
+ if (elf->kind == ELF_K_AR)
+ {
+ /* We cannot remove the descriptor now since we still have some
+ descriptors which depend on it. But we can free the archive
+ symbol table since this is only available via the archive ELF
+ descriptor. The long name table cannot be freed yet since
+ the archive headers for the ELF files in the archive point
+ into this array. */
+ if (elf->state.ar.ar_sym != (Elf_Arsym *) -1l)
+ free (elf->state.ar.ar_sym);
+ elf->state.ar.ar_sym = NULL;
+
+ if (elf->state.ar.children != NULL)
+ {
+ rwlock_unlock(elf->lock);
+ return 0;
+ }
+ }
+
+ /* Remove this structure from the children list. */
+ parent = elf->parent;
+ if (parent != NULL)
+ {
+ /* This is tricky. Lock must be acquire from the father to
+ the child but here we already have the child lock. We
+ solve this problem by giving free the child lock. The
+ state of REF_COUNT==0 is handled all over the library, so
+ this should be ok. */
+ rwlock_unlock (elf->lock);
+ rwlock_rdlock (parent->lock);
+ rwlock_wrlock (elf->lock);
+
+ if (parent->state.ar.children == elf)
+ parent->state.ar.children = elf->next;
+ else
+ {
+ struct Elf *child = parent->state.ar.children;
+
+ while (child->next != elf)
+ child = child->next;
+
+ child->next = elf->next;
+ }
+
+ rwlock_unlock (parent->lock);
+ }
+
+ /* This was the last activation. Free all resources. */
+ switch (elf->kind)
+ {
+ case ELF_K_AR:
+ if (elf->state.ar.long_names != NULL)
+ free (elf->state.ar.long_names);
+ break;
+
+ case ELF_K_ELF:
+ {
+ void *rawchunks
+ = (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.rawchunks)
+ == offsetof (struct Elf, state.elf64.rawchunks))
+ ? elf->state.elf32.rawchunks
+ : elf->state.elf64.rawchunks);
+ tdestroy (rawchunks, free_chunk);
+
+ Elf_ScnList *list = (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns))
+ ? &elf->state.elf32.scns
+ : &elf->state.elf64.scns);
+
+ do
+ {
+ /* Free all separately allocated section headers. */
+ size_t cnt = list->max;
+
+ while (cnt-- > 0)
+ {
+ /* These pointers can be NULL; it's safe to use
+ 'free' since it will check for this. */
+ Elf_Scn *scn = &list->data[cnt];
+ Elf_Data_List *runp;
+
+ if ((scn->shdr_flags & ELF_F_MALLOCED) != 0)
+ /* It doesn't matter which pointer. */
+ free (scn->shdr.e32);
+
+ /* Free zdata if uncompressed, but not yet used as
+ rawdata_base. If it is already used it will be
+ freed below. */
+ if (scn->zdata_base != scn->rawdata_base)
+ {
+ free (scn->zdata_base);
+ scn->zdata_base = NULL;
+ }
+
+ /* If the file has the same byte order and the
+ 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)
+ 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
+ || scn->rawdata_base == scn->zdata_base
+ || (scn->flags & ELF_F_MALLOCED) != 0)
+ free (scn->rawdata_base);
+
+ /* Free the list of data buffers for the section.
+ We don't free the buffers themselves since this
+ is the users job. */
+ runp = scn->data_list.next;
+ while (runp != NULL)
+ {
+ Elf_Data_List *oldp = runp;
+ runp = runp->next;
+ if ((oldp->flags & ELF_F_MALLOCED) != 0)
+ free (oldp);
+ }
+ }
+
+ /* Free the memory for the array. */
+ Elf_ScnList *oldp = list;
+ list = list->next;
+ assert (list == NULL || oldp->cnt == oldp->max);
+ if (oldp != (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns))
+ ? &elf->state.elf32.scns
+ : &elf->state.elf64.scns))
+ free (oldp);
+ }
+ while (list != NULL);
+ }
+
+ /* Free the section header. */
+ if (elf->state.elf.shdr_malloced != 0)
+ free (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.shdr)
+ == offsetof (struct Elf, state.elf64.shdr))
+ ? (void *) elf->state.elf32.shdr
+ : (void *) elf->state.elf64.shdr);
+
+ /* Free the program header. */
+ if ((elf->state.elf.phdr_flags & ELF_F_MALLOCED) != 0)
+ free (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.phdr)
+ == offsetof (struct Elf, state.elf64.phdr))
+ ? (void *) elf->state.elf32.phdr
+ : (void *) elf->state.elf64.phdr);
+ break;
+
+ default:
+ break;
+ }
+
+ if (elf->map_address != NULL && parent == NULL)
+ {
+ /* The file was read or mapped for this descriptor. */
+ if ((elf->flags & ELF_F_MALLOCED) != 0)
+ free (elf->map_address);
+ else if ((elf->flags & ELF_F_MMAPPED) != 0)
+ munmap (elf->map_address, elf->maximum_size);
+ }
+
+ rwlock_unlock (elf->lock);
+ rwlock_fini (elf->lock);
+
+ /* Finally the descriptor itself. */
+ free (elf);
+
+ return (parent != NULL && parent->ref_count == 0
+ ? INTUSE(elf_end) (parent) : 0);
+}
+INTDEF(elf_end)
diff --git a/contrib/libdw/elf_error.c b/contrib/libdw/elf_error.c
new file mode 100644
index 0000000..e596108
--- /dev/null
+++ b/contrib/libdw/elf_error.c
@@ -0,0 +1,354 @@
+/* Error handling in libelf.
+ Copyright (C) 1998-2010, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+/* The error number. */
+static __thread int global_error;
+
+
+int
+elf_errno (void)
+{
+ int result = global_error;
+ global_error = ELF_E_NOERROR;
+ return result;
+}
+
+
+/* Return the appropriate message for the error. */
+static const char msgstr[] =
+{
+#define ELF_E_NOERROR_IDX 0
+ N_("no error")
+ "\0"
+#define ELF_E_UNKNOWN_ERROR_IDX (ELF_E_NOERROR_IDX + sizeof "no error")
+ N_("unknown error")
+ "\0"
+#define ELF_E_UNKNOWN_VERSION_IDX \
+ (ELF_E_UNKNOWN_ERROR_IDX + sizeof "unknown error")
+ N_("unknown version")
+ "\0"
+#define ELF_E_UNKNOWN_TYPE_IDX \
+ (ELF_E_UNKNOWN_VERSION_IDX + sizeof "unknown version")
+ N_("unknown type")
+ "\0"
+#define ELF_E_INVALID_HANDLE_IDX \
+ (ELF_E_UNKNOWN_TYPE_IDX + sizeof "unknown type")
+ N_("invalid `Elf' handle")
+ "\0"
+#define ELF_E_SOURCE_SIZE_IDX \
+ (ELF_E_INVALID_HANDLE_IDX + sizeof "invalid `Elf' handle")
+ N_("invalid size of source operand")
+ "\0"
+#define ELF_E_DEST_SIZE_IDX \
+ (ELF_E_SOURCE_SIZE_IDX + sizeof "invalid size of source operand")
+ N_("invalid size of destination operand")
+ "\0"
+#define ELF_E_INVALID_ENCODING_IDX \
+ (ELF_E_DEST_SIZE_IDX + sizeof "invalid size of destination operand")
+ N_("invalid encoding")
+ "\0"
+#define ELF_E_NOMEM_IDX \
+ (ELF_E_INVALID_ENCODING_IDX + sizeof "invalid encoding")
+ N_("out of memory")
+ "\0"
+#define ELF_E_INVALID_FILE_IDX \
+ (ELF_E_NOMEM_IDX + sizeof "out of memory")
+ N_("invalid file descriptor")
+ "\0"
+#define ELF_E_INVALID_ELF_IDX \
+ (ELF_E_INVALID_FILE_IDX + sizeof "invalid file descriptor")
+ N_("invalid ELF file data")
+ "\0"
+#define ELF_E_INVALID_OP_IDX \
+ (ELF_E_INVALID_ELF_IDX + sizeof "invalid ELF file data")
+ N_("invalid operation")
+ "\0"
+#define ELF_E_NO_VERSION_IDX \
+ (ELF_E_INVALID_OP_IDX + sizeof "invalid operation")
+ N_("ELF version not set")
+ "\0"
+#define ELF_E_INVALID_CMD_IDX \
+ (ELF_E_NO_VERSION_IDX + sizeof "ELF version not set")
+ N_("invalid command")
+ "\0"
+#define ELF_E_RANGE_IDX \
+ (ELF_E_INVALID_CMD_IDX + sizeof "invalid command")
+ N_("offset out of range")
+ "\0"
+#define ELF_E_ARCHIVE_FMAG_IDX \
+ (ELF_E_RANGE_IDX + sizeof "offset out of range")
+ N_("invalid fmag field in archive header")
+ "\0"
+#define ELF_E_INVALID_ARCHIVE_IDX \
+ (ELF_E_ARCHIVE_FMAG_IDX + sizeof "invalid fmag field in archive header")
+ N_("invalid archive file")
+ "\0"
+#define ELF_E_NO_ARCHIVE_IDX \
+ (ELF_E_INVALID_ARCHIVE_IDX + sizeof "invalid archive file")
+ N_("descriptor is not for an archive")
+ "\0"
+#define ELF_E_NO_INDEX_IDX \
+ (ELF_E_NO_ARCHIVE_IDX + sizeof "descriptor is not for an archive")
+ N_("no index available")
+ "\0"
+#define ELF_E_READ_ERROR_IDX \
+ (ELF_E_NO_INDEX_IDX + sizeof "no index available")
+ N_("cannot read data from file")
+ "\0"
+#define ELF_E_WRITE_ERROR_IDX \
+ (ELF_E_READ_ERROR_IDX + sizeof "cannot read data from file")
+ N_("cannot write data to file")
+ "\0"
+#define ELF_E_INVALID_CLASS_IDX \
+ (ELF_E_WRITE_ERROR_IDX + sizeof "cannot write data to file")
+ N_("invalid binary class")
+ "\0"
+#define ELF_E_INVALID_INDEX_IDX \
+ (ELF_E_INVALID_CLASS_IDX + sizeof "invalid binary class")
+ N_("invalid section index")
+ "\0"
+#define ELF_E_INVALID_OPERAND_IDX \
+ (ELF_E_INVALID_INDEX_IDX + sizeof "invalid section index")
+ N_("invalid operand")
+ "\0"
+#define ELF_E_INVALID_SECTION_IDX \
+ (ELF_E_INVALID_OPERAND_IDX + sizeof "invalid operand")
+ N_("invalid section")
+ "\0"
+#define ELF_E_INVALID_COMMAND_IDX \
+ (ELF_E_INVALID_SECTION_IDX + sizeof "invalid section")
+ N_("invalid command")
+ "\0"
+#define ELF_E_WRONG_ORDER_EHDR_IDX \
+ (ELF_E_INVALID_COMMAND_IDX + sizeof "invalid command")
+ N_("executable header not created first")
+ "\0"
+#define ELF_E_FD_DISABLED_IDX \
+ (ELF_E_WRONG_ORDER_EHDR_IDX + sizeof "executable header not created first")
+ N_("file descriptor disabled")
+ "\0"
+#define ELF_E_FD_MISMATCH_IDX \
+ (ELF_E_FD_DISABLED_IDX + sizeof "file descriptor disabled")
+ N_("archive/member file descriptor mismatch")
+ "\0"
+#define ELF_E_OFFSET_RANGE_IDX \
+ (ELF_E_FD_MISMATCH_IDX + sizeof "archive/member file descriptor mismatch")
+ N_("offset out of range")
+ "\0"
+#define ELF_E_NOT_NUL_SECTION_IDX \
+ (ELF_E_OFFSET_RANGE_IDX + sizeof "offset out of range")
+ N_("cannot manipulate null section")
+ "\0"
+#define ELF_E_DATA_MISMATCH_IDX \
+ (ELF_E_NOT_NUL_SECTION_IDX + sizeof "cannot manipulate null section")
+ N_("data/scn mismatch")
+ "\0"
+#define ELF_E_INVALID_SECTION_HEADER_IDX \
+ (ELF_E_DATA_MISMATCH_IDX + sizeof "data/scn mismatch")
+ N_("invalid section header")
+ "\0"
+#define ELF_E_INVALID_DATA_IDX \
+ (ELF_E_INVALID_SECTION_HEADER_IDX + sizeof "invalid section header")
+ N_("invalid data")
+ "\0"
+#define ELF_E_DATA_ENCODING_IDX \
+ (ELF_E_INVALID_DATA_IDX + sizeof "invalid data")
+ N_("unknown data encoding")
+ "\0"
+#define ELF_E_SECTION_TOO_SMALL_IDX \
+ (ELF_E_DATA_ENCODING_IDX + sizeof "unknown data encoding")
+ N_("section `sh_size' too small for data")
+ "\0"
+#define ELF_E_INVALID_ALIGN_IDX \
+ (ELF_E_SECTION_TOO_SMALL_IDX + sizeof "section `sh_size' too small for data")
+ N_("invalid section alignment")
+ "\0"
+#define ELF_E_INVALID_SHENTSIZE_IDX \
+ (ELF_E_INVALID_ALIGN_IDX + sizeof "invalid section alignment")
+ N_("invalid section entry size")
+ "\0"
+#define ELF_E_UPDATE_RO_IDX \
+ (ELF_E_INVALID_SHENTSIZE_IDX + sizeof "invalid section entry size")
+ N_("update() for write on read-only file")
+ "\0"
+#define ELF_E_NOFILE_IDX \
+ (ELF_E_UPDATE_RO_IDX + sizeof "update() for write on read-only file")
+ N_("no such file")
+ "\0"
+#define ELF_E_GROUP_NOT_REL_IDX \
+ (ELF_E_NOFILE_IDX + sizeof "no such file")
+ N_("only relocatable files can contain section groups")
+ "\0"
+#define ELF_E_INVALID_PHDR_IDX \
+ (ELF_E_GROUP_NOT_REL_IDX \
+ + sizeof "only relocatable files can contain section groups")
+ N_("program header only allowed in executables, shared objects, and \
+core files")
+ "\0"
+#define ELF_E_NO_PHDR_IDX \
+ (ELF_E_INVALID_PHDR_IDX \
+ + sizeof "program header only allowed in executables, shared objects, and \
+core files")
+ N_("file has no program header")
+ "\0"
+#define ELF_E_INVALID_OFFSET_IDX \
+ (ELF_E_NO_PHDR_IDX \
+ + sizeof "file has no program header")
+ N_("invalid offset")
+ "\0"
+#define ELF_E_INVALID_SECTION_TYPE_IDX \
+ (ELF_E_INVALID_OFFSET_IDX \
+ + sizeof "invalid offset")
+ N_("invalid section type")
+ "\0"
+#define ELF_E_INVALID_SECTION_FLAGS_IDX \
+ (ELF_E_INVALID_SECTION_TYPE_IDX \
+ + sizeof "invalid section type")
+ N_("invalid section flags")
+ "\0"
+#define ELF_E_NOT_COMPRESSED_IDX \
+ (ELF_E_INVALID_SECTION_FLAGS_IDX \
+ + sizeof "invalid section flags")
+ N_("section does not contain compressed data")
+ "\0"
+#define ELF_E_ALREADY_COMPRESSED_IDX \
+ (ELF_E_NOT_COMPRESSED_IDX \
+ + sizeof "section does not contain compressed data")
+ N_("section contains compressed data")
+ "\0"
+#define ELF_E_UNKNOWN_COMPRESSION_TYPE_IDX \
+ (ELF_E_ALREADY_COMPRESSED_IDX \
+ + sizeof "section contains compressed data")
+ N_("unknown compression type")
+ "\0"
+#define ELF_E_COMPRESS_ERROR_IDX \
+ (ELF_E_UNKNOWN_COMPRESSION_TYPE_IDX \
+ + sizeof "unknown compression type")
+ N_("cannot compress data")
+ "\0"
+#define ELF_E_DECOMPRESS_ERROR_IDX \
+ (ELF_E_COMPRESS_ERROR_IDX \
+ + sizeof "cannot compress data")
+ N_("cannot decompress data")
+};
+
+
+static const uint_fast16_t msgidx[ELF_E_NUM] =
+{
+ [ELF_E_NOERROR] = ELF_E_NOERROR_IDX,
+ [ELF_E_UNKNOWN_ERROR] = ELF_E_UNKNOWN_ERROR_IDX,
+ [ELF_E_UNKNOWN_VERSION] = ELF_E_UNKNOWN_VERSION_IDX,
+ [ELF_E_UNKNOWN_TYPE] = ELF_E_UNKNOWN_TYPE_IDX,
+ [ELF_E_INVALID_HANDLE] = ELF_E_INVALID_HANDLE_IDX,
+ [ELF_E_SOURCE_SIZE] = ELF_E_SOURCE_SIZE_IDX,
+ [ELF_E_DEST_SIZE] = ELF_E_DEST_SIZE_IDX,
+ [ELF_E_INVALID_ENCODING] = ELF_E_INVALID_ENCODING_IDX,
+ [ELF_E_NOMEM] = ELF_E_NOMEM_IDX,
+ [ELF_E_INVALID_FILE] = ELF_E_INVALID_FILE_IDX,
+ [ELF_E_INVALID_ELF] = ELF_E_INVALID_ELF_IDX,
+ [ELF_E_INVALID_OP] = ELF_E_INVALID_OP_IDX,
+ [ELF_E_NO_VERSION] = ELF_E_NO_VERSION_IDX,
+ [ELF_E_INVALID_CMD] = ELF_E_INVALID_CMD_IDX,
+ [ELF_E_RANGE] = ELF_E_RANGE_IDX,
+ [ELF_E_ARCHIVE_FMAG] = ELF_E_ARCHIVE_FMAG_IDX,
+ [ELF_E_INVALID_ARCHIVE] = ELF_E_INVALID_ARCHIVE_IDX,
+ [ELF_E_NO_ARCHIVE] = ELF_E_NO_ARCHIVE_IDX,
+ [ELF_E_NO_INDEX] = ELF_E_NO_INDEX_IDX,
+ [ELF_E_READ_ERROR] = ELF_E_READ_ERROR_IDX,
+ [ELF_E_WRITE_ERROR] = ELF_E_WRITE_ERROR_IDX,
+ [ELF_E_INVALID_CLASS] = ELF_E_INVALID_CLASS_IDX,
+ [ELF_E_INVALID_INDEX] = ELF_E_INVALID_INDEX_IDX,
+ [ELF_E_INVALID_OPERAND] = ELF_E_INVALID_OPERAND_IDX,
+ [ELF_E_INVALID_SECTION] = ELF_E_INVALID_SECTION_IDX,
+ [ELF_E_INVALID_COMMAND] = ELF_E_INVALID_COMMAND_IDX,
+ [ELF_E_WRONG_ORDER_EHDR] = ELF_E_WRONG_ORDER_EHDR_IDX,
+ [ELF_E_FD_DISABLED] = ELF_E_FD_DISABLED_IDX,
+ [ELF_E_FD_MISMATCH] = ELF_E_FD_MISMATCH_IDX,
+ [ELF_E_OFFSET_RANGE] = ELF_E_OFFSET_RANGE_IDX,
+ [ELF_E_NOT_NUL_SECTION] = ELF_E_NOT_NUL_SECTION_IDX,
+ [ELF_E_DATA_MISMATCH] = ELF_E_DATA_MISMATCH_IDX,
+ [ELF_E_INVALID_SECTION_HEADER] = ELF_E_INVALID_SECTION_HEADER_IDX,
+ [ELF_E_INVALID_DATA] = ELF_E_INVALID_DATA_IDX,
+ [ELF_E_DATA_ENCODING] = ELF_E_DATA_ENCODING_IDX,
+ [ELF_E_SECTION_TOO_SMALL] = ELF_E_SECTION_TOO_SMALL_IDX,
+ [ELF_E_INVALID_ALIGN] = ELF_E_INVALID_ALIGN_IDX,
+ [ELF_E_INVALID_SHENTSIZE] = ELF_E_INVALID_SHENTSIZE_IDX,
+ [ELF_E_UPDATE_RO] = ELF_E_UPDATE_RO_IDX,
+ [ELF_E_NOFILE] = ELF_E_NOFILE_IDX,
+ [ELF_E_GROUP_NOT_REL] = ELF_E_GROUP_NOT_REL_IDX,
+ [ELF_E_INVALID_PHDR] = ELF_E_INVALID_PHDR_IDX,
+ [ELF_E_NO_PHDR] = ELF_E_NO_PHDR_IDX,
+ [ELF_E_INVALID_OFFSET] = ELF_E_INVALID_OFFSET_IDX,
+ [ELF_E_INVALID_SECTION_TYPE] = ELF_E_INVALID_SECTION_TYPE_IDX,
+ [ELF_E_INVALID_SECTION_FLAGS] = ELF_E_INVALID_SECTION_FLAGS_IDX,
+ [ELF_E_NOT_COMPRESSED] = ELF_E_NOT_COMPRESSED_IDX,
+ [ELF_E_ALREADY_COMPRESSED] = ELF_E_ALREADY_COMPRESSED_IDX,
+ [ELF_E_UNKNOWN_COMPRESSION_TYPE] = ELF_E_UNKNOWN_COMPRESSION_TYPE_IDX,
+ [ELF_E_COMPRESS_ERROR] = ELF_E_COMPRESS_ERROR_IDX,
+ [ELF_E_DECOMPRESS_ERROR] = ELF_E_DECOMPRESS_ERROR_IDX
+};
+#define nmsgidx ((int) (sizeof (msgidx) / sizeof (msgidx[0])))
+
+
+void
+internal_function
+__libelf_seterrno (int value)
+{
+ global_error = value >= 0 && value < nmsgidx ? value : ELF_E_UNKNOWN_ERROR;
+}
+
+
+const char *
+elf_errmsg (int error)
+{
+ int last_error = global_error;
+
+ if (error == 0)
+ {
+ assert (msgidx[last_error] < sizeof (msgstr));
+ return last_error != 0 ? _(msgstr + msgidx[last_error]) : NULL;
+ }
+ else if (error < -1 || error >= nmsgidx)
+ return _(msgstr + ELF_E_UNKNOWN_ERROR_IDX);
+
+ assert (msgidx[error == -1 ? last_error : error] < sizeof (msgstr));
+ return _(msgstr + msgidx[error == -1 ? last_error : error]);
+}
diff --git a/contrib/libdw/elf_getdata.c b/contrib/libdw/elf_getdata.c
new file mode 100644
index 0000000..7c3ac04
--- /dev/null
+++ b/contrib/libdw/elf_getdata.c
@@ -0,0 +1,599 @@
+/* Return the next data element from the section after possibly converting it.
+ Copyright (C) 1998-2005, 2006, 2007, 2015, 2016 Red Hat, Inc.
+ Copyright (C) 2022 Mark J. Wielaard
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+#include "common.h"
+#include "elf-knowledge.h"
+
+
+#define TYPEIDX(Sh_Type) \
+ (Sh_Type >= SHT_NULL && Sh_Type < SHT_NUM \
+ ? Sh_Type \
+ : (Sh_Type >= SHT_GNU_HASH && Sh_Type <= SHT_HISUNW \
+ ? SHT_NUM + Sh_Type - SHT_GNU_HASH \
+ : 0))
+
+/* Associate section types with libelf types. */
+static const Elf_Type shtype_map[TYPEIDX (SHT_HISUNW) + 1] =
+ {
+ [SHT_SYMTAB] = ELF_T_SYM,
+ [SHT_RELA] = ELF_T_RELA,
+ [SHT_HASH] = ELF_T_WORD,
+ [SHT_DYNAMIC] = ELF_T_DYN,
+ [SHT_REL] = ELF_T_REL,
+ [SHT_DYNSYM] = ELF_T_SYM,
+ [SHT_INIT_ARRAY] = ELF_T_ADDR,
+ [SHT_FINI_ARRAY] = ELF_T_ADDR,
+ [SHT_PREINIT_ARRAY] = ELF_T_ADDR,
+ [SHT_GROUP] = ELF_T_WORD,
+ [SHT_SYMTAB_SHNDX] = ELF_T_WORD,
+ [SHT_NOTE] = ELF_T_NHDR, /* Need alignment to guess ELF_T_NHDR8. */
+ [TYPEIDX (SHT_GNU_verdef)] = ELF_T_VDEF,
+ [TYPEIDX (SHT_GNU_verneed)] = ELF_T_VNEED,
+ [TYPEIDX (SHT_GNU_versym)] = ELF_T_HALF,
+ [TYPEIDX (SHT_SUNW_syminfo)] = ELF_T_SYMINFO,
+ [TYPEIDX (SHT_SUNW_move)] = ELF_T_MOVE,
+ [TYPEIDX (SHT_GNU_LIBLIST)] = ELF_T_LIB,
+ [TYPEIDX (SHT_GNU_HASH)] = ELF_T_GNUHASH,
+ };
+
+/* Associate libelf types with their internal alignment requirements. */
+const uint_fast8_t __libelf_type_aligns[ELFCLASSNUM - 1][ELF_T_NUM] =
+ {
+# define TYPE_ALIGNS(Bits) \
+ [ELF_T_ADDR] = __alignof__ (ElfW2(Bits,Addr)), \
+ [ELF_T_EHDR] = __alignof__ (ElfW2(Bits,Ehdr)), \
+ [ELF_T_HALF] = __alignof__ (ElfW2(Bits,Half)), \
+ [ELF_T_OFF] = __alignof__ (ElfW2(Bits,Off)), \
+ [ELF_T_PHDR] = __alignof__ (ElfW2(Bits,Phdr)), \
+ [ELF_T_SHDR] = __alignof__ (ElfW2(Bits,Shdr)), \
+ [ELF_T_SWORD] = __alignof__ (ElfW2(Bits,Sword)), \
+ [ELF_T_WORD] = __alignof__ (ElfW2(Bits,Word)), \
+ [ELF_T_XWORD] = __alignof__ (ElfW2(Bits,Xword)), \
+ [ELF_T_SXWORD] = __alignof__ (ElfW2(Bits,Sxword)), \
+ [ELF_T_SYM] = __alignof__ (ElfW2(Bits,Sym)), \
+ [ELF_T_SYMINFO] = __alignof__ (ElfW2(Bits,Syminfo)), \
+ [ELF_T_REL] = __alignof__ (ElfW2(Bits,Rel)), \
+ [ELF_T_RELA] = __alignof__ (ElfW2(Bits,Rela)), \
+ [ELF_T_DYN] = __alignof__ (ElfW2(Bits,Dyn)), \
+ [ELF_T_VDEF] = __alignof__ (ElfW2(Bits,Verdef)), \
+ [ELF_T_VDAUX] = __alignof__ (ElfW2(Bits,Verdaux)), \
+ [ELF_T_VNEED] = __alignof__ (ElfW2(Bits,Verneed)), \
+ [ELF_T_VNAUX] = __alignof__ (ElfW2(Bits,Vernaux)), \
+ [ELF_T_MOVE] = __alignof__ (ElfW2(Bits,Move)), \
+ [ELF_T_LIB] = __alignof__ (ElfW2(Bits,Lib)), \
+ [ELF_T_NHDR] = __alignof__ (ElfW2(Bits,Nhdr)), \
+ [ELF_T_AUXV] = __alignof__ (ElfW2(Bits,auxv_t)), \
+ [ELF_T_CHDR] = __alignof__ (ElfW2(Bits,Chdr)), \
+ [ELF_T_NHDR8] = 8 /* Special case for GNU Property note. */
+ [ELFCLASS32 - 1] = {
+ TYPE_ALIGNS (32),
+ [ELF_T_GNUHASH] = __alignof__ (Elf32_Word),
+ },
+ [ELFCLASS64 - 1] = {
+ TYPE_ALIGNS (64),
+ [ELF_T_GNUHASH] = __alignof__ (Elf64_Xword),
+ },
+# undef TYPE_ALIGNS
+ };
+
+
+Elf_Type
+internal_function
+__libelf_data_type (GElf_Ehdr *ehdr, int sh_type, GElf_Xword align)
+{
+ /* Some broken ELF ABI for 64-bit machines use the wrong hash table
+ entry size. See elf-knowledge.h for more information. */
+ if (sh_type == SHT_HASH && ehdr->e_ident[EI_CLASS] == ELFCLASS64)
+ {
+ return (SH_ENTSIZE_HASH (ehdr) == 4 ? ELF_T_WORD : ELF_T_XWORD);
+ }
+ else
+ {
+ Elf_Type t = shtype_map[TYPEIDX (sh_type)];
+ /* Special case for GNU Property notes. */
+ if (t == ELF_T_NHDR && align == 8)
+ t = ELF_T_NHDR8;
+ return t;
+ }
+}
+
+/* Convert the data in the current section. */
+static void
+convert_data (Elf_Scn *scn, int eclass,
+ int data, size_t size, Elf_Type type)
+{
+ const size_t align = __libelf_type_align (eclass, type);
+
+ /* Do we need to convert the data and/or adjust for alignment? */
+ if (data == MY_ELFDATA || type == ELF_T_BYTE)
+ {
+ if (((((size_t) (char *) scn->rawdata_base)) & (align - 1)) == 0)
+ /* No need to copy, we can use the raw data. */
+ scn->data_base = scn->rawdata_base;
+ else
+ {
+ scn->data_base = malloc (size);
+ if (scn->data_base == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return;
+ }
+
+ /* The copy will be appropriately aligned for direct access. */
+ memcpy (scn->data_base, scn->rawdata_base, size);
+ }
+ }
+ else
+ {
+ xfct_t fp;
+
+ scn->data_base = malloc (size);
+ if (scn->data_base == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return;
+ }
+
+ /* Make sure the source is correctly aligned for the conversion
+ function to directly access the data elements. */
+ char *rawdata_source;
+ if (((((size_t) (char *) scn->rawdata_base)) & (align - 1)) == 0)
+ rawdata_source = scn->rawdata_base;
+ else
+ {
+ rawdata_source = malloc (size);
+ if (rawdata_source == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return;
+ }
+
+ /* The copy will be appropriately aligned for direct access. */
+ memcpy (rawdata_source, scn->rawdata_base, size);
+ }
+
+ /* Get the conversion function. */
+ fp = __elf_xfctstom[eclass - 1][type];
+
+ fp (scn->data_base, rawdata_source, size, 0);
+
+ if (rawdata_source != scn->rawdata_base)
+ free (rawdata_source);
+ }
+
+ scn->data_list.data.d.d_buf = scn->data_base;
+ scn->data_list.data.d.d_size = size;
+ scn->data_list.data.d.d_type = type;
+ scn->data_list.data.d.d_off = scn->rawdata.d.d_off;
+ scn->data_list.data.d.d_align = scn->rawdata.d.d_align;
+ scn->data_list.data.d.d_version = scn->rawdata.d.d_version;
+
+ scn->data_list.data.s = scn;
+}
+
+
+/* Store the information for the raw data in the `rawdata' element. */
+int
+internal_function
+__libelf_set_rawdata_wrlock (Elf_Scn *scn)
+{
+ Elf64_Off offset;
+ Elf64_Xword size;
+ Elf64_Xword align;
+ Elf64_Xword flags;
+ int type;
+ Elf *elf = scn->elf;
+
+ if (elf->class == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr
+ = scn->shdr.e32 ?: __elf32_getshdr_wrlock (scn);
+
+ if (shdr == NULL)
+ /* Something went terribly wrong. */
+ return 1;
+
+ offset = shdr->sh_offset;
+ size = shdr->sh_size;
+ type = shdr->sh_type;
+ align = shdr->sh_addralign;
+ flags = shdr->sh_flags;
+ }
+ else
+ {
+ Elf64_Shdr *shdr
+ = scn->shdr.e64 ?: __elf64_getshdr_wrlock (scn);
+
+ if (shdr == NULL)
+ /* Something went terribly wrong. */
+ return 1;
+
+ offset = shdr->sh_offset;
+ size = shdr->sh_size;
+ type = shdr->sh_type;
+ align = shdr->sh_addralign;
+ flags = shdr->sh_flags;
+ }
+
+ /* If the section has no data (for whatever reason), leave the `d_buf'
+ pointer NULL. */
+ if (size != 0 && type != SHT_NOBITS)
+ {
+ /* First a test whether the section is valid at all. */
+ size_t entsize;
+
+ /* Compressed data has a header, but then compressed data.
+ Make sure to set the alignment of the header explicitly,
+ don't trust the file alignment for the section, it is
+ often wrong. */
+ if ((flags & SHF_COMPRESSED) != 0)
+ {
+ entsize = 1;
+ align = __libelf_type_align (elf->class, ELF_T_CHDR);
+ }
+ else if (type == SHT_HASH)
+ {
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return 1;
+ entsize = SH_ENTSIZE_HASH (ehdr);
+ }
+ else
+ {
+ Elf_Type t = shtype_map[TYPEIDX (type)];
+ if (t == ELF_T_NHDR && align == 8)
+ t = ELF_T_NHDR8;
+ if (t == ELF_T_VDEF || t == ELF_T_NHDR || t == ELF_T_NHDR8
+ || (t == ELF_T_GNUHASH && elf->class == ELFCLASS64))
+ entsize = 1;
+ else
+ entsize = __libelf_type_sizes[elf->class - 1][t];
+ }
+
+ /* We assume it is an array of bytes if it is none of the structured
+ sections we know of. */
+ if (entsize == 0)
+ entsize = 1;
+
+ if (unlikely (size % entsize != 0))
+ {
+ __libelf_seterrno (ELF_E_INVALID_DATA);
+ return 1;
+ }
+
+ /* We can use the mapped or loaded data if available. */
+ if (elf->map_address != NULL)
+ {
+ /* First see whether the information in the section header is
+ valid and it does not ask for too much. Check for unsigned
+ overflow. */
+ if (unlikely (offset > elf->maximum_size
+ || elf->maximum_size - offset < size))
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ return 1;
+ }
+
+ scn->rawdata_base = scn->rawdata.d.d_buf
+ = (char *) elf->map_address + elf->start_offset + offset;
+ }
+ else if (likely (elf->fildes != -1))
+ {
+ /* First see whether the information in the section header is
+ valid and it does not ask for too much. Check for unsigned
+ overflow. */
+ if (unlikely (offset > elf->maximum_size
+ || elf->maximum_size - offset < size))
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ return 1;
+ }
+
+ /* We have to read the data from the file. Allocate the needed
+ memory. */
+ scn->rawdata_base = scn->rawdata.d.d_buf = malloc (size);
+ if (scn->rawdata.d.d_buf == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ return 1;
+ }
+
+ ssize_t n = pread_retry (elf->fildes, scn->rawdata.d.d_buf, size,
+ elf->start_offset + offset);
+ if (unlikely ((size_t) n != size))
+ {
+ /* Cannot read the data. */
+ free (scn->rawdata.d.d_buf);
+ scn->rawdata_base = scn->rawdata.d.d_buf = NULL;
+ __libelf_seterrno (ELF_E_READ_ERROR);
+ return 1;
+ }
+ }
+ else
+ {
+ /* The file descriptor is already closed, we cannot get the data
+ anymore. */
+ __libelf_seterrno (ELF_E_FD_DISABLED);
+ return 1;
+ }
+ }
+
+ scn->rawdata.d.d_size = size;
+
+ /* Compressed data always has type ELF_T_CHDR regardless of the
+ section type. */
+ if ((flags & SHF_COMPRESSED) != 0)
+ scn->rawdata.d.d_type = ELF_T_CHDR;
+ else
+ {
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr = __gelf_getehdr_rdlock (elf, &ehdr_mem);
+ if (unlikely (ehdr == NULL))
+ return 1;
+ scn->rawdata.d.d_type = __libelf_data_type (ehdr, type, align);
+ }
+ scn->rawdata.d.d_off = 0;
+
+ /* Make sure the alignment makes sense. d_align should be aligned both
+ in the section (trivially true since d_off is zero) and in the file.
+ Unfortunately we cannot be too strict because there are ELF files
+ out there that fail this requirement. We will try to fix those up
+ in elf_update when writing out the image. But for very large
+ alignment values this can bloat the image considerably. So here
+ just check and clamp the alignment value to not be bigger than the
+ actual offset of the data in the file. Given that there is always
+ at least an ehdr this will only trigger for alignment values > 64
+ which should be uncommon. */
+ align = align ?: 1;
+ if (type != SHT_NOBITS && align > offset)
+ {
+ /* Align the offset to the next power of two. Uses algorithm from
+ https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 */
+ align = offset - 1;
+ align |= align >> 1;
+ align |= align >> 2;
+ align |= align >> 4;
+ align |= align >> 8;
+ align |= align >> 16;
+ align |= align >> 32;
+ align++;
+ }
+ scn->rawdata.d.d_align = align;
+ if (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.ehdr)
+ == offsetof (struct Elf, state.elf64.ehdr)))
+ scn->rawdata.d.d_version =
+ elf->state.elf32.ehdr->e_ident[EI_VERSION];
+ else
+ scn->rawdata.d.d_version =
+ elf->state.elf64.ehdr->e_ident[EI_VERSION];
+
+ scn->rawdata.s = scn;
+
+ scn->data_read = 1;
+
+ /* We actually read data from the file. At least we tried. */
+ scn->flags |= ELF_F_FILEDATA;
+
+ return 0;
+}
+
+int
+internal_function
+__libelf_set_rawdata (Elf_Scn *scn)
+{
+ int result;
+
+ if (scn == NULL)
+ return 1;
+
+ rwlock_wrlock (scn->elf->lock);
+ result = __libelf_set_rawdata_wrlock (scn);
+ rwlock_unlock (scn->elf->lock);
+
+ return result;
+}
+
+void
+internal_function
+__libelf_set_data_list_rdlock (Elf_Scn *scn, int wrlocked)
+{
+ if (scn->rawdata.d.d_buf != NULL && scn->rawdata.d.d_size > 0)
+ {
+ Elf *elf = scn->elf;
+
+ /* Upgrade the lock to a write lock if necessary and check
+ nobody else already did the work. */
+ if (!wrlocked)
+ {
+ rwlock_unlock (elf->lock);
+ rwlock_wrlock (elf->lock);
+ if (scn->data_list_rear != NULL)
+ return;
+ }
+
+ /* Convert according to the version and the type. */
+ convert_data (scn, elf->class,
+ (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.ehdr)
+ == offsetof (struct Elf, state.elf64.ehdr))
+ ? elf->state.elf32.ehdr->e_ident[EI_DATA]
+ : elf->state.elf64.ehdr->e_ident[EI_DATA]),
+ scn->rawdata.d.d_size, scn->rawdata.d.d_type);
+ }
+ else
+ {
+ /* This is an empty or NOBITS section. There is no buffer but
+ the size information etc is important. */
+ scn->data_list.data.d = scn->rawdata.d;
+ scn->data_list.data.s = scn;
+ }
+
+ scn->data_list_rear = &scn->data_list;
+}
+
+Elf_Data *
+internal_function
+__elf_getdata_rdlock (Elf_Scn *scn, Elf_Data *data)
+{
+ Elf_Data *result = NULL;
+ Elf *elf;
+ int locked = 0;
+
+ if (scn == NULL)
+ return NULL;
+
+ if (unlikely (scn->elf->kind != ELF_K_ELF))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ /* We will need this multiple times later on. */
+ elf = scn->elf;
+
+ /* If `data' is not NULL this means we are not addressing the initial
+ data in the file. But this also means this data is already read
+ (since otherwise it is not possible to have a valid `data' pointer)
+ and all the data structures are initialized as well. In this case
+ we can simply walk the list of data records. */
+ if (data != NULL)
+ {
+ Elf_Data_List *runp;
+
+ /* It is not possible that if DATA is not NULL the first entry is
+ returned. But this also means that there must be a first data
+ entry. */
+ if (scn->data_list_rear == NULL
+ /* The section the reference data is for must match the section
+ parameter. */
+ || unlikely (((Elf_Data_Scn *) data)->s != scn))
+ {
+ __libelf_seterrno (ELF_E_DATA_MISMATCH);
+ goto out;
+ }
+
+ /* We start searching with the first entry. */
+ runp = &scn->data_list;
+
+ while (1)
+ {
+ /* If `data' does not match any known record punt. */
+ if (runp == NULL)
+ {
+ __libelf_seterrno (ELF_E_DATA_MISMATCH);
+ goto out;
+ }
+
+ if (&runp->data.d == data)
+ /* Found the entry. */
+ break;
+
+ runp = runp->next;
+ }
+
+ /* Return the data for the next data record. */
+ result = runp->next ? &runp->next->data.d : NULL;
+ goto out;
+ }
+
+ /* If the data for this section was not yet initialized do it now. */
+ if (scn->data_read == 0)
+ {
+ /* We cannot acquire a write lock while we are holding a read
+ lock. Therefore give up the read lock and then get the write
+ lock. But this means that the data could meanwhile be
+ modified, therefore start the tests again. */
+ rwlock_unlock (elf->lock);
+ rwlock_wrlock (elf->lock);
+ locked = 1;
+
+ /* Read the data from the file. There is always a file (or
+ memory region) associated with this descriptor since
+ otherwise the `data_read' flag would be set. */
+ if (scn->data_read == 0 && __libelf_set_rawdata_wrlock (scn) != 0)
+ /* Something went wrong. The error value is already set. */
+ goto out;
+ }
+
+ /* At this point we know the raw data is available. But it might be
+ empty in case the section has size zero (for whatever reason).
+ Now create the converted data in case this is necessary. */
+ if (scn->data_list_rear == NULL)
+ __libelf_set_data_list_rdlock (scn, locked);
+
+ /* Return the first data element in the list. */
+ result = &scn->data_list.data.d;
+
+ out:
+ return result;
+}
+
+Elf_Data *
+elf_getdata (Elf_Scn *scn, Elf_Data *data)
+{
+ Elf_Data *result;
+
+ if (scn == NULL)
+ return NULL;
+
+ rwlock_rdlock (scn->elf->lock);
+ result = __elf_getdata_rdlock (scn, data);
+ rwlock_unlock (scn->elf->lock);
+
+ return result;
+}
+
+Elf_Data *
+internal_function
+__elf_getdata_wrlock (Elf_Scn *scn, Elf_Data *data)
+{
+ Elf_Data *result;
+
+ if (scn == NULL)
+ return NULL;
+
+ result = __elf_getdata_rdlock (scn, data);
+
+ return result;
+}
+INTDEF(elf_getdata)
diff --git a/contrib/libdw/elf_getscn.c b/contrib/libdw/elf_getscn.c
new file mode 100644
index 0000000..be9c76f
--- /dev/null
+++ b/contrib/libdw/elf_getscn.c
@@ -0,0 +1,120 @@
+/* Get section at specific index.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+Elf_Scn *
+elf_getscn (Elf *elf, size_t idx)
+{
+ if (elf == NULL)
+ return NULL;
+
+ if (unlikely (elf->kind != ELF_K_ELF))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ rwlock_rdlock (elf->lock);
+
+ Elf_Scn *result = NULL;
+
+ /* Find the section in the list. */
+ Elf_ScnList *runp = (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns))
+ ? &elf->state.elf32.scns : &elf->state.elf64.scns);
+
+ /* Section zero is special. It always exists even if there is no
+ "first" section. And it is needed to store "overflow" values
+ from the Elf header. */
+ if (idx == 0 && runp->cnt == 0 && runp->max > 0)
+ {
+ Elf_Scn *scn0 = &runp->data[0];
+ if (elf->class == ELFCLASS32)
+ {
+ scn0->shdr.e32 = calloc (1, sizeof (Elf32_Shdr));
+ if (scn0->shdr.e32 == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto out;
+ }
+ }
+ else
+ {
+ scn0->shdr.e64 = calloc (1, sizeof (Elf64_Shdr));
+ if (scn0->shdr.e64 == NULL)
+ {
+ __libelf_seterrno (ELF_E_NOMEM);
+ goto out;
+ }
+ }
+ scn0->elf = elf;
+ scn0->shdr_flags = ELF_F_DIRTY | ELF_F_MALLOCED;
+ scn0->list = elf->state.elf.scns_last;
+ scn0->data_read = 1;
+ runp->cnt = 1;
+ }
+
+ while (1)
+ {
+ if (idx < runp->max)
+ {
+ if (idx < runp->cnt)
+ result = &runp->data[idx];
+ else
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ break;
+ }
+
+ idx -= runp->max;
+
+ runp = runp->next;
+ if (runp == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ break;
+ }
+ }
+
+ out:
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
+INTDEF(elf_getscn)
diff --git a/contrib/libdw/elf_getshdrnum.c b/contrib/libdw/elf_getshdrnum.c
new file mode 100644
index 0000000..18e5d14
--- /dev/null
+++ b/contrib/libdw/elf_getshdrnum.c
@@ -0,0 +1,87 @@
+/* Return number of sections in the ELF file.
+ Copyright (C) 2002, 2009, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+int
+internal_function
+__elf_getshdrnum_rdlock (Elf *elf, size_t *dst)
+{
+ int result = 0;
+ int idx;
+
+ if (elf == NULL)
+ return -1;
+
+ if (unlikely (elf->kind != ELF_K_ELF))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return -1;
+ }
+
+ idx = elf->state.elf.scns_last->cnt;
+ if (idx != 0
+ || (elf->state.elf.scns_last
+ != (elf->class == ELFCLASS32
+ || (offsetof (Elf, state.elf32.scns)
+ == offsetof (Elf, state.elf64.scns))
+ ? &elf->state.elf32.scns : &elf->state.elf64.scns)))
+ /* There is at least one section. */
+ *dst = 1 + elf->state.elf.scns_last->data[idx - 1].index;
+ else
+ *dst = 0;
+
+ return result;
+}
+
+int
+elf_getshdrnum (Elf *elf, size_t *dst)
+{
+ int result;
+
+ if (elf == NULL)
+ return -1;
+
+ rwlock_rdlock (elf->lock);
+ result = __elf_getshdrnum_rdlock (elf, dst);
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
+/* Alias for the deprecated name. */
+strong_alias (elf_getshdrnum, elf_getshnum)
diff --git a/contrib/libdw/elf_getshdrstrndx.c b/contrib/libdw/elf_getshdrstrndx.c
new file mode 100644
index 0000000..2391317
--- /dev/null
+++ b/contrib/libdw/elf_getshdrstrndx.c
@@ -0,0 +1,233 @@
+/* Return section index of section header string table.
+ Copyright (C) 2002, 2005, 2009, 2014, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2002.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+#include "common.h"
+
+
+int
+elf_getshdrstrndx (Elf *elf, size_t *dst)
+{
+ int result = 0;
+
+ if (elf == NULL)
+ return -1;
+
+ if (unlikely (elf->kind != ELF_K_ELF))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return -1;
+ }
+
+ rwlock_rdlock (elf->lock);
+
+ /* We rely here on the fact that the `elf' element is a common prefix
+ of `elf32' and `elf64'. */
+ assert (offsetof (struct Elf, state.elf.ehdr)
+ == offsetof (struct Elf, state.elf32.ehdr));
+ assert (sizeof (elf->state.elf.ehdr)
+ == sizeof (elf->state.elf32.ehdr));
+ assert (offsetof (struct Elf, state.elf.ehdr)
+ == offsetof (struct Elf, state.elf64.ehdr));
+ assert (sizeof (elf->state.elf.ehdr)
+ == sizeof (elf->state.elf64.ehdr));
+
+ if (unlikely (elf->state.elf.ehdr == NULL))
+ {
+ __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
+ result = -1;
+ }
+ else
+ {
+ Elf32_Word num;
+
+ num = (elf->class == ELFCLASS32
+ ? elf->state.elf32.ehdr->e_shstrndx
+ : elf->state.elf64.ehdr->e_shstrndx);
+
+ /* Determine whether the index is too big to fit in the ELF
+ header. */
+ if (unlikely (num == SHN_XINDEX))
+ {
+ /* Yes. Search the zeroth section header. */
+ if (elf->class == ELFCLASS32)
+ {
+ size_t offset;
+ if (unlikely (elf->state.elf32.scns.cnt == 0))
+ {
+ /* Cannot use SHN_XINDEX without section headers. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
+ if (elf->state.elf32.scns.data[0].shdr.e32 != NULL)
+ {
+ num = elf->state.elf32.scns.data[0].shdr.e32->sh_link;
+ goto success;
+ }
+
+ offset = elf->state.elf32.ehdr->e_shoff;
+
+ if (elf->map_address != NULL
+ && elf->state.elf32.ehdr->e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (((size_t) ((char *) elf->map_address
+ + elf->start_offset + offset))
+ & (__alignof__ (Elf32_Shdr) - 1)) == 0))
+ {
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf32_Shdr)))
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
+ /* We can directly access the memory. */
+ num = ((Elf32_Shdr *) (elf->map_address + elf->start_offset
+ + offset))->sh_link;
+ }
+ else
+ {
+ /* We avoid reading in all the section headers. Just read
+ the first one. */
+ Elf32_Shdr shdr_mem;
+ ssize_t r;
+
+ if (unlikely ((r = pread_retry (elf->fildes, &shdr_mem,
+ sizeof (Elf32_Shdr), offset))
+ != sizeof (Elf32_Shdr)))
+ {
+ /* We must be able to read this ELF section header. */
+ if (r < 0)
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ else
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ result = -1;
+ goto out;
+ }
+
+ if (elf->state.elf32.ehdr->e_ident[EI_DATA] != MY_ELFDATA)
+ CONVERT (shdr_mem.sh_link);
+ num = shdr_mem.sh_link;
+ }
+ }
+ else
+ {
+ if (unlikely (elf->state.elf64.scns.cnt == 0))
+ {
+ /* Cannot use SHN_XINDEX without section headers. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
+ if (elf->state.elf64.scns.data[0].shdr.e64 != NULL)
+ {
+ num = elf->state.elf64.scns.data[0].shdr.e64->sh_link;
+ goto success;
+ }
+
+ size_t offset = elf->state.elf64.ehdr->e_shoff;
+
+ if (elf->map_address != NULL
+ && elf->state.elf64.ehdr->e_ident[EI_DATA] == MY_ELFDATA
+ && (ALLOW_UNALIGNED
+ || (((size_t) ((char *) elf->map_address
+ + elf->start_offset + offset))
+ & (__alignof__ (Elf64_Shdr) - 1)) == 0))
+ {
+ /* First see whether the information in the ELF header is
+ valid and it does not ask for too much. */
+ if (unlikely (elf->maximum_size - offset
+ < sizeof (Elf64_Shdr)))
+ {
+ /* Something is wrong. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION_HEADER);
+ result = -1;
+ goto out;
+ }
+
+ /* We can directly access the memory. */
+ num = ((Elf64_Shdr *) (elf->map_address + elf->start_offset
+ + offset))->sh_link;
+ }
+ else
+ {
+ /* We avoid reading in all the section headers. Just read
+ the first one. */
+ Elf64_Shdr shdr_mem;
+ ssize_t r;
+
+ if (unlikely ((r = pread_retry (elf->fildes, &shdr_mem,
+ sizeof (Elf64_Shdr), offset))
+ != sizeof (Elf64_Shdr)))
+ {
+ /* We must be able to read this ELF section header. */
+ if (r < 0)
+ __libelf_seterrno (ELF_E_INVALID_FILE);
+ else
+ __libelf_seterrno (ELF_E_INVALID_ELF);
+ result = -1;
+ goto out;
+ }
+
+ if (elf->state.elf64.ehdr->e_ident[EI_DATA] != MY_ELFDATA)
+ CONVERT (shdr_mem.sh_link);
+ num = shdr_mem.sh_link;
+ }
+ }
+ }
+
+ /* Store the result. */
+ success:
+ *dst = num;
+ }
+
+ out:
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
+INTDEF(elf_getshdrstrndx)
+/* Alias for the deprecated name. */
+strong_alias (elf_getshdrstrndx, elf_getshstrndx)
diff --git a/contrib/libdw/elf_kind.c b/contrib/libdw/elf_kind.c
new file mode 100644
index 0000000..0fb3f0c
--- /dev/null
+++ b/contrib/libdw/elf_kind.c
@@ -0,0 +1,44 @@
+/* Return the kind of file associated with the descriptor.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libelfP.h"
+
+
+Elf_Kind
+elf_kind (Elf *elf)
+{
+ return elf == NULL ? ELF_K_NONE : elf->kind;
+}
diff --git a/contrib/libdw/elf_nextscn.c b/contrib/libdw/elf_nextscn.c
new file mode 100644
index 0000000..d2f3e7c
--- /dev/null
+++ b/contrib/libdw/elf_nextscn.c
@@ -0,0 +1,83 @@
+/* Get next section.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+Elf_Scn *
+elf_nextscn (Elf *elf, Elf_Scn *scn)
+{
+ Elf_ScnList *list;
+ Elf_Scn *result = NULL;
+
+ if (elf == NULL)
+ return NULL;
+
+ rwlock_rdlock (elf->lock);
+
+ if (scn == NULL)
+ {
+ /* If no section handle is given return the first (not 0th) section.
+ Set scn to the 0th section and perform nextscn. */
+ if (elf->class == ELFCLASS32
+ || (offsetof (Elf, state.elf32.scns)
+ == offsetof (Elf, state.elf64.scns)))
+ list = &elf->state.elf32.scns;
+ else
+ list = &elf->state.elf64.scns;
+
+ scn = &list->data[0];
+ }
+ else
+ list = scn->list;
+
+ if (scn + 1 < &list->data[list->cnt])
+ result = scn + 1;
+ else if (scn + 1 == &list->data[list->max]
+ && (list = list->next) != NULL)
+ {
+ /* If there is another element in the section list it must
+ have at least one entry. */
+ assert (list->cnt > 0);
+ result = &list->data[0];
+ }
+
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
+INTDEF(elf_nextscn)
diff --git a/contrib/libdw/elf_rawdata.c b/contrib/libdw/elf_rawdata.c
new file mode 100644
index 0000000..db28f5d
--- /dev/null
+++ b/contrib/libdw/elf_rawdata.c
@@ -0,0 +1,76 @@
+/* Return raw section content.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+
+#include "libelfP.h"
+
+
+Elf_Data *
+elf_rawdata (Elf_Scn *scn, Elf_Data *data)
+{
+ if (scn == NULL || scn->elf->kind != ELF_K_ELF)
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ /* If `data' is not NULL this means we are not addressing the initial
+ data in the file. But this also means this data is already read
+ (since otherwise it is not possible to have a valid `data' pointer)
+ and all the data structures are initialized as well. In this case
+ we can simply walk the list of data records. */
+ if (data != NULL
+ || (scn->data_read != 0 && (scn->flags & ELF_F_FILEDATA) == 0))
+ {
+ /* We don't allow accessing any but the data read from the file
+ as raw. */
+ __libelf_seterrno (ELF_E_DATA_MISMATCH);
+ return NULL;
+ }
+
+ /* If the data for this section was not yet initialized do it now. */
+ if (scn->data_read == 0)
+ {
+ /* First thing we do is to read the data from the file. There is
+ always a file (or memory region) associated with this descriptor
+ since otherwise the `data_read' flag would be set. */
+ if (__libelf_set_rawdata (scn) != 0)
+ /* Something went wrong. The error value is already set. */
+ return NULL;
+ }
+
+ /* Return the first data element in the list. */
+ return &scn->rawdata.d;
+}
+INTDEF(elf_rawdata)
diff --git a/contrib/libdw/elf_readall.c b/contrib/libdw/elf_readall.c
new file mode 100644
index 0000000..d0f9a28
--- /dev/null
+++ b/contrib/libdw/elf_readall.c
@@ -0,0 +1,150 @@
+/* Read all of the file associated with the descriptor.
+ Copyright (C) 1998-2009, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libelfP.h"
+#include "common.h"
+
+
+static void
+set_address (Elf *elf, size_t offset)
+{
+ if (elf->kind == ELF_K_AR)
+ {
+ Elf *child = elf->state.ar.children;
+
+ while (child != NULL)
+ {
+ if (child->map_address == NULL)
+ {
+ child->map_address = elf->map_address;
+ child->start_offset -= offset;
+ if (child->kind == ELF_K_AR)
+ child->state.ar.offset -= offset;
+
+ set_address (child, offset);
+ }
+
+ child = child->next;
+ }
+ }
+}
+
+
+char *
+internal_function
+__libelf_readall (Elf *elf)
+{
+ /* Get the file. */
+ rwlock_wrlock (elf->lock);
+
+ if (elf->map_address == NULL && unlikely (elf->fildes == -1))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ rwlock_unlock (elf->lock);
+ return NULL;
+ }
+
+ /* If the file is not mmap'ed and not previously loaded, do it now. */
+ if (elf->map_address == NULL)
+ {
+ char *mem = NULL;
+
+ /* If this is an archive and we have derived descriptors get the
+ locks for all of them. */
+ libelf_acquire_all (elf);
+
+ if (elf->maximum_size == ~((size_t) 0))
+ {
+ /* We don't yet know how large the file is. Determine that now. */
+ struct stat st;
+
+ if (fstat (elf->fildes, &st) < 0)
+ goto read_error;
+
+ if (sizeof (size_t) >= sizeof (st.st_size)
+ || st.st_size <= ~((size_t) 0))
+ elf->maximum_size = (size_t) st.st_size;
+ else
+ {
+ errno = EOVERFLOW;
+ goto read_error;
+ }
+ }
+
+ /* Allocate all the memory we need. */
+ mem = malloc (elf->maximum_size);
+ if (mem != NULL)
+ {
+ /* Read the file content. */
+ if (unlikely ((size_t) pread_retry (elf->fildes, mem,
+ elf->maximum_size,
+ elf->start_offset)
+ != elf->maximum_size))
+ {
+ /* Something went wrong. */
+ read_error:
+ __libelf_seterrno (ELF_E_READ_ERROR);
+ free (mem);
+ }
+ else
+ {
+ /* Remember the address. */
+ elf->map_address = mem;
+
+ /* Also remember that we allocated the memory. */
+ elf->flags |= ELF_F_MALLOCED;
+
+ /* Propagate the information down to all children and
+ their children. */
+ set_address (elf, elf->start_offset);
+
+ /* Correct the own offsets. */
+ if (elf->kind == ELF_K_AR)
+ elf->state.ar.offset -= elf->start_offset;
+ elf->start_offset = 0;
+ }
+ }
+ else
+ __libelf_seterrno (ELF_E_NOMEM);
+
+ /* Free the locks on the children. */
+ libelf_release_all (elf);
+ }
+
+ rwlock_unlock (elf->lock);
+
+ return (char *) elf->map_address;
+}
diff --git a/contrib/libdw/elf_strptr.c b/contrib/libdw/elf_strptr.c
new file mode 100644
index 0000000..79a24d2
--- /dev/null
+++ b/contrib/libdw/elf_strptr.c
@@ -0,0 +1,242 @@
+/* Return string pointer from string section.
+ Copyright (C) 1998-2002, 2004, 2008, 2009, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+static void *
+get_zdata (Elf_Scn *strscn)
+{
+ size_t zsize, zalign;
+ void *zdata = __libelf_decompress_elf (strscn, &zsize, &zalign);
+ if (zdata == NULL)
+ return NULL;
+
+ strscn->zdata_base = zdata;
+ strscn->zdata_size = zsize;
+ strscn->zdata_align = zalign;
+
+ return zdata;
+}
+
+static bool validate_str (const char *str, size_t from, size_t to)
+{
+#if HAVE_DECL_MEMRCHR
+ // Check end first, which is likely a zero terminator, to prevent function call
+ return ((to > 0 && str[to - 1] == '\0')
+ || (to - from > 0 && memrchr (&str[from], '\0', to - from - 1) != NULL));
+#else
+ do {
+ if (to <= from)
+ return false;
+
+ to--;
+ } while (str[to]);
+
+ return true;
+#endif
+}
+
+char *
+elf_strptr (Elf *elf, size_t idx, size_t offset)
+{
+ if (elf == NULL)
+ return NULL;
+
+ if (elf->kind != ELF_K_ELF)
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ rwlock_rdlock (elf->lock);
+
+ char *result = NULL;
+ Elf_Scn *strscn;
+
+ /* Find the section in the list. */
+ Elf_ScnList *runp = (elf->class == ELFCLASS32
+ || (offsetof (struct Elf, state.elf32.scns)
+ == offsetof (struct Elf, state.elf64.scns))
+ ? &elf->state.elf32.scns : &elf->state.elf64.scns);
+ while (1)
+ {
+ if (idx < runp->max)
+ {
+ if (idx < runp->cnt)
+ strscn = &runp->data[idx];
+ else
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+ break;
+ }
+
+ idx -= runp->max;
+
+ runp = runp->next;
+ if (runp == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ goto out;
+ }
+ }
+
+ size_t sh_size = 0;
+ if (elf->class == ELFCLASS32)
+ {
+ Elf32_Shdr *shdr = strscn->shdr.e32 ?: __elf32_getshdr_rdlock (strscn);
+ if (unlikely (shdr == NULL || shdr->sh_type != SHT_STRTAB))
+ {
+ /* This is no string section. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION);
+ goto out;
+ }
+
+ if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
+ sh_size = shdr->sh_size;
+ else
+ {
+ if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
+ goto out;
+ sh_size = strscn->zdata_size;
+ }
+
+ if (unlikely (offset >= sh_size))
+ {
+ /* The given offset is too big, it is beyond this section. */
+ __libelf_seterrno (ELF_E_OFFSET_RANGE);
+ goto out;
+ }
+ }
+ else
+ {
+ Elf64_Shdr *shdr = strscn->shdr.e64 ?: __elf64_getshdr_rdlock (strscn);
+ if (unlikely (shdr == NULL || shdr->sh_type != SHT_STRTAB))
+ {
+ /* This is no string section. */
+ __libelf_seterrno (ELF_E_INVALID_SECTION);
+ goto out;
+ }
+
+ if ((shdr->sh_flags & SHF_COMPRESSED) == 0)
+ sh_size = shdr->sh_size;
+ else
+ {
+ if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
+ goto out;
+ sh_size = strscn->zdata_size;
+ }
+
+ if (unlikely (offset >= sh_size))
+ {
+ /* The given offset is too big, it is beyond this section. */
+ __libelf_seterrno (ELF_E_OFFSET_RANGE);
+ goto out;
+ }
+ }
+
+ if (strscn->rawdata_base == NULL && ! strscn->data_read)
+ {
+ rwlock_unlock (elf->lock);
+ rwlock_wrlock (elf->lock);
+ if (strscn->rawdata_base == NULL && ! strscn->data_read
+ /* Read the section data. */
+ && __libelf_set_rawdata_wrlock (strscn) != 0)
+ goto out;
+ }
+
+ if (unlikely (strscn->zdata_base != NULL))
+ {
+ /* Make sure the string is NUL terminated. Start from the end,
+ which very likely is a NUL char. */
+ if (likely (validate_str (strscn->zdata_base, offset, sh_size)))
+ result = &strscn->zdata_base[offset];
+ else
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ }
+ else if (likely (strscn->data_list_rear == NULL))
+ {
+ // XXX The above is currently correct since elf_newdata will
+ // make sure to convert the rawdata into the datalist if
+ // necessary. But it would be more efficient to keep the rawdata
+ // unconverted and only then iterate over the rest of the (newly
+ // added data) list. Note that when the ELF file is mmapped
+ // rawdata_base can be set while rawdata.d hasn't been
+ // initialized yet (when data_read is zero). So we cannot just
+ // look at the rawdata.d.d_size.
+
+ /* Make sure the string is NUL terminated. Start from the end,
+ which very likely is a NUL char. */
+ if (likely (validate_str (strscn->rawdata_base, offset, sh_size)))
+ result = &strscn->rawdata_base[offset];
+ else
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ }
+ else
+ {
+ /* This is a file which is currently created. Use the list of
+ data blocks. */
+ struct Elf_Data_List *dl = &strscn->data_list;
+ while (dl != NULL)
+ {
+ if (offset >= (size_t) dl->data.d.d_off
+ && offset < dl->data.d.d_off + dl->data.d.d_size)
+ {
+ /* Make sure the string is NUL terminated. Start from
+ the end, which very likely is a NUL char. */
+ if (likely (validate_str ((char *) dl->data.d.d_buf,
+ offset - dl->data.d.d_off,
+ dl->data.d.d_size)))
+ result = ((char *) dl->data.d.d_buf
+ + (offset - dl->data.d.d_off));
+ else
+ __libelf_seterrno (ELF_E_INVALID_INDEX);
+ break;
+ }
+
+ dl = dl->next;
+ }
+ }
+
+ out:
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
+INTDEF(elf_strptr)
diff --git a/contrib/libdw/elf_version.c b/contrib/libdw/elf_version.c
new file mode 100644
index 0000000..8296bb6
--- /dev/null
+++ b/contrib/libdw/elf_version.c
@@ -0,0 +1,71 @@
+/* Coordinate ELF library and application versions.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+/* Multiple threads may initialize __libelf_version.
+ pthread_once() ensures that __libelf_version is initialized only once. */
+once_define(static, version_once);
+
+/* Currently selected version. Should be EV_CURRENT.
+ Will be EV_NONE if elf_version () has not been called yet. */
+unsigned int __libelf_version = EV_NONE;
+
+static void initialize_version(void)
+{
+ __libelf_version = EV_CURRENT;
+}
+
+unsigned int
+elf_version (unsigned int version)
+{
+ if (version == EV_NONE)
+ return EV_CURRENT;
+
+ if (likely (version == EV_CURRENT))
+ {
+ /* Phew, we know this version. */
+
+ /* Signal that the version is now initialized. */
+ once(version_once, initialize_version);
+
+ /* And return the last (or initial) version. */
+ return EV_CURRENT;
+ }
+
+ /* We cannot handle this version. */
+ __libelf_seterrno (ELF_E_UNKNOWN_VERSION);
+ return EV_NONE;
+}
+INTDEF(elf_version)
diff --git a/contrib/libdw/exttypes.h b/contrib/libdw/exttypes.h
new file mode 100644
index 0000000..7bacd65
--- /dev/null
+++ b/contrib/libdw/exttypes.h
@@ -0,0 +1,104 @@
+/* External ELF types.
+ Copyright (C) 1998-2010, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifndef _EXTTYPES_H
+#define _EXTTYPES_H 1
+
+/* Integral types. */
+typedef char Elf32_Ext_Addr[ELF32_FSZ_ADDR];
+typedef char Elf32_Ext_Off[ELF32_FSZ_OFF];
+typedef char Elf32_Ext_Half[ELF32_FSZ_HALF];
+typedef char Elf32_Ext_Sword[ELF32_FSZ_SWORD];
+typedef char Elf32_Ext_Word[ELF32_FSZ_WORD];
+typedef char Elf32_Ext_Sxword[ELF32_FSZ_SXWORD];
+typedef char Elf32_Ext_Xword[ELF32_FSZ_XWORD];
+
+typedef char Elf64_Ext_Addr[ELF64_FSZ_ADDR];
+typedef char Elf64_Ext_Off[ELF64_FSZ_OFF];
+typedef char Elf64_Ext_Half[ELF64_FSZ_HALF];
+typedef char Elf64_Ext_Sword[ELF64_FSZ_SWORD];
+typedef char Elf64_Ext_Word[ELF64_FSZ_WORD];
+typedef char Elf64_Ext_Sxword[ELF64_FSZ_SXWORD];
+typedef char Elf64_Ext_Xword[ELF64_FSZ_XWORD];
+
+
+/* Define the composed types. */
+#define START(Bits, Name, EName) typedef struct {
+#define END(Bits, Name) } ElfW2(Bits, Name)
+#define TYPE_NAME(Type, Name) Type Name;
+#define TYPE_EXTRA(Text) Text
+#define TYPE_XLATE(Text)
+
+/* Get the abstract definitions. */
+#include "abstract.h"
+
+/* And define the types. */
+Ehdr32 (Ext_);
+Phdr32 (Ext_);
+Shdr32 (Ext_);
+Sym32 (Ext_);
+Rel32 (Ext_);
+Rela32 (Ext_);
+Note32 (Ext_);
+Dyn32 (Ext_);
+Verdef32 (Ext_);
+Verdaux32 (Ext_);
+Verneed32 (Ext_);
+Vernaux32 (Ext_);
+Syminfo32 (Ext_);
+Move32 (Ext_);
+Lib32 (Ext_);
+auxv_t32 (Ext_);
+Chdr32 (Ext_);
+
+Ehdr64 (Ext_);
+Phdr64 (Ext_);
+Shdr64 (Ext_);
+Sym64 (Ext_);
+Rel64 (Ext_);
+Rela64 (Ext_);
+Note64 (Ext_);
+Dyn64 (Ext_);
+Verdef64 (Ext_);
+Verdaux64 (Ext_);
+Verneed64 (Ext_);
+Vernaux64 (Ext_);
+Syminfo64 (Ext_);
+Move64 (Ext_);
+Lib64 (Ext_);
+auxv_t64 (Ext_);
+Chdr64 (Ext_);
+
+#undef START
+#undef END
+#undef TYPE_NAME
+#undef TYPE_EXTRA
+#undef TYPE_XLATE
+
+#endif /* exttypes.h */
diff --git a/contrib/libdw/frame-cache.c b/contrib/libdw/frame-cache.c
new file mode 100644
index 0000000..6da773b
--- /dev/null
+++ b/contrib/libdw/frame-cache.c
@@ -0,0 +1,70 @@
+/* Frame cache handling.
+ Copyright (C) 2009, 2015 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libebl.h"
+#include "cfi.h"
+#include
+#include
+
+
+static void
+free_cie (void *arg)
+{
+ struct dwarf_cie *cie = arg;
+
+ free ((Dwarf_Frame *) cie->initial_state);
+ free (cie);
+}
+
+#define free_fde free
+
+static void
+free_expr (void *arg)
+{
+ struct loc_s *loc = arg;
+
+ free (loc->loc);
+ free (loc);
+}
+
+void
+internal_function
+__libdw_destroy_frame_cache (Dwarf_CFI *cache)
+{
+ /* Most of the data is in our two search trees. */
+ tdestroy (cache->fde_tree, free_fde);
+ tdestroy (cache->cie_tree, free_cie);
+ tdestroy (cache->expr_tree, free_expr);
+
+// if (cache->ebl != NULL && cache->ebl != (void *) -1l)
+// ebl_closebackend (cache->ebl);
+}
diff --git a/contrib/libdw/gelf.h b/contrib/libdw/gelf.h
new file mode 100644
index 0000000..1847021
--- /dev/null
+++ b/contrib/libdw/gelf.h
@@ -0,0 +1,345 @@
+/* This file defines generic ELF types, structures, and macros.
+ Copyright (C) 1999, 2000, 2001, 2002, 2004, 2005, 2007, 2015 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 . */
+
+#ifndef _GELF_H
+#define _GELF_H 1
+
+#include
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Class independent type definitions. Correctly speaking this is not
+ true. We assume that 64-bit binaries are the largest class and
+ therefore all other classes can be represented without loss. */
+
+/* Type for a 16-bit quantity. */
+typedef Elf64_Half GElf_Half;
+
+/* Types for signed and unsigned 32-bit quantities. */
+typedef Elf64_Word GElf_Word;
+typedef Elf64_Sword GElf_Sword;
+
+/* Types for signed and unsigned 64-bit quantities. */
+typedef Elf64_Xword GElf_Xword;
+typedef Elf64_Sxword GElf_Sxword;
+
+/* Type of addresses. */
+typedef Elf64_Addr GElf_Addr;
+
+/* Type of file offsets. */
+typedef Elf64_Off GElf_Off;
+
+
+/* The ELF file header. This appears at the start of every ELF file. */
+typedef Elf64_Ehdr GElf_Ehdr;
+
+/* Section header. */
+typedef Elf64_Shdr GElf_Shdr;
+
+/* Section index. */
+/* XXX This should probably be a larger type in preparation of times when
+ regular section indices can be larger. */
+typedef Elf64_Section GElf_Section;
+
+/* Symbol table entry. */
+typedef Elf64_Sym GElf_Sym;
+
+/* The syminfo section if available contains additional information about
+ every dynamic symbol. */
+typedef Elf64_Syminfo GElf_Syminfo;
+
+/* Relocation table entry without addend (in section of type SHT_REL). */
+typedef Elf64_Rel GElf_Rel;
+
+/* Relocation table entry with addend (in section of type SHT_RELA). */
+typedef Elf64_Rela GElf_Rela;
+
+/* Relative relocation entry (in section of type SHT_RELR). */
+typedef Elf64_Relr GElf_Relr;
+
+/* Program segment header. */
+typedef Elf64_Phdr GElf_Phdr;
+
+/* Header of a compressed section. */
+typedef Elf64_Chdr GElf_Chdr;
+
+/* Dynamic section entry. */
+typedef Elf64_Dyn GElf_Dyn;
+
+
+/* Version definition sections. */
+typedef Elf64_Verdef GElf_Verdef;
+
+/* Auxiliary version information. */
+typedef Elf64_Verdaux GElf_Verdaux;
+
+/* Version dependency section. */
+typedef Elf64_Verneed GElf_Verneed;
+
+/* Auxiliary needed version information. */
+typedef Elf64_Vernaux GElf_Vernaux;
+
+
+/* Type for version symbol information. */
+typedef Elf64_Versym GElf_Versym;
+
+
+/* Auxiliary vector. */
+typedef Elf64_auxv_t GElf_auxv_t;
+
+
+/* Note section contents. */
+typedef Elf64_Nhdr GElf_Nhdr;
+
+
+/* Move structure. */
+typedef Elf64_Move GElf_Move;
+
+
+/* Library list structure. */
+typedef Elf64_Lib GElf_Lib;
+
+
+/* How to extract and insert information held in the st_info field. */
+
+#define GELF_ST_BIND(val) ELF64_ST_BIND (val)
+#define GELF_ST_TYPE(val) ELF64_ST_TYPE (val)
+#define GELF_ST_INFO(bind, type) ELF64_ST_INFO (bind, type)
+
+/* How to extract information held in the st_other field. */
+
+#define GELF_ST_VISIBILITY(val) ELF64_ST_VISIBILITY (val)
+
+
+/* How to extract and insert information held in the r_info field. */
+
+#define GELF_R_SYM(info) ELF64_R_SYM (info)
+#define GELF_R_TYPE(info) ELF64_R_TYPE (info)
+#define GELF_R_INFO(sym, type) ELF64_R_INFO (sym, type)
+
+
+/* How to extract and insert information held in the m_info field. */
+#define GELF_M_SYM(info) ELF64_M_SYM (info)
+#define GELF_M_SIZE(info) ELF64_M_SIZE (info)
+#define GELF_M_INFO(sym, size) ELF64_M_INFO (sym, size)
+
+
+/* Get class of the file associated with ELF. */
+extern int gelf_getclass (Elf *__elf);
+
+
+/* Return size of array of COUNT elements of the type denoted by TYPE
+ in the external representation. The binary class is taken from ELF.
+ The result is based on version VERSION of the ELF standard. */
+extern size_t gelf_fsize (Elf *__elf, Elf_Type __type, size_t __count,
+ unsigned int __version);
+
+/* Retrieve object file header. */
+extern GElf_Ehdr *gelf_getehdr (Elf *__elf, GElf_Ehdr *__dest);
+
+/* Update the ELF header. */
+extern int gelf_update_ehdr (Elf *__elf, GElf_Ehdr *__src);
+
+/* Create new ELF header if none exists. Creates an Elf32_Ehdr if CLASS
+ is ELFCLASS32 or an Elf64_Ehdr if CLASS is ELFCLASS64. Returns NULL
+ on error. */
+extern void *gelf_newehdr (Elf *__elf, int __class);
+
+/* Get section at OFFSET. */
+extern Elf_Scn *gelf_offscn (Elf *__elf, GElf_Off __offset);
+
+/* Retrieve section header. */
+extern GElf_Shdr *gelf_getshdr (Elf_Scn *__scn, GElf_Shdr *__dst);
+
+/* Update section header. */
+extern int gelf_update_shdr (Elf_Scn *__scn, GElf_Shdr *__src);
+
+/* Retrieve program header table entry. */
+extern GElf_Phdr *gelf_getphdr (Elf *__elf, int __ndx, GElf_Phdr *__dst);
+
+/* Update the program header. */
+extern int gelf_update_phdr (Elf *__elf, int __ndx, GElf_Phdr *__src);
+
+/* Create new program header with PHNUM entries. Creates either an
+ Elf32_Phdr or an Elf64_Phdr depending on whether the given ELF is
+ ELFCLASS32 or ELFCLASS64. Returns NULL on error. */
+extern void *gelf_newphdr (Elf *__elf, size_t __phnum);
+
+/* Get compression header of section if any. Returns NULL and sets
+ elf_errno if the section isn't compressed or an error occurred. */
+extern GElf_Chdr *gelf_getchdr (Elf_Scn *__scn, GElf_Chdr *__dst);
+
+/* Convert data structure from the representation in the file represented
+ by ELF to their memory representation. */
+extern Elf_Data *gelf_xlatetom (Elf *__elf, Elf_Data *__dest,
+ const Elf_Data *__src, unsigned int __encode);
+
+/* Convert data structure from to the representation in memory
+ represented by ELF file representation. */
+extern Elf_Data *gelf_xlatetof (Elf *__elf, Elf_Data *__dest,
+ const Elf_Data *__src, unsigned int __encode);
+
+
+/* Retrieve REL relocation info at the given index. */
+extern GElf_Rel *gelf_getrel (Elf_Data *__data, int __ndx, GElf_Rel *__dst);
+
+/* Retrieve RELA relocation info at the given index. */
+extern GElf_Rela *gelf_getrela (Elf_Data *__data, int __ndx, GElf_Rela *__dst);
+
+/* Update REL relocation information at given index. */
+extern int gelf_update_rel (Elf_Data *__dst, int __ndx, GElf_Rel *__src);
+
+/* Update RELA relocation information at given index. */
+extern int gelf_update_rela (Elf_Data *__dst, int __ndx, GElf_Rela *__src);
+
+
+/* Retrieve symbol information from the symbol table at the given index. */
+extern GElf_Sym *gelf_getsym (Elf_Data *__data, int __ndx, GElf_Sym *__dst);
+
+/* Update symbol information in the symbol table at the given index. */
+extern int gelf_update_sym (Elf_Data *__data, int __ndx, GElf_Sym *__src);
+
+
+/* Retrieve symbol information and separate section index from the
+ symbol table at the given index. */
+extern GElf_Sym *gelf_getsymshndx (Elf_Data *__symdata, Elf_Data *__shndxdata,
+ int __ndx, GElf_Sym *__sym,
+ Elf32_Word *__xshndx);
+
+/* Update symbol information and separate section index in the symbol
+ table at the given index. */
+extern int gelf_update_symshndx (Elf_Data *__symdata, Elf_Data *__shndxdata,
+ int __ndx, GElf_Sym *__sym,
+ Elf32_Word __xshndx);
+
+
+/* Retrieve additional symbol information from the symbol table at the
+ given index. */
+extern GElf_Syminfo *gelf_getsyminfo (Elf_Data *__data, int __ndx,
+ GElf_Syminfo *__dst);
+
+/* Update additional symbol information in the symbol table at the
+ given index. */
+extern int gelf_update_syminfo (Elf_Data *__data, int __ndx,
+ GElf_Syminfo *__src);
+
+
+/* Get information from dynamic table at the given index. */
+extern GElf_Dyn *gelf_getdyn (Elf_Data *__data, int __ndx, GElf_Dyn *__dst);
+
+/* Update information in dynamic table at the given index. */
+extern int gelf_update_dyn (Elf_Data *__dst, int __ndx, GElf_Dyn *__src);
+
+
+/* Get move structure at the given index. */
+extern GElf_Move *gelf_getmove (Elf_Data *__data, int __ndx, GElf_Move *__dst);
+
+/* Update move structure at the given index. */
+extern int gelf_update_move (Elf_Data *__data, int __ndx,
+ GElf_Move *__src);
+
+
+/* Get library from table at the given index. */
+extern GElf_Lib *gelf_getlib (Elf_Data *__data, int __ndx, GElf_Lib *__dst);
+
+/* Update library in table at the given index. */
+extern int gelf_update_lib (Elf_Data *__data, int __ndx, GElf_Lib *__src);
+
+
+
+/* Retrieve symbol version information at given index. */
+extern GElf_Versym *gelf_getversym (Elf_Data *__data, int __ndx,
+ GElf_Versym *__dst);
+
+/* Update symbol version information. */
+extern int gelf_update_versym (Elf_Data *__data, int __ndx,
+ GElf_Versym *__src);
+
+
+/* Retrieve required symbol version information at given offset. */
+extern GElf_Verneed *gelf_getverneed (Elf_Data *__data, int __offset,
+ GElf_Verneed *__dst);
+
+/* Update required symbol version information. */
+extern int gelf_update_verneed (Elf_Data *__data, int __offset,
+ GElf_Verneed *__src);
+
+/* Retrieve additional required symbol version information at given offset. */
+extern GElf_Vernaux *gelf_getvernaux (Elf_Data *__data, int __offset,
+ GElf_Vernaux *__dst);
+
+/* Update additional required symbol version information. */
+extern int gelf_update_vernaux (Elf_Data *__data, int __offset,
+ GElf_Vernaux *__src);
+
+
+/* Retrieve symbol version definition information at given offset. */
+extern GElf_Verdef *gelf_getverdef (Elf_Data *__data, int __offset,
+ GElf_Verdef *__dst);
+
+/* Update symbol version definition information. */
+extern int gelf_update_verdef (Elf_Data *__data, int __offset,
+ GElf_Verdef *__src);
+
+/* Retrieve additional symbol version definition information at given
+ offset. */
+extern GElf_Verdaux *gelf_getverdaux (Elf_Data *__data, int __offset,
+ GElf_Verdaux *__dst);
+
+/* Update additional symbol version definition information. */
+extern int gelf_update_verdaux (Elf_Data *__data, int __offset,
+ GElf_Verdaux *__src);
+
+
+/* Get auxv entry at the given index. */
+extern GElf_auxv_t *gelf_getauxv (Elf_Data *__data, int __ndx,
+ GElf_auxv_t *__dst);
+
+/* Update auxv entry at the given index. */
+extern int gelf_update_auxv (Elf_Data *__data, int __ndx, GElf_auxv_t *__src);
+
+
+/* Get note header at the given offset into the data, and the offsets of
+ the note's name and descriptor data. Returns the offset of the next
+ note header, or 0 for an invalid offset or corrupt note header. */
+extern size_t gelf_getnote (Elf_Data *__data, size_t __offset,
+ GElf_Nhdr *__result,
+ size_t *__name_offset, size_t *__desc_offset);
+
+
+/* Compute simple checksum from permanent parts of the ELF file. */
+extern long int gelf_checksum (Elf *__elf);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* gelf.h */
diff --git a/contrib/libdw/gelf_fsize.c b/contrib/libdw/gelf_fsize.c
new file mode 100644
index 0000000..63bcbae
--- /dev/null
+++ b/contrib/libdw/gelf_fsize.c
@@ -0,0 +1,104 @@
+/* Return the size of an object file type.
+ Copyright (C) 1998-2010, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libelfP.h"
+
+
+/* These are the sizes for all the known types. */
+const size_t __libelf_type_sizes[ELFCLASSNUM - 1][ELF_T_NUM] =
+{
+ [ELFCLASS32 - 1] = {
+#define TYPE_SIZES(LIBELFBITS) \
+ [ELF_T_ADDR] = ELFW2(LIBELFBITS, FSZ_ADDR), \
+ [ELF_T_OFF] = ELFW2(LIBELFBITS, FSZ_OFF), \
+ [ELF_T_BYTE] = 1, \
+ [ELF_T_HALF] = ELFW2(LIBELFBITS, FSZ_HALF), \
+ [ELF_T_WORD] = ELFW2(LIBELFBITS, FSZ_WORD), \
+ [ELF_T_SWORD] = ELFW2(LIBELFBITS, FSZ_SWORD), \
+ [ELF_T_XWORD] = ELFW2(LIBELFBITS, FSZ_XWORD), \
+ [ELF_T_SXWORD] = ELFW2(LIBELFBITS, FSZ_SXWORD), \
+ [ELF_T_EHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Ehdr)), \
+ [ELF_T_SHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Shdr)), \
+ [ELF_T_SYM] = sizeof (ElfW2(LIBELFBITS, Ext_Sym)), \
+ [ELF_T_REL] = sizeof (ElfW2(LIBELFBITS, Ext_Rel)), \
+ [ELF_T_RELA] = sizeof (ElfW2(LIBELFBITS, Ext_Rela)), \
+ [ELF_T_PHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Phdr)), \
+ [ELF_T_DYN] = sizeof (ElfW2(LIBELFBITS, Ext_Dyn)), \
+ [ELF_T_VDEF] = sizeof (ElfW2(LIBELFBITS, Ext_Verdef)), \
+ [ELF_T_VDAUX] = sizeof (ElfW2(LIBELFBITS, Ext_Verdaux)), \
+ [ELF_T_VNEED] = sizeof (ElfW2(LIBELFBITS, Ext_Verneed)), \
+ [ELF_T_VNAUX] = sizeof (ElfW2(LIBELFBITS, Ext_Vernaux)), \
+ [ELF_T_NHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)), \
+ /* Note the header size is the same, but padding is different. */ \
+ [ELF_T_NHDR8] = sizeof (ElfW2(LIBELFBITS, Ext_Nhdr)), \
+ [ELF_T_SYMINFO] = sizeof (ElfW2(LIBELFBITS, Ext_Syminfo)), \
+ [ELF_T_MOVE] = sizeof (ElfW2(LIBELFBITS, Ext_Move)), \
+ [ELF_T_LIB] = sizeof (ElfW2(LIBELFBITS, Ext_Lib)), \
+ [ELF_T_AUXV] = sizeof (ElfW2(LIBELFBITS, Ext_auxv_t)), \
+ [ELF_T_CHDR] = sizeof (ElfW2(LIBELFBITS, Ext_Chdr)), \
+ [ELF_T_GNUHASH] = ELFW2(LIBELFBITS, FSZ_WORD), \
+ [ELF_T_RELR] = ELFW2(LIBELFBITS, FSZ_RELR)
+ TYPE_SIZES (32)
+ },
+ [ELFCLASS64 - 1] = {
+ TYPE_SIZES (64)
+ }
+};
+
+
+size_t
+gelf_fsize (Elf *elf, Elf_Type type, size_t count, unsigned int version)
+{
+ /* We do not have differences between file and memory sizes. Better
+ not since otherwise `mmap' would not work. */
+ if (elf == NULL)
+ return 0;
+
+ if (version != EV_CURRENT)
+ {
+ __libelf_seterrno (ELF_E_UNKNOWN_VERSION);
+ return 0;
+ }
+
+ if (type >= ELF_T_NUM)
+ {
+ __libelf_seterrno (ELF_E_UNKNOWN_TYPE);
+ return 0;
+ }
+
+ return count * __libelf_type_sizes[elf->class - 1][type];
+}
+INTDEF(gelf_fsize)
diff --git a/contrib/libdw/gelf_getchdr.c b/contrib/libdw/gelf_getchdr.c
new file mode 100644
index 0000000..394bf4b
--- /dev/null
+++ b/contrib/libdw/gelf_getchdr.c
@@ -0,0 +1,69 @@
+/* Return section compression header.
+ Copyright (C) 2015 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include "libelfP.h"
+#include
+#include
+
+
+GElf_Chdr *
+gelf_getchdr (Elf_Scn *scn, GElf_Chdr *dest)
+{
+ if (scn == NULL)
+ return NULL;
+
+ if (dest == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ return NULL;
+ }
+
+ if (scn->elf->class == ELFCLASS32)
+ {
+ Elf32_Chdr *chdr = elf32_getchdr (scn);
+ if (chdr == NULL)
+ return NULL;
+ dest->ch_type = chdr->ch_type;
+ dest->ch_size = chdr->ch_size;
+ dest->ch_addralign = chdr->ch_addralign;
+ }
+ else
+ {
+ Elf64_Chdr *chdr = elf64_getchdr (scn);
+ if (chdr == NULL)
+ return NULL;
+ *dest = *chdr;
+ }
+
+ return dest;
+}
+INTDEF(gelf_getchdr)
diff --git a/contrib/libdw/gelf_getehdr.c b/contrib/libdw/gelf_getehdr.c
new file mode 100644
index 0000000..abeb70c
--- /dev/null
+++ b/contrib/libdw/gelf_getehdr.c
@@ -0,0 +1,108 @@
+/* Get ELF header.
+ Copyright (C) 1998, 1999, 2000, 2001, 2002, 2005, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+
+GElf_Ehdr *
+internal_function
+__gelf_getehdr_rdlock (Elf *elf, GElf_Ehdr *dest)
+{
+ GElf_Ehdr *result = NULL;
+
+ if (elf == NULL)
+ return NULL;
+
+ if (unlikely (elf->kind != ELF_K_ELF))
+ {
+ __libelf_seterrno (ELF_E_INVALID_HANDLE);
+ return NULL;
+ }
+
+ /* The following is an optimization: the ehdr element is at the same
+ position in both the elf32 and elf64 structure. */
+ if (offsetof (struct Elf, state.elf32.ehdr)
+ != offsetof (struct Elf, state.elf64.ehdr))
+ abort ();
+ /* Just pick one of the values. */
+ if (unlikely (elf->state.elf64.ehdr == NULL))
+ /* Maybe no ELF header was created yet. */
+ __libelf_seterrno (ELF_E_WRONG_ORDER_EHDR);
+ else if (elf->class == ELFCLASS32)
+ {
+ Elf32_Ehdr *ehdr = elf->state.elf32.ehdr;
+
+ /* Convert the 32-bit struct to an 64-bit one. */
+ memcpy (dest->e_ident, ehdr->e_ident, EI_NIDENT);
+#define COPY(name) \
+ dest->name = ehdr->name
+ COPY (e_type);
+ COPY (e_machine);
+ COPY (e_version);
+ COPY (e_entry);
+ COPY (e_phoff);
+ COPY (e_shoff);
+ COPY (e_flags);
+ COPY (e_ehsize);
+ COPY (e_phentsize);
+ COPY (e_phnum);
+ COPY (e_shentsize);
+ COPY (e_shnum);
+ COPY (e_shstrndx);
+
+ result = dest;
+ }
+ else
+ result = memcpy (dest, elf->state.elf64.ehdr, sizeof (*dest));
+
+ return result;
+}
+
+GElf_Ehdr *
+gelf_getehdr (Elf *elf, GElf_Ehdr *dest)
+{
+ GElf_Ehdr *result;
+ if (elf == NULL)
+ return NULL;
+
+ rwlock_rdlock (elf->lock);
+ result = __gelf_getehdr_rdlock (elf, dest);
+ rwlock_unlock (elf->lock);
+
+ return result;
+}
diff --git a/contrib/libdw/gelf_getshdr.c b/contrib/libdw/gelf_getshdr.c
new file mode 100644
index 0000000..3858c8e
--- /dev/null
+++ b/contrib/libdw/gelf_getshdr.c
@@ -0,0 +1,103 @@
+/* Return section header.
+ Copyright (C) 1998, 1999, 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+
+#include "libelfP.h"
+
+
+GElf_Shdr *
+gelf_getshdr (Elf_Scn *scn, GElf_Shdr *dst)
+{
+ GElf_Shdr *result = NULL;
+
+ if (scn == NULL)
+ return NULL;
+
+ if (dst == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ return NULL;
+ }
+
+ rwlock_rdlock (scn->elf->lock);
+
+ if (scn->elf->class == ELFCLASS32)
+ {
+ /* Copy the elements one-by-one. */
+ Elf32_Shdr *shdr
+ = scn->shdr.e32 ?: __elf32_getshdr_rdlock (scn);
+
+ if (shdr == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ goto out;
+ }
+
+#define COPY(name) \
+ dst->name = shdr->name
+ COPY (sh_name);
+ COPY (sh_type);
+ COPY (sh_flags);
+ COPY (sh_addr);
+ COPY (sh_offset);
+ COPY (sh_size);
+ COPY (sh_link);
+ COPY (sh_info);
+ COPY (sh_addralign);
+ COPY (sh_entsize);
+
+ result = dst;
+ }
+ else
+ {
+ Elf64_Shdr *shdr
+ = scn->shdr.e64 ?: __elf64_getshdr_rdlock (scn);
+
+ if (shdr == NULL)
+ {
+ __libelf_seterrno (ELF_E_INVALID_OPERAND);
+ goto out;
+ }
+
+ /* We only have to copy the data. */
+ result = memcpy (dst, shdr, sizeof (GElf_Shdr));
+ }
+
+ out:
+ rwlock_unlock (scn->elf->lock);
+
+ return result;
+}
+INTDEF(gelf_getshdr)
diff --git a/contrib/libdw/gelf_xlate.c b/contrib/libdw/gelf_xlate.c
new file mode 100644
index 0000000..749da1a
--- /dev/null
+++ b/contrib/libdw/gelf_xlate.c
@@ -0,0 +1,216 @@
+/* Transformation functions for ELF data types.
+ Copyright (C) 1998,1999,2000,2002,2004,2005,2006,2007,2015 Red Hat, Inc.
+ Copyright (C) 2022 Mark J. Wielaard
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 1998.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include
+#include
+#include
+
+#include "libelfP.h"
+
+#ifndef LIBELFBITS
+# define LIBELFBITS 32
+#endif
+
+
+/* Well, what shall I say. Nothing to do here. */
+#define elf_cvt_Byte(dest, src, n) \
+ (__builtin_constant_p (n) && (n) == 1 \
+ ? (void) (*((char *) (dest)) = *((char *) (src))) \
+ : Elf32_cvt_Byte (dest, src, n))
+static void
+(elf_cvt_Byte) (void *dest, const void *src, size_t n,
+ int encode __attribute__ ((unused)))
+{
+ if (n != 0)
+ memmove (dest, src, n);
+}
+
+
+/* We'll optimize the definition of the conversion functions here a
+ bit. We need only functions for 16, 32, and 64 bits. The
+ functions referenced in the table will be aliases for one of these
+ functions. Which one is decided by the ELFxx_FSZ_type. */
+
+#if ALLOW_UNALIGNED
+
+#define FETCH(Bits, ptr) (*(const uint##Bits##_t *) ptr)
+#define STORE(Bits, ptr, val) (*(uint##Bits##_t *) ptr = val)
+
+#else
+
+union unaligned
+ {
+ uint16_t u16;
+ uint32_t u32;
+ uint64_t u64;
+ } attribute_packed;
+
+#define FETCH(Bits, ptr) (((const union unaligned *) ptr)->u##Bits)
+#define STORE(Bits, ptr, val) (((union unaligned *) ptr)->u##Bits = val)
+
+#endif
+
+/* Now define the conversion functions for the basic types. We use here
+ the fact that file and memory types are the same and that we have the
+ ELFxx_FSZ_* macros.
+
+ At the same time we define inline functions which we will use to
+ convert the complex types. */
+#define FUNDAMENTAL(NAME, Name, Bits) \
+ INLINE2 (ELFW2(Bits,FSZ_##NAME), ElfW2(Bits,cvt_##Name), ElfW2(Bits,Name))
+#define INLINE2(Bytes, FName, TName) \
+ INLINE3 (Bytes, FName, TName)
+#define INLINE3(Bytes, FName, TName) \
+ static inline void FName##1 (void *dest, const void *ptr) \
+ { \
+ switch (Bytes) \
+ { \
+ case 2: STORE (16, dest, bswap_16 (FETCH (16, ptr))); break; \
+ case 4: STORE (32, dest, bswap_32 (FETCH (32, ptr))); break; \
+ case 8: STORE (64, dest, bswap_64 (FETCH (64, ptr))); break; \
+ default: \
+ abort (); \
+ } \
+ } \
+ \
+ static void FName (void *dest, const void *ptr, size_t len, \
+ int encode __attribute__ ((unused))) \
+ { \
+ size_t n = len / sizeof (TName); \
+ if (dest < ptr) \
+ while (n-- > 0) \
+ { \
+ FName##1 (dest, ptr); \
+ dest += Bytes; \
+ ptr += Bytes; \
+ } \
+ else \
+ { \
+ dest += len; \
+ ptr += len; \
+ while (n-- > 0) \
+ { \
+ ptr -= Bytes; \
+ dest -= Bytes; \
+ FName##1 (dest, ptr); \
+ } \
+ } \
+ }
+
+
+/* Now the tricky part: define the transformation functions for the
+ complex types. We will use the definitions of the types in
+ abstract.h. */
+#define START(Bits, Name, EName) \
+ static void \
+ ElfW2 (Bits, cvt_##Name) (void *dest, const void *src, size_t len, \
+ int encode __attribute__ ((unused))) \
+ { ElfW2(Bits, Name) *tdest = (ElfW2(Bits, Name) *) dest; \
+ ElfW2(Bits, Name) *tsrc = (ElfW2(Bits, Name) *) src; \
+ size_t sz = sizeof (ElfW2(Bits, Name)); \
+ size_t n; \
+ for (n = len / sz; n > 0; ++tdest, ++tsrc, --n) {
+#define END(Bits, Name) \
+ } \
+ if (len % sz > 0) /* Cannot convert partial structures, just copy. */ \
+ memmove (dest, src, len % sz); \
+ }
+#define TYPE_EXTRA(Code)
+#define TYPE_XLATE(Code) Code
+#define TYPE_NAME(Type, Name) TYPE_NAME2 (Type, Name)
+#define TYPE_NAME2(Type, Name) Type##1 (&tdest->Name, &tsrc->Name);
+#define TYPE(Name, Bits) TYPE2 (Name, Bits)
+#define TYPE2(Name, Bits) TYPE3 (Name##Bits)
+#define TYPE3(Name) Name (cvt_)
+
+/* Signal that we are generating conversion functions. */
+#define GENERATE_CONVERSION
+
+/* First generate the 32-bit conversion functions. */
+#define LIBELFBITS 32
+#include "gelf_xlate.h"
+
+/* Now generate the 64-bit conversion functions. */
+#define LIBELFBITS 64
+#include "gelf_xlate.h"
+
+
+/* We have a few functions which we must create by hand since the sections
+ do not contain records of only one type. */
+#include "version_xlate.h"
+#include "gnuhash_xlate.h"
+#include "note_xlate.h"
+#include "chdr_xlate.h"
+
+
+/* Now the externally visible table with the function pointers. */
+const xfct_t __elf_xfctstom[ELFCLASSNUM - 1][ELF_T_NUM] =
+{
+ [ELFCLASS32 - 1] = {
+#define define_xfcts(Bits) \
+ [ELF_T_BYTE] = elf_cvt_Byte, \
+ [ELF_T_ADDR] = ElfW2(Bits, cvt_Addr), \
+ [ELF_T_DYN] = ElfW2(Bits, cvt_Dyn), \
+ [ELF_T_EHDR] = ElfW2(Bits, cvt_Ehdr), \
+ [ELF_T_HALF] = ElfW2(Bits, cvt_Half), \
+ [ELF_T_OFF] = ElfW2(Bits, cvt_Off), \
+ [ELF_T_PHDR] = ElfW2(Bits, cvt_Phdr), \
+ [ELF_T_RELA] = ElfW2(Bits, cvt_Rela), \
+ [ELF_T_REL] = ElfW2(Bits, cvt_Rel), \
+ [ELF_T_SHDR] = ElfW2(Bits, cvt_Shdr), \
+ [ELF_T_SWORD] = ElfW2(Bits, cvt_Sword), \
+ [ELF_T_SYM] = ElfW2(Bits, cvt_Sym), \
+ [ELF_T_WORD] = ElfW2(Bits, cvt_Word), \
+ [ELF_T_XWORD] = ElfW2(Bits, cvt_Xword), \
+ [ELF_T_SXWORD] = ElfW2(Bits, cvt_Sxword), \
+ [ELF_T_VDEF] = elf_cvt_Verdef, \
+ [ELF_T_VDAUX] = elf_cvt_Verdef, \
+ [ELF_T_VNEED] = elf_cvt_Verneed, \
+ [ELF_T_VNAUX] = elf_cvt_Verneed, \
+ [ELF_T_NHDR] = elf_cvt_note4, \
+ [ELF_T_NHDR8] = elf_cvt_note8, \
+ [ELF_T_SYMINFO] = ElfW2(Bits, cvt_Syminfo), \
+ [ELF_T_MOVE] = ElfW2(Bits, cvt_Move), \
+ [ELF_T_LIB] = ElfW2(Bits, cvt_Lib), \
+ [ELF_T_AUXV] = ElfW2(Bits, cvt_auxv_t), \
+ [ELF_T_CHDR] = ElfW2(Bits, cvt_chdr), \
+ [ELF_T_RELR] = ElfW2(Bits, cvt_Relr)
+ define_xfcts (32),
+ [ELF_T_GNUHASH] = Elf32_cvt_Word
+ },
+ [ELFCLASS64 - 1] = {
+ define_xfcts (64),
+ [ELF_T_GNUHASH] = elf_cvt_gnuhash
+ }
+};
diff --git a/contrib/libdw/gelf_xlate.h b/contrib/libdw/gelf_xlate.h
new file mode 100644
index 0000000..d5511c3
--- /dev/null
+++ b/contrib/libdw/gelf_xlate.h
@@ -0,0 +1,58 @@
+/* Helper file for type conversion function generation.
+ Copyright (C) 1998, 1999, 2000, 2002, 2004, 2007 Red Hat, Inc.
+ This file is part of elfutils.
+ Contributed by Ulrich Drepper , 1998.
+
+ 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 . */
+
+
+/* Simple types. */
+FUNDAMENTAL (ADDR, Addr, LIBELFBITS);
+FUNDAMENTAL (OFF, Off, LIBELFBITS);
+FUNDAMENTAL (HALF, Half, LIBELFBITS);
+FUNDAMENTAL (WORD, Word, LIBELFBITS);
+FUNDAMENTAL (SWORD, Sword, LIBELFBITS);
+FUNDAMENTAL (XWORD, Xword, LIBELFBITS);
+FUNDAMENTAL (SXWORD, Sxword, LIBELFBITS);
+FUNDAMENTAL (RELR, Relr, LIBELFBITS);
+
+/* The structured types. */
+TYPE (Ehdr, LIBELFBITS)
+TYPE (Phdr, LIBELFBITS)
+TYPE (Shdr, LIBELFBITS)
+TYPE (Sym, LIBELFBITS)
+TYPE (Rel, LIBELFBITS)
+TYPE (Rela, LIBELFBITS)
+TYPE (Note, LIBELFBITS)
+TYPE (Dyn, LIBELFBITS)
+TYPE (Syminfo, LIBELFBITS)
+TYPE (Move, LIBELFBITS)
+TYPE (Lib, LIBELFBITS)
+TYPE (auxv_t, LIBELFBITS)
+TYPE (Chdr, LIBELFBITS)
+
+
+/* Prepare for the next round. */
+#undef LIBELFBITS
diff --git a/contrib/libdw/gelf_xlatetof.c b/contrib/libdw/gelf_xlatetof.c
new file mode 100644
index 0000000..e266180
--- /dev/null
+++ b/contrib/libdw/gelf_xlatetof.c
@@ -0,0 +1,50 @@
+/* Convert from memory to file representation. Generic ELF version.
+ Copyright (C) 2000, 2002, 2015 Red Hat, Inc.
+ This file is part of elfutils.
+ Written by Ulrich Drepper , 2000.
+
+ 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 . */
+
+#ifdef HAVE_CONFIG_H
+# include
+#endif
+
+#include