From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2205) id D89623858C83; Wed, 11 Jan 2023 10:44:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D89623858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673433844; bh=1dg5rdKZzVIMpFfYqa6tEyxp146wiBp0ftMpD03qMos=; h=From:To:Subject:Date:From; b=H5YlOF3+Jqg0qFOVNx+VX9cYt1WEcYMmdGFmfL/15Mfub55sSvzMA3qYYF3Notriv o+JsS+/hK515/Jebz4XYynxGzbK+g66gxgye1Bj8DCPdAN0NhHRl322yq6sWCMliW6 19Y7D1sLz7g03A67xBW9dlg81hjxXPgw70FGYHhE= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom de Vries To: gdb-cvs@sourceware.org Subject: [binutils-gdb] [gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glibc, again X-Act-Checkin: binutils-gdb X-Git-Author: Tom de Vries X-Git-Refname: refs/heads/master X-Git-Oldrev: f56532cc17868e2c7e765bfd78322157048ff6ec X-Git-Newrev: f1e19328594fb0cc35dc7d6573a7a36f5ab9ecc4 Message-Id: <20230111104404.D89623858C83@sourceware.org> Date: Wed, 11 Jan 2023 10:44:04 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Df1e19328594f= b0cc35dc7d6573a7a36f5ab9ecc4 commit f1e19328594fb0cc35dc7d6573a7a36f5ab9ecc4 Author: Tom de Vries Date: Wed Jan 11 11:44:00 2023 +0100 [gdb/testsuite] Fix gdb.threads/dlopen-libpthread.exp for upstream glib= c, again =20 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. =20 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 =3D> /lib/x86_64-linux-gnu/libgtk3-nocsd.so.0 (inter= preter =3D> none) libdl.so.2 =3D> /lib/x86_64-linux-gnu/libdl.so.2 libpthread.so.0 =3D> /lib/x86_64-linux-gnu/libpthread.so.0 libc.so.6 =3D> /lib/x86_64-linux-gnu/libc.so.6 ld-linux-x86-64.so.2 =3D> /lib/x86_64-linux-gnu/ld-linux-x86-64= .so.2 ... =20 So, while test-case gdb.threads/dlopen-libpthread.exp appears to run ok: ... # of expected passes 12 # of unsupported tests 1 ... with LD_PRELOAD=3D"" 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 ... =20 The problem is that libpthread is expected as dependency of dlopen-libpthread.so, but it's missing: ... $ lddtree dlopen-libpthread.so dlopen-libpthread.so =3D> ./dlopen-libpthread.so (interpreter =3D> none) libc.so.6 =3D> $outputs/gdb.threads/dlopen-libpthread/dlopen-libpth= read.so.d/libc.so.6 ld-linux-x86-64.so.2 =3D> /lib/x86_64-linux-gnu/ld-linux-x86-64= .so.2 ... due to having glibc 2.35, which has libpthread integrated into libc. =20 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. =20 Also add a missing return after untested "no matching probes". =20 Tested on x86_64-linux, with and without LD_PRELOAD=3D"". 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/testsuit= e/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 { =20 if { !$have_probe } { untested "no matching probes" + return -1 +} + +# We link the exec without -lpthread, but libpthread.so may already be loa= ded at main +# due to LD_PRELOAD. +set libpthread_maybe_preloaded 0 +set binfile [standard_output_file $executable] +if { [has_dependency $binfile libpthread\\.so] =3D=3D 1 } { + set libpthread_maybe_preloaded 1 +} + +# We link the shlib with -lpthread, but since glibc 2.34 libpthread has be= en +# merged with libc, so libpthread.so may not be a dependency. +set libpthread_missing 0 +if { [has_dependency $binfile_lib libpthread\\.so] =3D=3D 0 } { + set libpthread_missing 1 } =20 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 .*" =20 -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 } =20 +# 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 !=3D 0 || $output =3D=3D "" } { + return -1 + } + return [regexp $dep $output] +} + # Always load compatibility stuff. load_lib future.exp