Blame SOURCES/gdb-tls-2of2.patch

e1d87d
http://sourceware.org/ml/gdb-patches/2016-10/msg00207.html
e1d87d
Subject: [patch+7.12.1 2/2] Fix TLS (such as 'errno') regression
e1d87d
e1d87d
e1d87d
--3Pql8miugIZX0722
e1d87d
Content-Type: text/plain; charset=us-ascii
e1d87d
Content-Disposition: inline
e1d87d
e1d87d
Hi,
e1d87d
e1d87d
2273f0ac95a79ce29ef42025c63f90e82cf907d7 is the first bad commit
e1d87d
commit 2273f0ac95a79ce29ef42025c63f90e82cf907d7
e1d87d
Author: Tom Tromey <tromey@redhat.com>
e1d87d
Date:   Tue Oct 15 13:28:57 2013 -0600
e1d87d
    change minsyms not to be relocated at read-time
e1d87d
[FYI v3 06/10] change minsyms not to be relocated at read-time
e1d87d
Message-Id: <1393441273-32268-7-git-send-email-tromey@redhat.com>
e1d87d
https://sourceware.org/ml/gdb-patches/2014-02/msg00798.html
e1d87d
e1d87d
mv /usr/lib/debug /usr/lib/debug-x
e1d87d
echo 'int main(){}'|gcc -pthread -x c -
e1d87d
./gdb -q -ex start -ex 'set debug expr 1' -ex 'p errno' ./a.out 
e1d87d
	    0  UNOP_MEMVAL_TLS       TLS type @0x35df7e0 (__thread /* "/lib64/libc.so.6" */ <thread local variable, no debug info>)
e1d87d
	    4    OP_LONG               Type @0x35df850 (__CORE_ADDR), value 140737345728528 (0x7ffff77fb010)
e1d87d
Cannot access memory at address 0xffffef7c9698
e1d87d
->
e1d87d
	    0  UNOP_MEMVAL_TLS       TLS type @0x3ad9520 (__thread /* "/lib64/libc.so.6" */ <thread local variable, no debug info>)
e1d87d
	    4    OP_LONG               Type @0x3ad9590 (__CORE_ADDR), value 16 (0x10)
e1d87d
$1 = 0
e1d87d
e1d87d
With glibc debuginfo, that is without: mv /usr/lib/debug /usr/lib/debug-x
e1d87d
	    0  OP_VAR_VALUE          Block @0x3b30e70, symbol @0x3b30d10 (errno)
e1d87d
$1 = 0
e1d87d
So such case is unrelated to this patch and the regression is not visible with
e1d87d
glibc debuginfo installed.
e1d87d
e1d87d
I guess all these issues will be solved by Gary Benson's Infinity.
e1d87d
But at least for older non-Infinity glibcs GDB should not regress.
e1d87d
e1d87d
For the testcase it is important the variable is in objfile with non-zero base
e1d87d
address.  glibc is a shared library for 'errno' but I found easier for the
e1d87d
testcase to use PIE instead of a shlib.  For TLS variables in PT_EXEC the
e1d87d
regression obviously does not happen.
e1d87d
e1d87d
It has been found by a more complete testcase present in Fedora, the fix there
e1d87d
also solves more cases where FSF GDB currently cannot resolve 'errno':
e1d87d
	http://pkgs.fedoraproject.org/cgit/rpms/gdb.git/tree/gdb-6.5-bz185337-resolve-tls-without-debuginfo-v2.patch
e1d87d
	FAIL: gdb.dwarf2/dw2-errno2.exp: macros=N threads=Y: print errno for core
e1d87d
e1d87d
No regressions on {x86_64,x86_64-m32,i686}-fedora26pre-linux-gnu.
e1d87d
e1d87d
OK for check-in?
e1d87d
e1d87d
e1d87d
Thanks,
e1d87d
Jan
e1d87d
e1d87d
--3Pql8miugIZX0722
e1d87d
Content-Type: text/plain; charset=us-ascii
e1d87d
Content-Disposition: inline; filename="tls1-2.patch"
e1d87d
e1d87d
gdb/ChangeLog
e1d87d
2016-10-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
e1d87d
e1d87d
	* parse.c (write_exp_msymbol): Fix ADDR computation.
