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

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