ldconfig: be more conservative when removing stale symlinks:
* Only do so if the referenced file does not exist, not if there was some
  other error accessing it.
* Never remove symlinks if the -X option was given.

References:
* https://sourceware.org/bugzilla/show_bug.cgi?id=16871
* https://bugs.gentoo.org/show_bug.cgi?id=508052

Index: glibc-2.19/elf/ldconfig.c
===================================================================
--- glibc-2.19.orig/elf/ldconfig.c
+++ glibc-2.19/elf/ldconfig.c
@@ -800,7 +800,7 @@ search_dir (const struct dir_entry *entr
 		error (0, errno, _("Cannot stat %s"), file_name);
 
 	      /* Remove stale symlinks.  */
-	      if (strstr (direntry->d_name, ".so."))
+	      if (errno == ENOENT && do_remove && strstr (direntry->d_name, ".so."))
 		unlink (real_file_name);
 	      continue;
 	    }