]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Don't optimise bfd_seek to same position
authorAlan Modra <amodra@gmail.com>
Wed, 24 May 2023 03:17:09 +0000 (12:47 +0930)
committerAlan Modra <amodra@gmail.com>
Wed, 24 May 2023 09:34:48 +0000 (19:04 +0930)
It's not worth avoiding an fseek to the same position, and can cause
problems if the linker's output file (which is opened "w+") is read,
because that can result in writing, reading, then writing again.

POSIX.1-2017 (IEEE Std 1003.1) says of fopen:
"When a file is opened with update mode ('+' as the second or third
character in the mode argument), both input and output may be
performed on the associated stream. However, the application shall
ensure that output is not directly followed by input without an
intervening call to fflush() or to a file positioning function
(fseek(), fsetpos(), or rewind()), and input is not directly followed
by output without an intervening call to a file positioning function,
unless the input operation encounters end-of-file."

* bfdio.c (bfd_seek): Always call iovec->bseek.

bfd/bfdio.c

index 75a3309c582079c93c3ae040b728e6b950415ede..22c39a7b0ccfb0bd9ef29cea58ce1d699dec9d45 100644 (file)
@@ -456,10 +456,6 @@ 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)
     {