[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
Mon Jun 10 12:46:38 PDT 2019
abrachet created this revision.
abrachet added reviewers: jhenderson, rupprecht.
Herald added subscribers: llvm-commits, MaskRay, jakehehrlich, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: alexshap.
Herald added a project: LLVM.
llvm-objcopy/strip now error when -p is specified when reading from stdin or writing to stdout
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63090
Files:
llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
llvm/tools/llvm-objcopy/CopyConfig.cpp
Index: llvm/tools/llvm-objcopy/CopyConfig.cpp
===================================================================
--- llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -667,6 +667,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());
@@ -735,7 +740,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());
@@ -800,13 +805,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/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-objcopy/ELF/invalid-preserve-dates.test
@@ -0,0 +1,14 @@
+# 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 - < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates - %p/Inputs/alloc-symtab.o < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o - %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 < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
+# RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o -o - < %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.203875.patch
Type: text/x-patch
Size: 2833 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190610/c0109808/attachment.bin>
More information about the llvm-commits
mailing list