OSDN Git Service

buildsys: cache build flags in vars
[uclinux-h8/uClibc.git] / ldso / ldso / dl-debug.c
1 /* vi: set sw=4 ts=4: */
2 /* common debug code for ELF shared library loader
3  *
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>
15  *
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions
20  * are met:
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.
26  *
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
37  * SUCH DAMAGE.
38  */
39
40 #include "ldso.h"
41
42 #if defined (__SUPPORT_LD_DEBUG__)
43
44 /* include the arch-specific _dl_reltypes_tab */
45 #include "dl-debug.h"
46
47 static const char *_dl_reltypes(int type)
48 {
49         static char buf[50];
50         const char *str;
51         int tabsize;
52
53         tabsize = (int)(sizeof(_dl_reltypes_tab) / sizeof(_dl_reltypes_tab[0]));
54
55         if (type >= tabsize || (str = _dl_reltypes_tab[type]) == NULL)
56                 str = _dl_simple_ltoa(buf, (unsigned long)type);
57
58         return str;
59 }
60 static void debug_sym(ElfW(Sym) *symtab, char *strtab, int symtab_index)
61 {
62         if (!_dl_debug_symbols || !symtab_index)
63                 return;
64
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);
73 }
74
75 static void debug_reloc(ElfW(Sym) *symtab, char *strtab, ELF_RELOC *rpnt)
76 {
77         if (!_dl_debug_reloc)
78                 return;
79
80         if (_dl_debug_symbols) {
81                 _dl_dprintf(_dl_debug_file, "\n\t");
82         } else {
83                 int symtab_index;
84                 const char *sym;
85
86                 symtab_index = ELF_R_SYM(rpnt->r_info);
87                 sym = symtab_index ? strtab + symtab[symtab_index].st_name : "sym=0x0";
88
89                 _dl_dprintf(_dl_debug_file, "\n%s\n\t", sym);
90         }
91
92         _dl_dprintf(_dl_debug_file, "%s\toffset=%x",
93                 _dl_reltypes(ELF_R_TYPE(rpnt->r_info)),
94                 rpnt->r_offset);
95 #ifdef ELF_USES_RELOCA
96         _dl_dprintf(_dl_debug_file, "\taddend=%x", rpnt->r_addend);
97 #endif
98         _dl_dprintf(_dl_debug_file, "\n");
99 }
100
101 #else
102
103 #define debug_sym(symtab, strtab, symtab_index)
104 #define debug_reloc(symtab, strtab, rpnt)
105
106 #endif /* __SUPPORT_LD_DEBUG__ */
107
108 #ifdef __LDSO_PRELINK_SUPPORT__
109 static void
110 internal_function
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)
113 {
114 #ifdef SHARED
115   unsigned long symbol_addr;
116
117   if (_dl_trace_prelink)
118     {
119       int conflict = 0;
120       struct symbol_ref val = { ref, NULL };
121
122       if ((_dl_trace_prelink_map == NULL
123            || _dl_trace_prelink_map == _dl_loaded_modules)
124           && undef_map != _dl_loaded_modules)
125         {
126                 symbol_addr = (unsigned long)
127                                           _dl_find_hash(undef_name, &undef_map->symbol_scope,
128                                                                         undef_map, type_class, &val);
129
130           if (val.sym != value->sym || val.tpnt != value->tpnt)
131             conflict = 1;
132         }
133
134       if (value->sym
135           && (__builtin_expect (ELF_ST_TYPE(value->sym->st_info)
136                                 == STT_TLS, 0)))
137         type_class = 4;
138
139       if (conflict
140           || _dl_trace_prelink_map == undef_map
141           || _dl_trace_prelink_map == NULL
142           || type_class == 4)
143         {
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));
150           if (conflict)
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);
155         }
156 }
157 #endif
158 }
159
160 #else
161 #define _dl_debug_lookup(undef_name, undef_map, ref, value, type_class)
162 #endif