Jan Kratochvil 3d3c8f2
--- gdb-7.4.50.20120120/gdb/solib-svr4.c.orig	2012-03-17 10:23:11.000000000 +0100
Jan Kratochvil 3d3c8f2
+++ gdb-7.4.50.20120120/gdb/solib-svr4.c	2012-03-17 10:36:22.265628529 +0100
Jan Kratochvil 3d3c8f2
@@ -1228,14 +1228,27 @@ svr4_read_so_list (CORE_ADDR lm, struct
Jan Kratochvil 3d3c8f2
 	}
Jan Kratochvil 3d3c8f2
 
Jan Kratochvil 3d3c8f2
       {
Jan Kratochvil 3d3c8f2
-	struct build_id *build_id;
Jan Kratochvil 3d3c8f2
+	struct build_id *build_id = NULL;
Jan Kratochvil 3d3c8f2
 
Jan Kratochvil 3d3c8f2
 	strncpy (new->so_original_name, buffer, SO_NAME_MAX_PATH_SIZE - 1);
Jan Kratochvil 3d3c8f2
 	new->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
Jan Kratochvil 3d3c8f2
 	/* May get overwritten below.  */
Jan Kratochvil 3d3c8f2
 	strcpy (new->so_name, new->so_original_name);
Jan Kratochvil 3d3c8f2
 
Jan Kratochvil 3d3c8f2
-	build_id = build_id_addr_get (new->lm_info->l_ld);
Jan Kratochvil 3d3c8f2
+	/* In the case the main executable was found according to its build-id
Jan Kratochvil 3d3c8f2
+	   (from a core file) prevent loading a different build of a library
Jan Kratochvil 3d3c8f2
+	   with accidentally the same SO_NAME.
Jan Kratochvil 3d3c8f2
+
Jan Kratochvil 3d3c8f2
+	   It suppresses bogus backtraces (and prints "??" there instead) if
Jan Kratochvil 3d3c8f2
+	   the on-disk files no longer match the running program version.
Jan Kratochvil 3d3c8f2
+
Jan Kratochvil 3d3c8f2
+	   If the main executable was not loaded according to its build-id do
Jan Kratochvil 3d3c8f2
+	   not do any build-id checking of the libraries.  There may be missing
Jan Kratochvil 3d3c8f2
+	   build-ids dumped in the core file and we would map all the libraries
Jan Kratochvil 3d3c8f2
+	   to the only existing file loaded that time - the executable.  */
Jan Kratochvil 3d3c8f2
+	if (symfile_objfile != NULL
Jan Kratochvil 3d3c8f2
+	    && (symfile_objfile->flags & OBJF_BUILD_ID_CORE_LOADED) != 0)
Jan Kratochvil 3d3c8f2
+	  build_id = build_id_addr_get (new->lm_info->l_ld);
Jan Kratochvil 3d3c8f2
 	if (build_id != NULL)
Jan Kratochvil 3d3c8f2
 	  {
Jan Kratochvil 3d3c8f2
 	    char *name, *build_id_filename;
Jan Kratochvil 3d3c8f2
@@ -1250,23 +1263,7 @@ svr4_read_so_list (CORE_ADDR lm, struct
Jan Kratochvil 3d3c8f2
 		xfree (name);
Jan Kratochvil 3d3c8f2
 	      }
Jan Kratochvil 3d3c8f2
 	    else
Jan Kratochvil 3d3c8f2
-	      {
Jan Kratochvil 3d3c8f2
-		debug_print_missing (new->so_name, build_id_filename);
Jan Kratochvil 3d3c8f2
-
Jan Kratochvil 3d3c8f2
-		/* In the case the main executable was found according to
Jan Kratochvil 3d3c8f2
-		   its build-id (from a core file) prevent loading
Jan Kratochvil 3d3c8f2
-		   a different build of a library with accidentally the
Jan Kratochvil 3d3c8f2
-		   same SO_NAME.
Jan Kratochvil 3d3c8f2
-
Jan Kratochvil 3d3c8f2
-		   It suppresses bogus backtraces (and prints "??" there
Jan Kratochvil 3d3c8f2
-		   instead) if the on-disk files no longer match the
Jan Kratochvil 3d3c8f2
-		   running program version.  */
Jan Kratochvil 3d3c8f2
-
Jan Kratochvil 3d3c8f2
-		if (symfile_objfile != NULL
Jan Kratochvil 3d3c8f2
-		    && (symfile_objfile->flags
Jan Kratochvil 3d3c8f2
-			& OBJF_BUILD_ID_CORE_LOADED) != 0)
Jan Kratochvil 3d3c8f2
-		  new->so_name[0] = 0;
Jan Kratochvil 3d3c8f2
-	      }
Jan Kratochvil 3d3c8f2
+	      debug_print_missing (new->so_name, build_id_filename);
Jan Kratochvil 3d3c8f2
 
Jan Kratochvil 3d3c8f2
 	    xfree (build_id_filename);
Jan Kratochvil 3d3c8f2
 	    xfree (build_id);