This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Tidy bfdio to consistenly use containing archive


On Tue, Jun 05, 2018 at 10:38:26PM +0930, Alan Modra wrote:
> and bfd_seek optimized calls that didn't move the
> file pointer.

Which turns out to be quite important.  In cases where section data is
filled in piece by piece with bfd_set_section_contents, you get an
fseek followed by an fwrite of the data.  At least when the fwrite
isn't exactly one 4k disk sector that results in an lseek to the
containing sector, a read of that sector, another lseek, then a write,
repeated piece by piece.  A huge increase in IO.

This patch reinstates the bfd_seek optimization.  Seeks within
archives are optimized too, something that wasn't possible before the
patch that caused this PR.

	PR 23282
	* bfdio.c (bfd_seek): Optimize away seeks to current position.

diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 136fa8b1d3..1f4caca4ed 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -330,6 +330,10 @@ bfd_seek (bfd *abfd, file_ptr position, int direction)
   if (direction != SEEK_CUR)
     position += offset;
 
+  if ((direction == SEEK_CUR && position == 0)
+      || (direction == SEEK_SET && (ufile_ptr) position == abfd->where))
+    return 0;
+
   result = abfd->iovec->bseek (abfd, position, direction);
   if (result != 0)
     {

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]