1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[objcopy] Error when --preserve-dates is specified with standard streams

Summary: llvm-objcopy/strip now error when -p is specified when reading from stdin or writing to stdout

Reviewers: jhenderson, rupprecht, espindola, alexshap

Reviewed By: jhenderson, rupprecht

Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63090

llvm-svn: 363485
This commit is contained in:
Alex Brachet 2019-06-15 05:32:23 +00:00
parent 70f373fb8d
commit 1c3240a461
2 changed files with 35 additions and 2 deletions

View File

@ -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

View File

@ -668,6 +668,11 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
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 @@ Expected<DriverConfig> parseStripOptions(ArrayRef<const char *> ArgsArr) {
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 @@ Expected<DriverConfig> parseStripOptions(ArrayRef<const char *> ArgsArr) {
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);
}