summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
Diffstat (limited to 'llvm')
-rw-r--r--llvm/test/tools/dsymutil/Inputs/mismatch/1.obin0 -> 1980 bytes
-rw-r--r--llvm/test/tools/dsymutil/Inputs/mismatch/mismatch.pcmbin0 -> 24940 bytes
-rw-r--r--llvm/test/tools/dsymutil/Inputs/modules/1.obin2392 -> 2392 bytes
-rw-r--r--llvm/test/tools/dsymutil/Inputs/modules/Bar.pcmbin25520 -> 25532 bytes
-rw-r--r--llvm/test/tools/dsymutil/Inputs/modules/Foo.pcmbin25448 -> 25464 bytes
-rw-r--r--llvm/test/tools/dsymutil/X86/mismatch.m23
-rw-r--r--llvm/test/tools/dsymutil/X86/modules.m7
-rw-r--r--llvm/tools/dsymutil/DwarfLinker.cpp47
8 files changed, 63 insertions, 14 deletions
diff --git a/llvm/test/tools/dsymutil/Inputs/mismatch/1.o b/llvm/test/tools/dsymutil/Inputs/mismatch/1.o
new file mode 100644
index 00000000000..45d176c96be
--- /dev/null
+++ b/llvm/test/tools/dsymutil/Inputs/mismatch/1.o
Binary files differ
diff --git a/llvm/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm b/llvm/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm
new file mode 100644
index 00000000000..94f3cf5fffb
--- /dev/null
+++ b/llvm/test/tools/dsymutil/Inputs/mismatch/mismatch.pcm
Binary files differ
diff --git a/llvm/test/tools/dsymutil/Inputs/modules/1.o b/llvm/test/tools/dsymutil/Inputs/modules/1.o
index 6e0775f5755..254ae692a8e 100644
--- a/llvm/test/tools/dsymutil/Inputs/modules/1.o
+++ b/llvm/test/tools/dsymutil/Inputs/modules/1.o
Binary files differ
diff --git a/llvm/test/tools/dsymutil/Inputs/modules/Bar.pcm b/llvm/test/tools/dsymutil/Inputs/modules/Bar.pcm
index 8b628e3cf01..8d3a534667c 100644
--- a/llvm/test/tools/dsymutil/Inputs/modules/Bar.pcm
+++ b/llvm/test/tools/dsymutil/Inputs/modules/Bar.pcm
Binary files differ
diff --git a/llvm/test/tools/dsymutil/Inputs/modules/Foo.pcm b/llvm/test/tools/dsymutil/Inputs/modules/Foo.pcm
index 2416a405443..33bca2a6547 100644
--- a/llvm/test/tools/dsymutil/Inputs/modules/Foo.pcm
+++ b/llvm/test/tools/dsymutil/Inputs/modules/Foo.pcm
Binary files differ
diff --git a/llvm/test/tools/dsymutil/X86/mismatch.m b/llvm/test/tools/dsymutil/X86/mismatch.m
new file mode 100644
index 00000000000..cd40cba4919
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/mismatch.m
@@ -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
+
+@import mismatch;
+
+void f() {}
+// CHECK: warning: hash mismatch
diff --git a/llvm/test/tools/dsymutil/X86/modules.m b/llvm/test/tools/dsymutil/X86/modules.m
index 6a93f28587a..c17e1632b95 100644
--- a/llvm/test/tools/dsymutil/X86/modules.m
+++ b/llvm/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/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp
index fb7ffceec8f..6bd4f2c42a5 100644
--- a/llvm/tools/dsymutil/DwarfLinker.cpp
+++ b/llvm/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<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::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<CompileUnit> 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<CompileUnit>(*CU, UnitID++, !Options.NoODR);
Unit->setHasInterestingContent();
gatherDIEParents(CUDie, 0, *Unit, &ODRContexts.getRoot(), StringPool,
OpenPOWER on IntegriCloud