1# Copyright (c) 2021 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("//build/ohos.gni") 15import("../../base/config.gni") 16 17config("hook_config") { 18 defines = [ "is_ohos=1" ] 19 defines += [ 20 "HAVE_LIBUNWIND=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/hook_client.cpp", 40 "src/hook_socket_client.cpp", 41 "src/runtime_stack_range.cpp", 42 "src/stack_writer.cpp", 43 ] 44 include_dirs = [ 45 "./include", 46 "../api/include", 47 "../api/src", 48 "../../base/include/", 49 "../native_daemon/include", 50 "${OHOS_PROFILER_DIR}/interfaces/kits", 51 "${OHOS_PROFILER_DIR}/device/services/ipc/include", 52 "${OHOS_PROFILER_DIR}/device/services/shared_memory/include", 53 "//third_party/bounds_checking_function/include", 54 "//third_party/googletest/googletest/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 "//third_party/bounds_checking_function:libsec_static", 64 "//third_party/zlib:libz", 65 ] 66 external_deps = [ "init:libbegetutil" ] 67 68 public_deps = [ "//third_party/libunwind:unwind_source_${target_cpu}" ] 69 70 if (current_toolchain != host_toolchain) { 71 defines = [ "HAVE_HILOG" ] 72 external_deps += [ "hilog:libhilog" ] 73 } 74 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 75 part_name = "${OHOS_PROFILER_PART_NAME}" 76 defines += [ "NO_PROTOBUF" ] 77 cflags = [ 78 "-Wno-error=inline-asm", 79 "-DPERF_TEST_DATA", 80 "-O3", 81 ] 82} 83 84ohos_shared_library("native_hook") { 85 output_name = "native_hook" 86 deps = [ ":native_hook_source" ] 87 version_script = "libnative_hook.map" 88 install_enable = true 89 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 90 part_name = "${OHOS_PROFILER_PART_NAME}" 91} 92 93ohos_executable("nativetest_c") { 94 output_name = "nativetest_c" 95 sources = [ "test/hook_test.c" ] 96 97 if (current_toolchain != host_toolchain) { 98 defines = [ "HAVE_HILOG" ] 99 if (use_musl && !is_asan) { 100 defines += [ "HOOK_ENABLE" ] 101 } 102 external_deps = [ "hilog:libhilog" ] 103 } 104 include_dirs = [ "//third_party/bounds_checking_function/include" ] 105 deps = [ "//third_party/bounds_checking_function:libsec_static" ] 106 cflags = [ 107 "-Wno-error=inline-asm", 108 "-O3", 109 ] 110 ldflags = [ "-rdynamic" ] 111 install_enable = false 112 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 113 part_name = "${OHOS_PROFILER_PART_NAME}" 114} 115 116ohos_executable("nativetest_cpp") { 117 output_name = "nativetest_cpp" 118 sources = [ "test/hook_test.cpp" ] 119 120 if (current_toolchain != host_toolchain) { 121 defines = [ "HAVE_HILOG" ] 122 external_deps = [ "hilog:libhilog" ] 123 } 124 125 cflags = [ 126 "-Wno-error=inline-asm", 127 "-O3", 128 ] 129 ldflags = [ "-rdynamic" ] 130 131 install_enable = false 132 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 133 part_name = "${OHOS_PROFILER_PART_NAME}" 134} 135 136ohos_shared_library("nativetest_so") { 137 output_name = "nativetest_so" 138 sources = [ "test/hook_so.cpp" ] 139 140 if (current_toolchain != host_toolchain) { 141 defines = [ "HAVE_HILOG" ] 142 external_deps = [ "hilog:libhilog" ] 143 } 144 145 cflags = [ 146 "-Wno-error=inline-asm", 147 "-O3", 148 ] 149 150 install_enable = false 151 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 152 part_name = "${OHOS_PROFILER_PART_NAME}" 153} 154 155ohos_executable("malloctest_cpp") { 156 output_name = "malloctest_cpp" 157 sources = [ "test/malloc_test.cpp" ] 158 159 if (current_toolchain != host_toolchain) { 160 defines = [ "HAVE_HILOG" ] 161 external_deps = [ "hilog:libhilog" ] 162 } 163 164 include_dirs = [ "//third_party/bounds_checking_function/include" ] 165 deps = [ "//third_party/bounds_checking_function:libsec_static" ] 166 167 cflags = [ 168 "-Wno-error=inline-asm", 169 "-O3", 170 ] 171 ldflags = [ "-rdynamic" ] 172 install_enable = false 173 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 174 part_name = "${OHOS_PROFILER_PART_NAME}" 175} 176 177ohos_executable("perf_test_data") { 178 output_name = "perf_test_data" 179 sources = [ "test/perf_test_data.cpp" ] 180 181 if (current_toolchain != host_toolchain) { 182 defines = [ "HAVE_HILOG" ] 183 external_deps = [ "hilog:libhilog" ] 184 } 185 186 cflags = [ "-Wno-error=inline-asm" ] 187 install_enable = false 188 ldflags = [ "-rdynamic" ] 189 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 190 part_name = "${OHOS_PROFILER_PART_NAME}" 191} 192 193ohos_executable("statisticstest_cpp") { 194 output_name = "statisticstest_cpp" 195 sources = [ "test/statistics_test.cpp" ] 196 197 if (current_toolchain != host_toolchain) { 198 defines = [ "HAVE_HILOG" ] 199 external_deps = [ "hilog:libhilog" ] 200 } 201 202 cflags = [ 203 "-Wno-error=inline-asm", 204 "-O3", 205 ] 206 207 deps = [ "//third_party/bounds_checking_function:libsec_static" ] 208 include_dirs = [ "//third_party/bounds_checking_function/include" ] 209 ldflags = [ "-rdynamic" ] 210 install_enable = false 211 subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}" 212 part_name = "${OHOS_PROFILER_PART_NAME}" 213} 214