Date: Wed, 19 Mar 2014 21:00:39 +0100 From: Dimitry Andric <dim@FreeBSD.org> To: Andriy Gapon <avg@FreeBSD.org> Cc: freebsd-toolchain@FreeBSD.org Subject: Re: stray warning from gcc's cpp Message-ID: <E0220F76-0FE3-4F9D-8110-4E228F06E3F0@FreeBSD.org> In-Reply-To: <53296A34.1060108@FreeBSD.org> References: <53296A34.1060108@FreeBSD.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--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 <avg@FreeBSD.org> 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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E0220F76-0FE3-4F9D-8110-4E228F06E3F0>