$NetBSD: patch-ag,v 1.5 2005/07/31 15:26:58 recht Exp $ --- libgc/dyn_load.c.orig 2005-04-11 16:12:45.000000000 +0200 +++ libgc/dyn_load.c @@ -70,6 +70,12 @@ # include # include #endif + +#ifdef NETBSD +#include +#include +#endif + #ifdef SUNOS4 # include # include @@ -509,6 +515,31 @@ GC_FirstDLOpenedLinkMap() break; } } + +#if defined(NETBSD) +#undef dlopen +#undef dlsym +#undef dlclose + /* This is a hack. For now, it seems that NetBSD 2.0 does not provide + a _DYNAMIC with the neccessary DT_DEBUG information. A simple dlopen(0, RTLD_LAZY) + does the job. Maybe a NetBSD guru could explain this... + */ + if(cachedResult == 0) { + void* startupSyms = dlopen(0, RTLD_LAZY); + dp = (ElfW(Dyn)*)dlsym(startupSyms, "_DYNAMIC"); + + for(; (tag = dp->d_tag) != 0; dp++ ) { + if( tag == DT_DEBUG ) { + struct link_map *lm + = ((struct r_debug *)(dp->d_un.d_ptr))->r_map; + if( lm != 0 ) cachedResult = lm->l_next; /* might be NIL */ + break; + } + } + + dlclose(startupSyms); + } +#endif } return cachedResult; }