Generating LLVM IR

8 views
Skip to first unread message

Zhihao Lin

unread,
Jul 6, 2022, 6:57:57 AM7/6/22
to clang-bu...@googlegroups.com
Hello, I'm trying to build the kernel using LLVM and generate LLVM IR. In the makefile, I saw there is a target "dir/file.ll" provided. However, I want to add more attributes to the IR file generated, such as adding debug information. Is there any way to generate personalized IR by either modifying the Makefile or changing Makefile variables? 

Thank you for your patience in advance!

Zhihao Lin


Nathan Chancellor

unread,
Jul 6, 2022, 11:18:11 AM7/6/22
to Zhihao Lin, clang-bu...@googlegroups.com, ll...@lists.linux.dev
Hi Zhihao,

On Wed, Jul 06, 2022 at 10:57:53AM +0000, Zhihao Lin wrote:
> Hello, I'm trying to build the kernel using LLVM and generate LLVM IR.
> In the makefile, I saw there is a target "dir/file.ll" provided.
> However, I want to add more attributes to the IR file generated, such
> as adding debug information. Is there any way to generate personalized
> IR by either modifying the Makefile or changing Makefile variables?

You can add additional flags to the "dir/file.ll" compiler invocation
with the KCFLAGS make variable:

$ make KCFLAGS="-ffoo -Wfoo" dir/file.ll

Additionally, there are kernel configurations, such as CONFIG_DEBUG_INFO
or CONFIG_DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT (depending on the kernel
version you are working against), which will add the compiler arguments
to generate debug info.

If you have any further questions, feel free to let us know! I have
added our new mailing list (ll...@lists.linux.dev) to the thread so it
can be archived at https://lore.kernel.org/llvm for future travellers,
please use that list if you start any new threads in the future :)

Cheers,
Nathan
Reply all
Reply to author
Forward
0 new messages