• 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
14if (defined(ohos_lite)) {
15  import("//build/lite/config/component/lite_component.gni")
16} else {
17  import("//build/ohos.gni")
18}
19import("//third_party/libunwind/libunwind.gni")
20
21common_source = [
22  "src/dwarf/Gexpr.c",
23  "src/dwarf/Gfde.c",
24  "src/dwarf/Gfind_proc_info-lsb.c",
25  "src/dwarf/Gfind_unwind_table.c",
26  "src/dwarf/global.c",
27  "src/dwarf/Gparser.c",
28  "src/dwarf/Gpe.c",
29  "src/dwarf/Lexpr.c",
30  "src/dwarf/Lfde.c",
31  "src/dwarf/Lfind_proc_info-lsb.c",
32  "src/dwarf/Lfind_unwind_table.c",
33  "src/dwarf/Lparser.c",
34  "src/dwarf/Lpe.c",
35  "src/mi/backtrace.c",
36  "src/mi/dyn-cancel.c",
37  "src/mi/dyn-info-list.c",
38  "src/mi/dyn-register.c",
39  "src/mi/flush_cache.c",
40  "src/mi/Gdestroy_addr_space.c",
41  "src/mi/Gdyn-extract.c",
42  "src/mi/Gdyn-remote.c",
43  "src/mi/Gfind_dynamic_proc_info.c",
44  "src/mi/Gget_accessors.c",
45  "src/mi/Gget_fpreg.c",
46  "src/mi/Gget_proc_info_by_ip.c",
47  "src/mi/Gget_proc_name.c",
48  "src/mi/Gget_reg.c",
49  "src/mi/Gput_dynamic_unwind_info.c",
50  "src/mi/Gset_cache_size.c",
51  "src/mi/Gset_caching_policy.c",
52  "src/mi/Gset_fpreg.c",
53  "src/mi/Gset_reg.c",
54  "src/mi/init.c",
55  "src/mi/Ldestroy_addr_space.c",
56  "src/mi/Ldyn-extract.c",
57  "src/mi/Lfind_dynamic_proc_info.c",
58  "src/mi/Lget_fpreg.c",
59  "src/mi/Lget_proc_info_by_ip.c",
60  "src/mi/Lget_proc_name.c",
61  "src/mi/Lget_reg.c",
62  "src/mi/Lput_dynamic_unwind_info.c",
63  "src/mi/Lset_cache_size.c",
64  "src/mi/Lset_caching_policy.c",
65  "src/mi/Lset_fpreg.c",
66  "src/mi/Lset_reg.c",
67  "src/mi/mempool.c",
68  "src/mi/strerror.c",
69  "src/os-linux.c",
70  "src/ohos-config.c",
71  "src/ptrace/_UPT_access_fpreg.c",
72  "src/ptrace/_UPT_access_mem.c",
73  "src/ptrace/_UPT_access_reg.c",
74  "src/ptrace/_UPT_accessors.c",
75  "src/ptrace/_UPT_create.c",
76  "src/ptrace/_UPT_destroy.c",
77  "src/ptrace/_UPT_find_proc_info.c",
78  "src/ptrace/_UPT_get_dyn_info_list_addr.c",
79  "src/ptrace/_UPT_get_proc_name.c",
80  "src/ptrace/_UPT_put_unwind_info.c",
81  "src/ptrace/_UPT_reg_offset.c",
82  "src/ptrace/_UPT_resume.c",
83  "src/mi/maps.c",
84]
85
86# as libc++ is static linked with libunwind.a
87# we remove the Gstep.c for duplicated symbol violation
88arm_source = [
89  "src/arm/Gapply_reg_state.c",
90  "src/arm/Gcreate_addr_space.c",
91  "src/arm/Gex_tables.c",
92  "src/arm/Gget_proc_info.c",
93  "src/arm/Gget_save_loc.c",
94  "src/arm/Gglobal.c",
95  "src/arm/Ginit.c",
96  "src/arm/Ginit_local.c",
97  "src/arm/Ginit_remote.c",
98  "src/arm/Gos-linux.c",
99  "src/arm/Greg_states_iterate.c",
100  "src/arm/Gregs.c",
101  "src/arm/Gresume.c",
102  "src/arm/Gstash_frame.c",
103  "src/arm/Gstep.c",
104  "src/arm/Gtrace.c",
105  "src/arm/Lcreate_addr_space.c",
106  "src/arm/Lex_tables.c",
107  "src/arm/Lget_proc_info.c",
108  "src/arm/Lget_save_loc.c",
109  "src/arm/Lglobal.c",
110  "src/arm/Linit.c",
111  "src/arm/Linit_local.c",
112  "src/arm/Linit_remote.c",
113  "src/arm/Los-linux.c",
114  "src/arm/Lregs.c",
115  "src/arm/Lresume.c",
116  "src/arm/Lstash_frame.c",
117  "src/arm/Lstep.c",
118  "src/arm/Ltrace.c",
119  "src/arm/getcontext.S",
120  "src/arm/is_fpreg.c",
121  "src/arm/regname.c",
122  "src/arm/siglongjmp.S",
123  "src/elf32.c",
124]
125
126arm64_source = [
127  "src/aarch64/Gcreate_addr_space.c",
128  "src/aarch64/Gget_proc_info.c",
129  "src/aarch64/Gget_save_loc.c",
130  "src/aarch64/Gglobal.c",
131  "src/aarch64/Ginit.c",
132  "src/aarch64/Ginit_local.c",
133  "src/aarch64/Ginit_remote.c",
134  "src/aarch64/Gis_signal_frame.c",
135  "src/aarch64/Gregs.c",
136  "src/aarch64/Gresume.c",
137  "src/aarch64/Gstash_frame.c",
138  "src/aarch64/Gstep.c",
139  "src/aarch64/Gtrace.c",
140  "src/aarch64/Lcreate_addr_space.c",
141  "src/aarch64/Lget_proc_info.c",
142  "src/aarch64/Lget_save_loc.c",
143  "src/aarch64/Lglobal.c",
144  "src/aarch64/Linit.c",
145  "src/aarch64/Linit_local.c",
146  "src/aarch64/Linit_remote.c",
147  "src/aarch64/Lis_signal_frame.c",
148  "src/aarch64/Lregs.c",
149  "src/aarch64/Lresume.c",
150  "src/aarch64/Lstash_frame.c",
151  "src/aarch64/Lstep.c",
152  "src/aarch64/Ltrace.c",
153  "src/aarch64/getcontext.S",
154  "src/aarch64/is_fpreg.c",
155  "src/aarch64/regname.c",
156  "src/elf64.c",
157]
158
159x64_source = [
160  "src/elf64.c",
161  "src/x86_64/Gcreate_addr_space.c",
162  "src/x86_64/Gget_proc_info.c",
163  "src/x86_64/Gget_save_loc.c",
164  "src/x86_64/Gglobal.c",
165  "src/x86_64/Ginit.c",
166  "src/x86_64/Ginit_local.c",
167  "src/x86_64/Ginit_remote.c",
168  "src/x86_64/Gos-linux.c",
169  "src/x86_64/Gregs.c",
170  "src/x86_64/Gresume.c",
171  "src/x86_64/Gstash_frame.c",
172  "src/x86_64/Gstep.c",
173  "src/x86_64/Gtrace.c",
174  "src/x86_64/Lcreate_addr_space.c",
175  "src/x86_64/Lget_proc_info.c",
176  "src/x86_64/Lget_save_loc.c",
177  "src/x86_64/Lglobal.c",
178  "src/x86_64/Linit.c",
179  "src/x86_64/Linit_local.c",
180  "src/x86_64/Linit_remote.c",
181  "src/x86_64/Los-linux.c",
182  "src/x86_64/Lregs.c",
183  "src/x86_64/Lresume.c",
184  "src/x86_64/Lstash_frame.c",
185  "src/x86_64/Lstep.c",
186  "src/x86_64/Ltrace.c",
187  "src/x86_64/getcontext.S",
188  "src/x86_64/is_fpreg.c",
189  "src/x86_64/regname.c",
190  "src/x86_64/setcontext.S",
191]
192
193riscv64_source = [
194  "src/elf64.c",
195  "src/riscv/Gapply_reg_state.c",
196  "src/riscv/Gcreate_addr_space.c",
197  "src/riscv/getcontext.S",
198  "src/riscv/Gget_proc_info.c",
199  "src/riscv/Gget_save_loc.c",
200  "src/riscv/Gglobal.c",
201  "src/riscv/Ginit.c",
202  "src/riscv/Ginit_local.c",
203  "src/riscv/Ginit_remote.c",
204  "src/riscv/Gis_signal_frame.c",
205  "src/riscv/Gregs.c",
206  "src/riscv/Greg_states_iterate.c",
207  "src/riscv/Gresume.c",
208  "src/riscv/Gstep.c",
209  "src/riscv/is_fpreg.c",
210  "src/riscv/Lcreate_addr_space.c",
211  "src/riscv/Lget_proc_info.c",
212  "src/riscv/Lget_save_loc.c",
213  "src/riscv/Lglobal.c",
214  "src/riscv/Linit.c",
215  "src/riscv/Linit_local.c",
216  "src/riscv/Linit_remote.c",
217  "src/riscv/Lis_signal_frame.c",
218  "src/riscv/Lregs.c",
219  "src/riscv/Lreg_states_iterate.c",
220  "src/riscv/Lresume.c",
221  "src/riscv/Lstep.c",
222  "src/riscv/offsets.h",
223  "src/riscv/regname.c",
224  "src/riscv/setcontext.S",
225  "src/riscv/siglongjmp.S",
226]
227
228remove_sources = []
229
230ptrace_sources = [
231  "src/ptrace/_UPT_access_fpreg.c",
232  "src/ptrace/_UPT_access_mem.c",
233  "src/ptrace/_UPT_access_reg.c",
234  "src/ptrace/_UPT_accessors.c",
235  "src/ptrace/_UPT_create.c",
236  "src/ptrace/_UPT_destroy.c",
237  "src/ptrace/_UPT_find_proc_info.c",
238  "src/ptrace/_UPT_get_dyn_info_list_addr.c",
239  "src/ptrace/_UPT_get_proc_name.c",
240  "src/ptrace/_UPT_put_unwind_info.c",
241  "src/ptrace/_UPT_reg_offset.c",
242  "src/ptrace/_UPT_resume.c",
243]
244
245libunwind_la_SOURCES_local_nounwind = [
246  "src/mi/backtrace.c",
247  "src/mi/dyn-cancel.c",
248  "src/mi/dyn-info-list.c",
249  "src/mi/dyn-register.c",
250  "src/mi/Ldyn-extract.c",
251  "src/mi/Lfind_dynamic_proc_info.c",
252
253  # "src/mi/Lget_accessors.c", # miss
254  "src/mi/Lget_proc_info_by_ip.c",
255  "src/mi/Lget_proc_name.c",
256  "src/mi/Lput_dynamic_unwind_info.c",
257  "src/mi/Ldestroy_addr_space.c",
258  "src/mi/Lget_reg.c",
259  "src/mi/Lset_reg.c",
260  "src/mi/Lget_fpreg.c",
261  "src/mi/Lset_fpreg.c",
262  "src/mi/Lset_caching_policy.c",
263  "src/mi/Lset_cache_size.c",
264]
265
266libunwind_dwarf_local_la_SOURCES = [
267  "src/dwarf/Lexpr.c",
268  "src/dwarf/Lfde.c",
269  "src/dwarf/Lparser.c",
270  "src/dwarf/Lpe.c",
271  "src/dwarf/Lfind_proc_info-lsb.c",
272  "src/dwarf/Lfind_unwind_table.c",
273]
274
275# remove local file
276remove_sources += libunwind_la_SOURCES_local_nounwind
277remove_sources += libunwind_dwarf_local_la_SOURCES
278remove_sources += ptrace_sources
279
280if (is_mingw) {
281  common_source += [ "src/mingw/pal-single-threaded.c" ]
282}
283
284config("unwind_config_public") {
285  include_dirs = [
286    "src",
287    "include",
288  ]
289
290  cflags = [
291    "-D_GNU_SOURCE",
292    "-DHAVE_CONFIG_H",
293    "-DNDEBUG",
294    "-DCC_IS_CLANG",
295    "-fcommon",
296    "-Werror",
297    "-Wno-absolute-value",
298    "-Wno-header-guard",
299    "-Wno-unused-parameter",
300    "-Wno-unused-variable",
301    "-Wno-int-to-pointer-cast",
302    "-Wno-pointer-to-int-cast",
303  ]
304
305  if (defined(ohos_lite)) {
306    cflags += [ "-fPIC" ]
307  }
308
309  if (target_cpu == "arm") {
310    include_dirs += [ "include/tdep-arm" ]
311    cflags += [
312      "-Wno-inline-asm",
313      "-Wno-shift-count-overflow",
314      "-Wno-tautological-constant-out-of-range-compare",
315      "-Wno-unused-function",
316    ]
317  } else if (target_cpu == "riscv64") {
318    include_dirs += [ "include/tdep-riscv" ]
319    cflags += [ "-Wno-implicit-function-declaration" ]
320  } else if (target_cpu == "arm64") {
321    include_dirs += [ "include/tdep-aarch64" ]
322    cflags += [ "-Wno-incompatible-pointer-types" ]
323  } else if (target_cpu == "x64" || target_cpu == "x86_64") {
324    include_dirs += [ "include/tdep-x86_64" ]
325  } else if (target_cpu == "mipsel") {
326    include_dirs += [ "include/tdep-mips" ]
327  }
328}
329
330config("unwind_config_remote") {
331  cflags =
332      [ "-Wno-format" ]  # some debug feature will warning in host x64 build
333}
334
335config("unwind_config_local_only") {
336  defines = [ "UNW_LOCAL_ONLY" ]
337}
338
339config("unwind_config_remote_public") {
340  cflags = []
341  include_dirs = []
342  defines = []
343
344  # this is a host tools build
345  # what means host use remote mode to unwind
346  # with dwarf from stack or coredump or something not real target
347  # There is an exception, we can support local unwind for linux.
348  cflags += [ "-DUNW_REMOTE_ONLY" ]
349
350  cflags += [ "-DBUILD_REMOTE" ]
351
352  cflags += [ "-Wno-sometimes-uninitialized" ]  # some value not initialized in
353                                                # host x64 build
354  cflags += [ "-Wno-int-to-void-pointer-cast" ]
355
356  if (is_mingw) {
357    include_dirs += [ "include/mingw" ]
358    cflags += [ "-DMINGW" ]
359  } else if (is_linux) {
360    cflags += [ "-g" ]  # we need debug info when it crash.
361  }
362
363  defines += [ "build_remote=1" ]
364  defines += [ "target_cpu=${target_cpu}" ]
365  defines += [ "host_toolchain=${host_toolchain}" ]
366  defines += [ "current_toolchain=${current_toolchain}" ]
367  defines += [ "default_toolchain=${default_toolchain}" ]
368}
369
370config("unwind_config_arm") {
371  defines = [ "UNW_TARGET_ARM" ]
372}
373
374config("unwind_config_arm64") {
375  defines = [ "UNW_TARGET_ARM64" ]
376}
377
378config("unwind_config_arm64_opt") {
379  defines = [ "ONLY_RECOVER_GENERAL_REGS" ]
380}
381
382config("unwind_config_x64") {
383  defines = [ "UNW_TARGET_X86_64" ]
384  defines += [ "UNW_TARGET_X86_64_LINUX" ]
385}
386
387config("unwind_config_x86_64") {
388  defines = [ "UNW_TARGET_X86_64" ]
389  defines += [ "UNW_TARGET_X86_64_LINUX" ]
390}
391
392config("unwind_config_riscv64") {
393  defines = [ "UNW_TARGET_RISCV" ]
394}
395
396if (defined(ohos_lite)) {
397  source_set("unwind_source_arm") {
398    configs += [ ":unwind_config_remote" ]
399    public_configs = [
400      ":unwind_config_public",
401      ":unwind_config_remote_public",
402      ":unwind_config_arm",
403    ]
404    sources = common_source
405
406    # no jump lib
407    arm_source -= [
408      "src/arm/getcontext.S",
409      "src/arm/siglongjmp.S",
410    ]
411    sources += arm_source
412    sources -= remove_sources
413  }
414
415  source_set("unwind_source_arm64") {
416    configs += [ ":unwind_config_remote" ]
417    public_configs = [
418      ":unwind_config_public",
419      ":unwind_config_remote_public",
420      ":unwind_config_arm64",
421    ]
422    sources = common_source
423
424    arm64_source -= [ "src/aarch64/getcontext.S" ]
425
426    sources += arm64_source
427    sources -= remove_sources
428  }
429
430  source_set("unwind_source_x64") {
431    configs += [ ":unwind_config_remote" ]
432    public_configs = [
433      ":unwind_config_public",
434      ":unwind_config_remote_public",
435      ":unwind_config_x64",
436    ]
437    sources = common_source
438
439    # no jump lib
440    x64_source -= [
441      "src/x86_64/getcontext.S",
442      "src/x86_64/setcontext.S",
443    ]
444    sources += x64_source
445    sources -= remove_sources
446  }
447
448  source_set("unwind_source_riscv64") {
449    configs += [ ":unwind_config_remote" ]
450    public_configs = [
451      ":unwind_config_public",
452      ":unwind_config_remote_public",
453      ":unwind_config_riscv64",
454    ]
455    sources = common_source
456
457    # no jump lib
458    riscv64_source -= [
459      "src/riscv/getcontext.S",
460      "src/riscv/setcontext.S",
461    ]
462
463    sources += riscv64_source
464    sources -= remove_sources
465  }
466
467  source_set("unwind_source") {
468    configs += [ ":unwind_config_public" ]
469    sources = common_source
470
471    if (target_cpu == "arm") {
472      # no jump lib
473      arm_source -= [
474        "src/arm/getcontext.S",
475        "src/arm/siglongjmp.S",
476      ]
477
478      # as libc++ is static linked with libunwind.a
479      # we remove the Gstep.c for duplicated symbol violation
480      sources += arm_source
481      public_configs = [ ":unwind_config_arm" ]
482    } else if (target_cpu == "arm64") {
483      sources += arm64_source
484      public_configs = [ ":unwind_config_arm64" ]
485    } else if (target_cpu == "riscv64") {
486      sources += riscv64_source
487      public_configs = [ ":unwind_config_riscv64" ]
488    } else if (target_cpu == "x64") {
489      sources += x64_source
490      public_configs = [ ":unwind_config_x64" ]
491    } else if (target_cpu == "x86_64") {
492      sources += x64_source
493      public_configs = [ ":unwind_config_x86_64" ]
494    }
495
496    sources += [ "src/os-ohos.c" ]
497  }
498
499  shared_library("libunwind") {
500    deps = [ ":unwind_source" ]
501    public_configs = [ ":unwind_config_public" ]
502  }
503
504  static_library("libunwind_local") {
505    sources = common_source
506    public_configs = [ ":unwind_config_public" ]
507    public_configs += [ ":unwind_config_local_only" ]
508
509    if (target_cpu == "arm") {
510      sources += arm_source
511      sources -= arm_source_local
512      public_configs += [ ":unwind_config_arm" ]
513    } else if (target_cpu == "arm64") {
514      sources += arm64_source
515      sources -= arm64_source_local
516      public_configs += [ ":unwind_config_arm64" ]
517    } else if (target_cpu == "riscv64") {
518      sources += riscv64_source
519      sources -= riscv64_source_local
520      public_configs += [ ":unwind_config_riscv64" ]
521    } else if (target_cpu == "x64") {
522      sources += x64_source
523      sources -= x64_source_local
524      public_configs += [ ":unwind_config_x64" ]
525    } else if (target_cpu == "x86_64") {
526      sources += x64_source
527      sources -= x64_source_local
528      public_configs += [ ":unwind_config_x86_64" ]
529    }
530
531    sources += [ "src/os-ohos.c" ]
532    sources -= libunwind_dwarf_local_la_SOURCES
533    sources -= libunwind_la_SOURCES_local
534    sources -= ptrace_sources
535
536    cflags = [
537      "-DHAS_ARK_FRAME",
538      "-DPARSE_BUILD_ID",
539      "-DUNW_LOCAL_ONLY",
540      "-DNO_RESERVE_CACHE",
541    ]
542  }
543} else {
544  ohos_source_set("unwind_source_arm") {
545    configs = [ ":unwind_config_remote" ]
546    public_configs = [
547      ":unwind_config_public",
548      ":unwind_config_remote_public",
549      ":unwind_config_arm",
550    ]
551    sources = common_source
552
553    # no jump lib
554    arm_source -= [
555      "src/arm/getcontext.S",
556      "src/arm/siglongjmp.S",
557    ]
558    sources += arm_source
559    sources -= remove_sources
560  }
561
562  ohos_source_set("unwind_source_arm64") {
563    configs = [ ":unwind_config_remote" ]
564    public_configs = [
565      ":unwind_config_public",
566      ":unwind_config_remote_public",
567      ":unwind_config_arm64",
568    ]
569    sources = common_source
570
571    arm64_source -= [ "src/aarch64/getcontext.S" ]
572
573    sources += arm64_source
574    sources -= remove_sources
575  }
576
577  ohos_source_set("unwind_source_arm64_opt") {
578    configs = [ ":unwind_config_remote" ]
579    public_configs = [
580      ":unwind_config_public",
581      ":unwind_config_remote_public",
582      ":unwind_config_arm64",
583      ":unwind_config_arm64_opt",
584    ]
585    sources = common_source
586
587    arm64_source -= [ "src/aarch64/getcontext.S" ]
588
589    sources += arm64_source
590    sources -= remove_sources
591  }
592
593  ohos_source_set("unwind_source_x64") {
594    configs = [ ":unwind_config_remote" ]
595    public_configs = [
596      ":unwind_config_public",
597      ":unwind_config_remote_public",
598      ":unwind_config_x64",
599    ]
600    sources = common_source
601
602    # no jump lib
603    x64_source -= [
604      "src/x86_64/getcontext.S",
605      "src/x86_64/setcontext.S",
606    ]
607    sources += x64_source
608    sources -= remove_sources
609  }
610
611  ohos_source_set("unwind_source_x86_64") {
612    configs = [ ":unwind_config_remote" ]
613    public_configs = [
614      ":unwind_config_public",
615      ":unwind_config_remote_public",
616      ":unwind_config_x86_64",
617    ]
618    sources = common_source
619
620    # no jump lib
621    x64_source -= [
622      "src/x86_64/getcontext.S",
623      "src/x86_64/setcontext.S",
624    ]
625    sources += x64_source
626    sources -= remove_sources
627  }
628
629  ohos_source_set("unwind_source_riscv64") {
630    configs = [ ":unwind_config_remote" ]
631    public_configs = [
632      ":unwind_config_public",
633      ":unwind_config_remote_public",
634      ":unwind_config_riscv64",
635    ]
636    sources = common_source
637
638    # no jump lib
639    riscv64_source -= [
640      "src/riscv/getcontext.S",
641      "src/riscv/setcontext.S",
642    ]
643
644    sources += riscv64_source
645    sources -= remove_sources
646  }
647
648  ohos_source_set("unwind_source") {
649    configs = [ ":unwind_config_public" ]
650    sources = common_source
651
652    if (target_cpu == "riscv64") {
653      # as libc++ is static linked with libunwind.a
654      # we remove the Gstep.c for duplicated symbol violation
655      sources += riscv64_source
656      public_configs = [ ":unwind_config_riscv64" ]
657    } else if (target_cpu == "arm") {
658      sources += arm_source
659      public_configs = [ ":unwind_config_arm" ]
660    } else if (target_cpu == "arm64") {
661      sources += arm64_source
662      public_configs = [ ":unwind_config_arm64" ]
663    } else if (target_cpu == "x64") {
664      sources += x64_source
665      public_configs = [ ":unwind_config_x64" ]
666    } else if (target_cpu == "x86_64") {
667      sources += x64_source
668      public_configs = [ ":unwind_config_x86_64" ]
669    }
670
671    sources += [ "src/os-ohos.c" ]
672    cflags = [
673      "-DHAS_ARK_FRAME",
674      "-DPARSE_BUILD_ID",
675      "-DPARSE_ELF_IN_HAP",
676    ]
677  }
678
679  ohos_shared_library("libunwind") {
680    deps = [ ":unwind_source" ]
681    install_images = [
682      "system",
683      "updater",
684    ]
685    public_configs = [ ":unwind_config_public" ]
686    innerapi_tags = [
687      "platformsdk",
688      "chipsetsdk",
689    ]
690    subsystem_name = "thirdparty"
691    part_name = "libunwind"
692  }
693
694  # for internal use only, the interfaces may have compatible issue
695  ohos_static_library("libunwind_local") {
696    sources = common_source
697    public_configs = [ ":unwind_config_public" ]
698    public_configs += [ ":unwind_config_local_only" ]
699
700    if (target_cpu == "arm") {
701      sources += arm_source
702      sources -= arm_source_local
703      public_configs += [ ":unwind_config_arm" ]
704    } else if (target_cpu == "arm64") {
705      sources += arm64_source
706      sources -= arm64_source_local
707      public_configs += [ ":unwind_config_arm64" ]
708    } else if (target_cpu == "riscv64") {
709      sources += riscv64_source
710      sources -= riscv64_source_local
711      public_configs += [ ":unwind_config_riscv64" ]
712    } else if (target_cpu == "x64") {
713      sources += x64_source
714      sources -= x64_source_local
715      public_configs += [ ":unwind_config_x64" ]
716    } else if (target_cpu == "x86_64") {
717      sources += x64_source
718      sources -= x64_source_local
719      public_configs += [ ":unwind_config_x86_64" ]
720    }
721
722    sources += [ "src/os-ohos.c" ]
723    sources -= libunwind_dwarf_local_la_SOURCES
724    sources -= libunwind_la_SOURCES_local
725    sources -= ptrace_sources
726
727    cflags = [
728      "-DHAS_ARK_FRAME",
729      "-DPARSE_BUILD_ID",
730      "-DUNW_LOCAL_ONLY",
731      "-DNO_RESERVE_CACHE",
732      "-DHAVE_PIPE2",
733    ]
734
735    subsystem_name = "thirdparty"
736    part_name = "libunwind"
737  }
738}
739
740if (!defined(ohos_lite)) {
741  import("//build/test.gni")
742  module_output_path = "thirdparty/libunwind"
743  group("unittest") {
744    testonly = true
745    deps = [
746      ":Gtest_bt",
747      ":Gtest_dyn1",
748      ":Gtest_init",
749      ":Gtest_trace",
750      ":Ltest_bt",
751      ":Ltest_cxx_exceptions",
752      ":Ltest_dyn1",
753      ":Ltest_init",
754      ":Ltest_init_local_signal",
755      ":Ltest_mem_validate",
756      ":Ltest_nocalloc",
757      ":Ltest_nomalloc",
758      ":Ltest_trace",
759      ":test_ptrace_misc",
760      ":test_static_link",
761    ]
762  }
763  config("unwind_test") {
764    cflags = [ "-O0" ]
765  }
766
767  ohos_unittest("Gtest_init") {
768    module_out_path = module_output_path
769    sources = [ "tests/Gtest-init.cxx" ]
770    include_dirs = [
771      "tests",
772      "include",
773    ]
774
775    configs = [ ":unwind_test" ]
776    deps = [ ":libunwind" ]
777    subsystem_name = "thirdparty"
778    part_name = "libunwind"
779  }
780
781  ohos_unittest("Ltest_init") {
782    module_out_path = module_output_path
783    sources = [ "tests/Ltest-init.cxx" ]
784    include_dirs = [
785      "tests",
786      "include",
787    ]
788    configs = [ ":unwind_test" ]
789    deps = [ ":libunwind" ]
790    subsystem_name = "thirdparty"
791    part_name = "libunwind"
792  }
793
794  ohos_unittest("Ltest_cxx_exceptions") {
795    module_out_path = module_output_path
796    sources = [ "tests/Ltest-cxx-exceptions.cxx" ]
797    include_dirs = [
798      "tests",
799      "include",
800    ]
801    configs = [ ":unwind_test" ]
802    cflags = [ "-fexceptions" ]
803    deps = [ ":libunwind" ]
804    subsystem_name = "thirdparty"
805    part_name = "libunwind"
806    remove_configs = [ "//build/config/compiler:no_exceptions" ]
807  }
808
809  ohos_unittest("Ltest_init_local_signal") {
810    module_out_path = module_output_path
811    sources = [
812      "tests/Ltest-init-local-signal-lib.c",
813      "tests/Ltest-init-local-signal.c",
814    ]
815    include_dirs = [
816      "tests",
817      "include",
818    ]
819    configs = [ ":unwind_test" ]
820    deps = [ ":libunwind" ]
821    subsystem_name = "thirdparty"
822    part_name = "libunwind"
823  }
824
825  ohos_unittest("Gtest_dyn1") {
826    module_out_path = module_output_path
827    sources = [
828      "tests/Gtest-dyn1.c",
829      "tests/flush-cache.h",
830    ]
831    if (target_cpu == "arm") {
832      sources += [ "tests/flush-cache.S" ]
833    }
834    include_dirs = [
835      "tests",
836      "include",
837    ]
838    configs = [ ":unwind_test" ]
839    cflags = [ "-DHAVE__BUILTIN___CLEAR_CACHE" ]
840    deps = [ ":libunwind" ]
841    subsystem_name = "thirdparty"
842    part_name = "libunwind"
843  }
844
845  ohos_unittest("Ltest_dyn1") {
846    module_out_path = module_output_path
847    sources = [
848      "tests/Ltest-dyn1.c",
849      "tests/flush-cache.h",
850    ]
851    if (target_cpu == "arm") {
852      sources += [ "tests/flush-cache.S" ]
853    }
854    include_dirs = [
855      "tests",
856      "include",
857    ]
858    configs = [ ":unwind_test" ]
859    cflags = [ "-DHAVE__BUILTIN___CLEAR_CACHE" ]
860    deps = [ ":libunwind" ]
861    subsystem_name = "thirdparty"
862    part_name = "libunwind"
863  }
864
865  ohos_unittest("test_static_link") {
866    module_out_path = module_output_path
867    sources = [
868      "tests/test-static-link-gen.c",
869      "tests/test-static-link-loc.c",
870    ]
871    include_dirs = [
872      "tests",
873      "include",
874    ]
875    configs = [ ":unwind_test" ]
876    deps = [ ":libunwind" ]
877    subsystem_name = "thirdparty"
878    part_name = "libunwind"
879  }
880
881  ohos_unittest("Gtest_bt") {
882    module_out_path = module_output_path
883    sources = [
884      "tests/Gtest-bt.c",
885      "tests/dummy_backtrace.c",
886      "tests/ident.c",
887    ]
888    include_dirs = [
889      "tests",
890      "include",
891    ]
892    configs = [ ":unwind_test" ]
893    deps = [ ":libunwind" ]
894    subsystem_name = "thirdparty"
895    part_name = "libunwind"
896  }
897
898  ohos_unittest("Ltest_bt") {
899    module_out_path = module_output_path
900    sources = [
901      "tests/Ltest-bt.c",
902      "tests/dummy_backtrace.c",
903      "tests/ident.c",
904    ]
905    include_dirs = [
906      "tests",
907      "include",
908    ]
909    configs = [ ":unwind_test" ]
910    deps = [ ":libunwind" ]
911    subsystem_name = "thirdparty"
912    part_name = "libunwind"
913  }
914
915  ohos_unittest("test_ptrace_misc") {
916    module_out_path = module_output_path
917    sources = [
918      "tests/ident.c",
919      "tests/test-ptrace-misc.c",
920    ]
921    include_dirs = [
922      "tests",
923      "include",
924    ]
925    configs = [ ":unwind_test" ]
926    deps = [ ":libunwind" ]
927    subsystem_name = "thirdparty"
928    part_name = "libunwind"
929  }
930
931  ohos_unittest("Ltest_nomalloc") {
932    module_out_path = module_output_path
933    sources = [ "tests/Ltest-nomalloc.c" ]
934    include_dirs = [
935      "tests",
936      "include",
937    ]
938    configs = [ ":unwind_test" ]
939    deps = [ ":libunwind" ]
940    subsystem_name = "thirdparty"
941    part_name = "libunwind"
942  }
943
944  ohos_unittest("Ltest_nocalloc") {
945    module_out_path = module_output_path
946    sources = [ "tests/Ltest-nocalloc.c" ]
947    include_dirs = [
948      "tests",
949      "include",
950    ]
951    configs = [ ":unwind_test" ]
952    deps = [ ":libunwind" ]
953    subsystem_name = "thirdparty"
954    part_name = "libunwind"
955  }
956
957  ohos_unittest("Gtest_trace") {
958    module_out_path = module_output_path
959    sources = [
960      "tests/Gtest-trace.c",
961      "tests/dummy_backtrace.c",
962      "tests/ident.c",
963    ]
964    include_dirs = [
965      "tests",
966      "include",
967    ]
968    configs = [ ":unwind_test" ]
969    deps = [ ":libunwind" ]
970    subsystem_name = "thirdparty"
971    part_name = "libunwind"
972  }
973
974  ohos_unittest("Ltest_trace") {
975    module_out_path = module_output_path
976    sources = [
977      "tests/Ltest-trace.c",
978      "tests/dummy_backtrace.c",
979      "tests/ident.c",
980    ]
981    include_dirs = [
982      "tests",
983      "include",
984    ]
985    configs = [ ":unwind_test" ]
986    deps = [ ":libunwind" ]
987    subsystem_name = "thirdparty"
988    part_name = "libunwind"
989  }
990
991  ohos_unittest("Ltest_mem_validate") {
992    module_out_path = module_output_path
993    sources = [ "tests/Ltest-mem-validate.c" ]
994    include_dirs = [
995      "tests",
996      "include",
997    ]
998    configs = [ ":unwind_test" ]
999    deps = [ ":libunwind" ]
1000    subsystem_name = "thirdparty"
1001    part_name = "libunwind"
1002  }
1003} else {
1004  group("unittest") {
1005    testonly = true
1006    deps = []
1007  }
1008}
1009