• 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("//build/ohos.gni")
15common_source = [
16  "src/dwarf/Gexpr.c",
17  "src/dwarf/Gfde.c",
18  "src/dwarf/Gfind_proc_info-lsb.c",
19  "src/dwarf/Gfind_unwind_table.c",
20  "src/dwarf/global.c",
21  "src/dwarf/Gparser.c",
22  "src/dwarf/Gpe.c",
23  "src/dwarf/Lexpr.c",
24  "src/dwarf/Lfde.c",
25  "src/dwarf/Lfind_proc_info-lsb.c",
26  "src/dwarf/Lfind_unwind_table.c",
27  "src/dwarf/Lparser.c",
28  "src/dwarf/Lpe.c",
29  "src/mi/backtrace.c",
30  "src/mi/dyn-cancel.c",
31  "src/mi/dyn-info-list.c",
32  "src/mi/dyn-register.c",
33  "src/mi/flush_cache.c",
34  "src/mi/Gdestroy_addr_space.c",
35  "src/mi/Gdyn-extract.c",
36  "src/mi/Gdyn-remote.c",
37  "src/mi/Gfind_dynamic_proc_info.c",
38  "src/mi/Gget_accessors.c",
39  "src/mi/Gget_fpreg.c",
40  "src/mi/Gget_proc_info_by_ip.c",
41  "src/mi/Gget_proc_name.c",
42  "src/mi/Gget_reg.c",
43  "src/mi/Gput_dynamic_unwind_info.c",
44  "src/mi/Gset_cache_size.c",
45  "src/mi/Gset_caching_policy.c",
46  "src/mi/Gset_fpreg.c",
47  "src/mi/Gset_reg.c",
48  "src/mi/init.c",
49  "src/mi/Ldestroy_addr_space.c",
50  "src/mi/Ldyn-extract.c",
51  "src/mi/Lfind_dynamic_proc_info.c",
52  "src/mi/Lget_fpreg.c",
53  "src/mi/Lget_proc_info_by_ip.c",
54  "src/mi/Lget_proc_name.c",
55  "src/mi/Lget_reg.c",
56  "src/mi/Lput_dynamic_unwind_info.c",
57  "src/mi/Lset_cache_size.c",
58  "src/mi/Lset_caching_policy.c",
59  "src/mi/Lset_fpreg.c",
60  "src/mi/Lset_reg.c",
61  "src/mi/mempool.c",
62  "src/mi/strerror.c",
63  "src/os-linux.c",
64  "src/ohos-config.c",
65  "src/ptrace/_UPT_access_fpreg.c",
66  "src/ptrace/_UPT_access_mem.c",
67  "src/ptrace/_UPT_access_reg.c",
68  "src/ptrace/_UPT_accessors.c",
69  "src/ptrace/_UPT_create.c",
70  "src/ptrace/_UPT_destroy.c",
71  "src/ptrace/_UPT_find_proc_info.c",
72  "src/ptrace/_UPT_get_dyn_info_list_addr.c",
73  "src/ptrace/_UPT_get_proc_name.c",
74  "src/ptrace/_UPT_put_unwind_info.c",
75  "src/ptrace/_UPT_reg_offset.c",
76  "src/ptrace/_UPT_resume.c",
77  "src/mi/maps.c",
78]
79
80# as libc++ is static linked with libunwind.a
81# we remove the Gstep.c for duplicated symbol violation
82if (target_cpu == "arm") {
83  arm_source = [
84    "src/arm/Gapply_reg_state.c",
85    "src/arm/Gcreate_addr_space.c",
86    "src/arm/Gex_tables.c",
87    "src/arm/Gget_proc_info.c",
88    "src/arm/Gget_save_loc.c",
89    "src/arm/Gglobal.c",
90    "src/arm/Ginit.c",
91    "src/arm/Ginit_local.c",
92    "src/arm/Ginit_remote.c",
93    "src/arm/Gos-linux.c",
94    "src/arm/Greg_states_iterate.c",
95    "src/arm/Gregs.c",
96    "src/arm/Gresume.c",
97    "src/arm/Gstash_frame.c",
98    "src/arm/Gstep.c",
99    "src/arm/Gtrace.c",
100    "src/arm/Lcreate_addr_space.c",
101    "src/arm/Lex_tables.c",
102    "src/arm/Lget_proc_info.c",
103    "src/arm/Lget_save_loc.c",
104    "src/arm/Lglobal.c",
105    "src/arm/Linit.c",
106    "src/arm/Linit_local.c",
107    "src/arm/Linit_remote.c",
108    "src/arm/Los-linux.c",
109    "src/arm/Lregs.c",
110    "src/arm/Lresume.c",
111    "src/arm/Lstash_frame.c",
112    "src/arm/Lstep.c",
113    "src/arm/Ltrace.c",
114    "src/arm/gen-offsets.c",
115    "src/arm/getcontext.S",
116    "src/arm/is_fpreg.c",
117    "src/arm/regname.c",
118    "src/arm/siglongjmp.S",
119    "src/elf32.c",
120  ]
121}
122if (target_cpu == "arm64") {
123  arm64_source = [
124    "src/aarch64/Gcreate_addr_space.c",
125    "src/aarch64/Gget_proc_info.c",
126    "src/aarch64/Gget_save_loc.c",
127    "src/aarch64/Gglobal.c",
128    "src/aarch64/Ginit.c",
129    "src/aarch64/Ginit_local.c",
130    "src/aarch64/Ginit_remote.c",
131    "src/aarch64/Gis_signal_frame.c",
132    "src/aarch64/Gregs.c",
133    "src/aarch64/Gresume.c",
134    "src/aarch64/Gstash_frame.c",
135    "src/aarch64/Gstep.c",
136    "src/aarch64/Gtrace.c",
137    "src/aarch64/Lcreate_addr_space.c",
138    "src/aarch64/Lget_proc_info.c",
139    "src/aarch64/Lget_save_loc.c",
140    "src/aarch64/Lglobal.c",
141    "src/aarch64/Linit.c",
142    "src/aarch64/Linit_local.c",
143    "src/aarch64/Linit_remote.c",
144    "src/aarch64/Lis_signal_frame.c",
145    "src/aarch64/Lregs.c",
146    "src/aarch64/Lresume.c",
147    "src/aarch64/Lstash_frame.c",
148    "src/aarch64/Lstep.c",
149    "src/aarch64/Ltrace.c",
150    "src/aarch64/getcontext.S",
151    "src/aarch64/is_fpreg.c",
152    "src/aarch64/regname.c",
153    "src/elf64.c",
154  ]
155}
156
157if (target_cpu == "x64") {
158  x64_source = [
159    "src/elf64.c",
160    "src/x86_64/Gcreate_addr_space.c",
161    "src/x86_64/Gget_proc_info.c",
162    "src/x86_64/Gget_save_loc.c",
163    "src/x86_64/Gglobal.c",
164    "src/x86_64/Ginit.c",
165    "src/x86_64/Ginit_local.c",
166    "src/x86_64/Ginit_remote.c",
167    "src/x86_64/Gos-linux.c",
168    "src/x86_64/Gregs.c",
169    "src/x86_64/Gresume.c",
170    "src/x86_64/Gstash_frame.c",
171    "src/x86_64/Gstep.c",
172    "src/x86_64/Gtrace.c",
173    "src/x86_64/Lcreate_addr_space.c",
174    "src/x86_64/Lget_proc_info.c",
175    "src/x86_64/Lget_save_loc.c",
176    "src/x86_64/Lglobal.c",
177    "src/x86_64/Linit.c",
178    "src/x86_64/Linit_local.c",
179    "src/x86_64/Linit_remote.c",
180    "src/x86_64/Los-linux.c",
181    "src/x86_64/Lregs.c",
182    "src/x86_64/Lresume.c",
183    "src/x86_64/Lstash_frame.c",
184    "src/x86_64/Lstep.c",
185    "src/x86_64/Ltrace.c",
186    "src/x86_64/getcontext.S",
187    "src/x86_64/is_fpreg.c",
188    "src/x86_64/regname.c",
189    "src/x86_64/setcontext.S",
190  ]
191}
192remove_sources = []
193
194ptrace_sources = [
195  "src/ptrace/_UPT_access_fpreg.c",
196  "src/ptrace/_UPT_access_mem.c",
197  "src/ptrace/_UPT_access_reg.c",
198  "src/ptrace/_UPT_accessors.c",
199  "src/ptrace/_UPT_create.c",
200  "src/ptrace/_UPT_destroy.c",
201  "src/ptrace/_UPT_find_proc_info.c",
202  "src/ptrace/_UPT_get_dyn_info_list_addr.c",
203  "src/ptrace/_UPT_get_proc_name.c",
204  "src/ptrace/_UPT_put_unwind_info.c",
205  "src/ptrace/_UPT_reg_offset.c",
206  "src/ptrace/_UPT_resume.c",
207]
208
209libunwind_la_SOURCES_local_nounwind = [
210  "src/mi/backtrace.c",
211  "src/mi/dyn-cancel.c",
212  "src/mi/dyn-info-list.c",
213  "src/mi/dyn-register.c",
214  "src/mi/Ldyn-extract.c",
215  "src/mi/Lfind_dynamic_proc_info.c",
216  "src/mi/Lget_proc_info_by_ip.c",
217  "src/mi/Lget_proc_name.c",
218  "src/mi/Lput_dynamic_unwind_info.c",
219  "src/mi/Ldestroy_addr_space.c",
220  "src/mi/Lget_reg.c",
221  "src/mi/Lset_reg.c",
222  "src/mi/Lget_fpreg.c",
223  "src/mi/Lset_fpreg.c",
224  "src/mi/Lset_caching_policy.c",
225  "src/mi/Lset_cache_size.c",
226]
227
228libunwind_dwarf_local_la_SOURCES = [
229  "src/dwarf/Lexpr.c",
230  "src/dwarf/Lfde.c",
231  "src/dwarf/Lparser.c",
232  "src/dwarf/Lpe.c",
233  "src/dwarf/Lfind_proc_info-lsb.c",
234  "src/dwarf/Lfind_unwind_table.c",
235]
236
237# remove local file
238remove_sources += libunwind_la_SOURCES_local_nounwind
239remove_sources += libunwind_dwarf_local_la_SOURCES
240remove_sources += ptrace_sources
241
242if (is_mingw) {
243  common_source += [ "src/mingw/pal-single-threaded.c" ]
244}
245
246config("unwind_config_public") {
247  include_dirs = [
248    "src",
249    "include",
250  ]
251
252  cflags = [
253    "-D_GNU_SOURCE",
254    "-DHAVE_CONFIG_H",
255    "-DCC_IS_CLANG",
256    "-fcommon",
257    "-Werror",
258    "-Wno-absolute-value",
259    "-Wno-header-guard",
260    "-Wno-unused-parameter",
261    "-Wno-unused-variable",
262    "-Wno-unused-result",
263    "-Wno-tautological-constant-out-of-range-compare",
264  ]
265  if (use_wasm) {
266    cflags += [ "-Wno-incompatible-pointer-types" ]
267  }
268  if (is_mingw) {
269    cflags += [
270      "-Wno-attributes",
271      "-Wno-pointer-to-int-cast",
272      "-Wno-implicit-function-declaration",
273    ]
274  }
275
276  if (defined(ohos_lite)) {
277    cflags += [ "-fPIC" ]
278  }
279
280  if (target_cpu == "arm") {
281    include_dirs += [ "include/tdep-arm" ]
282    cflags += [
283      "-Wno-inline-asm",
284      "-Wno-shift-count-overflow",
285      "-Wno-tautological-constant-out-of-range-compare",
286      "-Wno-unused-function",
287    ]
288  } else if (target_cpu == "arm64") {
289    include_dirs += [ "include/tdep-aarch64" ]
290    cflags += [ "-Wno-incompatible-pointer-types" ]
291  } else if (target_cpu == "x64") {
292    include_dirs += [ "include/tdep-x86_64" ]
293  }
294}
295config("unwind_config_remote") {
296  cflags =
297      [ "-Wno-format" ]  # some debug feature will warning in host x64 build
298}
299config("unwind_config_remote_public") {
300  cflags = []
301  include_dirs = []
302  defines = []
303
304  # this is a host tools build
305  # what means host use remote mode to unwind
306  # with dwarf from stack or coredump or something not real target
307  # There is an exception, we can support local unwind for linux.
308  cflags += [ "-DUNW_REMOTE_ONLY" ]
309
310  cflags += [ "-DBUILD_REMOTE" ]
311
312  cflags += [ "-Wno-sometimes-uninitialized" ]  # some value not initialized in
313                                                # host x64 build
314  cflags += [ "-Wno-int-to-void-pointer-cast" ]
315
316  if (is_mingw) {
317    include_dirs += [ "include/mingw" ]
318    cflags += [ "-DMINGW" ]
319  } else if (is_linux) {
320    cflags += [ "-g" ]  # we need debug info when it crash.
321  }
322
323  defines += [ "build_remote=1" ]
324  defines += [ "target_cpu=${target_cpu}" ]
325}
326
327config("unwind_config_arm") {
328  defines = [ "UNW_TARGET_ARM" ]
329}
330
331config("unwind_config_arm64") {
332  defines = [ "UNW_TARGET_ARM64" ]
333}
334
335config("unwind_config_x64") {
336  defines = [ "UNW_TARGET_X86_64" ]
337  defines += [ "UNW_TARGET_X86_64_LINUX" ]
338}
339if (target_cpu == "arm") {
340  ohos_source_set("unwind_source_arm") {
341    subsystem_name = "developtools"
342    part_name = "smartperf_host"
343    configs += [ ":unwind_config_remote" ]
344    public_configs = [
345      ":unwind_config_public",
346      ":unwind_config_remote_public",
347      ":unwind_config_arm",
348    ]
349    sources = common_source
350
351    # there is a main function in this file
352    # for a lib we dont need this
353    arm_source -= [ "src/arm/gen-offsets.c" ]
354
355    # no jump lib
356    arm_source -= [
357      "src/arm/getcontext.S",
358      "src/arm/siglongjmp.S",
359    ]
360    sources += arm_source
361    sources -= remove_sources
362  }
363}
364if (target_cpu == "arm64") {
365  ohos_source_set("unwind_source_arm64") {
366    subsystem_name = "developtools"
367    part_name = "smartperf_host"
368    configs += [ ":unwind_config_remote" ]
369    public_configs = [
370      ":unwind_config_public",
371      ":unwind_config_remote_public",
372      ":unwind_config_arm64",
373    ]
374    sources = common_source
375
376    arm64_source -= [ "src/aarch64/getcontext.S" ]
377
378    sources += arm64_source
379    sources -= remove_sources
380  }
381}
382if (target_cpu == "x86") {
383  ohos_source_set("unwind_source_x64") {
384    subsystem_name = "developtools"
385    part_name = "smartperf_host"
386    configs += [ ":unwind_config_remote" ]
387    public_configs = [
388      ":unwind_config_public",
389      ":unwind_config_remote_public",
390      ":unwind_config_x64",
391    ]
392    sources = common_source
393
394    # no jump lib
395    x64_source -= [
396      "src/x86_64/getcontext.S",
397      "src/x86_64/setcontext.S",
398    ]
399    sources += x64_source
400    sources -= remove_sources
401  }
402}
403ohos_source_set("unwind_source") {
404  subsystem_name = "developtools"
405  part_name = "smartperf_host"
406  configs += [ ":unwind_config_public" ]
407  sources = common_source
408  if (target_cpu == "arm") {
409    # as libc++ is static linked with libunwind.a
410    # we remove the Gstep.c for duplicated symbol violation
411    sources += arm_source
412    public_configs = [ ":unwind_config_arm" ]
413  } else if (target_cpu == "arm64") {
414    sources += arm64_source
415    public_configs = [ ":unwind_config_arm64" ]
416  } else if (target_cpu == "x64") {
417    sources += x64_source
418    public_configs = [ ":unwind_config_x64" ]
419  }
420
421  sources += [ "src/os-ohos.c" ]
422}
423
424if (defined(ohos_lite)) {
425  source_set("libunwind") {
426    deps = [ ":unwind_source" ]
427    public_configs = [ ":unwind_config_public" ]
428  }
429} else {
430  source_set("libunwind") {
431    deps = [ ":unwind_source" ]
432    public_configs = [ ":unwind_config_public" ]
433  }
434}
435