1//
2// Copyright (C) 2017 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
17package {
18    default_applicable_licenses: [
19        "Android-Apache-2.0",
20        "system_unwinding_libunwindstack_license",
21    ],
22}
23
24license {
25    name: "system_unwinding_libunwindstack_license",
26    visibility: [":__subpackages__"],
27    license_kinds: [
28        "SPDX-license-identifier-BSD",
29    ],
30    license_text: ["LICENSE_BSD"],
31}
32
33cc_defaults {
34    name: "libunwindstack_flags",
35
36    host_supported: true,
37
38    cflags: [
39        "-Wall",
40        "-Werror",
41        "-Wextra",
42    ],
43
44    target: {
45        darwin: {
46            enabled: false,
47        },
48        linux_bionic: {
49            enabled: true,
50        },
51    },
52}
53
54cc_defaults {
55    name: "libunwindstack_defaults",
56    defaults: ["libunwindstack_flags"],
57    export_include_dirs: ["include"],
58
59    srcs: [
60        "ArmExidx.cpp",
61        "DexFiles.cpp",
62        "DwarfCfa.cpp",
63        "DwarfEhFrameWithHdr.cpp",
64        "DwarfMemory.cpp",
65        "DwarfOp.cpp",
66        "DwarfSection.cpp",
67        "Elf.cpp",
68        "ElfInterface.cpp",
69        "ElfInterfaceArm.cpp",
70        "Global.cpp",
71        "JitDebug.cpp",
72        "Log.cpp",
73        "MapInfo.cpp",
74        "Maps.cpp",
75        "Memory.cpp",
76        "MemoryMte.cpp",
77        "LocalUnwinder.cpp",
78        "Regs.cpp",
79        "RegsArm.cpp",
80        "RegsArm64.cpp",
81        "RegsX86.cpp",
82        "RegsX86_64.cpp",
83        "RegsMips.cpp",
84        "RegsMips64.cpp",
85        "Symbols.cpp",
86        "ThreadEntry.cpp",
87        "ThreadUnwinder.cpp",
88        "Unwinder.cpp",
89    ],
90
91    cflags: [
92        "-Wexit-time-destructors",
93        "-fno-c++-static-destructors",
94    ],
95
96    target: {
97        host: {
98            // Always disable optimizations for host to make it easier to debug.
99            cflags: [
100                "-O0",
101                "-g",
102            ],
103        },
104        bionic: {
105            header_libs: ["bionic_libc_platform_headers"],
106            static_libs: ["libasync_safe"],
107        },
108    },
109
110    arch: {
111        x86: {
112            srcs: ["AsmGetRegsX86.S"],
113        },
114        x86_64: {
115            srcs: ["AsmGetRegsX86_64.S"],
116        },
117    },
118
119    static_libs: [
120        "libprocinfo",
121    ],
122
123    shared_libs: [
124        "libbase",
125        "liblog",
126        "liblzma",
127    ],
128}
129
130cc_library {
131    name: "libunwindstack",
132    vendor_available: true,
133    product_available: true,
134    recovery_available: true,
135    vendor_ramdisk_available: true,
136    // TODO(b/153609531): remove when no longer needed.
137    native_bridge_supported: true,
138    vndk: {
139        enabled: true,
140        support_system_process: true,
141    },
142    defaults: ["libunwindstack_defaults"],
143    srcs: ["DexFile.cpp"],
144    cflags: ["-DDEXFILE_SUPPORT"],
145    static_libs: ["libdexfile_support"],
146    runtime_libs: ["libdexfile"], // libdexfile_support dependency
147
148    target: {
149        vendor: {
150            cflags: ["-UDEXFILE_SUPPORT"],
151            exclude_srcs: ["DexFile.cpp"],
152            exclude_static_libs: ["libdexfile_support"],
153            exclude_runtime_libs: ["libdexfile"],
154        },
155        product: {
156            cflags: ["-UDEXFILE_SUPPORT"],
157            exclude_srcs: ["DexFile.cpp"],
158            exclude_static_libs: ["libdexfile_support"],
159            exclude_runtime_libs: ["libdexfile"],
160        },
161        recovery: {
162            cflags: ["-UDEXFILE_SUPPORT"],
163            exclude_srcs: ["DexFile.cpp"],
164            exclude_static_libs: ["libdexfile_support"],
165            exclude_runtime_libs: ["libdexfile"],
166        },
167        vendor_ramdisk: {
168            cflags: ["-UDEXFILE_SUPPORT"],
169            exclude_srcs: ["DexFile.cpp"],
170            exclude_static_libs: ["libdexfile_support"],
171            exclude_runtime_libs: ["libdexfile"],
172        },
173        native_bridge: {
174            cflags: ["-UDEXFILE_SUPPORT"],
175            exclude_srcs: ["DexFile.cpp"],
176            exclude_static_libs: ["libdexfile_support"],
177            exclude_runtime_libs: ["libdexfile"],
178        },
179    },
180
181    apex_available: [
182        "//apex_available:platform",
183        "com.android.art",
184        "com.android.art.debug",
185    ],
186    min_sdk_version: "29",
187}
188
189// Static library without DEX support to avoid dependencies on the ART APEX.
190cc_library_static {
191    name: "libunwindstack_no_dex",
192    recovery_available: true,
193    vendor_ramdisk_available: true,
194    defaults: ["libunwindstack_defaults"],
195
196    visibility: [
197        "//external/gwp_asan",
198        "//system/core/debuggerd",
199        "//system/core/init",
200        "//system/unwinding/libbacktrace",
201    ],
202    apex_available: [
203        "//apex_available:platform",
204        "com.android.runtime",
205    ],
206}
207
208//-------------------------------------------------------------------------
209// Unit Tests
210//-------------------------------------------------------------------------
211cc_library_shared {
212    name: "libunwindstack_local",
213    defaults: ["libunwindstack_flags"],
214    srcs: ["tests/TestLocal.cpp"],
215
216    cflags: [
217        "-O0",
218        "-g",
219    ],
220
221    shared_libs: [
222        "libunwindstack",
223    ],
224}
225
226cc_defaults {
227    name: "libunwindstack_testlib_flags",
228    defaults: ["libunwindstack_flags"],
229
230    srcs: [
231        "tests/ArmExidxDecodeTest.cpp",
232        "tests/ArmExidxExtractTest.cpp",
233        "tests/DexFileTest.cpp",
234        "tests/DexFilesTest.cpp",
235        "tests/DwarfCfaLogTest.cpp",
236        "tests/DwarfCfaTest.cpp",
237        "tests/DwarfDebugFrameTest.cpp",
238        "tests/DwarfEhFrameTest.cpp",
239        "tests/DwarfEhFrameWithHdrTest.cpp",
240        "tests/DwarfMemoryTest.cpp",
241        "tests/DwarfOpLogTest.cpp",
242        "tests/DwarfOpTest.cpp",
243        "tests/DwarfSectionTest.cpp",
244        "tests/DwarfSectionImplTest.cpp",
245        "tests/ElfCacheTest.cpp",
246        "tests/ElfFake.cpp",
247        "tests/ElfInterfaceArmTest.cpp",
248        "tests/ElfInterfaceTest.cpp",
249        "tests/ElfTest.cpp",
250        "tests/ElfTestUtils.cpp",
251        "tests/GlobalDebugImplTest.cpp",
252        "tests/IsolatedSettings.cpp",
253        "tests/JitDebugTest.cpp",
254        "tests/LocalUnwinderTest.cpp",
255        "tests/LocalUpdatableMapsTest.cpp",
256        "tests/LogFake.cpp",
257        "tests/MapInfoCreateMemoryTest.cpp",
258        "tests/MapInfoGetBuildIDTest.cpp",
259        "tests/MapInfoGetElfTest.cpp",
260        "tests/MapInfoGetLoadBiasTest.cpp",
261        "tests/MapInfoTest.cpp",
262        "tests/MapsTest.cpp",
263        "tests/MemoryBufferTest.cpp",
264        "tests/MemoryCacheTest.cpp",
265        "tests/MemoryFake.cpp",
266        "tests/MemoryFileTest.cpp",
267        "tests/MemoryLocalTest.cpp",
268        "tests/MemoryOfflineBufferTest.cpp",
269        "tests/MemoryOfflineTest.cpp",
270        "tests/MemoryRangeTest.cpp",
271        "tests/MemoryRangesTest.cpp",
272        "tests/MemoryRemoteTest.cpp",
273        "tests/MemoryTest.cpp",
274        "tests/MemoryThreadCacheTest.cpp",
275        "tests/MemoryMteTest.cpp",
276        "tests/MemoryXzTest.cpp",
277        "tests/RegsInfoTest.cpp",
278        "tests/RegsIterateTest.cpp",
279        "tests/RegsStepIfSignalHandlerTest.cpp",
280        "tests/RegsTest.cpp",
281        "tests/SymbolsTest.cpp",
282        "tests/TestUtils.cpp",
283        "tests/UnwindOfflineTest.cpp",
284        "tests/UnwindTest.cpp",
285        "tests/UnwinderTest.cpp",
286        "tests/VerifyBionicTerminationTest.cpp",
287    ],
288
289    cflags: [
290        "-O0",
291        "-g",
292    ],
293
294    shared_libs: [
295        "libbase",
296        "liblog",
297        "liblzma",
298        "libunwindstack",
299    ],
300
301    static_libs: [
302        "libdexfile_support",
303        "libgmock",
304    ],
305
306    test_suites: ["device-tests"],
307    data: [
308        "tests/files/boot_arm.oat.gnu_debugdata",
309        "tests/files/boot_arm.oat.gnu_debugdata.xz",
310        "tests/files/boot_arm.oat.gnu_debugdata.xz.non-power",
311        "tests/files/boot_arm.oat.gnu_debugdata.xz.odd-sizes",
312        "tests/files/boot_arm.oat.gnu_debugdata.xz.one-block",
313        "tests/files/elf32.xz",
314        "tests/files/elf64.xz",
315        "tests/files/offline/art_quick_osr_stub_arm/*",
316        "tests/files/offline/bad_eh_frame_hdr_arm64/*",
317        "tests/files/offline/debug_frame_first_x86/*",
318        "tests/files/offline/debug_frame_load_bias_arm/*",
319        "tests/files/offline/eh_frame_bias_x86/*",
320        "tests/files/offline/eh_frame_hdr_begin_x86_64/*",
321        "tests/files/offline/empty_arm64/*",
322        "tests/files/offline/invalid_elf_offset_arm/*",
323        "tests/files/offline/jit_debug_arm/*",
324        "tests/files/offline/jit_debug_x86/*",
325        "tests/files/offline/jit_map_arm/*",
326        "tests/files/offline/gnu_debugdata_arm/*",
327        "tests/files/offline/load_bias_different_section_bias_arm64/*",
328        "tests/files/offline/load_bias_ro_rx_x86_64/*",
329        "tests/files/offline/offset_arm/*",
330        "tests/files/offline/pauth_pc_arm64/*",
331        "tests/files/offline/shared_lib_in_apk_arm64/*",
332        "tests/files/offline/shared_lib_in_apk_memory_only_arm64/*",
333        "tests/files/offline/shared_lib_in_apk_single_map_arm64/*",
334        "tests/files/offline/signal_load_bias_arm/*",
335        "tests/files/offline/signal_fde_x86/*",
336        "tests/files/offline/signal_fde_x86_64/*",
337        "tests/files/offline/straddle_arm/*",
338        "tests/files/offline/straddle_arm64/*",
339    ],
340
341    target: {
342        android: {
343            header_libs: ["bionic_libc_platform_headers"],
344        },
345        linux_bionic: {
346            header_libs: ["bionic_libc_platform_headers"],
347        },
348    },
349}
350
351cc_test {
352    name: "libunwindstack_unit_test",
353    defaults: ["libunwindstack_testlib_flags"],
354    isolated: true,
355    data: [
356        ":libunwindstack_local",
357    ],
358}
359
360//-------------------------------------------------------------------------
361// Fuzzers
362//-------------------------------------------------------------------------
363cc_defaults {
364    name: "libunwindstack_fuzz_defaults",
365    host_supported: true,
366    defaults: ["libunwindstack_flags"],
367    cflags: [
368        "-Wexit-time-destructors",
369        "-fno-c++-static-destructors",
370        "-g",
371    ],
372    shared_libs: [
373        "libbase",
374        "liblog",
375        "liblzma",
376        "libunwindstack",
377    ],
378    static_libs: [
379        "libdexfile_support",
380    ],
381}
382
383cc_fuzz {
384    name: "libunwindstack_fuzz_unwinder",
385    defaults: ["libunwindstack_fuzz_defaults"],
386    srcs: [
387        "tests/MemoryFake.cpp",
388        "tests/ElfFake.cpp",
389        "tests/fuzz/UnwinderComponentCreator.cpp",
390        "tests/fuzz/UnwinderFuzz.cpp",
391    ],
392}
393
394//-------------------------------------------------------------------------
395// Tools
396//-------------------------------------------------------------------------
397cc_defaults {
398    name: "libunwindstack_tools",
399    defaults: ["libunwindstack_flags"],
400
401    shared_libs: [
402        "libunwindstack",
403        "libbase",
404        "liblzma",
405    ],
406    target: {
407        // Always disable optimizations for host to make it easier to debug.
408        host: {
409            cflags: [
410                "-O0",
411                "-g",
412            ],
413        },
414    },
415}
416
417cc_binary {
418    name: "unwind",
419    defaults: ["libunwindstack_tools"],
420
421    srcs: [
422        "tools/unwind.cpp",
423    ],
424}
425
426cc_binary {
427    name: "unwind_info",
428    defaults: ["libunwindstack_tools"],
429
430    srcs: [
431        "tools/unwind_info.cpp",
432    ],
433}
434
435cc_binary {
436    name: "unwind_symbols",
437    defaults: ["libunwindstack_tools"],
438
439    srcs: [
440        "tools/unwind_symbols.cpp",
441    ],
442}
443
444cc_binary {
445    name: "unwind_for_offline",
446    defaults: ["libunwindstack_tools"],
447
448    srcs: [
449        "tools/unwind_for_offline.cpp",
450    ],
451}
452
453cc_binary {
454    name: "unwind_reg_info",
455    defaults: ["libunwindstack_tools"],
456
457    srcs: [
458        "tools/unwind_reg_info.cpp",
459    ],
460}
461
462//-------------------------------------------------------------------------
463// Benchmarks
464//-------------------------------------------------------------------------
465cc_benchmark {
466    name: "unwind_benchmarks",
467    host_supported: true,
468    defaults: ["libunwindstack_flags"],
469
470    // Disable optimizations so that all of the calls are not optimized away.
471    cflags: [
472        "-O0",
473    ],
474
475    srcs: [
476        "benchmarks/ElfBenchmark.cpp",
477        "benchmarks/MapsBenchmark.cpp",
478        "benchmarks/SymbolBenchmark.cpp",
479        "benchmarks/Utils.cpp",
480        "benchmarks/local_unwind_benchmarks.cpp",
481        "benchmarks/main.cpp",
482        "benchmarks/remote_unwind_benchmarks.cpp",
483        "benchmarks/thread_unwind_benchmarks.cpp",
484    ],
485
486    data: [
487        "benchmarks/files/*",
488    ],
489
490    shared_libs: [
491        "libbase",
492        "libunwindstack",
493    ],
494
495    target: {
496        android: {
497            static_libs: [
498                "libmeminfo",
499                "libprocinfo",
500            ],
501        },
502    },
503}
504
505// Generates the elf data for use in the tests for .gnu_debugdata frames.
506// Once these files are generated, use the xz command to compress the data.
507cc_binary_host {
508    name: "gen_gnudebugdata",
509    defaults: ["libunwindstack_flags"],
510
511    srcs: [
512        "tests/GenGnuDebugdata.cpp",
513    ],
514}
515