[binutils-gdb] BFD: Add BFD pointer member to archive member references
Maciej W. Rozycki
macro@sourceware.org
Fri Feb 20 17:43:13 GMT 2026
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5d507b1aa5bdda2adb4466d2d3587b780c46a6e8
commit 5d507b1aa5bdda2adb4466d2d3587b780c46a6e8
Author: Maciej W. Rozycki <macro@redhat.com>
Date: Fri Feb 20 17:29:51 2026 +0000
BFD: Add BFD pointer member to archive member references
In preparation for the next change replace a file offset with a union
of one and a BFD pointer in `struct bfd' and `struct artdata' members
used to refer to archive members and rename the members accordingly.
No functional change at this point.
Diff:
---
bfd/archive.c | 35 ++++++++++++++++++-----------------
bfd/archive64.c | 4 ++--
bfd/bfd-in2.h | 7 ++++---
bfd/bfd.c | 7 ++++---
bfd/coff-alpha.c | 6 +++---
bfd/coff-rs6000.c | 13 ++++++-------
bfd/coff64-rs6000.c | 5 ++---
bfd/ecoff.c | 4 ++--
bfd/libbfd-in.h | 2 +-
bfd/libbfd.h | 2 +-
bfd/som.c | 6 +++---
bfd/vms-lib.c | 16 +++++++++-------
binutils/bucomm.c | 5 +++--
13 files changed, 58 insertions(+), 54 deletions(-)
diff --git a/bfd/archive.c b/bfd/archive.c
index 85b7107938a..15adb6ac678 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -741,7 +741,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos,
n_bfd = _bfd_get_elt_at_filepos (ext_arch, origin, info);
if (n_bfd == NULL)
return NULL;
- n_bfd->proxy_origin = bfd_tell (archive);
+ n_bfd->proxy_handle.file_offset = bfd_tell (archive);
/* Copy BFD_COMPRESS, BFD_DECOMPRESS and BFD_COMPRESS_GABI
flags. */
@@ -788,7 +788,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos,
return NULL;
}
- n_bfd->proxy_origin = bfd_tell (archive);
+ n_bfd->proxy_handle.file_offset = bfd_tell (archive);
if (bfd_is_thin_archive (archive))
{
@@ -796,7 +796,7 @@ _bfd_get_elt_at_filepos (bfd *archive, file_ptr filepos,
}
else
{
- n_bfd->origin = n_bfd->proxy_origin;
+ n_bfd->origin = n_bfd->proxy_handle.file_offset;
if (!bfd_set_filename (n_bfd, filename))
goto out;
}
@@ -878,10 +878,10 @@ bfd_generic_openr_next_archived_file (bfd *archive, bfd *last_file)
ufile_ptr filestart;
if (!last_file)
- filestart = bfd_ardata (archive)->first_file_filepos;
+ filestart = bfd_ardata (archive)->first_file.file_offset;
else
{
- filestart = last_file->proxy_origin;
+ filestart = last_file->proxy_handle.file_offset;
if (! bfd_is_thin_archive (archive))
{
bfd_size_type size = arelt_size (last_file);
@@ -891,7 +891,7 @@ bfd_generic_openr_next_archived_file (bfd *archive, bfd *last_file)
Note that last_file->origin can be odd in the case of
BSD-4.4-style element with a long odd size. */
filestart += filestart % 2;
- if (filestart < last_file->proxy_origin)
+ if (filestart < last_file->proxy_handle.file_offset)
{
/* Prevent looping. See PR19256. */
bfd_set_error (bfd_error_malformed_archive);
@@ -937,7 +937,7 @@ bfd_generic_archive_p (bfd *abfd)
if (bfd_ardata (abfd) == NULL)
return NULL;
- bfd_ardata (abfd)->first_file_filepos = SARMAG;
+ bfd_ardata (abfd)->first_file.file_offset = SARMAG;
if (!BFD_SEND (abfd, _bfd_slurp_armap, (abfd))
|| !BFD_SEND (abfd, _bfd_slurp_extended_name_table, (abfd)))
@@ -1153,9 +1153,9 @@ do_slurp_bsd_armap (bfd *abfd)
set->u.file_offset = H_GET_32 (abfd, rbase + BSD_SYMDEF_OFFSET_SIZE);
}
- ardata->first_file_filepos = bfd_tell (abfd);
+ ardata->first_file.file_offset = bfd_tell (abfd);
/* Pad to an even boundary if you have to. */
- ardata->first_file_filepos += (ardata->first_file_filepos) % 2;
+ ardata->first_file.file_offset += (ardata->first_file.file_offset) % 2;
/* FIXME, we should provide some way to free raw_ardata when
we are done using the strings from it. For now, it seems
to be allocated on an objalloc anyway... */
@@ -1260,10 +1260,10 @@ do_slurp_coff_armap (bfd *abfd)
}
ardata->symdef_count = nsymz;
- ardata->first_file_filepos = bfd_tell (abfd);
+ ardata->first_file.file_offset = bfd_tell (abfd);
/* Pad to an even boundary if you have to. */
- ardata->first_file_filepos += (ardata->first_file_filepos) % 2;
- if (bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET) != 0)
+ ardata->first_file.file_offset += (ardata->first_file.file_offset) % 2;
+ if (bfd_seek (abfd, ardata->first_file.file_offset, SEEK_SET) != 0)
goto release_symdefs;
abfd->has_armap = true;
@@ -1275,7 +1275,7 @@ do_slurp_coff_armap (bfd *abfd)
{
if (tmp->arch_header[0] == '/'
&& tmp->arch_header[1] == ' ')
- ardata->first_file_filepos
+ ardata->first_file.file_offset
+= (tmp->parsed_size + sizeof (struct ar_hdr) + 1) & ~(unsigned) 1;
free (tmp);
}
@@ -1379,7 +1379,8 @@ _bfd_slurp_extended_name_table (bfd *abfd)
/* FIXME: Formatting sucks here, and in case of failure of BFD_READ,
we probably don't want to return TRUE. */
- if (bfd_seek (abfd, bfd_ardata (abfd)->first_file_filepos, SEEK_SET) != 0)
+ if (bfd_seek (abfd, bfd_ardata (abfd)->first_file.file_offset,
+ SEEK_SET) != 0)
return false;
if (bfd_read (nextname, 16, abfd) == 16)
@@ -1453,9 +1454,9 @@ _bfd_slurp_extended_name_table (bfd *abfd)
}
/* Pad to an even boundary if you have to. */
- bfd_ardata (abfd)->first_file_filepos = bfd_tell (abfd);
- bfd_ardata (abfd)->first_file_filepos +=
- (bfd_ardata (abfd)->first_file_filepos) % 2;
+ bfd_ardata (abfd)->first_file.file_offset = bfd_tell (abfd);
+ bfd_ardata (abfd)->first_file.file_offset +=
+ (bfd_ardata (abfd)->first_file.file_offset) % 2;
free (namedata);
}
diff --git a/bfd/archive64.c b/bfd/archive64.c
index 4789bef52db..6d4c268b629 100644
--- a/bfd/archive64.c
+++ b/bfd/archive64.c
@@ -138,9 +138,9 @@ _bfd_archive_64_bit_slurp_armap (bfd *abfd)
}
ardata->symdef_count = nsymz;
- ardata->first_file_filepos = bfd_tell (abfd);
+ ardata->first_file.file_offset = bfd_tell (abfd);
/* Pad to an even boundary if you have to. */
- ardata->first_file_filepos += (ardata->first_file_filepos) % 2;
+ ardata->first_file.file_offset += (ardata->first_file.file_offset) % 2;
abfd->has_armap = true;
bfd_release (abfd, raw_armap);
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 0aad6a903e4..7186c3c85d8 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2176,12 +2176,13 @@ struct bfd
contained in an archive. */
ufile_ptr origin;
- /* The origin in the archive of the proxy entry. This will
+ /* A reference in the archive for the proxy entry. This will
normally be the same as origin, except for thin archives,
when it will contain the current offset of the proxy in the
thin archive rather than the offset of the bfd in its actual
- container. */
- ufile_ptr proxy_origin;
+ container. Room for a BFD pointer is alternatively provided
+ for future use. */
+ ufile_ptr_or_bfd proxy_handle;
/* A hash table for section names. */
struct bfd_hash_table section_htab;
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 27c43ad3d85..5c84dc404fe 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -326,12 +326,13 @@ CODE_FRAGMENT
. contained in an archive. *}
. ufile_ptr origin;
.
-. {* The origin in the archive of the proxy entry. This will
+. {* A reference in the archive for the proxy entry. This will
. normally be the same as origin, except for thin archives,
. when it will contain the current offset of the proxy in the
. thin archive rather than the offset of the bfd in its actual
-. container. *}
-. ufile_ptr proxy_origin;
+. container. Room for a BFD pointer is alternatively provided
+. for future use. *}
+. ufile_ptr_or_bfd proxy_handle;
.
. {* A hash table for section names. *}
. struct bfd_hash_table section_htab;
diff --git a/bfd/coff-alpha.c b/bfd/coff-alpha.c
index e1793035a15..622e9e19aeb 100644
--- a/bfd/coff-alpha.c
+++ b/bfd/coff-alpha.c
@@ -2203,7 +2203,7 @@ alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
ufile_ptr filestart;
if (last_file == NULL)
- filestart = bfd_ardata (archive)->first_file_filepos;
+ filestart = bfd_ardata (archive)->first_file.file_offset;
else
{
struct areltdata *t;
@@ -2219,9 +2219,9 @@ alpha_ecoff_openr_next_archived_file (bfd *archive, bfd *last_file)
/* Pad to an even boundary...
Note that last_file->origin can be odd in the case of
BSD-4.4-style element with a long odd size. */
- filestart = last_file->proxy_origin + size;
+ filestart = last_file->proxy_handle.file_offset + size;
filestart += filestart % 2;
- if (filestart < last_file->proxy_origin)
+ if (filestart < last_file->proxy_handle.file_offset)
{
/* Prevent looping. See PR19256. */
bfd_set_error (bfd_error_malformed_archive);
diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c
index c1b34c479f9..39f13cd7f09 100644
--- a/bfd/coff-rs6000.c
+++ b/bfd/coff-rs6000.c
@@ -1542,7 +1542,7 @@ _bfd_xcoff_archive_p (bfd *abfd)
goto error_ret;
}
- GET_VALUE_IN_FIELD (bfd_ardata (abfd)->first_file_filepos,
+ GET_VALUE_IN_FIELD (bfd_ardata (abfd)->first_file.file_offset,
hdr.firstmemoff, 10);
memcpy (&x_artdata (abfd)->u.hdr, &hdr, SIZEOF_AR_FILE_HDR);
@@ -1564,9 +1564,8 @@ _bfd_xcoff_archive_p (bfd *abfd)
goto error_ret;
}
- bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
- (const char **) 0,
- 10);
+ bfd_ardata (abfd)->first_file.file_offset
+ = bfd_scan_vma (hdr.firstmemoff, (const char **) 0, 10);
memcpy (&x_artdata (abfd)->u.bhdr, &hdr, SIZEOF_AR_FILE_HDR_BIG);
}
@@ -1780,7 +1779,7 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR;
x_artdata (archive)->ranges.next = NULL;
x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR;
- filestart = bfd_ardata (archive)->first_file_filepos;
+ filestart = bfd_ardata (archive)->first_file.file_offset;
}
else
GET_VALUE_IN_FIELD (filestart, arch_xhdr (last_file)->nextoff, 10);
@@ -1803,7 +1802,7 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
x_artdata (archive)->ranges.end = SIZEOF_AR_FILE_HDR_BIG;
x_artdata (archive)->ranges.next = NULL;
x_artdata (archive)->ar_hdr_size = SIZEOF_AR_HDR_BIG;
- filestart = bfd_ardata (archive)->first_file_filepos;
+ filestart = bfd_ardata (archive)->first_file.file_offset;
}
else
GET_VALUE_IN_FIELD (filestart, arch_xhdr_big (last_file)->nextoff, 10);
@@ -1825,7 +1824,7 @@ _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
archive element cache until the next element is opened. */
if (last_file != NULL)
{
- ufile_ptr laststart = last_file->proxy_origin;
+ ufile_ptr laststart = last_file->proxy_handle.file_offset;
laststart -= x_artdata (archive)->ar_hdr_size;
laststart -= arch_eltdata (last_file)->extra_size;
if (filestart == laststart)
diff --git a/bfd/coff64-rs6000.c b/bfd/coff64-rs6000.c
index 87e31b666e7..e7ba511efa6 100644
--- a/bfd/coff64-rs6000.c
+++ b/bfd/coff64-rs6000.c
@@ -1937,9 +1937,8 @@ xcoff64_archive_p (bfd *abfd)
bfd_ardata (abfd)->tdata = (void *) ((struct artdata *) bfd_ardata (abfd) + 1);
- bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
- (const char **) NULL,
- 10);
+ bfd_ardata (abfd)->first_file.file_offset
+ = bfd_scan_vma (hdr.firstmemoff, (const char **) NULL, 10);
memcpy (&x_artdata (abfd)->u.bhdr, &hdr, SIZEOF_AR_FILE_HDR_BIG);
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 09fd1900502..725433f0f09 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -3069,9 +3069,9 @@ _bfd_ecoff_slurp_armap (bfd *abfd)
++symdef_ptr;
}
- ardata->first_file_filepos = bfd_tell (abfd);
+ ardata->first_file.file_offset = bfd_tell (abfd);
/* Pad to an even boundary. */
- ardata->first_file_filepos += ardata->first_file_filepos % 2;
+ ardata->first_file.file_offset += ardata->first_file.file_offset % 2;
abfd->has_armap = true;
return true;
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index fe263e27ec8..4cc391fad47 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -61,7 +61,7 @@ extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN;
struct artdata
{
- ufile_ptr first_file_filepos;
+ ufile_ptr_or_bfd first_file;
/* Speed up searching the armap */
htab_t cache;
carsym *symdefs; /* The symdef entries. */
diff --git a/bfd/libbfd.h b/bfd/libbfd.h
index 18f12e84bb0..bdd0bd22b95 100644
--- a/bfd/libbfd.h
+++ b/bfd/libbfd.h
@@ -67,7 +67,7 @@ extern unsigned int _bfd_section_id ATTRIBUTE_HIDDEN;
struct artdata
{
- ufile_ptr first_file_filepos;
+ ufile_ptr_or_bfd first_file;
/* Speed up searching the armap */
htab_t cache;
carsym *symdefs; /* The symdef entries. */
diff --git a/bfd/som.c b/bfd/som.c
index 9a4ccaacad7..34c0a4fd4d0 100644
--- a/bfd/som.c
+++ b/bfd/som.c
@@ -6163,7 +6163,7 @@ som_slurp_armap (bfd *abfd)
}
/* Save off the file offset of the first real user data. */
- ardata->first_file_filepos = bfd_tell (abfd) + parsed_size;
+ ardata->first_file.file_offset = bfd_tell (abfd) + parsed_size;
/* Read in the library symbol table. We'll make heavy use of this
in just a minute. */
@@ -6185,7 +6185,7 @@ som_slurp_armap (bfd *abfd)
return false;
/* Get back to the start of the library symbol table. */
- if (bfd_seek (abfd, (ardata->first_file_filepos - parsed_size
+ if (bfd_seek (abfd, (ardata->first_file.file_offset - parsed_size
+ sizeof (struct som_external_lst_header)),
SEEK_SET) != 0)
return false;
@@ -6207,7 +6207,7 @@ som_slurp_armap (bfd *abfd)
/* Seek back to the "first" file in the archive. Note the "first"
file may be the extended name table. */
- if (bfd_seek (abfd, ardata->first_file_filepos, SEEK_SET) != 0)
+ if (bfd_seek (abfd, ardata->first_file.file_offset, SEEK_SET) != 0)
return false;
/* Notify the generic archive code that we have a symbol map. */
diff --git a/bfd/vms-lib.c b/bfd/vms-lib.c
index 995c7ec2aac..ff241291fd4 100644
--- a/bfd/vms-lib.c
+++ b/bfd/vms-lib.c
@@ -1553,7 +1553,7 @@ _bfd_vms_lib_openr_next_archived_file (bfd *archive,
if (!last_file)
idx = 0;
else
- idx = last_file->proxy_origin + 1;
+ idx = last_file->proxy_handle.file_offset + 1;
if (idx >= bfd_libdata (archive)->nbr_modules)
{
@@ -1564,7 +1564,7 @@ _bfd_vms_lib_openr_next_archived_file (bfd *archive,
res = _bfd_vms_lib_get_module (archive, idx);
if (res == NULL)
return res;
- res->proxy_origin = idx;
+ res->proxy_handle.file_offset = idx;
return res;
}
@@ -1890,11 +1890,13 @@ vms_write_index (bfd *abfd,
struct vms_rfa *rfa;
rfa = (struct vms_rfa *)(rblk[j]->keys + blk[j].len);
- bfd_putl32 ((idx->abfd->proxy_origin / VMS_BLOCK_SIZE) + 1,
- rfa->vbn);
+ bfd_putl32
+ (((idx->abfd->proxy_handle.file_offset / VMS_BLOCK_SIZE)
+ + 1),
+ rfa->vbn);
bfd_putl16
- ((idx->abfd->proxy_origin % VMS_BLOCK_SIZE)
- + (is_elfidx ? 0 : DATA__DATA),
+ (((idx->abfd->proxy_handle.file_offset % VMS_BLOCK_SIZE)
+ + (is_elfidx ? 0 : DATA__DATA)),
rfa->offset);
if (is_elfidx)
@@ -2212,7 +2214,7 @@ _bfd_vms_lib_write_archive_contents (bfd *arch)
unsigned int sz;
current = modules[i].abfd;
- current->proxy_origin = off;
+ current->proxy_handle.file_offset = off;
if (is_elfidx)
sz = 0;
diff --git a/binutils/bucomm.c b/binutils/bucomm.c
index 0f25a3c4038..4d6730ae2ca 100644
--- a/binutils/bucomm.c
+++ b/binutils/bucomm.c
@@ -477,8 +477,9 @@ print_arelt_descr (FILE *file, bfd *abfd, bool verbose, bool offsets)
if (offsets)
{
- if (bfd_is_thin_archive (abfd) && abfd->proxy_origin)
- fprintf (file, " 0x%lx", (unsigned long) abfd->proxy_origin);
+ if (bfd_is_thin_archive (abfd) && abfd->proxy_handle.file_offset)
+ fprintf (file, " 0x%lx",
+ (unsigned long) abfd->proxy_handle.file_offset);
else if (!bfd_is_thin_archive (abfd) && abfd->origin)
fprintf (file, " 0x%lx", (unsigned long) abfd->origin);
}
More information about the Binutils-cvs
mailing list