From d486e90488cc0e9351069d292b6a016a7b3c2cc9 Mon Sep 17 00:00:00 2001 From: Jonas Devlieghere Date: Wed, 11 Oct 2017 13:34:52 +0000 Subject: [PATCH] [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@315456 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/dsymutil/ARM/swift-ast.test | 26 ++++++++++++++ .../tools/dsymutil/Inputs/swift-ast.macho.fat | Bin 0 -> 131312 bytes test/tools/dsymutil/X86/swift-ast-x86_64.test | 11 ++++-- tools/dsymutil/BinaryHolder.h | 12 +++---- tools/dsymutil/DwarfLinker.cpp | 33 +++++++++++++----- tools/dsymutil/dsymutil.cpp | 6 +++- tools/dsymutil/dsymutil.h | 9 ++--- 7 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 test/tools/dsymutil/ARM/swift-ast.test create mode 100755 test/tools/dsymutil/Inputs/swift-ast.macho.fat diff --git a/test/tools/dsymutil/ARM/swift-ast.test b/test/tools/dsymutil/ARM/swift-ast.test new file mode 100644 index 00000000000..bd33e7af436 --- /dev/null +++ b/test/tools/dsymutil/ARM/swift-ast.test @@ -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 diff --git a/test/tools/dsymutil/Inputs/swift-ast.macho.fat b/test/tools/dsymutil/Inputs/swift-ast.macho.fat new file mode 100755 index 0000000000000000000000000000000000000000..a3f8d369d02547c9b78b71043d2c135a58e596f6 GIT binary patch literal 131312 zcmeI*O=whC6u|K_NtCgQMkr!YY!o6^G&71qC|yi!f{mXchN5n6Gnp5CG9Qw8qmx2u zHi8z!NGWt#=&n!@YoYC;PPeVJcGHcEs!?bcf(tiVt3Bs^B$H9mLaCeoh4b$BeRqEE zZRfrpAAR?|h_q=e(O4v@oMw%?dRdx^+O%kGKXh7~1_=QK5I_I{1Q0*~0R#|0009IL zKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~0R#|0009ILKmY**5I_I{1Q0*~ z0R#|0009L4V}V~D+kyFxTP4b$?I~vXn_3a!uJTSc9TIZ*5 z^8BVJYPL?V4s>p0;N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d*b8zMGkS*lYH77$qxmUXUMV#=7;G0{4`Ay6~Qb$zs7(gIeC@ z{jzOkuzb80R5R6+{&=u?v>Nn;rBbC(D|)()3#)Fz8!viefnO=R6W&BsbL|_+ZnHJF L)DQS4?7sg1-&B4D literal 0 HcmV?d00001 diff --git a/test/tools/dsymutil/X86/swift-ast-x86_64.test b/test/tools/dsymutil/X86/swift-ast-x86_64.test index 72fc7520b73..98d3850efb0 100644 --- a/test/tools/dsymutil/X86/swift-ast-x86_64.test +++ b/test/tools/dsymutil/X86/swift-ast-x86_64.test @@ -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 diff --git a/tools/dsymutil/BinaryHolder.h b/tools/dsymutil/BinaryHolder.h index f4ca0b2bc3a..5b2061d23aa 100644 --- a/tools/dsymutil/BinaryHolder.h +++ b/tools/dsymutil/BinaryHolder.h @@ -66,12 +66,6 @@ class BinaryHolder { MapArchiveAndGetMemberBuffers(StringRef Filename, sys::TimePoint Timestamp); - void changeBackingMemoryBuffer(std::unique_ptr &&MemBuf); - ErrorOr 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 Timestamp); + void changeBackingMemoryBuffer(std::unique_ptr &&MemBuf); + ErrorOr 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). diff --git a/tools/dsymutil/DwarfLinker.cpp b/tools/dsymutil/DwarfLinker.cpp index 4b3a336de0e..d96f6e1ba0e 100644 --- a/tools/dsymutil/DwarfLinker.cpp +++ b/tools/dsymutil/DwarfLinker.cpp @@ -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 &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. @@ -712,12 +712,11 @@ void DwarfStreamer::emitStrings(const NonRelocatableStringpool &Pool) { } /// Emit the swift_ast section stored in \p Buffers. -void DwarfStreamer::emitSwiftAST(const std::vector &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 @@ -3491,12 +3490,28 @@ bool DwarfLinker::link(const DebugMap &Map) { // 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; } diff --git a/tools/dsymutil/dsymutil.cpp b/tools/dsymutil/dsymutil.cpp index 51eb3ff2e39..975f8a5f095 100644 --- a/tools/dsymutil/dsymutil.cpp +++ b/tools/dsymutil/dsymutil.cpp @@ -68,7 +68,10 @@ static opt NoOutput("no-output", desc("Do the link in memory, but do not emit the result file."), init(false), cat(DsymCategory)); - +static opt + NoTimestamp("no-swiftmodule-timestamp", + desc("Don't check timestamp for swiftmodule files."), + init(false), cat(DsymCategory)); static list 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(); diff --git a/tools/dsymutil/dsymutil.h b/tools/dsymutil/dsymutil.h index 91cb3276612..8f587421005 100644 --- a/tools/dsymutil/dsymutil.h +++ b/tools/dsymutil/dsymutil.h @@ -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. -- 2.50.1