1# honggfuzz - Android makefile 2# ----------------------------------------- 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 16LOCAL_PATH := $(abspath $(call my-dir)/..) 17 18# Enable Linux ptrace() instead of POSIX signal interface by default 19ANDROID_WITH_PTRACE ?= true 20 21# Make sure compiler toolchain is compatible / supported 22ifneq (,$(findstring clang,$(NDK_TOOLCHAIN))) 23 $(error Clang toolchains are not supported yet. Clang uses __aeabi_read_tp to \ 24 implement thread_local, which isn't supported by bionic [$(NDK_TOOLCHAIN)]) 25endif 26 27ifeq ($(ANDROID_WITH_PTRACE),true) 28 ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi armeabi-v7a)) 29 ARCH_ABI := arm 30 UNW_ARCH := arm 31 else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86)) 32 ARCH_ABI := x86 33 UNW_ARCH := x86 34 else ifeq ($(APP_ABI),$(filter $(APP_ABI),arm64-v8a)) 35 ARCH_ABI := arm64 36 UNW_ARCH := aarch64 37 else ifeq ($(APP_ABI),$(filter $(APP_ABI),x86_64)) 38 ARCH_ABI := x86_64 39 UNW_ARCH := x86_64 40 else 41 $(error Unsuported / Unknown APP_API '$(APP_ABI)') 42 endif 43 44 # Additional libcrypto OpenSSL flags required to mitigate bug (ARM systems with API <= 21) 45 ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi)) 46 OPENSSL_ARMCAP_ABI := "5" 47 else ifeq ($(APP_ABI),$(filter $(APP_ABI),armeabi-v7a)) 48 OPENSSL_ARMCAP_ABI := "7" 49 endif 50 51 # Upstream libunwind compiled from sources with Android NDK toolchain 52 LIBUNWIND_A := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(UNW_ARCH).a 53 ifeq ("$(wildcard $(LIBUNWIND_A))","") 54 $(error libunwind-$(UNW_ARCH). is missing. Please execute \ 55 'third_party/android/scripts/compile-libunwind.sh third_party/android/libunwind $(ARCH_ABI)') 56 endif 57 58 include $(CLEAR_VARS) 59 LOCAL_MODULE := libunwind 60 LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind.a 61 LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include 62 include $(PREBUILT_STATIC_LIBRARY) 63 64 include $(CLEAR_VARS) 65 LOCAL_MODULE := libunwind-arch 66 LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-$(UNW_ARCH).a 67 LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include 68 include $(PREBUILT_STATIC_LIBRARY) 69 70 include $(CLEAR_VARS) 71 LOCAL_MODULE := libunwind-ptrace 72 LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-ptrace.a 73 LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include 74 include $(PREBUILT_STATIC_LIBRARY) 75 76 LOCAL_MODULE := libunwind-dwarf-generic 77 LOCAL_SRC_FILES := third_party/android/libunwind/$(ARCH_ABI)/libunwind-dwarf-generic.a 78 LOCAL_EXPORT_C_INCLUDES := third_party/android/libunwind/include 79 include $(PREBUILT_STATIC_LIBRARY) 80 81 # Upstream capstone compiled from sources with Android NDK toolchain 82 LIBCAPSTONE_A := third_party/android/capstone/$(ARCH_ABI)/libcapstone.a 83 ifeq ("$(wildcard $(LIBCAPSTONE_A))","") 84 $(error libunwind-$(UNW_ARCH). is missing. Please execute \ 85 'third_party/android/scripts/compile-capstone.sh third_party/android/capstone $(ARCH_ABI)') 86 endif 87 include $(CLEAR_VARS) 88 LOCAL_MODULE := libcapstone 89 LOCAL_SRC_FILES := $(LIBCAPSTONE_A) 90 LOCAL_EXPORT_C_INCLUDES := third_party/android/capstone/include 91 include $(PREBUILT_STATIC_LIBRARY) 92endif 93 94# Main honggfuzz module 95include $(CLEAR_VARS) 96 97LOCAL_MODULE := honggfuzz 98LOCAL_SRC_FILES := honggfuzz.c cmdline.c display.c log.c files.c fuzz.c report.c mangle.c util.c sancov.c 99LOCAL_CFLAGS := -std=c11 -I. \ 100 -D_GNU_SOURCE \ 101 -Wall -Wextra -Wno-initializer-overrides -Wno-override-init \ 102 -Wno-unknown-warning-option -Werror -funroll-loops -O2 \ 103 -Wframe-larger-than=51200 104LOCAL_LDFLAGS := -lm 105 106ifeq ($(ANDROID_WITH_PTRACE),true) 107 LOCAL_C_INCLUDES := third_party/android/libunwind/include third_party/android/capstone/include 108 LOCAL_STATIC_LIBRARIES := libunwind-arch libunwind libunwind-ptrace libunwind-dwarf-generic libcapstone 109 LOCAL_CFLAGS += -D__HF_USE_CAPSTONE__ 110 ARCH_SRCS := linux/arch.c linux/ptrace_utils.c linux/perf.c linux/unwind.c linux/pt.c 111 ARCH := LINUX 112 ifeq ($(ARCH_ABI),arm) 113 LOCAL_CFLAGS += -DOPENSSL_ARMCAP_ABI='$(OPENSSL_ARMCAP_ABI)' 114 endif 115 $(info $(shell (echo "********************************************************************"))) 116 $(info $(shell (echo "Android PTRACE build: Will prevent debuggerd from processing crashes"))) 117 $(info $(shell (echo "********************************************************************"))) 118else 119 ARCH_SRCS := posix/arch.c 120 ARCH := POSIX 121 $(info $(shell (echo "********************************************************************"))) 122 $(info $(shell (echo "Android POSIX build: Will allow debuggerd to also process crashes"))) 123 $(info $(shell (echo "********************************************************************"))) 124endif 125 126LOCAL_SRC_FILES += $(ARCH_SRCS) 127LOCAL_CFLAGS += -D_HF_ARCH_${ARCH} 128 129include $(BUILD_EXECUTABLE) 130