Currently libgc isn't used even when enabled, because NewAlloc.c
never includes SDCCglobl.h
(which defines OPT_ENABLE_LIBGC
).
I discovered this when using ldd
on the built binaries and noticing that none of them linked against libgc.
I decided to migrate all allocations and frees to newalloc because libgc cannot detect references stored inside memory allocated by the system C library:
WARNING: pointers inside memory allocated by the standard (system)
malloc
are not seen by the garbage collector. Thus objects pointed to only from such a region may be prematurely deallocated. It is thus suggested that the standardmalloc
be used only for memory regions, such as I/O buffers, that are guaranteed not to contain pointers to garbage collectible memory. Pointers in C language automatic, static, or register variables, are correctly recognized. (Note thatGC_malloc_uncollectable
has semantics similar to standard malloc, but allocates objects that are traced by the collector.)
To achieve this I also had to add a compile flag for support/util
, -DUTIL_USE_NEWALLOC
, so that it can be compiled with or without support.
Finally, I added a --enable-libgc
configure flag in debugger/mcs51
to match the top-level flag. I didn't regenerate configure because I have a different autoconf version than you do.
Does not introduce any new regressions, and can compile the standard library for all targets that are enabled by default.