aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-08-18 18:18:56 +0000
committerbloodstalker <thabogre@gmail.com>2018-08-18 18:18:56 +0000
commit0c7b93feba2b421ef612607b625de845c0dd2e70 (patch)
tree24685644fb452215850f0b0ece88111a897e7af8 /bruiser
parentupdating faultreiber and tablegen to their respective latest commits (diff)
downloadmutator-0c7b93feba2b421ef612607b625de845c0dd2e70.tar.gz
mutator-0c7b93feba2b421ef612607b625de845c0dd2e70.zip
makefile updates for obfuscator and bruiser
Diffstat (limited to '')
-rw-r--r--bruiser/lua-5.3.4/src/Makefile2
-rw-r--r--bruiser/luatablegen/makefile2
-rw-r--r--bruiser/makefile198
3 files changed, 156 insertions, 46 deletions
diff --git a/bruiser/lua-5.3.4/src/Makefile b/bruiser/lua-5.3.4/src/Makefile
index f3859af..0eb167f 100644
--- a/bruiser/lua-5.3.4/src/Makefile
+++ b/bruiser/lua-5.3.4/src/Makefile
@@ -7,7 +7,7 @@
PLAT= none
CC= gcc -std=gnu99
-CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_MODULE -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)
+CFLAGS= -fpic -O2 -Wall -Wextra -DLUA_COMPAT_MODULE -DLUA_COMPAT_5_2 $(SYSCFLAGS) $(MYCFLAGS)
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
LIBS= -lm $(SYSLIBS) $(MYLIBS)
diff --git a/bruiser/luatablegen/makefile b/bruiser/luatablegen/makefile
index a4ecdaf..472c591 100644
--- a/bruiser/luatablegen/makefile
+++ b/bruiser/luatablegen/makefile
@@ -1,6 +1,6 @@
CC=clang
CC?=clang
-CC_FLAGS=$(shell $(PY_CONF) --includes)
+CC_FLAGS=$(shell $(PY_CONF) --includes) -fpic
CC_EXTRA?=
CC_FLAGS+=$(CC_EXTRA)
SRCS=$(wildcard *.c)
diff --git a/bruiser/makefile b/bruiser/makefile
index cde4611..a5194c0 100644
--- a/bruiser/makefile
+++ b/bruiser/makefile
@@ -1,48 +1,114 @@
-
-######################################INCLUDES#################################
-include ../macros.mk
-#######################################VARS####################################
+TARGET=bruiser
+LLVM_CONF?=llvm-config
+PY_CONF?=python3-config
+LIB_LUA=./lua-5.3.4/src/liblua.a
+SHELL=bash
+SHELL?=bash
CC=clang
CC?=clang
-CXX_FLAGS+=-I/usr/include -g
-CXX_FLAGS+=$(shell $(PY_CONF) --includes)
-CC_FLAGS+=-g $(shell $(PY_CONF) --includes)
-BRUISER=bruiser
-LUA?=JIT
-LIB_LUA=./lua-5.3.4/src/liblua.a
-LIB_LUA_JIT=./LuaJIT/src/libluajit.a
-HEADER_LIST=
-SRCS=$(wildcard *.cpp)
-C_SRCS=$(wildcard *.c)
-#for some reason without ld the build fails on ubuntu trusty on travis
-#EXTRA_LD_FLAGS+=-lpthread -ldl -lutil -lm -Xlinker -lpython3
+CC_FLAGS=-fpic -std=c11 $(shell $(PY_CONF) --includes)
+CXX=clang++
+CXX?=clang++
+CXX_FLAGS=-fpic -I/usr/include $(shell $(PY_CONF) --includes)
+CXX_EXTRA?=
+CTAGS_I_PATH?=./
+LD_FLAGS=
+EXTRA_LD_FLAGS?=
+ADD_SANITIZERS_CC= -g -fsanitize=address -fno-omit-frame-pointer
+ADD_SANITIZERS_LD= -g -fsanitize=address
+MEM_SANITIZERS_CC= -g -fsanitize=memory -fno-omit-frame-pointer
+MEM_SANITIZERS_LD= -g -fsanitize=memory
+UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer
+UB_SANITIZERS_LD= -g -fsanitize=undefined
+COV_CXX= -fprofile-instr-generate -fcoverage-mapping
+COV_LD= -fprofile-instr-generate
+# BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN
+BUILD_MODE?=RELEASE
+OBJ_LIST:=$(patsubst %.cpp, %.o, $(wildcard *.cpp))
+ASM_LIST:=$(patsubst %.cpp, %.dis, $(wildcard *.cpp))
+
+LLVM_CXX_FLAGS=$(shell $(LLVM_CONF) --cxxflags)
+LLVM_CXX_FLAGS+=-I$(shell $(LLVM_CONF) --src-root)/tools/clang/include\
+ -I$(shell $(LLVM_CONF) --obj-root)/tools/clang/include\
+ -stdlib=libstdc++ -std=c++17 -fexceptions
+LLVM_LD_FLAGS=-Wl,--start-group -lclangAST -lclangAnalysis -lclangBasic\
+ -lclangDriver -lclangEdit -lclangFrontend -lclangFrontendTool\
+ -lclangLex -lclangParse -lclangSema -lclangEdit -lclangASTMatchers\
+ -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerFrontend\
+ -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore\
+ -lclangSerialization -lclangToolingCore -lclangTooling -lstdc++\
+ -lLLVMRuntimeDyld -lm -Wl,--end-group
+LLVM_LD_FLAGS+=$(shell $(LLVM_CONF) --ldflags --libs --system-libs)
+
+CXX_FLAGS+=$(LLVM_CXX_FLAGS)
+LD_FLAGS+=$(LLVM_LD_FLAGS)
+
+#MAKEFLAGS+=--warn-undefined-variables
+ifeq ($(BUILD_MODE), ADDSAN)
+ifeq ($(CXX), g++)
+$(error This build mode is only useable with clang++.)
+endif
+CXX_EXTRA+=$(ADD_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(ADD_SANITIZERS_LD)
+endif
+
+ifeq ($(BUILD_MODE), MEMSAN)
+ifeq ($(CXX), g++)
+$(error This build mode is only useable with clang++.)
+endif
+CXX_EXTRA+=$(MEM_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(MEM_SANITIZERS_LD)
+endif
+
+ifeq ($(BUILD_MODE), UBSAN)
+ifeq ($(CXX), g++)
+$(error This build mode is only useable with clang++.)
+endif
+CXX_EXTRA+=$(UB_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(UB_SANITIZERS_LD)
+endif
+
+SRCS:=$(wildcard *.cpp)
+C_SRCS:=$(wildcard *.c)
+CXX_FLAGS+=$(CXX_EXTRA)
EXTRA_LD_FLAGS+=$(shell $(PY_CONF) --ldflags) -lffi -lcapstone -lkeystone -L./lua-5.3.4/src -llua
TBG_OBJLIST_INC=$(patsubst ./luatablegen/%.c, ./luatablegen/%.o, $(wildcard ./luatablegen/*.c))
-SAN?=
-######################################RULES####################################
-.DEFAULT: all
+LD_FLAGS+=$(EXTRA_LD_FLAGS)
+
+.DEFAULT:all
-.PHONY: all clean help
+.PHONY:all clean help ASM SO TAGS
-all: $(BRUISER) ./wasmtablegen.json
+all:$(TARGET)
+
+everything:$(TARGET) A ASM SO $(TARGET)-dbg TAGS $(TARGET)-cov
depend:.depend
dependc:.dependc
.depend:$(SRCS)
+ rm -rf .depend
$(CXX) -MM $(CXX_FLAGS) $^ > ./.depend
+ echo $(patsubst %.o:, %.odbg:, $(shell $(CXX) -MM $(CXX_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\_]+\.odbg/\n&/g' >> ./.depend
+ echo $(patsubst %.o:, %.ocov:, $(shell $(CXX) -MM $(CXX_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\_]+\.ocov/\n&/g' >> ./.depend
.dependc:$(C_SRCS)
+ rm -rf .dependc
$(CC) -MM $(CC_FLAGS) $^ > ./.dependc
+ echo $(patsubst %.o:, %.odbg:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\_]+\.odbg/\n&/g' >> ./.dependc
+ echo $(patsubst %.o:, %.ocov:, $(shell $(CC) -MM $(CC_FLAGS) $^)) | sed -r 's/[A-Za-z0-9\_]+\.ocov/\n&/g' >> ./.dependc
+
+-include ./.depend
+-include ./.dependc
--include .depend
--include .dependc
+.c.o:
+ $(CC) $(CC_FLAGS) -c $< -o $@
.cpp.o:
$(CXX) $(CXX_FLAGS) -c $< -o $@
-.c.o:
- $(CC) $(CC_FLAGS) -c $< -o $@
+../mutator_aux.o:../mutator_aux.cpp
+ $(CXX) $(CXX_FLAGS) -c $< -o $@
linenoise.o:
$(CC) $(CC_FLAGS) linenoise/linenoise.c -c -o linenoise.o
@@ -58,36 +124,80 @@ linenoise.o:
$(LIB_LUA):
$(MAKE) -C lua-5.3.4/src linux a
- @echo "building with vanilla"
-$(LIB_LUA_JIT):
- $(MAKE) -C LuaJIT
- @echo "building with jit"
+%.odbg:%.cpp
+ $(CXX) $(CXX_FLAGS) -g -c $< -o $@
-$(BRUISER): $(BRUISER).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
- @echo $(TBG_OBJLIST_INC)
+%.ocov:%.cpp
+ $(CXX) $(CXX_FLAGS) $(COV_CXX) -c $< -o $@
+
+$(TARGET): $(TARGET).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
$(CXX) $^ $(LD_FLAGS) -o $@
+$(TARGET)-static: $(TARGET).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
+ $(CXX) $^ $(LD_FLAGS) -static -o $@
+
+$(TARGET)-dbg: $(TARGET).odbg ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
+ $(CXX) $^ $(LD_FLAGS) -g -o $@
+
+$(TARGET)-cov: $(TARGET).ocov ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
+ $(CXX) $^ $(LD_FLAGS) $(COV_LD) -o $@
+
+cov:
+ @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata
+ @llvm-cov show $(TARGET)-cov -instr-profile=default.profdata
+
+covrep:
+ @llvm-profdata merge -sparse ./default.profraw -o ./default.profdata
+ @llvm-cov report $(TARGET)-cov -instr-profile=default.profdata
+
+ASM:$(ASM_LIST)
+
+SO:$(TARGET).so
+
+A:$(TARGET).a
+
+TAGS:tags
+
+tags:$(SRCS)
+ $(shell $(CXX) -c $(shell $(PY_CONF) --includes) $(shell $(LLVM_CONF) --cxxflags) -I$(shell $(LLVM_CONF)\
+ --src-root)/tools/clang/include -I$(shell $(LLVM_CONF) --obj-root)/tools/clang/include -I $(CTAGS_I_PATH) -M $(SRCS)|\
+ sed -e 's/[\\ ]/\n/g'|sed -e '/^$$/d' -e '/\.o:[ \t]*$$/d'|\
+ ctags -L - --c++-kinds=+p --fields=+iaS --extra=+q)
+
+%.dis: %.o
+ objdump -r -d -M intel -S $< > $@
+
+$(TARGET).so: $(TARGET).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
+ $(CXX) $^ $(LD_FLAGS) -shared -o $@
+
+$(TARGET).a: $(TARGET).o ../mutator_aux.o ../tinyxml2/tinyxml2.o linenoise.o CompletionHints.o mutagen.o ORCmutation.o bruiserffi.o asmrewriter.o bruisercapstone.o ramdump.o ffs.o $(LIB_LUA) $(TBG_OBJLIST_INC)
+ ar rcs $(TARGET).a $(TARGET).o
+
clean:
- rm -f *.o *~ $(BRUISER)
- rm .depend
- rm .dependc
+ rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov
$(MAKE) -C luatablegen clean
-install:
- mkdir $$(HOME)/.bruiser
-
deepclean:
- rm -f *.o *~ $(BRUISER)
+ rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov FILE*.cpp FILE*.hpp
rm .depend
- rm .dependc
$(MAKE) -C lua-5.3.4 clean
$(MAKE) -C LuaJIT clean
$(MAKE) -C luatablegen clean
help:
- @echo 'there is help.'
- @echo 'all is the defualt target.'
- @echo 'clean runs clean.'
- @echo 'deepclean will also clean lua and luajit'
- @echo 'for a more complete and detaild list of BUILD_MODE and other things look at the main makefiles help under project root.'
+ @echo "--all is the default target, runs $(TARGET) target"
+ @echo "--everything will build everything"
+ @echo "--SO will generate the so"
+ @echo "--ASM will generate assembly files"
+ @echo "--TAGS will generate tags file"
+ @echo "--$(TARGET) builds the dynamically-linked executable"
+ @echo "--$(TARGET)-dbg will generate the debug build. BUILD_MODE should be set to DEBUG to work"
+ @echo "--$(TARGET)-static will statically link the executable to the libraries"
+ @echo "--$(TARGET)-cov is the coverage build"
+ @echo "--cov will print the line coverage report"
+ @echo "--covrep will print the coverage report"
+ @echo "--A will build the static library"
+ @echo "--TAGS will build the tags file"
+ @echo "--clean"
+ @echo "--deepclean will clean almost everything"