[binutils-gdb] Remove section_offsets typedef
Tom Tromey
tromey@sourceware.org
Wed Nov 19 22:43:51 GMT 2025
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=1e808504adc01b01d9b8b6ba274e63ca8f5bdd28
commit 1e808504adc01b01d9b8b6ba274e63ca8f5bdd28
Author: Tom Tromey <tom@tromey.com>
Date: Wed Nov 19 11:09:35 2025 -0700
Remove section_offsets typedef
This patch removes the section_offsets typedef, in favor of using
either std::vector or gdb::array_view as appropriate.
v2: preserve const-ness when creating views
Regression tested on x86-64 Fedora 40.
Approved-By: Simon Marchi <simon.marchi@efficios.com>
Diff:
---
gdb/block.c | 5 +++--
gdb/block.h | 6 ++++--
gdb/defs.h | 4 ----
gdb/mdebugread.c | 8 +++++---
gdb/objfiles.c | 10 +++++-----
gdb/objfiles.h | 5 +++--
gdb/remote.c | 2 +-
gdb/solib-aix.c | 8 ++++----
gdb/solib-dsbt.c | 2 +-
gdb/solib-frv.c | 2 +-
gdb/solib-svr4.c | 4 ++--
gdb/solib-target.c | 2 +-
gdb/symfile.c | 10 +++++-----
gdb/symfile.h | 4 ++--
gdb/symtab.c | 2 +-
gdb/symtab.h | 2 +-
16 files changed, 39 insertions(+), 37 deletions(-)
diff --git a/gdb/block.c b/gdb/block.c
index 4d7f2124f39..98088aa3807 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -369,7 +369,8 @@ block::static_link () const
/* See block.h. */
void
-block::relocate (struct objfile *objfile, const section_offsets &offsets)
+block::relocate (struct objfile *objfile,
+ gdb::array_view<const CORE_ADDR> offsets)
{
int block_line_section = SECT_OFF_TEXT (objfile);
@@ -889,7 +890,7 @@ blockvector::~blockvector ()
void
blockvector::relocate (struct objfile *objfile,
- const section_offsets &offsets)
+ gdb::array_view<const CORE_ADDR> offsets)
{
int block_line_section = SECT_OFF_TEXT (objfile);
diff --git a/gdb/block.h b/gdb/block.h
index ceff97d79e3..b199663273c 100644
--- a/gdb/block.h
+++ b/gdb/block.h
@@ -318,7 +318,8 @@ struct block : public allocate_on_obstack<block>
/* Relocate this block and all contained blocks. OBJFILE is the
objfile holding this block, and OFFSETS is the relocation offsets
to use. */
- void relocate (struct objfile *objfile, const section_offsets &offsets);
+ void relocate (struct objfile *objfile,
+ gdb::array_view<const CORE_ADDR> offsets);
private:
@@ -517,7 +518,8 @@ struct blockvector
/* Relocate this blockvector and all contained blocks. OBJFILE is
the objfile holding this blockvector, and OFFSETS is the
relocation offsets to use. */
- void relocate (struct objfile *objfile, const section_offsets &offsets);
+ void relocate (struct objfile *objfile,
+ gdb::array_view<const CORE_ADDR> offsets);
private:
/* An address map mapping addresses to blocks in this blockvector.
diff --git a/gdb/defs.h b/gdb/defs.h
index bb047d9cb4c..8bf9d3dcbda 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -411,8 +411,4 @@ DEF_ENUM_FLAGS_TYPE (enum user_selected_what_flag, user_selected_what);
extern void _initialize_ ## NAME (); \
void _initialize_ ## NAME ()
-/* How to relocate the symbols from each section in a symbol file.
- This is indexed by section numbers. */
-typedef std::vector<CORE_ADDR> section_offsets;
-
#endif /* GDB_DEFS_H */
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 10c4133e6c2..e7c526a84ed 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -640,7 +640,8 @@ add_data_symbol (SYMR *sh, union aux_ext *ax, int bigend,
static int
parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
- const section_offsets §ion_offsets, struct objfile *objfile)
+ gdb::array_view<const CORE_ADDR> section_offsets,
+ struct objfile *objfile)
{
struct gdbarch *gdbarch = objfile->arch ();
const bfd_size_type external_sym_size = debug_swap->external_sym_size;
@@ -2125,7 +2126,8 @@ parse_procedure (PDR *pr, struct compunit_symtab *search_symtab,
This routine clobbers top_stack->cur_block and ->cur_st. */
static void
-parse_external (EXTR *es, int bigend, const section_offsets §ion_offsets,
+parse_external (EXTR *es, int bigend,
+ gdb::array_view<const CORE_ADDR> section_offsets,
struct objfile *objfile)
{
union aux_ext *ax;
@@ -3193,7 +3195,7 @@ mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
FDR *fh;
struct linetable *lines;
CORE_ADDR lowest_pdr_addr = 0;
- const section_offsets §ion_offsets = objfile->section_offsets;
+ gdb::array_view<const CORE_ADDR> section_offsets (objfile->section_offsets);
if (pst->readin)
return;
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 658b01e5955..0d166ceec4c 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -514,9 +514,9 @@ objfile::~objfile ()
static int
objfile_relocate1 (struct objfile *objfile,
- const section_offsets &new_offsets)
+ gdb::array_view<const CORE_ADDR> new_offsets)
{
- section_offsets delta (objfile->section_offsets.size ());
+ std::vector<CORE_ADDR> delta (objfile->section_offsets.size ());
int something_changed = 0;
@@ -567,7 +567,7 @@ objfile_relocate1 (struct objfile *objfile,
void
objfile_relocate (struct objfile *objfile,
- const section_offsets &new_offsets)
+ gdb::array_view<const CORE_ADDR> new_offsets)
{
int changed = 0;
@@ -588,7 +588,7 @@ objfile_relocate (struct objfile *objfile,
gdb_assert (debug_objfile->section_offsets.size ()
== gdb_bfd_count_sections (debug_objfile->obfd.get ()));
- section_offsets new_debug_offsets
+ std::vector<CORE_ADDR> new_debug_offsets
(debug_objfile->section_offsets.size ());
relative_addr_info_to_section_offsets (new_debug_offsets, objfile_addrs);
@@ -607,7 +607,7 @@ objfile_relocate (struct objfile *objfile,
static int
objfile_rebase1 (struct objfile *objfile, CORE_ADDR slide)
{
- section_offsets new_offsets (objfile->section_offsets.size (), slide);
+ std::vector<CORE_ADDR> new_offsets (objfile->section_offsets.size (), slide);
return objfile_relocate1 (objfile, new_offsets);
}
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 31651c4ee57..0dd3fafac03 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -772,7 +772,7 @@ public:
minimal symbols) which have been read have been relocated by this
much. Symbols which are yet to be read need to be relocated by it. */
- ::section_offsets section_offsets;
+ std::vector<CORE_ADDR> section_offsets;
/* Indexes in the section_offsets array. These are initialized by the
*_symfile_offsets() family of functions (som_symfile_offsets,
@@ -918,7 +918,8 @@ extern void build_objfile_section_table (struct objfile *);
extern void free_objfile_separate_debug (struct objfile *);
-extern void objfile_relocate (struct objfile *, const section_offsets &);
+extern void objfile_relocate (struct objfile *,
+ gdb::array_view<const CORE_ADDR>);
extern void objfile_rebase (struct objfile *, CORE_ADDR);
/* Return true if any objfile of PSPACE has partial symbols. */
diff --git a/gdb/remote.c b/gdb/remote.c
index da44b22a259..fd80b6ddb59 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -4930,7 +4930,7 @@ remote_target::get_offsets ()
warning (_("Target reported unsupported offsets: %s"), buf);
objfile *objf = current_program_space->symfile_object_file;
- section_offsets offs = objf->section_offsets;
+ std::vector<CORE_ADDR> offs = objf->section_offsets;
symfile_segment_data_up data = get_symfile_segment_data (objf->obfd.get ());
do_segments = (data != NULL);
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 308ff80c38c..5076d7e2f06 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -380,13 +380,13 @@ aix_solib_ops::relocate_section_addresses (solib &so,
/* Compute and return the OBJFILE's section_offset array, using
the associated loader info (INFO). */
-static section_offsets
+static std::vector<CORE_ADDR>
solib_aix_get_section_offsets (struct objfile *objfile,
lm_info_aix *info)
{
bfd *abfd = objfile->obfd.get ();
- section_offsets offsets (objfile->section_offsets.size ());
+ std::vector<CORE_ADDR> offsets (objfile->section_offsets.size ());
/* .text */
@@ -451,8 +451,8 @@ aix_solib_ops::create_inferior_hook (int from_tty) const
if (current_program_space->symfile_object_file != NULL)
{
objfile *objf = current_program_space->symfile_object_file;
- section_offsets offsets = solib_aix_get_section_offsets (objf,
- &exec_info);
+ std::vector<CORE_ADDR> offsets
+ = solib_aix_get_section_offsets (objf, &exec_info);
objfile_relocate (objf, offsets);
}
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index 883164eda04..23042b4158e 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -816,7 +816,7 @@ dsbt_relocate_main_executable (void)
info->main_executable_lm_info = new lm_info_dsbt (ldm);
objfile *objf = current_program_space->symfile_object_file;
- section_offsets new_offsets (objf->section_offsets.size ());
+ std::vector<CORE_ADDR> new_offsets (objf->section_offsets.size ());
changed = 0;
for (obj_section &osect : objf->sections ())
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index 1cb063f7673..9d36b0fd4ed 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -748,7 +748,7 @@ frv_relocate_main_executable (void)
main_executable_lm_info = new lm_info_frv (ldm, 0, 0);
objfile *objf = current_program_space->symfile_object_file;
- section_offsets new_offsets (objf->section_offsets.size ());
+ std::vector<CORE_ADDR> new_offsets (objf->section_offsets.size ());
changed = 0;
for (obj_section &osect : objf->sections ())
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 2d15e7dfd8a..7c4a8b274c4 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3291,8 +3291,8 @@ svr4_relocate_main_executable (void)
objfile *objf = current_program_space->symfile_object_file;
if (objf)
{
- section_offsets new_offsets (objf->section_offsets.size (),
- displacement);
+ std::vector<CORE_ADDR> new_offsets (objf->section_offsets.size (),
+ displacement);
objfile_relocate (objf, new_offsets);
}
else if (current_program_space->exec_bfd ())
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 2ae25a8f3ae..36654a76fc3 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -42,7 +42,7 @@ struct lm_info_target final : public lm_info
/* The cached offsets for each section of this shared library,
determined from SEGMENT_BASES, or SECTION_BASES. */
- section_offsets offsets;
+ std::vector<CORE_ADDR> offsets;
};
using lm_info_target_up = std::unique_ptr<lm_info_target>;
diff --git a/gdb/symfile.c b/gdb/symfile.c
index d2c9bb1950d..11388772ff5 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -327,7 +327,7 @@ init_objfile_sect_indices (struct objfile *objfile)
the user did not provide an offset. */
static void
-place_section (bfd *abfd, asection *sect, section_offsets &offsets,
+place_section (bfd *abfd, asection *sect, std::vector<CORE_ADDR> &offsets,
CORE_ADDR &lowest)
{
CORE_ADDR start_addr;
@@ -391,7 +391,7 @@ place_section (bfd *abfd, asection *sect, section_offsets &offsets,
filled-in) by addr_info_make_relative into SECTION_OFFSETS. */
void
-relative_addr_info_to_section_offsets (section_offsets §ion_offsets,
+relative_addr_info_to_section_offsets (std::vector<CORE_ADDR> §ion_offsets,
const section_addr_info &addrs)
{
int i;
@@ -636,7 +636,7 @@ default_symfile_offsets (struct objfile *objfile,
if (cur_sec == NULL)
{
- section_offsets &offsets = objfile->section_offsets;
+ std::vector<CORE_ADDR> &offsets = objfile->section_offsets;
/* Pick non-overlapping offsets for sections the user did not
place explicitly. */
@@ -2135,7 +2135,7 @@ set_objfile_default_section_offset (struct objfile *objf,
CORE_ADDR offset)
{
/* Add OFFSET to all sections by default. */
- section_offsets offsets (objf->section_offsets.size (), offset);
+ std::vector<CORE_ADDR> offsets (objf->section_offsets.size (), offset);
/* Create sorted lists of all sections in ADDRS as well as all
sections in OBJF. */
@@ -3643,7 +3643,7 @@ get_symfile_segment_data (bfd *abfd)
int
symfile_map_offsets_to_segments (bfd *abfd,
const struct symfile_segment_data *data,
- section_offsets &offsets,
+ std::vector<CORE_ADDR> &offsets,
int num_segment_bases,
const CORE_ADDR *segment_bases)
{
diff --git a/gdb/symfile.h b/gdb/symfile.h
index 418e0847df4..cc2e8c94aff 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -178,7 +178,7 @@ extern section_addr_info
build_section_addr_info_from_objfile (const struct objfile *objfile);
extern void relative_addr_info_to_section_offsets
- (section_offsets §ion_offsets, const section_addr_info &addrs);
+ (std::vector<CORE_ADDR> §ion_offsets, const section_addr_info &addrs);
extern void addr_info_make_relative (section_addr_info *addrs,
bfd *abfd);
@@ -338,7 +338,7 @@ extern bfd_byte *symfile_relocate_debug_section (struct objfile *, asection *,
extern int symfile_map_offsets_to_segments (bfd *,
const struct symfile_segment_data *,
- section_offsets &,
+ std::vector<CORE_ADDR> &,
int, const CORE_ADDR *);
symfile_segment_data_up get_symfile_segment_data (bfd *abfd);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 0100bc4704c..701aa5d0007 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6611,7 +6611,7 @@ symbol::value_block () const
/* See symtab.h. */
void
-symbol::relocate (const section_offsets &delta)
+symbol::relocate (gdb::array_view<const CORE_ADDR> delta)
{
if ((loc_class () == LOC_LABEL || loc_class () == LOC_STATIC)
&& section_index () >= 0)
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 708eaf2c329..33cf0a6c229 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1460,7 +1460,7 @@ struct symbol : public general_symbol_info, public allocate_on_obstack<symbol>
/* Relocate this symbol. OFFSETS is the relocation offsets to use. */
- void relocate (const section_offsets &offsets);
+ void relocate (gdb::array_view<const CORE_ADDR> offsets);
/* Data type of value */
More information about the Gdb-cvs
mailing list