1b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Interface for libelf.
25ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaard   Copyright (C) 1998-2010, 2015 Red Hat, Inc.
3de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is part of elfutils.
4361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
5de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   This file is free software; you can redistribute it and/or modify
6de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   it under the terms of either
7361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
8de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU Lesser General Public License as published by the Free
9de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 3 of the License, or (at
10de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
11de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
12de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or
13de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
14de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard     * the GNU General Public License as published by the Free
15de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       Software Foundation; either version 2 of the License, or (at
16de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard       your option) any later version
17de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
18de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   or both in parallel, as here.
19de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard
20de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   elfutils is distributed in the hope that it will be useful, but
21361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   WITHOUT ANY WARRANTY; without even the implied warranty of
22361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper   General Public License for more details.
24361df7da6dfecd817b27e62b91752ac316d7cdd4Ulrich Drepper
25de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   You should have received copies of the GNU General Public License and
26de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   the GNU Lesser General Public License along with this program.  If
27de2ed97f33139af5c7a0811e4ec66fc896a13cf2Mark Wielaard   not, see <http://www.gnu.org/licenses/>.  */
28b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
29b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifndef _LIBELF_H
30b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define _LIBELF_H 1
31b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
32b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stone#include <stdint.h>
33b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <sys/types.h>
34b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
35b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the ELF types.  */
36b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#include <elf.h>
37b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
38344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard#ifndef SHF_COMPRESSED
39344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard /* Older glibc elf.h might not yet define the ELF compression types.  */
40344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define SHF_COMPRESSED      (1 << 11)  /* Section with compressed data. */
41344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard
42344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard /* Section compression header.  Used when SHF_COMPRESSED is set.  */
43344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard
44344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard typedef struct
45344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard {
46344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf32_Word   ch_type;        /* Compression format.  */
47344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf32_Word   ch_size;        /* Uncompressed data size.  */
48344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf32_Word   ch_addralign;   /* Uncompressed data alignment.  */
49344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard } Elf32_Chdr;
50344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard
51344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard typedef struct
52344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard {
53344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf64_Word   ch_type;        /* Compression format.  */
54344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf64_Word   ch_reserved;
55344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf64_Xword  ch_size;        /* Uncompressed data size.  */
56344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard   Elf64_Xword  ch_addralign;   /* Uncompressed data alignment.  */
57344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard } Elf64_Chdr;
58344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard
59344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard /* Legal values for ch_type (compression algorithm).  */
60344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define ELFCOMPRESS_ZLIB       1          /* ZLIB/DEFLATE algorithm.  */
61344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define ELFCOMPRESS_LOOS       0x60000000 /* Start of OS-specific.  */
62344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define ELFCOMPRESS_HIOS       0x6fffffff /* End of OS-specific.  */
63344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define ELFCOMPRESS_LOPROC     0x70000000 /* Start of processor-specific.  */
64344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard #define ELFCOMPRESS_HIPROC     0x7fffffff /* End of processor-specific.  */
65344ca0775da729e1bfdd61bb88ba4c64befece07Mark Wielaard#endif
66b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
67b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Known translation types.  */
68b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum
69b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
70b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_BYTE,                   /* unsigned char */
71b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_ADDR,                   /* Elf32_Addr, Elf64_Addr, ... */
72b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_DYN,                    /* Dynamic section record.  */
73b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_EHDR,                   /* ELF header.  */
74b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_HALF,                   /* Elf32_Half, Elf64_Half, ... */
75b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_OFF,                    /* Elf32_Off, Elf64_Off, ... */
76b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_PHDR,                   /* Program header.  */
77b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_RELA,                   /* Relocation entry with addend.  */
78b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_REL,                    /* Relocation entry.  */
79b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_SHDR,                   /* Section header.  */
80b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_SWORD,                  /* Elf32_Sword, Elf64_Sword, ... */
81b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_SYM,                    /* Symbol record.  */
82b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_WORD,                   /* Elf32_Word, Elf64_Word, ... */
83b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_XWORD,                  /* Elf32_Xword, Elf64_Xword, ... */
84b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_SXWORD,                 /* Elf32_Sxword, Elf64_Sxword, ... */
85b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_VDEF,                   /* Elf32_Verdef, Elf64_Verdef, ... */
86b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_VDAUX,                  /* Elf32_Verdaux, Elf64_Verdaux, ... */
87b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_VNEED,                  /* Elf32_Verneed, Elf64_Verneed, ... */
88b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_VNAUX,                  /* Elf32_Vernaux, Elf64_Vernaux, ... */
89b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_NHDR,                   /* Elf32_Nhdr, Elf64_Nhdr, ... */
90b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_SYMINFO,		/* Elf32_Syminfo, Elf64_Syminfo, ... */
91b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_MOVE,			/* Elf32_Move, Elf64_Move, ... */
92b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_LIB,			/* Elf32_Lib, Elf64_Lib, ... */
938ae5814209558f51c93b583c9ae6fdd482f0cbb2Ulrich Drepper  ELF_T_GNUHASH,		/* GNU-style hash section.  */
94cb6d865011ad98a8ac2018f072f396a2268739caRoland McGrath  ELF_T_AUXV,			/* Elf32_auxv_t, Elf64_auxv_t, ... */
955ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaard  ELF_T_CHDR,			/* Compressed, Elf32_Chdr, Elf64_Chdr, ... */
96b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Keep this the last entry.  */
97b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_T_NUM
98b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Type;
99b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
100b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for data to be converted to or from memory format.  */
101b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct
102b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
103b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  void *d_buf;			/* Pointer to the actual data.  */
104b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  Elf_Type d_type;		/* Type of this piece of data.  */
105b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  unsigned int d_version;	/* ELF version.  */
106b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t d_size;		/* Size in bytes.  */
107b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stone  int64_t d_off;		/* Offset into section.  */
108b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t d_align;		/* Alignment in section.  */
109b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Data;
110b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
111b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
112b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Commands for `...'.  */
113b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum
114b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
115b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_NULL,			/* Nothing, terminate, or compute only.  */
116b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_READ,			/* Read .. */
117b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_RDWR,			/* Read and write .. */
118b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_WRITE,			/* Write .. */
119b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_CLR,			/* Clear flag.  */
120b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_SET,			/* Set flag.  */
121b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_FDDONE,			/* Signal that file descriptor will not be
122b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				   used anymore.  */
123b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_FDREAD,			/* Read rest of data so that file descriptor
124b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				   is not used anymore.  */
125b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* The following are extensions.  */
126b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_READ_MMAP,		/* Read, but mmap the file if possible.  */
127b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_RDWR_MMAP,		/* Read and write, with mmap.  */
128b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_WRITE_MMAP,		/* Write, with mmap.  */
129b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_READ_MMAP_PRIVATE,	/* Read, but memory is writable, results are
130b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				   not written to the file.  */
131b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_EMPTY,			/* Copy basic file data but not the content. */
132b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Keep this the last entry.  */
133b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_C_NUM
134b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Cmd;
135b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
136b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
137b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Flags for the ELF structures.  */
138b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperenum
139b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
140b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_F_DIRTY = 0x1,
141b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_DIRTY		ELF_F_DIRTY
142b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_F_LAYOUT = 0x4,
143b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_LAYOUT		ELF_F_LAYOUT
144b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_F_PERMISSIVE = 0x8
145b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#define ELF_F_PERMISSIVE	ELF_F_PERMISSIVE
146b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper};
147b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
148272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard/* Flags for elf_compress[_gnu].  */
149272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaardenum
150272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard{
151272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard  ELF_CHF_FORCE = 0x1
152272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard#define ELF_CHF_FORCE ELF_CHF_FORCE
153272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard};
154b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
155b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Identification values for recognized object files.  */
156b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef enum
157b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
158b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_K_NONE,			/* Unknown.  */
159b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_K_AR,			/* Archive.  */
160b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_K_COFF,			/* Stupid old COFF.  */
161b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_K_ELF,			/* ELF file.  */
162b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  /* Keep this the last entry.  */
163b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  ELF_K_NUM
164b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Kind;
165b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
166b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
167b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Archive member header.  */
168b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct
169b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
170b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  char *ar_name;		/* Name of archive member.  */
171b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  time_t ar_date;		/* File date.  */
172b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  uid_t ar_uid;			/* User ID.  */
173b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  gid_t ar_gid;			/* Group ID.  */
174b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  mode_t ar_mode;		/* File mode.  */
175b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stone  int64_t ar_size;		/* File size.  */
176b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  char *ar_rawname;		/* Original name of archive member.  */
177b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Arhdr;
178b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
179b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
180b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Archive symbol table entry.  */
181b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct
182b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper{
183b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  char *as_name;		/* Symbol name.  */
184b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  size_t as_off;		/* Offset for this file in the archive.  */
185b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  unsigned long int as_hash;	/* Hash value of the name.  */
186b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper} Elf_Arsym;
187b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
188b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
189b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for the ELF file.  */
190b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Elf Elf;
191b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
192b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Descriptor for ELF file section.  */
193b08d5a8fb42f4586d756068065186b5af7e48daUlrich Dreppertypedef struct Elf_Scn Elf_Scn;
194b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
195b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
196b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef __cplusplus
197b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern "C" {
198b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif
199b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
200b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return descriptor for ELF file to work according to CMD.  */
201b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf *elf_begin (int __fildes, Elf_Cmd __cmd, Elf *__ref);
202b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
203b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create a clone of an existing ELF descriptor.  */
204b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper  extern Elf *elf_clone (Elf *__elf, Elf_Cmd __cmd);
205b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
206b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create descriptor for memory region.  */
207b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf *elf_memory (char *__image, size_t __size);
208b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
209b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Advance archive descriptor to next element.  */
210b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Cmd elf_next (Elf *__elf);
211b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
212b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Free resources allocated for ELF.  */
213b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_end (Elf *__elf);
214b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
215b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Update ELF descriptor and write file to disk.  */
216b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stoneextern int64_t elf_update (Elf *__elf, Elf_Cmd __cmd);
217b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
218b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Determine what kind of file is associated with ELF.  */
219b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Kind elf_kind (Elf *__elf) __attribute__ ((__pure__));
220b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
221b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the base offset for an object file.  */
222b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stoneextern int64_t elf_getbase (Elf *__elf);
223b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
224b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
225b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve file identification data.  */
2261d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern char *elf_getident (Elf *__elf, size_t *__nbytes);
227b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
228b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve class-dependent object file header.  */
229b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Ehdr *elf32_getehdr (Elf *__elf);
230b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
231b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Ehdr *elf64_getehdr (Elf *__elf);
232b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
233b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create ELF header if none exists.  */
234b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Ehdr *elf32_newehdr (Elf *__elf);
235b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
236b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Ehdr *elf64_newehdr (Elf *__elf);
237b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2386fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrath/* Get the number of program headers in the ELF file.  If the file uses
2396fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrath   more headers than can be represented in the e_phnum field of the ELF
2406fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrath   header the information from the sh_info field in the zeroth section
2416fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrath   header is used.  */
2426fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrathextern int elf_getphdrnum (Elf *__elf, size_t *__dst);
2436fd3cd104adf4107aa64e1c1e84028b4ea0b3296Roland McGrath
244b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve class-dependent program header table.  */
245b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Phdr *elf32_getphdr (Elf *__elf);
246b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
247b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Phdr *elf64_getphdr (Elf *__elf);
248b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
249b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create ELF program header.  */
250b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Phdr *elf32_newphdr (Elf *__elf, size_t __cnt);
251b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
252b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Phdr *elf64_newphdr (Elf *__elf, size_t __cnt);
253b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
254b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
255b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get section at INDEX.  */
256b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_getscn (Elf *__elf, size_t __index);
257b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
25841de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper/* Get section at OFFSET.  */
25941de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepperextern Elf_Scn *elf32_offscn (Elf *__elf, Elf32_Off __offset);
26041de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper/* Similar bug this time the binary calls is ELFCLASS64.  */
26141de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepperextern Elf_Scn *elf64_offscn (Elf *__elf, Elf64_Off __offset);
26241de488a0ad6679e816dbab960351e5f62ab8eadUlrich Drepper
263b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get index of section.  */
264b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf_ndxscn (Elf_Scn *__scn);
265b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
266b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get section with next section index.  */
267b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_nextscn (Elf *__elf, Elf_Scn *__scn);
268b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
269b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create a new section and append it at the end of the table.  */
270b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Scn *elf_newscn (Elf *__elf);
271b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
2723cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper/* Get the section index of the extended section index table for the
2733cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper   given symbol table.  */
2743cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepperextern int elf_scnshndx (Elf_Scn *__scn);
2753cbdd387c752999255aea91600b5cfdefbeac7d0Ulrich Drepper
276b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the number of sections in the ELF file.  If the file uses more
277b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   sections than can be represented in the e_shnum field of the ELF
278b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   header the information from the sh_size field in the zeroth section
279b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   header is used.  */
280f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepperextern int elf_getshdrnum (Elf *__elf, size_t *__dst);
281f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper/* Sun messed up the implementation of 'elf_getshnum' in their implementation.
282f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper   It was agreed to make the same functionality available under a different
283f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper   name and obsolete the old name.  */
284f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepperextern int elf_getshnum (Elf *__elf, size_t *__dst)
285f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper     __attribute__ ((__deprecated__));
286b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
287b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
288b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get the section index of the section header string table in the ELF
289b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   file.  If the index cannot be represented in the e_shnum field of
290b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   the ELF header the information from the sh_link field in the zeroth
291b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   section header is used.  */
292f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepperextern int elf_getshdrstrndx (Elf *__elf, size_t *__dst);
293f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper/* Sun messed up the implementation of 'elf_getshnum' in their implementation.
294f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper   It was agreed to make the same functionality available under a different
295f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper   name and obsolete the old name.  */
296f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepperextern int elf_getshstrndx (Elf *__elf, size_t *__dst)
297f189493154d0041deced00e6a99cc5426dc9d260Ulrich Drepper     __attribute__ ((__deprecated__));
298b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
299b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
300b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve section header of ELFCLASS32 binary.  */
301b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf32_Shdr *elf32_getshdr (Elf_Scn *__scn);
302b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar for ELFCLASS64.  */
303b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf64_Shdr *elf64_getshdr (Elf_Scn *__scn);
304b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
3055ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaard/* Returns compression header for a section if section data is
3065ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaard   compressed.  Returns NULL and sets elf_errno if the section isn't
3075ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaard   compressed or an error occurred.  */
3085ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaardextern Elf32_Chdr *elf32_getchdr (Elf_Scn *__scn);
3095ddb50af4a488fdec358570502cbe058acb8ae93Mark Wielaardextern Elf64_Chdr *elf64_getchdr (Elf_Scn *__scn);
310b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
311272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard/* Compress or decompress the data of a section and adjust the section
312272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   header.
313272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
314272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   elf_compress works by setting or clearing the SHF_COMPRESS flag
315272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   from the section Shdr and will encode or decode a Elf32_Chdr or
316272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   Elf64_Chdr at the start of the section data.  elf_compress_gnu will
317272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   encode or decode any section, but is traditionally only used for
318272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   sections that have a name starting with ".debug" when
319272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   uncompressed or ".zdebug" when compressed and stores just the
320272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   uncompressed size.  The GNU compression method is deprecated and
321272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   should only be used for legacy support.
322272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
323272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   elf_compress takes a compression type that should be either zero to
324272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   decompress or an ELFCOMPRESS algorithm to use for compression.
325272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   Currently only ELFCOMPRESS_ZLIB is supported.  elf_compress_gnu
326272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   will compress in the traditional GNU compression format when
327272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   compress is one and decompress the section data when compress is
328272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   zero.
329272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
330272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   The FLAGS argument can be zero or ELF_CHF_FORCE.  If FLAGS contains
331272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   ELF_CHF_FORCE then it will always compress the section, even if
332272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   that would not reduce the size of the data section (including the
333272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   header).  Otherwise elf_compress and elf_compress_gnu will compress
334272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   the section only if the total data size is reduced.
335272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
336272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   On successful compression or decompression the function returns
337272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   one.  If (not forced) compression is requested and the data section
338272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   would not actually reduce in size, the section is not actually
339272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   compressed and zero is returned.  Otherwise -1 is returned and
340272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   elf_errno is set.
341272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
342272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   It is an error to request compression for a section that already
343272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   has SHF_COMPRESSED set, or (for elf_compress) to request
344272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   decompression for an section that doesn't have SHF_COMPRESSED set.
345272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   It is always an error to call these functions on SHT_NOBITS
346272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   sections or if the section has the SHF_ALLOC flag set.
347272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   elf_compress_gnu will not check whether the section name starts
348272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   with ".debug" or .zdebug".  It is the responsibilty of the caller
349272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   to make sure the deprecated GNU compression method is only called
350272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   on correctly named sections (and to change the name of the section
351272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   when using elf_compress_gnu).
352272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
353272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   All previous returned Shdrs and Elf_Data buffers are invalidated by
354272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   this call and should no longer be accessed.
355272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
356272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   Note that although this changes the header and data returned it
357272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   doesn't mark the section as dirty.  To keep the changes when
358272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   calling elf_update the section has to be flagged ELF_F_DIRTY.  */
359272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaardextern int elf_compress (Elf_Scn *scn, int type, unsigned int flags);
360272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaardextern int elf_compress_gnu (Elf_Scn *scn, int compress, unsigned int flags);
361272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard
362b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set or clear flags for ELF file.  */
363b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagelf (Elf *__elf, Elf_Cmd __cmd,
364b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __flags);
365b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the ELF header.  */
366b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagehdr (Elf *__elf, Elf_Cmd __cmd,
367b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				  unsigned int __flags);
368b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the ELF program header.  */
369b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagphdr (Elf *__elf, Elf_Cmd __cmd,
370b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				  unsigned int __flags);
371b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF section.  */
372b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagscn (Elf_Scn *__scn, Elf_Cmd __cmd,
373b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __flags);
374b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF data.  */
375b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagdata (Elf_Data *__data, Elf_Cmd __cmd,
376b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				  unsigned int __flags);
377b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similarly for the given ELF section header.  */
378b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_flagshdr (Elf_Scn *__scn, Elf_Cmd __cmd,
379b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				  unsigned int __flags);
380b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
381b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
382272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard/* Get data from section while translating from file representation to
383272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   memory representation.  The Elf_Data d_type is set based on the
384272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   section type if known.  Otherwise d_type is set to ELF_T_BYTE.  If
385272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   the section contains compressed data then d_type is always set to
386272018bba1f253bae00b5ba280ad0e0f18c04006Mark Wielaard   ELF_T_CHDR.  */
387b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_getdata (Elf_Scn *__scn, Elf_Data *__data);
388b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
389b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Get uninterpreted section content.  */
390b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_rawdata (Elf_Scn *__scn, Elf_Data *__data);
391b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
392b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Create new data descriptor for section SCN.  */
393b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf_newdata (Elf_Scn *__scn);
394b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
39559ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath/* Get data translated from a chunk of the file contents as section data
39659ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath   would be for TYPE.  The resulting Elf_Data pointer is valid until
39759ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath   elf_end (ELF) is called.  */
39859ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrathextern Elf_Data *elf_getdata_rawchunk (Elf *__elf,
399b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stone				       int64_t __offset, size_t __size,
40059ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath				       Elf_Type __type);
40159ea7f33f781e6e3f8c9d81d457e5d99eee8f1ceRoland McGrath
402b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
403b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return pointer to string at OFFSET in section INDEX.  */
404b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern char *elf_strptr (Elf *__elf, size_t __index, size_t __offset);
405b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
406b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
407b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return header of archive.  */
408b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Arhdr *elf_getarhdr (Elf *__elf);
409b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
4105d83229c852a7e7359c12b58864751db2c755926Ulrich Drepper/* Return offset in archive for current file ELF.  */
411b1d0b0fc7ef850851574031851cd36d114ea30e7Josh Stoneextern int64_t elf_getaroff (Elf *__elf);
4125d83229c852a7e7359c12b58864751db2c755926Ulrich Drepper
413b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Select archive element at OFFSET.  */
414b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf_rand (Elf *__elf, size_t __offset);
415b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
4161d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrath/* Get symbol table of archive.  */
4171d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern Elf_Arsym *elf_getarsym (Elf *__elf, size_t *__narsyms);
418b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
419b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
420b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Control ELF descriptor.  */
421b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_cntl (Elf *__elf, Elf_Cmd __cmd);
422b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
423b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Retrieve uninterpreted file contents.  */
4241d3a64d70c8f2aec1fc3ae26d124823c1ef304a9Roland McGrathextern char *elf_rawfile (Elf *__elf, size_t *__nbytes);
425b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
426b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
427b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return size of array of COUNT elements of the type denoted by TYPE
428b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   in the external representation.  The binary class is taken from ELF.
429b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   The result is based on version VERSION of the ELF standard.  */
430b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf32_fsize (Elf_Type __type, size_t __count,
431b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper			   unsigned int __version)
432b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper       __attribute__ ((__const__));
433b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
434b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern size_t elf64_fsize (Elf_Type __type, size_t __count,
435b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper			   unsigned int __version)
436b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper       __attribute__ ((__const__));
437b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
438b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
439b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert data structure from the representation in the file represented
440b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   by ELF to their memory representation.  */
441b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf32_xlatetom (Elf_Data *__dest, const Elf_Data *__src,
442b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __encode);
443b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Same for 64 bit class.  */
444b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf64_xlatetom (Elf_Data *__dest, const Elf_Data *__src,
445b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __encode);
446b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
447b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Convert data structure from to the representation in memory
448b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   represented by ELF file representation.  */
449b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf32_xlatetof (Elf_Data *__dest, const Elf_Data *__src,
450b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __encode);
451b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Same for 64 bit class.  */
452b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern Elf_Data *elf64_xlatetof (Elf_Data *__dest, const Elf_Data *__src,
453b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper				 unsigned int __encode);
454b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
455b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
456b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error code of last failing function call.  This value is kept
457b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   separately for each thread.  */
458b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern int elf_errno (void);
459b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
460b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Return error string for ERROR.  If ERROR is zero, return error string
461b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   for most recent error or NULL is none occurred.  If ERROR is -1 the
462b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   behaviour is similar to the last case except that not NULL but a legal
463b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper   string is returned.  */
464b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern const char *elf_errmsg (int __error);
465b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
466b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
467b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Coordinate ELF library and application versions.  */
468b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned int elf_version (unsigned int __version);
469b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
470b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Set fill bytes used to fill holes in data structures.  */
471b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern void elf_fill (int __fill);
472b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
473b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Compute hash value.  */
474b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern unsigned long int elf_hash (const char *__string)
475b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper       __attribute__ ((__pure__));
476b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
47728ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper/* Compute hash value using the GNU-specific hash function.  */
47828ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepperextern unsigned long int elf_gnu_hash (const char *__string)
47928ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper       __attribute__ ((__pure__));
48028ed895fdc303b2a793506bb1fcdd35d5fd14e70Ulrich Drepper
481b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
482b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Compute simple checksum from permanent parts of the ELF file.  */
483b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern long int elf32_checksum (Elf *__elf);
484b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper/* Similar but this time the binary calls is ELFCLASS64.  */
485b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepperextern long int elf64_checksum (Elf *__elf);
486b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
487b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#ifdef __cplusplus
488b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper}
489b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif
490b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper
491b08d5a8fb42f4586d756068065186b5af7e48daUlrich Drepper#endif  /* libelf.h */
492