diff options
-rw-r--r-- | llvm/test/tools/dsymutil/Inputs/modules/libstatic.a | bin | 0 -> 2632 bytes | |||
-rw-r--r-- | llvm/test/tools/dsymutil/X86/modules-warnings.test | 37 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DebugMap.h | 2 | ||||
-rw-r--r-- | llvm/tools/dsymutil/DwarfLinker.cpp | 35 |
4 files changed, 60 insertions, 14 deletions
diff --git a/llvm/test/tools/dsymutil/Inputs/modules/libstatic.a b/llvm/test/tools/dsymutil/Inputs/modules/libstatic.a Binary files differnew file mode 100644 index 00000000000..46e79a5dd94 --- /dev/null +++ b/llvm/test/tools/dsymutil/Inputs/modules/libstatic.a diff --git a/llvm/test/tools/dsymutil/X86/modules-warnings.test b/llvm/test/tools/dsymutil/X86/modules-warnings.test index 1ad843592e5..35538d60bb1 100644 --- a/llvm/test/tools/dsymutil/X86/modules-warnings.test +++ b/llvm/test/tools/dsymutil/X86/modules-warnings.test @@ -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 } +... diff --git a/llvm/tools/dsymutil/DebugMap.h b/llvm/tools/dsymutil/DebugMap.h index 06ac5a503dc..4907b8f1a72 100644 --- a/llvm/tools/dsymutil/DebugMap.h +++ b/llvm/tools/dsymutil/DebugMap.h @@ -1,4 +1,4 @@ -//===- tools/dsymutil/DebugMap.h - Generic debug map representation -------===// +//=== tools/dsymutil/DebugMap.h - Generic debug map representation -*- C++ -*-// // // The LLVM Linker // diff --git a/llvm/tools/dsymutil/DwarfLinker.cpp b/llvm/tools/dsymutil/DwarfLinker.cpp index 32ca5c4cecf..37dd02851dc 100644 --- a/llvm/tools/dsymutil/DwarfLinker.cpp +++ b/llvm/tools/dsymutil/DwarfLinker.cpp @@ -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(StringRef Filename, StringRef ModulePath, 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; |