1//
2// Copyright (C) 2020 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17cc_library {
18    defaults: [
19        "native_bridge_stub_library_defaults",
20        // Definitions come from bionic/libc/Android.bp that force
21        // the usage of the correct native allocator.
22        "libc_native_allocator_defaults",
23    ],
24    name: "libnative_bridge_guest_libc",
25    overrides: ["libc"],
26    stem: "libc",
27
28    srcs: [
29        ":libc_sources_shared",
30        "__cxa_thread_atexit_impl.cpp",
31        "__libc_add_main_thread.cpp",
32        "exit.c",
33        "fork.cpp",
34        "malloc_init.cpp",
35    ],
36
37    include_dirs: [
38        "bionic/libc",
39        "bionic/libc/arch-common/bionic",
40        "bionic/libc/async_safe/include",
41        "bionic/libc/bionic",
42        "bionic/libc/stdio",
43        "bionic/libstdc++/include",
44    ],
45
46    cflags: [
47        "-D_LIBC=1",
48        "-fno-emulated-tls", // Required for GWP-Asan.
49    ],
50
51    product_variables: {
52        platform_sdk_version: {
53            asflags: ["-DPLATFORM_SDK_VERSION=%d"],
54            cflags: ["-DPLATFORM_SDK_VERSION=%d"],
55        },
56    },
57
58    arch: {
59        arm: {
60            srcs: [
61                ":libc_sources_shared_arm",
62                "stubs_arm.cpp",
63            ],
64
65            cflags: [
66                "-DCRT_LEGACY_WORKAROUND",
67            ],
68
69            version_script: ":libc.arm.map",
70
71            // Arm 32 bit does not produce complete exidx unwind information
72            // so keep the .debug_frame which is relatively small and does
73            // include needed unwind information.
74            // See b/132992102 for details.
75            strip: {
76                keep_symbols_and_debug_frame: true,
77            },
78
79            whole_static_libs: [ "libunwind_llvm" ],
80        },
81        arm64: {
82            srcs: ["stubs_arm64.cpp"],
83
84            version_script: ":libc.arm64.map",
85
86            // Leave the symbols in the shared library so that stack unwinders can produce
87            // meaningful name resolution.
88            strip: {
89                keep_symbols: true,
90            },
91
92            whole_static_libs: [ "libgcc_stripped" ],
93        }
94    },
95
96    nocrt: true,
97
98    required: ["tzdata"],
99
100    whole_static_libs: [
101        "gwp_asan",
102        "libc_init_dynamic",
103        "libc_common_shared",
104    ],
105
106    shared_libs: [
107        "ld-android",
108        "libdl",
109    ],
110
111    static_libs: [
112        "libdl_android",
113    ],
114
115    system_shared_libs: [],
116    stl: "none",
117
118    strip: {
119        keep_symbols: true,
120    },
121
122    sanitize: {
123        never: true,
124    },
125
126    // lld complains about duplicate symbols in libcrt and libgcc. Suppress the
127    // warning since this is intended right now.
128    // Bug: 117558759
129    ldflags: ["-Wl,-z,muldefs"],
130}
131