[Gc] SIGSEGVs avoided by calling GC_expand_hp

Jan Stępień jan at stepien.cc
Sat Jan 8 10:49:11 PST 2011


Hi everyone,

During work on my thesis I've been developing a C application
which uses both the GC and GLib. I've encountered a problem which seems
to occur when a lot of small allocations are executed.

I'm on 32 bit GNU/Linux 2.6.35. I've configured gc-7.1 with
--disable-threads, --disable-cplusplus and --disable-shared and built a
static library. I've instructed GLib to use GC's allocation functions
instead of the ones from glibc and called GC_INIT before allocating
anything.

The SIGSEGV in GC_malloc_atomic is received at line malloc.c:225.

  *opp = obj_link(op);

After checking in gdb it appears that the op variable tends to have
small integer values lesser than 0xf00 which clearly aren't pointers.
Dereferencing them by obj_link causes a segfault.

A workaround I've found is to call GC_expand_hp right after calling
GC_INIT. I have to pass a really big value to solve the problem. For
instance after passing 1024L * 1024L the SIGSEGV is still received but
at mallocx.c:80 because of dereferencing a null pointer:

  sz = hhdr -> hb_sz;

Passing 1024L * 1024L * 1024L to GC_expand_hp solves the problem but
causes the program to use huge amounts of memory.

I've tried to link the target program with libgc.a both statically and
dynamically by creating a shared library which is statically linked
with libgc.a. It didn't help.

Are you aware of such kind of problems? I'd be really grateful for help
in solving this issue.

Best regards,
-- 
Jan Stępień <jan at stepien.cc>


More information about the Gc mailing list