[llvm-branch-commits] [llvm] 48d2068 - [dsymutil] Warn on timestmap mismatch between object file and debug map

Jonas Devlieghere via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Jan 13 09:19:52 PST 2021


Author: Jonas Devlieghere
Date: 2021-01-13T09:15:30-08:00
New Revision: 48d2068fb738302b9fba91c9bf8e4b051c3909eb

URL: https://github.com/llvm/llvm-project/commit/48d2068fb738302b9fba91c9bf8e4b051c3909eb
DIFF: https://github.com/llvm/llvm-project/commit/48d2068fb738302b9fba91c9bf8e4b051c3909eb.diff

LOG: [dsymutil] Warn on timestmap mismatch between object file and debug map

This re-lands e5553b9a6ab9 with two small fixes to the tests:

 - Don't touch the source directory in debug-map-parsing.test but
   instead copy everything over in a temporary directory in
   timestamp-mismatch.test.
 - Don't redirect stderr to stdout to avoid the output getting
   intertwined in extern-alias.test.

Added: 
    llvm/test/tools/dsymutil/X86/timestamp-mismatch.test

Modified: 
    llvm/test/tools/dsymutil/ARM/extern-alias.test
    llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test
    llvm/test/tools/dsymutil/debug-map-parsing.test
    llvm/tools/dsymutil/BinaryHolder.cpp
    llvm/tools/dsymutil/BinaryHolder.h
    llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/dsymutil/ARM/extern-alias.test b/llvm/test/tools/dsymutil/ARM/extern-alias.test
index 91297ac6ef54..0f0e347ad9d6 100644
--- a/llvm/test/tools/dsymutil/ARM/extern-alias.test
+++ b/llvm/test/tools/dsymutil/ARM/extern-alias.test
@@ -35,8 +35,8 @@ $ xcrun --sdk iphoneos clang -g private_extern.c -c -o private_extern.o -target
 $ xcrun --sdk iphoneos clang -g main.c -c -o main.o -target arm64-apple-ios14.0
 $ xcrun --sdk iphoneos clang private_extern.o main.o -target arm64-apple-ios14.0 -o private_extern.out -Xlinker -alias_list -Xlinker alias_list
 
-RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/private_extern/private_extern.out -o %t.dSYM --verbose 2>&1 | FileCheck %s
-RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/extern/extern.out -o %t.dSYM --verbose 2>&1 | FileCheck %s
+RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/private_extern/private_extern.out -o %t.dSYM --verbose | FileCheck %s
+RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/extern/extern.out -o %t.dSYM --verbose | FileCheck %s
 CHECK-NOT: could not find object file symbol for symbol _baz
 CHECK: { sym: _foo, objAddr: 0x0, binAddr: 0x100007F58, size: 0x20 }
 CHECK: { sym: _baz, objAddr: 0x0, binAddr: 0x100007F58, size: 0x0 }

diff  --git a/llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test b/llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test
index 626208ff3496..43d930af7128 100644
--- a/llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test
+++ b/llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test
@@ -20,7 +20,7 @@ READOBJ-NEXT: |.|
 DWARFDUMP: __swift_ast
 
 RUN: dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -no-output -verbose 2>&1 | FileCheck %s --check-prefix=TIMESTAMP
-TIMESTAMP: warning: Timestamp mismatch
+TIMESTAMP: warning: {{.*}}/swift-ast.swiftmodule: timestamp mismatch between swift interface file ({{.*}}) and debug map ({{.*}})
 
 RUN: dsymutil -s %T/swift-ast.dSYM/Contents/Resources/DWARF/swift-ast.macho.x86_64 | FileCheck %s --check-prefix=NAST
 NAST-NOT: N_AST

diff  --git a/llvm/test/tools/dsymutil/X86/timestamp-mismatch.test b/llvm/test/tools/dsymutil/X86/timestamp-mismatch.test
new file mode 100644
index 000000000000..7d41905e7951
--- /dev/null
+++ b/llvm/test/tools/dsymutil/X86/timestamp-mismatch.test
@@ -0,0 +1,10 @@
+RUN: mkdir -p %t/Inputs
+RUN: cp %p/../Inputs/basic.macho.x86_64 %t/Inputs
+RUN: cp %p/../Inputs/basic1.macho.x86_64.o %t/Inputs
+RUN: cp %p/../Inputs/basic2.macho.x86_64.o %t/Inputs
+RUN: cp %p/../Inputs/basic3.macho.x86_64.o %t/Inputs
+RUN: dsymutil -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s
+
+CHECK: warning: {{.*}}/Inputs/basic1.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
+CHECK: warning: {{.*}}/Inputs/basic2.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
+CHECK: warning: {{.*}}/Inputs/basic3.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})

