[PATCH] D128184: [lld-macho] Show source information for undefined references

Daniel Bertalan via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 20 23:26:49 PDT 2022


BertalanD added a comment.

Looks like `ObjFile::parseDebugInfo` wasn't checking if there were any compilation units before assigning the iterator's value to `compileUnit`. I'm not sure why that didn't cause issues previously, it's maybe because we were taking slightly different code paths as we did not parse `__debug_line`. The following change makes lld not crash when linking the Chromium reproducer.

  diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp
  index 2db8dae75d42..724e8f64d2ab 100644
  --- a/lld/MachO/InputFiles.cpp
  +++ b/lld/MachO/InputFiles.cpp
  @@ -1015,7 +1015,10 @@ void ObjFile::parseDebugInfo() {
     // FIXME: There can be more than one compile unit per object file. See
     // PR48637.
     auto it = units.begin();
  -  compileUnit = it->get();
  +  if (it == units.end())
  +    compileUnit = nullptr;
  +  else
  +    compileUnit = it->get();
   }
   
   ArrayRef<data_in_code_entry> ObjFile::getDataInCode() const {
  @@ -1376,6 +1379,8 @@ void ObjFile::registerEhFrames(Section &ehFrameSection) {
   }
   
   std::string ObjFile::sourceFile() const {
  +  if (!compileUnit)
  +    return {};
     SmallString<261> dir(compileUnit->getCompilationDir());
     StringRef sep = sys::path::get_separator();
     // We don't use `path::append` here because we want an empty `dir` to result

I'll set up a build on Linux to check if the failures there go away as well.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D128184/new/

https://reviews.llvm.org/D128184



More information about the llvm-commits mailing list