Blame SOURCES/gdb-rhbz1971095-libthread_db-update-2of5.patch

4a80f0
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
4a80f0
From: Kevin Buettner <kevinb@redhat.com>
4a80f0
Date: Wed, 9 Jun 2021 18:07:45 -0700
4a80f0
Subject: gdb-rhbz1971095-libthread_db-update-2of5.patch
4a80f0
4a80f0
;; Backport "libthread_db initialization changes related to upcoming
4a80f0
;; glibc-2.34"
4a80f0
;; (Kevin Buettner, RH BZ 19710950
4a80f0
4a80f0
This commit makes some adjustments to accomodate the upcoming
4a80f0
glibc-2.34 release.  Beginning with glibc-2.34, functionality formerly
4a80f0
contained in libpthread has been moved to libc.  For the time being,
4a80f0
libpthread.so still exists in the file system, but it won't show up in
4a80f0
ldd output and therefore won't be able to trigger initialization of
4a80f0
libthread_db related code.  E.g...
4a80f0
4a80f0
Fedora 34 / glibc-2.33.9000:
4a80f0
4a80f0
[kev@f34-2 gdb]$ ldd testsuite/outputs/gdb.threads/tls/tls
4a80f0
	linux-vdso.so.1 (0x00007ffcf94fa000)
4a80f0
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007ff0ba9af000)
4a80f0
	libm.so.6 => /lib64/libm.so.6 (0x00007ff0ba8d4000)
4a80f0
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007ff0ba8b9000)
4a80f0
	libc.so.6 => /lib64/libc.so.6 (0x00007ff0ba6c6000)
4a80f0
	/lib64/ld-linux-x86-64.so.2 (0x00007ff0babf0000)
4a80f0
4a80f0
Fedora 34 / glibc-2.33:
4a80f0
4a80f0
[kev@f34-1 gdb]$ ldd testsuite/outputs/gdb.threads/tls/tls
4a80f0
	linux-vdso.so.1 (0x00007fff32dc0000)
4a80f0
	libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f815f6de000)
4a80f0
	libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f815f4bf000)
4a80f0
	libm.so.6 => /lib64/libm.so.6 (0x00007f815f37b000)
4a80f0
	libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f815f360000)
4a80f0
	libc.so.6 => /lib64/libc.so.6 (0x00007f815f191000)
4a80f0
	/lib64/ld-linux-x86-64.so.2 (0x00007f815f721000)
4a80f0
4a80f0
Note that libpthread is missing from the ldd output for the
4a80f0
glibc-2.33.9000 machine.
4a80f0
4a80f0
This means that (unless we happen to think of some entirely different
4a80f0
mechanism), we'll now need to potentially match "libc" in addition to
4a80f0
"libpthread" as libraries which might be thread libraries.  This
4a80f0
accounts for the change made in solib.c.  Note that the new code
4a80f0
attempts to match "/libc." via strstr().  That trailing dot (".")
4a80f0
avoids inadvertently matching libraries such as libcrypt (and
4a80f0
all the other many libraries which begin with "libc").
4a80f0
4a80f0
To avoid attempts to load libthread_db when encountering older
4a80f0
versions of libc, we now attempt to find "pthread_create" (which is a
4a80f0
symbol that we'd expect to be in any pthread library) in the
4a80f0
associated objfile.  This accounts for the changes in
4a80f0
linux-thread-db.c.
4a80f0
4a80f0
I think that other small adjustments will need to be made elsewhere
4a80f0
too.  I've been working through regressions on my glibc-2.33.9000
4a80f0
machine; I've fixed some fairly "obvious" changes in the testsuite
4a80f0
(which are in other commits).  For the rest, it's not yet clear to me
4a80f0
whether the handful of remaining failures represent a problem in glibc
4a80f0
or gdb.  I'm still investigating, however, I'll note that these are
4a80f0
problems that I only see on my glibc-2.33.9000 machine.
4a80f0
4a80f0
gdb/ChangeLog:
4a80f0
4a80f0
	* solib.c (libpthread_name_p): Match "libc" in addition
4a80f0
	to "libpthread".
4a80f0
	* linux-thread-db.c (libpthread_objfile_p): New function.
4a80f0
	(libpthread_name_p): Adjust preexisting callers to use
4a80f0
	libpthread_objfile_p().
4a80f0
4a80f0
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
4a80f0
--- a/gdb/linux-thread-db.c
4a80f0
+++ b/gdb/linux-thread-db.c
4a80f0
@@ -800,6 +800,24 @@ check_thread_db (struct thread_db_info *info, bool log_progress)
4a80f0
   return test_passed;
4a80f0
 }