diff  --git a/llvm/test/tools/dsymutil/debug-map-parsing.test b/llvm/test/tools/dsymutil/debug-map-parsing.test
index fb4226093da1..a25e44598b30 100644
--- a/llvm/test/tools/dsymutil/debug-map-parsing.test
+++ b/llvm/test/tools/dsymutil/debug-map-parsing.test
@@ -46,7 +46,7 @@ opening the archive once if mulitple of its members are used).
 CHECK-ARCHIVE:      trying to open {{.*}}basic-archive.macho.x86_64'
 CHECK-ARCHIVE-NEXT: 	loaded object.
 CHECK-ARCHIVE-NEXT: trying to open {{.*}}/Inputs/basic1.macho.x86_64.o'
-CHECK-ARCHIVE-NEXT: 	loaded object.
+CHECK-ARCHIVE: 	loaded object.
 CHECK-ARCHIVE-NEXT: trying to open {{.*}}/libbasic.a(basic2.macho.x86_64.o)'
 CHECK-ARCHIVE-NEXT: 	loaded archive {{.*}}/libbasic.a'
 CHECK-ARCHIVE-NEXT: 	found member in archive.

diff  --git a/llvm/tools/dsymutil/BinaryHolder.cpp b/llvm/tools/dsymutil/BinaryHolder.cpp
index df3cb7161a81..b401d519718c 100644
--- a/llvm/tools/dsymutil/BinaryHolder.cpp
+++ b/llvm/tools/dsymutil/BinaryHolder.cpp
@@ -87,7 +87,8 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
 }
 
 Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
-                                      StringRef Filename, bool Verbose) {
+                                      StringRef Filename, TimestampTy Timestamp,
+                                      bool Verbose) {
   // Try to load regular binary and force it to be memory mapped.
   auto ErrOrBuff = (Filename == "-")
                        ? MemoryBuffer::getSTDIN()
@@ -95,6 +96,17 @@ Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
   if (auto Err = ErrOrBuff.getError())
     return errorCodeToError(Err);
 
+  if (Filename != "-" && Timestamp != sys::TimePoint<>()) {
+    llvm::ErrorOr<vfs::Status> Stat = VFS->status(Filename);
+    if (!Stat)
+      return errorCodeToError(Stat.getError());
+    if (Timestamp != Stat->getLastModificationTime())
+      WithColor::warning() << Filename
+                           << ": timestamp mismatch between object file ("
+                           << Stat->getLastModificationTime()
+                           << ") and debug map (" << Timestamp << ")\n";
+  }
+
   MemBuffer = std::move(*ErrOrBuff);
 
   if (Verbose)
@@ -182,7 +194,11 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
           if (Timestamp != sys::TimePoint<>() &&
               Timestamp != ModTimeOrErr.get()) {
             if (Verbose)
-              WithColor::warning() << "member has timestamp mismatch.\n";
+              WithColor::warning()
+                  << *NameOrErr
+                  << ": timestamp mismatch between archive member ("
+                  << ModTimeOrErr.get() << ") and debug map (" << Timestamp
+                  << ")\n";
             continue;
           }
 
@@ -246,7 +262,7 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
   std::lock_guard<std::mutex> Lock(ObjectCacheMutex);
   if (!ObjectCache.count(Filename)) {
     ObjectEntry &OE = ObjectCache[Filename];
-    auto Err = OE.load(VFS, Filename, Verbose);
+    auto Err = OE.load(VFS, Filename, Timestamp, Verbose);
     if (Err) {
       ObjectCache.erase(Filename);
       return std::move(Err);

diff  --git a/llvm/tools/dsymutil/BinaryHolder.h b/llvm/tools/dsymutil/BinaryHolder.h
index dee944d826a1..5e81fe4b93b1 100644
--- a/llvm/tools/dsymutil/BinaryHolder.h
+++ b/llvm/tools/dsymutil/BinaryHolder.h
@@ -58,7 +58,7 @@ class BinaryHolder {
   public:
     /// Load the given object binary in memory.
     Error load(IntrusiveRefCntPtr<vfs::FileSystem> VFS, StringRef Filename,
-               bool Verbose = false);
+               TimestampTy Timestamp, bool Verbose = false);
 
     /// Access all owned ObjectFiles.
     std::vector<const object::ObjectFile *> getObjects() const;

diff  --git a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
index fe57629bade1..29408e7c4946 100644
--- a/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
+++ b/llvm/tools/dsymutil/DwarfLinkerForBinary.cpp
@@ -412,9 +412,10 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
                 Stat.getLastModificationTime());
         if (ModificationTime != Obj->getTimestamp()) {
           // Not using the helper here as we can easily stream TimePoint<>.
-          WithColor::warning() << "Timestamp mismatch for " << File << ": "
-                               << Stat.getLastModificationTime() << " and "
-                               << sys::TimePoint<>(Obj->getTimestamp()) << "\n";
+          WithColor::warning()
+              << File << ": timestamp mismatch between swift interface file ("
+              << sys::TimePoint<>(Obj->getTimestamp()) << ") and debug map ("
+              << sys::TimePoint<>(Obj->getTimestamp()) << ")\n";
           continue;
         }
       }


        


More information about the llvm-branch-commits mailing list