public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
From: "pablogsal at gmail dot com" <sourceware-bugzilla@sourceware.org>
To: gdb-prs@sourceware.org
Subject: [Bug corefiles/31634] New: gdb doesn't correctly fetch the soname of shared libraries
Date: Fri, 12 Apr 2024 11:38:10 +0000	[thread overview]
Message-ID: <bug-31634-4717@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2024-04-12 11:38 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 11:38 pablogsal at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-31634-4717@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=gdb-prs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).