Blame SOURCES/gdb-tls-2of2.patch

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