public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries
@ 2024-04-12 11:38 pablogsal at gmail dot com
  2024-04-12 11:39 ` [Bug corefiles/31634] " pablogsal at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pablogsal at gmail dot com @ 2024-04-12 11:38 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

            Bug ID: 31634
           Summary: gdb doesn't correctly fetch the soname of shared
                    libraries
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: corefiles
          Assignee: unassigned at sourceware dot org
          Reporter: pablogsal at gmail dot com
  Target Milestone: ---

Looks like gdb_bfd_read_elf_soname fails to correctly fetch the soname of some
libraries. For example, consider the following:

$ cat main.c
extern void foo(int);

int main() {
  foo(13);
  return 0;
}

$ cat foo.c
#include <unistd.h>

void foo(int x);
void foo1(int x);
void foo2(int x);
void foo3(int x);

void foo(int x) { return foo1(x); }

void foo1(int x) { return foo2(x); }

void foo2(int x) { return foo3(x); }

void foo3(int x) { sleep(1000); }

$ gcc foo.c -o libfoo.so --shared -fPIC -g3 -O0 -Wl,-hlibfoo.so

$ gcc main.c -g3 -O0 -lfoo -L .

$ gdb ./a.out
Reading symbols from ./a.out...
(gdb) r
Starting program: /home/pablogsal/github/binutils-gdb/lel/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7e792f7 in clock_nanosleep () from /usr/lib/libc.so.6
(gdb) gcore
warning: Memory read failed for corefile section, 4096 bytes at
0xffffffffff600000.
Saved corefile core.1263203

$ gdb --args --gdb -c core.1263203 -e ./a.out
(gdb) b gdb_bfd_read_elf_soname
(gdb) r
...
Thread 1 "gdb" hit Breakpoint 1, gdb_bfd_read_elf_soname
(filename=0x5555563acf50 "/home/pablogsal/github/binutils-gdb/lel/libfoo.so")
at solib.c:1600
1600    {
(gdb) finish
...
Value returned is $1 = std::unique_ptr<char> = {get() = 0x55555631c340
"gisterTMCloneTable"}


As you can see the returned soname is some garbage (gisterTMCloneTable) but the
real soname is correctly set:

$ readelf -d libfoo.so

Dynamic section at offset 0x2df8 contains 25 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libfoo.so]
 ...

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
@ 2024-04-12 11:39 ` pablogsal at gmail dot com
  2024-04-19 19:53 ` amerey at redhat dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pablogsal at gmail dot com @ 2024-04-12 11:39 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

--- Comment #1 from Pablo Galindo Salgado <pablogsal at gmail dot com> ---
This was done with gdb HEAD and GCC 13.2.1 202308

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
  2024-04-12 11:39 ` [Bug corefiles/31634] " pablogsal at gmail dot com
@ 2024-04-19 19:53 ` amerey at redhat dot com
  2024-04-22 11:20 ` pablogsal at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: amerey at redhat dot com @ 2024-04-19 19:53 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

Aaron Merey <amerey at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amerey at redhat dot com

--- Comment #2 from Aaron Merey <amerey at redhat dot com> ---
Thanks for the detailed bug report.  I tried to reproduce this but it worked
correctly for me:

    Thread 1 "gdb" hit Breakpoint 1, gdb_bfd_read_elf_soname (filename=0xea0680
"/home/amerey/test/solib/libfoo.so")
        at solib.c:1599
    1599          gdb_bfd_ref_ptr abfd = gdb_bfd_open (filename, gnutarget);
    (gdb) finish
    [...]
    Value returned is $1 = std::unique_ptr<char> = {
      get() = 0xeaa860 "libfoo.so"
    }

If you're able to upload your corefile where this fails I'll take a look at it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
  2024-04-12 11:39 ` [Bug corefiles/31634] " pablogsal at gmail dot com
  2024-04-19 19:53 ` amerey at redhat dot com
@ 2024-04-22 11:20 ` pablogsal at gmail dot com
  2024-04-25 23:25 ` amerey at redhat dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pablogsal at gmail dot com @ 2024-04-22 11:20 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

--- Comment #3 from Pablo Galindo Salgado <pablogsal at gmail dot com> ---
Created attachment 15477
  --> https://sourceware.org/bugzilla/attachment.cgi?id=15477&action=edit
core file + libfoo

I am attaching the requested files to this ticket

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
                   ` (2 preceding siblings ...)
  2024-04-22 11:20 ` pablogsal at gmail dot com
@ 2024-04-25 23:25 ` amerey at redhat dot com
  2024-04-26  0:27 ` pablogsal at gmail dot com
  2024-04-26 14:39 ` sam at gentoo dot org
  5 siblings, 0 replies; 7+ messages in thread
From: amerey at redhat dot com @ 2024-04-25 23:25 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

--- Comment #4 from Aaron Merey <amerey at redhat dot com> ---
Hi Pablo, I'm still not able to reproduce this bug with the binaries you
provided. Valgrind did not detect any invalid reads or writes while gdb read
the corefile that was uploaded. I'm not yet sure what could be causing the junk
soname you're seeing.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
                   ` (3 preceding siblings ...)
  2024-04-25 23:25 ` amerey at redhat dot com
@ 2024-04-26  0:27 ` pablogsal at gmail dot com
  2024-04-26 14:39 ` sam at gentoo dot org
  5 siblings, 0 replies; 7+ messages in thread
From: pablogsal at gmail dot com @ 2024-04-26  0:27 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

--- Comment #5 from Pablo Galindo Salgado <pablogsal at gmail dot com> ---
Thanks a lot for checking! I am going to try to reproduce this myself in other
systems to see if I can provide more insights here or provide a better way to
reproduce. I have checked and this happens consistently in my system with gdb
HEAD so maybe I can dig a bit into what is going on. I will also try running
valgrind or asan over it

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

* [Bug corefiles/31634] gdb doesn't correctly fetch the soname of shared libraries
  2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
                   ` (4 preceding siblings ...)
  2024-04-26  0:27 ` pablogsal at gmail dot com
@ 2024-04-26 14:39 ` sam at gentoo dot org
  5 siblings, 0 replies; 7+ messages in thread
From: sam at gentoo dot org @ 2024-04-26 14:39 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=31634

Sam James <sam at gentoo dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sam at gentoo dot org

-- 
You are receiving this mail because:
You are on the CC list for the bug.

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

end of thread, other threads:[~2024-04-26 14:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-12 11:38 [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries pablogsal at gmail dot com
2024-04-12 11:39 ` [Bug corefiles/31634] " pablogsal at gmail dot com
2024-04-19 19:53 ` amerey at redhat dot com
2024-04-22 11:20 ` pablogsal at gmail dot com
2024-04-25 23:25 ` amerey at redhat dot com
2024-04-26  0:27 ` pablogsal at gmail dot com
2024-04-26 14:39 ` sam at gentoo dot org

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).