Index: lld/COFF/InputFiles.cpp =================================================================== --- lld/COFF/InputFiles.cpp +++ lld/COFF/InputFiles.cpp @@ -499,15 +499,15 @@ // seems better though. // (This behavior matches ModuleLinker::getComdatResult().) if (Selection != LeaderSelection) { - std::string Msg = ("conflicting comdat type for " + toString(*Leader) + + log(("conflicting comdat type for " + toString(*Leader) + ": " + Twine((int)LeaderSelection) + " in " + toString(Leader->getFile()) + " and " + Twine((int)Selection) + " in " + toString(this)) - .str(); - if (Config->ForceMultiple) - warn(Msg); - else - error(Msg); + .str()); + Symtab->reportDuplicate(Leader, this); + + // To make the switch below not emit another error. + Selection = IMAGE_COMDAT_SELECT_ANY; } switch (Selection) { Index: lld/test/COFF/comdat-selection.s =================================================================== --- lld/test/COFF/comdat-selection.s +++ lld/test/COFF/comdat-selection.s @@ -73,13 +73,21 @@ # lld-link rejects all comdat selection type mismatches. Spot-test just a few # combinations. -# RUN: not lld-link /dll /noentry /nodefaultlib %t.discard.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=DISCARDONE %s -# DISCARDONE: lld-link: error: conflicting comdat type for symbol: 2 in -# RUN: lld-link /force /dll /noentry /nodefaultlib %t.discard.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=DISCARDONEFORCE %s -# DISCARDONEFORCE: lld-link: warning: conflicting comdat type for symbol: 2 in - -# RUN: not lld-link /dll /noentry /nodefaultlib %t.same_contents.obj %t.same_size.obj 2>&1 | FileCheck --check-prefix=CONTENTSSIZE %s -# CONTENTSSIZE: lld-link: error: conflicting comdat type for symbol: 4 in +# RUN: not lld-link /verbose /dll /noentry /nodefaultlib %t.discard.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=DISCARDONE %s +# DISCARDONE: lld-link: conflicting comdat type for symbol: 2 in +# DISCARDONE: lld-link: error: duplicate symbol: symbol +# RUN: lld-link /verbose /force /dll /noentry /nodefaultlib %t.discard.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=DISCARDONEFORCE %s +# DISCARDONEFORCE: lld-link: conflicting comdat type for symbol: 2 in +# DISCARDONEFORCE: lld-link: warning: duplicate symbol: symbol + +# Make sure the error isn't depending on the order of .obj files. +# RUN: not lld-link /verbose /dll /noentry /nodefaultlib %t.one_only.obj %t.discard.obj 2>&1 | FileCheck --check-prefix=ONEDISCARD %s +# ONEDISCARD: lld-link: conflicting comdat type for symbol: 1 in +# ONEDISCARD: lld-link: error: duplicate symbol: symbol + +# RUN: not lld-link /verbose /dll /noentry /nodefaultlib %t.same_contents.obj %t.same_size.obj 2>&1 | FileCheck --check-prefix=CONTENTSSIZE %s +# CONTENTSSIZE: lld-link: conflicting comdat type for symbol: 4 in +# CONTENTSSIZE: lld-link: error: duplicate symbol: symbol # Check that linking one 'discard' and one 'largest' has the effect of # 'largest'. @@ -94,5 +102,6 @@ # These cases are accepted by link.exe but not by lld-link. -# RUN: not lld-link /dll /noentry /nodefaultlib %t.largest.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=LARGESTONE %s -# LARGESTONE: lld-link: error: conflicting comdat type for symbol: 6 in +# RUN: not lld-link /verbose /dll /noentry /nodefaultlib %t.largest.obj %t.one_only.obj 2>&1 | FileCheck --check-prefix=LARGESTONE %s +# LARGESTONE: lld-link: conflicting comdat type for symbol: 6 in +# LARGESTONE: lld-link: error: duplicate symbol: symbol