Add UBSAN build option and fix undefined behaviour errors.

1. The assembler tried to write to unaligned addresses but memcpy fixes this.
2. The InstKind and OperandKind enums allowed target specific kinds that did not
   fall in the defined range. Defining the maximum target kind in the enum sorts
   this problem.

BUG=
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1311653003 .
diff --git a/Makefile.standalone b/Makefile.standalone
index 0210ed4..9469f81 100644
--- a/Makefile.standalone
+++ b/Makefile.standalone
@@ -96,6 +96,18 @@
   OBJDIR := $(OBJDIR)+Asserts
 endif
 
+ifdef UBSAN
+  OBJDIR := $(OBJDIR)+UBSan
+  CXX_EXTRA += -fsanitize=undefined -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
+  LD_EXTRA += -fsanitize=undefined
+endif
+
+ifdef UBSAN_TRAP
+  OBJDIR := $(OBJDIR)+UBSan_Trap
+  CXX_EXTRA += -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error -fno-sanitize=vptr -fno-sanitize=nonnull-attribute
+  LD_EXTRA += -fsanitize=undefined-trap
+endif
+
 ifdef TSAN
   OBJDIR := $(OBJDIR)+TSan
   CXX_EXTRA += -fsanitize=thread
@@ -108,6 +120,12 @@
   LD_EXTRA += -fsanitize=address
 endif
 
+ifdef MSAN
+  OBJDIR := $(OBJDIR)+MSan
+  CXX_EXTRA += -fsanitize=memory
+  LD_EXTRA += -fsanitize=memory
+endif
+
 SB_OBJDIR := $(OBJDIR)+Sandboxed
 
 $(info -----------------------------------------------)