clang: x86 kernel build for 32-bits fails with "invalid output size for constraint '=q'" |
||||||
Issue description
32-bit x86 builds with clang currently fail with a bunch of "invalid output size for constraint xyz" errors:
arch/x86/kernel/process.c:183:11: error: invalid output size for constraint '=q'
msrval = this_cpu_read(msr_misc_features_shadow);
^
./include/linux/percpu-defs.h:494:29: note: expanded from macro 'this_cpu_read'
#define this_cpu_read(pcp) __pcpu_size_call_return(this_cpu_read_, pcp)
^
./include/linux/percpu-defs.h:308:23: note: expanded from macro '__pcpu_size_call_return'
case 1: pscr_ret__ = stem##1(variable); break; \
^
<scratch space>:220:1: note: expanded from here
this_cpu_read_1
^
./arch/x86/include/asm/percpu.h:414:31: note: expanded from macro 'this_cpu_read_1'
#define this_cpu_read_1(pcp) percpu_from_op("mov", pcp)
^
./arch/x86/include/asm/percpu.h:189:15: note: expanded from macro 'percpu_from_op'
: "=q" (pfo_ret__) \
^
...
A bug exists in upstream LLVM, however there hasn't been any movement: https://bugs.llvm.org/show_bug.cgi?id=33587
The C code is: http://elixir.free-electrons.com/linux/v4.14/source/arch/x86/kernel/process.c#L179
And the macro with the line assembly: http://elixir.free-electrons.com/linux/v4.14/source/arch/x86/include/asm/percpu.h#L183
constraint 'q':
Any register accessible as rl. In 32-bit mode, a, b, c, and d; in 64-bit mode, any integer register.
https://gcc.gnu.org/onlinedocs/gcc/Machine-Constraints.html#Machine-Constraints
The 'offending' constraint is in the branch for 8-bit variables and shouldn't be relevant for msrval, which is 64-bit. My guess is that clang doesn't optimize the non-relevant branches away, and thus tries to generate assembly for the 8-bit case.
While we don't need 32-bit kernel builds for CrOS we want to get the upstream kernel into a state where clang just works (TM), at least for arm64 and x86. One use case of 32-bit x86 builds relevant for automated testing are 'allnoconfig' builds.
,
Nov 16 2017
For example, if I do 'clang -v -save-temps hello.c', I get: Chromium OS 6.0_pre316199_p20171105 clang version 6.0.0 (/var/cache/chromeos-cache/distfiles/host/egit-src/clang.git 53df1a5045c5c9471b0b4b00f8d64433d862699d) (/var/cache/chromeos-cache/distfiles/host/egit-src/llvm.git f56176dd98a9f4f7a3c59e1309bf8201d4529f76) (based on LLVM 6.0.0svn) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/i686-pc-linux-gnu/4.9.x Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/4.9.x Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x Found candidate GCC installation: /usr/lib/gcc/i686-pc-linux-gnu/4.9.x Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.x Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/4.9.x Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 "/usr/bin/clang-6.0" -cc1 -triple x86_64-pc-linux-gnu -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/6.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/6.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/cmtice -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o hello.i -x c hello.c clang -cc1 version 6.0.0 based upon LLVM 6.0.0svn default target x86_64-pc-linux-gnu ignoring nonexistent directory "/usr/local/include" ignoring nonexistent directory "/include" #include "..." search starts here: #include <...> search starts here: /usr/lib64/clang/6.0.0/include /usr/include End of search list. "/usr/bin/clang-6.0" -cc1 -triple x86_64-pc-linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/6.0.0 -fdebug-compilation-dir /home/cmtice -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -disable-llvm-passes -o hello.bc -x cpp-output hello.i clang -cc1 version 6.0.0 based upon LLVM 6.0.0svn default target x86_64-pc-linux-gnu #include "..." search starts here: End of search list. "/usr/bin/clang-6.0" -cc1 -triple x86_64-pc-linux-gnu -S -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib64/clang/6.0.0 -fdebug-compilation-dir /home/cmtice -ferror-limit 19 -fmessage-length 80 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o hello.s -x ir hello.bc clang -cc1 version 6.0.0 based upon LLVM 6.0.0svn default target x86_64-pc-linux-gnu "/usr/bin/clang-6.0" -cc1as -triple x86_64-pc-linux-gnu -filetype obj -main-file-name hello.c -target-cpu x86-64 -dwarf-version=4 -mrelocation-model static -mrelax-all -o hello.o hello.s "/usr/bin/x86_64-pc-linux-gnu-ld" --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64/crt1.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64/crti.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/crtbegin.o -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64 -L/usr/bin/../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../x86_64-pc-linux-gnu/lib -L/usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../.. -L/usr/bin/../lib -L/lib -L/usr/lib hello.o /usr/lib64/clang/6.0.0/lib/linux/libclang_rt.builtins-x86_64.a -lgcc_eh -lc /usr/lib64/clang/6.0.0/lib/linux/libclang_rt.builtins-x86_64.a -lgcc_eh /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/crtend.o /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/4.9.x/../../../../lib64/crtn.o as well as hello.i, hello.s, hello.o and a.out
,
Nov 16 2017
Is there a specific position where the flags should be added? The default invocation is: "/usr/bin/clang-6.0" -cc1 -triple i386-pc-linux-gnu -E -disable-free -disable-llvm-verifier -discard-value-names -main-file-name process.c -mrelocation-model static -meabi gnu -mthread-model posix -mllvm -warn-stack-size=1024 -mregparm 3 -freg-struct-return -mdisable-fp-elim -relaxed-aliasing -mdisable-tail-calls -fmath-errno -masm-verbose -no-integrated-as -mconstructor-aliases -ffreestanding -fuse-init-array -target-cpu i686 -target-feature -sse -target-feature -mmx -target-feature -sse2 -target-feature -3dnow -target-feature -avx -no-implicit-float -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/mka/linux/arch/x86/kernel/process.gcno -nostdsysteminc -nobuiltininc -resource-dir /usr/lib64/clang/6.0.0 -dependency-file arch/x86/kernel/.process.o.d -MT arch/x86/kernel/process.o -sys-header-deps -isystem /usr/lib64/clang/6.0.0/include -include ./include/linux/kconfig.h -I ./arch/x86/include -I ./arch/x86/include/generated -I ./include -I ./arch/x86/include/uapi -I ./arch/x86/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi -D __KERNEL__ -D CONFIG_AS_CFI=1 -D CONFIG_AS_CFI_SIGNAL_FRAME=1 -D CONFIG_AS_CFI_SECTIONS=1 -D CONFIG_AS_SSSE3=1 -D CONFIG_AS_CRC32=1 -D CONFIG_AS_AVX=1 -D CONFIG_AS_AVX2=1 -D CONFIG_AS_AVX512=1 -D CONFIG_AS_SHA1_NI=1 -D CONFIG_AS_SHA256_NI=1 -D "KBUILD_BASENAME=\"process\"" -D "KBUILD_MODNAME=\"process\"" -O2 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -Werror-implicit-function-declaration -Wno-format-security -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-address-of-packed-member -Wno-tautological-compare -Wno-sign-compare -Wdeclaration-after-statement -Wno-pointer-sign -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-sign-compare -Wno-format-zero-length -Wno-uninitialized -std=gnu89 -fno-dwarf-directory-asm -fdebug-compilation-dir /home/mka/linux -ferror-limit 19 -fmessage-length 114 -fwrapv -mstack-alignment=4 -fwchar-type=short -fno-signed-wchar -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o process.i -x c arch/x86/kernel/process.c With the flags at the end: error: unknown argument: '-save-temps' And at the beginning: clang-6.0: error: unknown argument: '-cc1' clang-6.0: error: unknown argument: '-triple' clang-6.0: error: unknown argument: '-main-file-name' clang-6.0: error: unknown argument: '-mrelocation-model' clang-6.0: error: unknown argument: '-mregparm' clang-6.0: error: unknown argument: '-mdisable-fp-elim' clang-6.0: error: unknown argument: '-relaxed-aliasing' clang-6.0: error: unknown argument: '-mdisable-tail-calls' clang-6.0: error: unknown argument: '-masm-verbose' clang-6.0: error: unknown argument: '-mconstructor-aliases' clang-6.0: error: unknown argument: '-target-cpu' clang-6.0: error: unknown argument: '-target-feature' clang-6.0: error: unknown argument: '-sse' clang-6.0: error: unknown argument: '-target-feature' clang-6.0: error: unknown argument: '-mmx' clang-6.0: error: unknown argument: '-target-feature' clang-6.0: error: unknown argument: '-sse2' clang-6.0: error: unknown argument: '-target-feature' clang-6.0: error: unknown argument: '-3dnow' clang-6.0: fatal error: too many errors emitted, stopping now [-ferror-limit=]
,
Nov 17 2017
It looks like that *is* the invocation to create the .i file, so you don't need to add the -save-temps there. If you could send me the process.i file, and also the invocation that uses the .i file and tries to generate the .s file, I would appreciate it.
,
Nov 17 2017
The (compressed) .i file is attached. This is the invocation that uses the .i file: "/usr/bin/clang-6.0" -cc1 -triple i386-pc-linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name process.c -mrelocation-model static -meabi gnu -mthread-model posix -mllvm -warn-stack-size=1024 -mregparm 3 -freg-struct-return -mdisable-fp-elim -relaxed-aliasing -mdisable-tail-calls -fmath-errno -masm-verbose -no-integrated-as -mconstructor-aliases -ffreestanding -fuse-init-array -target-cpu i686 -target-feature -sse -target-feature -mmx -target-feature -sse2 -target-feature -3dnow -target-feature -avx -no-implicit-float -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -v -coverage-notes-file /home/mka/linux/arch/x86/kernel/process.gcno -nostdsysteminc -nobuiltininc -resource-dir /usr/lib64/clang/6.0.0 -O2 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -Werror-implicit-function-declaration -Wno-format-security -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-address-of-packed-member -Wno-tautological-compare -Wno-sign-compare -Wdeclaration-after-statement -Wno-pointer-sign -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -Werror=incompatible-pointer-types -Wno-initializer-overrides -Wno-unused-value -Wno-format -Wno-sign-compare -Wno-format-zero-length -Wno-uninitialized -std=gnu89 -fno-dwarf-directory-asm -fdebug-compilation-dir /home/mka/linux -ferror-limit 19 -fmessage-length 114 -fwrapv -mstack-alignment=4 -fwchar-type=short -fno-signed-wchar -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -disable-llvm-passes -o process.bc -x cpp-output process.i
,
Nov 27 2017
it looks like this can wait until Manoj is back (next week). The bug upstream mentions this happens with integrated-as but I thought you were not using the integrated assembler. Can you please clarify this.
,
Nov 27 2017
We are invoking clang with -no-integrated-as, still we see this problem. From earlier issues around inline assembly constraints my understanding is that even with -no-integrated-as clang still does some parsing of inline assembly.
,
Nov 27 2017
I agree. I just found weird the upstream bug mentions integrated-as.. this looks like a compiler bug.. not an integrated-as bug.
,
Nov 27 2017
I was discussing this bug briefly with Eric Christopher, and he said it was not an integrated-as bug but an inline assembly bug.
,
Dec 6 2017
Will try to look at it soon.
,
Dec 11 2017
The error is issued when clang is trying to verify the inline asm semantics.
,
Dec 26 2017
,
Jan 2 2018
[It appears that a bunch of old cros issues bulk-added the "Infra" component recently, but they should probably be "Infra>Client>ChromeOS".]
,
Jan 4 2018
,
Feb 5 2018
|
||||||
►
Sign in to add a comment |
||||||
Comment 1 by cmt...@chromium.org
, Nov 16 2017