2013-04-08 Tom Tromey <tromey@redhat.com>
+ * coffread.c (cs_to_section): Use gdb_bfd_section_index.
+ * elfread.c (record_minimal_symbol, elf_symtab_read): Use
+ gdb_bfd_section_index.
+ * gdb_bfd.c (gdb_bfd_section_index, gdb_bfd_count_sections):
+ New functions.
+ * gdb_bfd.h (gdb_bfd_section_index, gdb_bfd_count_sections):
+ Declare.
+ * machoread.c (macho_symtab_add_minsym, macho_symfile_offsets):
+ Update.
+ * objfiles.c (add_to_objfile_sections_full): New function.
+ (add_to_objfile_sections): Use it.
+ (build_section_table): Rewrite.
+ (objfile_relocate1): Use gdb_bfd_section_index. Update.
+ * objfiles.h (obj_section_offset): Use gdb_bfd_section_index.
+ (struct objfile) <sections>: Update comment.
+ (ALL_OBJFILE_OSECTIONS): Skip sections where the_bfd_section
+ is NULL.
+ (ALL_OBJSECTIONS): Use it.
+ * solib-dsbt.c (dsbt_relocate_main_executable): Update.
+ * solib-frv.c (frv_relocate_main_executable): Update.
+ * solib-target.c (solib_target_relocate_section_addresses):
+ Use gdb_bfd_section_index.
+ * symfile.c (build_section_addr_info_from_section_table):
+ Use gdb_bfd_section_index.
+ (build_section_addr_info_from_bfd, place_section): Likewise.
+ * symtab.c (fixup_section): Update.
+ * xcoffread.c (find_targ_sec): Use gdb_bfd_section_index.
+
+2013-04-08 Tom Tromey <tromey@redhat.com>
+
* minsyms.h (struct bound_minimal_symbol): New.
(lookup_minimal_symbol_and_objfile): Return bound_minimal_symbol.
Remove objfile argument.
if (sect == NULL)
return SECT_OFF_TEXT (objfile);
- return sect->index;
+ return gdb_bfd_section_index (objfile->obfd, sect);
}
/* Return the address of the section of a COFF symbol. */
address = gdbarch_addr_bits_remove (gdbarch, address);
return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
- ms_type, bfd_section->index,
+ ms_type,
+ gdb_bfd_section_index (objfile->obfd,
+ bfd_section),
bfd_section, objfile);
}
continue;
}
- offset = ANOFFSET (objfile->section_offsets, sym->section->index);
+ offset = ANOFFSET (objfile->section_offsets,
+ gdb_bfd_section_index (objfile->obfd, sym->section));
if (type == ST_DYNAMIC
&& sym->section == bfd_und_section_ptr
&& (sym->flags & BSF_FUNCTION))
&& bfd_get_section_by_name (abfd, ".plt") != NULL)
continue;
- symaddr += ANOFFSET (objfile->section_offsets, sect->index);
+ symaddr += ANOFFSET (objfile->section_offsets,
+ gdb_bfd_section_index (objfile->obfd, sect));
msym = record_minimal_symbol
(sym->name, strlen (sym->name), copy_names,
\f
+gdb_static_assert (ARRAY_SIZE (_bfd_std_section) == 4);
+
+/* See gdb_bfd.h. */
+
+int
+gdb_bfd_section_index (bfd *abfd, asection *section)
+{
+ if (section == NULL)
+ return -1;
+ else if (section == bfd_com_section_ptr)
+ return bfd_count_sections (abfd) + 1;
+ else if (section == bfd_und_section_ptr)
+ return bfd_count_sections (abfd) + 2;
+ else if (section == bfd_abs_section_ptr)
+ return bfd_count_sections (abfd) + 3;
+ else if (section == bfd_ind_section_ptr)
+ return bfd_count_sections (abfd) + 4;
+ return section->index;
+}
+
+/* See gdb_bfd.h. */
+
+int
+gdb_bfd_count_sections (bfd *abfd)
+{
+ return bfd_count_sections (abfd) + 4;
+}
+
+\f
+
/* A callback for htab_traverse that prints a single BFD. */
static int
bfd *gdb_bfd_fdopenr (const char *filename, const char *target, int fd);
+\f
+
+/* Return the index of the BFD section SECTION. Ordinarily this is
+ just the section's index, but for some special sections, like
+ bfd_com_section_ptr, it will be a synthesized value. */
+
+int gdb_bfd_section_index (bfd *abfd, asection *section);
+
+
+/* Like bfd_count_sections, but include any possible global sections,
+ like bfd_com_section_ptr. */
+
+int gdb_bfd_count_sections (bfd *abfd);
+
#endif /* GDB_BFD_H */
CORE_ADDR offset;
enum minimal_symbol_type ms_type;
- offset = ANOFFSET (objfile->section_offsets, sym->section->index);
+ offset = ANOFFSET (objfile->section_offsets,
+ gdb_bfd_section_index (objfile->obfd, sym->section));
/* Bfd symbols are section relative. */
symaddr = sym->value + sym->section->vma;
return; /* Skip this symbol. */
prim_record_minimal_symbol_and_info
- (sym->name, symaddr, ms_type, sym->section->index,
- sym->section, objfile);
+ (sym->name, symaddr, ms_type,
+ gdb_bfd_section_index (objfile->obfd, sym->section),
+ sym->section, objfile);
}
}
ALL_OBJFILE_OSECTIONS (objfile, osect)
{
const char *bfd_sect_name = osect->the_bfd_section->name;
- int sect_index = osect->the_bfd_section->index;
+ int sect_index = osect - objfile->sections;;
if (strncmp (bfd_sect_name, "LC_SEGMENT.", 11) == 0)
bfd_sect_name += 11;
the end of the table (objfile->sections_end). */
static void
+add_to_objfile_sections_full (struct bfd *abfd, struct bfd_section *asect,
+ struct objfile *objfile, int force)
+{
+ struct obj_section *section;
+
+ if (!force)
+ {
+ flagword aflag;
+
+ aflag = bfd_get_section_flags (abfd, asect);
+ if (!(aflag & SEC_ALLOC))
+ return;
+ }
+
+ section = &objfile->sections[gdb_bfd_section_index (abfd, asect)];
+ section->objfile = objfile;
+ section->the_bfd_section = asect;
+ section->ovly_mapped = 0;
+}
+
+static void
add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
void *objfilep)
{
- struct objfile *objfile = (struct objfile *) objfilep;
- struct obj_section section;
- flagword aflag;
-
- aflag = bfd_get_section_flags (abfd, asect);
- if (!(aflag & SEC_ALLOC))
- return;
- if (bfd_section_size (abfd, asect) == 0)
- return;
-
- section.objfile = objfile;
- section.the_bfd_section = asect;
- section.ovly_mapped = 0;
- obstack_grow (&objfile->objfile_obstack,
- (char *) §ion, sizeof (section));
- objfile->sections_end
- = (struct obj_section *) (((size_t) objfile->sections_end) + 1);
+ add_to_objfile_sections_full (abfd, asect, objfilep, 0);
}
/* Builds a section table for OBJFILE.
- Note that while we are building the table, which goes into the
- objfile obstack, we hijack the sections_end pointer to instead hold
- a count of the number of sections. When bfd_map_over_sections
- returns, this count is used to compute the pointer to the end of
- the sections table, which then overwrites the count.
-
- Also note that the OFFSET and OVLY_MAPPED in each table entry
- are initialized to zero.
-
- Also note that if anything else writes to the objfile obstack while
- we are building the table, we're pretty much hosed. */
+ Note that the OFFSET and OVLY_MAPPED in each table entry are
+ initialized to zero. */
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);
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);
}
/* Given a pointer to an initialized bfd (ABFD) and some flag bits
struct obj_section *s;
s = find_pc_section (objfile->ei.entry_point);
if (s)
- objfile->ei.entry_point += ANOFFSET (delta, s->the_bfd_section->index);
+ {
+ int idx = gdb_bfd_section_index (objfile->obfd, s->the_bfd_section);
+
+ objfile->ei.entry_point += ANOFFSET (delta, idx);
+ }
else
objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
}
/* Update the table in exec_ops, used to read memory. */
ALL_OBJFILE_OSECTIONS (objfile, s)
{
- int idx = s->the_bfd_section->index;
+ int idx = s - objfile->sections;
exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
obj_section_addr (s));
#include "symfile.h" /* For struct psymbol_allocation_list. */
#include "progspace.h"
#include "registry.h"
+#include "gdb_bfd.h"
struct bcache;
struct htab;
/* Relocation offset applied to S. */
#define obj_section_offset(s) \
- (((s)->objfile->section_offsets)->offsets[(s)->the_bfd_section->index])
+ (((s)->objfile->section_offsets)->offsets[gdb_bfd_section_index ((s)->objfile->obfd, (s)->the_bfd_section)])
/* The memory address of section S (vma + offset). */
#define obj_section_addr(s) \
among other things, is used to map pc addresses into sections.
SECTIONS points to the first entry in the table, and
SECTIONS_END points to the first location past the last entry
- in the table. The table is stored on the objfile_obstack.
- There is no particular order to the sections in this table, and it
- only contains sections we care about (e.g. non-empty, SEC_ALLOC). */
+ in the table. The table is stored on the objfile_obstack. The
+ sections are indexed by the BFD section index; but the
+ structure data is only valid for certain sections
+ (e.g. non-empty, SEC_ALLOC). */
struct obj_section *sections, *sections_end;
ALL_OBJFILE_MSYMBOLS (objfile, m)
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
- for (osect = objfile->sections; osect < objfile->sections_end; osect++)
+ for (osect = objfile->sections; osect < objfile->sections_end; osect++) \
+ if (osect->the_bfd_section == NULL) \
+ { \
+ /* Nothing. */ \
+ } \
+ else
/* Traverse all obj_sections in all objfiles in the current program
space.
? ((objfile) = (objfile)->next, \
(objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \
: 0)) \
- for ((osect) = (objfile)->sections; \
- (osect) < (objfile)->sections_end; \
- (osect)++)
+ ALL_OBJFILE_OSECTIONS (objfile, osect)
#define SECT_OFF_DATA(objfile) \
((objfile->sect_index_data == -1) \
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);
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);
}
}
- offset = so->lm_info->offsets->offsets[sec->the_bfd_section->index];
+ offset = so->lm_info->offsets->offsets[gdb_bfd_section_index (sec->bfd,
+ sec->the_bfd_section)];
sec->addr += offset;
sec->endaddr += offset;
}
sap->other[oidx].addr = stp->addr;
sap->other[oidx].name
= xstrdup (bfd_section_name (stp->bfd, stp->the_bfd_section));
- sap->other[oidx].sectindex = stp->the_bfd_section->index;
+ sap->other[oidx].sectindex
+ = gdb_bfd_section_index (stp->bfd, stp->the_bfd_section);
oidx++;
}
}
{
sap->other[i].addr = bfd_get_section_vma (abfd, sec);
sap->other[i].name = xstrdup (bfd_get_section_name (abfd, sec));
- sap->other[i].sectindex = sec->index;
+ sap->other[i].sectindex = gdb_bfd_section_index (abfd, sec);
i++;
}
return;
/* If the user specified an offset, honor it. */
- if (offsets[sect->index] != 0)
+ if (offsets[gdb_bfd_section_index (abfd, sect)] != 0)
return;
/* Otherwise, let's try to find a place for the section. */
}
while (!done);
- offsets[sect->index] = start_addr;
+ offsets[gdb_bfd_section_index (abfd, sect)] = start_addr;
arg->lowest = start_addr + bfd_get_section_size (sect);
}
ALL_OBJFILE_OSECTIONS (objfile, s)
{
- int idx = s->the_bfd_section->index;
+ int idx = s - objfile->sections;
CORE_ADDR offset = ANOFFSET (objfile->section_offsets, idx);
if (obj_section_addr (s) - offset <= addr
else if (bfd_get_section_flags (abfd, sect) & SEC_LOAD)
*args->resultp = SECT_OFF_DATA (objfile);
else
- *args->resultp = sect->index;
+ *args->resultp = gdb_bfd_section_index (abfd, sect);
*args->bfd_sect = sect;
}
}