Subject: kern/1787: Kernels can't be cross-compiled
To: None <gnats-bugs@NetBSD.ORG>
From: Ted Lemon <mellon@fugue.com>
List: netbsd-bugs
Date: 11/24/1995 21:29:51
>Number:         1787
>Category:       kern
>Synopsis:       Kernels can't be cross-compiled
>Confidential:   no
>Severity:       non-critical
>Priority:       high
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Nov 25 00:50:01 1995
>Last-Modified:
>Originator:     Ted Lemon
>Organization:
>Release:        current
>Environment:
	
System: NetBSD toccata 1.0 NetBSD 1.0 (PASSACAGLIA) #7: Sun Sep 3 23:19:25 PDT 1995 mellon@toccata:/usr/src/sys/arch/i386/compile/PASSACAGLIA i386


>Description:
	It's not possible to build a kernel for, e.g., the pmax, on an
	i386 machine.
>How-To-Repeat:
	Try building a kernel - it barfs the minute it tries to
	assemble something.
>Fix:
	The following patches provide a basis for cross-compilation
	support.   In addition to these changes, the conf/Makefile.xxx
	file must be modified for each architecture in order to
	provide definitions for TARGET_MACHINE, TARGET_ARCH, CC, AS,
	LD, NM, AR, RANLIB and LORDER.   These definitions must be
	conditional upon $(MACHINE) not matching the target machine.
	For an example of this, see sys/arch/pmax/conf/Makefile.pmax.

	The change to sys.mk provides default definitions for NM and
	LORDER, which must vary from architecture to architecture.

	The change to bsd.lib.mk uses $(LORDER) instead of lorder,
	allowing architectures which need to provide a different
	version of lorder or require lorder to use a different version
	of nm may do so.

	The changes to lorder.sh and lorder.sh.gnm check the NM
	environment variable, and if it's not set, set it to nm.  This
	allows a non-standard version of NM to be specified to lorder.

	The changes to sys/lib/libkern/Makefile.inc and
	sys/compat/common/Makefile.inc pass down the variable
	definitions defined in the sys/arch/xxx/conf/Makefile.xxx
	file, as described above.

	The changes to sys/lib/libkern/Makefile and
	sys/compat/common/Makefile set the variable TARGET_ARCH to
	MACHINE_ARCH and TARGET_MACHINE to MACHINE if they aren't
	already set (presumably by the invoking Makefile).   They also
	use TARGET_ARCH instead of MACHINE_ARCH to find
	architecture-specific files and definitions.

Index: sys/lib/libkern/Makefile
===================================================================
RCS file: /a/cvsroot/src/sys/lib/libkern/Makefile,v
retrieving revision 1.24
diff -c -r1.24 Makefile
*** Makefile	1995/10/20 01:10:06	1.24
--- Makefile	1995/11/25 05:01:20
***************
*** 6,22 ****
  DIR=${KERNREL}${KERNDIR}
  
  CC=	${KERNCC}
