[PATCH] D63090: [objcopy] Error when --preserve-dates is specified with standard streams
Alex Brachet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 22:29:20 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363485: [objcopy] Error when --preserve-dates is specified with standard streams (authored by abrachet, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D63090?vs=204681&id=204899#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D63090/new/
https://reviews.llvm.org/D63090
Files:
llvm/trunk/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
Index: llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
+++ llvm/trunk/tools/llvm-objcopy/CopyConfig.cpp
@@ -668,6 +668,11 @@
Config.PreserveDates = InputArgs.hasArg(OBJCOPY_preserve_dates);
+ if (Config.PreserveDates &&
+ (Config.OutputFilename == "-" || Config.InputFilename == "-"))
+ return createStringError(errc::invalid_argument,
+ "--preserve-dates requires a file");
+
for (auto Arg : InputArgs)
if (Arg->getOption().matches(OBJCOPY_set_start)) {
auto EAddr = getAsInteger<uint64_t>(Arg->getValue());
@@ -736,7 +741,7 @@
exit(0);
}
- SmallVector<const char *, 2> Positional;
+ SmallVector<StringRef, 2> Positional;
for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN))
return createStringError(errc::invalid_argument, "unknown argument '%s'",
Arg->getAsString(InputArgs).c_str());
@@ -801,13 +806,18 @@
InputArgs.getLastArgValue(STRIP_output, Positional[0]);
DC.CopyConfigs.push_back(std::move(Config));
} else {
- for (const char *Filename : Positional) {
+ for (StringRef Filename : Positional) {
Config.InputFilename = Filename;
Config.OutputFilename = Filename;
DC.CopyConfigs.push_back(Config);
}
}
+ if (Config.PreserveDates && (is_contained(Positional, "-") ||
+ InputArgs.getLastArgValue(STRIP_output) == "-"))
+ return createStringError(errc::invalid_argument,
+ "--preserve-dates requires a file");
+
return std::move(DC);
}
Index: llvm/trunk/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
===================================================================
--- llvm/trunk/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
+++ llvm/trunk/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
@@ -0,0 +1,23 @@
+## This tests for an expected error when --preserve dates is
+## specified at the same time as using stdin or stdout as input or
+## output files.
+
+# RUN: not llvm-objcopy --preserve-dates - %t 2>&1 | FileCheck %s
+# RUN: not llvm-objcopy --preserve-dates %p/Inputs/alloc-symtab.o - 2>&1 | FileCheck %s
+
+## Testing N args.
+# RUN: not llvm-strip --preserve-dates - < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o - < \
+# RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates - %p/Inputs/alloc-symtab.o < \
+# RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o - \
+# RUN: %p/Inputs/alloc-symtab.o < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+
+## Testing -o.
+# RUN: not llvm-strip --preserve-dates - -o %p/Inputs/alloc-symtab.o < \
+# RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o -o - < \
+# RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+
+# CHECK: error: --preserve-dates requires a file
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63090.204899.patch
Type: text/x-patch
Size: 3149 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190615/5c4ff7e6/attachment.bin>
More information about the llvm-commits
mailing list