Skip to content

Commit

Permalink
[ELF] - Implemented --fatal-warnings option.
Browse files Browse the repository at this point in the history
--fatal-warnings: Treat warnings as errors

DIfferential revision: http://reviews.llvm.org/D21969

llvm-svn: 274504
  • Loading branch information
George Rimar committed Jul 4, 2016
1 parent 8b82fce commit 857644c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions lld/ELF/Config.h
Expand Up @@ -81,6 +81,7 @@ struct Configuration {
bool EhFrameHdr;
bool EnableNewDtags;
bool ExportDynamic;
bool FatalWarnings;
bool GcSections;
bool GnuHash = false;
bool ICF;
Expand Down
1 change: 1 addition & 0 deletions lld/ELF/Driver.cpp
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion lld/ELF/Error.cpp
Expand Up @@ -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";
Expand Down
4 changes: 3 additions & 1 deletion lld/ELF/Options.td
Expand Up @@ -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">;

Expand Down Expand Up @@ -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">,
Expand Down
16 changes: 16 additions & 0 deletions lld/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

0 comments on commit 857644c

Please sign in to comment.