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("//base/hiviewdfx/faultloggerd/faultloggerd.gni")
15
16if (defined(ohos_lite)) {
17  shared_library("dfx_signalhandler") {
18    visibility = [ "*:*" ]
19    include_dirs = [
20      "include",
21      "$c_utils_include_path",
22      "$faultloggerd_interfaces_path/common",
23      "$faultloggerd_path/common/cutil",
24      "$faultloggerd_path/common/dfxlog",
25    ]
26    sources = [
27      "dfx_signal_handler.c",
28      "dfx_signalhandler_exception.c",
29      "musl_log.c",
30    ]
31
32    deps = [ "$faultloggerd_path/common/cutil:dfx_cutil" ]
33
34    external_deps = [ "bounds_checking_function:libsec_shared" ]
35
36    cflags = [
37      "-fPIC",
38      "-fno-builtin",
39      "-DDFX_NO_PRINT_LOG",
40    ]
41  }
42} else {
43  inherited_configs = [
44    "//build/config/compiler:afdo",
45    "//build/config/compiler:afdo_optimize_size",
46    "//build/config/compiler:compiler",
47    "//build/config/compiler:compiler_arm_fpu",
48    "//build/config/compiler:compiler_arm_thumb",
49    "//build/config/compiler:chromium_code",
50    "//build/config/compiler:default_include_dirs",
51    "//build/config/compiler:default_optimization",
52    "//build/config/compiler:default_stack_frames",
53    "//build/config/compiler:default_symbols",
54    "//build/config/compiler:export_dynamic",
55    "//build/config/compiler:no_exceptions",
56    "//build/config/compiler:no_rtti",
57    "//build/config/compiler:runtime_library",
58    "//build/config/compiler:thin_archive",
59    "//build/config/sanitizers:default_sanitizer_flags",
60  ]
61
62  config("dfx_signal_handler_config") {
63    visibility = [ "*:*" ]
64    include_dirs = [
65      "include",
66      "$faultloggerd_interfaces_path/common",
67    ]
68  }
69
70  config("static_sighandler_config") {
71    include_dirs = [
72      "include",
73      "$faultloggerd_common_path/cutil",
74      "$faultloggerd_common_path/dfxlog",
75      "$faultloggerd_interfaces_path/common",
76    ]
77
78    defines = []
79    configs = []
80    if (is_posix) {
81      configs += [ "//build/config/posix:runtime_library" ]
82    }
83
84    cflags_cc = []
85    libs = []
86
87    defines = [
88      "__GNU_SOURCE=1",  # Necessary for clone().
89      "CHROMIUM_CXX_TWEAK_INLINES",  # Saves binary size.
90    ]
91
92    defines += [
93      "__MUSL__",
94      "_LIBCPP_HAS_MUSL_LIBC",
95      "__BUILD_LINUX_WITH_CLANG",
96      "ENABLE_SIGHAND_MUSL_LOG",
97      "ENABLE_MUSL_CUTIL",
98    ]
99
100    ldflags = [ "-nostdlib" ]
101  }
102
103  ohos_shared_library("dfx_signalhandler") {
104    branch_protector_ret = "pac_ret"
105    public_configs = [
106      ":dfx_signal_handler_config",
107      "$faultloggerd_common_path/build:coverage_flags",
108    ]
109    include_dirs = [
110      "$faultloggerd_common_path/cutil",
111      "$faultloggerd_common_path/dfxlog",
112    ]
113    defines = [ "DFX_LOG_HILOG_BASE" ]
114    version_script = "libdfx_signalhandler.map"
115    sources = [
116      "dfx_signal_handler.c",
117      "dfx_signalhandler_exception.c",
118      "musl_log.c",
119    ]
120
121    deps = [
122      "$faultloggerd_common_path/cutil:dfx_cutil",
123      "$faultloggerd_common_path/dfxlog:dfx_hilog_base",
124    ]
125
126    external_deps = [
127      "c_utils:utils",
128      "hilog:libhilog_base",
129    ]
130
131    innerapi_tags = [
132      "chipsetsdk_indirect",
133      "platformsdk_indirect",
134    ]
135    if (use_musl) {
136      install_enable = false
137    } else {
138      install_enable = true
139    }
140
141    install_images = [
142      "system",
143      "updater",
144    ]
145
146    part_name = "faultloggerd"
147    subsystem_name = "hiviewdfx"
148  }
149
150  static_library("dfxsignalhandler") {
151    cflags = [ "-DDFX_SIGNAL_LIBC" ]
152
153    sources = [
154      "dfx_signal_handler.c",
155      "dfx_signalhandler_exception.c",
156      "musl_log.c",
157    ]
158
159    configs -= inherited_configs
160    configs += [
161      "//build/config/compiler:compiler",
162      ":static_sighandler_config",
163    ]
164  }
165}
166