From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lndn.lancelotsix.com (lndn.lancelotsix.com [51.195.220.111]) by sourceware.org (Postfix) with ESMTPS id DCDA73856956 for ; Mon, 25 Sep 2023 09:57:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCDA73856956 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=lancelotsix.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lancelotsix.com Received: from octopus (cust120-dsl54.idnet.net [212.69.54.120]) by lndn.lancelotsix.com (Postfix) with ESMTPSA id 548D68A19A; Mon, 25 Sep 2023 09:57:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lancelotsix.com; s=2021; t=1695635835; bh=2C2FeENFsFpECU4tBapFsq5cZwCft78gyhXEZZpmubM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aWPx/urGZXDELKh1wGsngmMxwSt+kmYVWLcHzU8/oXC3O/L0SjPkNO8FB2qcGYrfB fZGgYfwyvpTJ8N65ztwC1EdPFXDCfK8g0kzADuHK+fSUU1kAk0y81sb+axhEYJfCQN kK11GJajp15ga1ynOoOOU8XOI6Tb69U+/B6fzc6TWtLcvKxS5TEST4hNOZVUBjNzYv +GoeDwnaCP77oeIVqOZutED6dAIG+Sn7mUiO2iaOkhsg8itkOtwJbTMwhofzRta++s 2ZB33Z3wIEUHBV8/Xe+hr6qDAkZT/KbT4dxKrk/NQMsF3bJ2QOalG47ZiGWqoTZAxA 7XKMHpVG0Iy2g== Date: Mon, 25 Sep 2023 10:57:10 +0100 From: Lancelot SIX To: Kevin Buettner Cc: gdb-patches@sourceware.org, Jan Kratochvil Subject: Re: [PATCH] gdb/testsuite: Add relative versus absolute LD_LIBRARY_PATH test Message-ID: <20230925095710.k3xektglqa3z5v2g@octopus> References: <20230922012236.3254533-2-kevinb@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230922012236.3254533-2-kevinb@redhat.com> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (lndn.lancelotsix.com [0.0.0.0]); Mon, 25 Sep 2023 09:57:15 +0000 (UTC) X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hi Kevin, On Thu, Sep 21, 2023 at 06:22:12PM -0700, Kevin Buettner via Gdb-patches wrote: > At one time, circa 2006, there was a bug, which was presumably fixed > without adding a test case: > > If you provided some relative path to the shared library, such as > with > > export LD_LIBRARY_PATH=. > > then gdb would fail to match the shared library name during the > TLS lookup. > > I think there may have been a bit more to it than is provided by that > explanation, since the test also takes care to split the debug info > into a separate file. > > In any case, this commit is based on one of Red Hat's really old > local patches. I've attempted to update it and remove a fair amount > of cruft, hopefully without losing any critical elements from the > test. > > Testing on Fedora 38 (correctly) shows 1 unsupported test for > native-gdbserver and 5 PASSes for the native target as well as > native-extended-gdbserver. > > Co-Authored-by: Jan Kratochvil > --- > gdb/testsuite/gdb.threads/tls-sepdebug-main.c | 27 ++++++ > .../gdb.threads/tls-sepdebug-shared.c | 18 ++++ > gdb/testsuite/gdb.threads/tls-sepdebug.exp | 86 +++++++++++++++++++ > 3 files changed, 131 insertions(+) > create mode 100644 gdb/testsuite/gdb.threads/tls-sepdebug-main.c > create mode 100644 gdb/testsuite/gdb.threads/tls-sepdebug-shared.c > create mode 100644 gdb/testsuite/gdb.threads/tls-sepdebug.exp > > diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-main.c b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c > new file mode 100644 > index 00000000000..97b5bf5ae0e > --- /dev/null > +++ b/gdb/testsuite/gdb.threads/tls-sepdebug-main.c > @@ -0,0 +1,27 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2006-2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > + > +extern __thread int var; I think you could replace __thread (a GCC extension) with thread_local which was introduced in C11 (available in the header)[1]. This could require adding -std=c11 to additional_flags in the .exp file (not sure which C standard is picked by default by different versions of GCC). [1] https://en.cppreference.com/w/c/thread/thread_local Best, Lancelot. > + > +int main() > +{ > + /* Ensure we link against pthreads even with --as-needed. */ > + pthread_testcancel(); > + return var; > +} > diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c > new file mode 100644 > index 00000000000..c63515f3011 > --- /dev/null > +++ b/gdb/testsuite/gdb.threads/tls-sepdebug-shared.c > @@ -0,0 +1,18 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2006-2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +__thread int var = 42; > diff --git a/gdb/testsuite/gdb.threads/tls-sepdebug.exp b/gdb/testsuite/gdb.threads/tls-sepdebug.exp > new file mode 100644 > index 00000000000..df4fccee567 > --- /dev/null > +++ b/gdb/testsuite/gdb.threads/tls-sepdebug.exp > @@ -0,0 +1,86 @@ > +# Copyright 2006-2023 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# This test creates a shared library and a main program which uses > +# that library, extracts the debug info of the library to a separate > +# file, and then tests that a symbol from the shared library is > +# accessible using both absolute and relative settings of > +# LD_LIBRARY_PATH. > + > +# This test needs to change the environment in which the test program > +# is run, specifically the setting of LD_LIBRARY_PATH. GDB can adjust > +# this setting for both native and extended-remote targets, but not > +# for targets to which GDB connects after the program has already > +# started. Therefore, this test won't work for targets which use > +# "target remote". > +require !use_gdb_stub > + > +set testfile tls-sepdebug > +set srcmainfile ${testfile}-main.c > +set srcsharedfile ${testfile}-shared.c > + > +set binmainfile [standard_output_file ${testfile}-main] > +set binsharedbase ${testfile}-shared.so > +set binsharedfile [standard_output_file ${binsharedbase}] > + > +# Build the shared library, but use explicit -soname; otherwise the > +# full path to the library would get encoded into ${binmainfile} > +# making LD_LIBRARY_PATH tests useless. > +if { [gdb_compile_shlib \ > + "${srcdir}/${subdir}/${srcsharedfile}" "${binsharedfile}" \ > + [list debug additional_flags=-Wl,-soname=${binsharedbase}]] != "" } { > + untested "Couldn't compile test library" > + return -1 > +} > + > +# Strip debug information from $binsharedfile, placing it in > +# ${binsharedfile}.debug. Also add a .gnu_debuglink in the former, > +# pointing to the latter. > +gdb_gnu_strip_debug ${binsharedfile} > + > +# Build main program, but do not use `shlib=' since that would > +# automatically add -rpath for gcc. > +if { [gdb_compile_pthreads \ > + "${srcdir}/${subdir}/${srcmainfile} ${binsharedfile}" \ > + "${binmainfile}" executable {debug}] != "" } { > + untested "Couldn't compile test program" > + return -1 > +} > + > +set absdir [file dirname [standard_output_file ${binsharedbase}]] > + > +foreach ld_library_path [list $absdir [relative_filename [pwd] $absdir]] \ > + name { absolute relative } { > + with_test_prefix $name { > + > + # Restart, but defer loading until after setting LD_LIBRARY_PATH. > + clean_restart > + > + gdb_test_no_output "set env LD_LIBRARY_PATH=$ld_library_path" \ > + "set env LD_LIBRARY_PATH" > + > + gdb_load ${binmainfile} > + > + if ![runto_main] { > + return > + } > + > + # Print a thread local variable from the shared library to be certain > + # that its symbols were loaded from the separate debuginfo file. > + gdb_test "print var" \ > + "\\\$1 = \[0-9\].*" \ > + "print TLS variable from a shared library with separate debug info file" > + } > +} > -- > 2.41.0 >