This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix ELF stale reference


I was debugging and got to
this fix from a different side.  It is in fact a very common GDB crash - due
to CTRL-C hit (to get GDB prompt) in the moment an ELF file is being read in.

Original thread:

On Thu, 09 Sep 2010 16:56:15 +0200, Jan Kratochvil wrote:
> OTOH this patch is not completely clean, it can needlessly allocate
> bfd-associated memory and the right fix would probably span into bfd/ IMO.

While the memory could use for example register_objfile_data_with_cleanup
instead of bfd_alloc so that if errors/CTRL-Cs happen the dynamic symbol table
pointers memory is not allocated twice.   Still I would not find it correct as
such memory would be objfile-bound instead of abfd-bound - while being
referenced by abfd.

OK to check-in?  Or some bfd/ API improvement should be made?


2010-09-09  Jan Kratochvil  <>

	Fix stale memory references.
	* elfread.c: Include libbfd.h.
	(elf_symfile_read): Replace xmalloc by bfd_alloc, drop xfree, new

--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -37,6 +37,7 @@
 #include "complaints.h"
 #include "demangle.h"
 #include "psympriv.h"
+#include "libbfd.h"
 extern void _initialize_elfread (void);
@@ -792,8 +793,14 @@ elf_symfile_read (struct objfile *objfile, int symfile_flags)
   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,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]