11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/* 2dd57029ed1dfc9cd3116d3797c40d92d5310594eElliott Hughes * Copyright (C) 2008 The Android Open Source Project 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved. 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions of source code must retain the above copyright 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * * Redistributions in binary form must reproduce the above copyright 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * the documentation and/or other materials provided with the 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * distribution. 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _LINKER_DEBUG_H_ 301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _LINKER_DEBUG_H_ 311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 320493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// You can increase the verbosity of debug traces by defining the LD_DEBUG 330493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// environment variable to a numeric value from 0 to 2 (corresponding to 340493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// INFO, TRACE, and DEBUG calls in the source). This will only 350493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// affect new processes being launched. 360493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes 370493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// By default, traces are sent to logcat, with the "linker" tag. You can 380493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// change this to go to stdout instead by setting the definition of 390493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes// LINKER_DEBUG_TO_LOG to 0. 405c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define LINKER_DEBUG_TO_LOG 1 410493a6f7be42e22d68e1d6ddb8eb2edaf818756fElliott Hughes 425c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define TRACE_DEBUG 1 435c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define DO_TRACE_LOOKUP 1 445c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#define DO_TRACE_RELO 1 45c5a13efa9bc4264be0a9a9e37c00633af01584edBrigid Smith#define DO_TRACE_IFUNC 1 461dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define TIMING 0 471dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define STATS 0 481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define COUNT_PAGES 0 491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/********************************************************************* 511dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * You shouldn't need to modify anything below unless you are adding 521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * more debugging information. 531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 541dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * To enable/disable specific debug options, change the defines above 551dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *********************************************************************/ 561dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 578f2a5a0b40fc82126c691d5c30131d908772aab7Elliott Hughes#include "private/libc_logging.h" 583697b52605230d1479b662dceb27b4ef1fab0567Nick Kralevich 591728b2396591853345507a063ed6075dfd251706Elliott Hughes__LIBC_HIDDEN__ extern int g_ld_debug_verbosity; 60650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes 615c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#if LINKER_DEBUG_TO_LOG 62faf05bacd45719291b371f24b1b89543881b37f6Elliott Hughes#define _PRINTVF(v, x...) \ 63ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes do { \ 641728b2396591853345507a063ed6075dfd251706Elliott Hughes if (g_ld_debug_verbosity > (v)) __libc_format_log(5-(v), "linker", x); \ 655c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner } while (0) 665c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#else /* !LINKER_DEBUG_TO_LOG */ 67faf05bacd45719291b371f24b1b89543881b37f6Elliott Hughes#define _PRINTVF(v, x...) \ 68ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes do { \ 691728b2396591853345507a063ed6075dfd251706Elliott Hughes if (g_ld_debug_verbosity > (v)) { __libc_format_fd(1, x); write(1, "\n", 1); } \ 702e85579c34047c305caf15fb0ebe02bf3d001d0eDima Zavin } while (0) 715c734644eebf8d01be1e86cbe20a111a5c5a2738David 'Digit' Turner#endif /* !LINKER_DEBUG_TO_LOG */ 723697b52605230d1479b662dceb27b4ef1fab0567Nick Kralevich 73bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define PRINT(x...) _PRINTVF(-1, x) 74bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define INFO(x...) _PRINTVF(0, x) 75bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define TRACE(x...) _PRINTVF(1, x) 761dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#if TRACE_DEBUG 78bedfe38b8ba512dd6236c00e8b4a9b01c2bd1281Elliott Hughes#define DEBUG(x...) _PRINTVF(2, "DEBUG: " x) 791dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#else /* !TRACE_DEBUG */ 801dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define DEBUG(x...) do {} while (0) 811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* TRACE_DEBUG */ 821dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 83faf05bacd45719291b371f24b1b89543881b37f6Elliott Hughes#define TRACE_TYPE(t, x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0) 841dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 85114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#if COUNT_PAGES 86114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanovextern uint32_t bitmask[]; 87114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#if defined(__LP64__) 88114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#define MARK(offset) \ 89114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov do { \ 90114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov if ((((offset) >> 12) >> 5) < 4096) \ 91114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov bitmask[((offset) >> 12) >> 5] |= (1 << (((offset) >> 12) & 31)); \ 92114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov } while (0) 93114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#else 94114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#define MARK(offset) \ 95114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov do { \ 96114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov bitmask[((offset) >> 12) >> 3] |= (1 << (((offset) >> 12) & 7)); \ 97114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov } while (0) 98114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#endif 99114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#else 100114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#define MARK(x) do {} while (0) 101114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov 102114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov#endif 103114ff69f1753c7fe4d749f8fb0c082b80e0d43f4Dmitriy Ivanov 1041dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif /* _LINKER_DEBUG_H_ */ 105