diff options
-rw-r--r-- | llvm/test/tools/llvm-objcopy/strip-preserve-time.test | 8 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 3 |
2 files changed, 10 insertions, 1 deletions
diff --git a/llvm/test/tools/llvm-objcopy/strip-preserve-time.test b/llvm/test/tools/llvm-objcopy/strip-preserve-time.test index d2f50b777eb..408cabec049 100644 --- a/llvm/test/tools/llvm-objcopy/strip-preserve-time.test +++ b/llvm/test/tools/llvm-objcopy/strip-preserve-time.test @@ -7,6 +7,8 @@ # RUN: llvm-strip -p %t.1.o -o %t-preserved.1.o # RUN: ls -lu %t-preserved.1.o | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t-preserved.1.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# Check that the stripped output is in fact a valid object file. +# RUN: llvm-readobj %t-preserved.1.o # Preserve dates available via objcopy interface as well. # RUN: yaml2obj %s > %t.2.o @@ -15,6 +17,7 @@ # RUN: llvm-objcopy -p %t.2.o %t-preserved.2.o # RUN: ls -lu %t-preserved.2.o | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t-preserved.2.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj %t-preserved.2.o # Preserve dates when stripping in place. # RUN: yaml2obj %s > %t.3.o @@ -23,6 +26,7 @@ # RUN: llvm-strip -p %t.3.o # RUN: ls -lu %t.3.o | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t.3.o | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj %t.3.o # Without -p set, don't preserve dates. # RUN: yaml2obj %s > %t.4.o @@ -31,6 +35,7 @@ # RUN: llvm-strip %t.4.o # RUN: ls -lu %t.4.o | FileCheck %s --check-prefix=CHECK-NO-PRESERVE-ATIME # RUN: ls -l %t.4.o | FileCheck %s --check-prefix=CHECK-NO-PRESERVE-MTIME +# RUN: llvm-readobj %t.4.o # Preserve dates in archives. # RUN: yaml2obj %s > %t.5.o @@ -41,6 +46,7 @@ # RUN: llvm-strip -p %t.a # RUN: ls -lu %t.a | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t.a | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj %t.a # Preserve dates in split DWO files. # RUN: cp %p/Inputs/dwarf.dwo %t-input.dwo @@ -49,8 +55,10 @@ # RUN: llvm-objcopy -p -split-dwo=%t-dwo %t-input.dwo %t-nondwo # RUN: ls -lu %t-dwo | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t-dwo | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj %t-dwo # RUN: ls -lu %t-nondwo | FileCheck %s --check-prefix=CHECK-PRESERVE-ATIME # RUN: ls -l %t-nondwo | FileCheck %s --check-prefix=CHECK-PRESERVE-MTIME +# RUN: llvm-readobj %t-nondwo # CHECK-PRESERVE-ATIME: 1995 # CHECK-PRESERVE-MTIME: 1997 diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index 0bf9bc47d01..72501f3eb98 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -748,7 +748,8 @@ static void restoreDateOnFile(StringRef Filename, const sys::fs::file_status &Stat) { int FD; - if (auto EC = sys::fs::openFileForWrite(Filename, FD)) + if (auto EC = + sys::fs::openFileForWrite(Filename, FD, sys::fs::CD_OpenExisting)) reportError(Filename, EC); if (auto EC = sys::fs::setLastAccessAndModificationTime( |