llvm.org GIT mirror llvm / 1f1f241
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363485 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Brachet a month ago
2 changed file(s) with 35 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
0 ## This tests for an expected error when --preserve dates is
1 ## specified at the same time as using stdin or stdout as input or
2 ## output files.
3
4 # RUN: not llvm-objcopy --preserve-dates - %t 2>&1 | FileCheck %s
5 # RUN: not llvm-objcopy --preserve-dates %p/Inputs/alloc-symtab.o - 2>&1 | FileCheck %s
6
7 ## Testing N args.
8 # RUN: not llvm-strip --preserve-dates - < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
9 # RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o - < \
10 # RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
11 # RUN: not llvm-strip --preserve-dates - %p/Inputs/alloc-symtab.o < \
12 # RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
13 # RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o - \
14 # RUN: %p/Inputs/alloc-symtab.o < %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
15
16 ## Testing -o.
17 # RUN: not llvm-strip --preserve-dates - -o %p/Inputs/alloc-symtab.o < \
18 # RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
19 # RUN: not llvm-strip --preserve-dates %p/Inputs/alloc-symtab.o -o - < \
20 # RUN: %p/Inputs/alloc-symtab.o 2>&1 | FileCheck %s
21
22 # CHECK: error: --preserve-dates requires a file
667667
668668 Config.PreserveDates = InputArgs.hasArg(OBJCOPY_preserve_dates);
669669
670 if (Config.PreserveDates &&
671 (Config.OutputFilename == "-" || Config.InputFilename == "-"))
672 return createStringError(errc::invalid_argument,
673 "--preserve-dates requires a file");
674
670675 for (auto Arg : InputArgs)
671676 if (Arg->getOption().matches(OBJCOPY_set_start)) {
672677 auto EAddr = getAsInteger(Arg->getValue());
735740 exit(0);
736741 }
737742
738 SmallVector<const char *, 2> Positional;
743 SmallVector<StringRef, 2> Positional;
739744 for (auto Arg : InputArgs.filtered(STRIP_UNKNOWN))
740745 return createStringError(errc::invalid_argument, "unknown argument '%s'",
741746 Arg->getAsString(InputArgs).c_str());
800805 InputArgs.getLastArgValue(STRIP_output, Positional[0]);
801806 DC.CopyConfigs.push_back(std::move(Config));
802807 } else {
803 for (const char *Filename : Positional) {
808 for (StringRef Filename : Positional) {
804809 Config.InputFilename = Filename;
805810 Config.OutputFilename = Filename;
806811 DC.CopyConfigs.push_back(Config);
807812 }
808813 }
809814
815 if (Config.PreserveDates && (is_contained(Positional, "-") ||
816 InputArgs.getLastArgValue(STRIP_output) == "-"))
817 return createStringError(errc::invalid_argument,
818 "--preserve-dates requires a file");
819
810820 return std::move(DC);
811821 }
812822