[Gc] Dealing with `.data.rel.ro'

Ludovic Courtès ludo at gnu.org
Sun Feb 1 13:27:41 PST 2009


I was wondering whether GC was able to somehow be aware of
`.data.rel.ro' sections on GNU systems [0], or whether it was able to
unregister the corresponding memory region when the loader mprotects
them.  A quick look at `os_dep.c' suggests that GC isn't able to deal
with this, is that right?

The following example seems to suggest that even the `.rodata' section
of a library is registered as a static root.  Suppose the following

  #include <gc/gc.h>
  #include <stdio.h>

  extern const char *const my_const_data[];

  main (int argc, char *argv[])
    GC_INIT ();

    GC_gcollect ();
    GC_dump ();
    printf ("%p--%p\n", my_const_data, &my_const_data[1000000]);

    return 0;

Suppose this program is linked with `libfoo.so' (compiled with "-shared
-fPIC"), which contains this:

  const char *const my_const_data[1000000] = { 0 };  /* in `.rodata' */

Looking at the output of `GC_dump ()', it appears that the region
containing `my_const_data' is indeed registered as a static root.  Am I
missing something?


[0] https://www.airs.com/blog/archives/189

More information about the Gc mailing list