This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [patch] Fix ELF stale reference
- From: Jan Kratochvil <jan dot kratochvil at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org, Doug Evans <dje at google dot com>
- Date: Fri, 19 Nov 2010 23:48:54 +0100
- Subject: Re: [patch] Fix ELF stale reference
- References: <20100908185837.GA24606@host1.dyn.jankratochvil.net> <m3wrqwrplv.fsf@fleche.redhat.com> <20100909090511.GA937@host1.dyn.jankratochvil.net> <AANLkTikm4c_dPTiqA8hsw8AkNbpKbyQNxC3qgRJi98Au@mail.gmail.com> <20100909145615.GA5771@host1.dyn.jankratochvil.net> <20101014160653.GA24333@host1.dyn.jankratochvil.net> <m3hbgo8y6y.fsf@fleche.redhat.com>
On Thu, 14 Oct 2010 19:46:13 +0200, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
> Jan> OK to check-in? Or some bfd/ API improvement should be made?
>
> I think this is probably the cleanest fix.
Checked in.
> However, libbfd.h does say right at the top that it shouldn't be used.
>
> I guess we could ask for advice on the binutils list.
This part has been fixed recently in binutils (as you forwarded me):
http://sourceware.org/ml/binutils/2010-10/msg00413.html
So no new libbfd.h include is now needed in GDB.
Regarding the introduced memory leak it seems to be fixable but I have only
filed GDB PR for it now:
http://sourceware.org/bugzilla/show_bug.cgi?id=12243
Thanks,
Jan
http://sourceware.org/ml/gdb-cvs/2010-11/msg00094.html
--- src/gdb/ChangeLog 2010/11/19 18:10:43 1.12319
+++ src/gdb/ChangeLog 2010/11/19 22:30:44 1.12320
@@ -1,4 +1,10 @@
2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
+
+ Fix stale memory references.
+ * elfread.c (elf_symfile_read): Replace xmalloc by bfd_alloc, drop
+ xfree, new comment.
+
+2010-11-19 Jan Kratochvil <jan.kratochvil@redhat.com>
Tom Tromey <tromey@redhat.com>
* Makefile.in (.y.c): Directly create $@ from YLWRAP.
--- src/gdb/elfread.c 2010/10/01 20:26:11 1.99
+++ src/gdb/elfread.c 2010/11/19 22:30:47 1.100
@@ -790,8 +790,14 @@
if (storage_needed > 0)
{
- dyn_symbol_table = (asymbol **) xmalloc (storage_needed);
- make_cleanup (xfree, dyn_symbol_table);
+ /* Memory gets permanently referenced from ABFD after
+ bfd_get_synthetic_symtab so it must not get freed before ABFD gets.
+ It happens only in the case when elf_slurp_reloc_table sees
+ asection->relocation NULL. Determining which section is asection is
+ done by _bfd_elf_get_synthetic_symtab which is all a bfd
+ implementation detail, though. */
+
+ dyn_symbol_table = bfd_alloc (abfd, storage_needed);
dynsymcount = bfd_canonicalize_dynamic_symtab (objfile->obfd,
dyn_symbol_table);