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

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