Blame SOURCES/gdb-6.6-buildid-locate-solib-missing-ids.patch

a1b30c
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
a1b30c
From: Fedora GDB patches <invalid@email.com>
a1b30c
Date: Fri, 27 Oct 2017 21:07:50 +0200
a1b30c
Subject: gdb-6.6-buildid-locate-solib-missing-ids.patch
a1b30c
a1b30c
;; Fix loading of core files without build-ids but with build-ids in executables.
a1b30c
;; Load strictly build-id-checked core files only if no executable is specified
a1b30c
;; (Jan Kratochvil, RH BZ 1339862).
a1b30c
;;=push+jan
a1b30c
a1b30c
gdb returns an incorrect back trace when applying a debuginfo
a1b30c
https://bugzilla.redhat.com/show_bug.cgi?id=1339862
a1b30c
a1b30c
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
a1b30c
--- a/gdb/solib-svr4.c
a1b30c
+++ b/gdb/solib-svr4.c
a1b30c
@@ -1350,14 +1350,28 @@ svr4_read_so_list (svr4_info *info, CORE_ADDR lm, CORE_ADDR prev_lm,
a1b30c
 	}
a1b30c
 
a1b30c
       {
a1b30c
-	struct bfd_build_id *build_id;
a1b30c
+	struct bfd_build_id *build_id = NULL;
a1b30c
 
a1b30c
 	strncpy (newobj->so_original_name, buffer.get (), SO_NAME_MAX_PATH_SIZE - 1);
a1b30c
 	newobj->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0';
a1b30c
 	/* May get overwritten below.  */
a1b30c
 	strcpy (newobj->so_name, newobj->so_original_name);
a1b30c
 
a1b30c
-	build_id = build_id_addr_get (((lm_info_svr4 *) newobj->lm_info)->l_ld);
a1b30c
+	/* In the case the main executable was found according to its build-id
a1b30c
+	   (from a core file) prevent loading a different build of a library
a1b30c
+	   with accidentally the same SO_NAME.
a1b30c
+
a1b30c
+	   It suppresses bogus backtraces (and prints "??" there instead) if
a1b30c
+	   the on-disk files no longer match the running program version.
a1b30c
+
a1b30c
+	   If the main executable was not loaded according to its build-id do
a1b30c
+	   not do any build-id checking of the libraries.  There may be missing
a1b30c
+	   build-ids dumped in the core file and we would map all the libraries
a1b30c
+	   to the only existing file loaded that time - the executable.  */
a1b30c
+	if (current_program_space->symfile_object_file != NULL
a1b30c
+	    && (current_program_space->symfile_object_file->flags
a1b30c
+	         & OBJF_BUILD_ID_CORE_LOADED) != 0)
a1b30c
+	  build_id = build_id_addr_get (li->l_ld);
a1b30c
 	if (build_id != NULL)
a1b30c
 	  {
a1b30c
 	    char *name, *build_id_filename;
a1b30c
@@ -1372,23 +1386,7 @@ svr4_read_so_list (svr4_info *info, CORE_ADDR lm, CORE_ADDR prev_lm,
a1b30c
 		xfree (name);
a1b30c
 	      }
a1b30c
 	    else
a1b30c
-	      {
a1b30c
-		debug_print_missing (newobj->so_name, build_id_filename);
a1b30c
-
a1b30c
-		/* In the case the main executable was found according to
a1b30c
-		   its build-id (from a core file) prevent loading
a1b30c
-		   a different build of a library with accidentally the
a1b30c
-		   same SO_NAME.
a1b30c
-
a1b30c
-		   It suppresses bogus backtraces (and prints "??" there
a1b30c
-		   instead) if the on-disk files no longer match the
a1b30c
-		   running program version.  */
a1b30c
-
a1b30c
-		if (current_program_space->symfile_object_file != NULL
a1b30c
-		    && (current_program_space->symfile_object_file->flags
a1b30c
-			& OBJF_BUILD_ID_CORE_LOADED) != 0)
a1b30c
-		  newobj->so_name[0] = 0;
a1b30c
-	      }
a1b30c
+	      debug_print_missing (newobj->so_name, build_id_filename);
a1b30c
 
a1b30c
 	    xfree (build_id_filename);
a1b30c
 	    xfree (build_id);
a1b30c
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
a1b30c
new file mode 100644
a1b30c
--- /dev/null
a1b30c
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-lib.c
a1b30c
@@ -0,0 +1,21 @@
a1b30c
+/* Copyright 2010 Free Software Foundation, Inc.
a1b30c
+
a1b30c
+   This file is part of GDB.
a1b30c
+
a1b30c
+   This program is free software; you can redistribute it and/or modify
a1b30c
+   it under the terms of the GNU General Public License as published by
a1b30c
+   the Free Software Foundation; either version 3 of the License, or
a1b30c
+   (at your option) any later version.
a1b30c
+
a1b30c
+   This program is distributed in the hope that it will be useful,
a1b30c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a1b30c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a1b30c
+   GNU General Public License for more details.
a1b30c
+
a1b30c
+   You should have received a copy of the GNU General Public License
a1b30c
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
a1b30c
+
a1b30c
+void
a1b30c
+lib (void)
a1b30c
+{
a1b30c
+}
a1b30c
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
a1b30c
new file mode 100644
a1b30c
--- /dev/null
a1b30c
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib-main.c
a1b30c
@@ -0,0 +1,25 @@
a1b30c
+/* Copyright 2010 Free Software Foundation, Inc.
a1b30c
+
a1b30c
+   This file is part of GDB.
a1b30c
+
a1b30c
+   This program is free software; you can redistribute it and/or modify
a1b30c
+   it under the terms of the GNU General Public License as published by
a1b30c
+   the Free Software Foundation; either version 3 of the License, or
a1b30c
+   (at your option) any later version.
a1b30c
+
a1b30c
+   This program is distributed in the hope that it will be useful,
a1b30c
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
a1b30c
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a1b30c
+   GNU General Public License for more details.
a1b30c
+
a1b30c
+   You should have received a copy of the GNU General Public License
a1b30c
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
a1b30c
+
a1b30c
+extern void lib (void);
a1b30c
+
a1b30c
+int
a1b30c
+main (void)
a1b30c
+{
a1b30c
+  lib ();
a1b30c
+  return 0;
a1b30c
+}
a1b30c
diff --git a/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
a1b30c
new file mode 100644
a1b30c
--- /dev/null
a1b30c
+++ b/gdb/testsuite/gdb.base/gcore-buildid-exec-but-not-solib.exp
a1b30c
@@ -0,0 +1,105 @@
a1b30c
+# Copyright 2016 Free Software Foundation, Inc.
a1b30c
+
a1b30c
+# This program is free software; you can redistribute it and/or modify
a1b30c
+# it under the terms of the GNU General Public License as published by
a1b30c
+# the Free Software Foundation; either version 3 of the License, or
a1b30c
+# (at your option) any later version.
a1b30c
+#
a1b30c
+# This program is distributed in the hope that it will be useful,
a1b30c
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
a1b30c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a1b30c
+# GNU General Public License for more details.
a1b30c
+#
a1b30c
+# You should have received a copy of the GNU General Public License
a1b30c
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
a1b30c
+
a1b30c
+if {[skip_shlib_tests]} {
a1b30c
+    return 0
a1b30c
+}
a1b30c
+
a1b30c
+set testfile "gcore-buildid-exec-but-not-solib"
a1b30c
+set srcmainfile ${testfile}-main.c
a1b30c
+set srclibfile ${testfile}-lib.c
a1b30c
+set libfile [standard_output_file ${testfile}-lib.so]
a1b30c
+set objfile [standard_output_file ${testfile}-main.o]
a1b30c
+set executable ${testfile}-main
a1b30c
+set binfile [standard_output_file ${executable}]
a1b30c
+set gcorefile [standard_output_file ${executable}.gcore]
a1b30c
+set outdir [file dirname $binfile]
a1b30c
+
a1b30c
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} "debug additional_flags=-Wl,--build-id"] != ""
a1b30c
+     || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
a1b30c
+     unsupported "-Wl,--build-id compilation failed"
a1b30c
+     return -1
a1b30c
+}
a1b30c
+set opts [list debug shlib=${libfile} "additional_flags=-Wl,--build-id"]
a1b30c
+if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
a1b30c
+     unsupported "-Wl,--build-id compilation failed"
a1b30c
+     return -1
a1b30c
+}
a1b30c
+
a1b30c
+clean_restart $executable
a1b30c
+gdb_load_shlib $libfile
a1b30c
+
a1b30c
+# Does this gdb support gcore?
a1b30c
+set test "help gcore"
a1b30c
+gdb_test_multiple $test $test {
a1b30c
+    -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
a1b30c
+	# gcore command not supported -- nothing to test here.
a1b30c
+	unsupported "gdb does not support gcore on this target"
a1b30c
+	return -1;
a1b30c
+    }
a1b30c
+    -re "Save a core file .*\r\n$gdb_prompt $" {
a1b30c
+	pass $test
a1b30c
+    }
a1b30c
+}
a1b30c
+
a1b30c
+if { ![runto lib] } then {
a1b30c
+    return -1
a1b30c
+}
a1b30c
+
a1b30c
+set escapedfilename [string_to_regexp ${gcorefile}]
a1b30c
+
a1b30c
+set test "save a corefile"
a1b30c
+gdb_test_multiple "gcore ${gcorefile}" $test {
a1b30c
+    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
a1b30c
+	pass $test
a1b30c
+    }
a1b30c
+    -re "Can't create a corefile\r\n$gdb_prompt $" {
a1b30c
+	unsupported $test
a1b30c
+	return -1
a1b30c
+    }
a1b30c
+}
a1b30c
+
a1b30c
+# Now restart gdb and load the corefile.
a1b30c
+
a1b30c
+clean_restart $executable
a1b30c
+gdb_load_shlib $libfile
a1b30c
+
a1b30c
+set buildid [build_id_debug_filename_get $libfile]
a1b30c
+
a1b30c
+regsub {\.debug$} $buildid {} buildid
a1b30c
+
a1b30c
+set debugdir [standard_output_file ${testfile}-debugdir]
a1b30c
+file delete -force -- $debugdir
a1b30c
+
a1b30c
+file mkdir $debugdir/[file dirname $libfile]
a1b30c
+file copy $libfile $debugdir/${libfile}
a1b30c
+
a1b30c
+file mkdir $debugdir/[file dirname $buildid]
a1b30c
+file copy $libfile $debugdir/${buildid}
a1b30c
+
a1b30c
+remote_exec build "ln -s /lib       ${debugdir}/"
a1b30c
+remote_exec build "ln -s /lib64     ${debugdir}/"
a1b30c
+# /usr is not needed, all the libs are in /lib64: libm.so.6 libc.so.6 ld-linux-x86-64.so.2
a1b30c
+
a1b30c
+gdb_test "set solib-absolute-prefix $debugdir"
a1b30c
+
a1b30c
+gdb_test_no_output "set debug-file-directory $debugdir" "set debug-file-directory"
a1b30c
+
a1b30c
+gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
a1b30c
+
a1b30c
+gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"
a1b30c
+
a1b30c
+gdb_test "bt"
a1b30c
+gdb_test "info shared"