stray warning from gcc's cpp

Dimitry Andric dim at FreeBSD.org
Wed Mar 19 20:00:56 UTC 2014


On 19 Mar 2014, at 10:58, Andriy Gapon <avg at FreeBSD.org> wrote:
> 
> 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
> 
> 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.
> 
> The following patch seems to fix the issue, but perhaps there is a better /
> smarter alternative.
> 
> --- 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;
>     }
> 
> -  if (regular && total != size && STAT_SIZE_RELIABLE (file->st))
> +  if (regular && total != size && file->fd != 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix-dtrace-gnu-cpp-1.diff
Type: application/octet-stream
Size: 1581 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-toolchain/attachments/20140319/c3fe6e5a/attachment.obj>
-------------- next part --------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.freebsd.org/pipermail/freebsd-toolchain/attachments/20140319/c3fe6e5a/attachment.sig>


More information about the freebsd-toolchain mailing list