linker_debug.h revision 4e468ed2eb86a2406e14f1eca82072ee501d05fd
1#ifndef _LINKER_DEBUG_H_
2#define _LINKER_DEBUG_H_
3
4#include <stdio.h>
5
6/* WARNING: For linker debugging only.. Be careful not to leave  any of
7 * this on when submitting back to repository */
8#define LINKER_DEBUG         0
9#define TRACE_DEBUG          0
10#define DO_TRACE_LOOKUP      1
11#define DO_TRACE_RELO        1
12#define TIMING               0
13#define STATS                0
14#define COUNT_PAGES          0
15
16/*********************************************************************
17 * You shouldn't need to modify anything below unless you are adding
18 * more debugging information.
19 *
20 * To enable/disable specific debug options, change the defines above
21 *********************************************************************/
22
23
24/*********************************************************************/
25#undef TRUE
26#undef FALSE
27#define TRUE                 1
28#define FALSE                0
29
30
31#define __PRINTVF(v,f,x...)   do {                                        \
32        (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout))); \
33    } while (0)
34/* Only use printf() during debugging.  We have seen occasional memory
35 * corruption when the linker uses printf().
36 */
37#if LINKER_DEBUG
38extern int debug_verbosity;
39#warning "*** LINKER IS USING printf(); DO NOT CHECK THIS IN ***"
40#define _PRINTVF(v,f,x...)    __PRINTVF(v,f,x)
41#else /* !LINKER_DEBUG */
42#define _PRINTVF(v,f,x...)   do {} while(0)
43#endif /* LINKER_DEBUG */
44
45#define PRINT(x...)          _PRINTVF(-1, FALSE, x)
46#define INFO(x...)           _PRINTVF(0, TRUE, x)
47#define TRACE(x...)          _PRINTVF(1, TRUE, x)
48#define WARN(fmt,args...)    \
49        _PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args)
50#define ERROR(fmt,args...)   \
51        __PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args)
52
53#if TRACE_DEBUG
54#define DEBUG(x...)          _PRINTVF(2, TRUE, "DEBUG: " x)
55#else /* !TRACE_DEBUG */
56#define DEBUG(x...)          do {} while (0)
57#endif /* TRACE_DEBUG */
58
59#if LINKER_DEBUG
60#define TRACE_TYPE(t,x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
61#else  /* !LINKER_DEBUG */
62#define TRACE_TYPE(t,x...)   do {} while (0)
63#endif /* LINKER_DEBUG */
64
65#if STATS
66#define RELOC_ABSOLUTE        0
67#define RELOC_RELATIVE        1
68#define RELOC_COPY            2
69#define RELOC_SYMBOL          3
70#define NUM_RELOC_STATS       4
71
72struct _link_stats {
73    int reloc[NUM_RELOC_STATS];
74};
75extern struct _link_stats linker_stats;
76
77#define COUNT_RELOC(type)                                 \
78        do { if (type >= 0 && type < NUM_RELOC_STATS) {   \
79                linker_stats.reloc[type] += 1;            \
80             } else  {                                    \
81                PRINT("Unknown reloc stat requested\n");  \
82             }                                            \
83           } while(0)
84#else /* !STATS */
85#define COUNT_RELOC(type)     do {} while(0)
86#endif /* STATS */
87
88#if TIMING
89#undef WARN
90#define WARN(x...)           do {} while (0)
91#endif /* TIMING */
92
93#if COUNT_PAGES
94extern unsigned bitmask[];
95#define MARK(offset)         do {                                        \
96        bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \
97    } while(0)
98#else
99#define MARK(x)              do {} while (0)
100#endif
101
102#define DEBUG_DUMP_PHDR(phdr, name, pid) do { \
103        DEBUG("%5d %s (phdr = 0x%08x)\n", (pid), (name), (unsigned)(phdr));   \
104        DEBUG("\t\tphdr->offset   = 0x%08x\n", (unsigned)((phdr)->p_offset)); \
105        DEBUG("\t\tphdr->p_vaddr  = 0x%08x\n", (unsigned)((phdr)->p_vaddr));  \
106        DEBUG("\t\tphdr->p_paddr  = 0x%08x\n", (unsigned)((phdr)->p_paddr));  \
107        DEBUG("\t\tphdr->p_filesz = 0x%08x\n", (unsigned)((phdr)->p_filesz)); \
108        DEBUG("\t\tphdr->p_memsz  = 0x%08x\n", (unsigned)((phdr)->p_memsz));  \
109        DEBUG("\t\tphdr->p_flags  = 0x%08x\n", (unsigned)((phdr)->p_flags));  \
110        DEBUG("\t\tphdr->p_align  = 0x%08x\n", (unsigned)((phdr)->p_align));  \
111    } while (0)
112
113#endif /* _LINKER_DEBUG_H_ */
114