[PATCH v5 10/12] BFD: Add BFD pointer member to archive member references
Maciej W. Rozycki
macro@orcam.me.uk
Wed Jan 28 10:55:43 GMT 2026
From: Maciej W. Rozycki <macro@redhat.com>
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.
---
Changes from v4 (12/14),
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2601121838000.12909@angie.orcam.me.uk/>:
- Drop gratuitous reformatting done in `print_arelt_descr' in bucomm.c.
Changes from v3 (16/18),
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511200006410.57987@angie.orcam.me.uk/>:
- Mention the future use of the BFD pointer in the `proxy_handle' member
of `struct bfd'.
No change from v2 (14/16),
<https://inbox.sourceware.org/binutils/alpine.DEB.2.21.2511061545060.25436@angie.orcam.me.uk/>.
New change in v2.
---
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(-)
binutils-bfd-filepos-bfd.diff
Index: binutils-gdb/bfd/archive.c
===================================================================
--- binutils-gdb.orig/bfd/archive.c
+++ binutils-gdb/bfd/archive.c
@@ -741,7 +741,7 @@ _bfd_get_elt_at_filepos (bfd *archive, f
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, f
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, f
}
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 (bf
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 (bf
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 *abf
/* 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 *abf
}
/* 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);
}
Index: binutils-gdb/bfd/archive64.c
===================================================================
--- binutils-gdb.orig/bfd/archive64.c
+++ binutils-gdb/bfd/archive64.c
@@ -138,9 +138,9 @@ _bfd_archive_64_bit_slurp_armap (bfd *ab
}
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);
Index: binutils-gdb/bfd/bfd-in2.h
===================================================================
--- binutils-gdb.orig/bfd/bfd-in2.h
+++ binutils-gdb/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;
Index: binutils-gdb/bfd/bfd.c
===================================================================
--- binutils-gdb.orig/bfd/bfd.c
+++ binutils-gdb/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;
Index: binutils-gdb/bfd/coff-alpha.c
===================================================================
--- binutils-gdb.orig/bfd/coff-alpha.c
+++ binutils-gdb/bfd/coff-alpha.c
@@ -2203,7 +2203,7 @@ alpha_ecoff_openr_next_archived_file (bf
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 (bf
/* 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);
Index: binutils-gdb/bfd/coff-rs6000.c
===================================================================
--- binutils-gdb.orig/bfd/coff-rs6000.c
+++ binutils-gdb/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
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
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 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)
Index: binutils-gdb/bfd/coff64-rs6000.c
===================================================================
--- binutils-gdb.orig/bfd/coff64-rs6000.c
+++ binutils-gdb/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);
Index: binutils-gdb/bfd/ecoff.c
===================================================================
--- binutils-gdb.orig/bfd/ecoff.c
+++ binutils-gdb/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;
Index: binutils-gdb/bfd/libbfd-in.h
===================================================================
--- binutils-gdb.orig/bfd/libbfd-in.h
+++ binutils-gdb/bfd/libbfd-in.h
@@ -61,7 +61,7 @@ extern unsigned int _bfd_section_id ATTR
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. */
Index: binutils-gdb/bfd/libbfd.h
===================================================================
--- binutils-gdb.orig/bfd/libbfd.h
+++ binutils-gdb/bfd/libbfd.h
@@ -67,7 +67,7 @@ extern unsigned int _bfd_section_id ATTR
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. */
Index: binutils-gdb/bfd/som.c
===================================================================
--- binutils-gdb.orig/bfd/som.c
+++ binutils-gdb/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. */
Index: binutils-gdb/bfd/vms-lib.c
===================================================================
--- binutils-gdb.orig/bfd/vms-lib.c
+++ binutils-gdb/bfd/vms-lib.c
@@ -1553,7 +1553,7 @@ _bfd_vms_lib_openr_next_archived_file (b
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 (b
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
unsigned int sz;
current = modules[i].abfd;
- current->proxy_origin = off;
+ current->proxy_handle.file_offset = off;
if (is_elfidx)
sz = 0;
Index: binutils-gdb/binutils/bucomm.c
===================================================================
--- binutils-gdb.orig/binutils/bucomm.c
+++ binutils-gdb/binutils/bucomm.c
@@ -477,8 +477,9 @@ print_arelt_descr (FILE *file, bfd *abfd
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
mailing list