Index: lld/COFF/Config.h =================================================================== --- lld/COFF/Config.h +++ lld/COFF/Config.h @@ -174,6 +174,7 @@ bool HighEntropyVA = false; bool AppContainer = false; bool MinGW = false; + bool WarnLocallyDefinedImported = true; }; extern Configuration *Config; Index: lld/COFF/Driver.cpp =================================================================== --- lld/COFF/Driver.cpp +++ lld/COFF/Driver.cpp @@ -795,6 +795,13 @@ 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(); Index: lld/COFF/Options.td =================================================================== --- lld/COFF/Options.td +++ lld/COFF/Options.td @@ -29,6 +29,7 @@ // 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 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">; Index: lld/COFF/SymbolTable.cpp =================================================================== --- lld/COFF/SymbolTable.cpp +++ lld/COFF/SymbolTable.cpp @@ -117,9 +117,10 @@ for (Symbol *B : Config->GCRoot) { if (Undefs.count(B)) errorOrWarn(": undefined symbol: " + B->getName()); - if (Symbol *Imp = LocalImports.lookup(B)) - warn(": locally defined symbol imported: " + Imp->getName() + - " (defined in " + toString(Imp->getFile()) + ")"); + if (Config->WarnLocallyDefinedImported) + if (Symbol *Imp = LocalImports.lookup(B)) + warn(": locally defined symbol imported: " + Imp->getName() + + " (defined in " + toString(Imp->getFile()) + ")"); } for (ObjFile *File : ObjFile::Instances) { @@ -128,9 +129,11 @@ 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()) + + ")"); } } } Index: lld/test/COFF/ignore4217.yaml =================================================================== --- /dev/null +++ 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 +...