lld/coff: Make assoc comdat diag a bit more detailed

Many different sections can have the same name, so include the indices of the
sections mentioned in the diagnostic too.

I'm debugging something I can't repro locally, maybe this will help.


git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@352428 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/COFF/InputFiles.cpp b/COFF/InputFiles.cpp
index 4b87e02..6d4cb4e 100644
--- a/COFF/InputFiles.cpp
+++ b/COFF/InputFiles.cpp
@@ -225,6 +225,7 @@
                                         const coff_aux_section_definition *Def,
                                         uint32_t ParentIndex) {
   SectionChunk *Parent = SparseChunks[ParentIndex];
+  int32_t SectionNumber = Sym.getSectionNumber();
 
   auto Diag = [&]() {
     StringRef Name, ParentName;
@@ -233,8 +234,9 @@
     const coff_section *ParentSec;
     COFFObj->getSection(ParentIndex, ParentSec);
     COFFObj->getSectionName(ParentSec, ParentName);
-    error(toString(this) + ": associative comdat " + Name +
-          " has invalid reference to section " + ParentName);
+    error(toString(this) + ": associative comdat " + Name + " (sec " +
+          Twine(SectionNumber) + ") has invalid reference to section " +
+          ParentName + " (sec " + Twine(ParentIndex) + ")");
   };
 
   if (Parent == PendingComdat) {
@@ -247,7 +249,6 @@
 
   // Check whether the parent is prevailing. If it is, so are we, and we read
   // the section; otherwise mark it as discarded.
-  int32_t SectionNumber = Sym.getSectionNumber();
   if (Parent) {
     if (Parent->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
       Diag();
diff --git a/test/COFF/associative-comdat-empty.test b/test/COFF/associative-comdat-empty.test
index 1499d90..c4ee8b7 100644
--- a/test/COFF/associative-comdat-empty.test
+++ b/test/COFF/associative-comdat-empty.test
@@ -2,7 +2,7 @@
 # RUN: not lld-link /include:symbol /dll /noentry /nodefaultlib %t.obj /out:%t.exe 2>&1 | FileCheck %s
 
 # Tests an associative comdat being associated with an empty section errors.
-# CHECK: lld-link: error: {{.*}}: associative comdat .text$ac1 has invalid reference to section .text$nm
+# CHECK: lld-link: error: {{.*}}: associative comdat .text$ac1 (sec 1) has invalid reference to section .text$nm (sec 2)
 # CHECK-NOT: lld-link: error:
 
 --- !COFF
diff --git a/test/COFF/associative-comdat-order.test b/test/COFF/associative-comdat-order.test
index 09b1b46..dc58c2c 100644
--- a/test/COFF/associative-comdat-order.test
+++ b/test/COFF/associative-comdat-order.test
@@ -2,14 +2,14 @@
 # associated comdat later in the file produces an error.
 # RUN: sed -e s/ASSOC1/2/ -e s/ASSOC2/3/ %s | yaml2obj > %t.obj
 # RUN: not lld-link /include:symbol /dll /noentry /nodefaultlib %t.obj /out:%t.exe 2>&1 | FileCheck --check-prefix=FORWARD %s
-# FORWARD: lld-link: error: {{.*}}: associative comdat .text$ac1 has invalid reference to section .text$ac2
+# FORWARD: lld-link: error: {{.*}}: associative comdat .text$ac1 (sec 1) has invalid reference to section .text$ac2 (sec 2)
 # FORWARD-NOT: lld-link: error:
 
 # Tests that an associative comdat being associated with another
 # associated comdat earlier in the file produces an error.
 # RUN: sed -e s/ASSOC1/3/ -e s/ASSOC2/1/ %s | yaml2obj > %t.obj
 # RUN: not lld-link /include:symbol /dll /noentry /nodefaultlib %t.obj /out:%t.exe 2>&1 | FileCheck --check-prefix=BACKWARD %s
-# BACKWARD: lld-link: error: {{.*}}: associative comdat .text$ac2 has invalid reference to section .text$ac1
+# BACKWARD: lld-link: error: {{.*}}: associative comdat .text$ac2 (sec 2) has invalid reference to section .text$ac1 (sec 1)
 # BACKWARD-NOT: lld-link: error:
 
 --- !COFF