pax_global_header00006660000000000000000000000064136222177460014524gustar00rootroot0000000000000052 comment=064415e877eb4e6db8e048899acf73eec3a0c059 pax-utils-1.2.5/000077500000000000000000000000001362221774600134575ustar00rootroot00000000000000pax-utils-1.2.5/.depend000066400000000000000000000004131362221774600147150ustar00rootroot00000000000000scanelf.o: scanelf.c paxinc.h porting.h elf.h paxelf.h pspax.o: pspax.c paxinc.h porting.h elf.h paxelf.h dumpelf.o: dumpelf.c paxinc.h porting.h elf.h paxelf.h paxelf.o: paxelf.c paxinc.h porting.h elf.h paxelf.h paxinc.o: paxinc.c paxinc.h porting.h elf.h paxelf.h pax-utils-1.2.5/.gitignore000066400000000000000000000005371362221774600154540ustar00rootroot00000000000000*bz2 *~ *.[adio] *.l[ao] *.gdb *.pyc *.deps *.libs *.patch *.orig *.rej *.diff /pax-utils-* contrib a.out* lib*.so* core .gdb_history .gdbinit aclocal.m4 autom4te.cache build config.cache config.h config.h.in config.log config.status configure autotools libtool Makefile.in stamp-h1 /dumpelf /lddtree /pspax /scanelf /scanmacho /symtree /man/*.1 pax-utils-1.2.5/.pylintrc000066400000000000000000000013021362221774600153200ustar00rootroot00000000000000[MESSAGES CONTROL] # Disable the message, report, category or checker with the given id(s). You # can either give multiple identifier separated by comma (,) or put this option # multiple times (only on the command line, not in the configuration file where # it should appear only once). disable= too-many-lines, too-many-branches, too-many-statements, too-few-public-methods, too-many-instance-attributes, too-many-public-methods, too-many-locals, too-many-arguments, locally-enabled, locally-disabled, fixme, invalid-name, [REPORTS] reports=no [FORMAT] max-line-length=80 indent-string=' ' [SIMILARITIES] min-similarity-lines=20 [VARIABLES] dummy-variables-rgx=_ [DESIGN] max-parents=10 pax-utils-1.2.5/.travis.yml000066400000000000000000000024701362221774600155730ustar00rootroot00000000000000# Travis build integration. # https://docs.travis-ci.com/ language: c # Order here matters for implicit matrix generation and coverity scan. # See travis/main.sh for details. compiler: - gcc - clang sudo: false # Order here matters; see compiler comment above. os: - linux - osx # Travis currently uses Ubuntu 12.04 (Precise) which is too old: it does # not include pyelftools. Disable until they update. env: global: - USE_PYTHON=no - secure: "ePjz/xsdTlf0lhdZtANITiAk2lBAA9wwzB5PK/9aR5i1eBfjgXQgIJLY1y7Lqa4WU8TnSF2mwzd0pYgb320lQMC5rP7aEMAqxVZeG9WmFjet2G5vQ48tDhEJzzDhOpfvQyPehiWqLL6RUhNjE8+kpdK74P7oUFJVIuoQkUn2EuW9eUD9hV6z6tS60C0F4COdE/6DPnBySmqvjm9r9Sdfz1flCI2FXoV7MrrqrwLIx3OMtHmqmM9vGF1d2rGXRADVEGL+ldx9KvdfTLddXhWkCuHZil9YMvQLu0+gTK/g3V02Gh1/xrKmTa6v2RDqimCYDGKdHn0An+tQShYqk2JqJfzvPeysGS8lWfQePaEnHnf6niQN6h4078Ru5jH3D6AFjInrdPEOS3UZsbrJ//7hhUdiHONeQZcVcCVk7bvaJoanjjI9hJaPQXc72u81uyjlXaTOEj/znOAV92WyTaR62cT5r0GR+R7Jp214YR1IyAIB63zQVw2QCNi6W2HpyUEo3d2fOdJdaPwPQL52GxD/i3h4uGh1orYdRL4s/tdqwvYHklE2AGrEAboq2pIkmVirWH9+3+vRTnZ+fyoXD6dqDa0QvkN0pxEwmFy0IvbvTUA+0k6iplDVY21hqoid2OUpus+LjdXT2QALsY9OfMvMPdUaoFSTzWFm1jwZBPqlZN0=" # Note: OS X deps are maintained in .travis.sh until Travis supports it here. addons: apt: packages: - autoconf-archive - gnulib - xmlto script: ./travis/main.sh pax-utils-1.2.5/BUGS000066400000000000000000000006751362221774600141520ustar00rootroot00000000000000KNOWN BUGS ---------- dumpelf -vvvv ; This can segv on some malformed ELF files when trying to print *data; when using scanelf -ln and the /etc/ld.so.conf includes file which includes the orig /etc/ld.so.conf again will cause a recursion segv. This is not really a problem however as any system containing such a malformed ld.so.conf would have bigger problems. REPORTING BUGS -------------- e-mail us: solar@gentoo.org vapier@gentoo.org pax-utils-1.2.5/COPYING000066400000000000000000000431331362221774600145160ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. 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 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. pax-utils-1.2.5/Makefile000066400000000000000000000121431362221774600151200ustar00rootroot00000000000000# Copyright 2003-2006 Ned Ludd # Distributed under the terms of the GNU General Public License v2 #################################################################### check_compiler = \ $(shell if $(CC) $(WUNKNOWN) $(1) -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \ then echo "$(1)"; else echo "$(2)"; fi) check_compiler_many = $(foreach flag,$(1),$(call check_compiler,$(flag))) #################################################################### # Avoid CC overhead when installing ifneq ($(MAKECMDGOALS),install) WUNKNOWN := $(call check_compiler,-Werror=unknown-warning-option) _WFLAGS := \ -Wdeclaration-after-statement \ -Wextra \ -Wsequence-point \ -Wstrict-overflow \ -Wmisleading-indentation WFLAGS := -Wall -Wunused -Wimplicit -Wshadow -Wformat=2 \ -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings \ -Wbad-function-cast -Wnested-externs -Wcomment -Winline \ -Wchar-subscripts -Wcast-align -Wno-format-nonliteral \ $(call check_compiler_many,$(_WFLAGS)) endif CFLAGS ?= -O2 -pipe override CPPFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 LDFLAGS += LIBS := DESTDIR = PREFIX = $(DESTDIR)/usr DATADIR = $(PREFIX)/share MANDIR = $(DATADIR)/man DOCDIR = $(DATADIR)/doc PKGDOCDIR = $(DOCDIR)/pax-utils STRIP := strip MKDIR := mkdir -p INS_EXE := install -m755 INS_DATA := install -m644 PKG_CONFIG ?= pkg-config ifeq ($(USE_CAP),yes) LIBCAPS_CFLAGS := $(shell $(PKG_CONFIG) --cflags libcap) LIBCAPS_LIBS := $(shell $(PKG_CONFIG) --libs libcap) CPPFLAGS-pspax.c += $(LIBCAPS_CFLAGS) -DWANT_SYSCAP LIBS-pspax += $(LIBCAPS_LIBS) endif ifeq ($(USE_DEBUG),yes) override CPPFLAGS += -DEBUG endif ifeq ($(USE_SECCOMP),yes) LIBSECCOMP_CFLAGS := $(shell $(PKG_CONFIG) --cflags libseccomp) LIBSECCOMP_LIBS := $(shell $(PKG_CONFIG) --libs libseccomp) override CPPFLAGS += $(LIBSECCOMP_CFLAGS) -DWANT_SECCOMP LIBS += $(LIBSECCOMP_LIBS) endif ifdef PV override CPPFLAGS += -DVERSION=\"$(PV)\" else VCSID := $(shell git describe --tags HEAD) endif override CPPFLAGS += -DVCSID='"$(VCSID)"' #################################################################### ELF_TARGETS = scanelf dumpelf $(shell echo | $(CC) -dM -E - | grep -q __svr4__ || echo pspax) ELF_OBJS = paxelf.o paxldso.o MACH_TARGETS = scanmacho MACH_OBJS = paxmacho.o COMMON_OBJS = paxinc.o security.o xfuncs.o TARGETS = $(ELF_TARGETS) $(MACH_TARGETS) SCRIPTS_SH = lddtree symtree SCRIPTS_PY = lddtree OBJS = $(ELF_OBJS) $(MACH_OBJS) $(COMMON_OBJS) $(TARGETS:%=%.o) MPAGES = $(TARGETS:%=man/%.1) SOURCES = $(OBJS:%.o=%.c) all: $(OBJS) $(TARGETS) @: DEBUG_FLAGS = \ -nopie \ -fsanitize=address \ -fsanitize=leak \ -fsanitize=undefined debug: clean $(MAKE) CFLAGS="$(CFLAGS) -g3 -ggdb $(call check_compiler_many,$(DEBUG_FLAGS))" all @-chpax -permsx $(ELF_TARGETS) @-paxctl -permsx $(ELF_TARGETS) analyze: clean scan-build $(MAKE) all fuzz: clean $(MAKE) AFL_HARDEN=1 CC=afl-gcc all @rm -rf findings @printf '\nNow run:\n%s\n' \ "afl-fuzz -t 100 -i tests/fuzz/small/ -o findings/ ./scanelf -s '*' -axetrnibSDIYZB @@" compile.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(CPPFLAGS-$<) -o $@ -c $< ifeq ($(V),) Q := @ else Q := endif %.o: %.c ifeq ($(V),) @echo $(compile.c) endif $(Q)$(compile.c) $(WFLAGS) $(ELF_TARGETS): %: $(ELF_OBJS) $(COMMON_OBJS) %.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) $(LIBS-$@) $(MACH_TARGETS): %: $(MACH_OBJS) $(COMMON_OBJS) %.o $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) $(LIBS-$@) %.so: %.c $(CC) -shared -fPIC -o $@ $< depend: $(CC) $(CFLAGS) -MM $(SOURCES) > .depend clean: -rm -f $(OBJS) $(TARGETS) distclean: clean -rm -f *~ core *.o -cd man && $(MAKE) clean strip: all $(STRIP) $(TARGETS) strip-more: $(STRIP) --strip-unneeded $(TARGETS) install: all $(MKDIR) $(PREFIX)/bin/ $(MANDIR)/man1/ $(PKGDOCDIR)/ for sh in $(SCRIPTS_SH) ; do $(INS_EXE) $$sh.sh $(PREFIX)/bin/$$sh || exit $$? ; done ifneq ($(USE_PYTHON),no) for py in $(SCRIPTS_PY) ; do $(INS_EXE) $$py.py $(PREFIX)/bin/$$py || exit $$? ; done endif $(INS_EXE) $(TARGETS) $(PREFIX)/bin/ $(INS_DATA) README.md BUGS TODO $(PKGDOCDIR)/ $(INS_DATA) $(MPAGES) $(MANDIR)/man1/ PN = pax-utils P = $(PN)-$(PV) dist: ./make-tarball.sh $(DISTCHECK) $(PV) distcheck: $(MAKE) dist DISTCHECK=--check -include .depend check test: $(MAKE) -C tests .PHONY: all check clean dist install test # # All logic related to autotools is below here # GEN_MARK_START = \# @@@ GEN START @@@ \# GEN_MARK_END = \# @@@ GEN END @@@ \# EXTRA_DIST = $(shell git ls-files | grep -v ^travis/) autotools-update: $(MAKE) -C man -j sed -i.tmp '/^$(GEN_MARK_START)$$/,/^$(GEN_MARK_END)$$/d' Makefile.am @rm -f Makefile.am.tmp ( \ echo "$(GEN_MARK_START)"; \ printf 'dist_man_MANS +='; \ printf ' \\\n\t%s' `printf '%s\n' man/*.1 | LC_ALL=C sort`; \ echo; \ printf 'EXTRA_DIST +='; \ printf ' \\\n\t%s' $(EXTRA_DIST); \ echo; \ echo "$(GEN_MARK_END)"; \ ) >> Makefile.am autotools: ifeq ($(SKIP_AUTOTOOLS_UPDATE),) $(MAKE) autotools-update endif ./autogen.sh --from=make .PHONY: autotools autotools-update _autotools-update pax-utils-1.2.5/Makefile.am000066400000000000000000000040331362221774600155130ustar00rootroot00000000000000ACLOCAL_AMFLAGS = -I autotools/m4 SUBDIRS = autotools/gnulib AM_CPPFLAGS = \ -I$(top_builddir)/autotools/gnulib \ -I$(top_srcdir)/autotools/gnulib noinst_LTLIBRARIES = libpaxutils.la libpaxutils_la_LDFLAGS = -no-undefined libpaxutils_la_SOURCES = \ paxelf.c \ paxinc.c \ paxldso.c \ paxmacho.c \ security.c \ xfuncs.c LDADD = libpaxutils.la $(top_builddir)/autotools/gnulib/libgnu.a $(LIB_EACCESS) bin_SCRIPTS = lddtree symtree bin_PROGRAMS = scanelf dumpelf pspax scanmacho CLEANFILES = $(bin_SCRIPTS) if USE_PYTHON lddtree: lddtree.py else lddtree: lddtree.sh endif cp $< $@ symtree: symtree.sh cp $< $@ TMAKE = \ $(MAKE) -C $(abs_top_srcdir)/tests \ AUTOTOOLS=true \ abs_top_builddir="$(abs_top_builddir)" \ abs_top_srcdir="$(abs_top_srcdir)" check-hook: $(TMAKE) check check: check-hook # Start off with base values which we append below dist_man_MANS = EXTRA_DIST = autotools/m4/gnulib-cache.m4 # @@@ GEN START @@@ # dist_man_MANS += \ man/dumpelf.1 \ man/pspax.1 \ man/scanelf.1 \ man/scanmacho.1 EXTRA_DIST += \ .depend \ .gitignore \ .pylintrc \ .travis.yml \ BUGS \ COPYING \ Makefile \ Makefile.am \ README.md \ TODO \ autogen.sh \ configure.ac \ dumpelf.c \ elf.h \ lddtree.py \ lddtree.sh \ macho.h \ make-tarball.sh \ man/Makefile \ man/custom.xsl \ man/dumpelf.docbook \ man/fragment/date \ man/fragment/reftail \ man/fragment/version \ man/pax-utils.docbook \ man/pspax.docbook \ man/scanelf.docbook \ man/scanmacho.docbook \ paxelf.c \ paxelf.h \ paxinc.c \ paxinc.h \ paxldso.c \ paxldso.h \ paxmacho.c \ paxmacho.h \ porting.h \ pspax.c \ pylint \ scanelf.c \ scanmacho.c \ security.c \ security.h \ symtree.sh \ tests/Makefile \ tests/lddtree/Makefile \ tests/lddtree/dotest-cmp \ tests/lddtree/dotest-py \ tests/lddtree/dotest-sfx \ tests/lddtree/dotest-sh \ tests/lib.sh \ tests/scanelf/Makefile \ tests/scanelf/dotest \ tests/scanelf/scanelf.simple.good \ tests/source/Makefile \ tests/source/dotest \ tests/source/space \ xfuncs.c \ xfuncs.h # @@@ GEN END @@@ # pax-utils-1.2.5/README.md000066400000000000000000000057611362221774600147470ustar00rootroot00000000000000# ELF/PaX Utilities | What | How | | -------- | ----------------------------------------------------- | | HOMEPAGE | https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities | | GIT | git clone git://anongit.gentoo.org/proj/pax-utils.git | | VIEWVCS | https://gitweb.gentoo.org/proj/pax-utils.git/ | | STATUS | [![Build Status](https://travis-ci.org/gentoo/pax-utils.svg?branch=master)](https://travis-ci.org/gentoo/pax-utils) [![Coverity Status](https://scan.coverity.com/projects/9213/badge.svg)](https://scan.coverity.com/projects/gentoo-pax-utils) | pax-utils is a small set of utilities for peforming Q/A (mostly security) checks on systems (most notably, `scanelf`). It is focused on the ELF format, but does include a Mach-O helper too for OS X systems. While heavily integrated into Gentoo's build system, it can be used on any distro as it is a generic toolset. Originally focused only on [PaX](https://pax.grsecurity.net/), it has been expanded to be generally security focused. It still has a good number of PaX helpers for people interested in that. ## Building Just run `make`. This should work on any recent POSIX compliant system. Note: To rebuild the man-pages, you will need xmlto and the docbook-xml-dtd packages installed on your system. ## Installation `make install` You don't need PaX to use the pax-utils. Infact the only thing they really have in common is that pax-utils was initially written to aid in deploying PaX systems so it includes support for PT_PAX_FLAGS and the deprecated but still in use EI_PAX flags. For more information about PaX see the homepage at http://pax.grsecurity.net/ ## Links If you include pax-utils in your distro, feel free to send an update for this. ##### Gentoo * https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities * https://gitweb.gentoo.org/proj/pax-utils.git/ * Maintainer: Mike Frysinger , Ned Ludd ##### openSUSE * https://build.opensuse.org/package/show?package=pax-utils&project=openSUSE%3AFactory * Maintainer: ludwig.nussel@suse.de ##### Ubuntu * http://packages.ubuntu.com/edgy/devel/pax-utils * Maintainer: john.r.moser@gmail.com ##### Debian * http://packages.debian.org/unstable/misc/pax-utils * http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=388200 * Maintainer: rdenis@simphalempin.com ##### FreeBSD * http://portsmon.freebsd.org/portoverview.py?category=sysutils&portname=pax-utils * http://www.freshports.org/sysutils/pax-utils/ * http://archive.netbsd.se/?ml=freebsd-cvs-all&a=2006-08&m=2311441 * Maintainer: sbz@FreeBSD.org ##### OpenEmedded * http://www.openembedded.org/filebrowser/org.openembedded.dev/packages/pax-utils ##### Crux * http://magog.se/crux/pax-utils/Pkgfile * Maintainer: mattias@hedenskog.se ##### Fedora * https://apps.fedoraproject.org/packages/pax-utils * Maintainer: Dominik 'Rathann' Mierzejewski ##### ArchLinux * https://www.archlinux.org/packages/community/x86_64/pax-utils/ pax-utils-1.2.5/TODO000066400000000000000000000027401362221774600141520ustar00rootroot00000000000000pspax -u 0 errno = 0; uid = strtol(optarg, NULL, 10); if (uid == 0 && errno != 0) error("invalid value"); add support for RPATH checking with -nL ? we truncate 64bit types in many places to (unsigned long) ... do we really care though ? this would be an issue if: - host is 32bit - object being analyzed is 64bit - object has symbols which is larger than 32bits dumpelf does not do string checking in very very verbose mode. it assumes the strings are sane when dumping the sections. only way around this is to check everything single byte and print it out a character at a time ... sucks ... we don't handle versioned symbols well. take an ELF with debugging and do: scanelf -s '' elf notice that glibc symbols generally have version info. then search for that: scanelf -s foo@@ver elf no hits as all of our symbol comparisons ignore the versioning info. allow digging into ARM_ATTRIBUTES (.ARM.attributes) sections - need info on the section layout - figure out how to integrate cleanly (target-independent driller) http://sourceware.org/binutils/docs/as/GNU-Object-Attributes.html scanelf should look at the dynamic table for rpath/needed/soname entries instead of requiring section headers and looking up by section names. need to implement support for GNU_HASH first though so we can get the string table sizes. rewrite elf->e_shnum handling. if it's 0 (SH_UNDEF), then the size is contained in the sh_size of the first section header at index 0. add a source code check too. pax-utils-1.2.5/autogen.sh000077500000000000000000000026121362221774600154610ustar00rootroot00000000000000#!/bin/bash -e . "${0%/*}"/travis/lib.sh m4dir="autotools/m4" v rm -rf autotools if [[ $1 != "--from=make" ]] ; then v ${MAKE:-make} autotools-update fi # reload the gnulib code if possible PATH=/usr/local/src/gnu/gnulib:${PATH} mods=" alloca euidaccess faccessat fdopendir fstatat futimens getline getopt-posix mkdirat openat progname readlinkat renameat stat-time stpcpy strcasestr-simple strncat symlinkat sys_stat unlinkat utimensat vasprintf-posix " v --fold="gnulib-tool" gnulib-tool \ --source-base=autotools/gnulib --m4-base=autotools/m4 \ --import \ ${mods} # not everyone has sys-devel/autoconf-archive installed v tar xf travis/autotools.tar.xz has() { [[ " ${*:2} " == *" $1 "* ]] ; } import_ax() { local macro content m4 lm4s=() content=$(sed -e '/^[[:space:]]*#/d' -e 's:\.*::' "$@") for macro in $(echo "${content}" | grep -o '\' | sort -u) ; do for m4 in $(grep -rl "\[${macro}\]" /usr/share/aclocal/) ; do has ${m4} "${m4s[@]}" || lm4s+=( ${m4} ) done done if [[ ${#lm4s[@]} -gt 0 ]] ; then cp -v `printf '%s\n' ${lm4s[@]} | sort -u` autotools/m4/ m4s+=( "${lm4s[@]}" ) fi } m4s=() import_ax configure.ac curr=1 new=0 while [[ ${curr} -ne ${new} ]] ; do curr=${#m4s[@]} import_ax autotools/m4/ax_*.m4 new=${#m4s[@]} done export AUTOMAKE="automake --foreign" v autoreconf -i -f if [[ -x ./test.sh ]] ; then exec ./test.sh "$@" fi pax-utils-1.2.5/configure.ac000066400000000000000000000033321362221774600157460ustar00rootroot00000000000000AC_PREREQ([2.65]) AC_INIT([pax-utils], [git]) AC_CONFIG_AUX_DIR([autotools]) AM_INIT_AUTOMAKE([1.11 dist-xz no-dist-gzip silent-rules -Wall]) AM_SILENT_RULES([yes]) # AM_INIT_AUTOMAKE([silent-rules]) is broken atm AC_CONFIG_HEADER([config.h]) AC_CONFIG_MACRO_DIR([autotools/m4]) AC_PROG_CC_C99 AM_PROG_CC_C_O AM_PROG_AR AC_USE_SYSTEM_EXTENSIONS LT_INIT PKG_PROG_PKG_CONFIG gl_EARLY gl_INIT AC_ARG_WITH([caps], [AS_HELP_STRING([--with-caps], [build with capabilities])]) AS_IF([test "x$with_caps" = "xyes"], [ PKG_CHECK_MODULES(LIBCAP, libcap) CPPFLAGS="$CPPFLAGS $LIBCAP_CFLAGS -DWANT_SYSCAP" LIBS="$LIBS $LIBCAP_LIBS" ]) AC_ARG_WITH([debug], [AS_HELP_STRING([--with-debug], [enable debug code])]) AS_IF([test "x$with_debug" = "xyes"], [ CPPFLAGS="$CPPFLAGS -DEBUG" ]) AC_ARG_WITH([python], [AS_HELP_STRING([--with-python], [use lddtree.py])]) AM_CONDITIONAL([USE_PYTHON], [test "x$with_python" = "xyes"]) AC_ARG_WITH([seccomp], [AS_HELP_STRING([--with-seccomp], [build with seccomp])]) AS_IF([test "x$with_seccomp" = "xyes"], [ PKG_CHECK_MODULES(LIBSECCOMP, libseccomp) CPPFLAGS="$CPPFLAGS $LIBSECCOMP_CFLAGS -DWANT_SECCOMP" LIBS="$LIBS $LIBSECCOMP_LIBS" ]) AX_CFLAGS_WARN_ALL AC_DEFUN([PT_CHECK_CFLAG],[AX_CHECK_COMPILER_FLAGS([$1],[CFLAGS="$CFLAGS $1"])]) m4_foreach_w([flag], [ -Wunused -Wimplicit -Wshadow -Wformat=2 -Wmissing-declarations -Wno-missing-prototypes -Wwrite-strings -Wbad-function-cast -Wnested-externs -Wcomment -Winline -Wchar-subscripts -Wcast-align -Wno-format-nonliteral -Wsequence-point -Wold-style-definition -Wextra ], [ AX_CHECK_COMPILE_FLAG(flag, AS_VAR_APPEND([CFLAGS], " flag")) ]) AC_CHECK_HEADERS([linux/securebits.h]) AC_CONFIG_FILES([ Makefile autotools/gnulib/Makefile ]) AC_OUTPUT pax-utils-1.2.5/dumpelf.c000066400000000000000000000451341362221774600152660ustar00rootroot00000000000000/* * Copyright 2005-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - */ const char argv0[] = "dumpelf"; #include "paxinc.h" /* prototypes */ static void dumpelf(const char *filename, size_t file_cnt); static void dump_ehdr(elfobj *elf, const void *ehdr); static void dump_phdr(elfobj *elf, const void *phdr, size_t phdr_cnt); static void dump_shdr(elfobj *elf, const void *shdr, size_t shdr_cnt, const char *section_name); static void dump_dyn(elfobj *elf, const void *dyn, size_t dyn_cnt); #if 0 static void dump_sym(elfobj *elf, const void *sym); static void dump_rel(elfobj *elf, const void *rel); static void dump_rela(elfobj *elf, const void *rela); #endif static void usage(int status); static void parseargs(int argc, char *argv[]); /* variables to control behavior */ static char be_verbose = 0; /* misc dynamic tag caches */ static const void *phdr_dynamic_void; /* dump all internal elf info */ static void dumpelf(const char *filename, size_t file_cnt) { elfobj *elf; size_t i, b; /* verify this is real ELF */ if ((elf = readelf(filename)) == NULL) return; phdr_dynamic_void = NULL; printf("#include \n"); printf( "\n" "/*\n" " * ELF dump of '%s'\n" " * %ji (0x%jX) bytes\n" " */\n\n", filename, elf->len, elf->len); /* setup the struct to namespace this elf */ #define MAKE_STRUCT(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ b = B; \ printf( \ "Elf%1$i_Dyn dumpedelf_dyn_%2$zu[];\n" \ "struct {\n" \ "\tElf%1$i_Ehdr ehdr;\n" \ "\tElf%1$i_Phdr phdrs[%3$u];\n" \ "\tElf%1$i_Shdr shdrs[%4$u];\n" \ "\tElf%1$i_Dyn *dyns;\n" \ "} dumpedelf_%2$zu = {\n\n", \ B, file_cnt, \ (uint16_t)EGET(ehdr->e_phnum), \ (uint16_t)EGET(ehdr->e_shnum) \ ); \ } MAKE_STRUCT(32) MAKE_STRUCT(64) /* dump the elf header */ dump_ehdr(elf, elf->ehdr); /* dump the program headers */ printf("\n.phdrs = {\n"); if (elf->phdr) { #define DUMP_PHDRS(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ uint16_t phnum = EGET(ehdr->e_phnum); \ for (i = 0; i < phnum; ++i, ++phdr) \ dump_phdr(elf, phdr, i); \ } DUMP_PHDRS(32) DUMP_PHDRS(64) } else { printf(" /* no program headers ! */ "); } printf("},\n"); /* dump the section headers */ printf("\n.shdrs = {\n"); if (elf->shdr) { #define DUMP_SHDRS(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Shdr *shdr = SHDR ## B (elf->shdr); \ uint16_t shstrndx = EGET(ehdr->e_shstrndx); \ const Elf ## B ## _Shdr *strtbl = shdr + shstrndx; \ Elf ## B ## _Off offset; \ uint16_t shnum = EGET(ehdr->e_shnum); \ if (shstrndx >= shnum || !VALID_SHDR(elf, strtbl)) { \ printf(" /* corrupt section header strings table ! */ "); \ goto break_out_shdr; \ } \ offset = EGET(strtbl->sh_offset); \ for (i = 0; i < shnum; ++i, ++shdr) \ /* Don't use VALID_SHDR as we want to decode the fields */ \ dump_shdr(elf, shdr, i, elf->vdata + offset + EGET(shdr->sh_name)); \ } DUMP_SHDRS(32) DUMP_SHDRS(64) } else { printf(" /* no section headers ! */ "); } break_out_shdr: printf("},\n"); /* finish the namespace struct and start the abitrary ones */ printf("\n.dyns = dumpedelf_dyn_%zu,\n", file_cnt); printf("};\n"); /* start the arbitrary structs */ printf("Elf%zu_Dyn dumpedelf_dyn_%zu[] = {\n", b, file_cnt); if (phdr_dynamic_void) { #define DUMP_DYNS(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Phdr *phdr = phdr_dynamic_void; \ const Elf ## B ## _Dyn *dyn = elf->vdata + EGET(phdr->p_offset); \ i = 0; \ do { \ if ((void *)dyn >= elf->data_end - sizeof(*dyn)) { \ printf(" /* invalid dynamic tags ! */ "); \ break; \ } \ dump_dyn(elf, dyn++, i++); \ } while (EGET(dyn->d_tag) != DT_NULL); \ } DUMP_DYNS(32) DUMP_DYNS(64) } else { printf(" /* no dynamic tags ! */ "); } printf("};\n"); /* get out of here */ unreadelf(elf); } static void dump_ehdr(elfobj *elf, const void *ehdr_void) { #define DUMP_EHDR(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (ehdr_void); \ printf(".ehdr = {\n"); \ printf("\t.e_ident = { /* (EI_NIDENT bytes) */\n" \ "\t\t/* [%i] EI_MAG: */ 0x%X,'%c','%c','%c',\n" \ "\t\t/* [%i] EI_CLASS: */ %u , /* (%s) */\n" \ "\t\t/* [%i] EI_DATA: */ %u , /* (%s) */\n" \ "\t\t/* [%i] EI_VERSION: */ %u , /* (%s) */\n" \ "\t\t/* [%i] EI_OSABI: */ %u , /* (%s) */\n" \ "\t\t/* [%i] EI_ABIVERSION: */ %u ,\n" \ "\t\t/* [%i-%i] EI_PAD: */ 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X, 0x%X,\n" \ "\t},\n", \ EI_MAG0, ehdr->e_ident[EI_MAG0], ehdr->e_ident[EI_MAG1], ehdr->e_ident[EI_MAG2], ehdr->e_ident[EI_MAG3], \ EI_CLASS, ehdr->e_ident[EI_CLASS], get_elfeitype(EI_CLASS, ehdr->e_ident[EI_CLASS]), \ EI_DATA, ehdr->e_ident[EI_DATA], get_elfeitype(EI_DATA, ehdr->e_ident[EI_DATA]), \ EI_VERSION, ehdr->e_ident[EI_VERSION], get_elfeitype(EI_VERSION, ehdr->e_ident[EI_VERSION]), \ EI_OSABI, ehdr->e_ident[EI_OSABI], get_elfeitype(EI_OSABI, ehdr->e_ident[EI_OSABI]), \ EI_ABIVERSION, ehdr->e_ident[EI_ABIVERSION], \ EI_PAD, EI_NIDENT - 1, \ ehdr->e_ident[EI_PAD + 0], \ ehdr->e_ident[EI_PAD + 1], \ ehdr->e_ident[EI_PAD + 2], \ ehdr->e_ident[EI_PAD + 3], \ ehdr->e_ident[EI_PAD + 4], \ ehdr->e_ident[EI_PAD + 5], \ ehdr->e_ident[EI_PAD + 6] \ ); \ printf("\t.e_type = %-10u , /* (%s) */\n", (uint16_t)EGET(ehdr->e_type), get_elfetype(elf)); \ printf("\t.e_machine = %-10u , /* (%s) */\n", (uint16_t)EGET(ehdr->e_machine), get_elfemtype(elf)); \ printf("\t.e_version = %-10u , /* (%s) */\n", (uint32_t)EGET(ehdr->e_version), get_elfeitype(EI_VERSION, EGET(ehdr->e_version))); \ printf("\t.e_entry = 0x%-8"PRIX64" , /* (start address at runtime) */\n", EGET(ehdr->e_entry)); \ printf("\t.e_phoff = %-10"PRIi64" , /* (bytes into file) */\n", EGET(ehdr->e_phoff)); \ printf("\t.e_shoff = %-10"PRIi64" , /* (bytes into file) */\n", EGET(ehdr->e_shoff)); \ printf("\t.e_flags = 0x%-8X ,\n", (uint32_t)EGET(ehdr->e_flags)); \ printf("\t.e_ehsize = %-10u , /* (bytes) */\n", (uint16_t)EGET(ehdr->e_ehsize)); \ printf("\t.e_phentsize = %-10u , /* (bytes) */\n", (uint16_t)EGET(ehdr->e_phentsize)); \ /* TODO: Handle PN_XNUM */ \ printf("\t.e_phnum = %-10u , /* (program headers) */\n", (uint16_t)EGET(ehdr->e_phnum)); \ printf("\t.e_shentsize = %-10u , /* (bytes) */\n", (uint16_t)EGET(ehdr->e_shentsize)); \ printf("\t.e_shnum = %-10u , /* (section headers) */\n", (uint16_t)EGET(ehdr->e_shnum)); \ printf("\t.e_shstrndx = %-10u\n", (uint16_t)EGET(ehdr->e_shstrndx)); \ printf("},\n"); \ } DUMP_EHDR(32) DUMP_EHDR(64) } static void dump_notes(elfobj *elf, size_t B, const void *memory, const void *memory_end) { /* While normally we'd worry about Elf32_Nhdr vs Elf64_Nhdr, in the ELF * world, the two structs are exactly the same. So avoid ugly CPP. */ size_t i; bool corrupt = false; const void *ndata = memory; const char *name; const unsigned char *desc; uint32_t namesz, descsz; const Elf32_Nhdr *note; /* The first few bytes are the same between 32 & 64 bit ELFs. */ uint16_t e_type = EGET(((const Elf32_Ehdr *)elf->ehdr)->e_type); if (memory_end > elf->data_end) { printf("\n\t/%c note section is corrupt */\n", '*'); return; } printf("\n\t/%c note section dump:\n", '*'); for (i = 0; ndata < memory_end && !corrupt; ++i) { note = ndata; namesz = EGET(note->n_namesz); descsz = EGET(note->n_descsz); if (namesz > elf->len || descsz > elf->len) corrupt = true; name = namesz ? ndata + sizeof(*note) : NULL; desc = descsz ? ndata + sizeof(*note) + ALIGN_UP(namesz, 4) : NULL; ndata += sizeof(*note) + ALIGN_UP(namesz, 4) + ALIGN_UP(descsz, 4); if (ndata > memory_end) corrupt = true; if (corrupt) { name = NULL; desc = NULL; printf("\tNote is corrupt\n"); } printf("\t * Elf%zu_Nhdr note%zu = {\n", B, i); printf("\t * \t.n_namesz = %u, (bytes)", namesz); if (name) printf(" [%s]", name); printf("\n"); printf("\t * \t.n_descsz = %u, (bytes)", descsz); if (desc) { printf(" [ "); for (i = 0; i < descsz; ++i) printf("%.2X ", desc[i]); printf("]"); } printf("\n"); printf("\t * \t.n_type = %"PRIX64", [%s]\n", EGET(note->n_type), get_elfnttype(e_type, name, EGET(note->n_type))); printf("\t * };\n"); } printf("\t */\n"); } static const char *dump_p_flags(uint32_t type, uint32_t flags) { static char buf[1024]; char *p = buf; p[0] = p[1] = p[2] = '\0'; if (flags & PF_R) p = stpcpy(p, " | PF_R"); if (flags & PF_W) p = stpcpy(p, " | PF_W"); if (flags & PF_X) p = stpcpy(p, " | PF_X"); flags &= ~(PF_R | PF_W | PF_X); switch (type) { case PT_PAX_FLAGS: #define X(b) if (flags & b) { p = stpcpy(p, " | " #b); flags &= ~b; } X(PF_PAGEEXEC) X(PF_NOPAGEEXEC) X(PF_SEGMEXEC) X(PF_NOSEGMEXEC) X(PF_MPROTECT) X(PF_NOMPROTECT) X(PF_RANDEXEC) X(PF_NORANDEXEC) X(PF_EMUTRAMP) X(PF_NOEMUTRAMP) X(PF_RANDMMAP) X(PF_NORANDMMAP) #undef X break; } if (flags) sprintf(p, " | 0x%X", flags); return buf + 3; } static void dump_phdr(elfobj *elf, const void *phdr_void, size_t phdr_cnt) { #define DUMP_PHDR(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Phdr *phdr = PHDR ## B (phdr_void); \ Elf ## B ## _Off offset = EGET(phdr->p_offset); \ const void *vdata = elf->vdata + offset; \ uint32_t p_type = EGET(phdr->p_type); \ printf("/* Program Header #%zu 0x%tX */\n{\n", \ phdr_cnt, (uintptr_t)phdr_void - elf->udata); \ printf("\t.p_type = %-10u , /* [%s] */\n", p_type, get_elfptype(p_type)); \ printf("\t.p_offset = %-10"PRIi64" , /* (bytes into file) */\n", EGET(phdr->p_offset)); \ printf("\t.p_vaddr = 0x%-8"PRIX64" , /* (virtual addr at runtime) */\n", EGET(phdr->p_vaddr)); \ printf("\t.p_paddr = 0x%-8"PRIX64" , /* (physical addr at runtime) */\n", EGET(phdr->p_paddr)); \ printf("\t.p_filesz = %-10"PRIu64" , /* (bytes in file) */\n", EGET(phdr->p_filesz)); \ printf("\t.p_memsz = %-10"PRIu64" , /* (bytes in mem at runtime) */\n", EGET(phdr->p_memsz)); \ printf("\t.p_flags = 0x%-8X , /* %s */\n", (uint32_t)EGET(phdr->p_flags), dump_p_flags(p_type, EGET(phdr->p_flags))); \ printf("\t.p_align = %-10"PRIu64" , /* (min mem alignment in bytes) */\n", EGET(phdr->p_align)); \ \ if (!VALID_PHDR(elf, phdr)) { \ printf("\t/* Warning: Program segment is corrupt. */\n"); \ goto done##B; \ } \ \ switch (p_type) { \ case PT_DYNAMIC: \ phdr_dynamic_void = phdr_void; \ break; \ case PT_NOTE: \ dump_notes(elf, B, vdata, vdata + EGET(phdr->p_filesz)); \ break; \ } \ done##B: \ printf("},\n"); \ } DUMP_PHDR(32) DUMP_PHDR(64) } static const char *timestamp(uint64_t stamp) { /* This doesn't work when run on a 32-bit host with 32-bit time_t beyond * beyond 2038, but we'll worry about that later. */ static char buf[20]; time_t t; struct tm *tm; t = stamp; tm = gmtime(&t); snprintf (buf, sizeof(buf), "%04u-%02u-%02u %02u:%02u:%02u", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); return buf; } static void dump_shdr(elfobj *elf, const void *shdr_void, size_t shdr_cnt, const char *section_name) { size_t i; /* Make sure the string is valid. */ if ((const void *)section_name >= elf->data_end) section_name = ""; else if (memchr(section_name, 0, elf->len - (section_name - elf->data)) == NULL) section_name = ""; #define DUMP_SHDR(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Shdr *shdr = SHDR ## B (shdr_void); \ Elf ## B ## _Off offset = EGET(shdr->sh_offset); \ uint32_t type = EGET(shdr->sh_type); \ uint ## B ## _t size = EGET(shdr->sh_size); \ \ printf("/* Section Header #%zu '%s' 0x%tX */\n{\n", \ shdr_cnt, section_name, (uintptr_t)shdr_void - elf->udata); \ printf("\t.sh_name = %-10u ,\n", (uint32_t)EGET(shdr->sh_name)); \ printf("\t.sh_type = %-10u , /* [%s] */\n", (uint32_t)EGET(shdr->sh_type), get_elfshttype(type)); \ printf("\t.sh_flags = %-10"PRIu64" ,\n", EGET(shdr->sh_flags)); \ printf("\t.sh_addr = 0x%-8"PRIX64" ,\n", EGET(shdr->sh_addr)); \ printf("\t.sh_offset = %-10"PRIi64" , /* (bytes) */\n", (uint64_t)offset); \ printf("\t.sh_size = %-10"PRIu64" , /* (bytes) */\n", (uint64_t)size); \ printf("\t.sh_link = %-10u ,\n", (uint32_t)EGET(shdr->sh_link)); \ printf("\t.sh_info = %-10u ,\n", (uint32_t)EGET(shdr->sh_info)); \ printf("\t.sh_addralign = %-10"PRIu64" ,\n", (uint64_t)EGET(shdr->sh_addralign)); \ printf("\t.sh_entsize = %-10"PRIu64"\n", (uint64_t)EGET(shdr->sh_entsize)); \ \ if (type == SHT_NOBITS) { \ /* Special case so we can do valid check next. */ \ if (be_verbose) \ printf("\t/* NOBITS sections do not occupy the file. */\n"); \ } else if (!VALID_RANGE(elf, offset, size)) { \ printf(" /* corrupt section header ! */ "); \ } else if (size && be_verbose) { \ const void *vdata = elf->vdata + offset; \ const unsigned char *data = vdata; \ switch (type) { \ case SHT_PROGBITS: { \ if (strcmp(section_name, ".interp") == 0) { \ printf("\n\t/* ELF interpreter: %s */\n", data); \ break; \ } \ if (strcmp(section_name, ".comment") != 0) \ break; \ break; \ } \ case SHT_STRTAB: { \ char b; \ printf("\n\t/%c section dump:\n", '*'); \ b = 1; \ if (type == SHT_PROGBITS) --data; \ for (i = 0; i < size; ++i) { \ ++data; \ if (*data) { \ if (b) printf("\t * "); \ printf("%c", *data); \ b = 0; \ } else if (!b) { \ printf("\n"); \ b = 1; \ } \ } \ printf("\t */\n"); \ break; \ } \ case SHT_DYNSYM: { \ const Elf##B##_Sym *sym = vdata; \ printf("\n\t/%c section dump:\n", '*'); \ if (EGET(shdr->sh_entsize) < sizeof(*sym)) \ printf(" /* corrupt section ! */ "); \ else \ for (i = 0; i < EGET(shdr->sh_size) / EGET(shdr->sh_entsize); ++i) { \ printf("\t * Elf%i_Sym sym%zu = {\n", B, i); \ printf("\t * \t.st_name = %u,\n", (uint32_t)EGET(sym->st_name)); \ printf("\t * \t.st_value = 0x%"PRIX64",\n", EGET(sym->st_value)); \ printf("\t * \t.st_size = %"PRIu64", (bytes)\n", EGET(sym->st_size)); \ printf("\t * \t.st_info = %u,\n", (unsigned char)EGET(sym->st_info)); \ printf("\t * \t.st_other = %u,\n", (unsigned char)EGET(sym->st_other)); \ printf("\t * \t.st_shndx = %u\n", (uint16_t)EGET(sym->st_shndx)); \ printf("\t * };\n"); \ ++sym; \ } \ printf("\t */\n"); \ break; \ } \ case SHT_NOTE: \ dump_notes(elf, B, vdata, vdata + EGET(shdr->sh_size)); \ break; \ case SHT_GNU_LIBLIST: { \ const Elf##B##_Lib *lib = vdata; \ printf("\n\t/%c section dump:\n", '*'); \ if (EGET(shdr->sh_entsize) < sizeof(*lib)) \ printf(" /* corrupt section ! */ "); \ else \ for (i = 0; i < EGET(shdr->sh_size) / EGET(shdr->sh_entsize); ++i) { \ printf("\t * Elf%i_Lib lib%zu = {\n", B, i); \ printf("\t * \t.l_name = %"PRIu64",\n", EGET(lib->l_name)); \ printf("\t * \t.l_time_stamp = 0x%"PRIX64", (%s)\n", \ EGET(lib->l_time_stamp), timestamp(EGET(lib->l_time_stamp))); \ printf("\t * \t.l_checksum = 0x%"PRIX64",\n", EGET(lib->l_checksum)); \ printf("\t * \t.l_version = %"PRIu64",\n", EGET(lib->l_version)); \ printf("\t * \t.l_flags = 0x%"PRIX64"\n", EGET(lib->l_flags)); \ printf("\t * };\n"); \ ++lib; \ } \ printf("\t */\n"); \ break; \ } \ default: { \ if (be_verbose <= 1) \ break; \ printf("\n\t/%c section dump:\n", '*'); \ for (i = 0; i < size; ++i) { \ ++data; \ if (i % 20 == 0) printf("\t * "); \ printf("%.2X ", *data); /* this line can cause segfaults */ \ if (i % 20 == 19) printf("\n"); \ } \ if (i % 20) printf("\n"); \ printf("\t */\n"); \ } \ } \ } \ printf("},\n"); \ } DUMP_SHDR(32) DUMP_SHDR(64) } static void dump_dyn(elfobj *elf, const void *dyn_void, size_t dyn_cnt) { #define DUMP_DYN(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Dyn *dyn = dyn_void; \ int64_t tag = EGET(dyn->d_tag); \ printf("/* Dynamic tag #%zu '%s' 0x%tX */\n{\n", \ dyn_cnt, get_elfdtype(tag), (uintptr_t)dyn_void - elf->udata); \ printf("\t.d_tag = 0x%-8"PRIX64" ,\n", tag); \ printf("\t.d_un = {\n"); \ printf("\t\t.d_val = 0x%-8"PRIX64" ,\n", EGET(dyn->d_un.d_val)); \ printf("\t\t.d_ptr = 0x%-8"PRIX64" ,\n", EGET(dyn->d_un.d_val)); \ printf("\t},\n"); \ printf("},\n"); \ } DUMP_DYN(32) DUMP_DYN(64) } /* usage / invocation handling functions */ #define PARSE_FLAGS "vhV" #define a_argument required_argument static struct option const long_opts[] = { {"verbose", no_argument, NULL, 'v'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, no_argument, NULL, 0x0} }; static const char * const opts_help[] = { "Be verbose (can be specified more than once)", "Print this help and exit", "Print version and exit", NULL }; /* display usage and exit */ static void usage(int status) { size_t i; printf("* Dump internal ELF structure\n\n" "Usage: %s [file2 fileN ...]\n\n", argv0); printf("Options:\n"); for (i = 0; long_opts[i].name; ++i) if (long_opts[i].has_arg == no_argument) printf(" -%c, --%-13s* %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); else printf(" -%c, --%-6s * %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); exit(status); } /* parse command line arguments and preform needed actions */ static void parseargs(int argc, char *argv[]) { int flag; opterr = 0; while ((flag=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) { switch (flag) { case 'V': /* version info */ printf("pax-utils-%s: %s\n" "%s written for Gentoo by \n", VERSION, VCSID, argv0); exit(EXIT_SUCCESS); break; case 'h': usage(EXIT_SUCCESS); break; case 'v': be_verbose = (be_verbose % 20) + 1; break; case ':': err("Option missing parameter"); case '?': err("Unknown option"); default: err("Unhandled option '%c'", flag); } } if (optind == argc) err("Nothing to dump !?"); { size_t file_cnt = 0; while (optind < argc) dumpelf(argv[optind++], file_cnt++); } } int main(int argc, char *argv[]) { security_init(false); if (argc < 2) usage(EXIT_FAILURE); parseargs(argc, argv); return EXIT_SUCCESS; } pax-utils-1.2.5/elf.h000066400000000000000000004707551362221774600144200ustar00rootroot00000000000000/* This file defines standard ELF types, structures, and macros. Copyright (C) 1995-2015 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_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 */ #define EM_PARISC 15 /* HPPA */ #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_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 embeeded 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_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 embedded processor */ #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ #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 processor */ #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_A5 93 /* ARC Cores Tangent-A5 */ #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_VIDEOCORE 95 /* Alphamosaic VideoCore processor */ #define EM_TMM_GPP 96 /* Thompson Multimedia General Purpose Proc */ #define EM_NS32K 97 /* National Semiconductor 32000 series */ #define EM_TPC 98 /* Tenor Network TPC processor */ #define EM_SNP1K 99 /* Trebia SNP 1000 processor */ #define EM_ST200 100 /* STMicroelectronics ST200 microcontroller */ #define EM_IP2K 101 /* Ubicom IP2xxx microcontroller family */ #define EM_MAX 102 /* MAX Processor */ #define EM_CR 103 /* NatSemi CompactRISC microprocessor */ #define EM_F2MC16 104 /* Fujitsu F2MC16 */ #define EM_MSP430 105 /* TI embedded microcontroller msp430 */ #define EM_BLACKFIN 106 /* Analog Devices Blackfin (DSP) processor */ #define EM_SE_C33 107 /* S1C33 Family of Seiko Epson processors */ #define EM_SEP 108 /* Sharp embedded microprocessor */ #define EM_ARCA 109 /* Arca RISC Microprocessor */ #define EM_UNICORE 110 /* Microprocessor series from PKU-Unity Ltd. */ /* and MPRC of Peking University */ #define EM_ALTERA_NIOS2 113 /* Altera Nios II */ #define EM_AARCH64 183 /* ARM AARCH64 */ #define EM_TILEPRO 188 /* Tilera TILEPro */ #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze */ #define EM_TILEGX 191 /* Tilera TILE-Gx */ #define EM_NUM 192 /* 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 indeces */ #define SHT_NUM 19 /* 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_MASKOS 0x0ff00000 /* OS-specific. */ #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ #define SHF_ORDERED (1 << 30) /* Special ordering requirement (Solaris). */ #define SHF_EXCLUDE (1 << 31) /* Section is excluded unless referenced or allocated (Solaris).*/ /* 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-thru 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; /* 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_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_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_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_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_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 */ /* 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_NUM 34 /* 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. */ /* 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 */ /* 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. */ /* Auxialiary 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; /* Legal values for vna_flags. */ #define VER_FLG_WEAK 0x2 /* Weak version identifier */ /* 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_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 /* 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" /* 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 /* 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 */ /* Keep this the last entry. */ #define R_386_NUM 43 /* 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_64BIT_WHIRL 16 #define EF_MIPS_ABI2 32 #define EF_MIPS_ABI_ON32 64 #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 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. */ /* 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 /* 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_COPY 126 #define R_MIPS_JUMP_SLOT 127 /* Keep this the last entry. */ #define R_MIPS_NUM 128 /* 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 #define DT_MIPS_NUM 0x35 /* 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 indeces. */ #define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tenatively 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 */ /* 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_NUM 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 values for the DT_PPC64_OPT Dyn entry. */ #define PPC64_OPT_TLS 1 #define PPC64_OPT_MULTI_TOC 2 /* 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. */ /* 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 /* 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 */ #define R_X86_64_NUM 39 /* 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 #endif /* elf.h */ pax-utils-1.2.5/lddtree.py000077500000000000000000000643651362221774600154750ustar00rootroot00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2012-2014 Gentoo Foundation # Copyright 2012-2014 Mike Frysinger # Copyright 2012-2014 The Chromium OS Authors # Use of this source code is governed by a BSD-style license (BSD-3) # pylint: disable=C0301 """Read the ELF dependency tree and show it This does not work like `ldd` in that we do not execute/load code (only read files on disk), and we should the ELFs as a tree rather than a flat list. Paths may be globs that lddtree will take care of expanding. Useful when you want to glob a path under the ROOT path. When using the --root option, all paths are implicitly prefixed by that. e.g. lddtree -R /my/magic/root /bin/bash This will load up the ELF found at /my/magic/root/bin/bash and then resolve all libraries via that path. If you wish to actually read /bin/bash (and so use the ROOT path as an alternative library tree), you can specify the --no-auto-root option. When pairing --root with --copy-to-tree, the ROOT path will be stripped. e.g. lddtree -R /my/magic/root --copy-to-tree /foo /bin/bash You will see /foo/bin/bash and /foo/lib/libc.so.6 and not paths like /foo/my/magic/root/bin/bash. If you want that, you'll have to manually add the ROOT path to the output path. The --bindir and --libdir flags are used to normalize the output subdirs when used with --copy-to-tree. e.g. lddtree --copy-to-tree /foo /bin/bash /usr/sbin/lspci /usr/bin/lsof This will mirror the input paths in the output. So you will end up with /foo/bin/bash and /foo/usr/sbin/lspci and /foo/usr/bin/lsof. Similarly, the libraries needed will be scattered among /foo/lib/ and /foo/usr/lib/ and perhaps other paths (like /foo/lib64/ and /usr/lib/gcc/...). You can collapse all that down into nice directory structure. e.g. lddtree --copy-to-tree /foo /bin/bash /usr/sbin/lspci /usr/bin/lsof \\ --bindir /bin --libdir /lib This will place bash, lspci, and lsof into /foo/bin/. All the libraries they need will be placed into /foo/lib/ only. """ from __future__ import print_function import argparse import glob import errno import os import shutil import sys from elftools.elf.elffile import ELFFile from elftools.common import exceptions def warn(msg, prefix='warning'): """Write |msg| to stderr with a |prefix| before it""" print('%s: %s: %s' % (os.path.basename(sys.argv[0]), prefix, msg), file=sys.stderr) def err(msg, status=1): """Write |msg| to stderr and exit with |status|""" warn(msg, prefix='error') sys.exit(status) def dbg(debug, *args, **kwargs): """Pass |args| and |kwargs| to print() when |debug| is True""" if debug: print(*args, **kwargs) def bstr(buf): """Decode the byte string into a string""" if isinstance(buf, str): return buf return buf.decode('utf-8') def normpath(path): """Normalize a path Python's os.path.normpath() doesn't handle some cases: // -> // //..// -> // //..//..// -> /// """ return os.path.normpath(path).replace('//', '/') def readlink(path, root, prefixed=False): """Like os.readlink(), but relative to a |root| This does not currently handle the pathological case: /lib/foo.so -> ../../../../../../../foo.so This relies on the .. entries in / to point to itself. Args: path: The symlink to read root: The path to use for resolving absolute symlinks prefixed: When False, the |path| must not have |root| prefixed to it, nor will the return value have |root| prefixed. When True, |path| must have |root| prefixed, and the return value will have |root| added. Returns: A fully resolved symlink path """ root = root.rstrip('/') if prefixed: path = path[len(root):] while os.path.islink(root + path): path = os.path.join(os.path.dirname(path), os.readlink(root + path)) return normpath((root + path) if prefixed else path) def makedirs(path): """Like os.makedirs(), but ignore EEXIST errors""" try: os.makedirs(path) except OSError as e: if e.errno != errno.EEXIST: raise def dedupe(items): """Remove all duplicates from |items| (keeping order)""" seen = {} return [seen.setdefault(x, x) for x in items if x not in seen] def GenerateLdsoWrapper(root, path, interp, libpaths=()): """Generate a shell script wrapper which uses local ldso to run the ELF Since we cannot rely on the host glibc (or other libraries), we need to execute the local packaged ldso directly and tell it where to find our copies of libraries. Args: root: The root tree to generate scripts inside of path: The full path (inside |root|) to the program to wrap interp: The ldso interpreter that we need to execute libpaths: Extra lib paths to search for libraries """ basedir = os.path.dirname(path) interp_dir, interp_name = os.path.split(interp) libpaths = dedupe([interp_dir] + list(libpaths)) replacements = { 'interp': os.path.join(os.path.relpath(interp_dir, basedir), interp_name), 'libpaths': ':'.join(['${basedir}/' + os.path.relpath(p, basedir) for p in libpaths]), } wrapper = """#!/bin/sh if ! base=$(realpath "$0" 2>/dev/null); then case $0 in /*) base=$0;; *) base=${PWD:-`pwd`}/$0;; esac fi basedir=${base%%/*} exec \ "${basedir}/%(interp)s" \ --library-path "%(libpaths)s" \ --inhibit-cache \ --inhibit-rpath '' \ "${base}.elf" \ "$@" """ wrappath = root + path os.rename(wrappath, wrappath + '.elf') with open(wrappath, 'w') as f: f.write(wrapper % replacements) os.chmod(wrappath, 0o0755) def ParseLdPaths(str_ldpaths, root='', path=None): """Parse the colon-delimited list of paths and apply ldso rules to each Note the special handling as dictated by the ldso: - Empty paths are equivalent to $PWD - $ORIGIN is expanded to the path of the given file - (TODO) $LIB and friends Args: str_ldpaths: A colon-delimited string of paths root: The path to prepend to all paths found path: The object actively being parsed (used for $ORIGIN) Returns: list of processed paths """ ldpaths = [] for ldpath in str_ldpaths.split(':'): if ldpath == '': # The ldso treats "" paths as $PWD. ldpath = os.getcwd() elif '$ORIGIN' in ldpath: ldpath = ldpath.replace('$ORIGIN', os.path.dirname(path)) else: ldpath = root + ldpath ldpaths.append(normpath(ldpath)) return dedupe(ldpaths) def ParseLdSoConf(ldso_conf, root='/', debug=False, _first=True): """Load all the paths from a given ldso config file This should handle comments, whitespace, and "include" statements. Args: ldso_conf: The file to scan root: The path to prepend to all paths found debug: Enable debug output _first: Recursive use only; is this the first ELF ? Returns: list of paths found """ paths = [] dbg_pfx = '' if _first else ' ' try: dbg(debug, '%sParseLdSoConf(%s)' % (dbg_pfx, ldso_conf)) with open(ldso_conf) as f: for line in f.readlines(): line = line.split('#', 1)[0].strip() if not line: continue if line.startswith('include '): line = line[8:] if line[0] == '/': line = root + line.lstrip('/') else: line = os.path.dirname(ldso_conf) + '/' + line dbg(debug, '%s glob: %s' % (dbg_pfx, line)) # ldconfig in glibc uses glob() which returns entries sorted according # to LC_COLLATE. Further, ldconfig does not reset that but respects # the active env settings (which might be a mistake). Python does not # sort its results by default though, so do it ourselves. for path in sorted(glob.glob(line)): paths += ParseLdSoConf(path, root=root, debug=debug, _first=False) else: paths += [normpath(root + line)] except IOError as e: if e.errno != errno.ENOENT: warn(e) if _first: # XXX: Load paths from ldso itself. # Remove duplicate entries to speed things up. paths = dedupe(paths) return paths def LoadLdpaths(root='/', prefix='', debug=False): """Load linker paths from common locations This parses the ld.so.conf and LD_LIBRARY_PATH env var. Args: root: The root tree to prepend to paths prefix: The path under |root| to search debug: Enable debug output Returns: dict containing library paths to search """ ldpaths = { 'conf': [], 'env': [], 'interp': [], } # Load up $LD_LIBRARY_PATH. ldpaths['env'] = [] env_ldpath = os.environ.get('LD_LIBRARY_PATH') if not env_ldpath is None: if root != '/': warn('ignoring LD_LIBRARY_PATH due to ROOT usage') else: # XXX: If this contains $ORIGIN, we probably have to parse this # on a per-ELF basis so it can get turned into the right thing. ldpaths['env'] = ParseLdPaths(env_ldpath, path='') # Load up /etc/ld.so.conf. ldpaths['conf'] = ParseLdSoConf(root + prefix + '/etc/ld.so.conf', root=root, debug=debug) return ldpaths def CompatibleELFs(elf1, elf2): """See if two ELFs are compatible This compares the aspects of the ELF to see if they're compatible: bit size, endianness, machine type, and operating system. Args: elf1: an ELFFile object elf2: an ELFFile object Returns: True if compatible, False otherwise """ osabis = frozenset([e.header['e_ident']['EI_OSABI'] for e in (elf1, elf2)]) compat_sets = ( frozenset('ELFOSABI_%s' % x for x in ('NONE', 'SYSV', 'GNU', 'LINUX',)), ) return ((len(osabis) == 1 or any(osabis.issubset(x) for x in compat_sets)) and elf1.elfclass == elf2.elfclass and elf1.little_endian == elf2.little_endian and elf1.header['e_machine'] == elf2.header['e_machine']) def FindLib(elf, lib, ldpaths, root='/', debug=False): """Try to locate a |lib| that is compatible to |elf| in the given |ldpaths| Args: elf: The elf which the library should be compatible with (ELF wise) lib: The library (basename) to search for ldpaths: A list of paths to search root: The root path to resolve symlinks debug: Enable debug output Returns: Tuple of the full path to the desired library and the real path to it """ dbg(debug, ' FindLib(%s)' % lib) for ldpath in ldpaths: path = os.path.join(ldpath, lib) target = readlink(path, root, prefixed=True) if path != target: dbg(debug, ' checking: %s -> %s' % (path, target)) else: dbg(debug, ' checking:', path) if os.path.exists(target): with open(target, 'rb') as f: try: libelf = ELFFile(f) if CompatibleELFs(elf, libelf): return (target, path) except exceptions.ELFError as e: warn('%s: %s' % (target, e)) return (None, None) # We abuse the _all_libs state. We probably shouldn't, but we do currently. # pylint: disable=dangerous-default-value def ParseELF(path, root='/', prefix='', ldpaths={'conf':[], 'env':[], 'interp':[]}, display=None, debug=False, _first=True, _all_libs={}): """Parse the ELF dependency tree of the specified file Args: path: The ELF to scan root: The root tree to prepend to paths; this applies to interp and rpaths only as |path| and |ldpaths| are expected to be prefixed already prefix: The path under |root| to search ldpaths: dict containing library paths to search; should have the keys: conf, env, interp display: The path to show rather than |path| debug: Enable debug output _first: Recursive use only; is this the first ELF ? _all_libs: Recursive use only; dict of all libs we've seen Returns: a dict containing information about all the ELFs; e.g. { 'interp': '/lib64/ld-linux.so.2', 'needed': ['libc.so.6', 'libcurl.so.4',], 'libs': { 'libc.so.6': { 'path': '/lib64/libc.so.6', 'needed': [], }, 'libcurl.so.4': { 'path': '/usr/lib64/libcurl.so.4', 'needed': ['libc.so.6', 'librt.so.1',], }, }, } """ if _first: _all_libs = {} ldpaths = ldpaths.copy() ret = { 'interp': None, 'path': path if display is None else display, 'realpath': path, 'needed': [], 'rpath': [], 'runpath': [], 'libs': _all_libs, } dbg(debug, 'ParseELF(%s)' % path) with open(path, 'rb') as f: elf = ELFFile(f) # If this is the first ELF, extract the interpreter. if _first: for segment in elf.iter_segments(): if segment.header.p_type != 'PT_INTERP': continue interp = bstr(segment.get_interp_name()) dbg(debug, ' interp =', interp) ret['interp'] = normpath(root + interp) real_interp = readlink(ret['interp'], root, prefixed=True) ret['libs'][os.path.basename(interp)] = { 'path': ret['interp'], 'realpath': real_interp, 'needed': [], } # XXX: Could read it and scan for /lib paths. # If the interp is a symlink, lets follow it on the assumption that it # is in this path purely for ABI reasons, and the distro is using a # different (probably more correct) path. This can come up in some # multilib situations like s390x where /lib64/ contains all the native # libraries, but /lib/ld64.so.1 is the interp hardcoded in gcc, so the # ld64.so.1 is really a symlink to ../lib64/ld64.so.1. In the multiarch # setup, it'll be /lib/ld64.so.1 -> /lib/s390x-linux-gnu/ld64.so.1. # That is why we use |real_interp| here instead of |interp|. ldpaths['interp'] = [ os.path.dirname(real_interp), normpath(root + prefix + '/usr/' + os.path.dirname( real_interp)[len(root) + len(prefix):]), ] dbg(debug, ' ldpaths[interp] =', ldpaths['interp']) break # Parse the ELF's dynamic tags. libs = [] rpaths = [] runpaths = [] for segment in elf.iter_segments(): if segment.header.p_type != 'PT_DYNAMIC': continue for t in segment.iter_tags(): if t.entry.d_tag == 'DT_RPATH': rpaths = ParseLdPaths(bstr(t.rpath), root=root, path=path) elif t.entry.d_tag == 'DT_RUNPATH': runpaths = ParseLdPaths(bstr(t.runpath), root=root, path=path) elif t.entry.d_tag == 'DT_NEEDED': libs.append(bstr(t.needed)) if runpaths: # If both RPATH and RUNPATH are set, only the latter is used. rpaths = [] # XXX: We assume there is only one PT_DYNAMIC. This is # probably fine since the runtime ldso does the same. break if _first: # Propagate the rpaths used by the main ELF since those will be # used at runtime to locate things. ldpaths['rpath'] = rpaths ldpaths['runpath'] = runpaths dbg(debug, ' ldpaths[rpath] =', rpaths) dbg(debug, ' ldpaths[runpath] =', runpaths) ret['rpath'] = rpaths ret['runpath'] = runpaths ret['needed'] = libs # Search for the libs this ELF uses. all_ldpaths = None for lib in libs: if lib in _all_libs: continue if all_ldpaths is None: all_ldpaths = rpaths + ldpaths['rpath'] + ldpaths['env'] + runpaths + ldpaths['runpath'] + ldpaths['conf'] + ldpaths['interp'] realpath, fullpath = FindLib(elf, lib, all_ldpaths, root, debug=debug) _all_libs[lib] = { 'realpath': realpath, 'path': fullpath, 'needed': [], } if fullpath: try: lret = ParseELF(realpath, root, prefix, ldpaths, display=fullpath, debug=debug, _first=False, _all_libs=_all_libs) except exceptions.ELFError as e: warn('%s: %s' % (realpath, e)) _all_libs[lib]['needed'] = lret['needed'] del elf return ret # pylint: enable=dangerous-default-value class _NormalizePathAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): setattr(namespace, self.dest, normpath(values)) def _ActionShow(options, elf): """Show the dependency tree for this ELF""" def _show(lib, depth): chain_libs.append(lib) fullpath = elf['libs'][lib]['path'] if options.list: print(fullpath or lib) else: print('%s%s => %s' % (' ' * depth, lib, fullpath)) new_libs = [] for lib in elf['libs'][lib]['needed']: if lib in chain_libs: if not options.list: print('%s%s => !!! circular loop !!!' % (' ' * depth, lib)) continue if options.all or not lib in shown_libs: shown_libs.add(lib) new_libs.append(lib) for lib in new_libs: _show(lib, depth + 1) chain_libs.pop() shown_libs = set(elf['needed']) new_libs = elf['needed'][:] chain_libs = [] interp = elf['interp'] if interp: lib = os.path.basename(interp) shown_libs.add(lib) # If we are in non-list mode, then we want to show the "duplicate" interp # lines -- first the header (interp=>xxx), and then the DT_NEEDED line to # show that the ELF is directly linked against the interp. # If we're in list mode though, we only want to show the interp once. # Unless of course we have the --all flag active, then we show everything. if not options.all and options.list and lib in new_libs: new_libs.remove(lib) if options.list: print(elf['path']) if not interp is None: print(interp) else: print('%s (interpreter => %s)' % (elf['path'], interp)) for lib in new_libs: _show(lib, 1) def _ActionCopy(options, elf): """Copy the ELF and its dependencies to a destination tree""" def _StripRoot(path): return path[len(options.root) - 1:] def _copy(realsrc, src, striproot=True, wrapit=False, libpaths=(), outdir=None): if realsrc is None: return if wrapit: # Static ELFs don't need to be wrapped. if not elf['interp']: wrapit = False striproot = _StripRoot if striproot else lambda x: x if outdir: subdst = os.path.join(outdir, os.path.basename(src)) else: subdst = striproot(src) dst = options.dest + subdst try: # See if they're the same file. nstat = os.stat(dst + ('.elf' if wrapit else '')) ostat = os.stat(realsrc) for field in ('mode', 'mtime', 'size'): if getattr(ostat, 'st_' + field) != \ getattr(nstat, 'st_' + field): break else: return except OSError as e: if e.errno != errno.ENOENT: raise if options.verbose: print('%s -> %s' % (src, dst)) makedirs(os.path.dirname(dst)) try: shutil.copy2(realsrc, dst) except IOError: os.unlink(dst) shutil.copy2(realsrc, dst) if wrapit: if options.verbose: print('generate wrapper %s' % (dst,)) if options.libdir: interp = os.path.join(options.libdir, os.path.basename(elf['interp'])) else: interp = _StripRoot(elf['interp']) GenerateLdsoWrapper(options.dest, subdst, interp, libpaths) # XXX: We should automatically import libgcc_s.so whenever libpthread.so # is copied over (since we know it can be dlopen-ed by NPTL at runtime). # Similarly, we should provide an option for automatically copying over # the libnsl.so and libnss_*.so libraries, as well as an open ended list # for known libs that get loaded (e.g. curl will dlopen(libresolv)). uniq_libpaths = set() for lib in elf['libs']: libdata = elf['libs'][lib] path = libdata['realpath'] if path is None: warn('could not locate library: %s' % lib) continue if not options.libdir: uniq_libpaths.add(_StripRoot(os.path.dirname(path))) _copy(path, libdata['path'], outdir=options.libdir) if not options.libdir: libpaths = list(uniq_libpaths) if elf['runpath']: libpaths = elf['runpath'] + libpaths else: libpaths = elf['rpath'] + libpaths else: uniq_libpaths.add(options.libdir) libpaths = list(uniq_libpaths) # We don't bother to copy this as ParseElf adds the interp to the 'libs', # so it was already copied in the libs loop above. #_copy(elf['interp'], outdir=options.libdir) _copy(elf['realpath'], elf['path'], striproot=options.auto_root, wrapit=options.generate_wrappers, libpaths=libpaths, outdir=options.bindir) def GetParser(): """Get a CLI parser.""" parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument('-a', '--all', action='store_true', default=False, help='Show all duplicated dependencies') parser.add_argument('-R', '--root', default=os.environ.get('ROOT', ''), type=str, action=_NormalizePathAction, help='Search for all files/dependencies in ROOT') parser.add_argument('-P', '--prefix', default=os.environ.get( 'EPREFIX', '@GENTOO_PORTAGE_EPREFIX@'), type=str, action=_NormalizePathAction, help='Specify EPREFIX for binaries (for Gentoo Prefix)') parser.add_argument('--no-auto-root', dest='auto_root', action='store_false', default=True, help='Do not automatically prefix input ELFs with ROOT') parser.add_argument('-l', '--list', action='store_true', default=False, help='Display output in a simple list (easy for copying)') parser.add_argument('-x', '--debug', action='store_true', default=False, help='Run with debugging') parser.add_argument('-v', '--verbose', action='store_true', default=False, help='Be verbose') parser.add_argument('--skip-non-elfs', action='store_true', default=False, help='Skip plain (non-ELF) files instead of warning') parser.add_argument('-V', '--version', action='version', version='lddtree by Mike Frysinger ', help='Show version information') parser.add_argument('path', nargs='+') group = parser.add_argument_group('Copying options') group.add_argument('--copy-to-tree', dest='dest', default=None, type=str, action=_NormalizePathAction, help='Copy all files to the specified tree') group.add_argument('--bindir', default=None, type=str, action=_NormalizePathAction, help='Dir to store all ELFs specified on the command line') group.add_argument('--libdir', default=None, type=str, action=_NormalizePathAction, help='Dir to store all ELF libs') group.add_argument('--generate-wrappers', action='store_true', default=False, help='Wrap executable ELFs with scripts for local ldso') group.add_argument('--copy-non-elfs', action='store_true', default=False, help='Copy over plain (non-ELF) files instead of warn+ignore') return parser def main(argv): """The main entry point!""" parser = GetParser() options = parser.parse_args(argv) paths = options.path if options.root != '/': options.root += '/' if options.prefix == '@''GENTOO_PORTAGE_EPREFIX''@': options.prefix = '' if options.bindir and options.bindir[0] != '/': parser.error('--bindir accepts absolute paths only') if options.libdir and options.libdir[0] != '/': parser.error('--libdir accepts absolute paths only') if options.skip_non_elfs and options.copy_non_elfs: parser.error('pick one handler for non-ELFs: skip or copy') dbg(options.debug, 'root =', options.root) if options.dest: dbg(options.debug, 'dest =', options.dest) if not paths: err('missing ELF files to scan') ldpaths = LoadLdpaths(options.root, options.prefix, debug=options.debug) dbg(options.debug, 'ldpaths[conf] =', ldpaths['conf']) dbg(options.debug, 'ldpaths[env] =', ldpaths['env']) # Process all the files specified. ret = 0 for path in paths: dbg(options.debug, 'argv[x] =', path) # Only auto-prefix the path if the ELF is absolute. # If it's a relative path, the user most likely wants # the local path. if options.auto_root and path.startswith('/'): path = options.root + path.lstrip('/') dbg(options.debug, ' +auto-root =', path) matched = False for p in glob.iglob(path): # Once we've processed the globs, resolve the symlink. This way you can # operate on a path that is an absolute symlink itself. e.g.: # $ ln -sf /bin/bash $PWD/root/bin/sh # $ lddtree --root $PWD/root /bin/sh # First we'd turn /bin/sh into $PWD/root/bin/sh, then we want to resolve # the symlink to $PWD/root/bin/bash rather than a plain /bin/bash. dbg(options.debug, ' globbed =', p) if not path.startswith('/'): realpath = os.path.realpath(path) elif options.auto_root: realpath = readlink(p, options.root, prefixed=True) else: realpath = path if path != realpath: dbg(options.debug, ' resolved =', realpath) matched = True try: elf = ParseELF(realpath, options.root, options.prefix, ldpaths, display=p, debug=options.debug) except exceptions.ELFError as e: if options.skip_non_elfs: continue # XXX: Ugly. Should unify with _Action* somehow. if options.dest is not None and options.copy_non_elfs: if os.path.exists(p): elf = { 'interp': None, 'libs': [], 'runpath': [], 'rpath': [], 'path': p, 'realpath': realpath, } _ActionCopy(options, elf) continue ret = 1 warn('%s: %s' % (p, e)) continue except IOError as e: ret = 1 warn('%s: %s' % (p, e)) continue if options.dest is None: _ActionShow(options, elf) else: _ActionCopy(options, elf) if not matched: ret = 1 warn('%s: did not match any paths' % (path,)) return ret if __name__ == '__main__': sys.exit(main(sys.argv[1:])) pax-utils-1.2.5/lddtree.sh000077500000000000000000000145351362221774600154510ustar00rootroot00000000000000#!/bin/bash # Copyright 2007-2013 Gentoo Foundation # Copyright 2007-2013 Mike Frysinger # Distributed under the terms of the GNU General Public License v2 argv0=${0##*/} : ${ROOT:=/} [[ ${ROOT} != */ ]] && ROOT="${ROOT}/" [[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}" usage() { cat <<-EOF Display ELF dependencies as a tree Usage: ${argv0} [options] Options: -a Show all duplicated dependencies -x Run with debugging -R Use this ROOT filesystem tree --no-auto-root Do not automatically prefix input ELFs with ROOT -l Display output in a flat format -h Show this help output -V Show version information EOF exit ${1:-0} } version() { exec echo "lddtree by Mike Frysinger " } error() { echo "${argv0}: $*" 1>&2 ret=1 return 1 } elf_specs() { # With glibc, the NONE, SYSV, GNU, and LINUX OSABI's are compatible. # LINUX and GNU are the same thing, as are NONE and SYSV, so normalize # GNU & LINUX to NONE. #442024 #464380 scanelf -BF '#F%a %M %D %I' "$1" | \ sed -E 's: (LINUX|GNU)$: NONE:' } lib_paths_fallback="${ROOT}lib* ${ROOT}usr/lib* ${ROOT}usr/local/lib*" c_ldso_paths_loaded='false' find_elf() { _find_elf='' local elf=$1 needed_by=$2 if [[ ${elf} == */* ]] && [[ -e ${elf} ]] ; then _find_elf=${elf} return 0 else check_paths() { local elf=$1 ; shift local path pe for path ; do pe="${path%/}/${elf#/}" if [[ -e ${pe} ]] ; then if [[ $(elf_specs "${pe}") == "${elf_specs}" ]] ; then _find_elf=${pe} return 0 fi fi done return 1 } if [[ ${c_last_needed_by} != ${needed_by} ]] ; then c_last_needed_by=${needed_by} c_last_needed_by_rpaths=$(scanelf -qF '#F%r' "${needed_by}" | \ sed -e 's|:| |g' -e "s:[$]ORIGIN:${needed_by%/*}:") fi check_paths "${elf}" ${c_last_needed_by_rpaths} && return 0 if [[ -n ${LD_LIBRARY_PATH} ]] ; then # Need to handle empty paths as $PWD, # and handle spaces in between the colons local p path=${LD_LIBRARY_PATH} while : ; do p=${path%%:*} check_paths "${elf}" "${p:-${PWD}}" && return 0 [[ ${path} == *:* ]] || break path=${path#*:} done fi if ! ${c_ldso_paths_loaded} ; then c_ldso_paths_loaded='true' c_ldso_paths=() if [[ -r ${ROOT}etc/ld.so.conf ]] ; then read_ldso_conf() { local line p for p ; do # if the glob didnt match anything #360041, # or the files arent readable, skip it [[ -r ${p} ]] || continue while read line ; do case ${line} in "#"*) ;; "include "*) read_ldso_conf ${line#* } ;; *) c_ldso_paths+=( "${ROOT}${line#/}" ) ;; esac done <"${p}" done } # the 'include' command is relative pushd "${ROOT}"etc >/dev/null read_ldso_conf "${ROOT}"etc/ld.so.conf popd >/dev/null fi fi if [[ ${#c_ldso_paths[@]} -gt 0 ]] ; then check_paths "${elf}" "${c_ldso_paths[@]}" && return 0 fi check_paths "${elf}" ${lib_paths_ldso:-${lib_paths_fallback}} && return 0 fi return 1 } show_elf() { local elf=$1 indent=$2 parent_elfs=$3 local rlib lib libs local resolved find_elf "${elf}" resolved=${_find_elf} elf=${elf##*/} ${LIST} || printf "%${indent}s%s => " "" "${elf}" if [[ ,${parent_elfs}, == *,${elf},* ]] ; then ${LIST} || printf "!!! circular loop !!!\n" "" return fi parent_elfs="${parent_elfs},${elf}" if ${LIST} ; then echo "${resolved:-$1}" else printf "${resolved:-not found}" fi if [[ ${indent} -eq 0 ]] ; then local elf_specs interp full_interp elf_specs=$(elf_specs "${resolved}") interp=$(scanelf -qF '#F%i' "${resolved}") [[ -n ${interp} ]] && interp="${ROOT}${interp#/}" if ${LIST} ; then [[ -n ${interp} ]] && echo "${interp}" else printf " (interpreter => ${interp:-none})" fi if [[ -r ${interp} ]] ; then # Extract the default lib paths out of the ldso. lib_paths_ldso=$( strings "${interp}" | \ sed -nr -e "/^\/.*lib/{s|^/?|${ROOT}|;s|/$||;s|/?:/?|\n${ROOT}|g;p}" ) fi full_interp=${interp} interp=${interp##*/} # If we are in non-list mode, then we want to show the "duplicate" interp # lines -- first the header (interp=>xxx), and then the DT_NEEDED line to # show that the ELF is directly linked against the interp. # If we're in list mode though, we only want to show the interp once. ${LIST} && allhits+=",${interp}" fi ${LIST} || printf "\n" [[ -z ${resolved} ]] && return libs=$(scanelf -qF '#F%n' "${resolved}") local my_allhits if ! ${SHOW_ALL} ; then my_allhits="${allhits}" allhits+=",${libs}" fi for lib in ${libs//,/ } ; do lib=${lib##*/} # No need for leading comma w/my_allhits as we guarantee it always # starts with one due to the way we append the value above. [[ ${my_allhits}, == *,${lib},* ]] && continue # If the interp is being linked against directly, re-use the existing # full path rather than perform a search for it. When systems symlink # the interp to a diff location, we might locate a different path, and # displaying both doesn't make sense as it doesn't match the runtime -- # the ldso won't load another copy of ldso into memory from the search # path, it'll re-use the existing copy that was loaded from the full # hardcoded path. if [[ ${lib} == "${interp}" ]] ; then rlib=${full_interp} else find_elf "${lib}" "${resolved}" rlib=${_find_elf} fi show_elf "${rlib:-${lib}}" $((indent + 4)) "${parent_elfs}" done } # XXX: internal hack if [[ $1 != "/../..source.lddtree" ]] ; then SHOW_ALL=false SET_X=false LIST=false AUTO_ROOT=true while getopts haxVR:l-: OPT ; do case ${OPT} in a) SHOW_ALL=true;; x) SET_X=true;; h) usage;; V) version;; R) ROOT="${OPTARG%/}/";; l) LIST=true;; -) # Long opts ftw. case ${OPTARG} in no-auto-root) AUTO_ROOT=false;; *) usage 1;; esac ;; ?) usage 1;; esac done shift $((OPTIND - 1)) [[ -z $1 ]] && usage 1 ${SET_X} && set -x ret=0 for elf ; do unset lib_paths_ldso unset c_last_needed_by if ${AUTO_ROOT} && [[ ${elf} == /* ]] ; then elf="${ROOT}${elf#/}" fi if [[ ! -e ${elf} ]] ; then error "${elf}: file does not exist" elif [[ ! -r ${elf} ]] ; then error "${elf}: file is not readable" elif [[ -d ${elf} ]] ; then error "${elf}: is a directory" else allhits="" [[ ${elf} != */* ]] && elf="./${elf}" show_elf "${elf}" 0 "" fi done exit ${ret} fi pax-utils-1.2.5/macho.h000066400000000000000000000241031362221774600147170ustar00rootroot00000000000000/* * Copyright 2008-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 */ #ifndef _MACHO_H #define _MACHO_H 1 #include /* * http://developer.apple.com/documentation/DeveloperTools/Conceptual/MachORuntime/Reference/reference.html */ #define CPU_ARCH_ABI64 0x01000000 /* 64 bit */ typedef int cpu_type_t; typedef int cpu_subtype_t; struct mach_header { uint32_t magic; cpu_type_t cputype; cpu_subtype_t cpusubtype; uint32_t filetype; uint32_t ncmds; uint32_t sizeofcmds; uint32_t flags; }; /* magic */ #define MH_MAGIC 0xfeedface /* same endianness */ #define MH_CIGAM 0xcefaedfe /* the other endianness */ /* cputype */ #define CPU_TYPE_POWERPC ((cpu_type_t)18) #define CPU_TYPE_I386 ((cpu_type_t)7) #define CPU_TYPE_ARM ((cpu_type_t)12) /* cpusubtype */ #define CPU_SUBTYPE_POWERPC_ALL ((cpu_subtype_t)0) #define CPU_SUBTYPE_POWERPC_601 ((cpu_subtype_t)1) #define CPU_SUBTYPE_POWERPC_602 ((cpu_subtype_t)2) #define CPU_SUBTYPE_POWERPC_603 ((cpu_subtype_t)3) #define CPU_SUBTYPE_POWERPC_603e ((cpu_subtype_t)4) #define CPU_SUBTYPE_POWERPC_603ev ((cpu_subtype_t)5) #define CPU_SUBTYPE_POWERPC_604 ((cpu_subtype_t)6) #define CPU_SUBTYPE_POWERPC_604e ((cpu_subtype_t)7) #define CPU_SUBTYPE_POWERPC_620 ((cpu_subtype_t)8) #define CPU_SUBTYPE_POWERPC_750 ((cpu_subtype_t)9) #define CPU_SUBTYPE_POWERPC_7400 ((cpu_subtype_t)10) #define CPU_SUBTYPE_POWERPC_7450 ((cpu_subtype_t)11) #define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t)100) #define CPU_SUBTYPE_I386_ALL ((cpu_subtype_t)3) #define CPU_SUBTYPE_486 ((cpu_subtype_t)4) #define CPU_SUBTYPE_586 ((cpu_subtype_t)5) #define CPU_SUBTYPE_PENTIUM_3 ((cpu_subtype_t)8) #define CPU_SUBTYPE_PENTIUM_M ((cpu_subtype_t)9) #define CPU_SUBTYPE_PENTIUM_4 ((cpu_subtype_t)10) #define CPU_SUBTYPE_ITANIUM ((cpu_subtype_t)11) #define CPU_SUBTYPE_XEON ((cpu_subtype_t)12) /* filetype */ #define MH_OBJECT 0x1 /* intermediate object file (.o) */ #define MH_EXECUTE 0x2 /* standard executable program */ #define MH_BUNDLE 0x8 /* dlopen plugin (.bundle) */ #define MH_DYLIB 0x6 /* dynamic shared library (.dylib) */ #define MH_PRELOAD 0x5 /* executable not loaded by Mac OS X kernel (ROM) */ #define MH_CORE 0x4 /* program crash core file */ #define MH_DYLINKER 0x7 /* dynamic linker shared library (dyld) */ #define MH_DYLIB_STUB 0x9 /* shared library stub for static only, no section*/ #define MH_DSYM 0xa /* debug symbols file (in .dSYM dir) */ /* flags */ #define MH_NOUNDEFS 0x1 /* there are no undefined references */ #define MH_INCRLINK 0x2 /* the object file is the output of an incremental link against a base file and cannot be link edited again */ #define MH_DYLDLINK 0x4 /* the object file is input for the dynamic linker and cannot be staticly link edited again */ #define MH_TWOLEVEL 0x80 /* the image is using two-level namespace bindings */ #define MH_BINDATLOAD 0x8 /* the dynamic linker should bind the undefined references when the file is loaded */ #define MH_PREBOUND 0x10 /* the file’s undefined references are prebound */ #define MH_PREBINDABLE 0x800/* the file is not prebound but can have its prebinding redone, used only when MH_PREBOUND is not set */ #define MH_NOFIXPREBINDING 0x400 /* the dynamic linker doesn’t notify the prebinding agent about this executable */ #define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to all two-level namespace modules of its dependent libraries, used only when MH_PREBINDABLE and MH_TWOLEVEL are set */ #define MH_CANONICAL 0x4000 /* the file has been canonicalized by unprebinding, clearing prebinding information from the file */ #define MH_SPLIT_SEGS 0x20 /* the file has its read-only and read-write segments split */ #define MH_FORCE_FLAT 0x100 /* the executable is forcing all images to use flat namespace bindings */ #define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* the sections of the object file can be divided into individual blocks, these blocks are dead-stripped if they are not used by other code */ #define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees there are no multiple defintions of symbols in its subimages, as a result the two-level namespace hints can always be used */ struct mach_header_64 { uint32_t magic; cpu_type_t cputype; cpu_subtype_t cpusubtype; uint32_t filetype; uint32_t ncmds; uint32_t sizeofcmds; uint32_t flags; uint32_t reserved; }; /* magic */ #define MH_MAGIC_64 0xfeedfacf /* same endianness 64-bits */ #define MH_CIGAM_64 0xcffaedfe /* the other endianness 64-bits */ /* cputype */ #define CPU_TYPE_POWERPC64 (CPU_TYPE_POWERPC | CPU_ARCH_ABI64) #define CPU_TYPE_X86_64 (CPU_TYPE_I386 | CPU_ARCH_ABI64) struct load_command { uint32_t cmd; uint32_t cmdsize; }; /* features that are required to be supported are flagged, this is to * make the constants below a bit more readable (although we only use it * once for now) */ #define LC_REQ_DYLD 0x80000000 /* cmd */ #define LC_UUID 0x1b /* Specifies the 128-bit UUID for an image or its corresponding dSYM file. */ #define LC_RPATH (0x1c | LC_REQ_DYLD) /* Defines a runpath addition, used in @rpath directives in LC_LOAD_DYLIB. */ #define LC_SEGMENT 0x1 /* Defines a segment of this file to be mapped into the address space of the process that loads this file. It also includes all the sections contained by the segment. */ #define LC_SEGMENT_64 0x19 /* Defines a 64-bit segment of this file to be mapped into the address space of the process that loads this file. It also includes all the sections contained by the segment. */ #define LC_SYMTAB 0x2 /* Specifies the symbol table for this file. This information is used by both static and dynamic linkers when linking the file, and also by debuggers to map symbols to the original source code files from which the symbols were generated. */ #define LC_DYSYMTAB 0xb /* Specifies additional symbol table information used by the dynamic linker. */ #define LC_THREAD 0x4 #define LC_UNIXTHREAD 0x5 /* For an executable file, the LC_UNIXTHREAD command defines the initial thread state of the main thread of the process. LC_THREAD is similar to LC_UNIXTHREAD but does not cause the kernel to allocate a stack. */ #define LC_LOAD_DYLIB 0xc /* Defines the name of a dynamic shared library that this file links against. (needed) */ #define LC_ID_DYLIB 0xd /* Specifies the install name of a dynamic shared library. (soname) */ #define LC_PREBOUND_DYLIB 0x10 /* For a shared library that this executable is linked prebound against, specifies the modules in the shared library that are used. */ #define LC_LOAD_DYLINKER 0xe/* Specifies the dynamic linker that the kernel executes to load this file. (.interp) */ #define LC_ID_DYLINKER 0xf /* Identifies this file as a dynamic linker. */ #define LC_ROUTINES 0x11 /* Contains the address of the shared library initialization routine (specified by the linker’s -init option). */ #define LC_ROUTINES_64 0x1a /* Contains the address of the shared library 64-bit initialization routine (specified by the linker’s -init option). */ #define LC_TWOLEVEL_HINTS 0x16 /* Contains the two-level namespace lookup hint table. */ #define LC_SUB_FRAMEWORK 0x12/* Identifies this file as the implementation of a subframework of an umbrella framework. The name of the umbrella framework is stored in the string parameter. */ #define LC_SUB_UMBRELLA 0x13/* Specifies a file that is a subumbrella of this umbrella framework. */ #define LC_SUB_LIBRARY 0x15/* Identifies this file as the implementation of a sublibrary of an umbrella framework. The name of the umbrella framework is stored in the string parameter. Note that Apple has not defined a supported location for sublibraries. */ #define LC_SUB_CLIENT 0x14/* A subframework can explicitly allow another framework or bundle to link against it by including an LC_SUB_CLIENT load command containing the name of the framework or a client name for a bundle. */ union lc_str { uint32_t offset; /* The ptr field is not used in Mach-O files. char *ptr; */ }; /* offset: A byte offset from the start of the load command that * contains this string to the start of the string data. */ /* Defines the data used by the dynamic linker to match a shared library against the files that have linked to it. */ struct dylib { union lc_str name; uint32_t timestamp; uint32_t current_version; uint32_t compatibility_version; }; /* Defines the attributes of the LC_LOAD_DYLIB and LC_ID_DYLIB load commands. */ struct dylib_command { uint32_t cmd; uint32_t cmdsize; struct dylib dylib; }; /* cmd: set to either LC_LOAD_DYLIB, LC_LOAD_WEAK_DYLIB, or LC_ID_DYLIB. */ /* cmdsize: set to sizeof(dylib_command) plus the size of the data * pointed to by the name field of the dylib field. */ struct dylinker_command { uint32_t cmd; uint32_t cmdsize; union lc_str name; }; struct rpath_command { uint32_t cmd; uint32_t cmdsize; union lc_str path; }; struct fat_header { uint32_t magic; uint32_t nfat_arch; }; /* magic */ #define FAT_MAGIC 0xcafebabe /* big endian, how it is stored */ #define FAT_CIGAM 0xbebafeca /* for intel dudes */ /* nfat_arch: the number of far_arch structures following */ struct fat_arch { cpu_type_t cputype; cpu_subtype_t cpusubtype; uint32_t offset; uint32_t size; uint32_t align; }; #endif pax-utils-1.2.5/make-tarball.sh000077500000000000000000000027541362221774600163620ustar00rootroot00000000000000#!/bin/bash set -e if ! . /etc/init.d/functions.sh 2>/dev/null ; then einfo() { printf ' * %b\n' "$*"; } eerror() { einfo "$@" 1>&2; } fi die() { eerror "$@"; exit 1; } v() { printf '\t%s\n' "$*"; "$@"; } : ${MAKE:=make} CHECK=false if [[ $1 == "--check" ]] ; then CHECK=true shift fi if [[ $# -ne 1 ]] ; then die "Usage: $0 " fi case $1 in snap) ver=$(date -u +%Y%m%d) ;; git) ver="HEAD" ;; *) ver="v${1#v}" if ! git describe --tags "${ver}" >&/dev/null ; then die "Please create the tag first: git tag ${ver}" fi ;; esac p="pax-utils-${ver#v}" rm -rf "${p}" mkdir "${p}" einfo "Checking out clean git sources ..." git archive "${ver}" | tar xf - -C "${p}" pushd "${p}" >/dev/null einfo "Building docs ..." echo "${ver#v}" > man/fragment/version make -C man einfo "Building autotools ..." sed -i "/^AC_INIT/s:git:${ver}:" configure.ac sed -i "1iPV := ${ver}" Makefile SKIP_AUTOTOOLS_UPDATE=true LC_ALL=C ${MAKE} -s autotools >/dev/null rm -rf autom4te.cache popd >/dev/null einfo "Generating tarball ..." tar cf - "${p}" | xz > "${p}".tar.xz rm -r "${p}" if ${CHECK} ; then einfo "Checking tarball (simple) ..." tar xf "${p}".tar.* pushd "${p}" >/dev/null v ${MAKE} -s v ${MAKE} -s check popd >/dev/null rm -rf "${p}" einfo "Checking tarball (autotools) ..." tar xf "${p}".tar.* pushd "${p}" >/dev/null v ./configure -q v ${MAKE} -s v ${MAKE} -s check popd >/dev/null rm -rf "${p}" fi echo einfo "All ready for distribution!" du -b "${p}".tar.* exit 0 pax-utils-1.2.5/man/000077500000000000000000000000001362221774600142325ustar00rootroot00000000000000pax-utils-1.2.5/man/Makefile000066400000000000000000000007401362221774600156730ustar00rootroot00000000000000all: man XMLTO_FLAGS_man = -x custom.xsl --skip-validation man pdf txt xhtml xhtml-nochunks: @xmlto $@ $(XMLTO_FLAGS_$@) pax-utils.docbook || echo "If this failed, you probably need to emerge ~app-text/docbook-xml-dtd-4.4 app-text/xmlto dev-tex/xmltex" @# scanelf.1 has funky indented lists ... hack it back @sed -i.tmp 's:^[.]TP 4:.TP 2:' scanelf.1 @rm scanelf.1.tmp clean distclean: rm -f *.1 *.html .PHONY: all clean distclean \ man pdf txt xhtml xhtml-nochunks pax-utils-1.2.5/man/custom.xsl000066400000000000000000000012201362221774600162670ustar00rootroot00000000000000 .sp -1 .TP pax-utils-1.2.5/man/dumpelf.docbook000066400000000000000000000025431362221774600172340ustar00rootroot00000000000000 dumpelf 1 &project; dumpelf dump internal ELF structure dumpelf options ELFs DESCRIPTION dumpelf is a user-space utility to dump all of the internal ELF structures into the equivalent C structures for fun debugging and/or reference purposes. OPTIONS , Show condensed usage and exit , Print version and exit , Be verbose (can be used more than once) &reftail; pax-utils-1.2.5/man/fragment/000077500000000000000000000000001362221774600160355ustar00rootroot00000000000000pax-utils-1.2.5/man/fragment/date000066400000000000000000000000001362221774600166630ustar00rootroot00000000000000pax-utils-1.2.5/man/fragment/reftail000066400000000000000000000023431362221774600174100ustar00rootroot00000000000000 HOMEPAGE http://hardened.gentoo.org/pax-utils.xml REPORTING BUGS Please include as much information as possible (using any available debugging options) and send bug reports to the maintainers (see the AUTHORS section). Please use the Gentoo bugzilla at http://bugs.gentoo.org/ if possible. SEE ALSO chpax1, dumpelf1, paxctl1, pspax1, readelf1, scanelf1, elf5 pax-utils-1.2.5/man/fragment/version000066400000000000000000000000371362221774600174450ustar00rootroot00000000000000git pax-utils-1.2.5/man/pax-utils.docbook000066400000000000000000000023341362221774600175240ustar00rootroot00000000000000 ]> Documentation for pax-utils Ned Ludd Maintainer solar@gentoo.org Mike Frysinger Maintainer vapier@gentoo.org Fabian Groffen Mach-O Maintainer grobian@gentoo.org &version; &date; &dumpelf; &pspax; &scanelf; &scanmacho; pax-utils-1.2.5/man/pspax.docbook000066400000000000000000000057071362221774600167400ustar00rootroot00000000000000 pspax 1 &project; pspax list ELF/PaX information about running processes pspax options ELFs DESCRIPTION pspax is a user-space utility that scans the proc directory and list ELF types, as well as their respective PaX flags and filenames and attributes. Depending on build options, it may additionally display the process running set of capabilities. OPTIONS , Show all processes , Print GNU_STACK/PT_LOAD markings , Print ipaddr info if supported , PID Only process specified process id , UID Process user/uid # , GID Process group/gid # , Only display w^x processes , Only display w|x processes , Be verbose (can be used more than once) , Don't display the header , Show condensed usage and exit , Print version and exit &reftail; pax-utils-1.2.5/man/scanelf.docbook000066400000000000000000000421641362221774600172160ustar00rootroot00000000000000 scanelf 1 &project; scanelf user-space utility to scan ELF files scanelf options ELFs or directories DESCRIPTION scanelf is a user-space utility to quickly scan given ELFs, directories, or common system paths for different information. This may include ELF types, their PaX markings, TEXTRELs, etc... OPTIONS , Scan archives (.a files) , Print all useful/simple info , Don't display the header , Print symbol binding information (lazy or now) , Print ELF endianness (big/little/...) , ETYPE Print only ELF files matching specified etype (like ET_DYN, ET_EXEC, etc...) , Print GNU_STACK markings , FORMAT Use specified format for output; see the FORMAT section for more information , FILE Read input stream from specified filename , Use strncmp to match libraries (use with ). Or regexp with symbol matching , Show condensed usage and exit , Print OSABI , Print the interpreter information (.interp/PT_INTERP) , SECTION Find ELFs with the specified section. May be specified multiple times to match multiple sections simultaneously. See SECTION MATCHING for more info. , Utilize ld.so.cache information (use with /) , Scan all directories in /etc/ld.so.conf , BITS Print only ELF files matching specified numeric bits (like 32/64) , Don't recursively cross mount points , SONAME Find ELFs that need the specified SONAME. May be specified multiple times to match multiple SONAMEs simultaneously. See SONAME MATCHING for more info. , Print libraries the ELF is linked against (DT_NEEDED) , PERMS Print only ELF files with matching specified octal bits (like 755) , FILE Write output stream to specified filename , Scan all directories in PATH environment , Only output 'bad' things , Scan directories recursively , Print runpaths encoded in the ELF (DT_RPATH/DT_RUNPATH) , Print the ELF's shared library name (DT_SONAME) , SYMBOL Find the specified symbol; see SYMBOL MATCHING for more info , Locate cause of TEXTRELs via objdump , Print TEXTREL information , Print version and exit , Be verbose (can be used more than once) , Try and 'fix' bad things (use with /) , Print PaX markings , Print EABI (only matters for a few architectures) , Don't scan symlinks , SIZE Print ELF file size , FLAGS Sets EI_PAX/PT_PAX_FLAGS to specified flags (use with ) Use the ld.so.conf paths to find the full path to libraries (use in conjunction with --needed). PATH Search the specified root tree instead of /. Generally paired with options like -l or -p. This implicitly treats all paths specified on the command line as relative to the root, so be sure to omit it if you are explicitly listing ELFs. FORMAT The format string is much like a printf string in that it is a literal string with flags requesting different information. For example, you could use a format string and expect the following results. # scanelf "file %f needs %n; funky time" /bin/bash file bash needs libncurses.so.5,libdl.so.2,libc.so.6; funky time Note that when you use a format string, generally information related flags should be omitted. In other words, you do not want to try and request NEEDED output () and try to specify a format output at the same time as these operations are mutually exclusive. Each information related flag has an equivalent conversion specifier, so use those instead. You can of course continue to use non-information related flags (such as ). There are three characters that introduce conversion specifiers. % - replace with info # - silent boolean match + - verbose match And there are a number of conversion specifiers. We try to match up the specifier with corresponding option. a - machine (EM) type b - bind flags e - program headers D - endian I - osabi Y - eabi F - long filename f - short filename i - interp k - section M - EI class N - specified needed n - needed libraries p - filename (minus search) o - etype O - perms r - runpaths S - SONAME s - symbol T - all textrels t - textrel status x - pax flags Symbol Matching The string specified takes the form [%[modifiers]%][[+-]<symbol name>][,[.....]]. If the is empty, then all symbols are matched. If the is a glob ("*"), then all symbols are dumped in a debug format. Do not rely on the structure of this output as it changes whenever we feel like it. If the first char of the symbol name is a plus ("+"), then only match defined symbols. If it's a minus ("-"), only match undefined symbols. When we say "defined", we mean the symbol is defined in the ELF vs having an external reference. Putting modifiers in between the percent signs ("%") allows for more in depth filters. There are groups of modifiers. If you don't specify a member of a group, then all types in that group are matched. STT group (symbol type) n - STT_NOTYPE o - STT_OBJECT f - STT_FUNC F - STT_FILE STB group (symbol binding) l - STB_LOCAL g - STB_GLOBAL w - STB_WEAK STV group (symbol visibility) p - STV_DEFAULT i - STV_INTERNAL h - STV_HIDDEN P - STV_PROTECTED SHN group (section header) d - defined u - SHN_UNDEF a - SHN_ABS c - SHN_COMMON You can search for multiple symbols simultaneously by using a comma (",") to separate different searches. Every symbol that matches will be displayed while unmatched symbols will not. ELF ETYPES You can narrow your search by specifying the ELF object file type (ETYPE). The commandline option takes the numeric value and or symbolic type. Multiple values can be passed comma separated. Example -E ET_EXEC,ET_DYN,1 Here is the normal list available for your pleasure. You of course are free to specify any numeric value you want. 0 - ET_NONE - unknown type 1 - ET_REL - relocatable file 2 - ET_EXEC - executable file 3 - ET_DYN - shared object 4 - ET_CORE - core file ELF BITS You can also narrow your search by specifying the ELF bitsize. Again, specify the numeric value or the symbolic define. 32 - ELFCLASS32 - 32bit ELFs 64 - ELFCLASS64 - 64bit ELFs Section Matching A ! prefix will only show ELF's that do not have the specified section. Needed SONAME Matching A ! prefix will only show ELF's that do not depend on the specified library. &reftail; pax-utils-1.2.5/man/scanmacho.docbook000066400000000000000000000252721362221774600175400ustar00rootroot00000000000000 scanmacho 1 &project; scanmacho user-space utility to scan Mach-O files scanmacho options Mach-Os or directories DESCRIPTION scanmacho is a user-space utility to quickly scan given Mach-Os, directories, or common system paths for different information. This may include Mach-O types, their install_names, etc... Because Mach-O files can be "fat", it is possible for a single file to return multiple lines. Each line represents a single architecture, contained in the fat (universal) file. While there are no real restrictions, in practice, the entries can be distinguished by their arch type, e.g. ppc, ppc64, i386, x86_64, arm, ... OPTIONS , Scan archives (.a files) , Print all useful/simple info , Don't display the header , Print flags from mach_header , Print Mach-O endianness , filetype Print only Mach-O files matching specified etype (like MH_EXECUTABLE, MH_DYLIB, etc...) , FORMAT Use specified format for output; see the FORMAT section for more information. , FILE Read input stream from specified filename , Use strncmp to match libraries (use with ). Or regexp with symbol matching , Show condensed usage and exit , Print the interpreter information (LC_LOAD_DYLINKER) , BITS Print only Mach-O files matching specified numeric bits (like 32/64) , Don't recursively cross mount points , INSTALLNAME Find Mach-Os that need the specified INSTALL_NAME , Print libraries the Mach-O is linked against (LC_LOAD_DYLIB). , PERMS Print only Mach-O files with matching specified octal bits (like 755). , FILE Write output stream to specified filename. , Scan all directories in PATH environment. , Only output 'bad' things. , Scan directories recursively , Print RPATH encoded in the Mach-O (LC_RPATH) , Print the Mach-O's shared library name (install_name). , Print version and exit , Be verbose (can be used more than once) , Don't scan symlinks , SIZE Print Mach-O file size FORMAT The format string is much like a printf string in that it is a literal string with flags requesting different information. For example, you could use a format string and expect the following results. # scanmacho "file %f needs %n; funky time" /bin/bash file bash needs /usr/lib/libncurses.5.4.dylib,/usr/lib/libSystem.B.dylib; funky time Note that when you use a format string, generally information related flags should be omitted. In other words, you do not want to try and request NEEDED output () and try to specify a format output at the same time as these operations are mutually exclusive. Each information related flag has an equivalent conversion specifier, so use those instead. You can of course continue to use non-information related flags (such as ). There are three characters that introduce conversion specifiers. % - replace with info # - silent boolean match + - verbose match And there are a number of conversion specifiers. We try to match up the specifier with corresponding option. a - arch type b - mach_header flags D - endian F - long filename f - short filename i - dyld M - CPU_TYPE class N - specified needed n - needed libraries p - filename (minus search) o - mh_type O - perms r - rpaths S - install_name MACH-O FILETYPES You can narrow your search by specifying the Mach-O object file type. The commandline option takes the symbolic type name. Multiple values can be passed comma separated. Example -E MH_EXECUTE,MH_DYLIB Here is the normal list available for your pleasure. MH_OBJECT - intermediate object file (.o) MH_EXECUTE - standard executable program MH_BUNDLE - dlopen plugin (.bundle) MH_DYLIB - dynamic shared library (.dylib) MH_PRELOAD - executable not loaded by Mac OS X kernel (ROM) MH_CORE - program crash core file MH_DYLINKER - dynamic linker shared library (dyld) MH_DYLIB_STUB - shared library stub for static only, no sections MH_DSYM - debug symbols file (in .dSYM dir) MACH-O BITS You can also narrow your search by specifying the Mach-O bitsize. Specify the numeric value. 32 - 32bit mach_header 64 - 64bit mach_header_64 &reftail; pax-utils-1.2.5/paxelf.c000066400000000000000000000453641362221774600151160ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - */ #include "paxinc.h" /* * Setup a bunch of helper functions to translate * binary defines into readable strings. */ #define QUERY(n) { #n, n } typedef const struct { const char *str; /* We use unsigned int as we assume it's at least 32 bits. This covers all our uses so far as they have been limited to that size. */ unsigned int value; } pairtype; static inline const char *find_pairtype(pairtype *pt, unsigned int type) { size_t i; for (i = 0; pt[i].str; ++i) if (type == pt[i].value) return pt[i].str; return "UNKNOWN_TYPE"; } /* translate misc elf EI_ defines */ static pairtype elf_ei_class[] = { QUERY(ELFCLASSNONE), QUERY(ELFCLASS32), QUERY(ELFCLASS64), { 0, 0 } }; static pairtype elf_ei_data[] = { QUERY(ELFDATANONE), QUERY(ELFDATA2LSB), QUERY(ELFDATA2MSB), { 0, 0 } }; static pairtype elf_ei_version[] = { QUERY(EV_NONE), QUERY(EV_CURRENT), { 0, 0 } }; static pairtype elf_ei_osabi[] = { QUERY(ELFOSABI_NONE), QUERY(ELFOSABI_SYSV), QUERY(ELFOSABI_HPUX), QUERY(ELFOSABI_NETBSD), QUERY(ELFOSABI_GNU), QUERY(ELFOSABI_LINUX), QUERY(ELFOSABI_SOLARIS), QUERY(ELFOSABI_AIX), QUERY(ELFOSABI_IRIX), QUERY(ELFOSABI_FREEBSD), QUERY(ELFOSABI_TRU64), QUERY(ELFOSABI_MODESTO), QUERY(ELFOSABI_OPENBSD), QUERY(ELFOSABI_ARM_AEABI), QUERY(ELFOSABI_ARM), QUERY(ELFOSABI_STANDALONE), { 0, 0 } }; const char *get_elfeitype(int ei_type, int type) { switch (ei_type) { case EI_CLASS: return find_pairtype(elf_ei_class, type); case EI_DATA: return find_pairtype(elf_ei_data, type); case EI_VERSION: return find_pairtype(elf_ei_version, type); case EI_OSABI: return find_pairtype(elf_ei_osabi, type); } return "UNKNOWN_EI_TYPE"; } /* translate elf ET_ defines */ static pairtype elf_etypes[] = { QUERY(ET_NONE), QUERY(ET_REL), QUERY(ET_EXEC), QUERY(ET_DYN), QUERY(ET_CORE), { 0, 0 } }; unsigned int get_etype(const elfobj *elf) { if (elf->elf_class == ELFCLASS32) return EGET(EHDR32(elf->ehdr)->e_type); else return EGET(EHDR64(elf->ehdr)->e_type); } const char *get_elfetype(const elfobj *elf) { return find_pairtype(elf_etypes, get_etype(elf)); } const char *get_endian(const elfobj *elf) { switch (elf->data[EI_DATA]) { case ELFDATA2LSB: return "LE"; case ELFDATA2MSB: return "BE"; default: return "??"; } } /* translate elf EF_ defines -- tricky as it's based on EM_ */ static unsigned int get_eflags(const elfobj *elf) { if (elf->elf_class == ELFCLASS32) return EGET(EHDR32(elf->ehdr)->e_flags); else return EGET(EHDR64(elf->ehdr)->e_flags); } static int arm_eabi_poker(const elfobj *elf) { unsigned int emachine, eflags; if (ELFOSABI_NONE != elf->data[EI_OSABI]) return -1; emachine = get_emtype(elf); eflags = get_eflags(elf); if (emachine == EM_ARM) return EF_ARM_EABI_VERSION(eflags) >> 24; else return -1; } const char *get_elf_eabi(const elfobj *elf) { static char buf[26]; int eabi = arm_eabi_poker(elf); if (eabi >= 0) snprintf(buf, sizeof(buf), "%i", eabi); else strcpy(buf, "?"); return buf; } const char *get_elfosabi(const elfobj *elf) { const char *str = get_elfeitype(EI_OSABI, elf->data[EI_OSABI]); if (strncmp(str, "ELFOSABI_", 9) == 0) str += 9; return str; } void print_etypes(FILE *stream) { int i, wrap = 0; for (i = 0; elf_etypes[i].str; ++i) { fprintf(stream, " (%4x) = %-10s", elf_etypes[i].value, elf_etypes[i].str); if (++wrap >= 4) { fprintf(stream, "\n"); wrap = 0; } } if (wrap) fprintf(stream, "\n"); } unsigned int etype_lookup(const char *str) { if (*str == 'E') { size_t i; for (i = 0; elf_etypes[i].str; ++i) { if (strcmp(str, elf_etypes[i].str) == 0) return elf_etypes[i].value; } } return atoi(str); } /* translate elf EM_ defines */ static pairtype elf_emtypes[] = { QUERY(EM_NONE), QUERY(EM_M32), QUERY(EM_SPARC), QUERY(EM_386), QUERY(EM_68K), QUERY(EM_88K), QUERY(EM_860), QUERY(EM_MIPS), QUERY(EM_S370), QUERY(EM_MIPS_RS3_LE), QUERY(EM_PARISC), QUERY(EM_VPP500), QUERY(EM_SPARC32PLUS), QUERY(EM_960), QUERY(EM_PPC), QUERY(EM_PPC64), QUERY(EM_S390), QUERY(EM_V800), QUERY(EM_FR20), QUERY(EM_RH32), QUERY(EM_RCE), QUERY(EM_ARM), QUERY(EM_FAKE_ALPHA), QUERY(EM_SH), QUERY(EM_SPARCV9), QUERY(EM_TRICORE), QUERY(EM_ARC), QUERY(EM_H8_300), QUERY(EM_H8_300H), QUERY(EM_H8S), QUERY(EM_H8_500), QUERY(EM_IA_64), QUERY(EM_MIPS_X), QUERY(EM_COLDFIRE), QUERY(EM_68HC12), QUERY(EM_MMA), QUERY(EM_PCP), QUERY(EM_NCPU), QUERY(EM_NDR1), QUERY(EM_STARCORE), QUERY(EM_ME16), QUERY(EM_ST100), QUERY(EM_TINYJ), QUERY(EM_X86_64), QUERY(EM_PDSP), QUERY(EM_FX66), QUERY(EM_ST9PLUS), QUERY(EM_ST7), QUERY(EM_68HC16), QUERY(EM_68HC11), QUERY(EM_68HC08), QUERY(EM_68HC05), QUERY(EM_SVX), QUERY(EM_ST19), QUERY(EM_VAX), QUERY(EM_CRIS), QUERY(EM_JAVELIN), QUERY(EM_FIREPATH), QUERY(EM_ZSP), QUERY(EM_MMIX), QUERY(EM_HUANY), QUERY(EM_PRISM), QUERY(EM_AVR), QUERY(EM_FR30), QUERY(EM_D10V), QUERY(EM_D30V), QUERY(EM_V850), QUERY(EM_M32R), QUERY(EM_MN10300), QUERY(EM_MN10200), QUERY(EM_PJ), QUERY(EM_OPENRISC), QUERY(EM_ARC_A5), QUERY(EM_XTENSA), QUERY(EM_VIDEOCORE), QUERY(EM_TMM_GPP), QUERY(EM_NS32K), QUERY(EM_TPC), QUERY(EM_SNP1K), QUERY(EM_ST200), QUERY(EM_IP2K), QUERY(EM_MAX), QUERY(EM_CR), QUERY(EM_F2MC16), QUERY(EM_MSP430), QUERY(EM_BLACKFIN), QUERY(EM_SE_C33), QUERY(EM_SEP), QUERY(EM_ARCA), QUERY(EM_UNICORE), QUERY(EM_ALTERA_NIOS2), QUERY(EM_AARCH64), QUERY(EM_TILEPRO), QUERY(EM_MICROBLAZE), QUERY(EM_TILEGX), QUERY(EM_ALPHA), { 0, 0 } }; unsigned int get_emtype(const elfobj *elf) { if (elf->elf_class == ELFCLASS32) return EGET(EHDR32(elf->ehdr)->e_machine); else return EGET(EHDR64(elf->ehdr)->e_machine); } const char *get_elfemtype(const elfobj *elf) { return find_pairtype(elf_emtypes, get_emtype(elf)); } /* translate elf PT_ defines */ static pairtype elf_ptypes[] = { QUERY(PT_NULL), QUERY(PT_LOAD), QUERY(PT_DYNAMIC), QUERY(PT_INTERP), QUERY(PT_NOTE), QUERY(PT_SHLIB), QUERY(PT_PHDR), QUERY(PT_TLS), QUERY(PT_GNU_EH_FRAME), QUERY(PT_GNU_STACK), QUERY(PT_GNU_RELRO), QUERY(PT_PAX_FLAGS), { 0, 0 } }; const char *get_elfptype(int type) { return find_pairtype(elf_ptypes, type); } /* translate elf PT_ defines */ static pairtype elf_dtypes[] = { QUERY(DT_NULL), QUERY(DT_NEEDED), QUERY(DT_PLTRELSZ), QUERY(DT_PLTGOT), QUERY(DT_HASH), QUERY(DT_STRTAB), QUERY(DT_SYMTAB), QUERY(DT_RELA), QUERY(DT_RELASZ), QUERY(DT_RELAENT), QUERY(DT_STRSZ), QUERY(DT_SYMENT), QUERY(DT_INIT), QUERY(DT_FINI), QUERY(DT_SONAME), QUERY(DT_RPATH), QUERY(DT_SYMBOLIC), QUERY(DT_REL), QUERY(DT_RELSZ), QUERY(DT_RELENT), QUERY(DT_PLTREL), QUERY(DT_DEBUG), QUERY(DT_TEXTREL), QUERY(DT_JMPREL), QUERY(DT_BIND_NOW), QUERY(DT_INIT_ARRAY), QUERY(DT_FINI_ARRAY), QUERY(DT_INIT_ARRAYSZ), QUERY(DT_FINI_ARRAYSZ), QUERY(DT_RUNPATH), QUERY(DT_FLAGS), QUERY(DT_ENCODING), QUERY(DT_PREINIT_ARRAY), QUERY(DT_PREINIT_ARRAYSZ), QUERY(DT_GNU_PRELINKED), QUERY(DT_GNU_CONFLICTSZ), QUERY(DT_GNU_LIBLISTSZ), QUERY(DT_CHECKSUM), QUERY(DT_PLTPADSZ), QUERY(DT_MOVEENT), QUERY(DT_MOVESZ), QUERY(DT_GNU_HASH), QUERY(DT_TLSDESC_PLT), QUERY(DT_TLSDESC_GOT), QUERY(DT_GNU_CONFLICT), QUERY(DT_GNU_LIBLIST), QUERY(DT_CONFIG), QUERY(DT_DEPAUDIT), QUERY(DT_AUDIT), QUERY(DT_PLTPAD), QUERY(DT_MOVETAB), QUERY(DT_SYMINFO), QUERY(DT_VERSYM), QUERY(DT_RELACOUNT), QUERY(DT_RELCOUNT), QUERY(DT_FLAGS_1), QUERY(DT_VERDEF), QUERY(DT_VERDEFNUM), QUERY(DT_VERNEED), QUERY(DT_VERNEEDNUM), QUERY(DT_AUXILIARY), QUERY(DT_FILTER), { 0, 0 } }; const char *get_elfdtype(int type) { return find_pairtype(elf_dtypes, type); } /* translate elf SHT_ defines */ static pairtype elf_shttypes[] = { QUERY(SHT_NULL), QUERY(SHT_PROGBITS), QUERY(SHT_SYMTAB), QUERY(SHT_STRTAB), QUERY(SHT_RELA), QUERY(SHT_HASH), QUERY(SHT_DYNAMIC), QUERY(SHT_NOTE), QUERY(SHT_NOBITS), QUERY(SHT_REL), QUERY(SHT_SHLIB), QUERY(SHT_DYNSYM), QUERY(SHT_INIT_ARRAY), QUERY(SHT_FINI_ARRAY), QUERY(SHT_PREINIT_ARRAY), QUERY(SHT_GROUP), QUERY(SHT_SYMTAB_SHNDX), QUERY(SHT_GNU_ATTRIBUTES), QUERY(SHT_GNU_HASH), QUERY(SHT_GNU_LIBLIST), QUERY(SHT_CHECKSUM), QUERY(SHT_SUNW_move), QUERY(SHT_SUNW_COMDAT), QUERY(SHT_SUNW_syminfo), QUERY(SHT_GNU_verdef), QUERY(SHT_GNU_verneed), QUERY(SHT_GNU_versym), { 0, 0 } }; const char *get_elfshttype(int type) { return find_pairtype(elf_shttypes, type); } /* translate elf STT_ defines */ static pairtype elf_stttypes[] = { QUERY(STT_NOTYPE), QUERY(STT_OBJECT), QUERY(STT_FUNC), QUERY(STT_SECTION), QUERY(STT_FILE), QUERY(STT_COMMON), QUERY(STT_TLS), QUERY(STT_GNU_IFUNC), { 0, 0 } }; const char *get_elfstttype(int type) { return find_pairtype(elf_stttypes, type); } /* translate elf STB_ defines */ static pairtype elf_stbtypes[] = { QUERY(STB_LOCAL), QUERY(STB_GLOBAL), QUERY(STB_WEAK), QUERY(STB_GNU_UNIQUE), { 0, 0 } }; const char *get_elfstbtype(int type) { return find_pairtype(elf_stbtypes, type); } /* translate elf STV_ defines */ static pairtype elf_stvtypes[] = { QUERY(STV_DEFAULT), QUERY(STV_INTERNAL), QUERY(STV_HIDDEN), QUERY(STV_PROTECTED), { 0, 0 } }; const char *get_elfstvtype(int type) { return find_pairtype(elf_stvtypes, type); } /* translate elf SHN_ defines */ static pairtype elf_shntypes[] = { QUERY(SHN_UNDEF), QUERY(SHN_BEFORE), QUERY(SHN_AFTER), QUERY(SHN_ABS), QUERY(SHN_COMMON), QUERY(SHN_XINDEX), { 0, 0 } }; const char *get_elfshntype(int type) { if (type && type < SHN_LORESERVE) return "DEFINED"; return find_pairtype(elf_shntypes, type); } /* translate elf NT_ defines */ static pairtype elf_nttypes_GNU[] = { QUERY(NT_GNU_ABI_TAG), QUERY(NT_GNU_HWCAP), QUERY(NT_GNU_BUILD_ID), QUERY(NT_GNU_GOLD_VERSION), { 0, 0 } }; static pairtype elf_nttypes_core[] = { QUERY(NT_PRSTATUS), QUERY(NT_FPREGSET), QUERY(NT_PRPSINFO), QUERY(NT_PRXREG), QUERY(NT_TASKSTRUCT), QUERY(NT_PLATFORM), QUERY(NT_AUXV), QUERY(NT_GWINDOWS), QUERY(NT_ASRS), QUERY(NT_PSTATUS), QUERY(NT_PSINFO), QUERY(NT_PRCRED), QUERY(NT_UTSNAME), QUERY(NT_LWPSTATUS), QUERY(NT_LWPSINFO), QUERY(NT_PRFPXREG), QUERY(NT_SIGINFO), QUERY(NT_FILE), QUERY(NT_PRXFPREG), QUERY(NT_PPC_VMX), QUERY(NT_PPC_SPE), QUERY(NT_PPC_VSX), QUERY(NT_386_TLS), QUERY(NT_386_IOPERM), QUERY(NT_X86_XSTATE), QUERY(NT_S390_HIGH_GPRS), QUERY(NT_S390_TIMER), QUERY(NT_S390_TODCMP), QUERY(NT_S390_TODPREG), QUERY(NT_S390_CTRS), QUERY(NT_S390_PREFIX), QUERY(NT_S390_LAST_BREAK), QUERY(NT_S390_SYSTEM_CALL), QUERY(NT_S390_TDB), QUERY(NT_ARM_VFP), QUERY(NT_ARM_TLS), QUERY(NT_ARM_HW_BREAK), QUERY(NT_ARM_HW_WATCH), { 0, 0 } }; static pairtype elf_nttypes_fallback[] = { QUERY(NT_VERSION), { 0, 0 } }; const char *get_elfnttype(uint16_t e_type, const char *name, int type) { if (name) { if (!strcmp(name, "GNU")) return find_pairtype(elf_nttypes_GNU, type); /* Unknown extension, so just fallback to common ones. */ } if (e_type == ET_CORE) return find_pairtype(elf_nttypes_core, type); else return find_pairtype(elf_nttypes_fallback, type); } /* Read an ELF into memory */ #define IS_ELF_BUFFER(buff) \ (buff[EI_MAG0] == ELFMAG0 && \ buff[EI_MAG1] == ELFMAG1 && \ buff[EI_MAG2] == ELFMAG2 && \ buff[EI_MAG3] == ELFMAG3) #define DO_WE_LIKE_ELF(buff) \ ((buff[EI_CLASS] == ELFCLASS32 || buff[EI_CLASS] == ELFCLASS64) && \ (buff[EI_DATA] == ELFDATA2LSB || buff[EI_DATA] == ELFDATA2MSB) && \ (buff[EI_VERSION] == EV_CURRENT)) elfobj *readelf_buffer(const char *filename, const void *buffer, size_t buffer_len) { elfobj *elf; /* make sure we have enough bytes to scan e_ident */ if (buffer == NULL || buffer_len < EI_NIDENT) return NULL; elf = xzalloc(sizeof(*elf)); elf->fd = -1; elf->len = buffer_len; elf->data = buffer; elf->data_end = buffer + buffer_len; /* make sure we have an elf */ if (!IS_ELF_BUFFER(elf->data)) { free_elf_and_return: free(elf); return NULL; } /* check class and stuff */ if (!DO_WE_LIKE_ELF(elf->data)) { warn("we no likey %s: {%s,%s,%s,%s}", filename, get_elfeitype(EI_CLASS, elf->data[EI_CLASS]), get_elfeitype(EI_DATA, elf->data[EI_DATA]), get_elfeitype(EI_VERSION, elf->data[EI_VERSION]), get_elfeitype(EI_OSABI, elf->data[EI_OSABI])); goto free_elf_and_return; } elf->filename = filename; elf->base_filename = strrchr(filename, '/'); if (elf->base_filename == NULL) elf->base_filename = elf->filename; else elf->base_filename = elf->base_filename + 1; elf->elf_class = elf->data[EI_CLASS]; do_reverse_endian = (ELF_DATA != elf->data[EI_DATA]); /* for arches that need alignment, we have to make sure the buffer * is strictly aligned. archive (.a) files only align to 2 bytes * while the arch can easily require 8. so dupe the buffer so * that our local copy is always aligned (since we can't shift the * file mapping back and forth a few bytes). */ if (!__PAX_UNALIGNED_OK && ((unsigned long)elf->vdata & 0x7)) { elf->_data = xmalloc(elf->len); memcpy(elf->_data, elf->data, elf->len); elf->data = elf->_data; elf->data_end = elf->_data + elf->len; } #define READELF_HEADER(B) \ if (elf->elf_class == ELFCLASS ## B) { \ char invalid; \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ Elf ## B ## _Off size; \ /* verify program header */ \ invalid = 0; \ if (EGET(ehdr->e_phnum) <= 0) \ invalid = 1; /* this is not abnormal so dont warn */ \ else if (EGET(ehdr->e_phentsize) != sizeof(Elf ## B ## _Phdr)) \ invalid = 3; \ else { \ elf->phdr = elf->vdata + EGET(ehdr->e_phoff); \ size = EGET(ehdr->e_phnum) * EGET(ehdr->e_phentsize); \ if (elf->phdr < elf->ehdr || /* check overflow */ \ elf->phdr + size < elf->phdr || /* before start of mem */ \ elf->phdr + size > elf->ehdr + elf->len) /* before end of mem */ \ invalid = 2; \ } \ if (invalid > 1) \ warn("%s: Invalid program header info (%i)", filename, invalid); \ if (invalid) \ elf->phdr = NULL; \ /* verify section header */ \ invalid = 0; \ if (EGET(ehdr->e_shnum) <= 0) \ invalid = 1; /* this is not abnormal so dont warn */ \ else if (EGET(ehdr->e_shentsize) != sizeof(Elf ## B ## _Shdr)) \ invalid = 3; \ else { \ elf->shdr = elf->vdata + EGET(ehdr->e_shoff); \ size = EGET(ehdr->e_shnum) * EGET(ehdr->e_shentsize); \ if (elf->shdr < elf->ehdr || /* check overflow */ \ elf->shdr + size < elf->shdr || /* before start of mem */ \ elf->shdr + size > elf->ehdr + elf->len) /* before end of mem */ \ invalid = 2; \ } \ if (invalid > 1) \ warn("%s: Invalid section header info (%i)", filename, invalid); \ if (invalid) \ elf->shdr = NULL; \ } READELF_HEADER(32) READELF_HEADER(64) /* { char *p; strncpy(elf->basename, (p = strrchr(filename, '/')) == NULL ? "?" : p+1 , sizeof(elf->basename)); } */ return elf; } elfobj *_readelf_fd(const char *filename, int fd, size_t len, int read_only) { char *buffer; elfobj *ret; if (len == 0) { struct stat st; if (fstat(fd, &st) == -1) return NULL; len = st.st_size; if (len == 0) return NULL; } buffer = mmap(0, len, PROT_READ | (read_only ? 0 : PROT_WRITE), (read_only ? MAP_PRIVATE : MAP_SHARED), fd, 0); if (buffer == MAP_FAILED) { warn("mmap on '%s' of %li bytes failed :(", filename, (unsigned long)len); return NULL; } ret = readelf_buffer(filename, buffer, len); if (ret == NULL) munmap(buffer, len); else { ret->fd = fd; ret->is_mmap = 1; } return ret; } elfobj *_readelf(const char *filename, int read_only) { elfobj *ret; struct stat st; int fd; if ((fd = open(filename, (read_only ? O_RDONLY : O_RDWR))) == -1) return NULL; if (fstat(fd, &st) == -1) { close_fd_and_return: close(fd); return NULL; } /* make sure we have enough bytes to scan e_ident */ if (st.st_size <= EI_NIDENT) goto close_fd_and_return; ret = readelf_fd(filename, fd, st.st_size); if (ret == NULL) goto close_fd_and_return; return ret; } /* undo the readelf() stuff */ void unreadelf(elfobj *elf) { if (elf->is_mmap) munmap((void *)elf->vdata, elf->len); if (elf->fd != -1) close(elf->fd); if (!__PAX_UNALIGNED_OK) free(elf->_data); free(elf); } const char *pax_short_hf_flags(unsigned long flags) { static char buffer[7]; buffer[0] = (flags & HF_PAX_PAGEEXEC ? 'p' : 'P'); buffer[1] = (flags & HF_PAX_EMUTRAMP ? 'E' : 'e'); buffer[2] = (flags & HF_PAX_MPROTECT ? 'm' : 'M'); buffer[3] = (flags & HF_PAX_RANDMMAP ? 'r' : 'R'); buffer[4] = (flags & HF_PAX_RANDEXEC ? 'X' : 'x'); buffer[5] = (flags & HF_PAX_SEGMEXEC ? 's' : 'S'); buffer[6] = 0; return buffer; } /* PT_PAX_FLAGS are tristate ... * the display logic is: * lower case: explicitly disabled * upper case: explicitly enabled * - : default */ const char *pax_short_pf_flags(unsigned long flags) { static char buffer[7]; #define PAX_STATE(pf_on, pf_off, disp_on, disp_off) \ (flags & pf_on ? disp_on : (flags & pf_off ? disp_off : '-')) buffer[0] = PAX_STATE(PF_PAGEEXEC, PF_NOPAGEEXEC, 'P', 'p'); buffer[1] = PAX_STATE(PF_SEGMEXEC, PF_NOSEGMEXEC, 'S', 's'); buffer[2] = PAX_STATE(PF_MPROTECT, PF_NOMPROTECT, 'M', 'm'); buffer[3] = PAX_STATE(PF_RANDEXEC, PF_NORANDEXEC, 'X', 'x'); buffer[4] = PAX_STATE(PF_EMUTRAMP, PF_NOEMUTRAMP, 'E', 'e'); buffer[5] = PAX_STATE(PF_RANDMMAP, PF_NORANDMMAP, 'R', 'r'); buffer[6] = 0; if (((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC)) || \ ((flags & PF_SEGMEXEC) && (flags & PF_NOSEGMEXEC)) || \ ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP)) || \ ((flags & PF_RANDEXEC) && (flags & PF_NORANDEXEC)) || \ ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) || \ ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP))) warn("inconsistent state detected. flags=%lX", flags); return buffer; } const char *gnu_short_stack_flags(unsigned long flags) { static char buffer[4]; buffer[0] = (flags & PF_R ? 'R' : '-'); buffer[1] = (flags & PF_W ? 'W' : '-'); buffer[2] = (flags & PF_X ? 'X' : '-'); buffer[3] = 0; return buffer; } const void *elf_findsecbyname(const elfobj *elf, const char *name) { unsigned int i; const char *shdr_name; const void *ret = NULL; if (elf->shdr == NULL) return NULL; #define FINDSEC(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Shdr *shdr = SHDR ## B (elf->shdr); \ const Elf ## B ## _Shdr *strtbl; \ Elf ## B ## _Off offset; \ uint16_t shstrndx = EGET(ehdr->e_shstrndx); \ uint16_t shnum = EGET(ehdr->e_shnum); \ if (shstrndx >= shnum) return NULL; \ strtbl = &(shdr[shstrndx]); \ for (i = 0; i < shnum; ++i) { \ offset = EGET(strtbl->sh_offset) + EGET(shdr[i].sh_name); \ if (offset >= (Elf ## B ## _Off)elf->len) continue; \ shdr_name = elf->data + offset; \ if (!strcmp(shdr_name, name)) { \ if (ret) warnf("Multiple '%s' sections !?", name); \ ret = &shdr[i]; \ } \ } } FINDSEC(32) FINDSEC(64) return ret; } pax-utils-1.2.5/paxelf.h000066400000000000000000000100411362221774600151030ustar00rootroot00000000000000/* * Copyright 2005-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - * * Make sure all of the common elf stuff is setup as we expect */ #ifndef _PAX_ELF_H #define _PAX_ELF_H typedef struct { const void *phdr; const void *shdr; /* When we need to duplicate the ELF buffer for alignment. */ void *_data; union { const void *ehdr, *vdata; const char *data; uintptr_t udata; }; const void *data_end; char elf_class; off_t len; int fd; int is_mmap; const char *filename; const char *base_filename; } elfobj; #define EHDR32(ptr) ((Elf32_Ehdr *)(ptr)) #define EHDR64(ptr) ((Elf64_Ehdr *)(ptr)) #define PHDR32(ptr) ((Elf32_Phdr *)(ptr)) #define PHDR64(ptr) ((Elf64_Phdr *)(ptr)) #define SHDR32(ptr) ((Elf32_Shdr *)(ptr)) #define SHDR64(ptr) ((Elf64_Shdr *)(ptr)) #define RELA32(ptr) ((Elf32_Rela *)(ptr)) #define RELA64(ptr) ((Elf64_Rela *)(ptr)) #define REL32(ptr) ((Elf32_Rel *)(ptr)) #define REL64(ptr) ((Elf64_Rel *)(ptr)) #define DYN32(ptr) ((Elf32_Dyn *)(ptr)) #define DYN64(ptr) ((Elf64_Dyn *)(ptr)) #define SYM32(ptr) ((Elf32_Sym *)(ptr)) #define SYM64(ptr) ((Elf64_Sym *)(ptr)) #define VALID_RANGE(elf, offset, size) \ ((uint64_t)(size) <= (uint64_t)elf->len && \ (uint64_t)(offset) <= (uint64_t)elf->len - (uint64_t)(size)) #define VALID_SHDR(elf, shdr) \ (shdr && \ EGET(shdr->sh_type) != SHT_NOBITS && \ VALID_RANGE(elf, EGET(shdr->sh_offset), EGET(shdr->sh_size))) #define VALID_PHDR(elf, phdr) \ (phdr && VALID_RANGE(elf, EGET(phdr->p_offset), EGET(phdr->p_filesz))) /* prototypes */ extern const char *pax_short_hf_flags(unsigned long flags); extern const char *pax_short_pf_flags(unsigned long flags); extern const char *gnu_short_stack_flags(unsigned long flags); extern elfobj *readelf_buffer(const char *filename, const void *buffer, size_t buffer_len); extern elfobj *_readelf_fd(const char *filename, int fd, size_t len, int read_only); #define readelf_fd(filename, fd, len) _readelf_fd(filename, fd, len, 1) extern elfobj *_readelf(const char *filename, int read_only); #define readelf(filename) _readelf(filename, 1) extern void unreadelf(elfobj *elf); extern const char *get_elfeitype(int ei_type, int type); extern const char *get_elfetype(const elfobj *elf); extern const char *get_endian(const elfobj *elf); extern const char *get_elfosabi(const elfobj *elf); extern const char *get_elf_eabi(const elfobj *elf); extern const char *get_elfemtype(const elfobj *elf); extern const char *get_elfptype(int type); extern const char *get_elfdtype(int type); extern const char *get_elfshntype(int type); extern const char *get_elfshttype(int type); extern const char *get_elfstbtype(int type); extern const char *get_elfstvtype(int type); extern const char *get_elfstttype(int type); extern const char *get_elfnttype(uint16_t e_type, const char *name, int type); extern const void *elf_findsecbyname(const elfobj *elf, const char *name); extern unsigned int get_etype(const elfobj *elf); extern unsigned int get_emtype(const elfobj *elf); extern void print_etypes(FILE *); extern unsigned int etype_lookup(const char *); /* PaX flags (to be read in elfhdr.e_flags) */ #define HF_PAX_PAGEEXEC 1 /* 0: Paging based non-exec pages */ #define HF_PAX_EMUTRAMP 2 /* 0: Emulate trampolines */ #define HF_PAX_MPROTECT 4 /* 0: Restrict mprotect() */ #define HF_PAX_RANDMMAP 8 /* 0: Randomize mmap() base */ #define HF_PAX_RANDEXEC 16 /* 1: Randomize ET_EXEC base */ #define HF_PAX_SEGMEXEC 32 /* 0: Segmentation based non-exec pages */ #define EI_PAX 14 /* Index in e_ident[] where to read flags */ #define __EI_PAX_FLAGS(B, elf) \ ((EHDR ## B (elf->ehdr)->e_ident[EI_PAX + 1] << 8) + \ EHDR ## B (elf->ehdr)->e_ident[EI_PAX]) #define EI_PAX_FLAGS(elf) \ (__extension__ ({ \ unsigned long __res; \ if (elf->elf_class == ELFCLASS32) \ __res = __EI_PAX_FLAGS(32, elf); \ else \ __res = __EI_PAX_FLAGS(64, elf); \ __res; \ })) #endif /* _PAX_ELF_H */ pax-utils-1.2.5/paxinc.c000066400000000000000000000115401362221774600151060ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - */ /* stick common symbols here that are needed by paxinc.h */ #define IN_paxinc #include "paxinc.h" char do_reverse_endian; /* some of this ar code was taken from busybox */ #define AR_MAGIC "!" #define AR_MAGIC_SIZE (sizeof(AR_MAGIC)-1) /* dont count null byte */ archive_handle *ar_open_fd(const char *filename, int fd, bool verbose) { static archive_handle ret; char buf[AR_MAGIC_SIZE]; ret.filename = filename; ret.fd = fd; ret.skip = 0; ret.extfn = NULL; ret.verbose = verbose; if (read(ret.fd, buf, AR_MAGIC_SIZE) != AR_MAGIC_SIZE) return NULL; if (strncmp(buf, AR_MAGIC, AR_MAGIC_SIZE)) return NULL; return &ret; } archive_handle *ar_open(const char *filename, bool verbose) { int fd; archive_handle *ret; if ((fd=open(filename, O_RDONLY)) == -1) errp("%s: could not open", filename); ret = ar_open_fd(filename, fd, verbose); if (ret == NULL) close(fd); return ret; } archive_member *ar_next(archive_handle *ar) { char *s; ssize_t len = 0; static archive_member ret; if (ar->skip && lseek(ar->fd, ar->skip, SEEK_CUR) == -1) { close_and_ret: free(ar->extfn); close(ar->fd); ar->extfn = NULL; ar->fd = -1; return NULL; } if (read(ar->fd, ret.buf.raw, sizeof(ret.buf.raw)) != sizeof(ret.buf.raw)) goto close_and_ret; /* ar header starts on an even byte (2 byte aligned) * '\n' is used for padding */ if (ret.buf.raw[0] == '\n') { memmove(ret.buf.raw, ret.buf.raw+1, 59); if (read(ar->fd, ret.buf.raw+59, 1) != 1) goto close_and_ret; } if ((ret.buf.formatted.magic[0] != '`') || (ret.buf.formatted.magic[1] != '\n')) { /* When dealing with corrupt or random embedded cross-compilers, they might * be abusing the archive format; only complain when in verbose mode. */ if (ar->verbose) warn("%s: invalid ar entry", ar->filename); goto close_and_ret; } if (ret.buf.formatted.name[0] == '/' && ret.buf.formatted.name[1] == '/') { if (ar->extfn != NULL) { warn("%s: Duplicate GNU extended filename section", ar->filename); goto close_and_ret; } len = atoi(ret.buf.formatted.size); ar->extfn = xmalloc(sizeof(char) * (len + 1)); if (read(ar->fd, ar->extfn, len) != len) goto close_and_ret; ar->extfn[len--] = '\0'; for (; len > 0; len--) if (ar->extfn[len] == '\n') ar->extfn[len] = '\0'; ar->skip = 0; return ar_next(ar); } s = ret.buf.formatted.name; if (s[0] == '#' && s[1] == '1' && s[2] == '/') { /* BSD extended filename, always in use on Darwin */ len = atoi(s + 3); if (len <= (ssize_t)sizeof(ret.buf.formatted.name)) { if (read(ar->fd, ret.buf.formatted.name, len) != len) goto close_and_ret; } else { s = alloca(sizeof(char) * len + 1); if (read(ar->fd, s, len) != len) goto close_and_ret; s[len] = '\0'; } } else if (s[0] == '/' && s[1] >= '0' && s[1] <= '9') { /* GNU extended filename */ if (ar->extfn == NULL) { warn("%s: GNU extended filename without special data section", ar->filename); goto close_and_ret; } s = ar->extfn + atoi(s + 1); } snprintf(ret.name, sizeof(ret.name), "%s:%s", ar->filename, s); ret.name[sizeof(ret.name) - 1] = '\0'; if ((s=strchr(ret.name+strlen(ar->filename), '/')) != NULL) *s = '\0'; ret.date = atoi(ret.buf.formatted.date); ret.uid = atoi(ret.buf.formatted.uid); ret.gid = atoi(ret.buf.formatted.gid); ret.mode = strtol(ret.buf.formatted.mode, NULL, 8); ret.size = atoi(ret.buf.formatted.size); ar->skip = ret.size - len; return &ret; } /* Convert file perms into octal string */ const char *strfileperms(const char *fname) { struct stat st; static char buf[8]; if (stat(fname, &st) == -1) return ""; snprintf(buf, sizeof(buf), "%o", st.st_mode); return buf + 2; } /* Color helpers */ #define COLOR(c,b) "\e[" c ";" b "m" const char *NORM = COLOR("00", "00"); const char *RED = COLOR("31", "01"); const char *YELLOW = COLOR("33", "01"); void color_init(bool disable) { if (!disable) { const char *nocolor = getenv("NOCOLOR"); if (nocolor) disable = !strcmp(nocolor, "yes") || !strcmp(nocolor, "true"); } if (disable) NORM = RED = YELLOW = ""; } /* File system helpers. */ int root_fd = AT_FDCWD; FILE *fopenat_r(int dir_fd, const char *path) { int fd = openat(dir_fd, path, O_RDONLY|O_CLOEXEC); if (fd == -1) return NULL; return fdopen(fd, "re"); } const char *root_rel_path(const char *path) { /* * openat() will ignore the dirfd if path starts with * a /, so consume all of that noise * * XXX: we don't handle relative paths like ../ that * break out of the --root option, but for now, just * don't do that :P. */ if (root_fd != AT_FDCWD) { while (*path == '/') ++path; if (*path == '\0') path = "."; } return path; } pax-utils-1.2.5/paxinc.h000066400000000000000000000073111362221774600151140ustar00rootroot00000000000000/* * Copyright 2005-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - * * Make sure all of the common stuff is setup as we expect */ #ifndef _PAX_INC_H #define _PAX_INC_H #include "porting.h" #include "xfuncs.h" #include "security.h" #ifndef VERSION # define VERSION "git" #endif #ifndef VCSID # define VCSID "" #endif #ifdef EBUG # define USE_DEBUG 1 #else # define USE_DEBUG 0 #endif /* ELF love */ #include "elf.h" #include "paxelf.h" #include "paxldso.h" /* Mach-O love */ #include "macho.h" #include "paxmacho.h" extern char do_reverse_endian; #ifdef IN_paxinc typedef struct { int fd; const char *filename; size_t skip; char *extfn; bool verbose; } archive_handle; #else typedef void archive_handle; #endif typedef struct { char name[__PAX_UTILS_PATH_MAX]; time_t date; uid_t uid; gid_t gid; mode_t mode; off_t size; #ifdef IN_paxinc union { char raw[60]; struct { char name[16]; char date[12]; char uid[6]; char gid[6]; char mode[8]; char size[10]; char magic[2]; } formatted; } buf; #endif } archive_member; archive_handle *ar_open_fd(const char *filename, int fd, bool verbose); archive_handle *ar_open(const char *filename, bool verbose); archive_member *ar_next(archive_handle *); const char *strfileperms(const char *fname); /* Get a value 'X', compensating for endianness. */ #define EGET(X) \ (__extension__ ({ \ uint64_t __res; \ if (!do_reverse_endian) { __res = (X); \ } else if (sizeof(X) == 1) { __res = (X); \ } else if (sizeof(X) == 2) { __res = bswap_16((X)); \ } else if (sizeof(X) == 4) { __res = bswap_32((X)); \ } else if (sizeof(X) == 8) { __res = bswap_64((X)); \ } else { errf("EGET failed :( (sizeof(X) == %i)", (int)sizeof(X)); } \ __res; \ })) /* Set a value 'Y' to 'X', compensating for endianness. */ #define ESET(Y,X) \ do { \ if (!do_reverse_endian) { Y = (X); \ } else if (sizeof(Y) == 1) { Y = (X); \ } else if (sizeof(Y) == 2) { Y = bswap_16((uint16_t)(X)); \ } else if (sizeof(Y) == 4) { Y = bswap_32((uint32_t)(X)); \ } else if (sizeof(Y) == 8) { Y = bswap_64((uint64_t)(X)); \ } else { errf("ESET failed :( (size(Y) == %i)", (int)sizeof(Y)); } \ } while (0) /* alignment helpers */ #define ALIGN_DOWN(base, size) ((base) & -((__typeof__(base)) (size))) #define ALIGN_UP(base, size) ALIGN_DOWN((base) + (size) - 1, (size)) #define PTR_ALIGN_DOWN(base, size) ((__typeof__(base))ALIGN_DOWN((uintptr_t)(base), (size))) #define PTR_ALIGN_UP(base, size) ((__typeof__(base))ALIGN_UP ((uintptr_t)(base), (size))) /* helper functions for showing errors */ extern const char *NORM, *RED, *YELLOW; void color_init(bool disable); /* constant pointer to a constant buffer ... each program needs to set this */ extern const char argv0[]; /* we need the space before the last comma or we trigger a bug in gcc-2 :( */ #define warn(fmt, args...) \ fprintf(stderr, "%s%s%s: " fmt "\n", RED, argv0, NORM , ## args) #define warnf(fmt, args...) warn("%s%s%s(): " fmt, YELLOW, __FUNCTION__, NORM , ## args) #define warnp(fmt, args...) warn(fmt ": %s" , ## args , strerror(errno)) #define warnfp(fmt, args...) warnf(fmt ": %s" , ## args , strerror(errno)) #define _err(wfunc, fmt, args...) \ do { \ wfunc(fmt, ## args); \ exit(EXIT_FAILURE); \ } while (0) #define err(fmt, args...) _err(warn, fmt, ## args) #define errf(fmt, args...) _err(warnf, fmt, ## args) #define errp(fmt, args...) _err(warnp, fmt , ## args) /* File system helper functions. */ extern int root_fd; FILE *fopenat_r(int dir_fd, const char *path); const char *root_rel_path(const char *path); #endif /* _PAX_INC_H */ pax-utils-1.2.5/paxldso.c000066400000000000000000000206001362221774600152730ustar00rootroot00000000000000/* * Copyright 2003-2016 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2016 Mike Frysinger - */ #include "paxinc.h" /* * ld.so.cache logic */ #if PAX_LDSO_CACHE static void *ldcache = NULL; static size_t ldcache_size = 0; static char *ldso_cache_buf = NULL; static size_t ldso_cache_buf_size = 0; #if defined(__GLIBC__) || defined(__UCLIBC__) /* Defines can be seen in glibc's sysdeps/generic/ldconfig.h */ #define LDSO_CACHE_MAGIC "ld.so-" #define LDSO_CACHE_MAGIC_LEN (sizeof LDSO_CACHE_MAGIC -1) #define LDSO_CACHE_VER "1.7.0" #define LDSO_CACHE_VER_LEN (sizeof LDSO_CACHE_VER -1) #define FLAG_ANY -1 #define FLAG_TYPE_MASK 0x00ff #define FLAG_LIBC4 0x0000 #define FLAG_ELF 0x0001 #define FLAG_ELF_LIBC5 0x0002 #define FLAG_ELF_LIBC6 0x0003 #define FLAG_REQUIRED_MASK 0xff00 #define FLAG_SPARC_LIB64 0x0100 #define FLAG_IA64_LIB64 0x0200 #define FLAG_X8664_LIB64 0x0300 #define FLAG_S390_LIB64 0x0400 #define FLAG_POWERPC_LIB64 0x0500 #define FLAG_MIPS64_LIBN32 0x0600 #define FLAG_MIPS64_LIBN64 0x0700 #define FLAG_X8664_LIBX32 0x0800 #define FLAG_ARM_LIBHF 0x0900 #define FLAG_AARCH64_LIB64 0x0a00 #define FLAG_ARM_LIBSF 0x0b00 #define FLAG_MIPS_LIB32_NAN2008 0x0c00 #define FLAG_MIPS64_LIBN32_NAN2008 0x0d00 #define FLAG_MIPS64_LIBN64_NAN2008 0x0e00 typedef struct { int flags; unsigned int sooffset; unsigned int liboffset; } libentry_t; static bool is_compatible(elfobj *elf, libentry_t *libent) { int flags = libent->flags & FLAG_REQUIRED_MASK; /* We assume that ((flags & FLAG_TYPE_MASK) == FLAG_ELF_LIBC6) * since anything older is very very old and no one cares. * * Otherwise we really only need to check here for cases where * an arch has more than one ABI per bitsize (e.g. x86, x32, and * x86_64). The default case should be fine otherwise. */ if (elf->elf_class == ELFCLASS32) { const Elf32_Ehdr *ehdr = EHDR32(elf->ehdr); switch (EGET(ehdr->e_machine)) { case EM_AARCH64: break; case EM_ARM: if ((flags == FLAG_ARM_LIBHF && (ehdr->e_flags & EF_ARM_ABI_FLOAT_HARD)) || (flags == FLAG_ARM_LIBSF && (ehdr->e_flags & EF_ARM_ABI_FLOAT_SOFT)) || (flags == 0 && !(ehdr->e_flags & (EF_ARM_ABI_FLOAT_HARD | EF_ARM_ABI_FLOAT_SOFT)))) return true; break; case EM_IA_64: break; case EM_MIPS: { int ef_flags = (ehdr->e_flags & (EF_MIPS_ABI2 | EF_MIPS_NAN2008)); if ((flags == 0 && ef_flags == 0) || (flags == FLAG_MIPS64_LIBN32 && ef_flags == EF_MIPS_ABI2) || (flags == FLAG_MIPS_LIB32_NAN2008 && ef_flags == EF_MIPS_NAN2008) || (flags == FLAG_MIPS64_LIBN32_NAN2008 && ef_flags == (EF_MIPS_ABI2 | EF_MIPS_NAN2008))) return true; break; } case EM_X86_64: if (flags == FLAG_X8664_LIBX32) return true; break; default: /* A sane enough default. */ if (flags == 0) return true; break; } } else { const Elf64_Ehdr *ehdr = EHDR64(elf->ehdr); switch (EGET(ehdr->e_machine)) { case EM_AARCH64: if (flags == FLAG_AARCH64_LIB64) return true; break; case EM_ARM: break; case EM_IA_64: if (flags == FLAG_IA64_LIB64) return true; break; case EM_MIPS: { int ef_flags = (ehdr->e_flags & EF_MIPS_NAN2008); if ((flags == FLAG_MIPS64_LIBN64 && ef_flags == 0) || (flags == FLAG_MIPS64_LIBN64_NAN2008 && ef_flags == EF_MIPS_NAN2008)) return true; break; } case EM_X86_64: if (flags == FLAG_X8664_LIB64) return true; break; default: /* A sane enough default. */ if (flags != 0) return true; break; } } return false; } char *ldso_cache_lookup_lib(elfobj *elf, const char *fname) { unsigned int nlib; char *ret = NULL; char *strs; typedef struct { char magic[LDSO_CACHE_MAGIC_LEN]; char version[LDSO_CACHE_VER_LEN]; unsigned int nlibs; } header_t; header_t *header; libentry_t *libent; if (fname == NULL) return NULL; if (ldcache == NULL) { int fd; const char *cachefile = root_rel_path("/etc/ld.so.cache"); struct stat st; if (fstatat(root_fd, cachefile, &st, 0)) return NULL; fd = openat(root_fd, cachefile, O_RDONLY); if (fd == -1) return NULL; /* cache these values so we only map/unmap the cache file once */ ldcache_size = st.st_size; header = ldcache = mmap(0, ldcache_size, PROT_READ, MAP_SHARED, fd, 0); close(fd); if (ldcache == MAP_FAILED) { ldcache = NULL; return NULL; } if (memcmp(header->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN) || memcmp(header->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN)) { munmap(ldcache, ldcache_size); ldcache = NULL; return NULL; } ldso_cache_buf_size = 4096; ldso_cache_buf = xrealloc(ldso_cache_buf, ldso_cache_buf_size); } else header = ldcache; libent = ldcache + sizeof(header_t); strs = (char *) &libent[header->nlibs]; for (nlib = 0; nlib < header->nlibs; ++nlib) { const char *lib; size_t lib_len; if (!is_compatible(elf, &libent[nlib])) continue; if (strcmp(fname, strs + libent[nlib].sooffset) != 0) continue; /* Return first hit because that is how the ldso rolls */ lib = strs + libent[nlib].liboffset; lib_len = strlen(lib) + 1; if (lib_len > ldso_cache_buf_size) { ldso_cache_buf = xrealloc(ldso_cache_buf, ldso_cache_buf_size + 4096); ldso_cache_buf_size += 4096; } memcpy(ldso_cache_buf, lib, lib_len); ret = ldso_cache_buf; break; } return ret; } #endif static void ldso_cache_cleanup(void) { free(ldso_cache_buf); if (ldcache != NULL) munmap(ldcache, ldcache_size); } #else # define ldso_cache_cleanup() #endif /* PAX_LDSO_CACHE */ /* * ld.so.conf logic */ static array_t _ldpaths = array_init_decl; array_t *ldpaths = &_ldpaths; #if PAX_LDSO_CONFIG #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__) int ldso_config_load(const char *fname) { FILE *fp = NULL; char *p, *path; size_t len; int curr_fd = -1; fp = fopenat_r(root_fd, root_rel_path(fname)); if (fp == NULL) return -1; path = NULL; len = 0; while (getline(&path, &len, fp) != -1) { if ((p = strrchr(path, '\r')) != NULL) *p = 0; if ((p = strchr(path, '\n')) != NULL) *p = 0; /* recursive includes of the same file will make this segfault. */ if ((memcmp(path, "include", 7) == 0) && isblank(path[7])) { glob_t gl; size_t x; const char *gpath; /* re-use existing path buffer ... need to be creative */ if (path[8] != '/') gpath = memcpy(path + 3, "/etc/", 5); else gpath = path + 8; if (root_fd != AT_FDCWD) { if (curr_fd == -1) { curr_fd = open(".", O_RDONLY|O_CLOEXEC); if (fchdir(root_fd)) errp("unable to change to root dir"); } gpath = root_rel_path(gpath); } if (glob(gpath, 0, NULL, &gl) == 0) { for (x = 0; x < gl.gl_pathc; ++x) { /* try to avoid direct loops */ if (strcmp(gl.gl_pathv[x], fname) == 0) continue; ldso_config_load(gl.gl_pathv[x]); } globfree(&gl); } /* failed globs are ignored by glibc */ continue; } if (*path != '/') continue; xarraypush_str(ldpaths, path); } free(path); fclose(fp); if (curr_fd != -1) { if (fchdir(curr_fd)) {/* don't care */} close(curr_fd); } return 0; } #elif defined(__FreeBSD__) || defined(__DragonFly__) int ldso_config_load(const char *fname) { FILE *fp = NULL; char *b = NULL, *p; struct elfhints_hdr hdr; fp = fopenat_r(root_fd, root_rel_path(fname)); if (fp == NULL) return -1; if (fread(&hdr, 1, sizeof(hdr), fp) != sizeof(hdr) || hdr.magic != ELFHINTS_MAGIC || hdr.version != 1 || fseek(fp, hdr.strtab + hdr.dirlist, SEEK_SET) == -1) { fclose(fp); return -1; } b = xmalloc(hdr.dirlistlen + 1); if (fread(b, 1, hdr.dirlistlen+1, fp) != hdr.dirlistlen+1) { fclose(fp); free(b); return -1; } while ((p = strsep(&b, ":"))) { if (*p == '\0') continue; xarraypush_str(ldpaths, p); } free(b); fclose(fp); return 0; } #endif static void ldso_config_cleanup(void) { xarrayfree(ldpaths); } #else # define ldso_config_cleanup() #endif /* PAX_LDSO_CONFIG */ #ifndef paxldso_cleanup void paxldso_cleanup(void) { ldso_cache_cleanup(); ldso_config_cleanup(); } #endif pax-utils-1.2.5/paxldso.h000066400000000000000000000026311362221774600153040ustar00rootroot00000000000000/* * Copyright 2003-2016 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2016 Mike Frysinger - */ #ifndef _PAX_LDSO_H #define _PAX_LDSO_H /* * ld.so.cache logic */ #if !defined(__GLIBC__) && \ !defined(__UCLIBC__) # ifdef __ELF__ # warning Cache support not implemented for your target # endif # define PAX_LDSO_CACHE 0 #else # define PAX_LDSO_CACHE 1 #endif #if PAX_LDSO_CACHE extern char *ldso_cache_lookup_lib(elfobj *elf, const char *fname); #else static inline char *ldso_cache_lookup_lib(__unused__ elfobj *elf, __unused__ const char *fname) { return NULL; } #endif /* * ld.so.conf logic */ #if !defined(__GLIBC__) && \ !defined(__UCLIBC__) && \ !defined(__NetBSD__) && \ !defined(__FreeBSD__) && \ !defined(__DragonFly__) # ifdef __ELF__ # warning Cache config support not implemented for your target # endif # define PAX_LDSO_CONFIG 0 #else # define PAX_LDSO_CONFIG 1 #endif /* Consumers refer to ldpaths directly, so can't hide its def. */ extern array_t *ldpaths; #if PAX_LDSO_CONFIG extern int ldso_config_load(const char *fname); #else static inline int ldso_config_load(__unused__ const char *fname) { return 0; } #endif #if PAX_LDSO_CACHE || PAX_LDSO_CONFIG extern void paxldso_cleanup(void); #else # define paxldso_cleanup() #endif #endif pax-utils-1.2.5/paxmacho.c000066400000000000000000000244171362221774600154330ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - * 2008-2012 Fabian Groffen - */ #include "paxinc.h" /* lil' static string pool */ static const char STR_BE[] = "BE"; static const char STR_LE[] = "LE"; static const char STR_PPC[] = "ppc"; static const char STR_PPC64[] = "ppc64"; static const char STR_I386[] = "i386"; static const char STR_X86_64[] = "x86_64"; static const char STR_ARM[] = "arm"; /* iPhone */ static const char STR_UNKNOWN[] = "unknown"; #define QUERY(n) { #n, n } typedef const struct { const char *str; unsigned int value; } pairtype; static inline const char *find_pairtype(pairtype *pt, unsigned int type) { size_t i; for (i = 0; pt[i].str; ++i) if (type == pt[i].value) return pt[i].str; return "UNKNOWN TYPE"; } /* translate misc mach-o MH_ defines */ static pairtype macho_mh_type[] = { QUERY(MH_OBJECT), QUERY(MH_EXECUTE), QUERY(MH_BUNDLE), QUERY(MH_DYLIB), QUERY(MH_PRELOAD), QUERY(MH_CORE), QUERY(MH_DYLINKER), QUERY(MH_DYLIB_STUB), QUERY(MH_DSYM), { 0, 0 } }; const char *get_machomhtype(fatobj *fobj) { /* can use 32-bits header, since 64 and 32 are aligned here */ return find_pairtype(macho_mh_type, MOBJGET(fobj, mhdr.hdr32->filetype)); } /* translate misc mach-o MH_ flags */ static pairtype macho_mh_flag[] = { QUERY(MH_NOUNDEFS), QUERY(MH_INCRLINK), QUERY(MH_DYLDLINK), QUERY(MH_TWOLEVEL), QUERY(MH_BINDATLOAD), QUERY(MH_PREBOUND), QUERY(MH_PREBINDABLE), QUERY(MH_NOFIXPREBINDING), QUERY(MH_ALLMODSBOUND), QUERY(MH_CANONICAL), QUERY(MH_SPLIT_SEGS), QUERY(MH_FORCE_FLAT), QUERY(MH_SUBSECTIONS_VIA_SYMBOLS), QUERY(MH_NOMULTIDEFS), { 0, 0 } }; void get_machomhflags(fatobj *fobj, char **ret, size_t *ret_len) { uint32_t flags; int i; char first = 1; /* can use 32-bits header, since 64 and 32 are aligned here */ flags = MOBJGET(fobj, mhdr.hdr32->flags); for (i = 0; macho_mh_flag[i].str; ++i) if ((flags & macho_mh_flag[i].value) == macho_mh_flag[i].value) { if (!first) xchrcat(ret, ',', ret_len); xstrcat(ret, macho_mh_flag[i].str, ret_len); first = 0; } } static pairtype macho_cputype[] = { QUERY(CPU_TYPE_POWERPC), QUERY(CPU_TYPE_I386), QUERY(CPU_TYPE_ARM), QUERY(CPU_TYPE_POWERPC64), QUERY(CPU_TYPE_X86_64), { 0, 0 } }; const char *get_machocputype(fatobj *fobj) { /* can use 32-bits header, since 64 and 32 are aligned here */ const char *ret = find_pairtype(macho_cputype, MOBJGET(fobj, mhdr.hdr32->cputype)); return ret + sizeof("CPU_TYPE_") - 1; } /* translate cpusubtypes */ static pairtype macho_cpusubtypeppc[] = { QUERY(CPU_SUBTYPE_POWERPC_ALL), QUERY(CPU_SUBTYPE_POWERPC_601), QUERY(CPU_SUBTYPE_POWERPC_602), QUERY(CPU_SUBTYPE_POWERPC_603), QUERY(CPU_SUBTYPE_POWERPC_603e), QUERY(CPU_SUBTYPE_POWERPC_603ev), QUERY(CPU_SUBTYPE_POWERPC_604), QUERY(CPU_SUBTYPE_POWERPC_604e), QUERY(CPU_SUBTYPE_POWERPC_620), QUERY(CPU_SUBTYPE_POWERPC_750), QUERY(CPU_SUBTYPE_POWERPC_7400), QUERY(CPU_SUBTYPE_POWERPC_7450), QUERY(CPU_SUBTYPE_POWERPC_970), { 0, 0 } }; static pairtype macho_cpusubtypex86[] = { QUERY(CPU_SUBTYPE_I386_ALL), QUERY(CPU_SUBTYPE_486), QUERY(CPU_SUBTYPE_586), QUERY(CPU_SUBTYPE_PENTIUM_3), QUERY(CPU_SUBTYPE_PENTIUM_M), QUERY(CPU_SUBTYPE_PENTIUM_4), QUERY(CPU_SUBTYPE_ITANIUM), QUERY(CPU_SUBTYPE_XEON), { 0, 0 } }; const char *get_machosubcputype(fatobj *fobj) { const char *ret; /* can use 32-bits header, since 64 and 32 are aligned here */ uint32_t type = MOBJGET(fobj, mhdr.hdr32->cputype); pairtype *pt = NULL; if (type == CPU_TYPE_I386 || type == CPU_TYPE_X86_64) pt = macho_cpusubtypex86; else if (type == CPU_TYPE_POWERPC || type == CPU_TYPE_POWERPC64) pt = macho_cpusubtypeppc; if (pt) { type = MOBJGET(fobj, mhdr.hdr32->cpusubtype); ret = find_pairtype(pt, type); return ret + sizeof("CPU_SUBTYPE_") - 1; } else return STR_UNKNOWN; } /* Determines the type of this object, and sets the right 32-bit or * 64-bits pointer. The ismach64 flag is filled in appropriately. The * return of this function is the read magic value, or 0 when the file * is not recognised. * Note: the input addr must be enough to map on struct mach_header! */ inline static uint32_t read_mach_header(fatobj *fobj, void *addr) { struct mach_header *mhdr = addr; fobj->mhdata = addr; switch (mhdr->magic) { case MH_CIGAM: fobj->swapped = 1; /* fall through */ case MH_MAGIC: /* 32-bits */ fobj->ismach64 = 0; fobj->mhdr.hdr32 = mhdr; fobj->isbigendian = (*fobj->mhdata == (char)(MH_MAGIC >> 24) ? 1 : 0); return mhdr->magic; case MH_CIGAM_64: fobj->swapped = 1; /* fall through */ case MH_MAGIC_64: /* 64-bits */ fobj->ismach64 = 1; fobj->mhdr.hdr64 = addr; fobj->isbigendian = (*fobj->mhdata == (char)(MH_MAGIC_64 >> 24) ? 1 : 0); return mhdr->magic; default: return 0; /* unrecognised file */ } } /* Read a macho into memory, returning a fatobj struct with at least one * arch. */ fatobj *readmacho(const char *filename) { int fd; fatobj *ret; if ((fd = open(filename, O_RDONLY)) == -1) return NULL; ret = readmacho_fd(filename, fd, 0); if (ret == NULL) close(fd); return ret; } fatobj *readmacho_fd(const char *filename, int fd, size_t len) { char *data; fatobj *ret; if (len == 0) { struct stat st; if (fstat(fd, &st) == -1) return NULL; len = st.st_size; if (len == 0) return NULL; } data = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); if (data == MAP_FAILED) { warn("mmap on '%s' of %zu bytes failed :(", filename, len); return NULL; } ret = readmacho_buffer(filename, data, len); if (ret != NULL) { ret->fd = fd; return ret; } munmap(data, len); return NULL; } fatobj *readmacho_buffer(const char *filename, char *buffer, size_t buffer_len) { struct fat_header *fhdr; fatobj *ret = xmalloc(sizeof(*ret)); ret->fd = -1; ret->filename = filename; ret->base_filename = strrchr(ret->filename, '/'); ret->base_filename = (ret->base_filename == NULL ? ret->filename : ret->base_filename + 1); ret->len = buffer_len; ret->data = buffer; ret->swapped = 0; /* make sure we have enough bytes to scan */ if (ret->len <= sizeof(struct fat_header)) goto fail; fhdr = ret->data; /* Check what kind of file this is. Unfortunately we don't have * configure, so we don't know if we're on big or little endian, so * we cannot check if the fat_header is in bigendian like it should. */ if (fhdr->magic == FAT_MAGIC || fhdr->magic == FAT_CIGAM) { /* we're indeed in a FAT file */ uint32_t i; fatobj *fobj = ret; struct fat_arch *farch; void *dptr = ret->data + sizeof(struct fat_header); uint32_t bufleft = ret->len - sizeof(struct fat_header); char swapped = 0; uint32_t narchs = fhdr->nfat_arch; uint32_t offset; /* FAT headers are always big-endian, so swap if on little * machines... */ if (fhdr->magic == FAT_CIGAM) { swapped = 1; narchs = bswap_32(narchs); } /* can we read the headers at all? * beware of corrupt files and Java bytecode which shares * the same magic with us :( */ if (sizeof(struct fat_arch) * narchs > bufleft) goto fail; for (i = 1; i <= narchs; i++) { farch = (struct fat_arch *)dptr; offset = MGET(swapped, farch->offset); if (offset + sizeof(struct mach_header) >= bufleft || read_mach_header(fobj, ret->data + offset) == 0) goto fail; if (i < narchs) { fobj = fobj->next = xzalloc(sizeof(*fobj)); /* filename and size are necessary for printing */ fobj->filename = ret->filename; fobj->base_filename = ret->base_filename; fobj->len = ret->len; } else { fobj->next = NULL; } dptr += sizeof(struct fat_arch); bufleft -= sizeof(struct fat_arch); } } else { /* simple Mach-O file, treat as single arch FAT file */ if (ret->len < sizeof(struct mach_header) || read_mach_header(ret, ret->data) == 0) goto fail; ret->next = NULL; } return ret; fail: free(ret); return NULL; } /* undo the readmacho() stuff */ void unreadmacho(fatobj *macho) { if (macho->data != NULL) { munmap(macho->data, macho->len); close(macho->fd); } /* free all arches recursively */ if (macho->next != NULL) unreadmacho(macho->next); free(macho); } /* Returns the first load_command in the file (after the mach_header) * and allocates a loadcmd struct to store it together with some * convenience data. The struct can be manually freed, if not traversed * until the end of the load section. */ loadcmd *firstloadcmd(fatobj *fobj) { loadcmd *ret = xmalloc(sizeof(*ret)); ret->data = fobj->mhdata + (fobj->ismach64 ? sizeof(struct mach_header_64) : sizeof(struct mach_header)); ret->lcmd = ret->data; ret->cleft = MOBJGET(fobj, mhdr.hdr32->ncmds); /* 32 and 64 bits are aligned here */ ret->align = (fobj->ismach64 ? 8 : 4); ret->swapped = fobj->swapped; /* a bit useless, but a nice consistency check for ourselves now */ if (ret->lcmd->cmdsize % ret->align != 0) warn("cmdsize isn't properly aligned on %d bytes boundary (%d)", ret->align, ret->lcmd->cmdsize); return ret; } /* Sets up the given loadcmd struct with the next load command, or frees * it if there are no more load commands. If a new load command was * loaded, 1 is returned, 0 otherwise. This behaviour is useful when * looping over all load commands, since firstloadcmd will allocate the * loadcmd struct, and nextloadcmd will free it once all load commands * have been seen. */ int nextloadcmd(loadcmd *lcmd) { uint32_t size = MOBJGET(lcmd, lcmd->cmdsize); if (--(lcmd->cleft) == 0) { free(lcmd); return 0; } if (size % lcmd->align != 0) { /* fix alignment, this should actually never happen, but the doc * says we have to pad if the alignment sucks */ size += lcmd->align - (size % lcmd->align); } lcmd->data += size; lcmd->lcmd = lcmd->data; return 1; } const char *get_machoendian(fatobj *fobj) { return fobj->isbigendian ? STR_BE : STR_LE; } const char *get_machomtype(fatobj *fobj) { switch (MOBJGET(fobj, mhdr.hdr32->cputype)) { case CPU_TYPE_POWERPC: return STR_PPC; case CPU_TYPE_I386: return STR_I386; case CPU_TYPE_ARM: return STR_ARM; case CPU_TYPE_POWERPC64: return STR_PPC64; case CPU_TYPE_X86_64: return STR_X86_64; default: return STR_UNKNOWN; } } pax-utils-1.2.5/paxmacho.h000066400000000000000000000044551362221774600154400ustar00rootroot00000000000000/* * Copyright 2005-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - * 2008-2012 Fabian Groffen - * * Make sure all of the common mach-o stuff is setup as we expect */ #ifndef _PAX_MACHO_H #define _PAX_MACHO_H #include "macho.h" #define MGET(swapped, value) (swapped ? (__typeof__(value))bswap_32(value) : value) #define MOBJGET(obj, member) MGET((obj)->swapped, (obj)->member) typedef struct _fatobj { void *data; /* mmapped image of the whole file */ size_t len; /* length of data (file length) */ int fd; /* open filedescriptor to the file */ const char *filename; /* full filename */ const char *base_filename; /* basename of filename (don't free) */ char swapped; /* whether values need to be swapped */ char ismach64; /* whether mach_header_64 is in use */ char isbigendian; /* whether the byte order is big-endian */ union { struct mach_header *hdr32; /* pointer to arch Mach-O header */ struct mach_header_64 *hdr64; /* 64-bits variant */ } mhdr; char *mhdata; /* pointer to the image of the mach_header */ struct _fatobj *next; /* pointer to the next arch */ } fatobj; typedef struct { void *data; /* pointer to the current command header */ struct load_command* lcmd; /* the load command */ uint32_t cleft; /* load commands left */ uint32_t align; /* alignment size in bytes */ char swapped; /* whether values need to be swapped */ } loadcmd; const char *get_machomhtype(fatobj *fobj); void get_machomhflags(fatobj *fobj, char **ret, size_t *ret_len); const char *get_machocputype(fatobj *fobj); const char *get_machosubcputype(fatobj *fobj); fatobj *readmacho(const char *filename); fatobj *readmacho_fd(const char *filename, int fd, size_t len); fatobj *readmacho_buffer(const char *filename, char *buffer, size_t buffer_len); void unreadmacho(fatobj *macho); loadcmd *firstloadcmd(fatobj *fobj); int nextloadcmd(loadcmd* lcmd); const char *get_machoendian(fatobj *fobj); const char *get_machomtype(fatobj *fobj); #endif /* _PAX_MACHO_H */ pax-utils-1.2.5/porting.h000066400000000000000000000144551362221774600153230ustar00rootroot00000000000000/* * Copyright 2005-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2005-2012 Ned Ludd - * Copyright 2005-2012 Mike Frysinger - * * Make sure all of the common elf stuff is setup as we expect */ #ifndef _PORTING_H #define _PORTING_H #ifdef HAVE_CONFIG_H # include "config.h" #endif #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*arr)) #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "elf.h" #if !defined(__FreeBSD__) && !defined(__OpenBSD__) # include #endif #if defined(__linux__) # include # if !defined(HAVE_CONFIG_H) || defined(HAVE_LINUX_SECUREBITS_H) # include # endif #endif #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__ANDROID__) # include # include #elif defined(__FreeBSD__) # include #elif defined(__sun__) # include #elif defined(__MACH__) # include #endif #if defined(__GLIBC__) || defined(__UCLIBC__) # include #endif #if defined(__GLIBC__) || defined(__UCLIBC__) || defined(__NetBSD__) # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG "/etc/ld.so.conf" #elif defined(__FreeBSD__) || defined(__DragonFly__) # include # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG _PATH_ELF_HINTS #else # define __PAX_UTILS_DEFAULT_LD_CACHE_CONFIG "" #endif #undef PAX_UTILS_CLEANUP /* bounds checking code will fart on free(NULL) even though that * is valid usage. So let's wrap it if need be. */ #ifdef __BOUNDS_CHECKING_ON # define free(ptr) do { if (ptr) free(ptr); } while (0) # define PAX_UTILS_CLEANUP 1 #endif /* LSAN (Leak Sanitizer) will complain about things we leak. */ #ifdef __SANITIZE_ADDRESS__ # define PAX_UTILS_CLEANUP 1 #endif /* Coverity catches some things we leak on purpose. */ #ifdef __COVERITY__ # define PAX_UTILS_CLEANUP 1 #endif #ifndef PAX_UTILS_CLEANUP # define PAX_UTILS_CLEANUP 0 #endif /* Few arches can safely do unaligned accesses */ #if defined(__cris__) || \ defined(__i386__) || \ defined(__powerpc__) || \ defined(__s390__) || \ defined(__x86_64__) # define __PAX_UNALIGNED_OK 1 #else # define __PAX_UNALIGNED_OK 0 #endif #if !defined(bswap_16) # if defined(bswap16) # define bswap_16 bswap16 # define bswap_32 bswap32 # define bswap_64 bswap64 # else # define bswap_16(x) \ ((((x) & 0xff00) >> 8) | \ (((x) & 0x00ff) << 8)) # define bswap_32(x) \ ((((x) & 0xff000000) >> 24) | \ (((x) & 0x00ff0000) >> 8) | \ (((x) & 0x0000ff00) << 8) | \ (((x) & 0x000000ff) << 24)) # if defined(__GNUC__) # define bswap_64(x) \ ((((x) & 0xff00000000000000ull) >> 56) | \ (((x) & 0x00ff000000000000ull) >> 40) | \ (((x) & 0x0000ff0000000000ull) >> 24) | \ (((x) & 0x000000ff00000000ull) >> 8) | \ (((x) & 0x00000000ff000000ull) << 8) | \ (((x) & 0x0000000000ff0000ull) << 24) | \ (((x) & 0x000000000000ff00ull) << 40) | \ (((x) & 0x00000000000000ffull) << 56)) # else # define bswap_64(x) \ ((((x) & 0xff00000000000000) >> 56) | \ (((x) & 0x00ff000000000000) >> 40) | \ (((x) & 0x0000ff0000000000) >> 24) | \ (((x) & 0x000000ff00000000) >> 8) | \ (((x) & 0x00000000ff000000) << 8) | \ (((x) & 0x0000000000ff0000) << 24) | \ (((x) & 0x000000000000ff00) << 40) | \ (((x) & 0x00000000000000ff) << 56)) # endif # endif #endif #define _minmax(x, y, op) \ ({ __typeof__(x) __x = (x); __typeof__(y) __y = (y); (__x op __y ? __x : __y); }) #if !defined(min) # define min(x, y) _minmax(x, y, <) #endif #if !defined(max) # define max(x, y) _minmax(x, y, >) #endif #if !defined(_POSIX_PATH_MAX) && !defined(PATH_MAX) /* __PAX_UTILS_PATH_MAX */ # define __PAX_UTILS_PATH_MAX 8192 #elif _POSIX_PATH_MAX > PATH_MAX /* __PAX_UTILS_PATH_MAX */ # define __PAX_UTILS_PATH_MAX _POSIX_PATH_MAX #else # define __PAX_UTILS_PATH_MAX PATH_MAX #endif /* fall back case for non-Linux hosts ... so lame */ #if !defined(ELF_DATA) # if defined(BYTE_ORDER) # if BYTE_ORDER == LITTLE_ENDIAN # define ELF_DATA ELFDATA2LSB # elif BYTE_ORDER == BIG_ENDIAN # define ELF_DATA ELFDATA2MSB # else # error "BYTE_ORDER: you fail" # endif # elif defined(__BYTE_ORDER) # if __BYTE_ORDER == __LITTLE_ENDIAN # define ELF_DATA ELFDATA2LSB # elif __BYTE_ORDER == __BIG_ENDIAN # define ELF_DATA ELFDATA2BSB # else # error "__BYTE_ORDER: you fail" # endif # elif defined(WORDS_LITTLENDIAN) # define ELF_DATA ELFDATA2LSB # elif defined(WORDS_BIGENDIAN) # define ELF_DATA ELFDATA2MSB # elif defined(_LITTLE_ENDIAN) # define ELF_DATA ELFDATA2LSB # elif defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__) # define ELF_DATA ELFDATA2MSB # else # error "no idea what the native byte order is" # endif #endif /* * propably will never be official added to the toolchain. * But none the less we should try to get 0x65041580 reserved */ #ifndef PT_PAX_FLAGS # define PT_PAX_FLAGS 0x65041580 # define PF_PAGEEXEC (1 << 4) /* Enable PAGEEXEC */ # define PF_NOPAGEEXEC (1 << 5) /* Disable PAGEEXEC */ # define PF_SEGMEXEC (1 << 6) /* Enable SEGMEXEC */ # define PF_NOSEGMEXEC (1 << 7) /* Disable SEGMEXEC */ # define PF_MPROTECT (1 << 8) /* Enable MPROTECT */ # define PF_NOMPROTECT (1 << 9) /* Disable MPROTECT */ # define PF_RANDEXEC (1 << 10) /* Enable RANDEXEC */ # define PF_NORANDEXEC (1 << 11) /* Disable RANDEXEC */ # define PF_EMUTRAMP (1 << 12) /* Enable EMUTRAMP */ # define PF_NOEMUTRAMP (1 << 13) /* Disable EMUTRAMP */ # define PF_RANDMMAP (1 << 14) /* Enable RANDMMAP */ # define PF_NORANDMMAP (1 << 15) /* Disable RANDMMAP */ #endif /* PT_PAX_ */ /* older glibc/uclibc will need this since they typo-ed the define */ #ifndef EM_ST19 # ifdef EM_AT19 # define EM_ST19 EM_AT19 # else # define EM_ST19 74 # endif #endif #ifndef O_CLOEXEC # define O_CLOEXEC 0 #endif #ifndef O_PATH # define O_PATH 0 #endif #define __unused__ __attribute__((__unused__)) #endif /* _PORTING_H */ pax-utils-1.2.5/pspax.c000066400000000000000000000311501362221774600147560ustar00rootroot00000000000000/******************************************************************************/ /* THE BEER-WARE LICENSE (Revision 42): */ /* As long as you retain this notice you can do whatever you want with this */ /* stuff. If we meet some day, and you think this stuff is worth it, */ /* you can buy me a beer in return. Ned Ludd. --solarx */ /******************************************************************************/ /* * normal compile. * cc -o pspax pspax.c * or with libcap. * cc -o pspax pspax.c -DWANT_SYSCAP -lcap */ const char argv0[] = "pspax"; #include "paxinc.h" #include #ifdef WANT_SYSCAP # undef _POSIX_SOURCE # include # define WRAP_SYSCAP(x) x #else # define WRAP_SYSCAP(x) #endif #define PROC_DIR "/proc" /* variables to control behavior */ static char show_all = 0; static char verbose = 0; static char show_banner = 1; static char show_phdr = 0; static char show_addr = 0; static char noexec = 1; static char writeexec = 1; static char wide_output = 0; static pid_t show_pid = 0; static uid_t show_uid = (uid_t)-1; static gid_t show_gid = (gid_t)-1; static int proc_open(int pfd, const char *file) { return openat(pfd, file, O_RDONLY|O_CLOEXEC); } static FILE *proc_fopen(int pfd, const char *file) { int fd; FILE *fp; fd = proc_open(pfd, file); if (fd == -1) return NULL; fp = fdopen(fd, "re"); if (fp == NULL) close(fd); return fp; } static elfobj *proc_readelf(int pfd) { int fd; elfobj *elf; fd = proc_open(pfd, "exe"); if (fd == -1) return NULL; elf = readelf_fd("proc/exe", fd, 0); close(fd); return elf; } static const char *get_proc_name_cmdline(int pfd) { FILE *fp; static char str[1024]; fp = proc_fopen(pfd, "cmdline"); if (fp == NULL) return NULL; if (fscanf(fp, "%s.1023", str) != 1) { fclose(fp); return NULL; } fclose(fp); return (str); } static const char *get_proc_name(int pfd) { FILE *fp; static char str[BUFSIZ]; if (wide_output) return get_proc_name_cmdline(pfd); fp = proc_fopen(pfd, "stat"); if (fp == NULL) return NULL; if (fscanf(fp, "%*d %s.16", str) != 1) { fclose(fp); return NULL; } if (*str) { str[strlen(str) - 1] = '\0'; str[16] = 0; } fclose(fp); return (str+1); } static int get_proc_maps(int pfd) { FILE *fp; static char str[BUFSIZ]; if ((fp = proc_fopen(pfd, "maps")) == NULL) return -1; while (fgets(str, sizeof(str), fp)) { char *p; if ((p = strchr(str, ' ')) != NULL) { if (strlen(p) < 6) continue; /* 0x0-0x0 rwxp fffff000 00:00 0 */ /* 0x0-0x0 R+W+XP fffff000 00:00 0 */ ++p; /* ' ' */ ++p; /* r */ if (*p == '+') ++p; /* FIXME: all of wx, w+, +x, ++ indicate w|x */ if (tolower(*p) == 'w') { ++p; if (*p == '+') ++p; if (tolower(*p) == 'x') { fclose(fp); return 1; } } } } fclose(fp); return 0; } static int print_executable_mappings(int pfd) { FILE *fp; static char str[BUFSIZ]; if ((fp = proc_fopen(pfd, "maps")) == NULL) return -1; while (fgets(str, sizeof(str), fp)) { char *p; if ((p = strchr(str, ' ')) != NULL) { if (strlen(p) < 6) continue; /* 0x0-0x0 rwxp fffff000 00:00 0 */ /* 0x0-0x0 R+W+XP fffff000 00:00 0 */ ++p; /* ' ' */ ++p; /* r */ if (*p == '+') ++p; /* FIXME: all of wx, w+, +x, ++ indicate w|x */ if (tolower(*p) == 'w') { ++p; if (*p == '+') ++p; if (tolower(*p) == 'x') printf(" %s", str); } } } fclose(fp); return 0; } #ifdef __BOUNDS_CHECKING_ON # define NOTE_TO_SELF warn( \ "This is bullshit but getpwuid() is leaking memory and I wasted a few hrs 1 day tracking it down in pspax\n" \ "Later on I forgot I tracked it down before and saw pspax leaking memory so I tracked it down all over again (silly me)\n" \ "Hopefully the getpwuid()/nis/nss/pam or whatever wont suck later on in the future.") #else # define NOTE_TO_SELF #endif static const struct passwd *get_proc_passwd(int pfd) { struct stat st; const struct passwd *pwd = NULL; if (fstatat(pfd, "stat", &st, AT_SYMLINK_NOFOLLOW) != -1) pwd = getpwuid(st.st_uid); return pwd; } static const char *get_proc_status(int pfd, const char *name) { FILE *fp; size_t len; static char str[BUFSIZ]; if ((fp = proc_fopen(pfd, "status")) == NULL) return NULL; len = strlen(name); while (fgets(str, sizeof(str), fp)) { if (strncasecmp(str, name, len) != 0) continue; if (str[len] == ':') { fclose(fp); str[strlen(str) - 1] = 0; return (str + len + 2); } } fclose(fp); return NULL; } static const char *get_pid_attr(int pfd) { FILE *fp; char *p; static char buf[BUFSIZ]; if ((fp = proc_fopen(pfd, "attr/current")) == NULL) return NULL; if (fgets(buf, sizeof(buf), fp) != NULL) if ((p = strchr(buf, '\n')) != NULL) *p = 0; fclose(fp); return buf; } static const char *get_pid_addr(int pfd) { FILE *fp; char *p; static char buf[BUFSIZ]; if ((fp = proc_fopen(pfd, "ipaddr")) == NULL) return NULL; if (fgets(buf, sizeof(buf), fp) != NULL) if ((p = strchr(buf, '\n')) != NULL) *p = 0; fclose(fp); return buf; } static const char *get_proc_type(int pfd) { elfobj *elf; const char *ret; elf = proc_readelf(pfd); if (elf == NULL) return NULL; ret = get_elfetype(elf); unreadelf(elf); return ret; } static const char *scanelf_file_phdr(elfobj *elf) { static char ret[8]; unsigned long i, off, multi_stack, multi_load; memcpy(ret, "--- ---\0", 8); multi_stack = multi_load = 0; if (elf->phdr) { uint32_t flags; #define SHOW_PHDR(B) \ if (elf->elf_class == ELFCLASS ## B) { \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ if (EGET(phdr[i].p_type) == PT_GNU_STACK) { \ if (multi_stack++) warnf("%s: multiple PT_GNU_STACK's !?", elf->filename); \ off = 0; \ } else if (EGET(phdr[i].p_type) == PT_LOAD) { \ off = 4; \ } else \ continue; \ flags = EGET(phdr[i].p_flags); \ memcpy(ret+off, gnu_short_stack_flags(flags), 3); \ } \ } SHOW_PHDR(32) SHOW_PHDR(64) } return ret; } /* we scan the elf file two times when the -e flag is given. But we don't need -e very often so big deal */ static const char *get_proc_phdr(int pfd) { elfobj *elf; const char *ret; elf = proc_readelf(pfd); if (elf == NULL) return NULL; ret = scanelf_file_phdr(elf); unreadelf(elf); return ret; } static void pspax(const char *find_name) { register DIR *dir; register struct dirent *de; pid_t pid; pid_t ppid = show_pid; int have_attr, have_addr, wx; const struct passwd *pwd; const char *pax, *type, *name, *attr, *addr; char *caps; int pfd; WRAP_SYSCAP(ssize_t length; cap_t cap_d;) WRAP_SYSCAP(cap_d = cap_init()); dir = opendir(PROC_DIR); if (dir == NULL || chdir(PROC_DIR)) errp(PROC_DIR); if (access("/proc/self/attr/current", R_OK) != -1) have_attr = 1; else have_attr = 0; if ((access("/proc/self/ipaddr", R_OK) != -1) && show_addr) have_addr = 1; else have_addr = 0; if (show_banner) printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s %s\n", "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", have_attr ? "ATTR" : "", have_addr ? "IPADDR" : "", show_phdr ? "STACK LOAD" : ""); while ((de = readdir(dir))) { /* Check the name first if it's an int as it's faster. */ pid = atoi(de->d_name); if (pid == 0) continue; /* Get an open handle so the kernel won't reap on us later. */ pfd = open(de->d_name, O_RDONLY|O_CLOEXEC|O_PATH|O_DIRECTORY); if (pfd == -1) continue; if (find_name && pid) { const char *str = get_proc_name(pfd); if (!str) goto next_pid; if (strcmp(str, find_name) != 0) pid = 0; } if (ppid > 0 && pid != ppid) goto next_pid; wx = get_proc_maps(pfd); if (noexec != writeexec) { if (wx == 1 && writeexec != wx) goto next_pid; if (wx == 0 && writeexec) goto next_pid; } pwd = get_proc_passwd(pfd); pax = get_proc_status(pfd, "PAX"); type = get_proc_type(pfd); name = get_proc_name(pfd); attr = (have_attr ? get_pid_attr(pfd) : NULL); addr = (have_addr ? get_pid_addr(pfd) : NULL); if (pwd) { if (show_uid != (uid_t)-1) if (pwd->pw_uid != show_uid) goto next_pid; if (show_gid != (gid_t)-1) if (pwd->pw_gid != show_gid) goto next_pid; } /* this is a non-POSIX function */ caps = NULL; WRAP_SYSCAP(capgetp(pfd, cap_d)); WRAP_SYSCAP(caps = cap_to_text(cap_d, &length)); if (pwd && strlen(pwd->pw_name) >= 8) pwd->pw_name[8] = 0; if (show_all || type) { printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n", pwd ? pwd->pw_name : "--------", pid, pax ? pax : "---", (wx == 1) ? "w|x" : (wx == -1) ? "---" : "w^x", type ? type : "-------", name ? name : "-----", caps ? caps : " = ", attr ? attr : "", addr ? addr : "", show_phdr ? get_proc_phdr(pfd) : ""); if (verbose && wx) print_executable_mappings(pfd); } WRAP_SYSCAP(if (caps) cap_free(caps)); next_pid: close(pfd); } closedir(dir); } /* usage / invocation handling functions */ #define PARSE_FLAGS "aeip:u:g:nwWvCBhV" #define a_argument required_argument static struct option const long_opts[] = { {"all", no_argument, NULL, 'a'}, {"header", no_argument, NULL, 'e'}, {"ipaddr", no_argument, NULL, 'i'}, {"pid", a_argument, NULL, 'p'}, {"user", a_argument, NULL, 'u'}, {"group", a_argument, NULL, 'g'}, {"nx", no_argument, NULL, 'n'}, {"wx", no_argument, NULL, 'w'}, {"wide", no_argument, NULL, 'W'}, {"verbose", no_argument, NULL, 'v'}, {"nocolor", no_argument, NULL, 'C'}, {"nobanner", no_argument, NULL, 'B'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, no_argument, NULL, 0x0} }; static const char * const opts_help[] = { "Show all processes", "Print GNU_STACK/PT_LOAD markings", "Print ipaddr info if supported", "Process ID/pid #", "Process user/uid #", "Process group/gid #", "Only display w^x processes", "Only display w|x processes", "Wide output display of cmdline", "Be verbose about executable mappings", "Don't emit color in output", "Don't display the header", "Print this help and exit", "Print version and exit", NULL }; /* display usage and exit */ static void usage(int status) { int i; printf("* List ELF/PaX information about running processes\n\n" "Usage: %s [options]\n\n", argv0); fputs("Options:\n", stdout); for (i = 0; long_opts[i].name; ++i) printf(" -%c, --%-12s* %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); #ifdef MANLYPAGE for (i = 0; long_opts[i].name; ++i) printf(".TP\n\\fB\\-%c, \\-\\-%s\\fR\n%s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); #endif exit(status); } /* parse command line arguments and preform needed actions */ static void parseargs(int argc, char *argv[]) { int flag; const struct passwd *pwd = NULL; const struct group *gwd = NULL; opterr = 0; while ((flag=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) { switch (flag) { case 'V': /* version info */ printf("pax-utils-%s: %s\n" "%s written for Gentoo by \n", VERSION, VCSID, argv0); exit(EXIT_SUCCESS); break; case 'h': usage(EXIT_SUCCESS); break; case 'C': color_init(true); break; case 'B': show_banner = 0; break; case 'a': show_all = 1; break; case 'e': show_phdr = 1; break; case 'i': show_addr = 1; break; case 'p': show_pid = atoi(optarg); break; case 'n': noexec = 1; writeexec = 0; break; case 'w': noexec = 0; writeexec = 1; break; case 'W': wide_output = 1; break; case 'v': verbose++; break; case 'u': show_uid = atoi(optarg); if (show_uid == 0 && (strcmp(optarg, "0") != 0)) { pwd = getpwnam(optarg); if (pwd) show_uid = pwd->pw_uid; else err("unknown uid"); } break; case 'g': show_gid = atoi(optarg); if (show_gid == 0 && (strcmp(optarg, "0") != 0)) { gwd = getgrnam(optarg); if (gwd) show_gid = gwd->gr_gid; else err("unknown gid"); } break; case ':': case '?': warn("Unknown option or missing parameter"); usage(EXIT_FAILURE); break; default: err("Unhandled option '%c'", flag); break; } } } int main(int argc, char *argv[]) { const char *name = NULL; /* We unshare pidns but don't actually enter it. That means * we still get to scan /proc, but just not fork children. */ security_init(false); color_init(false); parseargs(argc, argv); if ((optind < argc) && (show_pid == 0)) name = argv[optind]; pspax(name); NOTE_TO_SELF; return EXIT_SUCCESS; } pax-utils-1.2.5/pylint000077500000000000000000000023141362221774600147240ustar00rootroot00000000000000#!/usr/bin/python # -*- coding: utf-8 -*- # Copyright 1999-2017 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 """Run pylint with the right settings.""" from __future__ import print_function import os import sys def find_all_modules(source_root): """Locate all python modules in the tree for scanning""" ret = [] for root, _dirs, files in os.walk(source_root, topdown=False): # Add all of the .py modules in the tree. ret += [os.path.join(root, x) for x in files if x.endswith('.py')] # Add the main scripts that don't end in .py. ret += [os.path.join(source_root, x) for x in ('pylint',)] return ret def main(argv): """The main entry point""" source_root = os.path.dirname(os.path.realpath(__file__)) if not argv: argv = find_all_modules(source_root) pympath = source_root pythonpath = os.environ.get('PYTHONPATH') if pythonpath is None: pythonpath = pympath else: pythonpath = pympath + ':' + pythonpath os.environ['PYTHONPATH'] = pythonpath pylintrc = os.path.join(source_root, '.pylintrc') cmd = ['pylint', '--rcfile', pylintrc] os.execvp(cmd[0], cmd + argv) if __name__ == '__main__': sys.exit(main(sys.argv[1:])) pax-utils-1.2.5/scanelf.c000066400000000000000000002106101362221774600152360ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2012 Mike Frysinger - */ const char argv0[] = "scanelf"; #include "paxinc.h" #define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') /* prototypes */ static int file_matches_list(const char *filename, char **matchlist); /* variables to control behavior */ static array_t _match_etypes = array_init_decl, *match_etypes = &_match_etypes; static char scan_ldpath = 0; static char scan_envpath = 0; static char scan_symlink = 1; static char scan_archives = 0; static char dir_recurse = 0; static char dir_crossmount = 1; static char show_pax = 0; static char show_perms = 0; static char show_size = 0; static char show_phdr = 0; static char show_textrel = 0; static char show_rpath = 0; static char show_needed = 0; static char show_interp = 0; static char show_bind = 0; static char show_soname = 0; static char show_textrels = 0; static char show_banner = 1; static char show_endian = 0; static char show_osabi = 0; static char show_eabi = 0; static char be_quiet = 0; static char be_verbose = 0; static char be_wewy_wewy_quiet = 0; static char be_semi_verbose = 0; static char *find_sym = NULL; static array_t _find_sym_arr = array_init_decl, *find_sym_arr = &_find_sym_arr; static array_t _find_sym_regex_arr = array_init_decl, *find_sym_regex_arr = &_find_sym_regex_arr; static char *find_lib = NULL; static array_t _find_lib_arr = array_init_decl, *find_lib_arr = &_find_lib_arr; static char *find_section = NULL; static array_t _find_section_arr = array_init_decl, *find_section_arr = &_find_section_arr; static char *out_format = NULL; static char *search_path = NULL; static char fix_elf = 0; static char g_match = 0; static char use_ldcache = 0; static char use_ldpath = 0; static char **qa_textrels = NULL; static char **qa_execstack = NULL; static char **qa_wx_load = NULL; static int match_bits = 0; static unsigned int match_perms = 0; static unsigned long setpax = 0UL; static const char *objdump; /* Boiler plate wrapper for expanding ELF macros for specific ELF sizes. */ #define _SCANELF_IF_ELF_SIZE(B, x) \ do { \ if (elf->elf_class == ELFCLASS ## B) { \ x(B); \ } \ } while (0) #define SCANELF_ELF_SIZED(x) \ do { \ _SCANELF_IF_ELF_SIZE(32, x); \ _SCANELF_IF_ELF_SIZE(64, x); \ } while (0) /* Find the path to a file by name. Note: we do not currently handle the * empty path element correctly (should behave by searching $PWD). */ static const char *which(const char *fname, const char *envvar) { size_t path_len, fname_len; const char *env_path; char *path, *p, *ep; p = getenv(envvar); if (p) return p; env_path = getenv("PATH"); if (!env_path) return NULL; /* Create a copy of the $PATH that we can safely modify. * Make it a little bigger so we can append "/fname". * We do this twice -- once for a perm copy, and once for * room at the end of the last element. */ path_len = strlen(env_path); fname_len = strlen(fname); path = xmalloc(path_len + (fname_len * 2) + 2 + 2); memcpy(path, env_path, path_len + 1); p = path + path_len + 1 + fname_len + 1; *p = '/'; memcpy(p + 1, fname, fname_len + 1); /* Repoint fname to the copy in the env string as it has * the leading slash which we can include in a single memcpy. * Increase the fname len to include the '/' and '\0'. */ fname = p; fname_len += 2; p = path; while (p) { ep = strchr(p, ':'); /* Append the /foo path to the current element. */ if (ep) memcpy(ep, fname, fname_len); else memcpy(path + path_len, fname, fname_len); if (access(p, R_OK) != -1) return p; p = ep; if (ep) { /* If not the last element, restore the chunk we clobbered. */ size_t offset = ep - path; size_t restore = min(path_len - offset, fname_len); memcpy(ep, env_path + offset, restore); ++p; } } free(path); return NULL; } /* * Return the index into the program header table for the |p_type| segment. * Useful only when there is one instance of a particular type. */ static ssize_t scanelf_file_find_phdr(elfobj *elf, uint32_t p_type) { ssize_t ret = -1; #define FIND_PT_TYPE(B) \ size_t i; \ const Elf##B##_Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf##B##_Phdr *phdr = PHDR ## B (elf->phdr); \ \ for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ if (EGET(phdr[i].p_type) != p_type) \ continue; \ \ if (ret == -1) \ ret = i; \ else \ warnf("ELF has more than one %s segment !?", get_elfptype(p_type)); \ } if (elf->phdr) SCANELF_ELF_SIZED(FIND_PT_TYPE); return ret; } static const void *scanelf_file_get_pt_dynamic(elfobj *elf) { ssize_t i = scanelf_file_find_phdr(elf, PT_DYNAMIC); if (i == -1) return NULL; #define CHECK_PT_DYNAMIC(B) \ const Elf##B##_Phdr *phdr = &PHDR##B(elf->phdr)[i]; \ Elf##B##_Off offset; \ \ if (EGET(phdr->p_filesz) == 0) \ break; \ offset = EGET(phdr->p_offset); \ if (!VALID_RANGE(elf, offset, sizeof(Elf##B##_Dyn))) \ break; \ return phdr; SCANELF_ELF_SIZED(CHECK_PT_DYNAMIC); return NULL; } #define scanelf_dt_for_each(B, elf, dyn) \ { \ const Elf##B##_Phdr *_phdr = scanelf_file_get_pt_dynamic(elf); \ dyn = (_phdr == NULL) ? elf->data_end : DYN##B(elf->vdata + EGET(_phdr->p_offset)); \ } \ --dyn; \ while ((void *)++dyn < elf->data_end - sizeof(*dyn) && EGET(dyn->d_tag) != DT_NULL) /* sub-funcs for scanelf_fileat() */ static void scanelf_file_get_symtabs(elfobj *elf, const void **sym, const void **str) { /* find the best SHT_DYNSYM and SHT_STRTAB sections */ /* debug sections */ const void *symtab = elf_findsecbyname(elf, ".symtab"); const void *strtab = elf_findsecbyname(elf, ".strtab"); /* runtime sections */ const void *dynsym = elf_findsecbyname(elf, ".dynsym"); const void *dynstr = elf_findsecbyname(elf, ".dynstr"); /* * If the sections are marked NOBITS, then they don't exist, so we just * skip them. This let's us work sanely with splitdebug ELFs (rather * than spewing a lot of "corrupt ELF" messages later on). In malformed * ELFs, the section might be wrongly set to NOBITS, but screw em. * * We need to make sure the debug/runtime sym/str sets are used together * as they are generated in sync. Trying to mix them won't work. */ #define GET_SYMTABS(B) \ const Elf ## B ## _Shdr *esymtab = symtab; \ const Elf ## B ## _Shdr *estrtab = strtab; \ const Elf ## B ## _Shdr *edynsym = dynsym; \ const Elf ## B ## _Shdr *edynstr = dynstr; \ \ if (!VALID_SHDR(elf, esymtab)) \ symtab = NULL; \ if (!VALID_SHDR(elf, edynsym)) \ dynsym = NULL; \ if (!VALID_SHDR(elf, estrtab)) \ strtab = NULL; \ if (!VALID_SHDR(elf, edynstr)) \ dynstr = NULL; \ \ /* Use the set with more symbols if both exist. */ \ if (symtab && dynsym && strtab && dynstr) { \ if (EGET(esymtab->sh_size) > EGET(edynsym->sh_size)) \ goto debug##B; \ else \ goto runtime##B; \ } else if (symtab && strtab) { \ debug##B: \ *sym = symtab; \ *str = strtab; \ return; \ } else if (dynsym && dynstr) { \ runtime##B: \ *sym = dynsym; \ *str = dynstr; \ return; \ } else { \ *sym = *str = NULL; \ } SCANELF_ELF_SIZED(GET_SYMTABS); if (*sym && *str) return; /* * damn, they're really going to make us work for it huh? * reconstruct the section header info out of the dynamic * tags so we can see what symbols this guy uses at runtime. */ #define GET_SYMTABS_DT(B) \ size_t i; \ static Elf ## B ## _Shdr sym_shdr, str_shdr; \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ Elf ## B ## _Addr vsym, vstr, vhash, vgnu_hash; \ const Elf ## B ## _Dyn *dyn; \ \ /* lookup symbols used at runtime with DT_SYMTAB / DT_STRTAB */ \ vsym = vstr = vhash = vgnu_hash = 0; \ memset(&sym_shdr, 0, sizeof(sym_shdr)); \ memset(&str_shdr, 0, sizeof(str_shdr)); \ \ /* Find the dynamic headers */ \ scanelf_dt_for_each(B, elf, dyn) { \ switch (EGET(dyn->d_tag)) { \ case DT_SYMTAB: vsym = EGET(dyn->d_un.d_val); break; \ case DT_SYMENT: sym_shdr.sh_entsize = dyn->d_un.d_val; break; \ case DT_STRTAB: vstr = EGET(dyn->d_un.d_val); break; \ case DT_STRSZ: str_shdr.sh_size = dyn->d_un.d_val; break; \ case DT_HASH: vhash = EGET(dyn->d_un.d_val); break; \ /*case DT_GNU_HASH: vgnu_hash = EGET(dyn->d_un.d_val); break;*/ \ } \ } \ if (!vsym || !vstr || !(vhash || vgnu_hash)) \ return; \ \ /* calc offset into the ELF by finding the load addr of the syms */ \ for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ Elf ## B ## _Addr vaddr = EGET(phdr[i].p_vaddr); \ Elf ## B ## _Addr filesz = EGET(phdr[i].p_filesz); \ Elf ## B ## _Off offset = EGET(phdr[i].p_offset); \ Elf ## B ## _Off hash_offset = offset + (vhash - vaddr); \ \ if (EGET(phdr[i].p_type) != PT_LOAD) \ continue; \ \ if (!VALID_RANGE(elf, offset, filesz)) \ goto corrupt_hash; \ if (!VALID_RANGE(elf, hash_offset, sizeof(Elf32_Word) * 4)) \ goto corrupt_hash; \ \ if (vhash >= vaddr && vhash < vaddr + filesz) { \ /* Scan the hash table to see how many entries we have */ \ Elf32_Word max_sym_idx = 0; \ const Elf32_Word *hashtbl = elf->vdata + hash_offset; \ Elf32_Word b, nbuckets = EGET(hashtbl[0]); \ Elf32_Word nchains = EGET(hashtbl[1]); \ const Elf32_Word *buckets = &hashtbl[2]; \ const Elf32_Word *chains = &buckets[nbuckets]; \ Elf32_Word sym_idx; \ Elf32_Word chained; \ \ if (!VALID_RANGE(elf, offset, nbuckets * 4)) \ goto corrupt_hash; \ if (!VALID_RANGE(elf, offset, nchains * 4)) \ goto corrupt_hash; \ \ for (b = 0; b < nbuckets; ++b) { \ if (!buckets[b]) \ continue; \ for (sym_idx = buckets[b], chained = 0; \ (sym_idx < nchains && sym_idx && chained <= nchains && \ (void *)&chains[sym_idx] + sizeof(*chains) < elf->data_end); \ sym_idx = chains[sym_idx], ++chained) { \ if (max_sym_idx < sym_idx) \ max_sym_idx = sym_idx; \ } \ if (chained > nchains) \ goto corrupt_hash; \ } \ ESET(sym_shdr.sh_size, sym_shdr.sh_entsize * max_sym_idx); \ } \ \ if (vsym >= vaddr && vsym < vaddr + filesz) { \ const Elf##B##_Shdr *shdr = &sym_shdr; \ ESET(sym_shdr.sh_offset, offset + (vsym - vaddr)); \ if (VALID_SHDR(elf, shdr)) \ *sym = shdr; \ } \ \ if (vstr >= vaddr && vstr < vaddr + filesz) { \ const Elf##B##_Shdr *shdr = &str_shdr; \ ESET(str_shdr.sh_offset, offset + (vstr - vaddr)); \ if (VALID_SHDR(elf, shdr)) \ *str = shdr; \ } \ } if (elf->phdr) SCANELF_ELF_SIZED(GET_SYMTABS_DT); return; corrupt_hash: warn("%s: ELF hash table is corrupt", elf->filename); } static const char *scanelf_file_pax(elfobj *elf, char *found_pax) { static char ret[7]; unsigned long i, shown; if (!show_pax) return NULL; shown = 0; memset(&ret, 0, sizeof(ret)); #define SHOW_PAX(B) \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ for (i = 0; i < EGET(ehdr->e_phnum); i++) { \ if (EGET(phdr[i].p_type) != PT_PAX_FLAGS) \ continue; \ if (fix_elf && setpax) { \ /* set the paxctl flags */ \ Elf ## B ## _Phdr *wphdr = (void *)&phdr[i]; \ ESET(wphdr->p_flags, setpax); \ } \ if (be_quiet && (EGET(phdr[i].p_flags) == (PF_NOEMUTRAMP | PF_NORANDEXEC))) \ continue; \ memcpy(ret, pax_short_pf_flags(EGET(phdr[i].p_flags)), 6); \ *found_pax = 1; \ ++shown; \ break; \ } if (elf->phdr) SCANELF_ELF_SIZED(SHOW_PAX); /* Note: We do not support setting EI_PAX if not PT_PAX_FLAGS * was found. This is known to break ELFs on glibc systems, * and mainline PaX has deprecated use of this for a long time. * We could support changing PT_GNU_STACK, but that doesn't * seem like it's worth the effort. #411919 */ /* fall back to EI_PAX if no PT_PAX was found */ if (!*ret) { const char *paxflags = pax_short_hf_flags(EI_PAX_FLAGS(elf)); if (!be_quiet || (be_quiet && EI_PAX_FLAGS(elf))) { *found_pax = 1; return (be_wewy_wewy_quiet ? NULL : paxflags); } strcpy(ret, paxflags); } if (be_wewy_wewy_quiet || (be_quiet && !shown)) return NULL; else return ret; } static const char *scanelf_file_phdr(elfobj *elf, char *found_phdr, char *found_relro, char *found_load) { static char ret[12]; char *found; unsigned long i, shown, multi_stack, multi_relro, multi_load; if (!show_phdr) return NULL; memcpy(ret, "--- --- ---\0", 12); shown = 0; multi_stack = multi_relro = multi_load = 0; #define NOTE_GNU_STACK ".note.GNU-stack" #define SHOW_PHDR(B) \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ Elf ## B ## _Off offset; \ uint32_t flags, check_flags; \ if (elf->phdr != NULL) { \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ if (EGET(phdr[i].p_type) == PT_GNU_STACK) { \ if (multi_stack++) \ warnf("%s: multiple PT_GNU_STACK's !?", elf->filename); \ if (file_matches_list(elf->filename, qa_execstack)) \ continue; \ found = found_phdr; \ offset = 0; \ check_flags = PF_X; \ } else if (EGET(phdr[i].p_type) == PT_GNU_RELRO) { \ if (multi_relro++) \ warnf("%s: multiple PT_GNU_RELRO's !?", elf->filename); \ found = found_relro; \ offset = 4; \ check_flags = PF_X; \ } else if (EGET(phdr[i].p_type) == PT_LOAD) { \ if (file_matches_list(elf->filename, qa_wx_load)) \ continue; \ found = found_load; \ offset = 8; \ check_flags = PF_W|PF_X; \ } else \ continue; \ flags = EGET(phdr[i].p_flags); \ if (be_quiet && ((flags & check_flags) != check_flags)) \ continue; \ if ((EGET(phdr[i].p_type) != PT_LOAD) && (fix_elf && ((flags & PF_X) != flags))) { \ Elf ## B ## _Phdr *wphdr = (void *)&phdr[i]; \ ESET(wphdr->p_flags, flags & (PF_X ^ (size_t)-1)); \ ret[3] = ret[7] = '!'; \ flags = EGET(phdr[i].p_flags); \ } \ memcpy(ret+offset, gnu_short_stack_flags(flags), 3); \ *found = 1; \ ++shown; \ } \ } else if (elf->shdr != NULL) { \ /* no program headers which means this is prob an object file */ \ const Elf ## B ## _Shdr *shdr = SHDR ## B (elf->shdr); \ uint16_t shstrndx = EGET(ehdr->e_shstrndx); \ const Elf ## B ## _Shdr *strtbl = shdr + shstrndx; \ uint16_t shnum = EGET(ehdr->e_shnum); \ if (shstrndx >= shnum || !VALID_SHDR(elf, strtbl)) \ goto corrupt_shdr; \ /* let's flag -w/+x object files since the final ELF will most likely \ * need write access to the stack (who doesn't !?). so the combined \ * output will bring in +w automatically and that's bad. \ */ \ check_flags = /*SHF_WRITE|*/SHF_EXECINSTR; \ for (i = 0; i < shnum; ++i) { \ if (EGET(shdr[i].sh_type) != SHT_PROGBITS) continue; \ offset = EGET(strtbl->sh_offset) + EGET(shdr[i].sh_name); \ if (!VALID_RANGE(elf, offset, sizeof(NOTE_GNU_STACK))) \ continue; \ if (!strcmp(elf->data + offset, NOTE_GNU_STACK)) { \ if (multi_stack++) warnf("%s: multiple .note.GNU-stack's !?", elf->filename); \ if (file_matches_list(elf->filename, qa_execstack)) \ continue; \ flags = EGET(shdr[i].sh_flags); \ if (be_quiet && ((flags & check_flags) != check_flags)) \ continue; \ ++*found_phdr; \ shown = 1; \ if (flags & SHF_WRITE) ret[0] = 'W'; \ if (flags & SHF_ALLOC) ret[1] = 'A'; \ if (flags & SHF_EXECINSTR) ret[2] = 'X'; \ if (flags & 0xFFFFFFF8) warn("Invalid section flags for GNU-stack"); \ break; \ } \ } \ if (!multi_stack) { \ if (file_matches_list(elf->filename, qa_execstack)) \ return NULL; \ *found_phdr = 1; \ shown = 1; \ memcpy(ret, "!WX", 3); \ } \ } SCANELF_ELF_SIZED(SHOW_PHDR); if (be_wewy_wewy_quiet || (be_quiet && !shown)) return NULL; else return ret; corrupt_shdr: warnf("%s: section table is corrupt", elf->filename); return NULL; } /* * See if this ELF contains a DT_TEXTREL tag in any of its * PT_DYNAMIC sections. */ static const char *scanelf_file_textrel(elfobj *elf, char *found_textrel) { static const char *ret = "TEXTREL"; if (!show_textrel && !show_textrels) return NULL; if (file_matches_list(elf->filename, qa_textrels)) return NULL; #define SHOW_TEXTREL(B) \ const Elf ## B ## _Dyn *dyn; \ \ scanelf_dt_for_each(B, elf, dyn) { \ if (EGET(dyn->d_tag) == DT_TEXTREL) { /*dyn->d_tag != DT_FLAGS)*/ \ *found_textrel = 1; \ /*if (dyn->d_un.d_val & DF_TEXTREL)*/ \ return (be_wewy_wewy_quiet ? NULL : ret); \ } \ } if (elf->phdr) SCANELF_ELF_SIZED(SHOW_TEXTREL); if (be_quiet || be_wewy_wewy_quiet) return NULL; else return " - "; } /* * Scan the .text section to see if there are any relocations in it. * Should rewrite this to check PT_LOAD sections that are marked * Executable rather than the section named '.text'. */ static const char *scanelf_file_textrels(elfobj *elf, char *found_textrels, char *found_textrel) { unsigned long r, rmax; const void *symtab_void, *strtab_void; if (!show_textrels) return NULL; /* don't search for TEXTREL's if the ELF doesn't have any */ if (!*found_textrel) scanelf_file_textrel(elf, found_textrel); if (!*found_textrel) return NULL; scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); #define SHOW_TEXTRELS(B) \ size_t i; \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr; \ const Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \ const Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ const Elf ## B ## _Rel *rel; \ const Elf ## B ## _Rela *rela; \ const Elf ## B ## _Dyn *dyn, *drel, *drelsz, *drelent, *dpltrel; \ uint32_t pltrel; \ Elf ## B ## _Addr load_address = 0; \ Elf ## B ## _Addr file_offset; \ \ /* Walk all the dynamic tags to find relocation info */ \ drel = drelsz = drelent = dpltrel = NULL; \ scanelf_dt_for_each(B, elf, dyn) { \ switch (EGET(dyn->d_tag)) { \ case DT_REL: \ case DT_RELA: \ drel = dyn; \ break; \ case DT_RELSZ: \ case DT_RELASZ: \ drelsz = dyn; \ break; \ case DT_RELENT: \ case DT_RELAENT: \ drelent = dyn; \ break; \ case DT_PLTREL: \ dpltrel = dyn; \ break; \ } \ } \ if (!drel || !drelsz || !drelent || !dpltrel) { \ warnf("ELF is missing relocation information"); \ break; \ } \ phdr = PHDR ## B(elf->phdr); \ /* Lookup load base: byte 0 is mapped at load_address */ \ for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ /* Only care about loadable segments. */ \ if (EGET(phdr[i].p_type) != PT_LOAD) \ continue; \ /* We search for the first program header to map into memory */ \ if (EGET(phdr[i].p_offset) != 0) \ continue; \ load_address = EGET(phdr[i].p_vaddr); \ } \ switch (EGET(dpltrel->d_un.d_val)) { \ case DT_REL: \ file_offset = EGET(drel->d_un.d_val) - load_address; \ if (!VALID_RANGE(elf, file_offset, sizeof (drel->d_un.d_val))) { \ rel = NULL; \ rela = NULL; \ warn("%s: DT_REL is out of file range", elf->filename); \ break; \ } \ rel = REL##B(elf->vdata + file_offset); \ rela = NULL; \ pltrel = DT_REL; \ break; \ case DT_RELA: \ file_offset = EGET(drel->d_un.d_val) - load_address; \ if (!VALID_RANGE(elf, file_offset, sizeof (drel->d_un.d_val))) { \ rel = NULL; \ rela = NULL; \ warn("%s: DT_RELA is out of file range", elf->filename); \ break; \ } \ rel = NULL; \ rela = RELA##B(elf->vdata + file_offset); \ pltrel = DT_RELA; \ break; \ default: \ warn("Unknown relocation type"); \ rel = NULL; \ rela = NULL; \ break; \ } \ if (!rel && !rela) \ break; \ rmax = EGET(drelsz->d_un.d_val) / EGET(drelent->d_un.d_val); \ \ /* search the program segments for relocations */ \ for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ Elf ## B ## _Addr vaddr = EGET(phdr[i].p_vaddr); \ uint ## B ## _t memsz = EGET(phdr[i].p_memsz); \ \ /* Only care about loadable segments. */ \ if (EGET(phdr[i].p_type) != PT_LOAD) \ continue; \ /* Only care about executable segments. */ \ if ((EGET(phdr[i].p_flags) & PF_X) != PF_X) \ continue; \ \ /* now see if any of the relocs touch this segment */ \ for (r = 0; r < rmax; ++r) { \ unsigned long sym_max; \ Elf ## B ## _Addr offset_tmp; \ const Elf ## B ## _Sym *func; \ const Elf ## B ## _Sym *sym; \ Elf ## B ## _Addr r_offset; \ uint ## B ## _t r_info; \ if (pltrel == DT_REL) { \ r_offset = EGET(rel[r].r_offset); \ r_info = EGET(rel[r].r_info); \ } else { \ r_offset = EGET(rela[r].r_offset); \ r_info = EGET(rela[r].r_info); \ } \ /* make sure this relocation is inside of the .text */ \ if (r_offset < vaddr || r_offset >= vaddr + memsz) { \ if (be_verbose <= 2) continue; \ } else \ *found_textrels = 1; \ /* locate this relocation symbol name */ \ sym = SYM ## B (elf->vdata + EGET(symtab->sh_offset)); \ if ((void*)sym > elf->data_end) { \ warn("%s: corrupt ELF symbol", elf->filename); \ continue; \ } \ sym_max = ELF ## B ## _R_SYM(r_info); \ if (sym_max * EGET(symtab->sh_entsize) < symtab->sh_size) \ sym += sym_max; \ else \ sym = NULL; \ sym_max = EGET(symtab->sh_size) / EGET(symtab->sh_entsize); \ /* show the raw details about this reloc */ \ printf(" %s: ", elf->base_filename); \ if (!strtab) \ printf("(missing symbols)"); \ else if (sym && sym->st_name) \ printf("%s", elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name)); \ else \ printf("(memory/data?)"); \ printf(" [0x%lX]", (unsigned long)r_offset); \ /* now try to find the closest symbol that this rel is probably in */ \ sym = SYM ## B (elf->vdata + EGET(symtab->sh_offset)); \ func = NULL; \ offset_tmp = 0; \ while (sym_max--) { \ if (EGET(sym->st_value) < r_offset && EGET(sym->st_value) > offset_tmp) { \ func = sym; \ offset_tmp = EGET(sym->st_value); \ } \ ++sym; \ } \ printf(" in "); \ if (func && func->st_name) { \ if (strtab) { \ const char *func_name = elf->data + EGET(strtab->sh_offset) + EGET(func->st_name); \ if (r_offset > EGET(func->st_size)) \ printf("(optimized out: previous %s)", func_name); \ else \ printf("%s", func_name); \ } else \ printf("(missing symbols)"); \ } else \ printf("(optimized out)"); \ printf(" [0x%lX]\n", (unsigned long)offset_tmp); \ if (be_verbose && objdump) { \ Elf ## B ## _Addr end_addr = offset_tmp + EGET(func->st_size); \ char *sysbuf; \ int ret; \ if (end_addr < r_offset) \ /* not uncommon when things are optimized out */ \ end_addr = r_offset + 0x100; \ ret = asprintf( \ &sysbuf, \ "%s -r -R -d -w -l --start-address=0x%lX --stop-address=0x%lX %s | " \ "grep --color -i -C 3 '.*[[:space:]]%lX:[[:space:]]*R_.*'\n", \ objdump, \ (unsigned long)offset_tmp, \ (unsigned long)end_addr, \ elf->filename, \ (unsigned long)r_offset); \ if (ret < 0) \ errp("asprintf() failed"); \ fflush(stdout); \ if (system(sysbuf)) {/* don't care */} \ fflush(stdout); \ free(sysbuf); \ } \ } \ } if (symtab_void && elf->phdr) SCANELF_ELF_SIZED(SHOW_TEXTRELS); if (!*found_textrels) warnf("ELF %s has TEXTREL markings but doesnt appear to have any real TEXTREL's !?", elf->filename); return NULL; } static void rpath_security_checks(elfobj *elf, const char *item, const char *dt_type) { struct stat st; switch (*item) { case '/': break; case '.': warnf("Security problem with relative %s '%s' in %s", dt_type, item, elf->filename); break; case ':': case '\0': warnf("Security problem NULL %s in %s", dt_type, elf->filename); break; case '$': if (fstat(elf->fd, &st) != -1) if ((st.st_mode & S_ISUID) || (st.st_mode & S_ISGID)) warnf("Security problem with %s='%s' in %s with mode set of %o", dt_type, item, elf->filename, (unsigned int) st.st_mode & 07777); break; default: warnf("Maybe? sec problem with %s='%s' in %s", dt_type, item, elf->filename); break; } if (fix_elf) warnf("Note: RPATH has been automatically fixed, but this should be fixed in the package itself"); } static void scanelf_file_rpath(elfobj *elf, char *found_rpath, char **ret, size_t *ret_len) { const char *rpath, *runpath, **r; const void *strtab_void; if (!show_rpath) return; /* * TODO: Switch to the string table found via dynamic tags. * Note: We can't use scanelf_file_get_symtabs as these strings are * *only* found in dynstr and not in .strtab. */ strtab_void = elf_findsecbyname(elf, ".dynstr"); rpath = runpath = NULL; #define SHOW_RPATH(B) \ const Elf ## B ## _Dyn *dyn; \ const Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ Elf ## B ## _Off offset; \ Elf ## B ## _Xword word; \ \ /* Just scan dynamic RPATH/RUNPATH headers */ \ scanelf_dt_for_each(B, elf, dyn) { \ word = EGET(dyn->d_tag); \ if (word == DT_RPATH) { \ r = &rpath; \ } else if (word == DT_RUNPATH) { \ r = &runpath; \ } else { \ continue; \ } \ /* Verify the memory is somewhat sane */ \ offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ if (offset < (Elf ## B ## _Off)elf->len) { \ if (*r) warn("ELF has multiple %s's !?", get_elfdtype(word)); \ *r = elf->data + offset; \ /* cache the length in case we need to nuke this section later on */ \ if (fix_elf) \ offset = strlen(*r); \ /* If quiet, don't output paths in ld.so.conf */ \ if (be_quiet) { \ size_t len; \ const char *start, *end; \ /* note that we only 'chop' off leading known paths. */ \ /* since *r is read-only memory, we can only move the ptr forward. */ \ start = *r; \ /* scan each path in : delimited list */ \ while (start) { \ rpath_security_checks(elf, start, get_elfdtype(word)); \ end = strchr(start, ':'); \ len = (end ? (size_t)(end - start) : strlen(start)); \ if (use_ldcache) { \ size_t n; \ const char *ldpath; \ array_for_each(ldpaths, n, ldpath) \ if (!strncmp(ldpath, start, len) && !ldpath[len]) { \ *r = end; \ /* corner case ... if RPATH reads "/usr/lib:", we want \ * to show ':' rather than '' */ \ if (end && end[1] != '\0') \ (*r)++; \ break; \ } \ } \ if (!*r || !end) \ break; \ else \ start = start + len + 1; \ } \ } \ if (*r) { \ if (fix_elf > 2 || (fix_elf && **r == '\0')) { \ /* just nuke it */ \ nuke_it##B: { \ /* We have to cast away the const. \ * We know we mapped the backing memory as writable. */ \ Elf ## B ## _Dyn *wdyn = (void *)dyn; \ memset((void *)*r, 0x00, offset); \ *r = NULL; \ ESET(wdyn->d_tag, DT_DEBUG); \ ESET(wdyn->d_un.d_ptr, 0); \ } \ } else if (fix_elf) { \ /* try to clean "bad" paths */ \ size_t len, tmpdir_len; \ char *start, *end; \ const char *tmpdir; \ start = (void *)*r; \ tmpdir = (getenv("TMPDIR") ? : "."); \ tmpdir_len = strlen(tmpdir); \ while (1) { \ end = strchr(start, ':'); \ if (start == end) { \ eat_this_path##B: \ len = strlen(end); \ memmove(start, end+1, len); \ start[len-1] = '\0'; \ end = start - 1; \ } else if (tmpdir && !strncmp(start, tmpdir, tmpdir_len)) { \ if (!end) { \ if (start == *r) \ goto nuke_it##B; \ *--start = '\0'; \ } else \ goto eat_this_path##B; \ } \ if (!end) \ break; \ start = end + 1; \ } \ if (**r == '\0') \ goto nuke_it##B; \ } \ if (*r) \ *found_rpath = 1; \ } \ } \ } if (elf->phdr && strtab_void) SCANELF_ELF_SIZED(SHOW_RPATH); if (be_wewy_wewy_quiet) return; if (rpath && runpath) { if (!strcmp(rpath, runpath)) { xstrcat(ret, runpath, ret_len); } else { fprintf(stderr, "RPATH [%s] != RUNPATH [%s]\n", rpath, runpath); xchrcat(ret, '{', ret_len); xstrcat(ret, rpath, ret_len); xchrcat(ret, ',', ret_len); xstrcat(ret, runpath, ret_len); xchrcat(ret, '}', ret_len); } } else if (rpath || runpath) xstrcat(ret, (runpath ? runpath : rpath), ret_len); else if (!be_quiet) xstrcat(ret, " - ", ret_len); } static char *lookup_config_lib(const char *fname) { static char buf[__PAX_UTILS_PATH_MAX] = ""; const char *ldpath; size_t n; array_for_each(ldpaths, n, ldpath) { snprintf(buf, sizeof(buf), "%s/%s", root_rel_path(ldpath), fname); if (faccessat(root_fd, buf, F_OK, AT_SYMLINK_NOFOLLOW) == 0) return buf; } return NULL; } static const char *scanelf_file_needed_lib(elfobj *elf, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len) { const char *needed; const void *strtab_void; char *p; /* * -n -> op==0 -> print all * -N -> op==1 -> print requested */ if ((op == 0 && !show_needed) || (op == 1 && !find_lib)) return NULL; /* * TODO: Switch to the string table found via dynamic tags. * Note: We can't use scanelf_file_get_symtabs as these strings are * *only* found in dynstr and not in .strtab. */ strtab_void = elf_findsecbyname(elf, ".dynstr"); #define SHOW_NEEDED(B) \ const Elf ## B ## _Dyn *dyn; \ const Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ size_t matched = 0; \ \ /* Walk all the dynamic tags to find NEEDED entries */ \ scanelf_dt_for_each(B, elf, dyn) { \ if (EGET(dyn->d_tag) == DT_NEEDED) { \ Elf ## B ## _Off offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ if (offset >= (Elf ## B ## _Off)elf->len) \ continue; \ needed = elf->data + offset; \ if (op == 0) { \ /* -n -> print all entries */ \ if (!be_wewy_wewy_quiet) { \ if (*found_needed) xchrcat(ret, ',', ret_len); \ if (use_ldpath) { \ if ((p = lookup_config_lib(needed)) != NULL) \ needed = p; \ } else if (use_ldcache) { \ if ((p = ldso_cache_lookup_lib(elf, needed)) != NULL) \ needed = p; \ } \ xstrcat(ret, needed, ret_len); \ } \ *found_needed = 1; \ } else { \ /* -N -> print matching entries */ \ size_t n; \ const char *find_lib_name; \ \ array_for_each(find_lib_arr, n, find_lib_name) { \ int invert = 1; \ if (find_lib_name[0] == '!') \ invert = 0, ++find_lib_name; \ if ((!strcmp(find_lib_name, needed)) == invert) \ ++matched; \ } \ \ if (matched == array_cnt(find_lib_arr)) { \ *found_lib = 1; \ return (be_wewy_wewy_quiet ? NULL : find_lib); \ } \ } \ } \ } if (elf->phdr && strtab_void) { SCANELF_ELF_SIZED(SHOW_NEEDED); if (op == 0 && !*found_needed && be_verbose) warn("ELF lacks DT_NEEDED sections: %s", elf->filename); } return NULL; } static const char *scanelf_file_interp(elfobj *elf, char *found_interp) { uint64_t offset = 0; if (!show_interp) return NULL; if (elf->phdr) { /* Walk all the program headers to find the PT_INTERP */ #define GET_PT_INTERP(B) \ size_t i; \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Phdr *phdr = PHDR ## B (elf->phdr); \ for (i = 0; i < EGET(ehdr->e_phnum); ++i) { \ if (EGET(phdr[i].p_type) == PT_INTERP) { \ offset = EGET(phdr[i].p_offset); \ break; \ } \ } SCANELF_ELF_SIZED(GET_PT_INTERP); } else if (elf->shdr) { /* Use the section headers to find it */ const void *section = elf_findsecbyname(elf, ".interp"); #define GET_INTERP(B) \ const Elf ## B ## _Shdr *shdr = SHDR ## B (section); \ offset = EGET(shdr->sh_offset); if (section) SCANELF_ELF_SIZED(GET_INTERP); } /* Validate the pointer even if we don't use it in output */ if (offset && offset <= (uint64_t)elf->len) { const char *interp = elf->data + offset; /* If it isn't a C pointer, it's garbage */ if (memchr(interp, 0, elf->len - offset)) { *found_interp = 1; if (!be_wewy_wewy_quiet) return interp; } } return NULL; } static const char *scanelf_file_bind(elfobj *elf, char *found_bind) { struct stat s; bool dynamic = false; if (!show_bind) return NULL; if (!elf->phdr) return NULL; #define SHOW_BIND(B) \ const Elf ## B ## _Dyn *dyn; \ \ scanelf_dt_for_each(B, elf, dyn) { \ dynamic = true; \ if (EGET(dyn->d_tag) == DT_BIND_NOW || \ (EGET(dyn->d_tag) == DT_FLAGS && EGET(dyn->d_un.d_val) & DF_BIND_NOW)) { \ if (be_quiet) \ return NULL; \ *found_bind = 1; \ return (char *)(be_wewy_wewy_quiet ? NULL : "NOW"); \ } \ } SCANELF_ELF_SIZED(SHOW_BIND); if (be_wewy_wewy_quiet) return NULL; /* don't output anything if quiet mode and the ELF is static or not setuid */ if (be_quiet && (!dynamic || (!fstat(elf->fd, &s) && !(s.st_mode & (S_ISUID|S_ISGID))))) { return NULL; } else { *found_bind = 1; return dynamic ? "LAZY" : "STATIC"; } } static const char *scanelf_file_soname(elfobj *elf, char *found_soname) { const char *soname; const void *strtab_void; if (!show_soname) return NULL; /* * TODO: Switch to the string table found via dynamic tags. * Note: We can't use scanelf_file_get_symtabs as these strings are * *only* found in dynstr and not in .strtab. */ strtab_void = elf_findsecbyname(elf, ".dynstr"); #define SHOW_SONAME(B) \ const Elf ## B ## _Dyn *dyn; \ const Elf ## B ## _Ehdr *ehdr = EHDR ## B (elf->ehdr); \ const Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ \ /* only look for soname in shared objects */ \ if (EGET(ehdr->e_type) != ET_DYN) \ return NULL; \ \ scanelf_dt_for_each(B, elf, dyn) { \ if (EGET(dyn->d_tag) == DT_SONAME) { \ Elf ## B ## _Off offset = EGET(strtab->sh_offset) + EGET(dyn->d_un.d_ptr); \ if (offset >= (Elf ## B ## _Off)elf->len) \ continue; \ soname = elf->data + offset; \ *found_soname = 1; \ return (be_wewy_wewy_quiet ? NULL : soname); \ } \ } if (elf->phdr && strtab_void) SCANELF_ELF_SIZED(SHOW_SONAME); return NULL; } /* * We support the symbol form: * [%[modifiers]%][[+-]][,[.....]] * If the symbol name is empty, then all symbols are matched. * If the symbol name is a glob ("*"), then all symbols are dumped (debug). * Do not rely on this output format at all. * Otherwise the symbol name is used to search (either regex or string compare). * If the first char of the symbol name is a plus ("+"), then only match * defined symbols. If it's a minus ("-"), only match undefined symbols. * Putting modifiers in between the percent signs allows for more in depth * filters. There are groups of modifiers. If you don't specify a member * of a group, then all types in that group are matched. The current * groups and their types are: * STT group: STT_NOTYPE:n STT_OBJECT:o STT_FUNC:f STT_FILE:F * STB group: STB_LOCAL:l STB_GLOBAL:g STB_WEAK:w * STV group: STV_DEFAULT:p STV_INTERNAL:i STV_HIDDEN:h STV_PROTECTED:P * SHN group: SHN_UNDEF:u SHN_ABS:a SHN_COMMON:c {defined}:d * The "defined" value in the SHN group does not correspond to a SHN_xxx define. * You can search for multiple symbols at once by seperating with a comma (","). * * Some examples: * ELFs with a weak function "foo": * scanelf -s %wf%foo * ELFs that define the symbol "main": * scanelf -s +main * scanelf -s %d%main * ELFs that refer to the undefined symbol "brk": * scanelf -s -brk * scanelf -s %u%brk * All global defined objects in an ELF: * scanelf -s %ogd% */ static void scanelf_match_symname(elfobj *elf, char *found_sym, char **ret, size_t *ret_len, const char *symname, unsigned int stt, unsigned int stb, unsigned int stv, unsigned int shn, unsigned long size) { const char *this_sym; size_t n; array_for_each(find_sym_arr, n, this_sym) { bool inc_notype, inc_object, inc_func, inc_file, inc_local, inc_global, inc_weak, inc_visdef, inc_intern, inc_hidden, inc_prot, inc_def, inc_undef, inc_abs, inc_common; /* symbol selection! */ inc_notype = inc_object = inc_func = inc_file = inc_local = inc_global = inc_weak = inc_visdef = inc_intern = inc_hidden = inc_prot = inc_def = inc_undef = inc_abs = inc_common = (*this_sym != '%'); /* parse the contents of %...% */ if (!inc_notype) { while (*(this_sym++)) { if (*this_sym == '%') { ++this_sym; break; } switch (*this_sym) { case 'n': inc_notype = true; break; case 'o': inc_object = true; break; case 'f': inc_func = true; break; case 'F': inc_file = true; break; case 'l': inc_local = true; break; case 'g': inc_global = true; break; case 'w': inc_weak = true; break; case 'p': inc_visdef = true; break; case 'i': inc_intern = true; break; case 'h': inc_hidden = true; break; case 'P': inc_prot = true; break; case 'd': inc_def = true; break; case 'u': inc_undef = true; break; case 'a': inc_abs = true; break; case 'c': inc_common = true; break; default: err("invalid symbol selector '%c'", *this_sym); } } /* If no types are matched, not match all */ if (!inc_notype && !inc_object && !inc_func && !inc_file) inc_notype = inc_object = inc_func = inc_file = true; if (!inc_local && !inc_global && !inc_weak) inc_local = inc_global = inc_weak = true; if (!inc_visdef && !inc_intern && !inc_hidden && !inc_prot) inc_visdef = inc_intern = inc_hidden = inc_prot = true; if (!inc_def && !inc_undef && !inc_abs && !inc_common) inc_def = inc_undef = inc_abs = inc_common = true; /* backwards compat for defined/undefined short hand */ } else if (*this_sym == '+') { inc_undef = false; ++this_sym; } else if (*this_sym == '-') { inc_def = inc_abs = inc_common = false; ++this_sym; } /* filter symbols */ if ((!inc_notype && stt == STT_NOTYPE ) || \ (!inc_object && stt == STT_OBJECT ) || \ (!inc_func && stt == STT_FUNC ) || \ (!inc_file && stt == STT_FILE ) || \ (!inc_local && stb == STB_LOCAL ) || \ (!inc_global && stb == STB_GLOBAL ) || \ (!inc_weak && stb == STB_WEAK ) || \ (!inc_visdef && stv == STV_DEFAULT ) || \ (!inc_intern && stv == STV_INTERNAL ) || \ (!inc_hidden && stv == STV_HIDDEN ) || \ (!inc_prot && stv == STV_PROTECTED) || \ (!inc_def && shn && shn < SHN_LORESERVE) || \ (!inc_undef && shn == SHN_UNDEF ) || \ (!inc_abs && shn == SHN_ABS ) || \ (!inc_common && shn == SHN_COMMON )) continue; if (*this_sym == '*') { /* a "*" symbol gets you debug output */ printf("%s(%s) %5lX %-15s %-15s %-15s %-15s %s\n", ((*found_sym == 0) ? "\n\t" : "\t"), elf->base_filename, size, get_elfstttype(stt), get_elfstbtype(stb), get_elfstvtype(stv), get_elfshntype(shn), symname); goto matched; } else { if (g_match) { /* regex match the symbol */ if (regexec(find_sym_regex_arr->eles[n], symname, 0, NULL, 0) == REG_NOMATCH) continue; } else if (*this_sym) { /* give empty symbols a "pass", else do a normal compare */ const size_t len = strlen(this_sym); if (!(strncmp(this_sym, symname, len) == 0 && /* Accept unversioned symbol names */ (symname[len] == '\0' || symname[len] == '@'))) continue; } if (be_semi_verbose) { char buf[1024]; snprintf(buf, sizeof(buf), "%lX %s %s", size, get_elfstttype(stt), this_sym); *ret = xstrdup(buf); } else { if (*ret) xchrcat(ret, ',', ret_len); xstrcat(ret, symname, ret_len); } goto matched; } } return; matched: *found_sym = 1; } static char *scanelf_file_sym(elfobj *elf, char *found_sym) { char *ret; const void *symtab_void, *strtab_void; if (!find_sym) return NULL; ret = NULL; scanelf_file_get_symtabs(elf, &symtab_void, &strtab_void); #define FIND_SYM(B) \ const Elf ## B ## _Shdr *symtab = SHDR ## B (symtab_void); \ const Elf ## B ## _Shdr *strtab = SHDR ## B (strtab_void); \ const Elf ## B ## _Sym *sym = SYM ## B (elf->vdata + EGET(symtab->sh_offset)); \ Elf ## B ## _Word i, cnt = EGET(symtab->sh_entsize); \ const char *symname; \ size_t ret_len = 0; \ if (cnt) \ cnt = EGET(symtab->sh_size) / cnt; \ for (i = 0; i < cnt; ++i) { \ if ((void *)sym >= elf->data_end - sizeof(*sym)) \ goto break_out; \ if (sym->st_name) { \ /* make sure the symbol name is in acceptable memory range */ \ symname = elf->data + EGET(strtab->sh_offset) + EGET(sym->st_name); \ if (EGET(sym->st_name) >= (uint64_t)elf->len || \ EGET(strtab->sh_offset) + EGET(sym->st_name) >= (uint64_t)elf->len || \ !memchr(symname, 0, elf->len - EGET(strtab->sh_offset) + EGET(sym->st_name))) \ goto break_out; \ scanelf_match_symname(elf, found_sym, \ &ret, &ret_len, symname, \ ELF##B##_ST_TYPE(EGET(sym->st_info)), \ ELF##B##_ST_BIND(EGET(sym->st_info)), \ ELF##B##_ST_VISIBILITY(EGET(sym->st_other)), \ EGET(sym->st_shndx), \ /* st_size can be 64bit, but no one is really that big, so screw em */ \ EGET(sym->st_size)); \ } \ ++sym; \ } if (symtab_void && strtab_void) SCANELF_ELF_SIZED(FIND_SYM); if (be_wewy_wewy_quiet) { free(ret); return NULL; } if (*find_sym != '*' && *found_sym) return ret; else free(ret); if (be_quiet) return NULL; else return xstrdup(" - "); break_out: warnf("%s: corrupt ELF symbols", elf->filename); free(ret); return NULL; } static const char *scanelf_file_sections(elfobj *elf, char *found_section) { if (!find_section) return NULL; #define FIND_SECTION(B) \ size_t matched, n; \ int invert; \ const char *section_name; \ const Elf ## B ## _Shdr *section; \ \ matched = 0; \ array_for_each(find_section_arr, n, section_name) { \ invert = (*section_name == '!' ? 1 : 0); \ section = SHDR ## B (elf_findsecbyname(elf, section_name + invert)); \ if ((section == NULL && invert) || (section != NULL && !invert)) \ ++matched; \ } \ \ if (matched == array_cnt(find_section_arr)) \ *found_section = 1; SCANELF_ELF_SIZED(FIND_SECTION); if (be_wewy_wewy_quiet) return NULL; if (*found_section) return find_section; if (be_quiet) return NULL; else return " - "; } /* scan an elf file and show all the fun stuff */ #define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; }) static int scanelf_elfobj(elfobj *elf) { unsigned long i; char found_pax, found_phdr, found_relro, found_load, found_textrel, found_rpath, found_needed, found_interp, found_bind, found_soname, found_sym, found_lib, found_file, found_textrels, found_section; static char *out_buffer = NULL; static size_t out_len; found_pax = found_phdr = found_relro = found_load = found_textrel = \ found_rpath = found_needed = found_interp = found_bind = found_soname = \ found_sym = found_lib = found_file = found_textrels = found_section = 0; if (be_verbose > 2) printf("%s: scanning file {%s,%s}\n", elf->filename, get_elfeitype(EI_CLASS, elf->elf_class), get_elfeitype(EI_DATA, elf->data[EI_DATA])); else if (be_verbose > 1) printf("%s: scanning file\n", elf->filename); /* init output buffer */ if (!out_buffer) { out_len = sizeof(char) * 80; out_buffer = xmalloc(out_len); } *out_buffer = '\0'; /* show the header */ if (!be_quiet && show_banner) { for (i = 0; out_format[i]; ++i) { if (!IS_MODIFIER(out_format[i])) continue; switch (out_format[++i]) { case '+': break; case '%': break; case '#': break; case 'F': case 'p': case 'f': prints("FILE "); found_file = 1; break; case 'o': prints(" TYPE "); break; case 'x': prints(" PAX "); break; case 'e': prints("STK/REL/PTL "); break; case 't': prints("TEXTREL "); break; case 'r': prints("RPATH "); break; case 'M': prints("CLASS "); break; case 'l': case 'n': prints("NEEDED "); break; case 'i': prints("INTERP "); break; case 'b': prints("BIND "); break; case 'Z': prints("SIZE "); break; case 'S': prints("SONAME "); break; case 's': prints("SYM "); break; case 'N': prints("LIB "); break; case 'T': prints("TEXTRELS "); break; case 'k': prints("SECTION "); break; case 'a': prints("ARCH "); break; case 'I': prints("OSABI "); break; case 'Y': prints("EABI "); break; case 'O': prints("PERM "); break; case 'D': prints("ENDIAN "); break; default: warnf("'%c' has no title ?", out_format[i]); } } if (!found_file) prints("FILE "); prints("\n"); found_file = 0; show_banner = 0; } /* dump all the good stuff */ for (i = 0; out_format[i]; ++i) { char *allocated; const char *out; const char *tmp; static char ubuf[sizeof(unsigned long)*2]; if (!IS_MODIFIER(out_format[i])) { xchrcat(&out_buffer, out_format[i], &out_len); continue; } out = allocated = NULL; be_wewy_wewy_quiet = (out_format[i] == '#'); be_semi_verbose = (out_format[i] == '+'); switch (out_format[++i]) { case '+': case '%': case '#': xchrcat(&out_buffer, out_format[i], &out_len); break; case 'F': found_file = 1; if (be_wewy_wewy_quiet) break; xstrcat(&out_buffer, elf->filename, &out_len); break; case 'p': found_file = 1; if (be_wewy_wewy_quiet) break; tmp = elf->filename; if (search_path) { ssize_t len_search = strlen(search_path); ssize_t len_file = strlen(elf->filename); if (!strncmp(elf->filename, search_path, len_search) && \ len_file > len_search) tmp += len_search; if (*tmp == '/' && search_path[len_search-1] == '/') tmp++; } xstrcat(&out_buffer, tmp, &out_len); break; case 'f': found_file = 1; if (be_wewy_wewy_quiet) break; tmp = strrchr(elf->filename, '/'); tmp = (tmp == NULL ? elf->filename : tmp+1); xstrcat(&out_buffer, tmp, &out_len); break; case 'o': out = get_elfetype(elf); break; case 'x': out = scanelf_file_pax(elf, &found_pax); break; case 'e': out = scanelf_file_phdr(elf, &found_phdr, &found_relro, &found_load); break; case 't': out = scanelf_file_textrel(elf, &found_textrel); break; case 'T': out = scanelf_file_textrels(elf, &found_textrels, &found_textrel); break; case 'r': scanelf_file_rpath(elf, &found_rpath, &out_buffer, &out_len); break; case 'M': out = get_elfeitype(EI_CLASS, elf->data[EI_CLASS]); break; case 'D': out = get_endian(elf); break; case 'O': out = strfileperms(elf->filename); break; case 'n': case 'N': out = scanelf_file_needed_lib(elf, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break; case 'i': out = scanelf_file_interp(elf, &found_interp); break; case 'b': out = scanelf_file_bind(elf, &found_bind); break; case 'S': out = scanelf_file_soname(elf, &found_soname); break; case 's': out = allocated = scanelf_file_sym(elf, &found_sym); break; case 'k': out = scanelf_file_sections(elf, &found_section); break; case 'a': out = get_elfemtype(elf); break; case 'I': out = get_elfosabi(elf); break; case 'Y': out = get_elf_eabi(elf); break; case 'Z': snprintf(ubuf, sizeof(ubuf), "%"PRIu64, (uint64_t)elf->len); out = ubuf; break;; default: warnf("'%c' has no scan code?", out_format[i]); } if (out) { xstrcat(&out_buffer, out, &out_len); free(allocated); } } #define FOUND_SOMETHING() \ (found_pax || found_phdr || found_relro || found_load || found_textrel || \ found_rpath || found_needed || found_interp || found_bind || \ found_soname || found_sym || found_lib || found_textrels || found_section ) if (!found_file && (!be_quiet || (be_quiet && FOUND_SOMETHING()))) { xchrcat(&out_buffer, ' ', &out_len); xstrcat(&out_buffer, elf->filename, &out_len); } if (!be_quiet || (be_quiet && FOUND_SOMETHING())) { puts(out_buffer); fflush(stdout); } return 0; } /* scan a single elf */ static int scanelf_elf(const char *filename, int fd, size_t len) { int ret = 1; size_t n; const char *match_etype; elfobj *elf; /* Verify this is a real ELF */ if ((elf = _readelf_fd(filename, fd, len, !fix_elf)) == NULL) { if (be_verbose > 2) printf("%s: not an ELF\n", filename); return 2; } /* Possibly filter based on ELF bitness */ switch (match_bits) { case 32: if (elf->elf_class != ELFCLASS32) goto done; break; case 64: if (elf->elf_class != ELFCLASS64) goto done; break; } /* Possibly filter based on the ELF's e_type field */ array_for_each(match_etypes, n, match_etype) if (etype_lookup(match_etype) == get_etype(elf)) goto scanit; if (array_cnt(match_etypes)) goto done; scanit: ret = scanelf_elfobj(elf); done: unreadelf(elf); return ret; } /* scan an archive of elfs */ static int scanelf_archive(const char *filename, int fd, size_t len) { archive_handle *ar; archive_member *m; char *ar_buffer; elfobj *elf; ar = ar_open_fd(filename, fd, be_verbose); if (ar == NULL) return 1; ar_buffer = mmap(0, len, PROT_READ | (fix_elf ? PROT_WRITE : 0), (fix_elf ? MAP_SHARED : MAP_PRIVATE), fd, 0); while ((m = ar_next(ar)) != NULL) { off_t cur_pos = lseek(fd, 0, SEEK_CUR); if (cur_pos == -1) errp("lseek() failed"); elf = readelf_buffer(m->name, ar_buffer + cur_pos, m->size); if (elf) { scanelf_elfobj(elf); unreadelf(elf); } } munmap(ar_buffer, len); return 0; } /* scan a file which may be an elf or an archive or some other magical beast */ static int scanelf_fileat(int dir_fd, const char *filename, const struct stat *st_cache) { const struct stat *st = st_cache; struct stat symlink_st; int fd; /* always handle regular files and handle symlinked files if no -y */ if (S_ISLNK(st->st_mode)) { if (!scan_symlink) return 1; fstatat(dir_fd, filename, &symlink_st, 0); st = &symlink_st; } if (!S_ISREG(st->st_mode)) { if (be_verbose > 2) printf("%s: skipping non-file\n", filename); return 1; } if (match_perms) { if ((st->st_mode | match_perms) != st->st_mode) return 1; } fd = openat(dir_fd, filename, (fix_elf ? O_RDWR : O_RDONLY) | O_CLOEXEC); if (fd == -1) { if (fix_elf && errno == ETXTBSY) warnp("%s: could not fix", filename); else if (be_verbose > 2) printf("%s: skipping file: %s\n", filename, strerror(errno)); return 1; } if (scanelf_elf(filename, fd, st->st_size) == 2) { /* if it isn't an ELF, maybe it's an .a archive */ if (scan_archives) scanelf_archive(filename, fd, st->st_size); /* * unreadelf() implicitly closes its fd, so only close it * when we are returning it in the non-ELF case */ close(fd); } return 0; } /* scan a directory for ET_EXEC files and print when we find one */ static int scanelf_dirat(int dir_fd, const char *path) { register DIR *dir; register struct dirent *dentry; struct stat st_top, st; char buf[__PAX_UTILS_PATH_MAX], *subpath; size_t pathlen = 0, len = 0; int ret = 0; int subdir_fd; /* make sure path exists */ if (fstatat(dir_fd, path, &st_top, AT_SYMLINK_NOFOLLOW) == -1) { if (be_verbose > 2) printf("%s: does not exist\n", path); return 1; } /* ok, if it isn't a directory, assume we can open it */ if (!S_ISDIR(st_top.st_mode)) return scanelf_fileat(dir_fd, path, &st_top); /* now scan the dir looking for fun stuff */ subdir_fd = openat(dir_fd, path, O_RDONLY|O_CLOEXEC); if (subdir_fd == -1) dir = NULL; else dir = fdopendir(subdir_fd); if (dir == NULL) { if (subdir_fd != -1) close(subdir_fd); else if (be_verbose > 2) printf("%s: skipping dir: %s\n", path, strerror(errno)); return 1; } if (be_verbose > 1) printf("%s: scanning dir\n", path); subpath = stpcpy(buf, path); if (subpath[-1] != '/') *subpath++ = '/'; pathlen = subpath - buf; while ((dentry = readdir(dir))) { if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) continue; if (fstatat(subdir_fd, dentry->d_name, &st, AT_SYMLINK_NOFOLLOW) == -1) continue; len = strlen(dentry->d_name); if (len + pathlen + 1 >= sizeof(buf)) { warnf("Skipping '%s%s': len > sizeof(buf); %zu > %zu", path, dentry->d_name, len + pathlen + 1, sizeof(buf)); continue; } memcpy(subpath, dentry->d_name, len); subpath[len] = '\0'; if (S_ISREG(st.st_mode)) ret = scanelf_fileat(dir_fd, buf, &st); else if (dir_recurse && S_ISDIR(st.st_mode)) { if (dir_crossmount || (st_top.st_dev == st.st_dev)) ret = scanelf_dirat(dir_fd, buf); } } closedir(dir); return ret; } static int scanelf_dir(const char *path) { return scanelf_dirat(root_fd, root_rel_path(path)); } static int scanelf_from_file(const char *filename) { FILE *fp; char *p, *path; size_t len; int ret; if (strcmp(filename, "-") == 0) fp = stdin; else if ((fp = fopen(filename, "r")) == NULL) return 1; path = NULL; len = 0; ret = 0; while (getline(&path, &len, fp) != -1) { if ((p = strchr(path, '\n')) != NULL) *p = 0; search_path = path; ret = scanelf_dir(path); } free(path); if (fp != stdin) fclose(fp); return ret; } static void load_ld_cache_config(const char *fname) { bool scan_l, scan_ul, scan_ull; size_t n; const char *ldpath; ldso_config_load(fname); scan_l = scan_ul = scan_ull = false; array_for_each(ldpaths, n, ldpath) { if (!scan_l && !strcmp(ldpath, "/lib")) scan_l = true; if (!scan_ul && !strcmp(ldpath, "/usr/lib")) scan_ul = true; if (!scan_ull && !strcmp(ldpath, "/usr/local/lib")) scan_ull = true; } if (!scan_l) xarraypush_str(ldpaths, "/lib"); if (!scan_ul) xarraypush_str(ldpaths, "/usr/lib"); if (!scan_ull) xarraypush_str(ldpaths, "/usr/local/lib"); } /* scan /etc/ld.so.conf for paths */ static void scanelf_ldpath(void) { size_t n; const char *ldpath; array_for_each(ldpaths, n, ldpath) scanelf_dir(ldpath); } /* scan env PATH for paths */ static void scanelf_envpath(void) { char *path, *p; path = getenv("PATH"); if (!path) err("PATH is not set in your env !"); path = xstrdup(path); while ((p = strrchr(path, ':')) != NULL) { scanelf_dir(p + 1); *p = 0; } free(path); } /* usage / invocation handling functions */ /* Free Flags: c d j u w G H J K P Q U W */ #define PARSE_FLAGS "plRmyAXz:xetrnLibSs:k:gN:TaqvF:f:o:E:M:DIYO:ZCBhV" #define a_argument required_argument static struct option const long_opts[] = { {"path", no_argument, NULL, 'p'}, {"ldpath", no_argument, NULL, 'l'}, {"use-ldpath",no_argument, NULL, 129}, {"root", a_argument, NULL, 128}, {"recursive", no_argument, NULL, 'R'}, {"mount", no_argument, NULL, 'm'}, {"symlink", no_argument, NULL, 'y'}, {"archives", no_argument, NULL, 'A'}, {"ldcache", no_argument, NULL, 'L'}, {"fix", no_argument, NULL, 'X'}, {"setpax", a_argument, NULL, 'z'}, {"pax", no_argument, NULL, 'x'}, {"header", no_argument, NULL, 'e'}, {"textrel", no_argument, NULL, 't'}, {"rpath", no_argument, NULL, 'r'}, {"needed", no_argument, NULL, 'n'}, {"interp", no_argument, NULL, 'i'}, {"bind", no_argument, NULL, 'b'}, {"soname", no_argument, NULL, 'S'}, {"symbol", a_argument, NULL, 's'}, {"section", a_argument, NULL, 'k'}, {"lib", a_argument, NULL, 'N'}, {"gmatch", no_argument, NULL, 'g'}, {"textrels", no_argument, NULL, 'T'}, {"etype", a_argument, NULL, 'E'}, {"bits", a_argument, NULL, 'M'}, {"endian", no_argument, NULL, 'D'}, {"osabi", no_argument, NULL, 'I'}, {"eabi", no_argument, NULL, 'Y'}, {"perms", a_argument, NULL, 'O'}, {"size", no_argument, NULL, 'Z'}, {"all", no_argument, NULL, 'a'}, {"quiet", no_argument, NULL, 'q'}, {"verbose", no_argument, NULL, 'v'}, {"format", a_argument, NULL, 'F'}, {"from", a_argument, NULL, 'f'}, {"file", a_argument, NULL, 'o'}, {"nocolor", no_argument, NULL, 'C'}, {"nobanner", no_argument, NULL, 'B'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, no_argument, NULL, 0x0} }; static const char * const opts_help[] = { "Scan all directories in PATH environment", "Scan all directories in /etc/ld.so.conf", "Use ld.so.conf to show full path (use with -r/-n)", "Root directory (use with -l or -p)", "Scan directories recursively", "Don't recursively cross mount points", "Don't scan symlinks", "Scan archives (.a files)", "Utilize ld.so.cache to show full path (use with -r/-n)", "Try and 'fix' bad things (use with -r/-e)", "Sets EI_PAX/PT_PAX_FLAGS to (use with -Xx)\n", "Print PaX markings", "Print GNU_STACK/PT_LOAD markings", "Print TEXTREL information", "Print RPATH information", "Print NEEDED information", "Print INTERP information", "Print BIND information", "Print SONAME information", "Find a specified symbol", "Find a specified section", "Find a specified library", "Use regex rather than string compare (with -s); specify twice for case insensitive", "Locate cause of TEXTREL", "Print only ELF files matching etype ET_DYN,ET_EXEC ...", "Print only ELF files matching numeric bits", "Print Endianness", "Print OSABI", "Print EABI (EM_ARM Only)", "Print only ELF files matching octal permissions", "Print ELF file size", "Print all useful/simple info\n", "Only output 'bad' things", "Be verbose (can be specified more than once)", "Use specified format for output", "Read input stream from a filename", "Write output stream to a filename", "Don't emit color in output", "Don't display the header", "Print this help and exit", "Print version and exit", NULL }; /* display usage and exit */ static void usage(int status) { const char a_arg[] = ""; size_t a_arg_len = strlen(a_arg) + 2; size_t i; int optlen; printf("* Scan ELF binaries for stuff\n\n" "Usage: %s [options] [dir2 dirN file2 fileN ...]\n\n", argv0); printf("Options: -[%s]\n", PARSE_FLAGS); /* prescan the --long opt length to auto-align */ optlen = 0; for (i = 0; long_opts[i].name; ++i) { int l = strlen(long_opts[i].name); if (long_opts[i].has_arg == a_argument) l += a_arg_len; optlen = max(l, optlen); } for (i = 0; long_opts[i].name; ++i) { /* first output the short flag if it has one */ if (long_opts[i].val > '~') printf(" "); else printf(" -%c, ", long_opts[i].val); /* then the long flag */ if (long_opts[i].has_arg == no_argument) printf("--%-*s", optlen, long_opts[i].name); else printf("--%s %s %*s", long_opts[i].name, a_arg, (int)(optlen - strlen(long_opts[i].name) - a_arg_len), ""); /* finally the help text */ printf("* %s\n", opts_help[i]); } puts("\nFor more information, see the scanelf(1) manpage"); exit(status); } /* parse command line arguments and preform needed actions */ #define do_pax_state(option, flag) \ if (islower(option)) { \ flags &= ~PF_##flag; \ flags |= PF_NO##flag; \ } else { \ flags &= ~PF_NO##flag; \ flags |= PF_##flag; \ } static void parse_delimited(array_t *arr, char *arg, const char *delim) { char *ele = strtok(arg, delim); if (!ele) /* edge case: -s '' */ xarraypush_str(arr, ""); while (ele) { xarraypush_str(arr, ele); ele = strtok(NULL, delim); } } static int parseargs(int argc, char *argv[]) { int i; const char *from_file = NULL; int ret = 0; char load_cache_config = 0; opterr = 0; while ((i=getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) { switch (i) { case 'V': printf("pax-utils-%s: %s\n" "%s written for Gentoo by \n", VERSION, VCSID, argv0); exit(EXIT_SUCCESS); break; case 'h': usage(EXIT_SUCCESS); break; case 'f': if (from_file) warn("You prob don't want to specify -f twice"); from_file = optarg; break; case 'E': /* historically, this was comma delimited */ parse_delimited(match_etypes, optarg, ","); break; case 'M': match_bits = atoi(optarg); if (match_bits == 0) { if (strcmp(optarg, "ELFCLASS32") == 0) match_bits = 32; if (strcmp(optarg, "ELFCLASS64") == 0) match_bits = 64; } break; case 'O': if (sscanf(optarg, "%o", &match_perms) == -1) match_bits = 0; break; case 'o': { if (freopen(optarg, "w", stdout) == NULL) errp("Could not freopen(%s)", optarg); break; } case 'k': xarraypush_str(find_section_arr, optarg); break; case 's': /* historically, this was comma delimited */ parse_delimited(find_sym_arr, optarg, ","); break; case 'N': xarraypush_str(find_lib_arr, optarg); break; case 'F': { if (PAX_UTILS_CLEANUP) { free(out_format); out_format = xstrdup(optarg); } else out_format = optarg; break; } case 'z': { unsigned long flags = (PF_NOEMUTRAMP | PF_NORANDEXEC); size_t x; for (x = 0; x < strlen(optarg); x++) { switch (optarg[x]) { case 'p': case 'P': do_pax_state(optarg[x], PAGEEXEC); break; case 's': case 'S': do_pax_state(optarg[x], SEGMEXEC); break; case 'm': case 'M': do_pax_state(optarg[x], MPROTECT); break; case 'e': case 'E': do_pax_state(optarg[x], EMUTRAMP); break; case 'r': case 'R': do_pax_state(optarg[x], RANDMMAP); break; case 'x': case 'X': do_pax_state(optarg[x], RANDEXEC); break; default: break; } } if (!(((flags & PF_PAGEEXEC) && (flags & PF_NOPAGEEXEC)) || ((flags & PF_SEGMEXEC) && (flags & PF_NOSEGMEXEC)) || ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP)) || ((flags & PF_RANDEXEC) && (flags & PF_NORANDEXEC)) || ((flags & PF_EMUTRAMP) && (flags & PF_NOEMUTRAMP)) || ((flags & PF_RANDMMAP) && (flags & PF_NORANDMMAP)))) setpax = flags; break; } case 'Z': show_size = 1; break; case 'g': ++g_match; break; case 'L': load_cache_config = use_ldcache = 1; break; case 'y': scan_symlink = 0; break; case 'A': scan_archives = 1; break; case 'C': color_init(true); break; case 'B': show_banner = 0; break; case 'l': load_cache_config = scan_ldpath = 1; break; case 'p': scan_envpath = 1; break; case 'R': dir_recurse = 1; break; case 'm': dir_crossmount = 0; break; case 'X': ++fix_elf; break; case 'x': show_pax = 1; break; case 'e': show_phdr = 1; break; case 't': show_textrel = 1; break; case 'r': show_rpath = 1; break; case 'n': show_needed = 1; break; case 'i': show_interp = 1; break; case 'b': show_bind = 1; break; case 'S': show_soname = 1; break; case 'T': show_textrels = 1; break; case 'q': be_quiet = min(be_quiet, 20) + 1; break; case 'v': be_verbose = min(be_verbose, 20) + 1; break; case 'a': show_perms = show_pax = show_phdr = show_textrel = show_rpath = show_bind = show_endian = 1; break; case 'D': show_endian = 1; break; case 'I': show_osabi = 1; break; case 'Y': show_eabi = 1; break; case 128: if (root_fd != AT_FDCWD) close(root_fd); root_fd = open(optarg, O_RDONLY|O_CLOEXEC); if (root_fd == -1) err("Could not open root: %s", optarg); break; case 129: load_cache_config = use_ldpath = 1; break; case ':': err("Option '%c' is missing parameter", optopt); case '?': err("Unknown option '%c' or argument missing", optopt); default: err("Unhandled option '%c'; please report this", i); } } if (show_textrels && be_verbose) objdump = which("objdump", "OBJDUMP"); /* precompile all the regexes */ if (g_match) { regex_t preg; const char *this_sym; size_t n; int flags = REG_EXTENDED | REG_NOSUB | (g_match > 1 ? REG_ICASE : 0); array_for_each(find_sym_arr, n, this_sym) { /* see scanelf_match_symname for logic info */ switch (this_sym[0]) { case '%': while (*(this_sym++)) if (*this_sym == '%') { ++this_sym; break; } break; case '+': case '-': ++this_sym; break; } if (*this_sym == '*') ++this_sym; ret = regcomp(&preg, this_sym, flags); if (ret) { char err[256]; regerror(ret, &preg, err, sizeof(err)); err("regcomp of %s failed: %s", this_sym, err); } xarraypush(find_sym_regex_arr, &preg, sizeof(preg)); } } /* flatten arrays for display */ find_sym = array_flatten_str(find_sym_arr); find_lib = array_flatten_str(find_lib_arr); find_section = array_flatten_str(find_section_arr); /* let the format option override all other options */ if (out_format) { show_pax = show_phdr = show_textrel = show_rpath = \ show_needed = show_interp = show_bind = show_soname = \ show_textrels = show_perms = show_endian = show_size = \ show_osabi = show_eabi = 0; for (i = 0; out_format[i]; ++i) { if (!IS_MODIFIER(out_format[i])) continue; switch (out_format[++i]) { case '+': break; case '%': break; case '#': break; case 'F': break; case 'p': break; case 'f': break; case 'k': break; case 's': break; case 'N': break; case 'o': break; case 'a': break; case 'M': break; case 'Z': show_size = 1; break; case 'D': show_endian = 1; break; case 'I': show_osabi = 1; break; case 'Y': show_eabi = 1; break; case 'O': show_perms = 1; break; case 'x': show_pax = 1; break; case 'e': show_phdr = 1; break; case 't': show_textrel = 1; break; case 'r': show_rpath = 1; break; case 'n': show_needed = 1; break; case 'i': show_interp = 1; break; case 'b': show_bind = 1; break; case 'S': show_soname = 1; break; case 'T': show_textrels = 1; break; default: err("invalid format specifier '%c' (byte %i)", out_format[i], i+1); } } /* construct our default format */ } else { size_t fmt_len = 30; out_format = xmalloc(sizeof(char) * fmt_len); *out_format = '\0'; if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len); if (show_pax) xstrcat(&out_format, "%x ", &fmt_len); if (show_perms) xstrcat(&out_format, "%O ", &fmt_len); if (show_size) xstrcat(&out_format, "%Z ", &fmt_len); if (show_endian) xstrcat(&out_format, "%D ", &fmt_len); if (show_osabi) xstrcat(&out_format, "%I ", &fmt_len); if (show_eabi) xstrcat(&out_format, "%Y ", &fmt_len); if (show_phdr) xstrcat(&out_format, "%e ", &fmt_len); if (show_textrel) xstrcat(&out_format, "%t ", &fmt_len); if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len); if (show_needed) xstrcat(&out_format, "%n ", &fmt_len); if (show_interp) xstrcat(&out_format, "%i ", &fmt_len); if (show_bind) xstrcat(&out_format, "%b ", &fmt_len); if (show_soname) xstrcat(&out_format, "%S ", &fmt_len); if (show_textrels) xstrcat(&out_format, "%T ", &fmt_len); if (find_sym) xstrcat(&out_format, "%s ", &fmt_len); if (find_section) xstrcat(&out_format, "%k ", &fmt_len); if (find_lib) xstrcat(&out_format, "%N ", &fmt_len); if (!be_quiet) xstrcat(&out_format, "%F ", &fmt_len); } if (be_verbose > 2) printf("Format: %s\n", out_format); /* Now lock down the pidns since we know whether we'll be forking. */ if (!show_textrels || !be_verbose) security_init_pid(); /* now lets actually do the scanning */ if (load_cache_config) load_ld_cache_config(__PAX_UTILS_DEFAULT_LD_CACHE_CONFIG); if (scan_ldpath) scanelf_ldpath(); if (scan_envpath) scanelf_envpath(); if (!from_file && optind == argc && ttyname(0) == NULL && !scan_ldpath && !scan_envpath) from_file = "-"; if (from_file) { scanelf_from_file(from_file); from_file = *argv; } if (optind == argc && !scan_ldpath && !scan_envpath && !from_file) err("Nothing to scan !?"); while (optind < argc) { search_path = argv[optind++]; ret = scanelf_dir(search_path); } if (PAX_UTILS_CLEANUP) { /* clean up */ xarrayfree(find_sym_arr); xarrayfree(find_lib_arr); xarrayfree(find_section_arr); free(find_sym); free(find_lib); free(find_section); { size_t n; regex_t *preg; array_for_each(find_sym_regex_arr, n, preg) regfree(preg); xarrayfree(find_sym_regex_arr); } paxldso_cleanup(); } return ret; } static char **get_split_env(const char *envvar) { const char *delims = " \t\n"; char **envvals = NULL; char *env, *s; int nentry; if ((env = getenv(envvar)) == NULL) return NULL; env = xstrdup(env); if (env == NULL) return NULL; s = strtok(env, delims); if (s == NULL) { free(env); return NULL; } nentry = 0; while (s != NULL) { ++nentry; envvals = xrealloc(envvals, sizeof(*envvals) * (nentry+1)); envvals[nentry-1] = s; s = strtok(NULL, delims); } envvals[nentry] = NULL; /* don't want to free(env) as it contains the memory that backs * the envvals array of strings */ return envvals; } static void parseenv(void) { color_init(false); qa_textrels = get_split_env("QA_TEXTRELS"); qa_execstack = get_split_env("QA_EXECSTACK"); qa_wx_load = get_split_env("QA_WX_LOAD"); } static void cleanup(void) { if (!PAX_UTILS_CLEANUP) return; free(out_format); free(qa_textrels); free(qa_execstack); free(qa_wx_load); if (root_fd != AT_FDCWD) close(root_fd); } int main(int argc, char *argv[]) { int ret; security_init(true); if (argc < 2) usage(EXIT_FAILURE); parseenv(); ret = parseargs(argc, argv); fclose(stdout); cleanup(); return ret; } /* Match filename against entries in matchlist, return TRUE * if the file is listed */ static int file_matches_list(const char *filename, char **matchlist) { char **file; char *match; char buf[__PAX_UTILS_PATH_MAX]; if (matchlist == NULL) return 0; for (file = matchlist; *file != NULL; file++) { if (search_path) { snprintf(buf, sizeof(buf), "%s%s", search_path, *file); match = buf; } else { match = *file; } if (fnmatch(match, filename, 0) == 0) return 1; } return 0; } pax-utils-1.2.5/scanmacho.c000066400000000000000000000515771362221774600155760ustar00rootroot00000000000000/* * Copyright 2008-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * based on scanelf by: * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2012 Mike Frysinger - * for Darwin specific fun: * 2008-2013 Fabian Groffen - */ const char argv0[] = "scanmacho"; #include "paxinc.h" #define IS_MODIFIER(c) (c == '%' || c == '#' || c == '+') /* prototypes */ static int scanmacho_fatobj(fatobj *fobj); static int scanmacho_file(const char *filename, const struct stat *st_cache); static int scanmacho_from_file(const char *filename); static int scanmacho_dir(const char *path); static void scanmacho_envpath(void); static void usage(int status); static int parseargs(int argc, char *argv[]); /* variables to control behavior */ static const char *match_etypes = NULL; static char scan_envpath = 0; static char scan_symlink = 1; static char scan_archives = 0; static char dir_recurse = 0; static char dir_crossmount = 1; static char show_perms = 0; static char show_size = 0; static char show_rpath = 0; static char show_needed = 0; static char show_interp = 0; static char show_bind = 0; static char show_soname = 0; static char show_banner = 1; static char show_endian = 0; static char be_quiet = 0; static char be_verbose = 0; static char be_wewy_wewy_quiet = 0; static char be_semi_verbose = 0; static char *find_lib = NULL; static char *out_format = NULL; static char *search_path = NULL; static char g_match = 0; static int match_bits = 0; static unsigned int match_perms = 0; static void scanmacho_file_rpath( fatobj *fobj, char *found_rpath, char **ret, size_t *ret_len) { loadcmd *lcmd; uint32_t lc_rpath; if (!show_rpath) return; lcmd = firstloadcmd(fobj); lc_rpath = MGET(fobj->swapped, LC_RPATH); do { if (lcmd->lcmd->cmd == lc_rpath) { struct rpath_command *dlcmd = lcmd->data; char *rpath; rpath = lcmd->data + MGET(fobj->swapped, dlcmd->path.offset); if (*found_rpath) xchrcat(ret, ':', ret_len); xstrcat(ret, rpath, ret_len); *found_rpath = 1; } } while (nextloadcmd(lcmd)); if (be_wewy_wewy_quiet) return; if (!*found_rpath && !be_quiet) xstrcat(ret, " - ", ret_len); } static const char *macho_file_needed_lib( fatobj *fobj, char *found_needed, char *found_lib, int op, char **ret, size_t *ret_len ) { loadcmd *lcmd; uint32_t lc_load_dylib; if ((op == 0 && !show_needed) || (op == 1 && !find_lib)) return NULL; lcmd = firstloadcmd(fobj); lc_load_dylib = MGET(fobj->swapped, LC_LOAD_DYLIB); do { if (lcmd->lcmd->cmd == lc_load_dylib) { struct dylib_command *dlcmd = lcmd->data; char *needed; needed = lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset); if (op == 0) { if (!be_wewy_wewy_quiet) { if (*found_needed) xchrcat(ret, ',', ret_len); xstrcat(ret, needed, ret_len); } *found_needed = 1; } else { if (!strncmp(find_lib, needed, strlen(!g_match ? needed : find_lib))) { *found_lib = 1; free(lcmd); return (be_wewy_wewy_quiet ? NULL : needed); } } } } while (nextloadcmd(lcmd)); if (op == 0 && !*found_needed && be_verbose) warn("Mach-O lacks LC_LOAD_DYLIB commands: %s", fobj->filename); return NULL; } static char *macho_file_interp(fatobj *fobj, char *found_interp) { loadcmd *lcmd; uint32_t lc_load_dylinker; if (!show_interp) return NULL; lcmd = firstloadcmd(fobj); lc_load_dylinker = MGET(fobj->swapped, LC_LOAD_DYLINKER); do { if (lcmd->lcmd->cmd == lc_load_dylinker) { struct dylinker_command *dlcmd = lcmd->data; char *dylinker; dylinker = lcmd->data + MGET(fobj->swapped, dlcmd->name.offset); *found_interp = 1; free(lcmd); return (be_wewy_wewy_quiet ? NULL : dylinker); } } while (nextloadcmd(lcmd)); return NULL; } static char *macho_file_soname(fatobj *fobj, char *found_soname) { loadcmd *lcmd; uint32_t lc_id_dylib; if (!show_soname) return NULL; lcmd = firstloadcmd(fobj); lc_id_dylib = MGET(fobj->swapped, LC_ID_DYLIB); do { if (lcmd->lcmd->cmd == lc_id_dylib) { struct dylib_command *dlcmd = lcmd->data; char *soname; soname = lcmd->data + MGET(fobj->swapped, dlcmd->dylib.name.offset); *found_soname = 1; free(lcmd); return (be_wewy_wewy_quiet ? NULL : soname); } } while (nextloadcmd(lcmd)); return NULL; } /* scan a macho file and show all the fun stuff */ #define prints(str) ({ ssize_t ret = write(fileno(stdout), str, strlen(str)); ret; }) static int scanmacho_fatobj(fatobj *fobj) { unsigned long i; char found_rpath, found_needed, found_interp, found_soname, found_lib, found_file; static char *out_buffer = NULL; static size_t out_len; found_rpath = found_needed = found_interp = found_soname = \ found_lib = found_file = 0; if (be_verbose > 2) printf("%s: scanning file {%s,%s}\n", fobj->filename, get_machocputype(fobj), get_machosubcputype(fobj)); else if (be_verbose > 1) printf("%s: scanning file\n", fobj->filename); /* init output buffer */ if (!out_buffer) { out_len = sizeof(char) * 80; out_buffer = xmalloc(out_len); } *out_buffer = '\0'; /* show the header */ if (!be_quiet && show_banner) { for (i = 0; out_format[i]; ++i) { if (!IS_MODIFIER(out_format[i])) continue; switch (out_format[++i]) { case '+': break; case '%': break; case '#': break; case 'F': case 'p': case 'f': prints("FILE "); found_file = 1; break; case 'o': prints(" TYPE "); break; case 'M': prints("CPU "); break; case 'r': prints("RPATH "); break; case 'n': prints("NEEDED "); break; case 'i': prints("DYLINKER "); break; case 'b': prints("FLAGS "); break; case 'Z': prints("SIZE "); break; case 'S': prints("INSTALLNAME "); break; case 'N': prints("LIB "); break; case 'a': prints("ARCH "); break; case 'O': prints("PERM "); break; case 'D': prints("ENDIAN "); break; default: warnf("'%c' has no title ?", out_format[i]); } } if (!found_file) prints("FILE "); prints("\n"); found_file = 0; show_banner = 0; } /* dump all the good stuff */ for (i = 0; out_format[i]; ++i) { const char *out; const char *tmp; static char ubuf[sizeof(unsigned long)*2]; if (!IS_MODIFIER(out_format[i])) { xchrcat(&out_buffer, out_format[i], &out_len); continue; } out = NULL; be_wewy_wewy_quiet = (out_format[i] == '#'); be_semi_verbose = (out_format[i] == '+'); switch (out_format[++i]) { case '+': case '%': case '#': xchrcat(&out_buffer, out_format[i], &out_len); break; case 'F': found_file = 1; if (be_wewy_wewy_quiet) break; xstrcat(&out_buffer, fobj->filename, &out_len); break; case 'p': found_file = 1; if (be_wewy_wewy_quiet) break; tmp = fobj->filename; if (search_path) { ssize_t len_search = strlen(search_path); ssize_t len_file = strlen(fobj->filename); if (!strncmp(fobj->filename, search_path, len_search) && \ len_file > len_search) tmp += len_search; if (*tmp == '/' && search_path[len_search-1] == '/') tmp++; } xstrcat(&out_buffer, tmp, &out_len); break; case 'f': found_file = 1; if (be_wewy_wewy_quiet) break; xstrcat(&out_buffer, fobj->base_filename, &out_len); break; case 'r': scanmacho_file_rpath(fobj, &found_rpath, &out_buffer, &out_len); break; case 'o': out = get_machomhtype(fobj); break; case 'M': out = get_machocputype(fobj); break; case 'D': out = get_machoendian(fobj); break; case 'O': out = strfileperms(fobj->filename); break; case 'n': case 'N': out = macho_file_needed_lib(fobj, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break; case 'i': out = macho_file_interp(fobj, &found_interp); break; case 'b': get_machomhflags(fobj, &out_buffer, &out_len); break; case 'S': out = macho_file_soname(fobj, &found_soname); break; case 'a': out = get_machomtype(fobj); break; case 'Z': snprintf(ubuf, sizeof(ubuf), "%llu", (unsigned long long int)fobj->len); out = ubuf; break;; default: warnf("'%c' has no scan code?", out_format[i]); } if (out) { /* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */ if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL) xstrncat(&out_buffer, out, &out_len, (tmp-out)); else xstrcat(&out_buffer, out, &out_len); } } #define FOUND_SOMETHING() \ (found_rpath || found_needed || found_interp || found_soname || found_lib) if (!found_file && (!be_quiet || (be_quiet && FOUND_SOMETHING()))) { xchrcat(&out_buffer, ' ', &out_len); xstrcat(&out_buffer, fobj->filename, &out_len); } if (!be_quiet || (be_quiet && FOUND_SOMETHING())) { puts(out_buffer); fflush(stdout); } return 0; } /* scan a single Mach-O */ static int scanmacho_fat(const char *filename, int fd, size_t len) { int ret = 1; fatobj *fobj; fatobj *walk; /* verify this is real Mach-O */ if ((fobj = readmacho_fd(filename, fd, len)) == NULL) { if (be_verbose > 2) printf("%s: not a Mach-O object\n", filename); return ret; } switch (match_bits) { case 32: case 64: walk = fobj; do { if ((walk->ismach64 && match_bits == 64) || (!walk->ismach64 && match_bits == 32)) { ret = scanmacho_fatobj(walk); } } while (walk->next != NULL && (walk = walk->next)); goto label_done; default: break; } if (match_etypes) { char sbuf[128]; char ftype[32]; snprintf(sbuf, 128, ",%s,", match_etypes); walk = fobj; do { snprintf(ftype, 32, ",%s,", get_machomhtype(walk)); if (strstr(sbuf, ftype) != NULL) { ret = scanmacho_fatobj(walk); } } while (walk->next != NULL && (walk = walk->next)); goto label_done; } walk = fobj; do { ret = scanmacho_fatobj(walk); } while (walk->next != NULL && (walk = walk->next)); label_done: unreadmacho(fobj); return ret; } /* scan an archive of Mach-Os */ static int scanmacho_archive(const char *filename, int fd, size_t len) { archive_handle *ar; archive_member *m; char *ar_buffer; fatobj *fobj; fatobj *walk; ar = ar_open_fd(filename, fd, be_verbose); if (ar == NULL) return 1; ar_buffer = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, 0); while ((m = ar_next(ar)) != NULL) { fobj = readmacho_buffer(m->name, ar_buffer + lseek(fd, 0, SEEK_CUR), m->size); if (fobj) { walk = fobj; do { scanmacho_fatobj(walk); } while (walk->next != NULL && (walk = walk->next)); fobj->data = NULL; unreadmacho(fobj); } } munmap(ar_buffer, len); return 0; } /* scan a file which may be an Mach-O or an archive or some other * magical beast */ static int scanmacho_file(const char *filename, const struct stat *st_cache) { const struct stat *st = st_cache; struct stat symlink_st; int fd; /* always handle regular files and handle symlinked files if no -y */ if (S_ISLNK(st->st_mode)) { if (!scan_symlink) return 1; if (stat(filename, &symlink_st)) return 1; st = &symlink_st; } if (!S_ISREG(st->st_mode)) { if (be_verbose > 2) printf("%s: skipping non-file\n", filename); return 1; } if (match_perms) { if ((st->st_mode | match_perms) != st->st_mode) return 1; } if ((fd = open(filename, O_RDONLY)) == -1) return 1; if (scanmacho_fat(filename, fd, st->st_size) == 1 && scan_archives) /* if it isn't an Mach-O, maybe it's an .a archive */ scanmacho_archive(filename, fd, st->st_size); close(fd); return 0; } /* scan a directory for Mach-O files and print when we find one */ static int scanmacho_dir(const char *path) { register DIR *dir; register struct dirent *dentry; struct stat st_top, st; char buf[__PAX_UTILS_PATH_MAX]; size_t pathlen = 0, len = 0; int ret = 0; /* make sure path exists */ if (lstat(path, &st_top) == -1) { if (be_verbose > 2) printf("%s: does not exist\n", path); return 1; } /* ok, if it isn't a directory, assume we can open it */ if (!S_ISDIR(st_top.st_mode)) return scanmacho_file(path, &st_top); /* now scan the dir looking for fun stuff */ if ((dir = opendir(path)) == NULL) { warnf("could not opendir %s: %s", path, strerror(errno)); return 1; } if (be_verbose > 1) printf("%s: scanning dir\n", path); pathlen = strlen(path); while ((dentry = readdir(dir))) { if (!strcmp(dentry->d_name, ".") || !strcmp(dentry->d_name, "..")) continue; len = (pathlen + 1 + strlen(dentry->d_name) + 1); if (len >= sizeof(buf)) { warnf("Skipping '%s': len > sizeof(buf); %zu > %zu", path, len, sizeof(buf)); continue; } snprintf(buf, sizeof(buf), "%s%s%s", path, (path[pathlen-1] == '/') ? "" : "/", dentry->d_name); if (lstat(buf, &st) != -1) { if (S_ISREG(st.st_mode)) ret = scanmacho_file(buf, &st); else if (dir_recurse && S_ISDIR(st.st_mode)) { if (dir_crossmount || (st_top.st_dev == st.st_dev)) ret = scanmacho_dir(buf); } } } closedir(dir); return ret; } static int scanmacho_from_file(const char *filename) { FILE *fp = NULL; char *p; char path[__PAX_UTILS_PATH_MAX]; int ret = 0; if (strcmp(filename, "-") == 0) fp = stdin; else if ((fp = fopen(filename, "r")) == NULL) return 1; while ((fgets(path, __PAX_UTILS_PATH_MAX, fp)) != NULL) { if ((p = strchr(path, '\n')) != NULL) *p = 0; search_path = path; ret = scanmacho_dir(path); } if (fp != stdin) fclose(fp); return ret; } /* scan env PATH for paths */ static void scanmacho_envpath(void) { char *path, *p; path = getenv("PATH"); if (!path) err("PATH is not set in your env !"); path = xstrdup(path); while ((p = strrchr(path, ':')) != NULL) { scanmacho_dir(p + 1); *p = 0; } free(path); } /* usage / invocation handling functions */ /* Free Flags: c d e j k l s t u w x z G H I J K L P Q T U W X Y */ #define PARSE_FLAGS "pRmyArnibSN:gE:M:DO:ZaqvF:f:o:CBhV" #define a_argument required_argument static struct option const long_opts[] = { {"path", no_argument, NULL, 'p'}, {"recursive", no_argument, NULL, 'R'}, {"mount", no_argument, NULL, 'm'}, {"symlink", no_argument, NULL, 'y'}, {"archives", no_argument, NULL, 'A'}, {"rpath", no_argument, NULL, 'r'}, {"needed", no_argument, NULL, 'n'}, {"interp", no_argument, NULL, 'i'}, {"bind", no_argument, NULL, 'b'}, {"soname", no_argument, NULL, 'S'}, {"lib", a_argument, NULL, 'N'}, {"gmatch", no_argument, NULL, 'g'}, {"etype", a_argument, NULL, 'E'}, {"bits", a_argument, NULL, 'M'}, {"endian", no_argument, NULL, 'D'}, {"perms", a_argument, NULL, 'O'}, {"size", no_argument, NULL, 'Z'}, {"all", no_argument, NULL, 'a'}, {"quiet", no_argument, NULL, 'q'}, {"verbose", no_argument, NULL, 'v'}, {"format", a_argument, NULL, 'F'}, {"from", a_argument, NULL, 'f'}, {"file", a_argument, NULL, 'o'}, {"nocolor", no_argument, NULL, 'C'}, {"nobanner", no_argument, NULL, 'B'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {NULL, no_argument, NULL, 0x0} }; static const char * const opts_help[] = { "Scan all directories in PATH environment", "Scan directories recursively", "Don't recursively cross mount points", "Don't scan symlinks", "Scan archives (.a files)\n", "Print LC_RPATH information (ELF: RPATH/RUNPATH)", "Print LC_LOAD_DYLIB information (ELF: NEEDED)", "Print LC_LOAD_DYLINKER information (ELF: INTERP)", "Print flags from mach_header (ELF: BIND)", "Print LC_ID_DYLIB information (ELF: SONAME)", "Find a specified library", "Use strncmp to match libraries. (use with -N)", "Print only Mach-O files matching mach_header\n" " MH_OBJECT,MH_EXECUTE ... (ELF: etype)", "Print only Mach-O files matching numeric bits", "Print Endianness", "Print only Mach-O files matching octal permissions", "Print Mach-O file size", "Print all useful/simple info\n", "Only output 'bad' things", "Be verbose (can be specified more than once)", "Use specified format for output", "Read input stream from a filename", "Write output stream to a filename", "Don't emit color in output", "Don't display the header", "Print this help and exit", "Print version and exit", NULL }; /* display usage and exit */ static void usage(int status) { unsigned long i; printf("* Scan Mach-O binaries for stuff\n\n" "Usage: %s [options] [dir2 dirN file2 fileN ...]\n\n", argv0); printf("Options: -[%s]\n", PARSE_FLAGS); for (i = 0; long_opts[i].name; ++i) if (long_opts[i].has_arg == no_argument) printf(" -%c, --%-14s* %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); else printf(" -%c, --%-7s * %s\n", long_opts[i].val, long_opts[i].name, opts_help[i]); puts("\nFor more information, see the scanmacho(1) manpage"); exit(status); } /* parse command line arguments and preform needed actions */ static int parseargs(int argc, char *argv[]) { int i; const char *from_file = NULL; int ret = 0; opterr = 0; while ((i = getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) { switch (i) { case 'V': printf("pax-utils-%s: %s\n" "%s written for Gentoo by \n", VERSION, VCSID, argv0); exit(EXIT_SUCCESS); break; case 'h': usage(EXIT_SUCCESS); break; case 'f': if (from_file) warn("You prob don't want to specify -f twice"); from_file = optarg; break; case 'E': match_etypes = optarg; break; case 'M': match_bits = atoi(optarg); break; case 'O': if (sscanf(optarg, "%o", &match_perms) == -1) match_bits = 0; break; case 'o': { if (freopen(optarg, "w", stdout) == NULL) err("Could not open output stream '%s': %s", optarg, strerror(errno)); break; } case 'N': { if (find_lib) warn("You prob don't want to specify -N twice"); find_lib = optarg; break; } case 'F': { if (out_format) warn("You prob don't want to specify -F twice"); out_format = optarg; break; } case 'Z': show_size = 1; break; case 'g': g_match = 1; break; case 'y': scan_symlink = 0; break; case 'A': scan_archives = 1; break; case 'C': color_init(true); break; case 'B': show_banner = 0; break; case 'p': scan_envpath = 1; break; case 'R': dir_recurse = 1; break; case 'm': dir_crossmount = 0; break; case 'r': show_rpath = 1; break; case 'n': show_needed = 1; break; case 'i': show_interp = 1; break; case 'b': show_bind = 1; break; case 'S': show_soname = 1; break; case 'q': be_quiet = 1; break; case 'v': be_verbose = (be_verbose % 20) + 1; break; case 'a': show_perms = show_endian = show_bind = 1; break; case 'D': show_endian = 1; break; case ':': err("Option '%c' is missing parameter", optopt); case '?': err("Unknown option '%c' or argument missing", optopt); default: err("Unhandled option '%c'; please report this", i); } } /* let the format option override all other options */ if (out_format) { show_rpath = show_needed = show_interp = show_bind = show_soname = \ show_perms = show_endian = show_size = 0; for (i = 0; out_format[i]; ++i) { if (!IS_MODIFIER(out_format[i])) continue; switch (out_format[++i]) { case '+': break; case '%': break; case '#': break; case 'F': break; case 'p': break; case 'f': break; case 'k': break; case 'N': break; case 'o': break; case 'a': break; case 'M': break; case 'Z': show_size = 1; break; case 'D': show_endian = 1; break; case 'O': show_perms = 1; break; case 'r': show_rpath = 1; break; case 'n': show_needed = 1; break; case 'i': show_interp = 1; break; case 'b': show_bind = 1; break; case 'S': show_soname = 1; break; default: err("Invalid format specifier '%c' (byte %i)", out_format[i], i+1); } } /* construct our default format */ } else { size_t fmt_len = 30; out_format = xmalloc(sizeof(char) * fmt_len); *out_format = '\0'; if (!be_quiet) xstrcat(&out_format, "%a ", &fmt_len); if (!be_quiet) xstrcat(&out_format, "%o ", &fmt_len); if (show_perms) xstrcat(&out_format, "%O ", &fmt_len); if (show_size) xstrcat(&out_format, "%Z ", &fmt_len); if (show_endian) xstrcat(&out_format, "%D ", &fmt_len); if (show_rpath) xstrcat(&out_format, "%r ", &fmt_len); if (show_needed) xstrcat(&out_format, "%n ", &fmt_len); if (show_interp) xstrcat(&out_format, "%i ", &fmt_len); if (show_bind) xstrcat(&out_format, "%b ", &fmt_len); if (show_soname) xstrcat(&out_format, "%S ", &fmt_len); if (find_lib) xstrcat(&out_format, "%N ", &fmt_len); if (!be_quiet) xstrcat(&out_format, "%F ", &fmt_len); } if (be_verbose > 2) printf("Format: %s\n", out_format); /* now lets actually do the scanning */ if (scan_envpath) scanmacho_envpath(); if (!from_file && optind == argc && ttyname(0) == NULL && !scan_envpath) from_file = "-"; if (from_file) { scanmacho_from_file(from_file); from_file = *argv; } if (optind == argc && !scan_envpath && !from_file) err("Nothing to scan !?"); while (optind < argc) { search_path = argv[optind++]; ret = scanmacho_dir(search_path); } return ret; } int main(int argc, char *argv[]) { int ret; security_init(false); if (argc < 2) usage(EXIT_FAILURE); color_init(false); ret = parseargs(argc, argv); fclose(stdout); return ret; } pax-utils-1.2.5/security.c000066400000000000000000000152351362221774600155000ustar00rootroot00000000000000/* * Copyright 2015 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2015 Mike Frysinger - */ #include "paxinc.h" #ifdef __linux__ /* Older versions of Linux might not have these. */ #ifndef CLONE_NEWIPC #define CLONE_NEWIPC 0 #endif #ifndef CLONE_NEWNET #define CLONE_NEWNET 0 #endif #ifndef CLONE_NEWNS #define CLONE_NEWNS 0 #endif #ifndef CLONE_NEWPID #define CLONE_NEWPID 0 #endif #ifndef CLONE_NEWUTS #define CLONE_NEWUTS 0 #endif #ifdef __SANITIZE_ADDRESS__ /* ASAN does some weird stuff. */ # define ALLOW_PIDNS 0 #else # define ALLOW_PIDNS 1 #endif #ifdef WANT_SECCOMP # include /* Simple helper to add all of the syscalls in an array. */ static int pax_seccomp_rules_add(scmp_filter_ctx ctx, int syscalls[], size_t num) { static uint8_t prio; size_t i; for (i = 0; i < num; ++i) { if (syscalls[i] < 0) continue; if (seccomp_syscall_priority(ctx, syscalls[i], prio++) < 0) { warnp("seccomp_syscall_priority failed"); return -1; } if (seccomp_rule_add(ctx, SCMP_ACT_ALLOW, syscalls[i], 0) < 0) { warnp("seccomp_rule_add failed"); return -1; } } return 0; } #define pax_seccomp_rules_add(ctx, syscalls) pax_seccomp_rules_add(ctx, syscalls, ARRAY_SIZE(syscalls)) static void pax_seccomp_sigal(__unused__ int signo, siginfo_t *info, __unused__ void *context) { #ifdef si_syscall warn("seccomp violated: syscall %i", info->si_syscall); fflush(stderr); warn(" syscall = %s", seccomp_syscall_resolve_num_arch(seccomp_arch_native(), info->si_syscall)); fflush(stderr); #else warn("seccomp violated: syscall unknown (no si_syscall)"); #endif kill(getpid(), SIGSYS); _exit(1); } static void pax_seccomp_signal_init(void) { struct sigaction act; sigemptyset(&act.sa_mask); act.sa_sigaction = pax_seccomp_sigal, act.sa_flags = SA_SIGINFO | SA_RESETHAND; sigaction(SIGSYS, &act, NULL); } static void pax_seccomp_init(bool allow_forking) { /* Order determines priority (first == lowest prio). */ int base_syscalls[] = { /* We write the most w/scanelf. */ SCMP_SYS(write), SCMP_SYS(writev), SCMP_SYS(pwrite64), SCMP_SYS(pwritev), /* Then the stat family of functions. */ SCMP_SYS(newfstatat), SCMP_SYS(fstat), SCMP_SYS(fstat64), SCMP_SYS(fstatat64), SCMP_SYS(lstat), SCMP_SYS(lstat64), SCMP_SYS(stat), SCMP_SYS(stat64), /* Then the fd close func. */ SCMP_SYS(close), /* Then fd open family of functions. */ SCMP_SYS(open), SCMP_SYS(openat), /* Then the memory mapping functions. */ SCMP_SYS(mmap), SCMP_SYS(mmap2), SCMP_SYS(munmap), /* Then the directory reading functions. */ SCMP_SYS(getdents), SCMP_SYS(getdents64), /* Then the file reading functions. */ SCMP_SYS(pread64), SCMP_SYS(read), SCMP_SYS(readv), SCMP_SYS(preadv), /* Then the fd manipulation functions. */ SCMP_SYS(fcntl), SCMP_SYS(fcntl64), /* After this point, just sort the list alphabetically. */ SCMP_SYS(access), SCMP_SYS(brk), SCMP_SYS(capget), SCMP_SYS(chdir), SCMP_SYS(dup), SCMP_SYS(dup2), SCMP_SYS(dup3), SCMP_SYS(exit), SCMP_SYS(exit_group), SCMP_SYS(faccessat), SCMP_SYS(fchdir), SCMP_SYS(getpid), SCMP_SYS(gettid), SCMP_SYS(ioctl), SCMP_SYS(lseek), SCMP_SYS(_llseek), SCMP_SYS(mprotect), /* Syscalls listed because of compiler settings. */ SCMP_SYS(futex), /* Syscalls listed because of sandbox. */ SCMP_SYS(readlink), SCMP_SYS(readlinkat), SCMP_SYS(getcwd), /* Syscalls listed because of fakeroot. */ SCMP_SYS(msgget), SCMP_SYS(msgrcv), SCMP_SYS(msgsnd), SCMP_SYS(semget), SCMP_SYS(semop), SCMP_SYS(semtimedop), /* * Some targets like ppc and i386 implement the above * syscall as subcalls via ipc() syscall. * https://bugs.gentoo.org/675378 */ SCMP_SYS(ipc), }; int fork_syscalls[] = { SCMP_SYS(clone), SCMP_SYS(execve), SCMP_SYS(fork), SCMP_SYS(rt_sigaction), SCMP_SYS(rt_sigprocmask), SCMP_SYS(unshare), SCMP_SYS(vfork), SCMP_SYS(wait4), SCMP_SYS(waitid), SCMP_SYS(waitpid), }; scmp_filter_ctx ctx = seccomp_init(USE_DEBUG ? SCMP_ACT_TRAP : SCMP_ACT_KILL); if (!ctx) { warnp("seccomp_init failed"); return; } if (pax_seccomp_rules_add(ctx, base_syscalls) < 0) goto done; if (allow_forking) if (pax_seccomp_rules_add(ctx, fork_syscalls) < 0) goto done; /* We already called prctl. */ seccomp_attr_set(ctx, SCMP_FLTATR_CTL_NNP, 0); if (USE_DEBUG) pax_seccomp_signal_init(); #ifndef __SANITIZE_ADDRESS__ /* ASAN does some weird stuff. */ if (seccomp_load(ctx) < 0) { /* We have to assume that EINVAL == CONFIG_SECCOMP is disabled. */ if (errno != EINVAL) warnp("seccomp_load failed"); } #endif done: seccomp_release(ctx); } #else # define pax_seccomp_init(allow_forking) #endif static int ns_unshare(int flags) { int flag, ret = 0; /* Try to oneshot it. Maybe we'll get lucky! */ if (unshare(flags) == 0) return flags; /* No access at all, so don't waste time below. */ else if (errno == EPERM) return ret; /* * We have to run these one permission at a time because if any are * not supported (too old a kernel, or it's disabled), then all of * them will be rejected and we won't know which one is a problem. */ /* First the ones that work against the current process. */ flag = 1; while (flags) { if (flags & flag) { if (unshare(flag) == 0) ret |= flag; flags &= ~flag; } flag <<= 1; } return ret; } void security_init_pid(void) { int flags; if (!ALLOW_PIDNS || CLONE_NEWPID == 0) return; flags = ns_unshare(CLONE_NEWPID); if (USE_SLOW_SECURITY) { if (flags & CLONE_NEWPID) if (vfork() == 0) _exit(0); } } void security_init(bool allow_forking) { int flags; if (!ALLOW_PIDNS) allow_forking = true; /* Drop all possible caps for us and our children. */ #ifdef PR_SET_NO_NEW_PRIVS /* New to linux-3.5 */ prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); #endif #ifdef PR_SET_SECUREBITS /* New to linux-2.6.26 */ # ifdef SECBIT_KEEP_CAPS_LOCKED /* New to linux-2.6.33 (all SECBIT_xxx) */ prctl(PR_SET_SECUREBITS, SECBIT_KEEP_CAPS_LOCKED | SECBIT_NO_SETUID_FIXUP | SECBIT_NO_SETUID_FIXUP_LOCKED | SECBIT_NOROOT | SECBIT_NOROOT_LOCKED, 0, 0, 0); # endif #endif /* None of the pax tools need access to these features. */ flags = CLONE_NEWIPC | CLONE_NEWUTS; /* Would be nice to leverage mount/net ns, but they're just way too slow. */ if (USE_SLOW_SECURITY) flags |= CLONE_NEWNET | CLONE_NEWNS; if (!allow_forking) flags |= CLONE_NEWPID; flags = ns_unshare(flags); if (USE_SLOW_SECURITY) { /* We spawn one child and kill it so the kernel will fail in the future. */ if (flags & CLONE_NEWPID) if (vfork() == 0) _exit(0); } pax_seccomp_init(allow_forking); } #endif pax-utils-1.2.5/security.h000066400000000000000000000014051362221774600154770ustar00rootroot00000000000000/* Various security related features. * * Copyright 2015 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2015 Mike Frysinger - */ #ifndef _PAX_SECURITY_H #define _PAX_SECURITY_H /* Whether to enable features that significantly impact speed. */ #ifdef SLOW_SECURITY # define USE_SLOW_SECURITY 1 #else # define USE_SLOW_SECURITY 0 #endif #ifdef __linux__ /* Lock down the runtime; allow_forking controls whether to use a pidns. */ void security_init(bool allow_forking); /* Disable forking; usable only when allow_forking above was true. */ void security_init_pid(void); #else static inline void security_init(bool allow_forking) {} static inline void security_init_pid(void) {} #endif #endif pax-utils-1.2.5/symtree.sh000077500000000000000000000037511362221774600155140ustar00rootroot00000000000000#!/bin/bash argv0=${0##*/} usage() { cat <<-EOF Display libraries that satisfy undefined symbols, as a tree Usage: ${argv0} [options] Options: -x Run with debugging -h Show this help output EOF exit ${1:-0} } sym_list() { # with large strings, bash is much slower than sed local type=$1; shift echo "%${type}%$@" | sed "s:,:,%${type}%:g" } find_elf() { echo "$2" | awk -F/ -v lib="$1" '$NF == lib {print}' } show_elf() { local elf=$1 local rlib lib libs local resolved=$(realpath "${elf}") local resolved_libs=$(lddtree -l "${resolved}") printf "%s\n" "${resolved}" libs=$(scanelf -qF '#F%n' "${resolved}") local u uu d dd u=$(scanelf -q -F'%s#F' -s'%u%' "${elf}") for lib in ${libs//,/ } ; do lib=${lib##*/} rlib=$(find_elf "${lib}" "${resolved_libs}") d=$(scanelf -qF'%s#F' -s`sym_list d "${u}"` "${rlib}") if [[ -n ${d} ]] ; then dd=${dd:+${dd},}${d} printf "%4s%s => %s\n" "" "${lib}" "${d}" else printf "%4s%s => %s\n" "" "${lib}" "!?! useless link !?!" fi done uu= for u in `echo "${u}" | sed 's:,: :g'` ; do [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u} done if [[ -n ${uu} ]] ; then u=${uu} dd=$(scanelf -qF'%s#F' -s`sym_list w "${u}"` "${resolved}") if [[ -n ${dd} ]] ; then printf "%4s%s => %s\n" "" "WEAK" "${dd}" uu= for u in `echo "${u}" | sed 's:,: :g'` ; do [[ ,${dd}, != *,${u},* ]] && uu=${uu:+${uu},}${u} done fi if [[ -n ${uu} ]] ; then printf "%4s%s => %s\n" "" "UNRESOLVED" "${uu}" fi fi } SET_X=false while getopts hx OPT ; do case ${OPT} in x) SET_X=true;; h) usage;; *) usage 1;; esac done shift $((OPTIND - 1)) [[ -z $1 ]] && usage 1 ${SET_X} && set -x ret=0 for elf in "$@" ; do if [[ ! -e ${elf} ]] ; then error "${elf}: file does not exist" elif [[ ! -r ${elf} ]] ; then error "${elf}: file is not readable" elif [[ -d ${elf} ]] ; then error "${elf}: is a directory" else [[ ${elf} != */* ]] && elf="./${elf}" show_elf "${elf}" 0 "" fi done exit ${ret} pax-utils-1.2.5/tests/000077500000000000000000000000001362221774600146215ustar00rootroot00000000000000pax-utils-1.2.5/tests/Makefile000066400000000000000000000006531362221774600162650ustar00rootroot00000000000000SUBDIRS = $(patsubst %/Makefile,%,$(wildcard */Makefile)) abs_top_srcdir = $(realpath $(PWD)/..) abs_top_builddir = $(realpath $(PWD)/..) # DO NOT STARE AT THE SUN all: %:; $(MAKE) `printf '%s_$@_ ' $(SUBDIRS)` _words = $(subst _, ,$1) _dir = $(firstword $(call _words,$@)) _targ = $(lastword $(call _words,$@)) %_:; $(MAKE) -C $(_dir) $(_targ) srcdir=$(abs_top_srcdir)/tests/$(_dir) builddir=$(abs_top_builddir)/tests/$(_dir) pax-utils-1.2.5/tests/lddtree/000077500000000000000000000000001362221774600162445ustar00rootroot00000000000000pax-utils-1.2.5/tests/lddtree/Makefile000066400000000000000000000002461362221774600177060ustar00rootroot00000000000000all: check %.check: ./dotest-$(@:.check=) test check: sh.check ifneq ($(USE_PYTHON),no) test check: py.check cmp.check endif clean: .PHONY: all check clean test pax-utils-1.2.5/tests/lddtree/dotest-cmp000077500000000000000000000012041362221774600202460ustar00rootroot00000000000000#!/bin/bash . "${0%/*}"/../lib.sh # # make sure list output matches # for sfx in py sh ; do lddtree.${sfx} -l /bin/bash > "${builddir}"/lddtree.${sfx}.list & done wait if diff -u "${builddir}"/lddtree.*.list ; then pass "lddtree -l /bin/bash" else fail "lddtree -l /bin/bash" fi rm -f "${builddir}"/lddtree.*.list # # Same as above but with the -a flag # for sfx in py sh ; do lddtree.${sfx} -l -a /bin/bash > "${builddir}"/lddtree.${sfx}.list-all & done wait if diff -u "${builddir}"/lddtree.*.list-all ; then pass "lddtree -l -a /bin/bash" else fail "lddtree -l -a /bin/bash" fi rm -f "${builddir}"/lddtree.*.list-all exit ${ret} pax-utils-1.2.5/tests/lddtree/dotest-py000077500000000000000000000000501362221774600201150ustar00rootroot00000000000000#!/bin/bash sfx=${0##*-} . ./dotest-sfx pax-utils-1.2.5/tests/lddtree/dotest-sfx000066400000000000000000000002741362221774600202720ustar00rootroot00000000000000#!/bin/bash . "${0%/*}"/../lib.sh # # smoke tests of sorts # lddtree.${sfx} /bin/bash | \ grep -i 'none' > "${builddir}"/lddtree.${sfx}.smoke testit lddtree.${sfx}.smoke exit ${ret} pax-utils-1.2.5/tests/lddtree/dotest-sh000077500000000000000000000000501362221774600200770ustar00rootroot00000000000000#!/bin/bash sfx=${0##*-} . ./dotest-sfx pax-utils-1.2.5/tests/lib.sh000066400000000000000000000014711362221774600157260ustar00rootroot00000000000000if [[ -z ${abs_top_builddir} ]] ; then srcdir=$(cd "${0%/*}" && pwd) top_srcdir=$(cd "${srcdir}/../.." && pwd) builddir=${srcdir} top_builddir=${top_srcdir} else mkdir -p "${builddir}" top_srcdir=${abs_top_srcdir} top_builddir=${abs_top_builddir} fi [ -e /etc/init.d/functions.sh ] && source /etc/init.d/functions.sh PATH="${top_srcdir}:${top_builddir}:${PATH}" unset ROOT # who knows! ret=0 pass() { echo "${GOOD}PASS${NORMAL}: $*" } fail() { ret=1 echo "${BAD}FAIL${NORMAL}: $*" >&2 } testit() { local tret=0 err case $# in 1) if [[ -s ${builddir}/$1 ]] ; then tret=1 err=$(<"${builddir}/$1") fi ;; 2) if ! err=$(diff -u "${builddir}/$1" "${srcdir}/$2") ; then tret=1 fi esac if [[ ${tret} -eq 0 ]] ; then pass "$1" else fail "$1" echo "${err}" fi rm -f "${builddir}/$1" } pax-utils-1.2.5/tests/scanelf/000077500000000000000000000000001362221774600162345ustar00rootroot00000000000000pax-utils-1.2.5/tests/scanelf/Makefile000066400000000000000000000001101362221774600176640ustar00rootroot00000000000000all: check test check: ./dotest clean: .PHONY: all check clean test pax-utils-1.2.5/tests/scanelf/dotest000077500000000000000000000003121362221774600174600ustar00rootroot00000000000000#!/bin/bash . "${0%/*}"/../lib.sh # # simple scanelf symbol checks # scanelf -qsmain -F'%s %f' "${top_builddir}"/scanelf \ > "${builddir}"/scanelf.simple testit scanelf.simple{,.good} exit ${ret} pax-utils-1.2.5/tests/scanelf/scanelf.simple.good000066400000000000000000000000151362221774600220050ustar00rootroot00000000000000main scanelf pax-utils-1.2.5/tests/source/000077500000000000000000000000001362221774600161215ustar00rootroot00000000000000pax-utils-1.2.5/tests/source/Makefile000066400000000000000000000001101362221774600175510ustar00rootroot00000000000000all: check test check: ./dotest clean: .PHONY: all check clean test pax-utils-1.2.5/tests/source/dotest000077500000000000000000000055411362221774600173560ustar00rootroot00000000000000#!/bin/bash . "${0%/*}"/../lib.sh findfiles() { find "${top_srcdir}" \ '(' -type d -a '(' -name .git -o -name autotools ')' -prune ')' \ -o '(' '(' -name '*.[ch]' -a ! -name 'config.h' ')' -print0 ')' } # # check for misc common typos # find "${top_srcdir}" \ '(' -type d -a '(' -name .git -o -name tests ')' -prune ')' \ -o '(' -type f -a -print0 ')' | xargs -0 \ grep -n -I \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ -e '\' \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.typos testit src.typos # # don't allow obsolete functions # findfiles | xargs -0 \ grep -n -E -e '\<(bcmp|bcopy|bzero|getwd|index|mktemp|rindex|utimes)\>[[:space:]]*\(' \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.obsolete.funcs testit src.obsolete.funcs # # make sure people use our constants # findfiles | xargs -0 \ grep -n -E -e '\' | grep -v __PAX_UTILS_PATH_MAX \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.bad.constants testit src.bad.constants # # don't allow obsolete headers # findfiles | xargs -0 \ grep -n -E -e '\<(malloc|memory|sys/(errno|fcntl|signal|stropts|termios|unistd))\.h\>' \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.obsolete.headers testit src.obsolete.headers # # make sure people use the x* helper funcs # xfuncs=$(printf '%s|' $(sed -n 's:.*x\([^(]*\)(.*:\1:p' "${top_srcdir}"/xfuncs.h)) xfuncs=${xfuncs:0:${#xfuncs}-1} findfiles | xargs -0 \ grep -n -E -e "\<(${xfuncs})[[:space:]]*\(" \ | grep -v xfuncs.c \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.use.xfuncs testit src.use.xfuncs # # check for style # findfiles | xargs -0 \ grep -n -E \ -e '\<(for|if|switch|while)\(' \ -e '\<(for|if|switch|while) \( ' \ -e ' ;' \ -e '[[:space:]]$' \ -e '\){' \ -e '(^|[^:])//' \ | sed -e "s:^\.\./\.\./::g" > "${builddir}"/src.style testit src.style # # Auto clean up the space issues # while read -d'\0' x; do case ${x} in */elf.h) continue ;; # Not our files esac ./space "${x}" > "${builddir}/${x}~" if ! diff -u "${x}" "${builddir}/${x}~" ; then echo "New file: ${x}~" else rm -f "${builddir}/${x}~" fi done > "${builddir}"/src.space < <(findfiles) testit src.space # # Make sure we don't keep re-importing stuff into elf.h that # breaks non-GNU systems. #507470 # grep -E "features.h|_DECLS" "${top_srcdir}"/elf.h > "${builddir}"/src.elf.h testit src.elf.h # # Python checks # if pyflakes /dev/null; then find "${top_srcdir}" \ '!' -ipath '*/tests/*' \ -name '*.py' \ -exec pyflakes {} + > "${builddir}"/src.pyflakes testit src.pyflakes fi exit ${ret} pax-utils-1.2.5/tests/source/space000077500000000000000000000005471362221774600171500ustar00rootroot00000000000000#!/bin/sh # Usage: space # Trim trailing whitespace and consecutive newlines. i=$1 if [ $# != 1 ] ; then cat <<-EOF Usage: ${0##/*} Trim trailing whitespace and consecutive newlines. EOF fi sed -E '/[[:space:]]+$/s:[[:space:]]+$::' "$i" | \ awk '{ if (NF == 0) { while (NF == 0) if (getline == 0) exit print "" } print }' pax-utils-1.2.5/travis/000077500000000000000000000000001362221774600147675ustar00rootroot00000000000000pax-utils-1.2.5/travis/autotools.tar.xz000066400000000000000000000217701362221774600201770ustar00rootroot000000000000007zXZִF!t/#]0J0bHN"z S:ܦI,Yq 59FL'sW Ϯfu맭nI&CK m9 >Q1~ފn3nsz~ A˽Ac șw[:LCs!wf/`8̶{oV I)>*ZYpp\~Q[a\+Qv|.bڧ:YBކ&v3彷lET*Y}|3fz X>ls3qN\ikB'sΝz!t侞K} F#Mȡˢ\dzV~m |L)J/A xc6^t@NGvd0%=Uc 2үoĮ8j!jm\D(}QfdO5kS/*Q'hLpr-}ˮ9A9R!;ܾa[:3Y=P%Uo5Nwжx#;[&-{ǠDͧy *bx~^D#J. Z;_ pNZ$\H+=jfJRUIZفf«ѭkp 2_ ԧ:B2rCm$j3) b?OgODugاWsn^pd\U*QƒG5q֣<Ǒ\Q w__݉Y6@ nrc" uGgFc&-[0jaOJzc dr\u f fdWyUZ3Dln2sҠh W~rLM#"VYqW0 42[s:bjP!JfrcnLi SXxY4+W 7{kv+@ Jց?UѦ"qW'f&%jx|U9" tF2iC+V|[yAFZ6%hr("%s:)\{gf 15:Wݜ>ƱB 0ݥ1TJ JX` DFz_)roW<[_6IoD1wMƫ / h%ڎ2}֛O#Ň.BS oFD:M=e v4r;{SˮƬg>K}3n^T˦P.]aNaFF~̿h1,?u`K@I,(.CuiH [J7З1}t?khEsn]T3痆ZzQ'-_JSRψO]^\ƠoJgUgwೀdzXeۅ 3/?%뀰(MW?9uZX:s_YrDق1ߘ> 50+7 iZoQ@C¯oFuAN"uEɊON-Zj8>\ݿ, E4ֵkj7yk &}_5|񱾏ctHAaSf=_f+Duօx9x/sβ<6lU'ŗq&:*/X"ԇ4'oNHsbg1j܅4bZt_/UzwW5 η*zLAz\&d%-w^񵤱K 9CQg,~.^e+X=nj؂鋈s'3('0'/d<@+XeW`,a= ՇSl`+Š䙾&1N@V*Eg_h9aG*<X( JU5T|BK+^wKzὛm&.SmMN HeTkӒ#i]'rztmrTQ|i*?" ‘nصSŔx0w!#&-1F]p#)xåP1$a@}s ^z-AlA{/~*Њ2^xFi7JY}&C› B֛pf1}V_7~'iSwl>Z,1aa .S'V.z&WN.ӑCـ͂2m.ϞG.uQKncRlޛ4U܏$ujLrfE[Mgw+r &c`j`J R X!ycNGﳒsc/ AV&meKZּM {ʻi U/sE?hIhzfC6 X+DsɭnTѠKkܹ #fSIbPk<R D<ン'm^s9hM,hsfv 7Bg4 +i50tTv z+E1Etz}JEm|m06.M*&+g@(܇zZƥxuk7{REoEJi!~u @γ'D }5u(m,k鰈=1J̓nw jrh XޯQ&<$Ť/*q0!gN w;hMxcE,,#;szϧ#'.LdueH{+rMX˸ƥ8+؎k)eOoyNd2]I7{TN\#5\ Ej f42]kz)_nig=ȸO6%#"ZGODz%/E^sN@@!gǼ8SThdtYpN Zԧr_&K܉XNXㄞU]: BSI+<<h÷;ܞ#bB}¼}J#] ݥiѝ!!QgmM攇PMy% SJ*b9(ioBX$I Cs\ #Ea  y^($=&˞f=[)ʶ t} d0)neuE3Cyh2ֵVYZoU*dc4utÛ9Qw_ Fƍ Q }MXmqo2%pco Ad)KF_=$o[$DKya.=(Jx&*'x5*t(URO7V͇)/1?|G9, rU4(ieda-rf0oa{r@6LԌٗYxRyN2qzGUھq!1!V}}˙9.u0H$xn&/Sfa=zҜcqI֖3R9}{ N[+3k[嬫AXQ!{]'IG1'ChX ;h$ ઔRtI:G^PF mp^3 `LXg~4ڲ"=:CCL7:LB goG&h(Hd3UѴ4Y(O `zB">|>wա}6򍘞]x> L.&P$U{_5qNuH^<@ExwAC{:HK'yE4$tD`c#ѕُ|F/|{kpyoS9~^\Qhh^Cy2Vl_)!UbSSL=gaA֡,5a~Rީ <~]Г"[%CMK%#F'Lo338S8]إ^cA9ɇ~7}Ǵ1pP}Pq]u&1yw?x^%`:eDųb(Y9Z.Dimhs_ tjt.I pt4TBk;,nˣ9/L"8Fl2UX! мyŎ&awt%nNpeD݊\8lF?Ju"_q7dR4#eDo{J p%b[M<~ H'Q ]|*_P H盱FG187Cl:}[Z&#J_:oÝ-h)7O̲W~-PYdo!$/-HQ7-~'g}=Z&Жҳ+$1ܫ, gÐo>*[oWׄ OM~ͫR Ph!NF ]O#alD)Tj𴿿BJ1~\z!mγ|vC0RG,]1bn||ؘRk#gA-;ݿB-ե}|~Ma1{ghh_HEIտka-`7=T{(X!,n4~fڿk Esdկ1dEmwMNFG2Lx߯2_=ϞmtDDGFe ?xGzx6ݹ`{wwgd3Hr+<ZNhCtލW~HraRV{^1ODz3fIg&ۑqZNmWW&bk̃L6-K冋WsK#ዃd9+ sPޢC(Q1VfFZEBĝ˧[ p h^ulv]6 z-|䕉G|7؋D^PnZKD ,y:8*X%!I8VW'I/` b9qV a`">QFz'.%a.PбOf aQľH;"ֱ =N}#%:$2;bx@f1WyN]5ׯKDҤlRb}k/}" XfL|_c15F Ү%SS l?9rg;,]FJzD.l)支4||߶!PY=]) ѓ( F0LŸV&9{a@=ԅv\&+oBc !#%WwHЍ&>yb:Je Z $$/ǍIk2Ă9N%oPq%f6ż [Zb~D?vRZ@,ƖYٶnЋJt.|R @n*K:ևrҮ:ނҦ= Vt/Q^6qq(k|TE.%+L$Ҩ.c'"ʾeN>q3ibBhj5~#>4QIO F=)噾mQȆvkBgnDϦ՛v9""T$[[l)yE爳PDXQ$Ÿ-MFx,DTWC>ײ_]*{r˦7:J4/цS*GEB UEٶ&;V' N.6ɬ&EIҒE M%aN.`'+}ש<u.9<JG+xu} b&?5So|d.|ƒDka$ Te6bO> /cvStHQxäMXb}ÛD:av2EjفHF&0ǵ4%"|#$TfA{2SB\G1X[2nSҸݺ,'{<`|6+tίZubcEKH?1Kix&F/kl143a>NJQxwRjgQ"vK!yz.-I8^?x쬵N\ =0+5|0aUU 3Q޼?uZ.Nԫ=y|a|vk-Zc*Xk<}EJzՈ'=l tқ%(OBX&O50Z34[b^v{Yh]aOYX-df9A?c}Ur+z(&6wRur{6vd@ezՓ.y~=x֒!X6; jn }%pԫ"9Y4%GAG*GgYZpax-utils-1.2.5/travis/lib.sh000066400000000000000000000011541362221774600160720ustar00rootroot00000000000000#!/bin/bash # Common funcs for working w/Travis. travis_fold() { if [[ -n ${TRAVIS_OS_NAME} ]] ; then printf 'travis_fold:%s:%s\r\n' "$@" | sed 's: :_:g' fi } if [[ -n ${TRAVIS_OS_NAME} ]] ; then whitebg=$(tput setab 7) blackfg=$(tput setaf 0) normal=$(tput sgr0) else whitebg= blackbg= normal= fi v() { local fold="" case $1 in --fold=*) fold=${1:7}; shift;; esac if [[ -n ${fold} ]] ; then travis_fold start "${fold}" echo "\$ $*" "$@" travis_fold end "${fold}" else echo "${whitebg}${blackfg}\$ $*${normal}" "$@" fi } ncpus=$(getconf _NPROCESSORS_ONLN) m() { v make -j${ncpus} "$@" } pax-utils-1.2.5/travis/main.sh000077500000000000000000000042721362221774600162570ustar00rootroot00000000000000#!/bin/bash -e . "${0%/*}"/lib.sh # We have to do this by hand rather than use the coverity addon because of # matrix explosion: https://github.com/travis-ci/travis-ci/issues/1975 # We also do it by hand because when we're throttled, the addon will exit # the build immediately and skip the main script! coverity_scan() { local reason [[ ${TRAVIS_JOB_NUMBER} != *.1 ]] && reason="not first build job" [[ -n ${TRAVIS_TAG} ]] && reason="git tag" [[ ${TRAVIS_PULL_REQUEST} == "true" ]] && reason="pull request" if [[ -n ${reason} ]] ; then echo "Skipping coverity scan due to: ${reason}" return fi export COVERITY_SCAN_PROJECT_NAME="${TRAVIS_REPO_SLUG}" export COVERITY_SCAN_NOTIFICATION_EMAIL="vapier@gentoo.org" export COVERITY_SCAN_BUILD_COMMAND="make -j${ncpus}" export COVERITY_SCAN_BUILD_COMMAND_PREPEND="git clean -q -x -d -f; git checkout -f" export COVERITY_SCAN_BRANCH_PATTERN="master" curl -s "https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh" | bash || : } main() { if [[ ${TRAVIS_OS_NAME} == "osx" ]] ; then # Note: Linux deps are maintained in .travis.yml. v --fold="brew_update" brew update v --fold="brew_install" brew install xmlto xz fi # See if we have to bootstrap gnulib. This is the case on OS X, and on # Linux until they whitelist the package: # https://github.com/travis-ci/apt-package-whitelist/issues/727 if ! gnulib-tool --version >&/dev/null ; then if [[ ! -d ../gnulib ]] ; then v --fold="git_clone_gnulib" \ git clone --depth=1 https://github.com/coreutils/gnulib.git ../gnulib else pushd ../gnulib v --fold="git_pull_gnulib" git pull popd fi export PATH="${PATH}:${PWD}/../gnulib" fi if [[ ${TRAVIS_OS_NAME} == "linux" ]] ; then # Standard optimized build. m m check # Debug build w/ASAN and such enabled. m debug m check fi # Autotools based build. v ./autogen.sh if [[ ${TRAVIS_OS_NAME} == "linux" ]] ; then v --fold="configure" ./configure m V=1 distcheck else # ELF checks don't work on OS X -- no ELFs! v ./configure m V=1 fi # Do scans last as they like to dirty the tree and some tests # expect a clean tree (like code style checks). v --fold="coverity_scan" coverity_scan } main "$@" pax-utils-1.2.5/xfuncs.c000066400000000000000000000042651362221774600151400ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2012 Mike Frysinger - */ #include "paxinc.h" char *xstrdup(const char *s) { char *ret = strdup(s); if (!ret) err("Could not strdup(): %s", strerror(errno)); return ret; } void *xmalloc(size_t size) { void *ret = malloc(size); if (!ret) err("Could not malloc() %zu bytes", size); return ret; } void *xzalloc(size_t size) { return memset(xmalloc(size), 0, size); } void *xrealloc(void *ptr, size_t size) { void *ret = realloc(ptr, size); if (!ret) err("Could not realloc() %zu bytes", size); return ret; } void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n) { bool init; size_t new_len; init = *curr_len ? false : true; new_len = (init ? 0 : strlen(*dst)) + strlen(src); if (*curr_len <= new_len) { *curr_len = new_len + (*curr_len / 2) + 1; *dst = realloc(*dst, *curr_len); if (!*dst) err("could not realloc() %zu bytes", *curr_len); if (init) *dst[0] = '\0'; } if (n) strncat(*dst, src, n); else strcat(*dst, src); } void xchrcat(char **dst, const char append, size_t *curr_len) { static char my_app[2]; my_app[0] = append; my_app[1] = '\0'; xstrcat(dst, my_app, curr_len); } void *xmemdup(const void *src, size_t n) { void *ret = xmalloc(n); memcpy(ret, src, n); return ret; } void xarraypush(array_t *arr, const void *ele, size_t ele_len) { size_t n = arr->num++; /* We allocate one excess element so that array_for_each can * always safely fetch the next element. It's minor memory * wastage to avoid having to do a len check all the time. */ arr->eles = xrealloc_array(arr->eles, arr->num + 1, sizeof(ele)); arr->eles[n] = xmemdup(ele, ele_len); } void xarrayfree(array_t *arr) { array_t blank = array_init_decl; size_t n; for (n = 0; n < arr->num; ++n) free(arr->eles[n]); free(arr->eles); *arr = blank; } char *array_flatten_str(array_t *array) { size_t n, len = 0; char *str, *ret = NULL; array_for_each(array, n, str) { if (ret) xchrcat(&ret, ',', &len); xstrcat(&ret, str, &len); } return ret; } pax-utils-1.2.5/xfuncs.h000066400000000000000000000027351362221774600151450ustar00rootroot00000000000000/* * Copyright 2003-2012 Gentoo Foundation * Distributed under the terms of the GNU General Public License v2 * * Copyright 2003-2012 Ned Ludd - * Copyright 2004-2012 Mike Frysinger - */ #ifndef __XFUNCS_H__ #define __XFUNCS_H__ char *xstrdup(const char *s); void *xmalloc(size_t size); void *xzalloc(size_t size); void *xrealloc(void *ptr, size_t size); void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n); #define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0) void xchrcat(char **dst, const char append, size_t *curr_len); void *xmemdup(const void *src, size_t n); typedef struct { void **eles; size_t num; } array_t; void xarraypush(array_t *array, const void *ele, size_t ele_len); #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/) void xarrayfree(array_t *array); #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size)) /* The assignment after the check is unfortunate as we do a non-NULL check (we * already do not permit pushing of NULL pointers), but we can't put it in the * increment phase as that will cause a load beyond the bounds of valid memory. */ #define array_for_each(arr, n, ele) \ for (n = 0, ele = array_cnt(arr) ? arr->eles[n] : NULL; \ n < array_cnt(arr) && (ele = arr->eles[n]); \ ++n) #define array_init_decl { .eles = NULL, .num = 0, } #define array_cnt(arr) (arr)->num char *array_flatten_str(array_t *array); #endif