[llvm] r315684 - Re-land "[dsymutil] Timestmap verification for __swift_ast"

Jonas Devlieghere via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 13 07:41:23 PDT 2017


Author: jdevlieghere
Date: Fri Oct 13 07:41:23 2017
New Revision: 315684

URL: http://llvm.org/viewvc/llvm-project?rev=315684&view=rev
Log:
Re-land "[dsymutil] Timestmap verification for __swift_ast"

This patch adds timestamp verification for swiftmodule files. A new flag
is provided to allows us to disable this check in order to allow testing
of this feature.

Differential revision: https://reviews.llvm.org/D38686

Modified:
    llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test
    llvm/trunk/tools/dsymutil/BinaryHolder.h
    llvm/trunk/tools/dsymutil/DwarfLinker.cpp
    llvm/trunk/tools/dsymutil/dsymutil.cpp
    llvm/trunk/tools/dsymutil/dsymutil.h

Modified: llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test?rev=315684&r1=315683&r2=315684&view=diff
==============================================================================
--- llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test (original)
+++ llvm/trunk/test/tools/dsymutil/X86/swift-ast-x86_64.test Fri Oct 13 07:41:23 2017
@@ -1,14 +1,19 @@
-RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -o %T/swift-ast.dSYM -verbose | FileCheck %s --check-prefix=DSYMUTIL
+RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.x86_64 -o %T/swift-ast.dSYM -verbose -no-swiftmodule-timestamp | FileCheck %s --check-prefix=DSYMUTIL
 RUN: llvm-readobj -sections -section-data %T/swift-ast.dSYM/Contents/Resources/DWARF/swift-ast.macho.x86_64 | FileCheck %s --check-prefix=READOBJ
 
 The tested object file has been created by the dummy Swift code:
 let x = 1
 
-Compiled with: swiftc /tmp/test.swift -Onone -target x86_64-apple-macosx10.9 -c
-Linked with: ld swift-ast.o -add_ast_path Inputs/swift-ast.swiftmodule -arch x86_64 -lSystem -macosx_version_min 10.9.0
+Compiled with:
+  swiftc /tmp/test.swift -Onone -target x86_64-apple-macosx10.9 -c
+  ld swift-ast.o -add_ast_path Inputs/swift-ast.swiftmodule -arch x86_64 -lSystem -macosx_version_min 10.9.0
 
 DSYMUTIL: filename:{{.*}}swift-ast.swiftmodule
 DSYMUTIL: DEBUG MAP OBJECT:{{.*}}swift-ast.swiftmodule
 
 READOBJ: Name:{{.*}}__swift_ast
 READOBJ: |SWIFTMODULE DATA|
+READOBJ-NEXT: |.|
+
+RUN: llvm-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

