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

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