From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 3712C3858CDB; Wed, 24 May 2023 09:34:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3712C3858CDB Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Don't optimise bfd_seek to same position X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 2a2b2372420bf0373b932734e80a80c10adfdf14 X-Git-Newrev: 014a602b86f08de96fc80ef3f96a87db6cccad56 Message-Id: <20230524093458.3712C3858CDB@sourceware.org> Date: Wed, 24 May 2023 09:34:58 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 May 2023 09:34:58 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D014a602b86f0= 8de96fc80ef3f96a87db6cccad56 commit 014a602b86f08de96fc80ef3f96a87db6cccad56 Author: Alan Modra Date: Wed May 24 12:47:09 2023 +0930 Don't optimise bfd_seek to same position =20 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. =20 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." =20 * 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 !=3D SEEK_CUR) position +=3D offset; =20 - if ((direction =3D=3D SEEK_CUR && position =3D=3D 0) - || (direction =3D=3D SEEK_SET && (ufile_ptr) position =3D=3D abfd->w= here)) - return 0; - result =3D abfd->iovec->bseek (abfd, position, direction); if (result !=3D 0) {