Question

I have some code that looks like this:

__attribute__((section("__DATA,__mysection"))) char *mumble;

...

mumble = GC_MALLOC(100);
...

I'm using the Boehm garbage collector. I would expect the data that mumble points to to be safe, since it's still live. But in fact, it is collected and reused. I checked GC_print_static_roots(): it appears that the entire __mysection section is not contained in any of the roots.

(I did find a solution to this -- but does anyone have any simpler ideas?)

Was it helpful?

Solution

You'll need these globals:

extern char __first_mysection __asm("section$start$__DATA$__mysection");
extern char __last_mysection  __asm("section$end$__DATA$__mysection");

Immediately after GC_INIT(), call the following function: GC_add_roots(&__first_mysection, &__last_mysection_p+1);

Then everything will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top