From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id kW/TIoqVx2rzMxYAWB0awg (envelope-from ) for ; Thu, 08 Oct 2026 09:07:22 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=undo.io header.i=@undo.io header.a=rsa-sha256 header.s=google header.b=MDutjd8M; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 8762E1E051; Thu, 08 Oct 2026 09:07:22 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B42A91E04E for ; Thu, 08 Oct 2026 09:07:20 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 529D24BA5436 for ; Thu, 8 Oct 2026 13:07:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 529D24BA5436 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=undo.io header.i=@undo.io header.a=rsa-sha256 header.s=google header.b=MDutjd8M Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id 250864BA2E20 for ; Thu, 8 Oct 2026 13:06:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 250864BA2E20 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=undo.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=undo.io ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 250864BA2E20 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791464786; cv=none; b=j2c/0uP421MX41JuRZGh2w/3GZ67LBo1JOdBlks2URpduRVzWilzG+3H94vnmiKKLCocRFRuSqpIkRIsAfFDckH3nBE4uPpoaZ5f35yF2Qsm8LkwCIKb1ZiUZ5Ikf5fCcUqRpzFHbxGB8IpdO/J77JkAC0u5MljbYY7IP4i4fSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791464786; c=relaxed/simple; bh=6x8yO4Y5uMFP0wDdRfONgV7VSC/tbgVeZmpgB+sfzE8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sWqfTc+BugnPzv2+a32zzh8oeB95mct7pIjqlTJ+LsMHurQ8kGYtqmaLuUJxSEHoB2mcF3TXFyGXDO8LWSTegt1/Qko3/ti8uViTcbEQz7rPXfbeZ9GyGHC8O9FtJ9wNl29g0zEYBWQu7Ur8lE94izKyJg2H82WML+f48FIR64Q= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=undo.io header.i=@undo.io header.a=rsa-sha256 header.s=google header.b=MDutjd8M DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 250864BA2E20 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-48c4649b3aaso2002682f8f.2 for ; Thu, 08 Oct 2026 06:06:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google; t=1791464785; x=1792069585; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=A7WKrqlmAfKq5aAsaPC3qApwa57dHCCtWZzqyC2stFM=; b=MDutjd8MnyEgE6sU036zBWyv8dlqf/KihvQyzPz7fuDyAInTr3Is+fNSL5nq6SuNsS opadWHIPvZ4BALdweWxTVZQmPk1qXodzdvu34KG4PPGELqMfZ+PLKhn7Iij1Qyn0jK0a niJUyVk9aJOVYq/oC1DxEUvQ8yl6tQdlfa6k7FoRu974VNvE/g5cSaE+xIowF03q0pUy 6j43+lyaoYVV8R7Y0lY0qDQoMQKDRMgRThFoerVi8ROYArLjTjRuYKImi/ThIVAYgtWo G12N4ksKfUFYKukQAy0zZpSUjFWLnaa9uYgm9mmbYz4AQwDr/CTUIurNH6x1oBJ2/xlJ DUag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791464785; x=1792069585; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=A7WKrqlmAfKq5aAsaPC3qApwa57dHCCtWZzqyC2stFM=; b=bOzP+MRLOhSxB30jBV1k1mZJPhXQ6HtkIaqaog23XcDzyWTDZcI5zgmYc0PwtE1z/s ZlxsfXLHHmE14t+5p2K+8Kalb45Cqh1DQXj7Cc70TR8yvic0KtiBTooPg43r33xfypUt 5YhPft02f1C9pa/YVPuD/cQclL2UX/TEbVSpwi98G9slLmzAsVWpMQSVsH02GlS9ihb9 vEhdDU3lYRddg1U8Y0zNUxJgWLlSR4NfSDxoDB2xixGQccJnJpRZE7dNigsS66laqwhI bflOTZJCm+1cEw0Al0/APuLqTU9DNIPIDzS6DvgHfrc97wn5Cv1Gz3ZMPnziNDJktGEF ukjg== X-Gm-Message-State: AFuF++m7J9cbKcZ9PSWEwswQpHe1tIvoqcys+P2IEsVRdpU1DPsFgBEg Jk99vZvgYkAbBfW+OBgKkEikEzymC69nne7x+USVOMfkmSY+H7MqEtiDvTXZ5/rDmLO1J2H7euh yJzVNfyvpUIVpORYyazWFO1kixBHtoZuD5uGAzrnahBNMqbtHeyYOxHhe4uUSf444rB+8iUWRY/ kdqB4fuYOLks5We8cNrxWvG8GOFlCdPtsc5u88GA== X-Gm-Gg: AYBFou2QYNssKTlwXLYDNSAKxanPuETiyto33J0GHPvnXGHQQRVpTivmHJfN7QayhUf z9TE/tKVLKpoe/7fgfB0IiACjY3Bcj8lGyOu406g+pVO3RmJgrxWQM0m8zQsBzjLPRXkdboYo+/ RNhwFyGMe44UPTNrskAsyAn1wsuN4yIvgI9gyIT1IG8DSLXTBH2MwOTWyngYtq1ISP8e9AOzBVY OG9vaLAgENKqGsmmReaV0NxqvR9PB2egxrWwQMHi24JIRcXBNxT6g5hrfwetIbBe+cCoXndaLq8 fquavXjxZ3MEyj8kPF9z2nS8+yqJ8bByB3gyj3xCnMggBud0AUpx0cNWO4gY+i7D4FD9WJvRdYp pjbZ18MclNb5BPZfpdHO8w5w4h9LJm7xgs2eM6JPDfb65VxQ34rsXS7J1NgeDLXtkBG8tDMJqog 080/zT9Ju+R81Cv/7TI8K2s9+hyS/1YWagYLBE642nZbkZ9R62FNMX1f+7wS18I0Psvc6MuTGjF 2RAxmuVHuJbRFQPa9RZojn4/KJCQJAuwSL38k7ozgfisa1xx6+d4309RtJabYdDJ8F6 X-Received: by 2002:a05:600c:4ecb:b0:49f:ff7b:f056 with SMTP id 5b1f17b1804b1-4a180409410mr99718805e9.9.1791464784638; Thu, 08 Oct 2026 06:06:24 -0700 (PDT) Received: from r90v1yyb-ubuntu.undoers.io (cfbb001091.b.cam.camfibre.uk. [185.219.110.245]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a184262f8asm69918845e9.0.2026.10.08.06.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Oct 2026 06:06:23 -0700 (PDT) From: Eduard-Petru Jipa To: gdb-patches@sourceware.org Cc: stephan.rohr@intel.com, Eduard Jipa Subject: [PATCH v3] gdb: don't abort shared library reload when one library fails to open Date: Thu, 8 Oct 2026 14:06:42 +0100 Message-ID: <20261008130642.54868-1-ejipa@undo.io> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Eduard Jipa When the set of shared libraries is reloaded, for example after 'set sysroot' or 'set solib-search-path', reload_shared_libraries_1 calls solib_ops::bfd_open for each library in turn. This can throw an error, for example if the file found is not in executable format, or its architecture is not compatible with the target. Nothing in the loop catches that error, so a single bad library stops the whole reload. Any libraries after it in the list are not reloaded, and the error propagates out of the command that triggered the reload. Catch the error, print it, and carry on with the rest of the libraries. This matches what is already done for errors from solib_map_sections later in the same loop. The library that failed to open is handled as if it had not been found. Add a test that builds a sysroot in which the first of two libraries is not a valid object file, and checks that, after 'set sysroot', the first library is no longer loaded and the second library is reloaded from the new sysroot. Tested on x86_64-linux with no regressions. Reviewed-By: Rohr, Stephan --- Changes in v3: - Combine the two 'info sharedlibrary' checks into a single test. Changes in v2: - Print the library name only once, on a single line. - Reword the commit message: the error is printed, not emitted with warning (). - Test that lib1 is not loaded after the failed reload. Thank you Stephan for the review. gdb/solib.c | 11 ++- .../gdb.base/solib-reload-error-lib.c | 25 ++++++ gdb/testsuite/gdb.base/solib-reload-error.c | 25 ++++++ gdb/testsuite/gdb.base/solib-reload-error.exp | 86 +++++++++++++++++++ 4 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/solib-reload-error-lib.c create mode 100644 gdb/testsuite/gdb.base/solib-reload-error.c create mode 100644 gdb/testsuite/gdb.base/solib-reload-error.exp diff --git a/gdb/solib.c b/gdb/solib.c index 7ea3084bf48..cef9a429f45 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1463,7 +1463,16 @@ reload_shared_libraries_1 (int from_tty) gdb::unique_xmalloc_ptr filename = gdb_rl_tilde_expand (so.original_name.c_str ()); - gdb_bfd_ref_ptr abfd = so.ops ().bfd_open (filename.get ()); + gdb_bfd_ref_ptr abfd; + try + { + abfd = so.ops ().bfd_open (filename.get ()); + } + catch (const gdb_exception_error &e) + { + exception_fprintf (gdb_stderr, e, + _("Error while opening shared library: ")); + } if (abfd != NULL) found_pathname = bfd_get_filename (abfd.get ()); diff --git a/gdb/testsuite/gdb.base/solib-reload-error-lib.c b/gdb/testsuite/gdb.base/solib-reload-error-lib.c new file mode 100644 index 00000000000..7aaa13fd697 --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-reload-error-lib.c @@ -0,0 +1,25 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2026 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 file is compiled twice, with LIB_FUNC defined to a different + name each time. */ + +int +LIB_FUNC (void) +{ + return 0; +} diff --git a/gdb/testsuite/gdb.base/solib-reload-error.c b/gdb/testsuite/gdb.base/solib-reload-error.c new file mode 100644 index 00000000000..465cf7e82e6 --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-reload-error.c @@ -0,0 +1,25 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2026 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 . */ + +extern int lib1_func (void); +extern int lib2_func (void); + +int +main (void) +{ + return lib1_func () + lib2_func (); +} diff --git a/gdb/testsuite/gdb.base/solib-reload-error.exp b/gdb/testsuite/gdb.base/solib-reload-error.exp new file mode 100644 index 00000000000..f9e30ef49ab --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-reload-error.exp @@ -0,0 +1,86 @@ +# Copyright 2026 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 . + +# Check that an error opening one shared library while reloading +# shared libraries (in this case, triggered by 'set sysroot') does not +# stop GDB from reloading the shared libraries that come after it. + +require allow_shlib_tests +require {!is_remote host} + +standard_testfile .c -lib.c + +set lib1 [standard_output_file ${testfile}-lib1.so] +set lib2 [standard_output_file ${testfile}-lib2.so] + +if { [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $lib1 \ + {debug additional_flags=-DLIB_FUNC=lib1_func}] != "" + || [gdb_compile_shlib $srcdir/$subdir/$srcfile2 $lib2 \ + {debug additional_flags=-DLIB_FUNC=lib2_func}] != "" } { + untested "failed to compile shared libraries" + return +} + +# Link against lib1 first, so that it is ahead of lib2 in the list of +# shared libraries that GDB reloads. +if { [prepare_for_testing "failed to prepare" $testfile $srcfile \ + [list debug shlib=$lib1 shlib=$lib2]] } { + return +} + +gdb_load_shlib $lib1 +gdb_load_shlib $lib2 + +if { ![runto_main] } { + return +} + +# The rest of the test relies on lib1 being reloaded before lib2. +if { [gdb_test "info sharedlibrary" \ + "[string_to_regexp $lib1]\r\n.*[string_to_regexp $lib2]\r\n.*" \ + "lib1 is ahead of lib2 in the list"] != 0 } { + return +} + +# Build a sysroot in which lib1 is not a valid object file, but lib2 +# is a good copy of the real library. +set sysroot [standard_output_file sysroot] +set sysroot_lib1 $sysroot$lib1 +set sysroot_lib2 $sysroot$lib2 +file delete -force $sysroot +file mkdir [file dirname $sysroot_lib1] +set fd [open $sysroot_lib1 w] +puts $fd "This is not an object file." +close $fd +file copy $lib2 $sysroot_lib2 + +# Changing the sysroot reloads every shared library. Opening lib1 +# fails, and GDB should report that and carry on. +gdb_test "set sysroot $sysroot" \ + "Error while opening shared library: `[string_to_regexp $sysroot_lib1]': not in executable format: .*" \ + "set sysroot with bad lib1" + +# lib1 could not be opened, so its symbols should no longer be loaded. +# lib2 comes after lib1 in the list, so it is only reloaded from the +# new sysroot if the error opening lib1 did not stop the reload. +gdb_test "info sharedlibrary" \ + [multi_line \ + "" \ + "\[ \t\]+No\[ \t\]+[string_to_regexp $lib1]" \ + "$hex\[ \t\]+$hex\[ \t\]+Yes\[^\r\n\]*[string_to_regexp $sysroot_lib2]" \ + ".*"] \ + "lib1 is not loaded and lib2 is reloaded from the new sysroot" + +gdb_test "info symbol lib2_func" "lib2_func in section \\.text of [string_to_regexp $sysroot_lib2]" -- 2.43.0