1# Copyright (c) 2023-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("//base/hiviewdfx/faultloggerd/faultloggerd.gni") 15 16dfx_unwinder_sources = [ 17 "arch_util.cpp", 18 "dfx_accessors.cpp", 19 "dfx_ark.cpp", 20 "dfx_config.cpp", 21 "dfx_elf.cpp", 22 "dfx_elf_parser.cpp", 23 "dfx_frame_formatter.cpp", 24 "dfx_hap.cpp", 25 "dfx_instr_statistic.cpp", 26 "dfx_instructions.cpp", 27 "dfx_map.cpp", 28 "dfx_maps.cpp", 29 "dfx_memory.cpp", 30 "dfx_mmap.cpp", 31 "dfx_ptrace.cpp", 32 "dfx_regs.cpp", 33 "dfx_regs_arm.cpp", 34 "dfx_regs_arm64.cpp", 35 "dfx_regs_riscv64.cpp", 36 "dfx_regs_x86_64.cpp", 37 "dfx_signal.cpp", 38 "dfx_symbols.cpp", 39 "getcontext_x86_64.S", 40 "thread_context.cpp", 41 "unwinder.cpp", 42 "unwinder_config.cpp", 43] 44 45dfx_exidx_sources = [ "arm_exidx.cpp" ] 46 47dfx_dwarf_sources = [ 48 "dwarf_cfa_instructions.cpp", 49 "dwarf_op.cpp", 50 "dwarf_section.cpp", 51] 52 53if (defined(ohos_lite)) { 54 config("ohos_lite_config") { 55 defines = [ 56 "is_ohos=${is_ohos}", 57 "is_ohos_lite", 58 ] 59 } 60 61 shared_library("libunwinder") { 62 visibility = [ "*:*" ] 63 64 public_configs = [ ":ohos_lite_config" ] 65 66 include_dirs = [ 67 "include", 68 "$c_utils_include_path", 69 "$faultloggerd_common_path/dfxlog", 70 "$faultloggerd_common_path/dfxutil", 71 "$faultloggerd_interfaces_path/common", 72 "$hilog_lite_include_path", 73 ] 74 75 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 76 sources = dfx_unwinder_sources 77 sources += dfx_exidx_sources 78 sources += dfx_dwarf_sources 79 sources += [ "$c_utils_src_path/directory_ex.cpp" ] 80 81 deps = [ 82 "$faultloggerd_common_path/dfxlog:dfx_hilog", 83 "$faultloggerd_common_path/dfxutil:dfx_util", 84 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 85 "$hilog_lite_deps_path", 86 ] 87 88 external_deps = [ "bounds_checking_function:libsec_shared" ] 89 } 90 91 static_library("libunwinder_static") { 92 visibility = [ "*:*" ] 93 94 public_configs = [ ":ohos_lite_config" ] 95 96 include_dirs = [ 97 "include", 98 "$c_utils_include_path", 99 "$faultloggerd_common_path/dfxlog", 100 "$faultloggerd_common_path/dfxutil", 101 "$faultloggerd_interfaces_path/common", 102 "$hilog_lite_include_path", 103 ] 104 105 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 106 sources = dfx_unwinder_sources 107 sources += dfx_exidx_sources 108 sources += dfx_dwarf_sources 109 sources += [ "$c_utils_src_path/directory_ex.cpp" ] 110 111 deps = [ 112 "$faultloggerd_common_path/dfxlog:dfx_hilog", 113 "$faultloggerd_common_path/dfxutil:dfx_util", 114 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 115 "$hilog_lite_deps_path", 116 ] 117 external_deps = [ "bounds_checking_function:libsec_shared" ] 118 } 119 120 static_library("unwinder_host") { 121 # empty 122 } 123} else { 124 config("dfx_unwinder_config") { 125 visibility = [ "*:*" ] 126 127 include_dirs = [ 128 "include", 129 "$faultloggerd_common_path/dfxlog", 130 "$faultloggerd_common_path/dfxutil", 131 "$faultloggerd_interfaces_path/common", 132 ] 133 134 defines = [ 135 "is_ohos=${is_ohos}", 136 "is_linux=${is_linux}", 137 "is_mingw=${is_mingw}", 138 "RUSTC_DEMANGLE", 139 ] 140 141 if (libunwinder_debug) { 142 defines += [ "DFX_LOG_UNWIND" ] 143 } 144 } 145 146 config("mixstack_config") { 147 if (target_cpu == "arm64") { 148 defines = [ "ENABLE_MIXSTACK" ] 149 defines += [ "ONLINE_MIXSTACK" ] 150 } 151 } 152 153 config("offline_mixstack_config") { 154 if (target_cpu == "arm64") { 155 defines = [ "ENABLE_MIXSTACK" ] 156 defines += [ "OFFLINE_MIXSTACK" ] 157 } 158 } 159 160 config("lzma_config") { 161 if (is_ohos && !is_mingw && !is_emulator) { 162 defines = [ "ENABLE_MINIDEBUGINFO" ] 163 } 164 } 165 166 ohos_shared_library("libunwinder") { 167 branch_protector_ret = "pac_ret" 168 public_configs = [ 169 ":dfx_unwinder_config", 170 ":lzma_config", 171 ":offline_mixstack_config", 172 "$faultloggerd_common_path/build:coverage_flags", 173 ] 174 defines = [ 175 "DFX_UNWIND_ERROR", 176 "DFX_ENABLE_TRACE", 177 ] 178 if (target_cpu == "arm64") { 179 defines += [ "ENABLE_PARAMETER" ] 180 } 181 182 if (target_cpu != "x86_64") { 183 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 184 } 185 sources = dfx_unwinder_sources 186 sources += dfx_exidx_sources 187 sources += dfx_dwarf_sources 188 189 deps = [ 190 "$faultloggerd_common_path/dfxlog:dfx_hilog", 191 "$faultloggerd_common_path/dfxutil:dfx_util", 192 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 193 ] 194 195 if (is_ohos && !is_mingw && !is_emulator) { 196 sources += [ "dfx_xz_utils.cpp" ] 197 } 198 version_script = "libunwinder.map" 199 public_external_deps = [ "lzma:lzma_shared" ] 200 external_deps = [ 201 "bounds_checking_function:libsec_shared", 202 "c_utils:utils", 203 "hilog:libhilog", 204 "init:libbegetutil", 205 ] 206 install_images = [ 207 "system", 208 "updater", 209 ] 210 innerapi_tags = [ 211 "chipsetsdk_indirect", 212 "platformsdk_indirect", 213 ] 214 part_name = "faultloggerd" 215 subsystem_name = "hiviewdfx" 216 } 217 218 ohos_static_library("libunwinder_static") { 219 public_configs = [ 220 ":dfx_unwinder_config", 221 ":lzma_config", 222 ":offline_mixstack_config", 223 ] 224 225 if (target_cpu != "x86_64") { 226 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 227 } 228 sources = dfx_unwinder_sources 229 sources += dfx_exidx_sources 230 sources += dfx_dwarf_sources 231 232 deps = [ 233 "$faultloggerd_common_path/dfxlog:dfx_hilog", 234 "$faultloggerd_common_path/dfxutil:dfx_util", 235 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 236 ] 237 238 if (is_ohos && !is_mingw && !is_emulator) { 239 sources += [ "dfx_xz_utils.cpp" ] 240 } 241 public_external_deps = [ "lzma:lzma_shared" ] 242 external_deps = [ 243 "bounds_checking_function:libsec_shared", 244 "c_utils:utils", 245 "hilog:libhilog", 246 ] 247 part_name = "faultloggerd" 248 subsystem_name = "hiviewdfx" 249 } 250 251 ohos_static_library("libunwinder_base") { 252 public_configs = [ 253 ":dfx_unwinder_config", 254 ":lzma_config", 255 ":offline_mixstack_config", 256 ] 257 defines = [ "DFX_LOG_HILOG_BASE" ] 258 259 if (target_cpu != "x86_64") { 260 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 261 } 262 sources = dfx_unwinder_sources 263 sources += dfx_exidx_sources 264 sources += dfx_dwarf_sources 265 266 deps = [ 267 "$faultloggerd_common_path/dfxlog:dfx_hilog_base_static", 268 "$faultloggerd_common_path/dfxutil:dfx_util_static", 269 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 270 ] 271 272 if (is_ohos && !is_mingw && !is_emulator) { 273 sources += [ "dfx_xz_utils.cpp" ] 274 } 275 public_external_deps = [ "lzma:lzma_static" ] 276 external_deps = [ 277 "bounds_checking_function:libsec_static", 278 "c_utils:utilsbase", 279 "hilog:libhilog_base", 280 ] 281 part_name = "faultloggerd" 282 subsystem_name = "hiviewdfx" 283 } 284 285 ohos_source_set("libunwinder_src") { 286 public_configs = [ 287 ":dfx_unwinder_config", 288 ":lzma_config", 289 ":mixstack_config", 290 ] 291 defines = [ 292 "DFX_LOG_UNWIND", 293 "DFX_UNWIND_ERROR", 294 "INSTR_STATISTIC_ENABLE", 295 ] 296 297 if (target_cpu != "x86_64") { 298 dfx_unwinder_sources -= [ "getcontext_x86_64.S" ] 299 } 300 sources = dfx_unwinder_sources 301 sources += dfx_exidx_sources 302 sources += dfx_dwarf_sources 303 304 deps = [ 305 "$faultloggerd_common_path/dfxlog:dfx_hilog", 306 "$faultloggerd_common_path/dfxutil:dfx_util", 307 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 308 ] 309 310 if (is_ohos && !is_mingw && !is_emulator) { 311 sources += [ "dfx_xz_utils.cpp" ] 312 } 313 public_external_deps = [ "lzma:lzma_shared" ] 314 external_deps = [ 315 "bounds_checking_function:libsec_shared", 316 "c_utils:utils", 317 "hilog:libhilog", 318 ] 319 part_name = "faultloggerd" 320 subsystem_name = "hiviewdfx" 321 } 322 323 config("unwinder_host_config") { 324 visibility = [ "*:*" ] 325 326 include_dirs = [ 327 "include", 328 "$faultloggerd_common_path/dfxlog", 329 "$faultloggerd_common_path/dfxutil", 330 "$faultloggerd_interfaces_path/common", 331 "$faultloggerd_interfaces_path/nonlinux", 332 ] 333 334 defines = [ 335 "is_ohos=${is_ohos}", 336 "is_linux=${is_linux}", 337 "is_mingw=${is_mingw}", 338 "is_emulator=${is_emulator}", 339 "DFX_NO_PRINT_LOG", 340 ] 341 } 342 343 ohos_static_library("unwinder_host") { 344 public_configs = [ ":unwinder_host_config" ] 345 sources = [ 346 "dfx_elf.cpp", 347 "dfx_elf_parser.cpp", 348 "dfx_hap.cpp", 349 "dfx_map.cpp", 350 "dfx_maps.cpp", 351 "dfx_memory.cpp", 352 "dfx_mmap.cpp", 353 "dfx_symbols.cpp", 354 "unwinder_config.cpp", 355 ] 356 if (is_ohos && !is_mingw && !is_emulator) { 357 sources += [ "dfx_xz_utils.cpp" ] 358 public_external_deps = [ "lzma:lzma_static" ] 359 } 360 deps = [ 361 "$faultloggerd_common_path/dfxutil:dfx_util_host", 362 "$faultloggerd_common_path/trace:dfx_trace_dlsym", 363 ] 364 external_deps = [ "bounds_checking_function:libsec_static" ] 365 if (is_ohos) { 366 external_deps += [ "c_utils:utils" ] 367 } 368 part_name = "faultloggerd" 369 subsystem_name = "hiviewdfx" 370 } 371} 372