[PATCH] D156443: [BPF] Narrow some interfaces

Tamir Duberstein via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 27 08:56:19 PDT 2023


tamird created this revision.
tamird added reviewers: ast, yonghong-song, eddyz87.
Herald added subscribers: JDevlieghere, hiraditya.
Herald added a project: All.
tamird requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When compiling Rust code we sometimes see incomplete debug info leading
to crashes. Narrow the interfaces so we can see where it happens.

[BPF] Emit better error on missing line info

When compiling Rust code we may end up with calls to functions provided
by other code units. Presently this code crashes on a null pointer
dereference - this patch changes that to an explicit crash with an
informative message.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156443

Files:
  llvm/lib/Target/BPF/BTFDebug.cpp
  llvm/lib/Target/BPF/BTFDebug.h


Index: llvm/lib/Target/BPF/BTFDebug.h
===================================================================
--- llvm/lib/Target/BPF/BTFDebug.h
+++ llvm/lib/Target/BPF/BTFDebug.h
@@ -341,12 +341,12 @@
   /// Check whether the type is a forward declaration candidate or not.
   bool IsForwardDeclCandidate(const DIType *Base);
 
-  /// Get the file content for the subprogram. Certain lines of the file
+  /// Get the file content. Certain lines of the file
   /// later may be put into string table and referenced by line info.
-  std::string populateFileContent(const DISubprogram *SP);
+  std::string populateFileContent(const DIFile *File);
 
   /// Construct a line info.
-  void constructLineInfo(const DISubprogram *SP, MCSymbol *Label, uint32_t Line,
+  void constructLineInfo(const DIFile *File, MCSymbol *Label, uint32_t Line,
                          uint32_t Column);
 
   /// Generate types and variables for globals.
Index: llvm/lib/Target/BPF/BTFDebug.cpp
===================================================================
--- llvm/lib/Target/BPF/BTFDebug.cpp
+++ llvm/lib/Target/BPF/BTFDebug.cpp
@@ -973,8 +973,7 @@
 }
 
 /// Read file contents from the actual file or from the source
-std::string BTFDebug::populateFileContent(const DISubprogram *SP) {
-  auto File = SP->getFile();
+std::string BTFDebug::populateFileContent(const DIFile *File) {
   std::string FileName;
 
   if (!File->getFilename().startswith("/") && File->getDirectory().size())
@@ -1005,9 +1004,9 @@
   return FileName;
 }
 
-void BTFDebug::constructLineInfo(const DISubprogram *SP, MCSymbol *Label,
+void BTFDebug::constructLineInfo(const DIFile *File, MCSymbol *Label,
                                  uint32_t Line, uint32_t Column) {
-  std::string FileName = populateFileContent(SP);
+  std::string FileName = populateFileContent(File);
   BTFLineInfo LineInfo;
 
   LineInfo.Label = Label;
@@ -1373,9 +1372,18 @@
     // This instruction will be skipped, no LineInfo has
     // been generated, construct one based on function signature.
     if (LineInfoGenerated == false) {
-      auto *S = MI->getMF()->getFunction().getSubprogram();
+      const Function &F = MI->getMF()->getFunction();
+      auto *S = F.getSubprogram();
+      if (!S) {
+        std::string Str;
+        {
+          raw_string_ostream OS(Str);
+          OS << "call to subprogram '" << F.getName() << "' without line info";
+        }
+        report_fatal_error(Str.c_str());
+      }
       MCSymbol *FuncLabel = Asm->getFunctionBegin();
-      constructLineInfo(S, FuncLabel, S->getLine(), 0);
+      constructLineInfo(S->getFile(), FuncLabel, S->getLine(), 0);
       LineInfoGenerated = true;
     }
 
@@ -1387,8 +1395,7 @@
   OS.emitLabel(LineSym);
 
   // Construct the lineinfo.
-  auto SP = DL->getScope()->getSubprogram();
-  constructLineInfo(SP, LineSym, DL.getLine(), DL.getCol());
+  constructLineInfo(DL->getFile(), LineSym, DL.getLine(), DL.getCol());
 
   LineInfoGenerated = true;
   PrevInstLoc = DL;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156443.544799.patch
Type: text/x-patch
Size: 2994 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230727/aa841455/attachment.bin>


More information about the llvm-commits mailing list