Solved Compile i386 kernel on amd64 CPU fails

Hi,

I'm trying to compile a 10.2-RELEASE kernel for my Soekris i386 1 GByte memory system (the target system). Due to it's slowness, I'm compiling the kernel on a AMD64 system (the build system).

Unfortunately, I'm getting compile errors, and I wonder if I might have done some silly. This is not unlikely: this is in fact the first time I'm attempting to build a custom FreeBSD kernel.

The build system runs FreeBSD 10.2-RELEASE #0 r2886666.

So far, I've done:

1. Ensure my build system is up-to-date.

I assume that freebsd-update also updates /usr/src.

freebsd-update fetch reports No updates needed to update system to 10.2-RELEASE-p5.
pkg update; pkg upgrade report All repositories are up-to-date and Your packages are up to date.

2. Create a kernel configuration.

cat [FILE]/usr/src/sys/i386/conf/SOEKRIS_ZFS[/FILE]
Code:
include GENERIC
options  CPU_SOEKRIS
options KSTACK_PAGES=4
options KVA_PAGES=320

3. Build compiler

make kernel-toolchain exited normally.

4. Build kernel

make DESTDIR=/root/kernels/wolfje TARGET=i386 KERNCONF=SOEKRIS_ZFS buildkernel 2>&1 | tee /root/kernels/buildkernel.log

Here are some relevant excerpts from buildkernel.log:

Code:
>>> Kernel build for SOEKRIS_ZFS started on Sun Oct 18 22:31:58 CEST 2015
--------------------------------------------------------------
===> SOEKRIS_ZFS
mkdir -p /usr/obj/i386.i386/usr/src/sys

--------------------------------------------------------------
>>> stage 1: configuring the kernel
--------------------------------------------------------------
cd /usr/src/sys/i386/conf;  PATH=/usr/obj/i386.i386/usr/src/tmp/legacy/usr/sbin:/usr/obj/i386.i386/usr/src/tmp/legacy/usr/bin:/usr/obj/i386.i386/usr/src/tmp/legacy/usr/games:/usr/obj/i386.i386/usr/src/tmp/legacy/bin:/usr/obj/i386.i386/usr/src/tmp/usr/sbin:/usr/obj/i386.i386/usr/src/tmp/usr/bin:/usr/obj/i386.i386/usr/src/tmp/usr/games:/sbin:/bin:/usr/sbin:/usr/bin  config  -d /usr/obj/i386.i386/usr/src/sys/SOEKRIS_ZFS  -I '/usr/src/sys/i386/conf' '/usr/src/sys/i386/conf/SOEKRIS_ZFS'
Kernel build directory is /usr/obj/i386.i386/usr/src/sys/SOEKRIS_ZFS
Don't forget to do ``make cleandepend && make depend''
....

Code:
cc  -c -O -pipe -std=c99 -g -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -fformat-extensions -Wmissing-include-dirs -fdiagnostics-show-option -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -nostdinc -I. -I/usr/src/sys -I/usr/src/sys/contrib/altq -I/usr/src/sys/contrib/ipfilter -I/usr/src/sys/dev/ath -I/usr/src/sys/dev/ath/ath_hal -I/usr/src/sys/contrib/dev/ath/ath_hal -I/usr/src/sys/contrib/ngatm -I/usr/src/sys/dev/twa -I/usr/src/sys/dev/cxgb -I/usr/src/sys/dev/cxgbe -I/usr/src/sys/contrib/libfdt -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h -mno-aes -mno-avx -mno-mmx -mno-sse -msoft-float -ffreestanding -fstack-protector -gdwarf-2 /usr/src/sys/i386/i386/genassym.c
In file included from /usr/src/sys/i386/i386/genassym.c:44:
In file included from /usr/src/sys/sys/systm.h:42:
./machine/cpufunc.h:487:41: warning: cast to 'char *' from smaller integer type 'u_int' (aka 'unsigned int') [-Wint-to-pointer-cast]
  __asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory");
  ^
In file included from /usr/src/sys/i386/i386/genassym.c:47:
In file included from /usr/src/sys/sys/buf.h:261:
In file included from /usr/src/sys/sys/proc.h:62:
In file included from /usr/src/sys/sys/pcpu.h:48:
In file included from ./machine/pcpu.h:36:
./machine/segments.h:91:29: error: use of undeclared identifier 'NLDT'
extern union descriptor ldt[NLDT];
  ^
In file included from /usr/src/sys/i386/i386/genassym.c:76:
In file included from ./machine/pcb.h:45:
In file included from ./machine/npx.h:44:
./x86/fpu.h:132:1: error: use of 'savefpu' with tag type that does not match previous declaration
struct savefpu {
^~~~~~
union
./machine/md_var.h:91:7: note: previous use is here
union  savefpu;
  ^

It seems some of the sources are old (would freebsd-update also updates /usr/src?), or not using the right headers (is TARGET=i386 properly recognised?) Am I using the correct invocation of these calls?

Regards,
Freek
 
[edit: report my solution]

Success!

>>> Kernel build for SOEKRIS_ZFS completed on Mon Oct 19 16:50:38 CEST 2015

Instead of running make kernel-toolchain, I ran make buildworld TARGET=i386.

I thought that make kernel-toolchain would only compile the clang compiler, and perhaps some other tools to run on my build system. Since the build system is amd64, it should compile clang for amd64. However, I noticed that the buildkernel PATH contains /usr/obj/i386.i386. So perhaps make kernel-toolchain does need the proper TARGET after all. Just be sure, I also used make buildworld (which includes make kernel-toolchain).

Thanks for the suggestions! I hope this report may be useful to others.
 
That's likely because what I have done in the past when cross-compiling for i386 is make buildworld TARGET=i386 and it has worked fine. The kernel-toolchain target is included in buildworld.
 
If I recall correctly you'd use kernel-toolchain if you only need to build a kernel and haven't done a full buildworld yet.
 
Back
Top