[5/10] RFC: introduce gdb_bfd_section_index
Yao Qi
yao@codesourcery.com
Mon Apr 29 10:21:00 GMT 2013
Tom,
This patch is related to a GDB crash for tic6x-uclinux target. I am not
familiar with objfile/section stuff, so correct me if my thoughts below
are incorrect.
On 02/19/2013 04:27 AM, Tom Tromey wrote:
> void
> build_objfile_section_table (struct objfile *objfile)
> {
> - objfile->sections_end = 0;
> + int count = gdb_bfd_count_sections (objfile->obfd);
> +
> + objfile->sections = OBSTACK_CALLOC (&objfile->objfile_obstack,
> + count,
> + struct obj_section);
> + objfile->sections_end = (objfile->sections + count);
We start allocate 'gdb_bfd_count_sections' (which is bfd_count_sections
+ 4) entries of sections.
> bfd_map_over_sections (objfile->obfd,
> add_to_objfile_sections, (void *) objfile);
> - objfile->sections = obstack_finish (&objfile->objfile_obstack);
> - objfile->sections_end = objfile->sections + (size_t) objfile->sections_end;
> +
> + /* See gdb_bfd_section_index. */
> + add_to_objfile_sections_full (objfile->obfd, bfd_com_section_ptr, objfile, 1);
> + add_to_objfile_sections_full (objfile->obfd, bfd_und_section_ptr, objfile, 1);
> + add_to_objfile_sections_full (objfile->obfd, bfd_abs_section_ptr, objfile, 1);
> + add_to_objfile_sections_full (objfile->obfd, bfd_ind_section_ptr, objfile, 1);
> }
>
> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index df9caef..0f1cd68 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -1060,7 +1060,7 @@ fixup_section (struct general_symbol_info *ginfo,
>
> ALL_OBJFILE_OSECTIONS (objfile, s)
> {
> - int idx = s->the_bfd_section->index;
> + int idx = s - objfile->sections;
The range of IDX will be [0, bfd_count_sections () + 4),
> CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
the 'objfile->section_offsets' is allocated with objfile->num_sections
entries, which is bfd_count_sections (), IIUC. I can't reproduce any
crash caused by this potential overflow here.
> diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
> index c41326b..586ab8e 100644
> --- a/gdb/solib-dsbt.c
> +++ b/gdb/solib-dsbt.c
> @@ -1054,7 +1054,7 @@ dsbt_relocate_main_executable (void)
> int osect_idx;
> int seg;
>
> - osect_idx = osect->the_bfd_section->index;
> + osect_idx = osect - symfile_objfile->sections;
>
> /* Current address of section. */
> addr = obj_section_addr (osect);
The code here can abbreviated like this,
new_offsets = xcalloc (symfile_objfile->num_sections,
sizeof (struct section_offsets));
ALL_OBJFILE_OSECTIONS (symfile_objfile, osect)
{
osect_idx = osect - symfile_objfile->sections;
new_offsets->offsets[osect_idx] =
I can see a crash here. We allocate NEW_OFFSETS for
'symfile_objfile->num_sections' entries, but ALL_OBJFILE_OSECTIONS will
iterate 'symfile_objfile->num_sections + 4'. These four special
sections are not used in tic6x, so probably I can skip them when setting
'new_offsets'. Before I post a patch for the crash, I'd like to know
how do you think about this problem overall.
--
Yao (é½å°§)
More information about the Gdb-patches
mailing list