Subject: toolchain/36159: Cross build on Cygwin fails (sha1.c)
To: None <toolchain-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <bsh@netbsd.org>
List: netbsd-bugs
Date: 04/17/2007 04:05:00
>Number:         36159
>Category:       toolchain
>Synopsis:       Cross build of NetBSD/i386 on Windows XP with Cygwin 1.5.24 fails while compiling sha1.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 17 04:05:00 +0000 2007
>Originator:     Hiroyuki Bessho
>Release:        NetBSD-current as of 2007-Apr-16
>Organization:
>Environment:
System: CYGWIN_NT-5.1 takanoha 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin
Architecture: i386
Machine: i386
>Description:
	Cross build of NetBSD/i386 on Windows XP with Cygwin 1.5.24 fails.

===> build.sh command: ./build.sh -mi386 -U -D../destdir.i386 -T../tools -uo tools
===> build.sh started: Tue Apr 17 09:55:51     2007
===> NetBSD version:   4.99.17
===> MACHINE:          i386
===> MACHINE_ARCH:     i386
===> Build platform:   CYGWIN_NT-5.1 1.5.24(0.156/4/2) i686
===> HOST_SH:          /usr/bin/sh
===> TOOLDIR path:     /cygdrive/e/nb/current/src/../tools
===> DESTDIR path:     /cygdrive/e/nb/current/src/../destdir.i386
===> RELEASEDIR path:  /cygdrive/e/nb/current/src/releasedir
===> makewrapper:      /cygdrive/e/nb/current/src/../tools/bin/nbmake-i386
===> Updated /cygdrive/e/nb/current/src/../tools/bin/nbmake-i386
echo /cygdrive/e/nb/current/src/../tools >PREVIOUSTOOLDIR
dependall ===> host-mkdep
install ===> host-mkdep
dependall ===> compat
#   compile  compat/sha1.lo
cc -O  -I. -I./include -I/cygdrive/e/nb/current/src/tools/compat -I/cygdrive/e/nb/current/src/tools/compat/sys  -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D__DBINTERFACE_PRIVATE -c -o sha1.lo.o    /cygdrive/e/nb/current/src/tools/compat/../../common/lib/libc/hash/sha1/sha1.c
/cygdrive/e/nb/current/src/tools/compat/../../common/lib/libc/hash/sha1/sha1.c: In function `SHA1Transform':
/cygdrive/e/nb/current/src/tools/compat/../../common/lib/libc/hash/sha1/sha1.c:151: error: argument "state" doesn't match prototype
/cygdrive/e/nb/current/src/tools/compat/../../sys/sys/sha1.h:25: error: prototype declaration

*** Failed target:  sha1.lo
*** Failed command: cc -O -I. -I./include -I/cygdrive/e/nb/current/src/tools/compat -I/cygdrive/e/nb/current/src/tools/compat/sys -DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D__DBINTERFACE_PRIVATE -c -o sha1.lo.o /cygdrive/e/nb/current/src/tools/compat/../../common/lib/libc/hash/sha1/sha1.c
*** Error code 1

Stop.
nbmake: stopped in /cygdrive/e/nb/current/src/tools/compat

*** Failed target:  dependall
*** Failed command: cd /cygdrive/e/nb/current/src/tools/compat; /cygdrive/e/nb/current/src/../tools/bin/nbmake realall
*** Error code 1

Stop.
nbmake: stopped in /cygdrive/e/nb/current/src/tools/compat

*** Failed target:  dependall-compat
*** Failed command: _makedirtarget() { dir="$1"; shift; target="$1"; shift; case "${dir}" in /*) this="${dir}/"; real="${dir}" ;; .) this=""; real="/cygdrive/e/nb/current/src/tools" ;; *) this="${dir}/"; real="/cygdrive/e/nb/current/src/tools/${dir}" ;; esac; show=${this:-.}; echo "${target} ===> ${show%/}${1:+ (with: $@)}"; cd "${real}" && /cygdrive/e/nb/current/src/../tools/bin/nbmake _THISDIR_="${this}" "$@" ${target}; }; _makedirtarget compat dependall
*** Error code 1

Stop.
nbmake: stopped in /cygdrive/e/nb/current/src/tools

ERROR: Failed to make dependall tools
*** BUILD ABORTED ***
>How-To-Repeat:
Run "build.sh tools" on Windows.

>Fix:
This happens because SHA1Transform() is prototyped as
	SHA1Transform(uint32_t[5], const u_char[64])
and defined as
	SHA1Transform(u_int32_t[5], const u_char[64])

uint32_t and u_int32_t should be the same, but uint32_t is unsigned long and u_int32_t is unsigned int on Cygwin.

The following patch gives a workaround.

Index: sha1/sha1.c
===================================================================
RCS file: /u0/cvsupbase/cvsroot-netbsd/src/common/lib/libc/hash/sha1/sha1.c,v
retrieving revision 1.2
diff -u -r1.2 sha1.c
--- sha1/sha1.c	27 Oct 2006 21:25:21 -0000	1.2
+++ sha1/sha1.c	17 Apr 2007 01:42:46 -0000
@@ -146,10 +146,10 @@
  * Hash a single 512-bit block. This is the core of the algorithm.
  */
 void SHA1Transform(state, buffer)
-    u_int32_t state[5];
+    uint32_t state[5];
     const u_char buffer[64];
 {
-    u_int32_t a, b, c, d, e;
+    uint32_t a, b, c, d, e;
     CHAR64LONG16 *block;
 
 #ifdef SHA1HANDSOFF