xref: /aosp_15_r20/system/unwinding/libunwindstack/Android.bp (revision eb293b8f56ee8303637c5595cfcdeef8039e85c6)
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_team: "trendy_team_native_tools_libraries",
19    default_applicable_licenses: [
20        "Android-Apache-2.0",
21        "system_unwinding_libunwindstack_license",
22    ],
23}
24
25license {
26    name: "system_unwinding_libunwindstack_license",
27    visibility: [":__subpackages__"],
28    license_kinds: [
29        "SPDX-license-identifier-BSD",
30    ],
31    license_text: ["LICENSE_BSD"],
32}
33
34cc_defaults {
35    name: "libunwindstack_flags",
36
37    host_supported: true,
38
39    cflags: [
40        "-Wall",
41        "-Werror",
42        "-Wextra",
43        "-Wno-deprecated-volatile",
44        // Disable this warning, it doesn't provide any useful data.
45        "-Wno-reorder-init-list",
46    ],
47
48    target: {
49        darwin: {
50            enabled: false,
51        },
52        linux_bionic: {
53            enabled: true,
54        },
55    },
56}
57
58libunwindstack_common_src_files = [
59    "AndroidUnwinder.cpp",
60    "ArmExidx.cpp",
61    "Demangle.cpp",
62    "DexFiles.cpp",
63    "DwarfCfa.cpp",
64    "DwarfEhFrameWithHdr.cpp",
65    "DwarfMemory.cpp",
66    "DwarfOp.cpp",
67    "DwarfSection.cpp",
68    "Elf.cpp",
69    "ElfInterface.cpp",
70    "ElfInterfaceArm.cpp",
71    "Global.cpp",
72    "JitDebug.cpp",
73    "MapInfo.cpp",
74    "Maps.cpp",
75    "Memory.cpp",
76    "MemoryMte.cpp",
77    "MemoryXz.cpp",
78    "Regs.cpp",
79    "RegsArm.cpp",
80    "RegsArm64.cpp",
81    "RegsX86.cpp",
82    "RegsX86_64.cpp",
83    "RegsRiscv64.cpp",
84    "Symbols.cpp",
85    "ThreadEntry.cpp",
86    "ThreadUnwinder.cpp",
87    "Unwinder.cpp",
88]
89
90cc_defaults {
91    name: "libunwindstack_defaults",
92    defaults: ["libunwindstack_flags"],
93    export_include_dirs: ["include"],
94
95    srcs: libunwindstack_common_src_files,
96
97    cflags: [
98        "-Wexit-time-destructors",
99        "-fno-c++-static-destructors",
100    ],
101
102    target: {
103        host: {
104            // Always disable optimizations for host to make it easier to debug.
105            cflags: [
106                "-O0",
107                "-g",
108            ],
109        },
110        bionic: {
111            header_libs: ["bionic_libc_platform_headers"],
112            whole_static_libs: ["libasync_safe"],
113        },
114    },
115
116    arch: {
117        x86: {
118            srcs: ["AsmGetRegsX86.S"],
119        },
120        x86_64: {
121            srcs: ["AsmGetRegsX86_64.S"],
122        },
123    },
124
125    static_libs: [
126        "libprocinfo",
127    ],
128
129    whole_static_libs: [
130        "librustc_demangle_static",
131        "libzstd",
132    ],
133
134    shared_libs: [
135        "libbase",
136        "liblog",
137        "liblzma",
138        "libz",
139    ],
140}
141
142cc_library {
143    name: "libunwindstack",
144    ramdisk_available: true,
145    vendor_available: true,
146    product_available: true,
147    recovery_available: true,
148    vendor_ramdisk_available: true,
149    // TODO(b/153609531): remove when no longer needed.
150    native_bridge_supported: true,
151    double_loadable: true,
152    defaults: ["libunwindstack_defaults"],
153    srcs: [
154        "DexFile.cpp",
155        "LogAndroid.cpp",
156    ],
157    cflags: ["-DDEXFILE_SUPPORT"],
158    static_libs: ["libdexfile_support"],
159
160    target: {
161        vendor: {
162            cflags: ["-UDEXFILE_SUPPORT"],
163            exclude_srcs: ["DexFile.cpp"],
164            exclude_static_libs: ["libdexfile_support"],
165            exclude_runtime_libs: ["libdexfile"],
166        },
167        product: {
168            cflags: ["-UDEXFILE_SUPPORT"],
169            exclude_srcs: ["DexFile.cpp"],
170            exclude_static_libs: ["libdexfile_support"],
171            exclude_runtime_libs: ["libdexfile"],
172        },
173        recovery: {
174            cflags: ["-UDEXFILE_SUPPORT"],
175            exclude_srcs: ["DexFile.cpp"],
176            exclude_static_libs: ["libdexfile_support"],
177            exclude_runtime_libs: ["libdexfile"],
178        },
179        vendor_ramdisk: {
180            cflags: ["-UDEXFILE_SUPPORT"],
181            exclude_srcs: ["DexFile.cpp"],
182            exclude_static_libs: ["libdexfile_support"],
183            exclude_runtime_libs: ["libdexfile"],
184        },
185        ramdisk: {
186            cflags: ["-UDEXFILE_SUPPORT"],
187            exclude_srcs: ["DexFile.cpp"],
188            exclude_static_libs: ["libdexfile_support"],
189            exclude_runtime_libs: ["libdexfile"],
190        },
191        native_bridge: {
192            cflags: ["-UDEXFILE_SUPPORT"],
193            exclude_srcs: ["DexFile.cpp"],
194            exclude_static_libs: ["libdexfile_support"],
195            exclude_runtime_libs: ["libdexfile"],
196        },
197        android: {
198            runtime_libs: ["libdexfile"], // libdexfile_support dependency
199        },
200        linux: {
201            runtime_libs: ["libdexfile"], // libdexfile_support dependency
202        },
203        musl: {
204            cflags: ["-DNT_RISCV_VECTOR=0x901"],
205        },
206    },
207
208    arch: {
209        arm: {
210            version_script: "exported.map",
211        },
212        arm64: {
213            version_script: "exported.map",
214        },
215        riscv64: {
216            version_script: "exported.map",
217        },
218        x86: {
219            version_script: "exported_x86.map",
220        },
221        x86_64: {
222            version_script: "exported_x86.map",
223        },
224    },
225
226    apex_available: [
227        "//apex_available:platform",
228        "com.android.art",
229        "com.android.art.debug",
230        "com.android.runtime",
231    ],
232    min_sdk_version: "29",
233}
234
235// Make sure that the code can be compiled without Android Logging.
236cc_library_static {
237    name: "libunwindstack_stdout_log",
238    defaults: ["libunwindstack_defaults"],
239    srcs: [
240        "LogStdout.cpp",
241    ],
242    target: {
243        android: {
244            srcs: [
245                "AndroidLogStdout.cpp",
246                "DexFile.cpp",
247            ],
248            cflags: ["-DDEXFILE_SUPPORT"],
249            whole_static_libs: ["libdexfile_support"],
250        },
251    },
252    whole_static_libs: [
253        "liblzma",
254        "libz",
255    ],
256}
257
258// Static library without DEX support to avoid dependencies on the ART APEX.
259cc_library_static {
260    name: "libunwindstack_no_dex",
261    ramdisk_available: true,
262    recovery_available: true,
263    vendor_ramdisk_available: true,
264    defaults: ["libunwindstack_defaults"],
265    srcs: ["LogAndroid.cpp"],
266
267    visibility: [
268        "//external/gwp_asan",
269        "//system/core/debuggerd",
270        "//system/core/init",
271        "//system/core/libutils",
272        "//system/unwinding/libbacktrace",
273    ],
274    apex_available: [
275        "//apex_available:platform",
276        "com.android.runtime",
277    ],
278}
279
280//-------------------------------------------------------------------------
281// Utils
282//-------------------------------------------------------------------------
283cc_library {
284    name: "libunwindstack_utils",
285    defaults: ["libunwindstack_flags"],
286    export_include_dirs: ["utils"],
287    shared_libs: [
288        "libbase",
289        "libunwindstack",
290    ],
291    whole_static_libs: [
292        "libprocinfo",
293        "libz",
294    ],
295    srcs: [
296        "utils/MemoryFake.cpp",
297        "utils/OfflineUnwindUtils.cpp",
298        "utils/PidUtils.cpp",
299        "utils/ProcessTracer.cpp",
300    ],
301}
302
303//-------------------------------------------------------------------------
304// Unit Tests
305//-------------------------------------------------------------------------
306cc_library_shared {
307    name: "libunwindstack_local",
308    defaults: ["libunwindstack_flags"],
309    srcs: ["tests/TestLocal.cpp"],
310
311    cflags: [
312        "-O0",
313        "-g",
314    ],
315
316    shared_libs: [
317        "libunwindstack",
318    ],
319}
320
321cc_defaults {
322    name: "libunwindstack_testlib_flags",
323    defaults: ["libunwindstack_flags"],
324
325    srcs: [
326        "tests/AndroidUnwinderTest.cpp",
327        "tests/ArmExidxDecodeTest.cpp",
328        "tests/ArmExidxExtractTest.cpp",
329        "tests/DemangleTest.cpp",
330        "tests/DexFileTest.cpp",
331        "tests/DexFilesTest.cpp",
332        "tests/DwarfCfaLogTest.cpp",
333        "tests/DwarfCfaTest.cpp",
334        "tests/DwarfDebugFrameTest.cpp",
335        "tests/DwarfEhFrameTest.cpp",
336        "tests/DwarfEhFrameWithHdrTest.cpp",
337        "tests/DwarfMemoryTest.cpp",
338        "tests/DwarfOpLogTest.cpp",
339        "tests/DwarfOpTest.cpp",
340        "tests/DwarfSectionTest.cpp",
341        "tests/DwarfSectionImplTest.cpp",
342        "tests/ElfCacheTest.cpp",
343        "tests/ElfFake.cpp",
344        "tests/ElfInterfaceArmTest.cpp",
345        "tests/ElfInterfaceTest.cpp",
346        "tests/ElfTest.cpp",
347        "tests/ElfTestUtils.cpp",
348        "tests/GlobalDebugImplTest.cpp",
349        "tests/GlobalTest.cpp",
350        "tests/IsolatedSettings.cpp",
351        "tests/JitDebugTest.cpp",
352        "tests/LocalUpdatableMapsTest.cpp",
353        "tests/LogFake.cpp",
354        "tests/MapInfoCreateMemoryTest.cpp",
355        "tests/MapInfoGetBuildIDTest.cpp",
356        "tests/MapInfoGetElfTest.cpp",
357        "tests/MapInfoGetLoadBiasTest.cpp",
358        "tests/MapInfoTest.cpp",
359        "tests/MapsTest.cpp",
360        "tests/MemoryBufferTest.cpp",
361        "tests/MemoryCacheTest.cpp",
362        "tests/MemoryFileTest.cpp",
363        "tests/MemoryLocalTest.cpp",
364        "tests/MemoryLocalUnsafeTest.cpp",
365        "tests/MemoryOfflineBufferTest.cpp",
366        "tests/MemoryOfflineTest.cpp",
367        "tests/MemoryRangeTest.cpp",
368        "tests/MemoryRangesTest.cpp",
369        "tests/MemoryRemoteTest.cpp",
370        "tests/MemoryTest.cpp",
371        "tests/MemoryThreadCacheTest.cpp",
372        "tests/MemoryMteTest.cpp",
373        "tests/MemoryXzTest.cpp",
374        "tests/RegsInfoTest.cpp",
375        "tests/RegsIterateTest.cpp",
376        "tests/RegsRemoteTest.cpp",
377        "tests/RegsStepIfSignalHandlerTest.cpp",
378        "tests/RegsTest.cpp",
379        "tests/SymbolsTest.cpp",
380        "tests/TestUtils.cpp",
381        "tests/UnwindOfflineTest.cpp",
382        "tests/UnwindTest.cpp",
383        "tests/UnwinderTest.cpp",
384        "tests/VerifyBionicTerminationTest.cpp",
385        "utils/tests/ProcessTracerTest.cpp",
386    ],
387
388    cflags: [
389        "-O0",
390        "-g",
391    ],
392
393    shared_libs: [
394        "libbase",
395        "liblog",
396        "liblzma",
397        "libunwindstack",
398    ],
399
400    static_libs: [
401        "libdexfile_support",
402        "libgmock",
403        "libunwindstack_utils",
404    ],
405
406    test_suites: ["device-tests"],
407    data: [
408        "tests/files/boot_arm.oat.gnu_debugdata",
409        "tests/files/boot_arm.oat.gnu_debugdata.xz",
410        "tests/files/boot_arm.oat.gnu_debugdata.xz.non-power",
411        "tests/files/boot_arm.oat.gnu_debugdata.xz.odd-sizes",
412        "tests/files/boot_arm.oat.gnu_debugdata.xz.one-block",
413        "tests/files/elf32.xz",
414        "tests/files/elf64.xz",
415        "tests/files/libs/*",
416        "offline_files/common/*",
417        "offline_files/apk_rorx_arm64/*",
418        "offline_files/apk_rorx_unreadable_arm64/*",
419        "offline_files/apk_rx_arm64/*",
420        "offline_files/apk_rx_unreadable_arm64/*",
421        "offline_files/apk_soname_at_end_arm64/*",
422        "offline_files/art_quick_osr_stub_arm/*",
423        "offline_files/bad_eh_frame_hdr_arm64/*",
424        "offline_files/debug_frame_first_x86/*",
425        "offline_files/debug_frame_load_bias_arm/*",
426        "offline_files/eh_frame_bias_x86/*",
427        "offline_files/eh_frame_hdr_begin_x86_64/*",
428        "offline_files/empty_arm64/*",
429        "offline_files/invalid_elf_offset_arm/*",
430        "offline_files/jit_debug_arm/*",
431        "offline_files/jit_map_arm/*",
432        "offline_files/gnu_debugdata_arm/*",
433        "offline_files/load_bias_different_section_bias_arm64/*",
434        "offline_files/load_bias_ro_rx_x86_64/*",
435        "offline_files/offset_arm/*",
436        "offline_files/pauth_pc_arm64/*",
437        "offline_files/shared_lib_in_apk_arm64/*",
438        "offline_files/shared_lib_in_apk_memory_only_arm64/*",
439        "offline_files/shared_lib_in_apk_single_map_arm64/*",
440        "offline_files/signal_load_bias_arm/*",
441        "offline_files/signal_fde_x86/*",
442        "offline_files/signal_fde_x86_64/*",
443        "offline_files/straddle_arm/*",
444        "offline_files/jit_debug_x86/*",
445        "offline_files/straddle_arm64/*",
446        "offline_files/bluetooth_arm64/pc_1/*",
447        "offline_files/bluetooth_arm64/pc_2/*",
448        "offline_files/bluetooth_arm64/pc_3/*",
449        "offline_files/bluetooth_arm64/pc_4/*",
450        "offline_files/photos_reset_arm64/*",
451        "offline_files/youtube_compiled_arm64/*",
452        "offline_files/yt_music_arm64/*",
453        "offline_files/maps_compiled_arm64/28613_main-thread/*",
454        "offline_files/maps_compiled_arm64/28644/*",
455        "offline_files/maps_compiled_arm64/28648/*",
456        "offline_files/maps_compiled_arm64/28656_oat_odex_jar/*",
457        "offline_files/maps_compiled_arm64/28667/*",
458        "offline_files/vlenb_riscv64/*",
459        "offline_files/zlib_compress_arm/*",
460        "offline_files/zstd_compress_arm/*",
461    ],
462
463    target: {
464        android: {
465            header_libs: ["bionic_libc_platform_headers"],
466        },
467        linux_bionic: {
468            header_libs: ["bionic_libc_platform_headers"],
469        },
470    },
471}
472
473cc_test {
474    name: "libunwindstack_unit_test",
475    defaults: ["libunwindstack_testlib_flags"],
476    isolated: true,
477    data: [
478        ":libunwindstack_local",
479    ],
480}
481
482//-------------------------------------------------------------------------
483// Fuzzers
484//-------------------------------------------------------------------------
485cc_defaults {
486    name: "libunwindstack_fuzz_defaults",
487    host_supported: true,
488    defaults: ["libunwindstack_flags"],
489    cflags: [
490        "-Wexit-time-destructors",
491        "-fno-c++-static-destructors",
492        "-g",
493    ],
494    shared_libs: [
495        "libbase",
496        "liblog",
497        "liblzma",
498        "libunwindstack",
499    ],
500    static_libs: [
501        "libdexfile_support",
502        "libunwindstack_utils",
503    ],
504}
505
506cc_fuzz {
507    name: "libunwindstack_fuzz_unwinder",
508    defaults: ["libunwindstack_fuzz_defaults"],
509    srcs: [
510        "tests/ElfFake.cpp",
511        "tests/fuzz/UnwinderComponentCreator.cpp",
512        "tests/fuzz/UnwinderFuzz.cpp",
513    ],
514}
515
516//-------------------------------------------------------------------------
517// Tools
518//-------------------------------------------------------------------------
519cc_defaults {
520    name: "libunwindstack_tools",
521    defaults: ["libunwindstack_flags"],
522
523    shared_libs: [
524        "libbase",
525        "liblzma",
526    ],
527    static_libs: [
528        "libunwindstack_stdout_log",
529    ],
530    target: {
531        // Always disable optimizations for host to make it easier to debug.
532        host: {
533            cflags: [
534                "-O0",
535                "-g",
536            ],
537        },
538    },
539}
540
541cc_binary {
542    name: "unwind",
543    defaults: ["libunwindstack_tools"],
544
545    srcs: [
546        "tools/unwind.cpp",
547    ],
548}
549
550cc_binary {
551    name: "unwind_info",
552    defaults: ["libunwindstack_tools"],
553
554    srcs: [
555        "tools/unwind_info.cpp",
556    ],
557}
558
559cc_binary {
560    name: "unwind_symbols",
561    defaults: ["libunwindstack_tools"],
562
563    srcs: [
564        "tools/unwind_symbols.cpp",
565    ],
566}
567
568cc_binary {
569    name: "unwind_for_offline",
570    defaults: ["libunwindstack_tools"],
571    static_libs: [
572        "libunwindstack_utils",
573    ],
574
575    srcs: [
576        "tools/unwind_for_offline.cpp",
577    ],
578}
579
580cc_binary {
581    name: "unwind_reg_info",
582    defaults: ["libunwindstack_tools"],
583
584    srcs: [
585        "tools/unwind_reg_info.cpp",
586    ],
587}
588
589//-------------------------------------------------------------------------
590// Benchmarks
591//-------------------------------------------------------------------------
592cc_benchmark {
593    name: "unwind_benchmarks",
594    host_supported: true,
595    defaults: ["libunwindstack_flags"],
596
597    // Disable optimizations so that all of the calls are not optimized away.
598    cflags: [
599        "-O0",
600    ],
601
602    srcs: [
603        "benchmarks/ElfBenchmark.cpp",
604        "benchmarks/MapsBenchmark.cpp",
605        "benchmarks/SymbolBenchmark.cpp",
606        "benchmarks/Utils.cpp",
607        "benchmarks/local_unwind_benchmarks.cpp",
608        "benchmarks/main.cpp",
609        "benchmarks/remote_unwind_benchmarks.cpp",
610        "benchmarks/thread_unwind_benchmarks.cpp",
611        "benchmarks/OfflineUnwindBenchmarks.cpp",
612        "benchmarks/EvalBenchmark.cpp",
613    ],
614
615    data: [
616        "benchmarks/files/*",
617        "offline_files/common/*",
618        "offline_files/jit_debug_arm/*",
619        "offline_files/straddle_arm64/*",
620        "offline_files/bluetooth_arm64/pc_1/*",
621        "offline_files/bluetooth_arm64/pc_2/*",
622        "offline_files/bluetooth_arm64/pc_3/*",
623        "offline_files/bluetooth_arm64/pc_4/*",
624        "offline_files/photos_reset_arm64/*",
625        "offline_files/youtube_compiled_arm64/*",
626        "offline_files/yt_music_arm64/*",
627        "offline_files/maps_compiled_arm64/28613_main-thread/*",
628        "offline_files/maps_compiled_arm64/28644/*",
629        "offline_files/maps_compiled_arm64/28648/*",
630        "offline_files/maps_compiled_arm64/28656_oat_odex_jar/*",
631        "offline_files/maps_compiled_arm64/28667/*",
632    ],
633
634    shared_libs: [
635        "libbase",
636        "libunwindstack",
637    ],
638
639    static_libs: [
640        "libprocinfo",
641        "libunwindstack_utils",
642    ],
643
644    target: {
645        android: {
646            static_libs: [
647                "libmeminfo",
648            ],
649        },
650    },
651}
652
653// Generates the elf data for use in the tests for .gnu_debugdata frames.
654// Once these files are generated, use the xz command to compress the data.
655cc_binary_host {
656    name: "gen_gnudebugdata",
657    defaults: ["libunwindstack_flags"],
658
659    srcs: [
660        "tests/GenGnuDebugdata.cpp",
661    ],
662}
663