Add ASAN build target with UNICORN_ASAN or via './make.sh asan'

This commit is contained in:
Zach Riggle 2016-04-20 15:38:27 -07:00
parent 8932463f9d
commit 93063d089b
4 changed files with 32 additions and 4 deletions

View file

@ -64,6 +64,13 @@ else
CFLAGS += -O3 CFLAGS += -O3
endif endif
ifeq ($(UNICORN_ASAN),yes)
CC = clang -fsanitize=address -fno-omit-frame-pointer
CXX = clang++ -fsanitize=address -fno-omit-frame-pointer
AR = llvm-ar
LDFLAGS := -fsanitize=address ${LDFLAGS}
endif
ifeq ($(CROSS),) ifeq ($(CROSS),)
CC ?= cc CC ?= cc
AR ?= ar AR ?= ar
@ -122,7 +129,7 @@ EXT = so
VERSION_EXT = $(EXT).$(API_MAJOR) VERSION_EXT = $(EXT).$(API_MAJOR)
AR_EXT = a AR_EXT = a
$(LIBNAME)_LDFLAGS += -Wl,-Bsymbolic-functions,-soname,lib$(LIBNAME).$(VERSION_EXT) $(LIBNAME)_LDFLAGS += -Wl,-Bsymbolic-functions,-soname,lib$(LIBNAME).$(VERSION_EXT)
UNICORN_CFLAGS += -fvisibility=hidden # UNICORN_CFLAGS += -fvisibility=hidden
endif endif
endif endif
endif endif
@ -213,11 +220,11 @@ config:
qemu/config-host.h-timestamp: qemu/config-host.h-timestamp:
ifeq ($(UNICORN_DEBUG),yes) ifeq ($(UNICORN_DEBUG),yes)
cd qemu && \ cd qemu && \
./configure --extra-cflags="$(UNICORN_CFLAGS)" --target-list="$(UNICORN_TARGETS)" ${UNICORN_QEMU_FLAGS} ./configure --cc="${CC}" --extra-cflags="$(UNICORN_CFLAGS)" --target-list="$(UNICORN_TARGETS)" ${UNICORN_QEMU_FLAGS}
printf "$(UNICORN_ARCHS)" > config.log printf "$(UNICORN_ARCHS)" > config.log
else else
cd qemu && \ cd qemu && \
./configure --disable-debug-info --extra-cflags="$(UNICORN_CFLAGS)" --target-list="$(UNICORN_TARGETS)" ${UNICORN_QEMU_FLAGS} ./configure --cc="${CC}" --disable-debug-info --extra-cflags="$(UNICORN_CFLAGS)" --target-list="$(UNICORN_TARGETS)" ${UNICORN_QEMU_FLAGS}
printf "$(UNICORN_ARCHS)" > config.log printf "$(UNICORN_ARCHS)" > config.log
endif endif
@ -264,7 +271,6 @@ endif
test: all test: all
$(MAKE) -C tests/unit test $(MAKE) -C tests/unit test
install: compile_lib $(PKGCFGF) install: compile_lib $(PKGCFGF)
mkdir -p $(DESTDIR)$(LIBDIR) mkdir -p $(DESTDIR)$(LIBDIR)
ifeq ($(UNICORN_SHARED),yes) ifeq ($(UNICORN_SHARED),yes)

View file

@ -10,6 +10,13 @@ MAKE_JOBS=$((${MAKE_JOBS}+0))
[ ${MAKE_JOBS} -lt 1 ] && \ [ ${MAKE_JOBS} -lt 1 ] && \
MAKE_JOBS=4 MAKE_JOBS=4
# build for ASAN
asan() {
UNICORN_DEBUG=yes
UNICORN_ASAN=yes
${MAKE} V=1
}
# build iOS lib for all iDevices, or only specific device # build iOS lib for all iDevices, or only specific device
build_iOS() { build_iOS() {
IOS_SDK=`xcrun --sdk iphoneos --show-sdk-path` IOS_SDK=`xcrun --sdk iphoneos --show-sdk-path`
@ -90,6 +97,7 @@ export CC INSTALL_BIN PREFIX PKGCFGDIR LIBDIRARCH LIBARCHS CFLAGS LDFLAGS
case "$1" in case "$1" in
"" ) build;; "" ) build;;
"asan" ) asan;;
"default" ) build;; "default" ) build;;
"install" ) install;; "install" ) install;;
"uninstall" ) uninstall;; "uninstall" ) uninstall;;

View file

@ -37,6 +37,13 @@ else
CC = $(CROSS)gcc CC = $(CROSS)gcc
endif endif
ifeq ($(UNICORN_ASAN),yes)
CC = clang -fsanitize=address -fno-omit-frame-pointer
CXX = clang++ -fsanitize=address -fno-omit-frame-pointer
AR = llvm-ar
LDFLAGS := -fsanitize=address ${LDFLAGS}
endif
#CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch)) #CFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))
#LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch)) #LDFLAGS += $(foreach arch,$(LIBARCHS),-arch $(arch))

View file

@ -4,6 +4,13 @@ CFLAGS += -L ../../
CFLAGS += -lcmocka -lunicorn CFLAGS += -lcmocka -lunicorn
CFLAGS += -I ../../include CFLAGS += -I ../../include
ifeq ($(UNICORN_ASAN),yes)
CC = clang -fsanitize=address -fno-omit-frame-pointer
CXX = clang++ -fsanitize=address -fno-omit-frame-pointer
AR = llvm-ar
LDFLAGS := -fsanitize=address ${LDFLAGS}
endif
ALL_TESTS = test_sanity test_x86 test_mem_map test_mem_high test_mem_map_ptr \ ALL_TESTS = test_sanity test_x86 test_mem_map test_mem_high test_mem_map_ptr \
test_tb_x86 test_multihook test_pc_change test_x86_soft_paging \ test_tb_x86 test_multihook test_pc_change test_x86_soft_paging \
test_hookcounts test_hookcounts