[PATCH 1/3] always add base bfd->origin to file offset
J.W. Jagersma
jwjagersma@gmail.com
Thu Mar 19 19:19:21 GMT 2020
The comment preceding the 'origin' field in struct bfd mentions that:
/* Currently my_archive is tested before adding origin to
anything. I believe that this can become always an add of
origin, with origin set to 0 for non archive files. */
This patch implements that change. Since the origin is always zero for
bfds not contained in an archive, this currently has no effect.
bfd/
2020-03-19 Jan W. Jagersma <jwjagersma@gmail.com>
* bfdio.c (bfd_bread, bfd_tell, bfd_seek, bfd_mmap): Always add
bfd->origin to file offset.
* bfdwin.c (bfd_get_file_window): Likewise.
* bfd.c: Clarify the use of the bfd->origin field.
* bfd-in2.h: Regenerate.
---
bfd/bfd.c | 5 ++---
bfd/bfdio.c | 4 ++++
bfd/bfdwin.c | 1 +
3 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 100359ccfe..3aed9be237 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -249,9 +249,8 @@ CODE_FRAGMENT
. library. *}
. bfd *plugin_dummy_bfd;
.
-. {* Currently my_archive is tested before adding origin to
-. anything. I believe that this can become always an add of
-. origin, with origin set to 0 for non archive files. *}
+. {* The offset of this bfd in the file, typically 0 if it is not
+. contained in an archive. *}
. ufile_ptr origin;
.
. {* The origin in the archive of the proxy entry. This will
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 71ac17ec51..fb97d036b1 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -187,6 +187,7 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
offset += abfd->origin;
abfd = abfd->my_archive;
}
+ offset += abfd->origin;
/* If this is an archive element, don't read past the end of
this element. */
@@ -256,6 +257,7 @@ bfd_tell (bfd *abfd)
offset += abfd->origin;
abfd = abfd->my_archive;
}
+ offset += abfd->origin;
if (abfd->iovec == NULL)
return 0;
@@ -316,6 +318,7 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
offset += abfd->origin;
abfd = abfd->my_archive;
}
+ offset += abfd->origin;
if (abfd->iovec == NULL)
{
@@ -508,6 +511,7 @@ bfd_mmap (bfd *abfd, void *addr, bfd_size_type len,
offset += abfd->origin;
abfd = abfd->my_archive;
}
+ offset += abfd->origin;
if (abfd->iovec == NULL)
{
diff --git a/bfd/bfdwin.c b/bfd/bfdwin.c
index 6beed1f1ba..51b4faca76 100644
--- a/bfd/bfdwin.c
+++ b/bfd/bfdwin.c
@@ -150,6 +150,7 @@ bfd_get_file_window (bfd *abfd,
offset += abfd->origin;
abfd = abfd->my_archive;
}
+ offset += abfd->origin;
/* Seek into the file, to ensure it is open if cacheable. */
if (abfd->iostream == NULL
--
2.25.2
More information about the Binutils
mailing list