llvm.org GIT mirror llvm / d8baf47
[llvm-objcopy] Changed command line parsing errors Summary: Tidied up errors during command line parsing to be more consistent with the rest of llvm-objcopy errors. Reviewers: jhenderson, rupprecht, espindola, alexshap Reviewed By: jhenderson, rupprecht Subscribers: emaste, arichardson, MaskRay, llvm-commits, jakehehrlich Tags: #llvm Differential Revision: https://reviews.llvm.org/D62973 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363350 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Brachet 3 months ago
12 changed file(s) with 35 addition(s) and 35 deletion(s). Raw diff Collapse all Expand all
1414 Type: ET_EXEC
1515 Machine: EM_386
1616
17 # BAD-OUTPUT-FORMAT: Invalid output format: 'xyz'
18 # BAD-OUTPUT-FORMAT-BSD: Invalid output format: 'xyz-freebsd'
17 # BAD-OUTPUT-FORMAT: invalid output format: 'xyz'
18 # BAD-OUTPUT-FORMAT-BSD: invalid output format: 'xyz-freebsd'
55 # RUN: not llvm-objcopy -I binary -B xyz %t.txt %t.o 2>&1 \
66 # RUN: | FileCheck %s --check-prefix=BAD-BINARY-ARCH
77
8 # MISSING-BINARY-ARCH: Specified binary input without specifiying an architecture
9 # BAD-BINARY-ARCH: Invalid architecture: 'xyz'
8 # MISSING-BINARY-ARCH: specified binary input without specifiying an architecture
9 # BAD-BINARY-ARCH: invalid architecture: 'xyz'
22 # RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o
33 # RUN: not llvm-objcopy --compress-debug-sections=zlib --decompress-debug-sections %t.o 2>&1 | FileCheck %s
44
5 # CHECK: Cannot specify --compress-debug-sections at the same time as --decompress-debug-sections at the same time
5 # CHECK: cannot specify both --compress-debug-sections and --decompress-debug-sections
66
0 # RUN: yaml2obj %p/Inputs/compress-debug-sections.yaml -o %t.o
11 # RUN: not llvm-objcopy --compress-debug-sections=zlib-fake %t.o 2>&1 | FileCheck %s
22
3 # CHECK: Invalid or unsupported --compress-debug-sections format: zlib-fake
3 # CHECK: invalid or unsupported --compress-debug-sections format: zlib-fake
44
1515 # OBJCOPY-USAGE: USAGE: llvm-objcopy
1616 # STRIP-USAGE: USAGE: llvm-strip
1717 # UNKNOWN-ARG: unknown argument '{{-+}}abcabc'
18 # NO-INPUT-FILES: No input file specified
18 # NO-INPUT-FILES: no input file specified
8787 #CHECK-NEXT: Section: .text
8888 #CHECK-NEXT: }
8989
90 #BAD-FORMAT: Bad format for --redefine-sym
91 #MULTIPLE-REDEFINITION: Multiple redefinition of symbol foo
90 #BAD-FORMAT: bad format for --redefine-sym
91 #MULTIPLE-REDEFINITION: multiple redefinition of symbol 'foo'
9292 #MISSING-SYM-NAME: error: {{.*}}.rename.txt:2: missing new symbol name
9393 #NO-FILE: error: '{{.*}}.rename-none.txt': {{[Nn]}}o such file or directory
9494
9494 # WRITE-NEXT: SHF_WRITE (0x1)
9595 # CHECK-NEXT: ]
9696
97 # BAD-FLAG: Unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
97 # BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
2525 # CHECK: Name: .strtab
2626 # CHECK: Name: .shstrtab
2727
28 #BAD-FORMAT: Bad format for --rename-section: missing '='
29 #MULTIPLE-RENAMES: Multiple renames of section .foo
28 #BAD-FORMAT: bad format for --rename-section: missing '='
29 #MULTIPLE-RENAMES: multiple renames of section '.foo'
116116 # WRITE-NEXT: SHF_WRITE (0x1)
117117 # CHECK-NEXT: ]
118118
119 # BAD-FORMAT: Bad format for --set-section-flags: missing '='
120 # MULTIPLE-SETS: --set-section-flags set multiple times for section .foo
119 # BAD-FORMAT: bad format for --set-section-flags: missing '='
120 # MULTIPLE-SETS: --set-section-flags set multiple times for section '.foo'
121121
122 # BAD-FLAG: Unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
122 # BAD-FLAG: unrecognized section flag 'xyzzy'. Flags supported for GNU compatibility: alloc, load, noload, readonly, debug, code, data, rom, share, contents, merge, strings
7070 # CHECK-NEXT: }
7171 # CHECK-NEXT: ]
7272
73 # BAD-O-FLAG: Multiple input files cannot be used in combination with -o
73 # BAD-O-FLAG: multiple input files cannot be used in combination with -o
117117 if (ParsedFlag == SectionFlag::SecNone)
118118 return createStringError(
119119 errc::invalid_argument,
120 "Unrecognized section flag '%s'. Flags supported for GNU "
120 "unrecognized section flag '%s'. Flags supported for GNU "
121121 "compatibility: alloc, load, noload, readonly, debug, code, data, "
122122 "rom, share, contents, merge, strings",
123123 Flag.str().c_str());
130130 static Expected parseRenameSectionValue(StringRef FlagValue) {
131131 if (!FlagValue.contains('='))
132132 return createStringError(errc::invalid_argument,
133 "Bad format for --rename-section: missing '='");
133 "bad format for --rename-section: missing '='");
134134
135135 // Initial split: ".foo" = ".bar,f1,f2,..."
136136 auto Old2New = FlagValue.split('=');
157157 parseSetSectionFlagValue(StringRef FlagValue) {
158158 if (!StringRef(FlagValue).contains('='))
159159 return createStringError(errc::invalid_argument,
160 "Bad format for --set-section-flags: missing '='");
160 "bad format for --set-section-flags: missing '='");
161161
162162 // Initial split: ".foo" = "f1,f2,..."
163163 auto Section2Flags = StringRef(FlagValue).split('=');
271271 auto Iter = ArchMap.find(Arch);
272272 if (Iter == std::end(ArchMap))
273273 return createStringError(errc::invalid_argument,
274 "Invalid architecture: '%s'", Arch.str().c_str());
274 "invalid architecture: '%s'", Arch.str().c_str());
275275 return Iter->getValue();
276276 }
277277
313313 auto Iter = OutputFormatMap.find(Format);
314314 if (Iter == std::end(OutputFormatMap))
315315 return createStringError(errc::invalid_argument,
316 "Invalid output format: '%s'",
316 "invalid output format: '%s'",
317317 OriginalFormat.str().c_str());
318318 MachineInfo MI = Iter->getValue();
319319 if (IsFreeBSD)
423423 Positional.push_back(Arg->getValue());
424424
425425 if (Positional.empty())
426 return createStringError(errc::invalid_argument, "No input file specified");
426 return createStringError(errc::invalid_argument, "no input file specified");
427427
428428 if (Positional.size() > 2)
429429 return createStringError(errc::invalid_argument,
430 "Too many positional arguments");
430 "too many positional arguments");
431431
432432 CopyConfig Config;
433433 Config.InputFilename = Positional[0];
452452 if (BinaryArch.empty())
453453 return createStringError(
454454 errc::invalid_argument,
455 "Specified binary input without specifiying an architecture");
455 "specified binary input without specifiying an architecture");
456456 Expected MI = getMachineInfo(BinaryArch);
457457 if (!MI)
458458 return MI.takeError();
480480 if (Config.CompressionType == DebugCompressionType::None)
481481 return createStringError(
482482 errc::invalid_argument,
483 "Invalid or unsupported --compress-debug-sections format: %s",
483 "invalid or unsupported --compress-debug-sections format: %s",
484484 InputArgs.getLastArgValue(OBJCOPY_compress_debug_sections_eq)
485485 .str()
486486 .c_str());
525525 for (auto Arg : InputArgs.filtered(OBJCOPY_redefine_symbol)) {
526526 if (!StringRef(Arg->getValue()).contains('='))
527527 return createStringError(errc::invalid_argument,
528 "Bad format for --redefine-sym");
528 "bad format for --redefine-sym");
529529 auto Old2New = StringRef(Arg->getValue()).split('=');
530530 if (!Config.SymbolsToRename.insert(Old2New).second)
531531 return createStringError(errc::invalid_argument,
532 "Multiple redefinition of symbol %s",
532 "multiple redefinition of symbol '%s'",
533533 Old2New.first.str().c_str());
534534 }
535535
545545 return SR.takeError();
546546 if (!Config.SectionsToRename.try_emplace(SR->OriginalName, *SR).second)
547547 return createStringError(errc::invalid_argument,
548 "Multiple renames of section %s",
548 "multiple renames of section '%s'",
549549 SR->OriginalName.str().c_str());
550550 }
551551 for (auto Arg : InputArgs.filtered(OBJCOPY_set_section_flags)) {
556556 if (!Config.SetSectionFlags.try_emplace(SFU->Name, *SFU).second)
557557 return createStringError(
558558 errc::invalid_argument,
559 "--set-section-flags set multiple times for section %s",
559 "--set-section-flags set multiple times for section '%s'",
560560 SFU->Name.str().c_str());
561561 }
562562 // Prohibit combinations of --set-section-flags when the section name is used
692692 Config.CompressionType != DebugCompressionType::None) {
693693 return createStringError(
694694 errc::invalid_argument,
695 "Cannot specify --compress-debug-sections at the same time as "
696 "--decompress-debug-sections at the same time");
695 "cannot specify both --compress-debug-sections and "
696 "--decompress-debug-sections");
697697 }
698698
699699 if (Config.DecompressDebugSections && !zlib::isAvailable())
743743 Positional.push_back(Arg->getValue());
744744
745745 if (Positional.empty())
746 return createStringError(errc::invalid_argument, "No input file specified");
746 return createStringError(errc::invalid_argument, "no input file specified");
747747
748748 if (Positional.size() > 1 && InputArgs.hasArg(STRIP_output))
749749 return createStringError(
750750 errc::invalid_argument,
751 "Multiple input files cannot be used in combination with -o");
751 "multiple input files cannot be used in combination with -o");
752752
753753 CopyConfig Config;
754754 bool UseRegexp = InputArgs.hasArg(STRIP_regex);
5252 StringRef ToolName;
5353
5454 LLVM_ATTRIBUTE_NORETURN void error(Twine Message) {
55 WithColor::error(errs(), ToolName) << Message << ".\n";
55 WithColor::error(errs(), ToolName) << Message << "\n";
5656 errs().flush();
5757 exit(1);
5858 }
153153 return macho::executeObjcopyOnBinary(Config, *MachOBinary, Out);
154154 else
155155 return createStringError(object_error::invalid_file_type,
156 "Unsupported object file format");
156 "unsupported object file format");
157157 }
158158
159159 static Error executeObjcopyOnArchive(const CopyConfig &Config,