libdwarf_reloc.c revision 1.1 1 1.1 christos /*-
2 1.1 christos * Copyright (c) 2010 Kai Wang
3 1.1 christos * All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms, with or without
6 1.1 christos * modification, are permitted provided that the following conditions
7 1.1 christos * are met:
8 1.1 christos * 1. Redistributions of source code must retain the above copyright
9 1.1 christos * notice, this list of conditions and the following disclaimer.
10 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 christos * notice, this list of conditions and the following disclaimer in the
12 1.1 christos * documentation and/or other materials provided with the distribution.
13 1.1 christos *
14 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 1.1 christos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 1.1 christos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 1.1 christos * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 1.1 christos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 1.1 christos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 1.1 christos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 1.1 christos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 1.1 christos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 1.1 christos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 1.1 christos * SUCH DAMAGE.
25 1.1 christos */
26 1.1 christos
27 1.1 christos #include "_libdwarf.h"
28 1.1 christos
29 1.1 christos ELFTC_VCSID("Id: libdwarf_reloc.c 2948 2013-05-30 21:25:52Z kaiwang27 ");
30 1.1 christos
31 1.1 christos Dwarf_Unsigned
32 1.1 christos _dwarf_get_reloc_type(Dwarf_P_Debug dbg, int is64)
33 1.1 christos {
34 1.1 christos
35 1.1 christos assert(dbg != NULL);
36 1.1 christos
37 1.1 christos switch (dbg->dbgp_isa) {
38 1.1 christos case DW_ISA_X86:
39 1.1 christos return (R_386_32);
40 1.1 christos case DW_ISA_X86_64:
41 1.1 christos return (is64 ? R_X86_64_64 : R_X86_64_32);
42 1.1 christos case DW_ISA_SPARC:
43 1.1 christos return (is64 ? R_SPARC_UA64 : R_SPARC_UA32);
44 1.1 christos case DW_ISA_PPC:
45 1.1 christos return (R_PPC_ADDR32);
46 1.1 christos case DW_ISA_ARM:
47 1.1 christos return (R_ARM_ABS32);
48 1.1 christos case DW_ISA_MIPS:
49 1.1 christos return (is64 ? R_MIPS_64 : R_MIPS_32);
50 1.1 christos case DW_ISA_IA64:
51 1.1 christos return (is64 ? R_IA_64_DIR64LSB : R_IA_64_DIR32LSB);
52 1.1 christos default:
53 1.1 christos break;
54 1.1 christos }
55 1.1 christos return (0); /* NOT REACHED */
56 1.1 christos }
57 1.1 christos
58 1.1 christos int
59 1.1 christos _dwarf_get_reloc_size(Dwarf_Debug dbg, Dwarf_Unsigned rel_type)
60 1.1 christos {
61 1.1 christos
62 1.1 christos switch (dbg->dbg_machine) {
63 1.1 christos case EM_NONE:
64 1.1 christos break;
65 1.1 christos case EM_ARM:
66 1.1 christos if (rel_type == R_ARM_ABS32)
67 1.1 christos return (4);
68 1.1 christos break;
69 1.1 christos case EM_386:
70 1.1 christos if (rel_type == R_386_32)
71 1.1 christos return (4);
72 1.1 christos break;
73 1.1 christos case EM_X86_64:
74 1.1 christos if (rel_type == R_X86_64_32)
75 1.1 christos return (4);
76 1.1 christos else if (rel_type == R_X86_64_64)
77 1.1 christos return (8);
78 1.1 christos break;
79 1.1 christos case EM_SPARC:
80 1.1 christos if (rel_type == R_SPARC_UA32)
81 1.1 christos return (4);
82 1.1 christos else if (rel_type == R_SPARC_UA64)
83 1.1 christos return (8);
84 1.1 christos break;
85 1.1 christos case EM_PPC:
86 1.1 christos if (rel_type == R_PPC_ADDR32)
87 1.1 christos return (4);
88 1.1 christos break;
89 1.1 christos case EM_MIPS:
90 1.1 christos if (rel_type == R_MIPS_32)
91 1.1 christos return (4);
92 1.1 christos else if (rel_type == R_MIPS_64)
93 1.1 christos return (8);
94 1.1 christos break;
95 1.1 christos case EM_IA_64:
96 1.1 christos if (rel_type == R_IA_64_SECREL32LSB)
97 1.1 christos return (4);
98 1.1 christos else if (rel_type == R_IA_64_DIR64LSB)
99 1.1 christos return (8);
100 1.1 christos break;
101 1.1 christos default:
102 1.1 christos break;
103 1.1 christos }
104 1.1 christos
105 1.1 christos /* unknown relocation. */
106 1.1 christos return (0);
107 1.1 christos }
108 1.1 christos
109 1.1 christos int
110 1.1 christos _dwarf_reloc_section_init(Dwarf_P_Debug dbg, Dwarf_Rel_Section *drsp,
111 1.1 christos Dwarf_P_Section ref, Dwarf_Error *error)
112 1.1 christos {
113 1.1 christos Dwarf_Rel_Section drs;
114 1.1 christos char name[128];
115 1.1 christos int pseudo;
116 1.1 christos
117 1.1 christos assert(dbg != NULL && drsp != NULL && ref != NULL);
118 1.1 christos
119 1.1 christos if ((drs = calloc(1, sizeof(struct _Dwarf_Rel_Section))) == NULL) {
120 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
121 1.1 christos return (DW_DLE_MEMORY);
122 1.1 christos }
123 1.1 christos
124 1.1 christos drs->drs_ref = ref;
125 1.1 christos
126 1.1 christos /*
127 1.1 christos * FIXME The logic here is most likely wrong. It should
128 1.1 christos * be the ISA that determines relocation type.
129 1.1 christos */
130 1.1 christos if (dbg->dbgp_flags & DW_DLC_SIZE_64)
131 1.1 christos drs->drs_addend = 1;
132 1.1 christos else
133 1.1 christos drs->drs_addend = 0;
134 1.1 christos
135 1.1 christos if (dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS)
136 1.1 christos pseudo = 1;
137 1.1 christos else
138 1.1 christos pseudo = 0;
139 1.1 christos
140 1.1 christos snprintf(name, sizeof(name), "%s%s",
141 1.1 christos drs->drs_addend ? ".rela" : ".rel", ref->ds_name);
142 1.1 christos if (_dwarf_section_init(dbg, &drs->drs_ds, name, pseudo, error) !=
143 1.1 christos DW_DLE_NONE) {
144 1.1 christos free(drs);
145 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
146 1.1 christos return (DW_DLE_MEMORY);
147 1.1 christos }
148 1.1 christos
149 1.1 christos STAILQ_INIT(&drs->drs_dre);
150 1.1 christos STAILQ_INSERT_TAIL(&dbg->dbgp_drslist, drs, drs_next);
151 1.1 christos dbg->dbgp_drscnt++;
152 1.1 christos *drsp = drs;
153 1.1 christos
154 1.1 christos return (DW_DLE_NONE);
155 1.1 christos }
156 1.1 christos
157 1.1 christos void
158 1.1 christos _dwarf_reloc_section_free(Dwarf_P_Debug dbg, Dwarf_Rel_Section *drsp)
159 1.1 christos {
160 1.1 christos Dwarf_Rel_Section drs, tdrs;
161 1.1 christos Dwarf_Rel_Entry dre, tdre;
162 1.1 christos
163 1.1 christos assert(dbg != NULL && drsp != NULL);
164 1.1 christos
165 1.1 christos if (*drsp == NULL)
166 1.1 christos return;
167 1.1 christos
168 1.1 christos STAILQ_FOREACH_SAFE(drs, &dbg->dbgp_drslist, drs_next, tdrs) {
169 1.1 christos if (drs != *drsp)
170 1.1 christos continue;
171 1.1 christos STAILQ_REMOVE(&dbg->dbgp_drslist, drs, _Dwarf_Rel_Section,
172 1.1 christos drs_next);
173 1.1 christos STAILQ_FOREACH_SAFE(dre, &drs->drs_dre, dre_next, tdre) {
174 1.1 christos STAILQ_REMOVE(&drs->drs_dre, dre, _Dwarf_Rel_Entry,
175 1.1 christos dre_next);
176 1.1 christos free(dre);
177 1.1 christos }
178 1.1 christos if ((dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) == 0)
179 1.1 christos _dwarf_section_free(dbg, &drs->drs_ds);
180 1.1 christos else {
181 1.1 christos if (drs->drs_ds->ds_name)
182 1.1 christos free(drs->drs_ds->ds_name);
183 1.1 christos free(drs->drs_ds);
184 1.1 christos }
185 1.1 christos free(drs);
186 1.1 christos *drsp = NULL;
187 1.1 christos dbg->dbgp_drscnt--;
188 1.1 christos break;
189 1.1 christos }
190 1.1 christos }
191 1.1 christos
192 1.1 christos int
193 1.1 christos _dwarf_reloc_entry_add(Dwarf_P_Debug dbg, Dwarf_Rel_Section drs,
194 1.1 christos Dwarf_P_Section ds, unsigned char type, unsigned char length,
195 1.1 christos Dwarf_Unsigned offset, Dwarf_Unsigned symndx, Dwarf_Unsigned addend,
196 1.1 christos const char *secname, Dwarf_Error *error)
197 1.1 christos {
198 1.1 christos Dwarf_Rel_Entry dre;
199 1.1 christos Dwarf_Unsigned reloff;
200 1.1 christos int ret;
201 1.1 christos
202 1.1 christos assert(drs != NULL);
203 1.1 christos assert(offset <= ds->ds_size);
204 1.1 christos reloff = offset;
205 1.1 christos
206 1.1 christos /*
207 1.1 christos * If the DW_DLC_SYMBOLIC_RELOCATIONS flag is set or ElfXX_Rel
208 1.1 christos * is used instead of ELfXX_Rela, we need to write the addend
209 1.1 christos * in the storage unit to be relocated. Otherwise write 0 in the
210 1.1 christos * storage unit and the addend will be written into relocation
211 1.1 christos * section later.
212 1.1 christos */
213 1.1 christos if ((dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) ||
214 1.1 christos drs->drs_addend == 0)
215 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap, &offset,
216 1.1 christos addend, length, error);
217 1.1 christos else
218 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap, &offset,
219 1.1 christos 0, length, error);
220 1.1 christos if (ret != DW_DLE_NONE)
221 1.1 christos return (ret);
222 1.1 christos if (offset > ds->ds_size)
223 1.1 christos ds->ds_size = offset;
224 1.1 christos
225 1.1 christos if ((dre = calloc(1, sizeof(struct _Dwarf_Rel_Entry))) == NULL) {
226 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
227 1.1 christos return (DW_DLE_MEMORY);
228 1.1 christos }
229 1.1 christos STAILQ_INSERT_TAIL(&drs->drs_dre, dre, dre_next);
230 1.1 christos dre->dre_type = type;
231 1.1 christos dre->dre_length = length;
232 1.1 christos dre->dre_offset = reloff;
233 1.1 christos dre->dre_symndx = symndx;
234 1.1 christos dre->dre_addend = addend;
235 1.1 christos dre->dre_secname = secname;
236 1.1 christos drs->drs_drecnt++;
237 1.1 christos
238 1.1 christos return (DW_DLE_NONE);
239 1.1 christos }
240 1.1 christos
241 1.1 christos int
242 1.1 christos _dwarf_reloc_entry_add_pair(Dwarf_P_Debug dbg, Dwarf_Rel_Section drs,
243 1.1 christos Dwarf_P_Section ds, unsigned char length, Dwarf_Unsigned offset,
244 1.1 christos Dwarf_Unsigned symndx, Dwarf_Unsigned esymndx, Dwarf_Unsigned symoff,
245 1.1 christos Dwarf_Unsigned esymoff, Dwarf_Error *error)
246 1.1 christos {
247 1.1 christos Dwarf_Rel_Entry dre;
248 1.1 christos Dwarf_Unsigned reloff;
249 1.1 christos int ret;
250 1.1 christos
251 1.1 christos assert(drs != NULL);
252 1.1 christos assert(offset <= ds->ds_size);
253 1.1 christos assert(dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS);
254 1.1 christos reloff = offset;
255 1.1 christos
256 1.1 christos /* Write net offset into section stream. */
257 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap, &offset,
258 1.1 christos esymoff - symoff, length, error);
259 1.1 christos if (ret != DW_DLE_NONE)
260 1.1 christos return (ret);
261 1.1 christos if (offset > ds->ds_size)
262 1.1 christos ds->ds_size = offset;
263 1.1 christos
264 1.1 christos if ((dre = calloc(2, sizeof(struct _Dwarf_Rel_Entry))) == NULL) {
265 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
266 1.1 christos return (DW_DLE_MEMORY);
267 1.1 christos }
268 1.1 christos STAILQ_INSERT_TAIL(&drs->drs_dre, &dre[0], dre_next);
269 1.1 christos STAILQ_INSERT_TAIL(&drs->drs_dre, &dre[1], dre_next);
270 1.1 christos dre[0].dre_type = dwarf_drt_first_of_length_pair;
271 1.1 christos dre[0].dre_length = length;
272 1.1 christos dre[0].dre_offset = reloff;
273 1.1 christos dre[0].dre_symndx = symndx;
274 1.1 christos dre[0].dre_addend = 0;
275 1.1 christos dre[0].dre_secname = NULL;
276 1.1 christos dre[1].dre_type = dwarf_drt_second_of_length_pair;
277 1.1 christos dre[1].dre_length = length;
278 1.1 christos dre[1].dre_offset = reloff;
279 1.1 christos dre[1].dre_symndx = esymndx;
280 1.1 christos dre[1].dre_addend = 0;
281 1.1 christos dre[1].dre_secname = NULL;
282 1.1 christos drs->drs_drecnt += 2;
283 1.1 christos
284 1.1 christos return (DW_DLE_NONE);
285 1.1 christos }
286 1.1 christos
287 1.1 christos int
288 1.1 christos _dwarf_reloc_section_finalize(Dwarf_P_Debug dbg, Dwarf_Rel_Section drs,
289 1.1 christos Dwarf_Error *error)
290 1.1 christos {
291 1.1 christos Dwarf_P_Section ds;
292 1.1 christos Dwarf_Unsigned unit;
293 1.1 christos int ret, size;
294 1.1 christos
295 1.1 christos assert(dbg != NULL && drs != NULL && drs->drs_ds != NULL &&
296 1.1 christos drs->drs_ref != NULL);
297 1.1 christos
298 1.1 christos ds = drs->drs_ds;
299 1.1 christos
300 1.1 christos /*
301 1.1 christos * Calculate the size (in bytes) of the relocation section.
302 1.1 christos */
303 1.1 christos if (dbg->dbgp_flags & DW_DLC_SIZE_64)
304 1.1 christos unit = drs->drs_addend ? sizeof(Elf64_Rela) : sizeof(Elf64_Rel);
305 1.1 christos else
306 1.1 christos unit = drs->drs_addend ? sizeof(Elf32_Rela) : sizeof(Elf32_Rel);
307 1.1 christos assert(ds->ds_size == 0);
308 1.1 christos size = drs->drs_drecnt * unit;
309 1.1 christos
310 1.1 christos /*
311 1.1 christos * Discard this relocation section if there is no entry in it.
312 1.1 christos */
313 1.1 christos if (size == 0) {
314 1.1 christos _dwarf_reloc_section_free(dbg, &drs);
315 1.1 christos return (DW_DLE_NONE);
316 1.1 christos }
317 1.1 christos
318 1.1 christos /*
319 1.1 christos * If we are under stream mode, realloc the section data block to
320 1.1 christos * this size.
321 1.1 christos */
322 1.1 christos if ((dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) == 0) {
323 1.1 christos ds->ds_cap = size;
324 1.1 christos if ((ds->ds_data = realloc(ds->ds_data, (size_t) ds->ds_cap)) ==
325 1.1 christos NULL) {
326 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
327 1.1 christos return (DW_DLE_MEMORY);
328 1.1 christos }
329 1.1 christos }
330 1.1 christos
331 1.1 christos /*
332 1.1 christos * Notify the application the creation of this relocation section.
333 1.1 christos * Note that the section link here should point to the .symtab
334 1.1 christos * section, we set it to 0 since we have no way to know .symtab
335 1.1 christos * section index.
336 1.1 christos */
337 1.1 christos ret = _dwarf_pro_callback(dbg, ds->ds_name, size,
338 1.1 christos drs->drs_addend ? SHT_RELA : SHT_REL, 0, 0, drs->drs_ref->ds_ndx,
339 1.1 christos &ds->ds_symndx, NULL);
340 1.1 christos if (ret < 0) {
341 1.1 christos DWARF_SET_ERROR(dbg, error, DW_DLE_ELF_SECT_ERR);
342 1.1 christos return (DW_DLE_ELF_SECT_ERR);
343 1.1 christos }
344 1.1 christos ds->ds_ndx = ret;
345 1.1 christos
346 1.1 christos return (DW_DLE_NONE);
347 1.1 christos }
348 1.1 christos
349 1.1 christos int
350 1.1 christos _dwarf_reloc_section_gen(Dwarf_P_Debug dbg, Dwarf_Rel_Section drs,
351 1.1 christos Dwarf_Error *error)
352 1.1 christos {
353 1.1 christos Dwarf_Rel_Entry dre;
354 1.1 christos Dwarf_P_Section ds;
355 1.1 christos Dwarf_Unsigned type;
356 1.1 christos int ret;
357 1.1 christos
358 1.1 christos assert((dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) == 0);
359 1.1 christos assert(drs->drs_ds != NULL && drs->drs_ds->ds_size == 0);
360 1.1 christos assert(!STAILQ_EMPTY(&drs->drs_dre));
361 1.1 christos ds = drs->drs_ds;
362 1.1 christos
363 1.1 christos STAILQ_FOREACH(dre, &drs->drs_dre, dre_next) {
364 1.1 christos assert(dre->dre_length == 4 || dre->dre_length == 8);
365 1.1 christos type = _dwarf_get_reloc_type(dbg, dre->dre_length == 8);
366 1.1 christos if (dbg->dbgp_flags & DW_DLC_SIZE_64) {
367 1.1 christos /* Write r_offset (8 bytes) */
368 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap,
369 1.1 christos &ds->ds_size, dre->dre_offset, 8, error);
370 1.1 christos if (ret != DW_DLE_NONE)
371 1.1 christos return (ret);
372 1.1 christos /* Write r_info (8 bytes) */
373 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap,
374 1.1 christos &ds->ds_size, ELF64_R_INFO(dre->dre_symndx, type),
375 1.1 christos 8, error);
376 1.1 christos if (ret != DW_DLE_NONE)
377 1.1 christos return (ret);
378 1.1 christos /* Write r_addend (8 bytes) */
379 1.1 christos if (drs->drs_addend) {
380 1.1 christos ret = dbg->write_alloc(&ds->ds_data,
381 1.1 christos &ds->ds_cap, &ds->ds_size, dre->dre_addend,
382 1.1 christos 8, error);
383 1.1 christos if (ret != DW_DLE_NONE)
384 1.1 christos return (ret);
385 1.1 christos }
386 1.1 christos } else {
387 1.1 christos /* Write r_offset (4 bytes) */
388 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap,
389 1.1 christos &ds->ds_size, dre->dre_offset, 4, error);
390 1.1 christos if (ret != DW_DLE_NONE)
391 1.1 christos return (ret);
392 1.1 christos /* Write r_info (4 bytes) */
393 1.1 christos ret = dbg->write_alloc(&ds->ds_data, &ds->ds_cap,
394 1.1 christos &ds->ds_size, ELF32_R_INFO(dre->dre_symndx, type),
395 1.1 christos 4, error);
396 1.1 christos if (ret != DW_DLE_NONE)
397 1.1 christos return (ret);
398 1.1 christos /* Write r_addend (4 bytes) */
399 1.1 christos if (drs->drs_addend) {
400 1.1 christos ret = dbg->write_alloc(&ds->ds_data,
401 1.1 christos &ds->ds_cap, &ds->ds_size, dre->dre_addend,
402 1.1 christos 4, error);
403 1.1 christos if (ret != DW_DLE_NONE)
404 1.1 christos return (ret);
405 1.1 christos }
406 1.1 christos }
407 1.1 christos }
408 1.1 christos assert(ds->ds_size == ds->ds_cap);
409 1.1 christos
410 1.1 christos return (DW_DLE_NONE);
411 1.1 christos }
412 1.1 christos
413 1.1 christos int
414 1.1 christos _dwarf_reloc_gen(Dwarf_P_Debug dbg, Dwarf_Error *error)
415 1.1 christos {
416 1.1 christos Dwarf_Rel_Section drs;
417 1.1 christos Dwarf_Rel_Entry dre;
418 1.1 christos Dwarf_P_Section ds;
419 1.1 christos int ret;
420 1.1 christos
421 1.1 christos STAILQ_FOREACH(drs, &dbg->dbgp_drslist, drs_next) {
422 1.1 christos /*
423 1.1 christos * Update relocation entries: translate any section name
424 1.1 christos * reference to section symbol index.
425 1.1 christos */
426 1.1 christos STAILQ_FOREACH(dre, &drs->drs_dre, dre_next) {
427 1.1 christos if (dre->dre_secname == NULL)
428 1.1 christos continue;
429 1.1 christos ds = _dwarf_pro_find_section(dbg, dre->dre_secname);
430 1.1 christos assert(ds != NULL && ds->ds_symndx != 0);
431 1.1 christos dre->dre_symndx = ds->ds_symndx;
432 1.1 christos }
433 1.1 christos
434 1.1 christos /*
435 1.1 christos * Generate ELF relocation section if we are under stream
436 1.1 christos * mode.
437 1.1 christos */
438 1.1 christos if ((dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) == 0) {
439 1.1 christos ret = _dwarf_reloc_section_gen(dbg, drs, error);
440 1.1 christos if (ret != DW_DLE_NONE)
441 1.1 christos return (ret);
442 1.1 christos }
443 1.1 christos }
444 1.1 christos
445 1.1 christos return (DW_DLE_NONE);
446 1.1 christos }
447 1.1 christos
448 1.1 christos void
449 1.1 christos _dwarf_reloc_cleanup(Dwarf_P_Debug dbg)
450 1.1 christos {
451 1.1 christos Dwarf_Rel_Section drs, tdrs;
452 1.1 christos Dwarf_Rel_Entry dre, tdre;
453 1.1 christos
454 1.1 christos assert(dbg != NULL && dbg->dbg_mode == DW_DLC_WRITE);
455 1.1 christos
456 1.1 christos STAILQ_FOREACH_SAFE(drs, &dbg->dbgp_drslist, drs_next, tdrs) {
457 1.1 christos STAILQ_REMOVE(&dbg->dbgp_drslist, drs, _Dwarf_Rel_Section,
458 1.1 christos drs_next);
459 1.1 christos free(drs->drs_drd);
460 1.1 christos STAILQ_FOREACH_SAFE(dre, &drs->drs_dre, dre_next, tdre) {
461 1.1 christos STAILQ_REMOVE(&drs->drs_dre, dre, _Dwarf_Rel_Entry,
462 1.1 christos dre_next);
463 1.1 christos free(dre);
464 1.1 christos }
465 1.1 christos if (dbg->dbgp_flags & DW_DLC_SYMBOLIC_RELOCATIONS) {
466 1.1 christos if (drs->drs_ds) {
467 1.1 christos if (drs->drs_ds->ds_name)
468 1.1 christos free(drs->drs_ds->ds_name);
469 1.1 christos free(drs->drs_ds);
470 1.1 christos }
471 1.1 christos }
472 1.1 christos free(drs);
473 1.1 christos }
474 1.1 christos dbg->dbgp_drscnt = 0;
475 1.1 christos dbg->dbgp_drspos = NULL;
476 1.1 christos }
477