From e1bc3e2027b7e9f9bcf3d0a658d940eac73eda66 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 13 May 2016 00:17:58 +0000 Subject: [PATCH] dsymutil: Fix the DWOId mismatch check for cached modules. In verbose mode, we emit a warning if the DWOId of a skeleton CU mismatches the DWOId of the referenced module. This patch updates the cached DWOId after a module has been loaded to the DWOId of the module on disk (instead of storing the DWOId we expected to load). This allows us to correctly emit the mismatch warning for all subsequent object files that want to import the same module. This patch also ensures both warnings are only emitted in verbose mode. rdar://problem/26214027 llvm-svn: 269383 --- llvm/test/tools/dsymutil/X86/mismatch.m | 9 ++++++++- llvm/tools/dsymutil/DwarfLinker.cpp | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/llvm/test/tools/dsymutil/X86/mismatch.m b/llvm/test/tools/dsymutil/X86/mismatch.m index 821097a31bae..0bebe70c12d2 100644 --- a/llvm/test/tools/dsymutil/X86/mismatch.m +++ b/llvm/test/tools/dsymutil/X86/mismatch.m @@ -14,10 +14,17 @@ -fdisable-module-hash mismatch.m -o /dev/null */ -// RUN: llvm-dsymutil --verbose -f -oso-prepend-path=%p/../Inputs/mismatch \ +// RUN: rm -rf %t.dir && mkdir %t.dir +// RUN: cp %p/../Inputs/mismatch/1.o %p/../Inputs/mismatch/mismatch.pcm %t.dir +// RUN: cp %p/../Inputs/mismatch/1.o %t.dir/2.o +// RUN: llvm-dsymutil --verbose -f -oso-prepend-path=%t.dir \ // RUN: -y %p/dummy-debug-map.map -o %t.bin 2>&1 | FileCheck %s @import mismatch; void f() {} +// Mismatch after importing the module. // CHECK: warning: hash mismatch +// Mismatch in the cache. +// CHECK: warning: hash mismatch +// CHECK: cached diff --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp index b93cac37c337..f4868f35fca4 100644 --- a/llvm/tools/dsymutil/DwarfLinker.cpp +++ b/llvm/tools/dsymutil/DwarfLinker.cpp @@ -3249,7 +3249,10 @@ bool DwarfLinker::registerModuleReference( auto Cached = ClangModules.find(PCMfile); if (Cached != ClangModules.end()) { - if (Cached->second != DwoId) + // FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is + // fixed in clang, only warn about DWO_id mismatches in verbose mode. + // ASTFileSignatures will change randomly when a module is rebuilt. + if (Options.Verbose && (Cached->second != DwoId)) reportWarning(Twine("hash mismatch: this object file was built against a " "different version of the module ") + PCMfile); if (Options.Verbose) @@ -3343,10 +3346,15 @@ void DwarfLinker::loadClangModule(StringRef Filename, StringRef ModulePath, // FIXME: Until PR27449 (https://llvm.org/bugs/show_bug.cgi?id=27449) is // fixed in clang, only warn about DWO_id mismatches in verbose mode. // ASTFileSignatures will change randomly when a module is rebuilt. - if (Options.Verbose && (getDwoId(*CUDie, *CU) != DwoId)) - reportWarning( - Twine("hash mismatch: this object file was built against a " - "different version of the module ") + Filename); + uint64_t PCMDwoId = getDwoId(*CUDie, *CU); + if (PCMDwoId != DwoId) { + if (Options.Verbose) + reportWarning( + Twine("hash mismatch: this object file was built against a " + "different version of the module ") + Filename); + // Update the cache entry with the DwoId of the module loaded from disk. + ClangModules[Filename] = PCMDwoId; + } // Add this module. Unit = llvm::make_unique(*CU, UnitID++, !Options.NoODR,