# Copyright (c) 2021 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. if (defined(ohos_lite)) { import("//build/lite/config/component/lite_component.gni") } else { import("//build/ohos.gni") } common_source = [ "src/dwarf/Gexpr.c", "src/dwarf/Gfde.c", "src/dwarf/Gfind_proc_info-lsb.c", "src/dwarf/Gfind_unwind_table.c", "src/dwarf/global.c", "src/dwarf/Gparser.c", "src/dwarf/Gpe.c", "src/dwarf/Lexpr.c", "src/dwarf/Lfde.c", "src/dwarf/Lfind_proc_info-lsb.c", "src/dwarf/Lfind_unwind_table.c", "src/dwarf/Lparser.c", "src/dwarf/Lpe.c", "src/mi/backtrace.c", "src/mi/dyn-cancel.c", "src/mi/dyn-info-list.c", "src/mi/dyn-register.c", "src/mi/flush_cache.c", "src/mi/Gdestroy_addr_space.c", "src/mi/Gdyn-extract.c", "src/mi/Gdyn-remote.c", "src/mi/Gfind_dynamic_proc_info.c", "src/mi/Gget_accessors.c", "src/mi/Gget_fpreg.c", "src/mi/Gget_proc_info_by_ip.c", "src/mi/Gget_proc_name.c", "src/mi/Gget_reg.c", "src/mi/Gput_dynamic_unwind_info.c", "src/mi/Gset_cache_size.c", "src/mi/Gset_caching_policy.c", "src/mi/Gset_fpreg.c", "src/mi/Gset_reg.c", "src/mi/init.c", "src/mi/Ldestroy_addr_space.c", "src/mi/Ldyn-extract.c", "src/mi/Lfind_dynamic_proc_info.c", "src/mi/Lget_fpreg.c", "src/mi/Lget_proc_info_by_ip.c", "src/mi/Lget_proc_name.c", "src/mi/Lget_reg.c", "src/mi/Lput_dynamic_unwind_info.c", "src/mi/Lset_cache_size.c", "src/mi/Lset_caching_policy.c", "src/mi/Lset_fpreg.c", "src/mi/Lset_reg.c", "src/mi/mempool.c", "src/mi/strerror.c", "src/os-linux.c", "src/ohos-config.c", "src/ptrace/_UPT_access_fpreg.c", "src/ptrace/_UPT_access_mem.c", "src/ptrace/_UPT_access_reg.c", "src/ptrace/_UPT_accessors.c", "src/ptrace/_UPT_create.c", "src/ptrace/_UPT_destroy.c", "src/ptrace/_UPT_find_proc_info.c", "src/ptrace/_UPT_get_dyn_info_list_addr.c", "src/ptrace/_UPT_get_proc_name.c", "src/ptrace/_UPT_put_unwind_info.c", "src/ptrace/_UPT_reg_offset.c", "src/ptrace/_UPT_resume.c", "src/mi/maps.c", ] # as libc++ is static linked with libunwind.a # we remove the Gstep.c for duplicated symbol violation arm_source = [ "src/arm/Gapply_reg_state.c", "src/arm/Gcreate_addr_space.c", "src/arm/Gex_tables.c", "src/arm/Gget_proc_info.c", "src/arm/Gget_save_loc.c", "src/arm/Gglobal.c", "src/arm/Ginit.c", "src/arm/Ginit_local.c", "src/arm/Ginit_remote.c", "src/arm/Gos-linux.c", "src/arm/Greg_states_iterate.c", "src/arm/Gregs.c", "src/arm/Gresume.c", "src/arm/Gstash_frame.c", "src/arm/Gstep.c", "src/arm/Gtrace.c", "src/arm/Lcreate_addr_space.c", "src/arm/Lex_tables.c", "src/arm/Lget_proc_info.c", "src/arm/Lget_save_loc.c", "src/arm/Lglobal.c", "src/arm/Linit.c", "src/arm/Linit_local.c", "src/arm/Linit_remote.c", "src/arm/Los-linux.c", "src/arm/Lregs.c", "src/arm/Lresume.c", "src/arm/Lstash_frame.c", "src/arm/Lstep.c", "src/arm/Ltrace.c", "src/arm/gen-offsets.c", "src/arm/getcontext.S", "src/arm/is_fpreg.c", "src/arm/regname.c", "src/arm/siglongjmp.S", "src/elf32.c", ] arm64_source = [ "src/aarch64/Gcreate_addr_space.c", "src/aarch64/Gget_proc_info.c", "src/aarch64/Gget_save_loc.c", "src/aarch64/Gglobal.c", "src/aarch64/Ginit.c", "src/aarch64/Ginit_local.c", "src/aarch64/Ginit_remote.c", "src/aarch64/Gis_signal_frame.c", "src/aarch64/Gregs.c", "src/aarch64/Gresume.c", "src/aarch64/Gstash_frame.c", "src/aarch64/Gstep.c", "src/aarch64/Gtrace.c", "src/aarch64/Lcreate_addr_space.c", "src/aarch64/Lget_proc_info.c", "src/aarch64/Lget_save_loc.c", "src/aarch64/Lglobal.c", "src/aarch64/Linit.c", "src/aarch64/Linit_local.c", "src/aarch64/Linit_remote.c", "src/aarch64/Lis_signal_frame.c", "src/aarch64/Lregs.c", "src/aarch64/Lresume.c", "src/aarch64/Lstash_frame.c", "src/aarch64/Lstep.c", "src/aarch64/Ltrace.c", "src/aarch64/getcontext.S", "src/aarch64/is_fpreg.c", "src/aarch64/regname.c", "src/elf64.c", ] x64_source = [ "src/elf64.c", "src/x86_64/Gcreate_addr_space.c", "src/x86_64/Gget_proc_info.c", "src/x86_64/Gget_save_loc.c", "src/x86_64/Gglobal.c", "src/x86_64/Ginit.c", "src/x86_64/Ginit_local.c", "src/x86_64/Ginit_remote.c", "src/x86_64/Gos-linux.c", "src/x86_64/Gregs.c", "src/x86_64/Gresume.c", "src/x86_64/Gstash_frame.c", "src/x86_64/Gstep.c", "src/x86_64/Gtrace.c", "src/x86_64/Lcreate_addr_space.c", "src/x86_64/Lget_proc_info.c", "src/x86_64/Lget_save_loc.c", "src/x86_64/Lglobal.c", "src/x86_64/Linit.c", "src/x86_64/Linit_local.c", "src/x86_64/Linit_remote.c", "src/x86_64/Los-linux.c", "src/x86_64/Lregs.c", "src/x86_64/Lresume.c", "src/x86_64/Lstash_frame.c", "src/x86_64/Lstep.c", "src/x86_64/Ltrace.c", "src/x86_64/getcontext.S", "src/x86_64/is_fpreg.c", "src/x86_64/regname.c", "src/x86_64/setcontext.S", ] remove_sources = [] ptrace_sources = [ "src/ptrace/_UPT_access_fpreg.c", "src/ptrace/_UPT_access_mem.c", "src/ptrace/_UPT_access_reg.c", "src/ptrace/_UPT_accessors.c", "src/ptrace/_UPT_create.c", "src/ptrace/_UPT_destroy.c", "src/ptrace/_UPT_find_proc_info.c", "src/ptrace/_UPT_get_dyn_info_list_addr.c", "src/ptrace/_UPT_get_proc_name.c", "src/ptrace/_UPT_put_unwind_info.c", "src/ptrace/_UPT_reg_offset.c", "src/ptrace/_UPT_resume.c", ] libunwind_la_SOURCES_local_nounwind = [ "src/mi/backtrace.c", "src/mi/dyn-cancel.c", "src/mi/dyn-info-list.c", "src/mi/dyn-register.c", "src/mi/Ldyn-extract.c", "src/mi/Lfind_dynamic_proc_info.c", # "src/mi/Lget_accessors.c", # miss "src/mi/Lget_proc_info_by_ip.c", "src/mi/Lget_proc_name.c", "src/mi/Lput_dynamic_unwind_info.c", "src/mi/Ldestroy_addr_space.c", "src/mi/Lget_reg.c", "src/mi/Lset_reg.c", "src/mi/Lget_fpreg.c", "src/mi/Lset_fpreg.c", "src/mi/Lset_caching_policy.c", "src/mi/Lset_cache_size.c", ] libunwind_dwarf_local_la_SOURCES = [ "src/dwarf/Lexpr.c", "src/dwarf/Lfde.c", "src/dwarf/Lparser.c", "src/dwarf/Lpe.c", "src/dwarf/Lfind_proc_info-lsb.c", "src/dwarf/Lfind_unwind_table.c", ] # remove local file remove_sources += libunwind_la_SOURCES_local_nounwind remove_sources += libunwind_dwarf_local_la_SOURCES remove_sources += ptrace_sources if (is_mingw) { common_source += [ "src/mingw/pal-single-threaded.c" ] } config("unwind_config_public") { include_dirs = [ "src", "include", ] cflags = [ "-D_GNU_SOURCE", "-DHAVE_CONFIG_H", "-DNDEBUG", "-DCC_IS_CLANG", "-fcommon", "-Werror", "-Wno-absolute-value", "-Wno-header-guard", "-Wno-unused-parameter", "-Wno-unused-variable", "-Wno-int-to-pointer-cast", "-Wno-pointer-to-int-cast", ] if (defined(ohos_lite)) { cflags += [ "-fPIC" ] } if (target_cpu == "arm") { include_dirs += [ "include/tdep-arm" ] cflags += [ "-Wno-inline-asm", "-Wno-shift-count-overflow", "-Wno-tautological-constant-out-of-range-compare", "-Wno-unused-function", ] } else if (target_cpu == "arm64") { include_dirs += [ "include/tdep-aarch64" ] cflags += [ "-Wno-incompatible-pointer-types" ] } else if (target_cpu == "x64" || target_cpu == "x86_64") { include_dirs += [ "include/tdep-x86_64" ] } } config("unwind_config_remote") { cflags = [ "-Wno-format" ] # some debug feature will warning in host x64 build } config("unwind_config_remote_public") { cflags = [] include_dirs = [] defines = [] # this is a host tools build # what means host use remote mode to unwind # with dwarf from stack or coredump or something not real target # There is an exception, we can support local unwind for linux. cflags += [ "-DUNW_REMOTE_ONLY" ] cflags += [ "-DBUILD_REMOTE" ] cflags += [ "-Wno-sometimes-uninitialized" ] # some value not initialized in # host x64 build cflags += [ "-Wno-int-to-void-pointer-cast" ] if (is_mingw) { include_dirs += [ "include/mingw" ] cflags += [ "-DMINGW" ] } else if (is_linux) { cflags += [ "-g" ] # we need debug info when it crash. } defines += [ "build_remote=1" ] defines += [ "target_cpu=${target_cpu}" ] defines += [ "host_toolchain=${host_toolchain}" ] defines += [ "current_toolchain=${current_toolchain}" ] defines += [ "default_toolchain=${default_toolchain}" ] } config("unwind_config_arm") { defines = [ "UNW_TARGET_ARM" ] } config("unwind_config_arm64") { defines = [ "UNW_TARGET_ARM64" ] } config("unwind_config_x64") { defines = [ "UNW_TARGET_X86_64" ] defines += [ "UNW_TARGET_X86_64_LINUX" ] } config("unwind_config_x86_64") { defines = [ "UNW_TARGET_X86_64" ] defines += [ "UNW_TARGET_X86_64_LINUX" ] } if (defined(ohos_lite)) { source_set("unwind_source_arm") { configs += [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_arm", ] sources = common_source # there is a main function in this file # for a lib we dont need this arm_source -= [ "src/arm/gen-offsets.c" ] # no jump lib arm_source -= [ "src/arm/getcontext.S", "src/arm/siglongjmp.S", ] sources += arm_source sources -= remove_sources } source_set("unwind_source_arm64") { configs += [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_arm64", ] sources = common_source arm64_source -= [ "src/aarch64/getcontext.S" ] sources += arm64_source sources -= remove_sources } source_set("unwind_source_x64") { configs += [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_x64", ] sources = common_source # no jump lib x64_source -= [ "src/x86_64/getcontext.S", "src/x86_64/setcontext.S", ] sources += x64_source sources -= remove_sources } source_set("unwind_source") { configs += [ ":unwind_config_public" ] sources = common_source if (target_cpu == "arm") { # there is a main function in this file # for a lib we dont need this arm_source -= [ "src/arm/gen-offsets.c" ] # no jump lib arm_source -= [ "src/arm/getcontext.S", "src/arm/siglongjmp.S", ] # as libc++ is static linked with libunwind.a # we remove the Gstep.c for duplicated symbol violation sources += arm_source public_configs = [ ":unwind_config_arm" ] } else if (target_cpu == "arm64") { sources += arm64_source public_configs = [ ":unwind_config_arm64" ] } else if (target_cpu == "x64") { sources += x64_source public_configs = [ ":unwind_config_x64" ] } else if (target_cpu == "x86_64") { sources += x64_source public_configs = [ ":unwind_config_x86_64" ] } sources += [ "src/os-ohos.c" ] } shared_library("libunwind") { deps = [ ":unwind_source" ] public_configs = [ ":unwind_config_public" ] } } else { ohos_source_set("unwind_source_arm") { configs = [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_arm", ] sources = common_source # there is a main function in this file # for a lib we dont need this arm_source -= [ "src/arm/gen-offsets.c" ] # no jump lib arm_source -= [ "src/arm/getcontext.S", "src/arm/siglongjmp.S", ] sources += arm_source sources -= remove_sources } ohos_source_set("unwind_source_arm64") { configs = [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_arm64", ] sources = common_source arm64_source -= [ "src/aarch64/getcontext.S" ] sources += arm64_source sources -= remove_sources } ohos_source_set("unwind_source_x64") { configs = [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_x64", ] sources = common_source # no jump lib x64_source -= [ "src/x86_64/getcontext.S", "src/x86_64/setcontext.S", ] sources += x64_source sources -= remove_sources } ohos_source_set("unwind_source_x86_64") { configs = [ ":unwind_config_remote" ] public_configs = [ ":unwind_config_public", ":unwind_config_remote_public", ":unwind_config_x86_64", ] sources = common_source # no jump lib x64_source -= [ "src/x86_64/getcontext.S", "src/x86_64/setcontext.S", ] sources += x64_source sources -= remove_sources } ohos_source_set("unwind_source") { configs = [ ":unwind_config_public" ] sources = common_source if (target_cpu == "arm") { # as libc++ is static linked with libunwind.a # we remove the Gstep.c for duplicated symbol violation sources += arm_source public_configs = [ ":unwind_config_arm" ] } else if (target_cpu == "arm64") { sources += arm64_source public_configs = [ ":unwind_config_arm64" ] } else if (target_cpu == "x64") { sources += x64_source public_configs = [ ":unwind_config_x64" ] } else if (target_cpu == "x86_64") { sources += x64_source public_configs = [ ":unwind_config_x86_64" ] } sources += [ "src/os-ohos.c" ] cflags = [ "-DHAS_ARK_FRAME", "-DPARSE_BUILD_ID", "-DIS_VALIDATE_MEM", ] } ohos_shared_library("libunwind") { deps = [ ":unwind_source" ] install_images = [ "system", "updater", ] public_configs = [ ":unwind_config_public" ] part_name = "faultloggerd" subsystem_name = "hiviewdfx" } } if (!defined(ohos_lite)) { import("//build/test.gni") module_output_path = "hiviewdfx/faultloggerd" group("unittest") { testonly = true deps = [ ":Gtest_bt", ":Gtest_dyn1", ":Gtest_init", ":Gtest_trace", ":Ltest_bt", ":Ltest_cxx_exceptions", ":Ltest_dyn1", ":Ltest_init", ":Ltest_init_local_signal", ":Ltest_mem_validate", ":Ltest_nocalloc", ":Ltest_nomalloc", ":Ltest_trace", ":test_ptrace_misc", ":test_static_link", ] } config("unwind_test") { cflags = [ "-O0" ] } ohos_unittest("Gtest_init") { module_out_path = module_output_path sources = [ "tests/Gtest-init.cxx" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_init") { module_out_path = module_output_path sources = [ "tests/Ltest-init.cxx" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_cxx_exceptions") { module_out_path = module_output_path sources = [ "tests/Ltest-cxx-exceptions.cxx" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] cflags = [ "-fexceptions" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" remove_configs = [ "//build/config/compiler:no_exceptions" ] } ohos_unittest("Ltest_init_local_signal") { module_out_path = module_output_path sources = [ "tests/Ltest-init-local-signal-lib.c", "tests/Ltest-init-local-signal.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Gtest_dyn1") { module_out_path = module_output_path sources = [ "tests/Gtest-dyn1.c", "tests/flush-cache.h", ] if (target_cpu == "arm") { sources += [ "tests/flush-cache.S" ] } include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] cflags = [ "-DHAVE__BUILTIN___CLEAR_CACHE" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_dyn1") { module_out_path = module_output_path sources = [ "tests/Ltest-dyn1.c", "tests/flush-cache.h", ] if (target_cpu == "arm") { sources += [ "tests/flush-cache.S" ] } include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] cflags = [ "-DHAVE__BUILTIN___CLEAR_CACHE" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("test_static_link") { module_out_path = module_output_path sources = [ "tests/test-static-link-gen.c", "tests/test-static-link-loc.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Gtest_bt") { module_out_path = module_output_path sources = [ "tests/Gtest-bt.c", "tests/dummy_backtrace.c", "tests/ident.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_bt") { module_out_path = module_output_path sources = [ "tests/Ltest-bt.c", "tests/dummy_backtrace.c", "tests/ident.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("test_ptrace_misc") { module_out_path = module_output_path sources = [ "tests/ident.c", "tests/test-ptrace-misc.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_nomalloc") { module_out_path = module_output_path sources = [ "tests/Ltest-nomalloc.c" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_nocalloc") { module_out_path = module_output_path sources = [ "tests/Ltest-nocalloc.c" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Gtest_trace") { module_out_path = module_output_path sources = [ "tests/Gtest-trace.c", "tests/dummy_backtrace.c", "tests/ident.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_trace") { module_out_path = module_output_path sources = [ "tests/Ltest-trace.c", "tests/dummy_backtrace.c", "tests/ident.c", ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } ohos_unittest("Ltest_mem_validate") { module_out_path = module_output_path sources = [ "tests/Ltest-mem-validate.c" ] include_dirs = [ "tests", "include", ] configs = [ ":unwind_test" ] deps = [ ":libunwind" ] subsystem_name = "hiviewdfx" part_name = "faultloggerd" } } else { group("unittest") { testonly = true deps = [] } }