Jan Kratochvil 1bcf9b6
gdb:
Jan Kratochvil 1bcf9b6
https://bugzilla.redhat.com/show_bug.cgi?id=623749
Jan Kratochvil 1bcf9b6
kernel:
Jan Kratochvil 1bcf9b6
https://bugzilla.redhat.com/show_bug.cgi?id=636937
Jan Kratochvil 1bcf9b6
Jan Kratochvil 1bcf9b6
http://sourceware.org/ml/gdb-patches/2010-09/msg00395.html
Jan Kratochvil 1bcf9b6
Subject: Re: [patch] Fix gcore writer for -Wl,-z,relro (PR corefiles/11804)
Jan Kratochvil 1bcf9b6
Jan Kratochvil 1bcf9b6
gdb/testsuite/
Jan Kratochvil 1bcf9b6
2010-09-22  Jan Kratochvil  <jan.kratochvil@redhat.com>
Jan Kratochvil 1bcf9b6
Jan Kratochvil 1bcf9b6
	Fix gcore writer for -Wl,-z,relro.
Jan Kratochvil 1bcf9b6
	* gdb.base/gcore-relro.exp: New file.
Jan Kratochvil 1bcf9b6
	* gdb.base/gcore-relro-main.c: New file.
Jan Kratochvil 1bcf9b6
	* gdb.base/gcore-relro-lib.c: New file.
