405ea9
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
405ea9
From: Jan Kratochvil <jan.kratochvil@redhat.com>
405ea9
Date: Fri, 27 Oct 2017 21:07:50 +0200
405ea9
Subject: gdb-6.5-sharedlibrary-path.patch
405ea9
405ea9
;; Fix TLS symbols resolving for shared libraries with a relative pathname.
405ea9
;; The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.
405ea9
;;=fedoratest: One should recheck if it is really fixed upstream.
405ea9
405ea9
If you provided some relative path to the shared library, such as with
405ea9
	export LD_LIBRARY_PATH=.
405ea9
then gdb would fail to match the shared library name during the TLS lookup.
405ea9
405ea9
Dropped the workaround/fix for gdb-6.8.50.20081128 - is it still needed?
405ea9
405ea9
The testsuite needs `gdb-6.3-bz146810-solib_absolute_prefix_is_empty.patch'.
405ea9
The testsuite needs `gdb-6.5-tls-of-separate-debuginfo.patch'.
405ea9
405ea9
2006-09-01  Jan Kratochvil  <jan.kratochvil@redhat.com>
405ea9
405ea9
	* solib-svr4.c (svr4_fetch_objfile_link_map): Match even absolute
405ea9
	requested pathnames to the internal loaded relative pathnames.
405ea9
405ea9
2007-10-16  Jan Kratochvil  <jan.kratochvil@redhat.com>
405ea9
405ea9
	Port to GDB-6.7.
405ea9
405ea9
2008-02-27  Jan Kratochvil  <jan.kratochvil@redhat.com>
405ea9
405ea9
	Port to gdb-6.7.50.20080227.