Modified: llvm/trunk/tools/dsymutil/BinaryHolder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/BinaryHolder.h?rev=315684&r1=315683&r2=315684&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/BinaryHolder.h (original)
+++ llvm/trunk/tools/dsymutil/BinaryHolder.h Fri Oct 13 07:41:23 2017
@@ -66,12 +66,6 @@ class BinaryHolder {
   MapArchiveAndGetMemberBuffers(StringRef Filename,
                                 sys::TimePoint<std::chrono::seconds> Timestamp);
 
-  void changeBackingMemoryBuffer(std::unique_ptr<MemoryBuffer> &&MemBuf);
-  ErrorOr<const object::ObjectFile &> getObjfileForArch(const Triple &T);
-
-public:
-  BinaryHolder(bool Verbose) : Verbose(Verbose) {}
-
   /// Return the MemoryBufferRef that holds the memory mapping for the
   /// given \p Filename. This function will try to parse archive
   /// member specifications of the form /path/to/archive.a(member.o).
@@ -85,6 +79,12 @@ public:
   GetMemoryBuffersForFile(StringRef Filename,
                           sys::TimePoint<std::chrono::seconds> Timestamp);
 
+  void changeBackingMemoryBuffer(std::unique_ptr<MemoryBuffer> &&MemBuf);
+  ErrorOr<const object::ObjectFile &> getObjfileForArch(const Triple &T);
+
+public:
+  BinaryHolder(bool Verbose) : Verbose(Verbose) {}
+
   /// Get the ObjectFiles designated by the \p Filename. This
   /// might be an archive member specification of the form
   /// /path/to/archive.a(member.o).

Modified: llvm/trunk/tools/dsymutil/DwarfLinker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/DwarfLinker.cpp?rev=315684&r1=315683&r2=315684&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/DwarfLinker.cpp (original)
+++ llvm/trunk/tools/dsymutil/DwarfLinker.cpp Fri Oct 13 07:41:23 2017
@@ -525,8 +525,8 @@ public:
   /// Emit the string table described by \p Pool.
   void emitStrings(const NonRelocatableStringpool &Pool);
 
-  /// Emit the swift_ast section stored in \p Buffers.
-  void emitSwiftAST(const std::vector<MemoryBufferRef> &Buffers);
+  /// Emit the swift_ast section stored in \p Buffer.
+  void emitSwiftAST(StringRef Buffer);
 
   /// Emit debug_ranges for \p FuncRange by translating the
   /// original \p Entries.
@@ -713,12 +713,11 @@ void DwarfStreamer::emitStrings(const No
 }
 
 /// Emit the swift_ast section stored in \p Buffers.
-void DwarfStreamer::emitSwiftAST(const std::vector<MemoryBufferRef> &Buffers) {
+void DwarfStreamer::emitSwiftAST(StringRef Buffer) {
   MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
   SwiftASTSection->setAlignment(1 << 5);
   MS->SwitchSection(SwiftASTSection);
-  for (auto Buf : Buffers)
-    MS->EmitBytes(Buf.getBuffer());
+  MS->EmitBytes(Buffer);
 }
 
 /// Emit the debug_range section contents for \p FuncRange by
@@ -3492,12 +3491,28 @@ bool DwarfLinker::link(const DebugMap &M
     // N_AST objects (swiftmodule files) should get dumped directly into the
     // appropriate DWARF section.
     if (Obj->getType() == MachO::N_AST) {
-      auto ErrOrMemBufferRefs = BinHolder.GetMemoryBuffersForFile(
-          Obj->getObjectFilename(), Obj->getTimestamp());
-      if (ErrOrMemBufferRefs.getError())
+      StringRef File = Obj->getObjectFilename();
+      auto ErrorOrMem = MemoryBuffer::getFile(File);
+      if (!ErrorOrMem) {
+        errs() << "Warning: Could not open " << File << "\n";
         continue;
+      }
+      sys::fs::file_status Stat;
+      if (auto errc = sys::fs::status(File, Stat)) {
+        errs() << "Warning: " << errc.message() << "\n";
+        continue;
+      }
+      if (!Options.NoTimestamp && Stat.getLastModificationTime() !=
+                                      sys::TimePoint<>(Obj->getTimestamp())) {
+        errs() << "Warning: Timestamp mismatch for " << File << ": "
+               << Stat.getLastModificationTime() << " and "
+               << sys::TimePoint<>(Obj->getTimestamp()) << "\n";
+        continue;
+      }
+
+      // Copy the module into the .swift_ast section.
       if (!Options.NoOutput)
-        Streamer->emitSwiftAST(ErrOrMemBufferRefs.get());
+        Streamer->emitSwiftAST((*ErrorOrMem)->getBuffer());
       continue;
     }
 

Modified: llvm/trunk/tools/dsymutil/dsymutil.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.cpp?rev=315684&r1=315683&r2=315684&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.cpp (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.cpp Fri Oct 13 07:41:23 2017
@@ -68,7 +68,10 @@ static opt<bool>
     NoOutput("no-output",
              desc("Do the link in memory, but do not emit the result file."),
              init(false), cat(DsymCategory));
-
+static opt<bool>
+    NoTimestamp("no-swiftmodule-timestamp",
+                desc("Don't check timestamp for swiftmodule files."),
+                init(false), cat(DsymCategory));
 static list<std::string> ArchFlags(
     "arch",
     desc("Link DWARF debug information only for specified CPU architecture\n"
@@ -266,6 +269,7 @@ int main(int argc, char **argv) {
   Options.Verbose = Verbose;
   Options.NoOutput = NoOutput;
   Options.NoODR = NoODR;
+  Options.NoTimestamp = NoTimestamp;
   Options.PrependPath = OsoPrependPath;
 
   llvm::InitializeAllTargetInfos();

Modified: llvm/trunk/tools/dsymutil/dsymutil.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/dsymutil/dsymutil.h?rev=315684&r1=315683&r2=315684&view=diff
==============================================================================
--- llvm/trunk/tools/dsymutil/dsymutil.h (original)
+++ llvm/trunk/tools/dsymutil/dsymutil.h Fri Oct 13 07:41:23 2017
@@ -25,12 +25,13 @@ namespace llvm {
 namespace dsymutil {
 
 struct LinkOptions {
-  bool Verbose;  ///< Verbosity
-  bool NoOutput; ///< Skip emitting output
-  bool NoODR;    ///< Do not unique types according to ODR
+  bool Verbose;            ///< Verbosity
+  bool NoOutput;           ///< Skip emitting output
+  bool NoODR;              ///< Do not unique types according to ODR
+  bool NoTimestamp;        ///< Do not check swiftmodule timestamp
   std::string PrependPath; ///< -oso-prepend-path
 
-  LinkOptions() : Verbose(false), NoOutput(false) {}
+  LinkOptions() : Verbose(false), NoOutput(false), NoTimestamp(false) {}
 };
 
 /// \brief Extract the DebugMaps from the given file.




More information about the llvm-commits mailing list