[lld] r206863 - [PECOFF] Better handling of /OPT option.
Rui Ueyama
ruiu at google.com
Mon Apr 21 20:57:08 PDT 2014
Author: ruiu
Date: Mon Apr 21 22:57:07 2014
New Revision: 206863
URL: http://llvm.org/viewvc/llvm-project?rev=206863&view=rev
Log:
[PECOFF] Better handling of /OPT option.
Previously LLD would fail if /OPT:icf, /OPT:lbr or such are specified,
because these command line flags would be handled as unknown ones. We
rather want LLD to ignore these known but yet-to-be-implemented options
for now.
Added tests for the driver as well.
Modified:
lld/trunk/lib/Driver/WinLinkDriver.cpp
lld/trunk/lib/Driver/WinLinkOptions.td
lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=206863&r1=206862&r2=206863&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Mon Apr 21 22:57:07 2014
@@ -1088,6 +1088,22 @@ bool WinLinkDriver::parse(int argc, cons
ctx.appendInputSearchPath(ctx.allocate(inputArg->getValue()));
break;
+ case OPT_opt: {
+ StringRef arg = inputArg->getValue();
+ if (arg.equals_lower("noref")) {
+ ctx.setDeadStripping(false);
+ break;
+ }
+ if (arg.equals_lower("ref") || arg.equals_lower("icf") ||
+ arg.equals_lower("noicf") || arg.startswith_lower("icf=") ||
+ arg.equals_lower("lbr") || arg.equals_lower("nolbr")) {
+ // Ignore known but unsupported options.
+ break;
+ }
+ diag << "unknown option for /opt: " << arg << "\n";
+ return false;
+ }
+
case OPT_debug:
// LLD is not yet capable of creating a PDB file, so /debug does not have
// any effect, other than disabling dead stripping.
@@ -1161,7 +1177,6 @@ bool WinLinkDriver::parse(int argc, cons
ctx.setter(false); \
break
- DEFINE_BOOLEAN_FLAG(ref, setDeadStripping);
DEFINE_BOOLEAN_FLAG(nxcompat, setNxCompat);
DEFINE_BOOLEAN_FLAG(largeaddressaware, setLargeAddressAware);
DEFINE_BOOLEAN_FLAG(allowbind, setAllowBind);
@@ -1207,12 +1222,6 @@ bool WinLinkDriver::parse(int argc, cons
return false;
}
- // Specifying both /opt:ref and /opt:noref is an error.
- if (parsedArgs->getLastArg(OPT_ref) && parsedArgs->getLastArg(OPT_ref_no)) {
- diag << "/opt:ref must not be specified with /opt:noref\n";
- return false;
- }
-
// If dead-stripping is enabled, we need to add the entry symbol and
// symbols given by /include to the dead strip root set, so that it
// won't be removed from the output.
Modified: lld/trunk/lib/Driver/WinLinkOptions.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkOptions.td?rev=206863&r1=206862&r2=206863&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkOptions.td (original)
+++ lld/trunk/lib/Driver/WinLinkOptions.td Mon Apr 21 22:57:07 2014
@@ -36,6 +36,7 @@ def merge : P<"merge", "Combine sectio
def section : P<"section", "Specify section attributes">;
def subsystem : P<"subsystem", "Specify subsystem">;
def stub : P<"stub", "Specify DOS stub file">;
+def opt : P<"opt", "Control optimizations">;
def manifest : F<"manifest">;
def manifest_colon : P<"manifest", "Create manifest file">;
@@ -66,10 +67,6 @@ def force : F<"force">,
HelpText<"Allow undefined symbols when creating executables">;
def force_unresolved : F<"force:unresolved">;
-def ref : F<"opt:ref">;
-def ref_no : F<"opt:noref">,
- HelpText<"Keep unreferenced symbols to be included to the output">;
-
defm nxcompat : B<"nxcompat", "Disable data execution provention">;
defm largeaddressaware : B<"largeaddressaware", "Disable large addresses">;
defm allowbind: B<"allowbind", "Disable DLL binding">;
Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=206863&r1=206862&r2=206863&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Mon Apr 21 22:57:07 2014
@@ -642,6 +642,25 @@ TEST_F(WinLinkParserTest, Manifestdepend
}
//
+// Test for /OPT
+//
+
+TEST_F(WinLinkParserTest, OptNoRef) {
+ EXPECT_TRUE(parse("link.exe", "/opt:noref", "a.obj", nullptr));
+ EXPECT_FALSE(_context.deadStrip());
+}
+
+TEST_F(WinLinkParserTest, OptIgnore) {
+ EXPECT_TRUE(parse("link.exe", "/opt:ref", "/opt:icf", "/opt:noicf",
+ "/opt:icf=foo", "/opt:lbr", "/opt:nolbr", "a.obj",
+ nullptr));
+}
+
+TEST_F(WinLinkParserTest, OptUnknown) {
+ EXPECT_FALSE(parse("link.exe", "/opt:foo", "a.obj", nullptr));
+}
+
+//
// Test for command line flags that are ignored.
//
More information about the llvm-commits
mailing list