1 /* gelf API which supports ELFCLASS32 only.
2 Copyright (C) 2001 Red Hat, Inc.
3 Written by Jakub Jelinek <jakub@redhat.com>, 2001.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 typedef Elf32_Half GElf_Half;
28 typedef Elf32_Word GElf_Word;
29 typedef Elf32_Sword GElf_Sword;
30 typedef Elf32_Xword GElf_Xword;
31 typedef Elf32_Sxword GElf_Sxword;
32 typedef Elf32_Addr GElf_Addr;
33 typedef Elf32_Off GElf_Off;
34 typedef Elf32_Ehdr GElf_Ehdr;
35 typedef Elf32_Shdr GElf_Shdr;
36 typedef Elf32_Section GElf_Section;
37 typedef Elf32_Sym GElf_Sym;
38 typedef Elf32_Rel GElf_Rel;
39 typedef Elf32_Rela GElf_Rela;
40 typedef Elf32_Phdr GElf_Phdr;
41 typedef Elf32_Dyn GElf_Dyn;
42 #define GELF_ST_BIND ELF32_ST_BIND
43 #define GELF_ST_TYPE ELF32_ST_TYPE
44 #define GELF_ST_INFO ELF32_ST_INFO
45 #define GELF_R_SYM ELF32_R_SYM
46 #define GELF_R_TYPE ELF32_R_TYPE
47 #define GELF_R_INFO ELF32_R_INFO
50 gelf_getclass (Elf *elf)
53 char *e_ident = elf_getident (elf, &size);
54 if (e_ident [EI_CLASS] == ELFCLASS64)
55 error (EXIT_FAILURE, 0, "64-bit ELF not supported");
56 return e_ident [EI_CLASS] == ELFCLASS32 ? ELFCLASS32 : ELFCLASSNONE;
59 #define gelf_fsize(e,t,c,v) elf32_fsize(t,c,v)
61 extern inline GElf_Ehdr *gelf_getehdr (Elf *elf, GElf_Ehdr *dst)
63 Elf32_Ehdr *ehdr = elf32_getehdr (elf);
66 return memcpy (dst, ehdr, sizeof (Elf32_Ehdr));
70 gelf_update_ehdr (Elf *elf, GElf_Ehdr *src)
72 Elf32_Ehdr *ehdr = elf32_getehdr (elf);
75 memcpy (ehdr, src, sizeof (Elf32_Ehdr));
79 extern inline unsigned long
80 gelf_newehdr (Elf *elf, int class)
82 if (class != ELFCLASS32)
84 return (unsigned long) elf32_newehdr (elf);
87 extern inline GElf_Phdr *
88 gelf_getphdr (Elf *elf, int ndx, GElf_Phdr *dst)
90 Elf32_Ehdr *ehdr = elf32_getehdr (elf);
91 Elf32_Phdr *phdr = elf32_getphdr (elf);
92 if (ehdr == NULL || phdr == NULL || ndx >= ehdr->e_phnum)
94 return memcpy (dst, phdr + ndx, sizeof (Elf32_Phdr));
98 gelf_update_phdr (Elf *elf, int ndx, GElf_Phdr *src)
100 Elf32_Ehdr *ehdr = elf32_getehdr (elf);
101 Elf32_Phdr *phdr = elf32_getphdr (elf);
102 if (ehdr == NULL || phdr == NULL || ndx >= ehdr->e_phnum)
104 memcpy (phdr + ndx, src, sizeof (Elf32_Phdr));
108 extern inline unsigned long
109 gelf_newphdr (Elf *elf, size_t phnum)
111 return (unsigned long) elf32_newphdr (elf, phnum);
114 #define gelf_xlatetom(e,d,s,n) elf32_xlatetom(e,d,s,n)
115 #define gelf_xlatetof(e,d,s,n) elf32_xlatetof(e,d,s,n)
117 extern inline GElf_Shdr *
118 gelf_getshdr (Elf_Scn *scn, GElf_Shdr *dst)
120 Elf32_Shdr *shdr = elf32_getshdr (scn);
123 return memcpy (dst, shdr, sizeof (Elf32_Shdr));
127 gelf_update_shdr (Elf_Scn *scn, GElf_Shdr *src)
129 Elf32_Shdr *shdr = elf32_getshdr (scn);
132 memcpy (shdr, src, sizeof (Elf32_Shdr));
136 extern inline GElf_Sym *
137 gelf_getsym (Elf_Data *data, int ndx, GElf_Sym *dst)
139 if (data->d_type != ELF_T_SYM
140 || (ndx + 1) * sizeof (Elf32_Sym) > data->d_size)
142 *dst = ((GElf_Sym *) data->d_buf)[ndx];
147 gelf_update_sym (Elf_Data *data, int ndx, GElf_Sym *src)
149 if (data->d_type != ELF_T_SYM
150 || (ndx + 1) * sizeof (Elf32_Sym) > data->d_size)
152 ((GElf_Sym *) data->d_buf)[ndx] = *src;
156 extern inline GElf_Dyn *
157 gelf_getdyn (Elf_Data *data, int ndx, GElf_Dyn *dst)
159 if (data->d_type != ELF_T_DYN
160 || (ndx + 1) * sizeof (Elf32_Dyn) > data->d_size)
162 *dst = ((GElf_Dyn *) data->d_buf)[ndx];
167 gelf_update_dyn (Elf_Data *data, int ndx, GElf_Dyn *src)
169 if (data->d_type != ELF_T_DYN
170 || (ndx + 1) * sizeof (Elf32_Dyn) > data->d_size)
172 ((GElf_Dyn *) data->d_buf)[ndx] = *src;
176 extern inline GElf_Rel *
177 gelf_getrel (Elf_Data *data, int ndx, GElf_Rel *dst)
179 if (data->d_type != ELF_T_REL
180 || (ndx + 1) * sizeof (Elf32_Rel) > data->d_size)
182 *dst = ((GElf_Rel *) data->d_buf)[ndx];
187 gelf_update_rel (Elf_Data *data, int ndx, GElf_Rel *src)
189 if (data->d_type != ELF_T_REL
190 || (ndx + 1) * sizeof (Elf32_Rel) > data->d_size)
192 ((GElf_Rel *) data->d_buf)[ndx] = *src;
196 extern inline GElf_Rela *
197 gelf_getrela (Elf_Data *data, int ndx, GElf_Rela *dst)
199 if (data->d_type != ELF_T_RELA
200 || (ndx + 1) * sizeof (Elf32_Rela) > data->d_size)
202 *dst = ((GElf_Rela *) data->d_buf)[ndx];
207 gelf_update_rela (Elf_Data *data, int ndx, GElf_Rela *src)
209 if (data->d_type != ELF_T_RELA
210 || (ndx + 1) * sizeof (Elf32_Rela) > data->d_size)
212 ((GElf_Rela *) data->d_buf)[ndx] = *src;
216 #define gelfx_getshdr(elf,scn,shdr) gelf_getshdr(scn,shdr)
217 #define gelfx_update_shdr(elf,scn,shdr) gelf_update_shdr(scn,shdr)
218 #define gelfx_getsym(elf,data,ndx,x) gelf_getsym(data,ndx,x)
219 #define gelfx_update_sym(elf,data,ndx,x) gelf_update_sym(data,ndx,x)
220 #define gelfx_getdyn(elf,data,ndx,x) gelf_getdyn(data,ndx,x)
221 #define gelfx_update_dyn(elf,data,ndx,x) gelf_update_dyn(data,ndx,x)
222 #define gelfx_getrel(elf,data,ndx,x) gelf_getrel(data,ndx,x)
223 #define gelfx_update_rel(elf,data,ndx,x) gelf_update_rel(data,ndx,x)
224 #define gelfx_getrela(elf,data,ndx,x) gelf_getrela(data,ndx,x)
225 #define gelfx_update_rela(elf,data,ndx,x) gelf_update_rela(data,ndx,x)