-diff -ru glibc-2.5-ORIG/elf/dl-load.c glibc-2.5/elf/dl-load.c
---- glibc-2.5-ORIG/elf/dl-load.c	2007-09-25 17:20:30.000000000 +0300
-+++ glibc-2.5/elf/dl-load.c	2009-10-22 15:00:02.000000000 +0300
+--- a/elf/dl-load.c	2007-09-25 17:20:30.000000000 +0300
++++ b/elf/dl-load.c	2009-11-17 16:12:20.000000000 +0200
 @@ -388,7 +388,8 @@
  
  static struct r_search_path_elem **

 /* The map for the object we will profile.  */
 struct link_map *_dl_profile_map;
 
diff -ru glibc-2.5-ORIG/elf/rtld.c glibc-2.5/elf/rtld.c
--- glibc-2.5-ORIG/elf/rtld.c	2009-10-22 14:40:05.000000000 +0300
+++ glibc-2.5/elf/rtld.c	2009-10-22 14:50:47.000000000 +0300
@@ -951,6 +951,15 @@
 	    _dl_argc -= 2;
 	    INTUSE(_dl_argv) += 2;

 {
   char *cp;
   size_t nelems = 0;
@@ -445,9 +445,23 @@
 	}
 
       /* See if this directory is already known.  */
-      for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
-	if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
-	  break;
+      if (__builtin_expect (rpath_prefix != NULL, 0))
+	{
+	  /* has rpath_prefix */
+	  size_t rpath_prefix_len = strlen (rpath_prefix);
+
+	  for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
+	    if (dirp->dirnamelen == (rpath_prefix_len+len) &&
+		(memcmp (cp, rpath_prefix, rpath_prefix_len) == 0) &&
+		(memcmp (cp+rpath_prefix_len, dirp->dirname, len) == 0))
+	      break;
+	}
+      else
+	{
+	  for (dirp = GL(dl_all_dirs); dirp != NULL; dirp = dirp->next)
+	    if (dirp->dirnamelen == len && memcmp (cp, dirp->dirname, len) == 0)
+	      break;
+	}
 
       if (dirp != NULL)
 	{
@@ -464,22 +465,43 @@
 	  size_t cnt;
 	  enum r_dir_status init_val;
