A llvm segfault happens when I tried to add "-g -gdwarf-5 -gembed-source"
in bcc in order to get soruce code into IR and dwarf.
A little bit background, bcc (https://github.com/iovisor/bcc)
utilizes llvm MCJIT to generate BPF insns and load them
to the kernel for execution. Several files passed to clang
are memory mapped including the main program /virtual/main.c.
I did some analysis on why segfault happens and whether we did
get all file sources. And I found that we did not get source
for one instance:
!32 = !DIFile(filename: "/virtual/main.c", directory: "/usr/src/kernels/4.11.3-70_fbk18_4116_g1cf3f1a0ca4f")
After some debugging, I found this patch can fix the problem.
Basically, when the source is not available to generate DIFile
use the main program.
You can get more details of the bug, IR, cc1 flags, segfault
stack and how to reproduce at this commit:
https://github.com/yonghong-song/bcc/commit/7ac342e05468e60138d61e0e41691ed2f98bd929 Signed-off-by: Yonghong Song <yhs@fb.com>