Created attachment 2873 [details] bugpoint program output After making two changes to the kernel to get it to build with clang, 1. In kernel's Makefile, scripts/Makefile.lib and scripts/Makefile.host, perform the following substitution: s/-Wp,-MD,/-MD -MF / 2. In include/linux/kernel.h, force macro _THIS_IP_ to return zero, rather than using __label__. (Older kernels may not require this step) clang successfully begins the build process, making it to one of the first actual kernel files, init/main.c, where it crashes (shown below). I ran bugpoint, and have attached the output. clang -MD -MF init/.main.o.d -nostdinc -isystem include -Iinclude -I/spare/repo/linux-2.6/arch/x86/include -include include/linux/autoconf.h -D__KERNEL__ -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m64 -march=core2 -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wframe-larger-than=2048 -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -Wdeclaration-after-statement -Wno-pointer-sign -fwrapv -fno-dwarf2-cfi-asm -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(main)" -D"KBUILD_MODNAME=KBUILD_STR(main)" -c -o init/main.o init/main.c clang: warning: the clang compiler does not yet support '-pg' warning: unknown warning option: -Wframe-larger-than=2048 init/main.c:570:9: warning: format string is not a string literal (potentially insecure) [-Wformat-nonliteral] printk(linux_banner); ^~~~~~~~~~~~ init/main.c:628:9: warning: format string is not a string literal (potentially insecure) [-Wformat-nonliteral] panic(panic_later, panic_param); ^~~~~~~~~~~ clang-cc: /garz/repo/llvm/include/llvm/Target/TargetRegisterInfo.h:301: static bool llvm::TargetRegisterInfo::isPhysicalRegister(unsigned int): Assertion `Reg && "this is not a register!"' failed. 0 clang-cc 0x000000000103677f 1 clang-cc 0x0000000001036b69 2 libpthread.so.0 0x00000034c020f0f0 3 libc.so.6 0x00000034bf632f05 gsignal + 53 4 libc.so.6 0x00000034bf634a73 abort + 387 5 libc.so.6 0x00000034bf62bef9 __assert_fail + 233 6 clang-cc 0x0000000000a45532 7 clang-cc 0x0000000000a4721e 8 clang-cc 0x0000000000d1a410 9 clang-cc 0x0000000000a4619b 10 clang-cc 0x0000000000a46b0e 11 clang-cc 0x0000000000fd2b49 12 clang-cc 0x0000000000fd352e 13 clang-cc 0x0000000000fd373b 14 clang-cc 0x00000000004386e5 15 clang-cc 0x0000000000438b17 16 clang-cc 0x00000000005a431d 17 clang-cc 0x0000000000474c56 18 clang-cc 0x000000000047c0e1 main + 1953 19 libc.so.6 0x00000034bf61e576 __libc_start_main + 230 20 clang-cc 0x00000000004287e9 Stack dump: 0. Program arguments: /usr/local/bin/../libexec/clang-cc -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name main.c --relocation-model static --disable-fp-elim --unwind-tables=1 --disable-red-zone --mattr -mmx,-sse,-sse2,-3dnow --fmath-errno=1 -nostdinc -dependency-file init/.main.o.d -MT init/main.o -sys-header-deps -isystem include -include include/linux/autoconf.h -D__KERNEL__ -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DKBUILD_STR(s)=#s -DKBUILD_BASENAME=KBUILD_STR(main) -DKBUILD_MODNAME=KBUILD_STR(main) -Iinclude -I/spare/repo/linux-2.6/arch/x86/include -O2 -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -Werror-implicit-function-declaration -Wno-sign-compare -Wframe-larger-than=2048 -Wdeclaration-after-statement -Wno-pointer-sign -fno-common -fdiagnostics-show-option -o /tmp/cc-ZU4Nhi.s -x c init/main.c 1. <eof> parser at end of file 2. Code generation 3. Running pass 'X86 AT&T-Style Assembly Printer' on function '@start_kernel' make[1]: *** [init/main.o] Error 250 make: *** [init] Error 2
Created attachment 2874 [details] bugpoint output 2 of 3
Created attachment 2875 [details] bugpoint output 3 of 3
Created attachment 2876 [details] bitcode for original file (pre-bugpoint)
this is the offending asm line: %0 = call i64 asm "movq %gs:${1:P},$0", "=r,*m,~{dirflag},~{fpsr},~{flags}"(i64* @per_cpu__kernel_stack) Looks like #3379
*** Bug 4080 has been marked as a duplicate of this bug. ***
The frequency of this assertion increases dramatically, when building latest upstream kernel (~2.6.30-rc3) rather than 2.6.29.
Created attachment 2894 [details] proposed patch This patch makes the assert go away, and the correct asm is emitted. However I am not sure if it'll work in all cases, since I can't find the documentation for %P1 in gcc's docs.
The definition of P is: P -- if PIC, print an @PLT suffix. (this is above print_operand in gcc/config/i386/i386.c). The patch looks ok to me as a start, but should check to see if in PIC mode or not I guess. Also, why the +3?
(In reply to comment #7) > Created an attachment (id=2894) [details] > proposed patch > > This patch makes the assert go away, and the correct asm is emitted. > However I am not sure if it'll work in all cases, since I can't find the > documentation for %P1 in gcc's docs. The patch does not work in PIC mode.... I'm working on the fix.
I hope this should fix it: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090427/076811.html