• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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 #pragma once
30 
31 // You can increase the verbosity of debug traces by defining the LD_DEBUG
32 // environment variable to a numeric value from 0 to 2 (corresponding to
33 // INFO, TRACE, and DEBUG calls in the source). This will only
34 // affect new processes being launched.
35 
36 // By default, traces are sent to logcat, with the "linker" tag. You can
37 // change this to go to stdout instead by setting the definition of
38 // LINKER_DEBUG_TO_LOG to 0.
39 #define LINKER_DEBUG_TO_LOG  1
40 
41 #define TRACE_DEBUG          1
42 #define DO_TRACE_LOOKUP      1
43 #define DO_TRACE_RELO        1
44 #define DO_TRACE_IFUNC       1
45 #define TIMING               0
46 #define STATS                0
47 
48 /*********************************************************************
49  * You shouldn't need to modify anything below unless you are adding
50  * more debugging information.
51  *
52  * To enable/disable specific debug options, change the defines above
53  *********************************************************************/
54 
55 #include <stdarg.h>
56 #include <unistd.h>
57 
58 #include <async_safe/log.h>
59 #include <async_safe/CHECK.h>
60 
61 #define LINKER_VERBOSITY_PRINT (-1)
62 #define LINKER_VERBOSITY_INFO   0
63 #define LINKER_VERBOSITY_TRACE  1
64 #define LINKER_VERBOSITY_DEBUG  2
65 
66 __LIBC_HIDDEN__ extern int g_ld_debug_verbosity;
67 
68 __LIBC_HIDDEN__ void linker_log_va_list(int prio, const char* fmt, va_list ap);
69 __LIBC_HIDDEN__ void linker_log(int prio, const char* fmt, ...) __printflike(2, 3);
70 
71 #define _PRINTVF(v, x...) \
72     do { \
73       if (g_ld_debug_verbosity > (v)) linker_log((v), x); \
74     } while (0)
75 
76 #define PRINT(x...)          _PRINTVF(LINKER_VERBOSITY_PRINT, x)
77 #define INFO(x...)           _PRINTVF(LINKER_VERBOSITY_INFO, x)
78 #define TRACE(x...)          _PRINTVF(LINKER_VERBOSITY_TRACE, x)
79 
80 #if TRACE_DEBUG
81 #define DEBUG(x...)          _PRINTVF(LINKER_VERBOSITY_DEBUG, "DEBUG: " x)
82 #else /* !TRACE_DEBUG */
83 #define DEBUG(x...)          do {} while (0)
84 #endif /* TRACE_DEBUG */
85 
86 #define TRACE_TYPE(t, x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0)
87