ports/175233: GC does not scan static roots in shared object

hiroshi oota hirosho.oota+sp at firstclass.ddo.jp
Sat Jan 12 15:30:00 UTC 2013


>Number:         175233
>Category:       ports
>Synopsis:       GC does not scan static roots in shared object
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jan 12 15:30:00 UTC 2013
>Closed-Date:
>Last-Modified:
>Originator:     hiroshi oota
>Release:        10-current
>Organization:
>Environment:
FreeBSD aries 10.0-CURRENT FreeBSD 10.0-CURRENT #xxx r243674: Wed Jan  2 00:06:38 JST 2013     root@  amd64
>Description:
Bohem GC implements a scaning capability of static roots in shared object.
But, the method that enumerate shared objects is incorrent.
then no static roots will be scaned.

>How-To-Repeat:
execute the test program
$ cc -I/usr/local/include -L/usr/local/lib test.c -lgc
#include <sys/types.h>
#include <gc/gc.h>
int main(int ac, char **av)
{
    GC_register_dynamic_libraries();
    GC_print_static_roots();
    return 0;
}

$ ./a.out
Total size: 0 
no static roots in shared object.
>Fix:
--- dyn_load.c- 2013-01-07 11:47:37.692122307 +0900
+++ dyn_load.c  2013-01-11 17:58:07.623141180 +0900
@@ -88,6 +88,9 @@ static int (*GC_has_static_roots)(const
 #   include <stddef.h>
 #   include <elf.h>
 #   include <link.h>
+#if defined(FREEBSD)
+#   include <dlfcn.h>
+#endif
 #endif

 /* Newer versions of GNU/Linux define this macro.  We
@@ -497,6 +500,7 @@ extern ElfW(Dyn) _DYNAMIC[];

 static struct link_map *
 GC_FirstDLOpenedLinkMap()
+#if !defined(FREEBSD)
 {
     ElfW(Dyn) *dp;
     static struct link_map *cachedResult = 0;
@@ -517,7 +521,21 @@ GC_FirstDLOpenedLinkMap()
     }
     return cachedResult;
 }
-
+#else
+{
+    static struct link_map *cachedResult = 0;
+    if (cachedResult == 0) {
+       void *p;
+#undef dlopen
+       if ((p = dlopen(NULL, RTLD_NOW | RTLD_NOLOAD)) != NULL) {
+#define dlopen done!call!me
+           dlinfo(p, RTLD_DI_LINKMAP, &cachedResult);
+           dlclose(p);
+       }
+    }
+    return cachedResult;
+}
+#endif

 void GC_register_dynamic_libraries()
 {
@@ -541,7 +559,13 @@ void GC_register_dynamic_libraries()

        e = (ElfW(Ehdr) *) lm->l_addr;
         p = ((ElfW(Phdr) *)(((char *)(e)) + e->e_phoff));
+#if defined(FREEBSD)
+       if (lm == GC_FirstDLOpenedLinkMap())
+         offset = 0;
+       else
+#endif
         offset = ((unsigned long)(lm->l_addr));
+
         for( i = 0; i < (int)(e->e_phnum); ((i++),(p++)) ) {
           switch( p->p_type ) {
             case PT_LOAD:


>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-ports-bugs mailing list