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