[llvm] r248396 - dsymutil: print a warning when there is a module hash mismatch.

Adrian Prantl via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 10:11:10 PDT 2015


Author: adrian
Date: Wed Sep 23 12:11:10 2015
New Revision: 248396

URL: http://llvm.org/viewvc/llvm-project?rev=248396&view=rev
Log:
dsymutil: print a warning when there is a module hash mismatch.

This also updates the module binaries in the test directory because
their module hash mismatched.

Added:
    llvm/trunk/test/tools/dsymutil/Inputs/mismatch/
    llvm/trunk/test/tools/dsymutil/Inputs/mismatch/1.o
    llvm/trunk/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm
      - copied, changed from r248395, llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm
    llvm/trunk/test/tools/dsymutil/X86/mismatch.m
Modified:
    llvm/trunk/test/tools/dsymutil/Inputs/modules/1.o
    llvm/trunk/test/tools/dsymutil/Inputs/modules/Bar.pcm
    llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm
    llvm/trunk/test/tools/dsymutil/X86/modules.m
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp

Added: llvm/trunk/test/tools/dsymutil/Inputs/mismatch/1.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/mismatch/1.o?rev=248396&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/mismatch/1.o (added) and llvm/trunk/test/tools/dsymutil/Inputs/mismatch/1.o Wed Sep 23 12:11:10 2015 differ

