From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id AD1033858D3C; Fri, 11 Mar 2022 16:26:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AD1033858D3C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Avoid crash with cross-linux core file X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 8bdc7ff421aa5f07dd99ea7b446fb3fc2f0a3127 X-Git-Newrev: c0e0d6bcfed32f7bdb76c92b319148e7b25eabd0 Message-Id: <20220311162626.AD1033858D3C@sourceware.org> Date: Fri, 11 Mar 2022 16:26:26 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Mar 2022 16:26:26 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Dc0e0d6bcfed3= 2f7bdb76c92b319148e7b25eabd0 commit c0e0d6bcfed32f7bdb76c92b319148e7b25eabd0 Author: Tom Tromey Date: Mon Dec 13 14:43:18 2021 -0700 Avoid crash with cross-linux core file =20 An internal test case creates a core file using gcore, then restarts gdb with that core. When run with a cross-linux gdb (in this case, x86-64 host with ppc64-linux target), the test fails: =20 | (gdb) core core | [New LWP 18437] | warning: `/lib64/libc.so.6': Shared library architecture unknown = is not compatible with target architecture powerpc:common64. | warning: Could not load shared library symbols for /lib64/ld64.so= .1. | Do you need "set solib-search-path" or "set sysroot"? | ../../src/gdb/gdbarch.c:3388: internal-error: int gdbarch_elf_mak= e_msymbol_special_p(gdbarch*): Assertion `gdbarch !=3D NULL' failed. | A problem internal to GDB has been detected, | further debugging may prove unreliable. | Quit this debugging session? (y or n) y =20 What's happening here is that the core file lists some shared libraries. These aren't available via the solib search path, and so gdb finds the local (x86-64) libraries. This is not ideal, but on the other hand, it is what was asked for -- while the test does set solib-search-path, it does not set the sysroot. =20 But, because gdb isn't configured to handle these libraries, it crashes. =20 It seems to me that it's better to avoid the crash by having solib_bfd_open fail in the case where a library is incompatible. That is what this patch does. Now it looks like: =20 | [New LWP 15488] | Error while mapping shared library sections: | `/lib64/libc.so.6': Shared library architecture unknown is not co= mpatible with target architecture powerpc:common64. =20 ... and does not crash gdb. =20 I don't have a good setup for testing this using dejagnu, so I don't know whether an existing gdb test covers this scenario. Diff: --- gdb/solib.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gdb/solib.c b/gdb/solib.c index b9b1d037187..8bcbfa22df1 100644 --- a/gdb/solib.c +++ b/gdb/solib.c @@ -511,10 +511,10 @@ solib_bfd_open (const char *pathname) /* Check bfd arch. */ b =3D gdbarch_bfd_arch_info (target_gdbarch ()); if (!b->compatible (b, bfd_get_arch_info (abfd.get ()))) - warning (_("`%s': Shared library architecture %s is not compatible " - "with target architecture %s."), bfd_get_filename (abfd.get ()), - bfd_get_arch_info (abfd.get ())->printable_name, - b->printable_name); + error (_("`%s': Shared library architecture %s is not compatible " + "with target architecture %s."), bfd_get_filename (abfd.get ()), + bfd_get_arch_info (abfd.get ())->printable_name, + b->printable_name); =20 return abfd; }