linker_debug.h revision a27d2baa0c1a2ec70f47ea9199b1dd6762c8a349
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/* Only use printf() during debugging.  We have seen occasional memory
31 * corruption when the linker uses printf().
32 */
33#if LINKER_DEBUG
34extern int debug_verbosity;
35#warning "*** LINKER IS USING printf(); DO NOT CHECK THIS IN ***"
36#define _PRINTVF(v,f,x...)   do {                                        \
37        (debug_verbosity > (v)) && (printf(x), ((f) && fflush(stdout))); \
38    } while (0)
39#else /* !LINKER_DEBUG */
40#define _PRINTVF(v,f,x...)   do {} while(0)
41#endif /* LINKER_DEBUG */
42
43#define PRINT(x...)          _PRINTVF(-1, FALSE, x)
44#define INFO(x...)           _PRINTVF(0, TRUE, x)
45#define TRACE(x...)          _PRINTVF(1, TRUE, x)
46#define WARN(fmt,args...)    \
47        _PRINTVF(-1, TRUE, "%s:%d| WARNING: " fmt, __FILE__, __LINE__, ## args)
48#define ERROR(fmt,args...)   \
49        _PRINTVF(-1, TRUE, "%s:%d| ERROR: " fmt, __FILE__, __LINE__, ## args)
50
51#if TRACE_DEBUG
52#define DEBUG(x...)          _PRINTVF(2, TRUE, "DEBUG: " x)
53#else /* !TRACE_DEBUG */
54#define DEBUG(x...)          do {} while (0)
55#endif /* TRACE_DEBUG */
56
57#if LINKER_DEBUG
58#define TRACE_TYPE(t,x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
59#else  /* !LINKER_DEBUG */
60#define TRACE_TYPE(t,x...)   do {} while (0)
61#endif /* LINKER_DEBUG */
62
63#if STATS
64#define RELOC_ABSOLUTE        0
65#define RELOC_RELATIVE        1
66#define RELOC_COPY            2
67#define RELOC_SYMBOL          3
68#define NUM_RELOC_STATS       4
69
70struct _link_stats {
71    int reloc[NUM_RELOC_STATS];
72};
73extern struct _link_stats linker_stats;
74
75#define COUNT_RELOC(type)                                 \
76        do { if (type >= 0 && type < NUM_RELOC_STATS) {   \
77                linker_stats.reloc[type] += 1;            \
78             } else  {                                    \
79                PRINT("Unknown reloc stat requested\n");  \
80             }                                            \
81           } while(0)
82#else /* !STATS */
83#define COUNT_RELOC(type)     do {} while(0)
84#endif /* STATS */
85
86#if TIMING
87#undef WARN
88#define WARN(x...)           do {} while (0)
89#endif /* TIMING */
90
91#if COUNT_PAGES
92extern unsigned bitmask[];
93#define MARK(offset)         do {                                        \
94        bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \
95    } while(0)
96#else
97#define MARK(x)              do {} while (0)
98#endif
99
100#define DEBUG_DUMP_PHDR(phdr, name, pid) do { \
101        DEBUG("%5d %s (phdr = 0x%08x)\n", (pid), (name), (unsigned)(phdr));   \
102        DEBUG("\t\tphdr->offset   = 0x%08x\n", (unsigned)((phdr)->p_offset)); \
103        DEBUG("\t\tphdr->p_vaddr  = 0x%08x\n", (unsigned)((phdr)->p_vaddr));  \
104        DEBUG("\t\tphdr->p_paddr  = 0x%08x\n", (unsigned)((phdr)->p_paddr));  \
105        DEBUG("\t\tphdr->p_filesz = 0x%08x\n", (unsigned)((phdr)->p_filesz)); \
106        DEBUG("\t\tphdr->p_memsz  = 0x%08x\n", (unsigned)((phdr)->p_memsz));  \
107        DEBUG("\t\tphdr->p_flags  = 0x%08x\n", (unsigned)((phdr)->p_flags));  \
108        DEBUG("\t\tphdr->p_align  = 0x%08x\n", (unsigned)((phdr)->p_align));  \
109    } while (0)
110
111#endif /* _LINKER_DEBUG_H_ */
112