[PATCH] D53329: Generate DIFile with main program if source is not available

Yonghong Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 16 09:56:52 PDT 2018


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 <yhs at 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53329.169843.patch
Type: text/x-patch
Size: 538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181016/5a0396c7/attachment.bin>


More information about the cfe-commits mailing list