public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] bfd: Don't check non-thin archive member file size
@ 2021-12-24 23:46 H.J. Lu
  2021-12-27  6:56 ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2021-12-24 23:46 UTC (permalink / raw)
  To: binutils

There is no need to check member file size for thin archive member.

	* bfdio.c (bfd_bread): Don't check non-thin archive member file
	size.
---
 bfd/bfdio.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 463b3879c52..9aa15c1ffa4 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -231,9 +231,11 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
     }
   offset += abfd->origin;
 
-  /* If this is an archive element, don't read past the end of
+  /* If this is a non-thin archive element, don't read past the end of
      this element.  */
-  if (element_bfd->arelt_data != NULL)
+  if (element_bfd->arelt_data != NULL
+      && element_bfd->my_archive != NULL
+      && !bfd_is_thin_archive (element_bfd->my_archive))
     {
       bfd_size_type maxbytes = arelt_size (element_bfd);
 
-- 
2.33.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bfd: Don't check non-thin archive member file size
  2021-12-24 23:46 [PATCH] bfd: Don't check non-thin archive member file size H.J. Lu
@ 2021-12-27  6:56 ` Alan Modra
  2021-12-27 13:31   ` H.J. Lu
  0 siblings, 1 reply; 4+ messages in thread
From: Alan Modra @ 2021-12-27  6:56 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Fri, Dec 24, 2021 at 03:46:04PM -0800, H.J. Lu via Binutils wrote:
> There is no need to check member file size for thin archive member.

Does it hurt to check against the file size recorded in the archive
header?  Did someone report a "bug", perhaps that a thin archive
member file was updated without running ar, and then hit an error?

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bfd: Don't check non-thin archive member file size
  2021-12-27  6:56 ` Alan Modra
@ 2021-12-27 13:31   ` H.J. Lu
  2021-12-28  8:19     ` Alan Modra
  0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2021-12-27 13:31 UTC (permalink / raw)
  To: Alan Modra; +Cc: Binutils

On Sun, Dec 26, 2021 at 10:56 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Dec 24, 2021 at 03:46:04PM -0800, H.J. Lu via Binutils wrote:
> > There is no need to check member file size for thin archive member.
>
> Does it hurt to check against the file size recorded in the archive
> header?  Did someone report a "bug", perhaps that a thin archive
> member file was updated without running ar, and then hit an error?
>

While debugging a GCC bootstrap bug, I copied a .o file without running
ar on a thin archive.  Other linkers didn't complain.  There is no need to.

-- 
H.J.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] bfd: Don't check non-thin archive member file size
  2021-12-27 13:31   ` H.J. Lu
@ 2021-12-28  8:19     ` Alan Modra
  0 siblings, 0 replies; 4+ messages in thread
From: Alan Modra @ 2021-12-28  8:19 UTC (permalink / raw)
  To: H.J. Lu; +Cc: Binutils

On Mon, Dec 27, 2021 at 05:31:13AM -0800, H.J. Lu wrote:
> On Sun, Dec 26, 2021 at 10:56 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Fri, Dec 24, 2021 at 03:46:04PM -0800, H.J. Lu via Binutils wrote:
> > > There is no need to check member file size for thin archive member.
> >
> > Does it hurt to check against the file size recorded in the archive
> > header?  Did someone report a "bug", perhaps that a thin archive
> > member file was updated without running ar, and then hit an error?
> >
> 
> While debugging a GCC bootstrap bug, I copied a .o file without running
> ar on a thin archive.  Other linkers didn't complain.  There is no need to.

No doubt what you did was reasonably safe, but if an object file that
is part of a thin archive is replaced without running ar then it is
possible for the archive symbol table to be wrong.  That could lead to
linker misbehaviour.  So I'm inclined to say we should be checking
the archive header size against file size.

Such a check doesn't really belong in bfd_bread though, so please go
ahead and apply your patch.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-12-28  8:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-24 23:46 [PATCH] bfd: Don't check non-thin archive member file size H.J. Lu
2021-12-27  6:56 ` Alan Modra
2021-12-27 13:31   ` H.J. Lu
2021-12-28  8:19     ` Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).