1//
2// Copyright (C) 2014 The Android Open Source Project
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17// Set to true to enable a debug build of the libraries.
18// To control what is logged, set the environment variable UNW_DEBUG_LEVEL=x,
19// where x controls the verbosity (from 1 to 20).
20libunwind_debug = ["false"]
21
22libunwind_common_cppflags = [
23    "-Wno-old-style-cast",
24]
25
26libunwind_common_cflags = [
27    "-Wno-unused-parameter",
28    "-Werror",
29]
30
31// gcc 4.8 appears to be overeager declaring that a variable is uninitialized,
32// under certain circumstances. Turn off this warning only for target so that
33// coverage is still present for the host code. When the entire build system
34// is switched to 4.9, then this can be removed.
35libunwind_common_cflags_target = ["-Wno-maybe-uninitialized"]
36
37// src/mi/backtrace.c is misdetected as a bogus header guard by clang 3.5
38// src/x86_64/Gstash_frame.c has unnecessary calls to labs.
39libunwind_common_clang_cflags = [
40    "-Wno-header-guard",
41    "-Wno-absolute-value",
42    // The latest clang (r230699) does not allow SP/PC to be declared in inline asm lists.
43    "-Wno-inline-asm",
44]
45
46libunwind_common_cflags += [
47    "-DHAVE_CONFIG_H",
48    "-D_GNU_SOURCE",
49    "-DNDEBUG",
50]
51
52libunwind_common_debug_cflags = [
53    "-UNDEBUG",
54    "-DDEBUG",
55    "-U_FORTIFY_SOURCE",
56]
57
58libunwind_common_c_local_includes = [
59    "src",
60    "include",
61]
62
63libunwind_common_arch_includes = {
64    arm: {
65        local_include_dirs: ["include/tdep-arm"],
66    },
67    arm64: {
68        local_include_dirs: ["include/tdep-aarch64"],
69    },
70    mips: {
71        local_include_dirs: ["include/tdep-mips"],
72    },
73    mips64: {
74        local_include_dirs: ["include/tdep-mips"],
75    },
76    x86: {
77        local_include_dirs: ["include/tdep-x86"],
78    },
79    x86_64: {
80        local_include_dirs: ["include/tdep-x86_64"],
81    },
82}
83
84//-----------------------------------------------------------------------
85// libunwind shared and static library
86//-----------------------------------------------------------------------
87
88cc_library {
89    name: "libunwind",
90    host_supported: true,
91    srcs: [
92        "src/mi/init.c",
93        "src/mi/flush_cache.c",
94        "src/mi/mempool.c",
95        "src/mi/strerror.c",
96        "src/mi/backtrace.c",
97        "src/mi/dyn-cancel.c",
98        "src/mi/dyn-info-list.c",
99        "src/mi/dyn-register.c",
100        "src/mi/map.c",
101        "src/mi/Lmap.c",
102        "src/mi/Ldyn-extract.c",
103        "src/mi/Lfind_dynamic_proc_info.c",
104        "src/mi/Lget_proc_info_by_ip.c",
105        "src/mi/Lget_proc_name.c",
106        "src/mi/Lput_dynamic_unwind_info.c",
107        "src/mi/Ldestroy_addr_space.c",
108        "src/mi/Lget_reg.c",
109        "src/mi/Lset_reg.c",
110        "src/mi/Lget_fpreg.c",
111        "src/mi/Lset_fpreg.c",
112        "src/mi/Lset_caching_policy.c",
113        "src/mi/Gdyn-extract.c",
114        "src/mi/Gdyn-remote.c",
115        "src/mi/Gfind_dynamic_proc_info.c",
116        "src/mi/Gget_accessors.c",
117        "src/mi/Gget_proc_info_by_ip.c",
118        "src/mi/Gget_proc_name.c",
119        "src/mi/Gput_dynamic_unwind_info.c",
120        "src/mi/Gdestroy_addr_space.c",
121        "src/mi/Gget_reg.c",
122        "src/mi/Gset_reg.c",
123        "src/mi/Gget_fpreg.c",
124        "src/mi/Gset_fpreg.c",
125        "src/mi/Gset_caching_policy.c",
126        "src/dwarf/Lexpr.c",
127        "src/dwarf/Lfde.c",
128        "src/dwarf/Lparser.c",
129        "src/dwarf/Lpe.c",
130        "src/dwarf/Lstep_dwarf.c",
131        "src/dwarf/Lfind_proc_info-lsb.c",
132        "src/dwarf/Lfind_unwind_table.c",
133        "src/dwarf/Gexpr.c",
134        "src/dwarf/Gfde.c",
135        "src/dwarf/Gfind_proc_info-lsb.c",
136        "src/dwarf/Gfind_unwind_table.c",
137        "src/dwarf/Gparser.c",
138        "src/dwarf/Gpe.c",
139        "src/dwarf/Gstep_dwarf.c",
140        "src/dwarf/global.c",
141        "src/os-common.c",
142        "src/os-linux.c",
143        "src/Los-common.c",
144
145        // ptrace files for remote unwinding.
146        "src/ptrace/_UPT_accessors.c",
147        "src/ptrace/_UPT_access_fpreg.c",
148        "src/ptrace/_UPT_access_mem.c",
149        "src/ptrace/_UPT_access_reg.c",
150        "src/ptrace/_UPT_create.c",
151        "src/ptrace/_UPT_destroy.c",
152        "src/ptrace/_UPT_find_proc_info.c",
153        "src/ptrace/_UPT_get_dyn_info_list_addr.c",
154        "src/ptrace/_UPT_put_unwind_info.c",
155        "src/ptrace/_UPT_get_proc_name.c",
156        "src/ptrace/_UPT_reg_offset.c",
157        "src/ptrace/_UPT_resume.c",
158     ],
159
160    cflags: libunwind_common_cflags,
161    clang_cflags: libunwind_common_clang_cflags,
162    local_include_dirs: libunwind_common_c_local_includes,
163
164    arch: {
165        arm: {
166            srcs: [
167                "src/arm/is_fpreg.c",
168                "src/arm/regname.c",
169                "src/arm/Gcreate_addr_space.c",
170                "src/arm/Gget_proc_info.c",
171                "src/arm/Gget_save_loc.c",
172                "src/arm/Gglobal.c",
173                "src/arm/Ginit.c",
174                "src/arm/Ginit_local.c",
175                "src/arm/Ginit_remote.c",
176                "src/arm/Gregs.c",
177                "src/arm/Gresume.c",
178                "src/arm/Gstep.c",
179                "src/arm/Lcreate_addr_space.c",
180                "src/arm/Lget_proc_info.c",
181                "src/arm/Lget_save_loc.c",
182                "src/arm/Lglobal.c",
183                "src/arm/Linit.c",
184                "src/arm/Linit_local.c",
185                "src/arm/Linit_remote.c",
186                "src/arm/Lregs.c",
187                "src/arm/Lresume.c",
188                "src/arm/Lstep.c",
189
190                "src/arm/getcontext.S",
191                "src/arm/Gis_signal_frame.c",
192                "src/arm/Gex_tables.c",
193                "src/arm/Lis_signal_frame.c",
194                "src/arm/Lex_tables.c",
195            ],
196        },
197        arm64: {
198            srcs: [
199                "src/aarch64/is_fpreg.c",
200                "src/aarch64/regname.c",
201                "src/aarch64/Gcreate_addr_space.c",
202                "src/aarch64/Gget_proc_info.c",
203                "src/aarch64/Gget_save_loc.c",
204                "src/aarch64/Gglobal.c",
205                "src/aarch64/Ginit.c",
206                "src/aarch64/Ginit_local.c",
207                "src/aarch64/Ginit_remote.c",
208                "src/aarch64/Gregs.c",
209                "src/aarch64/Gresume.c",
210                "src/aarch64/Gstep.c",
211                "src/aarch64/Lcreate_addr_space.c",
212                "src/aarch64/Lget_proc_info.c",
213                "src/aarch64/Lget_save_loc.c",
214                "src/aarch64/Lglobal.c",
215                "src/aarch64/Linit.c",
216                "src/aarch64/Linit_local.c",
217                "src/aarch64/Linit_remote.c",
218                "src/aarch64/Lregs.c",
219                "src/aarch64/Lresume.c",
220                "src/aarch64/Lstep.c",
221
222                "src/aarch64/Gis_signal_frame.c",
223                "src/aarch64/Lis_signal_frame.c",
224            ],
225        },
226        mips: {
227            srcs: [
228                "src/mips/is_fpreg.c",
229                "src/mips/regname.c",
230                "src/mips/Gcreate_addr_space.c",
231                "src/mips/Gget_proc_info.c",
232                "src/mips/Gget_save_loc.c",
233                "src/mips/Gglobal.c",
234                "src/mips/Ginit.c",
235                "src/mips/Ginit_local.c",
236                "src/mips/Ginit_remote.c",
237                "src/mips/Gregs.c",
238                "src/mips/Gresume.c",
239                "src/mips/Gstep.c",
240                "src/mips/Lcreate_addr_space.c",
241                "src/mips/Lget_proc_info.c",
242                "src/mips/Lget_save_loc.c",
243                "src/mips/Lglobal.c",
244                "src/mips/Linit.c",
245                "src/mips/Linit_local.c",
246                "src/mips/Linit_remote.c",
247                "src/mips/Lregs.c",
248                "src/mips/Lresume.c",
249                "src/mips/Lstep.c",
250
251                "src/mips/getcontext-android.S",
252                "src/mips/Gis_signal_frame.c",
253                "src/mips/Lis_signal_frame.c",
254            ],
255        },
256        // mips and mips64 use the same sources but define _MIP_SIM differently
257        // to change the behavior.
258        //   mips uses o32 abi (_MIPS_SIM == _ABIO32).
259        //   mips64 uses n64 abi (_MIPS_SIM == _ABI64).
260        mips64: {
261            srcs: [
262                "src/mips/is_fpreg.c",
263                "src/mips/regname.c",
264                "src/mips/Gcreate_addr_space.c",
265                "src/mips/Gget_proc_info.c",
266                "src/mips/Gget_save_loc.c",
267                "src/mips/Gglobal.c",
268                "src/mips/Ginit.c",
269                "src/mips/Ginit_local.c",
270                "src/mips/Ginit_remote.c",
271                "src/mips/Gregs.c",
272                "src/mips/Gresume.c",
273                "src/mips/Gstep.c",
274                "src/mips/Lcreate_addr_space.c",
275                "src/mips/Lget_proc_info.c",
276                "src/mips/Lget_save_loc.c",
277                "src/mips/Lglobal.c",
278                "src/mips/Linit.c",
279                "src/mips/Linit_local.c",
280                "src/mips/Linit_remote.c",
281                "src/mips/Lregs.c",
282                "src/mips/Lresume.c",
283                "src/mips/Lstep.c",
284
285                "src/mips/getcontext-android.S",
286                "src/mips/Gis_signal_frame.c",
287                "src/mips/Lis_signal_frame.c",
288            ],
289        },
290        x86: {
291            srcs: [
292                "src/x86/is_fpreg.c",
293                "src/x86/regname.c",
294                "src/x86/Gcreate_addr_space.c",
295                "src/x86/Gget_proc_info.c",
296                "src/x86/Gget_save_loc.c",
297                "src/x86/Gglobal.c",
298                "src/x86/Ginit.c",
299                "src/x86/Ginit_local.c",
300                "src/x86/Ginit_remote.c",
301                "src/x86/Gregs.c",
302                "src/x86/Gresume.c",
303                "src/x86/Gstep.c",
304                "src/x86/Lcreate_addr_space.c",
305                "src/x86/Lget_proc_info.c",
306                "src/x86/Lget_save_loc.c",
307                "src/x86/Lglobal.c",
308                "src/x86/Linit.c",
309                "src/x86/Linit_local.c",
310                "src/x86/Linit_remote.c",
311                "src/x86/Lregs.c",
312                "src/x86/Lresume.c",
313                "src/x86/Lstep.c",
314
315                "src/x86/getcontext-linux.S",
316                "src/x86/Gos-linux.c",
317                "src/x86/Los-linux.c",
318            ],
319        },
320        x86_64: {
321            srcs: [
322                "src/x86_64/is_fpreg.c",
323                "src/x86_64/regname.c",
324                "src/x86_64/Gcreate_addr_space.c",
325                "src/x86_64/Gget_proc_info.c",
326                "src/x86_64/Gget_save_loc.c",
327                "src/x86_64/Gglobal.c",
328                "src/x86_64/Ginit.c",
329                "src/x86_64/Ginit_local.c",
330                "src/x86_64/Ginit_remote.c",
331                "src/x86_64/Gregs.c",
332                "src/x86_64/Gresume.c",
333                "src/x86_64/Gstep.c",
334                "src/x86_64/Lcreate_addr_space.c",
335                "src/x86_64/Lget_proc_info.c",
336                "src/x86_64/Lget_save_loc.c",
337                "src/x86_64/Lglobal.c",
338                "src/x86_64/Linit.c",
339                "src/x86_64/Linit_local.c",
340                "src/x86_64/Linit_remote.c",
341                "src/x86_64/Lregs.c",
342                "src/x86_64/Lresume.c",
343                "src/x86_64/Lstep.c",
344
345                "src/x86_64/getcontext.S",
346                "src/x86_64/Gstash_frame.c",
347                "src/x86_64/Gtrace.c",
348                "src/x86_64/Gos-linux.c",
349                "src/x86_64/Lstash_frame.c",
350                "src/x86_64/Ltrace.c",
351                "src/x86_64/Los-linux.c",
352                "src/x86_64/setcontext.S",
353            ],
354        },
355    } + libunwind_common_arch_includes,
356
357    multilib: {
358        lib32: {
359            srcs: ["src/elf32.c"],
360        },
361        lib64: {
362            srcs: ["src/elf64.c"],
363        },
364    },
365
366    target: {
367        android: {
368            shared_libs: ["libdl"],
369            cflags: libunwind_common_cflags_target,
370        },
371        host: {
372            ldflags: ["-nostdlib"],
373            host_ldlibs: [
374                "-lc",
375                "-lpthread",
376            ],
377        },
378        darwin: {
379            enabled: false,
380        },
381    },
382
383    export_include_dirs: ["include"],
384    stl: "none",
385
386    shared_libs: ["liblzma"],
387
388    /*debug: {
389    shared_libs: ["liblog"],
390    cflags: libunwind_common_debug_cflags,
391    },*/
392}
393
394//-----------------------------------------------------------------------
395// libunwindbacktrace static library
396//-----------------------------------------------------------------------
397cc_library_static {
398    name: "libunwindbacktrace",
399    host_supported: true,
400    srcs: [
401        "src/unwind/BacktraceWrapper.c",
402        "src/unwind/DeleteException.c",
403        "src/unwind/FindEnclosingFunction.c",
404        "src/unwind/ForcedUnwind.c",
405        "src/unwind/GetBSP.c",
406        "src/unwind/GetCFA.c",
407        "src/unwind/GetDataRelBase.c",
408        "src/unwind/GetGR.c",
409        "src/unwind/GetIP.c",
410        "src/unwind/GetIPInfo.c",
411        "src/unwind/GetLanguageSpecificData.c",
412        "src/unwind/GetRegionStart.c",
413        "src/unwind/GetTextRelBase.c",
414        "src/unwind/RaiseException.c",
415        "src/unwind/Resume.c",
416        "src/unwind/Resume_or_Rethrow.c",
417        "src/unwind/SetGR.c",
418        "src/unwind/SetIP.c",
419    ],
420
421    cflags: libunwind_common_cflags + [
422        "-Wno-old-style-declaration",
423        "-fvisibility=hidden",
424    ],
425
426    clang_cflags: libunwind_common_clang_cflags,
427    local_include_dirs: libunwind_common_c_local_includes,
428
429    arch: libunwind_common_arch_includes,
430
431    target: {
432        android: {
433            cflags: libunwind_common_cflags_target,
434        },
435        darwin: {
436            enabled: false,
437        },
438    },
439
440    whole_static_libs: ["libunwind"],
441    stl: "none",
442}
443
444/*
445//-----------------------------------------------------------------------
446// libunwind testing
447//-----------------------------------------------------------------------
448libunwind-unit-tests_cflags = [
449"-fno-builtin",
450"-O0",
451"-g",
452]
453
454libunwind-unit-tests_c_local_includes = ["include"]
455
456libunwind-unit-tests_src_files = ["android/tests/local_test.cpp"]
457
458libunwind-unit-tests_shared_libraries = ["libunwind"]
459
460libunwind-unit-tests_multilib = ["both"]
461module = ["libunwind-unit-tests"]
462module_tag = ["optional"]
463build_type = ["target"]
464build_target = ["NATIVE_TEST"]
465// ANDROIDMK TRANSLATION ERROR: unsupported include
466// include $(LOCAL_PATH)/Android.build.mk
467build_type = ["host"]
468// ANDROIDMK TRANSLATION ERROR: unsupported include
469// include $(LOCAL_PATH)/Android.build.mk
470// Run the unit tests built for x86 or x86_64.
471// ANDROIDMK TRANSLATION ERROR: unsupported conditional
472// ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
473// ANDROIDMK TRANSLATION ERROR: unsupported conditional
474// ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86))
475LINKER = ["linker64"]
476TEST_SUFFIX = ["64"]
477// ANDROIDMK TRANSLATION ERROR: else from unsupported contitional
478// else
479LINKER = ["linker"]
480TEST_SUFFIX = ["32"]
481// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional
482// endif
483
484// ANDROIDMK TRANSLATION ERROR: endif from unsupported contitional
485// endif
486*/
487