forked from google/honggfuzz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
201 lines (178 loc) · 7.43 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# honggfuzz - Makefile
# -----------------------------------------
#
# Author: Robert Swiecki <swiecki@google.com>
#
# Copyright 2010-2015 by Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Common for all architectures
BIN := honggfuzz
COMMON_CFLAGS := -D_GNU_SOURCE -Wall -Werror -Wframe-larger-than=51200
COMMON_LDFLAGS := -lm
COMMON_SRCS := honggfuzz.c cmdline.c display.c log.c files.c fuzz.c report.c mangle.c util.c
INTERCEPTOR_SRCS := $(wildcard interceptor/*.c)
OS ?= $(shell uname -s)
MARCH ?= $(shell uname -m)
ifeq ($(OS),Linux)
ARCH := LINUX
ARCH_DSUFFIX := .so
CC ?= gcc
LD = $(CC)
ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
-Wextra -Wno-initializer-overrides -Wno-override-init \
-Wno-unknown-warning-option -funroll-loops -O2 \
-D_FILE_OFFSET_BITS=64
ARCH_LDFLAGS := -lpthread -L/usr/local/include -L/usr/include \
-lunwind-ptrace -lunwind-generic -lbfd -lopcodes -lrt
ARCH_SRCS := $(wildcard linux/*.c)
ifeq ("$(wildcard /usr/include/bfd.h)","")
WARN_LIBRARY += binutils-devel
endif
ifeq ("$(wildcard /usr/include/libunwind-ptrace.h)","")
WARN_LIBRARY += libunwind-devel/libunwind8-devel
endif
ifdef WARN_LIBRARY
$(info ***************************************************************)
$(info Development libraries which are most likely missing on your OS:)
$(info $(WARN_LIBRARY))
$(info ***************************************************************)
endif
ifeq ($(MARCH),$(filter $(MARCH),x86_64 i386))
# Support for popcnt (used in linux/perf.c)
ARCH_CFLAGS += -msse4.2
endif # MARCH
# OS Linux
else ifeq ($(OS),Darwin)
ARCH := DARWIN
ARCH_DSUFFIX := .dylib
CRASHWRANGLER := third_party/mac
OS_VERSION := $(shell sw_vers -productVersion)
ifneq (,$(findstring 10.11,$(OS_VERSION)))
# El Capitan didn't break compatibility
SDK_NAME := "macosx10.11"
CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
else ifneq (,$(findstring 10.10,$(OS_VERSION)))
SDK_NAME := "macosx10.10"
CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Yosemite.o
else ifneq (,$(findstring 10.9,$(OS_VERSION)))
SDK_NAME := "macosx10.9"
CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mavericks.o
else ifneq (,$(findstring 10.8,$(OS_VERSION)))
SDK_NAME := "macosx10.8"
CRASH_REPORT := $(CRASHWRANGLER)/CrashReport_Mountain_Lion.o
else
$(error Unsupported MAC OS X version)
endif
SDK := $(shell xcrun --sdk $(SDK_NAME) --show-sdk-path 2>/dev/null)
ifeq (,$(findstring MacOSX.platform,$(SDK)))
XC_PATH := $(shell xcode-select -p)
$(error $(SDK_NAME) not found in $(XC_PATH))
endif
CC := $(shell xcrun --sdk $(SDK_NAME) --find cc)
LD := $(shell xcrun --sdk $(SDK_NAME) --find cc)
ARCH_CFLAGS := -arch x86_64 -O3 -std=c99 -isysroot $(SDK) -I. \
-x objective-c -pedantic \
-Wimplicit -Wunused -Wcomment -Wchar-subscripts -Wuninitialized \
-Wreturn-type -Wpointer-arith -Wno-gnu-case-range -Wno-gnu-designator \
-Wno-deprecated-declarations -Wno-unknown-pragmas -Wno-attributes
ARCH_LDFLAGS := -F/System/Library/PrivateFrameworks -framework CoreSymbolication -framework IOKit \
-F$(SDK)/System/Library/Frameworks -F$(SDK)/System/Library/PrivateFrameworks \
-framework Foundation -framework ApplicationServices -framework Symbolication \
-framework CoreServices -framework CrashReporterSupport -framework CoreFoundation \
-framework CommerceKit $(CRASH_REPORT)
MIG_RET := $(shell mig -header mac/mach_exc.h -user mac/mach_excUser.c -sheader mac/mach_excServer.h \
-server mac/mach_excServer.c $(SDK)/usr/include/mach/mach_exc.defs &>/dev/null; echo $$?)
ifeq ($(MIG_RET),1)
$(error mig failed to generate RPC code)
endif
ARCH_SRCS := $(wildcard mac/*.c)
# OS Darwin
else
ARCH := POSIX
ARCH_DSUFFIX := .so
CC ?= gcc
LD = $(CC)
ARCH_SRCS := $(wildcard posix/*.c)
ARCH_CFLAGS := -std=c11 -I. -I/usr/local/include -I/usr/include \
-Wextra -Wno-initializer-overrides -Wno-override-init \
-Wno-unknown-warning-option -funroll-loops -O2
ARCH_LDFLAGS := -lpthread -L/usr/local/include -L/usr/include
# OS Posix
endif
SRCS := $(COMMON_SRCS) $(ARCH_SRCS)
OBJS := $(SRCS:.c=.o)
INTERCEPTOR_LIBS := $(INTERCEPTOR_SRCS:.c=$(ARCH_DSUFFIX))
# Respect external user defines
CFLAGS += $(COMMON_CFLAGS) $(ARCH_CFLAGS) -D_HF_ARCH_${ARCH}
LDFLAGS += $(COMMON_LDFLAGS) $(ARCH_LDFLAGS)
ifeq ($(DEBUG),true)
CFLAGS += -g -ggdb
endif
# Control Android builds
ANDROID_DEBUG_ENABLED ?= false
ANDROID_APP_ABI ?= armeabi-v7a
ANDROID_API ?= android-21
ANDROID_NDK_TOOLCHAIN ?=
NDK_BUILD_ARGS :=
ifeq ($(ANDROID_DEBUG_ENABLED),true)
NDK_BUILD_ARGS += V=1 NDK_DEBUG=1 APP_OPTIM=debug
endif
SUBDIR_ROOTS := linux mac posix interceptor
DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
CLEAN_PATTERNS := *.o *~ core *.a *.dSYM *.la *.so *.dylib
SUBDIR_GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(CLEAN_PATTERNS)))
MAC_GARGBAGE := $(wildcard mac/mach_exc*)
ANDROID_GARBAGE := obj libs
all: $(BIN) $(INTERCEPTOR_LIBS)
%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
%.so: %.c
$(CC) -fPIC -shared $(CFLAGS) -o $@ $<
%.dylib: %.c
$(CC) -fPIC -shared $(CFLAGS) -o $@ $<
$(BIN): $(OBJS)
$(LD) -o $(BIN) $(OBJS) $(LDFLAGS)
.PHONY: clean
clean:
$(RM) -r core $(OBJS) $(BIN) $(MAC_GARGBAGE) $(ANDROID_GARBAGE) $(SUBDIR_GARBAGE)
.PHONY: indent
indent:
indent -linux -l100 -lc100 -nut -i4 *.c *.h */*.c */*.h; rm -f *~ */*~
.PHONY: depend
depend:
makedepend -Y. -Y* -- $(SRCS)
.PHONY: android
android:
ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./android/Android.mk \
APP_PLATFORM=$(ANDROID_API) APP_ABI=$(ANDROID_APP_ABI) \
NDK_TOOLCHAIN=$(ANDROID_NDK_TOOLCHAIN) $(NDK_BUILD_ARGS)
# DO NOT DELETE
honggfuzz.o: common.h cmdline.h log.h files.h fuzz.h util.h
cmdline.o: cmdline.h common.h log.h files.h util.h
display.o: common.h display.h log.h util.h
log.o: log.h common.h
files.o: common.h files.h log.h
fuzz.o: common.h fuzz.h arch.h display.h files.h log.h mangle.h report.h
fuzz.o: util.h
report.o: common.h report.h log.h util.h
mangle.o: common.h mangle.h log.h util.h
util.o: common.h files.h log.h
linux/ptrace_utils.o: common.h linux/ptrace_utils.h files.h linux/bfd.h
linux/ptrace_utils.o: linux/unwind.h log.h util.h
linux/sancov.o: common.h linux/sancov.h util.h files.h log.h
linux/perf.o: common.h linux/perf.h log.h util.h
linux/bfd.o: common.h linux/bfd.h files.h log.h util.h
linux/unwind.o: common.h linux/unwind.h log.h
linux/arch.o: common.h arch.h linux/perf.h linux/ptrace_utils.h
linux/arch.o: linux/sancov.h log.h util.h files.h