aboutsummaryrefslogtreecommitdiff
path: root/bfd/bfdio.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-08-07 08:28:55 +0930
committerAlan Modra <amodra@gmail.com>2023-08-09 08:47:35 +0930
commitf82ee0c8dc4ee32556e23e6cd83ef083618f704f (patch)
tree6775612169afe1cd7270f7fe4c10f5b451dfdb44 /bfd/bfdio.c
parent7570a17cbbe647db6260ae2391f92c0509de7924 (diff)
downloadgdb-f82ee0c8dc4ee32556e23e6cd83ef083618f704f.zip
gdb-f82ee0c8dc4ee32556e23e6cd83ef083618f704f.tar.gz
gdb-f82ee0c8dc4ee32556e23e6cd83ef083618f704f.tar.bz2
PR30724, cygwin ld performance regression since 014a602b86
According to the reporter of this bug the newlib fseek implementation is likely slowed down by locking and fflush, only attempting to optimise seeks when the file is opened read-only. Thus when writing the output we get a dramatic slowdown due to commit 014a602b86. PR 30724 * bfd.c (enum bfd_last_io): New. (struct bfd): Add last_io field. * bfd-in2.h: Regenerate. * bfd-io.c (bfd_bread, bfd_bwrite): Force seek if last_io is opposite direction. (bfd_seek): Reinstate optimisation for seek to same position.
Diffstat (limited to 'bfd/bfdio.c')
-rw-r--r--bfd/bfdio.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 22c39a7..e0d47b3 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -279,6 +279,14 @@ bfd_bread (void *ptr, bfd_size_type size, bfd *abfd)
return -1;
}
+ if (abfd->last_io == bfd_io_write)
+ {
+ abfd->last_io = bfd_io_force;
+ if (bfd_seek (abfd, 0, SEEK_CUR) != 0)
+ return -1;
+ }
+ abfd->last_io = bfd_io_read;
+
nread = abfd->iovec->bread (abfd, ptr, size);
if (nread != -1)
abfd->where += nread;
@@ -313,6 +321,14 @@ bfd_bwrite (const void *ptr, bfd_size_type size, bfd *abfd)
return -1;
}
+ if (abfd->last_io == bfd_io_read)
+ {
+ abfd->last_io = bfd_io_force;
+ if (bfd_seek (abfd, 0, SEEK_CUR) != 0)
+ return -1;
+ }
+ abfd->last_io = bfd_io_write;
+
nwrote = abfd->iovec->bwrite (abfd, ptr, size);
if (nwrote != -1)
abfd->where += nwrote;
@@ -456,6 +472,13 @@ 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))
+ && abfd->last_io != bfd_io_force)
+ return 0;
+
+ abfd->last_io = bfd_io_seek;
+
result = abfd->iovec->bseek (abfd, position, direction);
if (result != 0)
{