forked from OSchip/llvm-project
				
			[dsymutil] Timestmap verification for __swift_ast
This patch adds timestamp verification for swiftmodule files. - A new flag is provided to allows us to continue testing of the code for embedding the__swift_ast. (git doesn't maintain timestamps) - Adds a new test for fat (arm) binaries. Differential revision: https://reviews.llvm.org/D38686 llvm-svn: 315456
This commit is contained in:
		
							parent
							
								
									5c1eef4618
								
							
						
					
					
						commit
						8acb2e3ac4
					
				| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.fat -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.fat | 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 armv7-apple-ios8.1 -c -o swift-ast-armv7.o
 | 
				
			||||||
 | 
					  ld swift-ast-armv7.o -add_ast_path swift-ast.swiftmodule -arch armv7 -ios_version_min 8.1  -syslibroot /path/to/iPhoneOS.sdk -L/path/to/usr/lib/swift/iphoneos -lobjc -lSystem -o swift-ast.macho.armv7
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  swiftc /tmp/test.swift -Onone -target arm64-apple-ios8.1 -c -o swift-ast-arm64.o
 | 
				
			||||||
 | 
					  ld swift-ast-arm64.o -add_ast_path swift-ast.swiftmodule -arch arm64 -ios_version_min 8.1  -syslibroot /path/to/iPhoneOS.sdk -L/path/to/usr/lib/swift/iphoneos -lobjc -lSystem -o swift-ast.macho.arm64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  lipo -create swift-ast.macho.armv7 swift-ast.macho.arm64 -o swift-ast.macho.fat
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DSYMUTIL: filename:{{.*}}swift-ast.swiftmodule
 | 
				
			||||||
 | 
					DSYMUTIL: DEBUG MAP OBJECT:{{.*}}swift-ast.swiftmodule
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					READOBJ: Name:{{.*}}__swift_ast
 | 
				
			||||||
 | 
					READOBJ: |SWIFTMODULE DATA|
 | 
				
			||||||
 | 
					READOBJ-NEXT: |.|
 | 
				
			||||||
 | 
					READOBJ: |SWIFTMODULE DATA|
 | 
				
			||||||
 | 
					READOBJ-NEXT: |.|
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					RUN: llvm-dsymutil -oso-prepend-path %p/.. %p/../Inputs/swift-ast.macho.fat -no-output -verbose 2>&1 | FileCheck %s --check-prefix=TIMESTAMP
 | 
				
			||||||
 | 
					TIMESTAMP: Warning: Timestamp mismatch
 | 
				
			||||||
										
											Binary file not shown.
										
									
								
							| 
						 | 
					@ -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
 | 
					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:
 | 
					The tested object file has been created by the dummy Swift code:
 | 
				
			||||||
let x = 1
 | 
					let x = 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Compiled with: swiftc /tmp/test.swift -Onone -target x86_64-apple-macosx10.9 -c
 | 
					Compiled with:
 | 
				
			||||||
Linked with: ld swift-ast.o -add_ast_path Inputs/swift-ast.swiftmodule -arch x86_64 -lSystem -macosx_version_min 10.9.0
 | 
					  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: filename:{{.*}}swift-ast.swiftmodule
 | 
				
			||||||
DSYMUTIL: DEBUG MAP OBJECT:{{.*}}swift-ast.swiftmodule
 | 
					DSYMUTIL: DEBUG MAP OBJECT:{{.*}}swift-ast.swiftmodule
 | 
				
			||||||
 | 
					
 | 
				
			||||||
READOBJ: Name:{{.*}}__swift_ast
 | 
					READOBJ: Name:{{.*}}__swift_ast
 | 
				
			||||||
READOBJ: |SWIFTMODULE DATA|
 | 
					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
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -66,12 +66,6 @@ class BinaryHolder {
 | 
				
			||||||
  MapArchiveAndGetMemberBuffers(StringRef Filename,
 | 
					  MapArchiveAndGetMemberBuffers(StringRef Filename,
 | 
				
			||||||
                                sys::TimePoint<std::chrono::seconds> Timestamp);
 | 
					                                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
 | 
					  /// Return the MemoryBufferRef that holds the memory mapping for the
 | 
				
			||||||
  /// given \p Filename. This function will try to parse archive
 | 
					  /// given \p Filename. This function will try to parse archive
 | 
				
			||||||
  /// member specifications of the form /path/to/archive.a(member.o).
 | 
					  /// member specifications of the form /path/to/archive.a(member.o).
 | 
				
			||||||
| 
						 | 
					@ -85,6 +79,12 @@ public:
 | 
				
			||||||
  GetMemoryBuffersForFile(StringRef Filename,
 | 
					  GetMemoryBuffersForFile(StringRef Filename,
 | 
				
			||||||
                          sys::TimePoint<std::chrono::seconds> Timestamp);
 | 
					                          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
 | 
					  /// Get the ObjectFiles designated by the \p Filename. This
 | 
				
			||||||
  /// might be an archive member specification of the form
 | 
					  /// might be an archive member specification of the form
 | 
				
			||||||
  /// /path/to/archive.a(member.o).
 | 
					  /// /path/to/archive.a(member.o).
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -525,8 +525,8 @@ public:
 | 
				
			||||||
  /// Emit the string table described by \p Pool.
 | 
					  /// Emit the string table described by \p Pool.
 | 
				
			||||||
  void emitStrings(const NonRelocatableStringpool &Pool);
 | 
					  void emitStrings(const NonRelocatableStringpool &Pool);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Emit the swift_ast section stored in \p Buffers.
 | 
					  /// Emit the swift_ast section stored in \p Buffer.
 | 
				
			||||||
  void emitSwiftAST(const std::vector<MemoryBufferRef> &Buffers);
 | 
					  void emitSwiftAST(StringRef Buffer);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Emit debug_ranges for \p FuncRange by translating the
 | 
					  /// Emit debug_ranges for \p FuncRange by translating the
 | 
				
			||||||
  /// original \p Entries.
 | 
					  /// original \p Entries.
 | 
				
			||||||
| 
						 | 
					@ -712,12 +712,11 @@ void DwarfStreamer::emitStrings(const NonRelocatableStringpool &Pool) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Emit the swift_ast section stored in \p Buffers.
 | 
					/// 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();
 | 
					  MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
 | 
				
			||||||
  SwiftASTSection->setAlignment(1 << 5);
 | 
					  SwiftASTSection->setAlignment(1 << 5);
 | 
				
			||||||
  MS->SwitchSection(SwiftASTSection);
 | 
					  MS->SwitchSection(SwiftASTSection);
 | 
				
			||||||
  for (auto Buf : Buffers)
 | 
					  MS->EmitBytes(Buffer);
 | 
				
			||||||
    MS->EmitBytes(Buf.getBuffer());
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Emit the debug_range section contents for \p FuncRange by
 | 
					/// Emit the debug_range section contents for \p FuncRange by
 | 
				
			||||||
| 
						 | 
					@ -3491,12 +3490,28 @@ bool DwarfLinker::link(const DebugMap &Map) {
 | 
				
			||||||
    // N_AST objects (swiftmodule files) should get dumped directly into the
 | 
					    // N_AST objects (swiftmodule files) should get dumped directly into the
 | 
				
			||||||
    // appropriate DWARF section.
 | 
					    // appropriate DWARF section.
 | 
				
			||||||
    if (Obj->getType() == MachO::N_AST) {
 | 
					    if (Obj->getType() == MachO::N_AST) {
 | 
				
			||||||
      auto ErrOrMemBufferRefs = BinHolder.GetMemoryBuffersForFile(
 | 
					      StringRef File = Obj->getObjectFilename();
 | 
				
			||||||
          Obj->getObjectFilename(), Obj->getTimestamp());
 | 
					      auto ErrorOrMem = MemoryBuffer::getFile(File);
 | 
				
			||||||
      if (ErrOrMemBufferRefs.getError())
 | 
					      if (!ErrorOrMem) {
 | 
				
			||||||
 | 
					        errs() << "Warning: Could not open " << File << "\n";
 | 
				
			||||||
        continue;
 | 
					        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)
 | 
					      if (!Options.NoOutput)
 | 
				
			||||||
        Streamer->emitSwiftAST(ErrOrMemBufferRefs.get());
 | 
					        Streamer->emitSwiftAST((*ErrorOrMem)->getBuffer());
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,10 @@ static opt<bool>
 | 
				
			||||||
    NoOutput("no-output",
 | 
					    NoOutput("no-output",
 | 
				
			||||||
             desc("Do the link in memory, but do not emit the result file."),
 | 
					             desc("Do the link in memory, but do not emit the result file."),
 | 
				
			||||||
             init(false), cat(DsymCategory));
 | 
					             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(
 | 
					static list<std::string> ArchFlags(
 | 
				
			||||||
    "arch",
 | 
					    "arch",
 | 
				
			||||||
    desc("Link DWARF debug information only for specified CPU architecture\n"
 | 
					    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.Verbose = Verbose;
 | 
				
			||||||
  Options.NoOutput = NoOutput;
 | 
					  Options.NoOutput = NoOutput;
 | 
				
			||||||
  Options.NoODR = NoODR;
 | 
					  Options.NoODR = NoODR;
 | 
				
			||||||
 | 
					  Options.NoTimestamp = NoTimestamp;
 | 
				
			||||||
  Options.PrependPath = OsoPrependPath;
 | 
					  Options.PrependPath = OsoPrependPath;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  llvm::InitializeAllTargetInfos();
 | 
					  llvm::InitializeAllTargetInfos();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,9 +28,10 @@ struct LinkOptions {
 | 
				
			||||||
  bool Verbose;            ///< Verbosity
 | 
					  bool Verbose;            ///< Verbosity
 | 
				
			||||||
  bool NoOutput;           ///< Skip emitting output
 | 
					  bool NoOutput;           ///< Skip emitting output
 | 
				
			||||||
  bool NoODR;              ///< Do not unique types according to ODR
 | 
					  bool NoODR;              ///< Do not unique types according to ODR
 | 
				
			||||||
 | 
					  bool NoTimestamp;        ///< Do not check swiftmodule timestamp
 | 
				
			||||||
  std::string PrependPath; ///< -oso-prepend-path
 | 
					  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.
 | 
					/// \brief Extract the DebugMaps from the given file.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue