Menu

#480 Patch to fix libgc usage

open
nobody
None
5
2024-10-12
2024-10-12
No

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 standard malloc 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 that GC_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.

1 Attachments

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.