[lld] r191247 - [PECOFF] Do not allow space to separate command line option and its value.

Rui Ueyama ruiu at google.com
Mon Sep 23 16:51:32 PDT 2013


Author: ruiu
Date: Mon Sep 23 18:51:31 2013
New Revision: 191247

URL: http://llvm.org/viewvc/llvm-project?rev=191247&view=rev
Log:
[PECOFF] Do not allow space to separate command line option and its value.

We used to support both Windows and Unix style command line options. In Windows
style, an option and its value are separated by ":" (colon). In Unix, separator
is a space. Accepting both styles were convenient, but we can no longer allow
Unix style because I found that can be ambiguous.

For example, /nodefaultlib option takes an optional argument. In Windows style
it's going to be something like "/nodefaultlib:foo". There's no ambiguity what
"foo" means. However, if the option is "/nodefaultlib foo", "foo" can be
interpreted either an optional argument for "/nodefaultlib" or an input file
"foo.obj". We should just stop accepting the non-standard command line style.

Modified:
    lld/trunk/lib/Driver/WinLinkOptions.td
    lld/trunk/test/pecoff/entry.test
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=191247&r1=191246&r2=191247&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Mon Sep 23 18:51:31 2013
@@ -6,10 +6,8 @@ include "llvm/Option/OptParser.td"
 class F<string name> : Flag<["/", "-", "-?"], name>;
 
 // Flag that takes one argument after ":".
-multiclass P<string name, string help> {
-  def "" : Joined<["/", "-", "-?"], name#":">, HelpText<help>;
-  def _c : Separate<["/", "-", "-?"], name>, Alias<!cast<Option>(name)>;
-}
+class P<string name, string help> :
+      Joined<["/", "-", "-?"], name#":">, HelpText<help>;
 
 // Boolean flag suffixed by ":no".
 multiclass B<string name, string help> {
@@ -17,20 +15,20 @@ multiclass B<string name, string help> {
   def _no : F<name#":no">, HelpText<help>;
 }
 
-defm base    : P<"base", "Base address of the program">;
-defm defaultlib : P<"defaultlib", "Add the library to the list of input files">;
-defm entry   : P<"entry", "Name of entry point symbol">;
+def base    : P<"base", "Base address of the program">;
+def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
+def entry   : P<"entry", "Name of entry point symbol">;
 // No help text because /failifmismatch is not intended to be used by the user.
-defm failifmismatch : P<"failifmismatch", "">;
-defm heap    : P<"heap", "Size of the heap">;
-defm align   : P<"align", "Section alignment">;
-defm libpath : P<"libpath", "Additional library search path">;
-defm mllvm   : P<"mllvm", "Options to pass to LLVM">;
-defm out     : P<"out", "Path to file to write output">;
-defm stack   : P<"stack", "Size of the stack">;
-defm machine : P<"machine", "Specify target platform">;
-defm version : P<"version", "Specify a version number in the PE header">;
-defm subsystem : P<"subsystem", "Specify subsystem">;
+def failifmismatch : P<"failifmismatch", "">;
+def heap    : P<"heap", "Size of the heap">;
+def align   : P<"align", "Section alignment">;
+def libpath : P<"libpath", "Additional library search path">;
+def mllvm   : P<"mllvm", "Options to pass to LLVM">;
+def out     : P<"out", "Path to file to write output">;
+def stack   : P<"stack", "Size of the stack">;
+def machine : P<"machine", "Specify target platform">;
+def version : P<"version", "Specify a version number in the PE header">;
+def subsystem : P<"subsystem", "Specify subsystem">;
 
 // We cannot use multiclass P because class name "incl" is different
 // from its command line option name. We do this because "include" is
@@ -65,16 +63,13 @@ def DASH_DASH : Option<["--"], "", KIND_
 // The flags below do nothing. They are defined only for link.exe compatibility.
 //
 
-multiclass Q<string name> {
-  def "" : Joined<["/", "-", "-?"], name#":">;
-  def _c : Separate<["/", "-", "-?"], name>, Alias<!cast<Option>(name)>;
-}
+class Q<string name> : Joined<["/", "-", "-?"], name#":">;
 
 def nologo : F<"nologo">;
-defm errorreport : Q<"errorreport">;
+def errorreport : Q<"errorreport">;
 
 def incremental : F<"incremental">;
 def no_incremental : F<"incremental:no">;
 
-defm delay : Q<"delay">;
-defm delayload : Q<"delayload">;
+def delay : Q<"delay">;
+def delayload : Q<"delayload">;

Modified: lld/trunk/test/pecoff/entry.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/entry.test?rev=191247&r1=191246&r2=191247&view=diff
==============================================================================
--- lld/trunk/test/pecoff/entry.test (original)
+++ lld/trunk/test/pecoff/entry.test Mon Sep 23 18:51:31 2013
@@ -2,7 +2,7 @@
 # Verify that entry atom will not be dead-stripped.
 
 # RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj
-# RUN: lld -flavor link /mllvm -debug-only=WriterPECOFF /out:%t.exe \
+# RUN: lld -flavor link /mllvm:-debug-only=WriterPECOFF /out:%t.exe \
 # RUN:   /subsystem:console /entry:_main /force -- %t.obj >& %t.log
 # RUN: FileCheck %s < %t.log
 

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=191247&r1=191246&r2=191247&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Sep 23 18:51:31 2013
@@ -61,8 +61,8 @@ TEST_F(WinLinkParserTest, Basic) {
   EXPECT_TRUE(_context.deadStrip());
 }
 
-TEST_F(WinLinkParserTest, UnixStyleOption) {
-  EXPECT_FALSE(parse("link.exe", "-subsystem", "console", "-out", "a.exe",
+TEST_F(WinLinkParserTest, StartsWithHyphen) {
+  EXPECT_FALSE(parse("link.exe", "-subsystem:console", "-out:a.exe",
                      "a.obj", nullptr));
   EXPECT_EQ(llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI, _context.getSubsystem());
   EXPECT_EQ("a.exe", _context.outputPath());
@@ -80,7 +80,7 @@ TEST_F(WinLinkParserTest, UppercaseOptio
 }
 
 TEST_F(WinLinkParserTest, Mllvm) {
-  EXPECT_FALSE(parse("link.exe", "-mllvm", "-debug", "a.obj", nullptr));
+  EXPECT_FALSE(parse("link.exe", "/mllvm:-debug", "a.obj", nullptr));
   const std::vector<const char *> &options = _context.llvmOptions();
   EXPECT_EQ(1U, options.size());
   EXPECT_EQ("-debug", options[0]);





More information about the llvm-commits mailing list