Copied: llvm/trunk/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm (from r248395, llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm?p2=llvm/trunk/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm&p1=llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm&r1=248395&r2=248396&rev=248396&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm (original) and llvm/trunk/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm Wed Sep 23 12:11:10 2015 differ

Modified: llvm/trunk/test/tools/dsymutil/Inputs/modules/1.o
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/modules/1.o?rev=248396&r1=248395&r2=248396&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/modules/1.o (original) and llvm/trunk/test/tools/dsymutil/Inputs/modules/1.o Wed Sep 23 12:11:10 2015 differ

Modified: llvm/trunk/test/tools/dsymutil/Inputs/modules/Bar.pcm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/modules/Bar.pcm?rev=248396&r1=248395&r2=248396&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/modules/Bar.pcm (original) and llvm/trunk/test/tools/dsymutil/Inputs/modules/Bar.pcm Wed Sep 23 12:11:10 2015 differ

Modified: llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm?rev=248396&r1=248395&r2=248396&view=diff
==============================================================================
Binary files llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm (original) and llvm/trunk/test/tools/dsymutil/Inputs/modules/Foo.pcm Wed Sep 23 12:11:10 2015 differ

Added: llvm/trunk/test/tools/dsymutil/X86/mismatch.m
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/mismatch.m?rev=248396&view=auto
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/mismatch.m (added)
+++ llvm/trunk/test/tools/dsymutil/X86/mismatch.m Wed Sep 23 12:11:10 2015
@@ -0,0 +1,23 @@
+/* Compile with:
+   cat >modules.modulemap <<EOF
+     module mismatch {
+       header "mismatch.h"
+     }
+   EOF
+   echo "struct s;"> mismatch.h
+   clang -cc1 -emit-obj -fmodules -fmodule-map-file=modules.modulemap \
+      -fmodule-format=obj -g -dwarf-ext-refs -fmodules-cache-path=. \
+      -fdisable-module-hash mismatch.m -o 1.o
+   echo > mismatch.h
+   clang -cc1 -emit-obj -fmodules -fmodule-map-file=modules.modulemap \
+      -fmodule-format=obj -g -dwarf-ext-refs -fmodules-cache-path=. \
+      -fdisable-module-hash mismatch.m -o /dev/null
+*/
+
+// RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/mismatch \
+// RUN:   -y %p/dummy-debug-map.map -o - 2>&1 | FileCheck %s
+
+ at import mismatch;
+
+void f() {}
+// CHECK: warning: hash mismatch

Modified: llvm/trunk/test/tools/dsymutil/X86/modules.m
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/modules.m?rev=248396&r1=248395&r2=248396&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/modules.m (original)
+++ llvm/trunk/test/tools/dsymutil/X86/modules.m Wed Sep 23 12:11:10 2015
@@ -20,6 +20,11 @@
 // RUN:   -y %p/dummy-debug-map.map -o - \
 // RUN:     | llvm-dwarfdump --debug-dump=info - | FileCheck %s
 
+// RUN: llvm-dsymutil -f -oso-prepend-path=%p/../Inputs/modules -y \
+// RUN:   %p/dummy-debug-map.map -o %t 2>&1 | FileCheck --check-prefix=WARN %s
+
+// WARN-NOT: warning: hash mismatch
+
 // ---------------------------------------------------------------------
 #ifdef BAR_H
 // ---------------------------------------------------------------------
@@ -37,7 +42,7 @@ struct Bar {
 // ---------------------------------------------------------------------
 #ifdef FOO_H
 // ---------------------------------------------------------------------
-// CHECK: 55{{.*}}DW_TAG_compile_unit
+// CHECK: DW_TAG_compile_unit
 // CHECK:   DW_TAG_module
 // CHECK-NEXT: DW_AT_name {{.*}}"Foo"
 // CHECK:      DW_TAG_typedef

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=248396&r1=248395&r2=248396&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Wed Sep 23 12:11:10 2015
@@ -13,7 +13,7 @@
 #include "MachOUtils.h"
 #include "NonRelocatableStringpool.h"
 #include "llvm/ADT/IntervalMap.h"
-#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/DIE.h"
@@ -1205,7 +1205,7 @@ private:
   /// Recursively add the debug info in this clang module .pcm
   /// file (and all the modules imported by it in a bottom-up fashion)
   /// to Units.
-  void loadClangModule(StringRef Filename, StringRef ModulePath,
+  void loadClangModule(StringRef Filename, StringRef ModulePath, uint64_t DwoId,
                        DebugMap &ModuleMap, unsigned Indent = 0);
 
   /// \brief Flags passed to DwarfLinker::lookForDIEsToKeep
@@ -1448,8 +1448,8 @@ private:
   /// debug_frame section.
   uint32_t LastCIEOffset;
 
-  /// FIXME: We may need to use something more resilient than the PCM filename.
-  StringSet<> ClangModules;
+  /// Mapping the PCM filename to the DwoId.
+  StringMap<uint64_t> ClangModules;
 };
 
 /// Similar to DWARFUnitSection::getUnitForOffset(), but returning our
@@ -3091,24 +3091,42 @@ void DwarfLinker::DIECloner::copyAbbrev(
   Linker.AssignAbbrev(Copy);
 }
 
+static uint64_t getDwoId(const DWARFDebugInfoEntryMinimal &CUDie,
+                         const DWARFUnit &Unit) {
+  uint64_t DwoId =
+      CUDie.getAttributeValueAsUnsignedConstant(&Unit, dwarf::DW_AT_dwo_id, 0);
+  if (!DwoId)
+    DwoId = CUDie.getAttributeValueAsUnsignedConstant(&Unit,
+                                                      dwarf::DW_AT_GNU_dwo_id, 0);
+  return DwoId;
+}
+
 bool DwarfLinker::registerModuleReference(
     const DWARFDebugInfoEntryMinimal &CUDie, const DWARFUnit &Unit,
     DebugMap &ModuleMap, unsigned Indent) {
   std::string PCMfile =
-      CUDie.getAttributeValueAsString(&Unit, dwarf::DW_AT_GNU_dwo_name, "");
+      CUDie.getAttributeValueAsString(&Unit, dwarf::DW_AT_dwo_name, "");
+  if (PCMfile.empty())
+    PCMfile =
+        CUDie.getAttributeValueAsString(&Unit, dwarf::DW_AT_GNU_dwo_name, "");
   if (PCMfile.empty())
     return false;
 
   // Clang module DWARF skeleton CUs abuse this for the path to the module.
   std::string PCMpath =
       CUDie.getAttributeValueAsString(&Unit, dwarf::DW_AT_comp_dir, "");
+  uint64_t DwoId = getDwoId(CUDie, Unit);
 
   if (Options.Verbose) {
     outs().indent(Indent);
     outs() << "Found clang module reference " << PCMfile;
   }
 
-  if (ClangModules.count(PCMfile)) {
+  auto Cached = ClangModules.find(PCMfile);
+  if (Cached != ClangModules.end()) {
+    if (Cached->second != DwoId)
+      reportWarning(Twine("hash mismatch: this object file was built against a "
+                          "different version of the module ") + PCMfile);
     if (Options.Verbose)
       outs() << " [cached].\n";
     return true;
@@ -3118,8 +3136,8 @@ bool DwarfLinker::registerModuleReferenc
 
   // Cyclic dependencies are disallowed by Clang, but we still
   // shouldn't run into an infinite loop, so mark it as processed now.
-  ClangModules.insert(PCMfile);
-  loadClangModule(PCMfile, PCMpath, ModuleMap, Indent + 2);
+  ClangModules.insert({PCMfile, DwoId});
+  loadClangModule(PCMfile, PCMpath, DwoId, ModuleMap, Indent + 2);
   return true;
 }
 
@@ -3139,7 +3157,8 @@ DwarfLinker::loadObject(BinaryHolder &Bi
 }
 
 void DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath,
-                                  DebugMap &ModuleMap, unsigned Indent) {
+                                  uint64_t DwoId, DebugMap &ModuleMap,
+                                  unsigned Indent) {
   SmallString<80> Path(Options.PrependPath);
   if (sys::path::is_relative(Filename))
     sys::path::append(Path, ModulePath, Filename);
@@ -3154,9 +3173,6 @@ void DwarfLinker::loadClangModule(String
     return;
   }
 
-  // FIXME: At this point dsymutil should verify the DW_AT_gnu_dwo_id
-  // against the module hash of the clang module.
-
   std::unique_ptr<CompileUnit> Unit;
 
   // Setup access to the debug info.
@@ -3166,12 +3182,17 @@ void DwarfLinker::loadClangModule(String
     auto *CUDie = CU->getUnitDIE(false);
     // Recursively get all modules imported by this one.
     if (!registerModuleReference(*CUDie, *CU, ModuleMap, Indent)) {
-      // Add this module.
       if (Unit) {
         errs() << Filename << ": Clang modules are expected to have exactly"
                << " 1 compile unit.\n";
         exitDsymutil(1);
       }
+      if (getDwoId(*CUDie, *CU) != DwoId)
+        reportWarning(
+            Twine("hash mismatch: this object file was built against a "
+                  "different version of the module ") + Filename);
+
+      // Add this module.
       Unit = llvm::make_unique<CompileUnit>(*CU, UnitID++, !Options.NoODR);
       Unit->setHasInterestingContent();
       gatherDIEParents(CUDie, 0, *Unit, &ODRContexts.getRoot(), StringPool,




More information about the llvm-commits mailing list