e1d87d
e1d87d
gdb/testsuite/ChangeLog
e1d87d
2016-10-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
e1d87d
e1d87d
	* gdb.threads/tls-nodebug-pie.c: New file.
e1d87d
	* gdb.threads/tls-nodebug-pie.exp: New file.
e1d87d
e1d87d
--- a/gdb/parse.c
e1d87d
+++ b/gdb/parse.c
e1d87d
@@ -480,13 +480,17 @@ write_exp_msymbol (struct parser_state *ps,
e1d87d
   struct objfile *objfile = bound_msym.objfile;
e1d87d
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
e1d87d
 
e1d87d
-  CORE_ADDR addr = BMSYMBOL_VALUE_ADDRESS (bound_msym);
e1d87d
   struct obj_section *section = MSYMBOL_OBJ_SECTION (objfile, msymbol);
e1d87d
   enum minimal_symbol_type type = MSYMBOL_TYPE (msymbol);
e1d87d
-  CORE_ADDR pc;
e1d87d
+  CORE_ADDR addr, pc;
e1d87d
   const int is_tls = (section != NULL
e1d87d
 		      && section->the_bfd_section->flags & SEC_THREAD_LOCAL);
e1d87d
 
e1d87d
+  if (is_tls)
e1d87d
+    addr = MSYMBOL_VALUE_RAW_ADDRESS (bound_msym.minsym);
e1d87d
+  else
e1d87d
+    addr = BMSYMBOL_VALUE_ADDRESS (bound_msym);
e1d87d
+
e1d87d
   /* The minimal symbol might point to a function descriptor;
e1d87d
      resolve it to the actual code address instead.  */
e1d87d
   pc = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, &current_target);
e1d87d
--- /dev/null
e1d87d
+++ b/gdb/testsuite/gdb.threads/tls-nodebug-pie.c
e1d87d
@@ -0,0 +1,27 @@
e1d87d
+/* This testcase is part of GDB, the GNU debugger.
e1d87d
+
e1d87d
+   Copyright 2016 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+   This program is free software; you can redistribute it and/or modify
e1d87d
+   it under the terms of the GNU General Public License as published by
e1d87d
+   the Free Software Foundation; either version 3 of the License, or
e1d87d
+   (at your option) any later version.
e1d87d
+
e1d87d
+   This program is distributed in the hope that it will be useful,
e1d87d
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+   GNU General Public License for more details.
e1d87d
+
e1d87d
+   You should have received a copy of the GNU General Public License
e1d87d
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
e1d87d
+
e1d87d
+#include <pthread.h>
e1d87d
+
e1d87d
+__thread int thread_local = 42;
e1d87d
+
e1d87d
+int main(void)
e1d87d
+{
e1d87d
+  /* Ensure we link against pthreads even with --as-needed.  */
e1d87d
+  pthread_testcancel();
e1d87d
+  return 0;
e1d87d
+}
e1d87d
--- /dev/null
e1d87d
+++ b/gdb/testsuite/gdb.threads/tls-nodebug-pie.exp
e1d87d
@@ -0,0 +1,29 @@
e1d87d
+# Copyright 2016 Free Software Foundation, Inc.
e1d87d
+
e1d87d
+# This program is free software; you can redistribute it and/or modify
e1d87d
+# it under the terms of the GNU General Public License as published by
e1d87d
+# the Free Software Foundation; either version 3 of the License, or
e1d87d
+# (at your option) any later version.
e1d87d
+#
e1d87d
+# This program is distributed in the hope that it will be useful,
e1d87d
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
e1d87d
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1d87d
+# GNU General Public License for more details.
e1d87d
+#
e1d87d
+# You should have received a copy of the GNU General Public License
e1d87d
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
e1d87d
+
e1d87d
+standard_testfile
e1d87d
+
e1d87d
+if {[gdb_compile_pthreads "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable \
e1d87d
+			  [list "additional_flags=-fPIE -pie"]] != "" } {
e1d87d
+    return -1
e1d87d
+}
e1d87d
+
e1d87d
+clean_restart ${binfile}
e1d87d
+if ![runto_main] then {
e1d87d
+   return 0
e1d87d
+}
e1d87d
+
e1d87d
+# Formerly: Cannot access memory at address 0xd5554d5216fc
e1d87d
+gdb_test "p thread_local" " = 42" "thread local storage"
e1d87d
e1d87d
--3Pql8miugIZX0722--
e1d87d