From: Adrian Prantl Date: Wed, 23 Sep 2015 17:11:10 +0000 (+0000) Subject: dsymutil: print a warning when there is a module hash mismatch. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=f4ad7592cd358241a59690321ee4aaf468c35cb4;p=oota-llvm.git 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248396 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/dsymutil/Inputs/mismatch/1.o b/test/tools/dsymutil/Inputs/mismatch/1.o new file mode 100644 index 00000000000..45d176c96be Binary files /dev/null and b/test/tools/dsymutil/Inputs/mismatch/1.o differ diff --git a/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm b/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm new file mode 100644 index 00000000000..94f3cf5fffb Binary files /dev/null and b/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm differ diff --git a/test/tools/dsymutil/Inputs/modules/1.o b/test/tools/dsymutil/Inputs/modules/1.o index 6e0775f5755..254ae692a8e 100644 Binary files a/test/tools/dsymutil/Inputs/modules/1.o and b/test/tools/dsymutil/Inputs/modules/1.o differ diff --git a/test/tools/dsymutil/Inputs/modules/Bar.pcm b/test/tools/dsymutil/Inputs/modules/Bar.pcm index 8b628e3cf01..8d3a534667c 100644 Binary files a/test/tools/dsymutil/Inputs/modules/Bar.pcm and b/test/tools/dsymutil/Inputs/modules/Bar.pcm differ diff --git a/test/tools/dsymutil/Inputs/modules/Foo.pcm b/test/tools/dsymutil/Inputs/modules/Foo.pcm index 2416a405443..33bca2a6547 100644 Binary files a/test/tools/dsymutil/Inputs/modules/Foo.pcm and b/test/tools/dsymutil/Inputs/modules/Foo.pcm differ diff --git a/test/tools/dsymutil/X86/mismatch.m b/test/tools/dsymutil/X86/mismatch.m new file mode 100644 index 00000000000..cd40cba4919 --- /dev/null +++ b/test/tools/dsymutil/X86/mismatch.m @@ -0,0 +1,23 @@ +/* Compile with: + cat >modules.modulemap < 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 + +@import mismatch; + +void f() {} +// CHECK: warning: hash mismatch diff --git a/test/tools/dsymutil/X86/modules.m b/test/tools/dsymutil/X86/modules.m index 6a93f28587a..c17e1632b95 100644 --- a/test/tools/dsymutil/X86/modules.m +++ b/test/tools/dsymutil/X86/modules.m @@ -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 diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index fb7ffceec8f..6bd4f2c42a5 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -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 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::registerModuleReference( // 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 &BinaryHolder, DebugMapObject &Obj, } 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(StringRef Filename, StringRef ModulePath, 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 Unit; // Setup access to the debug info. @@ -3166,12 +3182,17 @@ void DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath, 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(*CU, UnitID++, !Options.NoODR); Unit->setHasInterestingContent(); gatherDIEParents(CUDie, 0, *Unit, &ODRContexts.getRoot(), StringPool,