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.
29 * Support for printing debugging messages.
37 #include "rtld_printf.h"
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 %6lx %08lx %08lx %7d %10p %08lx\n";
47 debug_printf(const char *format
, ...)
53 rtld_vfdprintf(STDERR_FILENO
, format
, ap
);
54 rtld_fdputchar(STDERR_FILENO
, '\n');
61 dump_relocations (Obj_Entry
*obj0
)
65 for (obj
= globallist_curr(obj0
); obj
!= NULL
;
66 obj
= globallist_next(obj
)) {
67 dump_obj_relocations(obj
);
72 dump_obj_relocations (Obj_Entry
*obj
)
75 rtld_printf("Object \"%s\", relocbase %p\n", obj
->path
, obj
->relocbase
);
78 rtld_printf("Non-PLT Relocations: %ld\n",
79 (obj
->relsize
/ sizeof(Elf_Rel
)));
80 dump_Elf_Rel(obj
, obj
->rel
, obj
->relsize
);
84 rtld_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 rtld_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 rtld_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 rtld_putstr(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
);
115 rtld_printf(rel_format
,
116 obj
->strtab
+ sym
->st_name
,
117 (u_long
)rel
->r_info
, (u_long
)rel
->r_offset
,
118 (u_long
)sym
->st_value
, (int)sym
->st_size
,
119 dstaddr
, (u_long
)*dstaddr
);
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 rtld_putstr(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
);
137 rtld_printf(rel_format
,
138 obj
->strtab
+ sym
->st_name
,
139 (u_long
)rela
->r_info
, (u_long
)rela
->r_offset
,
140 (u_long
)sym
->st_value
, (int)sym
->st_size
,
141 dstaddr
, (u_long
)*dstaddr
);