[Gc] GC_enable_incremental() fails on FreeBSD

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Jul 16 12:46:59 PDT 2012

Hello list,

I have the following test case:

#include <gc.h>

int main()

    for (int i = 0; i < 1024; i++)
        void* mem = GC_malloc(sizeof(size_t) * 4);

This seems to consistently fail on FreeBSD:

$ ./a.out
Segfault at 0x631f90
Unexpected bus error or segmentation fault
Abort trap: 6 (core dumped)

This happens regardless of whether GC_INIT() is called before

GDB says:

(gdb) bt
#0  0x000000080085dbf8 in GC_FreeBSDGetDataStart () from
#1  0x000000080085dc69 in GC_register_data_segments () from
#2  0x000000080085c815 in GC_init_inner () from /usr/local/lib/libgc.so.1
#3  0x000000080085c965 in GC_enable_incremental () from
#4  0x000000000040074d in main ()

I don't have debug info here, so I just read the assembly:

0x000000080085dbf3 <GC_FreeBSDGetDataStart+83>:	mov    0x10(%rsp),%rax
0x000000080085dbf8 <GC_FreeBSDGetDataStart+88>:	movzbl (%rax),%eax ;
failing here
0x000000080085dbfb <GC_FreeBSDGetDataStart+91>:	mov    0x10(%rsp),%rax
0x000000080085dc00 <GC_FreeBSDGetDataStart+96>:	add    (%rsp),%rax

Which led me to this line:

os_dep.c:1922:            *(volatile char *)next_page;

It strikes me as odd, because a fault handler is set up just before
the attempt to read the memory.

Does anyone have a clue what might be breaking here?


$ uname -a
FreeBSD fbsd 9.0-RELEASE FreeBSD 9.0-RELEASE #0: Tue Jan  3 07:46:30
UTC 2012     root at farrell.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC
$ gcc -v
Using built-in specs.
Target: amd64-undermydesk-freebsd
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 4.2.1 20070831 patched [FreeBSD]

libgc version is 7.1.

Thanks in advance!


More information about the Gc mailing list