blob: 3aab18548ab48f8320289773b9d036d17b50bbf4 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
Elliott Hughesdd570292015-05-12 10:10:01 -07002 * Copyright (C) 2008 The Android Open Source Project
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08003 * 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
Elliott Hughescbc80ba2018-02-13 14:26:29 -080029#pragma once
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080030
Elliott Hughes0493a6f2013-03-07 11:48:58 -080031// 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
David 'Digit' Turner5c734642010-01-20 12:36:51 -080036#define TRACE_DEBUG 1
37#define DO_TRACE_LOOKUP 1
38#define DO_TRACE_RELO 1
Brigid Smithc5a13ef2014-07-23 11:22:25 -070039#define DO_TRACE_IFUNC 1
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080040#define TIMING 0
41#define STATS 0
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080042
43/*********************************************************************
44 * You shouldn't need to modify anything below unless you are adding
45 * more debugging information.
46 *
47 * To enable/disable specific debug options, change the defines above
48 *********************************************************************/
49
Ryan Prichard551565e2019-12-23 16:03:14 -080050#include <stdarg.h>
Dimitry Ivanove78deef2015-12-14 14:11:17 -080051#include <unistd.h>
Nick Kralevich3697b522012-08-24 13:40:25 -070052
Christopher Ferris7a3681e2017-04-24 17:48:32 -070053#include <async_safe/log.h>
Elliott Hughes3019d782019-02-13 12:39:07 -080054#include <async_safe/CHECK.h>
Christopher Ferris7a3681e2017-04-24 17:48:32 -070055
Chih-Hung Hsiehfa658eb2020-03-04 11:14:42 -080056#define LINKER_VERBOSITY_PRINT (-1)
Ryan Prichard551565e2019-12-23 16:03:14 -080057#define LINKER_VERBOSITY_INFO 0
58#define LINKER_VERBOSITY_TRACE 1
59#define LINKER_VERBOSITY_DEBUG 2
60
Elliott Hughes1728b232014-05-14 10:02:03 -070061__LIBC_HIDDEN__ extern int g_ld_debug_verbosity;
Elliott Hughes650be4e2013-03-05 18:47:58 -080062
Ryan Prichard551565e2019-12-23 16:03:14 -080063__LIBC_HIDDEN__ void linker_log_va_list(int prio, const char* fmt, va_list ap);
64__LIBC_HIDDEN__ void linker_log(int prio, const char* fmt, ...) __printflike(2, 3);
Nick Kralevich3697b522012-08-24 13:40:25 -070065
Ryan Prichard551565e2019-12-23 16:03:14 -080066#define _PRINTVF(v, x...) \
67 do { \
68 if (g_ld_debug_verbosity > (v)) linker_log((v), x); \
69 } while (0)
70
71#define PRINT(x...) _PRINTVF(LINKER_VERBOSITY_PRINT, x)
72#define INFO(x...) _PRINTVF(LINKER_VERBOSITY_INFO, x)
73#define TRACE(x...) _PRINTVF(LINKER_VERBOSITY_TRACE, x)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080074
75#if TRACE_DEBUG
Ryan Prichard551565e2019-12-23 16:03:14 -080076#define DEBUG(x...) _PRINTVF(LINKER_VERBOSITY_DEBUG, "DEBUG: " x)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080077#else /* !TRACE_DEBUG */
78#define DEBUG(x...) do {} while (0)
79#endif /* TRACE_DEBUG */
80
Elliott Hughesfaf05ba2014-02-11 16:59:37 -080081#define TRACE_TYPE(t, x...) do { if (DO_TRACE_##t) { TRACE(x); } } while (0)