Subject: [PATCH] cross-compilation broken
To: None <tech-toolchain@netbsd.org>
From: Ruslan Ermilov <ru@FreeBSD.org>
List: tech-toolchain
Date: 04/26/2006 17:25:38
--L6iaP+gRLNZHKoI4
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi there,

I'm cross-compiling NetBSD/evbmips on FreeBSD 7.0-CURRENT amd64.
It fails late in the "make sets" step due to nbmtree tool dumping
a core.  The following patch for tools/compat/compat_defs.h fixes
a problem:

%%%
Index: compat_defs.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/cvs/ipnet/ipnet/adm5120/netbsd/src/tools/compat/compat_defs=
=2Eh,v
retrieving revision 1.1.1.3
diff -u -p -r1.1.1.3 compat_defs.h
--- compat_defs.h	19 Apr 2006 11:24:12 -0000	1.1.1.3
+++ compat_defs.h	20 Apr 2006 10:22:57 -0000
@@ -37,7 +37,6 @@
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <grp.h>
 #include <limits.h>
 #include <paths.h>
 #include <stdarg.h>
@@ -75,6 +74,9 @@
 /* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
 struct passwd;
=20
+/* We don't include <grp.h> here, so that redefinitions below work. */
+struct group;
+
 /* Assume an ANSI compiler for the host. */
=20
 #undef __P
%%%

Without this patch, I get the following when compiling tools/mtree:

: $ ~/work/ipnet/adm5120/netbsd/tools/bin/nbmake-evbmips-el
:     compile  mtree/compare.lo
:     compile  mtree/crc.lo
:     compile  mtree/create.lo
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/create.c: In function `statf':
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/create.c:175: warning: assignment makes pointer from integer without a c=
ast
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/create.c: In function `statd':
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/create.c:351: warning: assignment makes pointer from integer without a c=
ast
:     compile  mtree/excludes.lo
:     compile  mtree/misc.lo
:     compile  mtree/mtree.lo
:     compile  mtree/spec.lo
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/spec.c: In function `dump_nodes':
: /usr/home/ru/work/ipnet/adm5120/netbsd/src/tools/mtree/../../usr.sbin/mtr=
ee/spec.c:341: warning: assignment makes pointer from integer without a cast
:     compile  mtree/verify.lo
:     compile  mtree/getid.lo
:     compile  mtree/stat_flags.lo
:     compile  mtree/pack_dev.lo
:        link  mtree/mtree
: $ head -175 ../../usr.sbin/mtree/create.c | tail -1
:                     (name =3D group_from_gid(p->fts_statp->st_gid, 1)) !=
=3D NULL)

The compat_defs.h does the following:

: #  define group_from_gid __nbcompat_group_from_gid

Unfortunately it does this already after <grp.h> is included so a
preprocessed source ends up having the "group_from_gid" prototype
=66rom <grp.h> and "__nbcompat_group_from_gid" anywhere later in the
code.   Since the function turns up unprototyped, the "int" return
value is implied which for amd64 is fatal, given that the function
returns a 64-bit pointer which gets truncated to a 32-bit "int".

Another problem with "make sets" -- it runs the "makesums" script
with insufficient environment.  In particular, the sets.subr script
it sources ends up using the host make(1) binary which in my case
(FreeBSD) gets upset by the following line in the wrapper
tools/bin/nbmake-evbmips-el script:

: MAKEFLAGS=3D'-de -m /usr/home/ru/work/ipnet/adm5120/netbsd/src/share/mk -=
X MKOBJDIRS=3Dyes'; export MAKEFLAGS

(The FreeBSD's make doesn't understand 'e' option to -d.)
The following patch for distrib/common/Makefile.distrib fixes it:

%%%
Index: Makefile.distrib
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/cvs/ipnet/ipnet/adm5120/netbsd/src/distrib/common/Makefile.=
distrib,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 Makefile.distrib
--- Makefile.distrib	27 Sep 2005 07:03:16 -0000	1.1.1.2
+++ Makefile.distrib	21 Apr 2006 13:42:16 -0000
@@ -25,7 +25,9 @@ DISTRIBVER!=3D	${HOST_SH} ${NETBSDSRCDIR}/
 DISTRIBVERDEP=3D	${NETBSDSRCDIR}/sys/sys/param.h \
 		${NETBSDSRCDIR}/sys/conf/osrelease.sh
=20
-MAKESUMS=3D	CKSUM=3D${TOOL_CKSUM:Q} ${HOST_SH} ${DISTRIBDIR}/sets/makesums
+MAKESUMS=3D	CKSUM=3D${TOOL_CKSUM:Q} \
+		MAKE=3D${MAKE:Q} \
+		${HOST_SH} ${DISTRIBDIR}/sets/makesums
 RELEASE_INSTALL=3D${INSTALL} ${RENAME} ${PRESERVE} ${COPY} -m ${NONBINMODE}
=20
=20
%%%


Cheers,
--=20
Ruslan Ermilov
ru@FreeBSD.org
FreeBSD committer

--L6iaP+gRLNZHKoI4
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (FreeBSD)

iD8DBQFET4LhqRfpzJluFF4RAg0jAJ9+l8U21piI6zh4cxpy5kH8s3dGOwCeJCgL
T6ma59v2kje3FWs+tcDfYHg=
=HlbM
-----END PGP SIGNATURE-----

--L6iaP+gRLNZHKoI4--