[llvmlinux] Build on x86 fails in arch/x86/include/asm/percpu.h

Jan-Simon Moeller dl9pf at gmx.de
Mon Dec 8 12:54:56 UTC 2014


Hi !

I have seen this issue, too just yesterday. 
My assumption is a macro misexpansion for the 32bit case - but someone needs 
to verify that (we switch on a sizeof calculation, not sure if clang likes 
that). 
Changing 'q' to 'r' might completely garble your per-cpu variables allocation 
and the failed boot is then expected.

We'll need to dig a little deeper here.

Best, 
Jan-Simon

Am Freitag, 5. Dezember 2014, 14:51:46 schrieb Michael L. Semon:
> Hi!  I'm trying rather desperately to get Clang to build a kernel on
> i686 Pentium 4.  Currently, I'm using a two-week-old SVN clang, just
> because I forgot to take last night's version home.  The kernel I'm
> trying to build is last night's `git clone` of the llvmlinux repository.
> The distribution is a month-old, 32-bit slackware-current.
> 
> Basically, for every build error in arch/x86/include/asm/percpu.h, clang
> is complaining about some input that is like "q" or "qi" in a switch
> where case is always 1 (3-4 different places).  The rest of the cases
> have something like "r" or "ri".  To switch "q" to "r" satisfies the
> build, but the resulting kernel boots to one blue square and one red
> square on VGA, no serial ouput, regardless of whether it's booted by
> LILO or by GRUB.  If I use this kernel as a panic kernel loaded by kexec,
> there's a staircase effect of fancy colors and then stoppage.
> 
> IOW, I have no clue of what I'm doing here, just reaching for straws.
> My asm skills are absolutely zero.
> 
> Anyway, my failed attempt is posted as a patch at the end of this letter,
> just so you know where I tried to change things and failed.
> 
> BTW, should arch/x86/boot/memory.c include "string.h"?  clang complains
> about implicit declaration of memcpy, but the resulting kernel doesn't
> seem to behave any differently.
> 
> Thanks!
> 
> Michael
> 
> [script output and failed patch follow:]
> 
> Script started on Fri 05 Dec 2014 12:46:39 PM EST
> # Note: SVN clang was built on November 22.
> # Note: I tried to clean out the ANSI escape sequences as well as I could.
> 
> root at kyhorse:/usr/src/llvmlinux/kernel# clang --version
> clang version 3.6.0 (trunk)
> Target: i386-pc-linux-gnu
> Thread model: posix
> root at kyhorse:/usr/src/llvmlinux/kernel# make CC=clang CXX=clang++
> HOSTCC=clang CHK     include/config/kernel.release
>   CHK     include/generated/uapi/linux/version.h
>   CHK     include/generated/utsrelease.h
>   CC      arch/x86/kernel/asm-offsets.s
>   GEN     include/generated/asm-offsets.h
>   CALL    scripts/checksyscalls.sh
>   CC      init/main.o
>   CHK     include/generated/compile.h
>   CC      init/version.o
>   CC      init/do_mounts.o
>   CC      init/do_mounts_rd.o
>   LD      init/mounts.o
>   CC      init/noinitramfs.o
>   CC      init/calibrate.o
>   CC      init/init_task.o
>   LD      init/built-in.o
>   AS      arch/x86/crypto/aes-i586-asm_32.o
>   CC      arch/x86/crypto/aes_glue.o
>   LD      arch/x86/crypto/aes-i586.o
>   AS      arch/x86/crypto/twofish-i586-asm_32.o
>   CC      arch/x86/crypto/twofish_glue.o
>   LD      arch/x86/crypto/twofish-i586.o
>   LD      arch/x86/crypto/built-in.o
>   CC      arch/x86/kernel/process_32.o
>   CC      arch/x86/kernel/signal.o
>   AS      arch/x86/kernel/entry_32.o
>   CC      arch/x86/kernel/traps.o
>   CC      arch/x86/kernel/irq.o
>   CC      arch/x86/kernel/irq_32.o
>   CC      arch/x86/kernel/dumpstack_32.o
>   CC      arch/x86/kernel/time.o
>   CC      arch/x86/kernel/ioport.o
>   CC      arch/x86/kernel/ldt.o
>   CC      arch/x86/kernel/dumpstack.o
>   CC      arch/x86/kernel/nmi.o
>   CC      arch/x86/kernel/setup.o
>   CC      arch/x86/kernel/x86_init.o
>   CC      arch/x86/kernel/i8259.o
>   CC      arch/x86/kernel/irqinit.o
>   CC      arch/x86/kernel/jump_label.o
>   CC      arch/x86/kernel/irq_work.o
>   CC      arch/x86/kernel/probe_roms.o
>   CC      arch/x86/kernel/i386_ksyms_32.o
>   CC      arch/x86/kernel/syscall_32.o
>   CC      arch/x86/kernel/vsyscall_gtod.o
>   CC      arch/x86/kernel/ksysfs.o
>   CC      arch/x86/kernel/bootflag.o
>   CC      arch/x86/kernel/e820.o
>   CC      arch/x86/kernel/pci-dma.o
>   CC      arch/x86/kernel/quirks.o
>   CC      arch/x86/kernel/topology.o
>   CC      arch/x86/kernel/kdebugfs.o
>   CC      arch/x86/kernel/alternative.o
>   CC      arch/x86/kernel/i8253.o
>   CC      arch/x86/kernel/pci-nommu.o
>   CC      arch/x86/kernel/hw_breakpoint.o
>   CC      arch/x86/kernel/tsc.o
> arch/x86/kernel/tsc.c:865:2: error: invalid input size for constraint 'qi'
>         this_cpu_write(cyc2ns.data[0].cyc2ns_offset, 0);
>         ^
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:366:11: note: expanded from macro
> '__pcpu_size_call' case 1: stem##1(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:271:1: note: expanded from here
> this_cpu_write_1
> ^
> ./arch/x86/include/asm/percpu.h:387:36: note: expanded from macro
>       'this_cpu_write_1'
> #define this_cpu_write_1(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:865:2: error: invalid input size for constraint 'qi'
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:367:11: note: expanded from macro
> '__pcpu_size_call' case 2: stem##2(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:273:1: note: expanded from here
> this_cpu_write_2
> ^
> ./arch/x86/include/asm/percpu.h:388:36: note: expanded from macro
>       'this_cpu_write_2'
> #define this_cpu_write_2(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:865:2: error: invalid input size for constraint 'qi'
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:368:11: note: expanded from macro
> '__pcpu_size_call' case 4: stem##4(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:273:1: note: expanded from here
> this_cpu_write_4
> ^
> ./arch/x86/include/asm/percpu.h:389:36: note: expanded from macro
>       'this_cpu_write_4'
> #define this_cpu_write_4(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:866:2: error: invalid input size for constraint 'qi'
>         this_cpu_write(cyc2ns.data[1].cyc2ns_offset, 0);
>         ^
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:366:11: note: expanded from macro
> '__pcpu_size_call' case 1: stem##1(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:273:1: note: expanded from here
> this_cpu_write_1
> ^
> ./arch/x86/include/asm/percpu.h:387:36: note: expanded from macro
>       'this_cpu_write_1'
> #define this_cpu_write_1(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:866:2: error: invalid input size for constraint 'qi'
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:367:11: note: expanded from macro
> '__pcpu_size_call' case 2: stem##2(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:273:1: note: expanded from here
> this_cpu_write_2
> ^
> ./arch/x86/include/asm/percpu.h:388:36: note: expanded from macro
>       'this_cpu_write_2'
> #define this_cpu_write_2(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:866:2: error: invalid input size for constraint 'qi'
> include/linux/percpu-defs.h:499:34: note: expanded from macro
> 'this_cpu_write' #define this_cpu_write(pcp, val)       
> __pcpu_size_call(this_cpu_write_... ^
> include/linux/percpu-defs.h:368:11: note: expanded from macro
> '__pcpu_size_call' case 4: stem##4(variable, __VA_ARGS__);break;          
> \ ^
> <scratch space>:273:1: note: expanded from here
> this_cpu_write_4
> ^
> ./arch/x86/include/asm/percpu.h:389:36: note: expanded from macro
>       'this_cpu_write_4'
> #define this_cpu_write_4(pcp, val)      percpu_to_op("mov", (pcp), val)
>                                         ^
> ./arch/x86/include/asm/percpu.h:101:15: note: expanded from macro
> 'percpu_to_op'
>                     : "qi" ((pto_T__)(val)));           \
> 
>                             ^
> arch/x86/kernel/tsc.c:980:28: warning: shift count >= width of type
>       [-Wshift-count-overflow]
>         .mask                   = CLOCKSOURCE_MASK(64),
>                                   ^~~~~~~~~~~~~~~~~~~~
> include/linux/clocksource.h:214:62: note: expanded from macro
> 'CLOCKSOURCE_MASK' #define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ?
> ((1ULL<<(bits))-1) : -1) ^ ~~~~~~ 1 warning and 6 errors generated.
> make[2]: *** [arch/x86/kernel/tsc.o] Error 1
> make[1]: *** [arch/x86/kernel] Error 2
> make: *** [arch/x86] Error 2
> 
> [failed patch]
> 
> From 0ff347719e66df38722454eef1ad22e10fe5d2b7 Mon Sep 17 00:00:00 2001
> From: "Michael L. Semon" <mlsemon35 at gmail.com>
> Date: Fri, 5 Dec 2014 12:38:36 -0500
> Subject: [PATCH] LLVMLinux: uneducated build workaround that did not result
> in bootable kernel
> 
> I was trying to work around build errors on x86 (i686 Pentium 4).  However,
> not knowing the correct answer, I tried to change "q" to "r" to match the
> other entries in the area.  Resulting kernel boots to something like this
> on the screen:
> 
> [blank][blank][blank][blue][blank][blank][blank][red]
> 
> What's the correct answer?
> ---
>  Makefile                      | 6 +++---
>  arch/x86/include/asm/percpu.h | 6 +++---
>  2 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 8a54b03..e21b72d 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -295,8 +295,8 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo
> $$BASH; \ else if [ -x /bin/bash ]; then echo /bin/bash; \
>  	  else echo sh; fi ; fi)
> 
> -HOSTCC       = gcc
> -HOSTCXX      = g++
> +HOSTCC       = clang
> +HOSTCXX      = clang++
>  HOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2
> -fomit-frame-pointer -std=gnu89 HOSTCXXFLAGS = -O2
> 
> @@ -354,7 +354,7 @@ include $(srctree)/scripts/Kbuild.include
>  # Make variables (CC, etc...)
>  AS		= $(CROSS_COMPILE)as
>  LD		= $(CROSS_COMPILE)ld
> -CC		= $(CROSS_COMPILE)gcc
> +CC		= $(CROSS_COMPILE)clang
>  CPP		= $(CC) -E
>  AR		= $(CROSS_COMPILE)ar
>  NM		= $(CROSS_COMPILE)nm
> diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
> index fd47218..87e9d1d 100644
> --- a/arch/x86/include/asm/percpu.h
> +++ b/arch/x86/include/asm/percpu.h
> @@ -98,7 +98,7 @@ do {							\
>  	case 1:						\
>  		asm(op "b %1,"__percpu_arg(0)		\
> 
>  		    : "+m" (var)			\
> 
> -		    : "qi" ((pto_T__)(val)));		\
> +		    : "ri" ((pto_T__)(val)));		\
>  		break;					\
>  	case 2:						\
>  		asm(op "w %1,"__percpu_arg(0)		\
> @@ -143,7 +143,7 @@ do {									\
>  		else							\
>  			asm("addb %1, "__percpu_arg(0)			\
> 
>  			    : "+m" (var)				\
> 
> -			    : "qi" ((pao_T__)(val)));			\
> +			    : "ri" ((pao_T__)(val)));			\
>  		break;							\
>  	case 2:								\
>  		if (pao_ID__ == 1)					\
> @@ -185,7 +185,7 @@ do {									\
>  	switch (sizeof(var)) {				\
>  	case 1:						\
>  		asm(op "b "__percpu_arg(1)",%0"		\
> -		    : "=q" (pfo_ret__)			\
> +		    : "=r" (pfo_ret__)			\
> 
>  		    : constraint);			\
> 
>  		break;					\
>  	case 2:						\



More information about the LLVMLinux mailing list