Skip to content

Commit 5886454

Browse files
authored
[dsymutil] Provide an option to ignore object timestamp mismatches (#113238)
Provide a option (--no-object-timestamp) to ignore object file timestamp mismatches. We already have a similar option for Swift modules (--no-swiftmodule-timestamp). rdar://123975869
1 parent 2ccbea1 commit 5886454

File tree

7 files changed

+56
-27
lines changed

7 files changed

+56
-27
lines changed

llvm/docs/CommandGuide/dsymutil.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ OPTIONS
8383
used in conjunction with ``--update`` option, this option will cause redundant
8484
accelerator tables to be removed.
8585

86+
.. option:: --no-object-timestamp
87+
88+
Don't check timestamp for object files.
89+
8690
.. option:: --no-odr
8791

8892
Do not use ODR (One Definition Rule) for uniquing C++ types.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ RUN: cp %p/../Inputs/basic.macho.x86_64 %t/Inputs
33
RUN: cp %p/../Inputs/basic1.macho.x86_64.o %t/Inputs
44
RUN: cp %p/../Inputs/basic2.macho.x86_64.o %t/Inputs
55
RUN: cp %p/../Inputs/basic3.macho.x86_64.o %t/Inputs
6-
RUN: dsymutil -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s
6+
RUN: dsymutil -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s --check-prefix=WARN
7+
RUN: dsymutil -no-object-timestamp -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s --allow-empty --check-prefix=NOWARN
78

8-
RUN: dsymutil --linker parallel -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s
9+
RUN: dsymutil --linker parallel -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s --check-prefix=WARN
10+
RUN: dsymutil --linker parallel -no-object-timestamp -oso-prepend-path=%t %t/Inputs/basic.macho.x86_64 -o %t.dSYM 2>&1 | FileCheck %s --allow-empty --check-prefix=NOWARN
911

10-
CHECK: warning: {{.*}}/Inputs/basic1.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
11-
CHECK: warning: {{.*}}/Inputs/basic2.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
12-
CHECK: warning: {{.*}}/Inputs/basic3.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
12+
WARN: warning: {{.*}}/Inputs/basic1.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
13+
WARN: warning: {{.*}}/Inputs/basic2.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
14+
WARN: warning: {{.*}}/Inputs/basic3.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})
15+
16+
NOWARN-NOT: warning: {{.*}}/Inputs/basic3.macho.x86_64.o: timestamp mismatch between object file ({{.*}}) and debug map ({{.*}})

llvm/test/tools/dsymutil/cmdline.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CHECK: -flat
1515
CHECK: -gen-reproducer
1616
CHECK: -help
1717
CHECK: -keep-function-for-static
18+
CHECK: -no-object-timestamp
1819
CHECK: -no-odr
1920
CHECK: -no-output
2021
CHECK: -no-swiftmodule-timestamp

llvm/tools/dsymutil/BinaryHolder.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,13 @@ getMachOFatMemoryBuffers(StringRef Filename, MemoryBuffer &Mem,
4141
return Buffers;
4242
}
4343

