<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Greatings,<div>  </div><div>     I am encountering the same issue with Kevin. Does anyone know how to compile the linux kernel to .bc file?</div><div>     Is there any oneline guide for this? Thanks!~</div><div><br></div><div>Bests,</div><div>Ping</div><div>     <br><br><div>> Date: Sat, 1 Jun 2013 20:15:56 +0200<br>> From: baldrick@free.fr<br>> To: llvmdev@cs.uiuc.edu<br>> Subject: Re: [LLVMdev] Compile Linux Kernel module into LLVM bitcode<br>> <br>> Hi Kevin,<br>> <br>> On 01/06/13 09:59, Kevin Boos wrote:<br>> > Greetings,<br>> ><br>> > I am trying to compile a linux kernel module (currently a small part of the gpu driver) into the bitcode ".bc" format so that I can run a pass on it using the "opt" command. This pass will count the number of times copy_to/from_user() is invoked.<br>> ><br>> > Compiling the gnu driver kernel modules works with clang as a front end. However, I am unable to get the "-emit-llvm" flag to work.<br>> ><br>> > I am using the typical Makefile system (kbuild) included with the kernel, as such:<br>> > $ make V=1 CC=clang CFLAGS="-emit-llvm -c"  drivers/gpu/drm/drm_drv.o<br>> ><br>> > I have tried setting KBUILD_CFLAGS or KCFLAGS instead of CFLAGS, but nothing I do gets it to work. Trying these few different variations gets me to the point where it doesn't actually use the  "-emit-llvm" flag in the clang (previously gcc) commands that are shown with the verbose V=1 option.  If the "-emit-llvm" flag *does* make it into the clang command, it doesn't create the .bc file<br>> <br>> -emit-llvm doesn't change the name of the file output, it changes what is put<br>> in the output file (bitcode rather than object code).  So it is normal not to<br>> see a file called xyz.bc, it will still be called xyz.o.  If you look inside<br>> it you should see that it starts with BC (followed by nasty stuff).  You can<br>> use llvm-dis to turn this into a file containing human readable IR.  The<br>> following error output shows that indeed bitcode is being output:<br>> <br>>   and sometimes errors out like this:<br>> ><br>> > ====================<br>> > objdump: scripts/mod/.tmp_empty.o: File format not recognized<br>> >    if [ "-pg" = "-pg" ]; then if [ scripts/mod/empty.o != "scripts/mod/empty.o" ]; then /home/kevin/split_io_Linux/scripts/recordmcount  "scripts/mod/empty.o"; fi; fi;<br>> >    gcc -Wp,-MD,scripts/mod/.mk_elfconfig.d -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer     -o scripts/mod/mk_elfconfig scripts/mod/mk_elfconfig.c<br>> >    scripts/mod/mk_elfconfig < scripts/mod/empty.o > scripts/mod/elfconfig.h<br>> > Error: not ELF<br>> <br>> Yup, it's not ELF, it's bitcode!  This is going to be a problem for something<br>> like the linux kernel that does a lot of tricky stuff with generated object<br>> files.  I suggest you only try compiling your particular module as bitcode,<br>> and compiling everything else normally.  For example, compile everything using<br>> clang but without -emit-llvm, and tell make to produce verbose output.  This<br>> should show you the clang command line it uses to compile your module.  Run<br>> that command line by hand, but adding -emit-llvm.  This should produce bitcode<br>> for your module.<br>> <br>> > make[2]: *** [scripts/mod/elfconfig.h] Error 1<br>> > make[1]: *** [scripts/mod] Error 2<br>> > make: *** [scripts] Error 2<br>> > ====================<br>> ><br>> ><br>> > Essentially, I need to know how to use LLVM/clang with a linux kernel makefile to output the .bc bitcode file. I thought clang was a good drop-in replacement for gcc, but it hasn't worked out for me yet.<br>> <br>> You didn't just drop it in, you made a major change, telling it to output<br>> bitcode rather than ELF.<br>> <br>> Ciao, Duncan.<br>> <br>>   How can I change the "make" command so that it produces .bc?<br>> ><br>> > Thanks in advance,<br>> > Kevin<br>> > _______________________________________________<br>> > LLVM Developers mailing list<br>> > LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu<br>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<br>> ><br>> <br>> _______________________________________________<br>> LLVM Developers mailing list<br>> LLVMdev@cs.uiuc.edu         http://llvm.cs.uiuc.edu<br>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev<br></div></div>                                          </div></body>
</html>