[llvm] r257784 - dsymutil: Provide better warnings when clang modules cannot be found.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 14 10:31:08 PST 2016


Author: adrian
Date: Thu Jan 14 12:31:07 2016
New Revision: 257784

URL: http://llvm.org/viewvc/llvm-project?rev=257784&view=rev
Log:
dsymutil: Provide better warnings when clang modules cannot be found.

rdar://problem/22823264

Added:
    llvm/trunk/test/tools/dsymutil/Inputs/modules/libstatic.a
Modified:
    llvm/trunk/test/tools/dsymutil/X86/modules-warnings.test
    llvm/trunk/tools/dsymutil/DebugMap.h
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp

Added: llvm/trunk/test/tools/dsymutil/Inputs/modules/libstatic.a
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/modules/libstatic.a?rev=257784&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/modules/libstatic.a (added) and llvm/trunk/test/tools/dsymutil/Inputs/modules/libstatic.a Thu Jan 14 12:31:07 2016 differ

Modified: llvm/trunk/test/tools/dsymutil/X86/modules-warnings.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/modules-warnings.test?rev=257784&r1=257783&r2=257784&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/modules-warnings.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/modules-warnings.test Thu Jan 14 12:31:07 2016
@@ -1,13 +1,26 @@
-Test for module-related warnings.
-This reuses the files from the modules.m testcase.
+# Test for module-related warnings.
+# This reuses the inputs from the modules.m testcase.
+#
+# RUN: rm -rf %t.dir && mkdir %t.dir
+# RUN: cp %p/../Inputs/modules/1.o %p/../Inputs/modules/Foo.pcm %t.dir
+#
+# RUN: llvm-dsymutil -f -oso-prepend-path=%t.dir -y \
+# RUN:   %p/dummy-debug-map.map -o %t 2>&1 | FileCheck %s
+#
+# Module-not-found should be reported only once.
+# The exact error message depends on the OS so we don't check for it.
+# CHECK:     warning: {{.*}}Bar.pcm:
+# CHECK-NOT: warning: {{.*}}Bar.pcm:
+#
+# RUN: cp %p/../Inputs/modules/libstatic.a %t.dir
+# RUN: llvm-dsymutil -f -oso-prepend-path=%t.dir -y %s -o %t 2>&1 | FileCheck %s
+# CHECK: rebuild the module cache
+# CHECK-NOT: static libraries
 
-RUN: rm -rf %t.dir && mkdir %t.dir
-RUN: cp %p/../Inputs/modules/1.o %p/../Inputs/modules/Foo.pcm %t.dir
-
-RUN: llvm-dsymutil -f -oso-prepend-path=%t.dir -y \
-RUN:   %p/dummy-debug-map.map -o %t 2>&1 | FileCheck %s
-
-Module-not-found should be reported only once.
-The exact error message deoends on the OS so we don't check for it.
-CHECK:     warning: {{.*}}Bar.pcm:
-CHECK-NOT: warning: {{.*}}Bar.pcm:
+---
+triple:          'x86_64-apple-darwin'
+objects:
+  - filename: libstatic.a(1.o)
+    symbols:
+      - { sym: __Z3foov, objAddr: 0x0, binAddr: 0x10000, size: 0x10 }
+...

Modified: llvm/trunk/tools/dsymutil/DebugMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DebugMap.h?rev=257784&r1=257783&r2=257784&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DebugMap.h (original)
+++ llvm/trunk/tools/dsymutil/DebugMap.h Thu Jan 14 12:31:07 2016
@@ -1,4 +1,4 @@
-//===- tools/dsymutil/DebugMap.h - Generic debug map representation -------===//
+//=== tools/dsymutil/DebugMap.h - Generic debug map representation -*- C++ -*-//
 //
 //                             The LLVM Linker
 //

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=257784&r1=257783&r2=257784&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Thu Jan 14 12:31:07 2016
@@ -1458,6 +1458,9 @@ private:
 
   /// Mapping the PCM filename to the DwoId.
   StringMap<uint64_t> ClangModules;
+
+  bool ModuleCacheHintDisplayed = false;
+  bool ArchiveHintDisplayed = false;
 };
 
 /// Similar to DWARFUnitSection::getUnitForOffset(), but returning our
@@ -3237,8 +3240,38 @@ void DwarfLinker::loadClangModule(String
   auto &Obj =
       ModuleMap.addDebugMapObject(Path, sys::TimeValue::PosixZeroTime());
   auto ErrOrObj = loadObject(ObjHolder, Obj, ModuleMap);
-  if (!ErrOrObj)
+  if (!ErrOrObj) {
+    // Try and emit more helpful warnings by applying some heuristics.
+    StringRef ObjFile = CurrentDebugObject->getObjectFilename();
+    bool isClangModule = sys::path::extension(Filename).equals(".pcm");
+    bool isArchive = ObjFile.endswith(")");
+    if (isClangModule) {
+      sys::path::remove_filename(Path);
+      StringRef ModuleCacheDir = sys::path::parent_path(Path);
+      if (sys::fs::exists(ModuleCacheDir)) {
+        // If the module's parent directory exists, we assume that the module
+        // cache has expired and was pruned by clang.  A more adventurous
+        // dsymutil would invoke clang to rebuild the module now.
+        if (!ModuleCacheHintDisplayed) {
+          errs() << "note: The clang module cache may have expired since this "
+                    "object file was built. Rebuilding the object file will "
+                    "rebuild the module cache.\n";
+          ModuleCacheHintDisplayed = true;
+        }
+      } else if (isArchive) {
+        // If the module cache directory doesn't exist at all and the object
+        // file is inside a static library, we assume that the static library
+        // was built on a different machine. We don't want to discourage module
+        // debugging for convenience libraries within a project though.
+        if (!ArchiveHintDisplayed) {
+          errs() << "note: Module debugging should be disabled when shipping "
+                    "static libraries.\n";
+          ArchiveHintDisplayed = true;
+        }
+      }
+    }
     return;
+  }
 
   std::unique_ptr<CompileUnit> Unit;
 




More information about the llvm-commits mailing list