[issue1525] boehm-gc problems

Jordan Gordeev jgordeev at dir.bg
Mon Sep 28 09:15:34 PDT 2009

I'll summarize what I've learned so far.
Boehm GC is a mark-sweep garbage collector.
The crashes and the hangs happen because the GC garbage collects its own 
internal data structures.
How could this happen?! Easy.
The mark procedure starts marking objects as reachable beginning from a 
number of root regions, which include, but are not limited to, the 
program's global data area and the global data areas of dynamically 
loaded libraries. Unfortunately, on DragonFly, the latter part doesn't 
work as intended. So, the garbage collector, which itself is a 
dynamically loaded library, doesn't mark its own data structures, and 
the sweeper frees the memory they occupy.
In the source code of the GC, functions of interest are 
GC_add_roots_inner() in mark_rts.c and GC_FirstDLOpenedLinkMap(), 
starting at line 493, in dyn_load.c.
GC_add_roots_inner() should get called once for the main executable and 
for each dynamic library loaded.
In GC_FirstDLOpenedLinkMap() we start from _DYNAMIC and in a loop try to 
find a Elf_Dyn entry with tag DT_DEBUG.
On DragonFly, the main executable has such an entry, however when 
GC_FirstDLOpenedLinkMap() iterates over the list it seems to iterate 
over the list of entries of libgc - a dynamic library which lacks 
DT_DEBUG entries in its .dynamic section. The DT_DEBUG entry we are 
looking for isn't found.
On FreeBSD, when we iterate over the list, we get a list of tags that is 
a prefix of the tags of the main executable.
The tags on the main executable:
1 1 1 15 12 13 4 5 6 10 11 21 20 23 17 18 19 0x6ffffffe 0x6fffffff 
What we get:
1 1 1 15 12 13 4 5 6 10 11 21

I'm leaving this problem report for now, to let my head recover.
If you've got any ideas, please let me know.
Here's some less important stuff:
And now, to see how well FreeBSD fares. Building the Boehm GC on FreeBSD 
7.1 and running 'gmake check' produces:
Boehm GC version 6.8 built from ports:
FAIL: gctest
PASS: test_cpp
1 of 2 tests failed
Please report to Hans.Boehm at hp.com

Boehm GC version 6.8 built manually:
PASS: gctest
All 1 tests passed
Boehm GC version 7.1 built manually:
PASS: gctest
PASS: leaktest
PASS: middletest
PASS: smashtest
PASS: hugetest
PASS: threadleaktest
All 6 tests passed

More information about the Bugs mailing list