[PATCHes] Misc aliasing fixes for building DLL with gcc-4.5.0

Dave Korn dave.korn.cygwin@googlemail.com
Mon Aug 10 02:58:00 GMT 2009


    Hi everyone,

  I tried compiling winsup with GCC-4.5.0 HEAD, and it finds a bunch of things
to complain about (which then break the -Werror build).  They are mostly
"dereferencing type-punned pointer will break strict-aliasing rules" errors, but
there is also some possibly-undefined behaviour in passwd.cc (looks like a
problem with sequence points to me).

  There are also a couple of functions in fhandler_tty that don't have a return
statement despite not being of void type.  That's because they have infinite
while(1) loops in them, but gcc still complains.  This is probably a bug or
false positive in gcc's warnings, but it seems harmless enough to work around by
adding a "return 0" while waiting for it to be fixed; perhaps it might be
preferable just to disable -Werror for that file in the meantime?  Or we can
just leave them here in the archive for anyone else who runs into the problem to
stumble across and use as a local fix.

  There's one other patch that we might want to wait for a fix rather than work
around; currently there appears to be no way to declare an extern "C" function
as a friend of a class.  I solved that in fork.cc by making fork() an empty stub
that calls out to a C++-linkage function that is the actual friend.  I filed
PR41020 to find out if this is a real bug or a corner case of the C++ language
spec, we'll see what happens with that.

  Appended is one big patch that fixes the lot, and a listing of the individual
error messages from my build logs for anyone who's interested.

winsup/cygwin/ChangeLog:

	* fhandler_disk_file.cc (fhandler_base::fstat_helper): Add new
	overload that accepts LARGE_INTEGER times instead of FILETIMEs.
	(fhandler_base::fstat_by_handle): Remove type-punning casts and
	pass LARGE_INTEGERs to new overload instead.
	(fhandler_base::fstat_by_name): Likewise.	
	* fhandler.h (fhandler_base::fstat_helper): Prototype new overload.
	* fhandler_floppy.cc (fhandler_dev_floppy::get_drive_info): Avoid
	dereferencing type-punned cast.
	* fhandler_proc.cc (format_proc_cpuinfo): Avoid type-punning.
	* passwd.cc (internal_getpwsid): Avoid undefined behaviour.
	* syscalls.cc (gethostid): Use memcpys to avoid type-punning.
	* include/cygwin/in6.h (IN6_ARE_ADDR_EQUAL): Use memcmp to avoid
	dereferencing type-punned pointers.

	* fhandler_tty.cc (process_input): Add dummy return to silence warning.
	(process_ioctl): Likewise.

	* fork.cc (cygfork): New name with friendable C++ linkage for ...
	(fork): ... un-friendable extern "C" function becomes stub calling it.
	(class frok): Declare cygfork() friend, not fork(), avoiding PR41020.

  I've listed the controversial ones last separately from the others for
clarity.  These fixes got me through to a complete build of the DLL, but I
haven't tested them yet - I'm in the middle of a bunch of GCC tests, so it'll be
a couple of days before I can replace my in-use DLL and give it a whirl.  (That
gives us time to decide what to do about those last two ones.)

  Assuming nothing then shows up, OK to commit some or all?

    cheers,
      DaveK

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-4.5.0-misc-fixes.diff
Type: text/x-c
Size: 10938 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20090810/cca36401/attachment.bin>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: all-errs.txt
URL: <http://cygwin.com/pipermail/cygwin-patches/attachments/20090810/cca36401/attachment.txt>


More information about the Cygwin-patches mailing list