2 * Copyright 1996-1998 John D. Polstra.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 * $FreeBSD: src/libexec/rtld-elf/debug.c,v 1.2 1999/08/28 00:10:09 peter Exp $
26 * $DragonFly: src/libexec/rtld-elf/debug.c,v 1.4 2005/03/30 00:53:59 joerg Exp $
30 * Support for printing debugging messages.
39 static const char rel_header[] =
40 " symbol name r_info r_offset st_value st_size address value\n"
41 " ------------------------------------------------------------------------------\n";
42 static const char rel_format[] = " %-25s %6x %08x %08x %7d %10p %08x\n";
47 debug_printf(const char *format, ...)
54 vfprintf(stderr, format, ap);
62 dump_relocations (Obj_Entry *obj0)
66 for (obj = obj0; obj != NULL; obj = obj->next) {
67 dump_obj_relocations(obj);
72 dump_obj_relocations (Obj_Entry *obj)
75 printf("Object \"%s\", relocbase %p\n", obj->path, obj->relocbase);
78 printf("Non-PLT Relocations: %ld\n",
79 (obj->relsize / sizeof(Elf_Rel)));
80 dump_Elf_Rel(obj, obj->rel, obj->relsize);
84 printf("Non-PLT Relocations with Addend: %ld\n",
85 (obj->relasize / sizeof(Elf_Rela)));
86 dump_Elf_Rela(obj, obj->rela, obj->relasize);
89 if (obj->pltrelsize) {
90 printf("PLT Relocations: %ld\n",
91 (obj->pltrelsize / sizeof(Elf_Rel)));
92 dump_Elf_Rel(obj, obj->pltrel, obj->pltrelsize);
95 if (obj->pltrelasize) {
96 printf("PLT Relocations with Addend: %ld\n",
97 (obj->pltrelasize / sizeof(Elf_Rela)));
98 dump_Elf_Rela(obj, obj->pltrela, obj->pltrelasize);
103 dump_Elf_Rel (Obj_Entry *obj, const Elf_Rel *rel0, u_long relsize)
106 const Elf_Rel *rellim;
110 printf("%s", rel_header);
111 rellim = (const Elf_Rel *)((const char *)rel0 + relsize);
112 for (rel = rel0; rel < rellim; rel++) {
113 dstaddr = (Elf_Addr *)(obj->relocbase + rel->r_offset);
114 sym = obj->symtab + ELF_R_SYM(rel->r_info);
116 obj->strtab + sym->st_name,
117 rel->r_info, rel->r_offset,
118 sym->st_value, sym->st_size,
125 dump_Elf_Rela (Obj_Entry *obj, const Elf_Rela *rela0, u_long relasize)
127 const Elf_Rela *rela;
128 const Elf_Rela *relalim;
132 printf("%s", rel_header);
133 relalim = (const Elf_Rela *)((const char *)rela0 + relasize);
134 for (rela = rela0; rela < relalim; rela++) {
135 dstaddr = (Elf_Addr *)(obj->relocbase + rela->r_offset);
136 sym = obj->symtab + ELF_R_SYM(rela->r_info);
138 obj->strtab + sym->st_name,
139 rela->r_info, rela->r_offset,
140 sym->st_value, sym->st_size,