yonghong-song created this revision. yonghong-song added reviewers: vsk, HsiangKai, ABataev. yonghong-song added a project: debug-info. Herald added subscribers: cfe-commits, JDevlieghere, aprantl.
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 <y...@fb.com> Repository: rC Clang https://reviews.llvm.org/D53329 Files: lib/CodeGen/CGDebugInfo.cpp Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -411,6 +411,10 @@ // If the location is not valid then use main input file. return getOrCreateMainFile(); + if (!getSource(SM, SM.getFileID(Loc))) + // If the source file is not valid then use main input file + return getOrCreateMainFile(); + // Cache the results. const char *fname = PLoc.getFilename(); auto It = DIFileCache.find(fname);
Index: lib/CodeGen/CGDebugInfo.cpp =================================================================== --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -411,6 +411,10 @@ // If the location is not valid then use main input file. return getOrCreateMainFile(); + if (!getSource(SM, SM.getFileID(Loc))) + // If the source file is not valid then use main input file + return getOrCreateMainFile(); + // Cache the results. const char *fname = PLoc.getFilename(); auto It = DIFileCache.find(fname);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits