diff options
| author | Bob Haarman <llvm@inglorion.net> | 2017-12-28 07:02:13 +0000 |
|---|---|---|
| committer | Bob Haarman <llvm@inglorion.net> | 2017-12-28 07:02:13 +0000 |
| commit | e90ac016e73e7df3deca4c300fdd11a5e0bbe6f0 (patch) | |
| tree | 83a581bb94787004c19940cde75ab42d20de3f07 | |
| parent | 364cbfe9641a948244bc4c903eff6c8fd5127dab (diff) | |
| download | bcm5719-llvm-e90ac016e73e7df3deca4c300fdd11a5e0bbe6f0.tar.gz bcm5719-llvm-e90ac016e73e7df3deca4c300fdd11a5e0bbe6f0.zip | |
[COFF] support /ignore:4217
Summary:
lld-link accepts link.exe's /ignore option, but used to ignore
it. This can lead to semantic differences when warnings are treated as
fatal errors. One such case is when we resolve an __imp_ symbol to a
local definition. We emit a warning in that case, which /wx turns into
a fatal. This change makes lld-link accept /ignore:4217 to suppress
that warning, so that code that links with link.exe /wx /ignore:4217
links with lld-link, too.
Fixes PR35762.
Reviewers: rnk, ruiu
Reviewed By: ruiu
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D41606
llvm-svn: 321512
| -rw-r--r-- | lld/COFF/Config.h | 1 | ||||
| -rw-r--r-- | lld/COFF/Driver.cpp | 7 | ||||
| -rw-r--r-- | lld/COFF/Options.td | 2 | ||||
| -rw-r--r-- | lld/COFF/SymbolTable.cpp | 15 | ||||
| -rw-r--r-- | lld/test/COFF/ignore4217.yaml | 72 |
5 files changed, 90 insertions, 7 deletions
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h index 4eb8bae3c62..93bef23a97f 100644 --- a/lld/COFF/Config.h +++ b/lld/COFF/Config.h @@ -174,6 +174,7 @@ struct Configuration { bool HighEntropyVA = false; bool AppContainer = false; bool MinGW = false; + bool WarnLocallyDefinedImported = true; }; extern Configuration *Config; diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index 8be44cf2c7e..7319c8dd7e3 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -795,6 +795,13 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) { SearchPaths.push_back(Arg->getValue()); addLibSearchPaths(); + // Handle /ignore + for (auto *Arg : Args.filtered(OPT_ignore)) { + if (StringRef(Arg->getValue()) == "4217") + Config->WarnLocallyDefinedImported = false; + // Other warning numbers are ignored. + } + // Handle /out if (auto *Arg = Args.getLastArg(OPT_out)) Config->OutputFile = Arg->getValue(); diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td index 0e7a79730fa..7d4cdba14f7 100644 --- a/lld/COFF/Options.td +++ b/lld/COFF/Options.td @@ -29,6 +29,7 @@ def export : P<"export", "Export a function">; // No help text because /failifmismatch is not intended to be used by the user. def failifmismatch : P<"failifmismatch", "">; def heap : P<"heap", "Size of the heap">; +def ignore : P<"ignore", "Specify warning codes to ignore">; def implib : P<"implib", "Import library name">; def libpath : P<"libpath", "Additional library search path">; def linkrepro : P<"linkrepro", "Dump linker invocation and input files for debugging">; @@ -155,7 +156,6 @@ def fastfail : F<"fastfail">; def delay : QF<"delay">; def errorreport : QF<"errorreport">; def idlout : QF<"idlout">; -def ignore : QF<"ignore">; def maxilksize : QF<"maxilksize">; def natvis : QF<"natvis">; def pdbaltpath : QF<"pdbaltpath">; diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 95b48e6d059..df76679535c 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -117,9 +117,10 @@ void SymbolTable::reportRemainingUndefines() { for (Symbol *B : Config->GCRoot) { if (Undefs.count(B)) errorOrWarn("<root>: undefined symbol: " + B->getName()); - if (Symbol *Imp = LocalImports.lookup(B)) - warn("<root>: locally defined symbol imported: " + Imp->getName() + - " (defined in " + toString(Imp->getFile()) + ")"); + if (Config->WarnLocallyDefinedImported) + if (Symbol *Imp = LocalImports.lookup(B)) + warn("<root>: locally defined symbol imported: " + Imp->getName() + + " (defined in " + toString(Imp->getFile()) + ")"); } for (ObjFile *File : ObjFile::Instances) { @@ -128,9 +129,11 @@ void SymbolTable::reportRemainingUndefines() { continue; if (Undefs.count(Sym)) errorOrWarn(toString(File) + ": undefined symbol: " + Sym->getName()); - if (Symbol *Imp = LocalImports.lookup(Sym)) - warn(toString(File) + ": locally defined symbol imported: " + - Imp->getName() + " (defined in " + toString(Imp->getFile()) + ")"); + if (Config->WarnLocallyDefinedImported) + if (Symbol *Imp = LocalImports.lookup(Sym)) + warn(toString(File) + ": locally defined symbol imported: " + + Imp->getName() + " (defined in " + toString(Imp->getFile()) + + ")"); } } } diff --git a/lld/test/COFF/ignore4217.yaml b/lld/test/COFF/ignore4217.yaml new file mode 100644 index 00000000000..5f9d3e3ddf8 --- /dev/null +++ b/lld/test/COFF/ignore4217.yaml @@ -0,0 +1,72 @@ +# Tests that /ignore:4217 suppresses "locally defined symbol imported" warnings. +# RUN: yaml2obj < %s > %t.obj + +# RUN: lld-link -entry:main -out:%t.exe %t.obj 2>&1 \ +# RUN: | FileCheck -check-prefix=WARNINGS %s +# RUN: lld-link -ignore:4217 -entry:main -out:%t.exe %t.obj 2>&1 \ +# RUN: | FileCheck -allow-empty -check-prefix=SUPPRESSED %s + +# WARNINGS: locally defined symbol imported +# SUPPRESSED-NOT: locally defined symbol imported + +--- !COFF +header: + Machine: IMAGE_FILE_MACHINE_AMD64 + Characteristics: [ ] +sections: + - Name: .text + Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ] + Alignment: 16 + SectionData: B82A000000C3662E0F1F8400000000004883EC28C744242400000000E800000000904883C428C3 + Relocations: + - VirtualAddress: 29 + SymbolName: __imp_foo + Type: IMAGE_REL_AMD64_REL32 + - Name: .data + Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ] + Alignment: 4 + SectionData: '' +symbols: + - Name: .text + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 39 + NumberOfRelocations: 1 + NumberOfLinenumbers: 0 + CheckSum: 3087210877 + Number: 1 + - Name: .data + Value: 0 + SectionNumber: 2 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_STATIC + SectionDefinition: + Length: 0 + NumberOfRelocations: 0 + NumberOfLinenumbers: 0 + CheckSum: 0 + Number: 2 + - Name: foo + Value: 0 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: main + Value: 16 + SectionNumber: 1 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_FUNCTION + StorageClass: IMAGE_SYM_CLASS_EXTERNAL + - Name: __imp_foo + Value: 0 + SectionNumber: 0 + SimpleType: IMAGE_SYM_TYPE_NULL + ComplexType: IMAGE_SYM_DTYPE_NULL + StorageClass: IMAGE_SYM_CLASS_EXTERNAL +... |

