2
* Copyright (C) 2008-2010 The Android Open Source Project
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
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
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
29
#ifndef _LINKER_DEBUG_H_
30
#define _LINKER_DEBUG_H_
35
#error LINKER_DEBUG should be defined to either 1 or 0 in Android.mk
38
/* set LINKER_DEBUG_TO_LOG to 1 to send the logs to logcat,
39
* or 0 to use stdout instead.
41
#define LINKER_DEBUG_TO_LOG 0
43
#define DO_TRACE_LOOKUP 1
44
#define DO_TRACE_RELO 1
49
/*********************************************************************
50
* You shouldn't need to modify anything below unless you are adding
51
* more debugging information.
53
* To enable/disable specific debug options, change the defines above
54
*********************************************************************/
57
/*********************************************************************/
63
/* Only use printf() during debugging. We have seen occasional memory
64
* corruption when the linker uses printf().
67
#include "linker_format.h"
68
extern int debug_verbosity;
69
#if LINKER_DEBUG_TO_LOG
70
extern int format_log(int, const char *, const char *, ...);
71
#define _PRINTVF(v,f,x...) \
73
if (debug_verbosity > (v)) format_log(5-(v),"linker",x); \
75
#else /* !LINKER_DEBUG_TO_LOG */
76
extern int format_fd(int, const char *, ...);
77
#define _PRINTVF(v,f,x...) \
79
if (debug_verbosity > (v)) format_fd(1, x); \
81
#endif /* !LINKER_DEBUG_TO_LOG */
82
#else /* !LINKER_DEBUG */
83
#define _PRINTVF(v,f,x...) do {} while(0)
84
#endif /* LINKER_DEBUG */
86
#define PRINT(x...) _PRINTVF(-1, FALSE, x)
87
#define INFO(x...) _PRINTVF(1, TRUE, x)
88
#define TRACE(x...) _PRINTVF(1, TRUE, x)
89
#define WARN(fmt,args...) \
90
_PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args)
91
#define ERROR(fmt,args...) \
92
_PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args)
96
#define DEBUG(x...) _PRINTVF(2, TRUE, "DEBUG: " x)
97
#else /* !TRACE_DEBUG */
98
#define DEBUG(x...) do {} while (0)
99
#endif /* TRACE_DEBUG */
102
#define TRACE_TYPE(t,x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
103
#else /* !LINKER_DEBUG */
104
#define TRACE_TYPE(t,x...) do {} while (0)
105
#endif /* LINKER_DEBUG */
108
#define RELOC_ABSOLUTE 0
109
#define RELOC_RELATIVE 1
111
#define RELOC_SYMBOL 3
112
#define NUM_RELOC_STATS 4
115
int reloc[NUM_RELOC_STATS];
117
extern struct _link_stats linker_stats;
119
#define COUNT_RELOC(type) \
120
do { if (type >= 0 && type < NUM_RELOC_STATS) { \
121
linker_stats.reloc[type] += 1; \
123
PRINT("Unknown reloc stat requested\n"); \
127
#define COUNT_RELOC(type) do {} while(0)
132
#define WARN(x...) do {} while (0)
136
extern unsigned bitmask[];
137
#define MARK(offset) do { \
138
bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \
141
#define MARK(x) do {} while (0)
144
#define DEBUG_DUMP_PHDR(phdr, name, pid) do { \
145
DEBUG("%5d %s (phdr = 0x%08x)\n", (pid), (name), (unsigned)(phdr)); \
146
DEBUG("\t\tphdr->offset = 0x%08x\n", (unsigned)((phdr)->p_offset)); \
147
DEBUG("\t\tphdr->p_vaddr = 0x%08x\n", (unsigned)((phdr)->p_vaddr)); \
148
DEBUG("\t\tphdr->p_paddr = 0x%08x\n", (unsigned)((phdr)->p_paddr)); \
149
DEBUG("\t\tphdr->p_filesz = 0x%08x\n", (unsigned)((phdr)->p_filesz)); \
150
DEBUG("\t\tphdr->p_memsz = 0x%08x\n", (unsigned)((phdr)->p_memsz)); \
151
DEBUG("\t\tphdr->p_flags = 0x%08x\n", (unsigned)((phdr)->p_flags)); \
152
DEBUG("\t\tphdr->p_align = 0x%08x\n", (unsigned)((phdr)->p_align)); \
155
#endif /* _LINKER_DEBUG_H_ */