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

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