Fix error message for unknown -format argument.

-format=<foo>, -format <foo> and -b <foo> are all the same.
Previous code was intended to produce an error message with the
same spelling as given from the command line, but it actually
always printed out this string: "unknown -format= value:".
This is probably more confusing than "unknown -format value:".
So I changed the message.

llvm-svn: 284693
This commit is contained in:
Rui Ueyama 2016-10-20 04:47:45 +00:00
parent 0aeb1199ea
commit d7c4454fb2
2 changed files with 7 additions and 4 deletions

View File

@ -581,13 +581,12 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
} }
// Returns a value of "-format" option. // Returns a value of "-format" option.
static bool getBinaryOption(opt::Arg *Arg) { static bool getBinaryOption(StringRef S) {
StringRef S = Arg->getValue();
if (S == "binary") if (S == "binary")
return true; return true;
if (S == "elf" || S == "default") if (S == "elf" || S == "default")
return false; return false;
error("unknown " + Arg->getSpelling() + " format: " + S + error("unknown -format value: " + S +
" (supported formats: elf, default, binary)"); " (supported formats: elf, default, binary)");
return false; return false;
} }
@ -609,7 +608,7 @@ void LinkerDriver::createFiles(opt::InputArgList &Args) {
Config->AsNeeded = true; Config->AsNeeded = true;
break; break;
case OPT_format: case OPT_format:
Config->Binary = getBinaryOption(Arg); Config->Binary = getBinaryOption(Arg->getValue());
break; break;
case OPT_no_as_needed: case OPT_no_as_needed:
Config->AsNeeded = false; Config->AsNeeded = false;

View File

@ -7,6 +7,10 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -b binary %t.binary -b default %t.o -shared -o %t.out # RUN: ld.lld %t.o -b binary %t.binary -b default %t.o -shared -o %t.out
# RUN: not ld.lld -b foo > %t.log 2>&1
# RUN: FileCheck -check-prefix=ERR %s < %t.log
# ERR: error: unknown -format value: foo (supported formats: elf, default, binary)
# CHECK: Name: .data # CHECK: Name: .data
# CHECK-NEXT: Type: SHT_PROGBITS # CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [ # CHECK-NEXT: Flags [