1# Copyright (c) 2023 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("${device_path}/config.gni") 15 16config("clang_cpu_arch") { 17 arch_cflags = board_cflags 18 if (board_arch != "") { 19 arch_cflags += [ "-march=$board_arch" ] 20 } 21 if (board_cpu != "") { 22 arch_cflags += [ "-mcpu=$board_cpu" ] 23 } 24 cflags = arch_cflags 25 cflags_cc = cflags 26 ldflags = cflags 27 asmflags = cflags 28} 29 30config("clang_common") { 31 defines = [ "_XOPEN_SOURCE=700" ] 32 cflags = [ 33 "-fno-common", 34 "-fno-builtin", 35 "-fno-strict-aliasing", 36 "-Wall", 37 ] 38 if (ohos_kernel_type == "linux") { 39 cflags += [ 40 "-funwind-tables", 41 "-fasynchronous-unwind-tables", 42 ] 43 } 44 cflags_cc = cflags 45 cflags += [ "-fsigned-char" ] 46} 47 48config("clang_security") { 49 defines = [ "_FORTIFY_SOURCE=2" ] 50 cflags = [ "-fstack-protector-all" ] 51 cflags_cc = cflags 52 ldflags = [ 53 "-Wl,-z,now", 54 "-Wl,-z,relro", 55 "-Wl,-z,noexecstack", 56 ] 57} 58 59config("clang_exceptions") { 60 cflags_cc = [ "-fexceptions" ] 61 cflags_objcc = cflags_cc 62} 63 64config("clang_stack_protector") { 65 cflags = [ "-fstack-protector-all" ] 66 cflags_cc = cflags 67} 68 69config("clang_static_pie_config") { 70 cflags = [ "-fPIE" ] 71 cflags_cc = cflags 72} 73 74config("clang_shared_library_config") { 75 cflags = [ "-fPIC" ] 76 cflags_cc = cflags 77} 78 79config("clang_pie_executable_config") { 80 ldflags = [ "-pie" ] 81} 82 83config("ohos_clang") { 84 if (ohos_kernel_type == "linux") { 85 defines = [ 86 "_LIBCPP_HAS_MUSL_LIBC", 87 "__BUILD_LINUX_WITH_CLANG", 88 ] 89 } 90 ldflags = [ 91 "-fuse-ld=lld", 92 "--rtlib=compiler-rt", 93 ] 94} 95 96config("clang_opt") { 97 cflags = [ "-Os" ] 98 cflags_cc = cflags 99} 100 101config("clang_default_link_path") { 102 ldflags = [ 103 "-L.", 104 "-Wl,-rpath-link=.", 105 ] 106} 107 108config("clang_kernel_configs") { 109 configs = [] 110 if (ohos_kernel_type == "liteos_a") { 111 configs += [ 112 ":clang_security", 113 ":clang_exceptions", 114 "//build/lite/config/kernel/liteos/cortex_a:default", 115 ] 116 } 117 if (ohos_kernel_type == "linux") { 118 configs += [ 119 ":clang_security", 120 ":clang_exceptions", 121 ] 122 } 123 if (ohos_kernel_type == "liteos_m") { 124 configs += [ ":clang_stack_protector" ] 125 } 126} 127 128config("clang_build_type_configs") { 129 configs = [] 130 if (ohos_build_type == "debug") { 131 configs += [ "//build/config/compiler/lite/common:debug" ] 132 } else if (ohos_build_type == "release") { 133 configs += [ "//build/config/compiler/lite/common:release" ] 134 } 135} 136 137config("clang_compiler_configs") { 138 configs = [] 139 if (current_os == "ohos") { 140 configs += [ 141 ":clang_cpu_arch", 142 ":clang_common", 143 ":clang_default_link_path", 144 ":clang_kernel_configs", 145 "//build/config/compiler/lite/common:board_config", 146 "//build/config/compiler/lite/common:kernel_macros", 147 ] 148 } 149 configs += [ ":clang_build_type_configs" ] 150} 151 152config("clang_shared_library_configs") { 153 configs = [ 154 ":clang_compiler_configs", 155 ":clang_shared_library_config", 156 ] 157} 158 159config("clang_static_library_configs") { 160 configs = [ ":clang_compiler_configs" ] 161 if (ohos_kernel_type != "liteos_m") { 162 configs += [ ":clang_static_pie_config" ] 163 } 164} 165 166config("clang_executable_configs") { 167 configs = [ ":clang_compiler_configs" ] 168 if (ohos_kernel_type != "liteos_m") { 169 configs += [ 170 ":clang_static_pie_config", 171 ":clang_pie_executable_config", 172 "//build/config/compiler/lite/common:board_exe_ld_flags", 173 ] 174 } 175} 176