# 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. 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 if (target_cpu == "arm") { 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", ] } if (target_cpu == "arm64") { 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", ] } if (target_cpu == "x64") { 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-unused-result", "-Wno-tautological-constant-out-of-range-compare", ] if (use_wasm) { cflags += [ "-Wno-incompatible-pointer-types" ] } if (is_mingw) { cflags += [ "-Wno-attributes", "-Wno-pointer-to-int-cast", "-Wno-implicit-function-declaration", # "-Wno-absolute-value", # "-Wno-header-guard", # "-Wno-tautological-constant-out-of-range-compare", # "-Wno-sometimes-uninitialized", # "-Wno-int-to-void-pointer-cast", ] } if (use_wasm) { cflags += [ # "-D __mips__" # "-D WASM", ] } 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") { 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" ] } if (target_cpu == "arm") { ohos_source_set("unwind_source_arm") { subsystem_name = "developtools" part_name = "smartperf_host" 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 } } if (target_cpu == "arm64") { ohos_source_set("unwind_source_arm64") { subsystem_name = "developtools" part_name = "smartperf_host" 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 } } if (target_cpu == "x86") { ohos_source_set("unwind_source_x64") { subsystem_name = "developtools" part_name = "smartperf_host" 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") { subsystem_name = "developtools" part_name = "smartperf_host" 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") { # deps = [ "unwind_source_x64" ] sources += x64_source public_configs = [ ":unwind_config_x64" ] # public_configs = [ # ":unwind_config_public", # ":unwind_config_remote_public", # ":unwind_config_x64", # ] } sources += [ "src/os-ohos.c" ] } if (defined(ohos_lite)) { # shared_library("libunwind") { source_set("libunwind") { deps = [ ":unwind_source" ] public_configs = [ ":unwind_config_public" ] } } else { source_set("libunwind") { deps = [ ":unwind_source" ] # install_images = [ # "system", # "updater", # ] public_configs = [ ":unwind_config_public" ] # part_name = "smartperf_host" # subsystem_name = "developtools" } }