public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Avoid crash with cross-linux core file
@ 2021-12-15 18:33 Tom Tromey
  2021-12-15 18:39 ` John Baldwin
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2021-12-15 18:33 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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:

    | (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_make_msymbol_special_p(gdbarch*): Assertion `gdbarch != NULL' failed.
    | A problem internal to GDB has been detected,
    | further debugging may prove unreliable.
    | Quit this debugging session? (y or n) y

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.

But, because gdb isn't configured to handle these libraries, it
crashes.

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:

    | [New LWP 15488]
    | Error while mapping shared library sections:
    | `/lib64/libc.so.6': Shared library architecture unknown is not compatible with target architecture powerpc:common64.

... and does not crash gdb.

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.
---
 gdb/solib.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gdb/solib.c b/gdb/solib.c
index 3947c2d1d2e..b2205fd245b 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -511,10 +511,10 @@ solib_bfd_open (const char *pathname)
   /* Check bfd arch.  */
   b = 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);
 
   return abfd;
 }
-- 
2.31.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid crash with cross-linux core file
  2021-12-15 18:33 [PATCH] Avoid crash with cross-linux core file Tom Tromey
@ 2021-12-15 18:39 ` John Baldwin
  2022-03-11 16:24   ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: John Baldwin @ 2021-12-15 18:39 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 12/15/21 10:33 AM, Tom Tromey via Gdb-patches wrote:
> 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:
> 
>      | (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_make_msymbol_special_p(gdbarch*): Assertion `gdbarch != NULL' failed.
>      | A problem internal to GDB has been detected,
>      | further debugging may prove unreliable.
>      | Quit this debugging session? (y or n) y
> 
> 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.
> 
> But, because gdb isn't configured to handle these libraries, it
> crashes.
> 
> 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:
> 
>      | [New LWP 15488]
>      | Error while mapping shared library sections:
>      | `/lib64/libc.so.6': Shared library architecture unknown is not compatible with target architecture powerpc:common64.

Do you no longer get the warning about setting sysroot, etc.?  If it's possible to keep
those that might be nice, but perhaps that means returning an error and the caller would
have to error out later (or maybe moving the suggestion message earlier to be part of this
error?)  I do think it is true that if the solib isn't compatible, we probably shouldn't
keep trying to use it "just in case".

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid crash with cross-linux core file
  2021-12-15 18:39 ` John Baldwin
@ 2022-03-11 16:24   ` Tom Tromey
  2022-03-11 16:55     ` John Baldwin
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2022-03-11 16:24 UTC (permalink / raw)
  To: John Baldwin; +Cc: Tom Tromey, gdb-patches

>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:

>> | [New LWP 15488]
>> | Error while mapping shared library sections:
>> | `/lib64/libc.so.6': Shared library architecture unknown is not compatible with target architecture powerpc:common64.

John> Do you no longer get the warning about setting sysroot, etc.?

I finally got around to reproducing this one so I could answer your
question.  Anyway, the answer is that we do still get it:

    Error while mapping shared library sections:
    `/lib64/libc.so.6': Shared library architecture i386:x86-64 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"?

I'm going to check this patch in.

thanks,
Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid crash with cross-linux core file
  2022-03-11 16:24   ` Tom Tromey
@ 2022-03-11 16:55     ` John Baldwin
  2022-03-11 18:52       ` Tom Tromey
  0 siblings, 1 reply; 5+ messages in thread
From: John Baldwin @ 2022-03-11 16:55 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

On 3/11/22 8:24 AM, Tom Tromey wrote:
>>>>>> "John" == John Baldwin <jhb@FreeBSD.org> writes:
> 
>>> | [New LWP 15488]
>>> | Error while mapping shared library sections:
>>> | `/lib64/libc.so.6': Shared library architecture unknown is not compatible with target architecture powerpc:common64.
> 
> John> Do you no longer get the warning about setting sysroot, etc.?
> 
> I finally got around to reproducing this one so I could answer your
> question.  Anyway, the answer is that we do still get it:
> 
>      Error while mapping shared library sections:
>      `/lib64/libc.so.6': Shared library architecture i386:x86-64 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"?
> 
> I'm going to check this patch in.

Ok, thanks for checking.  I didn't mean to be a blocker.

-- 
John Baldwin

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Avoid crash with cross-linux core file
  2022-03-11 16:55     ` John Baldwin
@ 2022-03-11 18:52       ` Tom Tromey
  0 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2022-03-11 18:52 UTC (permalink / raw)
  To: John Baldwin; +Cc: Tom Tromey, gdb-patches

John> Ok, thanks for checking.  I didn't mean to be a blocker.

It's no problem, I felt that was a good question that I hadn't thought
of, and so I wanted to check it before committing.

Tom

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-03-11 18:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-15 18:33 [PATCH] Avoid crash with cross-linux core file Tom Tromey
2021-12-15 18:39 ` John Baldwin
2022-03-11 16:24   ` Tom Tromey
2022-03-11 16:55     ` John Baldwin
2022-03-11 18:52       ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).