[llvmlinux] Generating linux kernel .bc files

João Corrêa joao.lvwr at gmail.com
Sat Oct 4 23:46:24 UTC 2014

Hi everyone,

I've been able to successfully compile the linux kernel with clang-3.5. In
order to run some analysis, I've been trying to generate the respective -bc
files. Reading older mailing archive, I've seen that it is not possible to
do that just adding the -emit-llvm -c to the compilation flags. Due to
this, I've written a wrapper code that invokes the original clang-3.5 and
later invokes clang-3.5 again with the emit-llvm -c flags for each file.
I'm calling make with the flags CC=clang-3.5 HOSTCC=clang-3.5, properly.

If my wrapper is called, I get an error, as if the command was generated
for compilation with gcc (a few unrecognized flags). If I rename the
wrapper to make sure that clang is called instead of it, the compilation
occurs perfectly.

I'm attacking a file with the output of a 'make CC=clang-3.5
HOSTCC=clang-3.5 V=1'.

Thanks a lot and any hint regarding this would be very useful.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linuxfoundation.org/pipermail/llvmlinux/attachments/20141004/3af6de93/attachment.html>
-------------- next part --------------
joao at ubuntu:~/kernel/linux-3.16$ make CC=clang-3.5 HOSTCC=clang-3.5 V=1
make -f scripts/Makefile.build obj=arch/x86/syscalls all
make -f scripts/Makefile.build obj=scripts/basic
(cat /dev/null; ) > scripts/basic/modules.order
rm -f .tmp_quiet_recordmcount
make -f scripts/Makefile.build obj=arch/x86/tools relocs
set -e; : '  CHK     include/config/kernel.release'; mkdir -p include/config/; 	echo "3.16.0$(/bin/bash ./scripts/setlocalversion .)" < include/config/auto.conf > include/config/kernel.release.tmp; if [ -r include/config/kernel.release ] && cmp -s include/config/kernel.release include/config/kernel.release.tmp; then rm -f include/config/kernel.release.tmp; else : '  UPD     include/config/kernel.release'; mv -f include/config/kernel.release.tmp include/config/kernel.release; fi
make -f ./scripts/Makefile.asm-generic \
	            src=asm obj=arch/x86/include/generated/asm
make -f ./scripts/Makefile.asm-generic \
	            src=uapi/asm obj=arch/x86/include/generated/uapi/asm
set -e; : '  CHK     include/generated/uapi/linux/version.h'; mkdir -p include/generated/uapi/linux/; 	(echo \#define LINUX_VERSION_CODE 200704; echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))';) < Makefile > include/generated/uapi/linux/version.h.tmp; if [ -r include/generated/uapi/linux/version.h ] && cmp -s include/generated/uapi/linux/version.h include/generated/uapi/linux/version.h.tmp; then rm -f include/generated/uapi/linux/version.h.tmp; else : '  UPD     include/generated/uapi/linux/version.h'; mv -f include/generated/uapi/linux/version.h.tmp include/generated/uapi/linux/version.h; fi
set -e; : '  CHK     include/generated/utsrelease.h'; mkdir -p include/generated/; 	if [ `echo -n "3.16.0" | wc -c ` -gt 64 ]; then echo '"3.16.0" exceeds 64 characters' >&2; exit 1; fi; (echo \#define UTS_RELEASE \"3.16.0\";) < include/config/kernel.release > include/generated/utsrelease.h.tmp; if [ -r include/generated/utsrelease.h ] && cmp -s include/generated/utsrelease.h include/generated/utsrelease.h.tmp; then rm -f include/generated/utsrelease.h.tmp; else : '  UPD     include/generated/utsrelease.h'; mv -f include/generated/utsrelease.h.tmp include/generated/utsrelease.h; fi
mkdir -p .tmp_versions ; rm -f .tmp_versions/*
make -f scripts/Makefile.build obj=.
(cat /dev/null; ) > modules.order
mkdir -p kernel/
  clang-3.5 -Wp,-MD,kernel/.bounds.s.d  -nostdinc -isystem /usr/lib/llvm-3.5/bin/../lib/clang/3.5.0/include -I./arch/x86/include -Iarch/x86/include/generated  -Iinclude -I./arch/x86/include/uapi -Iarch/x86/include/generated/uapi -I./include/uapi -Iinclude/generated/uapi -include ./include/linux/kconfig.h -D__KERNEL__ -Qunused-arguments -Wno-unknown-warning-option -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -no-integrated-as -Wno-format-security -m64 -mno-mmx -mno-sse -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -march=core2 -mno-red-zone -mcmodel=kernel -funit-at-a-time -maccumulate-outgoing-args -DCONFIG_AS_CFI=1 -DCONFIG_AS_CFI_SIGNAL_FRAME=1 -DCONFIG_AS_CFI_SECTIONS=1 -DCONFIG_AS_FXSAVEQ=1 -DCONFIG_AS_CRC32=1 -DCONFIG_AS_AVX=1 -DCONFIG_AS_AVX2=1 -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -Os -Wno-maybe-uninitialized -Wframe-larger-than=2048 -fno-stack-protector -Wno-unused-variable -Wno-format-invalid-specifier -Wno-gnu -Wno-tautological-compare -mno-global-merge -fno-omit-frame-pointer -fno-optimize-sibling-calls -fno-var-tracking-assignments -Wdeclaration-after-statement -Wno-pointer-sign -fno-strict-overflow -fconserve-stack -Werror=implicit-int -Werror=strict-prototypes -Werror=date-time -DCC_HAVE_ASM_GOTO    -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(bounds)"  -D"KBUILD_MODNAME=KBUILD_STR(bounds)"  -fverbose-asm -S -o kernel/bounds.s kernel/bounds.c
clang: error: unknown argument: '-mno-80387'
clang: error: unknown argument: '-mno-fp-ret-in-387'
clang: error: unknown argument: '-mpreferred-stack-boundary=3'
clang: error: unknown argument: '-maccumulate-outgoing-args'
clang: error: unknown argument: '-fno-var-tracking-assignments'
clang: error: unknown argument: '-fconserve-stack'
fixdep: error opening depfile: kernel/.bounds.s.d: No such file or directory
make[1]: *** [kernel/bounds.s] Error 2
make: *** [prepare0] Error 2
joao at ubuntu:~/kernel/linux-3.16$ 

More information about the LLVMLinux mailing list