diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-07-04 13:43:12 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-07-04 13:43:12 +0000 |
commit | 2b57e1a144ab7774bceb955091af1d1acb49f4b3 (patch) | |
tree | 47872478d095aa92261e42deb2def3d32c8881fd | |
parent | 31198128afa56f9944345e63fede8dd126e31ebb (diff) |
[ELF] - Implemented --fatal-warnings option.
--fatal-warnings: Treat warnings as errors
DIfferential revision: http://reviews.llvm.org/D21969
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@274504 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/Config.h | 1 | ||||
-rw-r--r-- | ELF/Driver.cpp | 1 | ||||
-rw-r--r-- | ELF/Error.cpp | 7 | ||||
-rw-r--r-- | ELF/Options.td | 4 | ||||
-rw-r--r-- | test/ELF/fatal-warnings.s | 16 |
5 files changed, 27 insertions, 2 deletions
diff --git a/ELF/Config.h b/ELF/Config.h index 851e150b0..3c9c7a1ea 100644 --- a/ELF/Config.h +++ b/ELF/Config.h @@ -81,6 +81,7 @@ struct Configuration { bool EhFrameHdr; bool EnableNewDtags; bool ExportDynamic; + bool FatalWarnings; bool GcSections; bool GnuHash = false; bool ICF; diff --git a/ELF/Driver.cpp b/ELF/Driver.cpp index c8041e0db..5ce2a8c4d 100644 --- a/ELF/Driver.cpp +++ b/ELF/Driver.cpp @@ -344,6 +344,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) { Config->EhFrameHdr = Args.hasArg(OPT_eh_frame_hdr); Config->EnableNewDtags = !Args.hasArg(OPT_disable_new_dtags); Config->ExportDynamic = Args.hasArg(OPT_export_dynamic); + Config->FatalWarnings = Args.hasArg(OPT_fatal_warnings); Config->GcSections = Args.hasArg(OPT_gc_sections); Config->ICF = Args.hasArg(OPT_icf); Config->NoGnuUnique = Args.hasArg(OPT_no_gnu_unique); diff --git a/ELF/Error.cpp b/ELF/Error.cpp index 991ec97d0..d4a02e143 100644 --- a/ELF/Error.cpp +++ b/ELF/Error.cpp @@ -24,7 +24,12 @@ void log(const Twine &Msg) { llvm::outs() << Msg << "\n"; } -void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; } +void warning(const Twine &Msg) { + if (Config->FatalWarnings) + error(Msg); + else + llvm::errs() << Msg << "\n"; +} void error(const Twine &Msg) { *ErrorOS << Msg << "\n"; diff --git a/ELF/Options.td b/ELF/Options.td index 139f08d18..d4d5b1bc9 100644 --- a/ELF/Options.td +++ b/ELF/Options.td @@ -66,6 +66,9 @@ def export_dynamic: F<"export-dynamic">, def export_dynamic_symbol: S<"export-dynamic-symbol">, HelpText<"Put a symbol in the dynamic symbol table">; +def fatal_warnings: F<"fatal-warnings">, + HelpText<"Treat warnings as errors">; + def fini: S<"fini">, MetaVarName<"<symbol>">, HelpText<"Specify a finalizer function">; @@ -232,7 +235,6 @@ def plugin_opt_eq: J<"plugin-opt=">; def allow_shlib_undefined: F<"allow-shlib-undefined">; def define_common: F<"define-common">; def detect_odr_violations: F<"detect-odr-violations">; -def fatal_warnings: F<"fatal-warnings">; def no_add_needed: F<"no-add-needed">; def no_allow_shlib_undefined: F<"no-allow-shlib-undefined">; def no_copy_dt_needed_entries: F<"no-copy-dt-needed-entries">, diff --git a/test/ELF/fatal-warnings.s b/test/ELF/fatal-warnings.s new file mode 100644 index 000000000..0bc2a2b44 --- /dev/null +++ b/test/ELF/fatal-warnings.s @@ -0,0 +1,16 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/warn-common.s -o %t2.o + +# RUN: ld.lld --warn-common %t1.o %t2.o -o %t1.out 2>&1 | \ +# RUN: FileCheck -check-prefix=ERR %s +# ERR: multiple common of + +# RUN: not ld.lld --warn-common --fatal-warnings %t1.o %t2.o -o %t2.out 2>&1 | \ +# RUN: FileCheck -check-prefix=ERR %s + +.globl _start +_start: + +.type arr,@object +.comm arr,4,4 |