mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-07-10 17:41:23 +08:00
stab nearest_line bfd_malloc_and_get_section
bfd_malloc_and_get_section performs some sanity checks on the section size before allocating memory. This patch avails the stab nearest_line code of that sanity checking, and tidies up memory afterward. * coffgen.c (_bfd_coff_close_and_cleanup): Call _bfd_stab_cleanup. * elf.c (_bfd_elf_close_and_cleanup): Likewise. * syms.c (_bfd_stab_section_find_nearest_line): Set *pinfo earlier. Use bfd_malloc_and_get_section. Free malloc'd buffers on failure. Malloc indextable. (_bfd_stab_cleanup): New function. * libbfd-in.h (_bfd_stab_cleanup): Declare. * libbfd.h: Regnerate.
This commit is contained in:
@ -3175,7 +3175,10 @@ _bfd_coff_close_and_cleanup (bfd *abfd)
|
|||||||
|
|
||||||
if (bfd_get_format (abfd) == bfd_object
|
if (bfd_get_format (abfd) == bfd_object
|
||||||
|| bfd_get_format (abfd) == bfd_core)
|
|| bfd_get_format (abfd) == bfd_core)
|
||||||
_bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
|
{
|
||||||
|
_bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
|
||||||
|
_bfd_stab_cleanup (abfd, &tdata->line_info);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return _bfd_generic_close_and_cleanup (abfd);
|
return _bfd_generic_close_and_cleanup (abfd);
|
||||||
}
|
}
|
||||||
|
@ -9649,6 +9649,7 @@ _bfd_elf_close_and_cleanup (bfd *abfd)
|
|||||||
if (elf_tdata (abfd)->o != NULL && elf_shstrtab (abfd) != NULL)
|
if (elf_tdata (abfd)->o != NULL && elf_shstrtab (abfd) != NULL)
|
||||||
_bfd_elf_strtab_free (elf_shstrtab (abfd));
|
_bfd_elf_strtab_free (elf_shstrtab (abfd));
|
||||||
_bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
|
_bfd_dwarf2_cleanup_debug_info (abfd, &tdata->dwarf2_find_line_info);
|
||||||
|
_bfd_stab_cleanup (abfd, &tdata->line_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _bfd_generic_close_and_cleanup (abfd);
|
return _bfd_generic_close_and_cleanup (abfd);
|
||||||
|
@ -615,6 +615,9 @@ extern bool _bfd_dwarf2_slurp_debug_info
|
|||||||
extern void _bfd_dwarf2_cleanup_debug_info
|
extern void _bfd_dwarf2_cleanup_debug_info
|
||||||
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
||||||
|
|
||||||
|
extern void _bfd_stab_cleanup
|
||||||
|
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
||||||
|
|
||||||
/* Create a new section entry. */
|
/* Create a new section entry. */
|
||||||
extern struct bfd_hash_entry *bfd_section_hash_newfunc
|
extern struct bfd_hash_entry *bfd_section_hash_newfunc
|
||||||
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
|
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
|
||||||
|
@ -620,6 +620,9 @@ extern bool _bfd_dwarf2_slurp_debug_info
|
|||||||
extern void _bfd_dwarf2_cleanup_debug_info
|
extern void _bfd_dwarf2_cleanup_debug_info
|
||||||
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
||||||
|
|
||||||
|
extern void _bfd_stab_cleanup
|
||||||
|
(bfd *, void **) ATTRIBUTE_HIDDEN;
|
||||||
|
|
||||||
/* Create a new section entry. */
|
/* Create a new section entry. */
|
||||||
extern struct bfd_hash_entry *bfd_section_hash_newfunc
|
extern struct bfd_hash_entry *bfd_section_hash_newfunc
|
||||||
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
|
(struct bfd_hash_entry *, struct bfd_hash_table *, const char *)
|
||||||
|
67
bfd/syms.c
67
bfd/syms.c
@ -978,7 +978,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
{
|
{
|
||||||
if (info->stabsec == NULL || info->strsec == NULL)
|
if (info->stabsec == NULL || info->strsec == NULL)
|
||||||
{
|
{
|
||||||
/* No stabs debugging information. */
|
/* No usable stabs debugging information. */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1000,6 +1000,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
info = (struct stab_find_info *) bfd_zalloc (abfd, amt);
|
info = (struct stab_find_info *) bfd_zalloc (abfd, amt);
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
*pinfo = info;
|
||||||
|
|
||||||
/* FIXME: When using the linker --split-by-file or
|
/* FIXME: When using the linker --split-by-file or
|
||||||
--split-by-reloc options, it is possible for the .stab and
|
--split-by-reloc options, it is possible for the .stab and
|
||||||
@ -1015,12 +1016,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
info->strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
|
info->strsec = bfd_get_section_by_name (abfd, "$GDB_STRINGS$");
|
||||||
|
|
||||||
if (info->stabsec == NULL || info->strsec == NULL)
|
if (info->stabsec == NULL || info->strsec == NULL)
|
||||||
{
|
return true;
|
||||||
/* No stabs debugging information. Set *pinfo so that we
|
|
||||||
can return quickly in the info != NULL case above. */
|
|
||||||
*pinfo = info;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stabsize = (info->stabsec->rawsize
|
stabsize = (info->stabsec->rawsize
|
||||||
@ -1031,16 +1027,10 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
? info->strsec->rawsize
|
? info->strsec->rawsize
|
||||||
: info->strsec->size);
|
: info->strsec->size);
|
||||||
|
|
||||||
info->stabs = (bfd_byte *) bfd_alloc (abfd, stabsize);
|
if (!bfd_malloc_and_get_section (abfd, info->stabsec, &info->stabs))
|
||||||
info->strs = (bfd_byte *) bfd_alloc (abfd, strsize);
|
goto out;
|
||||||
if (info->stabs == NULL || info->strs == NULL)
|
if (!bfd_malloc_and_get_section (abfd, info->strsec, &info->strs))
|
||||||
return false;
|
goto out1;
|
||||||
|
|
||||||
if (! bfd_get_section_contents (abfd, info->stabsec, info->stabs,
|
|
||||||
0, stabsize)
|
|
||||||
|| ! bfd_get_section_contents (abfd, info->strsec, info->strs,
|
|
||||||
0, strsize))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
/* Stab strings ought to be nul terminated. Ensure the last one
|
/* Stab strings ought to be nul terminated. Ensure the last one
|
||||||
is, to prevent running off the end of the buffer. */
|
is, to prevent running off the end of the buffer. */
|
||||||
@ -1052,15 +1042,24 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
this should be no big deal. */
|
this should be no big deal. */
|
||||||
reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec);
|
reloc_size = bfd_get_reloc_upper_bound (abfd, info->stabsec);
|
||||||
if (reloc_size < 0)
|
if (reloc_size < 0)
|
||||||
return false;
|
goto out2;
|
||||||
reloc_vector = (arelent **) bfd_malloc (reloc_size);
|
reloc_vector = (arelent **) bfd_malloc (reloc_size);
|
||||||
if (reloc_vector == NULL && reloc_size != 0)
|
if (reloc_vector == NULL && reloc_size != 0)
|
||||||
return false;
|
goto out2;
|
||||||
reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector,
|
reloc_count = bfd_canonicalize_reloc (abfd, info->stabsec, reloc_vector,
|
||||||
symbols);
|
symbols);
|
||||||
if (reloc_count < 0)
|
if (reloc_count < 0)
|
||||||
{
|
{
|
||||||
|
out3:
|
||||||
free (reloc_vector);
|
free (reloc_vector);
|
||||||
|
out2:
|
||||||
|
free (info->strs);
|
||||||
|
info->strs = NULL;
|
||||||
|
out1:
|
||||||
|
free (info->stabs);
|
||||||
|
info->stabs = NULL;
|
||||||
|
out:
|
||||||
|
info->stabsec = NULL;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (reloc_count > 0)
|
if (reloc_count > 0)
|
||||||
@ -1091,8 +1090,7 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
(_("unsupported .stab relocation"));
|
(_("unsupported .stab relocation"));
|
||||||
bfd_set_error (bfd_error_invalid_operation);
|
bfd_set_error (bfd_error_invalid_operation);
|
||||||
free (reloc_vector);
|
goto out3;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val = bfd_get_32 (abfd, info->stabs + octets);
|
val = bfd_get_32 (abfd, info->stabs + octets);
|
||||||
@ -1146,14 +1144,21 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
++info->indextablesize;
|
++info->indextablesize;
|
||||||
|
|
||||||
if (info->indextablesize == 0)
|
if (info->indextablesize == 0)
|
||||||
return true;
|
{
|
||||||
|
free (info->strs);
|
||||||
|
info->strs = NULL;
|
||||||
|
free (info->stabs);
|
||||||
|
info->stabs = NULL;
|
||||||
|
info->stabsec = NULL;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
++info->indextablesize;
|
++info->indextablesize;
|
||||||
|
|
||||||
amt = info->indextablesize;
|
amt = info->indextablesize;
|
||||||
amt *= sizeof (struct indexentry);
|
amt *= sizeof (struct indexentry);
|
||||||
info->indextable = (struct indexentry *) bfd_alloc (abfd, amt);
|
info->indextable = (struct indexentry *) bfd_malloc (amt);
|
||||||
if (info->indextable == NULL)
|
if (info->indextable == NULL)
|
||||||
return false;
|
goto out3;
|
||||||
|
|
||||||
file_name = NULL;
|
file_name = NULL;
|
||||||
directory_name = NULL;
|
directory_name = NULL;
|
||||||
@ -1280,8 +1285,6 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
info->indextablesize = i;
|
info->indextablesize = i;
|
||||||
qsort (info->indextable, (size_t) i, sizeof (struct indexentry),
|
qsort (info->indextable, (size_t) i, sizeof (struct indexentry),
|
||||||
cmpindexentry);
|
cmpindexentry);
|
||||||
|
|
||||||
*pinfo = info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We are passed a section relative offset. The offsets in the
|
/* We are passed a section relative offset. The offsets in the
|
||||||
@ -1446,6 +1449,18 @@ _bfd_stab_section_find_nearest_line (bfd *abfd,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
_bfd_stab_cleanup (bfd *abfd ATTRIBUTE_UNUSED, void **pinfo)
|
||||||
|
{
|
||||||
|
struct stab_find_info *info = (struct stab_find_info *) *pinfo;
|
||||||
|
if (info == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
free (info->indextable);
|
||||||
|
free (info->strs);
|
||||||
|
free (info->stabs);
|
||||||
|
}
|
||||||
|
|
||||||
long
|
long
|
||||||
_bfd_nosymbols_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED,
|
_bfd_nosymbols_canonicalize_symtab (bfd *abfd ATTRIBUTE_UNUSED,
|
||||||
asymbol **location ATTRIBUTE_UNUSED)
|
asymbol **location ATTRIBUTE_UNUSED)
|
||||||
|
Reference in New Issue
Block a user