Blame SOURCES/gdb-6.5-sharedlibrary-path.patch

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