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 17// We introduce this namespace so that native bridge guest libraries are built 18// only for targets that explicitly use this namespace via PRODUCT_SOONG_NAMESPACES 19// and checkbuild. 20soong_namespace { 21} 22 23package { 24 default_applicable_licenses: ["Android-Apache-2.0"], 25} 26 27cc_library { 28 defaults: [ 29 "native_bridge_stub_library_defaults", 30 // Definitions come from bionic/libc/Android.bp that force 31 // the usage of the correct native allocator. 32 "libc_native_allocator_defaults", 33 "keep_symbols", 34 ], 35 name: "libnative_bridge_guest_libc", 36 overrides: ["libc"], 37 stem: "libc", 38 39 srcs: [ 40 ":libc_sources_shared", 41 "__cxa_thread_atexit_impl.cpp", 42 "__libc_add_main_thread.cpp", 43 "__libc_init_scudo.cpp", 44 "__libc_set_target_sdk_version.cpp", 45 "exit.c", 46 "malloc_init.cpp", 47 ], 48 49 include_dirs: [ 50 "bionic/libc", 51 "bionic/libc/arch-common/bionic", 52 "bionic/libc/async_safe/include", 53 "bionic/libc/bionic", 54 "bionic/libc/stdio", 55 "bionic/libstdc++/include", 56 ], 57 58 cflags: [ 59 "-D_LIBC=1", 60 ], 61 62 product_variables: { 63 platform_sdk_version: { 64 asflags: ["-DPLATFORM_SDK_VERSION=%d"], 65 cflags: ["-DPLATFORM_SDK_VERSION=%d"], 66 }, 67 }, 68 69 arch: { 70 arm: { 71 srcs: [ 72 ":libc_sources_shared_arm", 73 "stubs_arm.cpp", 74 ], 75 76 cflags: [ 77 "-DCRT_LEGACY_WORKAROUND", 78 ], 79 80 version_script: ":libc.arm.map", 81 no_libcrt: true, 82 83 shared: { 84 // For backwards-compatibility, some arm32 builtins are exported from libc.so. 85 static_libs: ["libclang_rt.builtins-exported"], 86 }, 87 }, 88 arm64: { 89 srcs: ["stubs_arm64.cpp"], 90 91 version_script: ":libc.arm64.map", 92 }, 93 riscv64: { 94 srcs: ["stubs_riscv64.cpp"], 95 96 version_script: ":libc.riscv64.map", 97 }, 98 }, 99 100 nocrt: true, 101 102 required: ["tzdata_prebuilt"], 103 104 whole_static_libs: [ 105 "gwp_asan", 106 "libc_init_dynamic", 107 "libc_common_shared", 108 "libunwind-exported", 109 ], 110 111 shared_libs: [ 112 "ld-android", 113 "libdl", 114 ], 115 116 static_libs: [ 117 "libdl_android", 118 ], 119 120 system_shared_libs: [], 121 stl: "none", 122 123 strip: { 124 keep_symbols: true, 125 }, 126 127 sanitize: { 128 never: true, 129 }, 130 131 // lld complains about duplicate symbols in libc because we are intercepting some symbols that 132 // are not marked as weak in bionic. 133 // TODO(b/349973092): remove workaround when all relevant symbols are properly marked. 134 ldflags: ["-Wl,-z,muldefs"], 135} 136 137filegroup { 138 name: "native_bridge_proxy_libc_files", 139 srcs: [ 140 "proxy/cxa_trampolines.cc", 141 "proxy/libc_translation.cc", 142 "proxy/malloc_translation.cc", 143 "proxy/pthread_translation.cc", 144 "proxy/setjmp_thunks.cc", 145 "proxy/system_properties_trampolines.cc", 146 "proxy/unistd_thunks.cc", 147 ], 148} 149 150cc_defaults { 151 name: "native_bridge_proxy_libc_defaults", 152 srcs: ["//frameworks/libs/native_bridge_support/android_api/libc:native_bridge_proxy_libc_files"], 153 header_libs: [ 154 "libberberis_guest_abi_headers", 155 "libberberis_guest_os_primitives_headers", 156 "libberberis_guest_state_headers", 157 "libberberis_proxy_loader_headers", 158 "libberberis_runtime_primitives_headers", 159 ], 160 161 // We need to access Bionic private headers in the libc proxy. 162 include_dirs: ["bionic/libc"], 163} 164