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 17LOCAL_PATH := $(call my-dir) 18 19build_host := false 20ifeq ($(HOST_OS),linux) 21build_host := true 22endif 23 24# Set to true to enable a debug build of the libraries. 25# To control what is logged, set the environment variable UNW_DEBUG_LEVEL=x, 26# where x controls the verbosity (from 1 to 20). 27debug := false 28 29common_cflags := \ 30 -Wno-unused-parameter \ 31 -Werror \ 32 33# gcc 4.8 appears to be overeager declaring that a variable is uninitialized, 34# under certain circumstances. Turn off this warning only for target so that 35# coverage is still present for the host code. When the entire build system 36# is switched to 4.9, then this can be removed. 37common_cflags_target := \ 38 -Wno-maybe-uninitialized \ 39 40ifeq ($(LOCAL_CLANG),true) 41# src/mi/backtrace.c is misdetected as a bogus header guard by clang 3.5 42common_cflags += -Wno-header-guard 43endif 44 45ifneq ($(debug),true) 46common_cflags += \ 47 -DHAVE_CONFIG_H \ 48 -DNDEBUG \ 49 -D_GNU_SOURCE \ 50 51else 52common_cflags += \ 53 -DHAVE_CONFIG_H \ 54 -DDEBUG \ 55 -D_GNU_SOURCE \ 56 -U_FORTIFY_SOURCE \ 57 58endif 59 60common_c_includes := \ 61 $(LOCAL_PATH)/src \ 62 $(LOCAL_PATH)/include \ 63 64# Since mips and mips64 use the same source, only generate includes/srcs 65# for the below set of arches. 66generate_arches := arm arm64 mips x86 x86_64 67# The complete list of arches used by Android.build.mk to set arch 68# variables. 69libunwind_arches := $(generate_arches) mips64 70 71$(foreach arch,$(generate_arches), \ 72 $(eval common_c_includes_$(arch) := $(LOCAL_PATH)/include/tdep-$(arch))) 73 74#----------------------------------------------------------------------- 75# libunwind shared library 76#----------------------------------------------------------------------- 77libunwind_src_files := \ 78 src/mi/init.c \ 79 src/mi/flush_cache.c \ 80 src/mi/mempool.c \ 81 src/mi/strerror.c \ 82 src/mi/backtrace.c \ 83 src/mi/dyn-cancel.c \ 84 src/mi/dyn-info-list.c \ 85 src/mi/dyn-register.c \ 86 src/mi/map.c \ 87 src/mi/Lmap.c \ 88 src/mi/Ldyn-extract.c \ 89 src/mi/Lfind_dynamic_proc_info.c \ 90 src/mi/Lget_proc_info_by_ip.c \ 91 src/mi/Lget_proc_name.c \ 92 src/mi/Lput_dynamic_unwind_info.c \ 93 src/mi/Ldestroy_addr_space.c \ 94 src/mi/Lget_reg.c \ 95 src/mi/Lset_reg.c \ 96 src/mi/Lget_fpreg.c \ 97 src/mi/Lset_fpreg.c \ 98 src/mi/Lset_caching_policy.c \ 99 src/mi/Gdyn-extract.c \ 100 src/mi/Gdyn-remote.c \ 101 src/mi/Gfind_dynamic_proc_info.c \ 102 src/mi/Gget_accessors.c \ 103 src/mi/Gget_proc_info_by_ip.c \ 104 src/mi/Gget_proc_name.c \ 105 src/mi/Gput_dynamic_unwind_info.c \ 106 src/mi/Gdestroy_addr_space.c \ 107 src/mi/Gget_reg.c \ 108 src/mi/Gset_reg.c \ 109 src/mi/Gget_fpreg.c \ 110 src/mi/Gset_fpreg.c \ 111 src/mi/Gset_caching_policy.c \ 112 src/dwarf/Lexpr.c \ 113 src/dwarf/Lfde.c \ 114 src/dwarf/Lparser.c \ 115 src/dwarf/Lpe.c \ 116 src/dwarf/Lstep_dwarf.c \ 117 src/dwarf/Lfind_proc_info-lsb.c \ 118 src/dwarf/Lfind_unwind_table.c \ 119 src/dwarf/Gexpr.c \ 120 src/dwarf/Gfde.c \ 121 src/dwarf/Gfind_proc_info-lsb.c \ 122 src/dwarf/Gfind_unwind_table.c \ 123 src/dwarf/Gparser.c \ 124 src/dwarf/Gpe.c \ 125 src/dwarf/Gstep_dwarf.c \ 126 src/dwarf/global.c \ 127 src/os-common.c \ 128 src/os-linux.c \ 129 src/Los-common.c \ 130 131# Arch specific source files. 132$(foreach arch,$(generate_arches), \ 133 $(eval libunwind_src_files_$(arch) += \ 134 src/$(arch)/is_fpreg.c \ 135 src/$(arch)/regname.c \ 136 src/$(arch)/Gcreate_addr_space.c \ 137 src/$(arch)/Gget_proc_info.c \ 138 src/$(arch)/Gget_save_loc.c \ 139 src/$(arch)/Gglobal.c \ 140 src/$(arch)/Ginit.c \ 141 src/$(arch)/Ginit_local.c \ 142 src/$(arch)/Ginit_remote.c \ 143 src/$(arch)/Gregs.c \ 144 src/$(arch)/Gresume.c \ 145 src/$(arch)/Gstep.c \ 146 src/$(arch)/Lcreate_addr_space.c \ 147 src/$(arch)/Lget_proc_info.c \ 148 src/$(arch)/Lget_save_loc.c \ 149 src/$(arch)/Lglobal.c \ 150 src/$(arch)/Linit.c \ 151 src/$(arch)/Linit_local.c \ 152 src/$(arch)/Linit_remote.c \ 153 src/$(arch)/Lregs.c \ 154 src/$(arch)/Lresume.c \ 155 src/$(arch)/Lstep.c \ 156 )) 157 158libunwind_src_files_arm += \ 159 src/arm/getcontext.S \ 160 src/arm/Gis_signal_frame.c \ 161 src/arm/Gex_tables.c \ 162 src/arm/Lis_signal_frame.c \ 163 src/arm/Lex_tables.c \ 164 165libunwind_src_files_arm64 += \ 166 src/aarch64/Gis_signal_frame.c \ 167 src/aarch64/Lis_signal_frame.c \ 168 169libunwind_src_files_mips += \ 170 src/mips/getcontext-android.S \ 171 src/mips/Gis_signal_frame.c \ 172 src/mips/Lis_signal_frame.c \ 173 174libunwind_src_files_x86 += \ 175 src/x86/getcontext-linux.S \ 176 src/x86/Gos-linux.c \ 177 src/x86/Los-linux.c \ 178 179libunwind_src_files_x86_64 += \ 180 src/x86_64/getcontext.S \ 181 src/x86_64/Gstash_frame.c \ 182 src/x86_64/Gtrace.c \ 183 src/x86_64/Gos-linux.c \ 184 src/x86_64/Lstash_frame.c \ 185 src/x86_64/Ltrace.c \ 186 src/x86_64/Los-linux.c \ 187 src/x86_64/setcontext.S \ 188 189# mips and mips64 use the same sources but define _MIP_SIM differently 190# to change the behavior. 191# mips uses o32 abi (_MIPS_SIM == _ABIO32). 192# mips64 uses n64 abi (_MIPS_SIM == _ABI64). 193common_c_includes_mips64 := $(LOCAL_PATH)/include/tdep-mips 194libunwind_src_files_mips64 := $(libunwind_src_files_mips) 195 196# 64-bit architectures 197libunwind_src_files_arm64 += src/elf64.c 198libunwind_src_files_mips64 += src/elf64.c 199libunwind_src_files_x86_64 += src/elf64.c 200 201# 32-bit architectures 202libunwind_src_files_arm += src/elf32.c 203libunwind_src_files_mips += src/elf32.c 204libunwind_src_files_x86 += src/elf32.c 205 206libunwind_shared_libraries_target := \ 207 libdl \ 208 209libunwind_ldflags_host := \ 210 -nostdlib 211 212libunwind_ldlibs_host := \ 213 -lc \ 214 -lpthread \ 215 216ifeq ($(debug),true) 217libunwind_shared_libraries += \ 218 liblog \ 219 220endif 221 222module := libunwind 223module_tag := optional 224build_type := target 225build_target := SHARED_LIBRARY 226include $(LOCAL_PATH)/Android.build.mk 227build_type := host 228include $(LOCAL_PATH)/Android.build.mk 229build_type := target 230build_target := STATIC_LIBRARY 231include $(LOCAL_PATH)/Android.build.mk 232build_type := host 233include $(LOCAL_PATH)/Android.build.mk 234 235#----------------------------------------------------------------------- 236# libunwind-ptrace shared library 237#----------------------------------------------------------------------- 238libunwind-ptrace_src_files := \ 239 src/ptrace/_UPT_elf.c \ 240 src/ptrace/_UPT_accessors.c \ 241 src/ptrace/_UPT_access_fpreg.c \ 242 src/ptrace/_UPT_access_mem.c \ 243 src/ptrace/_UPT_access_reg.c \ 244 src/ptrace/_UPT_create.c \ 245 src/ptrace/_UPT_destroy.c \ 246 src/ptrace/_UPT_find_proc_info.c \ 247 src/ptrace/_UPT_get_dyn_info_list_addr.c \ 248 src/ptrace/_UPT_put_unwind_info.c \ 249 src/ptrace/_UPT_get_proc_name.c \ 250 src/ptrace/_UPT_reg_offset.c \ 251 src/ptrace/_UPT_resume.c \ 252 253libunwind-ptrace_shared_libraries := \ 254 libunwind \ 255 256libunwind-ptrace_ldflags_host := \ 257 -nostdlib 258 259libunwind-ptrace_ldlibs_host := \ 260 -lc \ 261 -lpthread \ 262 263ifeq ($(debug),true) 264libunwind-ptrace_shared_libraries += \ 265 liblog \ 266 267endif 268 269module := libunwind-ptrace 270module_tag := optional 271build_type := target 272build_target := SHARED_LIBRARY 273include $(LOCAL_PATH)/Android.build.mk 274build_type := host 275include $(LOCAL_PATH)/Android.build.mk 276 277#----------------------------------------------------------------------- 278# libunwindbacktrace static library 279#----------------------------------------------------------------------- 280libunwindbacktrace_src_files += \ 281 src/unwind/BacktraceWrapper.c \ 282 src/unwind/DeleteException.c \ 283 src/unwind/FindEnclosingFunction.c \ 284 src/unwind/ForcedUnwind.c \ 285 src/unwind/GetBSP.c \ 286 src/unwind/GetCFA.c \ 287 src/unwind/GetDataRelBase.c \ 288 src/unwind/GetGR.c \ 289 src/unwind/GetIP.c \ 290 src/unwind/GetIPInfo.c \ 291 src/unwind/GetLanguageSpecificData.c \ 292 src/unwind/GetRegionStart.c \ 293 src/unwind/GetTextRelBase.c \ 294 src/unwind/RaiseException.c \ 295 src/unwind/Resume.c \ 296 src/unwind/Resume_or_Rethrow.c \ 297 src/unwind/SetGR.c \ 298 src/unwind/SetIP.c \ 299 300libunwindbacktrace_cflags += \ 301 -Wno-old-style-declaration \ 302 -fvisibility=hidden \ 303 304module := libunwindbacktrace 305module_tag := optional 306build_type := target 307build_target := STATIC_LIBRARY 308libunwindbacktrace_whole_static_libraries := libunwind 309include $(LOCAL_PATH)/Android.build.mk 310build_type := host 311include $(LOCAL_PATH)/Android.build.mk 312 313#----------------------------------------------------------------------- 314# libunwind testing 315#----------------------------------------------------------------------- 316libunwind-unit-tests_cflags := \ 317 -fno-builtin \ 318 -O0 \ 319 -g \ 320 321libunwind-unit-tests_c_includes := \ 322 $(LOCAL_PATH)/include \ 323 324libunwind-unit-tests_src_files := \ 325 android/tests/local_test.cpp \ 326 327libunwind-unit-tests_shared_libraries := \ 328 libunwind \ 329 330libunwind-unit-tests_multilib := both 331module := libunwind-unit-tests 332module_tag := optional 333build_type := target 334build_target := NATIVE_TEST 335include $(LOCAL_PATH)/Android.build.mk 336build_type := host 337include $(LOCAL_PATH)/Android.build.mk 338 339# Run the unit tests built for x86 or x86_64. 340ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 341ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86)) 342LINKER = linker64 343TEST_SUFFIX = 64 344else 345LINKER = linker 346TEST_SUFFIX = 32 347endif 348 349libunwind-unit-tests-run-on-host: libunwind-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 350 if [ ! -d /system -o ! -d /system/bin ]; then \ 351 echo "Attempting to create /system/bin"; \ 352 sudo mkdir -p -m 0777 /system/bin; \ 353 fi 354 mkdir -p $(TARGET_OUT_DATA)/local/tmp 355 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 356 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 357 ANDROID_DATA=$(TARGET_OUT_DATA) \ 358 ANDROID_ROOT=$(TARGET_OUT) \ 359 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 360 $(TARGET_OUT_DATA_NATIVE_TESTS)/libunwind-unit-tests/libunwind-unit-tests$(TEST_SUFFIX) $(LIBUNWIND_TEST_FLAGS) 361endif 362