[PATCH] D58180: lld/coff: Simplify error message for comdat selection mismatches

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 13 07:28:46 PST 2019


thakis created this revision.
thakis added a reviewer: ruiu.
Herald added a project: LLVM.

Turns out nobody understands what "conflicting comdat type" is supposed to mean, so just emit a regular "duplicate symbol" error and move the comdat selection information into /verbose output.

This also fixes a problem where the error output would depend on the order of .obj files passed. Before this patch:

- If passed `one_only.obj discard.obj`, lld-link would only err "conflicting comdat type"
- If passed `discard.obj one_only.obj`, lld-link would err "conflicting comdat type" and then "duplicate symbol"

Now lld-link only errs "duplicate symbol" in both cases.

I considered adding a "Detail" parameter to reportDuplicate() that's printed in parens at the end of the "duplicate symbol" diag if present, and then put the comdat selection mismatch details there, but since users don't know what it's supposed to mean decided against it. I also considered special-casing the Detail message for one_only/discard mismatches, which in practice means "function defined as inline in TU 1 but as out-of-line in TU 2", but I wasn't sure how useful it is so I omitted that too.


https://reviews.llvm.org/D58180

Files:
  lld/COFF/InputFiles.cpp
  lld/test/COFF/comdat-selection.s


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
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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58180.186654.patch
Type: text/x-patch
Size: 3745 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190213/5b44cbab/attachment.bin>


More information about the llvm-commits mailing list