| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* | 
| Elliott Hughes | dd57029 | 2015-05-12 10:10:01 -0700 | [diff] [blame] | 2 |  * Copyright (C) 2008 The Android Open Source Project | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 |  | 
| Elliott Hughes | 0493a6f | 2013-03-07 11:48:58 -0800 | [diff] [blame] | 32 | // You can increase the verbosity of debug traces by defining the LD_DEBUG | 
 | 33 | // environment variable to a numeric value from 0 to 2 (corresponding to | 
 | 34 | // INFO, TRACE, and DEBUG calls in the source). This will only | 
 | 35 | // affect new processes being launched. | 
 | 36 |  | 
 | 37 | // By default, traces are sent to logcat, with the "linker" tag. You can | 
 | 38 | // change this to go to stdout instead by setting the definition of | 
 | 39 | // LINKER_DEBUG_TO_LOG to 0. | 
| David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 40 | #define LINKER_DEBUG_TO_LOG  1 | 
| Elliott Hughes | 0493a6f | 2013-03-07 11:48:58 -0800 | [diff] [blame] | 41 |  | 
| David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 42 | #define TRACE_DEBUG          1 | 
 | 43 | #define DO_TRACE_LOOKUP      1 | 
 | 44 | #define DO_TRACE_RELO        1 | 
| Brigid Smith | c5a13ef | 2014-07-23 11:22:25 -0700 | [diff] [blame] | 45 | #define DO_TRACE_IFUNC       1 | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 46 | #define TIMING               0 | 
 | 47 | #define STATS                0 | 
 | 48 | #define COUNT_PAGES          0 | 
 | 49 |  | 
 | 50 | /********************************************************************* | 
 | 51 |  * You shouldn't need to modify anything below unless you are adding | 
 | 52 |  * more debugging information. | 
 | 53 |  * | 
 | 54 |  * To enable/disable specific debug options, change the defines above | 
 | 55 |  *********************************************************************/ | 
 | 56 |  | 
| Elliott Hughes | 8f2a5a0 | 2013-03-15 15:30:25 -0700 | [diff] [blame] | 57 | #include "private/libc_logging.h" | 
| Dimitry Ivanov | e78deef | 2015-12-14 14:11:17 -0800 | [diff] [blame] | 58 | #include <unistd.h> | 
| Nick Kralevich | 3697b52 | 2012-08-24 13:40:25 -0700 | [diff] [blame] | 59 |  | 
| Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 60 | __LIBC_HIDDEN__ extern int g_ld_debug_verbosity; | 
| Elliott Hughes | 650be4e | 2013-03-05 18:47:58 -0800 | [diff] [blame] | 61 |  | 
| Dmitriy Ivanov | cf1cbbe | 2015-10-19 16:57:46 -0700 | [diff] [blame] | 62 | #define CHECK(predicate) { \ | 
 | 63 |     if (!(predicate)) { \ | 
 | 64 |       __libc_fatal("%s:%d: %s CHECK '" #predicate "' failed", \ | 
 | 65 |           __FILE__, __LINE__, __FUNCTION__); \ | 
 | 66 |     } \ | 
 | 67 |   } | 
 | 68 |  | 
| David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 69 | #if LINKER_DEBUG_TO_LOG | 
| Elliott Hughes | faf05ba | 2014-02-11 16:59:37 -0800 | [diff] [blame] | 70 | #define _PRINTVF(v, x...) \ | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 71 |     do { \ | 
| Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 72 |       if (g_ld_debug_verbosity > (v)) __libc_format_log(5-(v), "linker", x); \ | 
| Dima Zavin | 2e85579 | 2009-05-20 18:28:09 -0700 | [diff] [blame] | 73 |     } while (0) | 
| David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 74 | #else /* !LINKER_DEBUG_TO_LOG */ | 
| Elliott Hughes | faf05ba | 2014-02-11 16:59:37 -0800 | [diff] [blame] | 75 | #define _PRINTVF(v, x...) \ | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 76 |     do { \ | 
| Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 77 |       if (g_ld_debug_verbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \ | 
| David 'Digit' Turner | 5c73464 | 2010-01-20 12:36:51 -0800 | [diff] [blame] | 78 |     } while (0) | 
 | 79 | #endif /* !LINKER_DEBUG_TO_LOG */ | 
| Nick Kralevich | 3697b52 | 2012-08-24 13:40:25 -0700 | [diff] [blame] | 80 |  | 
| Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 81 | #define PRINT(x...)          _PRINTVF(-1, x) | 
 | 82 | #define INFO(x...)           _PRINTVF(0, x) | 
 | 83 | #define TRACE(x...)          _PRINTVF(1, x) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 84 |  | 
 | 85 | #if TRACE_DEBUG | 
| Elliott Hughes | bedfe38 | 2012-08-14 14:07:59 -0700 | [diff] [blame] | 86 | #define DEBUG(x...)          _PRINTVF(2, "DEBUG: " x) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 87 | #else /* !TRACE_DEBUG */ | 
 | 88 | #define DEBUG(x...)          do {} while (0) | 
 | 89 | #endif /* TRACE_DEBUG */ | 
 | 90 |  | 
| Elliott Hughes | faf05ba | 2014-02-11 16:59:37 -0800 | [diff] [blame] | 91 | #define TRACE_TYPE(t, x...)   do { if (DO_TRACE_##t) { TRACE(x); } } while (0) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 92 |  | 
| Dmitriy Ivanov | 114ff69 | 2015-01-14 11:36:38 -0800 | [diff] [blame] | 93 | #if COUNT_PAGES | 
 | 94 | extern uint32_t bitmask[]; | 
 | 95 | #if defined(__LP64__) | 
 | 96 | #define MARK(offset) \ | 
 | 97 |     do { \ | 
 | 98 |       if ((((offset) >> 12) >> 5) < 4096) \ | 
 | 99 |           bitmask[((offset) >> 12) >> 5] |= (1 << (((offset) >> 12) & 31)); \ | 
 | 100 |     } while (0) | 
 | 101 | #else | 
 | 102 | #define MARK(offset) \ | 
 | 103 |     do { \ | 
 | 104 |       bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \ | 
 | 105 |     } while (0) | 
 | 106 | #endif | 
 | 107 | #else | 
 | 108 | #define MARK(x) do {} while (0) | 
 | 109 |  | 
 | 110 | #endif | 
 | 111 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 112 | #endif /* _LINKER_DEBUG_H_ */ |