Skip to content

Commit e5553b9

Browse files
committed
[dsymutil] Warn on timestmap mismatch between object file and debug map
Add a warning when the timestmap doesn't match between the object file and the debug map entry. We were already emitting such warnings for archive members and swift interface files. This patch also unifies the warning across all three. rdar://65614640 Differential revision: https://reviews.llvm.org/D94536
1 parent 914e2f5 commit e5553b9

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

llvm/test/tools/dsymutil/Inputs/basic.macho.x86_64.o

Whitespace-only changes.

llvm/test/tools/dsymutil/X86/swift-ast-x86_64.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ READOBJ-NEXT: |.|
2020
DWARFDUMP: __swift_ast
2121

2222
RUN: dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -no-output -verbose 2>&1 | FileCheck %s --check-prefix=TIMESTAMP
23-
TIMESTAMP: warning: Timestamp mismatch
23+
TIMESTAMP: warning: {{.*}}/swift-ast.swiftmodule: timestamp mismatch between swift interface file ({{.*}}) and debug map ({{.*}})
2424

2525
RUN: dsymutil -s %T/swift-ast.dSYM/Contents/Resources/DWARF/swift-ast.macho.x86_64 | FileCheck %s --check-prefix=NAST
2626
NAST-NOT: N_AST

llvm/test/tools/dsymutil/debug-map-parsing.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
RUN: touch %p/Inputs/basic.macho.x86_64.o
12
RUN: dsymutil -dump-debug-map -oso-prepend-path=%p %p/Inputs/basic.macho.x86_64 | FileCheck %s
23
RUN: dsymutil -dump-debug-map -oso-prepend-path=%p %p/Inputs/basic-lto.macho.x86_64 | FileCheck %s --check-prefix=CHECK-LTO
34
RUN: dsymutil -verbose -dump-debug-map -oso-prepend-path=%p %p/Inputs/basic-archive.macho.x86_64 2>&1 | FileCheck %s --check-prefix=CHECK-ARCHIVE
@@ -46,6 +47,7 @@ opening the archive once if mulitple of its members are used).
4647
CHECK-ARCHIVE: trying to open {{.*}}basic-archive.macho.x86_64'
4748
CHECK-ARCHIVE-NEXT: loaded object.
4849
CHECK-ARCHIVE-NEXT: trying to open {{.*}}/Inputs/basic1.macho.x86_64.o'
50+
CHECK-ARCHIVE-NEXT: warning: {{.*}}/Inputs/basic1.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
4951
CHECK-ARCHIVE-NEXT: loaded object.
5052
CHECK-ARCHIVE-NEXT: trying to open {{.*}}/libbasic.a(basic2.macho.x86_64.o)'
5153
CHECK-ARCHIVE-NEXT: loaded archive {{.*}}/libbasic.a'

llvm/tools/dsymutil/BinaryHolder.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,26 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
8787
}
8888

8989
Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
90-
StringRef Filename, bool Verbose) {
90+
StringRef Filename, TimestampTy Timestamp,
91+
bool Verbose) {
9192
// Try to load regular binary and force it to be memory mapped.
9293
auto ErrOrBuff = (Filename == "-")
9394
? MemoryBuffer::getSTDIN()
9495
: VFS->getBufferForFile(Filename, -1, false);
9596
if (auto Err = ErrOrBuff.getError())
9697
return errorCodeToError(Err);
9798

99+
if (Filename != "-" && Timestamp != sys::TimePoint<>()) {
100+
llvm::ErrorOr<vfs::Status> Stat = VFS->status(Filename);
101+
if (!Stat)
102+
return errorCodeToError(Stat.getError());
103+
if (Timestamp != Stat->getLastModificationTime())
104+
WithColor::warning() << Filename
105+
<< ": timestamp mismatch between object file ("
106+
<< Stat->getLastModificationTime()
107+
<< ") and debug map (" << Timestamp << ")\n";
108+
}
109+
98110
MemBuffer = std::move(*ErrOrBuff);
99111

100112
if (Verbose)
@@ -182,7 +194,11 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
182194
if (Timestamp != sys::TimePoint<>() &&
183195
Timestamp != ModTimeOrErr.get()) {
184196
if (Verbose)
185-
WithColor::warning() << "member has timestamp mismatch.\n";
197+
WithColor::warning()
198+
<< *NameOrErr
199+
<< ": timestamp mismatch between archive member ("
200+
<< ModTimeOrErr.get() << ") and debug map (" << Timestamp
201+
<< ")\n";
186202
continue;
187203
}
188204

@@ -246,7 +262,7 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
246262
std::lock_guard<std::mutex> Lock(ObjectCacheMutex);
247263
if (!ObjectCache.count(Filename)) {
248264
ObjectEntry &OE = ObjectCache[Filename];
249-
auto Err = OE.load(VFS, Filename, Verbose);
265+
auto Err = OE.load(VFS, Filename, Timestamp, Verbose);
250266
if (Err) {
251267
ObjectCache.erase(Filename);
252268
return std::move(Err);

llvm/tools/dsymutil/BinaryHolder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class BinaryHolder {
5858
public:
5959
/// Load the given object binary in memory.
6060
Error load(IntrusiveRefCntPtr<vfs::FileSystem> VFS, StringRef Filename,
61-
bool Verbose = false);
61+
TimestampTy Timestamp, bool Verbose = false);
6262

6363
/// Access all owned ObjectFiles.
6464
std::vector<const object::ObjectFile *> getObjects() const;

llvm/tools/dsymutil/DwarfLinkerForBinary.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,10 @@ bool DwarfLinkerForBinary::link(const DebugMap &Map) {
412412
Stat.getLastModificationTime());
413413
if (ModificationTime != Obj->getTimestamp()) {
414414
// Not using the helper here as we can easily stream TimePoint<>.
415-
WithColor::warning() << "Timestamp mismatch for " << File << ": "
416-
<< Stat.getLastModificationTime() << " and "
417-
<< sys::TimePoint<>(Obj->getTimestamp()) << "\n";
415+
WithColor::warning()
416+
<< File << ": timestamp mismatch between swift interface file ("
417+
<< sys::TimePoint<>(Obj->getTimestamp()) << ") and debug map ("
418+
<< sys::TimePoint<>(Obj->getTimestamp()) << ")\n";
418419
continue;
419420
}
420421
}

0 commit comments

Comments
 (0)