405ea9
405ea9
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-main.c b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
405ea9
new file mode 100644
405ea9
--- /dev/null
405ea9
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c
405ea9
@@ -0,0 +1,31 @@
405ea9
+/* This testcase is part of GDB, the GNU debugger.
405ea9
+
405ea9
+   Copyright 2006 Free Software Foundation, Inc.
405ea9
+
405ea9
+   This program is free software; you can redistribute it and/or modify
405ea9
+   it under the terms of the GNU General Public License as published by
405ea9
+   the Free Software Foundation; either version 2 of the License, or
405ea9
+   (at your option) any later version.
405ea9
+
405ea9
+   This program is distributed in the hope that it will be useful,
405ea9
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
405ea9
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
405ea9
+   GNU General Public License for more details.
405ea9
+
405ea9
+   You should have received a copy of the GNU General Public License
405ea9
+   along with this program; if not, write to the Free Software
405ea9
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
405ea9
+
405ea9
+   Please email any bugs, comments, and/or additions to this file to:
405ea9
+   bug-gdb@prep.ai.mit.edu  */
405ea9
+
405ea9
+#include <pthread.h>
405ea9
+
405ea9
+extern __thread int var;
405ea9
+
405ea9
+int main()
405ea9
+{
405ea9
+  /* Ensure we link against pthreads even with --as-needed.  */
405ea9
+  pthread_testcancel();
405ea9
+  return var;
405ea9
+}
405ea9
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
405ea9
new file mode 100644
405ea9
--- /dev/null
405ea9
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c
405ea9
@@ -0,0 +1,22 @@
405ea9
+/* This testcase is part of GDB, the GNU debugger.
405ea9
+
405ea9
+   Copyright 2006 Free Software Foundation, Inc.
405ea9
+
405ea9
+   This program is free software; you can redistribute it and/or modify
405ea9
+   it under the terms of the GNU General Public License as published by
405ea9
+   the Free Software Foundation; either version 2 of the License, or
405ea9
+   (at your option) any later version.
405ea9
+
405ea9
+   This program is distributed in the hope that it will be useful,
405ea9
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
405ea9
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
405ea9
+   GNU General Public License for more details.
405ea9
+
405ea9
+   You should have received a copy of the GNU General Public License
405ea9
+   along with this program; if not, write to the Free Software
405ea9
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
405ea9
+
405ea9
+   Please email any bugs, comments, and/or additions to this file to:
405ea9
+   bug-gdb@prep.ai.mit.edu  */
405ea9
+
405ea9
+__thread int var = 42;
405ea9
diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug.exp b/gdb/testsuite/gdb.threads/tls-sepdebug.exp
405ea9
new file mode 100644
405ea9
--- /dev/null
405ea9
+++ b/gdb/testsuite/gdb.threads/tls-sepdebug.exp
405ea9
@@ -0,0 +1,94 @@
405ea9
+# Copyright 2006 Free Software Foundation, Inc.
405ea9
+
405ea9
+# This program is free software; you can redistribute it and/or modify
405ea9
+# it under the terms of the GNU General Public License as published by
405ea9
+# the Free Software Foundation; either version 2 of the License, or
405ea9
+# (at your option) any later version.
405ea9
+#
405ea9
+# This program is distributed in the hope that it will be useful,
405ea9
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
405ea9
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
405ea9
+# GNU General Public License for more details.
405ea9
+#
405ea9
+# You should have received a copy of the GNU General Public License
405ea9
+# along with this program; if not, write to the Free Software
405ea9
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
405ea9
+
405ea9
+# This test uses gdb_exit and gdb_start, which are not supported
405ea9
+# on non-extended-remote sessions.
405ea9
+if {[use_gdb_stub]} {
405ea9
+    untested "skipping test because of stub"
405ea9
+    return 0
405ea9
+}
405ea9
+
405ea9
+if $tracelevel then {
405ea9
+    strace $tracelevel
405ea9
+}
405ea9
+
405ea9
+set testfile tls-sepdebug
405ea9
+set srcmainfile   ${testfile}-main.c
405ea9
+set srcsharedfile ${testfile}-shared.c
405ea9
+
405ea9
+set binmainfile        [standard_output_file ${testfile}-main]
405ea9
+set binsharedbase      ${testfile}-shared.so
405ea9
+set binsharedfile      [standard_output_file ${binsharedbase}]
405ea9
+set binshareddebugfile [standard_output_file ${binsharedbase}.debug]
405ea9
+
405ea9
+# Use explicit -soname as otherwise the full path to the library would get
405ea9
+# encoded into ${binmainfile} making LD_LIBRARY_PATH tests useless.
405ea9
+
405ea9
+# FIXME: gcc dependency (-Wl,-soname).
405ea9
+
405ea9
+if  { [gdb_compile_shlib "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" [list debug additional_flags=-Wl,-soname=${binsharedbase}]] != "" } {
405ea9
+    untested "Couldn't compile test library"
405ea9
+    return -1
405ea9
+}
405ea9
+
405ea9
+# eu-strip(1) works fine but it is a part of `elfutils', not `binutils'.
405ea9
+if 0 then {
405ea9
+    remote_exec build "eu-strip -f ${binshareddebugfile} ${binsharedfile}"
405ea9
+} else {
405ea9
+    remote_exec build "objcopy --only-keep-debug ${binsharedfile} ${binshareddebugfile}"
405ea9
+    remote_exec build "objcopy --strip-debug ${binsharedfile}"
405ea9
+    remote_exec build "objcopy --add-gnu-debuglink=${binshareddebugfile} ${binsharedfile}"
405ea9
+}
405ea9
+
405ea9
+# Do not use `shlib=' as it will automatically add also -rpath for gcc.
405ea9
+
405ea9
+if  { [gdb_compile_pthreads "${srcdir}/${subdir}/${srcmainfile} ${binsharedfile}" "${binmainfile}" executable {debug}] != "" } {
405ea9
+    untested "Couldn't compile test program"
405ea9
+    return -1
405ea9
+}
405ea9
+
405ea9
+# Get things started.
405ea9
+
405ea9
+# Test also the proper resolving of relative library names to absolute ones.
405ea9
+# \$PWD is easy - it is the absolute way
405ea9
+# ${subdir} would fail on "print var"
405ea9
+
405ea9
+set absdir [file dirname [standard_output_file ${binsharedbase}]]
405ea9
+foreach ld_library_path [list $absdir [relative_filename [pwd] $absdir]] name { absolute relative }  {
405ea9
+
405ea9
+    gdb_exit
405ea9
+    gdb_start
405ea9
+    ###gdb_reinitialize_dir $srcdir/$subdir
405ea9
+
405ea9
+    gdb_test "set env LD_LIBRARY_PATH=$ld_library_path" \
405ea9
+             "" \
405ea9
+             "set env LD_LIBRARY_PATH is $name"
405ea9
+
405ea9
+    gdb_load ${binmainfile}
405ea9
+
405ea9
+    # For C programs, "start" should stop in main().
405ea9
+
405ea9
+    gdb_test "start" \
405ea9
+             "main \\(\\) at .*${srcmainfile}.*" \
405ea9
+             "start"
405ea9
+
405ea9
+    # Check for: Cannot find shared library `/usr/lib/debug/lib/libc-2.4.90.so.debug' in dynamic linker's load module list
405ea9
+    # as happens with TLS variables and `separate_debug_objfile_backlink'.
405ea9
+
405ea9
+    gdb_test "print var" \
405ea9
+             "\\\$1 = \[0-9\].*" \
405ea9
+             "print TLS variable from a shared library with $name-directory separate debug info file"
405ea9
+}