Jan Kratochvil 1bcf9b6
Jan Kratochvil 1bcf9b6
--- ./gdb/gcore.c	2010-09-23 20:14:56.000000000 +0200
Jan Kratochvil 1bcf9b6
+++ ./gdb/gcore.c	2010-09-23 20:37:56.000000000 +0200
Jan Kratochvil 1bcf9b6
@@ -401,6 +401,7 @@ gcore_create_callback (CORE_ADDR vaddr, 
Jan Kratochvil 1bcf9b6
 
Jan Kratochvil 1bcf9b6
   if (write == 0 && !solib_keep_data_in_core (vaddr, size))
Jan Kratochvil 1bcf9b6
     {
Jan Kratochvil 1bcf9b6
+#if 0 /* https://bugzilla.redhat.com/show_bug.cgi?id=636937  */
Jan Kratochvil 1bcf9b6
       /* See if this region of memory lies inside a known file on disk.
Jan Kratochvil 1bcf9b6
 	 If so, we can avoid copying its contents by clearing SEC_LOAD.  */
Jan Kratochvil 1bcf9b6
       struct objfile *objfile;
Jan Kratochvil 1bcf9b6
@@ -433,6 +434,7 @@ gcore_create_callback (CORE_ADDR vaddr, 
Jan Kratochvil 1bcf9b6
 	}
Jan Kratochvil 1bcf9b6
 
Jan Kratochvil 1bcf9b6
     keep:
Jan Kratochvil 1bcf9b6
+#endif
Jan Kratochvil 1bcf9b6
       flags |= SEC_READONLY;
Jan Kratochvil 1bcf9b6
     }
Jan Kratochvil 1bcf9b6
 
Jan Kratochvil 1bcf9b6
--- /dev/null
Jan Kratochvil 1bcf9b6
+++ b/gdb/testsuite/gdb.base/gcore-relro-lib.c
Jan Kratochvil 1bcf9b6
@@ -0,0 +1,21 @@
Jan Kratochvil 1bcf9b6
+/* Copyright 2010 Free Software Foundation, Inc.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This file is part of GDB.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This program is free software; you can redistribute it and/or modify
Jan Kratochvil 1bcf9b6
+   it under the terms of the GNU General Public License as published by
Jan Kratochvil 1bcf9b6
+   the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 1bcf9b6
+   (at your option) any later version.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This program is distributed in the hope that it will be useful,
Jan Kratochvil 1bcf9b6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 1bcf9b6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 1bcf9b6
+   GNU General Public License for more details.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   You should have received a copy of the GNU General Public License
Jan Kratochvil 1bcf9b6
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+void
Jan Kratochvil 1bcf9b6
+lib (void)
Jan Kratochvil 1bcf9b6
+{
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
--- /dev/null
Jan Kratochvil 1bcf9b6
+++ b/gdb/testsuite/gdb.base/gcore-relro-main.c
Jan Kratochvil 1bcf9b6
@@ -0,0 +1,25 @@
Jan Kratochvil 1bcf9b6
+/* Copyright 2010 Free Software Foundation, Inc.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This file is part of GDB.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This program is free software; you can redistribute it and/or modify
Jan Kratochvil 1bcf9b6
+   it under the terms of the GNU General Public License as published by
Jan Kratochvil 1bcf9b6
+   the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 1bcf9b6
+   (at your option) any later version.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   This program is distributed in the hope that it will be useful,
Jan Kratochvil 1bcf9b6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 1bcf9b6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 1bcf9b6
+   GNU General Public License for more details.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+   You should have received a copy of the GNU General Public License
Jan Kratochvil 1bcf9b6
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+extern void lib (void);
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+int
Jan Kratochvil 1bcf9b6
+main (void)
Jan Kratochvil 1bcf9b6
+{
Jan Kratochvil 1bcf9b6
+  lib ();
Jan Kratochvil 1bcf9b6
+  return 0;
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
--- /dev/null
Jan Kratochvil 1bcf9b6
+++ b/gdb/testsuite/gdb.base/gcore-relro.exp
Jan Kratochvil 1bcf9b6
@@ -0,0 +1,80 @@
Jan Kratochvil 1bcf9b6
+# Copyright 2010 Free Software Foundation, Inc.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+# This program is free software; you can redistribute it and/or modify
Jan Kratochvil 1bcf9b6
+# it under the terms of the GNU General Public License as published by
Jan Kratochvil 1bcf9b6
+# the Free Software Foundation; either version 3 of the License, or
Jan Kratochvil 1bcf9b6
+# (at your option) any later version.
Jan Kratochvil 1bcf9b6
+#
Jan Kratochvil 1bcf9b6
+# This program is distributed in the hope that it will be useful,
Jan Kratochvil 1bcf9b6
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
Jan Kratochvil 1bcf9b6
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Jan Kratochvil 1bcf9b6
+# GNU General Public License for more details.
Jan Kratochvil 1bcf9b6
+#
Jan Kratochvil 1bcf9b6
+# You should have received a copy of the GNU General Public License
Jan Kratochvil 1bcf9b6
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+if {[skip_shlib_tests]} {
Jan Kratochvil 1bcf9b6
+    return 0
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+set testfile "gcore-relro"
Jan Kratochvil 1bcf9b6
+set srcmainfile ${testfile}-main.c
Jan Kratochvil 1bcf9b6
+set srclibfile ${testfile}-lib.c
Jan Kratochvil 1bcf9b6
+set libfile ${objdir}/${subdir}/${testfile}-lib.so
Jan Kratochvil 1bcf9b6
+set objfile ${objdir}/${subdir}/${testfile}-main.o
Jan Kratochvil 1bcf9b6
+set executable ${testfile}-main
Jan Kratochvil 1bcf9b6
+set binfile ${objdir}/${subdir}/${executable}
Jan Kratochvil 1bcf9b6
+set gcorefile ${objdir}/${subdir}/${executable}.gcore
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+if { [gdb_compile_shlib ${srcdir}/${subdir}/${srclibfile} ${libfile} {debug}] != ""
Jan Kratochvil 1bcf9b6
+     || [gdb_compile ${srcdir}/${subdir}/${srcmainfile} ${objfile} object {debug}] != "" } {
Jan Kratochvil 1bcf9b6
+     untested ${testfile}.exp
Jan Kratochvil 1bcf9b6
+     return -1
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+set opts [list debug shlib=${libfile} additional_flags=-Wl,-z,relro]
Jan Kratochvil 1bcf9b6
+if { [gdb_compile ${objfile} ${binfile} executable $opts] != "" } {
Jan Kratochvil 1bcf9b6
+     unsupported "-Wl,-z,relro compilation failed"
Jan Kratochvil 1bcf9b6
+     return -1
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+clean_restart $executable
Jan Kratochvil 1bcf9b6
+gdb_load_shlibs $libfile
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+# Does this gdb support gcore?
Jan Kratochvil 1bcf9b6
+set test "help gcore"
Jan Kratochvil 1bcf9b6
+gdb_test_multiple $test $test {
Jan Kratochvil 1bcf9b6
+    -re "Undefined command: .gcore.*\r\n$gdb_prompt $" {
Jan Kratochvil 1bcf9b6
+	# gcore command not supported -- nothing to test here.
Jan Kratochvil 1bcf9b6
+	unsupported "gdb does not support gcore on this target"
Jan Kratochvil 1bcf9b6
+	return -1;
Jan Kratochvil 1bcf9b6
+    }
Jan Kratochvil 1bcf9b6
+    -re "Save a core file .*\r\n$gdb_prompt $" {
Jan Kratochvil 1bcf9b6
+	pass $test
Jan Kratochvil 1bcf9b6
+    }
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+if { ![runto lib] } then {
Jan Kratochvil 1bcf9b6
+    return -1
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+set escapedfilename [string_to_regexp ${gcorefile}]
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+set test "save a corefile"
Jan Kratochvil 1bcf9b6
+gdb_test_multiple "gcore ${gcorefile}" $test {
Jan Kratochvil 1bcf9b6
+    -re "Saved corefile ${escapedfilename}\r\n$gdb_prompt $" {
Jan Kratochvil 1bcf9b6
+	pass $test
Jan Kratochvil 1bcf9b6
+    }
Jan Kratochvil 1bcf9b6
+    -re "Can't create a corefile\r\n$gdb_prompt $" {
Jan Kratochvil 1bcf9b6
+	unsupported $test
Jan Kratochvil 1bcf9b6
+	return -1
Jan Kratochvil 1bcf9b6
+    }
Jan Kratochvil 1bcf9b6
+}
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+# Now restart gdb and load the corefile.
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+clean_restart $executable
Jan Kratochvil 1bcf9b6
+gdb_load_shlibs $libfile
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+gdb_test "core ${gcorefile}" "Core was generated by .*" "re-load generated corefile"
Jan Kratochvil 1bcf9b6
+
Jan Kratochvil 1bcf9b6
+gdb_test "frame" "#0 \[^\r\n\]* lib .*" "library got loaded"