1 /* vi: set sw=4 ts=4: */
2 /* common debug code for ELF shared library loader
4 * Copyright (c) 1994-2000 Eric Youngdale, Peter MacDonald,
5 * David Engel, Hongjiu Lu and Mitch D'Souza
6 * Copyright (C) 2001-2004 Erik Andersen
7 * Copyright (C) 2002-2004, Axis Communications AB
8 * Copyright (C) 2003, 2004 Red Hat, Inc.
9 * Copyright (C) 2002, Steven J. Hill (sjhill@realitydiluted.com)
10 * Copyright (C) 2001-2002 David A. Schleef
11 * Copyright (C) 2004 Joakim Tjernlund
12 * Copyright (C) 2002, Stefan Allius <allius@atecom.com> and
13 * Eddie C. Dost <ecd@atecom.com>
14 * Copyright (C) 2003, 2004, 2005 Paul Mundt <lethal@linux-sh.org>
16 * All rights reserved.
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. The name of the above contributors may not be
24 * used to endorse or promote products derived from this software
25 * without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #if defined (__SUPPORT_LD_DEBUG__)
44 /* include the arch-specific _dl_reltypes_tab */
47 static const char *_dl_reltypes(int type)
53 tabsize = (int)(sizeof(_dl_reltypes_tab) / sizeof(_dl_reltypes_tab[0]));
55 if (type >= tabsize || (str = _dl_reltypes_tab[type]) == NULL)
56 str = _dl_simple_ltoa(buf, (unsigned long)type);
60 static void debug_sym(ElfW(Sym) *symtab, char *strtab, int symtab_index)
62 if (!_dl_debug_symbols || !symtab_index)
65 _dl_dprintf(_dl_debug_file,
66 "\n%s\n\tvalue=%x\tsize=%x\tinfo=%x\tother=%x\tshndx=%x",
67 strtab + symtab[symtab_index].st_name,
68 symtab[symtab_index].st_value,
69 symtab[symtab_index].st_size,
70 symtab[symtab_index].st_info,
71 symtab[symtab_index].st_other,
72 symtab[symtab_index].st_shndx);
75 static void debug_reloc(ElfW(Sym) *symtab, char *strtab, ELF_RELOC *rpnt)
80 if (_dl_debug_symbols) {
81 _dl_dprintf(_dl_debug_file, "\n\t");
86 symtab_index = ELF_R_SYM(rpnt->r_info);
87 sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0";
89 _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym);
92 _dl_dprintf(_dl_debug_file, "%s\toffset=%x",
93 _dl_reltypes(ELF_R_TYPE(rpnt->r_info)),
95 #ifdef ELF_USES_RELOCA
96 _dl_dprintf(_dl_debug_file, "\taddend=%x", rpnt->r_addend);
98 _dl_dprintf(_dl_debug_file, "\n");
103 #define debug_sym(symtab, strtab, symtab_index)
104 #define debug_reloc(symtab, strtab, rpnt)
106 #endif /* __SUPPORT_LD_DEBUG__ */
108 #ifdef __LDSO_PRELINK_SUPPORT__
111 _dl_debug_lookup (const char *undef_name, struct elf_resolve *undef_map,
112 const ElfW(Sym) *ref, struct symbol_ref *value, int type_class)
115 unsigned long symbol_addr;
117 if (_dl_trace_prelink)
120 struct symbol_ref val = { ref, NULL };
122 if ((_dl_trace_prelink_map == NULL
123 || _dl_trace_prelink_map == _dl_loaded_modules)
124 && undef_map != _dl_loaded_modules)
126 symbol_addr = (unsigned long)
127 _dl_find_hash(undef_name, &undef_map->symbol_scope,
128 undef_map, type_class, &val);
130 if (val.sym != value->sym || val.tpnt != value->tpnt)
135 && (__builtin_expect (ELF_ST_TYPE(value->sym->st_info)
140 || _dl_trace_prelink_map == undef_map
141 || _dl_trace_prelink_map == NULL
144 _dl_dprintf (1, "%s %x %x -> %x %x ",
145 conflict ? "conflict" : "lookup",
146 (size_t) undef_map->mapaddr,
147 (size_t) (((ElfW(Addr)) ref) - undef_map->mapaddr),
148 (size_t) (value->tpnt ? value->tpnt->mapaddr : 0),
149 (size_t) (value->sym ? value->sym->st_value : 0));
151 _dl_dprintf (1, "x %x %x ",
152 (size_t) (val.tpnt ? val.tpnt->mapaddr : 0),
153 (size_t) (val.sym ? val.sym->st_value : 0));
154 _dl_dprintf (1, "/%x %s\n", type_class, undef_name);
161 #define _dl_debug_lookup(undef_name, undef_map, ref, value, type_class)