1cc_library_static {
2    name: "liblinker_malloc",
3    defaults: ["linux_bionic_supported"],
4
5    srcs: [
6        "linker_allocator.cpp",
7        "linker_memory.cpp",
8    ],
9
10    // We need to access Bionic private headers in the linker.
11    include_dirs: ["bionic/libc"],
12}
13
14cc_binary {
15    defaults: ["linux_bionic_supported"],
16    srcs: [
17        "dlfcn.cpp",
18        "linker.cpp",
19        "linker_block_allocator.cpp",
20        "linker_dlwarning.cpp",
21        "linker_cfi.cpp",
22        "linker_config.cpp",
23        "linker_gdb_support.cpp",
24        "linker_globals.cpp",
25        "linker_libc_support.c",
26        "linker_libcxx_support.cpp",
27        "linker_main.cpp",
28        "linker_namespaces.cpp",
29        "linker_logger.cpp",
30        "linker_mapped_file_fragment.cpp",
31        "linker_phdr.cpp",
32        "linker_sdk_versions.cpp",
33        "linker_soinfo.cpp",
34        "linker_utils.cpp",
35        "rt.cpp",
36    ],
37
38    arch: {
39        arm: {
40            srcs: ["arch/arm/begin.S"],
41
42            cflags: ["-D__work_around_b_24465209__"],
43        },
44        arm64: {
45            srcs: ["arch/arm64/begin.S"],
46        },
47        x86: {
48            srcs: ["arch/x86/begin.c"],
49
50            cflags: ["-D__work_around_b_24465209__"],
51        },
52        x86_64: {
53            srcs: ["arch/x86_64/begin.S"],
54        },
55        mips: {
56            srcs: [
57                "arch/mips/begin.S",
58                "linker_mips.cpp",
59            ],
60        },
61        mips64: {
62            srcs: [
63                "arch/mips64/begin.S",
64                "linker_mips.cpp",
65            ],
66        },
67    },
68
69    // We need to access Bionic private headers in the linker.
70    include_dirs: ["bionic/libc"],
71
72    // -shared is used to overwrite the -Bstatic and -static
73    // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
74    // This dynamic linker is actually a shared object linked with static libraries.
75    ldflags: [
76        "-shared",
77        "-Wl,-Bsymbolic",
78        "-Wl,--exclude-libs,ALL",
79    ],
80
81    cflags: [
82        "-fno-stack-protector",
83        "-Wstrict-overflow=5",
84        "-fvisibility=hidden",
85        "-Wall",
86        "-Wextra",
87        "-Wunused",
88        "-Werror",
89    ],
90
91    // TODO: split out the asflags.
92    asflags: [
93        "-fno-stack-protector",
94        "-Wstrict-overflow=5",
95        "-fvisibility=hidden",
96        "-Wall",
97        "-Wextra",
98        "-Wunused",
99        "-Werror",
100    ],
101
102    cppflags: ["-Wold-style-cast"],
103
104    // we are going to link libc++_static manually because
105    // when stl is not set to "none" build system adds libdl
106    // to the list of static libraries which needs to be
107    // avoided in the case of building loader.
108    stl: "none",
109
110    // we don't want crtbegin.o (because we have begin.o), so unset it
111    // just for this module
112    nocrt: true,
113
114    static_libs: [
115        "libc_nomalloc",
116        "libm",
117        "libziparchive",
118        "libutils",
119        "libbase",
120        "libz",
121
122        "libdebuggerd_handler_core",
123        "libdebuggerd_handler_fallback",
124        "libdebuggerd",
125        "libbacktrace",
126        "libunwind",
127        "liblzma",
128        "libcutils",
129
130        "liblog",
131        "libc++_static",
132
133        // Important: The liblinker_malloc should be the last library in the list
134        // to overwrite any other malloc implementations by other static libraries.
135        "liblinker_malloc"
136    ],
137    static_executable: true,
138
139    name: "linker",
140    symlinks: ["linker_asan"],
141    multilib: {
142        lib64: {
143            suffix: "64",
144        },
145    },
146    target: {
147        android: {
148            static_libs: ["libdebuggerd_client"],
149        },
150        android64: {
151            cflags: ["-DTARGET_IS_64_BIT"],
152        },
153        linux_bionic: {
154            cflags: ["-DTARGET_IS_64_BIT"],
155        },
156    },
157    compile_multilib: "both",
158
159    // Leave the symbols in the shared library so that stack unwinders can produce
160    // meaningful name resolution.
161    strip: {
162        keep_symbols: true,
163    },
164
165    // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
166    // looking up symbols in the linker by mistake.
167    prefix_symbols: "__dl_",
168}
169