4a80f0
 
4a80f0
+/* Predicate which tests whether objfile OBJ refers to the library
4a80f0
+   containing pthread related symbols.  Historically, this library has
4a80f0
+   been named in such a way that looking for "libpthread" in the name
4a80f0
+   was sufficient to identify it.  As of glibc-2.34, the C library
4a80f0
+   (libc) contains the thread library symbols.  Therefore we check
4a80f0
+   that the name matches a possible thread library, but we also check
4a80f0
+   that it contains at least one of the symbols (pthread_create) that
4a80f0
+   we'd expect to find in the thread library.  */
4a80f0
+
4a80f0
+static bool
4a80f0
+libpthread_objfile_p (objfile *obj)
4a80f0
+{
4a80f0
+  return (libpthread_name_p (objfile_name (obj))
4a80f0
+          && lookup_minimal_symbol ("pthread_create",
4a80f0
+	                            NULL,
4a80f0
+				    obj).minsym != NULL);
4a80f0
+}
4a80f0
+
4a80f0
 /* Attempt to initialize dlopen()ed libthread_db, described by INFO.
4a80f0
    Return true on success.
4a80f0
    Failure could happen if libthread_db does not have symbols we expect,
4a80f0
@@ -1072,7 +1090,7 @@ try_thread_db_load_from_pdir (const char *subdir)
4a80f0
     return false;
4a80f0
 
4a80f0
   for (objfile *obj : current_program_space->objfiles ())
4a80f0
-    if (libpthread_name_p (objfile_name (obj)))
4a80f0
+    if (libpthread_objfile_p (obj))
4a80f0
       {
4a80f0
 	if (try_thread_db_load_from_pdir_1 (obj, subdir))
4a80f0
 	  return true;
4a80f0
@@ -1181,7 +1199,7 @@ static bool
4a80f0
 has_libpthread (void)
4a80f0
 {
4a80f0
   for (objfile *obj : current_program_space->objfiles ())
4a80f0
-    if (libpthread_name_p (objfile_name (obj)))
4a80f0
+    if (libpthread_objfile_p (obj))
4a80f0
       return true;
4a80f0
 
4a80f0
   return false;
4a80f0
@@ -1295,7 +1313,7 @@ thread_db_new_objfile (struct objfile *objfile)
4a80f0
 	 of the list of shared libraries to load, and in an app of several
4a80f0
 	 thousand shared libraries, this can otherwise be painful.  */
4a80f0
       && ((objfile->flags & OBJF_MAINLINE) != 0
4a80f0
-	  || libpthread_name_p (objfile_name (objfile))))
4a80f0
+	  || libpthread_objfile_p (objfile)))
4a80f0
     check_for_thread_db ();
4a80f0
 }
4a80f0
 
4a80f0
diff --git a/gdb/solib.c b/gdb/solib.c
4a80f0
--- a/gdb/solib.c
4a80f0
+++ b/gdb/solib.c
4a80f0
@@ -906,12 +906,17 @@ Do you need \"set solib-search-path\" or \"set sysroot\"?"),
4a80f0
 
4a80f0
    Uses a fairly simplistic heuristic approach where we check
4a80f0
    the file name against "/libpthread".  This can lead to false
4a80f0
-   positives, but this should be good enough in practice.  */
4a80f0
+   positives, but this should be good enough in practice.
4a80f0
+
4a80f0
+   As of glibc-2.34, functions formerly residing in libpthread have
4a80f0
+   been moved to libc, so "/libc." needs to be checked too.  (Matching
4a80f0
+   the "." will avoid matching libraries such as libcrypt.) */
4a80f0
 
4a80f0
 bool
4a80f0
 libpthread_name_p (const char *name)
4a80f0
 {
4a80f0
-  return (strstr (name, "/libpthread") != NULL);
4a80f0
+  return (strstr (name, "/libpthread") != NULL
4a80f0
+          || strstr (name, "/libc.") != NULL );
4a80f0
 }
4a80f0
 
4a80f0
 /* Return non-zero if SO is the libpthread shared library.  */