From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tromey@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: RFC: solib.c:solib_map_sections so->so_name clobbering (was: [PATCH 02/10] clean up allocation of bfd filenames)
Date: Thu, 28 Mar 2013 12:29:00 -0000 [thread overview]
Message-ID: <20130328011107.GA17105@adacore.com> (raw)
In-Reply-To: <87r4s83lu5.fsf@fleche.redhat.com>
Hi Tom,
> BFD requires the user to allocate the file name for a BFD.
> GDB does this inconsistently: sometimes the file name is malloc'd,
> sometimes not. Sometimes it is freed, sometimes not.
>
> This patch adds a new function that reallocated the BFD's filename
> using bfd_alloc. This ties the lifetime to the BFD and removes the
> need to free the filename when closing the BFD.
[...]
> * solib-darwin.c (darwin_solib_get_all_image_info_addr_at_init):
> Free found_pathname.
This patch accidently triggered a regression in the "info sharedlibrary"
command for darwin targets. With gdb-7.5:
(gdb) info shared
From To Syms Read Shared Object Library
0x00007fff8d8129eb 0x00007fff8d8131d8 Yes (*) /usr/lib/libSystem.B.dylib
0x00007fff8e5a4320 0x00007fff8e5a91c0 Yes (*) /usr/lib/system/libcache.dylib
[etc]
But with the current HEAD, the solib name becomes:
(gdb) info shared
From To Syms Read Shared Object Library
0x00007fff8d8129eb 0x00007fff8d8131d8 Yes (*) i386:x86-64
0x00007fff8e5a4320 0x00007fff8e5a91c0 Yes (*) i386:x86-64
That's because the solist's so_name get overwritten with the shared
object's bfd's filename in solib_map_sections:
/* copy full path name into so_name, so that later symbol_file_add
can find it. */
[...]
strcpy (so->so_name, bfd_get_filename (abfd));
This used to work more or less by accident, thanks to the following
piece of code in solib-darwin.c:darwin_bfd_open:
/* Make sure that the filename is malloc'ed. The current filename
for fat-binaries BFDs is a name that was generated by BFD, usually
a static string containing the name of the architecture. */
res->filename = xstrdup (pathname);
But your patch removed (justifiably) this code, which led us to
use the filename created by the BFD layer. For Mach-O fat binaries,
bfd explicitly uses the architecture name of the extracted object.
See bfd_mach_o_fat_member_init. I don't know why, but that's not
the only architecture that produces something which is not a valid
filename (refer to our discussion re AIX archives and their shared
objects).
To me, the part that looks the most intriguing of all is why solib.c
would overwrite the so_name set by the solib backend. I tried researching
that, but found that it has been this way since the beginning of CVS.
The comment is now OBE, since symbol_file_add is no longer responsible
for creating the BFD - the solib backend is. I also verified that
so_name appears to be used for no other purposes but printing or
so_name matching (Eg: deciding if loading of symbols for shared
library should be done or not).
With that in mind, I think the overwriting of the so_name might not
be needed or make much sense anymore. Removing it should fix the
regression on Darwin, and also help in the case of my work with the
solib-aix patch [1].
What do you (or others!) think? I am happy to test and submit a proper
patch. We wouldn't be able to use a patch like this on the 7.6 branch,
so for Darwin, I'd restore the xstrdup below - it would be a memory
leak, but better to have a leak than not having the shared library name,
IMO.
Thanks!
> diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
> index bc2cd79..242f8cc 100644
> --- a/gdb/solib-darwin.c
> +++ b/gdb/solib-darwin.c
> @@ -510,17 +510,10 @@ darwin_bfd_open (char *pathname)
> gdbarch_bfd_arch_info (target_gdbarch));
> if (!res)
> {
> - gdb_bfd_unref (abfd);
> - make_cleanup (xfree, found_pathname);
> + make_cleanup_bfd_close (abfd);
> error (_("`%s': not a shared-library: %s"),
> - found_pathname, bfd_errmsg (bfd_get_error ()));
> + bfd_get_filename (abfd), bfd_errmsg (bfd_get_error ()));
> }
> -
> - /* Make sure that the filename is malloc'ed. The current filename
> - for fat-binaries BFDs is a name that was generated by BFD, usually
> - a static string containing the name of the architecture. */
> - res->filename = xstrdup (pathname);
--
Joel
[1] http://www.sourceware.org/ml/gdb-patches/2013-03/msg00818.html
next prev parent reply other threads:[~2013-03-28 1:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-18 19:34 [PATCH 02/10] clean up allocation of bfd filenames Tom Tromey
2012-07-19 18:52 ` Jan Kratochvil
2012-07-19 20:59 ` Tom Tromey
2012-07-20 16:30 ` Tom Tromey
2012-07-20 18:07 ` Jan Kratochvil
2013-03-28 12:29 ` Joel Brobecker [this message]
2013-03-28 19:12 ` RFC: solib.c:solib_map_sections so->so_name clobbering Tom Tromey
2013-03-29 1:59 ` Joel Brobecker
2013-03-29 7:43 ` darwin: fix SO name in "info sharedlibrary" (was: "RFC: solib.c:solib_map_sections so->so_name clobbering") Joel Brobecker
2013-04-09 2:17 ` darwin: fix SO name in "info sharedlibrary" Tom Tromey
2013-04-11 5:40 ` checked in: " Joel Brobecker
2013-04-11 4:03 ` checked in: Re: RFC: solib.c:solib_map_sections so->so_name clobbering Joel Brobecker
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=20130328011107.GA17105@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/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