• 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
217  # "src/mi/Lget_accessors.c", # miss
218  "src/mi/Lget_proc_info_by_ip.c",
219  "src/mi/Lget_proc_name.c",
220  "src/mi/Lput_dynamic_unwind_info.c",
221  "src/mi/Ldestroy_addr_space.c",
222  "src/mi/Lget_reg.c",
223  "src/mi/Lset_reg.c",
224  "src/mi/Lget_fpreg.c",
225  "src/mi/Lset_fpreg.c",
226  "src/mi/Lset_caching_policy.c",
227  "src/mi/Lset_cache_size.c",
228]
229
230libunwind_dwarf_local_la_SOURCES = [
231  "src/dwarf/Lexpr.c",
232  "src/dwarf/Lfde.c",
233  "src/dwarf/Lparser.c",
234  "src/dwarf/Lpe.c",
235  "src/dwarf/Lfind_proc_info-lsb.c",
236  "src/dwarf/Lfind_unwind_table.c",
237]
238
239# remove local file
240remove_sources += libunwind_la_SOURCES_local_nounwind
241remove_sources += libunwind_dwarf_local_la_SOURCES
242remove_sources += ptrace_sources
243
244if (is_mingw) {
245  common_source += [ "src/mingw/pal-single-threaded.c" ]
246}
247
248config("unwind_config_public") {
249  include_dirs = [
250    "src",
251    "include",
252  ]
253
254  cflags = [
255    "-D_GNU_SOURCE",
256    "-DHAVE_CONFIG_H",
257
258    # "-DNDEBUG",
259    "-DCC_IS_CLANG",
260    "-fcommon",
261    "-Werror",
262    "-Wno-absolute-value",
263    "-Wno-header-guard",
264    "-Wno-unused-parameter",
265    "-Wno-unused-variable",
266    "-Wno-unused-result",
267    "-Wno-tautological-constant-out-of-range-compare",
268  ]
269  if (use_wasm) {
270    cflags += [ "-Wno-incompatible-pointer-types" ]
271  }
272  if (is_mingw) {
273    cflags += [
274      "-Wno-attributes",
275      "-Wno-pointer-to-int-cast",
276      "-Wno-implicit-function-declaration",
277
278      # "-Wno-absolute-value",
279      # "-Wno-header-guard",
280      # "-Wno-tautological-constant-out-of-range-compare",
281      # "-Wno-sometimes-uninitialized",
282      # "-Wno-int-to-void-pointer-cast",
283    ]
284  }
285
286  if (use_wasm) {
287    cflags += [
288      # "-D __mips__"
289      # "-D WASM",
290    ]
291  }
292
293  if (defined(ohos_lite)) {
294    cflags += [ "-fPIC" ]
295  }
296
297  if (target_cpu == "arm") {
298    include_dirs += [ "include/tdep-arm" ]
299    cflags += [
300      "-Wno-inline-asm",
301      "-Wno-shift-count-overflow",
302      "-Wno-tautological-constant-out-of-range-compare",
303      "-Wno-unused-function",
304    ]
305  } else if (target_cpu == "arm64") {
306    include_dirs += [ "include/tdep-aarch64" ]
307    cflags += [ "-Wno-incompatible-pointer-types" ]
308  } else if (target_cpu == "x64") {
309    include_dirs += [ "include/tdep-x86_64" ]
310  }
311}
312config("unwind_config_remote") {
313  cflags =
314      [ "-Wno-format" ]  # some debug feature will warning in host x64 build
315}
316config("unwind_config_remote_public") {
317  cflags = []
318  include_dirs = []
319  defines = []
320
321  # this is a host tools build
322  # what means host use remote mode to unwind
323  # with dwarf from stack or coredump or something not real target
324  # There is an exception, we can support local unwind for linux.
325  cflags += [ "-DUNW_REMOTE_ONLY" ]
326
327  cflags += [ "-DBUILD_REMOTE" ]
328
329  cflags += [ "-Wno-sometimes-uninitialized" ]  # some value not initialized in
330                                                # host x64 build
331  cflags += [ "-Wno-int-to-void-pointer-cast" ]
332
333  if (is_mingw) {
334    include_dirs += [ "include/mingw" ]
335    cflags += [ "-DMINGW" ]
336  } else if (is_linux) {
337    cflags += [ "-g" ]  # we need debug info when it crash.
338  }
339
340  defines += [ "build_remote=1" ]
341  defines += [ "target_cpu=${target_cpu}" ]
342
343  # defines += [ "host_toolchain=${host_toolchain}" ]
344  # defines += [ "current_toolchain=${current_toolchain}" ]
345  # defines += [ "default_toolchain=${default_toolchain}" ]
346}
347
348config("unwind_config_arm") {
349  defines = [ "UNW_TARGET_ARM" ]
350}
351
352config("unwind_config_arm64") {
353  defines = [ "UNW_TARGET_ARM64" ]
354}
355
356config("unwind_config_x64") {
357  defines = [ "UNW_TARGET_X86_64" ]
358  defines += [ "UNW_TARGET_X86_64_LINUX" ]
359}
360if (target_cpu == "arm") {
361  ohos_source_set("unwind_source_arm") {
362    subsystem_name = "developtools"
363    part_name = "smartperf_host"
364    configs += [ ":unwind_config_remote" ]
365    public_configs = [
366      ":unwind_config_public",
367      ":unwind_config_remote_public",
368      ":unwind_config_arm",
369    ]
370    sources = common_source
371
372    # there is a main function in this file
373    # for a lib we dont need this
374    arm_source -= [ "src/arm/gen-offsets.c" ]
375
376    # no jump lib
377    arm_source -= [
378      "src/arm/getcontext.S",
379      "src/arm/siglongjmp.S",
380    ]
381    sources += arm_source
382    sources -= remove_sources
383  }
384}
385if (target_cpu == "arm64") {
386  ohos_source_set("unwind_source_arm64") {
387    subsystem_name = "developtools"
388    part_name = "smartperf_host"
389    configs += [ ":unwind_config_remote" ]
390    public_configs = [
391      ":unwind_config_public",
392      ":unwind_config_remote_public",
393      ":unwind_config_arm64",
394    ]
395    sources = common_source
396
397    arm64_source -= [ "src/aarch64/getcontext.S" ]
398
399    sources += arm64_source
400    sources -= remove_sources
401  }
402}
403if (target_cpu == "x86") {
404  ohos_source_set("unwind_source_x64") {
405    subsystem_name = "developtools"
406    part_name = "smartperf_host"
407    configs += [ ":unwind_config_remote" ]
408    public_configs = [
409      ":unwind_config_public",
410      ":unwind_config_remote_public",
411      ":unwind_config_x64",
412    ]
413    sources = common_source
414
415    # no jump lib
416    x64_source -= [
417      "src/x86_64/getcontext.S",
418      "src/x86_64/setcontext.S",
419    ]
420    sources += x64_source
421    sources -= remove_sources
422  }
423}
424ohos_source_set("unwind_source") {
425  subsystem_name = "developtools"
426  part_name = "smartperf_host"
427  configs += [ ":unwind_config_public" ]
428  sources = common_source
429  if (target_cpu == "arm") {
430    # as libc++ is static linked with libunwind.a
431    # we remove the Gstep.c for duplicated symbol violation
432    sources += arm_source
433    public_configs = [ ":unwind_config_arm" ]
434  } else if (target_cpu == "arm64") {
435    sources += arm64_source
436    public_configs = [ ":unwind_config_arm64" ]
437  } else if (target_cpu == "x64") {
438    # deps = [ "unwind_source_x64" ]
439    sources += x64_source
440    public_configs = [ ":unwind_config_x64" ]
441
442    # public_configs = [
443    # ":unwind_config_public",
444    # ":unwind_config_remote_public",
445    # ":unwind_config_x64",
446    # ]
447  }
448
449  sources += [ "src/os-ohos.c" ]
450}
451
452if (defined(ohos_lite)) {
453  # shared_library("libunwind") {
454  source_set("libunwind") {
455    deps = [ ":unwind_source" ]
456    public_configs = [ ":unwind_config_public" ]
457  }
458} else {
459  source_set("libunwind") {
460    deps = [ ":unwind_source" ]
461
462    # install_images = [
463    # "system",
464    # "updater",
465    # ]
466    public_configs = [ ":unwind_config_public" ]
467
468    # part_name = "smartperf_host"
469    # subsystem_name = "developtools"
470  }
471}
472