From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id qaPiF64qxmp58w0AWB0awg (envelope-from ) for ; Wed, 07 Oct 2026 07:19:10 -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=AJY5wAsz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 585C61E04E; Wed, 07 Oct 2026 07:19:10 -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 9DC4E1E04E for ; Wed, 07 Oct 2026 07:19:06 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4D8594BA2E0A for ; Wed, 7 Oct 2026 11:19:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D8594BA2E0A 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=AJY5wAsz Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 425A44BA2E09 for ; Wed, 7 Oct 2026 11:18:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 425A44BA2E09 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 425A44BA2E09 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791371918; cv=none; b=OEGCO8pzBGPjsGNxf+VpuSHIbZ/D97YibVSd+aUWbCcV44EmblB6VpjsE098Xyi2yx6uOuVx2XJD8mx4BsjyYiUUOfsNp6YAzBMui4SwvQHPz3clGeDtzjIwhkemLOv09w1cW3XbozjeslliLViSqO9mOieklzy2KsyU8kZUW1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791371918; c=relaxed/simple; bh=ObS37mvptUaT5u6lWLVy4RKKPFPR8rjecXd+pwoZHGA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dcdiDCkqO0utJp+6Jp3bhJKNvLvZZSTVDVdMtNXqAY7/U8u0Gtf8Ro4EwxGEkekYWrNo1c3A6d6XwbBtu3qk9GhR1PW+Nam0P4cGZMpR8fOoJO7hsPD+6ospKexJYl6Ltm2XcKqIC8ziiLUPwerD8EpE2gGxvqkNUY/r/klZy9Y= 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=AJY5wAsz DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 425A44BA2E09 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-48afe0081a6so744533f8f.2 for ; Wed, 07 Oct 2026 04:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google; t=1791371917; x=1791976717; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=6QO/QukeuyFH1e7Q25wQP5oK+U3vDzAMKoxhgcVxSVU=; b=AJY5wAszfuOg2J4QGZeRNqdzVjXXeqpDuC0UW04L/KDkrh/gIKF6k+s7Wa6DsX+YXo OZo2NMaRY5dwqPPtaV4kAOgaBr0D4WQPUw69gIJe5lZCQ1VSCyE5oI9Grt1lGz9cgsJQ 8U2kLAaI9SQ4RF8/iDu+rwoMEIalNF8nnEm21WIhoENNigenotlDupTKjvKac75N0113 qnVN/cAQFlxS+/gIrHaXLVAmtL3bmRkr7XxQUPqvN+XxvURzD8P3KCs6FH2bK6OmoMLQ s0JQZzYzPL+uWDmbcXgXcmwQUCSGdUcuRm2HgHeHlcv9A9gAriSZdvXlq0f+dkulwakR vqeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791371917; x=1791976717; h=content-transfer-encoding:mime-version: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=6QO/QukeuyFH1e7Q25wQP5oK+U3vDzAMKoxhgcVxSVU=; b=GJIth7c/EgfXSR8nBy3yeugk+pewLPsOopMEAswKZPswN+WxgkaxIERNNVSZStksuG /ScJ7Izq3UvsVqNLCmifB0PwETkSJ8BPjcQNndDxXc30ctVvt5V4QCVYsqjn8axROZd9 qZkwGmqwZFYQ1U1+ramG/LIbR0AnahqM9st/pUz7Ej3SyXO6OoTwO3ykbtDfaADGHByG yISHb2yJiRdMQND5Ic095eLpNWICdh468pynilCZf/Ts8qn9Yoxyi+3IFQi7ZFdUxVOr b/BICtXBK+vwuI7kR4M1WN0MOxDuEcQI4/rioKevPCRn/iL5ncEckVfXj8u/ex4NjWl9 ttrA== X-Gm-Message-State: AFq9FYLC3EIy/n93jJqWf8eMHRaQO72/AEFaLj82di4Jb3qYxfWzso6Y GzO4rx/bDdnLVe9Hhar1kCGCqGvi+8xNqP0e30resw4VwQpzgWmORLtbZaOIBWxRoWuVd8vkQjN qBjEH2ZUWVEHV/Lvnw9DQEPks6NZhM7ZjupOyaBU7gImwPEdhxwIqbGGXN1ebRjnPuZJKUNsbxt sScIWtckeTybvC7stYBfckikYdhrRdx99MOa7cCQ== X-Gm-Gg: AYBFou2aFyrHS6FLS3SFrJoQfFYCRYp8TQA5l5cBxpLqOUN4YU2uJlc9PzU3cwC2vLK KPJAYJ8wZRwJH3NmAHmEQZ0L5VGh4UWgSQjts8HxBVQqk5gEe6pKRJMejPgRsu9xY3F/ozqmMpA ZnJlEbNahXSZlidPBG1DgODTATCMmzNzMPjKrZTU/ZBReoPCnRyvN8DgupnF3BH9a7OSLVXXJkJ TQhP7w/htf0tefrjAdR7ySd2YbLuJ6MTIF42VBxJdSHzT0YRdWhciI+8/gS7R+BPGnOPF3dZcKn SI+1T/Rra5Nua5fQe5Yqx53Xf9dHunz9+qr82i07Mnx00Yt2qvdty5q7A0mkwvUTEkdzF6XsSv6 Y4bTaInrTJsf140HYM+TRRuhZ6Rv/jsb05hnjEwDpWYk3QIgfV3J/imqCdpO98CekBvSoOQiF22 C3IecuH9elOZKcDIkC5zQsYBX8JQOiZb7WzyMzcn77Ga9taDGyZHfXZwoFGKkpSINXmK+A0H2B8 fs/sfc3vuhVES4= X-Received: by 2002:a05:6000:24c6:b0:48c:4a62:9af7 with SMTP id ffacd0b85a97d-48c7278ec74mr3644674f8f.28.1791371916626; Wed, 07 Oct 2026 04:18:36 -0700 (PDT) Received: from r90v1yyb-ubuntu.powerhub ([2a0a:ef40:28b2:c201:1de:e379:4062:9bbf]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48c71c0b37csm4883233f8f.9.2026.10.07.04.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2026 04:18:35 -0700 (PDT) From: Eduard-Petru Jipa To: gdb-patches@sourceware.org Cc: Eduard Jipa Subject: [PATCH] gdb: don't abort shared library reload when one library fails to open Date: Wed, 7 Oct 2026 12:18:49 +0100 Message-ID: <20261007111849.4992-1-ejipa@undo.io> X-Mailer: git-send-email 2.43.0 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 as a warning, 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 the second library is still reloaded from the new sysroot after 'set sysroot'. Tested on x86_64-linux with no regressions. --- gdb/solib.c | 13 ++- .../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 | 81 +++++++++++++++++++ 4 files changed, 143 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..ad964e0afe9 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -1463,7 +1463,18 @@ 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 `%ps':\n"), + styled_string (file_name_style.style (), + filename.get ())); + } 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..adbafde1fbe --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-reload-error.exp @@ -0,0 +1,81 @@ +# 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 $lib1]':\r\n.*not in executable format.*" \ + "set sysroot with bad lib1" + +# 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" \ + "\r\n$hex\[ \t\]+$hex\[ \t\]+Yes\[^\r\n\]*[string_to_regexp $sysroot_lib2]\r\n.*" \ + "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