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