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