1# Copyright (c) 2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License 13 14import("//build/config/clang/clang.gni") 15import("//build/config/ohos/musl.gni") 16import("//build/ohos.gni") 17 18config("soft_musl_config") { 19 configs = [ 20 "//build/config/compiler:compiler_cpu_abi", 21 "//build/config/coverage:default_coverage", 22 ] 23 24 musl_out_dir = get_label_info(musl_target, "target_out_dir") 25 26 include_dirs = [ 27 "${musl_out_dir}/${musl_ported_dir}/arch/${musl_arch}", 28 "${musl_out_dir}/${musl_ported_dir}/arch/generic", 29 "${musl_out_dir}/${musl_ported_dir}/src/internal", 30 "${musl_out_dir}/${musl_ported_dir}/src/include", 31 "${musl_out_dir}/${musl_ported_dir}/src/gwp_asan", 32 "${musl_out_dir}/${musl_ported_dir}/src/hook", 33 "${musl_out_dir}/${musl_ported_dir}/src/network", 34 "${musl_out_dir}/${musl_ported_dir}/include", 35 "${musl_out_dir}/${musl_inc_out_dir}", 36 ] 37 38 cflags_basic = [ 39 "--target=${musl_target_triple}", 40 "-Wall", 41 "-Wl,-z,relro,-z,now,-z,noexecstack", 42 ] 43 44 if (musl_arch == "arm") { 45 cflags_basic += [ "-mtp=cp15" ] 46 } else if (musl_arch == "aarch64") { 47 } 48 49 cflags_auto = [ 50 "-D_XOPEN_SOURCE=700", 51 "-g", 52 "-pipe", 53 "-fno-omit-frame-pointer", 54 "-ffunction-sections", 55 "-fdata-sections", 56 "-Werror=implicit-function-declaration", 57 "-Werror=implicit-int", 58 "-Werror=pointer-sign", 59 "-Werror=pointer-arith", 60 "-Qunused-arguments", 61 "-Wno-int-conversion", 62 ] 63 64 if (is_llvm_build) { 65 cflags_auto += [ 66 "-fno-unwind-tables", 67 "-fno-asynchronous-unwind-tables", 68 ] 69 } else { 70 cflags_auto += [ 71 "-funwind-tables", 72 "-fasynchronous-unwind-tables", 73 ] 74 } 75 76 if (is_asan && use_hwasan) { 77 cflags_auto += [ "-DENABLE_HWASAN" ] 78 } 79 80 if (!is_asan && musl_arch != "mips") { 81 cflags_auto += [ 82 "-DHOOK_ENABLE", 83 "-DOHOS_SOCKET_HOOK_ENABLE", 84 ] 85 } 86 87 if (!is_llvm_build && !is_asan && musl_arch != "mips") { 88 cflags_auto += [ "-DOHOS_FDTRACK_HOOK_ENABLE" ] 89 } 90 91 if (musl_arch == "mips" && musl_is_legacy) { 92 cflags_auto += [ "-mnan=legacy" ] 93 } 94 95 if (musl_use_pthread_cancel) { 96 cflags_auto += [ "-DFEATURE_PTHREAD_CANCEL" ] 97 } 98 99 cflags_auto += [ "-DRESERVE_SIGNAL_STACK" ] 100 cflags_auto += [ "-DDFX_SIGNAL_LIBC" ] 101 102 cflags_c99fse = [ 103 "-std=c99", 104 "-nostdinc", 105 "-Wa,--noexecstack", 106 ] 107 108 cflags_all = cflags_basic + cflags_c99fse + cflags_auto 109 110 cflags = cflags_all 111 112 defines = [ "BROKEN_VFP_ASM" ] 113 if (!is_llvm_build) { 114 defines += [ "FEATURE_ATEXIT_CB_PROTECT" ] 115 } 116 if (is_standard_system) { 117 defines += [ 118 "OHOS_DNS_PROXY_BY_NETSYS=1", 119 "OHOS_FWMARK_CLIENT_BY_NETSYS=1", 120 "OHOS_PERMISSION_INTERNET=1", 121 "OHOS_DISABLE_IPV6=0", 122 ] 123 } 124 125 if (!is_standard_system && defined(musl_enable_musl_log)) { 126 if (musl_enable_musl_log) { 127 defines += [ "ENABLE_MUSL_LOG" ] 128 } 129 } 130 131 dynamic_list = rebase_path("${musl_out_dir}/${musl_ported_dir}/dynamic.list") 132 133 ldflags = cflags_all 134 ldflags += [ 135 "--target=${musl_target_triple}", 136 "-fuse-ld=lld", 137 "-Wl,--sort-section,alignment", 138 "-Wl,--sort-common", 139 "-Wl,--gc-sections", 140 "-Wl,--hash-style=both", 141 "-Wl,--no-undefined", 142 "-Wl,--dynamic-list=${dynamic_list}", 143 "-Wl,--build-id=md5", 144 ] 145 if (musl_arch == "mips") { 146 ldflags -= [ "-Wl,--hash-style=both" ] 147 } 148 asmflags = cflags 149} 150