Commit | Line | Data |
---|---|---|
d42e7319 JB |
1 | /* |
2 | * Copyright (C) 2008-2010 The Android Open Source Project | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * * Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in | |
12 | * the documentation and/or other materials provided with the | |
13 | * distribution. | |
14 | * | |
15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | |
18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | |
19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | |
22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |
25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
26 | * SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef _LINKER_DEBUG_H_ | |
30 | #define _LINKER_DEBUG_H_ | |
31 | ||
32 | #include <stdio.h> | |
33 | ||
34 | #ifndef LINKER_DEBUG | |
35 | #error LINKER_DEBUG should be defined to either 1 or 0 in Android.mk | |
36 | #endif | |
37 | ||
38 | #define TRACE_DEBUG 1 | |
39 | #define DO_TRACE_LOOKUP 1 | |
40 | #define DO_TRACE_RELO 1 | |
41 | #define TIMING 0 | |
42 | #define STATS 0 | |
43 | #define COUNT_PAGES 0 | |
44 | ||
45 | /********************************************************************* | |
46 | * You shouldn't need to modify anything below unless you are adding | |
47 | * more debugging information. | |
48 | * | |
49 | * To enable/disable specific debug options, change the defines above | |
50 | *********************************************************************/ | |
51 | ||
52 | ||
53 | /*********************************************************************/ | |
54 | #undef TRUE | |
55 | #undef FALSE | |
56 | #define TRUE 1 | |
57 | #define FALSE 0 | |
58 | ||
59 | /* Only use printf() during debugging. We have seen occasional memory | |
60 | * corruption when the linker uses printf(). | |
61 | */ | |
62 | #if LINKER_DEBUG | |
63 | #include "linker_format.h" | |
64 | extern int debug_verbosity; | |
65 | extern int debug_stdout; | |
66 | extern int format_log(int, const char *, const char *, ...); | |
67 | extern int format_fd(int, const char *, ...); | |
68 | #define _PRINTVF(v,f,x...) \ | |
69 | do { \ | |
70 | if (debug_verbosity > (v)) \ | |
71 | if (debug_stdout) \ | |
72 | format_fd(1, x); \ | |
73 | else \ | |
74 | format_log(5-(v),"linker",x); \ | |
75 | } while (0) | |
76 | #else /* !LINKER_DEBUG */ | |
77 | #define _PRINTVF(v,f,x...) do {} while(0) | |
78 | #endif /* LINKER_DEBUG */ | |
79 | ||
80 | #define PRINT(x...) _PRINTVF(-1, FALSE, x) | |
81 | #define INFO(x...) _PRINTVF(0, TRUE, x) | |
82 | #define TRACE(x...) _PRINTVF(1, TRUE, x) | |
83 | #define WARN(fmt,args...) \ | |
84 | _PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args) | |
85 | #define ERROR(fmt,args...) \ | |
86 | _PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args) | |
87 | ||
88 | ||
89 | #if TRACE_DEBUG | |
90 | #define DEBUG(x...) _PRINTVF(2, TRUE, "DEBUG: " x) | |
91 | #else /* !TRACE_DEBUG */ | |
92 | #define DEBUG(x...) do {} while (0) | |
93 | #endif /* TRACE_DEBUG */ | |
94 | ||
95 | #if LINKER_DEBUG | |
96 | #define TRACE_TYPE(t,x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0) | |
97 | #else /* !LINKER_DEBUG */ | |
98 | #define TRACE_TYPE(t,x...) do {} while (0) | |
99 | #endif /* LINKER_DEBUG */ | |
100 | ||
101 | #if STATS | |
102 | #define RELOC_ABSOLUTE 0 | |
103 | #define RELOC_RELATIVE 1 | |
104 | #define RELOC_COPY 2 | |
105 | #define RELOC_SYMBOL 3 | |
106 | #define NUM_RELOC_STATS 4 | |
107 | ||
108 | struct _link_stats { | |
109 | int reloc[NUM_RELOC_STATS]; | |
110 | }; | |
111 | extern struct _link_stats linker_stats; | |
112 | ||
113 | #define COUNT_RELOC(type) \ | |
114 | do { if (type >= 0 && type < NUM_RELOC_STATS) { \ | |
115 | linker_stats.reloc[type] += 1; \ | |
116 | } else { \ | |
117 | PRINT("Unknown reloc stat requested\n"); \ | |
118 | } \ | |
119 | } while(0) | |
120 | #else /* !STATS */ | |
121 | #define COUNT_RELOC(type) do {} while(0) | |
122 | #endif /* STATS */ | |
123 | ||
124 | #if TIMING | |
125 | #undef WARN | |
126 | #define WARN(x...) do {} while (0) | |
127 | #endif /* TIMING */ | |
128 | ||
129 | #if COUNT_PAGES | |
130 | extern unsigned bitmask[]; | |
131 | #define MARK(offset) do { \ | |
132 | bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \ | |
133 | } while(0) | |
134 | #else | |
135 | #define MARK(x) do {} while (0) | |
136 | #endif | |
137 | ||
138 | #define DEBUG_DUMP_PHDR(phdr, name, pid) do { \ | |
139 | DEBUG("%5d %s (phdr = 0x%08x)\n", (pid), (name), (unsigned)(phdr)); \ | |
140 | DEBUG("\t\tphdr->offset = 0x%08x\n", (unsigned)((phdr)->p_offset)); \ | |
141 | DEBUG("\t\tphdr->p_vaddr = 0x%08x\n", (unsigned)((phdr)->p_vaddr)); \ | |
142 | DEBUG("\t\tphdr->p_paddr = 0x%08x\n", (unsigned)((phdr)->p_paddr)); \ | |
143 | DEBUG("\t\tphdr->p_filesz = 0x%08x\n", (unsigned)((phdr)->p_filesz)); \ | |
144 | DEBUG("\t\tphdr->p_memsz = 0x%08x\n", (unsigned)((phdr)->p_memsz)); \ | |
145 | DEBUG("\t\tphdr->p_flags = 0x%08x\n", (unsigned)((phdr)->p_flags)); \ | |
146 | DEBUG("\t\tphdr->p_align = 0x%08x\n", (unsigned)((phdr)->p_align)); \ | |
147 | } while (0) | |
148 | ||
149 | #endif /* _LINKER_DEBUG_H_ */ |