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

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