Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -81,6 +81,7 @@ bool EhFrameHdr; bool EnableNewDtags; bool ExportDynamic; + bool FatalWarnings; bool GcSections; bool GnuHash = false; bool ICF; Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -344,6 +344,7 @@ 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); Index: ELF/Error.cpp =================================================================== --- ELF/Error.cpp +++ ELF/Error.cpp @@ -24,7 +24,12 @@ 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"; Index: ELF/Options.td =================================================================== --- ELF/Options.td +++ ELF/Options.td @@ -66,6 +66,9 @@ 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<"">, HelpText<"Specify a finalizer function">; @@ -232,7 +235,6 @@ 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">, Index: test/ELF/fatal-warnings.s =================================================================== --- test/ELF/fatal-warnings.s +++ 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 +# RUN: llvm-readobj %t1.out > /dev/null 2>&1 + +# RUN: not ld.lld --warn-common --fatal-warnings %t1.o %t2.o -o %t2.out 2>&1 | \ +# RUN: FileCheck -check-prefix=ERR %s +# ERR: multiple common of + +.globl _start +_start: + +.type arr,@object +.comm arr,4,4