! CFLAGS=	-I${DIR}/arch/${MACHINE_ARCH} \
  	${KERNCFLAGS:S/-D_KERNEL//:S@-I.@-I${KERNREL}.@g}
  
! .if exists (${DIR}/arch/${MACHINE_ARCH}/Makefile.inc)
! .PATH:	${DIR}/arch/${MACHINE_ARCH}
! .include "${DIR}/arch/${MACHINE_ARCH}/Makefile.inc"
  .endif
  
  .PATH: ${DIR}
  
! .if (${MACHINE_ARCH} != "alpha")
  # Quad support
  SRCS+=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
  	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
--- 6,29 ----
  DIR=${KERNREL}${KERNDIR}
  
  CC=	${KERNCC}
! LD=	${KERNLD}
! AS=	${KERNAS}
! AR=	${KERNAR}
! LORDER=	${KERNLORDER}
! RANLIB= ${KERNRANLIB}
! TARGET_MACHINE?= ${MACHINE}
! TARGET_ARCH?=${MACHINE_ARCH}
! CFLAGS=	-I${DIR}/arch/${TARGET_ARCH} \
  	${KERNCFLAGS:S/-D_KERNEL//:S@-I.@-I${KERNREL}.@g}
  
! .if exists (${DIR}/arch/${TARGET_ARCH}/Makefile.inc)
! .PATH:	${DIR}/arch/${TARGET_ARCH}
! .include "${DIR}/arch/${TARGET_ARCH}/Makefile.inc"
  .endif
  
  .PATH: ${DIR}
  
! .if (${TARGET_ARCH} != "alpha")
  # Quad support
  SRCS+=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
  	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
***************
*** 37,46 ****
  lib${LIB}.o:: ${OBJS}
  	@echo building standard ${LIB} library
  	@rm -f lib${LIB}.o
! 	@${LD} -r -o lib${LIB}.o `lorder ${OBJS} | tsort`
  
  POBJS+=	${OBJS:.o=.po} mcount.po
  lib${LIB}.po:: ${POBJS}
  	@echo building profiled ${LIB} library
  	@rm -f lib${LIB}.po
! 	@${LD} -r -o lib${LIB}.po `lorder ${POBJS} | tsort`
--- 44,53 ----
  lib${LIB}.o:: ${OBJS}
  	@echo building standard ${LIB} library
  	@rm -f lib${LIB}.o
! 	@${LD} -r -o lib${LIB}.o `$(LORDER) ${OBJS} | tsort`
  
  POBJS+=	${OBJS:.o=.po} mcount.po
  lib${LIB}.po:: ${POBJS}
  	@echo building profiled ${LIB} library
  	@rm -f lib${LIB}.po
! 	@${LD} -r -o lib${LIB}.po `$(LORDER) ${POBJS} | tsort`
Index: sys/lib/libkern/Makefile.inc
===================================================================
RCS file: /a/cvsroot/src/sys/lib/libkern/Makefile.inc,v
retrieving revision 1.12
diff -c -r1.12 Makefile.inc
*** Makefile.inc	1995/10/07 09:56:55	1.12
--- Makefile.inc	1995/11/25 05:01:20
***************
*** 13,18 ****
--- 13,25 ----
  	@echo making sure the kern library is up to date...
  	@(cd ${KERNDST} && ${MAKE} -f ${KERNREL}${KERNDIR}/Makefile \
  	  KERNCC="${CC}" \
+ 	  KERNLD="${LD}" \
+ 	  KERNAS="${AS}" \
+ 	  KERNAR="${AR}" \
+ 	  KERNLORDER="${LORDER}" \
+ 	  KERNLRANLIB="${RANLIB}" \
+ 	  TARGET_MACHINE="${TARGET_MACHINE}" \
+ 	  TARGET_ARCH="${TARGET_ARCH}" \
  	  KERNCFLAGS="${CFLAGS}" \
  	  KERNREL="${KERNREL}" \
  	  KERNDIR="${KERNDIR}" libkern.o)
Index: sys/compat/common/Makefile
===================================================================
RCS file: /a/cvsroot/src/sys/compat/common/Makefile,v
retrieving revision 1.4
diff -c -r1.4 Makefile
*** Makefile	1995/10/20 00:34:15	1.4
--- Makefile	1995/11/25 05:01:20
***************
*** 6,19 ****
  .PATH:	${COMPATREL}${COMPATDIR}
  
  CC=	${COMPATCC}
  CFLAGS=	${COMPATCFLAGS:S@-I.@-I${COMPATREL}.@g}
  
  SRCS=	compat_tty.c compat_util.c kern_exit_43.c kern_info_09.c \
  	kern_info_43.c kern_prot_43.c kern_resource_43.c kern_sig_43.c \
  	uipc_syscalls_43.c vfs_syscalls_43.c
  
  # really, all machines were sizeof(int) != sizeof(long)
! .if (${MACHINE_ARCH} != "alpha")
  SRCS+=	kern_ipc_10.c 
  .endif
  
--- 6,26 ----
  .PATH:	${COMPATREL}${COMPATDIR}
  
  CC=	${COMPATCC}
+ LD=	${COMPATLD}
+ AS=	${COMPATAS}
+ AR=	${COMPATAR}
+ LORDER=	${COMPATLORDER}
+ RANLIB=	${COMPATRANLIB}
  CFLAGS=	${COMPATCFLAGS:S@-I.@-I${COMPATREL}.@g}
+ TARGET_MACHINE?= ${MACHINE}
+ TARGET_ARCH?=${MACHINE_ARCH}
  
  SRCS=	compat_tty.c compat_util.c kern_exit_43.c kern_info_09.c \
  	kern_info_43.c kern_prot_43.c kern_resource_43.c kern_sig_43.c \
  	uipc_syscalls_43.c vfs_syscalls_43.c
  
  # really, all machines were sizeof(int) != sizeof(long)
! .if (${TARGET_ARCH} != "alpha")
  SRCS+=	kern_ipc_10.c 
  .endif
  
Index: sys/compat/common/Makefile.inc
===================================================================
RCS file: /a/cvsroot/src/sys/compat/common/Makefile.inc,v
retrieving revision 1.2
diff -c -r1.2 Makefile.inc
*** Makefile.inc	1995/06/26 03:27:15	1.2
--- Makefile.inc	1995/11/25 05:01:20
***************
*** 13,18 ****
--- 13,25 ----
  	@echo making sure the compat library is up to date...
  	@(cd ${COMPATDST} && ${MAKE} -f ${COMPATREL}${COMPATDIR}/Makefile \
  	  COMPATCC="${CC}" \
+ 	  COMPATLD="${LD}" \
+ 	  COMPATAS="${AS}" \
+ 	  COMPATAR="${AR}" \
+ 	  COMPATLORDER="${LORDER}" \
+ 	  COMPATRANLIB="${RANLIB}" \
+ 	  TARGET_MACHINE="${TARGET_MACHINE}" \
+ 	  TARGET_ARCH="${TARGET_ARCH}" \
  	  COMPATCFLAGS="${CFLAGS}" \
  	  COMPATREL="${COMPATREL}" \
  	  COMPATDIR="${COMPATDIR}" libcompat.a)
Index: share/mk/sys.mk
===================================================================
RCS file: /a/cvsroot/src/share/mk/sys.mk,v
retrieving revision 1.22
diff -c -r1.22 sys.mk
*** sys.mk	1995/09/24 23:49:09	1.22
--- sys.mk	1995/11/25 05:01:21
***************
*** 10,15 ****
--- 10,17 ----
  AR?=		ar
  ARFLAGS?=	rl
  RANLIB?=	ranlib
+ NM?=		nm
+ LORDER?=	lorder
  
  AS?=		as
  AFLAGS?=
Index: share/mk/bsd.lib.mk
===================================================================
RCS file: /a/cvsroot/src/share/mk/bsd.lib.mk,v
retrieving revision 1.66
diff -c -r1.66 bsd.lib.mk
*** bsd.lib.mk	1995/10/22 00:45:56	1.66
--- bsd.lib.mk	1995/11/25 05:01:22
***************
*** 110,130 ****
  lib${LIB}.a:: ${OBJS}
  	@echo building standard ${LIB} library
  	@rm -f lib${LIB}.a
! 	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort`
  	${RANLIB} lib${LIB}.a
  
  POBJS+=	${OBJS:.o=.po}
  lib${LIB}_p.a:: ${POBJS}
  	@echo building profiled ${LIB} library
  	@rm -f lib${LIB}_p.a
! 	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort`
  	${RANLIB} lib${LIB}_p.a
  
  SOBJS+=	${OBJS:.o=.so}
  lib${LIB}_pic.a:: ${SOBJS}
  	@echo building shared object ${LIB} library
  	@rm -f lib${LIB}_pic.a
! 	@${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort`
  	${RANLIB} lib${LIB}_pic.a
  
  lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
--- 110,130 ----
  lib${LIB}.a:: ${OBJS}
  	@echo building standard ${LIB} library
  	@rm -f lib${LIB}.a
! 	@${AR} cq lib${LIB}.a `$(LORDER) ${OBJS} | tsort`
  	${RANLIB} lib${LIB}.a
  
  POBJS+=	${OBJS:.o=.po}
  lib${LIB}_p.a:: ${POBJS}
  	@echo building profiled ${LIB} library
  	@rm -f lib${LIB}_p.a
! 	@${AR} cq lib${LIB}_p.a `$(LORDER) ${POBJS} | tsort`
  	${RANLIB} lib${LIB}_p.a
  
  SOBJS+=	${OBJS:.o=.so}
  lib${LIB}_pic.a:: ${SOBJS}
  	@echo building shared object ${LIB} library
  	@rm -f lib${LIB}_pic.a
! 	@${AR} cq lib${LIB}_pic.a `$(LORDER) ${SOBJS} | tsort`
  	${RANLIB} lib${LIB}_pic.a
  
  lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
Index: usr.bin/lorder/lorder.sh
===================================================================
RCS file: /a/cvsroot/src/usr.bin/lorder/lorder.sh,v
retrieving revision 1.3
diff -c -r1.3 lorder.sh
*** lorder.sh	1995/04/24 07:38:52	1.3
--- lorder.sh	1995/11/25 05:01:22
***************
*** 52,57 ****
--- 52,62 ----
  R=/tmp/_reference_$$
  S=/tmp/_symbol_$$
  
+ # Take nm from the environment if it's there...
+ if [ "$NM"x = "x" ]; then
+   NM=nm
+ fi
+ 
  # remove temporary files on HUP, INT, QUIT, PIPE, TERM
  trap "rm -f $R $S; exit 1" 1 2 3 13 15
  
***************
*** 63,69 ****
  #
  # if the line has " U " it's a globally undefined symbol, put it into
  # the reference file.
! nm -go $* | sed "
  	/:$/ {
  		s/://
  		s/.*/& &/
--- 68,74 ----
  #
  # if the line has " U " it's a globally undefined symbol, put it into
  # the reference file.
! $NM -go $* | sed "
  	/:$/ {
  		s/://
  		s/.*/& &/
Index: usr.bin/lorder/lorder.sh.gnm
===================================================================
RCS file: /a/cvsroot/src/usr.bin/lorder/lorder.sh.gnm,v
retrieving revision 1.1
diff -c -r1.1 lorder.sh.gnm
*** lorder.sh.gnm	1995/04/24 07:39:06	1.1
--- lorder.sh.gnm	1995/11/25 05:01:23
***************
*** 52,57 ****
--- 52,62 ----
  R=/tmp/_reference_$$
  S=/tmp/_symbol_$$
  
+ # Take nm from the environment if it's there...
+ if [ "$NM"x = "x" ]; then
+   NM=nm
+ fi
+ 
  # remove temporary files on HUP, INT, QUIT, PIPE, TERM
  trap "rm -f $R $S; exit 1" 1 2 3 13 15
  
***************
*** 64,70 ****
  # if the line has " U " it's a globally undefined symbol, put it into
  # the reference file.
  for file in $* ; do
! ( echo "" ; echo ${file}: ; nm -go $file ) | sed "
  	/:$/ {
  		s/://
  		s/.*/& &/
--- 69,75 ----
  # if the line has " U " it's a globally undefined symbol, put it into
  # the reference file.
  for file in $* ; do
! ( echo "" ; echo ${file}: ; $NM -go $file ) | sed "
  	/:$/ {
  		s/://
  		s/.*/& &/
>Audit-Trail:
>Unformatted: