public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] [gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibc, again
@ 2023-01-11 10:44 Tom de Vries
  0 siblings, 0 replies; only message in thread
From: Tom de Vries @ 2023-01-11 10:44 UTC (permalink / raw)
  To: gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f1e19328594fb0cc35dc7d6573a7a36f5ab9ecc4

commit f1e19328594fb0cc35dc7d6573a7a36f5ab9ecc4
Author: Tom de Vries <tdevries@suse.de>
Date:   Wed Jan 11 11:44:00 2023 +0100

    [gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibc, again
    
    On an x86_64 laptop running ubuntu 22.04.1 with unity desktop:
    ...
    $ echo $XDG_CURRENT_DESKTOP
    Unity:Unity7:ubuntu
    ...
    I have:
    ...
    $ echo $LD_PRELOAD
    libgtk3-nocsd.so.0
    ...
    due to package gtk3-nocsd, a package recommended by unity-session.
    
    Consequently, for each exec these dependencies are pulled in, including
    libpthread.so.0:
    ...
    $ lddtree /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0
    libgtk3-nocsd.so.0 => /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (interpreter => none)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6
            ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    ...
    
    So, while test-case gdb.threads/dlopen-libpthread.exp appears to run ok:
    ...
     # of expected passes           12
     # of unsupported tests         1
    ...
    with LD_PRELOAD="" we have instead:
    ...
    (gdb) PASS: gdb.threads/dlopen-libpthread.exp: continue to breakpoint: notify
    info sharedlibrary^M
    From  To                  Syms Read   Shared Object Library^M
    $hex  $hex  Yes         /lib64/ld-linux-x86-64.so.2^M
    $hex  $hex  Yes         /lib/x86_64-linux-gnu/libc.so.6^M
    $hex  $hex  Yes         dlopen-libpthread.so^M
    (gdb) FAIL: gdb.threads/dlopen-libpthread.exp: libpthread.so found
    ...
    
    The problem is that libpthread is expected as dependency of
    dlopen-libpthread.so, but it's missing:
    ...
    $ lddtree dlopen-libpthread.so
    dlopen-libpthread.so => ./dlopen-libpthread.so (interpreter => none)
        libc.so.6 => $outputs/gdb.threads/dlopen-libpthread/dlopen-libpthread.so.d/libc.so.6
            ld-linux-x86-64.so.2 => /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
    ...
    due to having glibc 2.35, which has libpthread integrated into libc.
    
    Fix this by:
    - adding a proc has_dependency
    - using [has_dependency $exec libpthread.so] as hint that libpthread
      may be preloaded
    - using ![has_dependency $shlib libpthread.so] to detect that
      the libpthread.so dependency is missing.
    
    Also add a missing return after untested "no matching probes".
    
    Tested on x86_64-linux, with and without LD_PRELOAD="".

Diff:
---
 gdb/testsuite/gdb.threads/dlopen-libpthread.exp | 30 ++++++++++++++++++++-----
 gdb/testsuite/lib/gdb.exp                       | 17 ++++++++++++++
 2 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/gdb/testsuite/gdb.threads/dlopen-libpthread.exp b/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
index 0b325ce622f..134265ff470 100644
--- a/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
+++ b/gdb/testsuite/gdb.threads/dlopen-libpthread.exp
@@ -61,16 +61,32 @@ foreach probe_name $probe_names {
 
 if { !$have_probe } {
     untested "no matching probes"
+    return -1
+}
+
+# We link the exec without -lpthread, but libpthread.so may already be loaded at main
+# due to LD_PRELOAD.
+set libpthread_maybe_preloaded 0
+set binfile [standard_output_file $executable]
+if { [has_dependency $binfile libpthread\\.so] == 1 } {
+    set libpthread_maybe_preloaded 1
+}
+
+# We link the shlib with -lpthread, but since glibc 2.34 libpthread has been
+# merged with libc, so libpthread.so may not be a dependency.
+set libpthread_missing 0
+if { [has_dependency $binfile_lib libpthread\\.so] == 0 } {
+    set libpthread_missing 1
 }
 
 set test "libpthread.so not found"
 gdb_test_multiple "info sharedlibrary" $test {
     -re "/libpthread\\.so.*\r\n$gdb_prompt $" {
-	# With newer glibc, libpthread has been integrated into glibc so we
-	# can expect it to be already loaded at main.  This means we no longer
-	# excercise the scenario we're trying to trigger, but continue
-	# nevertheless.
-	unsupported $test
+	if { $libpthread_maybe_preloaded } {
+	    unsupported $test
+	} else {
+	    fail $test
+	}
     }
     -re "/libc\\.so.*\r\n$gdb_prompt $" {
 	pass $test
@@ -85,4 +101,6 @@ gdb_breakpoint "notify"
 # Cannot find new threads: generic error
 gdb_continue_to_breakpoint "notify" ".* notify-here .*"
 
-gdb_test "info sharedlibrary" {/libpthread\.so.*} "libpthread.so found"
+if { !$libpthread_missing } {
+    gdb_test "info sharedlibrary" {/libpthread\.so.*} "libpthread.so found"
+}
diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
index c41d4698d66..39dfa67c344 100644
--- a/gdb/testsuite/lib/gdb.exp
+++ b/gdb/testsuite/lib/gdb.exp
@@ -9355,5 +9355,22 @@ proc decompress_bz2 { bz2 } {
     return $copy
 }
 
+# Return 1 if the output of "ldd FILE" contains regexp DEP, 0 if it doesn't,
+# and -1 if there was a problem running the command.
+
+proc has_dependency { file dep } {
+    set ldd [gdb_find_ldd]
+    set command "$ldd $file"
+    set result [remote_exec host $command]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+    verbose -log "status of $command is $status"
+    verbose -log "output of $command is $output"
+    if { $status != 0 || $output == "" } {
+	return -1
+    }
+    return [regexp $dep $output]
+}
+
 # Always load compatibility stuff.
 load_lib future.exp

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-11 10:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-11 10:44 [binutils-gdb] [gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibc, again Tom de Vries

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).