[lld] r316502 - [COFF] Add support for /WX
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 24 14:19:22 PDT 2017
Author: smeenai
Date: Tue Oct 24 14:19:22 2017
New Revision: 316502
URL: http://llvm.org/viewvc/llvm-project?rev=316502&view=rev
Log:
[COFF] Add support for /WX
link.exe supports this option to convert warnings into errors, and it's
useful to support in LLD as well.
Differential Revision: https://reviews.llvm.org/D39148
Added:
lld/trunk/test/COFF/wx.s
Modified:
lld/trunk/COFF/Config.h
lld/trunk/COFF/DriverUtils.cpp
lld/trunk/COFF/Error.cpp
lld/trunk/COFF/Options.td
Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=316502&r1=316501&r2=316502&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Tue Oct 24 14:19:22 2017
@@ -90,6 +90,7 @@ struct Configuration {
uint64_t ErrorLimit = 20;
bool Relocatable = true;
bool Force = false;
+ bool FatalWarnings = false;
bool Debug = false;
bool WriteSymtab = true;
unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=316502&r1=316501&r2=316502&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Tue Oct 24 14:19:22 2017
@@ -738,6 +738,9 @@ opt::InputArgList ArgParser::parse(Array
message(Msg);
}
+ // Handle /WX early since it converts missing argument warnings to errors.
+ Config->FatalWarnings = Args.hasFlag(OPT_WX, OPT_WX_no, false);
+
if (MissingCount)
fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument");
for (auto *Arg : Args.filtered(OPT_UNKNOWN))
Modified: lld/trunk/COFF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Error.cpp?rev=316502&r1=316501&r2=316502&view=diff
==============================================================================
--- lld/trunk/COFF/Error.cpp (original)
+++ lld/trunk/COFF/Error.cpp Tue Oct 24 14:19:22 2017
@@ -106,6 +106,11 @@ void fatal(llvm::Error &Err, const Twine
}
void warn(const Twine &Msg) {
+ if (Config->FatalWarnings) {
+ error(Msg);
+ return;
+ }
+
std::lock_guard<std::mutex> Lock(Mu);
print("warning: ", raw_ostream::MAGENTA);
*ErrorOS << Msg << "\n";
Modified: lld/trunk/COFF/Options.td
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Options.td?rev=316502&r1=316501&r2=316502&view=diff
==============================================================================
--- lld/trunk/COFF/Options.td (original)
+++ lld/trunk/COFF/Options.td Tue Oct 24 14:19:22 2017
@@ -85,6 +85,7 @@ def wholearchive_flag : F<"wholearchive"
def force : F<"force">,
HelpText<"Allow undefined symbols when creating executables">;
def force_unresolved : F<"force:unresolved">;
+defm WX : B<"WX", "Treat warnings as errors", "Don't treat warnings as errors">;
defm allowbind : B<"allowbind", "Enable DLL binding (default)",
"Disable DLL binding">;
@@ -162,5 +163,3 @@ def tlbid : QF<"tlbid">;
def tlbout : QF<"tlbout">;
def verbose_all : QF<"verbose">;
def guardsym : QF<"guardsym">;
-
-defm wx : QB<"wx">;
Added: lld/trunk/test/COFF/wx.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/wx.s?rev=316502&view=auto
==============================================================================
--- lld/trunk/test/COFF/wx.s (added)
+++ lld/trunk/test/COFF/wx.s Tue Oct 24 14:19:22 2017
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -triple=x86_64-windows-msvc -filetype=obj -o %t.obj %s
+# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX %t.obj 2>&1 | \
+# RUN: FileCheck -check-prefix=ERROR %s
+# RUN: not lld-link /out:%t.exe /entry:main -notarealoption /WX:NO /WX %t.obj 2>&1 | \
+# RUN: FileCheck -check-prefix=ERROR %s
+# RUN: lld-link /out:%t.exe /entry:main -notarealoption /WX /WX:NO %t.obj 2>&1 | \
+# RUN: FileCheck -check-prefix=WARNING %s
+
+# ERROR: error: ignoring unknown argument: -notarealoption
+# WARNING: warning: ignoring unknown argument: -notarealoption
+
+.text
+.global main
+main:
+ ret
More information about the llvm-commits
mailing list