aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmain.py5
-rw-r--r--resources/makefile94
-rw-r--r--resources/wasm.xml52
-rwxr-xr-xrun.sh2
-rw-r--r--test/autowasm.c14
-rw-r--r--test/makefile92
6 files changed, 221 insertions, 38 deletions
diff --git a/main.py b/main.py
index e5b89b1..908a6a9 100755
--- a/main.py
+++ b/main.py
@@ -282,6 +282,7 @@ class CodeGen(object):
if "isaggregate" in elem.attrib:
dummy_string += ", " + elem.attrib["name"] + "*" + " dummy_" + elem.attrib["name"]
read_source.write(static + inline + text.c_read_elem_sig.replace("YYY", elem.attrib["name"]).replace("XXX", elem.attrib["name"]+pointer))
+ read_source.write("dummy = malloc(sizeof(" + elem.attrib["name"] + "));\n")
count = get_elem_count(elem)
if count == 1:
for child in elem:
@@ -305,6 +306,8 @@ class CodeGen(object):
read_source.write(for_read)
else: # child_count == -1
count_name_str = child.attrib["count"][6:]
+ read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n")
+ read_source.write("dummy->" + child.attrib["name"] + " = " + "malloc(sizeof(void*)*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n")
for_read = text.c_read_elem_sig_2.replace("XXX", ref_node_name).replace("YYY", "dummy->" + child.attrib["name"] + "[i]") + ";\n"
read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem)))
else:
@@ -328,6 +331,8 @@ class CodeGen(object):
read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", str(child_count)))
else: # child_count = -1
count_name_str = child.attrib["count"][6:]
+ read_source.write("dummy->" + child.attrib["name"] + " = " + "malloc(sizeof(" + type_resolver(child, self.def_elems + self.read_elems) + ")*" + "dummy->" + get_node_name(count_name_str, elem) + ");\n")
+ read_source.write("if (" + "dummy->" + get_node_name(count_name_str, elem) + ")\n")
read_source.write(text.simple_loop.replace("YYY", for_read).replace("XXX", "dummy->" + get_node_name(count_name_str, elem)))
else:
pass
diff --git a/resources/makefile b/resources/makefile
index 434dc68..944bfe1 100644
--- a/resources/makefile
+++ b/resources/makefile
@@ -1,28 +1,56 @@
-TARGET=XXX
+TARGET=autowasm
CC=clang
CC?=clang
CC_FLAGS=-fpic
CC_EXTRA?=
-CC_FLAGS+=$(CC_EXTRA)
+CTAGS_I_PATH?=./
LD_FLAGS=
EXTRA_LD_FLAGS?=
-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
-BUILD_MODE?=COV_NO_CLANG_1Z
+UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer
+UB_SANITIZERS_LD= -g -fsanitize=undefined
+# BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN
+BUILD_MODE?=RELEASE
+
+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
-SRCS=$(wildcard *.c)
+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 ASM SO
+.PHONY:all clean help ASM SO TAGS
all:$(TARGET)
+everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS
+
depend:.depend
.depend:$(SRCS)
@@ -32,27 +60,59 @@ depend:.depend
-include ./.depend
.c.o:
- $(CC) $(CC_FLAGS) -c $< -o $@
+ $(CC) $(CC_FLAGS) -c $< -o $@
-$(TARGET): $(TARGET).o read.o aggregate.o structs.o
+%.odbg:%.c
+ $(CC) $(CC_FLAGS) -g -c $< -o $@
+
+$(TARGET): $(TARGET).o read.o structs.o aggregate.o
$(CC) $^ $(LD_FLAGS) -o $@
+$(TARGET)-static: $(TARGET).o read.o structs.o aggregate.o
+ $(CC) $^ $(LD_FLAGS) -static -o $@
+
+$(TARGET)-dbg: $(TARGET).odbg read.odbg structs.odbg aggregate.odbg
+ $(CC) $^ $(LD_FLAGS) -g -o $@
+
ASM:$(TARGET).asm
SO:$(TARGET).so
-$(TARGET).asm: $(TARGET).o
+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)
+
+$(TARGET).asm: $(TARGET).o read.o structs.o aggregate.o
objdump -r -d -M intel -S $(TARGET).o > $(TARGET).asm
-$(TARGET).so: $(TARGET).o
+$(TARGET).so: $(TARGET).o read.o structs.o aggregate.o
$(CC) $^ $(LD_FLAGS) -shared -o $@
+$(TARGET).a: $(TARGET).o read.o structs.o aggregate.o
+ ar rcs $(TARGET).a $(TARGET).o
+
clean:
- rm -f *.o *~ $(TARGET) $(TARGET).so $(TARGET).asm
+ rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm $(TARGET)-static $(TARGET)-dbg $(TARGET).a
+
+deepclean:
+ rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a
rm .depend
help:
- @echo "all is the default target"
- @echo "SO will generate the so"
- @echo "ASM will generate assembly files"
- @echo "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 "--A will build the static library"
+ @echo "--TAGS will build the tags file"
+ @echo "--clean"
+ @echo "--deepclean will clean almost everything"
diff --git a/resources/wasm.xml b/resources/wasm.xml
index c174429..6a9dfe9 100644
--- a/resources/wasm.xml
+++ b/resources/wasm.xml
@@ -4,45 +4,89 @@
<Magic_Number name="magic_number" type="uint32" count="1"></Magic_Number>
<Version name="version" type="uint32" count="1"></Version>
<Type_Section name="W_Type_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Type_Section_Entry count="self::Count" type="self::Type_Section_Entry" name="entries"/>
</Type_Section>
<Import_Section name="W_Import_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Import_Section_Entry" count="self::Count"/>
</Import_Section>
<Function_Section name="W_Function_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Types name="types" encoding="leb128u" type="uint32" count="self::Count"/>
</Function_Section>
<Table_Section name="W_Table_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Table_Type" count="self::Count"/>
</Table_Section>
<Memory_Section name="W_Memory_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Memory_Type" count="self::Count"/>
</Memory_Section>
<Global_Section name="W_Global_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Globals name="globals" type="self::Global_Entry" count="self::Count"/>
</Global_Section>
<Export_Section name="W_Export_Section" count="1" type="" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Export_Entry" count="self::Count"/>
</Export_Section>
<Start_Section name="W_Start_Section" count="1" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Index name="index" encoding="leb128u" type="uint32" count="1"/>
</Start_Section>
<Element_Section name="W_Element_Section" count="1" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Element_Segment" count="self::Count"/>
</Element_Section>
<Code_Section name="W_Code_Section" count="1" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Bodies name="bodies" type="self::Function_Body" count="self::Count"/>
</Code_Section>
<Data_Section name="W_Data_Section" count="1" isaggregate="true">
+ <ID name="id" type="uint8" encoding="leb128u"/>
+ <PayloadLength name="payloadlength" type="uint32" encoding="leb128u"/>
+ <NameLength name="namelength" type="uint32" encoding="leb128u"/>
+ <Name name="name" type="string" size="self::NameLength"/>
<Count name="count" encoding="leb128u" type="uint32" count="1"/>
<Entries name="entries" type="self::Data_Segment" count="self::Count"/>
</Data_Section>
@@ -69,11 +113,11 @@
<Resizable_Limit count="1" type="self::Resizable_Limit" name="resizable_limit"></Resizable_Limit>
</Memory_Type>
<Type_Section_Entry name="W_Type_Section_Entry" isaggregate="true">
- <Form name="form" encoding="leb128s" type="int8" count="1"/>
- <Param_Count name="param_count" encoding="leb128s" type="uint32" count="1"/>
- <Param_Types name="param_types" encoding="leb128s" type="int8" count="self::Param_Count"/>
+ <Form name="form" encoding="leb128u" type="uint8" count="1"/>
+ <Param_Count name="param_count" encoding="leb128u" type="uint32" count="1"/>
+ <Param_Types name="param_types" encoding="leb128u" type="uint8" count="self::Param_Count"/>
<Return_Count name="return_count" encoding="leb128u" type="uint8"/>
- <Return_Types name="return_types" encoding="leb128s" type="int8"/>
+ <Return_Types name="return_types" encoding="leb128u" type="uint8" count="self::Return_Count"/>
</Type_Section_Entry>
<Import_Section_Entry name="W_Import_Section_Entry" isaggregate="true">
<Module_Length name="module_length" encoding="leb128u" type="uint32" count="1"/>
diff --git a/run.sh b/run.sh
index d0e91d2..d95979d 100755
--- a/run.sh
+++ b/run.sh
@@ -1,5 +1,5 @@
#!/bin/sh
cd $(dirname $0)
"./faultreiber.py" --targetname autowasm --outdir ./test/ --structs ./test/struct.json --datetime --structsinclude ./resources/structsinclude.h --xml ./resources/wasm.xml
-"clang-format" -i ./test/read.c ./test/structs.h
+"clang-format" -i ./test/read.c ./test/structs.h ./test/aggregate.c ./test/aggregate.h ./test/read.h
#"less" ./test/structs.h
diff --git a/test/autowasm.c b/test/autowasm.c
index b62ad34..be2800d 100644
--- a/test/autowasm.c
+++ b/test/autowasm.c
@@ -13,6 +13,20 @@
int main (int argc, char** argv) {
int wasm = open("./test.wasm", O_RDONLY);
malloc_all();
+ read_aggr(wasm);
+ magic_number* mn = ft_ret_magic_number();
+ version* v = ft_ret_version();
+ W_Type_Section* ts = ft_ret_W_Type_Section();
+ printf("magic_number:%x\n", mn->magic_number);
+ printf("version:%d\n", v->version);
+ printf("type section id:%d\n", ts->id);
+ printf("type section payloadlength:%d\n", ts->payloadlength);
+ printf("type_section entry count:%d\n", ts->count);
+ for (int i=0; i < 7; ++i) {
+ //printf("param_count:%d\n",ts->entries[i]->param_count);
+ //printf("param_count:%d\n",ts->entries[i]);
+ }
+
#if 0
uint64_t test_u = 0U;
int64_t test_s = 0;
diff --git a/test/makefile b/test/makefile
index db69aff..944bfe1 100644
--- a/test/makefile
+++ b/test/makefile
@@ -3,26 +3,54 @@ CC=clang
CC?=clang
CC_FLAGS=-fpic
CC_EXTRA?=
-CC_FLAGS+=$(CC_EXTRA)
+CTAGS_I_PATH?=./
LD_FLAGS=
EXTRA_LD_FLAGS?=
-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
-BUILD_MODE?=COV_NO_CLANG_1Z
+UB_SANITIZERS_CC= -g -fsanitize=undefined -fno-omit-frame-pointer
+UB_SANITIZERS_LD= -g -fsanitize=undefined
+# BUILD_MODES are=RELEASE(default), DEBUG,ADDSAN,MEMSAN,UBSAN
+BUILD_MODE?=RELEASE
+
+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
-SRCS=$(wildcard *.c)
+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 ASM SO
+.PHONY:all clean help ASM SO TAGS
all:$(TARGET)
+everything:$(TARGET) A ASM SO $(TARGET)-static $(TARGET)-dbg TAGS
+
depend:.depend
.depend:$(SRCS)
@@ -32,27 +60,59 @@ depend:.depend
-include ./.depend
.c.o:
- $(CC) $(CC_FLAGS) -c $< -o $@
+ $(CC) $(CC_FLAGS) -c $< -o $@
-$(TARGET): $(TARGET).o read.o aggregate.o structs.o
+%.odbg:%.c
+ $(CC) $(CC_FLAGS) -g -c $< -o $@
+
+$(TARGET): $(TARGET).o read.o structs.o aggregate.o
$(CC) $^ $(LD_FLAGS) -o $@
+$(TARGET)-static: $(TARGET).o read.o structs.o aggregate.o
+ $(CC) $^ $(LD_FLAGS) -static -o $@
+
+$(TARGET)-dbg: $(TARGET).odbg read.odbg structs.odbg aggregate.odbg
+ $(CC) $^ $(LD_FLAGS) -g -o $@
+
ASM:$(TARGET).asm
SO:$(TARGET).so
-$(TARGET).asm: $(TARGET).o
+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)
+
+$(TARGET).asm: $(TARGET).o read.o structs.o aggregate.o
objdump -r -d -M intel -S $(TARGET).o > $(TARGET).asm
-$(TARGET).so: $(TARGET).o
+$(TARGET).so: $(TARGET).o read.o structs.o aggregate.o
$(CC) $^ $(LD_FLAGS) -shared -o $@
+$(TARGET).a: $(TARGET).o read.o structs.o aggregate.o
+ ar rcs $(TARGET).a $(TARGET).o
+
clean:
- rm -f *.o *~ $(TARGET) $(TARGET).so $(TARGET).asm
+ rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm $(TARGET)-static $(TARGET)-dbg $(TARGET).a
+
+deepclean:
+ rm -f *.o *.odbg *~ $(TARGET) $(TARGET).so $(TARGET).asm tags $(TARGET)-static $(TARGET)-dbg $(TARGET).a
rm .depend
help:
- @echo "all is the default target"
- @echo "SO will generate the so"
- @echo "ASM will generate assembly files"
- @echo "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 "--A will build the static library"
+ @echo "--TAGS will build the tags file"
+ @echo "--clean"
+ @echo "--deepclean will clean almost everything"