Subject: toolchain/24153: sparc64 -> i386 cross compile fails assembling negative bignums
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kirill@lava.net>
List: netbsd-bugs
Date: 01/19/2004 10:40:54
>Number:         24153
>Category:       toolchain
>Synopsis:       sparc64 -> i386 cross compile fails assembling negative bignums
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jan 19 18:42:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     
>Release:        NetBSD-current (ca. 17 Jan 2004)
>Organization:
>Environment:
System: NetBSD ultra2.ouranos 1.6.1 NetBSD 1.6.1 (GENERIC) #0: Mon Apr 7 10:27:16 UTC 2003 autobuild@cs20.apochromatic.org:/autobuilder/build/netbsd-1-6/sparc64/OBJ/autobuilder/build/netbsd-1-6/src/sys/arch/sparc64/compile/GENERIC sparc64
Architecture: sparc64
Machine: sparc64
>Description:
Cross-building a i386 kernel fails on a sparc64 in sys/crypto/sha2/sha2.c. The exact complait is about an invalid bignum. When I compiled with the -S flag, to see the assembly, the problem was a negative .quad bignum.
>How-To-Repeat:
Do a "./build.sh -m i386" a kernel on an ultrasparc. 
>Fix:
This sounds like a gas bug. I found
    http://sources.redhat.com/ml/binutils/2001-09/msg00389.html
when doing a Google search.

As a workaround, I compiled sha2.c using the powerpc gcc:
/home/source/src/../tool/bin/powerpc--netbsd-gcc -S -msoft-float -ffreestanding -O2 -Wreturn-type -Werror -Wall -Wno-main -Wno-format-zero-length -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wno-sign-compare -Dmacppc=macppc -I. -I/home/source/src/sys/arch -I/home/source/src/sys -nostdinc -DLKM -DDIAGNOSTIC -DZS_CONSOLE_ABORT -DMAXUSERS=32 -D_KERNEL -D_KERNEL_OPT -c /home/source/src/sys/crypto/sha2/sha2.c

Note that it generates the same constants, but uses .long rather than .quad.  I replaced the .quad sections in the i386 sha2.s with the .long sections generated by the powerpc compiler. (Note that this may result in different constants due to endian issues--I am not sure how this stuff works out) I then assembled sha2.o and resumed build.sh compilation with -u.
>Release-Note:
>Audit-Trail:
>Unformatted: