diff --git a/llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test b/llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test @@ -0,0 +1,5 @@ +# RUN: llvm-objcopy --preserve-dates - %t < %p/Inputs/alloc-symtab.o +# CHECK: error: --preserve-dates requires a file + +# RUN: llvm-objcopy --preserve-dates %p/Inputs/alloc-symtab.o - +# CHECK: error: --preserve-dates requires a file diff --git a/llvm/test/tools/llvm-objcopy/ELF/preserve-dates.test b/llvm/test/tools/llvm-objcopy/ELF/preserve-dates.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/ELF/preserve-dates.test @@ -0,0 +1,5 @@ +# RUN: llvm-objcopy %p/Inputs/alloc-symtab.o %t +# RUN: test %t -nt %p/Inputs/alloc-symtab.o + +# RUN: llvm-objcopy %p/Inputs/alloc-symtab.o %t --preserve-dates +# RUN: test ! %t -nt %p/Inputs/alloc-symtab.o diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -29,6 +29,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Option/Option.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/Errc.h" #include "llvm/Support/Error.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorOr.h" @@ -206,10 +207,13 @@ /// format-agnostic modifications, i.e. preserving dates. static Error executeObjcopy(const CopyConfig &Config) { sys::fs::file_status Stat; - if (Config.PreserveDates) + if (Config.PreserveDates) { + if (Config.InputFilename == "-" || Config.OutputFilename == "-") + return createStringError(errc::invalid_argument, + "--preserve-dates requires a file"); if (auto EC = sys::fs::status(Config.InputFilename, Stat)) return createFileError(Config.InputFilename, EC); - + } if (Config.InputFormat == "binary") { auto BufOrErr = MemoryBuffer::getFile(Config.InputFilename); if (!BufOrErr)