It appears that clang 3.9.1 and the kernel's TARGET_ARCH=powerpc assembler notations do not match in at least one way: --- locore.o --- /usr/src/sys/powerpc/aim/trap_subr32.S:409:2: error: too few operands for instruction cmp 0, %r1, %r3 ^ *** [locore.o] Error code 1 make[2]: stopped in /usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/sys/GENERICvtsc-NODBG .ERROR_TARGET='locore.o' .ERROR_META_FILE='/usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/sys/GENERICvtsc-NODBG/locore.o.meta' # Meta data file /usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/sys/GENERICvtsc-NODBG/locore.o.meta CMD cc -target powerpc-unknown-freebsd12.0 --sysroot=/usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/tmp -B/usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/tmp/usr/bin -c -x assembler-with-cpp -DLOCORE -O -pipe -g -nostdinc -I. -I/usr/src/sys -I/usr/src/sys/contrib/libfdt -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -include opt_global.h -msoft-float -fPIC -fno-omit-frame-pointer -mno-altivec -ffreestanding -fwrapv -fstack-protector -gdwarf-2 -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -D__printf__=__freebsd_kprintf__ -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error-tautological-compare -Wno-error-empty-body -Wno-error-parentheses-equality -Wno-error-unused-function -Wno-error-pointer-sign -Wno-error-shift-negative-value -msoft-float -std=iso9899:1999 -Werror /usr/src/sys/powerpc/aim/locore.S CWD /usr/obj/powerpcvtsc_clang_kernel/powerpc.powerpc/usr/src/sys/GENERICvtsc-NODBG TARGET locore.o -- command output -- /usr/src/sys/powerpc/aim/trap_subr32.S:409:2: error: too few operands for instruction cmp 0, %r1, %r3 ^ *** Error code 1 It is not clear to me which is to change: clang or the kernel assembler source (or both).
(In reply to Mark Millard from comment #0) Noting the SRC_ENV_CONF in use for the amd64 -> powerpc cross buildkernel: Script started on Sat Dec 31 00:15:10 2016 Command: env __MAKE_CONF=/root/src.configs/make.conf SRCCONF=/dev/null SRC_ENV_CONF=/root/src.configs/src.conf.powerpc64-clang-bootstrap.amd64-host WITH_META_MODE=yes MAKEOBJDIRPREFIX=/usr/obj/powerpc64vtsc_clang_kernel make -j 4 buildkernel # more ~/src.configs/src.conf.powerpc-clang-bootstrap.amd64-host TO_TYPE=powerpc # KERNCONF=GENERICvtsc-NODBG TARGET=${TO_TYPE} .if ${.MAKE.LEVEL} == 0 TARGET_ARCH=${TO_TYPE} .export TARGET_ARCH .endif # WITH_CROSS_COMPILER= WITHOUT_SYSTEM_COMPILER= # WITH_LIBCPLUSPLUS= WITH_BINUTILS_BOOTSTRAP= WITH_CLANG_BOOTSTRAP= WITH_CLANG= WITH_CLANG_IS_CC= WITH_CLANG_FULL= WITH_CLANG_EXTRAS= # lldb requires missing atomic 8-byte operations for powerpc (non-64) WITHOUT_LLDB= # WITH_BOOT= WITHOUT_LIB32= # WITHOUT_ELFTOOLCHAIN_BOOTSTRAP= WITHOUT_GCC_BOOTSTRAP= WITHOUT_GCC= WITHOUT_GCC_IS_CC= WITHOUT_GNUCXX= # NO_WERROR= #WERROR= MALLOC_PRODUCTION= # WITH_DEBUG_FILES=
(In reply to Mark Millard from comment #1) [Possibly to be treated as a kernel source code issue instead of a toolchain issue! Reassign?] It turns out that only one "normal" ppc instruction had such a syntactic rejection by llvm. So this is not a general syntax mismatch for clang 3.9.1 . I'd guess that the below means that the kernel source will be updated to avoid the problem. I've no clue if FreeBSD would request llvm to allow the assembler syntax that was rejected as well. clang 3.9.1 is not allowing the optional crD to be optional in the instruction format: cmp [crD,]L,rA,rB The following: # svnlite diff /usr/src/sys/powerpc/aim/trap_subr32.S Index: /usr/src/sys/powerpc/aim/trap_subr32.S =================================================================== --- /usr/src/sys/powerpc/aim/trap_subr32.S (revision 311147) +++ /usr/src/sys/powerpc/aim/trap_subr32.S (working copy) @@ -406,7 +406,7 @@ mtctr %r1 /* load counter */ im1: lwzu %r1, 8(%r2) /* get next pte */ - cmp 0, %r1, %r3 /* see if found pte */ + cmp 0, 0, %r1, %r3 /* see if found pte */ bdnzf 2, im1 /* dec count br if cmp ne and if * count not zero */ bne instr_sec_hash /* if not found set up second hash allows buildkernel to finish if WEEROR= is used. (The above filled in the default value explicltly.) The other code in trap_subr32.S has a couple of cmp instructions and they have the extra "0," already: . . . dm1: lwzu %r1, 8(%r2) /* get next pte */ cmp 0, 0, %r1, %r3 /* see if found pte */ bdnzf 2, dm1 /* dec count br if cmp ne and if * count not zero */ . . . ds1: lwzu %r1, 8(%r2) /* get next pte */ cmp 0, 0, %r1, %r3 /* see if found pte */ bdnzf 2, ds1 /* dec count br if cmp ne and if * count not zero */ So it appears that having the "extra" 0, is normal for the powerpc kernel sources. Extra information: The next error that buildkernel stopped at without WERROR= being in use was: --- adb_mouse.o --- /usr/src/sys/dev/adb/adb_mouse.c:523:21: error: implicit conversion from 'int' to 'int8_t' (aka 'signed char') changes value from 128 to -128 [-Werror,-Wconstant-conversion] sc->packet[0] = 1 << 7; ~ ~~^~~~ 1 error generated.
Apparently only one instruction is rejected by clang. Submitter has included a patch to the kernel source file /usr/src/sys/powerpc/aim/trap_subr32.S to fix this.
Created attachment 178692 [details] Avoid omitting the supposedly optional operand to cmp instruction clang 3.9.1 targeting powerpc (32-bit) reports a missing operand error for cmp with 3 operands, requiring the supposedly optional operand. The kernel has one example of the rejected notation: change it to supply all 4 operands --like the other cmp usage in the same file.
A commit references this bug: Author: jhibbits Date: Wed Jan 18 03:42:21 UTC 2017 New revision: 312369 URL: https://svnweb.freebsd.org/changeset/base/312369 Log: Use the explicit expanded form of cmp. Clang apparently requires the explicit form of this instruction, and rejects uses which ignore the optional cmpD register. This was the only use of the shorthand form of the instruction, so just fix it up to match the others. PR: kern/215681 Submitted by: Mark Millard Reported by: Mark Millard <markmi _AT_ dsl-only.net> MFC after: 2 weeks Changes: head/sys/powerpc/aim/trap_subr32.S
MFC'd to stable/11 r316369