diff --git a/Makefile.linux b/Makefile.linux index c344165f..5b5f87aa 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -34,7 +34,7 @@ ARCH ?= $(shell sh $(SRCDIR)/config-arch.sh) C_COMPILER_OPTIONS ?= -fno-strict-aliasing -fwrapv -DHAVE_CHICKEN_CONFIG_H ifdef DEBUGBUILD -C_COMPILER_OPTIMIZATION_OPTIONS ?= -g -Wall -Wno-unused -O0 -Wno-cpp +C_COMPILER_OPTIMIZATION_OPTIONS ?= -g -Wall -Wno-unused -O0 -Wno-cpp -fsanitize=address else ifdef OPTIMIZE_FOR_SPEED C_COMPILER_OPTIMIZATION_OPTIONS ?= -O3 -fomit-frame-pointer @@ -46,7 +46,7 @@ LINKER_LINK_SHARED_LIBRARY_OPTIONS = -shared LINKER_LINK_SHARED_DLOADABLE_OPTIONS = -L. -shared -Wl,-rpath="$(RUNTIME_LINKER_PATH)" LINKER_LINK_SHARED_PROGRAM_OPTIONS = -Wl,-rpath="$(RUNTIME_LINKER_PATH)" LIBCHICKEN_SO_LINKER_OPTIONS = -Wl,-soname,lib$(PROGRAM_PREFIX)chicken$(PROGRAM_SUFFIX).so.$(BINARYVERSION) -LIBRARIES = -lm -ldl +LIBRARIES = -lm -ldl -fsanitize=address NEEDS_RELINKING = yes USES_SONAME = yes diff --git a/runtime.c b/runtime.c index bc545def..ea18b43f 100644 --- a/runtime.c +++ b/runtime.c @@ -3862,6 +3862,14 @@ static C_regparm void really_mark(C_word *x, C_byte *tgt_space_start, C_byte **t if(C_gc_trace_hook != NULL) C_gc_trace_hook(x, gc_mode); #endif + if (debug_mode) { + if (val != NULL && C_header_bits(val) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(val), "import0")) { + C_dbg(C_text("debug"), C_text("Skipping value1 outside stack/heap/scratch space %p (stack between %p and %p)\n"), val, C_stack_pointer_test, stack_bottom); + } + if (val != NULL && C_header_bits(val) == C_SYMBOL_TYPE && C_header_bits(C_symbol_name(val)) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(C_symbol_name(val)), "import0")) { + C_dbg(C_text("debug"), C_text("Skipping symbol1 outside stack/heap/scratch space %p (stack between %p and %p)\n"), val, C_stack_pointer_test, stack_bottom); + } + } return; } @@ -3877,6 +3885,14 @@ static C_regparm void really_mark(C_word *x, C_byte *tgt_space_start, C_byte **t /* Already in target space, probably as result of chasing fptrs */ if ((C_uword)val >= (C_uword)tgt_space_start && (C_uword)val < (C_uword)*tgt_space_top) { *x = val; + if (debug_mode) { + if (C_header_bits(val) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(val), "import0")) { + C_dbg(C_text("debug"), C_text("Skipping value2 outside stack/heap/scratch space %p (stack between %p and %p)\n"), val, C_stack_pointer_test, stack_bottom); + } + if (val != NULL && C_header_bits(val) == C_SYMBOL_TYPE && C_header_bits(C_symbol_name(val)) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(C_symbol_name(val)), "import0")) { + C_dbg(C_text("debug"), C_text("Skipping symbol2 outside stack/heap/scratch space %p (stack between %p and %p)\n"), val, C_stack_pointer_test, stack_bottom); + } + } return; } @@ -3892,6 +3908,15 @@ static C_regparm void really_mark(C_word *x, C_byte *tgt_space_start, C_byte **t n = C_header_size(p); bytes = (h & C_BYTEBLOCK_BIT) ? n : n * sizeof(C_word); + if (debug_mode) { + if (C_header_bits(val) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(val), "import0")) { + C_dbg(C_text("debug"), C_text("Copying value import0 at %p\n"), val); + } + if (val != NULL && C_header_bits(val) == C_SYMBOL_TYPE && C_header_bits(C_symbol_name(val)) == C_BYTEVECTOR_TYPE && !strcmp(C_c_string(C_symbol_name(val)), "import0")) { + C_dbg(C_text("debug"), C_text("Copying symbol outside stack/heap/scratch space %p (stack between %p and %p)\n"), val, C_stack_pointer_test, stack_bottom); + } + } + if(C_unlikely(((C_byte *)p2 + bytes + sizeof(C_word)) > tgt_space_limit)) { if (gc_mode == GC_MAJOR) { /* Detect impossibilities before GC_REALLOC to preserve state: */ diff --git a/utf.c b/utf.c index d699ccf1..19e4be51 100644 --- a/utf.c +++ b/utf.c @@ -3197,18 +3197,30 @@ static C_char *utf8_decode(C_char *buf, C_u32 *c, int *e) * shifted out. */ *c = (C_u32)(s[0] & masks[len]) << 18; - *c |= (C_u32)(s[1] & 0x3f) << 12; - *c |= (C_u32)(s[2] & 0x3f) << 6; - *c |= (C_u32)(s[3] & 0x3f) << 0; + if (s[0] != '\0') { + *c |= (C_u32)(s[1] & 0x3f) << 12; + if (s[1] != '\0') { + *c |= (C_u32)(s[2] & 0x3f) << 6; + if (s[2] != '\0') { + *c |= (C_u32)(s[3] & 0x3f) << 0; + } + } + } *c >>= shiftc[len]; /* Accumulate the various error conditions. */ *e = (*c < mins[len]) << 6; // non-canonical encoding *e |= ((*c >> 11) == 0x1b) << 7; // surrogate half? *e |= (*c > 0x10FFFF) << 8; // out of range? - *e |= (s[1] & 0xc0) >> 2; - *e |= (s[2] & 0xc0) >> 4; - *e |= (s[3] ) >> 6; + if (s[0] != '\0') { + *e |= (s[1] & 0xc0) >> 2; + if (s[1] != '\0') { + *e |= (s[2] & 0xc0) >> 4; + if (s[2] != '\0') { + *e |= (s[3] ) >> 6; + } + } + } *e ^= 0x2a; // top two bits of each tail byte correct? *e >>= shifte[len];