From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id zVTEGulKxmpYAg8AWB0awg (envelope-from ) for ; Wed, 07 Oct 2026 09:36:41 -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=HjnEqMav; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 3A3AE1E04E; Wed, 07 Oct 2026 09:36:41 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 B33451E04E for ; Wed, 07 Oct 2026 09:36:36 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D06494BA2E22 for ; Wed, 7 Oct 2026 13:36:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D06494BA2E22 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=HjnEqMav Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id 3A3554BA2E04 for ; Wed, 7 Oct 2026 13:36:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3A3554BA2E04 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 3A3554BA2E04 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791380167; cv=none; b=RcStoY5INL4HsfjRfjJv4K6UNkuZI6VKFgaf2yKk59kiGa33tlqYOgh0JLTlg70690hp0cV9rPENjKfy4SW6joV1r2IcbE6ncTWjJjJS6eNXCkEzYAeLzCatY4uUlYFG9+lW/5CmZjXjRxbT8KcMUAXMnLYBcE0X3TfSHZfEMuU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1791380167; c=relaxed/simple; bh=VIOAhGwz5ucmSyGY+mSP+m4x9eFUnAjAVr1n3tu5Wz8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d7q7p5AWiE7nyY828vzORedLNb2PIhQlh1OyP8ywzKdddr9q6VlJKm/aUEOdAjTeyEpZyvN+aSOHymU5brSktLDugNWoSUvaTMaOarxpyoAT1fBaHWz7VgpGmJI4H5FSbL4o9OZqZsJjpyh5z1myclhOIXgsTzEqm5m/thV7gYM= 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=HjnEqMav DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A3554BA2E04 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4a018dc1f98so16397415e9.3 for ; Wed, 07 Oct 2026 06:36:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=undo.io; s=google; t=1791380166; x=1791984966; 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=BGU0V3e0254cVFC5llgl41+M5zVmDKQpWPHdYQA4tAk=; b=HjnEqMav1u7ve2TIaVEKoappGa1GqmUUn2yTsIbS9Z290A0XzU4EJzip001sXM8Q7m StZcNgO/YCiU4sLgRzuwnn5M+8mgmaE1+MLNQovtnW/S5ixjsn09RAsYUbwQh3bWjF4V iFkNTufDX0d3x2iL598z9Lv85CiAyGyJV25T/6rYMz2AtChwxD7TY2l14KxYeXHfcJpH ahtiOtlKe3qOyDjjXiroU8FRDHA0jo0kjyEdxQbcJmhPpaEobsBiVG64w1A7drj27RmN b0CxeSvPN6JS8ivSewrWOBu/iTE3s0SVqachczpvq8VYqF3uaQXs2SBJAA2qRXeqXc0J IG9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791380166; x=1791984966; 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=BGU0V3e0254cVFC5llgl41+M5zVmDKQpWPHdYQA4tAk=; b=ce3Aaf1qfuT9JPGrV2db/g7EYL8tDl3aSPVXtIagJHWLbJ4lY33ZUNSEG6/v7RhoD7 c+NH5HPei5JbRQX9bvdsVcvEQgLLseTL5llSnkuv5L7AEgN3gS8BRXOeffoFeH5hpVbr 9MHVECws+A2lo8GQmE0QD62L4/boSmzDLE8j6oUQmmKNyXuAonFvnCPS2tu1wjDrRBu9 BSjN1u8+lFATOKsK7P0x/hxZJ33PD3I2uss8R57NMgh3XxHFnKxzewJzhvwYEM90Qs3W MaMzXx05H+eFJLHU5Ktabubtj9GS5Bei2Kqx2nbNk8yNWpdMrmTy26DglcBHdEFKLIi+ WrLQ== X-Gm-Message-State: AFuF++liUDRi2B3QP+2BdJStl7ojCSHcvQseXfvLYLQ7dGieUENlUwqw wby+dmnN6t+zyzfg1fDPEAZWMBVfQX8X4OyyxeF6MzqUF9xdu9GV6GkgiUpiKlExvDj6PBJzHh3 Wtl/uDp01YtgF+9KyccCO+D7+MueEiYS2wutgraciVvjJL03yRquWLDqK7wPvVILZH8fT7Truvx cg8mddEQbcMDi0PqH7TvXW2d/5f01TijQOyg+xqQ== X-Gm-Gg: AYBFou2ozErmOe7dA8egJwZIAynROlitb6KFI1i06/Rgzxxw7IgNreVCWbtt2BSDZgv 4Cq7niCSe1WQZZBP+e+4NFk1YNnF6jB1SCTsMpZYJkUAkCHuuSDTKbLDiJ3gy8mKXn0ssswxVAv wfJ6/mflqUCXfyhkyeJQoCfHyglA5yCaYXFhKEAMDjqy191yYXLLFq+OnvgayB2YCp6jHZAgWNa Icj1irPwBw3XLLZroFNsEp16b5OUl9qv3H1qUEf2wOUySa0hcAIPehYMonhHjtXkQ7TC725LlEs WO7Xro21waE7iC6R7pM3cBdKwhqqiJaihuR62Ne6H78Alx6GOTf3YOUB0pTRUhhTdSUmv0lCYR1 bkO7QiNV3I6Aand1TzRrpP0eDU0c6ocXmlDSfnHfQZtjPSXfj/eWGpeo5ybQI9XxI7S9fSeiu8I 2P8RbyeJkj8jsnRxIuI72+jYbgED2yOVIrLQFdC3QwcVWFY5u5UhWE0KiMjMhccVWr2In2FF0U6 +8TUTvQ8XsZh88= X-Received: by 2002:a05:600c:6989:b0:49e:645e:2616 with SMTP id 5b1f17b1804b1-4a1802f6262mr38367685e9.5.1791380165900; Wed, 07 Oct 2026 06:36:05 -0700 (PDT) Received: from r90v1yyb-ubuntu.powerhub ([2a0a:ef40:28b2:c201:1de:e379:4062:9bbf]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4a1822af9d5sm41446955e9.15.2026.10.07.06.36.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2026 06:36:04 -0700 (PDT) From: Eduard-Petru Jipa To: gdb-patches@sourceware.org Cc: stephan.rohr@intel.com, Eduard Jipa Subject: [PATCH v2] gdb: don't abort shared library reload when one library fails to open Date: Wed, 7 Oct 2026 14:36:20 +0100 Message-ID: <20261007133620.50516-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. --- 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..a8db733558a --- /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. +gdb_test "info sharedlibrary" \ + "\r\n\[ \t\]+No\[ \t\]+[string_to_regexp $lib1]\r\n.*" \ + "lib1 is not 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" \ + "\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