From b57e640f3a7775203f24190c4b13240bf6c2c7d4 Mon Sep 17 00:00:00 2001 From: Shoaib Meenai Date: Tue, 24 Oct 2017 21:19:22 +0000 Subject: [PATCH] [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 llvm-svn: 316502 --- lld/COFF/Config.h | 1 + lld/COFF/DriverUtils.cpp | 3 +++ lld/COFF/Error.cpp | 5 +++++ lld/COFF/Options.td | 3 +-- lld/test/COFF/wx.s | 17 +++++++++++++++++ 5 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 lld/test/COFF/wx.s diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index 7a281b3..e6ade3b 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -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(DebugType::None); diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp index a7e1b4e..a892d1a 100644 --- a/lld/COFF/DriverUtils.cpp +++ b/lld/COFF/DriverUtils.cpp @@ -738,6 +738,9 @@ opt::InputArgList ArgParser::parse(ArrayRef Argv) { 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)) diff --git a/lld/COFF/Error.cpp b/lld/COFF/Error.cpp index 550d9b9..4b9c377 100644 --- a/lld/COFF/Error.cpp +++ b/lld/COFF/Error.cpp @@ -106,6 +106,11 @@ void fatal(llvm::Error &Err, const Twine &Msg) { } void warn(const Twine &Msg) { + if (Config->FatalWarnings) { + error(Msg); + return; + } + std::lock_guard Lock(Mu); print("warning: ", raw_ostream::MAGENTA); *ErrorOS << Msg << "\n"; diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index 7ad269c..638516b 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -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">; diff --git a/lld/test/COFF/wx.s b/lld/test/COFF/wx.s new file mode 100644 index 0000000..3a470ed --- /dev/null +++ b/lld/test/COFF/wx.s @@ -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 -- 2.7.4