1*0a6a1f1dSLionel Sambuc /* $NetBSD: libdwarf_elf_init.c,v 1.2 2014/03/09 16:58:04 christos Exp $ */
2*0a6a1f1dSLionel Sambuc
3*0a6a1f1dSLionel Sambuc /*-
4*0a6a1f1dSLionel Sambuc * Copyright (c) 2009 Kai Wang
5*0a6a1f1dSLionel Sambuc * All rights reserved.
6*0a6a1f1dSLionel Sambuc *
7*0a6a1f1dSLionel Sambuc * Redistribution and use in source and binary forms, with or without
8*0a6a1f1dSLionel Sambuc * modification, are permitted provided that the following conditions
9*0a6a1f1dSLionel Sambuc * are met:
10*0a6a1f1dSLionel Sambuc * 1. Redistributions of source code must retain the above copyright
11*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer.
12*0a6a1f1dSLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
13*0a6a1f1dSLionel Sambuc * notice, this list of conditions and the following disclaimer in the
14*0a6a1f1dSLionel Sambuc * documentation and/or other materials provided with the distribution.
15*0a6a1f1dSLionel Sambuc *
16*0a6a1f1dSLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*0a6a1f1dSLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*0a6a1f1dSLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*0a6a1f1dSLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*0a6a1f1dSLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*0a6a1f1dSLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*0a6a1f1dSLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*0a6a1f1dSLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*0a6a1f1dSLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*0a6a1f1dSLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*0a6a1f1dSLionel Sambuc * SUCH DAMAGE.
27*0a6a1f1dSLionel Sambuc */
28*0a6a1f1dSLionel Sambuc
29*0a6a1f1dSLionel Sambuc #include "_libdwarf.h"
30*0a6a1f1dSLionel Sambuc
31*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: libdwarf_elf_init.c,v 1.2 2014/03/09 16:58:04 christos Exp $");
32*0a6a1f1dSLionel Sambuc ELFTC_VCSID("Id: libdwarf_elf_init.c 2972 2013-12-23 06:46:04Z kaiwang27 ");
33*0a6a1f1dSLionel Sambuc
34*0a6a1f1dSLionel Sambuc static const char *debug_name[] = {
35*0a6a1f1dSLionel Sambuc ".debug_abbrev",
36*0a6a1f1dSLionel Sambuc ".debug_aranges",
37*0a6a1f1dSLionel Sambuc ".debug_frame",
38*0a6a1f1dSLionel Sambuc ".debug_info",
39*0a6a1f1dSLionel Sambuc ".debug_types",
40*0a6a1f1dSLionel Sambuc ".debug_line",
41*0a6a1f1dSLionel Sambuc ".debug_pubnames",
42*0a6a1f1dSLionel Sambuc ".eh_frame",
43*0a6a1f1dSLionel Sambuc ".debug_macinfo",
44*0a6a1f1dSLionel Sambuc ".debug_str",
45*0a6a1f1dSLionel Sambuc ".debug_loc",
46*0a6a1f1dSLionel Sambuc ".debug_pubtypes",
47*0a6a1f1dSLionel Sambuc ".debug_ranges",
48*0a6a1f1dSLionel Sambuc ".debug_static_func",
49*0a6a1f1dSLionel Sambuc ".debug_static_vars",
50*0a6a1f1dSLionel Sambuc ".debug_typenames",
51*0a6a1f1dSLionel Sambuc ".debug_weaknames",
52*0a6a1f1dSLionel Sambuc NULL
53*0a6a1f1dSLionel Sambuc };
54*0a6a1f1dSLionel Sambuc
55*0a6a1f1dSLionel Sambuc static void
_dwarf_elf_apply_reloc(Dwarf_Debug dbg,void * buf,Elf_Data * rel_data,Elf_Data * symtab_data,int endian)56*0a6a1f1dSLionel Sambuc _dwarf_elf_apply_reloc(Dwarf_Debug dbg, void *buf, Elf_Data *rel_data,
57*0a6a1f1dSLionel Sambuc Elf_Data *symtab_data, int endian)
58*0a6a1f1dSLionel Sambuc {
59*0a6a1f1dSLionel Sambuc Dwarf_Unsigned type;
60*0a6a1f1dSLionel Sambuc GElf_Rela rela;
61*0a6a1f1dSLionel Sambuc GElf_Sym sym;
62*0a6a1f1dSLionel Sambuc size_t symndx;
63*0a6a1f1dSLionel Sambuc uint64_t offset;
64*0a6a1f1dSLionel Sambuc int size, j;
65*0a6a1f1dSLionel Sambuc
66*0a6a1f1dSLionel Sambuc j = 0;
67*0a6a1f1dSLionel Sambuc while (gelf_getrela(rel_data, j++, &rela) != NULL) {
68*0a6a1f1dSLionel Sambuc symndx = GELF_R_SYM(rela.r_info);
69*0a6a1f1dSLionel Sambuc type = GELF_R_TYPE(rela.r_info);
70*0a6a1f1dSLionel Sambuc
71*0a6a1f1dSLionel Sambuc if (gelf_getsym(symtab_data, symndx, &sym) == NULL)
72*0a6a1f1dSLionel Sambuc continue;
73*0a6a1f1dSLionel Sambuc
74*0a6a1f1dSLionel Sambuc offset = rela.r_offset;
75*0a6a1f1dSLionel Sambuc size = _dwarf_get_reloc_size(dbg, type);
76*0a6a1f1dSLionel Sambuc
77*0a6a1f1dSLionel Sambuc if (endian == ELFDATA2MSB)
78*0a6a1f1dSLionel Sambuc _dwarf_write_msb(buf, &offset, rela.r_addend, size);
79*0a6a1f1dSLionel Sambuc else
80*0a6a1f1dSLionel Sambuc _dwarf_write_lsb(buf, &offset, rela.r_addend, size);
81*0a6a1f1dSLionel Sambuc }
82*0a6a1f1dSLionel Sambuc }
83*0a6a1f1dSLionel Sambuc
84*0a6a1f1dSLionel Sambuc static int
_dwarf_elf_relocate(Dwarf_Debug dbg,Elf * elf,Dwarf_Elf_Data * ed,size_t shndx,size_t symtab,Elf_Data * symtab_data,Dwarf_Error * error)85*0a6a1f1dSLionel Sambuc _dwarf_elf_relocate(Dwarf_Debug dbg, Elf *elf, Dwarf_Elf_Data *ed, size_t shndx,
86*0a6a1f1dSLionel Sambuc size_t symtab, Elf_Data *symtab_data, Dwarf_Error *error)
87*0a6a1f1dSLionel Sambuc {
88*0a6a1f1dSLionel Sambuc GElf_Ehdr eh;
89*0a6a1f1dSLionel Sambuc GElf_Shdr sh;
90*0a6a1f1dSLionel Sambuc Elf_Scn *scn;
91*0a6a1f1dSLionel Sambuc Elf_Data *rel;
92*0a6a1f1dSLionel Sambuc int elferr;
93*0a6a1f1dSLionel Sambuc
94*0a6a1f1dSLionel Sambuc if (symtab == 0 || symtab_data == NULL)
95*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
96*0a6a1f1dSLionel Sambuc
97*0a6a1f1dSLionel Sambuc if (gelf_getehdr(elf, &eh) == NULL) {
98*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
99*0a6a1f1dSLionel Sambuc return (DW_DLE_ELF);
100*0a6a1f1dSLionel Sambuc }
101*0a6a1f1dSLionel Sambuc
102*0a6a1f1dSLionel Sambuc scn = NULL;
103*0a6a1f1dSLionel Sambuc (void) elf_errno();
104*0a6a1f1dSLionel Sambuc while ((scn = elf_nextscn(elf, scn)) != NULL) {
105*0a6a1f1dSLionel Sambuc if (gelf_getshdr(scn, &sh) == NULL) {
106*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
107*0a6a1f1dSLionel Sambuc return (DW_DLE_ELF);
108*0a6a1f1dSLionel Sambuc }
109*0a6a1f1dSLionel Sambuc
110*0a6a1f1dSLionel Sambuc if (sh.sh_type != SHT_RELA || sh.sh_size == 0)
111*0a6a1f1dSLionel Sambuc continue;
112*0a6a1f1dSLionel Sambuc
113*0a6a1f1dSLionel Sambuc if (sh.sh_info == shndx && sh.sh_link == symtab) {
114*0a6a1f1dSLionel Sambuc if ((rel = elf_getdata(scn, NULL)) == NULL) {
115*0a6a1f1dSLionel Sambuc elferr = elf_errno();
116*0a6a1f1dSLionel Sambuc if (elferr != 0) {
117*0a6a1f1dSLionel Sambuc _DWARF_SET_ERROR(NULL, error,
118*0a6a1f1dSLionel Sambuc DW_DLE_ELF, elferr);
119*0a6a1f1dSLionel Sambuc return (DW_DLE_ELF);
120*0a6a1f1dSLionel Sambuc } else
121*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
122*0a6a1f1dSLionel Sambuc }
123*0a6a1f1dSLionel Sambuc
124*0a6a1f1dSLionel Sambuc ed->ed_alloc = malloc(ed->ed_data->d_size);
125*0a6a1f1dSLionel Sambuc if (ed->ed_alloc == NULL) {
126*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
127*0a6a1f1dSLionel Sambuc return (DW_DLE_MEMORY);
128*0a6a1f1dSLionel Sambuc }
129*0a6a1f1dSLionel Sambuc memcpy(ed->ed_alloc, ed->ed_data->d_buf,
130*0a6a1f1dSLionel Sambuc ed->ed_data->d_size);
131*0a6a1f1dSLionel Sambuc _dwarf_elf_apply_reloc(dbg, ed->ed_alloc, rel,
132*0a6a1f1dSLionel Sambuc symtab_data, eh.e_ident[EI_DATA]);
133*0a6a1f1dSLionel Sambuc
134*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
135*0a6a1f1dSLionel Sambuc }
136*0a6a1f1dSLionel Sambuc }
137*0a6a1f1dSLionel Sambuc elferr = elf_errno();
138*0a6a1f1dSLionel Sambuc if (elferr != 0) {
139*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
140*0a6a1f1dSLionel Sambuc return (DW_DLE_ELF);
141*0a6a1f1dSLionel Sambuc }
142*0a6a1f1dSLionel Sambuc
143*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
144*0a6a1f1dSLionel Sambuc }
145*0a6a1f1dSLionel Sambuc
146*0a6a1f1dSLionel Sambuc int
_dwarf_elf_init(Dwarf_Debug dbg,Elf * elf,Dwarf_Error * error)147*0a6a1f1dSLionel Sambuc _dwarf_elf_init(Dwarf_Debug dbg, Elf *elf, Dwarf_Error *error)
148*0a6a1f1dSLionel Sambuc {
149*0a6a1f1dSLionel Sambuc Dwarf_Obj_Access_Interface *iface;
150*0a6a1f1dSLionel Sambuc Dwarf_Elf_Object *e;
151*0a6a1f1dSLionel Sambuc const char *name;
152*0a6a1f1dSLionel Sambuc GElf_Shdr sh;
153*0a6a1f1dSLionel Sambuc Elf_Scn *scn;
154*0a6a1f1dSLionel Sambuc Elf_Data *symtab_data;
155*0a6a1f1dSLionel Sambuc size_t symtab_ndx;
156*0a6a1f1dSLionel Sambuc int elferr, i, j, n, ret;
157*0a6a1f1dSLionel Sambuc
158*0a6a1f1dSLionel Sambuc ret = DW_DLE_NONE;
159*0a6a1f1dSLionel Sambuc
160*0a6a1f1dSLionel Sambuc if ((iface = calloc(1, sizeof(*iface))) == NULL) {
161*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
162*0a6a1f1dSLionel Sambuc return (DW_DLE_MEMORY);
163*0a6a1f1dSLionel Sambuc }
164*0a6a1f1dSLionel Sambuc
165*0a6a1f1dSLionel Sambuc if ((e = calloc(1, sizeof(*e))) == NULL) {
166*0a6a1f1dSLionel Sambuc free(iface);
167*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
168*0a6a1f1dSLionel Sambuc return (DW_DLE_MEMORY);
169*0a6a1f1dSLionel Sambuc }
170*0a6a1f1dSLionel Sambuc
171*0a6a1f1dSLionel Sambuc e->eo_elf = elf;
172*0a6a1f1dSLionel Sambuc e->eo_methods.get_section_info = _dwarf_elf_get_section_info;
173*0a6a1f1dSLionel Sambuc e->eo_methods.get_byte_order = _dwarf_elf_get_byte_order;
174*0a6a1f1dSLionel Sambuc e->eo_methods.get_length_size = _dwarf_elf_get_length_size;
175*0a6a1f1dSLionel Sambuc e->eo_methods.get_pointer_size = _dwarf_elf_get_pointer_size;
176*0a6a1f1dSLionel Sambuc e->eo_methods.get_section_count = _dwarf_elf_get_section_count;
177*0a6a1f1dSLionel Sambuc e->eo_methods.load_section = _dwarf_elf_load_section;
178*0a6a1f1dSLionel Sambuc
179*0a6a1f1dSLionel Sambuc iface->object = e;
180*0a6a1f1dSLionel Sambuc iface->methods = &e->eo_methods;
181*0a6a1f1dSLionel Sambuc
182*0a6a1f1dSLionel Sambuc dbg->dbg_iface = iface;
183*0a6a1f1dSLionel Sambuc
184*0a6a1f1dSLionel Sambuc if (gelf_getehdr(elf, &e->eo_ehdr) == NULL) {
185*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
186*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
187*0a6a1f1dSLionel Sambuc goto fail_cleanup;
188*0a6a1f1dSLionel Sambuc }
189*0a6a1f1dSLionel Sambuc
190*0a6a1f1dSLionel Sambuc dbg->dbg_machine = e->eo_ehdr.e_machine;
191*0a6a1f1dSLionel Sambuc
192*0a6a1f1dSLionel Sambuc if (!elf_getshstrndx(elf, &e->eo_strndx)) {
193*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
194*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
195*0a6a1f1dSLionel Sambuc goto fail_cleanup;
196*0a6a1f1dSLionel Sambuc }
197*0a6a1f1dSLionel Sambuc
198*0a6a1f1dSLionel Sambuc n = 0;
199*0a6a1f1dSLionel Sambuc symtab_ndx = 0;
200*0a6a1f1dSLionel Sambuc symtab_data = NULL;
201*0a6a1f1dSLionel Sambuc scn = NULL;
202*0a6a1f1dSLionel Sambuc (void) elf_errno();
203*0a6a1f1dSLionel Sambuc while ((scn = elf_nextscn(elf, scn)) != NULL) {
204*0a6a1f1dSLionel Sambuc if (gelf_getshdr(scn, &sh) == NULL) {
205*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
206*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
207*0a6a1f1dSLionel Sambuc goto fail_cleanup;
208*0a6a1f1dSLionel Sambuc }
209*0a6a1f1dSLionel Sambuc
210*0a6a1f1dSLionel Sambuc if ((name = elf_strptr(elf, e->eo_strndx, sh.sh_name)) ==
211*0a6a1f1dSLionel Sambuc NULL) {
212*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
213*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
214*0a6a1f1dSLionel Sambuc goto fail_cleanup;
215*0a6a1f1dSLionel Sambuc }
216*0a6a1f1dSLionel Sambuc
217*0a6a1f1dSLionel Sambuc if (!strcmp(name, ".symtab")) {
218*0a6a1f1dSLionel Sambuc symtab_ndx = elf_ndxscn(scn);
219*0a6a1f1dSLionel Sambuc if ((symtab_data = elf_getdata(scn, NULL)) == NULL) {
220*0a6a1f1dSLionel Sambuc elferr = elf_errno();
221*0a6a1f1dSLionel Sambuc if (elferr != 0) {
222*0a6a1f1dSLionel Sambuc _DWARF_SET_ERROR(NULL, error,
223*0a6a1f1dSLionel Sambuc DW_DLE_ELF, elferr);
224*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
225*0a6a1f1dSLionel Sambuc goto fail_cleanup;
226*0a6a1f1dSLionel Sambuc }
227*0a6a1f1dSLionel Sambuc }
228*0a6a1f1dSLionel Sambuc continue;
229*0a6a1f1dSLionel Sambuc }
230*0a6a1f1dSLionel Sambuc
231*0a6a1f1dSLionel Sambuc for (i = 0; debug_name[i] != NULL; i++) {
232*0a6a1f1dSLionel Sambuc if (!strcmp(name, debug_name[i]))
233*0a6a1f1dSLionel Sambuc n++;
234*0a6a1f1dSLionel Sambuc }
235*0a6a1f1dSLionel Sambuc }
236*0a6a1f1dSLionel Sambuc elferr = elf_errno();
237*0a6a1f1dSLionel Sambuc if (elferr != 0) {
238*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
239*0a6a1f1dSLionel Sambuc return (DW_DLE_ELF);
240*0a6a1f1dSLionel Sambuc }
241*0a6a1f1dSLionel Sambuc
242*0a6a1f1dSLionel Sambuc e->eo_seccnt = n;
243*0a6a1f1dSLionel Sambuc
244*0a6a1f1dSLionel Sambuc if (n == 0)
245*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
246*0a6a1f1dSLionel Sambuc
247*0a6a1f1dSLionel Sambuc if ((e->eo_data = calloc(n, sizeof(Dwarf_Elf_Data))) == NULL ||
248*0a6a1f1dSLionel Sambuc (e->eo_shdr = calloc(n, sizeof(GElf_Shdr))) == NULL) {
249*0a6a1f1dSLionel Sambuc DWARF_SET_ERROR(NULL, error, DW_DLE_MEMORY);
250*0a6a1f1dSLionel Sambuc ret = DW_DLE_MEMORY;
251*0a6a1f1dSLionel Sambuc goto fail_cleanup;
252*0a6a1f1dSLionel Sambuc }
253*0a6a1f1dSLionel Sambuc
254*0a6a1f1dSLionel Sambuc scn = NULL;
255*0a6a1f1dSLionel Sambuc j = 0;
256*0a6a1f1dSLionel Sambuc while ((scn = elf_nextscn(elf, scn)) != NULL && j < n) {
257*0a6a1f1dSLionel Sambuc if (gelf_getshdr(scn, &sh) == NULL) {
258*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
259*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
260*0a6a1f1dSLionel Sambuc goto fail_cleanup;
261*0a6a1f1dSLionel Sambuc }
262*0a6a1f1dSLionel Sambuc
263*0a6a1f1dSLionel Sambuc memcpy(&e->eo_shdr[j], &sh, sizeof(sh));
264*0a6a1f1dSLionel Sambuc
265*0a6a1f1dSLionel Sambuc if ((name = elf_strptr(elf, e->eo_strndx, sh.sh_name)) ==
266*0a6a1f1dSLionel Sambuc NULL) {
267*0a6a1f1dSLionel Sambuc DWARF_SET_ELF_ERROR(dbg, error);
268*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
269*0a6a1f1dSLionel Sambuc goto fail_cleanup;
270*0a6a1f1dSLionel Sambuc }
271*0a6a1f1dSLionel Sambuc
272*0a6a1f1dSLionel Sambuc for (i = 0; debug_name[i] != NULL; i++) {
273*0a6a1f1dSLionel Sambuc if (strcmp(name, debug_name[i]))
274*0a6a1f1dSLionel Sambuc continue;
275*0a6a1f1dSLionel Sambuc
276*0a6a1f1dSLionel Sambuc (void) elf_errno();
277*0a6a1f1dSLionel Sambuc if ((e->eo_data[j].ed_data = elf_getdata(scn, NULL)) ==
278*0a6a1f1dSLionel Sambuc NULL) {
279*0a6a1f1dSLionel Sambuc elferr = elf_errno();
280*0a6a1f1dSLionel Sambuc if (elferr != 0) {
281*0a6a1f1dSLionel Sambuc _DWARF_SET_ERROR(dbg, error,
282*0a6a1f1dSLionel Sambuc DW_DLE_ELF, elferr);
283*0a6a1f1dSLionel Sambuc ret = DW_DLE_ELF;
284*0a6a1f1dSLionel Sambuc goto fail_cleanup;
285*0a6a1f1dSLionel Sambuc }
286*0a6a1f1dSLionel Sambuc }
287*0a6a1f1dSLionel Sambuc
288*0a6a1f1dSLionel Sambuc if (_libdwarf.applyrela) {
289*0a6a1f1dSLionel Sambuc if (_dwarf_elf_relocate(dbg, elf,
290*0a6a1f1dSLionel Sambuc &e->eo_data[j], elf_ndxscn(scn), symtab_ndx,
291*0a6a1f1dSLionel Sambuc symtab_data, error) != DW_DLE_NONE)
292*0a6a1f1dSLionel Sambuc goto fail_cleanup;
293*0a6a1f1dSLionel Sambuc }
294*0a6a1f1dSLionel Sambuc
295*0a6a1f1dSLionel Sambuc j++;
296*0a6a1f1dSLionel Sambuc }
297*0a6a1f1dSLionel Sambuc }
298*0a6a1f1dSLionel Sambuc
299*0a6a1f1dSLionel Sambuc assert(j == n);
300*0a6a1f1dSLionel Sambuc
301*0a6a1f1dSLionel Sambuc return (DW_DLE_NONE);
302*0a6a1f1dSLionel Sambuc
303*0a6a1f1dSLionel Sambuc fail_cleanup:
304*0a6a1f1dSLionel Sambuc
305*0a6a1f1dSLionel Sambuc _dwarf_elf_deinit(dbg);
306*0a6a1f1dSLionel Sambuc
307*0a6a1f1dSLionel Sambuc return (ret);
308*0a6a1f1dSLionel Sambuc }
309*0a6a1f1dSLionel Sambuc
310*0a6a1f1dSLionel Sambuc void
_dwarf_elf_deinit(Dwarf_Debug dbg)311*0a6a1f1dSLionel Sambuc _dwarf_elf_deinit(Dwarf_Debug dbg)
312*0a6a1f1dSLionel Sambuc {
313*0a6a1f1dSLionel Sambuc Dwarf_Obj_Access_Interface *iface;
314*0a6a1f1dSLionel Sambuc Dwarf_Elf_Object *e;
315*0a6a1f1dSLionel Sambuc int i;
316*0a6a1f1dSLionel Sambuc
317*0a6a1f1dSLionel Sambuc iface = dbg->dbg_iface;
318*0a6a1f1dSLionel Sambuc assert(iface != NULL);
319*0a6a1f1dSLionel Sambuc
320*0a6a1f1dSLionel Sambuc e = iface->object;
321*0a6a1f1dSLionel Sambuc assert(e != NULL);
322*0a6a1f1dSLionel Sambuc
323*0a6a1f1dSLionel Sambuc if (e->eo_data) {
324*0a6a1f1dSLionel Sambuc for (i = 0; (Dwarf_Unsigned) i < e->eo_seccnt; i++) {
325*0a6a1f1dSLionel Sambuc if (e->eo_data[i].ed_alloc)
326*0a6a1f1dSLionel Sambuc free(e->eo_data[i].ed_alloc);
327*0a6a1f1dSLionel Sambuc }
328*0a6a1f1dSLionel Sambuc free(e->eo_data);
329*0a6a1f1dSLionel Sambuc }
330*0a6a1f1dSLionel Sambuc if (e->eo_shdr)
331*0a6a1f1dSLionel Sambuc free(e->eo_shdr);
332*0a6a1f1dSLionel Sambuc
333*0a6a1f1dSLionel Sambuc free(e);
334*0a6a1f1dSLionel Sambuc free(iface);
335*0a6a1f1dSLionel Sambuc
336*0a6a1f1dSLionel Sambuc dbg->dbg_iface = NULL;
337*0a6a1f1dSLionel Sambuc }
338