[lld] r284693 - Fix error message for unknown -format argument.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 19 21:47:45 PDT 2016


Author: ruiu
Date: Wed Oct 19 23:47:45 2016
New Revision: 284693

URL: http://llvm.org/viewvc/llvm-project?rev=284693&view=rev
Log:
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.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/test/ELF/format-binary.test

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=284693&r1=284692&r2=284693&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Oct 19 23:47:45 2016
@@ -581,13 +581,12 @@ void LinkerDriver::readConfigs(opt::Inpu
 }
 
 // Returns a value of "-format" option.
-static bool getBinaryOption(opt::Arg *Arg) {
-  StringRef S = Arg->getValue();
+static bool getBinaryOption(StringRef S) {
   if (S == "binary")
     return true;
   if (S == "elf" || S == "default")
     return false;
-  error("unknown " + Arg->getSpelling() + " format: " + S +
+  error("unknown -format value: " + S +
         " (supported formats: elf, default, binary)");
   return false;
 }
@@ -609,7 +608,7 @@ void LinkerDriver::createFiles(opt::Inpu
       Config->AsNeeded = true;
       break;
     case OPT_format:
-      Config->Binary = getBinaryOption(Arg);
+      Config->Binary = getBinaryOption(Arg->getValue());
       break;
     case OPT_no_as_needed:
       Config->AsNeeded = false;

Modified: lld/trunk/test/ELF/format-binary.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/format-binary.test?rev=284693&r1=284692&r2=284693&view=diff
==============================================================================
--- lld/trunk/test/ELF/format-binary.test (original)
+++ lld/trunk/test/ELF/format-binary.test Wed Oct 19 23:47:45 2016
@@ -7,6 +7,10 @@
 # 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: 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-NEXT:     Type: SHT_PROGBITS
 # CHECK-NEXT:     Flags [




More information about the llvm-commits mailing list