Clang Linux Driver Compilation

I tried the following command for regular C source files:

clang-3.5 -S -emit-llvm hello.c -o - | opt -analyze -dot-callgraph

and it worked.

Now, I’m trying to do the same with linux device driver usbmouse.c (linux-4.1.1/drivers/hid/usbhid/). I tried the following make command:

make CC=clang-3.5 SUBDIRS=drivers/hid/usbhid/ CONFIG_USB_MOUSE=m modules

It gave several warnings, but nevertheless, looked like it compiled.

Could anybody please guide me on how I can modify the Makefile so as to generate callgraphs?

Thanks

Regards

I’m pretty certain the Linux makefile is not able to do that. What you will need to do compile all files to llvm-IR output, concatenating it together and then run opt -analyze … on that.

The way I can see that working is to use V=1 to give more verbose output, then filter out the clang commands - once you have that in a file, do a “search and replace” for -c to -S -emit-llvm [possibly also replace -o somefile.o with -o - and redirect all the output to a file.

I’m not sure how opt copes with multiple modules as one input - so you may need to clean up the input a bit further - or run it through llvm-link, perhaps?

I’ve never done this, so I’m just thinking about it logically and picking up pieces of knowledge like V=1 that I do have.