public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] Don't optimise bfd_seek to same position
Date: Wed, 24 May 2023 09:34:58 +0000 (GMT)	[thread overview]
Message-ID: <20230524093458.3712C3858CDB@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=014a602b86f08de96fc80ef3f96a87db6cccad56

commit 014a602b86f08de96fc80ef3f96a87db6cccad56
Author: Alan Modra <amodra@gmail.com>
Date:   Wed May 24 12:47:09 2023 +0930

    Don't optimise bfd_seek to same position
    
    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.

Diff:
---
 bfd/bfdio.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/bfd/bfdio.c b/bfd/bfdio.c
index 75a3309c582..22c39a7b0cc 100644
--- a/bfd/bfdio.c
+++ b/bfd/bfdio.c
@@ -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)
     {

                 reply	other threads:[~2023-05-24  9:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230524093458.3712C3858CDB@sourceware.org \
    --to=amodra@sourceware.org \
    --cc=bfd-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).