From owner-freebsd-toolchain@FreeBSD.ORG Wed Mar 19 20:00:56 2014 Return-Path: Delivered-To: freebsd-toolchain@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 95D5C755; Wed, 19 Mar 2014 20:00:56 +0000 (UTC) Received: from tensor.andric.com (tensor.andric.com [87.251.56.140]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 324C87D9; Wed, 19 Mar 2014 20:00:55 +0000 (UTC) Received: from [IPv6:2001:7b8:3a7::a026:571e:e171:37df] (unknown [IPv6:2001:7b8:3a7:0:a026:571e:e171:37df]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by tensor.andric.com (Postfix) with ESMTPSA id 635735C45; Wed, 19 Mar 2014 21:00:47 +0100 (CET) Content-Type: multipart/signed; boundary="Apple-Mail=_DBB510D3-A524-4324-B39B-5062877AB5BC"; protocol="application/pgp-signature"; micalg=pgp-sha1 Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) Subject: Re: stray warning from gcc's cpp From: Dimitry Andric In-Reply-To: <53296A34.1060108@FreeBSD.org> Date: Wed, 19 Mar 2014 21:00:39 +0100 Message-Id: References: <53296A34.1060108@FreeBSD.org> To: Andriy Gapon X-Mailer: Apple Mail (2.1874) Cc: freebsd-toolchain@FreeBSD.org X-BeenThere: freebsd-toolchain@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Maintenance of FreeBSD's integrated toolchain List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Mar 2014 20:00:56 -0000 --Apple-Mail=_DBB510D3-A524-4324-B39B-5062877AB5BC Content-Type: multipart/mixed; boundary="Apple-Mail=_F8E5405F-2B48-46A8-8271-D8CEABB85882" --Apple-Mail=_F8E5405F-2B48-46A8-8271-D8CEABB85882 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On 19 Mar 2014, at 10:58, Andriy Gapon wrote: >=20 > I observe the following minor annoyance on FreeBSD systems where cpp = is GCC's > cpp. If a DTrace script has the following shebang line: > #!/usr/sbin/dtrace -Cs > then the following warning is produced when the script is run: > cc1: warning: is shorter than expected >=20 > Some details. dtrace(1) first forks. Then a child seeks on a file = descriptor > associated with the script file, so that the shebang line is skipped = (because > otherwise it would confuse cpp). Then the child makes the file = descriptor its > standard input and then it execs cpp. cpp performs fstat(2) on its = standard > input descriptor and determines that it points to a regular file. = Then it > verifies that a number of bytes it reads from the file is the same as = a size of > the file. The check makes sense if the file is opened by cpp itself, = but it > does not always make sense for the stdin as described above. >=20 > The following patch seems to fix the issue, but perhaps there is a = better / > smarter alternative. >=20 > --- a/contrib/gcclibs/libcpp/files.c > +++ b/contrib/gcclibs/libcpp/files.c > @@ -601,7 +601,8 @@ read_file_guts (cpp_reader *pfile, _cpp_file = *file) > return false; > } >=20 > - if (regular && total !=3D size && STAT_SIZE_RELIABLE (file->st)) > + if (regular && total !=3D size && file->fd !=3D 0 > + && STAT_SIZE_RELIABLE (file->st)) > cpp_error (pfile, CPP_DL_WARNING, > "%s is shorter than expected", file->path); Something like the attached diff, perhaps? This just gets the current file pointer offset, and adds it to the total number of bytes read. The sum must still match the fstat'd size, of course. For files opened by cpp itself there is no functional change, but it does seem to fix the problem case you have described. -Dimitry --Apple-Mail=_F8E5405F-2B48-46A8-8271-D8CEABB85882 Content-Disposition: attachment; filename=fix-dtrace-gnu-cpp-1.diff Content-Type: application/octet-stream; name="fix-dtrace-gnu-cpp-1.diff" Content-Transfer-Encoding: 7bit Index: contrib/gcclibs/libcpp/files.c =================================================================== --- contrib/gcclibs/libcpp/files.c (revision 263376) +++ contrib/gcclibs/libcpp/files.c (working copy) @@ -545,7 +545,7 @@ static bool read_file_guts (cpp_reader *pfile, _cpp_file *file) { - ssize_t size, total, count; + ssize_t size, offset, total, count; uchar *buf; bool regular; @@ -573,12 +573,21 @@ } size = file->st.st_size; + + if ((offset = (ssize_t)lseek(file->fd, (off_t)0, SEEK_CUR)) < 0) + { + cpp_error (pfile, CPP_DL_ERROR, "%s has no current position", file->path); + return false; + } } else - /* 8 kilobytes is a sensible starting size. It ought to be bigger - than the kernel pipe buffer, and it's definitely bigger than - the majority of C source files. */ - size = 8 * 1024; + { + /* 8 kilobytes is a sensible starting size. It ought to be bigger + than the kernel pipe buffer, and it's definitely bigger than + the majority of C source files. */ + size = 8 * 1024; + offset = 0; + } buf = XNEWVEC (uchar, size + 1); total = 0; @@ -586,7 +595,7 @@ { total += count; - if (total == size) + if (offset + total == size) { if (regular) break; @@ -601,7 +610,7 @@ return false; } - if (regular && total != size && STAT_SIZE_RELIABLE (file->st)) + if (regular && offset + total != size && STAT_SIZE_RELIABLE (file->st)) cpp_error (pfile, CPP_DL_WARNING, "%s is shorter than expected", file->path); --Apple-Mail=_F8E5405F-2B48-46A8-8271-D8CEABB85882 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii --Apple-Mail=_F8E5405F-2B48-46A8-8271-D8CEABB85882-- --Apple-Mail=_DBB510D3-A524-4324-B39B-5062877AB5BC Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP using GPGMail -----BEGIN PGP SIGNATURE----- Version: GnuPG/MacGPG2 v2.0.22 (Darwin) iEYEARECAAYFAlMp920ACgkQsF6jCi4glqMFvQCg7A8l2mUOm78CZY9iwq5NHaAJ 3H0Anj9TL90PJZ1szhny+OiuoGOZYcQk =ztpM -----END PGP SIGNATURE----- --Apple-Mail=_DBB510D3-A524-4324-B39B-5062877AB5BC--