44+
BinaryHolder::BinaryHolder(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
45+
BinaryHolder::Options Opts)
46+
: VFS(VFS), Opts(Opts) {}
47+
4448
Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
4549
StringRef Filename,
46-
TimestampTy Timestamp, bool Verbose) {
50+
TimestampTy Timestamp, Options Opts) {
4751
StringRef ArchiveFilename = getArchiveAndObjectName(Filename).first;
4852

4953
// Try to load archive and force it to be memory mapped.
@@ -55,7 +59,7 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
5559

5660
MemBuffer = std::move(*ErrOrBuff);
5761

58-
if (Verbose)
62+
if (Opts.Verbose)
5963
WithColor::note() << "loaded archive '" << ArchiveFilename << "'\n";
6064

6165
// Load one or more archive buffers, depending on whether we're dealing with
@@ -88,15 +92,15 @@ Error BinaryHolder::ArchiveEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
8892

8993
Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
9094
StringRef Filename, TimestampTy Timestamp,
91-
bool Verbose) {
95+
Options Opts) {
9296
// Try to load regular binary and force it to be memory mapped.
9397
auto ErrOrBuff = (Filename == "-")
9498
? MemoryBuffer::getSTDIN()
9599
: VFS->getBufferForFile(Filename, -1, false);
96100
if (auto Err = ErrOrBuff.getError())
97101
return errorCodeToError(Err);
98102

99-
if (Filename != "-" && Timestamp != sys::TimePoint<>()) {
103+
if (Opts.Warn && Filename != "-" && Timestamp != sys::TimePoint<>()) {
100104
llvm::ErrorOr<vfs::Status> Stat = VFS->status(Filename);
101105
if (!Stat)
102106
return errorCodeToError(Stat.getError());
@@ -110,7 +114,7 @@ Error BinaryHolder::ObjectEntry::load(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
110114

111115
MemBuffer = std::move(*ErrOrBuff);
112116

113-
if (Verbose)
117+
if (Opts.Verbose)
114118
WithColor::note() << "loaded object.\n";
115119

116120
// Load one or more object buffers, depending on whether we're dealing with a
@@ -164,7 +168,7 @@ BinaryHolder::ObjectEntry::getObject(const Triple &T) const {
164168
Expected<const BinaryHolder::ObjectEntry &>
165169
BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
166170
TimestampTy Timestamp,
167-
bool Verbose) {
171+
Options Opts) {
168172
StringRef ArchiveFilename;
169173
StringRef ObjectFilename;
170174
std::tie(ArchiveFilename, ObjectFilename) = getArchiveAndObjectName(Filename);
@@ -192,7 +196,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
192196
if (Timestamp != sys::TimePoint<>() &&
193197
Timestamp != std::chrono::time_point_cast<std::chrono::seconds>(
194198
ModTimeOrErr.get())) {
195-
if (Verbose)
199+
if (Opts.Verbose)
196200
WithColor::warning()
197201
<< *NameOrErr
198202
<< ": timestamp mismatch between archive member ("
@@ -201,7 +205,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
201205
continue;
202206
}
203207

204-
if (Verbose)
208+
if (Opts.Verbose)
205209
WithColor::note() << "found member in archive.\n";
206210

207211
auto ErrOrMem = Child.getMemoryBufferRef();
@@ -230,7 +234,7 @@ BinaryHolder::ArchiveEntry::getObjectEntry(StringRef Filename,
230234

231235
Expected<const BinaryHolder::ObjectEntry &>
232236
BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
233-
if (Verbose)
237+
if (Opts.Verbose)
234238
WithColor::note() << "trying to open '" << Filename << "'\n";
235239

236240
// If this is an archive, we might have either the object or the archive
@@ -241,17 +245,17 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
241245
ArchiveRefCounter[ArchiveFilename]++;
242246
if (ArchiveCache.count(ArchiveFilename)) {
243247
return ArchiveCache[ArchiveFilename]->getObjectEntry(Filename, Timestamp,
244-
Verbose);
248+
Opts);
245249
} else {
246250
auto AE = std::make_unique<ArchiveEntry>();
247-
auto Err = AE->load(VFS, Filename, Timestamp, Verbose);
251+
auto Err = AE->load(VFS, Filename, Timestamp, Opts);
248252
if (Err) {
249253
// Don't return the error here: maybe the file wasn't an archive.
250254
llvm::consumeError(std::move(Err));
251255
} else {
252256
ArchiveCache[ArchiveFilename] = std::move(AE);
253-
return ArchiveCache[ArchiveFilename]->getObjectEntry(
254-
Filename, Timestamp, Verbose);
257+
return ArchiveCache[ArchiveFilename]->getObjectEntry(Filename,
258+
Timestamp, Opts);
255259
}
256260
}
257261
}
@@ -262,7 +266,7 @@ BinaryHolder::getObjectEntry(StringRef Filename, TimestampTy Timestamp) {
262266
ObjectRefCounter[Filename]++;
263267
if (!ObjectCache.count(Filename)) {
264268
auto OE = std::make_unique<ObjectEntry>();
265-
auto Err = OE->load(VFS, Filename, Timestamp, Verbose);
269+
auto Err = OE->load(VFS, Filename, Timestamp, Opts);
266270
if (Err)
267271
return std::move(Err);
268272
ObjectCache[Filename] = std::move(OE);
@@ -279,7 +283,7 @@ void BinaryHolder::clear() {
279283
}
280284

281285
void BinaryHolder::eraseObjectEntry(StringRef Filename) {
282-
if (Verbose)
286+
if (Opts.Verbose)
283287
WithColor::note() << "erasing '" << Filename << "' from cache\n";
284288

285289
if (isArchive(Filename)) {

llvm/tools/dsymutil/BinaryHolder.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,15 @@ class BinaryHolder {
3838
public:
3939
using TimestampTy = sys::TimePoint<std::chrono::seconds>;
4040

41-
BinaryHolder(IntrusiveRefCntPtr<vfs::FileSystem> VFS, bool Verbose = false)
42-
: VFS(VFS), Verbose(Verbose) {}
41+
struct Options {
42+
Options(bool Verbose = false, bool Warn = true)
43+
: Verbose(Verbose), Warn(Warn) {}
44+
bool Verbose;
45+
bool Warn;
46+
};
47+
48+
BinaryHolder(IntrusiveRefCntPtr<vfs::FileSystem> VFS,
49+
BinaryHolder::Options Opts = {});
4350

4451
// Forward declarations for friend declaration.
4552
class ObjectEntry;
@@ -58,7 +65,7 @@ class BinaryHolder {
5865
public:
5966
/// Load the given object binary in memory.
6067
Error load(IntrusiveRefCntPtr<vfs::FileSystem> VFS, StringRef Filename,
61-
TimestampTy Timestamp, bool Verbose = false);
68+
TimestampTy Timestamp, BinaryHolder::Options = {});
6269

6370
/// Access all owned ObjectFiles.
6471
std::vector<const object::ObjectFile *> getObjects() const;
@@ -110,11 +117,11 @@ class BinaryHolder {
110117

111118
/// Load the given object binary in memory.
112119
Error load(IntrusiveRefCntPtr<vfs::FileSystem> VFS, StringRef Filename,
113-
TimestampTy Timestamp, bool Verbose = false);
120+
TimestampTy Timestamp, BinaryHolder::Options = {});
114121

115122
Expected<const ObjectEntry &> getObjectEntry(StringRef Filename,
116123
TimestampTy Timestamp,
117-
bool Verbose = false);
124+
BinaryHolder::Options = {});
118125

119126
private:
120127
std::vector<std::unique_ptr<object::Archive>> Archives;
@@ -143,7 +150,7 @@ class BinaryHolder {
143150
/// Virtual File System instance.
144151
IntrusiveRefCntPtr<vfs::FileSystem> VFS;
145152

146-
bool Verbose;
153+
Options Opts;
147154
};
148155

149156
} // namespace dsymutil

llvm/tools/dsymutil/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ def no_swiftmodule_timestamp: F<"no-swiftmodule-timestamp">,
6565
HelpText<"Don't check timestamp for swiftmodule files.">,
6666
Group<grp_general>;
6767

68+
def no_object_timestamp: F<"no-object-timestamp">,
69+
HelpText<"Don't check timestamp for object files.">,
70+
Group<grp_general>;
71+
6872
def no_odr: F<"no-odr">,
6973
HelpText<"Do not use ODR (One Definition Rule) for type uniquing.">,
7074
Group<grp_general>;

llvm/tools/dsymutil/dsymutil.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct DsymutilOptions {
108108
bool Flat = false;
109109
bool InputIsYAMLDebugMap = false;
110110
bool ForceKeepFunctionForStatic = false;
111+
bool NoObjectTimestamp = false;
111112
std::string OutputFile;
112113
std::string Toolchain;
113114
std::string ReproducerPath;
@@ -292,6 +293,7 @@ static Expected<DsymutilOptions> getOptions(opt::InputArgList &Args) {
292293
Options.DumpStab = Args.hasArg(OPT_symtab);
293294
Options.Flat = Args.hasArg(OPT_flat);
294295
Options.InputIsYAMLDebugMap = Args.hasArg(OPT_yaml_input);
296+
Options.NoObjectTimestamp = Args.hasArg(OPT_no_object_timestamp);
295297

296298
if (Expected<DWARFVerify> Verify = getVerifyKind(Args)) {
297299
Options.Verify = *Verify;
@@ -664,7 +666,10 @@ int dsymutil_main(int argc, char **argv, const llvm::ToolContext &) {
664666

665667
for (auto &InputFile : Options.InputFiles) {
666668
// Shared a single binary holder for all the link steps.
667-
BinaryHolder BinHolder(Options.LinkOpts.VFS, Options.LinkOpts.Verbose);
669+
BinaryHolder::Options BinOpts;
670+
BinOpts.Verbose = Options.LinkOpts.Verbose;
671+
BinOpts.Warn = !Options.NoObjectTimestamp;
672+
BinaryHolder BinHolder(Options.LinkOpts.VFS, BinOpts);
668673

669674
// Dump the symbol table for each input file and requested arch
670675
if (Options.DumpStab) {

0 commit comments

Comments
 (0)