1# Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved. 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/ohos.gni") 15import("../../base/config.gni") 16 17config("hook_config") { 18 defines = [ 19 "HAVE_LIBUNWIND=0", 20 "HAVE_LIBUNWINDER=1", 21 "HIPERF_DEBUG", 22 "CONFIG_NO_HILOG", 23 ] 24 defines += [ "target_cpu_${target_cpu}" ] 25 if (!is_asan) { 26 defines += [ "HOOK_ENABLE" ] 27 } 28} 29 30ohos_source_set("native_hook_source") { 31 use_exceptions = true 32 sources = [ 33 "../../services/ipc/src/socket_context.cpp", 34 "../../services/ipc/src/unix_socket_client.cpp", 35 "../native_daemon/src/debug_logger.cpp", 36 "../native_daemon/src/get_thread_id.cpp", 37 "../native_daemon/src/register.cpp", 38 "../native_daemon/src/utilities.cpp", 39 "src/address_handler.cpp", 40 "src/hook_client.cpp", 41 "src/hook_socket_client.cpp", 42 "src/runtime_stack_range.cpp", 43 "src/sampling.cpp", 44 "src/stack_writer.cpp", 45 ] 46 include_dirs = [ 47 "./include", 48 "../api/include", 49 "../api/src", 50 "../../base/include/", 51 "../native_daemon/include", 52 "${OHOS_PROFILER_DIR}/interfaces/kits", 53 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 54 "${OHOS_PROFILER_DIR}/device/services/shared_memory/include", 55 ] 56 public_configs = [ 57 ":hook_config", 58 "${OHOS_PROFILER_DIR}/device/base:hiprofiler_test_config", 59 ] 60 deps = [ 61 "${OHOS_PROFILER_DIR}/device/services/shared_memory:shared_memory_lite", 62 "../../base:hiprofiler_base", 63 ] 64 if (hiprofiler_use_libunwind) { 65 public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ] 66 } 67 external_deps = [ 68 "bounds_checking_function:libsec_shared", 69 "cJSON:cjson", 70 "c_utils:utils", 71 "ffrt:libffrt", 72 "hitrace:libhitracechain", 73 "init:libbegetutil", 74 "zlib:libz", 75 ] 76 if (hiprofiler_use_libunwinder) { 77 external_deps += [ "faultloggerd:libunwinder" ] 78 } 79 80 if (current_toolchain != host_toolchain) { 81 defines = [ "HAVE_HILOG" ] 82 external_deps += [ "hilog:libhilog_base" ] 83 } 84 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 85 part_name = "${OHOS_PROFILER_PART_NAME}" 86 defines += [ "NO_PROTOBUF" ] 87 cflags = [ 88 "-Wno-error=inline-asm", 89 "-DPERF_TEST_DATA", 90 "-O3", 91 ] 92} 93 94ohos_shared_library("native_hook") { 95 output_name = "native_hook" 96 deps = [ ":native_hook_source" ] 97 if (current_toolchain != host_toolchain) { 98 defines = [ "HAVE_HILOG" ] 99 external_deps = [ "hilog:libhilog_base" ] 100 } 101 version_script = "libnative_hook.map" 102 install_enable = true 103 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 104 part_name = "${OHOS_PROFILER_PART_NAME}" 105} 106 107ohos_executable("nativetest_c") { 108 output_name = "nativetest_c" 109 sources = [ "test/hook_test.c" ] 110 111 if (current_toolchain != host_toolchain) { 112 defines = [ "HAVE_HILOG" ] 113 if (use_musl && !is_asan) { 114 defines += [ "HOOK_ENABLE" ] 115 } 116 external_deps = [ "hilog:libhilog_base" ] 117 } 118 cflags = [ 119 "-Wno-error=inline-asm", 120 "-O3", 121 ] 122 external_deps += [ "bounds_checking_function:libsec_shared" ] 123 ldflags = [ "-rdynamic" ] 124 install_enable = false 125 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 126 part_name = "${OHOS_PROFILER_PART_NAME}" 127} 128 129ohos_executable("nativetest_cpp") { 130 output_name = "nativetest_cpp" 131 sources = [ "test/hook_test.cpp" ] 132 133 if (current_toolchain != host_toolchain) { 134 defines = [ "HAVE_HILOG" ] 135 external_deps = [ "hilog:libhilog_base" ] 136 } 137 138 cflags = [ 139 "-Wno-error=inline-asm", 140 "-O3", 141 ] 142 ldflags = [ "-rdynamic" ] 143 144 install_enable = false 145 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 146 part_name = "${OHOS_PROFILER_PART_NAME}" 147} 148 149ohos_shared_library("nativetest_so") { 150 output_name = "nativetest_so" 151 sources = [ "test/hook_so.cpp" ] 152 153 if (current_toolchain != host_toolchain) { 154 defines = [ "HAVE_HILOG" ] 155 external_deps = [ "hilog:libhilog_base" ] 156 } 157 158 cflags = [ 159 "-Wno-error=inline-asm", 160 "-O3", 161 ] 162 163 install_enable = false 164 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 165 part_name = "${OHOS_PROFILER_PART_NAME}" 166} 167 168ohos_executable("malloctest_cpp") { 169 output_name = "malloctest_cpp" 170 sources = [ "test/malloc_test.cpp" ] 171 172 if (current_toolchain != host_toolchain) { 173 defines = [ "HAVE_HILOG" ] 174 external_deps = [ "hilog:libhilog_base" ] 175 } 176 177 cflags = [ 178 "-Wno-error=inline-asm", 179 "-O3", 180 ] 181 external_deps += [ 182 "bounds_checking_function:libsec_shared", 183 "hisysevent:libhisysevent", 184 ] 185 ldflags = [ "-rdynamic" ] 186 install_enable = false 187 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 188 part_name = "${OHOS_PROFILER_PART_NAME}" 189} 190 191ohos_executable("perf_test_data") { 192 output_name = "perf_test_data" 193 sources = [ "test/perf_test_data.cpp" ] 194 195 if (current_toolchain != host_toolchain) { 196 defines = [ "HAVE_HILOG" ] 197 external_deps = [ "hilog:libhilog_base" ] 198 } 199 200 cflags = [ "-Wno-error=inline-asm" ] 201 install_enable = false 202 ldflags = [ "-rdynamic" ] 203 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 204 part_name = "${OHOS_PROFILER_PART_NAME}" 205} 206 207ohos_executable("statisticstest_cpp") { 208 output_name = "statisticstest_cpp" 209 sources = [ "test/statistics_test.cpp" ] 210 211 if (current_toolchain != host_toolchain) { 212 defines = [ "HAVE_HILOG" ] 213 external_deps = [ "hilog:libhilog_base" ] 214 } 215 216 cflags = [ 217 "-Wno-error=inline-asm", 218 "-O3", 219 ] 220 ldflags = [ "-rdynamic" ] 221 external_deps += [ "bounds_checking_function:libsec_shared" ] 222 install_enable = false 223 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 224 part_name = "${OHOS_PROFILER_PART_NAME}" 225} 226