0

I want to get the LLVM IR of the zephyr os (https://github.com/zephyrproject-rtos/zephyr) for static analysis. For this I need to get the IR for each file basically. But as pointed out each file cannot be compiled directly as zephyr requires a board architecture and and app for a Kconfig and then using python scripts produces some header files which are not present from beforehand. So can you pls suggest what I can do ? Is there some way that I can get all the files required for the compilation of each file seperately even if they dont compile all together.

I have been trying to do this but I am unable to do so. Can you pls suggest. Thanks.

kratos
  • 11
  • 1
  • You seem to be asking how to modify their cmake files how to emit .bc or .ll files instead of .o files during one stage of compilation. Is that right? If so, you might start by learning the cmake language and looking at how it's used by zephyr. – arnt Nov 19 '21 at 21:56
  • So for zephyr the whole kernel cannot be compiled together as far as I know. If it is possible I can try to make changes in their cmake file. – kratos Nov 20 '21 at 02:55
  • You seem to think that generating IR requires that everything be compiled together, in a sense of "together" which is not true for compiling to runnable code. Do I understand you correctly? – arnt Nov 21 '21 at 13:43
  • hmm sort of. Yes. But I get it now that not everything needs to be compiled together. What I do not understand is do I need to do any kind of linking to the libraries. If I use : `clang -emit-llvm -S foo.c clang -emit-llvm -S bar.c llvm-link foo.ll bar.ll -o linked.ll` Is that it ? – kratos Nov 22 '21 at 05:04
  • You don't need the libraries for generating IR, you may need them for static analysis. Generating IR needs only the header files. As a brief overview: First the compiler handles #defines and #includes, then it generates IR in memory, then it runs some passes on the IR, then some more, then some more, and the last of the passes produce native object code. The compiler then invokes the linker with the paths to all of the object code files and all of the libraries, and you get a runnable file. "Generating IR" just means to write somethiing to a file earlyish or middleish in that process. – arnt Nov 22 '21 at 07:27

0 Answers0