libelf.h revision 3cbdd387c752999255aea91600b5cfdefbeac7d0
1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Interface for libelf. 2cb6d865011ad98a8ac2018f072f396a2268739caRoland McGrath Copyright (C) 1998, 1999, 2000, 2002, 2004, 2005, 2006, 2007 Red Hat, Inc. 3361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper This file is part of Red Hat elfutils. 4361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 5361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is free software; you can redistribute it and/or modify 6361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper it under the terms of the GNU General Public License as published by the 7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Free Software Foundation; version 2 of the License. 8361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 9361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is distributed in the hope that it will be useful, but 10361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper WITHOUT ANY WARRANTY; without even the implied warranty of 11361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper General Public License for more details. 13361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 14361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper You should have received a copy of the GNU General Public License along 15361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper with Red Hat elfutils; if not, write to the Free Software Foundation, 161e9ef50681e20ef14c2ba38aef37a71ff148be08Ulrich Drepper Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. 17361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 18361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper In addition, as a special exception, Red Hat, Inc. gives You the 19361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper additional right to link the code of Red Hat elfutils with code licensed 20361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper under any Open Source Initiative certified open source license 21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper (http://www.opensource.org/licenses/index.php) which requires the 22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper distribution of source code with any binary distribution and to 23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper distribute linked combinations of the two. Non-GPL Code permitted under 24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper this exception must only link to the code of Red Hat elfutils through 25361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper those well defined interfaces identified in the file named EXCEPTION 26361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper found in the source code files (the "Approved Interfaces"). The files 27361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper of Non-GPL Code may instantiate templates or use macros or inline 28361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper functions from the Approved Interfaces without causing the resulting 29361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper work to be covered by the GNU General Public License. Only Red Hat, 30361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Inc. may make changes or additions to the list of Approved Interfaces. 31361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat's grant of this exception is conditioned upon your not adding 32361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper any new exceptions. If you wish to add a new Approved Interface or 33361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper exception, please contact Red Hat. You must obey the GNU General Public 34361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper License in all respects for all of the Red Hat elfutils code and other 35361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper code used in conjunction with Red Hat elfutils except the Non-GPL Code 36361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper covered by this exception. If you modify this file, you may extend this 37361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper exception to your version of the file, but you are not obligated to do 38361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper so. If you do not wish to provide this exception without modification, 39361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper you must delete this exception statement from your version and license 40361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper this file solely under the GPL without exception. 41361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper 42361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Red Hat elfutils is an included package of the Open Invention Network. 43361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper An included package of the Open Invention Network is a package for which 44361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Open Invention Network licensees cross-license their patents. No patent 45361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper license is granted, either expressly or impliedly, by designation as an 46361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper included package. Should you wish to participate in the Open Invention 47361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper Network licensing program, please visit www.openinventionnetwork.com 48361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper <http://www.openinventionnetwork.com>. */ 49b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 50b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef _LIBELF_H 51b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _LIBELF_H 1 52b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 53b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <sys/types.h> 54b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 55b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the ELF types. */ 56b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <elf.h> 57b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 58b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 59b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Known translation types. */ 60b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum 61b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 62b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_BYTE, /* unsigned char */ 63b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_ADDR, /* Elf32_Addr, Elf64_Addr, ... */ 64b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_DYN, /* Dynamic section record. */ 65b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_EHDR, /* ELF header. */ 66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_HALF, /* Elf32_Half, Elf64_Half, ... */ 67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_OFF, /* Elf32_Off, Elf64_Off, ... */ 68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_PHDR, /* Program header. */ 69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_RELA, /* Relocation entry with addend. */ 70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_REL, /* Relocation entry. */ 71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_SHDR, /* Section header. */ 72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_SWORD, /* Elf32_Sword, Elf64_Sword, ... */ 73b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_SYM, /* Symbol record. */ 74b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_WORD, /* Elf32_Word, Elf64_Word, ... */ 75b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_XWORD, /* Elf32_Xword, Elf64_Xword, ... */ 76b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_SXWORD, /* Elf32_Sxword, Elf64_Sxword, ... */ 77b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_VDEF, /* Elf32_Verdef, Elf64_Verdef, ... */ 78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_VDAUX, /* Elf32_Verdaux, Elf64_Verdaux, ... */ 79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_VNEED, /* Elf32_Verneed, Elf64_Verneed, ... */ 80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_VNAUX, /* Elf32_Vernaux, Elf64_Vernaux, ... */ 81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_NHDR, /* Elf32_Nhdr, Elf64_Nhdr, ... */ 82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_SYMINFO, /* Elf32_Syminfo, Elf64_Syminfo, ... */ 83b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_MOVE, /* Elf32_Move, Elf64_Move, ... */ 84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_LIB, /* Elf32_Lib, Elf64_Lib, ... */ 858ae5814209558f51c93b583c9ae6fdd482f0cbb2Ulrich Drepper ELF_T_GNUHASH, /* GNU-style hash section. */ 86cb6d865011ad98a8ac2018f072f396a2268739caRoland McGrath ELF_T_AUXV, /* Elf32_auxv_t, Elf64_auxv_t, ... */ 87b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Keep this the last entry. */ 88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_T_NUM 89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Type; 90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for data to be converted to or from memory format. */ 92b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct 93b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 94b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper void *d_buf; /* Pointer to the actual data. */ 95b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper Elf_Type d_type; /* Type of this piece of data. */ 96b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int d_version; /* ELF version. */ 97b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t d_size; /* Size in bytes. */ 981a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrath loff_t d_off; /* Offset into section. */ 99b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t d_align; /* Alignment in section. */ 100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Data; 101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Commands for `...'. */ 104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum 105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_NULL, /* Nothing, terminate, or compute only. */ 107b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_READ, /* Read .. */ 108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_RDWR, /* Read and write .. */ 109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_WRITE, /* Write .. */ 110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_CLR, /* Clear flag. */ 111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_SET, /* Set flag. */ 112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_FDDONE, /* Signal that file descriptor will not be 113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper used anymore. */ 114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_FDREAD, /* Read rest of data so that file descriptor 115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper is not used anymore. */ 116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* The following are extensions. */ 117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_READ_MMAP, /* Read, but mmap the file if possible. */ 118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_RDWR_MMAP, /* Read and write, with mmap. */ 119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_WRITE_MMAP, /* Write, with mmap. */ 120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_READ_MMAP_PRIVATE, /* Read, but memory is writable, results are 121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper not written to the file. */ 122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_EMPTY, /* Copy basic file data but not the content. */ 123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Keep this the last entry. */ 124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_C_NUM 125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Cmd; 126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Flags for the ELF structures. */ 129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperenum 130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_F_DIRTY = 0x1, 132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_DIRTY ELF_F_DIRTY 133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_F_LAYOUT = 0x4, 134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_LAYOUT ELF_F_LAYOUT 135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_F_PERMISSIVE = 0x8 136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_PERMISSIVE ELF_F_PERMISSIVE 137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}; 138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Identification values for recognized object files. */ 141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum 142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_K_NONE, /* Unknown. */ 144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_K_AR, /* Archive. */ 145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_K_COFF, /* Stupid old COFF. */ 146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_K_ELF, /* ELF file. */ 147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper /* Keep this the last entry. */ 148b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper ELF_K_NUM 149b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Kind; 150b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 151b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 152b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Archive member header. */ 153b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct 154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *ar_name; /* Name of archive member. */ 156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper time_t ar_date; /* File date. */ 157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper uid_t ar_uid; /* User ID. */ 158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper gid_t ar_gid; /* Group ID. */ 159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper mode_t ar_mode; /* File mode. */ 1601a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrath loff_t ar_size; /* File size. */ 161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *ar_rawname; /* Original name of archive member. */ 162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Arhdr; 163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Archive symbol table entry. */ 166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct 167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{ 168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper char *as_name; /* Symbol name. */ 169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper size_t as_off; /* Offset for this file in the archive. */ 170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned long int as_hash; /* Hash value of the name. */ 171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Arsym; 172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for the ELF file. */ 175b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Elf Elf; 176b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 177b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for ELF file section. */ 178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Elf_Scn Elf_Scn; 179b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef __cplusplus 182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern "C" { 183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return descriptor for ELF file to work according to CMD. */ 186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf *elf_begin (int __fildes, Elf_Cmd __cmd, Elf *__ref); 187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create a clone of an existing ELF descriptor. */ 189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper extern Elf *elf_clone (Elf *__elf, Elf_Cmd __cmd); 190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 191b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create descriptor for memory region. */ 192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf *elf_memory (char *__image, size_t __size); 193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Advance archive descriptor to next element. */ 195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Cmd elf_next (Elf *__elf); 196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Free resources allocated for ELF. */ 198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_end (Elf *__elf); 199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Update ELF descriptor and write file to disk. */ 2011a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrathextern loff_t elf_update (Elf *__elf, Elf_Cmd __cmd); 202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Determine what kind of file is associated with ELF. */ 204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Kind elf_kind (Elf *__elf) __attribute__ ((__pure__)); 205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the base offset for an object file. */ 2071a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrathextern loff_t elf_getbase (Elf *__elf); 208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve file identification data. */ 2111d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern char *elf_getident (Elf *__elf, size_t *__nbytes); 212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve class-dependent object file header. */ 214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Ehdr *elf32_getehdr (Elf *__elf); 215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 216b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Ehdr *elf64_getehdr (Elf *__elf); 217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create ELF header if none exists. */ 219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Ehdr *elf32_newehdr (Elf *__elf); 220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Ehdr *elf64_newehdr (Elf *__elf); 222b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve class-dependent program header table. */ 224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Phdr *elf32_getphdr (Elf *__elf); 225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 226b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Phdr *elf64_getphdr (Elf *__elf); 227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create ELF program header. */ 229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Phdr *elf32_newphdr (Elf *__elf, size_t __cnt); 230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Phdr *elf64_newphdr (Elf *__elf, size_t __cnt); 232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get section at INDEX. */ 235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_getscn (Elf *__elf, size_t __index); 236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 23741de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper/* Get section at OFFSET. */ 23841de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepperextern Elf_Scn *elf32_offscn (Elf *__elf, Elf32_Off __offset); 23941de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper/* Similar bug this time the binary calls is ELFCLASS64. */ 24041de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepperextern Elf_Scn *elf64_offscn (Elf *__elf, Elf64_Off __offset); 24141de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper 242b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get index of section. */ 243b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf_ndxscn (Elf_Scn *__scn); 244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get section with next section index. */ 246b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_nextscn (Elf *__elf, Elf_Scn *__scn); 247b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 248b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create a new section and append it at the end of the table. */ 249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_newscn (Elf *__elf); 250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 2513cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper/* Get the section index of the extended section index table for the 2523cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper given symbol table. */ 2533cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepperextern int elf_scnshndx (Elf_Scn *__scn); 2543cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper 255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the number of sections in the ELF file. If the file uses more 256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper sections than can be represented in the e_shnum field of the ELF 257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper header the information from the sh_size field in the zeroth section 258b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper header is used. */ 259b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_getshnum (Elf *__elf, size_t *__dst); 260b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 261b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 262b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the section index of the section header string table in the ELF 263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper file. If the index cannot be represented in the e_shnum field of 264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper the ELF header the information from the sh_link field in the zeroth 265b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper section header is used. */ 266b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_getshstrndx (Elf *__elf, size_t *__dst); 267b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 268b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve section header of ELFCLASS32 binary. */ 270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Shdr *elf32_getshdr (Elf_Scn *__scn); 271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar for ELFCLASS64. */ 272b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Shdr *elf64_getshdr (Elf_Scn *__scn); 273b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 274b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 275b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set or clear flags for ELF file. */ 276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagelf (Elf *__elf, Elf_Cmd __cmd, 277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the ELF header. */ 279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagehdr (Elf *__elf, Elf_Cmd __cmd, 280b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 281b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the ELF program header. */ 282b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagphdr (Elf *__elf, Elf_Cmd __cmd, 283b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 284b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF section. */ 285b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagscn (Elf_Scn *__scn, Elf_Cmd __cmd, 286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF data. */ 288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagdata (Elf_Data *__data, Elf_Cmd __cmd, 289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF section header. */ 291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagshdr (Elf_Scn *__scn, Elf_Cmd __cmd, 292b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __flags); 293b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 294b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 295b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get data from section while translating from file representation 296b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper to memory representation. */ 297b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_getdata (Elf_Scn *__scn, Elf_Data *__data); 298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get uninterpreted section content. */ 300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_rawdata (Elf_Scn *__scn, Elf_Data *__data); 301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create new data descriptor for section SCN. */ 303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_newdata (Elf_Scn *__scn); 304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 30559ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Get data translated from a chunk of the file contents as section data 30659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath would be for TYPE. The resulting Elf_Data pointer is valid until 30759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath elf_end (ELF) is called. */ 30859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern Elf_Data *elf_getdata_rawchunk (Elf *__elf, 3091a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrath loff_t __offset, size_t __size, 31059ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath Elf_Type __type); 31159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath 312b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 313b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return pointer to string at OFFSET in section INDEX. */ 314b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern char *elf_strptr (Elf *__elf, size_t __index, size_t __offset); 315b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 316b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 317b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return header of archive. */ 318b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Arhdr *elf_getarhdr (Elf *__elf); 319b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 3205d83229c852a7e7359c12b58864751db2c755926Ulrich Drepper/* Return offset in archive for current file ELF. */ 3211a2e8f4f5bd2ca2aaed78d1cea3842eff2fa5295Roland McGrathextern loff_t elf_getaroff (Elf *__elf); 3225d83229c852a7e7359c12b58864751db2c755926Ulrich Drepper 323b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Select archive element at OFFSET. */ 324b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf_rand (Elf *__elf, size_t __offset); 325b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 3261d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrath/* Get symbol table of archive. */ 3271d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern Elf_Arsym *elf_getarsym (Elf *__elf, size_t *__narsyms); 328b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 329b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 330b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Control ELF descriptor. */ 331b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_cntl (Elf *__elf, Elf_Cmd __cmd); 332b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 333b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve uninterpreted file contents. */ 3341d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern char *elf_rawfile (Elf *__elf, size_t *__nbytes); 335b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 336b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 337b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return size of array of COUNT elements of the type denoted by TYPE 338b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper in the external representation. The binary class is taken from ELF. 339b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper The result is based on version VERSION of the ELF standard. */ 340b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf32_fsize (Elf_Type __type, size_t __count, 341b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __version) 342b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __attribute__ ((__const__)); 343b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 344b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf64_fsize (Elf_Type __type, size_t __count, 345b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __version) 346b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __attribute__ ((__const__)); 347b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 348b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 349b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert data structure from the representation in the file represented 350b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper by ELF to their memory representation. */ 351b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf32_xlatetom (Elf_Data *__dest, const Elf_Data *__src, 352b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __encode); 353b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Same for 64 bit class. */ 354b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf64_xlatetom (Elf_Data *__dest, const Elf_Data *__src, 355b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __encode); 356b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 357b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert data structure from to the representation in memory 358b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper represented by ELF file representation. */ 359b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf32_xlatetof (Elf_Data *__dest, const Elf_Data *__src, 360b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __encode); 361b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Same for 64 bit class. */ 362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf64_xlatetof (Elf_Data *__dest, const Elf_Data *__src, 363b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper unsigned int __encode); 364b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 365b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 366b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error code of last failing function call. This value is kept 367b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper separately for each thread. */ 368b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_errno (void); 369b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 370b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error string for ERROR. If ERROR is zero, return error string 371b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper for most recent error or NULL is none occurred. If ERROR is -1 the 372b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper behaviour is similar to the last case except that not NULL but a legal 373b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper string is returned. */ 374b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern const char *elf_errmsg (int __error); 375b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 376b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 377b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Coordinate ELF library and application versions. */ 378b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_version (unsigned int __version); 379b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 380b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set fill bytes used to fill holes in data structures. */ 381b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void elf_fill (int __fill); 382b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 383b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Compute hash value. */ 384b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned long int elf_hash (const char *__string) 385b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper __attribute__ ((__pure__)); 386b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 38728ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper/* Compute hash value using the GNU-specific hash function. */ 38828ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepperextern unsigned long int elf_gnu_hash (const char *__string) 38928ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper __attribute__ ((__pure__)); 39028ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper 391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Compute simple checksum from permanent parts of the ELF file. */ 393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern long int elf32_checksum (Elf *__elf); 394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64. */ 395b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern long int elf64_checksum (Elf *__elf); 396b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 397b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef __cplusplus 398b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} 399b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif 400b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper 401b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif /* libelf.h */ 402