aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser/autogen
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-09-16 15:19:31 +0000
committerbloodstalker <thabogre@gmail.com>2018-09-16 15:19:31 +0000
commit82a3deb3ce19e728d5bafd59e58ed2eb6419b0ef (patch)
treee7aba1a0d12ce1319fbb512777e875cb0970bb63 /bruiser/autogen
parentbegenning to integrate and test both the codegens. run git pull for faultreib... (diff)
downloadmutator-82a3deb3ce19e728d5bafd59e58ed2eb6419b0ef.tar.gz
mutator-82a3deb3ce19e728d5bafd59e58ed2eb6419b0ef.zip
WIP
Diffstat (limited to 'bruiser/autogen')
-rw-r--r--bruiser/autogen/wasm/ft/autowasm.c261
-rw-r--r--bruiser/autogen/wasm/ft/makefile14
-rwxr-xr-xbruiser/autogen/wasm/ltg.sh2
-rw-r--r--bruiser/autogen/wasm/ltg/makefile129
4 files changed, 262 insertions, 144 deletions
diff --git a/bruiser/autogen/wasm/ft/autowasm.c b/bruiser/autogen/wasm/ft/autowasm.c
index 30442ba..cbc6e5a 100644
--- a/bruiser/autogen/wasm/ft/autowasm.c
+++ b/bruiser/autogen/wasm/ft/autowasm.c
@@ -4,170 +4,179 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <sys/resource.h>
-#include "./aggregate.h"
-#include "./read.h"
#include "./structs.h"
+#include "./read.h"
+#include "./aggregate.h"
+
#pragma weak main
-int main(int argc, char **argv) {
+int main (int argc, char** argv) {
+ const rlim_t kStackSize = 160 * 1024 * 1024; // min stack size = 16 MB
+ struct rlimit rl;
+ int result;
+
+ result = getrlimit(RLIMIT_STACK, &rl);
+ if (result == 0)
+ {
+ if (rl.rlim_cur < kStackSize)
+ {
+ rl.rlim_cur = kStackSize;
+ result = setrlimit(RLIMIT_STACK, &rl);
+ if (result != 0)
+ {
+ fprintf(stderr, "setrlimit returned result = %d\n", result);
+ }
+ }
+ }
int wasm = open("./test.wasm", O_RDONLY);
- read_aggr_wasm(wasm);
-
- printf("magic_number:%x\n", magic_number_container->magic_number);
- printf("version:%x\n", version_container->version);
-
- printf("type section id:%d\n", W_Type_Section_container->id);
- printf("type section payloadlength:%d\n",
- W_Type_Section_container->payloadlength);
- printf("type_section entry count:%d\n", W_Type_Section_container->count);
- for (int i = 0; i < W_Type_Section_container->count; ++i) {
- printf("param_count:%d\n",
- W_Type_Section_container->entries[i]->param_count);
- for (int j = 0; j < W_Type_Section_container->entries[i]->param_count; ++j)
- printf("param_types:%d\n",
- W_Type_Section_container->entries[i]->param_types[j]);
- printf("return_count:%d\n",
- W_Type_Section_container->entries[i]->return_count);
- for (int j = 0; j < W_Type_Section_container->entries[i]->return_count; ++j)
- printf("param_types:%d\n",
- W_Type_Section_container->entries[i]->return_types[j]);
+ wasm_lib_ret_t* lib_ret = read_aggr_wasm(wasm);
+ printf("finished reading\n");
+
+#if 0
+ printf("magic_number:%x\n", lib_ret->obj->magic_number_container->magic_number);
+ printf("version:%x\n", lib_ret->obj->version_container->version);
+
+ printf("type section id:%d\n", lib_ret->obj->W_Type_Section_container->id);
+ printf("type section payloadlength:%d\n", lib_ret->obj->W_Type_Section_container->payloadlength);
+ printf("type_section entry count:%d\n", lib_ret->obj->W_Type_Section_container->count);
+ for (int i=0; i < lib_ret->obj->W_Type_Section_container->count; ++i) {
+ printf("param_count:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_count);
+ for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->param_count; ++j)
+ printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->param_types[j]);
+ printf("return_count:%d\n", lib_ret->obj->W_Type_Section_container->entries[i]->return_count);
+ for (int j = 0; j < lib_ret->obj->W_Type_Section_container->entries[i]->return_count; ++j)
+ printf("param_types:%d\n",lib_ret->obj->W_Type_Section_container->entries[i]->return_types[j]);
}
- printf("import_section_id:%d\n", W_Import_Section_container->id);
- printf("import_section_payloadlength:%d\n",
- W_Import_Section_container->payloadlength);
- printf("import_section_count:%d\n", W_Import_Section_container->count);
- for (int i = 0; i < W_Import_Section_container->count; ++i) {
- printf("module_length:%d\n",
- W_Import_Section_container->entries[i]->module_length);
- printf("module_str:%s\n",
- W_Import_Section_container->entries[i]->module_str);
- printf("field_length:%d\n",
- W_Import_Section_container->entries[i]->field_len);
- printf("field_str:%s\n", W_Import_Section_container->entries[i]->field_str);
- printf("kind:%d\n", W_Import_Section_container->entries[i]->kind);
- if (W_Import_Section_container->entries[i]->kind == 0)
- printf("type:%d\n", W_Import_Section_container->entries[i]->kind);
+ printf("import_section_id:%d\n", lib_ret->obj->W_Import_Section_container->id);
+ printf("import_section_payloadlength:%d\n", lib_ret->obj->W_Import_Section_container->payloadlength);
+ printf("import_section_count:%d\n", lib_ret->obj->W_Import_Section_container->count);
+ for(int i = 0; i < lib_ret->obj->W_Import_Section_container->count; ++i) {
+ printf("module_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_length);
+ printf("module_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->module_str);
+ printf("field_length:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_len);
+ printf("field_str:%s\n", lib_ret->obj->W_Import_Section_container->entries[i]->field_str);
+ printf("kind:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind);
+ if (lib_ret->obj->W_Import_Section_container->entries[i]->kind == 0)
+ printf("type:%d\n", lib_ret->obj->W_Import_Section_container->entries[i]->kind);
printf("\n");
}
- printf("function_section_id:%d\n", W_Function_Section_container->id);
- printf("function_section_payloadlength:%d\n",
- W_Function_Section_container->payloadlength);
- printf("function_section_count:%d\n", W_Function_Section_container->count);
- for (int i = 0; i < W_Function_Section_container->count; ++i)
- printf("type:%d\n", W_Function_Section_container->types[i]);
-
- printf("table_section_id:%d\n", W_Table_Section_container->id);
- printf("table_section_payloadlength:%d\n",
- W_Table_Section_container->payloadlength);
- printf("table_section_count:%d\n", W_Table_Section_container->count);
- for (int i = 0; i < W_Table_Section_container->count; ++i) {
- printf("element_type:%d\n",
- W_Table_Section_container->entries[i]->element_type);
- printf("rl_flags:%d\n",
- W_Table_Section_container->entries[i]->resizable_limit->flags);
- printf("rl_initial:%d\n",
- W_Table_Section_container->entries[i]->resizable_limit->initial);
- printf("rl_maximum:%d\n",
- W_Table_Section_container->entries[i]->resizable_limit->maximum);
+ printf("function_section_id:%d\n", lib_ret->obj->W_Function_Section_container->id);
+ printf("function_section_payloadlength:%d\n", lib_ret->obj->W_Function_Section_container->payloadlength);
+ printf("function_section_count:%d\n", lib_ret->obj->W_Function_Section_container->count);
+ for (int i = 0; i < lib_ret->obj->W_Function_Section_container->count; ++i)
+ printf("type:%d\n", lib_ret->obj->W_Function_Section_container->types[i]);
+
+ printf("table_section_id:%d\n", lib_ret->obj->W_Table_Section_container->id);
+ printf("table_section_payloadlength:%d\n", lib_ret->obj->W_Table_Section_container->payloadlength);
+ printf("table_section_count:%d\n", lib_ret->obj->W_Table_Section_container->count);
+ for (int i = 0; i < lib_ret->obj->W_Table_Section_container->count; ++i) {
+ printf("element_type:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->element_type);
+ printf("rl_flags:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->flags);
+ printf("rl_initial:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->initial);
+ printf("rl_maximum:%d\n", lib_ret->obj->W_Table_Section_container->entries[i]->resizable_limit->maximum);
}
- printf("memory_section_id:%d\n", W_Memory_Section_container->id);
- printf("memory_section_payload_length:%d\n",
- W_Memory_Section_container->payloadlength);
- printf("rl_flags:%d\n",
- W_Memory_Section_container->entries->resizable_limit->flags);
- printf("rl_initial:%d\n",
- W_Memory_Section_container->entries->resizable_limit->initial);
- printf("rl_maximum:%d\n",
- W_Memory_Section_container->entries->resizable_limit->maximum);
-
- if (W_Global_Section_container == NULL)
- printf("global section doesnt exist.\n");
-
- printf("export_section_id:%d\n", W_Export_Section_container->id);
- printf("export_section_payloadlength:%d\n",
- W_Export_Section_container->payloadlength);
- printf("entry count:%d\n", W_Export_Section_container->count);
-
- for (int i = 0; i < W_Export_Section_container->count; ++i) {
- printf("field_len:%d\n", W_Export_Section_container->entries[i]->field_len);
- printf("field_str:%s\n", W_Export_Section_container->entries[i]->field_str);
- printf("kind:%d\n", W_Export_Section_container->entries[i]->kind);
- printf("index:%d\n", W_Export_Section_container->entries[i]->index);
+ printf("memory_section_id:%d\n", lib_ret->obj->W_Memory_Section_container->id);
+ printf("memory_section_payload_length:%d\n", lib_ret->obj->W_Memory_Section_container->payloadlength);
+ printf("rl_flags:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->flags);
+ printf("rl_initial:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->initial);
+ printf("rl_maximum:%d\n", lib_ret->obj->W_Memory_Section_container->entries->resizable_limit->maximum);
+
+ if (lib_ret->obj->W_Global_Section_container == NULL) printf("global section doesnt exist.\n");
+
+ printf("export_section_id:%d\n", lib_ret->obj->W_Export_Section_container->id);
+ printf("export_section_payloadlength:%d\n", lib_ret->obj->W_Export_Section_container->payloadlength);
+ printf("entry count:%d\n", lib_ret->obj->W_Export_Section_container->count);
+
+ for (int i = 0; i < lib_ret->obj->W_Export_Section_container->count; ++i) {
+ printf("field_len:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_len);
+ printf("field_str:%s\n", lib_ret->obj->W_Export_Section_container->entries[i]->field_str);
+ printf("kind:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->kind);
+ printf("index:%d\n", lib_ret->obj->W_Export_Section_container->entries[i]->index);
}
- if (W_Start_Section_container == NULL)
- printf("start section doesnt exist.\n");
+ if (lib_ret->obj->W_Start_Section_container == NULL) printf("start section doesnt exist.\n");
- printf("element_seciton_id:%d\n", W_Element_Section_container->id);
- printf("element_section_payloadlength:%d\n",
- W_Element_Section_container->payloadlength);
- printf("entry count:%d\n", W_Element_Section_container->count);
+ printf("element_seciton_id:%d\n", lib_ret->obj->W_Element_Section_container->id);
+ printf("element_section_payloadlength:%d\n", lib_ret->obj->W_Element_Section_container->payloadlength);
+ printf("entry count:%d\n", lib_ret->obj->W_Element_Section_container->count);
- for (int i = 0; i < W_Element_Section_container->count; ++i) {
- printf("index:%d\n", W_Element_Section_container->entries[i]->index);
+ for (int i = 0; i < lib_ret->obj->W_Element_Section_container->count; ++i) {
+ printf("index:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->index);
for (int j = 0; j < 3; ++j) {
- printf("code:%d\n",
- W_Element_Section_container->entries[i]->init->code[j]);
+ printf("code:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->init->code[j]);
}
- printf("num_length:%d\n",
- W_Element_Section_container->entries[i]->num_length);
- for (int j = 0; j < W_Element_Section_container->entries[i]->num_length;
- ++j) {
- printf("elems:%d\n", W_Element_Section_container->entries[i]->elems[j]);
+ printf("num_length:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->num_length);
+ for (int j = 0; j < lib_ret->obj->W_Element_Section_container->entries[i]->num_length; ++j) {
+ printf("elems:%d\n", lib_ret->obj->W_Element_Section_container->entries[i]->elems[j]);
}
}
- printf("code_section_id:%d\n", W_Code_Section_container->id);
- printf("code_section_payloadlength:%d\n",
- W_Code_Section_container->payloadlength);
- printf("count:%d\n", W_Code_Section_container->count);
-
- for (int i = 0; i < W_Code_Section_container->count; ++i) {
- printf("body_size:%d\n", W_Code_Section_container->bodies[i]->body_size);
- printf("local_count:%d\n",
- W_Code_Section_container->bodies[i]->local_count);
- if (W_Code_Section_container->bodies[i]->local_count > 0) {
- for (int j = 0; j < W_Code_Section_container->bodies[i]->local_count;
- ++j) {
- for (int k = 0;
- k < W_Code_Section_container->bodies[i]->locals[j]->count; ++k) {
+ printf("code_section_id:%d\n", lib_ret->obj->W_Code_Section_container->id);
+ printf("code_section_payloadlength:%d\n", lib_ret->obj->W_Code_Section_container->payloadlength);
+ printf("count:%d\n", lib_ret->obj->W_Code_Section_container->count);
+
+ for (int i = 0; i < lib_ret->obj->W_Code_Section_container->count; ++i) {
+ printf("body_size:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->body_size);
+ printf("local_count:%d\n", lib_ret->obj->W_Code_Section_container->bodies[i]->local_count);
+ if (lib_ret->obj->W_Code_Section_container->bodies[i]->local_count > 0) {
+ for (int j =0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->local_count; ++j) {
+ for (int k = 0; k < lib_ret->obj->W_Code_Section_container->bodies[i]->locals[j]->count; ++k) {
}
}
}
printf("code:\n");
- for (int j = 0; j < W_Code_Section_container->bodies[i]->body_size; ++j) {
- printf("%02x ", W_Code_Section_container->bodies[i]->code[j]);
+ for (int j = 0; j < lib_ret->obj->W_Code_Section_container->bodies[i]->body_size; ++j) {
+ printf("%02x ", lib_ret->obj->W_Code_Section_container->bodies[i]->code[j]);
}
printf("\n");
}
- printf("data_section_id:%d\n", W_Data_Section_container->id);
- printf("data_section_payloadlength:%d\n",
- W_Data_Section_container->payloadlength);
- printf("data seg count:%d\n", W_Data_Section_container->count);
+ printf("data_section_id:%d\n", lib_ret->obj->W_Data_Section_container->id);
+ printf("data_section_payloadlength:%d\n", lib_ret->obj->W_Data_Section_container->payloadlength);
+ printf("data seg count:%d\n", lib_ret->obj->W_Data_Section_container->count);
- for (int i = 0; i < W_Data_Section_container->count; ++i) {
- printf("index:%d\n", W_Data_Section_container->entries[i]->index);
- printf("size:%d\n", W_Data_Section_container->entries[i]->size);
+ for (int i = 0; i < lib_ret->obj->W_Data_Section_container->count; ++i) {
+ printf("index:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->index);
+ printf("size:%d\n", lib_ret->obj->W_Data_Section_container->entries[i]->size);
printf("code:\n");
- for (int j = 0; j < W_Data_Section_container->entries[i]->size; ++j) {
- printf("%c ", W_Data_Section_container->entries[i]->data[j]);
+ for (int j = 0; j < lib_ret->obj->W_Data_Section_container->entries[i]->size; ++j) {
+ printf("%c ", lib_ret->obj->W_Data_Section_container->entries[i]->data[j]);
}
printf("\n");
int j = 0;
printf("offset:\n");
- while (1) {
- printf("%02x ", W_Data_Section_container->entries[i]->offset->code[j]);
- if (W_Data_Section_container->entries[i]->offset->code[j] == 11) {
+ while(1) {
+ printf("%02x ", lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j]);
+ if (lib_ret->obj->W_Data_Section_container->entries[i]->offset->code[j] == 11) {
break;
}
j++;
}
printf("\n");
}
-
- release_all();
+#endif
+
+ printf("sizeof magic:%d\n", sizeof(magic_number));
+ printf("sizeof version:%d\n", sizeof(version));
+ printf("current void count:%d\n", lib_ret->current_void_count);
+ printf("void_train first:0x%x\n", lib_ret->void_train[0]);
+ printf("void_train first:0x%x\n", lib_ret->void_train[1]);
+ printf("void_train self address:0x%x\n", lib_ret->void_train);
+ //free(lib_ret->void_train[0]);
+ //release_all(lib_ret->void_train, lib_ret->current_void_count);
+ //free(lib_ret->void_train[2]);
+ //free(lib_ret->void_train[1]);
+ //free(lib_ret->void_train[0]);
+ for (int i = lib_ret->current_void_count - 1; i >= 0; --i) {
+ printf("%d:0x%x ", i, lib_ret->void_train[i]);
+ //if (i == 1) continue;
+ free(lib_ret->void_train[i]);
+ }
+ free(lib_ret->void_train);
+ free(lib_ret->obj);
+ free(lib_ret);
return 0;
}
diff --git a/bruiser/autogen/wasm/ft/makefile b/bruiser/autogen/wasm/ft/makefile
index 86f0a6b..be67649 100644
--- a/bruiser/autogen/wasm/ft/makefile
+++ b/bruiser/autogen/wasm/ft/makefile
@@ -53,7 +53,7 @@ LD_FLAGS+=$(EXTRA_LD_FLAGS)
.PHONY:all clean help ASM SO TAGS
-all:$(TARGET)
+all:$(TARGET) $(TARGET)-dbg
everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov
@@ -82,10 +82,10 @@ $(TARGET): $(TARGET).o read.o aggregate.o structs.o
$(TARGET)-static: $(TARGET).o read.o aggregate.o structs.o
$(CC) $^ $(LD_FLAGS) -static -o $@
-$(TARGET)-dbg: $(TARGET).odbg read.o aggregate.o structs.o
+$(TARGET)-dbg: $(TARGET).odbg read.odbg aggregate.odbg structs.odbg
$(CC) $^ $(LD_FLAGS) -g -o $@
-$(TARGET)-cov: $(TARGET).ocov read.o aggregate.o structs.o
+$(TARGET)-cov: $(TARGET).ocov read.ocov aggregate.ocov structs.ocov
$(CC) $^ $(LD_FLAGS) $(COV_LD) -o $@
cov:
@@ -116,7 +116,13 @@ $(TARGET).so: $(TARGET).o read.o aggregate.o structs.o
$(CC) $^ $(LD_FLAGS) -shared -o $@
$(TARGET).a: $(TARGET).o read.o aggregate.o structs.o
- ar rcs $(TARGET).a $(TARGET).o
+ ar rcs $(TARGET).a $(TARGET).o read.o aggregate.o structs.o
+
+valgrind: $(TARGET)
+ valgrind --leak-check=yes $(TARGET)
+
+test: $(TARGET)
+ $(TARGET)
clean:
rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov
diff --git a/bruiser/autogen/wasm/ltg.sh b/bruiser/autogen/wasm/ltg.sh
index 94f052b..a7ca2e9 100755
--- a/bruiser/autogen/wasm/ltg.sh
+++ b/bruiser/autogen/wasm/ltg.sh
@@ -1,6 +1,6 @@
#!/usr/bin/bash
cd $(dirname $0)
-"../../tablegen/luatablegen.py" --out ./ltg/ --luaheader ../../../lua-5.3.4/src --headeraggr ./ltg/wasm_tables.h --lualibpath ./ltg/wasm.lua --docpath ./ltg/wasm.md --xml ./ltg/wasm.xml --tbldefs ./ltg/
+"../../tablegen/luatablegen.py" --out ./ltg/ --luaheader ../../../lua-5.3.4/src --headeraggr ./ltg/wasm_tables.h --lualibpath ./ltg/wasm.lua --docpath ./ltg/wasm.md --xml ./ltg/wasm.xml --tbldefs ./ltg/ --name wasm
clang-format ./ltg/*.c ./ltg/*.h -i
for filename in ./ltg/*.c; do
gcc -c $filename > /dev/null 2>&1
diff --git a/bruiser/autogen/wasm/ltg/makefile b/bruiser/autogen/wasm/ltg/makefile
index b59a216..3a98ee0 100644
--- a/bruiser/autogen/wasm/ltg/makefile
+++ b/bruiser/autogen/wasm/ltg/makefile
@@ -1,12 +1,14 @@
+TARGET=wasm_tables
+SHELL=bash
+SHELL?=bash
CC=clang
CC?=clang
-CC_FLAGS=-fpic
+CC_FLAGS= -fPIC
CC_EXTRA?=
-CC_FLAGS+=$(CC_EXTRA)
-SRCS=$(wildcard *.c)
-TBG_OBJLIST=$(patsubst %.c, %.o , $(wildcard *.c))
-TBG_OBJLIST_DBG=$(patsubst %.c, %.odbg , $(wildcard *.c))
-TBG_OBJLIST_COV=$(patsubst %.c, %.ocov , $(wildcard *.c))
+CTAGS_I_PATH?=./
+LD_FLAGS=
+LIB_LUA=../../../lua-5.3.4/src/liblua.a
+EXTRA_LD_FLAGS?=-lm -ldl
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
@@ -14,14 +16,47 @@ MEM_SANITIZERS_LD= -g -fsanitize=memory
UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer
UB_SANITIZERS_LD= -g -fsanitize=undefined
COV_CC= -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 %.c, %.o, $(wildcard *.c))
+ASM_LIST:=$(patsubst %.c, %.dis, $(wildcard *.c))
+
+ifeq ($(BUILD_MODE), ADDSAN)
+ifeq ($(CC), gcc)
+$(error This build mode is only useable with clang.)
+endif
+CC_EXTRA+=$(ADD_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(ADD_SANITIZERS_LD)
+endif
+
+ifeq ($(BUILD_MODE), MEMSAN)
+ifeq ($(CC), gcc)
+$(error This build mode is only useable with clang.)
+endif
+CC_EXTRA+=$(MEM_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(MEM_SANITIZERS_LD)
+endif
+
+ifeq ($(BUILD_MODE), UBSAN)
+ifeq ($(CC), gcc)
+$(error This build mode is only useable with clang.)
+endif
+CC_EXTRA+=$(UB_SANITIZERS_CC)
+EXTRA_LD_FLAGS+=$(UB_SANITIZERS_LD)
+endif
+
+SRCS:=$(wildcard *.c)
+CC_FLAGS+=$(CC_EXTRA)
+LD_FLAGS+=$(EXTRA_LD_FLAGS)
.DEFAULT:all
-.PHONY:all clean help
+.PHONY:all clean help ASM SO TAGS
+
+all:$(TARGET)
-all:$(TBG_OBJLIST) $(TBG_OBJLIST_DBG) $(TBG_OBJLIST_COV)
- @echo $(TBG_OBJLIST)
- @echo $(TBG_OBJLIST_INC)
+everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS $(TARGET)-cov
depend:.depend
@@ -42,10 +77,78 @@ depend:.depend
%.ocov:%.c
$(CC) $(CC_FLAGS) $(COV_CC) -c $< -o $@
+$(LIB_LUA):
+ $(MAKE) -C ../../../lua-5.3.4/src linux
+
+$(TARGET): $(TARGET).o $(LIB_LUA) $(OBJ_LIST)
+ $(CC) $(LD_FLAGS) $^ -o $@
+
+$(TARGET)-static: $(TARGET).o $(LIB_LUA) $(OBJ_LIST)
+ $(CC) $^ $(LD_FLAGS) -static -o $@
+
+$(TARGET)-dbg: $(TARGET).odbg $(LIB_LUA) $(OBJ_LIST)
+ $(CC) $^ $(LD_FLAGS) -g -o $@
+
+$(TARGET)-cov: $(TARGET).ocov $(LIB_LUA) $(OBJ_LIST)
+ $(CC) $^ $(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 $(CC) -c -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 $(LIB_LUA) $(OBJ_LIST)
+ $(CC) $^ $(LD_FLAGS) -shared -o $@
+
+$(TARGET).a: $(TARGET).o $(LIB_LUA) $(OBJ_LIST)
+ ar rcs $(TARGET).a $(OBJ_LIST)
+
+runcov: $(TARGET)-cov
+ $(TARGET)-cov
+
+valgrind: $(TARGET)
+ - valgrind --leak-check=yes $(TARGET)
+
clean:
- rm -f *.o *~ $(TARGET) *.ocov *.odbg
+ rm -f *.o *.dis *.odbg *.ocov *~ $(TARGET) $(TARGET).so $(TARGET)-static $(TARGET)-dbg $(TARGET).a $(TARGET)-cov
+
+deepclean: clean
+ if [[ -d tags ]];then rm tags;fi
rm .depend
+ $(MAKE) -C ../lua5 clean
help:
- @echo "all is the default target"
- @echo "there is clean."
+ @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 coverage report"
+ @echo "--covrep will print the line coverage report"
+ @echo "--A will build the static library"
+ @echo "--TAGS will build the tags file"
+ @echo "--clean"
+ @echo "--deepclean will clean almost everything"