$NetBSD: patch-ac,v 1.14 2009/11/10 23:31:36 asau Exp $

--- dyn_load.c.orig	2007-12-19 02:37:12.000000000 +0300
+++ dyn_load.c	2009-11-11 01:54:26.000000000 +0300
@@ -78,6 +78,8 @@
 #endif
 
 #if defined(NETBSD)
+#   include <sys/param.h>
+#   include <dlfcn.h>
 #   include <machine/elf_machdep.h>
 #   define ELFSIZE ARCH_ELFSIZE
 #endif
@@ -499,6 +501,15 @@
         return(0);
     }
     if( cachedResult == 0 ) {
+#if defined(NETBSD) && defined(RTLD_DI_LINKMAP)
+        struct link_map *lm = NULL;
+        int rv = dlinfo(RTLD_SELF, RTLD_DI_LINKMAP, &lm); 
+        if (rv != 0)
+            return (0);
+        if (lm == NULL)
+            return (0);
+        cachedResult = lm;
+#else  /* !(defined(NETBSD) && defined(RTLD_DI_LINKMAP)) */
         int tag;
         for( dp = _DYNAMIC; (tag = dp->d_tag) != 0; dp++ ) {
             if( tag == DT_DEBUG ) {
@@ -508,6 +519,7 @@
                 break;
             }
         }
+#endif /* !(defined(NETBSD) && __NetBSD_Version__ >= 599001900) */
     }
     return cachedResult;
 }
